Chromium Code Reviews| Index: webkit/media/crypto/ppapi_decryptor.cc |
| diff --git a/webkit/media/crypto/ppapi_decryptor.cc b/webkit/media/crypto/ppapi_decryptor.cc |
| index 5b049266b6528bfec0349ffd0f6ae7ad6b491718..b1b5181de21eff6f7edd2f69b41fd798333eb0b9 100644 |
| --- a/webkit/media/crypto/ppapi_decryptor.cc |
| +++ b/webkit/media/crypto/ppapi_decryptor.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/logging.h" |
| #include "base/message_loop.h" |
| #include "base/message_loop_proxy.h" |
| +#include "media/base/audio_decoder_config.h" |
| #include "media/base/decoder_buffer.h" |
| #include "media/base/decryptor_client.h" |
| #include "media/base/video_decoder_config.h" |
| @@ -73,8 +74,11 @@ void PpapiDecryptor::AddKey(const std::string& key_system, |
| ReportFailureToCallPlugin(key_system, session_id); |
| } |
| - if (!key_added_cb_.is_null()) |
| - key_added_cb_.Run(); |
| + if (!audio_key_added_cb_.is_null()) |
| + audio_key_added_cb_.Run(); |
| + |
| + if (!video_key_added_cb_.is_null()) |
| + video_key_added_cb_.Run(); |
| } |
| void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
| @@ -90,13 +94,14 @@ void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
| // TODO(xhwang): Remove Unretained in the following methods. |
| void PpapiDecryptor::Decrypt( |
| + StreamType stream_type, |
| const scoped_refptr<media::DecoderBuffer>& encrypted, |
| const DecryptCB& decrypt_cb) { |
| if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| render_loop_proxy_->PostTask( |
| FROM_HERE, |
| base::Bind(&PpapiDecryptor::Decrypt, base::Unretained(this), |
| - encrypted, decrypt_cb)); |
| + stream_type, encrypted, decrypt_cb)); |
| return; |
| } |
| @@ -105,11 +110,42 @@ void PpapiDecryptor::Decrypt( |
| decrypt_cb.Run(kError, NULL); |
| } |
| -void PpapiDecryptor::CancelDecrypt() { |
| +void PpapiDecryptor::CancelDecrypt(StreamType stream_type) { |
| DVLOG(1) << "CancelDecrypt()"; |
| // TODO(xhwang): Implement CancelDecrypt() in PluginInstance and call it here. |
| } |
| +void PpapiDecryptor::InitializeAudioDecoder( |
| + scoped_ptr<media::AudioDecoderConfig> config, |
| + const DecoderInitCB& init_cb, |
| + const KeyAddedCB& key_added_cb) { |
| + if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| + render_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&PpapiDecryptor::InitializeAudioDecoder, |
| + base::Unretained(this), base::Passed(&config), |
| + init_cb, key_added_cb)); |
| + return; |
| + } |
| + |
| + DVLOG(2) << "InitializeAudioDecoder()"; |
| + DCHECK(config->is_encrypted()); |
| + DCHECK(config->IsValidConfig()); |
| + |
| + audio_decoder_init_cb_ = init_cb; |
| + // TODO(xhwang): Implement InitializeAudioDecoder() in PluginInstance and call |
| + // it here. |
| + // if (!cdm_plugin_->InitializeAudioDecoder( |
| + // *config, |
| + // base::Bind(&PpapiDecryptor::OnDecoderInitialized, |
| + // base::Unretained(this), kAudio, key_added_cb))) { |
| + // base::ResetAndReturn(&audio_decoder_init_cb_).Run(false); |
|
ddorwin
2012/10/17 02:52:33
Uncomment this instead of 146? Then move 145 up to
xhwang
2012/10/17 22:29:06
Done.
|
| + // return; |
| + // } |
| + NOTIMPLEMENTED(); |
| + base::ResetAndReturn(&audio_decoder_init_cb_).Run(false); |
| +} |
| + |
| void PpapiDecryptor::InitializeVideoDecoder( |
| scoped_ptr<media::VideoDecoderConfig> config, |
| const DecoderInitCB& init_cb, |
| @@ -128,18 +164,34 @@ void PpapiDecryptor::InitializeVideoDecoder( |
| DCHECK(config->IsValidConfig()); |
| video_decoder_init_cb_ = init_cb; |
| - key_added_cb_ = key_added_cb; |
| - |
| if (!cdm_plugin_->InitializeVideoDecoder( |
| *config, |
| - base::Bind(&PpapiDecryptor::OnVideoDecoderInitialized, |
| - base::Unretained(this)))) { |
| - key_added_cb_.Reset(); |
| + base::Bind(&PpapiDecryptor::OnDecoderInitialized, |
| + base::Unretained(this), kVideo, key_added_cb))) { |
| base::ResetAndReturn(&video_decoder_init_cb_).Run(false); |
| return; |
| } |
| } |
| +void PpapiDecryptor::DecryptAndDecodeAudio( |
| + const scoped_refptr<media::DecoderBuffer>& encrypted, |
| + const AudioDecodeCB& audio_decode_cb) { |
| + if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| + render_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&PpapiDecryptor::DecryptAndDecodeAudio, |
| + base::Unretained(this), encrypted, audio_decode_cb)); |
| + return; |
| + } |
| + |
| + DVLOG(1) << "DecryptAndDecodeAudio()"; |
| + // TODO(xhwang): Enable this once PluginInstance is updated. |
| + // if (!cdm_plugin_->DecryptAndDecodeAudio(encrypted, audio_decode_cb)) |
| + // audio_decode_cb.Run(kError, NULL); |
|
ddorwin
2012/10/17 02:52:33
same.
And why does 192 have scoped_ptr instead of
xhwang
2012/10/17 22:29:06
It's not relevant now. But for your question, beca
|
| + NOTIMPLEMENTED(); |
| + audio_decode_cb.Run(kError, scoped_ptr<AudioBuffers>()); |
| +} |
| + |
| void PpapiDecryptor::DecryptAndDecodeVideo( |
| const scoped_refptr<media::DecoderBuffer>& encrypted, |
| const VideoDecodeCB& video_decode_cb) { |
| @@ -156,28 +208,29 @@ void PpapiDecryptor::DecryptAndDecodeVideo( |
| video_decode_cb.Run(kError, NULL); |
| } |
| -void PpapiDecryptor::CancelDecryptAndDecodeVideo() { |
| +void PpapiDecryptor::ResetDecoder(StreamType stream_type) { |
| if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| render_loop_proxy_->PostTask( |
| FROM_HERE, |
| - base::Bind(&PpapiDecryptor::CancelDecryptAndDecodeVideo, |
| - base::Unretained(this))); |
| + base::Bind(&PpapiDecryptor::ResetDecoder, |
| + base::Unretained(this), stream_type)); |
| return; |
| } |
| - DVLOG(2) << "CancelDecryptAndDecodeVideo()"; |
| + DVLOG(2) << "ResetDecoder()"; |
|
ddorwin
2012/10/17 07:16:05
Log stream_type throughout?
xhwang
2012/10/17 22:29:06
Done.
|
| cdm_plugin_->ResetDecoder(); |
|
ddorwin
2012/10/17 07:16:05
TODO: Add type param?
xhwang
2012/10/17 22:29:06
Done.
|
| } |
| -void PpapiDecryptor::StopVideoDecoder() { |
| +void PpapiDecryptor::DeinitializeDecoder(StreamType stream_type) { |
| if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| render_loop_proxy_->PostTask( |
| FROM_HERE, |
| - base::Bind(&PpapiDecryptor::StopVideoDecoder, base::Unretained(this))); |
| + base::Bind(&PpapiDecryptor::DeinitializeDecoder, |
| + base::Unretained(this), stream_type)); |
| return; |
| } |
| - DVLOG(2) << "StopVideoDecoder()"; |
| + DVLOG(2) << "DeinitializeDecoder()"; |
| cdm_plugin_->DeinitializeDecoder(); |
| } |
| @@ -187,14 +240,30 @@ void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, |
| client_->KeyError(key_system, session_id, kUnknownError, 0); |
| } |
| -void PpapiDecryptor::OnVideoDecoderInitialized(bool success) { |
| - DCHECK(!key_added_cb_.is_null()); |
| - DCHECK(!video_decoder_init_cb_.is_null()); |
| +void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type, |
| + const KeyAddedCB& key_added_cb, |
| + bool success) { |
| + DCHECK(!key_added_cb.is_null()); |
| + |
| + if (stream_type == kAudio) { |
|
ddorwin
2012/10/17 02:52:33
Should we use a switch?
xhwang
2012/10/17 22:29:06
Done.
|
| + DCHECK(audio_key_added_cb_.is_null()); |
| + DCHECK(!audio_decoder_init_cb_.is_null()); |
| + if (success) |
| + audio_key_added_cb_ = key_added_cb; |
| + base::ResetAndReturn(&audio_decoder_init_cb_).Run(success); |
| + return; |
| + } |
| - if (!success) |
| - key_added_cb_.Reset(); |
| + if (stream_type == kVideo) { |
| + DCHECK(video_key_added_cb_.is_null()); |
| + DCHECK(!video_decoder_init_cb_.is_null()); |
| + if (success) |
| + video_key_added_cb_ = key_added_cb; |
| + base::ResetAndReturn(&video_decoder_init_cb_).Run(success); |
| + return; |
| + } |
| - base::ResetAndReturn(&video_decoder_init_cb_).Run(success); |
| + NOTREACHED(); |
| } |
| } // namespace webkit_media |