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" | |
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()) { | |
dmichael (off chromium)
2012/08/09 16:24:52
nit: indentation is off.
Would it fit if you brea
| |
29 DCHECK(cdm_plugin_); | |
30 cdm_plugin_->SetDecryptClient(client); | |
20 } | 31 } |
21 | 32 |
22 PpapiDecryptor::~PpapiDecryptor() { | 33 PpapiDecryptor::~PpapiDecryptor() { |
23 } | 34 } |
24 | 35 |
25 void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, | 36 void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, |
26 const uint8* init_data, | 37 const uint8* init_data, |
27 int init_data_length) { | 38 int init_data_length) { |
39 DVLOG(1) << "GenerateKeyRequest()"; | |
40 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | |
28 DCHECK(cdm_plugin_); | 41 DCHECK(cdm_plugin_); |
42 | |
29 // TODO(xhwang): Enable the following once we have updated PluginInstance. | 43 // TODO(xhwang): Enable the following once we have updated PluginInstance. |
30 // if (!cdm_plugin_->GenerateKeyRequest(key_system, | 44 std::string init_data_string(reinterpret_cast<const char*>(init_data), |
31 // init_data, init_data_length)) { | 45 init_data_length); |
32 // client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); | 46 if (!cdm_plugin_->GenerateKeyRequest(key_system, init_data_string)) { |
33 // } | 47 client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); |
48 } | |
34 } | 49 } |
35 | 50 |
36 void PpapiDecryptor::AddKey(const std::string& key_system, | 51 void PpapiDecryptor::AddKey(const std::string& key_system, |
37 const uint8* key, | 52 const uint8* key, |
38 int key_length, | 53 int key_length, |
39 const uint8* init_data, | 54 const uint8* init_data, |
40 int init_data_length, | 55 int init_data_length, |
41 const std::string& session_id) { | 56 const std::string& session_id) { |
57 DVLOG(1) << "AddKey()"; | |
58 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | |
42 DCHECK(cdm_plugin_); | 59 DCHECK(cdm_plugin_); |
43 // TODO(xhwang): Enable the following once we have updated PluginInstance. | 60 // TODO(xhwang): Enable the following once we have updated PluginInstance. |
44 // if (!cdm_plugin_->AddKey(key_system, key, key_length, | 61 // if (!cdm_plugin_->AddKey(key_system, key, key_length, |
45 // init_data, init_data_length, session_id)) { | 62 // init_data, init_data_length, session_id)) { |
46 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); | 63 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
47 // } | 64 // } |
48 } | 65 } |
49 | 66 |
50 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, | 67 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
51 const std::string& session_id) { | 68 const std::string& session_id) { |
69 DVLOG(1) << "CancelKeyRequest()"; | |
70 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | |
52 DCHECK(cdm_plugin_); | 71 DCHECK(cdm_plugin_); |
53 // TODO(xhwang): Enable the following once we have updated PluginInstance. | 72 // TODO(xhwang): Enable the following once we have updated PluginInstance. |
54 // if (!cdm_plugin_->CancelKeyRequest(key_system, session_id)) | 73 // if (!cdm_plugin_->CancelKeyRequest(key_system, session_id)) |
55 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); | 74 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
56 } | 75 } |
57 | 76 |
58 void PpapiDecryptor::Decrypt( | 77 void PpapiDecryptor::Decrypt( |
59 const scoped_refptr<media::DecoderBuffer>& encrypted, | 78 const scoped_refptr<media::DecoderBuffer>& encrypted, |
60 const DecryptCB& decrypt_cb) { | 79 const DecryptCB& decrypt_cb) { |
80 DVLOG(1) << "Decrypt()"; | |
61 DCHECK(cdm_plugin_); | 81 DCHECK(cdm_plugin_); |
62 // TODO(xhwang): Enable the following once we have updated PluginInstance. | 82 |
63 // TODO(xhwang): Need to figure out thread safety about PPP calls. | 83 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
64 // if (!cdm_plugin_->Decrypt( | 84 render_loop_proxy_->PostTask(FROM_HERE, base::Bind(&PpapiDecryptor::Decrypt, |
65 // encrypted, base::Bind(&PpapiDecryptor::DataReady, this, decrypt_cb))) { | 85 base::Unretained(this), |
66 // decrypt_cb.Run(kError, NULL); | 86 encrypted, decrypt_cb)); |
67 // } | 87 return; |
88 } | |
89 | |
90 cdm_plugin_->Decrypt(encrypted, base::Bind(&PpapiDecryptor::DataReady, | |
91 base::Unretained(this), | |
92 decrypt_cb)); | |
93 | |
94 // TODO(xhwang): This is a hack only for testing purpose. | |
95 for (int i = 0; i < 4; ++i ) { | |
96 cdm_plugin_->Decrypt(encrypted, base::Bind(&PpapiDecryptor::DataReady, | |
97 base::Unretained(this), | |
98 DecryptCB())); | |
99 } | |
68 } | 100 } |
69 | 101 |
70 void PpapiDecryptor::Stop() { | 102 void PpapiDecryptor::Stop() { |
71 } | 103 } |
72 | 104 |
73 void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, | 105 void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, |
74 const uint8* data, int data_size ) { | 106 void* data, int data_size ) { |
107 DVLOG(1) << "DataReady()"; | |
108 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | |
109 | |
110 // TODO(xhwang): This is a hack only for testing purpose. | |
111 if (decrypt_cb.is_null()) | |
112 return; | |
113 | |
114 if (!data || !data_size) { | |
115 decrypt_cb.Run(kError, NULL); | |
116 return; | |
117 } | |
118 | |
119 scoped_refptr<media::DecoderBuffer> decrypted_data = | |
120 media::DecoderBuffer::CopyFrom(reinterpret_cast<const uint8*>(data), | |
121 data_size); | |
75 DCHECK(!decrypt_cb.is_null()); | 122 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); | 123 decrypt_cb.Run(kSuccess, decrypted_data); |
79 } | 124 } |
80 | 125 |
81 } // namespace webkit_media | 126 } // namespace webkit_media |
OLD | NEW |