| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 /* Struct for bottleneck model */ | 44 /* Struct for bottleneck model */ |
| 45 typedef struct { | 45 typedef struct { |
| 46 uint32_t send_time; /* samples */ | 46 uint32_t send_time; /* samples */ |
| 47 uint32_t arrival_time; /* samples */ | 47 uint32_t arrival_time; /* samples */ |
| 48 uint32_t sample_count; /* samples */ | 48 uint32_t sample_count; /* samples */ |
| 49 uint16_t rtp_number; | 49 uint16_t rtp_number; |
| 50 } BottleNeckModel; | 50 } BottleNeckModel; |
| 51 | 51 |
| 52 void get_arrival_time(int current_framesamples, /* samples */ | 52 void get_arrival_time(int current_framesamples, /* samples */ |
| 53 int packet_size, /* bytes */ | 53 size_t packet_size, /* bytes */ |
| 54 int bottleneck, /* excluding headers; bits/s *
/ | 54 int bottleneck, /* excluding headers; bits/s *
/ |
| 55 BottleNeckModel *BN_data) | 55 BottleNeckModel *BN_data) |
| 56 { | 56 { |
| 57 const int HeaderSize = 35; | 57 const int HeaderSize = 35; |
| 58 int HeaderRate; | 58 int HeaderRate; |
| 59 | 59 |
| 60 HeaderRate = HeaderSize * 8 * FS / current_framesamples; /* bits/s */ | 60 HeaderRate = HeaderSize * 8 * FS / current_framesamples; /* bits/s */ |
| 61 | 61 |
| 62 /* everything in samples */ | 62 /* everything in samples */ |
| 63 BN_data->sample_count = BN_data->sample_count + current_framesamples; | 63 BN_data->sample_count = BN_data->sample_count + current_framesamples; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 92 BN_data->rtp_number++; | 92 BN_data->rtp_number++; |
| 93 } | 93 } |
| 94 | 94 |
| 95 int main(int argc, char* argv[]) | 95 int main(int argc, char* argv[]) |
| 96 { | 96 { |
| 97 | 97 |
| 98 char inname[100], outname[100], outbitsname[100], bottleneck_file[100]; | 98 char inname[100], outname[100], outbitsname[100], bottleneck_file[100]; |
| 99 FILE *inp, *outp, *f_bn, *outbits; | 99 FILE *inp, *outp, *f_bn, *outbits; |
| 100 int endfile; | 100 int endfile; |
| 101 | 101 |
| 102 int i, errtype, h = 0, k, packetLossPercent = 0; | 102 size_t i; |
| 103 int errtype, h = 0, k, packetLossPercent = 0; |
| 103 int16_t CodingMode; | 104 int16_t CodingMode; |
| 104 int16_t bottleneck; | 105 int16_t bottleneck; |
| 105 int framesize = 30; /* ms */ | 106 int framesize = 30; /* ms */ |
| 106 int cur_framesmpls, err = 0, lostPackets = 0; | 107 int cur_framesmpls, err = 0, lostPackets = 0; |
| 107 | 108 |
| 108 /* Runtime statistics */ | 109 /* Runtime statistics */ |
| 109 double starttime, runtime, length_file; | 110 double starttime, runtime, length_file; |
| 110 | 111 |
| 111 int16_t stream_len = 0; | 112 int stream_len_int = 0; |
| 113 size_t stream_len = 0; |
| 112 int16_t framecnt; | 114 int16_t framecnt; |
| 113 int declen = 0; | 115 int declen = 0; |
| 114 int16_t shortdata[FRAMESAMPLES_10ms]; | 116 int16_t shortdata[FRAMESAMPLES_10ms]; |
| 115 int16_t decoded[MAX_FRAMESAMPLES]; | 117 int16_t decoded[MAX_FRAMESAMPLES]; |
| 116 uint16_t streamdata[500]; | 118 uint16_t streamdata[500]; |
| 117 int16_t speechType[1]; | 119 int16_t speechType[1]; |
| 118 int16_t prevFrameSize = 1; | 120 size_t prevFrameSize = 1; |
| 119 int16_t rateBPS = 0; | 121 int16_t rateBPS = 0; |
| 120 int16_t fixedFL = 0; | 122 int16_t fixedFL = 0; |
| 121 int16_t payloadSize = 0; | 123 int16_t payloadSize = 0; |
| 122 int32_t payloadRate = 0; | 124 int32_t payloadRate = 0; |
| 123 int setControlBWE = 0; | 125 int setControlBWE = 0; |
| 124 int readLoss; | 126 int readLoss; |
| 125 FILE *plFile = NULL; | 127 FILE *plFile = NULL; |
| 126 | 128 |
| 127 char version_number[20]; | 129 char version_number[20]; |
| 128 char tmpBit[5] = ".bit"; | 130 char tmpBit[5] = ".bit"; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 228 } |
| 227 | 229 |
| 228 /* Print version number */ | 230 /* Print version number */ |
| 229 WebRtcIsacfix_version(version_number); | 231 WebRtcIsacfix_version(version_number); |
| 230 printf("iSAC version %s \n\n", version_number); | 232 printf("iSAC version %s \n\n", version_number); |
| 231 | 233 |
| 232 /* Loop over all command line arguments */ | 234 /* Loop over all command line arguments */ |
| 233 CodingMode = 0; | 235 CodingMode = 0; |
| 234 testNum = 0; | 236 testNum = 0; |
| 235 testCE = 0; | 237 testCE = 0; |
| 236 for (i = 1; i + 2 < argc; i++) { | 238 for (i = 1; i + 2 < static_cast<size_t>(argc); i++) { |
| 237 /* Instantaneous mode */ | 239 /* Instantaneous mode */ |
| 238 if (!strcmp ("-I", argv[i])) { | 240 if (!strcmp ("-I", argv[i])) { |
| 239 printf("\nInstantaneous BottleNeck\n"); | 241 printf("\nInstantaneous BottleNeck\n"); |
| 240 CodingMode = 1; | 242 CodingMode = 1; |
| 241 i++; | 243 i++; |
| 242 } | 244 } |
| 243 | 245 |
| 244 /* Set (initial) bottleneck value */ | 246 /* Set (initial) bottleneck value */ |
| 245 if (!strcmp ("-INITRATE", argv[i])) { | 247 if (!strcmp ("-INITRATE", argv[i])) { |
| 246 rateBPS = atoi(argv[i + 1]); | 248 rateBPS = atoi(argv[i + 1]); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 if (testNum == 7) { | 560 if (testNum == 7) { |
| 559 srand(time(NULL)); | 561 srand(time(NULL)); |
| 560 } | 562 } |
| 561 | 563 |
| 562 /* iSAC encoding */ | 564 /* iSAC encoding */ |
| 563 if (!(testNum == 3 && framecnt == 0)) { | 565 if (!(testNum == 3 && framecnt == 0)) { |
| 564 if (nbTest != 1) { | 566 if (nbTest != 1) { |
| 565 short bwe; | 567 short bwe; |
| 566 | 568 |
| 567 /* Encode */ | 569 /* Encode */ |
| 568 stream_len = WebRtcIsacfix_Encode(ISAC_main_inst, | 570 stream_len_int = WebRtcIsacfix_Encode(ISAC_main_inst, |
| 569 shortdata, | 571 shortdata, |
| 570 (uint8_t*)streamdata); | 572 (uint8_t*)streamdata); |
| 571 | 573 |
| 572 /* If packet is ready, and CE testing, call the different API | 574 /* If packet is ready, and CE testing, call the different API |
| 573 functions from the internal API. */ | 575 functions from the internal API. */ |
| 574 if (stream_len>0) { | 576 if (stream_len_int>0) { |
| 575 if (testCE == 1) { | 577 if (testCE == 1) { |
| 576 err = WebRtcIsacfix_ReadBwIndex( | 578 err = WebRtcIsacfix_ReadBwIndex( |
| 577 reinterpret_cast<const uint8_t*>(streamdata), | 579 reinterpret_cast<const uint8_t*>(streamdata), |
| 578 stream_len, | 580 static_cast<size_t>(stream_len_int), |
| 579 &bwe); | 581 &bwe); |
| 580 stream_len = WebRtcIsacfix_GetNewBitStream( | 582 stream_len_int = WebRtcIsacfix_GetNewBitStream( |
| 581 ISAC_main_inst, | 583 ISAC_main_inst, |
| 582 bwe, | 584 bwe, |
| 583 scale, | 585 scale, |
| 584 reinterpret_cast<uint8_t*>(streamdata)); | 586 reinterpret_cast<uint8_t*>(streamdata)); |
| 585 } else if (testCE == 2) { | 587 } else if (testCE == 2) { |
| 586 /* transcode function not supported */ | 588 /* transcode function not supported */ |
| 587 } else if (testCE == 3) { | 589 } else if (testCE == 3) { |
| 588 /* Only for Function testing. The functions should normally | 590 /* Only for Function testing. The functions should normally |
| 589 not be used in this way */ | 591 not be used in this way */ |
| 590 | 592 |
| 591 err = WebRtcIsacfix_GetDownLinkBwIndex(ISAC_main_inst, &bwe); | 593 err = WebRtcIsacfix_GetDownLinkBwIndex(ISAC_main_inst, &bwe); |
| 592 /* Error Check */ | 594 /* Error Check */ |
| 593 if (err < 0) { | 595 if (err < 0) { |
| 594 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); | 596 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); |
| 595 printf("\nError in getSendBWE: %d.\n", errtype); | 597 printf("\nError in getSendBWE: %d.\n", errtype); |
| 596 } | 598 } |
| 597 | 599 |
| 598 err = WebRtcIsacfix_UpdateUplinkBw(ISAC_main_inst, bwe); | 600 err = WebRtcIsacfix_UpdateUplinkBw(ISAC_main_inst, bwe); |
| 599 /* Error Check */ | 601 /* Error Check */ |
| 600 if (err < 0) { | 602 if (err < 0) { |
| 601 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); | 603 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); |
| 602 printf("\nError in setBWE: %d.\n", errtype); | 604 printf("\nError in setBWE: %d.\n", errtype); |
| 603 } | 605 } |
| 604 | 606 |
| 605 } | 607 } |
| 606 } | 608 } |
| 607 } else { | 609 } else { |
| 608 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED | 610 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED |
| 609 stream_len = WebRtcIsacfix_EncodeNb(ISAC_main_inst, | 611 stream_len_int = WebRtcIsacfix_EncodeNb(ISAC_main_inst, |
| 610 shortdata, | 612 shortdata, |
| 611 streamdata); | 613 streamdata); |
| 612 #else | 614 #else |
| 613 stream_len = -1; | 615 stream_len_int = -1; |
| 614 #endif | 616 #endif |
| 615 } | 617 } |
| 616 } | 618 } |
| 617 else | 619 else |
| 618 { | 620 { |
| 619 break; | 621 break; |
| 620 } | 622 } |
| 621 | 623 |
| 622 if (stream_len < 0 || err < 0) { | 624 if (stream_len_int < 0 || err < 0) { |
| 623 /* exit if returned with error */ | 625 /* exit if returned with error */ |
| 624 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); | 626 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); |
| 625 printf("\nError in encoder: %d.\n", errtype); | 627 printf("\nError in encoder: %d.\n", errtype); |
| 626 } else { | 628 } else { |
| 629 stream_len = static_cast<size_t>(stream_len_int); |
| 627 if (fwrite(streamdata, sizeof(char), stream_len, outbits) != | 630 if (fwrite(streamdata, sizeof(char), stream_len, outbits) != |
| 628 (size_t)stream_len) { | 631 stream_len) { |
| 629 return -1; | 632 return -1; |
| 630 } | 633 } |
| 631 } | 634 } |
| 632 | 635 |
| 633 cur_framesmpls += FRAMESAMPLES_10ms; | 636 cur_framesmpls += FRAMESAMPLES_10ms; |
| 634 | 637 |
| 635 /* read next bottleneck rate */ | 638 /* read next bottleneck rate */ |
| 636 if (f_bn != NULL) { | 639 if (f_bn != NULL) { |
| 637 int aux_var; | 640 int aux_var; |
| 638 if (fscanf(f_bn, "%d", &aux_var) == EOF) { | 641 if (fscanf(f_bn, "%d", &aux_var) == EOF) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 lostFrame = !lostFrame; | 727 lostFrame = !lostFrame; |
| 725 } else { | 728 } else { |
| 726 lostFrame = (rand()%100 < packetLossPercent); | 729 lostFrame = (rand()%100 < packetLossPercent); |
| 727 } | 730 } |
| 728 | 731 |
| 729 | 732 |
| 730 | 733 |
| 731 /* iSAC decoding */ | 734 /* iSAC decoding */ |
| 732 if( lostFrame && framecnt > 0) { | 735 if( lostFrame && framecnt > 0) { |
| 733 if (nbTest !=2) { | 736 if (nbTest !=2) { |
| 734 declen = | 737 declen = static_cast<int>( |
| 735 WebRtcIsacfix_DecodePlc(ISAC_main_inst, decoded, prevFrameSize); | 738 WebRtcIsacfix_DecodePlc(ISAC_main_inst, decoded, prevFrameSize)); |
| 736 } else { | 739 } else { |
| 737 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED | 740 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED |
| 738 declen = WebRtcIsacfix_DecodePlcNb( | 741 declen = static_cast<int>(WebRtcIsacfix_DecodePlcNb( |
| 739 ISAC_main_inst, decoded, prevFrameSize); | 742 ISAC_main_inst, decoded, prevFrameSize)); |
| 740 #else | 743 #else |
| 741 declen = -1; | 744 declen = -1; |
| 742 #endif | 745 #endif |
| 743 } | 746 } |
| 744 lostPackets++; | 747 lostPackets++; |
| 745 } else { | 748 } else { |
| 746 if (nbTest !=2 ) { | 749 if (nbTest !=2 ) { |
| 747 short FL; | 750 size_t FL; |
| 748 /* Call getFramelen, only used here for function test */ | 751 /* Call getFramelen, only used here for function test */ |
| 749 err = WebRtcIsacfix_ReadFrameLen( | 752 err = WebRtcIsacfix_ReadFrameLen( |
| 750 reinterpret_cast<const uint8_t*>(streamdata), stream_len, &FL); | 753 reinterpret_cast<const uint8_t*>(streamdata), stream_len, &FL); |
| 751 declen = WebRtcIsacfix_Decode( | 754 declen = WebRtcIsacfix_Decode( |
| 752 ISAC_main_inst, | 755 ISAC_main_inst, |
| 753 reinterpret_cast<const uint8_t*>(streamdata), | 756 reinterpret_cast<const uint8_t*>(streamdata), |
| 754 stream_len, | 757 stream_len, |
| 755 decoded, | 758 decoded, |
| 756 speechType); | 759 speechType); |
| 757 /* Error check */ | 760 /* Error check */ |
| 758 if (err < 0 || declen < 0 || FL != declen) { | 761 if (err < 0 || declen < 0 || FL != static_cast<size_t>(declen)) { |
| 759 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); | 762 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); |
| 760 printf("\nError in decode_B/or getFrameLen: %d.\n", errtype); | 763 printf("\nError in decode_B/or getFrameLen: %d.\n", errtype); |
| 761 } | 764 } |
| 762 prevFrameSize = declen/480; | 765 prevFrameSize = static_cast<size_t>(declen/480); |
| 763 | 766 |
| 764 } else { | 767 } else { |
| 765 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED | 768 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED |
| 766 declen = WebRtcIsacfix_DecodeNb( ISAC_main_inst, streamdata, | 769 declen = WebRtcIsacfix_DecodeNb( ISAC_main_inst, streamdata, |
| 767 stream_len, decoded, speechType ); | 770 stream_len, decoded, speechType ); |
| 768 #else | 771 #else |
| 769 declen = -1; | 772 declen = -1; |
| 770 #endif | 773 #endif |
| 771 prevFrameSize = static_cast<int16_t>(declen / 240); | 774 prevFrameSize = static_cast<size_t>(declen / 240); |
| 772 } | 775 } |
| 773 } | 776 } |
| 774 | 777 |
| 775 if (declen <= 0) { | 778 if (declen <= 0) { |
| 776 /* exit if returned with error */ | 779 /* exit if returned with error */ |
| 777 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); | 780 errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); |
| 778 printf("\nError in decoder: %d.\n", errtype); | 781 printf("\nError in decoder: %d.\n", errtype); |
| 779 } | 782 } |
| 780 | 783 |
| 781 /* Write decoded speech frame to file */ | 784 /* Write decoded speech frame to file */ |
| 782 if (fwrite(decoded, sizeof(int16_t), | 785 if (fwrite(decoded, sizeof(int16_t), |
| 783 declen, outp) != (size_t)declen) { | 786 declen, outp) != (size_t)declen) { |
| 784 return -1; | 787 return -1; |
| 785 } | 788 } |
| 786 // fprintf( ratefile, "%f \n", stream_len / ( ((double)declen)/ | 789 // fprintf( ratefile, "%f \n", stream_len / ( ((double)declen)/ |
| 787 // ((double)FS) ) * 8 ); | 790 // ((double)FS) ) * 8 ); |
| 788 } else { | 791 } else { |
| 789 lostPackets++; | 792 lostPackets++; |
| 790 } | 793 } |
| 791 framecnt++; | 794 framecnt++; |
| 792 | 795 |
| 793 totalsmpls += declen; | 796 totalsmpls += declen; |
| 794 totalbits += 8 * stream_len; | 797 totalbits += static_cast<int>(8 * stream_len); |
| 795 | 798 |
| 796 /* Error test number 10, garbage data */ | 799 /* Error test number 10, garbage data */ |
| 797 if (testNum == 10) { | 800 if (testNum == 10) { |
| 798 if ( (seedfile = fopen(SEED_FILE, "a+t") ) == NULL ) { | 801 if ( (seedfile = fopen(SEED_FILE, "a+t") ) == NULL ) { |
| 799 printf( "Error: Could not open file %s\n", SEED_FILE); | 802 printf( "Error: Could not open file %s\n", SEED_FILE); |
| 800 } | 803 } |
| 801 else { | 804 else { |
| 802 fprintf(seedfile, "ok\n\n"); | 805 fprintf(seedfile, "ok\n\n"); |
| 803 fclose(seedfile); | 806 fclose(seedfile); |
| 804 } | 807 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 828 fclose(inp); | 831 fclose(inp); |
| 829 fclose(outp); | 832 fclose(outp); |
| 830 fclose(outbits); | 833 fclose(outbits); |
| 831 | 834 |
| 832 if ( testCE == 1) { | 835 if ( testCE == 1) { |
| 833 WebRtcIsacfix_FreeInternal(ISAC_main_inst); | 836 WebRtcIsacfix_FreeInternal(ISAC_main_inst); |
| 834 } | 837 } |
| 835 WebRtcIsacfix_Free(ISAC_main_inst); | 838 WebRtcIsacfix_Free(ISAC_main_inst); |
| 836 return 0; | 839 return 0; |
| 837 } | 840 } |
| OLD | NEW |