| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 *speech_type = ConvertSpeechType(temp_type); | 43 *speech_type = ConvertSpeechType(temp_type); |
| 44 return static_cast<int>(ret); | 44 return static_cast<int>(ret); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void AudioDecoderG722::Reset() { | 47 void AudioDecoderG722::Reset() { |
| 48 WebRtcG722_DecoderInit(dec_state_); | 48 WebRtcG722_DecoderInit(dec_state_); |
| 49 } | 49 } |
| 50 | 50 |
| 51 std::vector<AudioDecoder::ParseResult> AudioDecoderG722::ParsePayload( | 51 std::vector<AudioDecoder::ParseResult> AudioDecoderG722::ParsePayload( |
| 52 rtc::Buffer&& payload, | 52 rtc::Buffer&& payload, |
| 53 uint32_t timestamp, | 53 uint32_t timestamp) { |
| 54 bool is_primary) { | |
| 55 return LegacyEncodedAudioFrame::SplitBySamples(this, std::move(payload), | 54 return LegacyEncodedAudioFrame::SplitBySamples(this, std::move(payload), |
| 56 timestamp, is_primary, 8, 16); | 55 timestamp, 8, 16); |
| 57 } | 56 } |
| 58 | 57 |
| 59 int AudioDecoderG722::PacketDuration(const uint8_t* encoded, | 58 int AudioDecoderG722::PacketDuration(const uint8_t* encoded, |
| 60 size_t encoded_len) const { | 59 size_t encoded_len) const { |
| 61 // 1/2 encoded byte per sample per channel. | 60 // 1/2 encoded byte per sample per channel. |
| 62 return static_cast<int>(2 * encoded_len / Channels()); | 61 return static_cast<int>(2 * encoded_len / Channels()); |
| 63 } | 62 } |
| 64 | 63 |
| 65 int AudioDecoderG722::SampleRateHz() const { | 64 int AudioDecoderG722::SampleRateHz() const { |
| 66 return 16000; | 65 return 16000; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 return 2; | 120 return 2; |
| 122 } | 121 } |
| 123 | 122 |
| 124 void AudioDecoderG722Stereo::Reset() { | 123 void AudioDecoderG722Stereo::Reset() { |
| 125 WebRtcG722_DecoderInit(dec_state_left_); | 124 WebRtcG722_DecoderInit(dec_state_left_); |
| 126 WebRtcG722_DecoderInit(dec_state_right_); | 125 WebRtcG722_DecoderInit(dec_state_right_); |
| 127 } | 126 } |
| 128 | 127 |
| 129 std::vector<AudioDecoder::ParseResult> AudioDecoderG722Stereo::ParsePayload( | 128 std::vector<AudioDecoder::ParseResult> AudioDecoderG722Stereo::ParsePayload( |
| 130 rtc::Buffer&& payload, | 129 rtc::Buffer&& payload, |
| 131 uint32_t timestamp, | 130 uint32_t timestamp) { |
| 132 bool is_primary) { | 131 return LegacyEncodedAudioFrame::SplitBySamples(this, std::move(payload), |
| 133 return LegacyEncodedAudioFrame::SplitBySamples( | 132 timestamp, 2 * 8, 16); |
| 134 this, std::move(payload), timestamp, is_primary, 2 * 8, 16); | |
| 135 } | 133 } |
| 136 | 134 |
| 137 // Split the stereo packet and place left and right channel after each other | 135 // Split the stereo packet and place left and right channel after each other |
| 138 // in the output array. | 136 // in the output array. |
| 139 void AudioDecoderG722Stereo::SplitStereoPacket(const uint8_t* encoded, | 137 void AudioDecoderG722Stereo::SplitStereoPacket(const uint8_t* encoded, |
| 140 size_t encoded_len, | 138 size_t encoded_len, |
| 141 uint8_t* encoded_deinterleaved) { | 139 uint8_t* encoded_deinterleaved) { |
| 142 // Regroup the 4 bits/sample so |l1 l2| |r1 r2| |l3 l4| |r3 r4| ..., | 140 // Regroup the 4 bits/sample so |l1 l2| |r1 r2| |l3 l4| |r3 r4| ..., |
| 143 // where "lx" is 4 bits representing left sample number x, and "rx" right | 141 // where "lx" is 4 bits representing left sample number x, and "rx" right |
| 144 // sample. Two samples fit in one byte, represented with |...|. | 142 // sample. Two samples fit in one byte, represented with |...|. |
| 145 for (size_t i = 0; i + 1 < encoded_len; i += 2) { | 143 for (size_t i = 0; i + 1 < encoded_len; i += 2) { |
| 146 uint8_t right_byte = ((encoded[i] & 0x0F) << 4) + (encoded[i + 1] & 0x0F); | 144 uint8_t right_byte = ((encoded[i] & 0x0F) << 4) + (encoded[i + 1] & 0x0F); |
| 147 encoded_deinterleaved[i] = (encoded[i] & 0xF0) + (encoded[i + 1] >> 4); | 145 encoded_deinterleaved[i] = (encoded[i] & 0xF0) + (encoded[i + 1] >> 4); |
| 148 encoded_deinterleaved[i + 1] = right_byte; | 146 encoded_deinterleaved[i + 1] = right_byte; |
| 149 } | 147 } |
| 150 | 148 |
| 151 // Move one byte representing right channel each loop, and place it at the | 149 // Move one byte representing right channel each loop, and place it at the |
| 152 // end of the bytestream vector. After looping the data is reordered to: | 150 // end of the bytestream vector. After looping the data is reordered to: |
| 153 // |l1 l2| |l3 l4| ... |l(N-1) lN| |r1 r2| |r3 r4| ... |r(N-1) r(N)|, | 151 // |l1 l2| |l3 l4| ... |l(N-1) lN| |r1 r2| |r3 r4| ... |r(N-1) r(N)|, |
| 154 // where N is the total number of samples. | 152 // where N is the total number of samples. |
| 155 for (size_t i = 0; i < encoded_len / 2; i++) { | 153 for (size_t i = 0; i < encoded_len / 2; i++) { |
| 156 uint8_t right_byte = encoded_deinterleaved[i + 1]; | 154 uint8_t right_byte = encoded_deinterleaved[i + 1]; |
| 157 memmove(&encoded_deinterleaved[i + 1], &encoded_deinterleaved[i + 2], | 155 memmove(&encoded_deinterleaved[i + 1], &encoded_deinterleaved[i + 2], |
| 158 encoded_len - i - 2); | 156 encoded_len - i - 2); |
| 159 encoded_deinterleaved[encoded_len - 1] = right_byte; | 157 encoded_deinterleaved[encoded_len - 1] = right_byte; |
| 160 } | 158 } |
| 161 } | 159 } |
| 162 | 160 |
| 163 } // namespace webrtc | 161 } // namespace webrtc |
| OLD | NEW |