| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "media/base/audio_decoder_config.h" | 12 #include "media/base/audio_decoder_config.h" |
| 13 #include "media/base/channel_layout.h" | 13 #include "media/base/channel_layout.h" |
| 14 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
| 15 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
| 16 #include "media/base/pipeline_status.h" | 16 #include "media/base/pipeline_status.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 | 19 |
| 20 class AudioBuffer; | 20 class AudioBuffer; |
| 21 class DemuxerStream; | 21 class DemuxerStream; |
| 22 | 22 |
| 23 class MEDIA_EXPORT AudioDecoder { | 23 class MEDIA_EXPORT AudioDecoder { |
| 24 public: | 24 public: |
| 25 // Status codes for decode operations. | 25 // Status codes for decode operations. |
| 26 // TODO(rileya): Now that both AudioDecoder and VideoDecoder Status enums | 26 // TODO(rileya): Now that both AudioDecoder and VideoDecoder Status enums |
| 27 // match, break them into a decoder_status.h. | 27 // match, break them into a decoder_status.h. |
| 28 enum Status { | 28 enum Status { |
| 29 kOk, // We're all good. | 29 kOk, // We're all good. |
| 30 kAborted, // We aborted as a result of Reset() or destruction. | 30 kAborted, // We aborted as a result of Reset() or destruction. |
| 31 kDecodeError // A decoding error occurred. | 31 kDecodeError // A decoding error occurred. |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Callback for VideoDecoder initialization. | |
| 35 typedef base::Callback<void(bool success)> InitCB; | |
| 36 | |
| 37 // Callback for AudioDecoder to return a decoded frame whenever it becomes | 34 // Callback for AudioDecoder to return a decoded frame whenever it becomes |
| 38 // available. Only non-EOS frames should be returned via this callback. | 35 // available. Only non-EOS frames should be returned via this callback. |
| 39 typedef base::Callback<void(const scoped_refptr<AudioBuffer>&)> OutputCB; | 36 typedef base::Callback<void(const scoped_refptr<AudioBuffer>&)> OutputCB; |
| 40 | 37 |
| 41 // Callback for Decode(). Called after the decoder has completed decoding | 38 // Callback for Decode(). Called after the decoder has completed decoding |
| 42 // corresponding DecoderBuffer, indicating that it's ready to accept another | 39 // corresponding DecoderBuffer, indicating that it's ready to accept another |
| 43 // buffer to decode. | 40 // buffer to decode. |
| 44 typedef base::Callback<void(Status)> DecodeCB; | 41 typedef base::Callback<void(Status)> DecodeCB; |
| 45 | 42 |
| 46 AudioDecoder(); | 43 AudioDecoder(); |
| 47 | 44 |
| 48 // Fires any pending callbacks, stops and destroys the decoder. | 45 // Fires any pending callbacks, stops and destroys the decoder. |
| 49 // Note: Since this is a destructor, |this| will be destroyed after this call. | 46 // Note: Since this is a destructor, |this| will be destroyed after this call. |
| 50 // Make sure the callbacks fired from this call doesn't post any task that | 47 // Make sure the callbacks fired from this call doesn't post any task that |
| 51 // depends on |this|. | 48 // depends on |this|. |
| 52 virtual ~AudioDecoder(); | 49 virtual ~AudioDecoder(); |
| 53 | 50 |
| 54 // Returns the name of the decoder for logging purpose. | 51 // Returns the name of the decoder for logging purpose. |
| 55 virtual std::string GetDisplayName() const = 0; | 52 virtual std::string GetDisplayName() const = 0; |
| 56 | 53 |
| 57 // Initializes an AudioDecoder with the given DemuxerStream, executing the | 54 // Initializes an AudioDecoder with the given DemuxerStream, executing the |
| 58 // callback upon completion. | 55 // callback upon completion. |
| 59 // |init_cb| is used to return initialization status. | 56 // |statistics_cb| is used to update global pipeline statistics. |
| 60 // |output_cb| is called for decoded audio buffers (see Decode()). | 57 // |output_cb| is called for decoded audio buffers (see Decode()). |
| 61 virtual void Initialize(const AudioDecoderConfig& config, | 58 virtual void Initialize(const AudioDecoderConfig& config, |
| 62 const InitCB& init_cb, | 59 const PipelineStatusCB& status_cb, |
| 63 const OutputCB& output_cb) = 0; | 60 const OutputCB& output_cb) = 0; |
| 64 | 61 |
| 65 // Requests samples to be decoded. Only one decode may be in flight at any | 62 // Requests samples to be decoded. Only one decode may be in flight at any |
| 66 // given time. Once the buffer is decoded the decoder calls |decode_cb|. | 63 // given time. Once the buffer is decoded the decoder calls |decode_cb|. |
| 67 // |output_cb| specified in Initialize() is called for each decoded buffer, | 64 // |output_cb| specified in Initialize() is called for each decoded buffer, |
| 68 // before or after |decode_cb|. | 65 // before or after |decode_cb|. |
| 69 // | 66 // |
| 70 // Implementations guarantee that the callbacks will not be called from within | 67 // Implementations guarantee that the callbacks will not be called from within |
| 71 // this method. | 68 // this method. |
| 72 // | 69 // |
| 73 // If |buffer| is an EOS buffer then the decoder must be flushed, i.e. | 70 // If |buffer| is an EOS buffer then the decoder must be flushed, i.e. |
| 74 // |output_cb| must be called for each frame pending in the queue and | 71 // |output_cb| must be called for each frame pending in the queue and |
| 75 // |decode_cb| must be called after that. | 72 // |decode_cb| must be called after that. |
| 76 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 73 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 77 const DecodeCB& decode_cb) = 0; | 74 const DecodeCB& decode_cb) = 0; |
| 78 | 75 |
| 79 // Resets decoder state. All pending Decode() requests will be finished or | 76 // Resets decoder state. All pending Decode() requests will be finished or |
| 80 // aborted before |closure| is called. | 77 // aborted before |closure| is called. |
| 81 virtual void Reset(const base::Closure& closure) = 0; | 78 virtual void Reset(const base::Closure& closure) = 0; |
| 82 | 79 |
| 83 private: | 80 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); | 81 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); |
| 85 }; | 82 }; |
| 86 | 83 |
| 87 } // namespace media | 84 } // namespace media |
| 88 | 85 |
| 89 #endif // MEDIA_BASE_AUDIO_DECODER_H_ | 86 #endif // MEDIA_BASE_AUDIO_DECODER_H_ |
| OLD | NEW |