Chromium Code Reviews| 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 WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 5 #ifndef WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
| 6 #define WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 6 #define WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "media/base/decryptor.h" | 12 #include "media/base/decryptor.h" |
| 13 #include "media/base/decryptor_client.h" | |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 class MessageLoopProxy; | 16 class MessageLoopProxy; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace media { | 19 namespace media { |
| 19 class DecryptorClient; | 20 class DecryptorClient; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace WebKit { | 23 namespace WebKit { |
| 23 class WebFrame; | 24 class WebFrame; |
| 24 class WebMediaPlayerClient; | 25 class WebMediaPlayerClient; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace webkit_media { | 28 namespace webkit_media { |
| 28 | 29 |
| 29 // A decryptor proxy that creates a real decryptor object on demand and | 30 // A decryptor proxy that creates a real decryptor object on demand and |
| 30 // forwards decryptor calls to it. | 31 // forwards decryptor calls to it. |
| 31 // TODO(xhwang): Currently we don't support run-time switching among decryptor | 32 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
| 32 // objects. Fix this when needed. | 33 // objects. Fix this when needed. |
| 33 class ProxyDecryptor : public media::Decryptor { | 34 class ProxyDecryptor : public media::Decryptor, public media::DecryptorClient { |
| 34 public: | 35 public: |
| 36 typedef base::Callback<void(const std::string& key_system, | |
| 37 const std::string& session_id)> KeyAddedCB; | |
| 38 typedef base::Callback<void(const std::string& key_system, | |
| 39 const std::string& session_id, | |
| 40 media::Decryptor::KeyError error_code, | |
| 41 int system_code)> KeyErrorCB; | |
| 42 typedef base::Callback<void(const std::string& key_system, | |
| 43 const std::string& session_id, | |
| 44 scoped_array<uint8> message, | |
| 45 int message_length, | |
| 46 const std::string& default_url)> KeyMessageCB; | |
| 47 typedef base::Callback<void(const std::string& key_system, | |
| 48 const std::string& session_id, | |
| 49 scoped_array<uint8> init_data, | |
| 50 int init_data_size)> NeedKeyCB; | |
|
Ami GONE FROM CHROMIUM
2012/10/23 06:52:22
ISTM this CL went half-way to the real goal: delet
xhwang
2012/10/23 07:32:13
Agreed that if we choose the pure callback path th
| |
| 51 | |
| 35 ProxyDecryptor(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 52 ProxyDecryptor(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 36 media::DecryptorClient* decryptor_client, | 53 const KeyAddedCB& key_added_cb, |
| 54 const KeyErrorCB& key_error_cb, | |
| 55 const KeyMessageCB& key_message_cb, | |
| 56 const NeedKeyCB& need_key_cb, | |
| 37 WebKit::WebMediaPlayerClient* web_media_player_client, | 57 WebKit::WebMediaPlayerClient* web_media_player_client, |
| 38 WebKit::WebFrame* web_frame); | 58 WebKit::WebFrame* web_frame); |
| 39 virtual ~ProxyDecryptor(); | 59 virtual ~ProxyDecryptor(); |
| 40 | 60 |
| 41 void set_decryptor_for_testing(scoped_ptr<media::Decryptor> decryptor) { | 61 void set_decryptor_for_testing(scoped_ptr<media::Decryptor> decryptor) { |
| 42 decryptor_ = decryptor.Pass(); | 62 decryptor_ = decryptor.Pass(); |
| 43 } | 63 } |
| 44 | 64 |
| 45 // Callback to notify that the decryptor has been created. | 65 // Callback to notify that the decryptor has been created. |
| 46 typedef base::Callback<void(Decryptor*)> DecryptorNotificationCB; | 66 typedef base::Callback<void(Decryptor*)> DecryptorNotificationCB; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 const KeyAddedCB& key_added_cb) OVERRIDE; | 98 const KeyAddedCB& key_added_cb) OVERRIDE; |
| 79 virtual void DecryptAndDecodeAudio( | 99 virtual void DecryptAndDecodeAudio( |
| 80 const scoped_refptr<media::DecoderBuffer>& encrypted, | 100 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 81 const AudioDecodeCB& audio_decode_cb) OVERRIDE; | 101 const AudioDecodeCB& audio_decode_cb) OVERRIDE; |
| 82 virtual void DecryptAndDecodeVideo( | 102 virtual void DecryptAndDecodeVideo( |
| 83 const scoped_refptr<media::DecoderBuffer>& encrypted, | 103 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 84 const VideoDecodeCB& video_decode_cb) OVERRIDE; | 104 const VideoDecodeCB& video_decode_cb) OVERRIDE; |
| 85 virtual void ResetDecoder(StreamType stream_type) OVERRIDE; | 105 virtual void ResetDecoder(StreamType stream_type) OVERRIDE; |
| 86 virtual void DeinitializeDecoder(StreamType stream_type) OVERRIDE; | 106 virtual void DeinitializeDecoder(StreamType stream_type) OVERRIDE; |
| 87 | 107 |
| 108 // media::DecryptorClient implementation. | |
| 109 virtual void KeyAdded(const std::string& key_system, | |
| 110 const std::string& session_id) OVERRIDE; | |
| 111 virtual void KeyError(const std::string& key_system, | |
| 112 const std::string& session_id, | |
| 113 Decryptor::KeyError error_code, | |
| 114 int system_code) OVERRIDE; | |
| 115 virtual void KeyMessage(const std::string& key_system, | |
| 116 const std::string& session_id, | |
| 117 scoped_array<uint8> message, | |
| 118 int message_length, | |
| 119 const std::string& default_url) OVERRIDE; | |
| 120 virtual void NeedKey(const std::string& key_system, | |
| 121 const std::string& session_id, | |
| 122 scoped_array<uint8> init_data, | |
| 123 int init_data_length) OVERRIDE; | |
| 124 | |
| 88 private: | 125 private: |
| 89 // Helper functions to create decryptors to handle the given |key_system|. | 126 // Helper functions to create decryptors to handle the given |key_system|. |
| 90 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( | 127 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( |
| 91 const std::string& key_system); | 128 const std::string& key_system); |
| 92 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); | 129 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); |
| 93 | 130 |
| 94 void OnNewKeyAdded(); | 131 void OnNewKeyAdded(); |
| 95 | 132 |
| 96 // Sends |pending_buffer_to_decrypt_| to |decryptor_| for decryption. | 133 // Sends |pending_buffer_to_decrypt_| to |decryptor_| for decryption. |
| 97 void DecryptPendingBuffer(); | 134 void DecryptPendingBuffer(); |
| 98 | 135 |
| 99 // Callback passed to decryptor_->Decrypt(). It processes the |status| and | 136 // Callback passed to decryptor_->Decrypt(). It processes the |status| and |
| 100 // |decrypted| buffer from the |decryptor_|. | 137 // |decrypted| buffer from the |decryptor_|. |
| 101 void OnBufferDecrypted(media::Decryptor::Status status, | 138 void OnBufferDecrypted(media::Decryptor::Status status, |
| 102 const scoped_refptr<media::DecoderBuffer>& decrypted); | 139 const scoped_refptr<media::DecoderBuffer>& decrypted); |
| 103 | 140 |
| 104 // Message loop on which decryption-related methods happen. Note that | 141 // Message loop on which decryption-related methods happen. Note that |
| 105 // key/session-related methods do not run on this message loop. | 142 // key/session-related methods do not run on this message loop. |
| 106 scoped_refptr<base::MessageLoopProxy> const decryption_message_loop_; | 143 scoped_refptr<base::MessageLoopProxy> const decryption_message_loop_; |
| 107 | 144 |
| 108 // DecryptorClient through which key events are fired. | 145 // Callbacks for firing key events. |
| 109 media::DecryptorClient* client_; | 146 KeyAddedCB key_added_cb_; |
| 147 KeyErrorCB key_error_cb_; | |
| 148 KeyMessageCB key_message_cb_; | |
| 149 NeedKeyCB need_key_cb_; | |
| 110 | 150 |
| 111 // Needed to create the PpapiDecryptor. | 151 // Needed to create the PpapiDecryptor. |
| 112 WebKit::WebMediaPlayerClient* web_media_player_client_; | 152 WebKit::WebMediaPlayerClient* web_media_player_client_; |
| 113 WebKit::WebFrame* web_frame_; | 153 WebKit::WebFrame* web_frame_; |
| 114 | 154 |
| 115 // Protects the |decryptor_|. Note that |decryptor_| itself should be thread | 155 // Protects the |decryptor_|. Note that |decryptor_| itself should be thread |
| 116 // safe as per the Decryptor interface. | 156 // safe as per the Decryptor interface. |
| 117 base::Lock lock_; | 157 base::Lock lock_; |
| 118 | 158 |
| 119 DecryptorNotificationCB decryptor_notification_cb_; | 159 DecryptorNotificationCB decryptor_notification_cb_; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 145 // the |pending_buffer_to_decrypt_| again if kNoKey is returned because a | 185 // the |pending_buffer_to_decrypt_| again if kNoKey is returned because a |
| 146 // new key has been added. | 186 // new key has been added. |
| 147 bool has_new_key_added_; | 187 bool has_new_key_added_; |
| 148 | 188 |
| 149 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 189 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
| 150 }; | 190 }; |
| 151 | 191 |
| 152 } // namespace webkit_media | 192 } // namespace webkit_media |
| 153 | 193 |
| 154 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 194 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
| OLD | NEW |