OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include <CoreVideo/CoreVideo.h> | 7 #include <CoreVideo/CoreVideo.h> |
8 #include <OpenGL/CGLIOSurface.h> | 8 #include <OpenGL/CGLIOSurface.h> |
9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 const base::Callback<void(uint32_t, uint32_t, scoped_refptr<gl::GLImage>)>& | 295 const base::Callback<void(uint32_t, uint32_t, scoped_refptr<gl::GLImage>)>& |
296 bind_image) | 296 bind_image) |
297 : make_context_current_(make_context_current), | 297 : make_context_current_(make_context_current), |
298 bind_image_(bind_image), | 298 bind_image_(bind_image), |
299 client_(nullptr), | 299 client_(nullptr), |
300 state_(STATE_DECODING), | 300 state_(STATE_DECODING), |
301 format_(nullptr), | 301 format_(nullptr), |
302 session_(nullptr), | 302 session_(nullptr), |
303 last_sps_id_(-1), | 303 last_sps_id_(-1), |
304 last_pps_id_(-1), | 304 last_pps_id_(-1), |
305 config_changed_(false), | |
306 missing_idr_logged_(false), | |
305 gpu_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 307 gpu_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
306 decoder_thread_("VTDecoderThread"), | 308 decoder_thread_("VTDecoderThread"), |
307 weak_this_factory_(this) { | 309 weak_this_factory_(this) { |
308 DCHECK(!make_context_current_.is_null()); | 310 DCHECK(!make_context_current_.is_null()); |
309 callback_.decompressionOutputCallback = OutputThunk; | 311 callback_.decompressionOutputCallback = OutputThunk; |
310 callback_.decompressionOutputRefCon = this; | 312 callback_.decompressionOutputRefCon = this; |
311 weak_this_ = weak_this_factory_.GetWeakPtr(); | 313 weak_this_ = weak_this_factory_.GetWeakPtr(); |
312 } | 314 } |
313 | 315 |
314 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() { | 316 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 } | 605 } |
604 has_slice = true; | 606 has_slice = true; |
605 default: | 607 default: |
606 nalus.push_back(nalu); | 608 nalus.push_back(nalu); |
607 data_size += kNALUHeaderLength + nalu.size; | 609 data_size += kNALUHeaderLength + nalu.size; |
608 break; | 610 break; |
609 } | 611 } |
610 } | 612 } |
611 | 613 |
612 // Initialize VideoToolbox. | 614 // Initialize VideoToolbox. |
613 bool config_changed = false; | |
614 if (!sps.empty() && sps != last_sps_) { | 615 if (!sps.empty() && sps != last_sps_) { |
615 last_sps_.swap(sps); | 616 last_sps_.swap(sps); |
616 last_spsext_.swap(spsext); | 617 last_spsext_.swap(spsext); |
617 config_changed = true; | 618 config_changed_ = true; |
618 } | 619 } |
619 if (!pps.empty() && pps != last_pps_) { | 620 if (!pps.empty() && pps != last_pps_) { |
620 last_pps_.swap(pps); | 621 last_pps_.swap(pps); |
621 config_changed = true; | 622 config_changed_ = true; |
622 } | 623 } |
623 if (config_changed) { | 624 if (config_changed_) { |
624 if (last_sps_.empty()) { | 625 if (last_sps_.empty()) { |
626 config_changed_ = false; | |
625 DLOG(ERROR) << "Invalid configuration; no SPS"; | 627 DLOG(ERROR) << "Invalid configuration; no SPS"; |
626 NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); | 628 NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); |
627 return; | 629 return; |
628 } | 630 } |
629 if (last_pps_.empty()) { | 631 if (last_pps_.empty()) { |
632 config_changed_ = false; | |
630 DLOG(ERROR) << "Invalid configuration; no PPS"; | 633 DLOG(ERROR) << "Invalid configuration; no PPS"; |
631 NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); | 634 NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); |
632 return; | 635 return; |
633 } | 636 } |
634 | 637 |
635 // If it's not an IDR frame, we can't reconfigure the decoder anyway. We | 638 // Only reconfigure at IDRs to avoid corruption. |
636 // assume that any config change not on an IDR must be compatible. | 639 if (frame->is_idr) { |
637 if (frame->is_idr && !ConfigureDecoder()) | 640 config_changed_ = false; |
638 return; | 641 |
642 // ConfigureDecoder() calls NotifyError() on failure. | |
643 if (!ConfigureDecoder()) | |
644 return; | |
645 } | |
639 } | 646 } |
640 | 647 |
641 // If there are no image slices, drop the bitstream buffer by returning an | 648 // If no IDR has been seen yet, skip decoding. |
649 if (has_slice && !session_ && config_changed_) { | |
650 if (!missing_idr_logged_) { | |
651 LOG(ERROR) << "Illegal attempt to decode without IDR. " | |
652 << "Discarding decode requests until next IDR."; | |
653 missing_idr_logged_ = true; | |
DaleCurtis
2016/02/05 23:50:08
Do you want to reset this to false after the first
sandersd (OOO until July 31)
2016/02/05 23:53:52
We could do that, but I'm mostly just concerned wi
| |
654 } | |
655 has_slice = false; | |
656 } | |
657 | |
658 // If there is nothing to decode, drop the bitstream buffer by returning an | |
642 // empty frame. | 659 // empty frame. |
643 if (!has_slice) { | 660 if (!has_slice) { |
661 // Keep everything in order by flushing first. | |
644 if (!FinishDelayedFrames()) | 662 if (!FinishDelayedFrames()) |
645 return; | 663 return; |
646 gpu_task_runner_->PostTask(FROM_HERE, base::Bind( | 664 gpu_task_runner_->PostTask(FROM_HERE, base::Bind( |
647 &VTVideoDecodeAccelerator::DecodeDone, weak_this_, frame)); | 665 &VTVideoDecodeAccelerator::DecodeDone, weak_this_, frame)); |
648 return; | 666 return; |
649 } | 667 } |
650 | 668 |
651 // If the session is not configured by this point, fail. | 669 // If the session is not configured by this point, fail. |
652 if (!session_) { | 670 if (!session_) { |
653 DLOG(ERROR) << "Cannot decode without configuration"; | 671 DLOG(ERROR) << "Cannot decode without configuration"; |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1137 SupportedProfile profile; | 1155 SupportedProfile profile; |
1138 profile.profile = supported_profile; | 1156 profile.profile = supported_profile; |
1139 profile.min_resolution.SetSize(16, 16); | 1157 profile.min_resolution.SetSize(16, 16); |
1140 profile.max_resolution.SetSize(4096, 2160); | 1158 profile.max_resolution.SetSize(4096, 2160); |
1141 profiles.push_back(profile); | 1159 profiles.push_back(profile); |
1142 } | 1160 } |
1143 return profiles; | 1161 return profiles; |
1144 } | 1162 } |
1145 | 1163 |
1146 } // namespace content | 1164 } // namespace content |
OLD | NEW |