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_DECRYPTOR_H_ | 5 #ifndef MEDIA_BASE_DECRYPTOR_H_ |
6 #define MEDIA_BASE_DECRYPTOR_H_ | 6 #define MEDIA_BASE_DECRYPTOR_H_ |
7 | 7 |
| 8 #include <list> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "media/base/audio_decoder.h" |
13 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
14 | 16 |
15 namespace media { | 17 namespace media { |
16 | 18 |
| 19 class AudioDecoderConfig; |
| 20 class Buffer; |
17 class DecoderBuffer; | 21 class DecoderBuffer; |
18 class VideoDecoderConfig; | 22 class VideoDecoderConfig; |
19 class VideoFrame; | 23 class VideoFrame; |
20 | 24 |
21 // Performs key operations and decrypts (and decodes) encrypted buffer. | 25 // Performs key operations and decrypts (and decodes) encrypted buffer. |
22 // | 26 // |
23 // Key operations (GenerateKeyRequest(), AddKey() and CancelKeyRequest()) | 27 // Key operations (GenerateKeyRequest(), AddKey() and CancelKeyRequest()) |
24 // are called on the renderer thread. Therefore, these calls should be fast | 28 // are called on the renderer thread. Therefore, these calls should be fast |
25 // and nonblocking; key events should be fired asynchronously. | 29 // and nonblocking; key events should be fired asynchronously. |
26 // All other methods are called on the (video/audio) decoder thread. | 30 // All other methods are called on the (video/audio) decoder thread. |
(...skipping 12 matching lines...) Expand all Loading... |
39 kDomainError | 43 kDomainError |
40 }; | 44 }; |
41 | 45 |
42 enum Status { | 46 enum Status { |
43 kSuccess, // Decryption successfully completed. Decrypted buffer ready. | 47 kSuccess, // Decryption successfully completed. Decrypted buffer ready. |
44 kNoKey, // No key is available to decrypt. | 48 kNoKey, // No key is available to decrypt. |
45 kNeedMoreData, // Decoder needs more data to produce a frame. | 49 kNeedMoreData, // Decoder needs more data to produce a frame. |
46 kError // Key is available but an error occurred during decryption. | 50 kError // Key is available but an error occurred during decryption. |
47 }; | 51 }; |
48 | 52 |
| 53 enum StreamType { |
| 54 kAudio, |
| 55 kVideo |
| 56 }; |
| 57 |
49 Decryptor(); | 58 Decryptor(); |
50 virtual ~Decryptor(); | 59 virtual ~Decryptor(); |
51 | 60 |
52 // Generates a key request for the |key_system| with |init_data| provided. | 61 // Generates a key request for the |key_system| with |init_data| provided. |
53 // Returns true if generating key request succeeded, false otherwise. | 62 // Returns true if generating key request succeeded, false otherwise. |
54 // Note: AddKey() and CancelKeyRequest() should only be called after | 63 // Note: AddKey() and CancelKeyRequest() should only be called after |
55 // GenerateKeyRequest() returns true. | 64 // GenerateKeyRequest() returns true. |
56 virtual bool GenerateKeyRequest(const std::string& key_system, | 65 virtual bool GenerateKeyRequest(const std::string& key_system, |
57 const uint8* init_data, | 66 const uint8* init_data, |
58 int init_data_length) = 0; | 67 int init_data_length) = 0; |
(...skipping 23 matching lines...) Expand all Loading... |
82 // - Set to kError if unexpected error has occurred. In this case the | 91 // - Set to kError if unexpected error has occurred. In this case the |
83 // decrypted buffer must be NULL. | 92 // decrypted buffer must be NULL. |
84 // - This parameter should not be set to kNeedMoreData. | 93 // - This parameter should not be set to kNeedMoreData. |
85 // Second parameter: The decrypted buffer. | 94 // Second parameter: The decrypted buffer. |
86 typedef base::Callback<void(Status, | 95 typedef base::Callback<void(Status, |
87 const scoped_refptr<DecoderBuffer>&)> DecryptCB; | 96 const scoped_refptr<DecoderBuffer>&)> DecryptCB; |
88 | 97 |
89 // Decrypts the |encrypted| buffer. The decrypt status and decrypted buffer | 98 // Decrypts the |encrypted| buffer. The decrypt status and decrypted buffer |
90 // are returned via the provided callback |decrypt_cb|. The |encrypted| buffer | 99 // are returned via the provided callback |decrypt_cb|. The |encrypted| buffer |
91 // must not be NULL. | 100 // must not be NULL. |
92 // Decrypt() should not be called until any previous DecryptCB has completed. | 101 // Decrypt() should not be called until any previous DecryptCB of the same |
93 // Thus, only one DecryptCB may be pending at a time. | 102 // |stream_type| has completed. Thus, only one DecryptCB may be pending at |
94 virtual void Decrypt(const scoped_refptr<DecoderBuffer>& encrypted, | 103 // a time for a given |stream_type|. |
| 104 virtual void Decrypt(StreamType stream_type, |
| 105 const scoped_refptr<DecoderBuffer>& encrypted, |
95 const DecryptCB& decrypt_cb) = 0; | 106 const DecryptCB& decrypt_cb) = 0; |
96 | 107 |
97 // Cancels the scheduled decryption operation and fires the pending DecryptCB | 108 // Cancels the scheduled decryption operation for |stream_type| and fires the |
98 // immediately with kSuccess and NULL. | 109 // pending DecryptCB immediately with kSuccess and NULL. |
99 // Decrypt() should not be called again before the pending DecryptCB is fired. | 110 // Decrypt() should not be called again before the pending DecryptCB for the |
100 virtual void CancelDecrypt() = 0; | 111 // same |stream_type| is fired. |
| 112 virtual void CancelDecrypt(StreamType stream_type) = 0; |
101 | 113 |
102 // Indicates completion of decoder initialization. | 114 // Indicates completion of audio/video decoder initialization. |
103 // | 115 // |
104 // First Parameter: Indicates initialization success. | 116 // First Parameter: Indicates initialization success. |
105 // - Set to true if initialization was successful. False if an error occurred. | 117 // - Set to true if initialization was successful. False if an error occurred. |
106 typedef base::Callback<void(bool)> DecoderInitCB; | 118 typedef base::Callback<void(bool)> DecoderInitCB; |
107 | 119 |
108 // Indicates that a key has been added to the Decryptor. | 120 // Indicates that a key has been added to the Decryptor. |
109 typedef base::Callback<void()> KeyAddedCB; | 121 typedef base::Callback<void()> KeyAddedCB; |
110 | 122 |
111 // Initializes a video decoder with the given |config|, executing the | 123 // Initializes a decoder with the given |config|, executing the |init_cb| |
112 // |init_cb| upon completion. | 124 // upon completion. |
113 // Note: DecryptAndDecodeVideo(), ResetVideoDecoder() and StopVideoDecoder() | 125 // |key_added_cb| should be called when a key is added to the decryptor. |
114 // can only be called after InitializeVideoDecoder() succeeded. | 126 virtual void InitializeAudioDecoder(scoped_ptr<AudioDecoderConfig> config, |
| 127 const DecoderInitCB& init_cb, |
| 128 const KeyAddedCB& key_added_cb) = 0; |
115 virtual void InitializeVideoDecoder(scoped_ptr<VideoDecoderConfig> config, | 129 virtual void InitializeVideoDecoder(scoped_ptr<VideoDecoderConfig> config, |
116 const DecoderInitCB& init_cb, | 130 const DecoderInitCB& init_cb, |
117 const KeyAddedCB& key_added_cb) = 0; | 131 const KeyAddedCB& key_added_cb) = 0; |
118 | 132 |
119 // Indicates completion of video decrypting and decoding operation. | 133 // Helper structure for managing multiple decoded audio buffers per input. |
| 134 typedef std::list<scoped_refptr<Buffer> > AudioBuffers; |
| 135 |
| 136 // Indicates completion of audio/video decrypt-and-decode operation. |
120 // | 137 // |
121 // First parameter: The status of the decrypting and decoding operation. | 138 // First parameter: The status of the decrypt-and-decode operation. |
122 // - Set to kSuccess if the encrypted buffer is successfully decrypted and | 139 // - Set to kSuccess if the encrypted buffer is successfully decrypted and |
123 // decoded. In this case, the decoded video frame can be: | 140 // decoded. In this case, the decoded frame/buffers can be/contain: |
124 // 1) NULL, which means the operation has been aborted. | 141 // 1) NULL, which means the operation has been aborted. |
125 // 2) End-of-stream (EOS) frame, which means that the decoder has hit EOS, | 142 // 2) End-of-stream (EOS) frame, which means that the decoder has hit EOS, |
126 // flushed all internal buffers and cannot produce more video frames. | 143 // flushed all internal buffers and cannot produce more video frames. |
127 // 3) Decrypted and decoded video frame. | 144 // 3) Decrypted and decoded video frame or audio buffer. |
128 // - Set to kNoKey if no decryption key is available to decrypt the encrypted | 145 // - Set to kNoKey if no decryption key is available to decrypt the encrypted |
129 // buffer. In this case the decoded video frame must be NULL. | 146 // buffer. In this case the returned frame(s) must be NULL/empty. |
130 // - Set to kNeedMoreData if more data is needed to produce a video frame. In | 147 // - Set to kNeedMoreData if more data is needed to produce a video frame. In |
131 // this case the decoded video frame must be NULL. | 148 // this case the returned frame(s) must be NULL/empty. |
132 // - Set to kError if unexpected error has occurred. In this case the | 149 // - Set to kError if unexpected error has occurred. In this case the |
133 // decoded video frame must be NULL. | 150 // returned frame(s) must be NULL/empty. |
134 // Second parameter: The decoded video frame. | 151 // Second parameter: The decoded video frame or audio buffers. |
| 152 typedef base::Callback<void(Status, const AudioBuffers&)> AudioDecodeCB; |
135 typedef base::Callback<void(Status, | 153 typedef base::Callback<void(Status, |
136 const scoped_refptr<VideoFrame>&)> VideoDecodeCB; | 154 const scoped_refptr<VideoFrame>&)> VideoDecodeCB; |
137 | 155 |
138 // Decrypts and decodes the |encrypted| buffer. The status and the decrypted | 156 // Decrypts and decodes the |encrypted| buffer. The status and the decrypted |
139 // buffer are returned via the provided callback |video_decode_cb|. | 157 // buffer are returned via the provided callback. |
140 // The |encrypted| buffer must not be NULL. | 158 // The |encrypted| buffer must not be NULL. |
141 // At end-of-stream, this method should be called repeatedly with | 159 // At end-of-stream, this method should be called repeatedly with |
142 // end-of-stream DecoderBuffer until no video frame can be produced. | 160 // end-of-stream DecoderBuffer until no frame/buffer can be produced. |
| 161 // These methods can only be called after the corresponding decoder has |
| 162 // been successfully initialized. |
| 163 virtual void DecryptAndDecodeAudio( |
| 164 const scoped_refptr<DecoderBuffer>& encrypted, |
| 165 const AudioDecodeCB& audio_decode_cb) = 0; |
143 virtual void DecryptAndDecodeVideo( | 166 virtual void DecryptAndDecodeVideo( |
144 const scoped_refptr<DecoderBuffer>& encrypted, | 167 const scoped_refptr<DecoderBuffer>& encrypted, |
145 const VideoDecodeCB& video_decode_cb) = 0; | 168 const VideoDecodeCB& video_decode_cb) = 0; |
146 | 169 |
147 // Cancels scheduled video decrypt-and-decode operations and fires any pending | 170 // Resets the decoder to an initialized clean state, cancels any scheduled |
148 // VideoDecodeCB immediately with kError and NULL frame. | 171 // decrypt-and-decode operations, and fires any pending |
149 virtual void CancelDecryptAndDecodeVideo() = 0; | 172 // AudioDecodeCB/VideoDecodeCB immediately with kError and NULL. |
| 173 // This method can only be called after the corresponding decoder has been |
| 174 // successfully initialized. |
| 175 virtual void ResetDecoder(StreamType stream_type) = 0; |
150 | 176 |
151 // Stops decoder and sets it to an uninitialized state. | 177 // Releases decoder resources, deinitializes the decoder, cancels any |
152 // The decoder can be reinitialized by calling InitializeVideoDecoder() after | 178 // scheduled initialization or decrypt-and-decode operations, and fires |
153 // it is stopped. | 179 // any pending DecoderInitCB/AudioDecodeCB/VideoDecodeCB immediately. |
154 virtual void StopVideoDecoder() = 0; | 180 // DecoderInitCB should be fired with false. AudioDecodeCB/VideoDecodeCB |
| 181 // should be fired with kError. |
| 182 // This method can be called any time after Initialize{Audio|Video}Decoder() |
| 183 // has been called (with the correct stream type). |
| 184 // After this operation, the decoder is set to an uninitialized state. |
| 185 // The decoder can be reinitialized after it is uninitialized. |
| 186 virtual void DeinitializeDecoder(StreamType stream_type) = 0; |
155 | 187 |
156 private: | 188 private: |
157 DISALLOW_COPY_AND_ASSIGN(Decryptor); | 189 DISALLOW_COPY_AND_ASSIGN(Decryptor); |
158 }; | 190 }; |
159 | 191 |
160 } // namespace media | 192 } // namespace media |
161 | 193 |
162 #endif // MEDIA_BASE_DECRYPTOR_H_ | 194 #endif // MEDIA_BASE_DECRYPTOR_H_ |
OLD | NEW |