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 WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_BANDWIDTH_ESTIMATOR_H_
20 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_BANDWIDTH_ESTIMATOR_H_
21 
22 #include "structs.h"
23 
24 
25 /****************************************************************************
26  * WebRtcIsacfix_InitBandwidthEstimator(...)
27  *
28  * This function initializes the struct for the bandwidth estimator
29  *
30  * Input/Output:
31  *      - bwest_str        : Struct containing bandwidth information.
32  *
33  * Return value            : 0
34  */
35 
36 int32_t WebRtcIsacfix_InitBandwidthEstimator(BwEstimatorstr *bwest_str);
37 
38 
39 /****************************************************************************
40  * WebRtcIsacfix_UpdateUplinkBwImpl(...)
41  *
42  * This function updates bottle neck rate received from other side in payload
43  * and calculates a new bottle neck to send to the other side.
44  *
45  * Input/Output:
46  *      - bweStr           : struct containing bandwidth information.
47  *      - rtpNumber        : value from RTP packet, from NetEq
48  *      - frameSize        : length of signal frame in ms, from iSAC decoder
49  *      - sendTime         : value in RTP header giving send time in samples
50  *      - arrivalTime      : value given by timeGetTime() time of arrival in
51  *                           samples of packet from NetEq
52  *      - pksize           : size of packet in bytes, from NetEq
53  *      - Index            : integer (range 0...23) indicating bottle neck &
54  *                           jitter as estimated by other side
55  *
56  * Return value            : 0 if everything went fine,
57  *                           -1 otherwise
58  */
59 
60 int32_t WebRtcIsacfix_UpdateUplinkBwImpl(BwEstimatorstr       *bwest_str,
61                                          const uint16_t        rtp_number,
62                                          const int16_t         frameSize,
63                                          const uint32_t        send_ts,
64                                          const uint32_t        arr_ts,
65                                          const size_t          pksize,
66                                          const uint16_t        Index);
67 
68 /* Update receiving estimates. Used when we only receive BWE index, no iSAC data packet. */
69 int16_t WebRtcIsacfix_UpdateUplinkBwRec(BwEstimatorstr *bwest_str,
70                                         const int16_t Index);
71 
72 /****************************************************************************
73  * WebRtcIsacfix_GetDownlinkBwIndexImpl(...)
74  *
75  * This function calculates and returns the bandwidth/jitter estimation code
76  * (integer 0...23) to put in the sending iSAC payload.
77  *
78  * Input:
79  *      - bweStr       : BWE struct
80  *
81  * Return:
82  *      bandwith and jitter index (0..23)
83  */
84 uint16_t WebRtcIsacfix_GetDownlinkBwIndexImpl(BwEstimatorstr *bwest_str);
85 
86 /* Returns the bandwidth estimation (in bps) */
87 uint16_t WebRtcIsacfix_GetDownlinkBandwidth(const BwEstimatorstr *bwest_str);
88 
89 /* Returns the bandwidth that iSAC should send with in bps */
90 int16_t WebRtcIsacfix_GetUplinkBandwidth(const BwEstimatorstr *bwest_str);
91 
92 /* Returns the max delay (in ms) */
93 int16_t WebRtcIsacfix_GetDownlinkMaxDelay(const BwEstimatorstr *bwest_str);
94 
95 /* Returns the max delay value from the other side in ms */
96 int16_t WebRtcIsacfix_GetUplinkMaxDelay(const BwEstimatorstr *bwest_str);
97 
98 /* Fills in an IsacExternalBandwidthInfo struct. */
99 void WebRtcIsacfixBw_GetBandwidthInfo(BwEstimatorstr* bwest_str,
100                                       IsacBandwidthInfo* bwinfo);
101 
102 /* Uses the values from an IsacExternalBandwidthInfo struct. */
103 void WebRtcIsacfixBw_SetBandwidthInfo(BwEstimatorstr* bwest_str,
104                                       const IsacBandwidthInfo* bwinfo);
105 
106 /*
107  * update amount of data in bottle neck buffer and burst handling
108  * returns minimum payload size (bytes)
109  */
110 uint16_t WebRtcIsacfix_GetMinBytes(RateModel *State,
111                                    int16_t StreamSize,     /* bytes in bitstream */
112                                    const int16_t FrameLen,    /* ms per frame */
113                                    const int16_t BottleNeck,        /* bottle neck rate; excl headers (bps) */
114                                    const int16_t DelayBuildUp);     /* max delay from bottle neck buffering (ms) */
115 
116 /*
117  * update long-term average bitrate and amount of data in buffer
118  */
119 void WebRtcIsacfix_UpdateRateModel(RateModel *State,
120                                    int16_t StreamSize,    /* bytes in bitstream */
121                                    const int16_t FrameSamples,  /* samples per frame */
122                                    const int16_t BottleNeck);       /* bottle neck rate; excl headers (bps) */
123 
124 
125 void WebRtcIsacfix_InitRateModel(RateModel *State);
126 
127 /* Returns the new framelength value (input argument: bottle_neck) */
128 int16_t WebRtcIsacfix_GetNewFrameLength(int16_t bottle_neck, int16_t current_framelength);
129 
130 /* Returns the new SNR value (input argument: bottle_neck) */
131 //returns snr in Q10
132 int16_t WebRtcIsacfix_GetSnr(int16_t bottle_neck, int16_t framesamples);
133 
134 
135 #endif /*  WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_BANDWIDTH_ESTIMATOR_H_ */
136