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 needs_all_picture_buffers_to_decode_(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 needs_all_picture_buffers_to_decode_ = | |
170 capabilities.flags & | |
171 VideoDecodeAccelerator::Capabilities::NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE; | |
165 needs_bitstream_conversion_ = (config.codec() == kCodecH264); | 172 needs_bitstream_conversion_ = (config.codec() == kCodecH264); |
166 output_cb_ = BindToCurrentLoop(output_cb); | 173 output_cb_ = BindToCurrentLoop(output_cb); |
167 | 174 |
168 if (previously_initialized) { | 175 if (previously_initialized) { |
169 // Reinitialization with a different config (but same codec and profile). | 176 // Reinitialization with a different config (but same codec and profile). |
170 // VDA should handle it by detecting this in-stream by itself, | 177 // VDA should handle it by detecting this in-stream by itself, |
171 // no need to notify it. | 178 // no need to notify it. |
172 bound_init_cb.Run(true); | 179 bound_init_cb.Run(true); |
173 return; | 180 return; |
174 } | 181 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 NOTREACHED() << "Missing bitstreambuffer id: " << id; | 354 NOTREACHED() << "Missing bitstreambuffer id: " << id; |
348 } | 355 } |
349 | 356 |
350 bool GpuVideoDecoder::NeedsBitstreamConversion() const { | 357 bool GpuVideoDecoder::NeedsBitstreamConversion() const { |
351 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 358 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
352 return needs_bitstream_conversion_; | 359 return needs_bitstream_conversion_; |
353 } | 360 } |
354 | 361 |
355 bool GpuVideoDecoder::CanReadWithoutStalling() const { | 362 bool GpuVideoDecoder::CanReadWithoutStalling() const { |
356 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 363 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
357 return | 364 return next_picture_buffer_id_ == |
358 next_picture_buffer_id_ == 0 || // Decode() will ProvidePictureBuffers(). | 365 0 || // Decode() will ProvidePictureBuffers(). |
359 available_pictures_ > 0; | 366 (!needs_all_picture_buffers_to_decode_ && available_pictures_ > 0); |
Pawel Osciak
2015/12/10 02:03:23
I'm wondering, given the clarified definition, sho
liberato (no reviews please)
2015/12/10 15:56:06
good catch, i think so. will verify.
| |
360 } | 367 } |
361 | 368 |
362 int GpuVideoDecoder::GetMaxDecodeRequests() const { | 369 int GpuVideoDecoder::GetMaxDecodeRequests() const { |
363 return kMaxInFlightDecodes; | 370 return kMaxInFlightDecodes; |
364 } | 371 } |
365 | 372 |
366 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, | 373 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, |
367 const gfx::Size& size, | 374 const gfx::Size& size, |
368 uint32 texture_target) { | 375 uint32 texture_target) { |
369 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " | 376 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 645 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
639 if (!vda_) | 646 if (!vda_) |
640 return; | 647 return; |
641 | 648 |
642 state_ = kError; | 649 state_ = kError; |
643 | 650 |
644 DLOG(ERROR) << "VDA Error: " << error; | 651 DLOG(ERROR) << "VDA Error: " << error; |
645 DestroyVDA(); | 652 DestroyVDA(); |
646 } | 653 } |
647 | 654 |
648 bool GpuVideoDecoder::IsProfileSupported(VideoCodecProfile profile, | 655 bool GpuVideoDecoder::IsProfileSupported( |
649 const gfx::Size& coded_size) { | 656 const VideoDecodeAccelerator::Capabilities& capabilities, |
657 VideoCodecProfile profile, | |
658 const gfx::Size& coded_size) { | |
650 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 659 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
651 VideoDecodeAccelerator::SupportedProfiles supported_profiles = | 660 for (const auto& supported_profile : capabilities.supported_profiles) { |
652 factories_->GetVideoDecodeAcceleratorSupportedProfiles(); | |
653 for (const auto& supported_profile : supported_profiles) { | |
654 if (profile == supported_profile.profile) { | 661 if (profile == supported_profile.profile) { |
655 return IsCodedSizeSupported(coded_size, | 662 return IsCodedSizeSupported(coded_size, |
656 supported_profile.min_resolution, | 663 supported_profile.min_resolution, |
657 supported_profile.max_resolution); | 664 supported_profile.max_resolution); |
658 } | 665 } |
659 } | 666 } |
660 return false; | 667 return false; |
661 } | 668 } |
662 | 669 |
663 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 670 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
664 const { | 671 const { |
665 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 672 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
666 } | 673 } |
667 | 674 |
668 } // namespace media | 675 } // namespace media |
OLD | NEW |