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 "media/filters/gpu_video_decoder.h" | 5 #include "media/filters/gpu_video_decoder.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 GpuVideoDecoder::BufferData::~BufferData() {} | 61 GpuVideoDecoder::BufferData::~BufferData() {} |
| 62 | 62 |
| 63 GpuVideoDecoder::GpuVideoDecoder(GpuVideoAcceleratorFactories* factories) | 63 GpuVideoDecoder::GpuVideoDecoder(GpuVideoAcceleratorFactories* factories) |
| 64 : needs_bitstream_conversion_(false), | 64 : needs_bitstream_conversion_(false), |
| 65 factories_(factories), | 65 factories_(factories), |
| 66 state_(kNormal), | 66 state_(kNormal), |
| 67 decoder_texture_target_(0), | 67 decoder_texture_target_(0), |
| 68 next_picture_buffer_id_(0), | 68 next_picture_buffer_id_(0), |
| 69 next_bitstream_buffer_id_(0), | 69 next_bitstream_buffer_id_(0), |
| 70 available_pictures_(0), | 70 available_pictures_(0), |
| 71 can_stall_anytime_(false), | |
| 71 weak_factory_(this) { | 72 weak_factory_(this) { |
| 72 DCHECK(factories_); | 73 DCHECK(factories_); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void GpuVideoDecoder::Reset(const base::Closure& closure) { | 76 void GpuVideoDecoder::Reset(const base::Closure& closure) { |
| 76 DVLOG(3) << "Reset()"; | 77 DVLOG(3) << "Reset()"; |
| 77 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 78 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 78 | 79 |
| 79 if (state_ == kDrainingDecoder) { | 80 if (state_ == kDrainingDecoder) { |
| 80 base::MessageLoop::current()->PostTask( | 81 base::MessageLoop::current()->PostTask( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 << config.AsHumanReadableString(); | 148 << config.AsHumanReadableString(); |
| 148 | 149 |
| 149 // TODO(posciak): destroy and create a new VDA on codec/profile change | 150 // TODO(posciak): destroy and create a new VDA on codec/profile change |
| 150 // (http://crbug.com/260224). | 151 // (http://crbug.com/260224). |
| 151 if (previously_initialized && (config_.profile() != config.profile())) { | 152 if (previously_initialized && (config_.profile() != config.profile())) { |
| 152 DVLOG(1) << "Codec or profile changed, cannot reinitialize."; | 153 DVLOG(1) << "Codec or profile changed, cannot reinitialize."; |
| 153 bound_init_cb.Run(false); | 154 bound_init_cb.Run(false); |
| 154 return; | 155 return; |
| 155 } | 156 } |
| 156 | 157 |
| 157 if (!IsProfileSupported(config.profile(), config.coded_size())) { | 158 VideoDecodeAccelerator::Capabilities capabilities = |
| 159 factories_->GetVideoDecodeAcceleratorCapabilities(); | |
| 160 if (!IsProfileSupported(capabilities, config.profile(), | |
| 161 config.coded_size())) { | |
| 158 DVLOG(1) << "Profile " << config.profile() << " or coded size " | 162 DVLOG(1) << "Profile " << config.profile() << " or coded size " |
| 159 << config.coded_size().ToString() << " not supported."; | 163 << config.coded_size().ToString() << " not supported."; |
| 160 bound_init_cb.Run(false); | 164 bound_init_cb.Run(false); |
| 161 return; | 165 return; |
| 162 } | 166 } |
| 163 | 167 |
| 164 config_ = config; | 168 config_ = config; |
| 169 can_stall_anytime_ = capabilities.flags & | |
| 170 VideoDecodeAccelerator::Capabilities::CAN_STALL_ANY_TIME; | |
| 165 needs_bitstream_conversion_ = (config.codec() == kCodecH264); | 171 needs_bitstream_conversion_ = (config.codec() == kCodecH264); |
| 166 output_cb_ = BindToCurrentLoop(output_cb); | 172 output_cb_ = BindToCurrentLoop(output_cb); |
| 167 | 173 |
| 168 if (previously_initialized) { | 174 if (previously_initialized) { |
| 169 // Reinitialization with a different config (but same codec and profile). | 175 // Reinitialization with a different config (but same codec and profile). |
| 170 // VDA should handle it by detecting this in-stream by itself, | 176 // VDA should handle it by detecting this in-stream by itself, |
| 171 // no need to notify it. | 177 // no need to notify it. |
| 172 bound_init_cb.Run(true); | 178 bound_init_cb.Run(true); |
| 173 return; | 179 return; |
| 174 } | 180 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 NOTREACHED() << "Missing bitstreambuffer id: " << id; | 350 NOTREACHED() << "Missing bitstreambuffer id: " << id; |
| 345 } | 351 } |
| 346 | 352 |
| 347 bool GpuVideoDecoder::NeedsBitstreamConversion() const { | 353 bool GpuVideoDecoder::NeedsBitstreamConversion() const { |
| 348 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 354 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 349 return needs_bitstream_conversion_; | 355 return needs_bitstream_conversion_; |
| 350 } | 356 } |
| 351 | 357 |
| 352 bool GpuVideoDecoder::CanReadWithoutStalling() const { | 358 bool GpuVideoDecoder::CanReadWithoutStalling() const { |
| 353 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 359 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 354 return | 360 return next_picture_buffer_id_ == |
| 355 next_picture_buffer_id_ == 0 || // Decode() will ProvidePictureBuffers(). | 361 0 || // Decode() will ProvidePictureBuffers(). |
| 356 available_pictures_ > 0; | 362 (!can_stall_anytime_ && available_pictures_ > 0); |
|
Pawel Osciak
2015/12/05 00:18:55
The indents here seem wrong...
liberato (no reviews please)
2015/12/07 19:04:39
not sure, but it's what cl format does.
Pawel Osciak
2015/12/09 01:31:48
Maybe it gets confused by the inline comment? I th
| |
| 357 } | 363 } |
| 358 | 364 |
| 359 int GpuVideoDecoder::GetMaxDecodeRequests() const { | 365 int GpuVideoDecoder::GetMaxDecodeRequests() const { |
| 360 return kMaxInFlightDecodes; | 366 return kMaxInFlightDecodes; |
| 361 } | 367 } |
| 362 | 368 |
| 363 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, | 369 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, |
| 364 const gfx::Size& size, | 370 const gfx::Size& size, |
| 365 uint32 texture_target) { | 371 uint32 texture_target) { |
| 366 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " | 372 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 639 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 634 if (!vda_) | 640 if (!vda_) |
| 635 return; | 641 return; |
| 636 | 642 |
| 637 state_ = kError; | 643 state_ = kError; |
| 638 | 644 |
| 639 DLOG(ERROR) << "VDA Error: " << error; | 645 DLOG(ERROR) << "VDA Error: " << error; |
| 640 DestroyVDA(); | 646 DestroyVDA(); |
| 641 } | 647 } |
| 642 | 648 |
| 643 bool GpuVideoDecoder::IsProfileSupported(VideoCodecProfile profile, | 649 bool GpuVideoDecoder::IsProfileSupported( |
| 644 const gfx::Size& coded_size) { | 650 const VideoDecodeAccelerator::Capabilities& capabilities, |
| 651 VideoCodecProfile profile, | |
| 652 const gfx::Size& coded_size) { | |
| 645 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 653 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 646 VideoDecodeAccelerator::SupportedProfiles supported_profiles = | 654 const VideoDecodeAccelerator::SupportedProfiles& supported_profiles = |
| 647 factories_->GetVideoDecodeAcceleratorSupportedProfiles(); | 655 capabilities.supported_profiles; |
| 648 for (const auto& supported_profile : supported_profiles) { | 656 for (const auto& supported_profile : supported_profiles) { |
|
Pawel Osciak
2015/12/05 00:18:55
Nit: Personally I'd just s/supported_profiles/capa
liberato (no reviews please)
2015/12/07 19:04:39
Done.
| |
| 649 if (profile == supported_profile.profile) { | 657 if (profile == supported_profile.profile) { |
| 650 return IsCodedSizeSupported(coded_size, | 658 return IsCodedSizeSupported(coded_size, |
| 651 supported_profile.min_resolution, | 659 supported_profile.min_resolution, |
| 652 supported_profile.max_resolution); | 660 supported_profile.max_resolution); |
| 653 } | 661 } |
| 654 } | 662 } |
| 655 return false; | 663 return false; |
| 656 } | 664 } |
| 657 | 665 |
| 658 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 666 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 659 const { | 667 const { |
| 660 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 668 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 661 } | 669 } |
| 662 | 670 |
| 663 } // namespace media | 671 } // namespace media |
| OLD | NEW |