| 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 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( | 18 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( |
| 19 gpu::CommandBufferProxyImpl* impl) | 19 gpu::CommandBufferProxyImpl* impl) |
| 20 : channel_(impl->channel()), | 20 : channel_(impl->channel()), |
| 21 encoder_route_id_(MSG_ROUTING_NONE), | 21 encoder_route_id_(MSG_ROUTING_NONE), |
| 22 client_(nullptr), | 22 client_(nullptr), |
| 23 impl_(impl), | 23 impl_(impl), |
| 24 next_frame_id_(0), | 24 next_frame_id_(0), |
| 25 media_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 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); |
| 29 } | 30 } |
| 30 | 31 |
| 31 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { | 32 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { |
| 32 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
| 33 if (channel_ && encoder_route_id_ != MSG_ROUTING_NONE) | 34 if (channel_ && encoder_route_id_ != MSG_ROUTING_NONE) |
| 34 channel_->RemoveRoute(encoder_route_id_); | 35 channel_->RemoveRoute(encoder_route_id_); |
| 36 |
| 37 base::AutoLock lock(impl_lock_); |
| 35 if (impl_) | 38 if (impl_) |
| 36 impl_->RemoveDeletionObserver(this); | 39 impl_->RemoveDeletionObserver(this); |
| 37 } | 40 } |
| 38 | 41 |
| 39 bool GpuVideoEncodeAcceleratorHost::OnMessageReceived( | 42 bool GpuVideoEncodeAcceleratorHost::OnMessageReceived( |
| 40 const IPC::Message& message) { | 43 const IPC::Message& message) { |
| 41 bool handled = true; | 44 bool handled = true; |
| 42 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message) | 45 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message) |
| 43 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers, | 46 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers, |
| 44 OnRequireBitstreamBuffers) | 47 OnRequireBitstreamBuffers) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 79 } |
| 77 | 80 |
| 78 bool GpuVideoEncodeAcceleratorHost::Initialize( | 81 bool GpuVideoEncodeAcceleratorHost::Initialize( |
| 79 VideoPixelFormat input_format, | 82 VideoPixelFormat input_format, |
| 80 const gfx::Size& input_visible_size, | 83 const gfx::Size& input_visible_size, |
| 81 VideoCodecProfile output_profile, | 84 VideoCodecProfile output_profile, |
| 82 uint32_t initial_bitrate, | 85 uint32_t initial_bitrate, |
| 83 Client* client) { | 86 Client* client) { |
| 84 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
| 85 client_ = client; | 88 client_ = client; |
| 89 |
| 90 base::AutoLock lock(impl_lock_); |
| 86 if (!impl_) { | 91 if (!impl_) { |
| 87 DLOG(ERROR) << "impl_ destroyed"; | 92 DLOG(ERROR) << "impl_ destroyed"; |
| 88 return false; | 93 return false; |
| 89 } | 94 } |
| 90 | 95 |
| 91 int32_t route_id = channel_->GenerateRouteID(); | 96 int32_t route_id = channel_->GenerateRouteID(); |
| 92 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr()); | 97 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr()); |
| 93 | 98 |
| 94 CreateVideoEncoderParams params; | 99 CreateVideoEncoderParams params; |
| 95 params.input_format = input_format; | 100 params.input_format = input_format; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 172 |
| 168 void GpuVideoEncodeAcceleratorHost::Destroy() { | 173 void GpuVideoEncodeAcceleratorHost::Destroy() { |
| 169 DCHECK(CalledOnValidThread()); | 174 DCHECK(CalledOnValidThread()); |
| 170 if (channel_) | 175 if (channel_) |
| 171 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_)); | 176 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_)); |
| 172 client_ = nullptr; | 177 client_ = nullptr; |
| 173 delete this; | 178 delete this; |
| 174 } | 179 } |
| 175 | 180 |
| 176 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { | 181 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { |
| 177 DCHECK(CalledOnValidThread()); | 182 base::AutoLock lock(impl_lock_); |
| 178 impl_ = nullptr; | 183 impl_ = nullptr; |
| 179 | 184 |
| 180 // The gpu::CommandBufferProxyImpl is going away; error out this VEA. | 185 // The gpu::CommandBufferProxyImpl is going away; error out this VEA. |
| 181 OnChannelError(); | 186 media_task_runner_->PostTask( |
| 187 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnChannelError, |
| 188 weak_this_factory_.GetWeakPtr())); |
| 182 } | 189 } |
| 183 | 190 |
| 184 void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame( | 191 void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame( |
| 185 const scoped_refptr<VideoFrame>& frame, | 192 const scoped_refptr<VideoFrame>& frame, |
| 186 bool force_keyframe) { | 193 bool force_keyframe) { |
| 187 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { | 194 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { |
| 188 PostNotifyError(FROM_HERE, kPlatformFailureError, | 195 PostNotifyError(FROM_HERE, kPlatformFailureError, |
| 189 "EncodeSharedMemory(): cannot encode frame with invalid " | 196 "EncodeSharedMemory(): cannot encode frame with invalid " |
| 190 "shared memory handle"); | 197 "shared memory handle"); |
| 191 return; | 198 return; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 213 | 220 |
| 214 void GpuVideoEncodeAcceleratorHost::PostNotifyError( | 221 void GpuVideoEncodeAcceleratorHost::PostNotifyError( |
| 215 const tracked_objects::Location& location, | 222 const tracked_objects::Location& location, |
| 216 Error error, | 223 Error error, |
| 217 const std::string& message) { | 224 const std::string& message) { |
| 218 DCHECK(CalledOnValidThread()); | 225 DCHECK(CalledOnValidThread()); |
| 219 DLOG(ERROR) << "Error from " << location.function_name() << "(" | 226 DLOG(ERROR) << "Error from " << location.function_name() << "(" |
| 220 << location.file_name() << ":" << location.line_number() << ") " | 227 << location.file_name() << ":" << location.line_number() << ") " |
| 221 << message << " (error = " << error << ")"; | 228 << message << " (error = " << error << ")"; |
| 222 // Post the error notification back to this thread, to avoid re-entrancy. | 229 // Post the error notification back to this thread, to avoid re-entrancy. |
| 223 base::ThreadTaskRunnerHandle::Get()->PostTask( | 230 media_task_runner_->PostTask( |
| 224 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, | 231 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, |
| 225 weak_this_factory_.GetWeakPtr(), error)); | 232 weak_this_factory_.GetWeakPtr(), error)); |
| 226 } | 233 } |
| 227 | 234 |
| 228 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { | 235 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { |
| 229 DCHECK(CalledOnValidThread()); | 236 DCHECK(CalledOnValidThread()); |
| 230 uint32_t message_type = message->type(); | 237 uint32_t message_type = message->type(); |
| 231 if (!channel_->Send(message)) { | 238 if (!channel_->Send(message)) { |
| 232 PostNotifyError(FROM_HERE, kPlatformFailureError, | 239 PostNotifyError(FROM_HERE, kPlatformFailureError, |
| 233 base::StringPrintf("Send(%d) failed", message_type)); | 240 base::StringPrintf("Send(%d) failed", message_type)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 weak_this_factory_.InvalidateWeakPtrs(); | 296 weak_this_factory_.InvalidateWeakPtrs(); |
| 290 | 297 |
| 291 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the | 298 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the |
| 292 // last thing done on this stack! | 299 // last thing done on this stack! |
| 293 VideoEncodeAccelerator::Client* client = nullptr; | 300 VideoEncodeAccelerator::Client* client = nullptr; |
| 294 std::swap(client_, client); | 301 std::swap(client_, client); |
| 295 client->NotifyError(error); | 302 client->NotifyError(error); |
| 296 } | 303 } |
| 297 | 304 |
| 298 } // namespace media | 305 } // namespace media |
| OLD | NEW |