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

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

Issue 1124423008: MJPEG acceleration for video capture using VAAPI, the GPU and IPC part (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mjpeg-1-media
Patch Set: gpu_jpeg_decode_accelerator.cc filter to dispatch decode task Created 5 years, 6 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 "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_(nullptr), decoder_route_id_(route_id) {
21 DCHECK(channel_);
22 }
23
24 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() {
25 DCHECK(CalledOnValidThread());
26 Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_));
27
28 if (channel_) {
29 if (decoder_route_id_ != MSG_ROUTING_NONE)
30 channel_->RemoveRoute(decoder_route_id_);
31 channel_ = nullptr;
32 }
33 }
34
35 bool GpuJpegDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) {
36 DCHECK(CalledOnValidThread());
37 bool handled = true;
38 IPC_BEGIN_MESSAGE_MAP(GpuJpegDecodeAcceleratorHost, msg)
39 IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_DecodeAck, OnDecodeAck)
40 IPC_MESSAGE_UNHANDLED(handled = false)
41 IPC_END_MESSAGE_MAP()
42 DCHECK(handled);
43 return handled;
44 }
45
46 void GpuJpegDecodeAcceleratorHost::OnChannelError() {
47 DVLOG(3) << __func__;
48 DCHECK(CalledOnValidThread());
49
50 channel_ = nullptr;
51 OnDecodeAck(kInvalidBitstreamBufferId, PLATFORM_FAILURE);
52 }
53
54 bool GpuJpegDecodeAcceleratorHost::Initialize(
55 media::JpegDecodeAccelerator::Client* client) {
56 DCHECK(CalledOnValidThread());
57
58 bool succeeded = false;
59 // This cannot be on IO thread because the msg is synchronous.
60 Send(new GpuMsg_CreateJpegDecoder(decoder_route_id_, &succeeded));
61
62 if (!succeeded) {
63 DLOG(ERROR) << "Send(GpuMsg_CreateJpegDecoder()) failed";
64 return false;
65 }
66 client_ = client;
67
68 return true;
69 }
70
71 void GpuJpegDecodeAcceleratorHost::Decode(
72 const media::BitstreamBuffer& bitstream_buffer,
73 const scoped_refptr<media::VideoFrame>& video_frame) {
74 DCHECK(CalledOnValidThread());
75 if (!channel_)
76 return;
77
78 DCHECK(
79 base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle()));
80
81 base::SharedMemoryHandle input_handle =
82 channel_->ShareToGpuProcess(bitstream_buffer.handle());
83 DCHECK(base::SharedMemory::IsHandleValid(input_handle));
piman 2015/05/26 23:31:52 ShareToGpuProcess can legitimately fail, at least
kcwu 2015/05/27 14:13:23 Done.
84 base::SharedMemoryHandle output_handle =
85 channel_->ShareToGpuProcess(video_frame->shared_memory_handle());
86 DCHECK(base::SharedMemory::IsHandleValid(output_handle));
87
88 size_t output_buffer_size = media::VideoFrame::AllocationSize(
89 video_frame->format(), video_frame->coded_size());
90
91 AcceleratedJpegDecoderMsg_Decode_Params decode_params;
92 decode_params.coded_size = video_frame->coded_size();
93 decode_params.input_buffer_id = bitstream_buffer.id();
94 decode_params.input_buffer_handle = input_handle;
95 decode_params.input_buffer_size = bitstream_buffer.size();
96 decode_params.output_video_frame_handle = output_handle;
97 decode_params.output_buffer_size = output_buffer_size;
98 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params));
99 }
100
101 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) {
102 DVLOG(3) << __func__;
103 DCHECK(CalledOnValidThread());
104
105 if (!channel_)
106 return;
107 if (!channel_->Send(message)) {
108 DLOG(ERROR) << "Send(" << message->type() << ") failed";
109 }
110 }
111
112 void GpuJpegDecodeAcceleratorHost::OnDecodeAck(int32_t bitstream_buffer_id,
113 Error error) {
114 DCHECK(CalledOnValidThread());
115
116 if (!client_)
117 return;
118
119 if (error == media::JpegDecodeAccelerator::NO_ERROR) {
120 client_->VideoFrameReady(bitstream_buffer_id);
121 } else {
122 // Only NotifyError once.
123 client_->NotifyError(bitstream_buffer_id, error);
124 client_ = nullptr;
125 }
126 }
127
128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698