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

Side by Side 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, 9 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 2016 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/media/media_channel.h"
6
7 #include "content/common/gpu/gpu_channel.h"
8 #include "content/common/gpu/media/gpu_video_decode_accelerator.h"
9 #include "content/common/gpu/media/gpu_video_encode_accelerator.h"
10 #include "content/common/gpu/media/media_messages.h"
11
12 namespace content {
13
14 namespace {
15
16 void SendCreateJpegDecoderResult(
17 scoped_ptr<IPC::Message> reply_message,
18 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
19 base::WeakPtr<GpuChannel> channel,
20 scoped_refptr<GpuChannelMessageFilter> filter,
21 bool result) {
22 GpuChannelMsg_CreateJpegDecoder::WriteReplyParams(reply_message.get(),
23 result);
24 if (io_task_runner->BelongsToCurrentThread()) {
25 filter->Send(reply_message.release());
26 } else if (channel) {
27 channel->Send(reply_message.release());
28 }
29 }
30
31 } // namespace
32
33 MediaChannel::MediaChannel(GpuChannel* channel) : channel_(channel) {}
34
35 MediaChannel::~MediaChannel() {}
36
37 bool MediaChannel::Send(IPC::Message* msg) {
38 return channel_->Send(msg);
39 }
40
41 bool MediaChannel::OnMessageReceived(const IPC::Message& message) {
42 bool handled = true;
43 IPC_BEGIN_MESSAGE_MAP(MediaChannel, message)
44 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
45 OnCreateVideoDecoder(message))
46 IPC_MESSAGE_HANDLER_GENERIC(GpuCommandBufferMsg_CreateVideoEncoder,
47 OnCreateVideoEncoder(message))
48 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateJpegDecoder,
49 OnCreateJpegDecoder)
50 IPC_MESSAGE_UNHANDLED(handled = false)
51 IPC_END_MESSAGE_MAP()
52 return handled;
53 }
54
55 void MediaChannel::OnCreateJpegDecoder(int32_t route_id,
56 IPC::Message* reply_msg) {
57 scoped_ptr<IPC::Message> msg(reply_msg);
58 if (!jpeg_decoder_) {
59 jpeg_decoder_.reset(
60 new GpuJpegDecodeAccelerator(channel_, channel_->io_task_runner()));
61 }
62 jpeg_decoder_->AddClient(
63 route_id, base::Bind(&SendCreateJpegDecoderResult, base::Passed(&msg),
64 channel_->io_task_runner(), channel_->AsWeakPtr(),
65 make_scoped_refptr(channel_->filter())));
66 }
67
68 void MediaChannel::OnCreateVideoDecoder(const IPC::Message& message) {
69 TRACE_EVENT0("gpu", "MediaChannel::OnCreateVideoDecoder");
70
71 GpuCommandBufferStub* stub =
72 channel_->LookupCommandBuffer(message.routing_id());
73 DCHECK(stub);
74
75 GpuCommandBufferMsg_CreateVideoDecoder::SendParam params;
76 if (!GpuCommandBufferMsg_CreateVideoDecoder::ReadSendParam(&message,
77 &params)) {
78 return;
79 }
80
81 GpuVideoDecodeAccelerator* decoder = new GpuVideoDecodeAccelerator(
82 base::get<1>(params), stub, channel_->io_task_runner());
83 bool succeeded = decoder->Initialize(base::get<0>(params));
84 IPC::Message* reply_message = IPC::SyncMessage::GenerateReply(&message);
85 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(reply_message,
86 succeeded);
87 Send(reply_message);
88
89 // decoder is registered as a DestructionObserver of this stub and will
90 // self-delete during destruction of this stub.
91 }
92
93 void MediaChannel::OnCreateVideoEncoder(const IPC::Message& message) {
94 TRACE_EVENT0("gpu", "MediaChannel::OnCreateVideoEncoder");
95
96 GpuCommandBufferStub* stub =
97 channel_->LookupCommandBuffer(message.routing_id());
98 DCHECK(stub);
99
100 GpuCommandBufferMsg_CreateVideoEncoder::SendParam params;
101 if (!GpuCommandBufferMsg_CreateVideoEncoder::ReadSendParam(&message,
102 &params)) {
103 return;
104 }
105 media::VideoPixelFormat input_format = base::get<0>(params);
106 gfx::Size input_visible_size = base::get<1>(params);
107 media::VideoCodecProfile output_profile = base::get<2>(params);
108 uint32_t initial_bitrate = base::get<3>(params);
109 int32_t route_id = base::get<4>(params);
110
111 GpuVideoEncodeAccelerator* encoder =
112 new GpuVideoEncodeAccelerator(route_id, stub);
113 bool succeeded = encoder->Initialize(input_format, input_visible_size,
114 output_profile, initial_bitrate);
115 IPC::Message* reply_message = IPC::SyncMessage::GenerateReply(&message);
116 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(reply_message,
117 succeeded);
118 Send(reply_message);
119
120 // encoder is registered as a DestructionObserver of this stub and will
121 // self-delete during destruction of this stub.
122 }
123
124 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698