Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: content/common/gpu/client/gpu_jpeg_decode_accelerator_host.cc

Issue 1016773002: MJPEG acceleration for video capture using VAAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "content/common/gpu/client/gpu_channel_host.h"
11 #include "content/common/gpu/gpu_messages.h"
12 #include "ipc/ipc_message_macros.h"
13 #include "ipc/ipc_message_utils.h"
14
15 using media::JpegDecodeAccelerator;
16 namespace content {
17
18 GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost(
19 GpuChannelHost* channel,
20 int32 route_id)
21 : channel_(channel), client_(NULL), decoder_route_id_(route_id) {
22 DCHECK(channel_);
23 }
24
25 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() {
26 }
27
28 bool GpuJpegDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) {
29 DCHECK(CalledOnValidThread());
30 bool handled = true;
31 IPC_BEGIN_MESSAGE_MAP(GpuJpegDecodeAcceleratorHost, msg)
32 IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_VideoFrameReady,
33 OnVideoFrameReady)
34 IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_NotifyError,
35 OnNotifyError)
36 IPC_MESSAGE_UNHANDLED(handled = false)
37 IPC_END_MESSAGE_MAP()
38 DCHECK(handled);
39 // See OnNotifyError for why |this| mustn't be used after OnNotifyError might
40 // have been called above.
41 return handled;
42 }
43
44 void GpuJpegDecodeAcceleratorHost::OnChannelError() {
45 DVLOG(3) << __func__;
46 DCHECK(CalledOnValidThread());
47
48 channel_ = NULL;
49 OnNotifyError(kInvalidBitstreamBufferId, PLATFORM_FAILURE);
50 }
51
52 bool GpuJpegDecodeAcceleratorHost::Initialize(
53 media::JpegDecodeAccelerator::Client* client) {
54 DCHECK(CalledOnValidThread());
55
56 bool succeeded = false;
57 // This cannot be on IO thread because the msg is synchronous.
58 Send(new GpuMsg_CreateJpegDecoder(decoder_route_id_, &succeeded));
59
60 if (!succeeded) {
61 DLOG(ERROR) << "Send(GpuMsg_CreateJpegDecoder()) failed";
62 channel_->RemoveRoute(decoder_route_id_);
63 return false;
64 }
65 client_ = client;
66
67 return true;
68 }
69
70 void GpuJpegDecodeAcceleratorHost::Decode(
71 const media::BitstreamBuffer& bitstream_buffer,
72 const scoped_refptr<media::VideoFrame>& video_frame) {
73 DCHECK(CalledOnValidThread());
74 if (!channel_)
75 return;
76
77 base::SharedMemoryHandle input_handle =
78 channel_->ShareToGpuProcess(bitstream_buffer.handle());
79 if (!base::SharedMemory::IsHandleValid(input_handle)) {
80 LOG(ERROR) << "Failed to duplicate buffer handle of BitstreamBuffer";
81 OnNotifyError(bitstream_buffer.id(), INVALID_ARGUMENT);
82 return;
83 }
84
85 if (!base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle())) {
86 LOG(ERROR)
87 << "Decode(): cannot output to frame not backed by shared memory";
88 OnNotifyError(bitstream_buffer.id(), INVALID_ARGUMENT);
89 return;
90 }
91
92 base::SharedMemoryHandle output_handle =
93 channel_->ShareToGpuProcess(video_frame->shared_memory_handle());
94 if (!base::SharedMemory::IsHandleValid(output_handle)) {
95 LOG(ERROR) << "Decode(): failed to duplicate buffer handle of VideoFrame";
96 OnNotifyError(bitstream_buffer.id(), PLATFORM_FAILURE);
97 return;
98 }
99
100 size_t output_buffer_size = media::VideoFrame::AllocationSize(
101 video_frame->format(), video_frame->coded_size());
102
103 AcceleratedJpegDecoderMsg_Decode_Params decode_params;
104 decode_params.coded_size = video_frame->coded_size();
105 decode_params.input_buffer_id = bitstream_buffer.id();
106 decode_params.input_buffer_handle = input_handle;
107 decode_params.input_buffer_size = bitstream_buffer.size();
108 decode_params.output_video_frame_handle = output_handle;
109 decode_params.output_buffer_size = output_buffer_size;
110 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params));
111 }
112
113 void GpuJpegDecodeAcceleratorHost::Destroy() {
114 DCHECK(CalledOnValidThread());
115 Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_));
116
117 if (channel_) {
118 if (decoder_route_id_ != MSG_ROUTING_NONE)
119 channel_->RemoveRoute(decoder_route_id_);
120 channel_ = NULL;
121 }
122
123 delete this;
124 }
125
126 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) {
127 DVLOG(3) << __func__;
128 DCHECK(CalledOnValidThread());
129
130 if (!channel_)
131 return;
132 if (!channel_->Send(message)) {
133 DLOG(ERROR) << "Send(" << message->type() << ") failed";
134 }
135 }
136
137 void GpuJpegDecodeAcceleratorHost::OnVideoFrameReady(
138 int32_t bitstream_buffer_id) {
139 DCHECK(CalledOnValidThread());
140 DCHECK(client_);
141 client_->VideoFrameReady(bitstream_buffer_id);
142 }
143
144 void GpuJpegDecodeAcceleratorHost::OnNotifyError(int32_t bitstream_buffer_id,
145 Error error) {
146 DVLOG(2) << __func__ << ": error=" << error
147 << ", bitstream_buffer_id=" << bitstream_buffer_id;
148 DCHECK(CalledOnValidThread());
149 if (!client_)
150 return;
151
152 client_->NotifyError(bitstream_buffer_id,
153 static_cast<media::JpegDecodeAccelerator::Error>(error));
154 client_ = nullptr;
155 }
156
157 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698