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_gpu_channel.h" | 5 #include "media/gpu/ipc/service/media_gpu_channel.h" |
6 | 6 |
7 #include "base/unguessable_token.h" | 7 #include "base/unguessable_token.h" |
8 #include "gpu/ipc/service/gpu_channel.h" | 8 #include "gpu/ipc/service/gpu_channel.h" |
9 #include "ipc/message_filter.h" | 9 #include "ipc/message_filter.h" |
10 #include "media/gpu/ipc/common/media_messages.h" | 10 #include "media/gpu/ipc/common/media_messages.h" |
11 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" | 11 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" |
12 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" | 12 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" |
13 | 13 |
14 namespace media { | 14 namespace media { |
15 | 15 |
16 namespace { | |
17 | |
18 void SendCreateJpegDecoderResult( | |
19 std::unique_ptr<IPC::Message> reply_message, | |
20 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | |
21 base::WeakPtr<gpu::GpuChannel> channel, | |
22 scoped_refptr<gpu::GpuChannelMessageFilter> filter, | |
23 bool result) { | |
24 GpuChannelMsg_CreateJpegDecoder::WriteReplyParams(reply_message.get(), | |
25 result); | |
26 if (io_task_runner->BelongsToCurrentThread()) { | |
27 filter->Send(reply_message.release()); | |
28 } else if (channel) { | |
29 channel->Send(reply_message.release()); | |
30 } | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 class MediaGpuChannelDispatchHelper { | 16 class MediaGpuChannelDispatchHelper { |
36 public: | 17 public: |
37 MediaGpuChannelDispatchHelper(MediaGpuChannel* channel, int32_t routing_id) | 18 MediaGpuChannelDispatchHelper(MediaGpuChannel* channel, int32_t routing_id) |
38 : channel_(channel), routing_id_(routing_id) {} | 19 : channel_(channel), routing_id_(routing_id) {} |
39 | 20 |
40 bool Send(IPC::Message* msg) { return channel_->Send(msg); } | 21 bool Send(IPC::Message* msg) { return channel_->Send(msg); } |
41 | 22 |
42 void OnCreateVideoDecoder(const VideoDecodeAccelerator::Config& config, | 23 void OnCreateVideoDecoder(const VideoDecodeAccelerator::Config& config, |
43 int32_t decoder_route_id, | 24 int32_t decoder_route_id, |
44 IPC::Message* reply_message) { | 25 IPC::Message* reply_message) { |
(...skipping 12 matching lines...) Expand all Loading... |
57 DISALLOW_COPY_AND_ASSIGN(MediaGpuChannelDispatchHelper); | 38 DISALLOW_COPY_AND_ASSIGN(MediaGpuChannelDispatchHelper); |
58 }; | 39 }; |
59 | 40 |
60 // Filter to respond to GetChannelToken on the IO thread. | 41 // Filter to respond to GetChannelToken on the IO thread. |
61 class MediaGpuChannelFilter : public IPC::MessageFilter { | 42 class MediaGpuChannelFilter : public IPC::MessageFilter { |
62 public: | 43 public: |
63 explicit MediaGpuChannelFilter(const base::UnguessableToken& channel_token) | 44 explicit MediaGpuChannelFilter(const base::UnguessableToken& channel_token) |
64 : channel_token_(channel_token) {} | 45 : channel_token_(channel_token) {} |
65 | 46 |
66 void OnFilterAdded(IPC::Channel* channel) override { channel_ = channel; } | 47 void OnFilterAdded(IPC::Channel* channel) override { channel_ = channel; } |
67 bool Send(IPC::Message* msg) { return channel_->Send(msg); } | 48 |
| 49 void OnFilterRemoved() override { channel_ = nullptr; } |
68 | 50 |
69 bool OnMessageReceived(const IPC::Message& msg) override { | 51 bool OnMessageReceived(const IPC::Message& msg) override { |
70 bool handled = true; | 52 bool handled = true; |
71 IPC_BEGIN_MESSAGE_MAP(MediaGpuChannelFilter, msg) | 53 IPC_BEGIN_MESSAGE_MAP(MediaGpuChannelFilter, msg) |
72 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetChannelToken, | 54 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetChannelToken, |
73 OnGetChannelToken) | 55 OnGetChannelToken) |
74 IPC_MESSAGE_UNHANDLED(handled = false) | 56 IPC_MESSAGE_UNHANDLED(handled = false) |
75 IPC_END_MESSAGE_MAP() | 57 IPC_END_MESSAGE_MAP() |
76 return handled; | 58 return handled; |
77 } | 59 } |
78 | 60 |
79 void OnGetChannelToken(IPC::Message* reply_message) { | 61 void OnGetChannelToken(IPC::Message* reply_message) { |
80 GpuCommandBufferMsg_GetChannelToken::WriteReplyParams(reply_message, | 62 GpuCommandBufferMsg_GetChannelToken::WriteReplyParams(reply_message, |
81 channel_token_); | 63 channel_token_); |
82 Send(reply_message); | 64 Send(reply_message); |
83 } | 65 } |
84 | 66 |
| 67 bool Send(IPC::Message* msg) { |
| 68 if (channel_) |
| 69 return channel_->Send(msg); |
| 70 return false; |
| 71 } |
| 72 |
85 private: | 73 private: |
86 ~MediaGpuChannelFilter() override {} | 74 ~MediaGpuChannelFilter() override {} |
87 | 75 |
88 IPC::Channel* channel_; | 76 IPC::Channel* channel_; |
89 base::UnguessableToken channel_token_; | 77 base::UnguessableToken channel_token_; |
90 }; | 78 }; |
91 | 79 |
92 MediaGpuChannel::MediaGpuChannel( | 80 MediaGpuChannel::MediaGpuChannel( |
93 gpu::GpuChannel* channel, | 81 gpu::GpuChannel* channel, |
94 const base::UnguessableToken& channel_token, | 82 const base::UnguessableToken& channel_token, |
95 const AndroidOverlayMojoFactoryCB& overlay_factory_cb) | 83 const AndroidOverlayMojoFactoryCB& overlay_factory_cb) |
96 : channel_(channel), overlay_factory_cb_(overlay_factory_cb) { | 84 : channel_(channel), |
97 channel_->AddFilter(new MediaGpuChannelFilter(channel_token)); | 85 filter_(new MediaGpuChannelFilter(channel_token)), |
| 86 overlay_factory_cb_(overlay_factory_cb) { |
| 87 channel_->AddFilter(filter_.get()); |
98 } | 88 } |
99 | 89 |
100 MediaGpuChannel::~MediaGpuChannel() {} | 90 MediaGpuChannel::~MediaGpuChannel() {} |
101 | 91 |
102 bool MediaGpuChannel::Send(IPC::Message* msg) { | 92 bool MediaGpuChannel::Send(IPC::Message* msg) { |
103 return channel_->Send(msg); | 93 return channel_->Send(msg); |
104 } | 94 } |
105 | 95 |
106 bool MediaGpuChannel::OnMessageReceived(const IPC::Message& message) { | 96 bool MediaGpuChannel::OnMessageReceived(const IPC::Message& message) { |
107 MediaGpuChannelDispatchHelper helper(this, message.routing_id()); | 97 MediaGpuChannelDispatchHelper helper(this, message.routing_id()); |
108 bool handled = true; | 98 bool handled = true; |
109 IPC_BEGIN_MESSAGE_MAP(MediaGpuChannel, message) | 99 IPC_BEGIN_MESSAGE_MAP(MediaGpuChannel, message) |
110 IPC_MESSAGE_FORWARD_DELAY_REPLY( | 100 IPC_MESSAGE_FORWARD_DELAY_REPLY( |
111 GpuCommandBufferMsg_CreateVideoDecoder, &helper, | 101 GpuCommandBufferMsg_CreateVideoDecoder, &helper, |
112 MediaGpuChannelDispatchHelper::OnCreateVideoDecoder) | 102 MediaGpuChannelDispatchHelper::OnCreateVideoDecoder) |
113 IPC_MESSAGE_FORWARD_DELAY_REPLY( | 103 IPC_MESSAGE_FORWARD_DELAY_REPLY( |
114 GpuCommandBufferMsg_CreateVideoEncoder, &helper, | 104 GpuCommandBufferMsg_CreateVideoEncoder, &helper, |
115 MediaGpuChannelDispatchHelper::OnCreateVideoEncoder) | 105 MediaGpuChannelDispatchHelper::OnCreateVideoEncoder) |
116 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateJpegDecoder, | 106 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateJpegDecoder, |
117 OnCreateJpegDecoder) | 107 OnCreateJpegDecoder) |
118 IPC_MESSAGE_UNHANDLED(handled = false) | 108 IPC_MESSAGE_UNHANDLED(handled = false) |
119 IPC_END_MESSAGE_MAP() | 109 IPC_END_MESSAGE_MAP() |
120 return handled; | 110 return handled; |
121 } | 111 } |
122 | 112 |
| 113 namespace { |
| 114 |
| 115 void SendCreateJpegDecoderResult( |
| 116 std::unique_ptr<IPC::Message> reply_message, |
| 117 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 118 base::WeakPtr<IPC::Sender> channel, |
| 119 scoped_refptr<MediaGpuChannelFilter> filter, |
| 120 bool result) { |
| 121 GpuChannelMsg_CreateJpegDecoder::WriteReplyParams(reply_message.get(), |
| 122 result); |
| 123 if (io_task_runner->BelongsToCurrentThread()) { |
| 124 filter->Send(reply_message.release()); |
| 125 } else if (channel) { |
| 126 channel->Send(reply_message.release()); |
| 127 } |
| 128 } |
| 129 |
| 130 } // namespace |
| 131 |
123 void MediaGpuChannel::OnCreateJpegDecoder(int32_t route_id, | 132 void MediaGpuChannel::OnCreateJpegDecoder(int32_t route_id, |
124 IPC::Message* reply_msg) { | 133 IPC::Message* reply_msg) { |
125 std::unique_ptr<IPC::Message> msg(reply_msg); | 134 std::unique_ptr<IPC::Message> msg(reply_msg); |
126 if (!jpeg_decoder_) { | 135 if (!jpeg_decoder_) { |
127 // The lifetime of |jpeg_decoder_| is managed by a gpu::GpuChannel. The | 136 // The lifetime of |jpeg_decoder_| is managed by a gpu::GpuChannel. The |
128 // GpuChannels destroy all the GpuJpegDecodeAccelerator that they own when | 137 // GpuChannels destroy all the GpuJpegDecodeAccelerator that they own when |
129 // they are destroyed. Therefore, passing |channel_| as a raw pointer is | 138 // they are destroyed. Therefore, passing |channel_| as a raw pointer is |
130 // safe. | 139 // safe. |
131 jpeg_decoder_.reset( | 140 jpeg_decoder_.reset( |
132 new GpuJpegDecodeAccelerator(channel_, channel_->io_task_runner())); | 141 new GpuJpegDecodeAccelerator(channel_, channel_->io_task_runner())); |
133 } | 142 } |
134 jpeg_decoder_->AddClient( | 143 jpeg_decoder_->AddClient( |
135 route_id, base::Bind(&SendCreateJpegDecoderResult, base::Passed(&msg), | 144 route_id, |
136 channel_->io_task_runner(), channel_->AsWeakPtr(), | 145 base::Bind(&SendCreateJpegDecoderResult, base::Passed(&msg), |
137 channel_->filter())); | 146 channel_->io_task_runner(), channel_->AsWeakPtr(), filter_)); |
138 } | 147 } |
139 | 148 |
140 void MediaGpuChannel::OnCreateVideoDecoder( | 149 void MediaGpuChannel::OnCreateVideoDecoder( |
141 int32_t command_buffer_route_id, | 150 int32_t command_buffer_route_id, |
142 const VideoDecodeAccelerator::Config& config, | 151 const VideoDecodeAccelerator::Config& config, |
143 int32_t decoder_route_id, | 152 int32_t decoder_route_id, |
144 IPC::Message* reply_message) { | 153 IPC::Message* reply_message) { |
145 TRACE_EVENT0("gpu", "MediaGpuChannel::OnCreateVideoDecoder"); | 154 TRACE_EVENT0("gpu", "MediaGpuChannel::OnCreateVideoDecoder"); |
146 gpu::GpuCommandBufferStub* stub = | 155 gpu::GpuCommandBufferStub* stub = |
147 channel_->LookupCommandBuffer(command_buffer_route_id); | 156 channel_->LookupCommandBuffer(command_buffer_route_id); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 params.output_profile, params.initial_bitrate); | 190 params.output_profile, params.initial_bitrate); |
182 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message, | 191 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message, |
183 succeeded); | 192 succeeded); |
184 Send(reply_message); | 193 Send(reply_message); |
185 | 194 |
186 // encoder is registered as a DestructionObserver of this stub and will | 195 // encoder is registered as a DestructionObserver of this stub and will |
187 // self-delete during destruction of this stub. | 196 // self-delete during destruction of this stub. |
188 } | 197 } |
189 | 198 |
190 } // namespace media | 199 } // namespace media |
OLD | NEW |