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

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: 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 if (!base::SharedMemory::IsHandleValid(input_handle)) {
84 DLOG(ERROR) << "Failed to duplicate handle of BitstreamBuffer";
85 return;
86 }
87 base::SharedMemoryHandle output_handle =
88 channel_->ShareToGpuProcess(video_frame->shared_memory_handle());
89 if (!base::SharedMemory::IsHandleValid(output_handle)) {
90 DLOG(ERROR) << "Failed to duplicate handle of VideoFrame";
91 if (input_handle.auto_close) {
92 // Defer closing task to the ScopedFD.
93 base::ScopedFD(input_handle.fd);
piman 2015/05/28 22:01:39 This won't work on non-posix. You can use SharedMe
94 }
95 return;
96 }
97
98 size_t output_buffer_size = media::VideoFrame::AllocationSize(
99 video_frame->format(), video_frame->coded_size());
100
101 AcceleratedJpegDecoderMsg_Decode_Params decode_params;
102 decode_params.coded_size = video_frame->coded_size();
103 decode_params.input_buffer_id = bitstream_buffer.id();
104 decode_params.input_buffer_handle = input_handle;
105 decode_params.input_buffer_size = bitstream_buffer.size();
106 decode_params.output_video_frame_handle = output_handle;
107 decode_params.output_buffer_size = output_buffer_size;
108 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params));
109 }
110
111 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) {
112 DCHECK(CalledOnValidThread());
113
114 if (!channel_)
piman 2015/05/28 22:01:39 actually, you need to delete message here. Send gu
kcwu 2015/06/02 15:07:25 Done.
115 return;
116 if (!channel_->Send(message)) {
117 DLOG(ERROR) << "Send(" << message->type() << ") failed";
118 }
119 }
120
121 void GpuJpegDecodeAcceleratorHost::OnDecodeAck(int32_t bitstream_buffer_id,
122 Error error) {
123 DCHECK(CalledOnValidThread());
124
125 if (!client_)
126 return;
127
128 if (error == media::JpegDecodeAccelerator::NO_ERROR) {
129 client_->VideoFrameReady(bitstream_buffer_id);
130 } else {
131 // Only NotifyError once.
132 client_->NotifyError(bitstream_buffer_id, error);
133 client_ = nullptr;
134 }
135 }
136
137 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698