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 #include "webkit/media/crypto/ppapi_decryptor.h" | 5 #include "webkit/media/crypto/ppapi_decryptor.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/location.h" | |
|
ddorwin
2012/08/22 01:26:26
What is this used for?
xhwang
2012/08/24 00:51:51
For FROM_HERE in PostTask.
| |
| 7 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | |
| 13 #include "base/message_loop_proxy.h" | |
| 14 #include "content/public/renderer/render_thread.h" | |
| 8 #include "media/base/decoder_buffer.h" | 15 #include "media/base/decoder_buffer.h" |
| 9 #include "media/base/decryptor_client.h" | 16 #include "media/base/decryptor_client.h" |
| 10 #include "webkit/media/crypto/key_systems.h" | 17 #include "webkit/media/crypto/key_systems.h" |
| 11 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 18 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 12 | 19 |
| 13 namespace webkit_media { | 20 namespace webkit_media { |
| 14 | 21 |
| 15 PpapiDecryptor::PpapiDecryptor( | 22 PpapiDecryptor::PpapiDecryptor( |
| 16 media::DecryptorClient* client, | 23 media::DecryptorClient* client, |
| 17 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance) | 24 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance) |
| 18 : client_(client), | 25 : client_(client), |
| 19 cdm_plugin_(plugin_instance) { | 26 cdm_plugin_(plugin_instance), |
| 27 render_loop_proxy_(content::RenderThread::Get()->GetMessageLoop()-> | |
| 28 message_loop_proxy()) { | |
| 29 DCHECK(client_); | |
| 30 DCHECK(cdm_plugin_); | |
| 31 cdm_plugin_->SetDecryptClient(client); | |
| 20 } | 32 } |
| 21 | 33 |
| 22 PpapiDecryptor::~PpapiDecryptor() { | 34 PpapiDecryptor::~PpapiDecryptor() { |
| 23 } | 35 } |
| 24 | 36 |
| 25 void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, | 37 void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, |
| 26 const uint8* init_data, | 38 const uint8* init_data, |
| 27 int init_data_length) { | 39 int init_data_length) { |
| 40 DVLOG(1) << "GenerateKeyRequest()"; | |
|
ddorwin
2012/08/22 01:26:26
Probably worth providing context (PPAPI) since Aes
xhwang
2012/08/24 00:51:51
In the logging, it will always show the file name
| |
| 41 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | |
|
ddorwin
2012/08/22 01:26:26
It's not obvious why this needs to be the case in
xhwang
2012/08/24 00:51:51
I guess this is just another (better) way to comme
| |
| 28 DCHECK(cdm_plugin_); | 42 DCHECK(cdm_plugin_); |
| 29 // TODO(xhwang): Enable the following once we have updated PluginInstance. | 43 |
| 30 // if (!cdm_plugin_->GenerateKeyRequest(key_system, | 44 if (!cdm_plugin_->GenerateKeyRequest( |
| 31 // init_data, init_data_length)) { | 45 key_system, |
| 32 // client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); | 46 std::string(reinterpret_cast<const char*>(init_data), |
|
ddorwin
2012/08/22 01:26:26
It's unfortunate we have to do this cast in multip
dmichael (off chromium)
2012/08/22 20:30:15
It's not really clear to me why we pass a string i
xhwang
2012/08/24 00:51:51
We discussed this before, and decided to use:
- st
xhwang
2012/08/24 00:51:51
Yes, if we decided to use pointer/size for init_da
dmichael (off chromium)
2012/08/24 17:18:34
The performance wouldn't bother me if the code was
| |
| 33 // } | 47 init_data_length))) { |
| 48 client_->KeyError(key_system, "", kUnknownError, 0); | |
|
Tom Finegan
2012/08/22 01:05:47
nit: one line statement in the if, not sure about
ddorwin
2012/08/22 01:26:26
You might move this to a helper function and log "
xhwang
2012/08/24 00:51:51
Done.
xhwang
2012/08/24 00:51:51
I remember we should use curly braces when the if(
| |
| 49 } | |
| 34 } | 50 } |
| 35 | 51 |
| 36 void PpapiDecryptor::AddKey(const std::string& key_system, | 52 void PpapiDecryptor::AddKey(const std::string& key_system, |
| 37 const uint8* key, | 53 const uint8* key, |
| 38 int key_length, | 54 int key_length, |
| 39 const uint8* init_data, | 55 const uint8* init_data, |
| 40 int init_data_length, | 56 int init_data_length, |
| 41 const std::string& session_id) { | 57 const std::string& session_id) { |
| 58 DVLOG(1) << "AddKey()"; | |
| 59 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | |
| 42 DCHECK(cdm_plugin_); | 60 DCHECK(cdm_plugin_); |
| 43 // TODO(xhwang): Enable the following once we have updated PluginInstance. | 61 |
| 44 // if (!cdm_plugin_->AddKey(key_system, key, key_length, | 62 if (!cdm_plugin_->AddKey( |
| 45 // init_data, init_data_length, session_id)) { | 63 session_id, |
|
ddorwin
2012/08/22 01:26:26
nit: It seems this would look better if indented f
dmichael (off chromium)
2012/08/22 20:30:15
Agreed... I think it should be 4 from the open pa
xhwang
2012/08/24 00:51:51
Done. But not sure if this is what you meant.
| |
| 46 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); | 64 std::string(reinterpret_cast<const char*>(key), key_length), |
| 47 // } | 65 std::string(reinterpret_cast<const char*>(init_data), |
| 66 init_data_length))) { | |
| 67 client_->KeyError(key_system, session_id, kUnknownError, 0); | |
|
ddorwin
2012/08/22 01:26:26
Does client always post to ensure we never report
xhwang
2012/08/24 00:51:51
Yes, the client is the webmediaplayer_proxy, which
| |
| 68 } | |
| 48 } | 69 } |
| 49 | 70 |
| 50 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, | 71 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
| 51 const std::string& session_id) { | 72 const std::string& session_id) { |
| 73 DVLOG(1) << "CancelKeyRequest()"; | |
| 74 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | |
| 52 DCHECK(cdm_plugin_); | 75 DCHECK(cdm_plugin_); |
| 53 // TODO(xhwang): Enable the following once we have updated PluginInstance. | 76 |
| 54 // if (!cdm_plugin_->CancelKeyRequest(key_system, session_id)) | 77 if (!cdm_plugin_->CancelKeyRequest(session_id)) |
| 55 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); | 78 client_->KeyError(key_system, session_id, kUnknownError, 0); |
| 56 } | 79 } |
| 57 | 80 |
| 58 void PpapiDecryptor::Decrypt( | 81 void PpapiDecryptor::Decrypt( |
| 59 const scoped_refptr<media::DecoderBuffer>& encrypted, | 82 const scoped_refptr<media::DecoderBuffer>& encrypted, |
|
ddorwin
2012/08/22 01:26:26
Is it possible to avoid refptr for this?
xhwang
2012/08/24 00:51:51
I think the rule is if |encrypted| is a scoped_ref
| |
| 60 const DecryptCB& decrypt_cb) { | 83 const DecryptCB& decrypt_cb) { |
| 61 DCHECK(cdm_plugin_); | 84 DVLOG(1) << "Decrypt()"; |
| 62 // TODO(xhwang): Enable the following once we have updated PluginInstance. | 85 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 63 // TODO(xhwang): Need to figure out thread safety about PPP calls. | 86 render_loop_proxy_->PostTask( |
| 64 // if (!cdm_plugin_->Decrypt( | 87 FROM_HERE, |
| 65 // encrypted, base::Bind(&PpapiDecryptor::DataReady, this, decrypt_cb))) { | 88 base::Bind(&PpapiDecryptor::Decrypt, base::Unretained(this), |
| 66 // decrypt_cb.Run(kError, NULL); | 89 encrypted, decrypt_cb)); |
| 67 // } | 90 return; |
| 91 } | |
| 92 | |
| 93 if (cdm_plugin_->Decrypt(encrypted, decrypt_cb)) { | |
|
ddorwin
2012/08/22 01:26:26
Missing a '!' ?
xhwang
2012/08/24 00:51:51
Oops, thanks for catching this. Done.
| |
| 94 decrypt_cb.Run(kError, NULL); | |
| 95 } | |
| 68 } | 96 } |
| 69 | 97 |
| 70 void PpapiDecryptor::Stop() { | 98 void PpapiDecryptor::Stop() { |
| 71 } | 99 } |
| 72 | 100 |
| 73 void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, | |
| 74 const uint8* data, int data_size ) { | |
| 75 DCHECK(!decrypt_cb.is_null()); | |
| 76 scoped_refptr<media::DecoderBuffer> decrypted_data = | |
| 77 media::DecoderBuffer::CopyFrom(data, data_size); | |
| 78 decrypt_cb.Run(kSuccess, decrypted_data); | |
| 79 } | |
| 80 | |
| 81 } // namespace webkit_media | 101 } // namespace webkit_media |
| OLD | NEW |