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 <list> |
9 #include <string> | |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
12 #include "base/callback.h" | 11 #include "base/callback.h" |
13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
14 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
15 | 14 |
16 namespace media { | 15 namespace media { |
17 | 16 |
18 class AudioDecoderConfig; | 17 class AudioDecoderConfig; |
19 class DataBuffer; | 18 class DataBuffer; |
20 class DecoderBuffer; | 19 class DecoderBuffer; |
20 class MediaKeys; | |
21 class VideoDecoderConfig; | 21 class VideoDecoderConfig; |
22 class VideoFrame; | 22 class VideoFrame; |
23 | 23 |
24 // Performs key operations and decrypts (and decodes) encrypted buffer. | 24 // Decrypts (and decodes) encrypted buffer. |
25 // | 25 // |
26 // Key operations (GenerateKeyRequest(), AddKey() and CancelKeyRequest()) | 26 // All methods are called on the (video/audio) decoder thread. Decryptor |
27 // are called on the renderer thread. Therefore, these calls should be fast | 27 // implementations must be thread safe when methods are called this way. |
28 // and nonblocking; key events should be fired asynchronously. | |
29 // All other methods are called on the (video/audio) decoder thread. | |
30 // Decryptor implementations must be thread safe when methods are called | |
31 // following the above model. | |
32 // Depending on the implementation callbacks may be fired synchronously or | 28 // Depending on the implementation callbacks may be fired synchronously or |
33 // asynchronously. | 29 // asynchronously. |
34 class MEDIA_EXPORT Decryptor { | 30 class MEDIA_EXPORT Decryptor { |
35 public: | 31 public: |
36 // Reported to UMA, so never reuse a value! | |
37 // Must be kept in sync with WebKit::WebMediaPlayerClient::MediaKeyErrorCode | |
38 // (enforced in webmediaplayer_impl.cc). | |
39 enum KeyError { | |
40 kUnknownError = 1, | |
41 kClientError, | |
42 kServiceError, | |
43 kOutputError, | |
44 kHardwareChangeError, | |
45 kDomainError, | |
46 kMaxKeyError // Must be last and greater than any legit value. | |
47 }; | |
48 | |
49 // TODO(xhwang): Replace kError with kDecryptError and kDecodeError. | 32 // TODO(xhwang): Replace kError with kDecryptError and kDecodeError. |
50 // TODO(xhwang): Replace kNeedMoreData with kNotEnoughData. | 33 // TODO(xhwang): Replace kNeedMoreData with kNotEnoughData. |
51 enum Status { | 34 enum Status { |
52 kSuccess, // Decryption successfully completed. Decrypted buffer ready. | 35 kSuccess, // Decryption successfully completed. Decrypted buffer ready. |
53 kNoKey, // No key is available to decrypt. | 36 kNoKey, // No key is available to decrypt. |
54 kNeedMoreData, // Decoder needs more data to produce a frame. | 37 kNeedMoreData, // Decoder needs more data to produce a frame. |
55 kError // Key is available but an error occurred during decryption. | 38 kError // Key is available but an error occurred during decryption. |
56 }; | 39 }; |
57 | 40 |
58 // TODO(xhwang): Unify this with DemuxerStream::Type. | 41 // TODO(xhwang): Unify this with DemuxerStream::Type. |
59 enum StreamType { | 42 enum StreamType { |
60 kAudio, | 43 kAudio, |
61 kVideo | 44 kVideo |
62 }; | 45 }; |
63 | 46 |
64 Decryptor(); | 47 Decryptor(); |
65 virtual ~Decryptor(); | 48 virtual ~Decryptor(); |
66 | 49 |
67 // Generates a key request for the |key_system| with |type| and | 50 // Gets the MediaKey object associated with the Decryptor. Returns NULL if |
68 // |init_data| provided. | 51 // no MediaKey object is associated. The returned object is only guaranteed |
69 // Returns true if generating key request succeeded, false otherwise. | 52 // to be valid during the Decryptor's lifetime. |
ddorwin
2013/05/28 19:44:33
I guess we'll need to destroy the Decryptor when t
| |
70 // Note: AddKey() and CancelKeyRequest() should only be called after | 53 virtual MediaKeys* GetMediaKeys() = 0; |
71 // GenerateKeyRequest() returns true. | |
72 virtual bool GenerateKeyRequest(const std::string& key_system, | |
73 const std::string& type, | |
74 const uint8* init_data, | |
75 int init_data_length) = 0; | |
76 | 54 |
77 // Adds a |key| to the |key_system|. The |key| is not limited to a decryption | 55 // Indicates that a new key has been added to the MediaKey object associated |
ddorwin
2013/05/28 19:44:33
MediaKey_s_
xhwang
2013/05/28 23:50:39
Done.
| |
78 // key. It can be any data that the key system accepts, such as a license. | 56 // with the Decryptor. |
79 // If multiple calls of this function set different keys for the same | |
80 // key ID, the older key will be replaced by the newer key. | |
81 virtual void AddKey(const std::string& key_system, | |
82 const uint8* key, | |
83 int key_length, | |
84 const uint8* init_data, | |
85 int init_data_length, | |
86 const std::string& session_id) = 0; | |
87 | |
88 // Cancels the key request specified by |session_id|. | |
89 virtual void CancelKeyRequest(const std::string& key_system, | |
90 const std::string& session_id) = 0; | |
91 | |
92 // Indicates that a new key has been added to the Decryptor. | |
93 typedef base::Callback<void()> NewKeyCB; | 57 typedef base::Callback<void()> NewKeyCB; |
94 | 58 |
95 // Registers a NewKeyCB which should be called when a new key is added to the | 59 // Registers a NewKeyCB which should be called when a new key is added to the |
96 // decryptor. Only one NewKeyCB can be registered for one |stream_type|. | 60 // decryptor. Only one NewKeyCB can be registered for one |stream_type|. |
97 // If this function is called multiple times for the same |stream_type|, the | 61 // If this function is called multiple times for the same |stream_type|, the |
98 // previously registered callback will be replaced. In other words, | 62 // previously registered callback will be replaced. In other words, |
99 // registering a null callback cancels the originally registered callback. | 63 // registering a null callback cancels the originally registered callback. |
100 virtual void RegisterNewKeyCB(StreamType stream_type, | 64 virtual void RegisterNewKeyCB(StreamType stream_type, |
101 const NewKeyCB& key_added_cb) = 0; | 65 const NewKeyCB& key_added_cb) = 0; |
102 | 66 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 | 172 |
209 // Callback to set/cancel a DecryptorReadyCB. | 173 // Callback to set/cancel a DecryptorReadyCB. |
210 // Calling this callback with a non-null callback registers decryptor ready | 174 // Calling this callback with a non-null callback registers decryptor ready |
211 // notification. When the decryptor is ready, notification will be sent | 175 // notification. When the decryptor is ready, notification will be sent |
212 // through the provided callback. | 176 // through the provided callback. |
213 // Calling this callback with a null callback cancels previously registered | 177 // Calling this callback with a null callback cancels previously registered |
214 // decryptor ready notification. Any previously provided callback will be | 178 // decryptor ready notification. Any previously provided callback will be |
215 // fired immediately with NULL. | 179 // fired immediately with NULL. |
216 typedef base::Callback<void(const DecryptorReadyCB&)> SetDecryptorReadyCB; | 180 typedef base::Callback<void(const DecryptorReadyCB&)> SetDecryptorReadyCB; |
217 | 181 |
218 | |
219 // Key event callbacks. See the spec for details: | |
220 // http://dvcs.w3.org/hg/html-media/raw-file/eme-v0.1b/encrypted-media/encrypted -media.html#event-summary | |
221 typedef base::Callback<void(const std::string& key_system, | |
222 const std::string& session_id)> KeyAddedCB; | |
223 | |
224 typedef base::Callback<void(const std::string& key_system, | |
225 const std::string& session_id, | |
226 media::Decryptor::KeyError error_code, | |
227 int system_code)> KeyErrorCB; | |
228 | |
229 typedef base::Callback<void(const std::string& key_system, | |
230 const std::string& session_id, | |
231 const std::string& message, | |
232 const std::string& default_url)> KeyMessageCB; | |
233 | |
234 typedef base::Callback<void(const std::string& key_system, | |
235 const std::string& session_id, | |
236 const std::string& type, | |
237 scoped_ptr<uint8[]> init_data, | |
238 int init_data_size)> NeedKeyCB; | |
239 | |
240 } // namespace media | 182 } // namespace media |
241 | 183 |
242 #endif // MEDIA_BASE_DECRYPTOR_H_ | 184 #endif // MEDIA_BASE_DECRYPTOR_H_ |
OLD | NEW |