OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h" | 5 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "gpu/ipc/client/gpu_channel_host.h" | 10 #include "gpu/ipc/client/gpu_channel_host.h" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
12 #include "media/gpu/gpu_video_accelerator_util.h" | 12 #include "media/gpu/gpu_video_accelerator_util.h" |
13 #include "media/gpu/ipc/common/media_messages.h" | 13 #include "media/gpu/ipc/common/media_messages.h" |
14 #include "media/video/video_encode_accelerator.h" | 14 #include "media/video/video_encode_accelerator.h" |
15 #include "ui/gfx/gpu_memory_buffer.h" | 15 #include "ui/gfx/gpu_memory_buffer.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
19 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( | 19 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( |
20 gpu::CommandBufferProxyImpl* impl) | 20 gpu::CommandBufferProxyImpl* impl) |
21 : channel_(impl->channel()), | 21 : channel_(impl->channel()), |
22 encoder_route_id_(MSG_ROUTING_NONE), | 22 encoder_route_id_(MSG_ROUTING_NONE), |
23 client_(NULL), | 23 client_(nullptr), |
24 impl_(impl), | 24 impl_(impl), |
25 next_frame_id_(0), | 25 next_frame_id_(0), |
26 weak_this_factory_(this) { | 26 weak_this_factory_(this) { |
27 DCHECK(channel_); | 27 DCHECK(channel_); |
28 DCHECK(impl_); | 28 DCHECK(impl_); |
29 impl_->AddDeletionObserver(this); | 29 impl_->AddDeletionObserver(this); |
30 } | 30 } |
31 | 31 |
32 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { | 32 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { |
33 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
(...skipping 21 matching lines...) Expand all Loading... |
55 // See OnNotifyError for why |this| mustn't be used after OnNotifyError might | 55 // See OnNotifyError for why |this| mustn't be used after OnNotifyError might |
56 // have been called above. | 56 // have been called above. |
57 return handled; | 57 return handled; |
58 } | 58 } |
59 | 59 |
60 void GpuVideoEncodeAcceleratorHost::OnChannelError() { | 60 void GpuVideoEncodeAcceleratorHost::OnChannelError() { |
61 DCHECK(CalledOnValidThread()); | 61 DCHECK(CalledOnValidThread()); |
62 if (channel_) { | 62 if (channel_) { |
63 if (encoder_route_id_ != MSG_ROUTING_NONE) | 63 if (encoder_route_id_ != MSG_ROUTING_NONE) |
64 channel_->RemoveRoute(encoder_route_id_); | 64 channel_->RemoveRoute(encoder_route_id_); |
65 channel_ = NULL; | 65 channel_ = nullptr; |
66 } | 66 } |
67 PostNotifyError(FROM_HERE, kPlatformFailureError, "OnChannelError()"); | 67 PostNotifyError(FROM_HERE, kPlatformFailureError, "OnChannelError()"); |
68 } | 68 } |
69 | 69 |
70 VideoEncodeAccelerator::SupportedProfiles | 70 VideoEncodeAccelerator::SupportedProfiles |
71 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() { | 71 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() { |
72 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
73 if (!channel_) | 73 if (!channel_) |
74 return VideoEncodeAccelerator::SupportedProfiles(); | 74 return VideoEncodeAccelerator::SupportedProfiles(); |
75 return GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles( | 75 return GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles( |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 return; | 165 return; |
166 | 166 |
167 Send(new AcceleratedVideoEncoderMsg_RequestEncodingParametersChange( | 167 Send(new AcceleratedVideoEncoderMsg_RequestEncodingParametersChange( |
168 encoder_route_id_, bitrate, framerate)); | 168 encoder_route_id_, bitrate, framerate)); |
169 } | 169 } |
170 | 170 |
171 void GpuVideoEncodeAcceleratorHost::Destroy() { | 171 void GpuVideoEncodeAcceleratorHost::Destroy() { |
172 DCHECK(CalledOnValidThread()); | 172 DCHECK(CalledOnValidThread()); |
173 if (channel_) | 173 if (channel_) |
174 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_)); | 174 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_)); |
175 client_ = NULL; | 175 client_ = nullptr; |
176 delete this; | 176 delete this; |
177 } | 177 } |
178 | 178 |
179 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { | 179 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { |
180 DCHECK(CalledOnValidThread()); | 180 DCHECK(CalledOnValidThread()); |
181 impl_ = NULL; | 181 impl_ = nullptr; |
182 | 182 |
183 // The gpu::CommandBufferProxyImpl is going away; error out this VEA. | 183 // The gpu::CommandBufferProxyImpl is going away; error out this VEA. |
184 OnChannelError(); | 184 OnChannelError(); |
185 } | 185 } |
186 | 186 |
187 void GpuVideoEncodeAcceleratorHost::EncodeGpuMemoryBufferFrame( | 187 void GpuVideoEncodeAcceleratorHost::EncodeGpuMemoryBufferFrame( |
188 const scoped_refptr<VideoFrame>& frame, | 188 const scoped_refptr<VideoFrame>& frame, |
189 bool force_keyframe) { | 189 bool force_keyframe) { |
190 DCHECK_EQ(VideoFrame::NumPlanes(PIXEL_FORMAT_I420), | 190 DCHECK_EQ(VideoFrame::NumPlanes(PIXEL_FORMAT_I420), |
191 frame->gpu_memory_buffer_handles().size()); | 191 frame->gpu_memory_buffer_handles().size()); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 PostNotifyError(FROM_HERE, kPlatformFailureError, | 262 PostNotifyError(FROM_HERE, kPlatformFailureError, |
263 base::StringPrintf("Send(%d) failed", message_type)); | 263 base::StringPrintf("Send(%d) failed", message_type)); |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( | 267 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( |
268 uint32_t input_count, | 268 uint32_t input_count, |
269 const gfx::Size& input_coded_size, | 269 const gfx::Size& input_coded_size, |
270 uint32_t output_buffer_size) { | 270 uint32_t output_buffer_size) { |
271 DCHECK(CalledOnValidThread()); | 271 DCHECK(CalledOnValidThread()); |
272 DVLOG(2) << "OnRequireBitstreamBuffers(): input_count=" << input_count | 272 DVLOG(2) << __FUNCTION__ << " input_count=" << input_count |
273 << ", input_coded_size=" << input_coded_size.ToString() | 273 << ", input_coded_size=" << input_coded_size.ToString() |
274 << ", output_buffer_size=" << output_buffer_size; | 274 << ", output_buffer_size=" << output_buffer_size; |
275 if (client_) { | 275 if (client_) { |
276 client_->RequireBitstreamBuffers(input_count, input_coded_size, | 276 client_->RequireBitstreamBuffers(input_count, input_coded_size, |
277 output_buffer_size); | 277 output_buffer_size); |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
281 void GpuVideoEncodeAcceleratorHost::OnNotifyInputDone(int32_t frame_id) { | 281 void GpuVideoEncodeAcceleratorHost::OnNotifyInputDone(int32_t frame_id) { |
282 DCHECK(CalledOnValidThread()); | 282 DCHECK(CalledOnValidThread()); |
283 DVLOG(3) << "OnNotifyInputDone(): frame_id=" << frame_id; | 283 DVLOG(3) << __FUNCTION__ << " frame_id=" << frame_id; |
284 // Fun-fact: std::hash_map is not spec'd to be re-entrant; since freeing a | 284 // Fun-fact: std::hash_map is not spec'd to be re-entrant; since freeing a |
285 // frame can trigger a further encode to be kicked off and thus an .insert() | 285 // frame can trigger a further encode to be kicked off and thus an .insert() |
286 // back into the map, we separate the frame's dtor running from the .erase() | 286 // back into the map, we separate the frame's dtor running from the .erase() |
287 // running by holding on to the frame temporarily. This isn't "just | 287 // running by holding on to the frame temporarily. This isn't "just |
288 // theoretical" - Android's std::hash_map crashes if we don't do this. | 288 // theoretical" - Android's std::hash_map crashes if we don't do this. |
289 scoped_refptr<VideoFrame> frame = frame_map_[frame_id]; | 289 scoped_refptr<VideoFrame> frame = frame_map_[frame_id]; |
290 if (!frame_map_.erase(frame_id)) { | 290 if (!frame_map_.erase(frame_id)) { |
291 DLOG(ERROR) << "OnNotifyInputDone(): " | 291 DLOG(ERROR) << __FUNCTION__ << " invalid frame_id=" << frame_id; |
292 "invalid frame_id=" | |
293 << frame_id; | |
294 // See OnNotifyError for why this needs to be the last thing in this | 292 // See OnNotifyError for why this needs to be the last thing in this |
295 // function. | 293 // function. |
296 OnNotifyError(kPlatformFailureError); | 294 OnNotifyError(kPlatformFailureError); |
297 return; | 295 return; |
298 } | 296 } |
299 frame = NULL; // Not necessary but nice to be explicit; see fun-fact above. | 297 frame = |
| 298 nullptr; // Not necessary but nice to be explicit; see fun-fact above. |
300 } | 299 } |
301 | 300 |
302 void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady( | 301 void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady( |
303 int32_t bitstream_buffer_id, | 302 int32_t bitstream_buffer_id, |
304 uint32_t payload_size, | 303 uint32_t payload_size, |
305 bool key_frame, | 304 bool key_frame, |
306 base::TimeDelta timestamp) { | 305 base::TimeDelta timestamp) { |
307 DCHECK(CalledOnValidThread()); | 306 DCHECK(CalledOnValidThread()); |
308 DVLOG(3) << "OnBitstreamBufferReady(): " | 307 DVLOG(3) << __FUNCTION__ << " bitstream_buffer_id=" << bitstream_buffer_id |
309 "bitstream_buffer_id=" | 308 << ", payload_size=" << payload_size << ", key_frame=" << key_frame; |
310 << bitstream_buffer_id << ", payload_size=" << payload_size | |
311 << ", key_frame=" << key_frame; | |
312 if (client_) | 309 if (client_) |
313 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame, | 310 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame, |
314 timestamp); | 311 timestamp); |
315 } | 312 } |
316 | 313 |
317 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) { | 314 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) { |
318 DCHECK(CalledOnValidThread()); | 315 DCHECK(CalledOnValidThread()); |
319 DVLOG(2) << "OnNotifyError(): error=" << error; | 316 DLOG(ERROR) << __FUNCTION__ << " error=" << error; |
320 if (!client_) | 317 if (!client_) |
321 return; | 318 return; |
322 weak_this_factory_.InvalidateWeakPtrs(); | 319 weak_this_factory_.InvalidateWeakPtrs(); |
323 | 320 |
324 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the | 321 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the |
325 // last thing done on this stack! | 322 // last thing done on this stack! |
326 VideoEncodeAccelerator::Client* client = NULL; | 323 VideoEncodeAccelerator::Client* client = nullptr; |
327 std::swap(client_, client); | 324 std::swap(client_, client); |
328 client->NotifyError(error); | 325 client->NotifyError(error); |
329 } | 326 } |
330 | 327 |
331 } // namespace media | 328 } // namespace media |
OLD | NEW |