Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: media/base/audio_decoder.h

Issue 395703002: Fold {Audio|Video}Decoder::Stop() into the dtor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor fixes Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 Reset() or destruction.
29 kDecodeError, // A decoding error occurred. 29 kDecodeError, // A decoding error occurred.
30 kDecryptError // Decrypting error happened. 30 kDecryptError // Decrypting error happened.
31 }; 31 };
32 32
33 // Callback for AudioDecoder to return a decoded frame whenever it becomes 33 // Callback for AudioDecoder to return a decoded frame whenever it becomes
34 // available. Only non-EOS frames should be returned via this callback. 34 // available. Only non-EOS frames should be returned via this callback.
35 typedef base::Callback<void(const scoped_refptr<AudioBuffer>&)> OutputCB; 35 typedef base::Callback<void(const scoped_refptr<AudioBuffer>&)> OutputCB;
36 36
37 // Callback for Decode(). Called after the decoder has completed decoding 37 // Callback for Decode(). Called after the decoder has completed decoding
38 // corresponding DecoderBuffer, indicating that it's ready to accept another 38 // corresponding DecoderBuffer, indicating that it's ready to accept another
39 // buffer to decode. 39 // buffer to decode.
40 typedef base::Callback<void(Status)> DecodeCB; 40 typedef base::Callback<void(Status)> DecodeCB;
41 41
42 AudioDecoder(); 42 AudioDecoder();
43
44 // Fires any pending callbacks, stops and destroys the decoder.
45 // Note: Since this is a destructor, |this| will be destroyed after this call.
46 // Make sure the callbacks fired from this call doesn't post any task that
47 // depends on |this|.
43 virtual ~AudioDecoder(); 48 virtual ~AudioDecoder();
44 49
45 // Initializes an AudioDecoder with the given DemuxerStream, executing the 50 // Initializes an AudioDecoder with the given DemuxerStream, executing the
46 // callback upon completion. 51 // callback upon completion.
47 // |statistics_cb| is used to update global pipeline statistics. 52 // |statistics_cb| is used to update global pipeline statistics.
48 // |output_cb| is called for decoded audio buffers (see Decode()). 53 // |output_cb| is called for decoded audio buffers (see Decode()).
49 virtual void Initialize(const AudioDecoderConfig& config, 54 virtual void Initialize(const AudioDecoderConfig& config,
50 const PipelineStatusCB& status_cb, 55 const PipelineStatusCB& status_cb,
51 const OutputCB& output_cb) = 0; 56 const OutputCB& output_cb) = 0;
52 57
53 // Requests samples to be decoded. Only one decode may be in flight at any 58 // Requests samples to be decoded. Only one decode may be in flight at any
54 // given time. Once the buffer is decoded the decoder calls |decode_cb|. 59 // given time. Once the buffer is decoded the decoder calls |decode_cb|.
55 // |output_cb| specified in Initialize() is called for each decoded buffer, 60 // |output_cb| specified in Initialize() is called for each decoded buffer,
56 // before or after |decode_cb|. 61 // before or after |decode_cb|.
57 // 62 //
58 // Implementations guarantee that the callbacks will not be called from within 63 // Implementations guarantee that the callbacks will not be called from within
59 // this method. 64 // this method.
60 // 65 //
61 // If |buffer| is an EOS buffer then the decoder must be flushed, i.e. 66 // If |buffer| is an EOS buffer then the decoder must be flushed, i.e.
62 // |output_cb| must be called for each frame pending in the queue and 67 // |output_cb| must be called for each frame pending in the queue and
63 // |decode_cb| must be called after that. 68 // |decode_cb| must be called after that.
64 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, 69 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
65 const DecodeCB& decode_cb) = 0; 70 const DecodeCB& decode_cb) = 0;
66 71
67 // Resets decoder state. All pending Decode() requests will be finished or 72 // Resets decoder state. All pending Decode() requests will be finished or
68 // aborted before |closure| is called. 73 // aborted before |closure| is called.
69 virtual void Reset(const base::Closure& closure) = 0; 74 virtual void Reset(const base::Closure& closure) = 0;
70 75
71 // Stops decoder, fires any pending callbacks and sets the decoder to an
72 // uninitialized state. An AudioDecoder cannot be re-initialized after it has
73 // been stopped. DecodeCB and OutputCB may still be called for older buffers
74 // if they were scheduled before this method is called.
75 // Note that if Initialize() is pending or has finished successfully, Stop()
76 // must be called before destructing the decoder.
77 virtual void Stop() = 0;
78
79 private: 76 private:
80 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); 77 DISALLOW_COPY_AND_ASSIGN(AudioDecoder);
81 }; 78 };
82 79
83 } // namespace media 80 } // namespace media
84 81
85 #endif // MEDIA_BASE_AUDIO_DECODER_H_ 82 #endif // MEDIA_BASE_AUDIO_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698