| 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/clients/mojo_video_decoder.h" | 5 #include "media/mojo/clients/mojo_video_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/unguessable_token.h" |
| 13 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
| 14 #include "media/base/demuxer_stream.h" | 15 #include "media/base/demuxer_stream.h" |
| 15 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
| 16 #include "media/mojo/common/media_type_converters.h" | 17 #include "media/mojo/common/media_type_converters.h" |
| 17 #include "media/mojo/common/mojo_decoder_buffer_converter.h" | 18 #include "media/mojo/common/mojo_decoder_buffer_converter.h" |
| 19 #include "media/mojo/interfaces/media_types.mojom.h" |
| 20 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 18 | 21 |
| 19 namespace media { | 22 namespace media { |
| 20 | 23 |
| 21 MojoVideoDecoder::MojoVideoDecoder( | 24 MojoVideoDecoder::MojoVideoDecoder( |
| 22 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 25 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 23 GpuVideoAcceleratorFactories* gpu_factories, | 26 GpuVideoAcceleratorFactories* gpu_factories, |
| 24 mojom::VideoDecoderPtr remote_decoder) | 27 mojom::VideoDecoderPtr remote_decoder) |
| 25 : task_runner_(task_runner), | 28 : task_runner_(task_runner), |
| 29 remote_decoder_info_(remote_decoder.PassInterface()), |
| 26 gpu_factories_(gpu_factories), | 30 gpu_factories_(gpu_factories), |
| 27 remote_decoder_info_(remote_decoder.PassInterface()), | |
| 28 client_binding_(this) { | 31 client_binding_(this) { |
| 29 (void)gpu_factories_; | |
| 30 DVLOG(1) << __func__; | 32 DVLOG(1) << __func__; |
| 31 } | 33 } |
| 32 | 34 |
| 33 MojoVideoDecoder::~MojoVideoDecoder() { | 35 MojoVideoDecoder::~MojoVideoDecoder() { |
| 34 DVLOG(1) << __func__; | 36 DVLOG(1) << __func__; |
| 35 Stop(); | 37 Stop(); |
| 36 } | 38 } |
| 37 | 39 |
| 38 std::string MojoVideoDecoder::GetDisplayName() const { | 40 std::string MojoVideoDecoder::GetDisplayName() const { |
| 39 // TODO(sandersd): Build the name including information from the remote end. | 41 // TODO(sandersd): Build the name including information from the remote end. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 175 |
| 174 // TODO(sandersd): Does this need its own error handler? | 176 // TODO(sandersd): Does this need its own error handler? |
| 175 mojom::VideoDecoderClientAssociatedPtrInfo client_ptr_info; | 177 mojom::VideoDecoderClientAssociatedPtrInfo client_ptr_info; |
| 176 client_binding_.Bind(&client_ptr_info, remote_decoder_.associated_group()); | 178 client_binding_.Bind(&client_ptr_info, remote_decoder_.associated_group()); |
| 177 | 179 |
| 178 // TODO(sandersd): Better buffer sizing. | 180 // TODO(sandersd): Better buffer sizing. |
| 179 mojo::ScopedDataPipeConsumerHandle remote_consumer_handle; | 181 mojo::ScopedDataPipeConsumerHandle remote_consumer_handle; |
| 180 mojo_decoder_buffer_writer_ = MojoDecoderBufferWriter::Create( | 182 mojo_decoder_buffer_writer_ = MojoDecoderBufferWriter::Create( |
| 181 DemuxerStream::VIDEO, &remote_consumer_handle); | 183 DemuxerStream::VIDEO, &remote_consumer_handle); |
| 182 | 184 |
| 185 media::mojom::CommandBufferIdPtr command_buffer_id; |
| 186 if (gpu_factories_) { |
| 187 base::UnguessableToken channel_token = gpu_factories_->GetChannelToken(); |
| 188 if (channel_token) { |
| 189 command_buffer_id = media::mojom::CommandBufferId::New(); |
| 190 command_buffer_id->channel_token = std::move(channel_token); |
| 191 command_buffer_id->route_id = gpu_factories_->GetCommandBufferRouteId(); |
| 192 } |
| 193 } |
| 194 |
| 183 remote_decoder_->Construct(std::move(client_ptr_info), | 195 remote_decoder_->Construct(std::move(client_ptr_info), |
| 184 std::move(remote_consumer_handle)); | 196 std::move(remote_consumer_handle), |
| 197 std::move(command_buffer_id)); |
| 185 } | 198 } |
| 186 | 199 |
| 187 void MojoVideoDecoder::Stop() { | 200 void MojoVideoDecoder::Stop() { |
| 188 DVLOG(2) << __func__; | 201 DVLOG(2) << __func__; |
| 189 DCHECK(task_runner_->BelongsToCurrentThread()); | 202 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 190 | 203 |
| 191 has_connection_error_ = true; | 204 has_connection_error_ = true; |
| 192 | 205 |
| 193 if (!init_cb_.is_null()) | 206 if (!init_cb_.is_null()) |
| 194 base::ResetAndReturn(&init_cb_).Run(false); | 207 base::ResetAndReturn(&init_cb_).Run(false); |
| 195 | 208 |
| 196 for (const auto& pending_decode : pending_decodes_) | 209 for (const auto& pending_decode : pending_decodes_) |
| 197 pending_decode.second.Run(DecodeStatus::DECODE_ERROR); | 210 pending_decode.second.Run(DecodeStatus::DECODE_ERROR); |
| 198 pending_decodes_.clear(); | 211 pending_decodes_.clear(); |
| 199 | 212 |
| 200 if (!reset_cb_.is_null()) | 213 if (!reset_cb_.is_null()) |
| 201 base::ResetAndReturn(&reset_cb_).Run(); | 214 base::ResetAndReturn(&reset_cb_).Run(); |
| 202 } | 215 } |
| 203 | 216 |
| 204 } // namespace media | 217 } // namespace media |
| OLD | NEW |