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); } | |
68 | 48 |
69 bool OnMessageReceived(const IPC::Message& msg) override { | 49 bool OnMessageReceived(const IPC::Message& msg) override { |
70 bool handled = true; | 50 bool handled = true; |
71 IPC_BEGIN_MESSAGE_MAP(MediaGpuChannelFilter, msg) | 51 IPC_BEGIN_MESSAGE_MAP(MediaGpuChannelFilter, msg) |
72 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetChannelToken, | 52 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetChannelToken, |
73 OnGetChannelToken) | 53 OnGetChannelToken) |
74 IPC_MESSAGE_UNHANDLED(handled = false) | 54 IPC_MESSAGE_UNHANDLED(handled = false) |
75 IPC_END_MESSAGE_MAP() | 55 IPC_END_MESSAGE_MAP() |
76 return handled; | 56 return handled; |
77 } | 57 } |
78 | 58 |
79 void OnGetChannelToken(IPC::Message* reply_message) { | 59 void OnGetChannelToken(IPC::Message* reply_message) { |
80 GpuCommandBufferMsg_GetChannelToken::WriteReplyParams(reply_message, | 60 GpuCommandBufferMsg_GetChannelToken::WriteReplyParams(reply_message, |
81 channel_token_); | 61 channel_token_); |
82 Send(reply_message); | 62 Send(reply_message); |
83 } | 63 } |
84 | 64 |
65 bool Send(IPC::Message* msg) { return channel_->Send(msg); } | |
66 | |
85 private: | 67 private: |
86 ~MediaGpuChannelFilter() override {} | 68 ~MediaGpuChannelFilter() override {} |
87 | 69 |
88 IPC::Channel* channel_; | 70 IPC::Channel* channel_; |
89 base::UnguessableToken channel_token_; | 71 base::UnguessableToken channel_token_; |
90 }; | 72 }; |
91 | 73 |
92 MediaGpuChannel::MediaGpuChannel(gpu::GpuChannel* channel, | 74 MediaGpuChannel::MediaGpuChannel(gpu::GpuChannel* channel, |
93 const base::UnguessableToken& channel_token) | 75 const base::UnguessableToken& channel_token) |
94 : channel_(channel) { | 76 : channel_(channel), filter_(new MediaGpuChannelFilter(channel_token)) { |
sandersd (OOO until July 31)
2017/05/11 21:09:18
I'm not very comfortable keeping a reference to th
sunnyps
2017/05/11 22:21:46
Filter lifetime has never been tied to the (gpu or
sandersd (OOO until July 31)
2017/05/11 22:45:03
The specific implementation of this filter guarant
sunnyps
2017/05/11 22:53:24
Oh you mean accessing |channel_| right? That shoul
sandersd (OOO until July 31)
2017/05/11 23:14:38
I believe that OnFilterRemoved is a sufficient sol
| |
95 channel_->AddFilter(new MediaGpuChannelFilter(channel_token)); | 77 channel_->AddFilter(filter_.get()); |
96 } | 78 } |
97 | 79 |
98 MediaGpuChannel::~MediaGpuChannel() {} | 80 MediaGpuChannel::~MediaGpuChannel() {} |
99 | 81 |
100 bool MediaGpuChannel::Send(IPC::Message* msg) { | 82 bool MediaGpuChannel::Send(IPC::Message* msg) { |
101 return channel_->Send(msg); | 83 return channel_->Send(msg); |
102 } | 84 } |
103 | 85 |
104 bool MediaGpuChannel::OnMessageReceived(const IPC::Message& message) { | 86 bool MediaGpuChannel::OnMessageReceived(const IPC::Message& message) { |
105 MediaGpuChannelDispatchHelper helper(this, message.routing_id()); | 87 MediaGpuChannelDispatchHelper helper(this, message.routing_id()); |
106 bool handled = true; | 88 bool handled = true; |
107 IPC_BEGIN_MESSAGE_MAP(MediaGpuChannel, message) | 89 IPC_BEGIN_MESSAGE_MAP(MediaGpuChannel, message) |
108 IPC_MESSAGE_FORWARD_DELAY_REPLY( | 90 IPC_MESSAGE_FORWARD_DELAY_REPLY( |
109 GpuCommandBufferMsg_CreateVideoDecoder, &helper, | 91 GpuCommandBufferMsg_CreateVideoDecoder, &helper, |
110 MediaGpuChannelDispatchHelper::OnCreateVideoDecoder) | 92 MediaGpuChannelDispatchHelper::OnCreateVideoDecoder) |
111 IPC_MESSAGE_FORWARD_DELAY_REPLY( | 93 IPC_MESSAGE_FORWARD_DELAY_REPLY( |
112 GpuCommandBufferMsg_CreateVideoEncoder, &helper, | 94 GpuCommandBufferMsg_CreateVideoEncoder, &helper, |
113 MediaGpuChannelDispatchHelper::OnCreateVideoEncoder) | 95 MediaGpuChannelDispatchHelper::OnCreateVideoEncoder) |
114 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateJpegDecoder, | 96 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateJpegDecoder, |
115 OnCreateJpegDecoder) | 97 OnCreateJpegDecoder) |
116 IPC_MESSAGE_UNHANDLED(handled = false) | 98 IPC_MESSAGE_UNHANDLED(handled = false) |
117 IPC_END_MESSAGE_MAP() | 99 IPC_END_MESSAGE_MAP() |
118 return handled; | 100 return handled; |
119 } | 101 } |
120 | 102 |
103 namespace { | |
104 | |
105 void SendCreateJpegDecoderResult( | |
106 std::unique_ptr<IPC::Message> reply_message, | |
107 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | |
108 base::WeakPtr<IPC::Sender> channel, | |
109 scoped_refptr<MediaGpuChannelFilter> filter, | |
110 bool result) { | |
111 GpuChannelMsg_CreateJpegDecoder::WriteReplyParams(reply_message.get(), | |
112 result); | |
113 if (io_task_runner->BelongsToCurrentThread()) { | |
114 filter->Send(reply_message.release()); | |
115 } else if (channel) { | |
116 channel->Send(reply_message.release()); | |
117 } | |
118 } | |
119 | |
120 } // namespace | |
121 | |
121 void MediaGpuChannel::OnCreateJpegDecoder(int32_t route_id, | 122 void MediaGpuChannel::OnCreateJpegDecoder(int32_t route_id, |
122 IPC::Message* reply_msg) { | 123 IPC::Message* reply_msg) { |
123 std::unique_ptr<IPC::Message> msg(reply_msg); | 124 std::unique_ptr<IPC::Message> msg(reply_msg); |
124 if (!jpeg_decoder_) { | 125 if (!jpeg_decoder_) { |
125 // The lifetime of |jpeg_decoder_| is managed by a gpu::GpuChannel. The | 126 // The lifetime of |jpeg_decoder_| is managed by a gpu::GpuChannel. The |
126 // GpuChannels destroy all the GpuJpegDecodeAccelerator that they own when | 127 // GpuChannels destroy all the GpuJpegDecodeAccelerator that they own when |
127 // they are destroyed. Therefore, passing |channel_| as a raw pointer is | 128 // they are destroyed. Therefore, passing |channel_| as a raw pointer is |
128 // safe. | 129 // safe. |
129 jpeg_decoder_.reset( | 130 jpeg_decoder_.reset( |
130 new GpuJpegDecodeAccelerator(channel_, channel_->io_task_runner())); | 131 new GpuJpegDecodeAccelerator(channel_, channel_->io_task_runner())); |
131 } | 132 } |
132 jpeg_decoder_->AddClient( | 133 jpeg_decoder_->AddClient( |
133 route_id, base::Bind(&SendCreateJpegDecoderResult, base::Passed(&msg), | 134 route_id, |
134 channel_->io_task_runner(), channel_->AsWeakPtr(), | 135 base::Bind(&SendCreateJpegDecoderResult, base::Passed(&msg), |
135 channel_->filter())); | 136 channel_->io_task_runner(), channel_->AsWeakPtr(), filter_)); |
136 } | 137 } |
137 | 138 |
138 void MediaGpuChannel::OnCreateVideoDecoder( | 139 void MediaGpuChannel::OnCreateVideoDecoder( |
139 int32_t command_buffer_route_id, | 140 int32_t command_buffer_route_id, |
140 const VideoDecodeAccelerator::Config& config, | 141 const VideoDecodeAccelerator::Config& config, |
141 int32_t decoder_route_id, | 142 int32_t decoder_route_id, |
142 IPC::Message* reply_message) { | 143 IPC::Message* reply_message) { |
143 TRACE_EVENT0("gpu", "MediaGpuChannel::OnCreateVideoDecoder"); | 144 TRACE_EVENT0("gpu", "MediaGpuChannel::OnCreateVideoDecoder"); |
144 gpu::GpuCommandBufferStub* stub = | 145 gpu::GpuCommandBufferStub* stub = |
145 channel_->LookupCommandBuffer(command_buffer_route_id); | 146 channel_->LookupCommandBuffer(command_buffer_route_id); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 params.output_profile, params.initial_bitrate); | 179 params.output_profile, params.initial_bitrate); |
179 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message, | 180 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message, |
180 succeeded); | 181 succeeded); |
181 Send(reply_message); | 182 Send(reply_message); |
182 | 183 |
183 // encoder is registered as a DestructionObserver of this stub and will | 184 // encoder is registered as a DestructionObserver of this stub and will |
184 // self-delete during destruction of this stub. | 185 // self-delete during destruction of this stub. |
185 } | 186 } |
186 | 187 |
187 } // namespace media | 188 } // namespace media |
OLD | NEW |