Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/gpu/media/gpu_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 | 14 |
| 14 #include "content/common/gpu/gpu_channel.h" | 15 #include "content/common/gpu/gpu_channel.h" |
| 15 #include "content/common/gpu/gpu_messages.h" | 16 #include "content/common/gpu/gpu_messages.h" |
| 16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 17 #include "gpu/command_buffer/common/command_buffer.h" | 18 #include "gpu/command_buffer/common/command_buffer.h" |
| 18 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
| 19 #include "ipc/ipc_message_utils.h" | 20 #include "ipc/ipc_message_utils.h" |
| 20 #include "ui/gl/gl_context.h" | 21 #include "ui/gl/gl_context.h" |
| 21 #include "ui/gl/gl_surface_egl.h" | 22 #include "ui/gl/gl_surface_egl.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 47 } | 48 } |
| 48 | 49 |
| 49 if (!stub->decoder()->MakeCurrent()) { | 50 if (!stub->decoder()->MakeCurrent()) { |
| 50 DLOG(ERROR) << "Failed to MakeCurrent()"; | 51 DLOG(ERROR) << "Failed to MakeCurrent()"; |
| 51 return false; | 52 return false; |
| 52 } | 53 } |
| 53 | 54 |
| 54 return true; | 55 return true; |
| 55 } | 56 } |
| 56 | 57 |
| 58 class GpuVideoDecodeAccelerator::MessageFilter | |
| 59 : public IPC::ChannelProxy::MessageFilter { | |
| 60 public: | |
| 61 MessageFilter(GpuVideoDecodeAccelerator* owner, int32 host_route_id) | |
| 62 : owner_(owner), host_route_id_(host_route_id) {} | |
| 63 | |
| 64 virtual void OnFilterRemoved() OVERRIDE { | |
| 65 // This will delete |owner_| and |this|. | |
| 66 owner_->OnFilterRemoved(); | |
| 67 } | |
| 68 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { | |
| 69 if (msg.routing_id() != host_route_id_) | |
| 70 return false; | |
| 71 | |
| 72 IPC_BEGIN_MESSAGE_MAP(MessageFilter, msg) | |
| 73 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode) | |
|
Ami GONE FROM CHROMIUM
2013/08/27 17:10:33
I wonder if
s/OnDecode/owner_->OnDecode/
would w
wuchengli
2013/08/28 13:18:21
Good idea. I found IPC_MESSAGE_FORWARD is exactly
| |
| 74 IPC_MESSAGE_UNHANDLED(return false;) | |
| 75 IPC_END_MESSAGE_MAP() | |
| 76 return true; | |
| 77 } | |
| 78 | |
| 79 protected: | |
| 80 virtual ~MessageFilter() {} | |
| 81 | |
| 82 private: | |
| 83 void OnDecode(base::SharedMemoryHandle handle, int32 id, uint32 size) { | |
| 84 owner_->OnDecode(handle, id, size); | |
| 85 } | |
| 86 | |
| 87 GpuVideoDecodeAccelerator* owner_; | |
| 88 int32 host_route_id_; | |
| 89 }; | |
| 90 | |
| 57 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator(int32 host_route_id, | 91 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator(int32 host_route_id, |
| 58 GpuCommandBufferStub* stub) | 92 GpuCommandBufferStub* stub) |
| 59 : init_done_msg_(NULL), | 93 : init_done_msg_(NULL), |
| 60 host_route_id_(host_route_id), | 94 host_route_id_(host_route_id), |
| 61 stub_(stub), | 95 stub_(stub), |
| 62 texture_target_(0) { | 96 texture_target_(0) { |
| 63 DCHECK(stub_); | 97 DCHECK(stub_); |
| 64 stub_->AddDestructionObserver(this); | 98 stub_->AddDestructionObserver(this); |
| 65 stub_->channel()->AddRoute(host_route_id_, this); | 99 stub_->channel()->AddRoute(host_route_id_, this); |
| 100 child_message_loop_ = base::MessageLoopProxy::current(); | |
| 66 make_context_current_ = | 101 make_context_current_ = |
| 67 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); | 102 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); |
| 68 } | 103 } |
| 69 | 104 |
| 70 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { | 105 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { |
| 71 DCHECK(stub_); | |
| 72 if (video_decode_accelerator_) | 106 if (video_decode_accelerator_) |
| 73 video_decode_accelerator_.release()->Destroy(); | 107 video_decode_accelerator_.release()->Destroy(); |
| 74 | |
| 75 stub_->channel()->RemoveRoute(host_route_id_); | |
| 76 stub_->RemoveDestructionObserver(this); | |
| 77 } | 108 } |
| 78 | 109 |
| 79 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { | 110 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { |
| 80 DCHECK(stub_); | 111 DCHECK(stub_); |
| 81 if (!video_decode_accelerator_) | 112 if (!video_decode_accelerator_) |
| 82 return false; | 113 return false; |
| 83 bool handled = true; | 114 bool handled = true; |
| 84 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) | 115 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) |
| 85 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode) | |
| 86 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignPictureBuffers, | 116 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignPictureBuffers, |
| 87 OnAssignPictureBuffers) | 117 OnAssignPictureBuffers) |
| 88 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer, | 118 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer, |
| 89 OnReusePictureBuffer) | 119 OnReusePictureBuffer) |
| 90 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush) | 120 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush) |
| 91 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Reset, OnReset) | 121 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Reset, OnReset) |
| 92 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Destroy, OnDestroy) | 122 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Destroy, OnDestroy) |
| 93 IPC_MESSAGE_UNHANDLED(handled = false) | 123 IPC_MESSAGE_UNHANDLED(handled = false) |
| 94 IPC_END_MESSAGE_MAP() | 124 IPC_END_MESSAGE_MAP() |
| 95 return handled; | 125 return handled; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 } | 172 } |
| 143 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification( | 173 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification( |
| 144 host_route_id_, error))) { | 174 host_route_id_, error))) { |
| 145 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) " | 175 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) " |
| 146 << "failed"; | 176 << "failed"; |
| 147 } | 177 } |
| 148 } | 178 } |
| 149 | 179 |
| 150 void GpuVideoDecodeAccelerator::Initialize( | 180 void GpuVideoDecodeAccelerator::Initialize( |
| 151 const media::VideoCodecProfile profile, | 181 const media::VideoCodecProfile profile, |
| 152 IPC::Message* init_done_msg) { | 182 IPC::Message* init_done_msg, |
| 183 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) { | |
| 153 DCHECK(stub_); | 184 DCHECK(stub_); |
| 154 DCHECK(!video_decode_accelerator_.get()); | 185 DCHECK(!video_decode_accelerator_.get()); |
| 155 DCHECK(!init_done_msg_); | 186 DCHECK(!init_done_msg_); |
| 156 DCHECK(init_done_msg); | 187 DCHECK(init_done_msg); |
| 157 init_done_msg_ = init_done_msg; | 188 init_done_msg_ = init_done_msg; |
| 158 | 189 |
| 159 #if !defined(OS_WIN) | 190 #if !defined(OS_WIN) |
| 160 // Ensure we will be able to get a GL context at all before initializing | 191 // Ensure we will be able to get a GL context at all before initializing |
| 161 // non-Windows VDAs. | 192 // non-Windows VDAs. |
| 162 if (!make_context_current_.Run()) { | 193 if (!make_context_current_.Run()) { |
| 163 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 194 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 164 return; | 195 return; |
| 165 } | 196 } |
| 166 #endif | 197 #endif |
| 167 | 198 |
| 168 #if defined(OS_WIN) | 199 #if defined(OS_WIN) |
| 169 if (base::win::GetVersion() < base::win::VERSION_WIN7) { | 200 if (base::win::GetVersion() < base::win::VERSION_WIN7) { |
| 170 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 201 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| 171 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 202 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 172 return; | 203 return; |
| 173 } | 204 } |
| 174 DLOG(INFO) << "Initializing DXVA HW decoder for windows."; | 205 DLOG(INFO) << "Initializing DXVA HW decoder for windows."; |
| 175 video_decode_accelerator_.reset(new DXVAVideoDecodeAccelerator( | 206 video_decode_accelerator_.reset(new DXVAVideoDecodeAccelerator( |
| 176 this, make_context_current_)); | 207 this, make_context_current_)); |
| 177 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 208 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) |
| 178 video_decode_accelerator_.reset(new ExynosVideoDecodeAccelerator( | 209 video_decode_accelerator_.reset(new ExynosVideoDecodeAccelerator( |
| 179 gfx::GLSurfaceEGL::GetHardwareDisplay(), | 210 gfx::GLSurfaceEGL::GetHardwareDisplay(), |
| 180 stub_->decoder()->GetGLContext()->GetHandle(), | 211 stub_->decoder()->GetGLContext()->GetHandle(), |
| 181 this, | 212 this, |
| 182 make_context_current_)); | 213 make_context_current_, |
| 214 io_message_loop)); | |
| 183 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | 215 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
| 184 gfx::GLContextGLX* glx_context = | 216 gfx::GLContextGLX* glx_context = |
| 185 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | 217 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); |
| 186 GLXContext glx_context_handle = | 218 GLXContext glx_context_handle = |
| 187 static_cast<GLXContext>(glx_context->GetHandle()); | 219 static_cast<GLXContext>(glx_context->GetHandle()); |
| 188 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( | 220 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( |
| 189 glx_context->display(), glx_context_handle, this, | 221 glx_context->display(), glx_context_handle, this, |
| 190 make_context_current_)); | 222 make_context_current_)); |
| 191 #elif defined(OS_ANDROID) | 223 #elif defined(OS_ANDROID) |
| 192 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( | 224 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( |
| 193 this, | 225 this, |
| 194 stub_->decoder()->AsWeakPtr(), | 226 stub_->decoder()->AsWeakPtr(), |
| 195 make_context_current_)); | 227 make_context_current_)); |
| 196 #else | 228 #else |
| 197 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 229 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| 198 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 230 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 199 return; | 231 return; |
| 200 #endif | 232 #endif |
| 201 | 233 |
| 234 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
| 235 filter_ = new MessageFilter(this, host_route_id_); | |
| 236 stub_->channel()->AddFilter(filter_.get()); | |
| 237 } | |
| 238 | |
| 202 if (!video_decode_accelerator_->Initialize(profile)) | 239 if (!video_decode_accelerator_->Initialize(profile)) |
| 203 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 240 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 204 } | 241 } |
| 205 | 242 |
| 243 // Runs on IO thread. | |
|
Ami GONE FROM CHROMIUM
2013/08/27 17:10:33
Only if CanDecodeOnIOThread, no?
piman
2013/08/27 17:14:22
nit: // If video_decode_accelerator_->CanDecodeOnI
wuchengli
2013/08/28 13:18:21
Done.
| |
| 206 void GpuVideoDecodeAccelerator::OnDecode( | 244 void GpuVideoDecodeAccelerator::OnDecode( |
| 207 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 245 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
| 208 DCHECK(video_decode_accelerator_.get()); | 246 DCHECK(video_decode_accelerator_.get()); |
| 209 if (id < 0) { | 247 if (id < 0) { |
| 210 DLOG(FATAL) << "BitstreamBuffer id " << id << " out of range"; | 248 DLOG(FATAL) << "BitstreamBuffer id " << id << " out of range"; |
| 211 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 249 child_message_loop_->PostTask( |
| 250 FROM_HERE, | |
| 251 base::Bind(&GpuVideoDecodeAccelerator::NotifyError, | |
| 252 base::Unretained(this), | |
| 253 media::VideoDecodeAccelerator::INVALID_ARGUMENT)); | |
| 212 return; | 254 return; |
| 213 } | 255 } |
| 214 video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size)); | 256 video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size)); |
| 215 } | 257 } |
| 216 | 258 |
| 217 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( | 259 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( |
| 218 const std::vector<int32>& buffer_ids, | 260 const std::vector<int32>& buffer_ids, |
| 219 const std::vector<uint32>& texture_ids, | 261 const std::vector<uint32>& texture_ids, |
| 220 const std::vector<gfx::Size>& sizes) { | 262 const std::vector<gfx::Size>& sizes) { |
| 221 DCHECK(stub_); | 263 DCHECK(stub_); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 video_decode_accelerator_->Flush(); | 332 video_decode_accelerator_->Flush(); |
| 291 } | 333 } |
| 292 | 334 |
| 293 void GpuVideoDecodeAccelerator::OnReset() { | 335 void GpuVideoDecodeAccelerator::OnReset() { |
| 294 DCHECK(video_decode_accelerator_.get()); | 336 DCHECK(video_decode_accelerator_.get()); |
| 295 video_decode_accelerator_->Reset(); | 337 video_decode_accelerator_->Reset(); |
| 296 } | 338 } |
| 297 | 339 |
| 298 void GpuVideoDecodeAccelerator::OnDestroy() { | 340 void GpuVideoDecodeAccelerator::OnDestroy() { |
| 299 DCHECK(video_decode_accelerator_.get()); | 341 DCHECK(video_decode_accelerator_.get()); |
| 300 delete this; | 342 DCHECK(stub_); |
| 343 stub_->channel()->RemoveRoute(host_route_id_); | |
| 344 stub_->RemoveDestructionObserver(this); | |
| 345 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
| 346 // Remove the filter first because the member variables can be accessed on | |
| 347 // IO thread. When filter is removed, OnFilterRemoved will delete |this|. | |
| 348 stub_->channel()->RemoveFilter(filter_.get()); | |
| 349 } else { | |
| 350 delete this; | |
| 351 } | |
| 352 } | |
| 353 | |
| 354 void GpuVideoDecodeAccelerator::OnFilterRemoved() { | |
| 355 child_message_loop_->DeleteSoon(FROM_HERE, this); | |
| 301 } | 356 } |
| 302 | 357 |
| 303 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer( | 358 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer( |
| 304 int32 bitstream_buffer_id) { | 359 int32 bitstream_buffer_id) { |
| 305 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed( | 360 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed( |
| 306 host_route_id_, bitstream_buffer_id))) { | 361 host_route_id_, bitstream_buffer_id))) { |
| 307 DLOG(ERROR) | 362 DLOG(ERROR) |
| 308 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) " | 363 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) " |
| 309 << "failed"; | 364 << "failed"; |
| 310 } | 365 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 321 void GpuVideoDecodeAccelerator::NotifyFlushDone() { | 376 void GpuVideoDecodeAccelerator::NotifyFlushDone() { |
| 322 if (!Send(new AcceleratedVideoDecoderHostMsg_FlushDone(host_route_id_))) | 377 if (!Send(new AcceleratedVideoDecoderHostMsg_FlushDone(host_route_id_))) |
| 323 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed"; | 378 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed"; |
| 324 } | 379 } |
| 325 | 380 |
| 326 void GpuVideoDecodeAccelerator::NotifyResetDone() { | 381 void GpuVideoDecodeAccelerator::NotifyResetDone() { |
| 327 if (!Send(new AcceleratedVideoDecoderHostMsg_ResetDone(host_route_id_))) | 382 if (!Send(new AcceleratedVideoDecoderHostMsg_ResetDone(host_route_id_))) |
| 328 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ResetDone) failed"; | 383 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ResetDone) failed"; |
| 329 } | 384 } |
| 330 | 385 |
| 331 void GpuVideoDecodeAccelerator::OnWillDestroyStub() { | 386 void GpuVideoDecodeAccelerator::OnWillDestroyStub() { OnDestroy(); } |
| 332 delete this; | |
| 333 } | |
| 334 | 387 |
| 335 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { | 388 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { |
| 336 DCHECK(stub_); | 389 DCHECK(stub_); |
| 337 return stub_->channel()->Send(message); | 390 return stub_->channel()->Send(message); |
| 338 } | 391 } |
| 339 | 392 |
| 340 } // namespace content | 393 } // namespace content |
| OLD | NEW |