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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/client/gpu_jpeg_decode_accelerator_host.cc
diff --git a/content/common/gpu/client/gpu_jpeg_decode_accelerator_host.cc b/content/common/gpu/client/gpu_jpeg_decode_accelerator_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf097babffe8890c96dbf21fc8206733dfa81f50
--- /dev/null
+++ b/content/common/gpu/client/gpu_jpeg_decode_accelerator_host.cc
@@ -0,0 +1,128 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/gpu/client/gpu_jpeg_decode_accelerator_host.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "content/common/gpu/client/gpu_channel_host.h"
+#include "content/common/gpu/gpu_messages.h"
+#include "ipc/ipc_message_macros.h"
+#include "ipc/ipc_message_utils.h"
+
+using media::JpegDecodeAccelerator;
+namespace content {
+
+GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost(
+ GpuChannelHost* channel,
+ int32 route_id)
+ : channel_(channel), client_(nullptr), decoder_route_id_(route_id) {
+ DCHECK(channel_);
+}
+
+GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() {
+ DCHECK(CalledOnValidThread());
+ Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_));
+
+ if (channel_) {
+ if (decoder_route_id_ != MSG_ROUTING_NONE)
+ channel_->RemoveRoute(decoder_route_id_);
+ channel_ = nullptr;
+ }
+}
+
+bool GpuJpegDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) {
+ DCHECK(CalledOnValidThread());
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(GpuJpegDecodeAcceleratorHost, msg)
+ IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_DecodeAck, OnDecodeAck)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ DCHECK(handled);
+ return handled;
+}
+
+void GpuJpegDecodeAcceleratorHost::OnChannelError() {
+ DVLOG(3) << __func__;
+ DCHECK(CalledOnValidThread());
+
+ channel_ = nullptr;
+ OnDecodeAck(kInvalidBitstreamBufferId, PLATFORM_FAILURE);
+}
+
+bool GpuJpegDecodeAcceleratorHost::Initialize(
+ media::JpegDecodeAccelerator::Client* client) {
+ DCHECK(CalledOnValidThread());
+
+ bool succeeded = false;
+ // This cannot be on IO thread because the msg is synchronous.
+ Send(new GpuMsg_CreateJpegDecoder(decoder_route_id_, &succeeded));
+
+ if (!succeeded) {
+ DLOG(ERROR) << "Send(GpuMsg_CreateJpegDecoder()) failed";
+ return false;
+ }
+ client_ = client;
+
+ return true;
+}
+
+void GpuJpegDecodeAcceleratorHost::Decode(
+ const media::BitstreamBuffer& bitstream_buffer,
+ const scoped_refptr<media::VideoFrame>& video_frame) {
+ DCHECK(CalledOnValidThread());
+ if (!channel_)
+ return;
+
+ DCHECK(
+ base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle()));
+
+ base::SharedMemoryHandle input_handle =
+ channel_->ShareToGpuProcess(bitstream_buffer.handle());
+ 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.
+ base::SharedMemoryHandle output_handle =
+ channel_->ShareToGpuProcess(video_frame->shared_memory_handle());
+ DCHECK(base::SharedMemory::IsHandleValid(output_handle));
+
+ size_t output_buffer_size = media::VideoFrame::AllocationSize(
+ video_frame->format(), video_frame->coded_size());
+
+ AcceleratedJpegDecoderMsg_Decode_Params decode_params;
+ decode_params.coded_size = video_frame->coded_size();
+ decode_params.input_buffer_id = bitstream_buffer.id();
+ decode_params.input_buffer_handle = input_handle;
+ decode_params.input_buffer_size = bitstream_buffer.size();
+ decode_params.output_video_frame_handle = output_handle;
+ decode_params.output_buffer_size = output_buffer_size;
+ Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params));
+}
+
+void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) {
+ DVLOG(3) << __func__;
+ DCHECK(CalledOnValidThread());
+
+ if (!channel_)
+ return;
+ if (!channel_->Send(message)) {
+ DLOG(ERROR) << "Send(" << message->type() << ") failed";
+ }
+}
+
+void GpuJpegDecodeAcceleratorHost::OnDecodeAck(int32_t bitstream_buffer_id,
+ Error error) {
+ DCHECK(CalledOnValidThread());
+
+ if (!client_)
+ return;
+
+ if (error == media::JpegDecodeAccelerator::NO_ERROR) {
+ client_->VideoFrameReady(bitstream_buffer_id);
+ } else {
+ // Only NotifyError once.
+ client_->NotifyError(bitstream_buffer_id, error);
+ client_ = nullptr;
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698