OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2012 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 | |
11 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" | |
12 | |
13 #include <assert.h> | |
14 #include <memory> | |
15 #include <utility> | |
16 | |
17 #include "webrtc/base/array_view.h" | |
18 #include "webrtc/base/checks.h" | |
19 #include "webrtc/base/sanitizer.h" | |
20 #include "webrtc/base/trace_event.h" | |
21 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" | |
22 | |
23 namespace webrtc { | |
24 | |
25 AudioDecoder::ParseResult::ParseResult() = default; | |
26 AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; | |
27 AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, | |
28 int priority, | |
29 std::unique_ptr<EncodedAudioFrame> frame) | |
30 : timestamp(timestamp), priority(priority), frame(std::move(frame)) { | |
31 RTC_DCHECK_GE(priority, 0); | |
32 } | |
33 | |
34 AudioDecoder::ParseResult::~ParseResult() = default; | |
35 | |
36 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( | |
37 ParseResult&& b) = default; | |
38 | |
39 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( | |
40 rtc::Buffer&& payload, | |
41 uint32_t timestamp) { | |
42 std::vector<ParseResult> results; | |
43 std::unique_ptr<EncodedAudioFrame> frame( | |
44 new LegacyEncodedAudioFrame(this, std::move(payload))); | |
45 results.emplace_back(timestamp, 0, std::move(frame)); | |
46 return results; | |
47 } | |
48 | |
49 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, | |
50 int sample_rate_hz, size_t max_decoded_bytes, | |
51 int16_t* decoded, SpeechType* speech_type) { | |
52 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); | |
53 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); | |
54 int duration = PacketDuration(encoded, encoded_len); | |
55 if (duration >= 0 && | |
56 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { | |
57 return -1; | |
58 } | |
59 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, | |
60 speech_type); | |
61 } | |
62 | |
63 int AudioDecoder::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, | |
64 int sample_rate_hz, size_t max_decoded_bytes, | |
65 int16_t* decoded, SpeechType* speech_type) { | |
66 TRACE_EVENT0("webrtc", "AudioDecoder::DecodeRedundant"); | |
67 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); | |
68 int duration = PacketDurationRedundant(encoded, encoded_len); | |
69 if (duration >= 0 && | |
70 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { | |
71 return -1; | |
72 } | |
73 return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded, | |
74 speech_type); | |
75 } | |
76 | |
77 int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded, | |
78 size_t encoded_len, | |
79 int sample_rate_hz, int16_t* decoded, | |
80 SpeechType* speech_type) { | |
81 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, | |
82 speech_type); | |
83 } | |
84 | |
85 bool AudioDecoder::HasDecodePlc() const { return false; } | |
86 | |
87 size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) { | |
88 return 0; | |
89 } | |
90 | |
91 int AudioDecoder::IncomingPacket(const uint8_t* payload, | |
92 size_t payload_len, | |
93 uint16_t rtp_sequence_number, | |
94 uint32_t rtp_timestamp, | |
95 uint32_t arrival_timestamp) { | |
96 return 0; | |
97 } | |
98 | |
99 int AudioDecoder::ErrorCode() { return 0; } | |
100 | |
101 int AudioDecoder::PacketDuration(const uint8_t* encoded, | |
102 size_t encoded_len) const { | |
103 return kNotImplemented; | |
104 } | |
105 | |
106 int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded, | |
107 size_t encoded_len) const { | |
108 return kNotImplemented; | |
109 } | |
110 | |
111 bool AudioDecoder::PacketHasFec(const uint8_t* encoded, | |
112 size_t encoded_len) const { | |
113 return false; | |
114 } | |
115 | |
116 AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) { | |
117 switch (type) { | |
118 case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech. | |
119 case 1: | |
120 return kSpeech; | |
121 case 2: | |
122 return kComfortNoise; | |
123 default: | |
124 assert(false); | |
125 return kSpeech; | |
126 } | |
127 } | |
128 | |
129 } // namespace webrtc | |
OLD | NEW |