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/logging.h" | 10 #include "base/logging.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 if (!stub_) | 63 if (!stub_) |
64 return; | 64 return; |
65 stub_->AddDestructionObserver(this); | 65 stub_->AddDestructionObserver(this); |
66 make_context_current_ = | 66 make_context_current_ = |
67 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); | 67 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); |
68 } | 68 } |
69 | 69 |
70 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { | 70 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { |
71 if (stub_) | 71 if (stub_) |
72 stub_->RemoveDestructionObserver(this); | 72 stub_->RemoveDestructionObserver(this); |
73 if (video_decode_accelerator_) | 73 if (video_decode_accelerator_.get()) |
74 video_decode_accelerator_->Destroy(); | 74 video_decode_accelerator_.release()->Destroy(); |
75 } | 75 } |
76 | 76 |
77 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { | 77 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { |
78 if (!stub_ || !video_decode_accelerator_) | 78 if (!stub_ || !video_decode_accelerator_.get()) |
79 return false; | 79 return false; |
80 bool handled = true; | 80 bool handled = true; |
81 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) | 81 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) |
82 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode) | 82 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode) |
83 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignPictureBuffers, | 83 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignPictureBuffers, |
84 OnAssignPictureBuffers) | 84 OnAssignPictureBuffers) |
85 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer, | 85 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer, |
86 OnReusePictureBuffer) | 86 OnReusePictureBuffer) |
87 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush) | 87 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush) |
88 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Reset, OnReset) | 88 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Reset, OnReset) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 162 } |
163 #endif | 163 #endif |
164 | 164 |
165 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
166 if (base::win::GetVersion() < base::win::VERSION_WIN7) { | 166 if (base::win::GetVersion() < base::win::VERSION_WIN7) { |
167 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 167 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
168 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 168 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
169 return; | 169 return; |
170 } | 170 } |
171 DLOG(INFO) << "Initializing DXVA HW decoder for windows."; | 171 DLOG(INFO) << "Initializing DXVA HW decoder for windows."; |
172 scoped_refptr<DXVAVideoDecodeAccelerator> video_decoder( | 172 scoped_ptr<DXVAVideoDecodeAccelerator> video_decoder( |
173 new DXVAVideoDecodeAccelerator(this)); | 173 new DXVAVideoDecodeAccelerator(this)); |
174 video_decode_accelerator_ = video_decoder; | 174 video_decode_accelerator_ = video_decoder.Pass(); |
175 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 175 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
176 scoped_refptr<OmxVideoDecodeAccelerator> video_decoder( | 176 scoped_ptr<OmxVideoDecodeAccelerator> video_decoder( |
177 new OmxVideoDecodeAccelerator(this)); | 177 new OmxVideoDecodeAccelerator(this)); |
178 video_decoder->SetEglState( | 178 video_decoder->SetEglState( |
179 gfx::GLSurfaceEGL::GetHardwareDisplay(), | 179 gfx::GLSurfaceEGL::GetHardwareDisplay(), |
180 stub_->decoder()->GetGLContext()->GetHandle()); | 180 stub_->decoder()->GetGLContext()->GetHandle()); |
181 video_decode_accelerator_ = video_decoder; | 181 video_decode_accelerator_ = video_decoder.Pass(); |
182 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 182 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
183 scoped_refptr<VaapiVideoDecodeAccelerator> video_decoder( | 183 scoped_ptr<VaapiVideoDecodeAccelerator> video_decoder( |
184 new VaapiVideoDecodeAccelerator(this, make_context_current_)); | 184 new VaapiVideoDecodeAccelerator(this, make_context_current_)); |
185 gfx::GLContextGLX* glx_context = | 185 gfx::GLContextGLX* glx_context = |
186 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | 186 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); |
187 GLXContext glx_context_handle = | 187 GLXContext glx_context_handle = |
188 static_cast<GLXContext>(glx_context->GetHandle()); | 188 static_cast<GLXContext>(glx_context->GetHandle()); |
189 video_decoder->SetGlxState(glx_context->display(), glx_context_handle); | 189 video_decoder->SetGlxState(glx_context->display(), glx_context_handle); |
190 video_decode_accelerator_ = video_decoder; | 190 video_decode_accelerator_ = video_decoder.Pass(); |
191 #elif defined(OS_MACOSX) | 191 #elif defined(OS_MACOSX) |
192 scoped_refptr<MacVideoDecodeAccelerator> video_decoder( | 192 scoped_ptr<MacVideoDecodeAccelerator> video_decoder( |
193 new MacVideoDecodeAccelerator(this)); | 193 new MacVideoDecodeAccelerator(this)); |
194 video_decoder->SetCGLContext(static_cast<CGLContextObj>( | 194 video_decoder->SetCGLContext(static_cast<CGLContextObj>( |
195 stub_->decoder()->GetGLContext()->GetHandle())); | 195 stub_->decoder()->GetGLContext()->GetHandle())); |
196 video_decode_accelerator_ = video_decoder; | 196 video_decode_accelerator_ = video_decoder.Pass(); |
197 #else | 197 #else |
198 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 198 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
199 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 199 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
200 return; | 200 return; |
201 #endif | 201 #endif |
202 | 202 |
203 if (!video_decode_accelerator_->Initialize(profile)) | 203 if (!video_decode_accelerator_->Initialize(profile)) |
204 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 204 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
205 } | 205 } |
206 | 206 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 video_decode_accelerator_->Flush(); | 256 video_decode_accelerator_->Flush(); |
257 } | 257 } |
258 | 258 |
259 void GpuVideoDecodeAccelerator::OnReset() { | 259 void GpuVideoDecodeAccelerator::OnReset() { |
260 DCHECK(video_decode_accelerator_.get()); | 260 DCHECK(video_decode_accelerator_.get()); |
261 video_decode_accelerator_->Reset(); | 261 video_decode_accelerator_->Reset(); |
262 } | 262 } |
263 | 263 |
264 void GpuVideoDecodeAccelerator::OnDestroy() { | 264 void GpuVideoDecodeAccelerator::OnDestroy() { |
265 DCHECK(video_decode_accelerator_.get()); | 265 DCHECK(video_decode_accelerator_.get()); |
266 video_decode_accelerator_->Destroy(); | 266 video_decode_accelerator_.release()->Destroy(); |
267 } | 267 } |
268 | 268 |
269 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer( | 269 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer( |
270 int32 bitstream_buffer_id) { | 270 int32 bitstream_buffer_id) { |
271 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed( | 271 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed( |
272 host_route_id_, bitstream_buffer_id))) { | 272 host_route_id_, bitstream_buffer_id))) { |
273 DLOG(ERROR) | 273 DLOG(ERROR) |
274 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) " | 274 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) " |
275 << "failed"; | 275 << "failed"; |
276 } | 276 } |
(...skipping 12 matching lines...) Expand all Loading... |
289 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed"; | 289 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed"; |
290 } | 290 } |
291 | 291 |
292 void GpuVideoDecodeAccelerator::NotifyResetDone() { | 292 void GpuVideoDecodeAccelerator::NotifyResetDone() { |
293 if (!Send(new AcceleratedVideoDecoderHostMsg_ResetDone(host_route_id_))) | 293 if (!Send(new AcceleratedVideoDecoderHostMsg_ResetDone(host_route_id_))) |
294 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ResetDone) failed"; | 294 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ResetDone) failed"; |
295 } | 295 } |
296 | 296 |
297 void GpuVideoDecodeAccelerator::OnWillDestroyStub(GpuCommandBufferStub* stub) { | 297 void GpuVideoDecodeAccelerator::OnWillDestroyStub(GpuCommandBufferStub* stub) { |
298 DCHECK_EQ(stub, stub_.get()); | 298 DCHECK_EQ(stub, stub_.get()); |
299 if (video_decode_accelerator_) { | 299 if (video_decode_accelerator_.get()) |
300 video_decode_accelerator_->Destroy(); | 300 video_decode_accelerator_.release()->Destroy(); |
301 video_decode_accelerator_ = NULL; | |
302 } | |
303 if (stub_) { | 301 if (stub_) { |
304 stub_->RemoveDestructionObserver(this); | 302 stub_->RemoveDestructionObserver(this); |
305 stub_.reset(); | 303 stub_.reset(); |
306 } | 304 } |
307 } | 305 } |
308 | 306 |
309 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { | 307 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { |
310 DCHECK(sender_); | 308 DCHECK(sender_); |
311 return sender_->Send(message); | 309 return sender_->Send(message); |
312 } | 310 } |
OLD | NEW |