blob: fd285a75b2fcae8020013283713db4927c82019b [file] [log] [blame]
kwibergcf021e52015-09-22 13:16:511/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
kjellander@webrtc.org9592d2a2015-11-18 22:07:5711#include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h"
kwibergcf021e52015-09-22 13:16:5112
ossu59a0e9e2016-09-21 08:57:3113#include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h"
kjellander@webrtc.org9592d2a2015-11-18 22:07:5714#include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h"
kwibergcf021e52015-09-22 13:16:5115
16namespace webrtc {
17
18void AudioDecoderPcmU::Reset() {}
19
ossu59a0e9e2016-09-21 08:57:3120std::vector<AudioDecoder::ParseResult> AudioDecoderPcmU::ParsePayload(
21 rtc::Buffer&& payload,
ossu15d1e472016-09-22 09:06:2822 uint32_t timestamp) {
ossu59a0e9e2016-09-21 08:57:3123 return LegacyEncodedAudioFrame::SplitBySamples(
ossu15d1e472016-09-22 09:06:2824 this, std::move(payload), timestamp, 8 * num_channels_, 8);
ossu59a0e9e2016-09-21 08:57:3125}
26
kwiberg7a441a02016-05-31 09:46:2027int AudioDecoderPcmU::SampleRateHz() const {
28 return 8000;
29}
30
kwibergcf021e52015-09-22 13:16:5131size_t AudioDecoderPcmU::Channels() const {
kwiberg2027e772015-09-22 21:06:2932 return num_channels_;
kwibergcf021e52015-09-22 13:16:5133}
34
35int AudioDecoderPcmU::DecodeInternal(const uint8_t* encoded,
36 size_t encoded_len,
37 int sample_rate_hz,
38 int16_t* decoded,
39 SpeechType* speech_type) {
kwiberg7a441a02016-05-31 09:46:2040 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz);
kwibergcf021e52015-09-22 13:16:5141 int16_t temp_type = 1; // Default is speech.
42 size_t ret = WebRtcG711_DecodeU(encoded, encoded_len, decoded, &temp_type);
43 *speech_type = ConvertSpeechType(temp_type);
44 return static_cast<int>(ret);
45}
46
47int AudioDecoderPcmU::PacketDuration(const uint8_t* encoded,
48 size_t encoded_len) const {
49 // One encoded byte per sample per channel.
50 return static_cast<int>(encoded_len / Channels());
51}
52
kwibergcf021e52015-09-22 13:16:5153void AudioDecoderPcmA::Reset() {}
54
ossu59a0e9e2016-09-21 08:57:3155std::vector<AudioDecoder::ParseResult> AudioDecoderPcmA::ParsePayload(
56 rtc::Buffer&& payload,
ossu15d1e472016-09-22 09:06:2857 uint32_t timestamp) {
ossu59a0e9e2016-09-21 08:57:3158 return LegacyEncodedAudioFrame::SplitBySamples(
ossu15d1e472016-09-22 09:06:2859 this, std::move(payload), timestamp, 8 * num_channels_, 8);
ossu59a0e9e2016-09-21 08:57:3160}
61
kwiberg7a441a02016-05-31 09:46:2062int AudioDecoderPcmA::SampleRateHz() const {
63 return 8000;
64}
65
kwibergcf021e52015-09-22 13:16:5166size_t AudioDecoderPcmA::Channels() const {
kwiberg2027e772015-09-22 21:06:2967 return num_channels_;
kwibergcf021e52015-09-22 13:16:5168}
69
70int AudioDecoderPcmA::DecodeInternal(const uint8_t* encoded,
71 size_t encoded_len,
72 int sample_rate_hz,
73 int16_t* decoded,
74 SpeechType* speech_type) {
kwiberg7a441a02016-05-31 09:46:2075 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz);
kwibergcf021e52015-09-22 13:16:5176 int16_t temp_type = 1; // Default is speech.
77 size_t ret = WebRtcG711_DecodeA(encoded, encoded_len, decoded, &temp_type);
78 *speech_type = ConvertSpeechType(temp_type);
79 return static_cast<int>(ret);
80}
81
82int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded,
83 size_t encoded_len) const {
84 // One encoded byte per sample per channel.
85 return static_cast<int>(encoded_len / Channels());
86}
87
kwibergcf021e52015-09-22 13:16:5188} // namespace webrtc