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 "content/common/gpu/client/gpu_channel_host.h" | |
10 #include "content/common/gpu/gpu_messages.h" | |
11 #include "ipc/ipc_message_macros.h" | |
12 #include "ipc/ipc_message_utils.h" | |
13 | |
14 using media::JpegDecodeAccelerator; | |
15 namespace content { | |
16 | |
17 GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost( | |
18 GpuChannelHost* channel, | |
19 int32 route_id) | |
20 : channel_(channel), client_(NULL), decoder_route_id_(route_id) { | |
21 DCHECK(channel_); | |
22 } | |
23 | |
24 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() { | |
25 } | |
26 | |
27 bool GpuJpegDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { | |
28 DCHECK(CalledOnValidThread()); | |
29 bool handled = true; | |
30 IPC_BEGIN_MESSAGE_MAP(GpuJpegDecodeAcceleratorHost, msg) | |
31 IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_VideoFrameReady, | |
32 OnVideoFrameReady) | |
33 IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_NotifyError, | |
34 OnNotifyError) | |
35 IPC_MESSAGE_UNHANDLED(handled = false) | |
36 IPC_END_MESSAGE_MAP() | |
37 DCHECK(handled); | |
38 // See OnNotifyError for why |this| mustn't be used after OnNotifyError might | |
39 // have been called above. | |
40 return handled; | |
41 } | |
42 | |
43 void GpuJpegDecodeAcceleratorHost::OnChannelError() { | |
44 DVLOG(3) << __func__; | |
45 DCHECK(CalledOnValidThread()); | |
46 | |
47 channel_ = NULL; | |
piman
2015/05/18 22:46:18
nit: nullptr
kcwu
2015/05/22 19:46:50
Done.
| |
48 OnNotifyError(kInvalidBitstreamBufferId, PLATFORM_FAILURE); | |
49 } | |
50 | |
51 bool GpuJpegDecodeAcceleratorHost::Initialize( | |
52 media::JpegDecodeAccelerator::Client* client) { | |
53 DCHECK(CalledOnValidThread()); | |
54 | |
55 bool succeeded = false; | |
56 // This cannot be on IO thread because the msg is synchronous. | |
57 Send(new GpuMsg_CreateJpegDecoder(decoder_route_id_, &succeeded)); | |
58 | |
59 if (!succeeded) { | |
60 DLOG(ERROR) << "Send(GpuMsg_CreateJpegDecoder()) failed"; | |
61 channel_->RemoveRoute(decoder_route_id_); | |
62 return false; | |
piman
2015/05/18 22:46:18
So, if I understand correctly, the client is respo
kcwu
2015/05/22 19:46:50
Done.
| |
63 } | |
64 client_ = client; | |
65 | |
66 return true; | |
67 } | |
68 | |
69 void GpuJpegDecodeAcceleratorHost::Decode( | |
70 const media::BitstreamBuffer& bitstream_buffer, | |
71 const scoped_refptr<media::VideoFrame>& video_frame) { | |
72 DCHECK(CalledOnValidThread()); | |
73 if (!channel_) | |
74 return; | |
75 | |
76 base::SharedMemoryHandle input_handle = | |
77 channel_->ShareToGpuProcess(bitstream_buffer.handle()); | |
78 if (!base::SharedMemory::IsHandleValid(input_handle)) { | |
79 LOG(ERROR) << "Failed to duplicate buffer handle of BitstreamBuffer"; | |
80 OnNotifyError(bitstream_buffer.id(), INVALID_ARGUMENT); | |
81 return; | |
82 } | |
83 | |
84 if (!base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle())) { | |
85 LOG(ERROR) | |
86 << "Decode(): cannot output to frame not backed by shared memory"; | |
87 OnNotifyError(bitstream_buffer.id(), INVALID_ARGUMENT); | |
piman
2015/05/18 22:46:18
So, IIUC, on Windows, ShareToGpuProcess actually c
kcwu
2015/05/22 19:46:50
Done.
| |
88 return; | |
89 } | |
90 | |
91 base::SharedMemoryHandle output_handle = | |
92 channel_->ShareToGpuProcess(video_frame->shared_memory_handle()); | |
93 if (!base::SharedMemory::IsHandleValid(output_handle)) { | |
94 LOG(ERROR) << "Decode(): failed to duplicate buffer handle of VideoFrame"; | |
95 OnNotifyError(bitstream_buffer.id(), PLATFORM_FAILURE); | |
96 return; | |
97 } | |
98 | |
99 size_t output_buffer_size = media::VideoFrame::AllocationSize( | |
100 video_frame->format(), video_frame->coded_size()); | |
101 | |
102 AcceleratedJpegDecoderMsg_Decode_Params decode_params; | |
103 decode_params.coded_size = video_frame->coded_size(); | |
104 decode_params.input_buffer_id = bitstream_buffer.id(); | |
105 decode_params.input_buffer_handle = input_handle; | |
106 decode_params.input_buffer_size = bitstream_buffer.size(); | |
107 decode_params.output_video_frame_handle = output_handle; | |
108 decode_params.output_buffer_size = output_buffer_size; | |
109 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params)); | |
110 } | |
111 | |
112 void GpuJpegDecodeAcceleratorHost::Destroy() { | |
113 DCHECK(CalledOnValidThread()); | |
114 Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_)); | |
115 | |
116 if (channel_) { | |
117 if (decoder_route_id_ != MSG_ROUTING_NONE) | |
118 channel_->RemoveRoute(decoder_route_id_); | |
119 channel_ = NULL; | |
120 } | |
121 | |
122 delete this; | |
piman
2015/05/18 22:46:18
I'm not in love with this pattern, because it prev
kcwu
2015/05/22 19:46:50
This class implements media::JpegDecodeAccelerator
piman
2015/05/22 22:27:48
Honestly, I don't think VideoDecodeAccelerator is
kcwu
2015/05/25 18:57:16
Done.
Destroy methods are merged into destructors.
| |
123 } | |
124 | |
125 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) { | |
126 DVLOG(3) << __func__; | |
127 DCHECK(CalledOnValidThread()); | |
128 | |
129 if (!channel_) | |
130 return; | |
131 if (!channel_->Send(message)) { | |
132 DLOG(ERROR) << "Send(" << message->type() << ") failed"; | |
133 } | |
134 } | |
135 | |
136 void GpuJpegDecodeAcceleratorHost::OnVideoFrameReady( | |
137 int32_t bitstream_buffer_id) { | |
138 DCHECK(CalledOnValidThread()); | |
139 DCHECK(client_); | |
140 client_->VideoFrameReady(bitstream_buffer_id); | |
141 } | |
142 | |
143 void GpuJpegDecodeAcceleratorHost::OnNotifyError(int32_t bitstream_buffer_id, | |
144 Error error) { | |
145 DVLOG(2) << __func__ << ": error=" << error | |
146 << ", bitstream_buffer_id=" << bitstream_buffer_id; | |
147 DCHECK(CalledOnValidThread()); | |
148 if (!client_) | |
149 return; | |
150 | |
151 client_->NotifyError(bitstream_buffer_id, | |
152 static_cast<media::JpegDecodeAccelerator::Error>(error)); | |
153 client_ = nullptr; | |
154 } | |
155 | |
156 } // namespace content | |
OLD | NEW |