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

Side by Side Diff: webkit/media/crypto/ppapi_decryptor.cc

Issue 10871006: Connect PpapiDecryptor and PluginInstance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Avoid dependency on content. Created 8 years, 3 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 | « webkit/media/crypto/ppapi_decryptor.h ('k') | webkit/plugins/ppapi/DEPS » ('j') | no next file with comments »
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 #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"
8 #include "media/base/decoder_buffer.h" 14 #include "media/base/decoder_buffer.h"
9 #include "media/base/decryptor_client.h" 15 #include "media/base/decryptor_client.h"
10 #include "webkit/media/crypto/key_systems.h" 16 #include "webkit/media/crypto/key_systems.h"
11 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 17 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
12 18
13 namespace webkit_media { 19 namespace webkit_media {
14 20
15 PpapiDecryptor::PpapiDecryptor( 21 PpapiDecryptor::PpapiDecryptor(
16 media::DecryptorClient* client, 22 media::DecryptorClient* client,
17 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance) 23 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance)
18 : client_(client), 24 : client_(client),
19 cdm_plugin_(plugin_instance) { 25 cdm_plugin_(plugin_instance),
26 render_loop_proxy_(base::MessageLoopProxy::current()) {
27 DCHECK(client_);
28 DCHECK(cdm_plugin_);
29 cdm_plugin_->set_decrypt_client(client);
20 } 30 }
21 31
22 PpapiDecryptor::~PpapiDecryptor() { 32 PpapiDecryptor::~PpapiDecryptor() {
23 } 33 }
24 34
25 void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, 35 void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system,
26 const uint8* init_data, 36 const uint8* init_data,
27 int init_data_length) { 37 int init_data_length) {
38 DVLOG(1) << "GenerateKeyRequest()";
39 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
28 DCHECK(cdm_plugin_); 40 DCHECK(cdm_plugin_);
29 // TODO(xhwang): Enable the following once we have updated PluginInstance. 41
30 // if (!cdm_plugin_->GenerateKeyRequest(key_system, 42 if (!cdm_plugin_->GenerateKeyRequest(
31 // init_data, init_data_length)) { 43 key_system,
32 // client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); 44 std::string(reinterpret_cast<const char*>(init_data),
dmichael (off chromium) 2012/08/27 20:14:48 Could you add a TODO here about figuring out what
xhwang 2012/08/27 22:58:14 Done.
33 // } 45 init_data_length))) {
46 ReportFailureToCallPlugin(key_system, "");
47 }
34 } 48 }
35 49
36 void PpapiDecryptor::AddKey(const std::string& key_system, 50 void PpapiDecryptor::AddKey(const std::string& key_system,
37 const uint8* key, 51 const uint8* key,
38 int key_length, 52 int key_length,
39 const uint8* init_data, 53 const uint8* init_data,
40 int init_data_length, 54 int init_data_length,
41 const std::string& session_id) { 55 const std::string& session_id) {
56 DVLOG(1) << "AddKey()";
57 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
42 DCHECK(cdm_plugin_); 58 DCHECK(cdm_plugin_);
43 // TODO(xhwang): Enable the following once we have updated PluginInstance. 59
44 // if (!cdm_plugin_->AddKey(key_system, key, key_length, 60 if (!cdm_plugin_->AddKey(session_id,
45 // init_data, init_data_length, session_id)) { 61 std::string(reinterpret_cast<const char*>(key),
46 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); 62 key_length),
47 // } 63 std::string(reinterpret_cast<const char*>(init_data),
64 init_data_length))) {
65 ReportFailureToCallPlugin(key_system, session_id);
66 }
48 } 67 }
49 68
50 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, 69 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system,
51 const std::string& session_id) { 70 const std::string& session_id) {
71 DVLOG(1) << "CancelKeyRequest()";
72 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
52 DCHECK(cdm_plugin_); 73 DCHECK(cdm_plugin_);
53 // TODO(xhwang): Enable the following once we have updated PluginInstance. 74
54 // if (!cdm_plugin_->CancelKeyRequest(key_system, session_id)) 75 if (!cdm_plugin_->CancelKeyRequest(session_id))
55 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); 76 ReportFailureToCallPlugin(key_system, session_id);
56 } 77 }
57 78
58 void PpapiDecryptor::Decrypt( 79 void PpapiDecryptor::Decrypt(
59 const scoped_refptr<media::DecoderBuffer>& encrypted, 80 const scoped_refptr<media::DecoderBuffer>& encrypted,
60 const DecryptCB& decrypt_cb) { 81 const DecryptCB& decrypt_cb) {
61 DCHECK(cdm_plugin_); 82 DVLOG(1) << "Decrypt()";
62 // TODO(xhwang): Enable the following once we have updated PluginInstance. 83 if (!render_loop_proxy_->BelongsToCurrentThread()) {
63 // TODO(xhwang): Need to figure out thread safety about PPP calls. 84 render_loop_proxy_->PostTask(
64 // if (!cdm_plugin_->Decrypt( 85 FROM_HERE,
65 // encrypted, base::Bind(&PpapiDecryptor::DataReady, this, decrypt_cb))) { 86 base::Bind(&PpapiDecryptor::Decrypt, base::Unretained(this),
66 // decrypt_cb.Run(kError, NULL); 87 encrypted, decrypt_cb));
67 // } 88 return;
89 }
90
91 if (!cdm_plugin_->Decrypt(encrypted, decrypt_cb))
92 decrypt_cb.Run(kError, NULL);
68 } 93 }
69 94
70 void PpapiDecryptor::Stop() { 95 void PpapiDecryptor::Stop() {
71 } 96 }
72 97
73 void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, 98 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system,
74 const uint8* data, int data_size ) { 99 const std::string& session_id) {
75 DCHECK(!decrypt_cb.is_null()); 100 DVLOG(1) << "Failed to call plugin.";
76 scoped_refptr<media::DecoderBuffer> decrypted_data = 101 client_->KeyError(key_system, session_id, kUnknownError, 0);
77 media::DecoderBuffer::CopyFrom(data, data_size);
78 decrypt_cb.Run(kSuccess, decrypted_data);
79 } 102 }
80 103
81 } // namespace webkit_media 104 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/crypto/ppapi_decryptor.h ('k') | webkit/plugins/ppapi/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698