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

Unified 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: address most comments Created 5 years, 8 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..80c0e807697dbe5f0c33ae7508197f22b4042b53
--- /dev/null
+++ b/content/common/gpu/client/gpu_jpeg_decode_accelerator_host.cc
@@ -0,0 +1,175 @@
+// 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 "base/message_loop/message_loop.h"
+#include "base/synchronization/waitable_event.h"
wuchengli 2015/04/15 07:11:57 is this required?
kcwu 2015/04/16 14:38:27 Done.
+#include "content/common/gpu/client/gpu_channel_host.h"
+#include "content/common/gpu/gpu_messages.h"
+#include "content/common/view_messages.h"
wuchengli 2015/04/15 07:11:57 Is this required?
kcwu 2015/04/16 14:38:27 Done.
+#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_(NULL),
+ decoder_route_id_(route_id),
+ weak_this_factory_(this) {
+ DCHECK(channel_);
+}
+
+GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() {
+ DCHECK(CalledOnValidThread());
+
+ if (channel_ && decoder_route_id_ != MSG_ROUTING_NONE)
+ channel_->RemoveRoute(decoder_route_id_);
+}
+
+bool GpuJpegDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) {
+ DCHECK(CalledOnValidThread());
wuchengli 2015/04/15 07:11:57 OnMessageReceived is called on IO thread, which is
kcwu 2015/04/20 17:47:58 Done.
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(GpuJpegDecodeAcceleratorHost, msg)
+ IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_VideoFrameReady,
wuchengli 2015/04/15 07:11:57 Indentation? Run git cl format.
kcwu 2015/04/16 14:38:27 Fixed. The indentation was broken due to git cl fo
+ OnVideoFrameReady)
+ IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_NotifyError, OnNotifyError)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ DCHECK(handled);
+ // See OnNotifyError for why |this| mustn't be used after OnNotifyError might
+ // have been called above.
+ return handled;
+}
+
+void GpuJpegDecodeAcceleratorHost::OnChannelError() {
+ DVLOG(3) << __func__;
+ DCHECK(CalledOnValidThread());
+ if (channel_) {
+ if (decoder_route_id_ != MSG_ROUTING_NONE)
+ channel_->RemoveRoute(decoder_route_id_);
+ channel_ = NULL;
+ }
+ PostNotifyError(kInvalidBitstreamBufferId, PLATFORM_FAILURE);
+}
+
+bool GpuJpegDecodeAcceleratorHost::Initialize(
+ media::JpegDecodeAccelerator::Client* client) {
+ DCHECK(CalledOnValidThread());
+
+ bool succeeded = false;
+ // this cannot on main thread or IO thread
wuchengli 2015/04/15 07:11:57 s/cannot on/cannon be/. Explain why this cannot be
kcwu 2015/04/20 17:47:58 Done. Recheck the code, it's okay on main thread.
+ Send(new GpuMsg_CreateJpegDecoder(decoder_route_id_, &succeeded));
+
+ if (!succeeded) {
+ DLOG(ERROR) << "Send(GpuMsg_CreateJpegDecoder()) failed";
+ channel_->RemoveRoute(decoder_route_id_);
+ 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;
+
+ base::SharedMemoryHandle input_handle =
+ channel_->ShareToGpuProcess(bitstream_buffer.handle());
+ if (!base::SharedMemory::IsHandleValid(input_handle)) {
+ DLOG(ERROR) << "Failed to duplicate buffer handler of BitstreamBuffer";
wuchengli 2015/04/15 07:11:57 Use LOG(ERROR) because this shouldn't happen. s/ha
kcwu 2015/04/16 14:38:27 Done.
+ PostNotifyError(bitstream_buffer.id(), INVALID_ARGUMENT);
+ return;
+ }
+
+ if (!base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle())) {
+ DLOG(ERROR)
+ << "Decode(): cannot output to frame not backed by shared memory";
wuchengli 2015/04/15 07:11:57 Use LOG(ERROR) because this shouldn't happen.
kcwu 2015/04/16 14:38:27 Done.
+ PostNotifyError(bitstream_buffer.id(), PLATFORM_FAILURE);
wuchengli 2015/04/15 07:11:57 Maybe INVALID_ARGUMENT? Why this is a PLATFORM_FAI
kcwu 2015/04/16 14:38:27 Done.
+ return;
+ }
+
+ base::SharedMemoryHandle output_handle =
+ channel_->ShareToGpuProcess(video_frame->shared_memory_handle());
+ if (!base::SharedMemory::IsHandleValid(output_handle)) {
+ DLOG(ERROR) << "Decode(): failed to duplicate buffer handle of VideoFrame";
wuchengli 2015/04/15 07:11:57 s/DLOG/LOG/
kcwu 2015/04/16 14:38:27 Done.
+ PostNotifyError(bitstream_buffer.id(), PLATFORM_FAILURE);
+ return;
+ }
+
+ 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::Destroy() {
+ DCHECK(CalledOnValidThread());
+ if (channel_)
+ Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_));
+ client_ = NULL;
+ delete this;
+}
+
+void GpuJpegDecodeAcceleratorHost::PostNotifyError(int32_t bitstream_buffer_id,
+ Error error) {
+ DCHECK(CalledOnValidThread());
+ DVLOG(2) << "PostNotifyDecodeResult(): error=" << error;
wuchengli 2015/04/15 07:11:57 s/PostNotifyDecodeResult/__func__? Also log |bitst
kcwu 2015/04/16 14:38:27 Done.
+ // Post the error notification back to this thread, to avoid re-entrancy.
wuchengli 2015/04/15 07:11:57 I don't understand. Can you explain?
kcwu 2015/04/20 17:47:58 This is copied from GVEAHost. I guess it try to av
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&GpuJpegDecodeAcceleratorHost::OnNotifyError,
+ weak_this_factory_.GetWeakPtr(), bitstream_buffer_id, error));
+}
+
+void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) {
+ DVLOG(3) << __func__;
wuchengli 2015/04/15 07:11:57 Be consistent with the order DVLOG and DCHECK(Call
kcwu 2015/04/16 14:38:27 Done.
+ DCHECK(CalledOnValidThread());
+ uint32 message_type = message->type();
+ if (!channel_->Send(message)) {
+ DLOG(ERROR) << "Send(" << message_type << ") failed";
+ }
+}
+
+void GpuJpegDecodeAcceleratorHost::OnVideoFrameReady(
+ int32_t bitstream_buffer_id) {
+ DCHECK(CalledOnValidThread());
wuchengli 2015/04/15 07:11:57 Change DCHECK to IO thread. Please enable the DCHE
kcwu 2015/04/20 17:47:58 Done.
+
+ DCHECK(client_);
+ client_->VideoFrameReady(bitstream_buffer_id);
+}
+
+void GpuJpegDecodeAcceleratorHost::OnNotifyError(int32_t bitstream_buffer_id,
+ Error error) {
+ DCHECK(CalledOnValidThread());
wuchengli 2015/04/15 07:11:57 Change DCHECK to IO thread.
kcwu 2015/04/20 17:47:58 Done.
+ if (!client_)
+ return;
+ weak_this_factory_.InvalidateWeakPtrs();
+
+ // Client::NotifyError() may Destroy() |this|, so calling it needs to be the
+ // last thing done on this stack!
+ media::JpegDecodeAccelerator::Client* client = NULL;
+ std::swap(client, client_);
wuchengli 2015/04/15 07:11:57 Why do we need to swap? To avoid client->NotifyErr
kcwu 2015/04/20 17:47:58 Yes, I think so. This is copied from GVDAHost.
+ client->NotifyError(bitstream_buffer_id,
+ static_cast<media::JpegDecodeAccelerator::Error>(error));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698