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 18 matching lines...) Expand all Loading... | |
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 // Ensure encoder has at least as many inputs as it asked for |
501 // via RequireBitstreamBuffers(). | 503 // via RequireBitstreamBuffers(). |
502 void FeedEncoderWithInputs(); | 504 void FeedEncoderWithInputs(); |
503 | 505 |
506 // Feed the encoder with only one input frame if it hasn't overflow. | |
507 // Return false if no input frame was fed. | |
508 void FeedEncoderWithOneInputIfPossible(); | |
509 | |
510 // Helper function to implement the |FeedEncoderWithInput| and | |
511 // |FeedEncoderWithOneInputIfPossible|. | |
512 bool FeedEncoderWithOneInputInternal(); | |
513 | |
504 // Provide the encoder with a new output buffer. | 514 // Provide the encoder with a new output buffer. |
505 void FeedEncoderWithOutput(base::SharedMemory* shm); | 515 void FeedEncoderWithOutput(base::SharedMemory* shm); |
506 | 516 |
507 // Called on finding a complete frame (with |keyframe| set to true for | 517 // Called on finding a complete frame (with |keyframe| set to true for |
508 // keyframes) in the stream, to perform codec-independent, per-frame checks | 518 // keyframes) in the stream, to perform codec-independent, per-frame checks |
509 // and accounting. Returns false once we have collected all frames we needed. | 519 // and accounting. Returns false once we have collected all frames we needed. |
510 bool HandleEncodedFrame(bool keyframe); | 520 bool HandleEncodedFrame(bool keyframe); |
511 | 521 |
512 // Verify that stream bitrate has been close to current_requested_bitrate_, | 522 // Verify that stream bitrate has been close to current_requested_bitrate_, |
513 // assuming current_framerate_ since the last time VerifyStreamProperties() | 523 // assuming current_framerate_ since the last time VerifyStreamProperties() |
(...skipping 11 matching lines...) Expand all Loading... | |
525 | 535 |
526 // Update the parameters according to |mid_stream_bitrate_switch| and | 536 // Update the parameters according to |mid_stream_bitrate_switch| and |
527 // |mid_stream_framerate_switch|. | 537 // |mid_stream_framerate_switch|. |
528 void UpdateTestStreamData(bool mid_stream_bitrate_switch, | 538 void UpdateTestStreamData(bool mid_stream_bitrate_switch, |
529 bool mid_stream_framerate_switch); | 539 bool mid_stream_framerate_switch); |
530 | 540 |
531 ClientState state_; | 541 ClientState state_; |
532 scoped_ptr<VideoEncodeAccelerator> encoder_; | 542 scoped_ptr<VideoEncodeAccelerator> encoder_; |
533 | 543 |
534 TestStream* test_stream_; | 544 TestStream* test_stream_; |
545 | |
546 // The input frame rate to the encoder. | |
547 const double input_fps_; | |
548 | |
535 // Used to notify another thread about the state. VEAClient does not own this. | 549 // Used to notify another thread about the state. VEAClient does not own this. |
536 ClientStateNotification<ClientState>* note_; | 550 ClientStateNotification<ClientState>* note_; |
537 | 551 |
538 // Ids assigned to VideoFrames (start at 1 for easy comparison with | 552 // Ids assigned to VideoFrames (start at 1 for easy comparison with |
539 // num_encoded_frames_). | 553 // num_encoded_frames_). |
540 std::set<int32> inputs_at_client_; | 554 std::set<int32> inputs_at_client_; |
541 int32 next_input_id_; | 555 int32 next_input_id_; |
542 | 556 |
543 // Ids for output BitstreamBuffers. | 557 // Ids for output BitstreamBuffers. |
544 typedef std::map<int32, base::SharedMemory*> IdToSHM; | 558 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_; | 620 unsigned int requested_bitrate_; |
607 | 621 |
608 // Requested initial framerate. | 622 // Requested initial framerate. |
609 unsigned int requested_framerate_; | 623 unsigned int requested_framerate_; |
610 | 624 |
611 // Bitrate to switch to in the middle of the stream. | 625 // Bitrate to switch to in the middle of the stream. |
612 unsigned int requested_subsequent_bitrate_; | 626 unsigned int requested_subsequent_bitrate_; |
613 | 627 |
614 // Framerate to switch to in the middle of the stream. | 628 // Framerate to switch to in the middle of the stream. |
615 unsigned int requested_subsequent_framerate_; | 629 unsigned int requested_subsequent_framerate_; |
630 | |
631 // The timer used to feed the encoder with the input frames. | |
632 scoped_ptr<base::RepeatingTimer<VEAClient>> input_timer_; | |
633 | |
634 // The interval between two input frames. | |
635 base::TimeDelta input_duration_; | |
616 }; | 636 }; |
617 | 637 |
618 VEAClient::VEAClient(TestStream* test_stream, | 638 VEAClient::VEAClient(TestStream* test_stream, |
639 double input_fps, | |
619 ClientStateNotification<ClientState>* note, | 640 ClientStateNotification<ClientState>* note, |
620 bool save_to_file, | 641 bool save_to_file, |
621 unsigned int keyframe_period, | 642 unsigned int keyframe_period, |
622 bool force_bitrate, | 643 bool force_bitrate, |
623 bool test_perf, | 644 bool test_perf, |
624 bool mid_stream_bitrate_switch, | 645 bool mid_stream_bitrate_switch, |
625 bool mid_stream_framerate_switch) | 646 bool mid_stream_framerate_switch) |
626 : state_(CS_CREATED), | 647 : state_(CS_CREATED), |
627 test_stream_(test_stream), | 648 test_stream_(test_stream), |
649 input_fps_(input_fps), | |
628 note_(note), | 650 note_(note), |
629 next_input_id_(1), | 651 next_input_id_(1), |
630 next_output_buffer_id_(0), | 652 next_output_buffer_id_(0), |
631 pos_in_input_stream_(0), | 653 pos_in_input_stream_(0), |
632 num_required_input_buffers_(0), | 654 num_required_input_buffers_(0), |
633 output_buffer_size_(0), | 655 output_buffer_size_(0), |
634 num_frames_to_encode_(0), | 656 num_frames_to_encode_(0), |
635 num_encoded_frames_(0), | 657 num_encoded_frames_(0), |
636 num_frames_since_last_check_(0), | 658 num_frames_since_last_check_(0), |
637 seen_keyframe_in_this_buffer_(false), | 659 seen_keyframe_in_this_buffer_(false), |
(...skipping 11 matching lines...) Expand all Loading... | |
649 requested_subsequent_framerate_(0) { | 671 requested_subsequent_framerate_(0) { |
650 if (keyframe_period_) | 672 if (keyframe_period_) |
651 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); | 673 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); |
652 | 674 |
653 validator_ = StreamValidator::Create( | 675 validator_ = StreamValidator::Create( |
654 test_stream_->requested_profile, | 676 test_stream_->requested_profile, |
655 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 677 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
656 | 678 |
657 CHECK(validator_.get()); | 679 CHECK(validator_.get()); |
658 | 680 |
681 if (input_fps_ > 0) | |
wuchengli
2014/12/10 02:29:14
|input_fps_| is only used in the constructor. Remo
Owen Lin
2014/12/10 05:59:51
Done.
| |
682 input_duration_ = base::TimeDelta::FromSeconds(1) / input_fps_; | |
683 | |
659 if (save_to_file_) { | 684 if (save_to_file_) { |
660 CHECK(!test_stream_->out_filename.empty()); | 685 CHECK(!test_stream_->out_filename.empty()); |
661 base::FilePath out_filename(test_stream_->out_filename); | 686 base::FilePath out_filename(test_stream_->out_filename); |
662 // This creates or truncates out_filename. | 687 // This creates or truncates out_filename. |
663 // Without it, AppendToFile() will not work. | 688 // Without it, AppendToFile() will not work. |
664 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 689 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
665 } | 690 } |
666 | 691 |
667 // Initialize the parameters of the test streams. | 692 // Initialize the parameters of the test streams. |
668 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 693 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
(...skipping 30 matching lines...) Expand all Loading... | |
699 | 724 |
700 SetStreamParameters(requested_bitrate_, requested_framerate_); | 725 SetStreamParameters(requested_bitrate_, requested_framerate_); |
701 SetState(CS_INITIALIZED); | 726 SetState(CS_INITIALIZED); |
702 } | 727 } |
703 | 728 |
704 void VEAClient::DestroyEncoder() { | 729 void VEAClient::DestroyEncoder() { |
705 DCHECK(thread_checker_.CalledOnValidThread()); | 730 DCHECK(thread_checker_.CalledOnValidThread()); |
706 if (!has_encoder()) | 731 if (!has_encoder()) |
707 return; | 732 return; |
708 encoder_.reset(); | 733 encoder_.reset(); |
734 input_timer_.reset(); | |
709 } | 735 } |
710 | 736 |
711 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, | 737 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, |
712 bool mid_stream_framerate_switch) { | 738 bool mid_stream_framerate_switch) { |
713 // Use defaults for bitrate/framerate if they are not provided. | 739 // Use defaults for bitrate/framerate if they are not provided. |
714 if (test_stream_->requested_bitrate == 0) | 740 if (test_stream_->requested_bitrate == 0) |
715 requested_bitrate_ = kDefaultBitrate; | 741 requested_bitrate_ = kDefaultBitrate; |
716 else | 742 else |
717 requested_bitrate_ = test_stream_->requested_bitrate; | 743 requested_bitrate_ = test_stream_->requested_bitrate; |
718 | 744 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 ASSERT_GT(output_buffer_size_, 0UL); | 811 ASSERT_GT(output_buffer_size_, 0UL); |
786 | 812 |
787 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { | 813 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { |
788 base::SharedMemory* shm = new base::SharedMemory(); | 814 base::SharedMemory* shm = new base::SharedMemory(); |
789 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); | 815 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); |
790 output_shms_.push_back(shm); | 816 output_shms_.push_back(shm); |
791 FeedEncoderWithOutput(shm); | 817 FeedEncoderWithOutput(shm); |
792 } | 818 } |
793 | 819 |
794 encode_start_time_ = base::TimeTicks::Now(); | 820 encode_start_time_ = base::TimeTicks::Now(); |
795 FeedEncoderWithInputs(); | 821 if (input_duration_ == base::TimeDelta()) { |
822 FeedEncoderWithInputs(); | |
wuchengli
2014/12/10 02:29:14
This can be while(FeedEncoderWithOneInput())
Owen Lin
2014/12/10 05:59:51
Done.
| |
823 } else { | |
824 input_timer_.reset(new base::RepeatingTimer<VEAClient>()); | |
825 input_timer_->Start(FROM_HERE, input_duration_, this, | |
826 &VEAClient::FeedEncoderWithOneInputIfPossible); | |
827 } | |
796 } | 828 } |
797 | 829 |
798 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, | 830 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, |
799 size_t payload_size, | 831 size_t payload_size, |
800 bool key_frame) { | 832 bool key_frame) { |
801 DCHECK(thread_checker_.CalledOnValidThread()); | 833 DCHECK(thread_checker_.CalledOnValidThread()); |
802 ASSERT_LE(payload_size, output_buffer_size_); | 834 ASSERT_LE(payload_size, output_buffer_size_); |
803 | 835 |
804 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); | 836 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); |
805 ASSERT_NE(it, output_buffers_at_client_.end()); | 837 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_, | 881 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, |
850 current_framerate_); | 882 current_framerate_); |
851 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ | 883 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ |
852 << " bps @ " << current_framerate_ << " FPS"; | 884 << " bps @ " << current_framerate_ << " FPS"; |
853 } | 885 } |
854 | 886 |
855 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { | 887 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { |
856 std::set<int32>::iterator it = inputs_at_client_.find(input_id); | 888 std::set<int32>::iterator it = inputs_at_client_.find(input_id); |
857 ASSERT_NE(it, inputs_at_client_.end()); | 889 ASSERT_NE(it, inputs_at_client_.end()); |
858 inputs_at_client_.erase(it); | 890 inputs_at_client_.erase(it); |
859 FeedEncoderWithInputs(); | 891 if (input_duration_ == base::TimeDelta()) |
892 FeedEncoderWithInputs(); | |
860 } | 893 } |
861 | 894 |
862 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { | 895 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { |
863 CHECK_LE(position + test_stream_->aligned_buffer_size, | 896 CHECK_LE(position + test_stream_->aligned_buffer_size, |
864 test_stream_->mapped_aligned_in_file.length()); | 897 test_stream_->mapped_aligned_in_file.length()); |
865 | 898 |
866 uint8* frame_data_y = const_cast<uint8*>( | 899 uint8* frame_data_y = const_cast<uint8*>( |
867 test_stream_->mapped_aligned_in_file.data() + position); | 900 test_stream_->mapped_aligned_in_file.data() + position); |
868 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; | 901 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]; | 902 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1]; |
(...skipping 19 matching lines...) Expand all Loading... | |
889 base::Unretained(this), | 922 base::Unretained(this), |
890 next_input_id_))); | 923 next_input_id_))); |
891 | 924 |
892 CHECK(inputs_at_client_.insert(next_input_id_).second); | 925 CHECK(inputs_at_client_.insert(next_input_id_).second); |
893 ++next_input_id_; | 926 ++next_input_id_; |
894 | 927 |
895 return frame; | 928 return frame; |
896 } | 929 } |
897 | 930 |
898 void VEAClient::FeedEncoderWithInputs() { | 931 void VEAClient::FeedEncoderWithInputs() { |
899 if (!has_encoder()) | 932 while (FeedEncoderWithOneInputInternal()) |
900 return; | 933 ; |
934 } | |
901 | 935 |
902 if (state_ != CS_ENCODING) | 936 void VEAClient::FeedEncoderWithOneInputIfPossible() { |
903 return; | 937 // We keep |FeedEncoderWIthOneInputInternal| and |
wuchengli
2014/12/10 02:29:14
Use base::IgnoreResultHelper and remove FeedEncode
Owen Lin
2014/12/10 05:59:51
Done.
| |
938 // |FeedEncoderWithOntInputIfPossible| as two functions because we need it | |
939 // to be the receiver method of the timer. | |
940 FeedEncoderWithOneInputInternal(); | |
941 } | |
904 | 942 |
905 while (inputs_at_client_.size() < | 943 bool VEAClient::FeedEncoderWithOneInputInternal() { |
906 num_required_input_buffers_ + kNumExtraInputFrames) { | 944 if (!has_encoder() || state_ != CS_ENCODING) { |
907 size_t bytes_left = | 945 // Destructor will also stop the timer. |
908 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; | 946 input_timer_.reset(); |
909 if (bytes_left < test_stream_->aligned_buffer_size) { | 947 return false; |
910 DCHECK_EQ(bytes_left, 0UL); | 948 } |
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 | 949 |
919 bool force_keyframe = false; | 950 size_t bytes_left = |
920 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { | 951 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; |
921 keyframe_requested_at_ = next_input_id_; | 952 if (bytes_left < test_stream_->aligned_buffer_size) { |
922 force_keyframe = true; | 953 DCHECK_EQ(bytes_left, 0UL); |
923 } | 954 // Rewind if at the end of stream and we are still encoding. |
955 // This is to flush the encoder with additional frames from the beginning | |
956 // of the stream, or if the stream is shorter that the number of frames | |
957 // we require for bitrate tests. | |
958 pos_in_input_stream_ = 0; | |
959 } | |
924 | 960 |
925 scoped_refptr<media::VideoFrame> video_frame = | 961 if (inputs_at_client_.size() >= |
926 PrepareInputFrame(pos_in_input_stream_); | 962 num_required_input_buffers_ + kNumExtraInputFrames) { |
963 DVLOG(1) << "Drop Input Frame: " + pos_in_input_stream_; | |
927 pos_in_input_stream_ += test_stream_->aligned_buffer_size; | 964 pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
965 return false; | |
966 } | |
928 | 967 |
929 encoder_->Encode(video_frame, force_keyframe); | 968 bool force_keyframe = false; |
969 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { | |
970 keyframe_requested_at_ = next_input_id_; | |
971 force_keyframe = true; | |
930 } | 972 } |
973 | |
974 scoped_refptr<media::VideoFrame> video_frame = | |
975 PrepareInputFrame(pos_in_input_stream_); | |
976 pos_in_input_stream_ += test_stream_->aligned_buffer_size; | |
977 | |
978 encoder_->Encode(video_frame, force_keyframe); | |
979 return true; | |
931 } | 980 } |
932 | 981 |
933 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { | 982 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { |
934 if (!has_encoder()) | 983 if (!has_encoder()) |
935 return; | 984 return; |
936 | 985 |
937 if (state_ != CS_ENCODING) | 986 if (state_ != CS_ENCODING) |
938 return; | 987 return; |
939 | 988 |
940 base::SharedMemoryHandle dup_handle; | 989 base::SharedMemoryHandle dup_handle; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1017 current_requested_bitrate_, | 1066 current_requested_bitrate_, |
1018 kBitrateTolerance * current_requested_bitrate_); | 1067 kBitrateTolerance * current_requested_bitrate_); |
1019 } | 1068 } |
1020 } | 1069 } |
1021 | 1070 |
1022 // Setup test stream data and delete temporary aligned files at the beginning | 1071 // 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. | 1072 // and end of unittest. We only need to setup once for all test cases. |
1024 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { | 1073 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { |
1025 public: | 1074 public: |
1026 VideoEncodeAcceleratorTestEnvironment( | 1075 VideoEncodeAcceleratorTestEnvironment( |
1027 scoped_ptr<base::FilePath::StringType> data) { | 1076 scoped_ptr<base::FilePath::StringType> data, |
1077 double input_fps) { | |
1028 test_stream_data_ = data.Pass(); | 1078 test_stream_data_ = data.Pass(); |
1079 input_fps_ = input_fps; | |
1029 } | 1080 } |
1030 | 1081 |
1031 virtual void SetUp() { | 1082 virtual void SetUp() { |
1032 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); | 1083 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); |
1033 } | 1084 } |
1034 | 1085 |
1035 virtual void TearDown() { | 1086 virtual void TearDown() { |
1036 for (size_t i = 0; i < test_streams_.size(); i++) { | 1087 for (size_t i = 0; i < test_streams_.size(); i++) { |
1037 base::DeleteFile(test_streams_[i]->aligned_in_file, false); | 1088 base::DeleteFile(test_streams_[i]->aligned_in_file, false); |
1038 } | 1089 } |
1039 } | 1090 } |
1040 | 1091 |
1041 ScopedVector<TestStream> test_streams_; | 1092 ScopedVector<TestStream> test_streams_; |
1042 | 1093 |
1094 // The input frame rate to the encoder. | |
1095 double input_fps_; | |
1096 | |
1043 private: | 1097 private: |
1044 scoped_ptr<base::FilePath::StringType> test_stream_data_; | 1098 scoped_ptr<base::FilePath::StringType> test_stream_data_; |
1045 }; | 1099 }; |
1046 | 1100 |
1047 // Test parameters: | 1101 // Test parameters: |
1048 // - Number of concurrent encoders. | 1102 // - Number of concurrent encoders. |
1049 // - If true, save output to file (provided an output filename was supplied). | 1103 // - If true, save output to file (provided an output filename was supplied). |
1050 // - Force a keyframe every n frames. | 1104 // - Force a keyframe every n frames. |
1051 // - Force bitrate; the actual required value is provided as a property | 1105 // - Force bitrate; the actual required value is provided as a property |
1052 // of the input stream, because it depends on stream type/resolution/etc. | 1106 // of the input stream, because it depends on stream type/resolution/etc. |
(...skipping 20 matching lines...) Expand all Loading... | |
1073 | 1127 |
1074 // Create all encoders. | 1128 // Create all encoders. |
1075 for (size_t i = 0; i < num_concurrent_encoders; i++) { | 1129 for (size_t i = 0; i < num_concurrent_encoders; i++) { |
1076 size_t test_stream_index = i % g_env->test_streams_.size(); | 1130 size_t test_stream_index = i % g_env->test_streams_.size(); |
1077 // Disregard save_to_file if we didn't get an output filename. | 1131 // Disregard save_to_file if we didn't get an output filename. |
1078 bool encoder_save_to_file = | 1132 bool encoder_save_to_file = |
1079 (save_to_file && | 1133 (save_to_file && |
1080 !g_env->test_streams_[test_stream_index]->out_filename.empty()); | 1134 !g_env->test_streams_[test_stream_index]->out_filename.empty()); |
1081 | 1135 |
1082 notes.push_back(new ClientStateNotification<ClientState>()); | 1136 notes.push_back(new ClientStateNotification<ClientState>()); |
1083 clients.push_back(new VEAClient(g_env->test_streams_[test_stream_index], | 1137 clients.push_back(new VEAClient( |
1084 notes.back(), | 1138 g_env->test_streams_[test_stream_index], g_env->input_fps_, |
1085 encoder_save_to_file, | 1139 notes.back(), encoder_save_to_file, keyframe_period, force_bitrate, |
1086 keyframe_period, | 1140 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 | 1141 |
1092 encoder_thread.message_loop()->PostTask( | 1142 encoder_thread.message_loop()->PostTask( |
1093 FROM_HERE, | 1143 FROM_HERE, |
1094 base::Bind(&VEAClient::CreateEncoder, | 1144 base::Bind(&VEAClient::CreateEncoder, |
1095 base::Unretained(clients.back()))); | 1145 base::Unretained(clients.back()))); |
1096 } | 1146 } |
1097 | 1147 |
1098 // All encoders must pass through states in this order. | 1148 // All encoders must pass through states in this order. |
1099 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, | 1149 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, |
1100 CS_ENCODING, CS_FINISHED}; | 1150 CS_ENCODING, CS_FINISHED}; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 content::g_default_in_parameters)); | 1227 content::g_default_in_parameters)); |
1178 | 1228 |
1179 // Needed to enable DVLOG through --vmodule. | 1229 // Needed to enable DVLOG through --vmodule. |
1180 logging::LoggingSettings settings; | 1230 logging::LoggingSettings settings; |
1181 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 1231 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
1182 CHECK(logging::InitLogging(settings)); | 1232 CHECK(logging::InitLogging(settings)); |
1183 | 1233 |
1184 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 1234 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
1185 DCHECK(cmd_line); | 1235 DCHECK(cmd_line); |
1186 | 1236 |
1237 double input_fps = 0; | |
1187 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | 1238 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
1188 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1239 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
1189 it != switches.end(); | 1240 it != switches.end(); |
1190 ++it) { | 1241 ++it) { |
1191 if (it->first == "test_stream_data") { | 1242 if (it->first == "test_stream_data") { |
1192 test_stream_data->assign(it->second.c_str()); | 1243 test_stream_data->assign(it->second.c_str()); |
1193 continue; | 1244 continue; |
1194 } | 1245 } |
1246 if (it->first == "input_fps") { | |
1247 // On Windows, CommandLine::StringType is wstring. We need to convert | |
1248 // it to std::string first | |
1249 std::string input(it->second.begin(), it->second.end()); | |
1250 CHECK(base::StringToDouble(input, &input_fps)); | |
1251 continue; | |
1252 } | |
1195 if (it->first == "v" || it->first == "vmodule") | 1253 if (it->first == "v" || it->first == "vmodule") |
1196 continue; | 1254 continue; |
1197 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1255 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1198 } | 1256 } |
1199 | 1257 |
1200 content::g_env = | 1258 content::g_env = |
1201 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1259 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1202 testing::AddGlobalTestEnvironment( | 1260 testing::AddGlobalTestEnvironment( |
1203 new content::VideoEncodeAcceleratorTestEnvironment( | 1261 new content::VideoEncodeAcceleratorTestEnvironment( |
1204 test_stream_data.Pass()))); | 1262 test_stream_data.Pass(), input_fps))); |
1205 | 1263 |
1206 return RUN_ALL_TESTS(); | 1264 return RUN_ALL_TESTS(); |
1207 } | 1265 } |
OLD | NEW |