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

Side by Side Diff: content/common/gpu/client/gpu_video_encode_accelerator_host.cc

Issue 20632002: Add media::VideoEncodeAccelerator with WebRTC integration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: 7fd9dbd5 More debugging statements, some fixes Created 7 years, 4 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 (c) 2013 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_video_encode_accelerator_host.h"
6
7 #include "base/logging.h"
8 #include "content/common/gpu/client/gpu_channel_host.h"
9 #include "content/common/gpu/gpu_messages.h"
10 #include "content/common/gpu/media/gpu_video_encode_accelerator.h"
Ami GONE FROM CHROMIUM 2013/07/31 23:01:12 This seems unkosher. Why is renderer-side code in
sheu 2013/08/02 01:27:49 Yes this is slightly icky. My thought is that sin
11
12 namespace content {
13
14 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost(
15 media::VideoEncodeAccelerator::Client* client,
16 const scoped_refptr<GpuChannelHost>& gpu_channel_host,
17 int32 route_id)
18 : client_(client), channel_(gpu_channel_host), route_id_(route_id) {}
19
20 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() {
21 if (channel_)
22 channel_->RemoveRoute(route_id_);
Ami GONE FROM CHROMIUM 2013/07/31 23:01:12 Can the AddRoute be done in the ctor for symmetry?
sheu 2013/08/02 01:27:49 Done.
23 }
24
25 // static
26 std::vector<media::VideoEncodeAccelerator::SupportedProfile>
27 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() {
28 return GpuVideoEncodeAccelerator::GetSupportedProfiles();
Ami GONE FROM CHROMIUM 2013/07/31 23:01:12 see above
29 }
30
31 bool GpuVideoEncodeAcceleratorHost::OnMessageReceived(
32 const IPC::Message& message) {
33 bool handled = true;
34 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message)
35 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_NotifyInitializeDone,
36 OnNotifyInitializeDone)
37 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers,
38 OnRequireBitstreamBuffers)
39 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_NotifyInputDone,
40 OnNotifyInputDone)
41 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_BitstreamBufferReady,
42 OnBitstreamBufferReady)
43 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_NotifyError,
44 OnNotifyError)
45 IPC_MESSAGE_UNHANDLED(handled = false)
46 IPC_END_MESSAGE_MAP()
47 DCHECK(handled);
48 return handled;
49 }
50
51 void GpuVideoEncodeAcceleratorHost::OnChannelError() {
52 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::OnChannelError()";
53 OnNotifyError(kPlatformFailureError);
54 if (channel_) {
55 channel_->RemoveRoute(route_id_);
56 channel_ = NULL;
57 }
58 }
59
60 void GpuVideoEncodeAcceleratorHost::Initialize(
61 media::VideoFrame::Format input_format,
62 const gfx::Size& input_resolution,
63 media::VideoCodecProfile output_profile,
64 int32 initial_bitrate) {
65 if (!channel_)
66 return;
67 if (!Send(new AcceleratedVideoEncoderMsg_Initialize(route_id_,
68 input_format,
69 input_resolution,
70 output_profile,
71 initial_bitrate))) {
72 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Initialize(): Send() failed";
73 }
74 }
75
76 void GpuVideoEncodeAcceleratorHost::Encode(const media::BitstreamBuffer& buffer,
77 bool force_keyframe) {
78 if (!channel_)
79 return;
80 base::SharedMemoryHandle handle =
81 channel_->ShareToGpuProcess(buffer.handle());
82 if (!base::SharedMemory::IsHandleValid(handle)) {
83 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Encode(): failed to "
84 "duplicate buffer handle for GPU process: buffer.id()="
85 << buffer.id();
86 return;
Ami GONE FROM CHROMIUM 2013/07/31 23:01:12 NotifyError?
sheu 2013/08/02 01:27:49 Done.
87 }
88 if (!Send(new AcceleratedVideoEncoderMsg_Encode(
89 route_id_, buffer.id(), handle, buffer.size(), force_keyframe))) {
90 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Encode(): Send() failed: "
91 << "buffer.id()=" << buffer.id();
92 }
93 }
94
95 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer(
96 const media::BitstreamBuffer& buffer) {
97 if (!channel_)
98 return;
99 base::SharedMemoryHandle handle =
100 channel_->ShareToGpuProcess(buffer.handle());
101 if (!base::SharedMemory::IsHandleValid(handle)) {
102 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer(): "
103 "failed to duplicate buffer handle for GPU process: "
104 "buffer.id()=" << buffer.id();
Ami GONE FROM CHROMIUM 2013/07/31 23:01:12 NotifyError
sheu 2013/08/02 01:27:49 Done.
105 return;
106 }
107 if (!Send(new AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer(
108 route_id_, buffer.id(), handle, buffer.size()))) {
109 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer(): "
110 "Send() failed: buffer.id()=" << buffer.id();
111 }
112 }
113
114 void GpuVideoEncodeAcceleratorHost::RequestEncodingParameterChange(
115 int32 bitrate) {
116 if (!channel_)
117 return;
118 if (!Send(new AcceleratedVideoEncoderMsg_RequestEncodingParameterChange(
119 route_id_, bitrate))) {
120 DLOG(ERROR)
121 << "GpuVideoEncodeAcceleratorHost::RequestEncodingParameterChange(): "
122 "Send() failed";
123 }
124 }
125
126 void GpuVideoEncodeAcceleratorHost::Destroy() {
127 if (channel_)
Ami GONE FROM CHROMIUM 2013/07/31 23:01:12 braces on multiline if bodies
sheu 2013/08/02 01:27:49 Done.
128 if (!Send(new GpuChannelMsg_DestroyVideoEncoder(route_id_)))
129 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Destroy(): Send() failed";
130
131 delete this;
132 }
133
134 void GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone() {
135 DVLOG(2) << "GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone()";
136 if (client_)
137 client_->NotifyInitializeDone();
138 }
139
140 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers(
141 int input_count,
142 const gfx::Size& input_dimensions,
143 uint32 output_size) {
144 DVLOG(2) << "GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers(): "
145 "input_count=" << input_count
146 << ", input_dimensions=" << input_dimensions.width()
147 << "x" << input_dimensions.height()
148 << ", output_size=" << output_size;
149 if (client_) {
150 client_->RequireBitstreamBuffers(
151 input_count, input_dimensions, output_size);
152 }
153 }
154
155 void GpuVideoEncodeAcceleratorHost::OnNotifyInputDone(
156 int32 bitstream_buffer_id) {
157 DVLOG(3) << "GpuVideoEncodeAcceleratorHost::OnNotifyInputDone(): "
158 "bitstream_buffer_id=" << bitstream_buffer_id;
159 if (client_)
160 client_->NotifyInputDone(bitstream_buffer_id);
161 }
162
163 void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady(
164 int32 bitstream_buffer_id,
165 uint32 payload_size,
166 bool key_frame) {
167 DVLOG(3) << "GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady(): "
168 "bitstream_buffer_id=" << bitstream_buffer_id
169 << ", payload_size=" << payload_size
170 << ", key_frame=" << key_frame;
171 if (client_)
172 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame);
173 }
174
175 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) {
176 DVLOG(2) << "GpuVideoEncodeAcceleratorHost::OnNotifyError(): error=" << error;
177 if (client_) {
178 client_->NotifyError(error);
179 client_ = NULL;
180 }
181 }
182
183 bool GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) {
184 if (!channel_) {
185 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Send(): no channel";
186 delete message;
187 return false;
188 OnNotifyError(kPlatformFailureError);
189 } else if (!channel_->Send(message)) {
190 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Send(): sending failed";
191 OnNotifyError(kPlatformFailureError);
192 return false;
193 }
194 return true;
195 }
196
197 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698