OLD | NEW |
---|---|
(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/08/02 18:42:40
I feel this is no more legit than simply hard-codi
sheu
2013/08/03 01:31:03
It's not any more legit, but I think it at least c
| |
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 channel_->AddRoute(route_id_, AsWeakPtr()); | |
20 } | |
21 | |
22 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { | |
23 if (channel_) | |
24 channel_->RemoveRoute(route_id_); | |
25 } | |
26 | |
27 // static | |
28 std::vector<media::VideoEncodeAccelerator::SupportedProfile> | |
29 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() { | |
30 return GpuVideoEncodeAccelerator::GetSupportedProfiles(); | |
31 } | |
32 | |
33 bool GpuVideoEncodeAcceleratorHost::OnMessageReceived( | |
34 const IPC::Message& message) { | |
35 bool handled = true; | |
36 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message) | |
37 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_NotifyInitializeDone, | |
38 OnNotifyInitializeDone) | |
39 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers, | |
40 OnRequireBitstreamBuffers) | |
41 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_NotifyInputDone, | |
42 OnNotifyInputDone) | |
43 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_BitstreamBufferReady, | |
44 OnBitstreamBufferReady) | |
45 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_NotifyError, | |
46 OnNotifyError) | |
47 IPC_MESSAGE_UNHANDLED(handled = false) | |
48 IPC_END_MESSAGE_MAP() | |
49 DCHECK(handled); | |
50 return handled; | |
51 } | |
52 | |
53 void GpuVideoEncodeAcceleratorHost::OnChannelError() { | |
54 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::OnChannelError()"; | |
55 OnNotifyError(kPlatformFailureError); | |
56 if (channel_) { | |
57 channel_->RemoveRoute(route_id_); | |
58 channel_ = NULL; | |
59 } | |
60 } | |
61 | |
62 void GpuVideoEncodeAcceleratorHost::Initialize( | |
63 media::VideoFrame::Format input_format, | |
64 const gfx::Size& input_resolution, | |
65 media::VideoCodecProfile output_profile, | |
66 int32 initial_bitrate) { | |
67 if (!channel_) | |
68 return; | |
69 if (!Send(new AcceleratedVideoEncoderMsg_Initialize(route_id_, | |
70 input_format, | |
71 input_resolution, | |
72 output_profile, | |
73 initial_bitrate))) { | |
74 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Initialize(): Send() failed"; | |
75 } | |
76 } | |
77 | |
78 void GpuVideoEncodeAcceleratorHost::Encode(const media::BitstreamBuffer& buffer, | |
79 bool force_keyframe) { | |
80 if (!channel_) | |
81 return; | |
82 base::SharedMemoryHandle handle = | |
83 channel_->ShareToGpuProcess(buffer.handle()); | |
84 if (!base::SharedMemory::IsHandleValid(handle)) { | |
85 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Encode(): failed to " | |
86 "duplicate buffer handle for GPU process: buffer.id()=" | |
87 << buffer.id(); | |
88 OnNotifyError(kPlatformFailureError); | |
89 return; | |
90 } | |
91 if (!Send(new AcceleratedVideoEncoderMsg_Encode( | |
92 route_id_, buffer.id(), handle, buffer.size(), force_keyframe))) { | |
93 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Encode(): Send() failed: " | |
94 << "buffer.id()=" << buffer.id(); | |
95 } | |
96 } | |
97 | |
98 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( | |
99 const media::BitstreamBuffer& buffer) { | |
100 if (!channel_) | |
101 return; | |
102 base::SharedMemoryHandle handle = | |
103 channel_->ShareToGpuProcess(buffer.handle()); | |
104 if (!base::SharedMemory::IsHandleValid(handle)) { | |
105 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer(): " | |
106 "failed to duplicate buffer handle for GPU process: " | |
107 "buffer.id()=" << buffer.id(); | |
108 OnNotifyError(kPlatformFailureError); | |
109 return; | |
110 } | |
111 if (!Send(new AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer( | |
112 route_id_, buffer.id(), handle, buffer.size()))) { | |
113 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer(): " | |
114 "Send() failed: buffer.id()=" << buffer.id(); | |
115 } | |
116 } | |
117 | |
118 void GpuVideoEncodeAcceleratorHost::RequestEncodingParameterChange( | |
119 int32 bitrate) { | |
120 if (!channel_) | |
121 return; | |
122 if (!Send(new AcceleratedVideoEncoderMsg_RequestEncodingParameterChange( | |
123 route_id_, bitrate))) { | |
124 DLOG(ERROR) | |
125 << "GpuVideoEncodeAcceleratorHost::RequestEncodingParameterChange(): " | |
126 "Send() failed"; | |
127 } | |
128 } | |
129 | |
130 void GpuVideoEncodeAcceleratorHost::Destroy() { | |
131 if (channel_) { | |
132 if (!Send(new GpuChannelMsg_DestroyVideoEncoder(route_id_))) | |
133 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Destroy(): Send() failed"; | |
134 } | |
135 delete this; | |
136 } | |
137 | |
138 void GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone() { | |
139 DVLOG(2) << "GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone()"; | |
140 if (client_) | |
141 client_->NotifyInitializeDone(); | |
142 } | |
143 | |
144 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( | |
145 int input_count, | |
146 const gfx::Size& input_dimensions, | |
147 uint32 output_size) { | |
148 DVLOG(2) << "GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers(): " | |
149 "input_count=" << input_count | |
150 << ", input_dimensions=" << input_dimensions.ToString() | |
151 << ", output_size=" << output_size; | |
152 if (client_) { | |
153 client_->RequireBitstreamBuffers( | |
154 input_count, input_dimensions, output_size); | |
155 } | |
156 } | |
157 | |
158 void GpuVideoEncodeAcceleratorHost::OnNotifyInputDone( | |
159 int32 bitstream_buffer_id) { | |
160 DVLOG(3) << "GpuVideoEncodeAcceleratorHost::OnNotifyInputDone(): " | |
161 "bitstream_buffer_id=" << bitstream_buffer_id; | |
162 if (client_) | |
163 client_->NotifyInputDone(bitstream_buffer_id); | |
164 } | |
165 | |
166 void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady( | |
167 int32 bitstream_buffer_id, | |
168 uint32 payload_size, | |
169 bool key_frame) { | |
170 DVLOG(3) << "GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady(): " | |
171 "bitstream_buffer_id=" << bitstream_buffer_id | |
172 << ", payload_size=" << payload_size | |
173 << ", key_frame=" << key_frame; | |
174 if (client_) | |
175 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); | |
176 } | |
177 | |
178 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) { | |
179 DVLOG(2) << "GpuVideoEncodeAcceleratorHost::OnNotifyError(): error=" << error; | |
180 if (client_) { | |
181 client_->NotifyError(error); | |
182 client_ = NULL; | |
183 } | |
184 } | |
185 | |
186 bool GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { | |
187 if (!channel_) { | |
188 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Send(): no channel"; | |
189 delete message; | |
190 return false; | |
191 OnNotifyError(kPlatformFailureError); | |
192 } else if (!channel_->Send(message)) { | |
193 DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Send(): sending failed"; | |
194 OnNotifyError(kPlatformFailureError); | |
195 return false; | |
196 } | |
197 return true; | |
198 } | |
199 | |
200 } // namespace content | |
OLD | NEW |