| 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/dxva_video_decode_accelerator_win.h" | 5 #include "content/common/gpu/media/dxva_video_decode_accelerator_win.h" |
| 6 | 6 |
| 7 #if !defined(OS_WIN) | 7 #if !defined(OS_WIN) |
| 8 #error This file should only be built on Windows. | 8 #error This file should only be built on Windows. |
| 9 #endif // !defined(OS_WIN) | 9 #endif // !defined(OS_WIN) |
| 10 | 10 |
| (...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 | 1996 |
| 1997 if (GetState() != kUninitialized) { | 1997 if (GetState() != kUninitialized) { |
| 1998 Invalidate(); | 1998 Invalidate(); |
| 1999 } | 1999 } |
| 2000 } | 2000 } |
| 2001 | 2001 |
| 2002 void DXVAVideoDecodeAccelerator::Invalidate() { | 2002 void DXVAVideoDecodeAccelerator::Invalidate() { |
| 2003 if (GetState() == kUninitialized) | 2003 if (GetState() == kUninitialized) |
| 2004 return; | 2004 return; |
| 2005 | 2005 |
| 2006 // Best effort to make the GL context current. |
| 2007 make_context_current_.Run(); |
| 2008 |
| 2006 decoder_thread_.Stop(); | 2009 decoder_thread_.Stop(); |
| 2007 weak_this_factory_.InvalidateWeakPtrs(); | 2010 weak_this_factory_.InvalidateWeakPtrs(); |
| 2008 output_picture_buffers_.clear(); | 2011 output_picture_buffers_.clear(); |
| 2009 stale_output_picture_buffers_.clear(); | 2012 stale_output_picture_buffers_.clear(); |
| 2010 pending_output_samples_.clear(); | 2013 pending_output_samples_.clear(); |
| 2011 // We want to continue processing pending input after detecting a config | 2014 // We want to continue processing pending input after detecting a config |
| 2012 // change. | 2015 // change. |
| 2013 if (GetState() != kConfigChange) | 2016 if (GetState() != kConfigChange) |
| 2014 pending_input_buffers_.clear(); | 2017 pending_input_buffers_.clear(); |
| 2015 decoder_.Release(); | 2018 decoder_.Release(); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2287 | 2290 |
| 2288 main_thread_task_runner_->PostTask( | 2291 main_thread_task_runner_->PostTask( |
| 2289 FROM_HERE, | 2292 FROM_HERE, |
| 2290 base::Bind(&DXVAVideoDecodeAccelerator::RequestPictureBuffers, | 2293 base::Bind(&DXVAVideoDecodeAccelerator::RequestPictureBuffers, |
| 2291 weak_this_factory_.GetWeakPtr(), | 2294 weak_this_factory_.GetWeakPtr(), |
| 2292 width, | 2295 width, |
| 2293 height)); | 2296 height)); |
| 2294 } | 2297 } |
| 2295 | 2298 |
| 2296 void DXVAVideoDecodeAccelerator::DismissStaleBuffers(bool force) { | 2299 void DXVAVideoDecodeAccelerator::DismissStaleBuffers(bool force) { |
| 2300 RETURN_AND_NOTIFY_ON_FAILURE(make_context_current_.Run(), |
| 2301 "Failed to make context current", PLATFORM_FAILURE, ); |
| 2302 |
| 2297 OutputBuffers::iterator index; | 2303 OutputBuffers::iterator index; |
| 2298 | 2304 |
| 2299 for (index = output_picture_buffers_.begin(); | 2305 for (index = output_picture_buffers_.begin(); |
| 2300 index != output_picture_buffers_.end(); | 2306 index != output_picture_buffers_.end(); |
| 2301 ++index) { | 2307 ++index) { |
| 2302 if (force || index->second->available()) { | 2308 if (force || index->second->available()) { |
| 2303 DVLOG(1) << "Dismissing picture id: " << index->second->id(); | 2309 DVLOG(1) << "Dismissing picture id: " << index->second->id(); |
| 2304 client_->DismissPictureBuffer(index->second->id()); | 2310 client_->DismissPictureBuffer(index->second->id()); |
| 2305 } else { | 2311 } else { |
| 2306 // Move to |stale_output_picture_buffers_| for deferred deletion. | 2312 // Move to |stale_output_picture_buffers_| for deferred deletion. |
| 2307 stale_output_picture_buffers_.insert( | 2313 stale_output_picture_buffers_.insert( |
| 2308 std::make_pair(index->first, index->second)); | 2314 std::make_pair(index->first, index->second)); |
| 2309 } | 2315 } |
| 2310 } | 2316 } |
| 2311 | 2317 |
| 2312 output_picture_buffers_.clear(); | 2318 output_picture_buffers_.clear(); |
| 2313 } | 2319 } |
| 2314 | 2320 |
| 2315 void DXVAVideoDecodeAccelerator::DeferredDismissStaleBuffer( | 2321 void DXVAVideoDecodeAccelerator::DeferredDismissStaleBuffer( |
| 2316 int32_t picture_buffer_id) { | 2322 int32_t picture_buffer_id) { |
| 2323 RETURN_AND_NOTIFY_ON_FAILURE(make_context_current_.Run(), |
| 2324 "Failed to make context current", PLATFORM_FAILURE, ); |
| 2325 |
| 2317 OutputBuffers::iterator it = stale_output_picture_buffers_.find( | 2326 OutputBuffers::iterator it = stale_output_picture_buffers_.find( |
| 2318 picture_buffer_id); | 2327 picture_buffer_id); |
| 2319 DCHECK(it != stale_output_picture_buffers_.end()); | 2328 DCHECK(it != stale_output_picture_buffers_.end()); |
| 2320 DVLOG(1) << "Dismissing picture id: " << it->second->id(); | 2329 DVLOG(1) << "Dismissing picture id: " << it->second->id(); |
| 2321 client_->DismissPictureBuffer(it->second->id()); | 2330 client_->DismissPictureBuffer(it->second->id()); |
| 2322 stale_output_picture_buffers_.erase(it); | 2331 stale_output_picture_buffers_.erase(it); |
| 2323 } | 2332 } |
| 2324 | 2333 |
| 2325 DXVAVideoDecodeAccelerator::State | 2334 DXVAVideoDecodeAccelerator::State |
| 2326 DXVAVideoDecodeAccelerator::GetState() { | 2335 DXVAVideoDecodeAccelerator::GetState() { |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2825 RETURN_ON_HR_FAILURE(E_FAIL, "Failed to detect H.264 stream config", | 2834 RETURN_ON_HR_FAILURE(E_FAIL, "Failed to detect H.264 stream config", |
| 2826 E_FAIL); | 2835 E_FAIL); |
| 2827 } | 2836 } |
| 2828 *config_changed = config_change_detector_->config_changed(); | 2837 *config_changed = config_change_detector_->config_changed(); |
| 2829 return S_OK; | 2838 return S_OK; |
| 2830 } | 2839 } |
| 2831 | 2840 |
| 2832 void DXVAVideoDecodeAccelerator::ConfigChanged( | 2841 void DXVAVideoDecodeAccelerator::ConfigChanged( |
| 2833 const Config& config) { | 2842 const Config& config) { |
| 2834 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 2843 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 2844 |
| 2835 SetState(kConfigChange); | 2845 SetState(kConfigChange); |
| 2836 DismissStaleBuffers(true); | 2846 DismissStaleBuffers(true); |
| 2837 Invalidate(); | 2847 Invalidate(); |
| 2838 Initialize(config_, client_); | 2848 Initialize(config_, client_); |
| 2839 decoder_thread_task_runner_->PostTask( | 2849 decoder_thread_task_runner_->PostTask( |
| 2840 FROM_HERE, | 2850 FROM_HERE, |
| 2841 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, | 2851 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, |
| 2842 base::Unretained(this))); | 2852 base::Unretained(this))); |
| 2843 } | 2853 } |
| 2844 | 2854 |
| 2845 } // namespace content | 2855 } // namespace content |
| OLD | NEW |