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

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

Issue 10969028: Add video decoding methods in Decryptor and add DecryptingVideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reorder methods in the unittest Created 8 years, 2 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
« no previous file with comments | « no previous file | media/base/decryptor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_DECRYPTOR_H_ 5 #ifndef MEDIA_BASE_DECRYPTOR_H_
6 #define MEDIA_BASE_DECRYPTOR_H_ 6 #define MEDIA_BASE_DECRYPTOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "media/base/media_export.h" 13 #include "media/base/media_export.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 class DecoderBuffer; 17 class DecoderBuffer;
18 class VideoDecoderConfig;
19 class VideoFrame;
18 20
19 // Performs key operations and decrypts encrypted buffer. 21 // Performs key operations and decrypts (and decodes) encrypted buffer.
20 // All public methods other than Decrypt() will be called on the renderer 22 //
21 // thread. Therefore, these calls should be fast and nonblocking, with key 23 // Key operations (GenerateKeyRequest(), AddKey() and CancelKeyRequest())
22 // events fired asynchronously. Decrypt() will be called on the (video/audio) 24 // are called on the renderer thread. Therefore, these calls should be fast
23 // decoder thread. 25 // and nonblocking; key events should be fired asynchronously.
26 // All other methods are called on the (video/audio) decoder thread.
27 // Decryptor implementations must be thread safe when methods are called
28 // following the above model.
29 // Depending on the implementation callbacks may be fired synchronously or
30 // asynchronously.
24 class MEDIA_EXPORT Decryptor { 31 class MEDIA_EXPORT Decryptor {
25 public: 32 public:
26 enum KeyError { 33 enum KeyError {
27 kUnknownError = 1, 34 kUnknownError = 1,
28 kClientError, 35 kClientError,
29 kServiceError, 36 kServiceError,
30 kOutputError, 37 kOutputError,
31 kHardwareChangeError, 38 kHardwareChangeError,
32 kDomainError 39 kDomainError
33 }; 40 };
34 41
35 enum Status { 42 enum Status {
36 kSuccess, // Decryption successfully completed. Decrypted buffer ready. 43 kSuccess, // Decryption successfully completed. Decrypted buffer ready.
37 kNoKey, // No key is available to decrypt. 44 kNoKey, // No key is available to decrypt.
45 kNeedMoreData, // Decoder needs more data to produce a frame.
38 kError // Key is available but an error occurred during decryption. 46 kError // Key is available but an error occurred during decryption.
39 }; 47 };
40 48
41 Decryptor() {} 49 Decryptor();
42 virtual ~Decryptor() {} 50 virtual ~Decryptor();
43 51
44 // Generates a key request for the |key_system| with |init_data| provided. 52 // Generates a key request for the |key_system| with |init_data| provided.
45 // Returns true if generating key request succeeded, false otherwise. 53 // Returns true if generating key request succeeded, false otherwise.
46 // Note: AddKey() and CancelKeyRequest() should only be called after 54 // Note: AddKey() and CancelKeyRequest() should only be called after
47 // GenerateKeyRequest() returns true. 55 // GenerateKeyRequest() returns true.
48 virtual bool GenerateKeyRequest(const std::string& key_system, 56 virtual bool GenerateKeyRequest(const std::string& key_system,
49 const uint8* init_data, 57 const uint8* init_data,
50 int init_data_length) = 0; 58 int init_data_length) = 0;
51 59
52 // Adds a |key| to the |key_system|. The |key| is not limited to a decryption 60 // Adds a |key| to the |key_system|. The |key| is not limited to a decryption
53 // key. It can be any data that the key system accepts, such as a license. 61 // key. It can be any data that the key system accepts, such as a license.
54 // If multiple calls of this function set different keys for the same 62 // If multiple calls of this function set different keys for the same
55 // key ID, the older key will be replaced by the newer key. 63 // key ID, the older key will be replaced by the newer key.
56 virtual void AddKey(const std::string& key_system, 64 virtual void AddKey(const std::string& key_system,
57 const uint8* key, 65 const uint8* key,
58 int key_length, 66 int key_length,
59 const uint8* init_data, 67 const uint8* init_data,
60 int init_data_length, 68 int init_data_length,
61 const std::string& session_id) = 0; 69 const std::string& session_id) = 0;
62 70
63 // Cancels the key request specified by |session_id|. 71 // Cancels the key request specified by |session_id|.
64 virtual void CancelKeyRequest(const std::string& key_system, 72 virtual void CancelKeyRequest(const std::string& key_system,
65 const std::string& session_id) = 0; 73 const std::string& session_id) = 0;
66 74
75 // Indicates completion of a decryption operation.
76 //
77 // First parameter: The status of the decryption operation.
78 // - Set to kSuccess if the encrypted buffer is successfully decrypted and
79 // the decrypted buffer is ready to be read.
80 // - Set to kNoKey if no decryption key is available to decrypt the encrypted
81 // buffer. In this case the decrypted buffer must be NULL.
82 // - Set to kError if unexpected error has occurred. In this case the
83 // decrypted buffer must be NULL.
84 // - This parameter should not be set to kNeedMoreData.
85 // Second parameter: The decrypted buffer.
86 typedef base::Callback<void(Status,
87 const scoped_refptr<DecoderBuffer>&)> DecryptCB;
88
67 // Decrypts the |encrypted| buffer. The decrypt status and decrypted buffer 89 // Decrypts the |encrypted| buffer. The decrypt status and decrypted buffer
68 // are returned via the provided callback |decrypt_cb|. The |encrypted| buffer 90 // are returned via the provided callback |decrypt_cb|. The |encrypted| buffer
69 // must not be NULL. 91 // must not be NULL.
70 // Decrypt() should not be called until any previous DecryptCB has completed. 92 // Decrypt() should not be called until any previous DecryptCB has completed.
71 // Thus, only one DecryptCB may be pending at a time. 93 // Thus, only one DecryptCB may be pending at a time.
72 // Note that the callback maybe called synchronously or asynchronously.
73 //
74 // If the returned status is kSuccess, the |encrypted| buffer is successfully
75 // decrypted and the decrypted buffer is ready to be read.
76 // If the returned status is kNoKey, no decryption key is available to decrypt
77 // |encrypted| buffer. In this case the decrypted buffer must be NULL.
78 // If the returned status is kError, unexpected error has occurred. In this
79 // case the decrypted buffer must be NULL.
80 typedef base::Callback<void(Status,
81 const scoped_refptr<DecoderBuffer>&)> DecryptCB;
82 virtual void Decrypt(const scoped_refptr<DecoderBuffer>& encrypted, 94 virtual void Decrypt(const scoped_refptr<DecoderBuffer>& encrypted,
83 const DecryptCB& decrypt_cb) = 0; 95 const DecryptCB& decrypt_cb) = 0;
84 96
85 // Cancels the scheduled decryption operation and fires the pending DecryptCB 97 // Cancels the scheduled decryption operation and fires the pending DecryptCB
86 // immediately with kSuccess and NULL. 98 // immediately with kSuccess and NULL.
87 // Decrypt() should not be called again before the pending DecryptCB is fired. 99 // Decrypt() should not be called again before the pending DecryptCB is fired.
88 virtual void CancelDecrypt() = 0; 100 virtual void CancelDecrypt() = 0;
89 101
102 // Indicates completion of decoder initialization.
103 //
104 // First Parameter: Indicates initialization success.
105 // - Set to true if initialization was successful. False if an error occurred.
106 typedef base::Callback<void(bool)> DecoderInitCB;
107
108 // Initializes a video decoder with the given |config|, executing the
109 // |init_cb| upon completion.
110 // Note: DecryptAndDecodeVideo(), ResetVideoDecoder() and StopVideoDecoder()
111 // can only be called after InitializeVideoDecoder() succeeded.
112 virtual void InitializeVideoDecoder(const VideoDecoderConfig& config,
113 const DecoderInitCB& init_cb) = 0;
114
115 // Indicates completion of video decrypting and decoding operation.
116 //
117 // First parameter: The status of the decrypting and decoding operation.
118 // - Set to kSuccess if the encrypted buffer is successfully decrypted and
119 // decoded. In this case, the decoded video frame can be:
120 // 1) NULL, which means the operation has been aborted.
121 // 2) End-of-stream (EOS) frame, which means that the decoder has hit EOS,
122 // flushed all internal buffers and cannot produce more video frames.
123 // 3) Decrypted and decoded video frame.
124 // - Set to kNoKey if no decryption key is available to decrypt the encrypted
125 // buffer. In this case the decoded video frame must be NULL.
126 // - Set to kNeedMoreData if more data is needed to produce a video frame. In
127 // this case the decoded video frame must be NULL.
128 // - Set to kError if unexpected error has occurred. In this case the
129 // decoded video frame must be NULL.
130 // Second parameter: The decoded video frame.
131 typedef base::Callback<void(Status,
132 const scoped_refptr<VideoFrame>&)> VideoDecodeCB;
133
134 // Decrypts and decodes the |encrypted| buffer. The status and the decrypted
135 // buffer are returned via the provided callback |video_decode_cb|.
136 // The |encrypted| buffer must not be NULL.
137 // At end-of-stream, this method should be called repeatedly with
138 // end-of-stream DecoderBuffer until no video frame can be produced.
139 virtual void DecryptAndDecodeVideo(
140 const scoped_refptr<DecoderBuffer>& encrypted,
141 const VideoDecodeCB& video_decode_cb) = 0;
142
143 // Cancels scheduled video decrypt-and-decode operations and fires any pending
144 // VideoDecodeCB immediately with kError and NULL frame.
145 virtual void CancelDecryptAndDecodeVideo() = 0;
146
147 // Stops decoder and sets it to an uninitialized state.
148 // The decoder can be reinitialized by calling InitializeVideoDecoder() after
149 // it is stopped.
150 virtual void StopVideoDecoder() = 0;
151
90 private: 152 private:
91 DISALLOW_COPY_AND_ASSIGN(Decryptor); 153 DISALLOW_COPY_AND_ASSIGN(Decryptor);
92 }; 154 };
93 155
94 } // namespace media 156 } // namespace media
95 157
96 #endif // MEDIA_BASE_DECRYPTOR_H_ 158 #endif // MEDIA_BASE_DECRYPTOR_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/decryptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698