Chromium Code Reviews| 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 class DispatchHelper { | |
| 32 public: | |
| 33 DispatchHelper(MediaChannel* channel, uint32_t routing_id) | |
| 34 : channel_(channel), routing_id_(routing_id) {} | |
| 35 | |
| 36 bool Send(IPC::Message* msg) { return channel_->Send(msg); } | |
| 37 | |
| 38 void OnCreateVideoDecoder(const media::VideoDecodeAccelerator::Config& config, | |
| 39 int32_t decoder_route_id, | |
| 40 IPC::Message* reply_message) { | |
| 41 channel_->OnCreateVideoDecoder(routing_id_, config, decoder_route_id, | |
| 42 reply_message); | |
| 43 } | |
| 44 | |
| 45 void OnCreateVideoEncoder(const CreateVideoEncoderParams& params, | |
| 46 IPC::Message* reply_message) { | |
| 47 channel_->OnCreateVideoEncoder(routing_id_, params, reply_message); | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 MediaChannel* const channel_; | |
| 52 const int32_t routing_id_; | |
| 53 DISALLOW_COPY_AND_ASSIGN(DispatchHelper); | |
| 54 }; | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 MediaChannel::MediaChannel(GpuChannel* channel) : channel_(channel) {} | |
| 59 | |
| 60 MediaChannel::~MediaChannel() {} | |
| 61 | |
| 62 bool MediaChannel::Send(IPC::Message* msg) { | |
| 63 return channel_->Send(msg); | |
| 64 } | |
| 65 | |
| 66 bool MediaChannel::OnMessageReceived(const IPC::Message& message) { | |
| 67 DispatchHelper helper(this, message.routing_id()); | |
| 68 bool handled = true; | |
| 69 IPC_BEGIN_MESSAGE_MAP(MediaChannel, message) | |
| 70 IPC_MESSAGE_FORWARD_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoDecoder, | |
| 71 &helper, | |
| 72 DispatchHelper::OnCreateVideoDecoder) | |
| 73 IPC_MESSAGE_FORWARD_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoEncoder, | |
| 74 &helper, | |
| 75 DispatchHelper::OnCreateVideoEncoder) | |
| 76 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateJpegDecoder, | |
| 77 OnCreateJpegDecoder) | |
| 78 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 79 IPC_END_MESSAGE_MAP() | |
| 80 return handled; | |
| 81 } | |
| 82 | |
| 83 void MediaChannel::OnCreateJpegDecoder(int32_t route_id, | |
| 84 IPC::Message* reply_msg) { | |
| 85 scoped_ptr<IPC::Message> msg(reply_msg); | |
| 86 if (!jpeg_decoder_) { | |
| 87 jpeg_decoder_.reset( | |
| 88 new GpuJpegDecodeAccelerator(channel_, channel_->io_task_runner())); | |
| 89 } | |
| 90 jpeg_decoder_->AddClient( | |
| 91 route_id, base::Bind(&SendCreateJpegDecoderResult, base::Passed(&msg), | |
| 92 channel_->io_task_runner(), channel_->AsWeakPtr(), | |
| 93 make_scoped_refptr(channel_->filter()))); | |
| 94 } | |
| 95 | |
| 96 void MediaChannel::OnCreateVideoDecoder( | |
| 97 int32_t command_buffer_route_id, | |
| 98 const media::VideoDecodeAccelerator::Config& config, | |
| 99 int32_t decoder_route_id, | |
| 100 IPC::Message* reply_message) { | |
| 101 TRACE_EVENT0("gpu", "MediaChannel::OnCreateVideoDecoder"); | |
| 102 GpuCommandBufferStub* stub = | |
| 103 channel_->LookupCommandBuffer(command_buffer_route_id); | |
| 104 if (!stub) { | |
| 105 reply_message->set_reply_error(); | |
| 106 Send(reply_message); | |
| 107 return; | |
| 108 } | |
| 109 GpuVideoDecodeAccelerator* decoder = new GpuVideoDecodeAccelerator( | |
| 110 decoder_route_id, stub, stub->channel()->io_task_runner()); | |
| 111 bool succeeded = decoder->Initialize(config); | |
| 112 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(reply_message, | |
| 113 succeeded); | |
| 114 Send(reply_message); | |
| 115 | |
| 116 // decoder is registered as a DestructionObserver of this stub and will | |
| 117 // self-delete during destruction of this stub. | |
| 118 } | |
| 119 | |
| 120 void MediaChannel::OnCreateVideoEncoder(int command_buffer_route_id, | |
|
dcheng
2016/03/04 23:07:39
Nit: int32_t
| |
| 121 const CreateVideoEncoderParams& params, | |
| 122 IPC::Message* reply_message) { | |
| 123 TRACE_EVENT0("gpu", "MediaChannel::OnCreateVideoEncoder"); | |
| 124 GpuCommandBufferStub* stub = | |
| 125 channel_->LookupCommandBuffer(command_buffer_route_id); | |
| 126 if (!stub) { | |
| 127 reply_message->set_reply_error(); | |
| 128 Send(reply_message); | |
| 129 return; | |
| 130 } | |
| 131 GpuVideoEncodeAccelerator* encoder = | |
| 132 new GpuVideoEncodeAccelerator(params.encoder_route_id, stub); | |
| 133 bool succeeded = | |
| 134 encoder->Initialize(params.input_format, params.input_visible_size, | |
| 135 params.output_profile, params.initial_bitrate); | |
| 136 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message, | |
| 137 succeeded); | |
| 138 Send(reply_message); | |
| 139 | |
| 140 // encoder is registered as a DestructionObserver of this stub and will | |
| 141 // self-delete during destruction of this stub. | |
| 142 } | |
| 143 | |
| 144 } // namespace content | |
| OLD | NEW |