| 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 class MediaChannelDispatchHelper { |
| 34 public: |
| 35 MediaChannelDispatchHelper(MediaChannel* channel, int32_t routing_id) |
| 36 : channel_(channel), routing_id_(routing_id) {} |
| 37 |
| 38 bool Send(IPC::Message* msg) { return channel_->Send(msg); } |
| 39 |
| 40 void OnCreateVideoDecoder(const media::VideoDecodeAccelerator::Config& config, |
| 41 int32_t decoder_route_id, |
| 42 IPC::Message* reply_message) { |
| 43 channel_->OnCreateVideoDecoder(routing_id_, config, decoder_route_id, |
| 44 reply_message); |
| 45 } |
| 46 |
| 47 void OnCreateVideoEncoder(const CreateVideoEncoderParams& params, |
| 48 IPC::Message* reply_message) { |
| 49 channel_->OnCreateVideoEncoder(routing_id_, params, reply_message); |
| 50 } |
| 51 |
| 52 private: |
| 53 MediaChannel* const channel_; |
| 54 const int32_t routing_id_; |
| 55 DISALLOW_COPY_AND_ASSIGN(MediaChannelDispatchHelper); |
| 56 }; |
| 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 MediaChannelDispatchHelper helper(this, message.routing_id()); |
| 68 bool handled = true; |
| 69 IPC_BEGIN_MESSAGE_MAP(MediaChannel, message) |
| 70 IPC_MESSAGE_FORWARD_DELAY_REPLY( |
| 71 GpuCommandBufferMsg_CreateVideoDecoder, &helper, |
| 72 MediaChannelDispatchHelper::OnCreateVideoDecoder) |
| 73 IPC_MESSAGE_FORWARD_DELAY_REPLY( |
| 74 GpuCommandBufferMsg_CreateVideoEncoder, &helper, |
| 75 MediaChannelDispatchHelper::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(int32_t command_buffer_route_id, |
| 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 |