OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <inttypes.h> | 5 #include <inttypes.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 public: | 597 public: |
598 explicit H264Validator(const FrameFoundCallback& frame_cb) | 598 explicit H264Validator(const FrameFoundCallback& frame_cb) |
599 : StreamValidator(frame_cb), | 599 : StreamValidator(frame_cb), |
600 seen_sps_(false), | 600 seen_sps_(false), |
601 seen_pps_(false), | 601 seen_pps_(false), |
602 seen_idr_(false) {} | 602 seen_idr_(false) {} |
603 | 603 |
604 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; | 604 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; |
605 | 605 |
606 private: | 606 private: |
607 bool IsNewFrame(const H264NALU& nalu, int sps_id); | |
608 bool IsNewPrimaryCodedPicture(const H264SliceHeader* slice_hdr, | |
609 int sps_id) const; | |
610 | |
607 // Set to true when encoder provides us with the corresponding NALU type. | 611 // Set to true when encoder provides us with the corresponding NALU type. |
608 bool seen_sps_; | 612 bool seen_sps_; |
609 bool seen_pps_; | 613 bool seen_pps_; |
610 bool seen_idr_; | 614 bool seen_idr_; |
611 | 615 |
612 H264Parser h264_parser_; | 616 H264Parser h264_parser_; |
617 std::unique_ptr<H264SliceHeader> curr_slice_hdr_; | |
618 int curr_pic_order_cnt_type_; | |
613 }; | 619 }; |
614 | 620 |
615 void H264Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) { | 621 void H264Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) { |
616 h264_parser_.SetStream(stream, static_cast<off_t>(size)); | 622 h264_parser_.SetStream(stream, static_cast<off_t>(size)); |
617 | 623 |
618 while (1) { | 624 while (1) { |
619 H264NALU nalu; | 625 H264NALU nalu; |
620 H264Parser::Result result; | 626 H264Parser::Result result; |
621 | 627 |
622 result = h264_parser_.AdvanceToNextNALU(&nalu); | 628 result = h264_parser_.AdvanceToNextNALU(&nalu); |
623 if (result == H264Parser::kEOStream) | 629 if (result == H264Parser::kEOStream) |
624 break; | 630 break; |
625 | 631 |
626 ASSERT_EQ(H264Parser::kOk, result); | 632 ASSERT_EQ(H264Parser::kOk, result); |
627 | |
628 bool keyframe = false; | 633 bool keyframe = false; |
629 | 634 |
635 int sps_id = 0; | |
630 switch (nalu.nal_unit_type) { | 636 switch (nalu.nal_unit_type) { |
631 case H264NALU::kIDRSlice: | 637 case H264NALU::kIDRSlice: |
632 ASSERT_TRUE(seen_sps_); | 638 ASSERT_TRUE(seen_sps_); |
633 ASSERT_TRUE(seen_pps_); | 639 ASSERT_TRUE(seen_pps_); |
634 seen_idr_ = true; | 640 seen_idr_ = true; |
635 keyframe = true; | 641 keyframe = true; |
636 // fallthrough | 642 // fallthrough |
637 case H264NALU::kNonIDRSlice: { | 643 case H264NALU::kNonIDRSlice: { |
638 ASSERT_TRUE(seen_idr_); | 644 ASSERT_TRUE(seen_idr_); |
639 seen_sps_ = seen_pps_ = false; | 645 if (IsNewFrame(nalu, sps_id) && !frame_cb_.Run(keyframe)) |
640 if (!frame_cb_.Run(keyframe)) | |
641 return; | 646 return; |
642 break; | 647 break; |
643 } | 648 } |
644 | 649 |
645 case H264NALU::kSPS: { | 650 case H264NALU::kSPS: { |
646 int sps_id; | |
647 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParseSPS(&sps_id)); | 651 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParseSPS(&sps_id)); |
648 seen_sps_ = true; | 652 seen_sps_ = true; |
649 break; | 653 break; |
650 } | 654 } |
651 | 655 |
652 case H264NALU::kPPS: { | 656 case H264NALU::kPPS: { |
653 ASSERT_TRUE(seen_sps_); | 657 ASSERT_TRUE(seen_sps_); |
654 int pps_id; | 658 int pps_id; |
655 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParsePPS(&pps_id)); | 659 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParsePPS(&pps_id)); |
656 seen_pps_ = true; | 660 seen_pps_ = true; |
657 break; | 661 break; |
658 } | 662 } |
659 | 663 |
660 default: | 664 default: |
661 break; | 665 break; |
662 } | 666 } |
663 } | 667 } |
664 } | 668 } |
665 | 669 |
670 bool H264Validator::IsNewFrame(const H264NALU& nalu, int sps_id) { | |
671 std::unique_ptr<H264SliceHeader> slice_hdr(new H264SliceHeader()); | |
672 const bool par_res = h264_parser_.ParseSliceHeader(nalu, slice_hdr.get()); | |
673 if (par_res != H264Parser::kOk) { | |
674 LOG(ERROR) << "Cannot parse H264 slice header."; | |
675 return true; | |
676 } | |
677 | |
678 const bool is_new_frame = IsNewPrimaryCodedPicture(slice_hdr.get(), sps_id); | |
679 | |
680 curr_slice_hdr_.reset(slice_hdr.release()); | |
681 if (seen_sps_) { | |
682 const H264SPS* sps = h264_parser_.GetSPS(sps_id); | |
683 if (!sps) { | |
684 LOG(ERROR) << "Cannot parse SPS."; | |
685 return true; | |
686 } | |
687 curr_pic_order_cnt_type_ = sps->pic_order_cnt_type; | |
688 } | |
689 return is_new_frame; | |
690 } | |
691 | |
692 // This function follows the checks from H264Decoder::IsNewPrimaryCodedPicture() | |
693 // to identify if the given |slice_hdr| belongs to a new frame. | |
694 bool H264Validator::IsNewPrimaryCodedPicture(const H264SliceHeader* slice_hdr, | |
Pawel Osciak
2016/11/30 02:05:22
Perhaps we would be able to turn H264Decoder::IsNe
emircan
2016/12/05 21:24:31
Done.
| |
695 int sps_id) const { | |
696 if (!curr_slice_hdr_) | |
697 return true; | |
698 | |
699 if (slice_hdr->frame_num != curr_slice_hdr_->frame_num || | |
700 slice_hdr->pic_parameter_set_id != | |
701 curr_slice_hdr_->pic_parameter_set_id || | |
702 slice_hdr->nal_ref_idc != curr_slice_hdr_->nal_ref_idc || | |
703 slice_hdr->idr_pic_flag != curr_slice_hdr_->idr_pic_flag || | |
704 (slice_hdr->idr_pic_flag && | |
705 (slice_hdr->idr_pic_id != curr_slice_hdr_->idr_pic_id || | |
706 slice_hdr->first_mb_in_slice == 0))) | |
707 return true; | |
708 | |
709 const H264SPS* sps = h264_parser_.GetSPS(sps_id); | |
710 if (!sps) | |
711 return false; | |
712 | |
713 if (sps->pic_order_cnt_type == curr_pic_order_cnt_type_) { | |
714 if (curr_pic_order_cnt_type_ == 0) { | |
715 if (slice_hdr->pic_order_cnt_lsb != curr_slice_hdr_->pic_order_cnt_lsb || | |
716 slice_hdr->delta_pic_order_cnt_bottom != | |
717 curr_slice_hdr_->delta_pic_order_cnt_bottom) | |
718 return true; | |
719 } else if (curr_pic_order_cnt_type_ == 1) { | |
720 if (slice_hdr->delta_pic_order_cnt0 != | |
721 curr_slice_hdr_->delta_pic_order_cnt0 || | |
722 slice_hdr->delta_pic_order_cnt1 != | |
723 curr_slice_hdr_->delta_pic_order_cnt1) | |
724 return true; | |
725 } | |
726 } | |
727 | |
728 return false; | |
729 } | |
730 | |
666 class VP8Validator : public StreamValidator { | 731 class VP8Validator : public StreamValidator { |
667 public: | 732 public: |
668 explicit VP8Validator(const FrameFoundCallback& frame_cb) | 733 explicit VP8Validator(const FrameFoundCallback& frame_cb) |
669 : StreamValidator(frame_cb), seen_keyframe_(false) {} | 734 : StreamValidator(frame_cb), seen_keyframe_(false) {} |
670 | 735 |
671 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; | 736 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; |
672 | 737 |
673 private: | 738 private: |
674 // Have we already got a keyframe in the stream? | 739 // Have we already got a keyframe in the stream? |
675 bool seen_keyframe_; | 740 bool seen_keyframe_; |
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2094 VideoEncodeAcceleratorTest, | 2159 VideoEncodeAcceleratorTest, |
2095 ::testing::Values(std::make_tuple(3, | 2160 ::testing::Values(std::make_tuple(3, |
2096 false, | 2161 false, |
2097 0, | 2162 0, |
2098 false, | 2163 false, |
2099 false, | 2164 false, |
2100 false, | 2165 false, |
2101 false, | 2166 false, |
2102 false, | 2167 false, |
2103 false))); | 2168 false))); |
2169 | |
2170 INSTANTIATE_TEST_CASE_P( | |
2171 VerifyTimestamp, | |
2172 VideoEncodeAcceleratorTest, | |
2173 ::testing::Values( | |
2174 std::make_tuple(1, false, 0, false, false, false, false, false, true))); | |
2175 | |
2104 #if defined(OS_WIN) | 2176 #if defined(OS_WIN) |
2105 INSTANTIATE_TEST_CASE_P( | 2177 INSTANTIATE_TEST_CASE_P( |
2106 ForceBitrate, | 2178 ForceBitrate, |
2107 VideoEncodeAcceleratorTest, | 2179 VideoEncodeAcceleratorTest, |
2108 ::testing::Values( | 2180 ::testing::Values( |
2109 std::make_tuple(1, false, 0, true, false, false, false, false, false))); | 2181 std::make_tuple(1, false, 0, true, false, false, false, false, false))); |
2110 #endif // defined(OS_WIN) | 2182 #endif // defined(OS_WIN) |
2111 | 2183 |
2112 #endif // defined(OS_CHROMEOS) | 2184 #endif // defined(OS_CHROMEOS) |
2113 | 2185 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2199 | 2271 |
2200 media::g_env = | 2272 media::g_env = |
2201 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 2273 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
2202 testing::AddGlobalTestEnvironment( | 2274 testing::AddGlobalTestEnvironment( |
2203 new media::VideoEncodeAcceleratorTestEnvironment( | 2275 new media::VideoEncodeAcceleratorTestEnvironment( |
2204 std::move(test_stream_data), log_path, run_at_fps, | 2276 std::move(test_stream_data), log_path, run_at_fps, |
2205 needs_encode_latency, verify_all_output))); | 2277 needs_encode_latency, verify_all_output))); |
2206 | 2278 |
2207 return RUN_ALL_TESTS(); | 2279 return RUN_ALL_TESTS(); |
2208 } | 2280 } |
OLD | NEW |