Chromium Code Reviews| 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/bind_to_current_loop.h" | |
| 11 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
| 12 #include "media/gpu/gpu_video_accelerator_util.h" | 13 #include "media/gpu/gpu_video_accelerator_util.h" |
| 13 #include "media/gpu/ipc/common/media_messages.h" | 14 #include "media/gpu/ipc/common/media_messages.h" |
| 14 #include "media/video/video_encode_accelerator.h" | 15 #include "media/video/video_encode_accelerator.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( | 19 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( |
| 19 gpu::CommandBufferProxyImpl* impl) | 20 gpu::CommandBufferProxyImpl* impl) |
| 20 : channel_(impl->channel()), | 21 : channel_(impl->channel()), |
| 21 encoder_route_id_(MSG_ROUTING_NONE), | 22 encoder_route_id_(MSG_ROUTING_NONE), |
| 22 client_(nullptr), | 23 client_(nullptr), |
| 23 impl_(impl), | 24 impl_(impl), |
| 24 next_frame_id_(0), | 25 next_frame_id_(0), |
| 25 weak_this_factory_(this) { | 26 weak_this_factory_(this) { |
| 26 DCHECK(channel_); | 27 DCHECK(channel_); |
| 27 DCHECK(impl_); | 28 DCHECK(impl_); |
| 28 impl_->AddDeletionObserver(this); | 29 impl_->AddDeletionObserver(this); |
| 30 channel_error_cb_ = media::BindToCurrentLoop( | |
|
danakj
2017/01/13 18:27:50
same
emircan
2017/01/13 19:08:14
Done.
| |
| 31 base::Bind(&GpuVideoEncodeAcceleratorHost::OnChannelError, | |
| 32 weak_this_factory_.GetWeakPtr())); | |
| 29 } | 33 } |
| 30 | 34 |
| 31 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { | 35 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { |
| 32 DCHECK(CalledOnValidThread()); | 36 DCHECK(CalledOnValidThread()); |
| 33 if (channel_ && encoder_route_id_ != MSG_ROUTING_NONE) | 37 if (channel_ && encoder_route_id_ != MSG_ROUTING_NONE) |
| 34 channel_->RemoveRoute(encoder_route_id_); | 38 channel_->RemoveRoute(encoder_route_id_); |
| 39 | |
| 40 base::AutoLock lock(impl_lock_); | |
| 35 if (impl_) | 41 if (impl_) |
| 36 impl_->RemoveDeletionObserver(this); | 42 impl_->RemoveDeletionObserver(this); |
| 37 } | 43 } |
| 38 | 44 |
| 39 bool GpuVideoEncodeAcceleratorHost::OnMessageReceived( | 45 bool GpuVideoEncodeAcceleratorHost::OnMessageReceived( |
| 40 const IPC::Message& message) { | 46 const IPC::Message& message) { |
| 41 bool handled = true; | 47 bool handled = true; |
| 42 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message) | 48 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message) |
| 43 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers, | 49 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers, |
| 44 OnRequireBitstreamBuffers) | 50 OnRequireBitstreamBuffers) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 } | 82 } |
| 77 | 83 |
| 78 bool GpuVideoEncodeAcceleratorHost::Initialize( | 84 bool GpuVideoEncodeAcceleratorHost::Initialize( |
| 79 VideoPixelFormat input_format, | 85 VideoPixelFormat input_format, |
| 80 const gfx::Size& input_visible_size, | 86 const gfx::Size& input_visible_size, |
| 81 VideoCodecProfile output_profile, | 87 VideoCodecProfile output_profile, |
| 82 uint32_t initial_bitrate, | 88 uint32_t initial_bitrate, |
| 83 Client* client) { | 89 Client* client) { |
| 84 DCHECK(CalledOnValidThread()); | 90 DCHECK(CalledOnValidThread()); |
| 85 client_ = client; | 91 client_ = client; |
| 92 | |
| 93 base::AutoLock lock(impl_lock_); | |
| 86 if (!impl_) { | 94 if (!impl_) { |
| 87 DLOG(ERROR) << "impl_ destroyed"; | 95 DLOG(ERROR) << "impl_ destroyed"; |
| 88 return false; | 96 return false; |
| 89 } | 97 } |
| 90 | 98 |
| 91 int32_t route_id = channel_->GenerateRouteID(); | 99 int32_t route_id = channel_->GenerateRouteID(); |
| 92 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr()); | 100 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr()); |
| 93 | 101 |
| 94 CreateVideoEncoderParams params; | 102 CreateVideoEncoderParams params; |
| 95 params.input_format = input_format; | 103 params.input_format = input_format; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 | 175 |
| 168 void GpuVideoEncodeAcceleratorHost::Destroy() { | 176 void GpuVideoEncodeAcceleratorHost::Destroy() { |
| 169 DCHECK(CalledOnValidThread()); | 177 DCHECK(CalledOnValidThread()); |
| 170 if (channel_) | 178 if (channel_) |
| 171 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_)); | 179 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_)); |
| 172 client_ = nullptr; | 180 client_ = nullptr; |
| 173 delete this; | 181 delete this; |
| 174 } | 182 } |
| 175 | 183 |
| 176 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { | 184 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { |
| 177 DCHECK(CalledOnValidThread()); | 185 base::AutoLock lock(impl_lock_); |
| 178 impl_ = nullptr; | 186 impl_ = nullptr; |
| 179 | 187 |
| 180 // The gpu::CommandBufferProxyImpl is going away; error out this VEA. | 188 // The gpu::CommandBufferProxyImpl is going away; error out this VEA. |
| 181 OnChannelError(); | 189 channel_error_cb_.Run(); |
| 182 } | 190 } |
| 183 | 191 |
| 184 void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame( | 192 void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame( |
| 185 const scoped_refptr<VideoFrame>& frame, | 193 const scoped_refptr<VideoFrame>& frame, |
| 186 bool force_keyframe) { | 194 bool force_keyframe) { |
| 187 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { | 195 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { |
| 188 PostNotifyError(FROM_HERE, kPlatformFailureError, | 196 PostNotifyError(FROM_HERE, kPlatformFailureError, |
| 189 "EncodeSharedMemory(): cannot encode frame with invalid " | 197 "EncodeSharedMemory(): cannot encode frame with invalid " |
| 190 "shared memory handle"); | 198 "shared memory handle"); |
| 191 return; | 199 return; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 weak_this_factory_.InvalidateWeakPtrs(); | 297 weak_this_factory_.InvalidateWeakPtrs(); |
| 290 | 298 |
| 291 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the | 299 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the |
| 292 // last thing done on this stack! | 300 // last thing done on this stack! |
| 293 VideoEncodeAccelerator::Client* client = nullptr; | 301 VideoEncodeAccelerator::Client* client = nullptr; |
| 294 std::swap(client_, client); | 302 std::swap(client_, client); |
| 295 client->NotifyError(error); | 303 client->NotifyError(error); |
| 296 } | 304 } |
| 297 | 305 |
| 298 } // namespace media | 306 } // namespace media |
| OLD | NEW |