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 |
11 #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" | 11 #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" |
12 | 12 |
| 13 #include "webrtc/modules/audio_coding/codecs/split_by_samples.h" |
13 #include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h" | 14 #include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h" |
14 | 15 |
15 namespace webrtc { | 16 namespace webrtc { |
16 | 17 |
17 void AudioDecoderPcmU::Reset() {} | 18 void AudioDecoderPcmU::Reset() {} |
18 | 19 |
| 20 std::vector<AudioDecoder::PacketSplit> AudioDecoderPcmU::SplitPacket( |
| 21 rtc::ArrayView<const uint8_t> payload) const { |
| 22 return internal::SplitBySamples(payload, 8 * num_channels_, 8); |
| 23 } |
| 24 |
19 int AudioDecoderPcmU::SampleRateHz() const { | 25 int AudioDecoderPcmU::SampleRateHz() const { |
20 return 8000; | 26 return 8000; |
21 } | 27 } |
22 | 28 |
23 size_t AudioDecoderPcmU::Channels() const { | 29 size_t AudioDecoderPcmU::Channels() const { |
24 return num_channels_; | 30 return num_channels_; |
25 } | 31 } |
26 | 32 |
27 int AudioDecoderPcmU::DecodeInternal(const uint8_t* encoded, | 33 int AudioDecoderPcmU::DecodeInternal(const uint8_t* encoded, |
28 size_t encoded_len, | 34 size_t encoded_len, |
29 int sample_rate_hz, | 35 int sample_rate_hz, |
30 int16_t* decoded, | 36 int16_t* decoded, |
31 SpeechType* speech_type) { | 37 SpeechType* speech_type) { |
32 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); | 38 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); |
33 int16_t temp_type = 1; // Default is speech. | 39 int16_t temp_type = 1; // Default is speech. |
34 size_t ret = WebRtcG711_DecodeU(encoded, encoded_len, decoded, &temp_type); | 40 size_t ret = WebRtcG711_DecodeU(encoded, encoded_len, decoded, &temp_type); |
35 *speech_type = ConvertSpeechType(temp_type); | 41 *speech_type = ConvertSpeechType(temp_type); |
36 return static_cast<int>(ret); | 42 return static_cast<int>(ret); |
37 } | 43 } |
38 | 44 |
39 int AudioDecoderPcmU::PacketDuration(const uint8_t* encoded, | 45 int AudioDecoderPcmU::PacketDuration(const uint8_t* encoded, |
40 size_t encoded_len) const { | 46 size_t encoded_len) const { |
41 // One encoded byte per sample per channel. | 47 // One encoded byte per sample per channel. |
42 return static_cast<int>(encoded_len / Channels()); | 48 return static_cast<int>(encoded_len / Channels()); |
43 } | 49 } |
44 | 50 |
45 void AudioDecoderPcmA::Reset() {} | 51 void AudioDecoderPcmA::Reset() {} |
46 | 52 |
| 53 std::vector<AudioDecoder::PacketSplit> AudioDecoderPcmA::SplitPacket( |
| 54 rtc::ArrayView<const uint8_t> payload) const { |
| 55 return internal::SplitBySamples(payload, 8 * num_channels_, 8); |
| 56 } |
| 57 |
47 int AudioDecoderPcmA::SampleRateHz() const { | 58 int AudioDecoderPcmA::SampleRateHz() const { |
48 return 8000; | 59 return 8000; |
49 } | 60 } |
50 | 61 |
51 size_t AudioDecoderPcmA::Channels() const { | 62 size_t AudioDecoderPcmA::Channels() const { |
52 return num_channels_; | 63 return num_channels_; |
53 } | 64 } |
54 | 65 |
55 int AudioDecoderPcmA::DecodeInternal(const uint8_t* encoded, | 66 int AudioDecoderPcmA::DecodeInternal(const uint8_t* encoded, |
56 size_t encoded_len, | 67 size_t encoded_len, |
57 int sample_rate_hz, | 68 int sample_rate_hz, |
58 int16_t* decoded, | 69 int16_t* decoded, |
59 SpeechType* speech_type) { | 70 SpeechType* speech_type) { |
60 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); | 71 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); |
61 int16_t temp_type = 1; // Default is speech. | 72 int16_t temp_type = 1; // Default is speech. |
62 size_t ret = WebRtcG711_DecodeA(encoded, encoded_len, decoded, &temp_type); | 73 size_t ret = WebRtcG711_DecodeA(encoded, encoded_len, decoded, &temp_type); |
63 *speech_type = ConvertSpeechType(temp_type); | 74 *speech_type = ConvertSpeechType(temp_type); |
64 return static_cast<int>(ret); | 75 return static_cast<int>(ret); |
65 } | 76 } |
66 | 77 |
67 int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded, | 78 int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded, |
68 size_t encoded_len) const { | 79 size_t encoded_len) const { |
69 // One encoded byte per sample per channel. | 80 // One encoded byte per sample per channel. |
70 return static_cast<int>(encoded_len / Channels()); | 81 return static_cast<int>(encoded_len / Channels()); |
71 } | 82 } |
72 | 83 |
73 } // namespace webrtc | 84 } // namespace webrtc |
OLD | NEW |