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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return false; | 63 return false; |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 template <typename T> | 67 template <typename T> |
68 AudioEncoderDecoderIsacT<T>::AudioEncoderDecoderIsacT(const Config& config) | 68 AudioEncoderDecoderIsacT<T>::AudioEncoderDecoderIsacT(const Config& config) |
69 : payload_type_(config.payload_type), | 69 : payload_type_(config.payload_type), |
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 target_bitrate_bps_(config.adaptive_mode ? -1 : (config.bit_rate == 0 |
| 75 ? kDefaultBitRate |
| 76 : config.bit_rate)) { |
74 CHECK(config.IsOk()); | 77 CHECK(config.IsOk()); |
75 CHECK_EQ(0, T::Create(&isac_state_)); | 78 CHECK_EQ(0, T::Create(&isac_state_)); |
76 CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); | 79 CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); |
77 CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); | 80 CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); |
78 const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate; | 81 const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate; |
79 if (config.adaptive_mode) { | 82 if (config.adaptive_mode) { |
80 CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, | 83 CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, config.frame_size_ms, |
81 config.frame_size_ms, config.enforce_frame_size)); | 84 config.enforce_frame_size)); |
82 | |
83 } else { | 85 } else { |
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)); |
(...skipping 30 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 return target_bitrate_bps_; |
| 137 } |
| 138 |
| 139 template <typename T> |
133 AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT<T>::EncodeInternal( | 140 AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT<T>::EncodeInternal( |
134 uint32_t rtp_timestamp, | 141 uint32_t rtp_timestamp, |
135 const int16_t* audio, | 142 const int16_t* audio, |
136 size_t max_encoded_bytes, | 143 size_t max_encoded_bytes, |
137 uint8_t* encoded) { | 144 uint8_t* encoded) { |
138 CriticalSectionScoped cs_lock(lock_.get()); | 145 CriticalSectionScoped cs_lock(lock_.get()); |
139 if (!packet_in_progress_) { | 146 if (!packet_in_progress_) { |
140 // Starting a new packet; remember the timestamp for later. | 147 // Starting a new packet; remember the timestamp for later. |
141 packet_in_progress_ = true; | 148 packet_in_progress_ = true; |
142 packet_timestamp_ = rtp_timestamp; | 149 packet_timestamp_ = rtp_timestamp; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 229 |
223 template <typename T> | 230 template <typename T> |
224 int AudioEncoderDecoderIsacT<T>::ErrorCode() { | 231 int AudioEncoderDecoderIsacT<T>::ErrorCode() { |
225 CriticalSectionScoped cs(state_lock_.get()); | 232 CriticalSectionScoped cs(state_lock_.get()); |
226 return T::GetErrorCode(isac_state_); | 233 return T::GetErrorCode(isac_state_); |
227 } | 234 } |
228 | 235 |
229 } // namespace webrtc | 236 } // namespace webrtc |
230 | 237 |
231 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 238 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
OLD | NEW |