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

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: a lot of change, need to be reviewed again 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()";
ddorwin 2012/10/13 01:40:28 Do we have level 1 logs in Proxydecryptor or somet
xhwang 2012/10/15 19:53:01 We have a level 1 log in ReportFailureToCallPlugin
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 // TODO(xhwang): Implement CancelDecrypt() in PluginInstance and call it here. 109 // TODO(xhwang): Implement CancelDecrypt() in PluginInstance and call it here.
109 } 110 }
110 111
111 void PpapiDecryptor::InitializeVideoDecoder( 112 void PpapiDecryptor::InitializeVideoDecoder(
112 scoped_ptr<media::VideoDecoderConfig> config, 113 scoped_ptr<media::VideoDecoderConfig> config,
113 const DecoderInitCB& init_cb, 114 const DecoderInitCB& init_cb,
114 const KeyAddedCB& key_added_cb) { 115 const KeyAddedCB& key_added_cb) {
115 if (!render_loop_proxy_->BelongsToCurrentThread()) { 116 if (!render_loop_proxy_->BelongsToCurrentThread()) {
116 render_loop_proxy_->PostTask( 117 render_loop_proxy_->PostTask(
117 FROM_HERE, 118 FROM_HERE,
118 base::Bind(&PpapiDecryptor::InitializeVideoDecoder, 119 base::Bind(&PpapiDecryptor::InitializeVideoDecoder,
119 base::Unretained(this), base::Passed(&config), 120 base::Unretained(this), base::Passed(&config),
120 init_cb, key_added_cb)); 121 init_cb, key_added_cb));
121 return; 122 return;
122 } 123 }
123 124
124 DVLOG(1) << "InitializeVideoDecoder()"; 125 DVLOG(2) << "InitializeVideoDecoder()";
125 DCHECK(config->is_encrypted()); 126 DCHECK(config->is_encrypted());
126 DCHECK(config->IsValidConfig()); 127 DCHECK(config->IsValidConfig());
127 128
129 video_decoder_init_cb_ = init_cb;
128 key_added_cb_ = key_added_cb; 130 key_added_cb_ = key_added_cb;
129 131
130 // TODO(xhwang): Enable this once PluginInstance is updated. 132 if (!cdm_plugin_->InitializeVideoDecoder(
131 // if (!cdm_plugin_->InitializeVideoDecoder(video_config.Pass(), init_cb)) 133 *config,
132 // init_cb.Run(false); 134 base::Bind(&PpapiDecryptor::OnVideoDecoderInitialized,
133 init_cb.Run(false); 135 base::Unretained(this)))) {
136 key_added_cb_.Reset();
137 base::ResetAndReturn(&video_decoder_init_cb_).Run(false);
138 return;
139 }
134 } 140 }
135 141
136 void PpapiDecryptor::DecryptAndDecodeVideo( 142 void PpapiDecryptor::DecryptAndDecodeVideo(
137 const scoped_refptr<media::DecoderBuffer>& encrypted, 143 const scoped_refptr<media::DecoderBuffer>& encrypted,
138 const VideoDecodeCB& video_decode_cb) { 144 const VideoDecodeCB& video_decode_cb) {
139 if (!render_loop_proxy_->BelongsToCurrentThread()) { 145 if (!render_loop_proxy_->BelongsToCurrentThread()) {
140 render_loop_proxy_->PostTask( 146 render_loop_proxy_->PostTask(
141 FROM_HERE, 147 FROM_HERE,
142 base::Bind(&PpapiDecryptor::DecryptAndDecodeVideo, 148 base::Bind(&PpapiDecryptor::DecryptAndDecodeVideo,
143 base::Unretained(this), encrypted, video_decode_cb)); 149 base::Unretained(this), encrypted, video_decode_cb));
144 return; 150 return;
145 } 151 }
146 152
147 DVLOG(1) << "DecryptAndDecodeVideo()"; 153 DVLOG(3) << "DecryptAndDecodeVideo()";
148 // TODO(xhwang): Enable this once PluginInstance is updated. 154 if (!cdm_plugin_->DecryptAndDecode(encrypted, video_decode_cb))
149 // if (!cdm_plugin_->DecryptAndDecodeVideo(encrypted, video_decode_cb)) 155 video_decode_cb.Run(kError, NULL);
150 // video_decode_cb.Run(kError, NULL);
151 NOTIMPLEMENTED();
152 video_decode_cb.Run(kError, NULL);
153 } 156 }
154 157
155 void PpapiDecryptor::CancelDecryptAndDecodeVideo() { 158 void PpapiDecryptor::CancelDecryptAndDecodeVideo() {
ddorwin 2012/10/13 01:40:28 Should this be CancelVideoDecode() or eventually C
xhwang 2012/10/15 19:53:01 Yes, I plan to rename it to ResetDecoder(type) whe
156 DVLOG(1) << "CancelDecryptAndDecodeVideo()"; 159 if (!render_loop_proxy_->BelongsToCurrentThread()) {
157 // TODO(xhwang): Implement CancelDecryptAndDecodeVideo() in PluginInstance 160 render_loop_proxy_->PostTask(
158 // and call it here. 161 FROM_HERE,
159 NOTIMPLEMENTED(); 162 base::Bind(&PpapiDecryptor::CancelDecryptAndDecodeVideo,
163 base::Unretained(this)));
164 return;
165 }
166
167 DVLOG(2) << "CancelDecryptAndDecodeVideo()";
168 cdm_plugin_->ResetDecoder();
ddorwin 2012/10/13 01:40:28 When we have audio, this will reset both. Is that
xhwang 2012/10/15 19:53:01 ResetDecoder will take a StreamType param later.
160 } 169 }
161 170
162 void PpapiDecryptor::StopVideoDecoder() { 171 void PpapiDecryptor::StopVideoDecoder() {
ddorwin 2012/10/13 01:40:28 same here for both of the above.
xhwang 2012/10/15 19:53:01 ditto
163 DVLOG(1) << "StopVideoDecoder()"; 172 if (!render_loop_proxy_->BelongsToCurrentThread()) {
164 // TODO(xhwang): Implement StopVideoDecoder() in PluginInstance 173 render_loop_proxy_->PostTask(
165 // and call it here. 174 FROM_HERE,
166 NOTIMPLEMENTED(); 175 base::Bind(&PpapiDecryptor::StopVideoDecoder, base::Unretained(this)));
176 return;
177 }
178
179 DVLOG(2) << "StopVideoDecoder()";
180 cdm_plugin_->DeinitializeDecoder();
167 } 181 }
168 182
169 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, 183 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system,
170 const std::string& session_id) { 184 const std::string& session_id) {
171 DVLOG(1) << "Failed to call plugin."; 185 DVLOG(1) << "Failed to call plugin.";
172 client_->KeyError(key_system, session_id, kUnknownError, 0); 186 client_->KeyError(key_system, session_id, kUnknownError, 0);
173 } 187 }
174 188
189 void PpapiDecryptor::OnVideoDecoderInitialized(bool success) {
190 DCHECK(!key_added_cb_.is_null());
191 DCHECK(!video_decoder_init_cb_.is_null());
192
193 if (!success)
194 key_added_cb_.Reset();
195
196 base::ResetAndReturn(&video_decoder_init_cb_).Run(success);
197 }
198
175 } // namespace webkit_media 199 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698