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>::SetTargetBitrate(int bits_per_second) { | |
136 CriticalSectionScoped cs_lock(lock_.get()); | |
137 if (target_bitrate_bps_ == -1) { | |
138 // Adaptive mode. Cannot change the target bitrate manually. | |
139 return target_bitrate_bps_; | |
kwiberg-webrtc
2015/06/16 19:22:54
Just "return -1" might be clearer. Also, document
| |
140 } | |
141 // Clamp to at minimum 10000 bps and maximum 32000 bps or 56000 bps for SWB. | |
142 target_bitrate_bps_ = std::min(std::max(bits_per_second, 10000), | |
143 SampleRateHz() == 16000 ? 32000 : 56000); | |
144 CriticalSectionScoped cs(state_lock_.get()); | |
145 CHECK_EQ(0, T::Control(isac_state_, target_bitrate_bps_, | |
146 Num10MsFramesInNextPacket() * 10)); | |
147 return target_bitrate_bps_; | |
148 } | |
149 | |
150 template <typename T> | |
133 AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT<T>::EncodeInternal( | 151 AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT<T>::EncodeInternal( |
134 uint32_t rtp_timestamp, | 152 uint32_t rtp_timestamp, |
135 const int16_t* audio, | 153 const int16_t* audio, |
136 size_t max_encoded_bytes, | 154 size_t max_encoded_bytes, |
137 uint8_t* encoded) { | 155 uint8_t* encoded) { |
138 CriticalSectionScoped cs_lock(lock_.get()); | 156 CriticalSectionScoped cs_lock(lock_.get()); |
139 if (!packet_in_progress_) { | 157 if (!packet_in_progress_) { |
140 // Starting a new packet; remember the timestamp for later. | 158 // Starting a new packet; remember the timestamp for later. |
141 packet_in_progress_ = true; | 159 packet_in_progress_ = true; |
142 packet_timestamp_ = rtp_timestamp; | 160 packet_timestamp_ = rtp_timestamp; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 | 240 |
223 template <typename T> | 241 template <typename T> |
224 int AudioEncoderDecoderIsacT<T>::ErrorCode() { | 242 int AudioEncoderDecoderIsacT<T>::ErrorCode() { |
225 CriticalSectionScoped cs(state_lock_.get()); | 243 CriticalSectionScoped cs(state_lock_.get()); |
226 return T::GetErrorCode(isac_state_); | 244 return T::GetErrorCode(isac_state_); |
227 } | 245 } |
228 | 246 |
229 } // namespace webrtc | 247 } // namespace webrtc |
230 | 248 |
231 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 249 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
OLD | NEW |