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

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

Issue 11144036: Update Decryptor interface to support audio decoding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove leftover unretained 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 | Annotate | Revision Log
« no previous file with comments | « webkit/media/crypto/ppapi_decryptor.h ('k') | webkit/media/crypto/proxy_decryptor.h » ('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> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "media/base/audio_decoder_config.h"
15 #include "media/base/decoder_buffer.h" 16 #include "media/base/decoder_buffer.h"
16 #include "media/base/decryptor_client.h" 17 #include "media/base/decryptor_client.h"
17 #include "media/base/video_decoder_config.h" 18 #include "media/base/video_decoder_config.h"
18 #include "media/base/video_frame.h" 19 #include "media/base/video_frame.h"
19 #include "webkit/media/crypto/key_systems.h" 20 #include "webkit/media/crypto/key_systems.h"
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
21 22
22 namespace webkit_media { 23 namespace webkit_media {
23 24
24 PpapiDecryptor::PpapiDecryptor( 25 PpapiDecryptor::PpapiDecryptor(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 DCHECK(cdm_plugin_); 69 DCHECK(cdm_plugin_);
69 70
70 if (!cdm_plugin_->AddKey(session_id, 71 if (!cdm_plugin_->AddKey(session_id,
71 std::string(reinterpret_cast<const char*>(key), 72 std::string(reinterpret_cast<const char*>(key),
72 key_length), 73 key_length),
73 std::string(reinterpret_cast<const char*>(init_data), 74 std::string(reinterpret_cast<const char*>(init_data),
74 init_data_length))) { 75 init_data_length))) {
75 ReportFailureToCallPlugin(key_system, session_id); 76 ReportFailureToCallPlugin(key_system, session_id);
76 } 77 }
77 78
78 if (!key_added_cb_.is_null()) 79 if (!audio_key_added_cb_.is_null())
79 key_added_cb_.Run(); 80 audio_key_added_cb_.Run();
81
82 if (!video_key_added_cb_.is_null())
83 video_key_added_cb_.Run();
80 } 84 }
81 85
82 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, 86 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system,
83 const std::string& session_id) { 87 const std::string& session_id) {
84 DVLOG(2) << "CancelKeyRequest()"; 88 DVLOG(2) << "CancelKeyRequest()";
85 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 89 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
86 DCHECK(cdm_plugin_); 90 DCHECK(cdm_plugin_);
87 91
88 if (!cdm_plugin_->CancelKeyRequest(session_id)) 92 if (!cdm_plugin_->CancelKeyRequest(session_id))
89 ReportFailureToCallPlugin(key_system, session_id); 93 ReportFailureToCallPlugin(key_system, session_id);
90 } 94 }
91 95
92 void PpapiDecryptor::Decrypt( 96 void PpapiDecryptor::Decrypt(
97 StreamType stream_type,
93 const scoped_refptr<media::DecoderBuffer>& encrypted, 98 const scoped_refptr<media::DecoderBuffer>& encrypted,
94 const DecryptCB& decrypt_cb) { 99 const DecryptCB& decrypt_cb) {
95 if (!render_loop_proxy_->BelongsToCurrentThread()) { 100 if (!render_loop_proxy_->BelongsToCurrentThread()) {
96 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( 101 render_loop_proxy_->PostTask(FROM_HERE, base::Bind(
97 &PpapiDecryptor::Decrypt, weak_this_, encrypted, decrypt_cb)); 102 &PpapiDecryptor::Decrypt, weak_this_,
103 stream_type, encrypted, decrypt_cb));
98 return; 104 return;
99 } 105 }
100 106
101 DVLOG(3) << "Decrypt()"; 107 DVLOG(3) << "Decrypt() - stream_type: " << stream_type;
102 if (!cdm_plugin_->Decrypt(encrypted, decrypt_cb)) 108 if (!cdm_plugin_->Decrypt(encrypted, decrypt_cb))
103 decrypt_cb.Run(kError, NULL); 109 decrypt_cb.Run(kError, NULL);
104 } 110 }
105 111
106 void PpapiDecryptor::CancelDecrypt() { 112 void PpapiDecryptor::CancelDecrypt(StreamType stream_type) {
107 DVLOG(1) << "CancelDecrypt()"; 113 DVLOG(1) << "CancelDecrypt() - stream_type: " << stream_type;
108 // TODO(xhwang): Implement CancelDecrypt() in PluginInstance and call it here. 114 // TODO(xhwang): Implement CancelDecrypt() in PluginInstance and call it here.
109 } 115 }
110 116
117 void PpapiDecryptor::InitializeAudioDecoder(
118 scoped_ptr<media::AudioDecoderConfig> config,
119 const DecoderInitCB& init_cb,
120 const KeyAddedCB& key_added_cb) {
121 if (!render_loop_proxy_->BelongsToCurrentThread()) {
122 render_loop_proxy_->PostTask(FROM_HERE, base::Bind(
123 &PpapiDecryptor::InitializeAudioDecoder, weak_this_,
124 base::Passed(&config), init_cb, key_added_cb));
125 return;
126 }
127
128 DVLOG(2) << "InitializeAudioDecoder()";
129 DCHECK(config->is_encrypted());
130 DCHECK(config->IsValidConfig());
131
132 audio_decoder_init_cb_ = init_cb;
133 // TODO(xhwang): Implement InitializeAudioDecoder() in PluginInstance and call
134 // it here.
135 NOTIMPLEMENTED();
136 #if 0
137 if (!cdm_plugin_->InitializeAudioDecoder(*config, base::Bind(
138 &PpapiDecryptor::OnDecoderInitialized, weak_this_,
139 kAudio, key_added_cb))) {
140 #endif
141 base::ResetAndReturn(&audio_decoder_init_cb_).Run(false);
142 #if 0
143 return;
144 }
145 #endif
146 }
147
111 void PpapiDecryptor::InitializeVideoDecoder( 148 void PpapiDecryptor::InitializeVideoDecoder(
112 scoped_ptr<media::VideoDecoderConfig> config, 149 scoped_ptr<media::VideoDecoderConfig> config,
113 const DecoderInitCB& init_cb, 150 const DecoderInitCB& init_cb,
114 const KeyAddedCB& key_added_cb) { 151 const KeyAddedCB& key_added_cb) {
115 if (!render_loop_proxy_->BelongsToCurrentThread()) { 152 if (!render_loop_proxy_->BelongsToCurrentThread()) {
116 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( 153 render_loop_proxy_->PostTask(FROM_HERE, base::Bind(
117 &PpapiDecryptor::InitializeVideoDecoder, weak_this_, 154 &PpapiDecryptor::InitializeVideoDecoder, weak_this_,
118 base::Passed(&config), init_cb, key_added_cb)); 155 base::Passed(&config), init_cb, key_added_cb));
119 return; 156 return;
120 } 157 }
121 158
122 DVLOG(2) << "InitializeVideoDecoder()"; 159 DVLOG(2) << "InitializeVideoDecoder()";
123 DCHECK(config->is_encrypted()); 160 DCHECK(config->is_encrypted());
124 DCHECK(config->IsValidConfig()); 161 DCHECK(config->IsValidConfig());
125 162
126 video_decoder_init_cb_ = init_cb; 163 video_decoder_init_cb_ = init_cb;
127 key_added_cb_ = key_added_cb; 164 if (!cdm_plugin_->InitializeVideoDecoder(*config, base::Bind(
128 165 &PpapiDecryptor::OnDecoderInitialized, weak_this_,
129 if (!cdm_plugin_->InitializeVideoDecoder( 166 kVideo, key_added_cb))) {
130 *config,
131 base::Bind(&PpapiDecryptor::OnVideoDecoderInitialized, weak_this_))) {
132 key_added_cb_.Reset();
133 base::ResetAndReturn(&video_decoder_init_cb_).Run(false); 167 base::ResetAndReturn(&video_decoder_init_cb_).Run(false);
134 return; 168 return;
135 } 169 }
136 } 170 }
137 171
172 void PpapiDecryptor::DecryptAndDecodeAudio(
173 const scoped_refptr<media::DecoderBuffer>& encrypted,
174 const AudioDecodeCB& audio_decode_cb) {
175 if (!render_loop_proxy_->BelongsToCurrentThread()) {
176 render_loop_proxy_->PostTask(FROM_HERE, base::Bind(
177 &PpapiDecryptor::DecryptAndDecodeAudio, weak_this_,
178 encrypted, audio_decode_cb));
179 return;
180 }
181
182 DVLOG(1) << "DecryptAndDecodeAudio()";
183 NOTIMPLEMENTED();
184 // TODO(xhwang): Enable this once PluginInstance is updated.
185 #if 0
186 if (!cdm_plugin_->DecryptAndDecodeAudio(encrypted, audio_decode_cb))
187 #endif
188 audio_decode_cb.Run(kError, AudioBuffers());
189 }
190
138 void PpapiDecryptor::DecryptAndDecodeVideo( 191 void PpapiDecryptor::DecryptAndDecodeVideo(
139 const scoped_refptr<media::DecoderBuffer>& encrypted, 192 const scoped_refptr<media::DecoderBuffer>& encrypted,
140 const VideoDecodeCB& video_decode_cb) { 193 const VideoDecodeCB& video_decode_cb) {
141 if (!render_loop_proxy_->BelongsToCurrentThread()) { 194 if (!render_loop_proxy_->BelongsToCurrentThread()) {
142 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( 195 render_loop_proxy_->PostTask(FROM_HERE, base::Bind(
143 &PpapiDecryptor::DecryptAndDecodeVideo, weak_this_, 196 &PpapiDecryptor::DecryptAndDecodeVideo, weak_this_,
144 encrypted, video_decode_cb)); 197 encrypted, video_decode_cb));
145 return; 198 return;
146 } 199 }
147 200
148 DVLOG(3) << "DecryptAndDecodeVideo()"; 201 DVLOG(3) << "DecryptAndDecodeVideo()";
149 if (!cdm_plugin_->DecryptAndDecode(encrypted, video_decode_cb)) 202 if (!cdm_plugin_->DecryptAndDecode(encrypted, video_decode_cb))
150 video_decode_cb.Run(kError, NULL); 203 video_decode_cb.Run(kError, NULL);
151 } 204 }
152 205
153 void PpapiDecryptor::CancelDecryptAndDecodeVideo() { 206 void PpapiDecryptor::ResetDecoder(StreamType stream_type) {
154 if (!render_loop_proxy_->BelongsToCurrentThread()) { 207 if (!render_loop_proxy_->BelongsToCurrentThread()) {
155 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( 208 render_loop_proxy_->PostTask(FROM_HERE, base::Bind(
156 &PpapiDecryptor::CancelDecryptAndDecodeVideo, weak_this_)); 209 &PpapiDecryptor::ResetDecoder, weak_this_, stream_type));
157 return; 210 return;
158 } 211 }
159 212
160 DVLOG(2) << "CancelDecryptAndDecodeVideo()"; 213 DVLOG(2) << "ResetDecoder() - stream_type: " << stream_type;
214 // TODO(xhwang): Support stream type in PluginInstance.
161 cdm_plugin_->ResetDecoder(); 215 cdm_plugin_->ResetDecoder();
162 } 216 }
163 217
164 void PpapiDecryptor::StopVideoDecoder() { 218 void PpapiDecryptor::DeinitializeDecoder(StreamType stream_type) {
165 if (!render_loop_proxy_->BelongsToCurrentThread()) { 219 if (!render_loop_proxy_->BelongsToCurrentThread()) {
166 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( 220 render_loop_proxy_->PostTask(FROM_HERE, base::Bind(
167 &PpapiDecryptor::StopVideoDecoder, weak_this_)); 221 &PpapiDecryptor::DeinitializeDecoder, weak_this_, stream_type));
168 return; 222 return;
169 } 223 }
170 DVLOG(2) << "StopVideoDecoder()"; 224 DVLOG(2) << "DeinitializeDecoder() - stream_type: " << stream_type;
225 // TODO(xhwang): Support stream type in PluginInstance.
171 cdm_plugin_->DeinitializeDecoder(); 226 cdm_plugin_->DeinitializeDecoder();
172 } 227 }
173 228
174 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, 229 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system,
175 const std::string& session_id) { 230 const std::string& session_id) {
176 DVLOG(1) << "Failed to call plugin."; 231 DVLOG(1) << "Failed to call plugin.";
177 client_->KeyError(key_system, session_id, kUnknownError, 0); 232 client_->KeyError(key_system, session_id, kUnknownError, 0);
178 } 233 }
179 234
180 void PpapiDecryptor::OnVideoDecoderInitialized(bool success) { 235 void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type,
181 DCHECK(!key_added_cb_.is_null()); 236 const KeyAddedCB& key_added_cb,
182 DCHECK(!video_decoder_init_cb_.is_null()); 237 bool success) {
238 DCHECK(!key_added_cb.is_null());
183 239
184 if (!success) 240 switch (stream_type) {
185 key_added_cb_.Reset(); 241 case kAudio:
242 DCHECK(audio_key_added_cb_.is_null());
243 DCHECK(!audio_decoder_init_cb_.is_null());
244 if (success)
245 audio_key_added_cb_ = key_added_cb;
246 base::ResetAndReturn(&audio_decoder_init_cb_).Run(success);
247 break;
186 248
187 base::ResetAndReturn(&video_decoder_init_cb_).Run(success); 249 case kVideo:
250 DCHECK(video_key_added_cb_.is_null());
251 DCHECK(!video_decoder_init_cb_.is_null());
252 if (success)
253 video_key_added_cb_ = key_added_cb;
254 base::ResetAndReturn(&video_decoder_init_cb_).Run(success);
255 break;
256
257 default:
258 NOTREACHED();
259 }
188 } 260 }
189 261
190 } // namespace webkit_media 262 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/crypto/ppapi_decryptor.h ('k') | webkit/media/crypto/proxy_decryptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698