| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/gpu/media/media_channel.h" | |
| 6 | |
| 7 #include "content/common/gpu/gpu_channel.h" | |
| 8 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" | |
| 9 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" | |
| 10 #include "content/common/gpu/media/media_messages.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 void SendCreateJpegDecoderResult( | |
| 17 scoped_ptr<IPC::Message> reply_message, | |
| 18 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | |
| 19 base::WeakPtr<GpuChannel> channel, | |
| 20 scoped_refptr<GpuChannelMessageFilter> filter, | |
| 21 bool result) { | |
| 22 GpuChannelMsg_CreateJpegDecoder::WriteReplyParams(reply_message.get(), | |
| 23 result); | |
| 24 if (io_task_runner->BelongsToCurrentThread()) { | |
| 25 filter->Send(reply_message.release()); | |
| 26 } else if (channel) { | |
| 27 channel->Send(reply_message.release()); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 MediaChannel::MediaChannel(GpuChannel* channel) : channel_(channel) {} | |
| 34 | |
| 35 MediaChannel::~MediaChannel() {} | |
| 36 | |
| 37 bool MediaChannel::Send(IPC::Message* msg) { | |
| 38 return channel_->Send(msg); | |
| 39 } | |
| 40 | |
| 41 bool MediaChannel::OnMessageReceived(const IPC::Message& message) { | |
| 42 bool handled = true; | |
| 43 IPC_BEGIN_MESSAGE_MAP(MediaChannel, message) | |
| 44 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoDecoder, | |
| 45 OnCreateVideoDecoder) | |
| 46 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoEncoder, | |
| 47 OnCreateVideoEncoder) | |
| 48 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateJpegDecoder, | |
| 49 OnCreateJpegDecoder) | |
| 50 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 51 IPC_END_MESSAGE_MAP() | |
| 52 return handled; | |
| 53 } | |
| 54 | |
| 55 void MediaChannel::OnCreateJpegDecoder(int32_t route_id, | |
| 56 IPC::Message* reply_msg) { | |
| 57 scoped_ptr<IPC::Message> msg(reply_msg); | |
| 58 if (!jpeg_decoder_) { | |
| 59 jpeg_decoder_.reset( | |
| 60 new GpuJpegDecodeAccelerator(channel_, channel_->io_task_runner())); | |
| 61 } | |
| 62 jpeg_decoder_->AddClient( | |
| 63 route_id, base::Bind(&SendCreateJpegDecoderResult, base::Passed(&msg), | |
| 64 channel_->io_task_runner(), channel_->AsWeakPtr(), | |
| 65 make_scoped_refptr(channel_->filter()))); | |
| 66 } | |
| 67 | |
| 68 void MediaChannel::OnCreateVideoDecoder( | |
| 69 int32_t command_buffer_route_id, | |
| 70 const media::VideoDecodeAccelerator::Config& config, | |
| 71 int32_t decoder_route_id, | |
| 72 IPC::Message* reply_message) { | |
| 73 TRACE_EVENT0("gpu", "MediaChannel::OnCreateVideoDecoder"); | |
| 74 GpuCommandBufferStub* stub = | |
| 75 channel_->LookupCommandBuffer(command_buffer_route_id); | |
| 76 if (!stub) | |
| 77 return; | |
| 78 GpuVideoDecodeAccelerator* decoder = new GpuVideoDecodeAccelerator( | |
| 79 decoder_route_id, stub, stub->channel()->io_task_runner()); | |
| 80 bool succeeded = decoder->Initialize(config); | |
| 81 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(reply_message, | |
| 82 succeeded); | |
| 83 Send(reply_message); | |
| 84 | |
| 85 // decoder is registered as a DestructionObserver of this stub and will | |
| 86 // self-delete during destruction of this stub. | |
| 87 } | |
| 88 | |
| 89 void MediaChannel::OnCreateVideoEncoder(const CreateVideoEncoderParams& params, | |
| 90 IPC::Message* reply_message) { | |
| 91 TRACE_EVENT0("gpu", "MediaChannel::OnCreateVideoEncoder"); | |
| 92 GpuCommandBufferStub* stub = | |
| 93 channel_->LookupCommandBuffer(params.command_buffer_route_id); | |
| 94 if (!stub) | |
| 95 return; | |
| 96 GpuVideoEncodeAccelerator* encoder = | |
| 97 new GpuVideoEncodeAccelerator(params.encoder_route_id, stub); | |
| 98 bool succeeded = | |
| 99 encoder->Initialize(params.input_format, params.input_visible_size, | |
| 100 params.output_profile, params.initial_bitrate); | |
| 101 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message, | |
| 102 succeeded); | |
| 103 Send(reply_message); | |
| 104 | |
| 105 // encoder is registered as a DestructionObserver of this stub and will | |
| 106 // self-delete during destruction of this stub. | |
| 107 } | |
| 108 | |
| 109 } // namespace content | |
| OLD | NEW |