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

Unified Diff: content/common/gpu/media/media_channel.cc

Issue 1736643005: Decouple Media Service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove base changes Created 4 years, 10 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/media/media_channel.cc
diff --git a/content/common/gpu/media/media_channel.cc b/content/common/gpu/media/media_channel.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b651e3e162dc5cf37678a883618fcbbfdbcb5350
--- /dev/null
+++ b/content/common/gpu/media/media_channel.cc
@@ -0,0 +1,124 @@
+// Copyright 2016 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/media/media_channel.h"
+
+#include "content/common/gpu/gpu_channel.h"
+#include "content/common/gpu/media/gpu_video_decode_accelerator.h"
+#include "content/common/gpu/media/gpu_video_encode_accelerator.h"
+#include "content/common/gpu/media/media_messages.h"
+
+namespace content {
+
+namespace {
+
+void SendCreateJpegDecoderResult(
+ scoped_ptr<IPC::Message> reply_message,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
+ base::WeakPtr<GpuChannel> channel,
+ scoped_refptr<GpuChannelMessageFilter> filter,
+ bool result) {
+ GpuChannelMsg_CreateJpegDecoder::WriteReplyParams(reply_message.get(),
+ result);
+ if (io_task_runner->BelongsToCurrentThread()) {
+ filter->Send(reply_message.release());
+ } else if (channel) {
+ channel->Send(reply_message.release());
+ }
+}
+
+} // namespace
+
+MediaChannel::MediaChannel(GpuChannel* channel) : channel_(channel) {}
+
+MediaChannel::~MediaChannel() {}
+
+bool MediaChannel::Send(IPC::Message* msg) {
+ return channel_->Send(msg);
+}
+
+bool MediaChannel::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(MediaChannel, message)
+ IPC_MESSAGE_HANDLER_GENERIC(GpuCommandBufferMsg_CreateVideoDecoder,
dcheng 2016/03/03 23:46:42 Why IPC_MESSAGE_HANDLER_GENERIC? Why not use the m
Fady Samuel 2016/03/04 01:46:32 Switched to control messages.
piman 2016/03/04 20:13:28 You can't do that. That's probably related to the
+ OnCreateVideoDecoder(message))
+ IPC_MESSAGE_HANDLER_GENERIC(GpuCommandBufferMsg_CreateVideoEncoder,
+ OnCreateVideoEncoder(message))
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateJpegDecoder,
+ OnCreateJpegDecoder)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void MediaChannel::OnCreateJpegDecoder(int32_t route_id,
+ IPC::Message* reply_msg) {
+ scoped_ptr<IPC::Message> msg(reply_msg);
+ if (!jpeg_decoder_) {
+ jpeg_decoder_.reset(
+ new GpuJpegDecodeAccelerator(channel_, channel_->io_task_runner()));
+ }
+ jpeg_decoder_->AddClient(
+ route_id, base::Bind(&SendCreateJpegDecoderResult, base::Passed(&msg),
+ channel_->io_task_runner(), channel_->AsWeakPtr(),
+ make_scoped_refptr(channel_->filter())));
+}
+
+void MediaChannel::OnCreateVideoDecoder(const IPC::Message& message) {
+ TRACE_EVENT0("gpu", "MediaChannel::OnCreateVideoDecoder");
+
+ GpuCommandBufferStub* stub =
+ channel_->LookupCommandBuffer(message.routing_id());
+ DCHECK(stub);
+
+ GpuCommandBufferMsg_CreateVideoDecoder::SendParam params;
+ if (!GpuCommandBufferMsg_CreateVideoDecoder::ReadSendParam(&message,
+ &params)) {
+ return;
+ }
+
+ GpuVideoDecodeAccelerator* decoder = new GpuVideoDecodeAccelerator(
+ base::get<1>(params), stub, channel_->io_task_runner());
+ bool succeeded = decoder->Initialize(base::get<0>(params));
+ IPC::Message* reply_message = IPC::SyncMessage::GenerateReply(&message);
+ GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(reply_message,
+ succeeded);
+ Send(reply_message);
+
+ // decoder is registered as a DestructionObserver of this stub and will
+ // self-delete during destruction of this stub.
+}
+
+void MediaChannel::OnCreateVideoEncoder(const IPC::Message& message) {
+ TRACE_EVENT0("gpu", "MediaChannel::OnCreateVideoEncoder");
+
+ GpuCommandBufferStub* stub =
+ channel_->LookupCommandBuffer(message.routing_id());
+ DCHECK(stub);
+
+ GpuCommandBufferMsg_CreateVideoEncoder::SendParam params;
+ if (!GpuCommandBufferMsg_CreateVideoEncoder::ReadSendParam(&message,
+ &params)) {
+ return;
+ }
+ media::VideoPixelFormat input_format = base::get<0>(params);
+ gfx::Size input_visible_size = base::get<1>(params);
+ media::VideoCodecProfile output_profile = base::get<2>(params);
+ uint32_t initial_bitrate = base::get<3>(params);
+ int32_t route_id = base::get<4>(params);
+
+ GpuVideoEncodeAccelerator* encoder =
+ new GpuVideoEncodeAccelerator(route_id, stub);
+ bool succeeded = encoder->Initialize(input_format, input_visible_size,
+ output_profile, initial_bitrate);
+ IPC::Message* reply_message = IPC::SyncMessage::GenerateReply(&message);
+ GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message,
+ succeeded);
+ Send(reply_message);
+
+ // encoder is registered as a DestructionObserver of this stub and will
+ // self-delete during destruction of this stub.
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698