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

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

Issue 2326953003: Added a ParsePayload method to AudioDecoder. (Closed)
Patch Set: Clarifications. Cleanups. 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 // |decoded| will be large enough for 120 ms of audio at the decoder's
54 // sample rate. On success, returns an rtc::Optional containing the total
kwiberg-webrtc 2016/09/16 00:14:07 Might it be better to simply state that |decoded|
ossu 2016/09/16 11:24:16 I've incorporated the phrasing changes suggested i
55 // number of samples across all channels, as well as whether the decoder
56 // produced comfort noise or speech. On failure, returns an empty
57 // rtc::Optional. Decode must be called at most once per frame object.
kwiberg-webrtc 2016/09/16 00:14:07 My sometimes reliable sense of English suggests s/
ossu 2016/09/16 11:24:16 I believe you're right.
58 virtual rtc::Optional<DecodeResult> Decode(
59 rtc::ArrayView<int16_t> decoded) const = 0;
60 };
61
62 struct ParseResult {
63 ParseResult();
64 ParseResult(uint32_t timestamp,
65 bool primary,
66 std::unique_ptr<EncodedAudioFrame> frame);
67 ParseResult(ParseResult&& b);
68 ~ParseResult();
69
70 ParseResult& operator=(ParseResult&& b);
71
72 // The timestamp of the frame is in samples per channel.
73 uint32_t timestamp;
74 bool primary;
75 std::unique_ptr<EncodedAudioFrame> frame;
76 };
77
78 // Let the decoder parse this payload and prepare zero or more decodable
79 // frames. Each frame must be at most 120 ms long and should never be shorter
80 // than 10 ms. The caller must ensure that the AudioDecoder object outlives
kwiberg-webrtc 2016/09/16 00:14:07 This use of "must" and "should" gives the sense th
hlundin-webrtc 2016/09/16 07:40:45 They need not be an integer multiple of 10.
kwiberg-webrtc 2016/09/16 07:51:57 Are there no restrictions whatsoever, except the u
hlundin-webrtc 2016/09/16 08:25:02 In theory, no other restrictions. In practice I ca
ossu 2016/09/16 11:24:16 Acknowledged.
81 // any frame objects returned by this call. The decoder is free to swap or
82 // move the data from the |payload| buffer. |timestamp| is the input
83 // timestamp, in samples, corresponding to the start of the payload.
84 virtual std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
85 uint32_t timestamp,
86 bool is_primary);
87
36 // Decodes |encode_len| bytes from |encoded| and writes the result in 88 // Decodes |encode_len| bytes from |encoded| and writes the result in
37 // |decoded|. The maximum bytes allowed to be written into |decoded| is 89 // |decoded|. The maximum bytes allowed to be written into |decoded| is
38 // |max_decoded_bytes|. Returns the total number of samples across all 90 // |max_decoded_bytes|. Returns the total number of samples across all
39 // channels. If the decoder produced comfort noise, |speech_type| 91 // channels. If the decoder produced comfort noise, |speech_type|
40 // is set to kComfortNoise, otherwise it is kSpeech. The desired output 92 // 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 93 // sample rate is provided in |sample_rate_hz|, which must be valid for the
42 // codec at hand. 94 // codec at hand.
43 int Decode(const uint8_t* encoded, 95 int Decode(const uint8_t* encoded,
44 size_t encoded_len, 96 size_t encoded_len,
45 int sample_rate_hz, 97 int sample_rate_hz,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 int sample_rate_hz, 167 int sample_rate_hz,
116 int16_t* decoded, 168 int16_t* decoded,
117 SpeechType* speech_type); 169 SpeechType* speech_type);
118 170
119 private: 171 private:
120 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder); 172 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder);
121 }; 173 };
122 174
123 } // namespace webrtc 175 } // namespace webrtc
124 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_ 176 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/codecs/audio_decoder.cc » ('j') | webrtc/modules/audio_coding/neteq/neteq_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698