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

Unified Diff: webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c

Issue 1208923002: iSAC: Functions for importing and exporting bandwidth est. info (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: review comments Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c b/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c
index ce8ceb217a7b1c981c85abfd8210602fe0ad248c..940e8f50c76a740aada28079eeab9e42a04c09a8 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c
+++ b/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c
@@ -20,7 +20,9 @@
#include "settings.h"
#include "isac.h"
+#include <assert.h>
#include <math.h>
+#include <string.h>
/* array of quantization levels for bottle neck info; Matlab code: */
/* sprintf('%4.1ff, ', logspace(log10(5000), log10(40000), 12)) */
@@ -119,6 +121,9 @@ int32_t WebRtcIsac_InitBandwidthEstimator(
bwest_str->inWaitLatePkts = 0;
bwest_str->senderTimestamp = 0;
bwest_str->receiverTimestamp = 0;
+
+ bwest_str->external_bw_info.in_use = 0;
+
return 0;
}
@@ -154,6 +159,7 @@ int16_t WebRtcIsac_UpdateBandwidthEstimator(
int immediate_set = 0;
int num_pkts_expected;
+ assert(!bwest_str->external_bw_info.in_use);
// We have to adjust the header-rate if the first packet has a
// frame-size different than the initialized value.
@@ -508,6 +514,8 @@ int16_t WebRtcIsac_UpdateUplinkBwImpl(
int16_t index,
enum IsacSamplingRate encoderSamplingFreq)
{
+ assert(!bwest_str->external_bw_info.in_use);
+
if((index < 0) || (index > 23))
{
return -ISAC_RANGE_ERROR_BW_ESTIMATOR;
@@ -564,6 +572,8 @@ int16_t WebRtcIsac_UpdateUplinkJitter(
BwEstimatorstr* bwest_str,
int32_t index)
{
+ assert(!bwest_str->external_bw_info.in_use);
+
if((index < 0) || (index > 23))
{
return -ISAC_RANGE_ERROR_BW_ESTIMATOR;
@@ -589,7 +599,7 @@ int16_t WebRtcIsac_UpdateUplinkJitter(
// Returns the bandwidth/jitter estimation code (integer 0...23)
// to put in the sending iSAC payload
-uint16_t
+void
WebRtcIsac_GetDownlinkBwJitIndexImpl(
BwEstimatorstr* bwest_str,
int16_t* bottleneckIndex,
@@ -609,6 +619,12 @@ WebRtcIsac_GetDownlinkBwJitIndexImpl(
int16_t maxInd;
int16_t midInd;
+ if (bwest_str->external_bw_info.in_use) {
+ *bottleneckIndex = bwest_str->external_bw_info.bottleneck_idx;
+ *jitterInfo = bwest_str->external_bw_info.jitter_info;
+ return;
+ }
+
/* Get Max Delay Bit */
/* get unquantized max delay */
MaxDelay = (float)WebRtcIsac_GetDownlinkMaxDelay(bwest_str);
@@ -684,8 +700,6 @@ WebRtcIsac_GetDownlinkBwJitIndexImpl(
bwest_str->rec_bw_avg = (1 - weight) * bwest_str->rec_bw_avg + weight *
(rate + bwest_str->rec_header_rate);
-
- return 0;
}
@@ -697,6 +711,8 @@ int32_t WebRtcIsac_GetDownlinkBandwidth( const BwEstimatorstr *bwest_str)
float jitter_sign;
float bw_adjust;
+ assert(!bwest_str->external_bw_info.in_use);
+
/* create a value between -1.0 and 1.0 indicating "average sign" of jitter */
jitter_sign = bwest_str->rec_jitter_short_term /
bwest_str->rec_jitter_short_term_abs;
@@ -725,6 +741,8 @@ WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr *bwest_str)
{
int32_t rec_max_delay;
+ assert(!bwest_str->external_bw_info.in_use);
+
rec_max_delay = (int32_t)(bwest_str->rec_max_delay);
/* limit range of jitter estimate */
@@ -739,48 +757,41 @@ WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr *bwest_str)
return rec_max_delay;
}
-/* get the bottle neck rate from here to far side, as estimated by far side */
-void
-WebRtcIsac_GetUplinkBandwidth(
- const BwEstimatorstr* bwest_str,
- int32_t* bitRate)
-{
- /* limit range of bottle neck rate */
- if (bwest_str->send_bw_avg < MIN_ISAC_BW)
- {
- *bitRate = MIN_ISAC_BW;
- }
- else if (bwest_str->send_bw_avg > MAX_ISAC_BW)
- {
- *bitRate = MAX_ISAC_BW;
- }
- else
- {
- *bitRate = (int32_t)(bwest_str->send_bw_avg);
- }
- return;
+/* Clamp val to the closed interval [min,max]. */
+static int32_t clamp(int32_t val, int32_t min, int32_t max) {
+ assert(min <= max);
+ return val < min ? min : (val > max ? max : val);
}
-/* Returns the max delay value from the other side in ms */
-int32_t
-WebRtcIsac_GetUplinkMaxDelay(const BwEstimatorstr *bwest_str)
-{
- int32_t send_max_delay;
+int32_t WebRtcIsac_GetUplinkBandwidth(const BwEstimatorstr* bwest_str) {
+ return bwest_str->external_bw_info.in_use
+ ? bwest_str->external_bw_info.send_bw_avg
+ : clamp(bwest_str->send_bw_avg, MIN_ISAC_BW, MAX_ISAC_BW);
+}
- send_max_delay = (int32_t)(bwest_str->send_max_delay_avg);
+int32_t WebRtcIsac_GetUplinkMaxDelay(const BwEstimatorstr* bwest_str) {
+ return bwest_str->external_bw_info.in_use
+ ? bwest_str->external_bw_info.send_max_delay_avg
+ : clamp(bwest_str->send_max_delay_avg, MIN_ISAC_MD, MAX_ISAC_MD);
+}
- /* limit range of jitter estimate */
- if (send_max_delay < MIN_ISAC_MD)
- {
- send_max_delay = MIN_ISAC_MD;
- }
- else if (send_max_delay > MAX_ISAC_MD)
- {
- send_max_delay = MAX_ISAC_MD;
- }
- return send_max_delay;
+void WebRtcIsacBw_GetBandwidthInfo(BwEstimatorstr* bwest_str,
+ enum IsacSamplingRate decoder_sample_rate_hz,
+ IsacBandwidthInfo* bwinfo) {
+ assert(!bwest_str->external_bw_info.in_use);
+ bwinfo->in_use = 1;
+ bwinfo->send_bw_avg = WebRtcIsac_GetUplinkBandwidth(bwest_str);
+ bwinfo->send_max_delay_avg = WebRtcIsac_GetUplinkMaxDelay(bwest_str);
+ WebRtcIsac_GetDownlinkBwJitIndexImpl(bwest_str, &bwinfo->bottleneck_idx,
+ &bwinfo->jitter_info,
+ decoder_sample_rate_hz);
}
+void WebRtcIsacBw_SetBandwidthInfo(BwEstimatorstr* bwest_str,
+ const IsacBandwidthInfo* bwinfo) {
+ memcpy(&bwest_str->external_bw_info, bwinfo,
+ sizeof bwest_str->external_bw_info);
+}
/*
* update long-term average bitrate and amount of data in buffer

Powered by Google App Engine
This is Rietveld 408576698