| 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 |
| 11 /* | 11 /* |
| 12 * BwEstimator.c | 12 * BwEstimator.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 */ | 17 */ |
| 18 | 18 |
| 19 #include "bandwidth_estimator.h" | 19 #include "bandwidth_estimator.h" |
| 20 #include "settings.h" | 20 #include "settings.h" |
| 21 #include "isac.h" | 21 #include "isac.h" |
| 22 #include "webrtc/base/checks.h" |
| 22 | 23 |
| 23 #include <assert.h> | |
| 24 #include <math.h> | 24 #include <math.h> |
| 25 #include <string.h> | 25 #include <string.h> |
| 26 | 26 |
| 27 /* array of quantization levels for bottle neck info; Matlab code: */ | 27 /* array of quantization levels for bottle neck info; Matlab code: */ |
| 28 /* sprintf('%4.1ff, ', logspace(log10(5000), log10(40000), 12)) */ | 28 /* sprintf('%4.1ff, ', logspace(log10(5000), log10(40000), 12)) */ |
| 29 static const float kQRateTableWb[12] = | 29 static const float kQRateTableWb[12] = |
| 30 { | 30 { |
| 31 10000.0f, 11115.3f, 12355.1f, 13733.1f, 15264.8f, 16967.3f, | 31 10000.0f, 11115.3f, 12355.1f, 13733.1f, 15264.8f, 16967.3f, |
| 32 18859.8f, 20963.3f, 23301.4f, 25900.3f, 28789.0f, 32000.0f}; | 32 18859.8f, 20963.3f, 23301.4f, 25900.3f, 28789.0f, 32000.0f}; |
| 33 | 33 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 float arr_ts_diff; | 152 float arr_ts_diff; |
| 153 float send_ts_diff; | 153 float send_ts_diff; |
| 154 float arr_time_noise; | 154 float arr_time_noise; |
| 155 float arr_time_noise_abs; | 155 float arr_time_noise_abs; |
| 156 | 156 |
| 157 float delay_correction_factor = 1; | 157 float delay_correction_factor = 1; |
| 158 float late_diff = 0.0f; | 158 float late_diff = 0.0f; |
| 159 int immediate_set = 0; | 159 int immediate_set = 0; |
| 160 int num_pkts_expected; | 160 int num_pkts_expected; |
| 161 | 161 |
| 162 assert(!bwest_str->external_bw_info.in_use); | 162 RTC_DCHECK(!bwest_str->external_bw_info.in_use); |
| 163 | 163 |
| 164 // We have to adjust the header-rate if the first packet has a | 164 // We have to adjust the header-rate if the first packet has a |
| 165 // frame-size different than the initialized value. | 165 // frame-size different than the initialized value. |
| 166 if ( frame_length != bwest_str->prev_frame_length ) | 166 if ( frame_length != bwest_str->prev_frame_length ) |
| 167 { | 167 { |
| 168 bwest_str->rec_header_rate = (float)HEADER_SIZE * 8.0f * | 168 bwest_str->rec_header_rate = (float)HEADER_SIZE * 8.0f * |
| 169 1000.0f / (float)frame_length; /* bits/s */ | 169 1000.0f / (float)frame_length; /* bits/s */ |
| 170 } | 170 } |
| 171 | 171 |
| 172 /* UPDATE ESTIMATES ON THIS SIDE */ | 172 /* UPDATE ESTIMATES ON THIS SIDE */ |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 | 507 |
| 508 | 508 |
| 509 /* This function updates the send bottle neck rate
*/ | 509 /* This function updates the send bottle neck rate
*/ |
| 510 /* Index - integer (range 0...23) indicating bottle neck & jitter as est
imated by other side */ | 510 /* Index - integer (range 0...23) indicating bottle neck & jitter as est
imated by other side */ |
| 511 /* returns 0 if everything went fine, -1 otherwise
*/ | 511 /* returns 0 if everything went fine, -1 otherwise
*/ |
| 512 int16_t WebRtcIsac_UpdateUplinkBwImpl( | 512 int16_t WebRtcIsac_UpdateUplinkBwImpl( |
| 513 BwEstimatorstr* bwest_str, | 513 BwEstimatorstr* bwest_str, |
| 514 int16_t index, | 514 int16_t index, |
| 515 enum IsacSamplingRate encoderSamplingFreq) | 515 enum IsacSamplingRate encoderSamplingFreq) |
| 516 { | 516 { |
| 517 assert(!bwest_str->external_bw_info.in_use); | 517 RTC_DCHECK(!bwest_str->external_bw_info.in_use); |
| 518 | 518 |
| 519 if((index < 0) || (index > 23)) | 519 if((index < 0) || (index > 23)) |
| 520 { | 520 { |
| 521 return -ISAC_RANGE_ERROR_BW_ESTIMATOR; | 521 return -ISAC_RANGE_ERROR_BW_ESTIMATOR; |
| 522 } | 522 } |
| 523 | 523 |
| 524 /* UPDATE ESTIMATES FROM OTHER SIDE */ | 524 /* UPDATE ESTIMATES FROM OTHER SIDE */ |
| 525 if(encoderSamplingFreq == kIsacWideband) | 525 if(encoderSamplingFreq == kIsacWideband) |
| 526 { | 526 { |
| 527 if(index > 11) | 527 if(index > 11) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 565 } |
| 566 return 0; | 566 return 0; |
| 567 } | 567 } |
| 568 | 568 |
| 569 // called when there is upper-band bit-stream to update jitter | 569 // called when there is upper-band bit-stream to update jitter |
| 570 // statistics. | 570 // statistics. |
| 571 int16_t WebRtcIsac_UpdateUplinkJitter( | 571 int16_t WebRtcIsac_UpdateUplinkJitter( |
| 572 BwEstimatorstr* bwest_str, | 572 BwEstimatorstr* bwest_str, |
| 573 int32_t index) | 573 int32_t index) |
| 574 { | 574 { |
| 575 assert(!bwest_str->external_bw_info.in_use); | 575 RTC_DCHECK(!bwest_str->external_bw_info.in_use); |
| 576 | 576 |
| 577 if((index < 0) || (index > 23)) | 577 if((index < 0) || (index > 23)) |
| 578 { | 578 { |
| 579 return -ISAC_RANGE_ERROR_BW_ESTIMATOR; | 579 return -ISAC_RANGE_ERROR_BW_ESTIMATOR; |
| 580 } | 580 } |
| 581 | 581 |
| 582 if(index > 0) | 582 if(index > 0) |
| 583 { | 583 { |
| 584 /* compute the jitter estimate as decoded on the other side */ | 584 /* compute the jitter estimate as decoded on the other side */ |
| 585 bwest_str->send_max_delay_avg = 0.9f * bwest_str->send_max_delay_avg + | 585 bwest_str->send_max_delay_avg = 0.9f * bwest_str->send_max_delay_avg + |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 | 704 |
| 705 | 705 |
| 706 | 706 |
| 707 /* get the bottle neck rate from far side to here, as estimated on this side */ | 707 /* get the bottle neck rate from far side to here, as estimated on this side */ |
| 708 int32_t WebRtcIsac_GetDownlinkBandwidth( const BwEstimatorstr *bwest_str) | 708 int32_t WebRtcIsac_GetDownlinkBandwidth( const BwEstimatorstr *bwest_str) |
| 709 { | 709 { |
| 710 int32_t rec_bw; | 710 int32_t rec_bw; |
| 711 float jitter_sign; | 711 float jitter_sign; |
| 712 float bw_adjust; | 712 float bw_adjust; |
| 713 | 713 |
| 714 assert(!bwest_str->external_bw_info.in_use); | 714 RTC_DCHECK(!bwest_str->external_bw_info.in_use); |
| 715 | 715 |
| 716 /* create a value between -1.0 and 1.0 indicating "average sign" of jitter */ | 716 /* create a value between -1.0 and 1.0 indicating "average sign" of jitter */ |
| 717 jitter_sign = bwest_str->rec_jitter_short_term / | 717 jitter_sign = bwest_str->rec_jitter_short_term / |
| 718 bwest_str->rec_jitter_short_term_abs; | 718 bwest_str->rec_jitter_short_term_abs; |
| 719 | 719 |
| 720 /* adjust bw proportionally to negative average jitter sign */ | 720 /* adjust bw proportionally to negative average jitter sign */ |
| 721 bw_adjust = 1.0f - jitter_sign * (0.15f + 0.15f * jitter_sign * jitter_sign); | 721 bw_adjust = 1.0f - jitter_sign * (0.15f + 0.15f * jitter_sign * jitter_sign); |
| 722 | 722 |
| 723 /* adjust Rate if jitter sign is mostly constant */ | 723 /* adjust Rate if jitter sign is mostly constant */ |
| 724 rec_bw = (int32_t)(bwest_str->rec_bw * bw_adjust); | 724 rec_bw = (int32_t)(bwest_str->rec_bw * bw_adjust); |
| 725 | 725 |
| 726 /* limit range of bottle neck rate */ | 726 /* limit range of bottle neck rate */ |
| 727 if (rec_bw < MIN_ISAC_BW) | 727 if (rec_bw < MIN_ISAC_BW) |
| 728 { | 728 { |
| 729 rec_bw = MIN_ISAC_BW; | 729 rec_bw = MIN_ISAC_BW; |
| 730 } | 730 } |
| 731 else if (rec_bw > MAX_ISAC_BW) | 731 else if (rec_bw > MAX_ISAC_BW) |
| 732 { | 732 { |
| 733 rec_bw = MAX_ISAC_BW; | 733 rec_bw = MAX_ISAC_BW; |
| 734 } | 734 } |
| 735 return rec_bw; | 735 return rec_bw; |
| 736 } | 736 } |
| 737 | 737 |
| 738 /* Returns the max delay (in ms) */ | 738 /* Returns the max delay (in ms) */ |
| 739 int32_t | 739 int32_t |
| 740 WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr *bwest_str) | 740 WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr *bwest_str) |
| 741 { | 741 { |
| 742 int32_t rec_max_delay; | 742 int32_t rec_max_delay; |
| 743 | 743 |
| 744 assert(!bwest_str->external_bw_info.in_use); | 744 RTC_DCHECK(!bwest_str->external_bw_info.in_use); |
| 745 | 745 |
| 746 rec_max_delay = (int32_t)(bwest_str->rec_max_delay); | 746 rec_max_delay = (int32_t)(bwest_str->rec_max_delay); |
| 747 | 747 |
| 748 /* limit range of jitter estimate */ | 748 /* limit range of jitter estimate */ |
| 749 if (rec_max_delay < MIN_ISAC_MD) | 749 if (rec_max_delay < MIN_ISAC_MD) |
| 750 { | 750 { |
| 751 rec_max_delay = MIN_ISAC_MD; | 751 rec_max_delay = MIN_ISAC_MD; |
| 752 } | 752 } |
| 753 else if (rec_max_delay > MAX_ISAC_MD) | 753 else if (rec_max_delay > MAX_ISAC_MD) |
| 754 { | 754 { |
| 755 rec_max_delay = MAX_ISAC_MD; | 755 rec_max_delay = MAX_ISAC_MD; |
| 756 } | 756 } |
| 757 return rec_max_delay; | 757 return rec_max_delay; |
| 758 } | 758 } |
| 759 | 759 |
| 760 /* Clamp val to the closed interval [min,max]. */ | 760 /* Clamp val to the closed interval [min,max]. */ |
| 761 static int32_t clamp(int32_t val, int32_t min, int32_t max) { | 761 static int32_t clamp(int32_t val, int32_t min, int32_t max) { |
| 762 assert(min <= max); | 762 RTC_DCHECK_LE(min, max); |
| 763 return val < min ? min : (val > max ? max : val); | 763 return val < min ? min : (val > max ? max : val); |
| 764 } | 764 } |
| 765 | 765 |
| 766 int32_t WebRtcIsac_GetUplinkBandwidth(const BwEstimatorstr* bwest_str) { | 766 int32_t WebRtcIsac_GetUplinkBandwidth(const BwEstimatorstr* bwest_str) { |
| 767 return bwest_str->external_bw_info.in_use | 767 return bwest_str->external_bw_info.in_use |
| 768 ? bwest_str->external_bw_info.send_bw_avg | 768 ? bwest_str->external_bw_info.send_bw_avg |
| 769 : clamp(bwest_str->send_bw_avg, MIN_ISAC_BW, MAX_ISAC_BW); | 769 : clamp(bwest_str->send_bw_avg, MIN_ISAC_BW, MAX_ISAC_BW); |
| 770 } | 770 } |
| 771 | 771 |
| 772 int32_t WebRtcIsac_GetUplinkMaxDelay(const BwEstimatorstr* bwest_str) { | 772 int32_t WebRtcIsac_GetUplinkMaxDelay(const BwEstimatorstr* bwest_str) { |
| 773 return bwest_str->external_bw_info.in_use | 773 return bwest_str->external_bw_info.in_use |
| 774 ? bwest_str->external_bw_info.send_max_delay_avg | 774 ? bwest_str->external_bw_info.send_max_delay_avg |
| 775 : clamp(bwest_str->send_max_delay_avg, MIN_ISAC_MD, MAX_ISAC_MD); | 775 : clamp(bwest_str->send_max_delay_avg, MIN_ISAC_MD, MAX_ISAC_MD); |
| 776 } | 776 } |
| 777 | 777 |
| 778 void WebRtcIsacBw_GetBandwidthInfo(BwEstimatorstr* bwest_str, | 778 void WebRtcIsacBw_GetBandwidthInfo(BwEstimatorstr* bwest_str, |
| 779 enum IsacSamplingRate decoder_sample_rate_hz, | 779 enum IsacSamplingRate decoder_sample_rate_hz, |
| 780 IsacBandwidthInfo* bwinfo) { | 780 IsacBandwidthInfo* bwinfo) { |
| 781 assert(!bwest_str->external_bw_info.in_use); | 781 RTC_DCHECK(!bwest_str->external_bw_info.in_use); |
| 782 bwinfo->in_use = 1; | 782 bwinfo->in_use = 1; |
| 783 bwinfo->send_bw_avg = WebRtcIsac_GetUplinkBandwidth(bwest_str); | 783 bwinfo->send_bw_avg = WebRtcIsac_GetUplinkBandwidth(bwest_str); |
| 784 bwinfo->send_max_delay_avg = WebRtcIsac_GetUplinkMaxDelay(bwest_str); | 784 bwinfo->send_max_delay_avg = WebRtcIsac_GetUplinkMaxDelay(bwest_str); |
| 785 WebRtcIsac_GetDownlinkBwJitIndexImpl(bwest_str, &bwinfo->bottleneck_idx, | 785 WebRtcIsac_GetDownlinkBwJitIndexImpl(bwest_str, &bwinfo->bottleneck_idx, |
| 786 &bwinfo->jitter_info, | 786 &bwinfo->jitter_info, |
| 787 decoder_sample_rate_hz); | 787 decoder_sample_rate_hz); |
| 788 } | 788 } |
| 789 | 789 |
| 790 void WebRtcIsacBw_SetBandwidthInfo(BwEstimatorstr* bwest_str, | 790 void WebRtcIsacBw_SetBandwidthInfo(BwEstimatorstr* bwest_str, |
| 791 const IsacBandwidthInfo* bwinfo) { | 791 const IsacBandwidthInfo* bwinfo) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 s2nr = a_60 + b_60 * bottle_neck * 0.001 + c_60 * bottle_neck * | 1022 s2nr = a_60 + b_60 * bottle_neck * 0.001 + c_60 * bottle_neck * |
| 1023 bottle_neck * 0.000001; | 1023 bottle_neck * 0.000001; |
| 1024 break; | 1024 break; |
| 1025 default: | 1025 default: |
| 1026 s2nr = 0; | 1026 s2nr = 0; |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 return s2nr; | 1029 return s2nr; |
| 1030 | 1030 |
| 1031 } | 1031 } |
| OLD | NEW |