OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 29 matching lines...) Expand all Loading... | |
40 size_t ret = | 40 size_t ret = |
41 WebRtcG722_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type); | 41 WebRtcG722_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type); |
42 *speech_type = ConvertSpeechType(temp_type); | 42 *speech_type = ConvertSpeechType(temp_type); |
43 return static_cast<int>(ret); | 43 return static_cast<int>(ret); |
44 } | 44 } |
45 | 45 |
46 void AudioDecoderG722::Reset() { | 46 void AudioDecoderG722::Reset() { |
47 WebRtcG722_DecoderInit(dec_state_); | 47 WebRtcG722_DecoderInit(dec_state_); |
48 } | 48 } |
49 | 49 |
50 AudioDecoder::PacketSplits AudioDecoderG722::SplitPacket( | |
51 const uint8_t* payload, | |
52 size_t payload_len) const { | |
53 return SplitBySamples(payload, payload_len, 8, 16); | |
kwiberg-webrtc
2016/08/26 12:39:24
You could probably make the SplitBySamples calls e
| |
54 } | |
55 | |
50 int AudioDecoderG722::PacketDuration(const uint8_t* encoded, | 56 int AudioDecoderG722::PacketDuration(const uint8_t* encoded, |
51 size_t encoded_len) const { | 57 size_t encoded_len) const { |
52 // 1/2 encoded byte per sample per channel. | 58 // 1/2 encoded byte per sample per channel. |
53 return static_cast<int>(2 * encoded_len / Channels()); | 59 return static_cast<int>(2 * encoded_len / Channels()); |
54 } | 60 } |
55 | 61 |
56 int AudioDecoderG722::SampleRateHz() const { | 62 int AudioDecoderG722::SampleRateHz() const { |
57 return 16000; | 63 return 16000; |
58 } | 64 } |
59 | 65 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 116 |
111 size_t AudioDecoderG722Stereo::Channels() const { | 117 size_t AudioDecoderG722Stereo::Channels() const { |
112 return 2; | 118 return 2; |
113 } | 119 } |
114 | 120 |
115 void AudioDecoderG722Stereo::Reset() { | 121 void AudioDecoderG722Stereo::Reset() { |
116 WebRtcG722_DecoderInit(dec_state_left_); | 122 WebRtcG722_DecoderInit(dec_state_left_); |
117 WebRtcG722_DecoderInit(dec_state_right_); | 123 WebRtcG722_DecoderInit(dec_state_right_); |
118 } | 124 } |
119 | 125 |
126 AudioDecoder::PacketSplits AudioDecoderG722Stereo::SplitPacket( | |
127 const uint8_t* payload, | |
128 size_t payload_len) const { | |
129 // TODO(ossu): There didn't seem to be splitting in place for this before, but | |
130 // from looking at the code, it seems this should work: the two | |
131 // channels are interleaved (since they need to be explicitly | |
132 // deinterleaved before decoding) so regular splitting should be | |
133 // fine. | |
kwiberg-webrtc
2016/08/26 12:39:24
I agree. (And I don't think this comment needs to
ossu
2016/08/26 13:05:30
Cool. I've put this TODO here so that it doesn't g
| |
134 return SplitBySamples(payload, payload_len, 2 * 8, 16); | |
135 } | |
136 | |
120 // Split the stereo packet and place left and right channel after each other | 137 // Split the stereo packet and place left and right channel after each other |
121 // in the output array. | 138 // in the output array. |
122 void AudioDecoderG722Stereo::SplitStereoPacket(const uint8_t* encoded, | 139 void AudioDecoderG722Stereo::SplitStereoPacket(const uint8_t* encoded, |
123 size_t encoded_len, | 140 size_t encoded_len, |
124 uint8_t* encoded_deinterleaved) { | 141 uint8_t* encoded_deinterleaved) { |
125 // Regroup the 4 bits/sample so |l1 l2| |r1 r2| |l3 l4| |r3 r4| ..., | 142 // Regroup the 4 bits/sample so |l1 l2| |r1 r2| |l3 l4| |r3 r4| ..., |
126 // where "lx" is 4 bits representing left sample number x, and "rx" right | 143 // where "lx" is 4 bits representing left sample number x, and "rx" right |
127 // sample. Two samples fit in one byte, represented with |...|. | 144 // sample. Two samples fit in one byte, represented with |...|. |
128 for (size_t i = 0; i + 1 < encoded_len; i += 2) { | 145 for (size_t i = 0; i + 1 < encoded_len; i += 2) { |
129 uint8_t right_byte = ((encoded[i] & 0x0F) << 4) + (encoded[i + 1] & 0x0F); | 146 uint8_t right_byte = ((encoded[i] & 0x0F) << 4) + (encoded[i + 1] & 0x0F); |
130 encoded_deinterleaved[i] = (encoded[i] & 0xF0) + (encoded[i + 1] >> 4); | 147 encoded_deinterleaved[i] = (encoded[i] & 0xF0) + (encoded[i + 1] >> 4); |
131 encoded_deinterleaved[i + 1] = right_byte; | 148 encoded_deinterleaved[i + 1] = right_byte; |
132 } | 149 } |
133 | 150 |
134 // Move one byte representing right channel each loop, and place it at the | 151 // Move one byte representing right channel each loop, and place it at the |
135 // end of the bytestream vector. After looping the data is reordered to: | 152 // end of the bytestream vector. After looping the data is reordered to: |
136 // |l1 l2| |l3 l4| ... |l(N-1) lN| |r1 r2| |r3 r4| ... |r(N-1) r(N)|, | 153 // |l1 l2| |l3 l4| ... |l(N-1) lN| |r1 r2| |r3 r4| ... |r(N-1) r(N)|, |
137 // where N is the total number of samples. | 154 // where N is the total number of samples. |
138 for (size_t i = 0; i < encoded_len / 2; i++) { | 155 for (size_t i = 0; i < encoded_len / 2; i++) { |
139 uint8_t right_byte = encoded_deinterleaved[i + 1]; | 156 uint8_t right_byte = encoded_deinterleaved[i + 1]; |
140 memmove(&encoded_deinterleaved[i + 1], &encoded_deinterleaved[i + 2], | 157 memmove(&encoded_deinterleaved[i + 1], &encoded_deinterleaved[i + 2], |
141 encoded_len - i - 2); | 158 encoded_len - i - 2); |
142 encoded_deinterleaved[encoded_len - 1] = right_byte; | 159 encoded_deinterleaved[encoded_len - 1] = right_byte; |
143 } | 160 } |
144 } | 161 } |
145 | 162 |
146 } // namespace webrtc | 163 } // namespace webrtc |
OLD | NEW |