OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROMECAST_MEDIA_CMA_DECODER_CAST_AUDIO_DECODER_H_ |
| 6 #define CHROMECAST_MEDIA_CMA_DECODER_CAST_AUDIO_DECODER_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 |
| 12 namespace base { |
| 13 class SingleThreadTaskRunner; |
| 14 } // namespace base |
| 15 |
| 16 namespace chromecast { |
| 17 namespace media { |
| 18 struct AudioConfig; |
| 19 class DecoderBufferBase; |
| 20 |
| 21 // Audio decoder interface. |
| 22 class CastAudioDecoder { |
| 23 public: |
| 24 enum Status { |
| 25 kDecodeOk, |
| 26 kDecodeError, |
| 27 }; |
| 28 |
| 29 enum OutputFormat { |
| 30 kOutputSigned16, // Output signed 16-bit interleaved samples. |
| 31 kOutputPlanarFloat, // Output planar float samples. |
| 32 }; |
| 33 |
| 34 // The callback that is called when the decoder initialization is complete. |
| 35 // |success| is true if initialization was successful; if |success| is false |
| 36 // then the CastAudioDecoder instance is unusable and should be destroyed. |
| 37 typedef base::Callback<void(bool success)> InitializedCallback; |
| 38 typedef base::Callback<void( |
| 39 Status status, |
| 40 const scoped_refptr<media::DecoderBufferBase>& decoded)> DecodeCallback; |
| 41 |
| 42 // Creates a CastAudioDecoder instance for the given |config|. Decoding must |
| 43 // occur on the same thread as |task_runner|. Returns an empty scoped_ptr if |
| 44 // the decoder could not be created. |
| 45 static scoped_ptr<CastAudioDecoder> Create( |
| 46 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 47 const media::AudioConfig& config, |
| 48 OutputFormat output_format, |
| 49 const InitializedCallback& initialized_callback); |
| 50 |
| 51 // Given a CastAudioDecoder::OutputFormat, return the size of each sample in |
| 52 // that OutputFormat in bytes. |
| 53 static int OutputFormatSizeInBytes(CastAudioDecoder::OutputFormat format); |
| 54 |
| 55 CastAudioDecoder() {} |
| 56 virtual ~CastAudioDecoder() {} |
| 57 |
| 58 // Converts encoded data to the |output_format|. Must be called on the same |
| 59 // thread as |task_runner|. Decoded data will be passed to |decode_callback|. |
| 60 // It is OK to call Decode before the |initialized_callback| has been called; |
| 61 // those buffers will be queued until initialization completes, at which point |
| 62 // they will be decoded in order (if initialization was successful), or |
| 63 // ignored if initialization failed. |
| 64 // It is OK to pass an end-of-stream DecoderBuffer as |data|. |
| 65 // Returns |false| if the decoder is not ready yet. |
| 66 virtual bool Decode(const scoped_refptr<media::DecoderBufferBase>& data, |
| 67 const DecodeCallback& decode_callback) = 0; |
| 68 |
| 69 private: |
| 70 DISALLOW_COPY_AND_ASSIGN(CastAudioDecoder); |
| 71 }; |
| 72 |
| 73 } // namespace media |
| 74 } // namespace chromecast |
| 75 |
| 76 #endif // CHROMECAST_MEDIA_CMA_DECODER_CAST_AUDIO_DECODER_H_ |
OLD | NEW |