Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: media/gpu/video_encode_accelerator_unittest.cc

Issue 2538883002: Detect H264 slices of the same frame in VEAUnittest (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/gpu/h264_decoder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 ASSERT_EQ(H264Parser::kOk,
642 return; 651 h264_parser_.ParseSliceHeader(nalu, &slice_hdr));
652 if (IsNewPicture(slice_hdr)) {
653 if (!frame_cb_.Run(keyframe))
654 return;
655 ASSERT_TRUE(UpdateCurrentPicture(slice_hdr));
656 }
643 break; 657 break;
644 } 658 }
645 659
646 case H264NALU::kSPS: { 660 case H264NALU::kSPS: {
647 int sps_id; 661 int sps_id;
648 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParseSPS(&sps_id)); 662 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParseSPS(&sps_id));
649 seen_sps_ = true; 663 seen_sps_ = true;
650 break; 664 break;
651 } 665 }
652 666
653 case H264NALU::kPPS: { 667 case H264NALU::kPPS: {
654 ASSERT_TRUE(seen_sps_); 668 ASSERT_TRUE(seen_sps_);
655 int pps_id; 669 int pps_id;
656 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParsePPS(&pps_id)); 670 ASSERT_EQ(H264Parser::kOk, h264_parser_.ParsePPS(&pps_id));
657 seen_pps_ = true; 671 seen_pps_ = true;
658 break; 672 break;
659 } 673 }
660 674
661 default: 675 default:
662 break; 676 break;
663 } 677 }
664 } 678 }
665 } 679 }
666 680
681 bool H264Validator::IsNewPicture(const H264SliceHeader& slice_hdr) {
682 if (!curr_pic_)
683 return true;
684 return H264Decoder::IsNewPrimaryCodedPicture(
685 curr_pic_, curr_pps_id_, h264_parser_.GetSPS(curr_sps_id_), slice_hdr);
686 }
687
688 bool H264Validator::UpdateCurrentPicture(const H264SliceHeader& slice_hdr) {
689 curr_pps_id_ = slice_hdr.pic_parameter_set_id;
690 const H264PPS* pps = h264_parser_.GetPPS(curr_pps_id_);
691 if (!pps) {
692 LOG(ERROR) << "Cannot parse pps.";
693 return false;
694 }
695
696 curr_sps_id_ = pps->seq_parameter_set_id;
697 const H264SPS* sps = h264_parser_.GetSPS(curr_sps_id_);
698 if (!sps) {
699 LOG(ERROR) << "Cannot parse sps.";
700 return false;
701 }
702
703 curr_pic_ = H264Decoder::CreateH264PictureFromSliceHeader(sps, slice_hdr);
704 if (!curr_pic_) {
705 LOG(FATAL) << "Cannot initialize current frame.";
706 return false;
707 }
708 return true;
709 }
710
667 class VP8Validator : public StreamValidator { 711 class VP8Validator : public StreamValidator {
668 public: 712 public:
669 explicit VP8Validator(const FrameFoundCallback& frame_cb) 713 explicit VP8Validator(const FrameFoundCallback& frame_cb)
670 : StreamValidator(frame_cb), seen_keyframe_(false) {} 714 : StreamValidator(frame_cb), seen_keyframe_(false) {}
671 715
672 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override; 716 void ProcessStreamBuffer(const uint8_t* stream, size_t size) override;
673 717
674 private: 718 private:
675 // Have we already got a keyframe in the stream? 719 // Have we already got a keyframe in the stream?
676 bool seen_keyframe_; 720 bool seen_keyframe_;
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 VideoEncodeAcceleratorTest, 2270 VideoEncodeAcceleratorTest,
2227 ::testing::Values(std::make_tuple(3, 2271 ::testing::Values(std::make_tuple(3,
2228 false, 2272 false,
2229 0, 2273 0,
2230 false, 2274 false,
2231 false, 2275 false,
2232 false, 2276 false,
2233 false, 2277 false,
2234 false, 2278 false,
2235 false))); 2279 false)));
2280
2281 INSTANTIATE_TEST_CASE_P(
2282 VerifyTimestamp,
2283 VideoEncodeAcceleratorTest,
2284 ::testing::Values(
2285 std::make_tuple(1, false, 0, false, false, false, false, false, true)));
2286
2236 #if defined(OS_WIN) 2287 #if defined(OS_WIN)
2237 INSTANTIATE_TEST_CASE_P( 2288 INSTANTIATE_TEST_CASE_P(
2238 ForceBitrate, 2289 ForceBitrate,
2239 VideoEncodeAcceleratorTest, 2290 VideoEncodeAcceleratorTest,
2240 ::testing::Values( 2291 ::testing::Values(
2241 std::make_tuple(1, false, 0, true, false, false, false, false, false))); 2292 std::make_tuple(1, false, 0, true, false, false, false, false, false)));
2242 #endif // defined(OS_WIN) 2293 #endif // defined(OS_WIN)
2243 2294
2244 #endif // defined(OS_CHROMEOS) 2295 #endif // defined(OS_CHROMEOS)
2245 2296
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 2382
2332 media::g_env = 2383 media::g_env =
2333 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( 2384 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>(
2334 testing::AddGlobalTestEnvironment( 2385 testing::AddGlobalTestEnvironment(
2335 new media::VideoEncodeAcceleratorTestEnvironment( 2386 new media::VideoEncodeAcceleratorTestEnvironment(
2336 std::move(test_stream_data), log_path, run_at_fps, 2387 std::move(test_stream_data), log_path, run_at_fps,
2337 needs_encode_latency, verify_all_output))); 2388 needs_encode_latency, verify_all_output)));
2338 2389
2339 return RUN_ALL_TESTS(); 2390 return RUN_ALL_TESTS();
2340 } 2391 }
OLDNEW
« no previous file with comments | « media/gpu/h264_decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698