| 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 <memory> |
| 17 #include <vector> |
| 18 |
| 19 #include "webrtc/base/array_view.h" |
| 20 #include "webrtc/base/buffer.h" |
| 16 #include "webrtc/base/constructormagic.h" | 21 #include "webrtc/base/constructormagic.h" |
| 22 #include "webrtc/base/optional.h" |
| 17 #include "webrtc/typedefs.h" | 23 #include "webrtc/typedefs.h" |
| 18 | 24 |
| 19 namespace webrtc { | 25 namespace webrtc { |
| 20 | 26 |
| 21 // This is the interface class for decoders in NetEQ. Each codec type will have | 27 // This is the interface class for decoders in NetEQ. Each codec type will have |
| 22 // and implementation of this class. | 28 // and implementation of this class. |
| 23 class AudioDecoder { | 29 class AudioDecoder { |
| 24 public: | 30 public: |
| 25 enum SpeechType { | 31 enum SpeechType { |
| 26 kSpeech = 1, | 32 kSpeech = 1, |
| 27 kComfortNoise = 2 | 33 kComfortNoise = 2 |
| 28 }; | 34 }; |
| 29 | 35 |
| 30 // Used by PacketDuration below. Save the value -1 for errors. | 36 // Used by PacketDuration below. Save the value -1 for errors. |
| 31 enum { kNotImplemented = -2 }; | 37 enum { kNotImplemented = -2 }; |
| 32 | 38 |
| 33 AudioDecoder() = default; | 39 AudioDecoder() = default; |
| 34 virtual ~AudioDecoder() = default; | 40 virtual ~AudioDecoder() = default; |
| 35 | 41 |
| 42 class EncodedAudioFrame { |
| 43 public: |
| 44 struct DecodeResult { |
| 45 size_t num_decoded_samples; |
| 46 SpeechType speech_type; |
| 47 }; |
| 48 |
| 49 virtual ~EncodedAudioFrame() = default; |
| 50 |
| 51 // Returns the duration in samples-per-channel of this audio frame. |
| 52 // If no duration can be ascertained, returns zero. |
| 53 virtual size_t Duration() const = 0; |
| 54 |
| 55 // Decodes this frame of audio and writes the result in |decoded|. |
| 56 // |decoded| must be large enough to store as many samples as indicated by a |
| 57 // call to Duration() . On success, returns an rtc::Optional containing the |
| 58 // total number of samples across all channels, as well as whether the |
| 59 // decoder produced comfort noise or speech. On failure, returns an empty |
| 60 // rtc::Optional. Decode may be called at most once per frame object. |
| 61 virtual rtc::Optional<DecodeResult> Decode( |
| 62 rtc::ArrayView<int16_t> decoded) const = 0; |
| 63 }; |
| 64 |
| 65 struct ParseResult { |
| 66 ParseResult(); |
| 67 ParseResult(uint32_t timestamp, |
| 68 bool primary, |
| 69 std::unique_ptr<EncodedAudioFrame> frame); |
| 70 ParseResult(ParseResult&& b); |
| 71 ~ParseResult(); |
| 72 |
| 73 ParseResult& operator=(ParseResult&& b); |
| 74 |
| 75 // The timestamp of the frame is in samples per channel. |
| 76 uint32_t timestamp; |
| 77 bool primary; |
| 78 std::unique_ptr<EncodedAudioFrame> frame; |
| 79 }; |
| 80 |
| 81 // Let the decoder parse this payload and prepare zero or more decodable |
| 82 // frames. Each frame must be between 10 ms and 120 ms long. The caller must |
| 83 // ensure that the AudioDecoder object outlives any frame objects returned by |
| 84 // this call. The decoder is free to swap or move the data from the |payload| |
| 85 // buffer. |timestamp| is the input timestamp, in samples, corresponding to |
| 86 // the start of the payload. |
| 87 virtual std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload, |
| 88 uint32_t timestamp, |
| 89 bool is_primary); |
| 90 |
| 36 // Decodes |encode_len| bytes from |encoded| and writes the result in | 91 // Decodes |encode_len| bytes from |encoded| and writes the result in |
| 37 // |decoded|. The maximum bytes allowed to be written into |decoded| is | 92 // |decoded|. The maximum bytes allowed to be written into |decoded| is |
| 38 // |max_decoded_bytes|. Returns the total number of samples across all | 93 // |max_decoded_bytes|. Returns the total number of samples across all |
| 39 // channels. If the decoder produced comfort noise, |speech_type| | 94 // channels. If the decoder produced comfort noise, |speech_type| |
| 40 // is set to kComfortNoise, otherwise it is kSpeech. The desired output | 95 // 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 | 96 // sample rate is provided in |sample_rate_hz|, which must be valid for the |
| 42 // codec at hand. | 97 // codec at hand. |
| 43 int Decode(const uint8_t* encoded, | 98 int Decode(const uint8_t* encoded, |
| 44 size_t encoded_len, | 99 size_t encoded_len, |
| 45 int sample_rate_hz, | 100 int sample_rate_hz, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 int sample_rate_hz, | 170 int sample_rate_hz, |
| 116 int16_t* decoded, | 171 int16_t* decoded, |
| 117 SpeechType* speech_type); | 172 SpeechType* speech_type); |
| 118 | 173 |
| 119 private: | 174 private: |
| 120 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder); | 175 RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder); |
| 121 }; | 176 }; |
| 122 | 177 |
| 123 } // namespace webrtc | 178 } // namespace webrtc |
| 124 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_ | 179 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_INCLUDE_AUDIO_DECODER_H_ |
| OLD | NEW |