| 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::SupportedProfile matching_profile; |
| 159 if (!IsProfileSupported(config.profile(), config.coded_size(), |
| 160 matching_profile)) { |
| 158 DVLOG(1) << "Profile " << config.profile() << " or coded size " | 161 DVLOG(1) << "Profile " << config.profile() << " or coded size " |
| 159 << config.coded_size().ToString() << " not supported."; | 162 << config.coded_size().ToString() << " not supported."; |
| 160 bound_init_cb.Run(false); | 163 bound_init_cb.Run(false); |
| 161 return; | 164 return; |
| 162 } | 165 } |
| 163 | 166 |
| 164 config_ = config; | 167 config_ = config; |
| 168 can_stall_anytime_ = |
| 169 matching_profile.flags & |
| 170 VideoDecodeAccelerator::SupportedProfile::kCanStallAnytime; |
| 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); |
| 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 VideoCodecProfile profile, |
| 651 const gfx::Size& coded_size, |
| 652 VideoDecodeAccelerator::SupportedProfile& matching_profile_out) { |
| 645 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 653 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 646 VideoDecodeAccelerator::SupportedProfiles supported_profiles = | 654 VideoDecodeAccelerator::SupportedProfiles supported_profiles = |
| 647 factories_->GetVideoDecodeAcceleratorSupportedProfiles(); | 655 factories_->GetVideoDecodeAcceleratorSupportedProfiles(); |
| 648 for (const auto& supported_profile : supported_profiles) { | 656 for (const auto& supported_profile : supported_profiles) { |
| 649 if (profile == supported_profile.profile) { | 657 if (profile == supported_profile.profile) { |
| 658 matching_profile_out = supported_profile; |
| 650 return IsCodedSizeSupported(coded_size, | 659 return IsCodedSizeSupported(coded_size, |
| 651 supported_profile.min_resolution, | 660 supported_profile.min_resolution, |
| 652 supported_profile.max_resolution); | 661 supported_profile.max_resolution); |
| 653 } | 662 } |
| 654 } | 663 } |
| 655 return false; | 664 return false; |
| 656 } | 665 } |
| 657 | 666 |
| 658 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 667 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 659 const { | 668 const { |
| 660 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 669 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 661 } | 670 } |
| 662 | 671 |
| 663 } // namespace media | 672 } // namespace media |
| OLD | NEW |