1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 /* 12 * bandwidth_estimator.h 13 * 14 * This header file contains the API for the Bandwidth Estimator 15 * designed for iSAC. 16 * 17 */ 18 19 #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ 20 #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ 21 22 #include <stddef.h> 23 24 #include "modules/audio_coding/codecs/isac/main/source/settings.h" 25 #include "modules/audio_coding/codecs/isac/main/source/structs.h" 26 27 #define MIN_ISAC_BW 10000 28 #define MIN_ISAC_BW_LB 10000 29 #define MIN_ISAC_BW_UB 25000 30 31 #define MAX_ISAC_BW 56000 32 #define MAX_ISAC_BW_UB 32000 33 #define MAX_ISAC_BW_LB 32000 34 35 #define MIN_ISAC_MD 5 36 #define MAX_ISAC_MD 25 37 38 // assumed header size, in bytes; we don't know the exact number 39 // (header compression may be used) 40 #define HEADER_SIZE 35 41 42 // Initial Frame-Size, in ms, for Wideband & Super-Wideband Mode 43 #define INIT_FRAME_LEN_WB 60 44 #define INIT_FRAME_LEN_SWB 30 45 46 // Initial Bottleneck Estimate, in bits/sec, for 47 // Wideband & Super-wideband mode 48 #define INIT_BN_EST_WB 20e3f 49 #define INIT_BN_EST_SWB 56e3f 50 51 // Initial Header rate (header rate depends on frame-size), 52 // in bits/sec, for Wideband & Super-Wideband mode. 53 #define INIT_HDR_RATE_WB \ 54 ((float)HEADER_SIZE * 8.0f * 1000.0f / (float)INIT_FRAME_LEN_WB) 55 #define INIT_HDR_RATE_SWB \ 56 ((float)HEADER_SIZE * 8.0f * 1000.0f / (float)INIT_FRAME_LEN_SWB) 57 58 // number of packets in a row for a high rate burst 59 #define BURST_LEN 3 60 61 // ms, max time between two full bursts 62 #define BURST_INTERVAL 500 63 64 // number of packets in a row for initial high rate burst 65 #define INIT_BURST_LEN 5 66 67 // bits/s, rate for the first BURST_LEN packets 68 #define INIT_RATE_WB INIT_BN_EST_WB 69 #define INIT_RATE_SWB INIT_BN_EST_SWB 70 71 #if defined(__cplusplus) 72 extern "C" { 73 #endif 74 75 /* This function initializes the struct */ 76 /* to be called before using the struct for anything else */ 77 /* returns 0 if everything went fine, -1 otherwise */ 78 int32_t WebRtcIsac_InitBandwidthEstimator( 79 BwEstimatorstr* bwest_str, 80 enum IsacSamplingRate encoderSampRate, 81 enum IsacSamplingRate decoderSampRate); 82 83 /* This function updates the receiving estimate */ 84 /* Parameters: */ 85 /* rtp_number - value from RTP packet, from NetEq */ 86 /* frame length - length of signal frame in ms, from iSAC decoder */ 87 /* send_ts - value in RTP header giving send time in samples */ 88 /* arr_ts - value given by timeGetTime() time of arrival in samples of 89 * packet from NetEq */ 90 /* pksize - size of packet in bytes, from NetEq */ 91 /* Index - integer (range 0...23) indicating bottle neck & jitter as 92 * estimated by other side */ 93 /* returns 0 if everything went fine, -1 otherwise */ 94 int16_t WebRtcIsac_UpdateBandwidthEstimator(BwEstimatorstr* bwest_str, 95 const uint16_t rtp_number, 96 const int32_t frame_length, 97 const uint32_t send_ts, 98 const uint32_t arr_ts, 99 const size_t pksize); 100 101 /* Update receiving estimates. Used when we only receive BWE index, no iSAC data 102 * packet. */ 103 int16_t WebRtcIsac_UpdateUplinkBwImpl( 104 BwEstimatorstr* bwest_str, 105 int16_t Index, 106 enum IsacSamplingRate encoderSamplingFreq); 107 108 /* Returns the bandwidth/jitter estimation code (integer 0...23) to put in the 109 * sending iSAC payload */ 110 void WebRtcIsac_GetDownlinkBwJitIndexImpl( 111 BwEstimatorstr* bwest_str, 112 int16_t* bottleneckIndex, 113 int16_t* jitterInfo, 114 enum IsacSamplingRate decoderSamplingFreq); 115 116 /* Returns the bandwidth estimation (in bps) */ 117 int32_t WebRtcIsac_GetDownlinkBandwidth(const BwEstimatorstr* bwest_str); 118 119 /* Returns the max delay (in ms) */ 120 int32_t WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr* bwest_str); 121 122 /* Returns the bandwidth that iSAC should send with in bps */ 123 int32_t WebRtcIsac_GetUplinkBandwidth(const BwEstimatorstr* bwest_str); 124 125 /* Returns the max delay value from the other side in ms */ 126 int32_t WebRtcIsac_GetUplinkMaxDelay(const BwEstimatorstr* bwest_str); 127 128 /* 129 * update amount of data in bottle neck buffer and burst handling 130 * returns minimum payload size (bytes) 131 */ 132 int WebRtcIsac_GetMinBytes( 133 RateModel* State, 134 int StreamSize, /* bytes in bitstream */ 135 const int FrameLen, /* ms per frame */ 136 const double BottleNeck, /* bottle neck rate; excl headers (bps) */ 137 const double DelayBuildUp, /* max delay from bottleneck buffering (ms) */ 138 enum ISACBandwidth bandwidth 139 /*,int16_t frequentLargePackets*/); 140 141 /* 142 * update long-term average bitrate and amount of data in buffer 143 */ 144 void WebRtcIsac_UpdateRateModel( 145 RateModel* State, 146 int StreamSize, /* bytes in bitstream */ 147 const int FrameSamples, /* samples per frame */ 148 const double BottleNeck); /* bottle neck rate; excl headers (bps) */ 149 150 void WebRtcIsac_InitRateModel(RateModel* State); 151 152 /* Returns the new framelength value (input argument: bottle_neck) */ 153 int WebRtcIsac_GetNewFrameLength(double bottle_neck, int current_framelength); 154 155 /* Returns the new SNR value (input argument: bottle_neck) */ 156 double WebRtcIsac_GetSnr(double bottle_neck, int new_framelength); 157 158 int16_t WebRtcIsac_UpdateUplinkJitter(BwEstimatorstr* bwest_str, int32_t index); 159 160 #if defined(__cplusplus) 161 } 162 #endif 163 164 #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ \ 165 */ 166