Chromium Code Reviews| Index: media/mojo/services/mojo_audio_decoder_service.cc |
| diff --git a/media/mojo/services/mojo_audio_decoder_service.cc b/media/mojo/services/mojo_audio_decoder_service.cc |
| index dbe72d17125d6f94638e2e6c285b246a2ff60720..05c8b3b3f1b3a4257b0a7316a82e50667e697fce 100644 |
| --- a/media/mojo/services/mojo_audio_decoder_service.cc |
| +++ b/media/mojo/services/mojo_audio_decoder_service.cc |
| @@ -8,14 +8,18 @@ |
| #include "base/bind_helpers.h" |
| #include "base/logging.h" |
| #include "media/base/cdm_context.h" |
| +#include "media/base/media_keys.h" |
| #include "media/mojo/common/media_type_converters.h" |
| +#include "media/mojo/services/mojo_cdm_service_context.h" |
| namespace media { |
| MojoAudioDecoderService::MojoAudioDecoderService( |
| + base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, |
| scoped_ptr<media::AudioDecoder> decoder, |
| mojo::InterfaceRequest<interfaces::AudioDecoder> request) |
| : binding_(this, std::move(request)), |
| + mojo_cdm_service_context_(mojo_cdm_service_context), |
| decoder_(std::move(decoder)), |
| weak_factory_(this) { |
| weak_this_ = weak_factory_.GetWeakPtr(); |
| @@ -31,21 +35,36 @@ void MojoAudioDecoderService::Initialize( |
| DVLOG(1) << __FUNCTION__ << " " |
| << config.To<media::AudioDecoderConfig>().AsHumanReadableString(); |
| - // Encrypted streams are not supported for now. |
| - if (config.To<media::AudioDecoderConfig>().is_encrypted() && |
| - cdm_id == CdmContext::kInvalidCdmId) { |
| - // The client should prevent this situation. |
| - NOTREACHED() << "Encrypted streams are not supported"; |
| - callback.Run(false, false); |
| - return; |
| + // Get CdmContext from cdm_id if the stream is encrypted. |
| + CdmContext* cdm_context = nullptr; |
| + if (config.To<media::AudioDecoderConfig>().is_encrypted()) { |
| + if (!mojo_cdm_service_context_) { |
| + DVLOG(1) << "CDM service context not available."; |
| + callback.Run(false, false); |
| + return; |
| + } |
| + |
| + scoped_refptr<MediaKeys> cdm = mojo_cdm_service_context_->GetCdm(cdm_id); |
| + if (!cdm) { |
| + DVLOG(1) << "CDM not found for CDM id: " << cdm_id; |
| + callback.Run(false, false); |
| + return; |
| + } |
| + |
| + cdm_context = cdm->GetCdmContext(); |
| + if (!cdm_context) { |
| + DVLOG(1) << "CDM context not available for CDM id: " << cdm_id; |
| + callback.Run(false, false); |
| + return; |
| + } |
| + |
| + cdm_ = cdm; |
|
Tima Vaisburd
2016/03/21 21:53:01
I can bind |cdm| to OnInitialized() instead, but d
xhwang
2016/03/21 22:31:23
Either way is fine. When you bind |cdm| into the c
Tima Vaisburd
2016/03/21 23:07:05
That you, I missed the fact that Bind() will hold
xhwang
2016/03/21 23:13:03
Yes, this often results in more elegant code. But
|
| } |
| client_ = std::move(client); |
| - // TODO(timav): Get CdmContext from cdm_id. |
| decoder_->Initialize( |
| - config.To<media::AudioDecoderConfig>(), |
| - nullptr, // no CdmContext |
| + config.To<media::AudioDecoderConfig>(), cdm_context, |
| base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback), |
| base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, weak_this_)); |
| } |
| @@ -73,6 +92,10 @@ void MojoAudioDecoderService::Reset(const ResetCallback& callback) { |
| void MojoAudioDecoderService::OnInitialized(const InitializeCallback& callback, |
| bool success) { |
| DVLOG(1) << __FUNCTION__ << " success:" << success; |
| + |
| + if (!success) |
| + cdm_ = nullptr; |
| + |
| callback.Run(success, decoder_->NeedsBitstreamConversion()); |
| } |