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

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

Issue 10539150: Add Decryptor interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move decryptor.* and decryptor_client.h to src/media/base/ Created 8 years, 6 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') | media/crypto/aes_decryptor.h » ('J')
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_CRYPTO_AES_DECRYPTOR_H_ 5 #ifndef MEDIA_BASE_DECRYPTOR_H_
6 #define MEDIA_CRYPTO_AES_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/hash_tables.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/synchronization/lock.h"
14 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
15 13
16 namespace crypto {
17 class SymmetricKey;
18 }
19
20 namespace media { 14 namespace media {
21 15
22 class DecoderBuffer; 16 class DecoderBuffer;
23 class DecryptorClient; 17 class DecryptorClient;
24 18
25 // Decrypts AES encrypted buffer into unencrypted buffer. 19 // Performs key operations and decrypts encrypted buffer.
26 // All public methods other than Decrypt() will be called on the renderer 20 // All public methods other than Decrypt() will be called on the renderer
27 // thread. Therefore, these calls should be fast and nonblocking, with key 21 // thread. Therefore, these calls should be fast and nonblocking, with key
28 // events fired asynchronously. Decrypt() will be called on the (video/audio) 22 // events fired asynchronously. Decrypt() will be called on the (video/audio)
29 // decoder thread synchronously. 23 // decoder thread synchronously.
30 class MEDIA_EXPORT AesDecryptor { 24 class MEDIA_EXPORT Decryptor {
31 public: 25 public:
32 enum KeyError { 26 enum KeyError {
33 kUnknownError = 1, 27 kUnknownError = 1,
34 kClientError, 28 kClientError,
35 kServiceError, 29 kServiceError,
36 kOutputError, 30 kOutputError,
37 kHardwareChangeError, 31 kHardwareChangeError,
38 kDomainError 32 kDomainError
39 }; 33 };
40 34
41 // The AesDecryptor does not take ownership of the |client|. The |client| 35 // The AesDecryptor does not take ownership of the |client|. The |client|
42 // must be valid throughout the lifetime of the AesDecryptor. 36 // must be valid throughout the lifetime of the AesDecryptor.
43 explicit AesDecryptor(DecryptorClient* client); 37 explicit Decryptor(DecryptorClient* client);
44 ~AesDecryptor(); 38 virtual ~Decryptor();
45 39
46 // Generates a key request. The result of this call will be reported via the 40 // Generates a key request. The result of this call will be reported via the
47 // client's KeyMessage() or KeyError() methods. 41 // client's KeyMessage() or KeyError() methods.
48 void GenerateKeyRequest(const std::string& key_system, 42 virtual void GenerateKeyRequest(const std::string& key_system,
49 const uint8* init_data, 43 const uint8* init_data,
50 int init_data_length); 44 int init_data_length) = 0;
51 45
52 // Adds a |key| to the key system. The key is not limited to a decryption key. 46 // Adds a |key| to the key system. The key is not limited to a decryption key.
53 // It can be any data that the key system accepts, such as a license. 47 // 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 48 // 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. 49 // |key_id|, the older key will be replaced by the newer key.
56 // The result of this call will be reported via the client's KeyAdded(), 50 // The result of this call will be reported via the client's KeyAdded(),
57 // KeyMessage() or KeyError() methods. 51 // KeyMessage() or KeyError() methods.
58 void AddKey(const std::string& key_system, 52 virtual void AddKey(const std::string& key_system,
59 const uint8* key, 53 const uint8* key,
60 int key_length, 54 int key_length,
61 const uint8* init_data, 55 const uint8* init_data,
62 int init_data_length, 56 int init_data_length,
63 const std::string& session_id); 57 const std::string& session_id) = 0;
64 58
65 // Cancels the key request specified by |session_id|. 59 // Cancels the key request specified by |session_id|.
66 void CancelKeyRequest(const std::string& key_system, 60 virtual void CancelKeyRequest(const std::string& key_system,
67 const std::string& session_id); 61 const std::string& session_id) = 0;
68 62
69 // Decrypts the |input| buffer, which should not be NULL. 63 // Decrypts the |input| buffer, which should not be NULL.
70 // Returns a DecoderBuffer with the decrypted data if decryption succeeded. 64 // Returns a DecoderBuffer with the decrypted data if decryption succeeded.
71 // Returns NULL if decryption failed. 65 // Returns NULL if decryption failed.
72 scoped_refptr<DecoderBuffer> Decrypt( 66 virtual scoped_refptr<DecoderBuffer> Decrypt(
73 const scoped_refptr<DecoderBuffer>& input); 67 const scoped_refptr<DecoderBuffer>& input) = 0;
68
69 protected:
70 DecryptorClient* client() const;
74 71
75 private: 72 private:
76 // KeyMap owns the crypto::SymmetricKey* and must delete them when they are
77 // not needed any more.
78 typedef base::hash_map<std::string, crypto::SymmetricKey*> KeyMap;
79
80 // Since only Decrypt() is called off the renderer thread, we only need to
81 // protect |key_map_|, the only member variable that is shared between
82 // Decrypt() and other methods.
83 KeyMap key_map_; // Protected by the |key_map_lock_|.
84 base::Lock key_map_lock_; // Protects the |key_map_|.
85
86 DecryptorClient* client_; 73 DecryptorClient* client_;
scherkus (not reviewing) 2012/06/19 03:03:24 I really don't like the idea of having this here o
xhwang 2012/06/19 16:29:53 Done.
87 74
88 // Make session ID unique per renderer by making it static. 75 DISALLOW_COPY_AND_ASSIGN(Decryptor);
89 // TODO(xhwang): Make session ID more strictly defined if needed:
90 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16739#c0
91 static uint32 next_session_id_;
92
93 DISALLOW_COPY_AND_ASSIGN(AesDecryptor);
94 }; 76 };
95 77
96 } // namespace media 78 } // namespace media
97 79
98 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_ 80 #endif // MEDIA_BASE_DECRYPTOR_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/decryptor.cc » ('j') | media/crypto/aes_decryptor.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698