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" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/timer/timer.h" | |
16 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" | 17 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" |
17 #include "media/base/bind_to_current_loop.h" | 18 #include "media/base/bind_to_current_loop.h" |
18 #include "media/base/bitstream_buffer.h" | 19 #include "media/base/bitstream_buffer.h" |
19 #include "media/base/test_data_util.h" | 20 #include "media/base/test_data_util.h" |
20 #include "media/filters/h264_parser.h" | 21 #include "media/filters/h264_parser.h" |
21 #include "media/video/video_encode_accelerator.h" | 22 #include "media/video/video_encode_accelerator.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 #if defined(USE_X11) | 25 #if defined(USE_X11) |
25 #include "ui/gfx/x/x11_types.h" | 26 #include "ui/gfx/x/x11_types.h" |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 } else { | 457 } else { |
457 LOG(FATAL) << "Unsupported profile: " << profile; | 458 LOG(FATAL) << "Unsupported profile: " << profile; |
458 } | 459 } |
459 | 460 |
460 return validator.Pass(); | 461 return validator.Pass(); |
461 } | 462 } |
462 | 463 |
463 class VEAClient : public VideoEncodeAccelerator::Client { | 464 class VEAClient : public VideoEncodeAccelerator::Client { |
464 public: | 465 public: |
465 VEAClient(TestStream* test_stream, | 466 VEAClient(TestStream* test_stream, |
467 double input_fps, | |
466 ClientStateNotification<ClientState>* note, | 468 ClientStateNotification<ClientState>* note, |
467 bool save_to_file, | 469 bool save_to_file, |
468 unsigned int keyframe_period, | 470 unsigned int keyframe_period, |
469 bool force_bitrate, | 471 bool force_bitrate, |
470 bool test_perf, | 472 bool test_perf, |
471 bool mid_stream_bitrate_switch, | 473 bool mid_stream_bitrate_switch, |
472 bool mid_stream_framerate_switch); | 474 bool mid_stream_framerate_switch); |
473 virtual ~VEAClient(); | 475 virtual ~VEAClient(); |
474 void CreateEncoder(); | 476 void CreateEncoder(); |
475 void DestroyEncoder(); | 477 void DestroyEncoder(); |
(...skipping 14 matching lines...) Expand all Loading... | |
490 bool has_encoder() { return encoder_.get(); } | 492 bool has_encoder() { return encoder_.get(); } |
491 | 493 |
492 void SetState(ClientState new_state); | 494 void SetState(ClientState new_state); |
493 | 495 |
494 // Set current stream parameters to given |bitrate| at |framerate|. | 496 // Set current stream parameters to given |bitrate| at |framerate|. |
495 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 497 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
496 | 498 |
497 // Called when encoder is done with a VideoFrame. | 499 // Called when encoder is done with a VideoFrame. |
498 void InputNoLongerNeededCallback(int32 input_id); | 500 void InputNoLongerNeededCallback(int32 input_id); |
499 | 501 |
500 // Ensure encoder has at least as many inputs as it asked for | 502 // Feed the encoder with one input frame unless it has more input buffers |
501 // via RequireBitstreamBuffers(). | 503 // than it asked for via RequireBitstreamBuffers(). Return false if no input |
502 void FeedEncoderWithInputs(); | 504 // frame was fed. |
505 bool FeedEncoderWithOneInput(); | |
503 | 506 |
504 // Provide the encoder with a new output buffer. | 507 // Provide the encoder with a new output buffer. |
505 void FeedEncoderWithOutput(base::SharedMemory* shm); | 508 void FeedEncoderWithOutput(base::SharedMemory* shm); |
506 | 509 |
507 // Called on finding a complete frame (with |keyframe| set to true for | 510 // Called on finding a complete frame (with |keyframe| set to true for |
508 // keyframes) in the stream, to perform codec-independent, per-frame checks | 511 // keyframes) in the stream, to perform codec-independent, per-frame checks |
509 // and accounting. Returns false once we have collected all frames we needed. | 512 // and accounting. Returns false once we have collected all frames we needed. |
510 bool HandleEncodedFrame(bool keyframe); | 513 bool HandleEncodedFrame(bool keyframe); |
511 | 514 |
512 // Verify that stream bitrate has been close to current_requested_bitrate_, | 515 // Verify that stream bitrate has been close to current_requested_bitrate_, |
(...skipping 12 matching lines...) Expand all Loading... | |
525 | 528 |
526 // Update the parameters according to |mid_stream_bitrate_switch| and | 529 // Update the parameters according to |mid_stream_bitrate_switch| and |
527 // |mid_stream_framerate_switch|. | 530 // |mid_stream_framerate_switch|. |
528 void UpdateTestStreamData(bool mid_stream_bitrate_switch, | 531 void UpdateTestStreamData(bool mid_stream_bitrate_switch, |
529 bool mid_stream_framerate_switch); | 532 bool mid_stream_framerate_switch); |
530 | 533 |
531 ClientState state_; | 534 ClientState state_; |
532 scoped_ptr<VideoEncodeAccelerator> encoder_; | 535 scoped_ptr<VideoEncodeAccelerator> encoder_; |
533 | 536 |
534 TestStream* test_stream_; | 537 TestStream* test_stream_; |
538 | |
535 // Used to notify another thread about the state. VEAClient does not own this. | 539 // Used to notify another thread about the state. VEAClient does not own this. |
536 ClientStateNotification<ClientState>* note_; | 540 ClientStateNotification<ClientState>* note_; |
537 | 541 |
538 // Ids assigned to VideoFrames (start at 1 for easy comparison with | 542 // Ids assigned to VideoFrames (start at 1 for easy comparison with |
539 // num_encoded_frames_). | 543 // num_encoded_frames_). |
540 std::set<int32> inputs_at_client_; | 544 std::set<int32> inputs_at_client_; |
541 int32 next_input_id_; | 545 int32 next_input_id_; |
542 | 546 |
543 // Ids for output BitstreamBuffers. | 547 // Ids for output BitstreamBuffers. |
544 typedef std::map<int32, base::SharedMemory*> IdToSHM; | 548 typedef std::map<int32, base::SharedMemory*> IdToSHM; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 unsigned int requested_bitrate_; | 610 unsigned int requested_bitrate_; |
607 | 611 |
608 // Requested initial framerate. | 612 // Requested initial framerate. |
609 unsigned int requested_framerate_; | 613 unsigned int requested_framerate_; |
610 | 614 |
611 // Bitrate to switch to in the middle of the stream. | 615 // Bitrate to switch to in the middle of the stream. |
612 unsigned int requested_subsequent_bitrate_; | 616 unsigned int requested_subsequent_bitrate_; |
613 | 617 |
614 // Framerate to switch to in the middle of the stream. | 618 // Framerate to switch to in the middle of the stream. |
615 unsigned int requested_subsequent_framerate_; | 619 unsigned int requested_subsequent_framerate_; |
620 | |
621 // The timer used to feed the encoder with the input frames. | |
622 scoped_ptr<base::RepeatingTimer<VEAClient>> input_timer_; | |
623 | |
624 // The interval between two input frames. | |
625 base::TimeDelta input_duration_; | |
616 }; | 626 }; |
617 | 627 |
618 VEAClient::VEAClient(TestStream* test_stream, | 628 VEAClient::VEAClient(TestStream* test_stream, |
629 double input_fps, | |
619 ClientStateNotification<ClientState>* note, | 630 ClientStateNotification<ClientState>* note, |
620 bool save_to_file, | 631 bool save_to_file, |
621 unsigned int keyframe_period, | 632 unsigned int keyframe_period, |
622 bool force_bitrate, | 633 bool force_bitrate, |
623 bool test_perf, | 634 bool test_perf, |
624 bool mid_stream_bitrate_switch, | 635 bool mid_stream_bitrate_switch, |
625 bool mid_stream_framerate_switch) | 636 bool mid_stream_framerate_switch) |
626 : state_(CS_CREATED), | 637 : state_(CS_CREATED), |
627 test_stream_(test_stream), | 638 test_stream_(test_stream), |
628 note_(note), | 639 note_(note), |
(...skipping 20 matching lines...) Expand all Loading... | |
649 requested_subsequent_framerate_(0) { | 660 requested_subsequent_framerate_(0) { |
650 if (keyframe_period_) | 661 if (keyframe_period_) |
651 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); | 662 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); |
652 | 663 |
653 validator_ = StreamValidator::Create( | 664 validator_ = StreamValidator::Create( |
654 test_stream_->requested_profile, | 665 test_stream_->requested_profile, |
655 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 666 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
656 | 667 |
657 CHECK(validator_.get()); | 668 CHECK(validator_.get()); |
658 | 669 |
670 if (input_fps > 0) | |
671 input_duration_ = base::TimeDelta::FromSeconds(1) / input_fps; | |
672 | |
659 if (save_to_file_) { | 673 if (save_to_file_) { |
660 CHECK(!test_stream_->out_filename.empty()); | 674 CHECK(!test_stream_->out_filename.empty()); |
661 base::FilePath out_filename(test_stream_->out_filename); | 675 base::FilePath out_filename(test_stream_->out_filename); |
662 // This creates or truncates out_filename. | 676 // This creates or truncates out_filename. |
663 // Without it, AppendToFile() will not work. | 677 // Without it, AppendToFile() will not work. |
664 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 678 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
665 } | 679 } |
666 | 680 |
667 // Initialize the parameters of the test streams. | 681 // Initialize the parameters of the test streams. |
668 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 682 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
(...skipping 30 matching lines...) Expand all Loading... | |
699 | 713 |
700 SetStreamParameters(requested_bitrate_, requested_framerate_); | 714 SetStreamParameters(requested_bitrate_, requested_framerate_); |
701 SetState(CS_INITIALIZED); | 715 SetState(CS_INITIALIZED); |
702 } | 716 } |
703 | 717 |
704 void VEAClient::DestroyEncoder() { | 718 void VEAClient::DestroyEncoder() { |
705 DCHECK(thread_checker_.CalledOnValidThread()); | 719 DCHECK(thread_checker_.CalledOnValidThread()); |
706 if (!has_encoder()) | 720 if (!has_encoder()) |
707 return; | 721 return; |
708 encoder_.reset(); | 722 encoder_.reset(); |
723 input_timer_.reset(); | |
709 } | 724 } |
710 | 725 |
711 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, | 726 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, |
712 bool mid_stream_framerate_switch) { | 727 bool mid_stream_framerate_switch) { |
713 // Use defaults for bitrate/framerate if they are not provided. | 728 // Use defaults for bitrate/framerate if they are not provided. |
714 if (test_stream_->requested_bitrate == 0) | 729 if (test_stream_->requested_bitrate == 0) |
715 requested_bitrate_ = kDefaultBitrate; | 730 requested_bitrate_ = kDefaultBitrate; |
716 else | 731 else |
717 requested_bitrate_ = test_stream_->requested_bitrate; | 732 requested_bitrate_ = test_stream_->requested_bitrate; |
718 | 733 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 ASSERT_GT(output_buffer_size_, 0UL); | 800 ASSERT_GT(output_buffer_size_, 0UL); |
786 | 801 |
787 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { | 802 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { |
788 base::SharedMemory* shm = new base::SharedMemory(); | 803 base::SharedMemory* shm = new base::SharedMemory(); |
789 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); | 804 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); |
790 output_shms_.push_back(shm); | 805 output_shms_.push_back(shm); |
791 FeedEncoderWithOutput(shm); | 806 FeedEncoderWithOutput(shm); |
792 } | 807 } |
793 | 808 |
794 encode_start_time_ = base::TimeTicks::Now(); | 809 encode_start_time_ = base::TimeTicks::Now(); |
795 FeedEncoderWithInputs(); | 810 if (input_duration_ == base::TimeDelta()) { |
811 while (FeedEncoderWithOneInput()) | |
812 ; | |
813 } else { | |
814 input_timer_.reset(new base::RepeatingTimer<VEAClient>()); | |
815 input_timer_->Start( | |
816 FROM_HERE, input_duration_, | |
817 base::Bind(base::IgnoreResult(&VEAClient::FeedEncoderWithOneInput), | |
818 base::Unretained(this))); | |
819 } | |
796 } | 820 } |
797 | 821 |
798 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, | 822 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, |
799 size_t payload_size, | 823 size_t payload_size, |
800 bool key_frame) { | 824 bool key_frame) { |
801 DCHECK(thread_checker_.CalledOnValidThread()); | 825 DCHECK(thread_checker_.CalledOnValidThread()); |
802 ASSERT_LE(payload_size, output_buffer_size_); | 826 ASSERT_LE(payload_size, output_buffer_size_); |
803 | 827 |
804 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); | 828 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); |
805 ASSERT_NE(it, output_buffers_at_client_.end()); | 829 ASSERT_NE(it, output_buffers_at_client_.end()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, | 873 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, |
850 current_framerate_); | 874 current_framerate_); |
851 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ | 875 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ |
852 << " bps @ " << current_framerate_ << " FPS"; | 876 << " bps @ " << current_framerate_ << " FPS"; |
853 } | 877 } |
854 | 878 |
855 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { | 879 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { |
856 std::set<int32>::iterator it = inputs_at_client_.find(input_id); | 880 std::set<int32>::iterator it = inputs_at_client_.find(input_id); |
857 ASSERT_NE(it, inputs_at_client_.end()); | 881 ASSERT_NE(it, inputs_at_client_.end()); |
858 inputs_at_client_.erase(it); | 882 inputs_at_client_.erase(it); |
859 FeedEncoderWithInputs(); | 883 DCHECK(FeedEncoderWithOneInput()); |
wuchengli
2014/12/11 05:08:08
if (input_duration_ == base::TimeDelta()) is still
Owen Lin
2014/12/11 05:28:30
Thanks.
| |
860 } | 884 } |
861 | 885 |
862 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { | 886 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { |
863 CHECK_LE(position + test_stream_->aligned_buffer_size, | 887 CHECK_LE(position + test_stream_->aligned_buffer_size, |
864 test_stream_->mapped_aligned_in_file.length()); | 888 test_stream_->mapped_aligned_in_file.length()); |
865 | 889 |
866 uint8* frame_data_y = const_cast<uint8*>( | 890 uint8* frame_data_y = const_cast<uint8*>( |
867 test_stream_->mapped_aligned_in_file.data() + position); | 891 test_stream_->mapped_aligned_in_file.data() + position); |
868 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; | 892 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; |
869 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1]; | 893 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1]; |
(...skipping 18 matching lines...) Expand all Loading... | |
888 base::Bind(&VEAClient::InputNoLongerNeededCallback, | 912 base::Bind(&VEAClient::InputNoLongerNeededCallback, |
889 base::Unretained(this), | 913 base::Unretained(this), |
890 next_input_id_))); | 914 next_input_id_))); |
891 | 915 |
892 CHECK(inputs_at_client_.insert(next_input_id_).second); | 916 CHECK(inputs_at_client_.insert(next_input_id_).second); |
893 ++next_input_id_; | 917 ++next_input_id_; |
894 | 918 |
895 return frame; | 919 return frame; |
896 } | 920 } |
897 | 921 |
898 void VEAClient::FeedEncoderWithInputs() { | 922 bool VEAClient::FeedEncoderWithOneInput() { |
899 if (!has_encoder()) | 923 if (!has_encoder() || state_ != CS_ENCODING) { |
900 return; | 924 // Destructor will also stop the timer. |
925 input_timer_.reset(); | |
926 return false; | |
927 } | |
901 | 928 |
902 if (state_ != CS_ENCODING) | 929 size_t bytes_left = |
903 return; | 930 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; |
931 if (bytes_left < test_stream_->aligned_buffer_size) { | |
932 DCHECK_EQ(bytes_left, 0UL); | |
933 // Rewind if at the end of stream and we are still encoding. | |
934 // This is to flush the encoder with additional frames from the beginning | |
935 // of the stream, or if the stream is shorter that the number of frames | |
936 // we require for bitrate tests. | |
937 pos_in_input_stream_ = 0; | |
938 } | |
904 | 939 |
905 while (inputs_at_client_.size() < | 940 if (inputs_at_client_.size() >= |
906 num_required_input_buffers_ + kNumExtraInputFrames) { | 941 num_required_input_buffers_ + kNumExtraInputFrames) { |
907 size_t bytes_left = | 942 DVLOG(1) << "Drop input frame: " + pos_in_input_stream_; |
908 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; | 943 pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
909 if (bytes_left < test_stream_->aligned_buffer_size) { | 944 return false; |
910 DCHECK_EQ(bytes_left, 0UL); | 945 } |
911 // Rewind if at the end of stream and we are still encoding. | |
912 // This is to flush the encoder with additional frames from the beginning | |
913 // of the stream, or if the stream is shorter that the number of frames | |
914 // we require for bitrate tests. | |
915 pos_in_input_stream_ = 0; | |
916 continue; | |
917 } | |
918 | 946 |
919 bool force_keyframe = false; | 947 bool force_keyframe = false; |
920 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { | 948 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { |
921 keyframe_requested_at_ = next_input_id_; | 949 keyframe_requested_at_ = next_input_id_; |
922 force_keyframe = true; | 950 force_keyframe = true; |
923 } | 951 } |
924 | 952 |
925 scoped_refptr<media::VideoFrame> video_frame = | 953 scoped_refptr<media::VideoFrame> video_frame = |
926 PrepareInputFrame(pos_in_input_stream_); | 954 PrepareInputFrame(pos_in_input_stream_); |
927 pos_in_input_stream_ += test_stream_->aligned_buffer_size; | 955 pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
928 | 956 |
929 encoder_->Encode(video_frame, force_keyframe); | 957 encoder_->Encode(video_frame, force_keyframe); |
930 } | 958 return true; |
931 } | 959 } |
932 | 960 |
933 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { | 961 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { |
934 if (!has_encoder()) | 962 if (!has_encoder()) |
935 return; | 963 return; |
936 | 964 |
937 if (state_ != CS_ENCODING) | 965 if (state_ != CS_ENCODING) |
938 return; | 966 return; |
939 | 967 |
940 base::SharedMemoryHandle dup_handle; | 968 base::SharedMemoryHandle dup_handle; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1017 current_requested_bitrate_, | 1045 current_requested_bitrate_, |
1018 kBitrateTolerance * current_requested_bitrate_); | 1046 kBitrateTolerance * current_requested_bitrate_); |
1019 } | 1047 } |
1020 } | 1048 } |
1021 | 1049 |
1022 // Setup test stream data and delete temporary aligned files at the beginning | 1050 // Setup test stream data and delete temporary aligned files at the beginning |
1023 // and end of unittest. We only need to setup once for all test cases. | 1051 // and end of unittest. We only need to setup once for all test cases. |
1024 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { | 1052 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { |
1025 public: | 1053 public: |
1026 VideoEncodeAcceleratorTestEnvironment( | 1054 VideoEncodeAcceleratorTestEnvironment( |
1027 scoped_ptr<base::FilePath::StringType> data) { | 1055 scoped_ptr<base::FilePath::StringType> data, |
1056 double input_fps) { | |
1028 test_stream_data_ = data.Pass(); | 1057 test_stream_data_ = data.Pass(); |
1058 input_fps_ = input_fps; | |
1029 } | 1059 } |
1030 | 1060 |
1031 virtual void SetUp() { | 1061 virtual void SetUp() { |
1032 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); | 1062 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); |
1033 } | 1063 } |
1034 | 1064 |
1035 virtual void TearDown() { | 1065 virtual void TearDown() { |
1036 for (size_t i = 0; i < test_streams_.size(); i++) { | 1066 for (size_t i = 0; i < test_streams_.size(); i++) { |
1037 base::DeleteFile(test_streams_[i]->aligned_in_file, false); | 1067 base::DeleteFile(test_streams_[i]->aligned_in_file, false); |
1038 } | 1068 } |
1039 } | 1069 } |
1040 | 1070 |
1041 ScopedVector<TestStream> test_streams_; | 1071 ScopedVector<TestStream> test_streams_; |
1042 | 1072 |
1073 // The input frame rate to the encoder. | |
1074 double input_fps_; | |
1075 | |
1043 private: | 1076 private: |
1044 scoped_ptr<base::FilePath::StringType> test_stream_data_; | 1077 scoped_ptr<base::FilePath::StringType> test_stream_data_; |
1045 }; | 1078 }; |
1046 | 1079 |
1047 // Test parameters: | 1080 // Test parameters: |
1048 // - Number of concurrent encoders. | 1081 // - Number of concurrent encoders. |
1049 // - If true, save output to file (provided an output filename was supplied). | 1082 // - If true, save output to file (provided an output filename was supplied). |
1050 // - Force a keyframe every n frames. | 1083 // - Force a keyframe every n frames. |
1051 // - Force bitrate; the actual required value is provided as a property | 1084 // - Force bitrate; the actual required value is provided as a property |
1052 // of the input stream, because it depends on stream type/resolution/etc. | 1085 // of the input stream, because it depends on stream type/resolution/etc. |
(...skipping 20 matching lines...) Expand all Loading... | |
1073 | 1106 |
1074 // Create all encoders. | 1107 // Create all encoders. |
1075 for (size_t i = 0; i < num_concurrent_encoders; i++) { | 1108 for (size_t i = 0; i < num_concurrent_encoders; i++) { |
1076 size_t test_stream_index = i % g_env->test_streams_.size(); | 1109 size_t test_stream_index = i % g_env->test_streams_.size(); |
1077 // Disregard save_to_file if we didn't get an output filename. | 1110 // Disregard save_to_file if we didn't get an output filename. |
1078 bool encoder_save_to_file = | 1111 bool encoder_save_to_file = |
1079 (save_to_file && | 1112 (save_to_file && |
1080 !g_env->test_streams_[test_stream_index]->out_filename.empty()); | 1113 !g_env->test_streams_[test_stream_index]->out_filename.empty()); |
1081 | 1114 |
1082 notes.push_back(new ClientStateNotification<ClientState>()); | 1115 notes.push_back(new ClientStateNotification<ClientState>()); |
1083 clients.push_back(new VEAClient(g_env->test_streams_[test_stream_index], | 1116 clients.push_back(new VEAClient( |
1084 notes.back(), | 1117 g_env->test_streams_[test_stream_index], g_env->input_fps_, |
1085 encoder_save_to_file, | 1118 notes.back(), encoder_save_to_file, keyframe_period, force_bitrate, |
1086 keyframe_period, | 1119 test_perf, mid_stream_bitrate_switch, mid_stream_framerate_switch)); |
1087 force_bitrate, | |
1088 test_perf, | |
1089 mid_stream_bitrate_switch, | |
1090 mid_stream_framerate_switch)); | |
1091 | 1120 |
1092 encoder_thread.message_loop()->PostTask( | 1121 encoder_thread.message_loop()->PostTask( |
1093 FROM_HERE, | 1122 FROM_HERE, |
1094 base::Bind(&VEAClient::CreateEncoder, | 1123 base::Bind(&VEAClient::CreateEncoder, |
1095 base::Unretained(clients.back()))); | 1124 base::Unretained(clients.back()))); |
1096 } | 1125 } |
1097 | 1126 |
1098 // All encoders must pass through states in this order. | 1127 // All encoders must pass through states in this order. |
1099 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, | 1128 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, |
1100 CS_ENCODING, CS_FINISHED}; | 1129 CS_ENCODING, CS_FINISHED}; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 content::g_default_in_parameters)); | 1206 content::g_default_in_parameters)); |
1178 | 1207 |
1179 // Needed to enable DVLOG through --vmodule. | 1208 // Needed to enable DVLOG through --vmodule. |
1180 logging::LoggingSettings settings; | 1209 logging::LoggingSettings settings; |
1181 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 1210 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
1182 CHECK(logging::InitLogging(settings)); | 1211 CHECK(logging::InitLogging(settings)); |
1183 | 1212 |
1184 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 1213 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
1185 DCHECK(cmd_line); | 1214 DCHECK(cmd_line); |
1186 | 1215 |
1216 double input_fps = 0; | |
1187 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | 1217 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
1188 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1218 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
1189 it != switches.end(); | 1219 it != switches.end(); |
1190 ++it) { | 1220 ++it) { |
1191 if (it->first == "test_stream_data") { | 1221 if (it->first == "test_stream_data") { |
1192 test_stream_data->assign(it->second.c_str()); | 1222 test_stream_data->assign(it->second.c_str()); |
1193 continue; | 1223 continue; |
1194 } | 1224 } |
1225 if (it->first == "input_fps") { | |
1226 // On Windows, CommandLine::StringType is wstring. We need to convert | |
1227 // it to std::string first | |
1228 std::string input(it->second.begin(), it->second.end()); | |
1229 CHECK(base::StringToDouble(input, &input_fps)); | |
1230 continue; | |
1231 } | |
1195 if (it->first == "v" || it->first == "vmodule") | 1232 if (it->first == "v" || it->first == "vmodule") |
1196 continue; | 1233 continue; |
1197 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1234 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1198 } | 1235 } |
1199 | 1236 |
1200 content::g_env = | 1237 content::g_env = |
1201 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1238 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1202 testing::AddGlobalTestEnvironment( | 1239 testing::AddGlobalTestEnvironment( |
1203 new content::VideoEncodeAcceleratorTestEnvironment( | 1240 new content::VideoEncodeAcceleratorTestEnvironment( |
1204 test_stream_data.Pass()))); | 1241 test_stream_data.Pass(), input_fps))); |
1205 | 1242 |
1206 return RUN_ALL_TESTS(); | 1243 return RUN_ALL_TESTS(); |
1207 } | 1244 } |
OLD | NEW |