| 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/gpu/ipc/service/media_channel.h" | 5 #include "media/gpu/ipc/service/media_channel.h" |
| 6 | 6 |
| 7 #include "base/rand_util.h" |
| 7 #include "gpu/ipc/service/gpu_channel.h" | 8 #include "gpu/ipc/service/gpu_channel.h" |
| 9 #include "ipc/message_filter.h" |
| 8 #include "media/gpu/ipc/common/media_messages.h" | 10 #include "media/gpu/ipc/common/media_messages.h" |
| 9 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" | 11 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" |
| 10 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" | 12 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" |
| 11 | 13 |
| 12 namespace media { | 14 namespace media { |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 void SendCreateJpegDecoderResult( | 18 void SendCreateJpegDecoderResult( |
| 17 std::unique_ptr<IPC::Message> reply_message, | 19 std::unique_ptr<IPC::Message> reply_message, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 48 IPC::Message* reply_message) { | 50 IPC::Message* reply_message) { |
| 49 channel_->OnCreateVideoEncoder(routing_id_, params, reply_message); | 51 channel_->OnCreateVideoEncoder(routing_id_, params, reply_message); |
| 50 } | 52 } |
| 51 | 53 |
| 52 private: | 54 private: |
| 53 MediaChannel* const channel_; | 55 MediaChannel* const channel_; |
| 54 const int32_t routing_id_; | 56 const int32_t routing_id_; |
| 55 DISALLOW_COPY_AND_ASSIGN(MediaChannelDispatchHelper); | 57 DISALLOW_COPY_AND_ASSIGN(MediaChannelDispatchHelper); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 MediaChannel::MediaChannel(gpu::GpuChannel* channel) : channel_(channel) {} | 60 // Filter to respond to GetChannelToken on the IO thread. |
| 61 class MediaChannelFilter : public IPC::MessageFilter { |
| 62 public: |
| 63 explicit MediaChannelFilter(uint64_t channel_token) |
| 64 : channel_token_(channel_token) {} |
| 65 |
| 66 void OnFilterAdded(IPC::Sender* sender) override { sender_ = sender; } |
| 67 bool Send(IPC::Message* msg) { return sender_->Send(msg); } |
| 68 |
| 69 bool OnMessageReceived(const IPC::Message& msg) override { |
| 70 bool handled = true; |
| 71 IPC_BEGIN_MESSAGE_MAP(MediaChannelFilter, msg) |
| 72 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetChannelToken, |
| 73 OnGetChannelToken) |
| 74 IPC_MESSAGE_UNHANDLED(handled = false) |
| 75 IPC_END_MESSAGE_MAP() |
| 76 return handled; |
| 77 } |
| 78 |
| 79 void OnGetChannelToken(IPC::Message* reply_message) { |
| 80 GpuCommandBufferMsg_GetChannelToken::WriteReplyParams(reply_message, |
| 81 channel_token_); |
| 82 Send(reply_message); |
| 83 } |
| 84 |
| 85 private: |
| 86 ~MediaChannelFilter() override {} |
| 87 |
| 88 IPC::Sender* sender_; |
| 89 uint64_t channel_token_; |
| 90 }; |
| 91 |
| 92 MediaChannel::MediaChannel(gpu::GpuChannel* channel) : channel_(channel) { |
| 93 uint64_t channel_token; |
| 94 base::RandBytes(&channel_token, sizeof(channel_token)); |
| 95 channel_filter_ = new MediaChannelFilter(channel_token); |
| 96 channel_->AddFilter(channel_filter_.get()); |
| 97 } |
| 59 | 98 |
| 60 MediaChannel::~MediaChannel() {} | 99 MediaChannel::~MediaChannel() {} |
| 61 | 100 |
| 62 bool MediaChannel::Send(IPC::Message* msg) { | 101 bool MediaChannel::Send(IPC::Message* msg) { |
| 63 return channel_->Send(msg); | 102 return channel_->Send(msg); |
| 64 } | 103 } |
| 65 | 104 |
| 66 bool MediaChannel::OnMessageReceived(const IPC::Message& message) { | 105 bool MediaChannel::OnMessageReceived(const IPC::Message& message) { |
| 67 MediaChannelDispatchHelper helper(this, message.routing_id()); | 106 MediaChannelDispatchHelper helper(this, message.routing_id()); |
| 68 bool handled = true; | 107 bool handled = true; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 params.output_profile, params.initial_bitrate); | 174 params.output_profile, params.initial_bitrate); |
| 136 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message, | 175 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message, |
| 137 succeeded); | 176 succeeded); |
| 138 Send(reply_message); | 177 Send(reply_message); |
| 139 | 178 |
| 140 // encoder is registered as a DestructionObserver of this stub and will | 179 // encoder is registered as a DestructionObserver of this stub and will |
| 141 // self-delete during destruction of this stub. | 180 // self-delete during destruction of this stub. |
| 142 } | 181 } |
| 143 | 182 |
| 144 } // namespace media | 183 } // namespace media |
| OLD | NEW |