Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.cc

Issue 2326003002: Moved codec-specific audio packet splitting into decoders. (Closed)
Patch Set: Fixed types in packet splitting (size_t vs. uint32_t) Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/legacy_encoded_audio_frame.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::ParseResult> AudioDecoderPcmU::ParsePayload(
21 rtc::Buffer&& payload,
22 uint32_t timestamp,
23 bool is_primary) {
24 return LegacyEncodedAudioFrame::SplitBySamples(
25 this, std::move(payload), timestamp, is_primary, 8 * num_channels_, 8);
26 }
27
19 int AudioDecoderPcmU::SampleRateHz() const { 28 int AudioDecoderPcmU::SampleRateHz() const {
20 return 8000; 29 return 8000;
21 } 30 }
22 31
23 size_t AudioDecoderPcmU::Channels() const { 32 size_t AudioDecoderPcmU::Channels() const {
24 return num_channels_; 33 return num_channels_;
25 } 34 }
26 35
27 int AudioDecoderPcmU::DecodeInternal(const uint8_t* encoded, 36 int AudioDecoderPcmU::DecodeInternal(const uint8_t* encoded,
28 size_t encoded_len, 37 size_t encoded_len,
29 int sample_rate_hz, 38 int sample_rate_hz,
30 int16_t* decoded, 39 int16_t* decoded,
31 SpeechType* speech_type) { 40 SpeechType* speech_type) {
32 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); 41 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz);
33 int16_t temp_type = 1; // Default is speech. 42 int16_t temp_type = 1; // Default is speech.
34 size_t ret = WebRtcG711_DecodeU(encoded, encoded_len, decoded, &temp_type); 43 size_t ret = WebRtcG711_DecodeU(encoded, encoded_len, decoded, &temp_type);
35 *speech_type = ConvertSpeechType(temp_type); 44 *speech_type = ConvertSpeechType(temp_type);
36 return static_cast<int>(ret); 45 return static_cast<int>(ret);
37 } 46 }
38 47
39 int AudioDecoderPcmU::PacketDuration(const uint8_t* encoded, 48 int AudioDecoderPcmU::PacketDuration(const uint8_t* encoded,
40 size_t encoded_len) const { 49 size_t encoded_len) const {
41 // One encoded byte per sample per channel. 50 // One encoded byte per sample per channel.
42 return static_cast<int>(encoded_len / Channels()); 51 return static_cast<int>(encoded_len / Channels());
43 } 52 }
44 53
45 void AudioDecoderPcmA::Reset() {} 54 void AudioDecoderPcmA::Reset() {}
46 55
56 std::vector<AudioDecoder::ParseResult> AudioDecoderPcmA::ParsePayload(
57 rtc::Buffer&& payload,
58 uint32_t timestamp,
59 bool is_primary) {
60 return LegacyEncodedAudioFrame::SplitBySamples(
61 this, std::move(payload), timestamp, is_primary, 8 * num_channels_, 8);
62 }
63
47 int AudioDecoderPcmA::SampleRateHz() const { 64 int AudioDecoderPcmA::SampleRateHz() const {
48 return 8000; 65 return 8000;
49 } 66 }
50 67
51 size_t AudioDecoderPcmA::Channels() const { 68 size_t AudioDecoderPcmA::Channels() const {
52 return num_channels_; 69 return num_channels_;
53 } 70 }
54 71
55 int AudioDecoderPcmA::DecodeInternal(const uint8_t* encoded, 72 int AudioDecoderPcmA::DecodeInternal(const uint8_t* encoded,
56 size_t encoded_len, 73 size_t encoded_len,
57 int sample_rate_hz, 74 int sample_rate_hz,
58 int16_t* decoded, 75 int16_t* decoded,
59 SpeechType* speech_type) { 76 SpeechType* speech_type) {
60 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); 77 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz);
61 int16_t temp_type = 1; // Default is speech. 78 int16_t temp_type = 1; // Default is speech.
62 size_t ret = WebRtcG711_DecodeA(encoded, encoded_len, decoded, &temp_type); 79 size_t ret = WebRtcG711_DecodeA(encoded, encoded_len, decoded, &temp_type);
63 *speech_type = ConvertSpeechType(temp_type); 80 *speech_type = ConvertSpeechType(temp_type);
64 return static_cast<int>(ret); 81 return static_cast<int>(ret);
65 } 82 }
66 83
67 int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded, 84 int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded,
68 size_t encoded_len) const { 85 size_t encoded_len) const {
69 // One encoded byte per sample per channel. 86 // One encoded byte per sample per channel.
70 return static_cast<int>(encoded_len / Channels()); 87 return static_cast<int>(encoded_len / Channels());
71 } 88 }
72 89
73 } // namespace webrtc 90 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h ('k') | webrtc/modules/audio_coding/codecs/g711/g711.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698