OLD | NEW |
---|---|
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 Frame { | |
hlundin-webrtc
2016/09/09 12:11:50
Frame is too general, and already claimed for too
ossu
2016/09/12 10:31:37
I agree - EncodedFrame is better. EncodedAudioFram
ossu
2016/09/13 13:37:46
I've gone with EncodedAudioFrame. It makes more se
| |
40 public: | |
41 struct DecodeResult { | |
42 size_t num_decoded_samples; | |
43 SpeechType speech_type; | |
44 }; | |
45 | |
46 virtual ~Frame() = 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|. | |
hlundin-webrtc
2016/09/09 12:11:49
What can be expected of the state of the Frame aft
ossu
2016/09/12 10:31:36
I'm not sure. Practically, it currently acts as if
ossu
2016/09/13 13:37:46
I've clarified that Decode should only be called o
hlundin-webrtc
2016/09/15 08:12:16
Acknowledged.
| |
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. | |
56 virtual rtc::Optional<DecodeResult> Decode( | |
hlundin-webrtc
2016/09/09 12:11:50
How will error codes from the decoder be handled?
ossu
2016/09/12 10:31:36
No idea! You tell me! :) Are these the error codes
ossu
2016/09/12 12:37:35
From what I can see, the decoder error code is fre
hlundin-webrtc
2016/09/15 08:12:16
Right. Since no production code seems to care abou
| |
57 rtc::ArrayView<int16_t> decoded) const = 0; | |
58 }; | |
59 | |
60 struct ParseResult { | |
61 ParseResult(); | |
62 ParseResult(uint32_t timestamp, bool primary, std::unique_ptr<Frame> frame); | |
63 ParseResult(ParseResult&& b); | |
64 ~ParseResult(); | |
65 | |
66 ParseResult& operator=(ParseResult&& b); | |
67 | |
68 uint32_t timestamp; | |
hlundin-webrtc
2016/09/09 12:11:50
rtp_timestamp? Or timestamp_in_samples? G.722...
ossu
2016/09/12 10:31:36
I think it should be in samples, however I'm reall
ossu
2016/09/13 13:37:46
I've looked through the calling code and the times
hlundin-webrtc
2016/09/15 08:12:16
Acknowledged.
| |
69 bool primary; | |
70 std::unique_ptr<Frame> frame; | |
71 }; | |
kwiberg-webrtc
2016/09/10 07:34:59
Why do you need ParseResult and Frame to be two di
ossu
2016/09/12 10:31:36
Also, the stuff in ParseResult is used to create n
| |
72 | |
73 // Let the decoder parse this payload and prepare zero or more decodable | |
74 // frames. The decoder is free to steal the contents of the payload and retain | |
75 // them for as long as necessary. | |
76 virtual std::vector<ParseResult> ParsePayload(rtc::Buffer* payload, | |
77 uint32_t timestamp, | |
78 bool is_primary); | |
kwiberg-webrtc
2016/09/10 07:34:59
"and retain them for as long as necessary" is redu
ossu
2016/09/12 10:31:37
Yeah, I'll change it to something more specific.
ossu
2016/09/13 13:37:46
Also tried to address the contract of EncodedAudio
hlundin-webrtc
2016/09/15 08:12:16
kMaxFrameSize in neteq_impl.h defines that 120 ms
| |
79 | |
36 // Decodes |encode_len| bytes from |encoded| and writes the result in | 80 // Decodes |encode_len| bytes from |encoded| and writes the result in |
37 // |decoded|. The maximum bytes allowed to be written into |decoded| is | 81 // |decoded|. The maximum bytes allowed to be written into |decoded| is |
38 // |max_decoded_bytes|. Returns the total number of samples across all | 82 // |max_decoded_bytes|. Returns the total number of samples across all |
39 // channels. If the decoder produced comfort noise, |speech_type| | 83 // channels. If the decoder produced comfort noise, |speech_type| |
40 // is set to kComfortNoise, otherwise it is kSpeech. The desired output | 84 // 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 | 85 // sample rate is provided in |sample_rate_hz|, which must be valid for the |
42 // codec at hand. | 86 // codec at hand. |
43 int Decode(const uint8_t* encoded, | 87 int Decode(const uint8_t* encoded, |
44 size_t encoded_len, | 88 size_t encoded_len, |
45 int sample_rate_hz, | 89 int sample_rate_hz, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 int sample_rate_hz, | 159 int sample_rate_hz, |
116 int16_t* decoded, | 160 int16_t* decoded, |
117 SpeechType* speech_type); | 161 SpeechType* speech_type); |
118 | 162 |
119 private: | 163 private: |
120 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder); | 164 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder); |
121 }; | 165 }; |
122 | 166 |
123 } // namespace webrtc | 167 } // namespace webrtc |
124 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_ | 168 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_ |
OLD | NEW |