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

Side by Side Diff: webrtc/modules/audio_coding/codecs/audio_decoder.h

Issue 2326953003: Added a ParsePayload method to AudioDecoder. (Closed)
Patch Set: Addressed comments 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_
13 13
14 #include <stdlib.h> // NULL 14 #include <stdlib.h> // NULL
15 15
16 #include "webrtc/base/array_view.h"
17 #include "webrtc/base/buffer.h"
16 #include "webrtc/base/constructormagic.h" 18 #include "webrtc/base/constructormagic.h"
19 #include "webrtc/base/optional.h"
17 #include "webrtc/typedefs.h" 20 #include "webrtc/typedefs.h"
18 21
19 namespace webrtc { 22 namespace webrtc {
20 23
21 // This is the interface class for decoders in NetEQ. Each codec type will have 24 // This is the interface class for decoders in NetEQ. Each codec type will have
22 // and implementation of this class. 25 // and implementation of this class.
23 class AudioDecoder { 26 class AudioDecoder {
24 public: 27 public:
25 enum SpeechType { 28 enum SpeechType {
26 kSpeech = 1, 29 kSpeech = 1,
27 kComfortNoise = 2 30 kComfortNoise = 2
28 }; 31 };
29 32
30 // Used by PacketDuration below. Save the value -1 for errors. 33 // Used by PacketDuration below. Save the value -1 for errors.
31 enum { kNotImplemented = -2 }; 34 enum { kNotImplemented = -2 };
32 35
33 AudioDecoder() = default; 36 AudioDecoder() = default;
34 virtual ~AudioDecoder() = default; 37 virtual ~AudioDecoder() = default;
35 38
39 class EncodedAudioFrame {
40 public:
41 struct DecodeResult {
42 size_t num_decoded_samples;
43 SpeechType speech_type;
44 };
45
46 virtual ~EncodedAudioFrame() = default;
47
48 // Returns the duration in samples-per-channel of this audio frame.
49 // If no duration can be ascertained, returns zero.
50 virtual size_t Duration() const = 0;
51
52 // Decodes this frame of audio and writes the result in |decoded|.
53 // Returns rtc::Optional containing the total number of samples across all
54 // channels, as well as whether the decoder produced comfort noise or
55 // speech. Decode must only be called once per frame object.
kwiberg-webrtc 2016/09/15 12:00:59 You don't say under what circumstances the return
ossu 2016/09/15 13:07:54 I'd really prefer it if this method were handed a
kwiberg-webrtc 2016/09/16 00:14:07 IOW, it's supposed to be at least as large as nece
56 virtual rtc::Optional<DecodeResult> Decode(
57 rtc::ArrayView<int16_t> decoded) const = 0;
58 };
59
60 struct ParseResult {
61 ParseResult();
62 ParseResult(uint32_t timestamp,
63 bool primary,
64 std::unique_ptr<EncodedAudioFrame> frame);
65 ParseResult(ParseResult&& b);
66 ~ParseResult();
67
68 ParseResult& operator=(ParseResult&& b);
69
70 // The timestamp of the frame is in samples per channel.
71 uint32_t timestamp;
72 bool primary;
73 std::unique_ptr<EncodedAudioFrame> frame;
74 };
75
76 // Let the decoder parse this payload and prepare zero or more decodable
77 // frames. Each frame must be at most 120 ms long. The decoder is free to swap
78 // or move the data from the |payload| buffer.
79 virtual std::vector<ParseResult> ParsePayload(rtc::Buffer* payload,
80 uint32_t timestamp,
81 bool is_primary);
kwiberg-webrtc 2016/09/15 12:00:59 Do you intend for this to be a sink for the payloa
ossu 2016/09/15 13:07:54 It's a sink. I'll clarify the AudioDecoder's lifet
kwiberg-webrtc 2016/09/16 00:14:07 Acknowledged.
82
36 // Decodes |encode_len| bytes from |encoded| and writes the result in 83 // Decodes |encode_len| bytes from |encoded| and writes the result in
37 // |decoded|. The maximum bytes allowed to be written into |decoded| is 84 // |decoded|. The maximum bytes allowed to be written into |decoded| is
38 // |max_decoded_bytes|. Returns the total number of samples across all 85 // |max_decoded_bytes|. Returns the total number of samples across all
39 // channels. If the decoder produced comfort noise, |speech_type| 86 // channels. If the decoder produced comfort noise, |speech_type|
40 // is set to kComfortNoise, otherwise it is kSpeech. The desired output 87 // is set to kComfortNoise, otherwise it is kSpeech. The desired output
41 // sample rate is provided in |sample_rate_hz|, which must be valid for the 88 // sample rate is provided in |sample_rate_hz|, which must be valid for the
42 // codec at hand. 89 // codec at hand.
43 int Decode(const uint8_t* encoded, 90 int Decode(const uint8_t* encoded,
44 size_t encoded_len, 91 size_t encoded_len,
45 int sample_rate_hz, 92 int sample_rate_hz,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 int sample_rate_hz, 162 int sample_rate_hz,
116 int16_t* decoded, 163 int16_t* decoded,
117 SpeechType* speech_type); 164 SpeechType* speech_type);
118 165
119 private: 166 private:
120 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder); 167 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder);
121 }; 168 };
122 169
123 } // namespace webrtc 170 } // namespace webrtc
124 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_ 171 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698