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/audio_decoder_config.h" |
11 #include "media/base/channel_layout.h" | 11 #include "media/base/channel_layout.h" |
12 #include "media/base/decoder_buffer.h" | 12 #include "media/base/decoder_buffer.h" |
13 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
14 #include "media/base/pipeline_status.h" | 14 #include "media/base/pipeline_status.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 class AudioBuffer; | 18 class AudioBuffer; |
19 class DemuxerStream; | 19 class DemuxerStream; |
20 | 20 |
21 class MEDIA_EXPORT AudioDecoder { | 21 class MEDIA_EXPORT AudioDecoder { |
22 public: | 22 public: |
23 // Status codes for decode operations. | 23 // Status codes for decode operations. |
24 // TODO(rileya): Now that both AudioDecoder and VideoDecoder Status enums | 24 // TODO(rileya): Now that both AudioDecoder and VideoDecoder Status enums |
25 // match, break them into a decoder_status.h. | 25 // match, break them into a decoder_status.h. |
26 enum Status { | 26 enum Status { |
27 kOk, // We're all good. | 27 kOk, // We're all good. |
28 kAborted, // We aborted as a result of Stop() or Reset(). | 28 kAborted, // We aborted as a result of Stop() or Reset(). |
| 29 kNotEnoughData, // Not enough data to produce a video frame. |
29 kDecodeError, // A decoding error occurred. | 30 kDecodeError, // A decoding error occurred. |
30 kDecryptError // Decrypting error happened. | 31 kDecryptError // Decrypting error happened. |
31 }; | 32 }; |
32 | 33 |
33 // Callback to return decoded buffers. | |
34 typedef base::Callback<void(const scoped_refptr<AudioBuffer>&)> OutputCB; | |
35 | |
36 // Callback for Decode(). Called after the decoder has completed decoding | |
37 // corresponding DecoderBuffer, indicating that it's ready to accept another | |
38 // buffer to decode. | |
39 typedef base::Callback<void(Status)> DecodeCB; | |
40 | |
41 AudioDecoder(); | 34 AudioDecoder(); |
42 virtual ~AudioDecoder(); | 35 virtual ~AudioDecoder(); |
43 | 36 |
44 // Initializes an AudioDecoder with the given DemuxerStream, executing the | 37 // Initializes an AudioDecoder with the given DemuxerStream, executing the |
45 // callback upon completion. | 38 // callback upon completion. |
46 // |statistics_cb| is used to update global pipeline statistics. | 39 // statistics_cb is used to update global pipeline statistics. |
47 // |output_cb| is called for decoded audio buffers (see Decode()). | |
48 virtual void Initialize(const AudioDecoderConfig& config, | 40 virtual void Initialize(const AudioDecoderConfig& config, |
49 const PipelineStatusCB& status_cb, | 41 const PipelineStatusCB& status_cb) = 0; |
50 const OutputCB& output_cb) = 0; | |
51 | 42 |
52 // Requests samples to be decoded. Only one decode may be in flight at any | 43 // Requests samples to be decoded and returned via the provided callback. |
53 // given time. Once the buffer is decoded the decoder calls |decode_cb|. | 44 // Only one decode may be in flight at any given time. |
54 // |output_cb| specified in Initialize() is called for each decoded buffer, | |
55 // before or after |decode_cb|. | |
56 // | 45 // |
57 // Implementations guarantee that the callbacks will not be called from within | 46 // Implementations guarantee that the callback will not be called from within |
58 // this method. | 47 // this method. |
59 // | 48 // |
60 // If |buffer| is an EOS buffer then the decoder must be flushed, i.e. | 49 // Non-NULL sample buffer pointers will contain decoded audio data or may |
61 // |output_cb| must be called for each frame pending in the queue and | 50 // indicate the end of the stream. A NULL buffer pointer indicates an aborted |
62 // |decode_cb| must be called after that. | 51 // Decode(). |
| 52 typedef base::Callback<void(Status, const scoped_refptr<AudioBuffer>&)> |
| 53 DecodeCB; |
63 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 54 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
64 const DecodeCB& decode_cb) = 0; | 55 const DecodeCB& decode_cb) = 0; |
65 | 56 |
66 // Resets decoder state. All pending Decode() requests will be finished or | 57 // Some AudioDecoders will queue up multiple AudioBuffers from a single |
67 // aborted before |closure| is called. | 58 // DecoderBuffer, if we have any such queued buffers this will return the next |
| 59 // one. Otherwise we return a NULL AudioBuffer. |
| 60 virtual scoped_refptr<AudioBuffer> GetDecodeOutput(); |
| 61 |
| 62 // Resets decoder state, dropping any queued encoded data. |
68 virtual void Reset(const base::Closure& closure) = 0; | 63 virtual void Reset(const base::Closure& closure) = 0; |
69 | 64 |
70 // Stops decoder, fires any pending callbacks and sets the decoder to an | 65 // Stops decoder, fires any pending callbacks and sets the decoder to an |
71 // uninitialized state. An AudioDecoder cannot be re-initialized after it has | 66 // uninitialized state. An AudioDecoder cannot be re-initialized after it has |
72 // been stopped. DecodeCB and OutputCB may still be called for older buffers | 67 // been stopped. |
73 // if they were scheduled before this method is called. | |
74 // Note that if Initialize() is pending or has finished successfully, Stop() | 68 // Note that if Initialize() is pending or has finished successfully, Stop() |
75 // must be called before destructing the decoder. | 69 // must be called before destructing the decoder. |
76 virtual void Stop() = 0; | 70 virtual void Stop() = 0; |
77 | 71 |
78 private: | 72 private: |
79 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); | 73 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); |
80 }; | 74 }; |
81 | 75 |
82 } // namespace media | 76 } // namespace media |
83 | 77 |
84 #endif // MEDIA_BASE_AUDIO_DECODER_H_ | 78 #endif // MEDIA_BASE_AUDIO_DECODER_H_ |
OLD | NEW |