summaryrefslogtreecommitdiffstats
path: root/media/base/decryptor.h
diff options
context:
space:
mode:
authorxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-04 19:02:02 +0000
committerxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-04 19:02:02 +0000
commit95f5e3fddc416838a9c5fda8f57ccea058103978 (patch)
treea0482f27fe20e552abd6fa6bc340eb81320be034 /media/base/decryptor.h
parent06b5cfe707e6e983b29f7338f9638d9a5e9ffc29 (diff)
downloadchromium_src-95f5e3fddc416838a9c5fda8f57ccea058103978.zip
chromium_src-95f5e3fddc416838a9c5fda8f57ccea058103978.tar.gz
chromium_src-95f5e3fddc416838a9c5fda8f57ccea058103978.tar.bz2
Add video decoding methods in Decryptor and add DecryptingVideoDecoder.
In Decryptor interface, video decoding methods are added to support CDMs that support both decryption and video decoding. A new VideoDecoder, DecryptingVideoDecoder, is added to support video decoding by Decryptors in the media pipeline. DecryptingVideoDecoder uses adapter pattern to convert a Decryptor into a VideoDecoder. In AddDefaultDecodersToCollection, add a DecryptingVideoDecoder object into the video decoder list. BUG=141784 TEST=new tests added into media_unittest Review URL: https://chromiumcodereview.appspot.com/10969028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160183 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/decryptor.h')
-rw-r--r--media/base/decryptor.h98
1 files changed, 80 insertions, 18 deletions
diff --git a/media/base/decryptor.h b/media/base/decryptor.h
index 01372cb..876129a 100644
--- a/media/base/decryptor.h
+++ b/media/base/decryptor.h
@@ -15,12 +15,19 @@
namespace media {
class DecoderBuffer;
-
-// Performs key operations and decrypts encrypted buffer.
-// All public methods other than Decrypt() will be called on the renderer
-// thread. Therefore, these calls should be fast and nonblocking, with key
-// events fired asynchronously. Decrypt() will be called on the (video/audio)
-// decoder thread.
+class VideoDecoderConfig;
+class VideoFrame;
+
+// Performs key operations and decrypts (and decodes) encrypted buffer.
+//
+// Key operations (GenerateKeyRequest(), AddKey() and CancelKeyRequest())
+// are called on the renderer thread. Therefore, these calls should be fast
+// and nonblocking; key events should be fired asynchronously.
+// All other methods are called on the (video/audio) decoder thread.
+// Decryptor implementations must be thread safe when methods are called
+// following the above model.
+// Depending on the implementation callbacks may be fired synchronously or
+// asynchronously.
class MEDIA_EXPORT Decryptor {
public:
enum KeyError {
@@ -35,11 +42,12 @@ class MEDIA_EXPORT Decryptor {
enum Status {
kSuccess, // Decryption successfully completed. Decrypted buffer ready.
kNoKey, // No key is available to decrypt.
+ kNeedMoreData, // Decoder needs more data to produce a frame.
kError // Key is available but an error occurred during decryption.
};
- Decryptor() {}
- virtual ~Decryptor() {}
+ Decryptor();
+ virtual ~Decryptor();
// Generates a key request for the |key_system| with |init_data| provided.
// Returns true if generating key request succeeded, false otherwise.
@@ -64,21 +72,25 @@ class MEDIA_EXPORT Decryptor {
virtual void CancelKeyRequest(const std::string& key_system,
const std::string& session_id) = 0;
+ // Indicates completion of a decryption operation.
+ //
+ // First parameter: The status of the decryption operation.
+ // - Set to kSuccess if the encrypted buffer is successfully decrypted and
+ // the decrypted buffer is ready to be read.
+ // - Set to kNoKey if no decryption key is available to decrypt the encrypted
+ // buffer. In this case the decrypted buffer must be NULL.
+ // - Set to kError if unexpected error has occurred. In this case the
+ // decrypted buffer must be NULL.
+ // - This parameter should not be set to kNeedMoreData.
+ // Second parameter: The decrypted buffer.
+ typedef base::Callback<void(Status,
+ const scoped_refptr<DecoderBuffer>&)> DecryptCB;
+
// 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.
- // Note that the callback maybe called synchronously or asynchronously.
- //
- // If the returned status is kSuccess, the |encrypted| buffer is successfully
- // decrypted and the decrypted buffer is ready to be read.
- // If the returned status is kNoKey, no decryption key is available to decrypt
- // |encrypted| buffer. In this case the decrypted buffer must be NULL.
- // If the returned status is kError, unexpected error has occurred. In this
- // case the decrypted buffer must be NULL.
- typedef base::Callback<void(Status,
- const scoped_refptr<DecoderBuffer>&)> DecryptCB;
virtual void Decrypt(const scoped_refptr<DecoderBuffer>& encrypted,
const DecryptCB& decrypt_cb) = 0;
@@ -87,6 +99,56 @@ class MEDIA_EXPORT Decryptor {
// Decrypt() should not be called again before the pending DecryptCB is fired.
virtual void CancelDecrypt() = 0;
+ // Indicates completion of decoder initialization.
+ //
+ // First Parameter: Indicates initialization success.
+ // - Set to true if initialization was successful. False if an error occurred.
+ typedef base::Callback<void(bool)> DecoderInitCB;
+
+ // 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.
+ virtual void InitializeVideoDecoder(const VideoDecoderConfig& config,
+ const DecoderInitCB& init_cb) = 0;
+
+ // Indicates completion of video decrypting and decoding operation.
+ //
+ // First parameter: The status of the decrypting and decoding operation.
+ // - Set to kSuccess if the encrypted buffer is successfully decrypted and
+ // decoded. In this case, the decoded video frame can be:
+ // 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.
+ // - Set to kNoKey if no decryption key is available to decrypt the encrypted
+ // buffer. In this case the decoded video frame must be NULL.
+ // - Set to kNeedMoreData if more data is needed to produce a video frame. In
+ // this case the decoded video frame must be NULL.
+ // - Set to kError if unexpected error has occurred. In this case the
+ // decoded video frame must be NULL.
+ // Second parameter: The decoded video frame.
+ 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|.
+ // 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.
+ 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;
+
private:
DISALLOW_COPY_AND_ASSIGN(Decryptor);
};