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 28 matching lines...) Expand all Loading... | |
39 #include "media/base/cdm_context.h" | 39 #include "media/base/cdm_context.h" |
40 #include "media/base/decoder_buffer.h" | 40 #include "media/base/decoder_buffer.h" |
41 #include "media/base/media_util.h" | 41 #include "media/base/media_util.h" |
42 #include "media/base/test_data_util.h" | 42 #include "media/base/test_data_util.h" |
43 #include "media/base/video_decoder.h" | 43 #include "media/base/video_decoder.h" |
44 #include "media/base/video_frame.h" | 44 #include "media/base/video_frame.h" |
45 #include "media/filters/ffmpeg_glue.h" | 45 #include "media/filters/ffmpeg_glue.h" |
46 #include "media/filters/ffmpeg_video_decoder.h" | 46 #include "media/filters/ffmpeg_video_decoder.h" |
47 #include "media/filters/h264_parser.h" | 47 #include "media/filters/h264_parser.h" |
48 #include "media/filters/ivf_parser.h" | 48 #include "media/filters/ivf_parser.h" |
49 #include "media/gpu/h264_decoder.h" | |
50 #include "media/gpu/h264_dpb.h" | |
49 #include "media/gpu/video_accelerator_unittest_helpers.h" | 51 #include "media/gpu/video_accelerator_unittest_helpers.h" |
50 #include "media/video/fake_video_encode_accelerator.h" | 52 #include "media/video/fake_video_encode_accelerator.h" |
51 #include "media/video/video_encode_accelerator.h" | 53 #include "media/video/video_encode_accelerator.h" |
52 #include "testing/gtest/include/gtest/gtest.h" | 54 #include "testing/gtest/include/gtest/gtest.h" |
53 | 55 |
54 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) |
55 #if defined(USE_V4L2_CODEC) | 57 #if defined(USE_V4L2_CODEC) |
56 #include "base/threading/thread_task_runner_handle.h" | 58 #include "base/threading/thread_task_runner_handle.h" |
57 #include "media/gpu/v4l2_video_encode_accelerator.h" | 59 #include "media/gpu/v4l2_video_encode_accelerator.h" |
58 #endif | 60 #endif |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 public: | 600 public: |
599 explicit H264Validator(const FrameFoundCallback& frame_cb) | 601 explicit H264Validator(const FrameFoundCallback& frame_cb) |
600 : StreamValidator(frame_cb), | 602 : StreamValidator(frame_cb), |
601 seen_sps_(false), | 603 seen_sps_(false), |
602 seen_pps_(false), | 604 seen_pps_(false), |
603 seen_idr_(false) {} | 605 seen_idr_(false) {} |
604 | 606 |
605 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; | 607 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; |
606 | 608 |
607 private: | 609 private: |
610 bool IsNewPicture(const H264SliceHeader& slice_hdr); | |
611 bool UpdateCurrentPicture(const H264SliceHeader& slice_hdr); | |
612 | |
608 // Set to true when encoder provides us with the corresponding NALU type. | 613 // Set to true when encoder provides us with the corresponding NALU type. |
609 bool seen_sps_; | 614 bool seen_sps_; |
610 bool seen_pps_; | 615 bool seen_pps_; |
611 bool seen_idr_; | 616 bool seen_idr_; |
612 | 617 |
618 scoped_refptr<H264Picture> curr_pic_; | |
619 int curr_sps_id_ = -1; | |
620 int curr_pps_id_ = -1; | |
621 | |
613 H264Parser h264_parser_; | 622 H264Parser h264_parser_; |
614 }; | 623 }; |
615 | 624 |
616 void H264Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) { | 625 void H264Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) { |
617 h264_parser_.SetStream(stream, static_cast<off_t>(size)); | 626 h264_parser_.SetStream(stream, static_cast<off_t>(size)); |
618 | 627 |
619 while (1) { | 628 while (1) { |
620 H264NALU nalu; | 629 H264NALU nalu; |
621 H264Parser::Result result; | 630 H264Parser::Result result; |
622 | 631 |
623 result = h264_parser_.AdvanceToNextNALU(&nalu); | 632 result = h264_parser_.AdvanceToNextNALU(&nalu); |
624 if (result == H264Parser::kEOStream) | 633 if (result == H264Parser::kEOStream) |
625 break; | 634 break; |
626 | 635 |
627 ASSERT_EQ(H264Parser::kOk, result); | 636 ASSERT_EQ(H264Parser::kOk, result); |
628 | 637 |
629 bool keyframe = false; | 638 bool keyframe = false; |
630 | 639 |
631 switch (nalu.nal_unit_type) { | 640 switch (nalu.nal_unit_type) { |
632 case H264NALU::kIDRSlice: | 641 case H264NALU::kIDRSlice: |
633 ASSERT_TRUE(seen_sps_); | 642 ASSERT_TRUE(seen_sps_); |
634 ASSERT_TRUE(seen_pps_); | 643 ASSERT_TRUE(seen_pps_); |
635 seen_idr_ = true; | 644 seen_idr_ = true; |
636 keyframe = true; | 645 keyframe = true; |
637 // fallthrough | 646 // fallthrough |
638 case H264NALU::kNonIDRSlice: { | 647 case H264NALU::kNonIDRSlice: { |
639 ASSERT_TRUE(seen_idr_); | 648 ASSERT_TRUE(seen_idr_); |
640 seen_sps_ = seen_pps_ = false; | 649 H264SliceHeader slice_hdr; |
641 if (!frame_cb_.Run(keyframe)) | 650 const bool par_res = h264_parser_.ParseSliceHeader(nalu, &slice_hdr); |
Pawel Osciak
2017/02/14 09:27:34
s/bool/auto/
emircan
2017/02/14 22:58:45
Moved it inside ASSERT_EQ.
| |
651 if (par_res != H264Parser::kOk) { | |
Pawel Osciak
2017/02/14 09:27:34
ASSERT_TRUE perhaps?
emircan
2017/02/14 22:58:45
Moved the whole block into an ASSERT_EQ.
| |
652 LOG(ERROR) << "Cannot parse H264 slice header."; | |
642 return; | 653 return; |
654 } | |
655 if (IsNewPicture(slice_hdr)) { | |
656 if (!frame_cb_.Run(keyframe)) | |
657 return; | |
658 } | |
659 if (!UpdateCurrentPicture(slice_hdr)) { | |
Pawel Osciak
2017/02/14 09:27:34
This should also likely be a failure.
emircan
2017/02/14 22:58:45
Done.
| |
660 LOG(ERROR) << "Cannot update current picture."; | |
661 return; | |
662 } | |
643 break; | 663 break; |
644 } | 664 } |
645 | 665 |
646 case H264NALU::kSPS: { | 666 case H264NALU::kSPS: { |
647 int sps_id; | 667 int sps_id; |
648 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParseSPS(&sps_id)); | 668 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParseSPS(&sps_id)); |
649 seen_sps_ = true; | 669 seen_sps_ = true; |
650 break; | 670 break; |
651 } | 671 } |
652 | 672 |
653 case H264NALU::kPPS: { | 673 case H264NALU::kPPS: { |
654 ASSERT_TRUE(seen_sps_); | 674 ASSERT_TRUE(seen_sps_); |
655 int pps_id; | 675 int pps_id; |
656 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParsePPS(&pps_id)); | 676 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParsePPS(&pps_id)); |
657 seen_pps_ = true; | 677 seen_pps_ = true; |
658 break; | 678 break; |
659 } | 679 } |
660 | 680 |
661 default: | 681 default: |
662 break; | 682 break; |
663 } | 683 } |
664 } | 684 } |
665 } | 685 } |
666 | 686 |
687 bool H264Validator::IsNewPicture(const H264SliceHeader& slice_hdr) { | |
688 return H264Decoder::IsNewPrimaryCodedPicture( | |
689 curr_pic_, curr_pps_id_, h264_parser_.GetSPS(curr_sps_id_), slice_hdr); | |
690 } | |
691 | |
692 bool H264Validator::UpdateCurrentPicture(const H264SliceHeader& slice_hdr) { | |
693 curr_pps_id_ = slice_hdr.pic_parameter_set_id; | |
694 const H264PPS* pps = h264_parser_.GetPPS(curr_pps_id_); | |
695 if (!pps) { | |
696 LOG(ERROR) << "Cannot parse pps."; | |
697 return false; | |
698 } | |
699 | |
700 curr_sps_id_ = pps->seq_parameter_set_id; | |
701 curr_pic_ = H264Decoder::CreateH264PictureFromSliceHeader( | |
Pawel Osciak
2017/02/14 09:27:34
Should we only be Creating if IsNewPicture() retur
emircan
2017/02/14 22:58:45
Moved the call inside "if (IsNewPicture(slice_hdr)
| |
702 h264_parser_.GetSPS(curr_sps_id_), slice_hdr); | |
Pawel Osciak
2017/02/14 09:27:34
For symmetry, perhaps we could check GetSPS()'s re
emircan
2017/02/14 22:58:45
Done.
| |
703 if (!curr_pic_) { | |
704 LOG(FATAL) << "Cannot initialize current frame."; | |
705 return false; | |
706 } | |
707 return true; | |
708 } | |
709 | |
667 class VP8Validator : public StreamValidator { | 710 class VP8Validator : public StreamValidator { |
668 public: | 711 public: |
669 explicit VP8Validator(const FrameFoundCallback& frame_cb) | 712 explicit VP8Validator(const FrameFoundCallback& frame_cb) |
670 : StreamValidator(frame_cb), seen_keyframe_(false) {} | 713 : StreamValidator(frame_cb), seen_keyframe_(false) {} |
671 | 714 |
672 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; | 715 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; |
673 | 716 |
674 private: | 717 private: |
675 // Have we already got a keyframe in the stream? | 718 // Have we already got a keyframe in the stream? |
676 bool seen_keyframe_; | 719 bool seen_keyframe_; |
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2226 VideoEncodeAcceleratorTest, | 2269 VideoEncodeAcceleratorTest, |
2227 ::testing::Values(std::make_tuple(3, | 2270 ::testing::Values(std::make_tuple(3, |
2228 false, | 2271 false, |
2229 0, | 2272 0, |
2230 false, | 2273 false, |
2231 false, | 2274 false, |
2232 false, | 2275 false, |
2233 false, | 2276 false, |
2234 false, | 2277 false, |
2235 false))); | 2278 false))); |
2279 | |
2280 INSTANTIATE_TEST_CASE_P( | |
2281 VerifyTimestamp, | |
2282 VideoEncodeAcceleratorTest, | |
2283 ::testing::Values( | |
2284 std::make_tuple(1, false, 0, false, false, false, false, false, true))); | |
2285 | |
2236 #if defined(OS_WIN) | 2286 #if defined(OS_WIN) |
2237 INSTANTIATE_TEST_CASE_P( | 2287 INSTANTIATE_TEST_CASE_P( |
2238 ForceBitrate, | 2288 ForceBitrate, |
2239 VideoEncodeAcceleratorTest, | 2289 VideoEncodeAcceleratorTest, |
2240 ::testing::Values( | 2290 ::testing::Values( |
2241 std::make_tuple(1, false, 0, true, false, false, false, false, false))); | 2291 std::make_tuple(1, false, 0, true, false, false, false, false, false))); |
2242 #endif // defined(OS_WIN) | 2292 #endif // defined(OS_WIN) |
2243 | 2293 |
2244 #endif // defined(OS_CHROMEOS) | 2294 #endif // defined(OS_CHROMEOS) |
2245 | 2295 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2331 | 2381 |
2332 media::g_env = | 2382 media::g_env = |
2333 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 2383 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
2334 testing::AddGlobalTestEnvironment( | 2384 testing::AddGlobalTestEnvironment( |
2335 new media::VideoEncodeAcceleratorTestEnvironment( | 2385 new media::VideoEncodeAcceleratorTestEnvironment( |
2336 std::move(test_stream_data), log_path, run_at_fps, | 2386 std::move(test_stream_data), log_path, run_at_fps, |
2337 needs_encode_latency, verify_all_output))); | 2387 needs_encode_latency, verify_all_output))); |
2338 | 2388 |
2339 return RUN_ALL_TESTS(); | 2389 return RUN_ALL_TESTS(); |
2340 } | 2390 } |
OLD | NEW |