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; |
21 class VideoDecoderConfig; | 20 class VideoDecoderConfig; |
22 class VideoFrame; | 21 class VideoFrame; |
23 | 22 |
24 // Performs key operations and decrypts (and decodes) encrypted buffer. | 23 // Decrypts (and decodes) encrypted buffer. |
25 // | 24 // |
26 // Key operations (GenerateKeyRequest(), AddKey() and CancelKeyRequest()) | 25 // All methods are called on the (video/audio) decoder thread. Decryptor |
27 // are called on the renderer thread. Therefore, these calls should be fast | 26 // 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 | 27 // Depending on the implementation callbacks may be fired synchronously or |
33 // asynchronously. | 28 // asynchronously. |
34 class MEDIA_EXPORT Decryptor { | 29 class MEDIA_EXPORT Decryptor { |
35 public: | 30 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. | 31 // TODO(xhwang): Replace kError with kDecryptError and kDecodeError. |
ddorwin
2013/05/24 20:39:12
There are a bunch of cleanup TODOs in this file. P
xhwang
2013/05/24 23:15:56
Will do after this CL.
| |
50 // TODO(xhwang): Replace kNeedMoreData with kNotEnoughData. | 32 // TODO(xhwang): Replace kNeedMoreData with kNotEnoughData. |
51 enum Status { | 33 enum Status { |
52 kSuccess, // Decryption successfully completed. Decrypted buffer ready. | 34 kSuccess, // Decryption successfully completed. Decrypted buffer ready. |
53 kNoKey, // No key is available to decrypt. | 35 kNoKey, // No key is available to decrypt. |
54 kNeedMoreData, // Decoder needs more data to produce a frame. | 36 kNeedMoreData, // Decoder needs more data to produce a frame. |
55 kError // Key is available but an error occurred during decryption. | 37 kError // Key is available but an error occurred during decryption. |
56 }; | 38 }; |
57 | 39 |
58 // TODO(xhwang): Unify this with DemuxerStream::Type. | 40 // TODO(xhwang): Unify this with DemuxerStream::Type. |
59 enum StreamType { | 41 enum StreamType { |
60 kAudio, | 42 kAudio, |
61 kVideo | 43 kVideo |
62 }; | 44 }; |
63 | 45 |
64 Decryptor(); | 46 Decryptor(); |
65 virtual ~Decryptor(); | 47 virtual ~Decryptor(); |
66 | 48 |
67 // Generates a key request for the |key_system| with |type| and | |
68 // |init_data| provided. | |
69 // Returns true if generating key request succeeded, false otherwise. | |
70 // Note: AddKey() and CancelKeyRequest() should only be called after | |
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 | |
77 // Adds a |key| to the |key_system|. The |key| is not limited to a decryption | |
78 // key. It can be any data that the key system accepts, such as a license. | |
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. | 49 // Indicates that a new key has been added to the Decryptor. |
ddorwin
2013/05/24 20:39:12
Is "Decryptor" correct?
xhwang
2013/05/24 23:15:56
Done.
| |
93 typedef base::Callback<void()> NewKeyCB; | 50 typedef base::Callback<void()> NewKeyCB; |
94 | 51 |
95 // Registers a NewKeyCB which should be called when a new key is added to the | 52 // 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|. | 53 // 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 | 54 // If this function is called multiple times for the same |stream_type|, the |
98 // previously registered callback will be replaced. In other words, | 55 // previously registered callback will be replaced. In other words, |
99 // registering a null callback cancels the originally registered callback. | 56 // registering a null callback cancels the originally registered callback. |
100 virtual void RegisterNewKeyCB(StreamType stream_type, | 57 virtual void RegisterNewKeyCB(StreamType stream_type, |
101 const NewKeyCB& key_added_cb) = 0; | 58 const NewKeyCB& key_added_cb) = 0; |
102 | 59 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 | 165 |
209 // Callback to set/cancel a DecryptorReadyCB. | 166 // Callback to set/cancel a DecryptorReadyCB. |
210 // Calling this callback with a non-null callback registers decryptor ready | 167 // Calling this callback with a non-null callback registers decryptor ready |
211 // notification. When the decryptor is ready, notification will be sent | 168 // notification. When the decryptor is ready, notification will be sent |
212 // through the provided callback. | 169 // through the provided callback. |
213 // Calling this callback with a null callback cancels previously registered | 170 // Calling this callback with a null callback cancels previously registered |
214 // decryptor ready notification. Any previously provided callback will be | 171 // decryptor ready notification. Any previously provided callback will be |
215 // fired immediately with NULL. | 172 // fired immediately with NULL. |
216 typedef base::Callback<void(const DecryptorReadyCB&)> SetDecryptorReadyCB; | 173 typedef base::Callback<void(const DecryptorReadyCB&)> SetDecryptorReadyCB; |
217 | 174 |
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 | 175 } // namespace media |
241 | 176 |
242 #endif // MEDIA_BASE_DECRYPTOR_H_ | 177 #endif // MEDIA_BASE_DECRYPTOR_H_ |
OLD | NEW |