Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Side by Side Diff: webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c

Issue 2274083002: Replace calls to assert() with RTC_DCHECK_*() in .c code (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 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
11 /* 11 /*
12 * bandwidth_estimator.c 12 * bandwidth_estimator.c
13 * 13 *
14 * This file contains the code for the Bandwidth Estimator designed 14 * This file contains the code for the Bandwidth Estimator designed
15 * for iSAC. 15 * for iSAC.
16 * 16 *
17 * NOTE! Castings needed for C55, do not remove! 17 * NOTE! Castings needed for C55, do not remove!
18 * 18 *
19 */ 19 */
20 20
21 #include "bandwidth_estimator.h" 21 #include "bandwidth_estimator.h"
22 22
23 #include <assert.h>
24 #include "settings.h" 23 #include "settings.h"
25 24 #include "webrtc/base/checks.h"
26 25
27 /* array of quantization levels for bottle neck info; Matlab code: */ 26 /* array of quantization levels for bottle neck info; Matlab code: */
28 /* sprintf('%4.1ff, ', logspace(log10(5000), log10(40000), 12)) */ 27 /* sprintf('%4.1ff, ', logspace(log10(5000), log10(40000), 12)) */
29 static const int16_t kQRateTable[12] = { 28 static const int16_t kQRateTable[12] = {
30 10000, 11115, 12355, 13733, 15265, 16967, 29 10000, 11115, 12355, 13733, 15265, 16967,
31 18860, 20963, 23301, 25900, 28789, 32000 30 18860, 20963, 23301, 25900, 28789, 32000
32 }; 31 };
33 32
34 /* 0.1 times the values in the table kQRateTable */ 33 /* 0.1 times the values in the table kQRateTable */
35 /* values are in Q16 */ 34 /* values are in Q16 */
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 int32_t sign; 172 int32_t sign;
174 173
175 uint32_t byteSecondsPerBit; 174 uint32_t byteSecondsPerBit;
176 uint32_t tempLower; 175 uint32_t tempLower;
177 uint32_t tempUpper; 176 uint32_t tempUpper;
178 int32_t recBwAvgInv; 177 int32_t recBwAvgInv;
179 int32_t numPktsExpected; 178 int32_t numPktsExpected;
180 179
181 int16_t errCode; 180 int16_t errCode;
182 181
183 assert(!bweStr->external_bw_info.in_use); 182 RTC_DCHECK(!bweStr->external_bw_info.in_use);
184 183
185 /* UPDATE ESTIMATES FROM OTHER SIDE */ 184 /* UPDATE ESTIMATES FROM OTHER SIDE */
186 185
187 /* The function also checks if Index has a valid value */ 186 /* The function also checks if Index has a valid value */
188 errCode = WebRtcIsacfix_UpdateUplinkBwRec(bweStr, Index); 187 errCode = WebRtcIsacfix_UpdateUplinkBwRec(bweStr, Index);
189 if (errCode <0) { 188 if (errCode <0) {
190 return(errCode); 189 return(errCode);
191 } 190 }
192 191
193 192
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } 543 }
545 544
546 /* This function updates the send bottle neck rate */ 545 /* This function updates the send bottle neck rate */
547 /* Index - integer (range 0...23) indicating bottle neck & jitter as est imated by other side */ 546 /* Index - integer (range 0...23) indicating bottle neck & jitter as est imated by other side */
548 /* returns 0 if everything went fine, -1 otherwise */ 547 /* returns 0 if everything went fine, -1 otherwise */
549 int16_t WebRtcIsacfix_UpdateUplinkBwRec(BwEstimatorstr *bweStr, 548 int16_t WebRtcIsacfix_UpdateUplinkBwRec(BwEstimatorstr *bweStr,
550 const int16_t Index) 549 const int16_t Index)
551 { 550 {
552 uint16_t RateInd; 551 uint16_t RateInd;
553 552
554 assert(!bweStr->external_bw_info.in_use); 553 RTC_DCHECK(!bweStr->external_bw_info.in_use);
555 554
556 if ( (Index < 0) || (Index > 23) ) { 555 if ( (Index < 0) || (Index > 23) ) {
557 return -ISAC_RANGE_ERROR_BW_ESTIMATOR; 556 return -ISAC_RANGE_ERROR_BW_ESTIMATOR;
558 } 557 }
559 558
560 /* UPDATE ESTIMATES FROM OTHER SIDE */ 559 /* UPDATE ESTIMATES FROM OTHER SIDE */
561 560
562 if ( Index > 11 ) { 561 if ( Index > 11 ) {
563 RateInd = Index - 12; 562 RateInd = Index - 12;
564 /* compute the jitter estimate as decoded on the other side in Q9 */ 563 /* compute the jitter estimate as decoded on the other side in Q9 */
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 724
726 /* get the bottle neck rate from far side to here, as estimated on this side */ 725 /* get the bottle neck rate from far side to here, as estimated on this side */
727 uint16_t WebRtcIsacfix_GetDownlinkBandwidth(const BwEstimatorstr *bweStr) 726 uint16_t WebRtcIsacfix_GetDownlinkBandwidth(const BwEstimatorstr *bweStr)
728 { 727 {
729 uint32_t recBw; 728 uint32_t recBw;
730 int32_t jitter_sign; /* Q8 */ 729 int32_t jitter_sign; /* Q8 */
731 int32_t bw_adjust; /* Q16 */ 730 int32_t bw_adjust; /* Q16 */
732 int32_t rec_jitter_short_term_abs_inv; /* Q18 */ 731 int32_t rec_jitter_short_term_abs_inv; /* Q18 */
733 int32_t temp; 732 int32_t temp;
734 733
735 assert(!bweStr->external_bw_info.in_use); 734 RTC_DCHECK(!bweStr->external_bw_info.in_use);
736 735
737 /* Q18 rec jitter short term abs is in Q13, multiply it by 2^13 to save preci sion 736 /* Q18 rec jitter short term abs is in Q13, multiply it by 2^13 to save preci sion
738 2^18 then needs to be shifted 13 bits to 2^31 */ 737 2^18 then needs to be shifted 13 bits to 2^31 */
739 rec_jitter_short_term_abs_inv = 0x80000000u / bweStr->recJitterShortTermAbs; 738 rec_jitter_short_term_abs_inv = 0x80000000u / bweStr->recJitterShortTermAbs;
740 739
741 /* Q27 = 9 + 18 */ 740 /* Q27 = 9 + 18 */
742 jitter_sign = (bweStr->recJitterShortTerm >> 4) * 741 jitter_sign = (bweStr->recJitterShortTerm >> 4) *
743 rec_jitter_short_term_abs_inv; 742 rec_jitter_short_term_abs_inv;
744 743
745 if (jitter_sign < 0) { 744 if (jitter_sign < 0) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 } 782 }
784 783
785 return (uint16_t) recBw; 784 return (uint16_t) recBw;
786 } 785 }
787 786
788 /* Returns the mmax delay (in ms) */ 787 /* Returns the mmax delay (in ms) */
789 int16_t WebRtcIsacfix_GetDownlinkMaxDelay(const BwEstimatorstr *bweStr) 788 int16_t WebRtcIsacfix_GetDownlinkMaxDelay(const BwEstimatorstr *bweStr)
790 { 789 {
791 int16_t recMaxDelay = (int16_t)(bweStr->recMaxDelay >> 15); 790 int16_t recMaxDelay = (int16_t)(bweStr->recMaxDelay >> 15);
792 791
793 assert(!bweStr->external_bw_info.in_use); 792 RTC_DCHECK(!bweStr->external_bw_info.in_use);
794 793
795 /* limit range of jitter estimate */ 794 /* limit range of jitter estimate */
796 if (recMaxDelay < MIN_ISAC_MD) { 795 if (recMaxDelay < MIN_ISAC_MD) {
797 recMaxDelay = MIN_ISAC_MD; 796 recMaxDelay = MIN_ISAC_MD;
798 } else if (recMaxDelay > MAX_ISAC_MD) { 797 } else if (recMaxDelay > MAX_ISAC_MD) {
799 recMaxDelay = MAX_ISAC_MD; 798 recMaxDelay = MAX_ISAC_MD;
800 } 799 }
801 800
802 return recMaxDelay; 801 return recMaxDelay;
803 } 802 }
804 803
805 /* Clamp val to the closed interval [min,max]. */ 804 /* Clamp val to the closed interval [min,max]. */
806 static int16_t clamp(int16_t val, int16_t min, int16_t max) { 805 static int16_t clamp(int16_t val, int16_t min, int16_t max) {
807 assert(min <= max); 806 RTC_DCHECK_LE(min, max);
808 return val < min ? min : (val > max ? max : val); 807 return val < min ? min : (val > max ? max : val);
809 } 808 }
810 809
811 int16_t WebRtcIsacfix_GetUplinkBandwidth(const BwEstimatorstr* bweStr) { 810 int16_t WebRtcIsacfix_GetUplinkBandwidth(const BwEstimatorstr* bweStr) {
812 return bweStr->external_bw_info.in_use 811 return bweStr->external_bw_info.in_use
813 ? bweStr->external_bw_info.send_bw_avg 812 ? bweStr->external_bw_info.send_bw_avg
814 : clamp(bweStr->sendBwAvg >> 7, MIN_ISAC_BW, MAX_ISAC_BW); 813 : clamp(bweStr->sendBwAvg >> 7, MIN_ISAC_BW, MAX_ISAC_BW);
815 } 814 }
816 815
817 int16_t WebRtcIsacfix_GetUplinkMaxDelay(const BwEstimatorstr* bweStr) { 816 int16_t WebRtcIsacfix_GetUplinkMaxDelay(const BwEstimatorstr* bweStr) {
818 return bweStr->external_bw_info.in_use 817 return bweStr->external_bw_info.in_use
819 ? bweStr->external_bw_info.send_max_delay_avg 818 ? bweStr->external_bw_info.send_max_delay_avg
820 : clamp(bweStr->sendMaxDelayAvg >> 9, MIN_ISAC_MD, MAX_ISAC_MD); 819 : clamp(bweStr->sendMaxDelayAvg >> 9, MIN_ISAC_MD, MAX_ISAC_MD);
821 } 820 }
822 821
823 void WebRtcIsacfixBw_GetBandwidthInfo(BwEstimatorstr* bweStr, 822 void WebRtcIsacfixBw_GetBandwidthInfo(BwEstimatorstr* bweStr,
824 IsacBandwidthInfo* bwinfo) { 823 IsacBandwidthInfo* bwinfo) {
825 assert(!bweStr->external_bw_info.in_use); 824 RTC_DCHECK(!bweStr->external_bw_info.in_use);
826 bwinfo->in_use = 1; 825 bwinfo->in_use = 1;
827 bwinfo->send_bw_avg = WebRtcIsacfix_GetUplinkBandwidth(bweStr); 826 bwinfo->send_bw_avg = WebRtcIsacfix_GetUplinkBandwidth(bweStr);
828 bwinfo->send_max_delay_avg = WebRtcIsacfix_GetUplinkMaxDelay(bweStr); 827 bwinfo->send_max_delay_avg = WebRtcIsacfix_GetUplinkMaxDelay(bweStr);
829 bwinfo->bottleneck_idx = WebRtcIsacfix_GetDownlinkBwIndexImpl(bweStr); 828 bwinfo->bottleneck_idx = WebRtcIsacfix_GetDownlinkBwIndexImpl(bweStr);
830 bwinfo->jitter_info = 0; // Not used. 829 bwinfo->jitter_info = 0; // Not used.
831 } 830 }
832 831
833 void WebRtcIsacfixBw_SetBandwidthInfo(BwEstimatorstr* bweStr, 832 void WebRtcIsacfixBw_SetBandwidthInfo(BwEstimatorstr* bweStr,
834 const IsacBandwidthInfo* bwinfo) { 833 const IsacBandwidthInfo* bwinfo) {
835 memcpy(&bweStr->external_bw_info, bwinfo, 834 memcpy(&bweStr->external_bw_info, bwinfo,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 /*s2nr = -1*(a_60 << 10) + ((b_60 * bottle_neck) >> 10);*/ 1028 /*s2nr = -1*(a_60 << 10) + ((b_60 * bottle_neck) >> 10);*/
1030 s2nr = -22500 + (int16_t)(500 * bottle_neck >> 10); 1029 s2nr = -22500 + (int16_t)(500 * bottle_neck >> 10);
1031 break; 1030 break;
1032 default: 1031 default:
1033 s2nr = -1; /* Error */ 1032 s2nr = -1; /* Error */
1034 } 1033 }
1035 1034
1036 return s2nr; //return in Q10 1035 return s2nr; //return in Q10
1037 1036
1038 } 1037 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698