Chromium Code Reviews| 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 "media/gpu/v4l2_video_encode_accelerator.h" | 58 #include "media/gpu/v4l2_video_encode_accelerator.h" |
| 57 #endif | 59 #endif |
| 58 #if defined(ARCH_CPU_X86_FAMILY) | 60 #if defined(ARCH_CPU_X86_FAMILY) |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 | 594 |
| 593 FrameFoundCallback frame_cb_; | 595 FrameFoundCallback frame_cb_; |
| 594 }; | 596 }; |
| 595 | 597 |
| 596 class H264Validator : public StreamValidator { | 598 class H264Validator : public StreamValidator { |
| 597 public: | 599 public: |
| 598 explicit H264Validator(const FrameFoundCallback& frame_cb) | 600 explicit H264Validator(const FrameFoundCallback& frame_cb) |
| 599 : StreamValidator(frame_cb), | 601 : StreamValidator(frame_cb), |
| 600 seen_sps_(false), | 602 seen_sps_(false), |
| 601 seen_pps_(false), | 603 seen_pps_(false), |
| 602 seen_idr_(false) {} | 604 seen_idr_(false), |
| 605 curr_pic_(new H264Picture()), | |
|
Pawel Osciak
2016/12/20 08:34:22
Perhaps we could create this when a new frame is p
emircan
2017/01/03 19:29:00
Done.
| |
| 606 curr_sps_id_(-1), | |
|
Pawel Osciak
2016/12/20 08:34:22
Nit: perhaps initialize at definition site below?
emircan
2017/01/03 19:29:00
Done.
| |
| 607 curr_pps_id_(-1) {} | |
| 603 | 608 |
| 604 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; | 609 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; |
| 605 | 610 |
| 606 private: | 611 private: |
| 612 bool IsNewFrame(const H264NALU& nalu, int sps_id, int pps_id); | |
| 613 | |
| 607 // Set to true when encoder provides us with the corresponding NALU type. | 614 // Set to true when encoder provides us with the corresponding NALU type. |
| 608 bool seen_sps_; | 615 bool seen_sps_; |
| 609 bool seen_pps_; | 616 bool seen_pps_; |
| 610 bool seen_idr_; | 617 bool seen_idr_; |
| 611 | 618 |
| 619 scoped_refptr<H264Picture> curr_pic_; | |
| 620 int curr_sps_id_; | |
| 621 int curr_pps_id_; | |
| 622 | |
| 612 H264Parser h264_parser_; | 623 H264Parser h264_parser_; |
| 613 }; | 624 }; |
| 614 | 625 |
| 615 void H264Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) { | 626 void H264Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) { |
| 616 h264_parser_.SetStream(stream, static_cast<off_t>(size)); | 627 h264_parser_.SetStream(stream, static_cast<off_t>(size)); |
| 617 | 628 |
| 629 int sps_id = -1; | |
| 630 int pps_id = -1; | |
| 618 while (1) { | 631 while (1) { |
| 619 H264NALU nalu; | 632 H264NALU nalu; |
| 620 H264Parser::Result result; | 633 H264Parser::Result result; |
| 621 | 634 |
| 622 result = h264_parser_.AdvanceToNextNALU(&nalu); | 635 result = h264_parser_.AdvanceToNextNALU(&nalu); |
| 623 if (result == H264Parser::kEOStream) | 636 if (result == H264Parser::kEOStream) |
| 624 break; | 637 break; |
| 625 | 638 |
| 626 ASSERT_EQ(H264Parser::kOk, result); | 639 ASSERT_EQ(H264Parser::kOk, result); |
| 627 | |
| 628 bool keyframe = false; | 640 bool keyframe = false; |
| 629 | 641 |
| 630 switch (nalu.nal_unit_type) { | 642 switch (nalu.nal_unit_type) { |
| 631 case H264NALU::kIDRSlice: | 643 case H264NALU::kIDRSlice: |
| 632 ASSERT_TRUE(seen_sps_); | 644 ASSERT_TRUE(seen_sps_); |
| 633 ASSERT_TRUE(seen_pps_); | 645 ASSERT_TRUE(seen_pps_); |
| 634 seen_idr_ = true; | 646 seen_idr_ = true; |
| 635 keyframe = true; | 647 keyframe = true; |
| 636 // fallthrough | 648 // fallthrough |
| 637 case H264NALU::kNonIDRSlice: { | 649 case H264NALU::kNonIDRSlice: { |
| 638 ASSERT_TRUE(seen_idr_); | 650 ASSERT_TRUE(seen_idr_); |
| 639 seen_sps_ = seen_pps_ = false; | 651 if (IsNewFrame(nalu, sps_id, pps_id) && !frame_cb_.Run(keyframe)) |
|
Pawel Osciak
2016/12/20 08:34:22
For readability, please:
if (IsNewFrame()) {
if
emircan
2017/01/03 19:29:00
Done.
| |
| 640 if (!frame_cb_.Run(keyframe)) | |
| 641 return; | 652 return; |
| 642 break; | 653 break; |
| 643 } | 654 } |
| 644 | 655 |
| 645 case H264NALU::kSPS: { | 656 case H264NALU::kSPS: { |
| 646 int sps_id; | |
| 647 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParseSPS(&sps_id)); | 657 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParseSPS(&sps_id)); |
| 648 seen_sps_ = true; | 658 seen_sps_ = true; |
| 649 break; | 659 break; |
| 650 } | 660 } |
| 651 | 661 |
| 652 case H264NALU::kPPS: { | 662 case H264NALU::kPPS: { |
| 653 ASSERT_TRUE(seen_sps_); | 663 ASSERT_TRUE(seen_sps_); |
| 654 int pps_id; | |
| 655 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParsePPS(&pps_id)); | 664 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParsePPS(&pps_id)); |
| 656 seen_pps_ = true; | 665 seen_pps_ = true; |
| 657 break; | 666 break; |
| 658 } | 667 } |
| 659 | 668 |
| 660 default: | 669 default: |
| 661 break; | 670 break; |
| 662 } | 671 } |
| 663 } | 672 } |
| 664 } | 673 } |
| 665 | 674 |
| 675 bool H264Validator::IsNewFrame(const H264NALU& nalu, int sps_id, int pps_id) { | |
| 676 std::unique_ptr<H264SliceHeader> slice_hdr(new H264SliceHeader()); | |
| 677 const bool par_res = h264_parser_.ParseSliceHeader(nalu, slice_hdr.get()); | |
| 678 if (par_res != H264Parser::kOk) { | |
| 679 LOG(ERROR) << "Cannot parse H264 slice header."; | |
| 680 return true; | |
|
Pawel Osciak
2016/12/20 08:34:22
Should this be s/true/false/?
emircan
2017/01/03 19:29:00
Done.
| |
| 681 } | |
| 682 const bool is_new_frame = H264Decoder::IsNewPrimaryCodedPicture( | |
| 683 curr_pic_, curr_sps_id_, curr_pps_id_, h264_parser_, slice_hdr.get()); | |
| 684 | |
| 685 curr_sps_id_ = sps_id != -1 ? sps_id : curr_sps_id_; | |
| 686 curr_pps_id_ = pps_id != -1 ? pps_id : curr_pps_id_; | |
| 687 if (!H264Decoder::InitPictureFromSliceHeader(curr_sps_id_, h264_parser_, | |
| 688 slice_hdr.get(), curr_pic_)) { | |
| 689 LOG(FATAL) << "Cannot initialize current frame."; | |
| 690 } | |
| 691 return is_new_frame; | |
| 692 } | |
| 693 | |
| 666 class VP8Validator : public StreamValidator { | 694 class VP8Validator : public StreamValidator { |
| 667 public: | 695 public: |
| 668 explicit VP8Validator(const FrameFoundCallback& frame_cb) | 696 explicit VP8Validator(const FrameFoundCallback& frame_cb) |
| 669 : StreamValidator(frame_cb), seen_keyframe_(false) {} | 697 : StreamValidator(frame_cb), seen_keyframe_(false) {} |
| 670 | 698 |
| 671 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; | 699 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; |
| 672 | 700 |
| 673 private: | 701 private: |
| 674 // Have we already got a keyframe in the stream? | 702 // Have we already got a keyframe in the stream? |
| 675 bool seen_keyframe_; | 703 bool seen_keyframe_; |
| (...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2094 VideoEncodeAcceleratorTest, | 2122 VideoEncodeAcceleratorTest, |
| 2095 ::testing::Values(std::make_tuple(3, | 2123 ::testing::Values(std::make_tuple(3, |
| 2096 false, | 2124 false, |
| 2097 0, | 2125 0, |
| 2098 false, | 2126 false, |
| 2099 false, | 2127 false, |
| 2100 false, | 2128 false, |
| 2101 false, | 2129 false, |
| 2102 false, | 2130 false, |
| 2103 false))); | 2131 false))); |
| 2132 | |
| 2133 INSTANTIATE_TEST_CASE_P( | |
| 2134 VerifyTimestamp, | |
| 2135 VideoEncodeAcceleratorTest, | |
| 2136 ::testing::Values( | |
| 2137 std::make_tuple(1, false, 0, false, false, false, false, false, true))); | |
| 2138 | |
| 2104 #if defined(OS_WIN) | 2139 #if defined(OS_WIN) |
| 2105 INSTANTIATE_TEST_CASE_P( | 2140 INSTANTIATE_TEST_CASE_P( |
| 2106 ForceBitrate, | 2141 ForceBitrate, |
| 2107 VideoEncodeAcceleratorTest, | 2142 VideoEncodeAcceleratorTest, |
| 2108 ::testing::Values( | 2143 ::testing::Values( |
| 2109 std::make_tuple(1, false, 0, true, false, false, false, false, false))); | 2144 std::make_tuple(1, false, 0, true, false, false, false, false, false))); |
| 2110 #endif // defined(OS_WIN) | 2145 #endif // defined(OS_WIN) |
| 2111 | 2146 |
| 2112 #endif // defined(OS_CHROMEOS) | 2147 #endif // defined(OS_CHROMEOS) |
| 2113 | 2148 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2199 | 2234 |
| 2200 media::g_env = | 2235 media::g_env = |
| 2201 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 2236 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
| 2202 testing::AddGlobalTestEnvironment( | 2237 testing::AddGlobalTestEnvironment( |
| 2203 new media::VideoEncodeAcceleratorTestEnvironment( | 2238 new media::VideoEncodeAcceleratorTestEnvironment( |
| 2204 std::move(test_stream_data), log_path, run_at_fps, | 2239 std::move(test_stream_data), log_path, run_at_fps, |
| 2205 needs_encode_latency, verify_all_output))); | 2240 needs_encode_latency, verify_all_output))); |
| 2206 | 2241 |
| 2207 return RUN_ALL_TESTS(); | 2242 return RUN_ALL_TESTS(); |
| 2208 } | 2243 } |
| OLD | NEW |