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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/memory_mapped_file.h" | 9 #include "base/files/memory_mapped_file.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 // no simple way to detect this. We'd need to parse the frames and go through | 487 // no simple way to detect this. We'd need to parse the frames and go through |
488 // partition numbers/sizes. For now assume one frame per buffer. | 488 // partition numbers/sizes. For now assume one frame per buffer. |
489 } | 489 } |
490 | 490 |
491 // static | 491 // static |
492 scoped_ptr<StreamValidator> StreamValidator::Create( | 492 scoped_ptr<StreamValidator> StreamValidator::Create( |
493 media::VideoCodecProfile profile, | 493 media::VideoCodecProfile profile, |
494 const FrameFoundCallback& frame_cb) { | 494 const FrameFoundCallback& frame_cb) { |
495 scoped_ptr<StreamValidator> validator; | 495 scoped_ptr<StreamValidator> validator; |
496 | 496 |
497 if (g_fake_encoder) { | 497 if (IsH264(profile)) { |
498 validator.reset(NULL); | |
499 } else if (IsH264(profile)) { | |
500 validator.reset(new H264Validator(frame_cb)); | 498 validator.reset(new H264Validator(frame_cb)); |
501 } else if (IsVP8(profile)) { | 499 } else if (IsVP8(profile)) { |
502 validator.reset(new VP8Validator(frame_cb)); | 500 validator.reset(new VP8Validator(frame_cb)); |
503 } else { | 501 } else { |
504 LOG(FATAL) << "Unsupported profile: " << profile; | 502 LOG(FATAL) << "Unsupported profile: " << profile; |
505 } | 503 } |
506 | 504 |
507 return validator.Pass(); | 505 return validator.Pass(); |
508 } | 506 } |
509 | 507 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 | 624 |
627 // True if received a keyframe while processing current bitstream buffer. | 625 // True if received a keyframe while processing current bitstream buffer. |
628 bool seen_keyframe_in_this_buffer_; | 626 bool seen_keyframe_in_this_buffer_; |
629 | 627 |
630 // True if we are to save the encoded stream to a file. | 628 // True if we are to save the encoded stream to a file. |
631 bool save_to_file_; | 629 bool save_to_file_; |
632 | 630 |
633 // Request a keyframe every keyframe_period_ frames. | 631 // Request a keyframe every keyframe_period_ frames. |
634 const unsigned int keyframe_period_; | 632 const unsigned int keyframe_period_; |
635 | 633 |
636 // Frame number for which we requested a keyframe. | 634 // Number of keyframes requested by now. |
637 unsigned int keyframe_requested_at_; | 635 unsigned int num_keyframes_requested_; |
| 636 |
| 637 // Next keyframe expected before next_keyframe_at_ + kMaxKeyframeDelay. |
| 638 unsigned int next_keyframe_at_; |
638 | 639 |
639 // True if we are asking encoder for a particular bitrate. | 640 // True if we are asking encoder for a particular bitrate. |
640 bool force_bitrate_; | 641 bool force_bitrate_; |
641 | 642 |
642 // Current requested bitrate. | 643 // Current requested bitrate. |
643 unsigned int current_requested_bitrate_; | 644 unsigned int current_requested_bitrate_; |
644 | 645 |
645 // Current expected framerate. | 646 // Current expected framerate. |
646 unsigned int current_framerate_; | 647 unsigned int current_framerate_; |
647 | 648 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 bool save_to_file, | 690 bool save_to_file, |
690 unsigned int keyframe_period, | 691 unsigned int keyframe_period, |
691 bool force_bitrate, | 692 bool force_bitrate, |
692 bool test_perf, | 693 bool test_perf, |
693 bool mid_stream_bitrate_switch, | 694 bool mid_stream_bitrate_switch, |
694 bool mid_stream_framerate_switch, | 695 bool mid_stream_framerate_switch, |
695 bool run_at_fps) | 696 bool run_at_fps) |
696 : state_(CS_CREATED), | 697 : state_(CS_CREATED), |
697 test_stream_(test_stream), | 698 test_stream_(test_stream), |
698 note_(note), | 699 note_(note), |
699 next_input_id_(1), | 700 next_input_id_(0), |
700 next_output_buffer_id_(0), | 701 next_output_buffer_id_(0), |
701 pos_in_input_stream_(0), | 702 pos_in_input_stream_(0), |
702 num_required_input_buffers_(0), | 703 num_required_input_buffers_(0), |
703 output_buffer_size_(0), | 704 output_buffer_size_(0), |
704 num_frames_to_encode_(0), | 705 num_frames_to_encode_(0), |
705 num_encoded_frames_(0), | 706 num_encoded_frames_(0), |
706 num_frames_since_last_check_(0), | 707 num_frames_since_last_check_(0), |
707 seen_keyframe_in_this_buffer_(false), | 708 seen_keyframe_in_this_buffer_(false), |
708 save_to_file_(save_to_file), | 709 save_to_file_(save_to_file), |
709 keyframe_period_(keyframe_period), | 710 keyframe_period_(keyframe_period), |
710 keyframe_requested_at_(kMaxFrameNum), | 711 num_keyframes_requested_(0), |
| 712 next_keyframe_at_(kMaxFrameNum), |
711 force_bitrate_(force_bitrate), | 713 force_bitrate_(force_bitrate), |
712 current_requested_bitrate_(0), | 714 current_requested_bitrate_(0), |
713 current_framerate_(0), | 715 current_framerate_(0), |
714 encoded_stream_size_since_last_check_(0), | 716 encoded_stream_size_since_last_check_(0), |
715 test_perf_(test_perf), | 717 test_perf_(test_perf), |
716 requested_bitrate_(0), | 718 requested_bitrate_(0), |
717 requested_framerate_(0), | 719 requested_framerate_(0), |
718 requested_subsequent_bitrate_(0), | 720 requested_subsequent_bitrate_(0), |
719 requested_subsequent_framerate_(0), | 721 requested_subsequent_framerate_(0), |
720 run_at_fps_(run_at_fps) { | 722 run_at_fps_(run_at_fps) { |
721 if (keyframe_period_) | 723 if (keyframe_period_) |
722 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); | 724 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); |
723 | 725 |
724 validator_ = StreamValidator::Create( | 726 // Fake encoder produces an invalid stream, so skip validating it. |
725 test_stream_->requested_profile, | 727 if (!g_fake_encoder) { |
726 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 728 validator_ = StreamValidator::Create( |
727 | 729 test_stream_->requested_profile, |
728 | 730 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
729 CHECK(g_fake_encoder || validator_.get()); | 731 CHECK(validator_); |
| 732 } |
730 | 733 |
731 if (save_to_file_) { | 734 if (save_to_file_) { |
732 CHECK(!test_stream_->out_filename.empty()); | 735 CHECK(!test_stream_->out_filename.empty()); |
733 base::FilePath out_filename(test_stream_->out_filename); | 736 base::FilePath out_filename(test_stream_->out_filename); |
734 // This creates or truncates out_filename. | 737 // This creates or truncates out_filename. |
735 // Without it, AppendToFile() will not work. | 738 // Without it, AppendToFile() will not work. |
736 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 739 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
737 } | 740 } |
738 | 741 |
739 // Initialize the parameters of the test streams. | 742 // Initialize the parameters of the test streams. |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 DCHECK_EQ(bytes_left, 0UL); | 1046 DCHECK_EQ(bytes_left, 0UL); |
1044 // Rewind if at the end of stream and we are still encoding. | 1047 // Rewind if at the end of stream and we are still encoding. |
1045 // This is to flush the encoder with additional frames from the beginning | 1048 // This is to flush the encoder with additional frames from the beginning |
1046 // of the stream, or if the stream is shorter that the number of frames | 1049 // of the stream, or if the stream is shorter that the number of frames |
1047 // we require for bitrate tests. | 1050 // we require for bitrate tests. |
1048 pos_in_input_stream_ = 0; | 1051 pos_in_input_stream_ = 0; |
1049 } | 1052 } |
1050 | 1053 |
1051 bool force_keyframe = false; | 1054 bool force_keyframe = false; |
1052 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { | 1055 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { |
1053 keyframe_requested_at_ = next_input_id_; | |
1054 force_keyframe = true; | 1056 force_keyframe = true; |
| 1057 ++num_keyframes_requested_; |
1055 } | 1058 } |
1056 | 1059 |
1057 scoped_refptr<media::VideoFrame> video_frame = | 1060 scoped_refptr<media::VideoFrame> video_frame = |
1058 PrepareInputFrame(pos_in_input_stream_); | 1061 PrepareInputFrame(pos_in_input_stream_); |
1059 pos_in_input_stream_ += test_stream_->aligned_buffer_size; | 1062 pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
1060 | 1063 |
1061 encoder_->Encode(video_frame, force_keyframe); | 1064 encoder_->Encode(video_frame, force_keyframe); |
1062 } | 1065 } |
1063 | 1066 |
1064 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { | 1067 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { |
(...skipping 15 matching lines...) Expand all Loading... |
1080 | 1083 |
1081 bool VEAClient::HandleEncodedFrame(bool keyframe) { | 1084 bool VEAClient::HandleEncodedFrame(bool keyframe) { |
1082 // This would be a bug in the test, which should not ignore false | 1085 // This would be a bug in the test, which should not ignore false |
1083 // return value from this method. | 1086 // return value from this method. |
1084 CHECK_LE(num_encoded_frames_, num_frames_to_encode_); | 1087 CHECK_LE(num_encoded_frames_, num_frames_to_encode_); |
1085 | 1088 |
1086 ++num_encoded_frames_; | 1089 ++num_encoded_frames_; |
1087 ++num_frames_since_last_check_; | 1090 ++num_frames_since_last_check_; |
1088 | 1091 |
1089 last_frame_ready_time_ = base::TimeTicks::Now(); | 1092 last_frame_ready_time_ = base::TimeTicks::Now(); |
1090 if (keyframe) { | |
1091 // Got keyframe, reset keyframe detection regardless of whether we | |
1092 // got a frame in time or not. | |
1093 keyframe_requested_at_ = kMaxFrameNum; | |
1094 seen_keyframe_in_this_buffer_ = true; | |
1095 } | |
1096 | 1093 |
1097 // Because the keyframe behavior requirements are loose, we give | 1094 // Because the keyframe behavior requirements are loose, we give |
1098 // the encoder more freedom here. It could either deliver a keyframe | 1095 // the encoder more freedom here. It could either deliver a keyframe |
1099 // immediately after we requested it, which could be for a frame number | 1096 // immediately after we requested it, which could be for a frame number |
1100 // before the one we requested it for (if the keyframe request | 1097 // before the one we requested it for (if the keyframe request |
1101 // is asynchronous, i.e. not bound to any concrete frame, and because | 1098 // is asynchronous, i.e. not bound to any concrete frame, and because |
1102 // the pipeline can be deeper than one frame), at that frame, or after. | 1099 // the pipeline can be deeper than one frame), at that frame, or after. |
1103 // So the only constraints we put here is that we get a keyframe not | 1100 // So the only constraints we put here is that we get a keyframe not |
1104 // earlier than we requested one (in time), and not later than | 1101 // earlier than we requested one (in time), and not later than |
1105 // kMaxKeyframeDelay frames after the frame, for which we requested | 1102 // kMaxKeyframeDelay frames after the frame, for which we requested |
1106 // it, comes back encoded. | 1103 // it, comes back encoded. |
1107 EXPECT_LE(num_encoded_frames_, keyframe_requested_at_ + kMaxKeyframeDelay); | 1104 EXPECT_LE(num_encoded_frames_, next_keyframe_at_ + kMaxKeyframeDelay); |
| 1105 |
| 1106 if (keyframe) { |
| 1107 if (num_keyframes_requested_ > 0) |
| 1108 --num_keyframes_requested_; |
| 1109 next_keyframe_at_ += keyframe_period_; |
| 1110 seen_keyframe_in_this_buffer_ = true; |
| 1111 } |
1108 | 1112 |
1109 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { | 1113 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { |
1110 VerifyStreamProperties(); | 1114 VerifyStreamProperties(); |
1111 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || | 1115 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || |
1112 requested_subsequent_framerate_ != current_framerate_) { | 1116 requested_subsequent_framerate_ != current_framerate_) { |
1113 SetStreamParameters(requested_subsequent_bitrate_, | 1117 SetStreamParameters(requested_subsequent_bitrate_, |
1114 requested_subsequent_framerate_); | 1118 requested_subsequent_framerate_); |
1115 if (run_at_fps_ && input_timer_) | 1119 if (run_at_fps_ && input_timer_) |
1116 input_timer_->Start( | 1120 input_timer_->Start( |
1117 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, | 1121 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, |
(...skipping 27 matching lines...) Expand all Loading... |
1145 << " num frames in chunk: " << num_frames_since_last_check_; | 1149 << " num frames in chunk: " << num_frames_since_last_check_; |
1146 | 1150 |
1147 num_frames_since_last_check_ = 0; | 1151 num_frames_since_last_check_ = 0; |
1148 encoded_stream_size_since_last_check_ = 0; | 1152 encoded_stream_size_since_last_check_ = 0; |
1149 | 1153 |
1150 if (force_bitrate_) { | 1154 if (force_bitrate_) { |
1151 EXPECT_NEAR(bitrate, | 1155 EXPECT_NEAR(bitrate, |
1152 current_requested_bitrate_, | 1156 current_requested_bitrate_, |
1153 kBitrateTolerance * current_requested_bitrate_); | 1157 kBitrateTolerance * current_requested_bitrate_); |
1154 } | 1158 } |
| 1159 |
| 1160 // All requested keyframes should've been provided. Allow the last requested |
| 1161 // frame to remain undelivered if we haven't reached the maximum frame number |
| 1162 // by which it should have arrived. |
| 1163 if (num_encoded_frames_ < next_keyframe_at_ + kMaxKeyframeDelay) |
| 1164 EXPECT_LE(num_keyframes_requested_, 1UL); |
| 1165 else |
| 1166 EXPECT_EQ(num_keyframes_requested_, 0UL); |
1155 } | 1167 } |
1156 | 1168 |
1157 void VEAClient::WriteIvfFileHeader() { | 1169 void VEAClient::WriteIvfFileHeader() { |
1158 IvfFileHeader header; | 1170 IvfFileHeader header; |
1159 | 1171 |
1160 memset(&header, 0, sizeof(header)); | 1172 memset(&header, 0, sizeof(header)); |
1161 header.signature[0] = 'D'; | 1173 header.signature[0] = 'D'; |
1162 header.signature[1] = 'K'; | 1174 header.signature[1] = 'K'; |
1163 header.signature[2] = 'I'; | 1175 header.signature[2] = 'I'; |
1164 header.signature[3] = 'F'; | 1176 header.signature[3] = 'F'; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 } | 1408 } |
1397 | 1409 |
1398 content::g_env = | 1410 content::g_env = |
1399 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1411 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1400 testing::AddGlobalTestEnvironment( | 1412 testing::AddGlobalTestEnvironment( |
1401 new content::VideoEncodeAcceleratorTestEnvironment( | 1413 new content::VideoEncodeAcceleratorTestEnvironment( |
1402 test_stream_data.Pass(), run_at_fps))); | 1414 test_stream_data.Pass(), run_at_fps))); |
1403 | 1415 |
1404 return RUN_ALL_TESTS(); | 1416 return RUN_ALL_TESTS(); |
1405 } | 1417 } |
OLD | NEW |