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

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

Issue 2281453002: Moved codec-specific audio packet splitting into decoders. (Closed)
Patch Set: 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 <vector>
15 15
16 #include "webrtc/base/constructormagic.h" 16 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/typedefs.h" 17 #include "webrtc/typedefs.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 20
21 // This is the interface class for decoders in NetEQ. Each codec type will have 21 // This is the interface class for decoders in NetEQ. Each codec type will have
22 // and implementation of this class. 22 // and implementation of this class.
23 class AudioDecoder { 23 class AudioDecoder {
24 public: 24 public:
25 enum SpeechType { 25 enum SpeechType {
26 kSpeech = 1, 26 kSpeech = 1,
27 kComfortNoise = 2 27 kComfortNoise = 2
28 }; 28 };
29 29
30 // Used by PacketDuration below. Save the value -1 for errors. 30 // Used by PacketDuration below. Save the value -1 for errors.
31 enum { kNotImplemented = -2 }; 31 enum { kNotImplemented = -2 };
32 32
33 struct PacketSplit {
34 size_t byte_offset;
35 size_t num_bytes;
36 size_t timestamp_offset;
37 };
38
39 typedef std::vector<PacketSplit> PacketSplits;
kwiberg-webrtc 2016/08/26 12:39:24 I'm not sure it's worth having a typedef for this.
40
33 AudioDecoder() = default; 41 AudioDecoder() = default;
34 virtual ~AudioDecoder() = default; 42 virtual ~AudioDecoder() = default;
35 43
36 // Decodes |encode_len| bytes from |encoded| and writes the result in 44 // Decodes |encode_len| bytes from |encoded| and writes the result in
37 // |decoded|. The maximum bytes allowed to be written into |decoded| is 45 // |decoded|. The maximum bytes allowed to be written into |decoded| is
38 // |max_decoded_bytes|. Returns the total number of samples across all 46 // |max_decoded_bytes|. Returns the total number of samples across all
39 // channels. If the decoder produced comfort noise, |speech_type| 47 // channels. If the decoder produced comfort noise, |speech_type|
40 // is set to kComfortNoise, otherwise it is kSpeech. The desired output 48 // 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 49 // sample rate is provided in |sample_rate_hz|, which must be valid for the
42 // codec at hand. 50 // codec at hand.
(...skipping 24 matching lines...) Expand all
67 // Resets the decoder state (empty buffers etc.). 75 // Resets the decoder state (empty buffers etc.).
68 virtual void Reset() = 0; 76 virtual void Reset() = 0;
69 77
70 // Notifies the decoder of an incoming packet to NetEQ. 78 // Notifies the decoder of an incoming packet to NetEQ.
71 virtual int IncomingPacket(const uint8_t* payload, 79 virtual int IncomingPacket(const uint8_t* payload,
72 size_t payload_len, 80 size_t payload_len,
73 uint16_t rtp_sequence_number, 81 uint16_t rtp_sequence_number,
74 uint32_t rtp_timestamp, 82 uint32_t rtp_timestamp,
75 uint32_t arrival_timestamp); 83 uint32_t arrival_timestamp);
76 84
85 // Calculates positions where the packet can be split, and the respective
86 // timestamps of those positions. Returns a single PacketSplit spanning the
87 // whole payload (i.e. { 0, payload_len, 0 }) if the packet should not be
88 // split. This is the default behavior. If the packet is invalid, it is
89 // possible to return an empty PacketSplits vector.
kwiberg-webrtc 2016/08/26 12:39:24 Should we note that this (and the other static fun
90 virtual PacketSplits SplitPacket(const uint8_t* payload,
91 size_t payload_len) const;
kwiberg-webrtc 2016/08/26 12:39:24 Consider using a single rtc::ArrayView<const uint8
ossu 2016/08/26 13:05:29 I've used this since it's how the rest of the API
kwiberg-webrtc 2016/08/26 22:05:13 That's unavoidable if you want a gradual shift fro
92
77 // Returns the last error code from the decoder. 93 // Returns the last error code from the decoder.
78 virtual int ErrorCode(); 94 virtual int ErrorCode();
79 95
80 // Returns the duration in samples-per-channel of the payload in |encoded| 96 // Returns the duration in samples-per-channel of the payload in |encoded|
81 // which is |encoded_len| bytes long. Returns kNotImplemented if no duration 97 // which is |encoded_len| bytes long. Returns kNotImplemented if no duration
82 // estimate is available, or -1 in case of an error. 98 // estimate is available, or -1 in case of an error.
83 virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len) const; 99 virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len) const;
84 100
85 // Returns the duration in samples-per-channel of the redandant payload in 101 // Returns the duration in samples-per-channel of the redandant payload in
86 // |encoded| which is |encoded_len| bytes long. Returns kNotImplemented if no 102 // |encoded| which is |encoded_len| bytes long. Returns kNotImplemented if no
(...skipping 22 matching lines...) Expand all
109 int sample_rate_hz, 125 int sample_rate_hz,
110 int16_t* decoded, 126 int16_t* decoded,
111 SpeechType* speech_type) = 0; 127 SpeechType* speech_type) = 0;
112 128
113 virtual int DecodeRedundantInternal(const uint8_t* encoded, 129 virtual int DecodeRedundantInternal(const uint8_t* encoded,
114 size_t encoded_len, 130 size_t encoded_len,
115 int sample_rate_hz, 131 int sample_rate_hz,
116 int16_t* decoded, 132 int16_t* decoded,
117 SpeechType* speech_type); 133 SpeechType* speech_type);
118 134
135 // Splits a payload consisting of inidividual samples into reasonable chunks.
136 // Utility function for use by sample-based codecs to implement SplitPacket.
kwiberg-webrtc 2016/08/26 12:39:24 Hmm. If things are expected to change further, may
ossu 2016/08/26 13:05:29 Yeah, I don't love it here... It could be useful t
137 static PacketSplits SplitBySamples(const uint8_t* payload,
138 size_t payload_len,
139 size_t bytes_per_ms,
140 uint32_t timestamps_per_ms);
kwiberg-webrtc 2016/08/26 12:39:24 Consider replacing the first two arguments with an
119 private: 141 private:
120 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder); 142 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder);
121 }; 143 };
122 144
123 } // namespace webrtc 145 } // namespace webrtc
124 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_ 146 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698