Line data Source code
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 : #include "structs.h"
12 : #include "bandwidth_estimator.h"
13 : #include "entropy_coding.h"
14 : #include "codec.h"
15 :
16 :
17 : int
18 0 : WebRtcIsac_EstimateBandwidth(
19 : BwEstimatorstr* bwest_str,
20 : Bitstr* streamdata,
21 : size_t packet_size,
22 : uint16_t rtp_seq_number,
23 : uint32_t send_ts,
24 : uint32_t arr_ts,
25 : enum IsacSamplingRate encoderSampRate,
26 : enum IsacSamplingRate decoderSampRate)
27 : {
28 : int16_t index;
29 : int16_t frame_samples;
30 : uint32_t sendTimestampIn16kHz;
31 : uint32_t arrivalTimestampIn16kHz;
32 : uint32_t diffSendTime;
33 : uint32_t diffArrivalTime;
34 : int err;
35 :
36 : /* decode framelength and BW estimation */
37 0 : err = WebRtcIsac_DecodeFrameLen(streamdata, &frame_samples);
38 0 : if(err < 0) // error check
39 : {
40 0 : return err;
41 : }
42 0 : err = WebRtcIsac_DecodeSendBW(streamdata, &index);
43 0 : if(err < 0) // error check
44 : {
45 0 : return err;
46 : }
47 :
48 : /* UPDATE ESTIMATES FROM OTHER SIDE */
49 0 : err = WebRtcIsac_UpdateUplinkBwImpl(bwest_str, index, encoderSampRate);
50 0 : if(err < 0)
51 : {
52 0 : return err;
53 : }
54 :
55 : // We like BWE to work at 16 kHz sampling rate,
56 : // therefore, we have to change the timestamps accordingly.
57 : // translate the send timestamp if required
58 0 : diffSendTime = (uint32_t)((uint32_t)send_ts -
59 0 : (uint32_t)bwest_str->senderTimestamp);
60 0 : bwest_str->senderTimestamp = send_ts;
61 :
62 0 : diffArrivalTime = (uint32_t)((uint32_t)arr_ts -
63 0 : (uint32_t)bwest_str->receiverTimestamp);
64 0 : bwest_str->receiverTimestamp = arr_ts;
65 :
66 0 : if(decoderSampRate == kIsacSuperWideband)
67 : {
68 0 : diffArrivalTime = (uint32_t)diffArrivalTime >> 1;
69 0 : diffSendTime = (uint32_t)diffSendTime >> 1;
70 : }
71 :
72 : // arrival timestamp in 16 kHz
73 0 : arrivalTimestampIn16kHz = (uint32_t)((uint32_t)
74 0 : bwest_str->prev_rec_arr_ts + (uint32_t)diffArrivalTime);
75 : // send timestamp in 16 kHz
76 0 : sendTimestampIn16kHz = (uint32_t)((uint32_t)
77 0 : bwest_str->prev_rec_send_ts + (uint32_t)diffSendTime);
78 :
79 0 : err = WebRtcIsac_UpdateBandwidthEstimator(bwest_str, rtp_seq_number,
80 0 : (frame_samples * 1000) / FS, sendTimestampIn16kHz,
81 : arrivalTimestampIn16kHz, packet_size);
82 : // error check
83 0 : if(err < 0)
84 : {
85 0 : return err;
86 : }
87 :
88 0 : return 0;
89 : }
|