| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_decryptor_service.h" | 5 #include "media/mojo/services/mojo_decryptor_service.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "media/base/audio_decoder_config.h" | 12 #include "media/base/audio_decoder_config.h" |
| 13 #include "media/base/cdm_context.h" | 13 #include "media/base/cdm_context.h" |
| 14 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
| 15 #include "media/base/decryptor.h" | 15 #include "media/base/decryptor.h" |
| 16 #include "media/base/media_keys.h" | 16 #include "media/base/media_keys.h" |
| 17 #include "media/base/video_decoder_config.h" | 17 #include "media/base/video_decoder_config.h" |
| 18 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
| 19 #include "media/mojo/interfaces/demuxer_stream.mojom.h" | 19 #include "media/mojo/interfaces/demuxer_stream.mojom.h" |
| 20 #include "media/mojo/services/media_type_converters.h" | 20 #include "media/mojo/services/media_type_converters.h" |
| 21 | 21 |
| 22 namespace media { | 22 namespace media { |
| 23 | 23 |
| 24 MojoDecryptorService::MojoDecryptorService( | 24 MojoDecryptorService::MojoDecryptorService( |
| 25 const scoped_refptr<MediaKeys>& cdm, | 25 const scoped_refptr<MediaKeys>& cdm, |
| 26 mojo::InterfaceRequest<interfaces::Decryptor> request, | 26 mojo::InterfaceRequest<interfaces::Decryptor> request, |
| 27 const mojo::Closure& error_handler) | 27 const mojo::Closure& error_handler) |
| 28 : binding_(this, request.Pass()), cdm_(cdm), weak_factory_(this) { | 28 : binding_(this, std::move(request)), cdm_(cdm), weak_factory_(this) { |
| 29 decryptor_ = cdm->GetCdmContext()->GetDecryptor(); | 29 decryptor_ = cdm->GetCdmContext()->GetDecryptor(); |
| 30 DCHECK(decryptor_); | 30 DCHECK(decryptor_); |
| 31 weak_this_ = weak_factory_.GetWeakPtr(); | 31 weak_this_ = weak_factory_.GetWeakPtr(); |
| 32 binding_.set_connection_error_handler(error_handler); | 32 binding_.set_connection_error_handler(error_handler); |
| 33 } | 33 } |
| 34 | 34 |
| 35 MojoDecryptorService::~MojoDecryptorService() {} | 35 MojoDecryptorService::~MojoDecryptorService() {} |
| 36 | 36 |
| 37 void MojoDecryptorService::Initialize( | 37 void MojoDecryptorService::Initialize( |
| 38 mojo::ScopedDataPipeConsumerHandle receive_pipe, | 38 mojo::ScopedDataPipeConsumerHandle receive_pipe, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 141 } |
| 142 | 142 |
| 143 void MojoDecryptorService::OnAudioDecoded( | 143 void MojoDecryptorService::OnAudioDecoded( |
| 144 const DecryptAndDecodeAudioCallback& callback, | 144 const DecryptAndDecodeAudioCallback& callback, |
| 145 media::Decryptor::Status status, | 145 media::Decryptor::Status status, |
| 146 const media::Decryptor::AudioFrames& frames) { | 146 const media::Decryptor::AudioFrames& frames) { |
| 147 DVLOG(status != media::Decryptor::kSuccess ? 1 : 3) << __FUNCTION__ << "(" | 147 DVLOG(status != media::Decryptor::kSuccess ? 1 : 3) << __FUNCTION__ << "(" |
| 148 << status << ")"; | 148 << status << ")"; |
| 149 mojo::Array<interfaces::AudioBufferPtr> audio_buffers; | 149 mojo::Array<interfaces::AudioBufferPtr> audio_buffers; |
| 150 for (const auto& frame : frames) | 150 for (const auto& frame : frames) |
| 151 audio_buffers.push_back(interfaces::AudioBuffer::From(frame).Pass()); | 151 audio_buffers.push_back(interfaces::AudioBuffer::From(frame)); |
| 152 | 152 |
| 153 callback.Run(static_cast<Decryptor::Status>(status), audio_buffers.Pass()); | 153 callback.Run(static_cast<Decryptor::Status>(status), |
| 154 std::move(audio_buffers)); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void MojoDecryptorService::OnVideoDecoded( | 157 void MojoDecryptorService::OnVideoDecoded( |
| 157 const DecryptAndDecodeVideoCallback& callback, | 158 const DecryptAndDecodeVideoCallback& callback, |
| 158 media::Decryptor::Status status, | 159 media::Decryptor::Status status, |
| 159 const scoped_refptr<VideoFrame>& frame) { | 160 const scoped_refptr<VideoFrame>& frame) { |
| 160 DVLOG(status != media::Decryptor::kSuccess ? 1 : 3) << __FUNCTION__ << "(" | 161 DVLOG(status != media::Decryptor::kSuccess ? 1 : 3) << __FUNCTION__ << "(" |
| 161 << status << ")"; | 162 << status << ")"; |
| 162 if (!frame) { | 163 if (!frame) { |
| 163 DCHECK_NE(status, media::Decryptor::kSuccess); | 164 DCHECK_NE(status, media::Decryptor::kSuccess); |
| 164 callback.Run(static_cast<Decryptor::Status>(status), nullptr); | 165 callback.Run(static_cast<Decryptor::Status>(status), nullptr); |
| 165 return; | 166 return; |
| 166 } | 167 } |
| 167 | 168 |
| 168 callback.Run(static_cast<Decryptor::Status>(status), | 169 callback.Run(static_cast<Decryptor::Status>(status), |
| 169 interfaces::VideoFrame::From(frame).Pass()); | 170 interfaces::VideoFrame::From(frame)); |
| 170 } | 171 } |
| 171 | 172 |
| 172 interfaces::DecoderBufferPtr MojoDecryptorService::TransferDecoderBuffer( | 173 interfaces::DecoderBufferPtr MojoDecryptorService::TransferDecoderBuffer( |
| 173 const scoped_refptr<DecoderBuffer>& encrypted) { | 174 const scoped_refptr<DecoderBuffer>& encrypted) { |
| 174 interfaces::DecoderBufferPtr buffer = | 175 interfaces::DecoderBufferPtr buffer = |
| 175 interfaces::DecoderBuffer::From(encrypted); | 176 interfaces::DecoderBuffer::From(encrypted); |
| 176 if (encrypted->end_of_stream()) | 177 if (encrypted->end_of_stream()) |
| 177 return buffer; | 178 return buffer; |
| 178 | 179 |
| 179 // Serialize the data section of the DecoderBuffer into our pipe. | 180 // Serialize the data section of the DecoderBuffer into our pipe. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 197 uint32_t num_bytes = media_buffer->data_size(); | 198 uint32_t num_bytes = media_buffer->data_size(); |
| 198 DCHECK_GT(num_bytes, 0u); | 199 DCHECK_GT(num_bytes, 0u); |
| 199 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), | 200 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), |
| 200 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 201 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
| 201 MOJO_RESULT_OK); | 202 MOJO_RESULT_OK); |
| 202 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); | 203 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); |
| 203 return media_buffer; | 204 return media_buffer; |
| 204 } | 205 } |
| 205 | 206 |
| 206 } // namespace media | 207 } // namespace media |
| OLD | NEW |