OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
11 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" | 11 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <string.h> // memmove | |
15 | 14 |
16 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
17 #include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h" | 16 #include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h" |
18 #include "webrtc/modules/audio_coding/codecs/g711/include/g711_interface.h" | 17 #include "webrtc/modules/audio_coding/codecs/g711/include/g711_interface.h" |
19 #ifdef WEBRTC_CODEC_G722 | 18 #ifdef WEBRTC_CODEC_G722 |
20 #include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h" | 19 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_decoder_g722.h" |
21 #endif | 20 #endif |
22 #ifdef WEBRTC_CODEC_ILBC | 21 #ifdef WEBRTC_CODEC_ILBC |
23 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_decoder_ilbc.h
" | 22 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_decoder_ilbc.h
" |
24 #endif | 23 #endif |
25 #ifdef WEBRTC_CODEC_ISACFX | 24 #ifdef WEBRTC_CODEC_ISACFX |
26 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_is
acfix.h" | 25 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_is
acfix.h" |
27 #endif | 26 #endif |
28 #ifdef WEBRTC_CODEC_ISAC | 27 #ifdef WEBRTC_CODEC_ISAC |
29 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i
sac.h" | 28 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i
sac.h" |
30 #endif | 29 #endif |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded, | 87 int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded, |
89 size_t encoded_len) const { | 88 size_t encoded_len) const { |
90 // One encoded byte per sample per channel. | 89 // One encoded byte per sample per channel. |
91 return static_cast<int>(encoded_len / Channels()); | 90 return static_cast<int>(encoded_len / Channels()); |
92 } | 91 } |
93 | 92 |
94 size_t AudioDecoderPcmAMultiCh::Channels() const { | 93 size_t AudioDecoderPcmAMultiCh::Channels() const { |
95 return channels_; | 94 return channels_; |
96 } | 95 } |
97 | 96 |
98 // G.722 | |
99 #ifdef WEBRTC_CODEC_G722 | |
100 AudioDecoderG722::AudioDecoderG722() { | |
101 WebRtcG722_CreateDecoder(&dec_state_); | |
102 WebRtcG722_DecoderInit(dec_state_); | |
103 } | |
104 | |
105 AudioDecoderG722::~AudioDecoderG722() { | |
106 WebRtcG722_FreeDecoder(dec_state_); | |
107 } | |
108 | |
109 bool AudioDecoderG722::HasDecodePlc() const { | |
110 return false; | |
111 } | |
112 | |
113 int AudioDecoderG722::DecodeInternal(const uint8_t* encoded, | |
114 size_t encoded_len, | |
115 int sample_rate_hz, | |
116 int16_t* decoded, | |
117 SpeechType* speech_type) { | |
118 RTC_DCHECK_EQ(sample_rate_hz, 16000); | |
119 int16_t temp_type = 1; // Default is speech. | |
120 size_t ret = | |
121 WebRtcG722_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type); | |
122 *speech_type = ConvertSpeechType(temp_type); | |
123 return static_cast<int>(ret); | |
124 } | |
125 | |
126 void AudioDecoderG722::Reset() { | |
127 WebRtcG722_DecoderInit(dec_state_); | |
128 } | |
129 | |
130 int AudioDecoderG722::PacketDuration(const uint8_t* encoded, | |
131 size_t encoded_len) const { | |
132 // 1/2 encoded byte per sample per channel. | |
133 return static_cast<int>(2 * encoded_len / Channels()); | |
134 } | |
135 | |
136 size_t AudioDecoderG722::Channels() const { | |
137 return 1; | |
138 } | |
139 | |
140 AudioDecoderG722Stereo::AudioDecoderG722Stereo() { | |
141 WebRtcG722_CreateDecoder(&dec_state_left_); | |
142 WebRtcG722_CreateDecoder(&dec_state_right_); | |
143 WebRtcG722_DecoderInit(dec_state_left_); | |
144 WebRtcG722_DecoderInit(dec_state_right_); | |
145 } | |
146 | |
147 AudioDecoderG722Stereo::~AudioDecoderG722Stereo() { | |
148 WebRtcG722_FreeDecoder(dec_state_left_); | |
149 WebRtcG722_FreeDecoder(dec_state_right_); | |
150 } | |
151 | |
152 int AudioDecoderG722Stereo::DecodeInternal(const uint8_t* encoded, | |
153 size_t encoded_len, | |
154 int sample_rate_hz, | |
155 int16_t* decoded, | |
156 SpeechType* speech_type) { | |
157 RTC_DCHECK_EQ(sample_rate_hz, 16000); | |
158 int16_t temp_type = 1; // Default is speech. | |
159 // De-interleave the bit-stream into two separate payloads. | |
160 uint8_t* encoded_deinterleaved = new uint8_t[encoded_len]; | |
161 SplitStereoPacket(encoded, encoded_len, encoded_deinterleaved); | |
162 // Decode left and right. | |
163 size_t decoded_len = WebRtcG722_Decode(dec_state_left_, encoded_deinterleaved, | |
164 encoded_len / 2, decoded, &temp_type); | |
165 size_t ret = WebRtcG722_Decode( | |
166 dec_state_right_, &encoded_deinterleaved[encoded_len / 2], | |
167 encoded_len / 2, &decoded[decoded_len], &temp_type); | |
168 if (ret == decoded_len) { | |
169 ret += decoded_len; // Return total number of samples. | |
170 // Interleave output. | |
171 for (size_t k = ret / 2; k < ret; k++) { | |
172 int16_t temp = decoded[k]; | |
173 memmove(&decoded[2 * k - ret + 2], &decoded[2 * k - ret + 1], | |
174 (ret - k - 1) * sizeof(int16_t)); | |
175 decoded[2 * k - ret + 1] = temp; | |
176 } | |
177 } | |
178 *speech_type = ConvertSpeechType(temp_type); | |
179 delete [] encoded_deinterleaved; | |
180 return static_cast<int>(ret); | |
181 } | |
182 | |
183 size_t AudioDecoderG722Stereo::Channels() const { | |
184 return 2; | |
185 } | |
186 | |
187 void AudioDecoderG722Stereo::Reset() { | |
188 WebRtcG722_DecoderInit(dec_state_left_); | |
189 WebRtcG722_DecoderInit(dec_state_right_); | |
190 } | |
191 | |
192 // Split the stereo packet and place left and right channel after each other | |
193 // in the output array. | |
194 void AudioDecoderG722Stereo::SplitStereoPacket(const uint8_t* encoded, | |
195 size_t encoded_len, | |
196 uint8_t* encoded_deinterleaved) { | |
197 assert(encoded); | |
198 // Regroup the 4 bits/sample so |l1 l2| |r1 r2| |l3 l4| |r3 r4| ..., | |
199 // where "lx" is 4 bits representing left sample number x, and "rx" right | |
200 // sample. Two samples fit in one byte, represented with |...|. | |
201 for (size_t i = 0; i + 1 < encoded_len; i += 2) { | |
202 uint8_t right_byte = ((encoded[i] & 0x0F) << 4) + (encoded[i + 1] & 0x0F); | |
203 encoded_deinterleaved[i] = (encoded[i] & 0xF0) + (encoded[i + 1] >> 4); | |
204 encoded_deinterleaved[i + 1] = right_byte; | |
205 } | |
206 | |
207 // Move one byte representing right channel each loop, and place it at the | |
208 // end of the bytestream vector. After looping the data is reordered to: | |
209 // |l1 l2| |l3 l4| ... |l(N-1) lN| |r1 r2| |r3 r4| ... |r(N-1) r(N)|, | |
210 // where N is the total number of samples. | |
211 for (size_t i = 0; i < encoded_len / 2; i++) { | |
212 uint8_t right_byte = encoded_deinterleaved[i + 1]; | |
213 memmove(&encoded_deinterleaved[i + 1], &encoded_deinterleaved[i + 2], | |
214 encoded_len - i - 2); | |
215 encoded_deinterleaved[encoded_len - 1] = right_byte; | |
216 } | |
217 } | |
218 #endif | |
219 | |
220 AudioDecoderCng::AudioDecoderCng() { | 97 AudioDecoderCng::AudioDecoderCng() { |
221 RTC_CHECK_EQ(0, WebRtcCng_CreateDec(&dec_state_)); | 98 RTC_CHECK_EQ(0, WebRtcCng_CreateDec(&dec_state_)); |
222 WebRtcCng_InitDec(dec_state_); | 99 WebRtcCng_InitDec(dec_state_); |
223 } | 100 } |
224 | 101 |
225 AudioDecoderCng::~AudioDecoderCng() { | 102 AudioDecoderCng::~AudioDecoderCng() { |
226 WebRtcCng_FreeDec(dec_state_); | 103 WebRtcCng_FreeDec(dec_state_); |
227 } | 104 } |
228 | 105 |
229 void AudioDecoderCng::Reset() { | 106 void AudioDecoderCng::Reset() { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 case kDecoderRED: | 293 case kDecoderRED: |
417 case kDecoderAVT: | 294 case kDecoderAVT: |
418 case kDecoderArbitrary: | 295 case kDecoderArbitrary: |
419 default: { | 296 default: { |
420 return NULL; | 297 return NULL; |
421 } | 298 } |
422 } | 299 } |
423 } | 300 } |
424 | 301 |
425 } // namespace webrtc | 302 } // namespace webrtc |
OLD | NEW |