| 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.h" | 5 #include "media/mojo/services/mojo_audio_decoder.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/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "media/base/audio_buffer.h" | 14 #include "media/base/audio_buffer.h" |
| 15 #include "media/base/cdm_context.h" | 15 #include "media/base/cdm_context.h" |
| 16 #include "media/mojo/common/media_type_converters.h" | 16 #include "media/mojo/common/media_type_converters.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 | 19 |
| 20 MojoAudioDecoder::MojoAudioDecoder( | 20 MojoAudioDecoder::MojoAudioDecoder( |
| 21 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 21 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 22 interfaces::AudioDecoderPtr remote_decoder) | 22 interfaces::AudioDecoderPtr remote_decoder) |
| 23 : task_runner_(task_runner), | 23 : task_runner_(task_runner), |
| 24 remote_decoder_(std::move(remote_decoder)), | 24 remote_decoder_info_(remote_decoder.PassInterface()), |
| 25 binding_(this), | 25 binding_(this), |
| 26 has_connection_error_(false), | 26 has_connection_error_(false), |
| 27 needs_bitstream_conversion_(false) { | 27 needs_bitstream_conversion_(false) { |
| 28 DVLOG(1) << __FUNCTION__; | 28 DVLOG(1) << __FUNCTION__; |
| 29 } | 29 } |
| 30 | 30 |
| 31 MojoAudioDecoder::~MojoAudioDecoder() { | 31 MojoAudioDecoder::~MojoAudioDecoder() { |
| 32 DVLOG(1) << __FUNCTION__; | 32 DVLOG(1) << __FUNCTION__; |
| 33 } | 33 } |
| 34 | 34 |
| 35 std::string MojoAudioDecoder::GetDisplayName() const { | 35 std::string MojoAudioDecoder::GetDisplayName() const { |
| 36 return "MojoAudioDecoder"; | 36 return "MojoAudioDecoder"; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void MojoAudioDecoder::Initialize(const AudioDecoderConfig& config, | 39 void MojoAudioDecoder::Initialize(const AudioDecoderConfig& config, |
| 40 CdmContext* cdm_context, | 40 CdmContext* cdm_context, |
| 41 const InitCB& init_cb, | 41 const InitCB& init_cb, |
| 42 const OutputCB& output_cb) { | 42 const OutputCB& output_cb) { |
| 43 DVLOG(1) << __FUNCTION__; | 43 DVLOG(1) << __FUNCTION__; |
| 44 DCHECK(task_runner_->BelongsToCurrentThread()); | 44 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 45 | 45 |
| 46 // Bind |remote_decoder_| to the |task_runner_|. |
| 47 remote_decoder_.Bind(std::move(remote_decoder_info_)); |
| 48 |
| 46 // Fail immediately if the stream is encrypted but |cdm_context| is invalid. | 49 // Fail immediately if the stream is encrypted but |cdm_context| is invalid. |
| 47 int cdm_id = (config.is_encrypted() && cdm_context) | 50 int cdm_id = (config.is_encrypted() && cdm_context) |
| 48 ? cdm_context->GetCdmId() | 51 ? cdm_context->GetCdmId() |
| 49 : CdmContext::kInvalidCdmId; | 52 : CdmContext::kInvalidCdmId; |
| 50 | 53 |
| 51 if (config.is_encrypted() && CdmContext::kInvalidCdmId == cdm_id) { | 54 if (config.is_encrypted() && CdmContext::kInvalidCdmId == cdm_id) { |
| 52 task_runner_->PostTask(FROM_HERE, base::Bind(init_cb, false)); | 55 task_runner_->PostTask(FROM_HERE, base::Bind(init_cb, false)); |
| 53 return; | 56 return; |
| 54 } | 57 } |
| 55 | 58 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); | 224 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); |
| 222 DCHECK_GT(num_bytes, 0u); | 225 DCHECK_GT(num_bytes, 0u); |
| 223 CHECK_EQ(WriteDataRaw(producer_handle_.get(), media_buffer->data(), | 226 CHECK_EQ(WriteDataRaw(producer_handle_.get(), media_buffer->data(), |
| 224 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 227 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
| 225 MOJO_RESULT_OK); | 228 MOJO_RESULT_OK); |
| 226 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); | 229 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); |
| 227 return buffer; | 230 return buffer; |
| 228 } | 231 } |
| 229 | 232 |
| 230 } // namespace media | 233 } // namespace media |
| OLD | NEW |