OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 state_lock_(CriticalSectionWrapper::CreateCriticalSection()), | 70 state_lock_(CriticalSectionWrapper::CreateCriticalSection()), |
71 decoder_sample_rate_hz_(0), | 71 decoder_sample_rate_hz_(0), |
72 lock_(CriticalSectionWrapper::CreateCriticalSection()), | 72 lock_(CriticalSectionWrapper::CreateCriticalSection()), |
73 packet_in_progress_(false) { | 73 packet_in_progress_(false) { |
74 CHECK(config.IsOk()); | 74 CHECK(config.IsOk()); |
75 CHECK_EQ(0, T::Create(&isac_state_)); | 75 CHECK_EQ(0, T::Create(&isac_state_)); |
76 CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); | 76 CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); |
77 CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); | 77 CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); |
78 const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate; | 78 const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate; |
79 if (config.adaptive_mode) { | 79 if (config.adaptive_mode) { |
| 80 target_bitrate_bps_ = -1; |
80 CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, | 81 CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, |
81 config.frame_size_ms, config.enforce_frame_size)); | 82 config.frame_size_ms, config.enforce_frame_size)); |
82 | 83 |
83 } else { | 84 } else { |
| 85 target_bitrate_bps_ = bit_rate; |
84 CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms)); | 86 CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms)); |
85 } | 87 } |
86 // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is | 88 // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is |
87 // still set to 32000 Hz, since there is no full-band mode in the decoder. | 89 // still set to 32000 Hz, since there is no full-band mode in the decoder. |
88 CHECK_EQ(0, T::SetDecSampRate(isac_state_, | 90 CHECK_EQ(0, T::SetDecSampRate(isac_state_, |
89 std::min(config.sample_rate_hz, 32000))); | 91 std::min(config.sample_rate_hz, 32000))); |
90 if (config.max_payload_size_bytes != -1) | 92 if (config.max_payload_size_bytes != -1) |
91 CHECK_EQ(0, | 93 CHECK_EQ(0, |
92 T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); | 94 T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); |
93 if (config.max_bit_rate != -1) | 95 if (config.max_bit_rate != -1) |
(...skipping 29 matching lines...) Expand all Loading... |
123 return rtc::CheckedDivExact(samples_in_next_packet, | 125 return rtc::CheckedDivExact(samples_in_next_packet, |
124 rtc::CheckedDivExact(SampleRateHz(), 100)); | 126 rtc::CheckedDivExact(SampleRateHz(), 100)); |
125 } | 127 } |
126 | 128 |
127 template <typename T> | 129 template <typename T> |
128 int AudioEncoderDecoderIsacT<T>::Max10MsFramesInAPacket() const { | 130 int AudioEncoderDecoderIsacT<T>::Max10MsFramesInAPacket() const { |
129 return 6; // iSAC puts at most 60 ms in a packet. | 131 return 6; // iSAC puts at most 60 ms in a packet. |
130 } | 132 } |
131 | 133 |
132 template <typename T> | 134 template <typename T> |
| 135 int AudioEncoderDecoderIsacT<T>::GetTargetBitrate() const { |
| 136 CriticalSectionScoped cs_lock(lock_.get()); |
| 137 return target_bitrate_bps_; |
| 138 } |
| 139 |
| 140 template <typename T> |
133 AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT<T>::EncodeInternal( | 141 AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT<T>::EncodeInternal( |
134 uint32_t rtp_timestamp, | 142 uint32_t rtp_timestamp, |
135 const int16_t* audio, | 143 const int16_t* audio, |
136 size_t max_encoded_bytes, | 144 size_t max_encoded_bytes, |
137 uint8_t* encoded) { | 145 uint8_t* encoded) { |
138 CriticalSectionScoped cs_lock(lock_.get()); | 146 CriticalSectionScoped cs_lock(lock_.get()); |
139 if (!packet_in_progress_) { | 147 if (!packet_in_progress_) { |
140 // Starting a new packet; remember the timestamp for later. | 148 // Starting a new packet; remember the timestamp for later. |
141 packet_in_progress_ = true; | 149 packet_in_progress_ = true; |
142 packet_timestamp_ = rtp_timestamp; | 150 packet_timestamp_ = rtp_timestamp; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 230 |
223 template <typename T> | 231 template <typename T> |
224 int AudioEncoderDecoderIsacT<T>::ErrorCode() { | 232 int AudioEncoderDecoderIsacT<T>::ErrorCode() { |
225 CriticalSectionScoped cs(state_lock_.get()); | 233 CriticalSectionScoped cs(state_lock_.get()); |
226 return T::GetErrorCode(isac_state_); | 234 return T::GetErrorCode(isac_state_); |
227 } | 235 } |
228 | 236 |
229 } // namespace webrtc | 237 } // namespace webrtc |
230 | 238 |
231 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 239 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
OLD | NEW |