Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: content/common/gpu/media/gpu_video_decode_accelerator.cc

Issue 23125014: Run VDA::Decode on GPU IO thread if VDA supports it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a separate MessageFilter for GVDA Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // A message filter to run VDA::Decode in IO thread to reduce decode latency.
59 class GpuVideoDecodeAccelerator::GvdaMessageFilter
60 : public IPC::ChannelProxy::MessageFilter {
61 public:
62 GvdaMessageFilter(GpuVideoDecodeAccelerator* gvda,
Ami GONE FROM CHROMIUM 2013/08/26 17:20:03 virtual dtor please
Ami GONE FROM CHROMIUM 2013/08/26 17:20:03 s/gvda/owner/ here and in the member declaration a
wuchengli 2013/08/27 12:32:24 Done.
wuchengli 2013/08/27 12:32:24 Done.
63 int32 host_route_id,
64 scoped_refptr<base::MessageLoopProxy> message_loop);
Ami GONE FROM CHROMIUM 2013/08/26 17:20:03 "message_loop" is an uninformative name.
wuchengli 2013/08/27 12:32:24 Changed to child_message_loop.
65 virtual void OnFilterRemoved() OVERRIDE;
66 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
67 void OnDecode(base::SharedMemoryHandle handle, int32 id, uint32 size);
Ami GONE FROM CHROMIUM 2013/08/26 17:20:03 private?
wuchengli 2013/08/27 12:32:24 Done.
68
69 private:
70 GpuVideoDecodeAccelerator* gvda_; // GpuVideoDecodeAccelerator owns this.
71 int32 host_route_id_;
72 scoped_refptr<base::MessageLoopProxy> message_loop_;
73 };
74
75 GpuVideoDecodeAccelerator::GvdaMessageFilter::GvdaMessageFilter(
76 GpuVideoDecodeAccelerator* gvda,
77 int32 host_route_id,
78 scoped_refptr<base::MessageLoopProxy> message_loop)
79 : gvda_(gvda), host_route_id_(host_route_id), message_loop_(message_loop) {}
80
81 void GpuVideoDecodeAccelerator::GvdaMessageFilter::OnFilterRemoved() {
82 message_loop_->DeleteSoon(FROM_HERE, gvda_);
83 }
84
85 bool GpuVideoDecodeAccelerator::GvdaMessageFilter::OnMessageReceived(
86 const IPC::Message& msg) {
87 if (msg.routing_id() != host_route_id_)
88 return false;
89
90 bool handled = true;
91 IPC_BEGIN_MESSAGE_MAP(GvdaMessageFilter, msg)
92 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode)
93 IPC_MESSAGE_UNHANDLED(handled = false)
94 IPC_END_MESSAGE_MAP()
95 return handled;
96 }
97
98 void GpuVideoDecodeAccelerator::GvdaMessageFilter::OnDecode(
99 base::SharedMemoryHandle handle,
100 int32 id,
101 uint32 size) {
102 if (id < 0) {
103 DLOG(FATAL) << "BitstreamBuffer id " << id << " out of range";
104 message_loop_->PostTask(
105 FROM_HERE,
106 base::Bind(&GpuVideoDecodeAccelerator::NotifyError,
107 base::Unretained(gvda_),
108 media::VideoDecodeAccelerator::INVALID_ARGUMENT));
109 return;
110 }
111 gvda_->OnDecode(handle, id, size);
112 }
113
57 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator(int32 host_route_id, 114 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator(int32 host_route_id,
58 GpuCommandBufferStub* stub) 115 GpuCommandBufferStub* stub)
59 : init_done_msg_(NULL), 116 : init_done_msg_(NULL),
60 host_route_id_(host_route_id), 117 host_route_id_(host_route_id),
61 stub_(stub), 118 stub_(stub),
62 texture_target_(0) { 119 texture_target_(0) {
63 DCHECK(stub_); 120 DCHECK(stub_);
64 stub_->AddDestructionObserver(this); 121 stub_->AddDestructionObserver(this);
65 stub_->channel()->AddRoute(host_route_id_, this); 122 stub_->channel()->AddRoute(host_route_id_, this);
123 filter_.reset(new GvdaMessageFilter(
124 this, host_route_id, base::MessageLoopProxy::current()));
125 stub_->channel()->AddFilter(filter_.get());
66 make_context_current_ = 126 make_context_current_ =
67 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); 127 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr());
68 } 128 }
69 129
70 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { 130 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() {
71 DCHECK(stub_);
72 if (video_decode_accelerator_) 131 if (video_decode_accelerator_)
73 video_decode_accelerator_.release()->Destroy(); 132 video_decode_accelerator_.release()->Destroy();
74
75 stub_->channel()->RemoveRoute(host_route_id_);
76 stub_->RemoveDestructionObserver(this);
77 } 133 }
78 134
79 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { 135 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) {
80 DCHECK(stub_); 136 DCHECK(stub_);
81 if (!video_decode_accelerator_) 137 if (!video_decode_accelerator_)
82 return false; 138 return false;
83 bool handled = true; 139 bool handled = true;
84 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) 140 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg)
85 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode)
86 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignPictureBuffers, 141 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignPictureBuffers,
87 OnAssignPictureBuffers) 142 OnAssignPictureBuffers)
88 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer, 143 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer,
89 OnReusePictureBuffer) 144 OnReusePictureBuffer)
90 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush) 145 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush)
91 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Reset, OnReset) 146 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Reset, OnReset)
92 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Destroy, OnDestroy) 147 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Destroy, OnDestroy)
93 IPC_MESSAGE_UNHANDLED(handled = false) 148 IPC_MESSAGE_UNHANDLED(handled = false)
94 IPC_END_MESSAGE_MAP() 149 IPC_END_MESSAGE_MAP()
95 return handled; 150 return handled;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 197 }
143 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification( 198 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification(
144 host_route_id_, error))) { 199 host_route_id_, error))) {
145 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) " 200 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) "
146 << "failed"; 201 << "failed";
147 } 202 }
148 } 203 }
149 204
150 void GpuVideoDecodeAccelerator::Initialize( 205 void GpuVideoDecodeAccelerator::Initialize(
151 const media::VideoCodecProfile profile, 206 const media::VideoCodecProfile profile,
152 IPC::Message* init_done_msg) { 207 IPC::Message* init_done_msg,
208 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) {
153 DCHECK(stub_); 209 DCHECK(stub_);
154 DCHECK(!video_decode_accelerator_.get()); 210 DCHECK(!video_decode_accelerator_.get());
155 DCHECK(!init_done_msg_); 211 DCHECK(!init_done_msg_);
156 DCHECK(init_done_msg); 212 DCHECK(init_done_msg);
157 init_done_msg_ = init_done_msg; 213 init_done_msg_ = init_done_msg;
158 214
159 #if !defined(OS_WIN) 215 #if !defined(OS_WIN)
160 // Ensure we will be able to get a GL context at all before initializing 216 // Ensure we will be able to get a GL context at all before initializing
161 // non-Windows VDAs. 217 // non-Windows VDAs.
162 if (!make_context_current_.Run()) { 218 if (!make_context_current_.Run()) {
163 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); 219 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
164 return; 220 return;
165 } 221 }
166 #endif 222 #endif
167 223
168 #if defined(OS_WIN) 224 #if defined(OS_WIN)
169 if (base::win::GetVersion() < base::win::VERSION_WIN7) { 225 if (base::win::GetVersion() < base::win::VERSION_WIN7) {
170 NOTIMPLEMENTED() << "HW video decode acceleration not available."; 226 NOTIMPLEMENTED() << "HW video decode acceleration not available.";
171 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); 227 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
172 return; 228 return;
173 } 229 }
174 DLOG(INFO) << "Initializing DXVA HW decoder for windows."; 230 DLOG(INFO) << "Initializing DXVA HW decoder for windows.";
175 video_decode_accelerator_.reset(new DXVAVideoDecodeAccelerator( 231 video_decode_accelerator_.reset(new DXVAVideoDecodeAccelerator(
176 this, make_context_current_)); 232 this, make_context_current_));
177 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) 233 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
178 video_decode_accelerator_.reset(new ExynosVideoDecodeAccelerator( 234 video_decode_accelerator_.reset(new ExynosVideoDecodeAccelerator(
179 gfx::GLSurfaceEGL::GetHardwareDisplay(), 235 gfx::GLSurfaceEGL::GetHardwareDisplay(),
180 stub_->decoder()->GetGLContext()->GetHandle(), 236 stub_->decoder()->GetGLContext()->GetHandle(),
181 this, 237 this,
182 make_context_current_)); 238 make_context_current_,
239 io_message_loop));
183 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) 240 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
184 gfx::GLContextGLX* glx_context = 241 gfx::GLContextGLX* glx_context =
185 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); 242 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext());
186 GLXContext glx_context_handle = 243 GLXContext glx_context_handle =
187 static_cast<GLXContext>(glx_context->GetHandle()); 244 static_cast<GLXContext>(glx_context->GetHandle());
188 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( 245 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator(
189 glx_context->display(), glx_context_handle, this, 246 glx_context->display(), glx_context_handle, this,
190 make_context_current_)); 247 make_context_current_, io_message_loop));
191 #elif defined(OS_ANDROID) 248 #elif defined(OS_ANDROID)
192 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( 249 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator(
193 this, 250 this,
194 stub_->decoder()->AsWeakPtr(), 251 stub_->decoder()->AsWeakPtr(),
195 make_context_current_)); 252 make_context_current_));
196 #else 253 #else
197 NOTIMPLEMENTED() << "HW video decode acceleration not available."; 254 NOTIMPLEMENTED() << "HW video decode acceleration not available.";
198 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); 255 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
199 return; 256 return;
200 #endif 257 #endif
201 258
202 if (!video_decode_accelerator_->Initialize(profile)) 259 if (!video_decode_accelerator_->Initialize(profile))
203 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); 260 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
204 } 261 }
205 262
206 void GpuVideoDecodeAccelerator::OnDecode( 263 void GpuVideoDecodeAccelerator::OnDecode(
207 base::SharedMemoryHandle handle, int32 id, uint32 size) { 264 base::SharedMemoryHandle handle, int32 id, uint32 size) {
208 DCHECK(video_decode_accelerator_.get()); 265 DCHECK(video_decode_accelerator_.get());
209 if (id < 0) {
210 DLOG(FATAL) << "BitstreamBuffer id " << id << " out of range";
211 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
212 return;
213 }
214 video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size)); 266 video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size));
215 } 267 }
216 268
217 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( 269 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers(
218 const std::vector<int32>& buffer_ids, 270 const std::vector<int32>& buffer_ids,
219 const std::vector<uint32>& texture_ids, 271 const std::vector<uint32>& texture_ids,
220 const std::vector<gfx::Size>& sizes) { 272 const std::vector<gfx::Size>& sizes) {
221 DCHECK(stub_); 273 DCHECK(stub_);
222 if (buffer_ids.size() != texture_ids.size() || 274 if (buffer_ids.size() != texture_ids.size() ||
223 buffer_ids.size() != sizes.size()) { 275 buffer_ids.size() != sizes.size()) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 video_decode_accelerator_->Flush(); 342 video_decode_accelerator_->Flush();
291 } 343 }
292 344
293 void GpuVideoDecodeAccelerator::OnReset() { 345 void GpuVideoDecodeAccelerator::OnReset() {
294 DCHECK(video_decode_accelerator_.get()); 346 DCHECK(video_decode_accelerator_.get());
295 video_decode_accelerator_->Reset(); 347 video_decode_accelerator_->Reset();
296 } 348 }
297 349
298 void GpuVideoDecodeAccelerator::OnDestroy() { 350 void GpuVideoDecodeAccelerator::OnDestroy() {
299 DCHECK(video_decode_accelerator_.get()); 351 DCHECK(video_decode_accelerator_.get());
300 delete this; 352 DCHECK(stub_);
353 stub_->channel()->RemoveRoute(host_route_id_);
354 stub_->RemoveDestructionObserver(this);
355 // Remove the filter first because it can access the member variables on IO
356 // thread. When filter is removed, OnFilterRemoved will delete |this|.
357 stub_->channel()->RemoveFilter(filter_.get());
301 } 358 }
302 359
303 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer( 360 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer(
304 int32 bitstream_buffer_id) { 361 int32 bitstream_buffer_id) {
305 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed( 362 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed(
306 host_route_id_, bitstream_buffer_id))) { 363 host_route_id_, bitstream_buffer_id))) {
307 DLOG(ERROR) 364 DLOG(ERROR)
308 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) " 365 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) "
309 << "failed"; 366 << "failed";
310 } 367 }
(...skipping 10 matching lines...) Expand all
321 void GpuVideoDecodeAccelerator::NotifyFlushDone() { 378 void GpuVideoDecodeAccelerator::NotifyFlushDone() {
322 if (!Send(new AcceleratedVideoDecoderHostMsg_FlushDone(host_route_id_))) 379 if (!Send(new AcceleratedVideoDecoderHostMsg_FlushDone(host_route_id_)))
323 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed"; 380 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed";
324 } 381 }
325 382
326 void GpuVideoDecodeAccelerator::NotifyResetDone() { 383 void GpuVideoDecodeAccelerator::NotifyResetDone() {
327 if (!Send(new AcceleratedVideoDecoderHostMsg_ResetDone(host_route_id_))) 384 if (!Send(new AcceleratedVideoDecoderHostMsg_ResetDone(host_route_id_)))
328 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ResetDone) failed"; 385 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ResetDone) failed";
329 } 386 }
330 387
331 void GpuVideoDecodeAccelerator::OnWillDestroyStub() { 388 void GpuVideoDecodeAccelerator::OnWillDestroyStub() { OnDestroy(); }
332 delete this;
333 }
334 389
335 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { 390 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) {
336 DCHECK(stub_); 391 DCHECK(stub_);
337 return stub_->channel()->Send(message); 392 return stub_->channel()->Send(message);
338 } 393 }
339 394
340 } // namespace content 395 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698