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

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

Issue 11091005: Update PluginInstance for decrypt-and-decode video. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix a bug in ppp_content_decryptor_private_proxy.cc Created 8 years, 2 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
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> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
13 #include "base/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
14 #include "media/base/decoder_buffer.h" 15 #include "media/base/decoder_buffer.h"
15 #include "media/base/decryptor_client.h" 16 #include "media/base/decryptor_client.h"
16 #include "media/base/video_decoder_config.h" 17 #include "media/base/video_decoder_config.h"
17 #include "media/base/video_frame.h" 18 #include "media/base/video_frame.h"
18 #include "webkit/media/crypto/key_systems.h" 19 #include "webkit/media/crypto/key_systems.h"
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
(...skipping 10 matching lines...) Expand all
30 DCHECK(cdm_plugin_); 31 DCHECK(cdm_plugin_);
31 cdm_plugin_->set_decrypt_client(client); 32 cdm_plugin_->set_decrypt_client(client);
32 } 33 }
33 34
34 PpapiDecryptor::~PpapiDecryptor() { 35 PpapiDecryptor::~PpapiDecryptor() {
35 } 36 }
36 37
37 bool PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, 38 bool PpapiDecryptor::GenerateKeyRequest(const std::string& key_system,
38 const uint8* init_data, 39 const uint8* init_data,
39 int init_data_length) { 40 int init_data_length) {
40 DVLOG(1) << "GenerateKeyRequest()"; 41 DVLOG(2) << "GenerateKeyRequest()";
41 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 42 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
42 DCHECK(cdm_plugin_); 43 DCHECK(cdm_plugin_);
43 44
44 // TODO(xhwang): Finalize the data type for |init_data| to avoid unnecessary 45 // TODO(xhwang): Finalize the data type for |init_data| to avoid unnecessary
45 // data type conversions. 46 // data type conversions.
46 if (!cdm_plugin_->GenerateKeyRequest( 47 if (!cdm_plugin_->GenerateKeyRequest(
47 key_system, 48 key_system,
48 std::string(reinterpret_cast<const char*>(init_data), 49 std::string(reinterpret_cast<const char*>(init_data),
49 init_data_length))) { 50 init_data_length))) {
50 ReportFailureToCallPlugin(key_system, ""); 51 ReportFailureToCallPlugin(key_system, "");
51 return false; 52 return false;
52 } 53 }
53 54
54 return true; 55 return true;
55 } 56 }
56 57
57 void PpapiDecryptor::AddKey(const std::string& key_system, 58 void PpapiDecryptor::AddKey(const std::string& key_system,
58 const uint8* key, 59 const uint8* key,
59 int key_length, 60 int key_length,
60 const uint8* init_data, 61 const uint8* init_data,
61 int init_data_length, 62 int init_data_length,
62 const std::string& session_id) { 63 const std::string& session_id) {
63 DVLOG(1) << "AddKey()"; 64 DVLOG(2) << "AddKey()";
64 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 65 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
65 DCHECK(cdm_plugin_); 66 DCHECK(cdm_plugin_);
66 67
67 if (!cdm_plugin_->AddKey(session_id, 68 if (!cdm_plugin_->AddKey(session_id,
68 std::string(reinterpret_cast<const char*>(key), 69 std::string(reinterpret_cast<const char*>(key),
69 key_length), 70 key_length),
70 std::string(reinterpret_cast<const char*>(init_data), 71 std::string(reinterpret_cast<const char*>(init_data),
71 init_data_length))) { 72 init_data_length))) {
72 ReportFailureToCallPlugin(key_system, session_id); 73 ReportFailureToCallPlugin(key_system, session_id);
73 } 74 }
74 75
75 if (!key_added_cb_.is_null()) 76 if (!key_added_cb_.is_null())
76 key_added_cb_.Run(); 77 key_added_cb_.Run();
77 } 78 }
78 79
79 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, 80 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system,
80 const std::string& session_id) { 81 const std::string& session_id) {
81 DVLOG(1) << "CancelKeyRequest()"; 82 DVLOG(2) << "CancelKeyRequest()";
82 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 83 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
83 DCHECK(cdm_plugin_); 84 DCHECK(cdm_plugin_);
84 85
85 if (!cdm_plugin_->CancelKeyRequest(session_id)) 86 if (!cdm_plugin_->CancelKeyRequest(session_id))
86 ReportFailureToCallPlugin(key_system, session_id); 87 ReportFailureToCallPlugin(key_system, session_id);
87 } 88 }
88 89
89 // TODO(xhwang): Remove Unretained in the following methods. 90 // TODO(xhwang): Remove Unretained in the following methods.
90 91
91 void PpapiDecryptor::Decrypt( 92 void PpapiDecryptor::Decrypt(
92 const scoped_refptr<media::DecoderBuffer>& encrypted, 93 const scoped_refptr<media::DecoderBuffer>& encrypted,
93 const DecryptCB& decrypt_cb) { 94 const DecryptCB& decrypt_cb) {
94 if (!render_loop_proxy_->BelongsToCurrentThread()) { 95 if (!render_loop_proxy_->BelongsToCurrentThread()) {
95 render_loop_proxy_->PostTask( 96 render_loop_proxy_->PostTask(
96 FROM_HERE, 97 FROM_HERE,
97 base::Bind(&PpapiDecryptor::Decrypt, base::Unretained(this), 98 base::Bind(&PpapiDecryptor::Decrypt, base::Unretained(this),
98 encrypted, decrypt_cb)); 99 encrypted, decrypt_cb));
99 return; 100 return;
100 } 101 }
101 102
102 DVLOG(1) << "Decrypt()"; 103 DVLOG(3) << "Decrypt()";
103 if (!cdm_plugin_->Decrypt(encrypted, decrypt_cb)) 104 if (!cdm_plugin_->Decrypt(encrypted, decrypt_cb))
104 decrypt_cb.Run(kError, NULL); 105 decrypt_cb.Run(kError, NULL);
105 } 106 }
106 107
107 void PpapiDecryptor::CancelDecrypt() { 108 void PpapiDecryptor::CancelDecrypt() {
108 DVLOG(1) << "CancelDecrypt()"; 109 DVLOG(1) << "CancelDecrypt()";
109 // TODO(xhwang): Implement CancelDecrypt() in PluginInstance and call it here. 110 // TODO(xhwang): Implement CancelDecrypt() in PluginInstance and call it here.
110 } 111 }
111 112
112 void PpapiDecryptor::InitializeVideoDecoder( 113 void PpapiDecryptor::InitializeVideoDecoder(
113 scoped_ptr<media::VideoDecoderConfig> config, 114 scoped_ptr<media::VideoDecoderConfig> config,
114 const DecoderInitCB& init_cb, 115 const DecoderInitCB& init_cb,
115 const KeyAddedCB& key_added_cb) { 116 const KeyAddedCB& key_added_cb) {
116 if (!render_loop_proxy_->BelongsToCurrentThread()) { 117 if (!render_loop_proxy_->BelongsToCurrentThread()) {
117 render_loop_proxy_->PostTask( 118 render_loop_proxy_->PostTask(
118 FROM_HERE, 119 FROM_HERE,
119 base::Bind(&PpapiDecryptor::InitializeVideoDecoder, 120 base::Bind(&PpapiDecryptor::InitializeVideoDecoder,
120 base::Unretained(this), base::Passed(&config), 121 base::Unretained(this), base::Passed(&config),
121 init_cb, key_added_cb)); 122 init_cb, key_added_cb));
122 return; 123 return;
123 } 124 }
124 125
125 DVLOG(1) << "InitializeVideoDecoder()"; 126 DVLOG(2) << "InitializeVideoDecoder()";
126 DCHECK(config->is_encrypted()); 127 DCHECK(config->is_encrypted());
127 DCHECK(config->IsValidConfig()); 128 DCHECK(config->IsValidConfig());
128 129
129 // TODO(xhwang): Enable this once PluginInstance is updated. 130 video_decoder_init_cb_ = init_cb;
130 // if (!cdm_plugin_->InitializeVideoDecoder(video_config.Pass(), init_cb)) 131 key_added_cb_ = key_added_cb;
131 { 132
132 init_cb.Run(false); 133 if (!cdm_plugin_->InitializeVideoDecoder(
134 *config,
135 base::Bind(&PpapiDecryptor::OnVideoDecoderInitialized,
136 base::Unretained(this)))) {
137 key_added_cb_.Reset();
138 base::ResetAndReturn(&video_decoder_init_cb_).Run(false);
133 return; 139 return;
134 } 140 }
135
136 key_added_cb_ = key_added_cb;
137 init_cb.Run(true);
138 } 141 }
139 142
140 void PpapiDecryptor::DecryptAndDecodeVideo( 143 void PpapiDecryptor::DecryptAndDecodeVideo(
141 const scoped_refptr<media::DecoderBuffer>& encrypted, 144 const scoped_refptr<media::DecoderBuffer>& encrypted,
142 const VideoDecodeCB& video_decode_cb) { 145 const VideoDecodeCB& video_decode_cb) {
143 if (!render_loop_proxy_->BelongsToCurrentThread()) { 146 if (!render_loop_proxy_->BelongsToCurrentThread()) {
144 render_loop_proxy_->PostTask( 147 render_loop_proxy_->PostTask(
145 FROM_HERE, 148 FROM_HERE,
146 base::Bind(&PpapiDecryptor::DecryptAndDecodeVideo, 149 base::Bind(&PpapiDecryptor::DecryptAndDecodeVideo,
147 base::Unretained(this), encrypted, video_decode_cb)); 150 base::Unretained(this), encrypted, video_decode_cb));
148 return; 151 return;
149 } 152 }
150 153
151 DVLOG(1) << "DecryptAndDecodeVideo()"; 154 DVLOG(3) << "DecryptAndDecodeVideo()";
152 // TODO(xhwang): Enable this once PluginInstance is updated. 155 if (!cdm_plugin_->DecryptAndDecode(encrypted, video_decode_cb))
153 // if (!cdm_plugin_->DecryptAndDecodeVideo(encrypted, video_decode_cb)) 156 video_decode_cb.Run(kError, NULL);
154 // video_decode_cb.Run(kError, NULL);
155 NOTIMPLEMENTED();
156 video_decode_cb.Run(kError, NULL);
157 } 157 }
158 158
159 void PpapiDecryptor::CancelDecryptAndDecodeVideo() { 159 void PpapiDecryptor::CancelDecryptAndDecodeVideo() {
160 DVLOG(1) << "CancelDecryptAndDecodeVideo()"; 160 if (!render_loop_proxy_->BelongsToCurrentThread()) {
161 // TODO(xhwang): Implement CancelDecryptAndDecodeVideo() in PluginInstance 161 render_loop_proxy_->PostTask(
162 // and call it here. 162 FROM_HERE,
163 NOTIMPLEMENTED(); 163 base::Bind(&PpapiDecryptor::CancelDecryptAndDecodeVideo,
164 base::Unretained(this)));
165 return;
166 }
167
168 DVLOG(2) << "CancelDecryptAndDecodeVideo()";
169 cdm_plugin_->ResetDecoder();
164 } 170 }
165 171
166 void PpapiDecryptor::StopVideoDecoder() { 172 void PpapiDecryptor::StopVideoDecoder() {
167 DVLOG(1) << "StopVideoDecoder()"; 173 if (!render_loop_proxy_->BelongsToCurrentThread()) {
168 // TODO(xhwang): Implement StopVideoDecoder() in PluginInstance 174 render_loop_proxy_->PostTask(
169 // and call it here. 175 FROM_HERE,
170 NOTIMPLEMENTED(); 176 base::Bind(&PpapiDecryptor::StopVideoDecoder, base::Unretained(this)));
177 return;
178 }
179
180 DVLOG(2) << "StopVideoDecoder()";
181 cdm_plugin_->DeinitializeDecoder();
171 } 182 }
172 183
173 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, 184 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system,
174 const std::string& session_id) { 185 const std::string& session_id) {
175 DVLOG(1) << "Failed to call plugin."; 186 DVLOG(1) << "Failed to call plugin.";
176 client_->KeyError(key_system, session_id, kUnknownError, 0); 187 client_->KeyError(key_system, session_id, kUnknownError, 0);
177 } 188 }
178 189
190 void PpapiDecryptor::OnVideoDecoderInitialized(bool success) {
191 DCHECK(!key_added_cb_.is_null());
192 DCHECK(!video_decoder_init_cb_.is_null());
193
194 if (!success)
195 key_added_cb_.Reset();
196
197 base::ResetAndReturn(&video_decoder_init_cb_).Run(success);
198 }
199
179 } // namespace webkit_media 200 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698