diff options
author | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 20:05:42 +0000 |
---|---|---|
committer | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 20:05:42 +0000 |
commit | a1608f162b6cc3927dd10f5cf20b6a2037ba0cb9 (patch) | |
tree | c6cb71c586dcecf01b81679a054c02ab7d9dd3ec /media/base/decryptor.h | |
parent | 368ae3a1e123dbf8b5658d135132a549a0180e57 (diff) | |
download | chromium_src-a1608f162b6cc3927dd10f5cf20b6a2037ba0cb9.zip chromium_src-a1608f162b6cc3927dd10f5cf20b6a2037ba0cb9.tar.gz chromium_src-a1608f162b6cc3927dd10f5cf20b6a2037ba0cb9.tar.bz2 |
Update Decryptor interface to support audio decoding.
We were discussing the use of
decryptor_->DeinitializeDecoder(Decryptor::kVideo);
- vs -
decryptor_->DeinitializeVideoDecoder();
I choose to use parameterized methods so that we have less code (duplication). The non-parameterized methods are cleaner for callers. But I feel the former is slightly better in general.
Later on we'll have two Decryptors (ProxyDecryptor will not be a Decryptor anymore):
1) AesDecryptor, which doesn't care the stream type at all, not even for CancelDecrypt().
2) PpapiDecryptor, which merely passes similar calls to the PluginInstance which then make similar PPP calls. It seems to me that for passing calls it's slightly cleaner to use parameterized methods. Also we have parameterized PPP calls already for the same reason (less functions through multiple layers).
So in both cases, using parameterized methods results in less code.
It's unfortunate that InitializeXXXDecoder and DecryptAndDecodeXXX are exceptions, due to different types they take/return.
BUG=123421
TEST=media_unittest, content_unittest
Review URL: https://chromiumcodereview.appspot.com/11144036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162768 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/decryptor.h')
-rw-r--r-- | media/base/decryptor.h | 92 |
1 files changed, 62 insertions, 30 deletions
diff --git a/media/base/decryptor.h b/media/base/decryptor.h index b422dc5..92a3a09 100644 --- a/media/base/decryptor.h +++ b/media/base/decryptor.h @@ -5,15 +5,19 @@ #ifndef MEDIA_BASE_DECRYPTOR_H_ #define MEDIA_BASE_DECRYPTOR_H_ +#include <list> #include <string> #include "base/basictypes.h" #include "base/callback.h" #include "base/memory/ref_counted.h" +#include "media/base/audio_decoder.h" #include "media/base/media_export.h" namespace media { +class AudioDecoderConfig; +class Buffer; class DecoderBuffer; class VideoDecoderConfig; class VideoFrame; @@ -46,6 +50,11 @@ class MEDIA_EXPORT Decryptor { kError // Key is available but an error occurred during decryption. }; + enum StreamType { + kAudio, + kVideo + }; + Decryptor(); virtual ~Decryptor(); @@ -89,17 +98,20 @@ class MEDIA_EXPORT Decryptor { // Decrypts the |encrypted| buffer. The decrypt status and decrypted buffer // are returned via the provided callback |decrypt_cb|. The |encrypted| buffer // must not be NULL. - // Decrypt() should not be called until any previous DecryptCB has completed. - // Thus, only one DecryptCB may be pending at a time. - virtual void Decrypt(const scoped_refptr<DecoderBuffer>& encrypted, + // Decrypt() should not be called until any previous DecryptCB of the same + // |stream_type| has completed. Thus, only one DecryptCB may be pending at + // a time for a given |stream_type|. + virtual void Decrypt(StreamType stream_type, + const scoped_refptr<DecoderBuffer>& encrypted, const DecryptCB& decrypt_cb) = 0; - // Cancels the scheduled decryption operation and fires the pending DecryptCB - // immediately with kSuccess and NULL. - // Decrypt() should not be called again before the pending DecryptCB is fired. - virtual void CancelDecrypt() = 0; + // Cancels the scheduled decryption operation for |stream_type| and fires the + // pending DecryptCB immediately with kSuccess and NULL. + // Decrypt() should not be called again before the pending DecryptCB for the + // same |stream_type| is fired. + virtual void CancelDecrypt(StreamType stream_type) = 0; - // Indicates completion of decoder initialization. + // Indicates completion of audio/video decoder initialization. // // First Parameter: Indicates initialization success. // - Set to true if initialization was successful. False if an error occurred. @@ -108,50 +120,70 @@ class MEDIA_EXPORT Decryptor { // Indicates that a key has been added to the Decryptor. typedef base::Callback<void()> KeyAddedCB; - // Initializes a video decoder with the given |config|, executing the - // |init_cb| upon completion. - // Note: DecryptAndDecodeVideo(), ResetVideoDecoder() and StopVideoDecoder() - // can only be called after InitializeVideoDecoder() succeeded. + // Initializes a decoder with the given |config|, executing the |init_cb| + // upon completion. + // |key_added_cb| should be called when a key is added to the decryptor. + virtual void InitializeAudioDecoder(scoped_ptr<AudioDecoderConfig> config, + const DecoderInitCB& init_cb, + const KeyAddedCB& key_added_cb) = 0; virtual void InitializeVideoDecoder(scoped_ptr<VideoDecoderConfig> config, const DecoderInitCB& init_cb, const KeyAddedCB& key_added_cb) = 0; - // Indicates completion of video decrypting and decoding operation. + // Helper structure for managing multiple decoded audio buffers per input. + typedef std::list<scoped_refptr<Buffer> > AudioBuffers; + + // Indicates completion of audio/video decrypt-and-decode operation. // - // First parameter: The status of the decrypting and decoding operation. + // First parameter: The status of the decrypt-and-decode operation. // - Set to kSuccess if the encrypted buffer is successfully decrypted and - // decoded. In this case, the decoded video frame can be: + // decoded. In this case, the decoded frame/buffers can be/contain: // 1) NULL, which means the operation has been aborted. // 2) End-of-stream (EOS) frame, which means that the decoder has hit EOS, // flushed all internal buffers and cannot produce more video frames. - // 3) Decrypted and decoded video frame. + // 3) Decrypted and decoded video frame or audio buffer. // - Set to kNoKey if no decryption key is available to decrypt the encrypted - // buffer. In this case the decoded video frame must be NULL. + // buffer. In this case the returned frame(s) must be NULL/empty. // - Set to kNeedMoreData if more data is needed to produce a video frame. In - // this case the decoded video frame must be NULL. + // this case the returned frame(s) must be NULL/empty. // - Set to kError if unexpected error has occurred. In this case the - // decoded video frame must be NULL. - // Second parameter: The decoded video frame. + // returned frame(s) must be NULL/empty. + // Second parameter: The decoded video frame or audio buffers. + typedef base::Callback<void(Status, const AudioBuffers&)> AudioDecodeCB; typedef base::Callback<void(Status, const scoped_refptr<VideoFrame>&)> VideoDecodeCB; // Decrypts and decodes the |encrypted| buffer. The status and the decrypted - // buffer are returned via the provided callback |video_decode_cb|. + // buffer are returned via the provided callback. // The |encrypted| buffer must not be NULL. // At end-of-stream, this method should be called repeatedly with - // end-of-stream DecoderBuffer until no video frame can be produced. + // end-of-stream DecoderBuffer until no frame/buffer can be produced. + // These methods can only be called after the corresponding decoder has + // been successfully initialized. + virtual void DecryptAndDecodeAudio( + const scoped_refptr<DecoderBuffer>& encrypted, + const AudioDecodeCB& audio_decode_cb) = 0; virtual void DecryptAndDecodeVideo( const scoped_refptr<DecoderBuffer>& encrypted, const VideoDecodeCB& video_decode_cb) = 0; - // Cancels scheduled video decrypt-and-decode operations and fires any pending - // VideoDecodeCB immediately with kError and NULL frame. - virtual void CancelDecryptAndDecodeVideo() = 0; - - // Stops decoder and sets it to an uninitialized state. - // The decoder can be reinitialized by calling InitializeVideoDecoder() after - // it is stopped. - virtual void StopVideoDecoder() = 0; + // Resets the decoder to an initialized clean state, cancels any scheduled + // decrypt-and-decode operations, and fires any pending + // AudioDecodeCB/VideoDecodeCB immediately with kError and NULL. + // This method can only be called after the corresponding decoder has been + // successfully initialized. + virtual void ResetDecoder(StreamType stream_type) = 0; + + // Releases decoder resources, deinitializes the decoder, cancels any + // scheduled initialization or decrypt-and-decode operations, and fires + // any pending DecoderInitCB/AudioDecodeCB/VideoDecodeCB immediately. + // DecoderInitCB should be fired with false. AudioDecodeCB/VideoDecodeCB + // should be fired with kError. + // This method can be called any time after Initialize{Audio|Video}Decoder() + // has been called (with the correct stream type). + // After this operation, the decoder is set to an uninitialized state. + // The decoder can be reinitialized after it is uninitialized. + virtual void DeinitializeDecoder(StreamType stream_type) = 0; private: DISALLOW_COPY_AND_ASSIGN(Decryptor); |