OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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/client/gpu_jpeg_decode_accelerator_host.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/logging.h" | |
9 #include "base/message_loop/message_loop.h" | |
10 #include "base/synchronization/waitable_event.h" | |
wuchengli
2015/04/15 07:11:57
is this required?
kcwu
2015/04/16 14:38:27
Done.
| |
11 #include "content/common/gpu/client/gpu_channel_host.h" | |
12 #include "content/common/gpu/gpu_messages.h" | |
13 #include "content/common/view_messages.h" | |
wuchengli
2015/04/15 07:11:57
Is this required?
kcwu
2015/04/16 14:38:27
Done.
| |
14 #include "ipc/ipc_message_macros.h" | |
15 #include "ipc/ipc_message_utils.h" | |
16 | |
17 using media::JpegDecodeAccelerator; | |
18 namespace content { | |
19 | |
20 GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost( | |
21 GpuChannelHost* channel, | |
22 int32 route_id) | |
23 : channel_(channel), | |
24 client_(NULL), | |
25 decoder_route_id_(route_id), | |
26 weak_this_factory_(this) { | |
27 DCHECK(channel_); | |
28 } | |
29 | |
30 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() { | |
31 DCHECK(CalledOnValidThread()); | |
32 | |
33 if (channel_ && decoder_route_id_ != MSG_ROUTING_NONE) | |
34 channel_->RemoveRoute(decoder_route_id_); | |
35 } | |
36 | |
37 bool GpuJpegDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { | |
38 DCHECK(CalledOnValidThread()); | |
wuchengli
2015/04/15 07:11:57
OnMessageReceived is called on IO thread, which is
kcwu
2015/04/20 17:47:58
Done.
| |
39 bool handled = true; | |
40 IPC_BEGIN_MESSAGE_MAP(GpuJpegDecodeAcceleratorHost, msg) | |
41 IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_VideoFrameReady, | |
wuchengli
2015/04/15 07:11:57
Indentation? Run git cl format.
kcwu
2015/04/16 14:38:27
Fixed. The indentation was broken due to git cl fo
| |
42 OnVideoFrameReady) | |
43 IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_NotifyError, OnNotifyError) | |
44 IPC_MESSAGE_UNHANDLED(handled = false) | |
45 IPC_END_MESSAGE_MAP() | |
46 DCHECK(handled); | |
47 // See OnNotifyError for why |this| mustn't be used after OnNotifyError might | |
48 // have been called above. | |
49 return handled; | |
50 } | |
51 | |
52 void GpuJpegDecodeAcceleratorHost::OnChannelError() { | |
53 DVLOG(3) << __func__; | |
54 DCHECK(CalledOnValidThread()); | |
55 if (channel_) { | |
56 if (decoder_route_id_ != MSG_ROUTING_NONE) | |
57 channel_->RemoveRoute(decoder_route_id_); | |
58 channel_ = NULL; | |
59 } | |
60 PostNotifyError(kInvalidBitstreamBufferId, PLATFORM_FAILURE); | |
61 } | |
62 | |
63 bool GpuJpegDecodeAcceleratorHost::Initialize( | |
64 media::JpegDecodeAccelerator::Client* client) { | |
65 DCHECK(CalledOnValidThread()); | |
66 | |
67 bool succeeded = false; | |
68 // this cannot on main thread or IO thread | |
wuchengli
2015/04/15 07:11:57
s/cannot on/cannon be/. Explain why this cannot be
kcwu
2015/04/20 17:47:58
Done.
Recheck the code, it's okay on main thread.
| |
69 Send(new GpuMsg_CreateJpegDecoder(decoder_route_id_, &succeeded)); | |
70 | |
71 if (!succeeded) { | |
72 DLOG(ERROR) << "Send(GpuMsg_CreateJpegDecoder()) failed"; | |
73 channel_->RemoveRoute(decoder_route_id_); | |
74 return false; | |
75 } | |
76 client_ = client; | |
77 | |
78 return true; | |
79 } | |
80 | |
81 void GpuJpegDecodeAcceleratorHost::Decode( | |
82 const media::BitstreamBuffer& bitstream_buffer, | |
83 const scoped_refptr<media::VideoFrame>& video_frame) { | |
84 DCHECK(CalledOnValidThread()); | |
85 if (!channel_) | |
86 return; | |
87 | |
88 base::SharedMemoryHandle input_handle = | |
89 channel_->ShareToGpuProcess(bitstream_buffer.handle()); | |
90 if (!base::SharedMemory::IsHandleValid(input_handle)) { | |
91 DLOG(ERROR) << "Failed to duplicate buffer handler of BitstreamBuffer"; | |
wuchengli
2015/04/15 07:11:57
Use LOG(ERROR) because this shouldn't happen. s/ha
kcwu
2015/04/16 14:38:27
Done.
| |
92 PostNotifyError(bitstream_buffer.id(), INVALID_ARGUMENT); | |
93 return; | |
94 } | |
95 | |
96 if (!base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle())) { | |
97 DLOG(ERROR) | |
98 << "Decode(): cannot output to frame not backed by shared memory"; | |
wuchengli
2015/04/15 07:11:57
Use LOG(ERROR) because this shouldn't happen.
kcwu
2015/04/16 14:38:27
Done.
| |
99 PostNotifyError(bitstream_buffer.id(), PLATFORM_FAILURE); | |
wuchengli
2015/04/15 07:11:57
Maybe INVALID_ARGUMENT? Why this is a PLATFORM_FAI
kcwu
2015/04/16 14:38:27
Done.
| |
100 return; | |
101 } | |
102 | |
103 base::SharedMemoryHandle output_handle = | |
104 channel_->ShareToGpuProcess(video_frame->shared_memory_handle()); | |
105 if (!base::SharedMemory::IsHandleValid(output_handle)) { | |
106 DLOG(ERROR) << "Decode(): failed to duplicate buffer handle of VideoFrame"; | |
wuchengli
2015/04/15 07:11:57
s/DLOG/LOG/
kcwu
2015/04/16 14:38:27
Done.
| |
107 PostNotifyError(bitstream_buffer.id(), PLATFORM_FAILURE); | |
108 return; | |
109 } | |
110 | |
111 size_t output_buffer_size = media::VideoFrame::AllocationSize( | |
112 video_frame->format(), video_frame->coded_size()); | |
113 | |
114 AcceleratedJpegDecoderMsg_Decode_Params decode_params; | |
115 decode_params.coded_size = video_frame->coded_size(); | |
116 decode_params.input_buffer_id = bitstream_buffer.id(); | |
117 decode_params.input_buffer_handle = input_handle; | |
118 decode_params.input_buffer_size = bitstream_buffer.size(); | |
119 decode_params.output_video_frame_handle = output_handle; | |
120 decode_params.output_buffer_size = output_buffer_size; | |
121 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params)); | |
122 } | |
123 | |
124 void GpuJpegDecodeAcceleratorHost::Destroy() { | |
125 DCHECK(CalledOnValidThread()); | |
126 if (channel_) | |
127 Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_)); | |
128 client_ = NULL; | |
129 delete this; | |
130 } | |
131 | |
132 void GpuJpegDecodeAcceleratorHost::PostNotifyError(int32_t bitstream_buffer_id, | |
133 Error error) { | |
134 DCHECK(CalledOnValidThread()); | |
135 DVLOG(2) << "PostNotifyDecodeResult(): error=" << error; | |
wuchengli
2015/04/15 07:11:57
s/PostNotifyDecodeResult/__func__? Also log |bitst
kcwu
2015/04/16 14:38:27
Done.
| |
136 // Post the error notification back to this thread, to avoid re-entrancy. | |
wuchengli
2015/04/15 07:11:57
I don't understand. Can you explain?
kcwu
2015/04/20 17:47:58
This is copied from GVEAHost. I guess it try to av
| |
137 base::MessageLoopProxy::current()->PostTask( | |
138 FROM_HERE, | |
139 base::Bind(&GpuJpegDecodeAcceleratorHost::OnNotifyError, | |
140 weak_this_factory_.GetWeakPtr(), bitstream_buffer_id, error)); | |
141 } | |
142 | |
143 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) { | |
144 DVLOG(3) << __func__; | |
wuchengli
2015/04/15 07:11:57
Be consistent with the order DVLOG and DCHECK(Call
kcwu
2015/04/16 14:38:27
Done.
| |
145 DCHECK(CalledOnValidThread()); | |
146 uint32 message_type = message->type(); | |
147 if (!channel_->Send(message)) { | |
148 DLOG(ERROR) << "Send(" << message_type << ") failed"; | |
149 } | |
150 } | |
151 | |
152 void GpuJpegDecodeAcceleratorHost::OnVideoFrameReady( | |
153 int32_t bitstream_buffer_id) { | |
154 DCHECK(CalledOnValidThread()); | |
wuchengli
2015/04/15 07:11:57
Change DCHECK to IO thread. Please enable the DCHE
kcwu
2015/04/20 17:47:58
Done.
| |
155 | |
156 DCHECK(client_); | |
157 client_->VideoFrameReady(bitstream_buffer_id); | |
158 } | |
159 | |
160 void GpuJpegDecodeAcceleratorHost::OnNotifyError(int32_t bitstream_buffer_id, | |
161 Error error) { | |
162 DCHECK(CalledOnValidThread()); | |
wuchengli
2015/04/15 07:11:57
Change DCHECK to IO thread.
kcwu
2015/04/20 17:47:58
Done.
| |
163 if (!client_) | |
164 return; | |
165 weak_this_factory_.InvalidateWeakPtrs(); | |
166 | |
167 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the | |
168 // last thing done on this stack! | |
169 media::JpegDecodeAccelerator::Client* client = NULL; | |
170 std::swap(client, client_); | |
wuchengli
2015/04/15 07:11:57
Why do we need to swap? To avoid client->NotifyErr
kcwu
2015/04/20 17:47:58
Yes, I think so. This is copied from GVDAHost.
| |
171 client->NotifyError(bitstream_buffer_id, | |
172 static_cast<media::JpegDecodeAccelerator::Error>(error)); | |
173 } | |
174 | |
175 } // namespace content | |
OLD | NEW |