Line data Source code
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 0 : AudioDecoder::ParseResult::ParseResult(uint32_t timestamp,
28 : int priority,
29 0 : std::unique_ptr<EncodedAudioFrame> frame)
30 0 : : timestamp(timestamp), priority(priority), frame(std::move(frame)) {
31 0 : RTC_DCHECK_GE(priority, 0);
32 0 : }
33 :
34 : AudioDecoder::ParseResult::~ParseResult() = default;
35 :
36 : AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=(
37 : ParseResult&& b) = default;
38 :
39 0 : std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload(
40 : rtc::Buffer&& payload,
41 : uint32_t timestamp) {
42 0 : std::vector<ParseResult> results;
43 : std::unique_ptr<EncodedAudioFrame> frame(
44 0 : new LegacyEncodedAudioFrame(this, std::move(payload)));
45 0 : results.emplace_back(timestamp, 0, std::move(frame));
46 0 : return results;
47 : }
48 :
49 0 : 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 0 : TRACE_EVENT0("webrtc", "AudioDecoder::Decode");
53 0 : rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len));
54 0 : int duration = PacketDuration(encoded, encoded_len);
55 0 : if (duration >= 0 &&
56 0 : duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
57 0 : return -1;
58 : }
59 : return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
60 0 : speech_type);
61 : }
62 :
63 0 : 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 0 : TRACE_EVENT0("webrtc", "AudioDecoder::DecodeRedundant");
67 0 : rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len));
68 0 : int duration = PacketDurationRedundant(encoded, encoded_len);
69 0 : if (duration >= 0 &&
70 0 : duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
71 0 : return -1;
72 : }
73 : return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded,
74 0 : speech_type);
75 : }
76 :
77 0 : 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 0 : speech_type);
83 : }
84 :
85 0 : bool AudioDecoder::HasDecodePlc() const { return false; }
86 :
87 0 : size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) {
88 0 : return 0;
89 : }
90 :
91 0 : 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 0 : return 0;
97 : }
98 :
99 0 : int AudioDecoder::ErrorCode() { return 0; }
100 :
101 0 : int AudioDecoder::PacketDuration(const uint8_t* encoded,
102 : size_t encoded_len) const {
103 0 : return kNotImplemented;
104 : }
105 :
106 0 : int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded,
107 : size_t encoded_len) const {
108 0 : return kNotImplemented;
109 : }
110 :
111 0 : bool AudioDecoder::PacketHasFec(const uint8_t* encoded,
112 : size_t encoded_len) const {
113 0 : return false;
114 : }
115 :
116 0 : AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) {
117 0 : switch (type) {
118 : case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech.
119 : case 1:
120 0 : return kSpeech;
121 : case 2:
122 0 : return kComfortNoise;
123 : default:
124 0 : assert(false);
125 : return kSpeech;
126 : }
127 : }
128 :
129 : } // namespace webrtc
|