| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "media/mojo/services/mojo_audio_decoder_service.h" | 5 #include "media/mojo/services/mojo_audio_decoder_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/base/cdm_context.h" | 10 #include "media/base/cdm_context.h" |
| 11 #include "media/base/media_keys.h" | 11 #include "media/base/content_decryption_module.h" |
| 12 #include "media/mojo/common/media_type_converters.h" | 12 #include "media/mojo/common/media_type_converters.h" |
| 13 #include "media/mojo/common/mojo_decoder_buffer_converter.h" | 13 #include "media/mojo/common/mojo_decoder_buffer_converter.h" |
| 14 #include "media/mojo/services/mojo_cdm_service_context.h" | 14 #include "media/mojo/services/mojo_cdm_service_context.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 MojoAudioDecoderService::MojoAudioDecoderService( | 18 MojoAudioDecoderService::MojoAudioDecoderService( |
| 19 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, | 19 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, |
| 20 std::unique_ptr<media::AudioDecoder> decoder) | 20 std::unique_ptr<media::AudioDecoder> decoder) |
| 21 : mojo_cdm_service_context_(mojo_cdm_service_context), | 21 : mojo_cdm_service_context_(mojo_cdm_service_context), |
| 22 decoder_(std::move(decoder)), | 22 decoder_(std::move(decoder)), |
| 23 weak_factory_(this) { | 23 weak_factory_(this) { |
| 24 weak_this_ = weak_factory_.GetWeakPtr(); | 24 weak_this_ = weak_factory_.GetWeakPtr(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 MojoAudioDecoderService::~MojoAudioDecoderService() {} | 27 MojoAudioDecoderService::~MojoAudioDecoderService() {} |
| 28 | 28 |
| 29 void MojoAudioDecoderService::Initialize( | 29 void MojoAudioDecoderService::Initialize( |
| 30 mojom::AudioDecoderClientAssociatedPtrInfo client, | 30 mojom::AudioDecoderClientAssociatedPtrInfo client, |
| 31 mojom::AudioDecoderConfigPtr config, | 31 mojom::AudioDecoderConfigPtr config, |
| 32 int32_t cdm_id, | 32 int32_t cdm_id, |
| 33 const InitializeCallback& callback) { | 33 const InitializeCallback& callback) { |
| 34 DVLOG(1) << __func__ << " " | 34 DVLOG(1) << __func__ << " " |
| 35 << config.To<media::AudioDecoderConfig>().AsHumanReadableString(); | 35 << config.To<media::AudioDecoderConfig>().AsHumanReadableString(); |
| 36 | 36 |
| 37 // Get CdmContext from cdm_id if the stream is encrypted. | 37 // Get CdmContext from cdm_id if the stream is encrypted. |
| 38 CdmContext* cdm_context = nullptr; | 38 CdmContext* cdm_context = nullptr; |
| 39 scoped_refptr<MediaKeys> cdm; | 39 scoped_refptr<ContentDecryptionModule> cdm; |
| 40 if (config.To<media::AudioDecoderConfig>().is_encrypted()) { | 40 if (config.To<media::AudioDecoderConfig>().is_encrypted()) { |
| 41 if (!mojo_cdm_service_context_) { | 41 if (!mojo_cdm_service_context_) { |
| 42 DVLOG(1) << "CDM service context not available."; | 42 DVLOG(1) << "CDM service context not available."; |
| 43 callback.Run(false, false); | 43 callback.Run(false, false); |
| 44 return; | 44 return; |
| 45 } | 45 } |
| 46 | 46 |
| 47 cdm = mojo_cdm_service_context_->GetCdm(cdm_id); | 47 cdm = mojo_cdm_service_context_->GetCdm(cdm_id); |
| 48 if (!cdm) { | 48 if (!cdm) { |
| 49 DVLOG(1) << "CDM not found for CDM id: " << cdm_id; | 49 DVLOG(1) << "CDM not found for CDM id: " << cdm_id; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 std::move(buffer), base::BindOnce(&MojoAudioDecoderService::OnReadDone, | 83 std::move(buffer), base::BindOnce(&MojoAudioDecoderService::OnReadDone, |
| 84 weak_this_, callback)); | 84 weak_this_, callback)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { | 87 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { |
| 88 DVLOG(1) << __func__; | 88 DVLOG(1) << __func__; |
| 89 decoder_->Reset( | 89 decoder_->Reset( |
| 90 base::Bind(&MojoAudioDecoderService::OnResetDone, weak_this_, callback)); | 90 base::Bind(&MojoAudioDecoderService::OnResetDone, weak_this_, callback)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void MojoAudioDecoderService::OnInitialized(const InitializeCallback& callback, | 93 void MojoAudioDecoderService::OnInitialized( |
| 94 scoped_refptr<MediaKeys> cdm, | 94 const InitializeCallback& callback, |
| 95 bool success) { | 95 scoped_refptr<ContentDecryptionModule> cdm, |
| 96 bool success) { |
| 96 DVLOG(1) << __func__ << " success:" << success; | 97 DVLOG(1) << __func__ << " success:" << success; |
| 97 | 98 |
| 98 if (success) { | 99 if (success) { |
| 99 cdm_ = cdm; | 100 cdm_ = cdm; |
| 100 callback.Run(success, decoder_->NeedsBitstreamConversion()); | 101 callback.Run(success, decoder_->NeedsBitstreamConversion()); |
| 101 } else { | 102 } else { |
| 102 // Do not call decoder_->NeedsBitstreamConversion() if init failed. | 103 // Do not call decoder_->NeedsBitstreamConversion() if init failed. |
| 103 callback.Run(false, false); | 104 callback.Run(false, false); |
| 104 } | 105 } |
| 105 } | 106 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 134 | 135 |
| 135 void MojoAudioDecoderService::OnAudioBufferReady( | 136 void MojoAudioDecoderService::OnAudioBufferReady( |
| 136 const scoped_refptr<AudioBuffer>& audio_buffer) { | 137 const scoped_refptr<AudioBuffer>& audio_buffer) { |
| 137 DVLOG(1) << __func__; | 138 DVLOG(1) << __func__; |
| 138 | 139 |
| 139 // TODO(timav): Use DataPipe. | 140 // TODO(timav): Use DataPipe. |
| 140 client_->OnBufferDecoded(mojom::AudioBuffer::From(audio_buffer)); | 141 client_->OnBufferDecoded(mojom::AudioBuffer::From(audio_buffer)); |
| 141 } | 142 } |
| 142 | 143 |
| 143 } // namespace media | 144 } // namespace media |
| OLD | NEW |