Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BASE_AUDIO_DECODER_H_ | 5 #ifndef MEDIA_BASE_AUDIO_DECODER_H_ |
| 6 #define MEDIA_BASE_AUDIO_DECODER_H_ | 6 #define MEDIA_BASE_AUDIO_DECODER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "media/base/audio_decoder_config.h" | |
| 10 #include "media/base/channel_layout.h" | 11 #include "media/base/channel_layout.h" |
| 12 #include "media/base/decoder_buffer.h" | |
| 13 #include "media/base/media_export.h" | |
| 11 #include "media/base/pipeline_status.h" | 14 #include "media/base/pipeline_status.h" |
| 12 #include "media/base/media_export.h" | |
| 13 | 15 |
| 14 namespace media { | 16 namespace media { |
| 15 | 17 |
| 16 class AudioBuffer; | 18 class AudioBuffer; |
| 17 class DemuxerStream; | 19 class DemuxerStream; |
| 18 | 20 |
| 19 class MEDIA_EXPORT AudioDecoder { | 21 class MEDIA_EXPORT AudioDecoder { |
| 20 public: | 22 public: |
| 21 // Status codes for read operations. | 23 // Status codes for decode operations. |
| 22 enum Status { | 24 enum Status { |
| 23 kOk, | 25 kOk, // We're all good. |
| 24 kAborted, | 26 kAborted, // We aborted as a result of Stop() or Reset(). |
| 25 kDecodeError, | 27 kNotEnoughData, // Not enough data to produce a video frame. |
| 28 kDecodeError, // A decoding error occurred. | |
| 29 kDecryptError // Decrypting error happened. | |
| 26 }; | 30 }; |
| 27 | 31 |
| 28 AudioDecoder(); | 32 AudioDecoder(); |
| 29 virtual ~AudioDecoder(); | 33 virtual ~AudioDecoder(); |
| 30 | 34 |
| 31 // Initializes an AudioDecoder with the given DemuxerStream, executing the | 35 // Initializes an AudioDecoder with the given DemuxerStream, executing the |
| 32 // callback upon completion. | 36 // callback upon completion. |
| 33 // statistics_cb is used to update global pipeline statistics. | 37 // statistics_cb is used to update global pipeline statistics. |
| 34 virtual void Initialize(DemuxerStream* stream, | 38 virtual void Initialize(const AudioDecoderConfig& config, |
| 35 const PipelineStatusCB& status_cb, | 39 const PipelineStatusCB& status_cb) = 0; |
| 36 const StatisticsCB& statistics_cb) = 0; | |
| 37 | 40 |
| 38 // Requests samples to be decoded and returned via the provided callback. | 41 // Requests samples to be decoded and returned via the provided callback. |
| 39 // Only one read may be in flight at any given time. | 42 // Only one read may be in flight at any given time. |
| 40 // | 43 // |
| 41 // Implementations guarantee that the callback will not be called from within | 44 // Implementations guarantee that the callback will not be called from within |
| 42 // this method. | 45 // this method. |
| 43 // | 46 // |
| 44 // Non-NULL sample buffer pointers will contain decoded audio data or may | 47 // Non-NULL sample buffer pointers will contain decoded audio data or may |
| 45 // indicate the end of the stream. A NULL buffer pointer indicates an aborted | 48 // indicate the end of the stream. A NULL buffer pointer indicates an aborted |
| 46 // Read(). This can happen if the DemuxerStream gets flushed and doesn't have | 49 // Read(). This can happen if the DemuxerStream gets flushed and doesn't have |
| 47 // any more data to return. | 50 // any more data to return. |
| 48 typedef base::Callback<void(Status, const scoped_refptr<AudioBuffer>&)> | 51 typedef base::Callback<void(Status, const scoped_refptr<AudioBuffer>&)> |
| 49 ReadCB; | 52 DecodeCB; |
| 50 virtual void Read(const ReadCB& read_cb) = 0; | 53 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 54 const DecodeCB& decode_cb) = 0; | |
| 51 | 55 |
| 52 // Resets decoder state, dropping any queued encoded data. | 56 // Resets decoder state, dropping any queued encoded data. |
| 53 virtual void Reset(const base::Closure& closure) = 0; | 57 virtual void Reset(const base::Closure& closure) = 0; |
| 54 | 58 |
| 55 // Stops decoder, fires any pending callbacks and sets the decoder to an | 59 // Stops decoder, fires any pending callbacks and sets the decoder to an |
| 56 // uninitialized state. An AudioDecoder cannot be re-initialized after it has | 60 // uninitialized state. An AudioDecoder cannot be re-initialized after it has |
| 57 // been stopped. | 61 // been stopped. |
| 58 // Note that if Initialize() has been called, Stop() must be called and | 62 // Note that if Initialize() has been called, Stop() must be called and |
| 59 // complete before deleting the decoder. | 63 // complete before deleting the decoder. |
| 60 virtual void Stop(const base::Closure& closure) = 0; | 64 virtual void Stop(const base::Closure& closure) = 0; |
| 61 | 65 |
| 66 // Returns true if the decoder currently has the ability to decode and return | |
| 67 // an AudioBuffer. Most implementations can allocate a new AudioBuffer and | |
| 68 // hence this will always return true. Override and return false for decoders | |
| 69 // that use a fixed set of AudioBuffers for decoding. | |
| 70 virtual bool CanReadWithoutStalling() const; | |
|
rileya (GONE FROM CHROMIUM)
2014/02/19 22:37:51
Borrowed this from VideoDecoder, this will be alwa
| |
| 71 | |
| 62 // Returns various information about the decoded audio format. | 72 // Returns various information about the decoded audio format. |
| 63 virtual int bits_per_channel() = 0; | 73 virtual int bits_per_channel() = 0; |
| 64 virtual ChannelLayout channel_layout() = 0; | 74 virtual ChannelLayout channel_layout() = 0; |
| 65 virtual int samples_per_second() = 0; | 75 virtual int samples_per_second() = 0; |
| 66 | 76 |
| 77 // Some AudioDecoders will get multiple AudioBuffers out of a single | |
| 78 // DecoderBuffer, if this returns true, then the client should call Decode() | |
| 79 // with null DecoderBuffers until this returns false. | |
| 80 virtual bool HasQueuedData() const; | |
|
rileya (GONE FROM CHROMIUM)
2014/02/19 22:37:51
This seems like a clunky way of doing this... Anot
| |
| 81 | |
| 67 private: | 82 private: |
| 68 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); | 83 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); |
| 69 }; | 84 }; |
| 70 | 85 |
| 71 } // namespace media | 86 } // namespace media |
| 72 | 87 |
| 73 #endif // MEDIA_BASE_AUDIO_DECODER_H_ | 88 #endif // MEDIA_BASE_AUDIO_DECODER_H_ |
| OLD | NEW |