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

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

Issue 769133003: vea_unittest - Control the rate of input frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and rename to run_at_fps Created 5 years, 12 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 | « no previous file | 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 "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/sys_byteorder.h" 15 #include "base/sys_byteorder.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/timer/timer.h"
17 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" 18 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h"
18 #include "media/base/bind_to_current_loop.h" 19 #include "media/base/bind_to_current_loop.h"
19 #include "media/base/bitstream_buffer.h" 20 #include "media/base/bitstream_buffer.h"
20 #include "media/base/test_data_util.h" 21 #include "media/base/test_data_util.h"
21 #include "media/filters/h264_parser.h" 22 #include "media/filters/h264_parser.h"
22 #include "media/video/video_encode_accelerator.h" 23 #include "media/video/video_encode_accelerator.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 #if defined(USE_X11) 26 #if defined(USE_X11)
26 #include "ui/gfx/x/x11_types.h" 27 #include "ui/gfx/x/x11_types.h"
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 498
498 class VEAClient : public VideoEncodeAccelerator::Client { 499 class VEAClient : public VideoEncodeAccelerator::Client {
499 public: 500 public:
500 VEAClient(TestStream* test_stream, 501 VEAClient(TestStream* test_stream,
501 ClientStateNotification<ClientState>* note, 502 ClientStateNotification<ClientState>* note,
502 bool save_to_file, 503 bool save_to_file,
503 unsigned int keyframe_period, 504 unsigned int keyframe_period,
504 bool force_bitrate, 505 bool force_bitrate,
505 bool test_perf, 506 bool test_perf,
506 bool mid_stream_bitrate_switch, 507 bool mid_stream_bitrate_switch,
507 bool mid_stream_framerate_switch); 508 bool mid_stream_framerate_switch,
509 bool run_at_fps);
508 virtual ~VEAClient(); 510 virtual ~VEAClient();
509 void CreateEncoder(); 511 void CreateEncoder();
510 void DestroyEncoder(); 512 void DestroyEncoder();
511 513
512 // Return the number of encoded frames per second. 514 // Return the number of encoded frames per second.
513 double frames_per_second(); 515 double frames_per_second();
514 516
515 // VideoDecodeAccelerator::Client implementation. 517 // VideoDecodeAccelerator::Client implementation.
516 virtual void RequireBitstreamBuffers(unsigned int input_count, 518 virtual void RequireBitstreamBuffers(unsigned int input_count,
517 const gfx::Size& input_coded_size, 519 const gfx::Size& input_coded_size,
518 size_t output_buffer_size) override; 520 size_t output_buffer_size) override;
519 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, 521 virtual void BitstreamBufferReady(int32 bitstream_buffer_id,
520 size_t payload_size, 522 size_t payload_size,
521 bool key_frame) override; 523 bool key_frame) override;
522 virtual void NotifyError(VideoEncodeAccelerator::Error error) override; 524 virtual void NotifyError(VideoEncodeAccelerator::Error error) override;
523 525
524 private: 526 private:
525 bool has_encoder() { return encoder_.get(); } 527 bool has_encoder() { return encoder_.get(); }
526 528
527 void SetState(ClientState new_state); 529 void SetState(ClientState new_state);
528 530
529 // Set current stream parameters to given |bitrate| at |framerate|. 531 // Set current stream parameters to given |bitrate| at |framerate|.
530 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); 532 void SetStreamParameters(unsigned int bitrate, unsigned int framerate);
531 533
532 // Called when encoder is done with a VideoFrame. 534 // Called when encoder is done with a VideoFrame.
533 void InputNoLongerNeededCallback(int32 input_id); 535 void InputNoLongerNeededCallback(int32 input_id);
534 536
535 // Ensure encoder has at least as many inputs as it asked for 537 // Feed the encoder with one input frame.
536 // via RequireBitstreamBuffers(). 538 void FeedEncoderWithOneInput();
537 void FeedEncoderWithInputs();
538 539
539 // Provide the encoder with a new output buffer. 540 // Provide the encoder with a new output buffer.
540 void FeedEncoderWithOutput(base::SharedMemory* shm); 541 void FeedEncoderWithOutput(base::SharedMemory* shm);
541 542
542 // Called on finding a complete frame (with |keyframe| set to true for 543 // Called on finding a complete frame (with |keyframe| set to true for
543 // keyframes) in the stream, to perform codec-independent, per-frame checks 544 // keyframes) in the stream, to perform codec-independent, per-frame checks
544 // and accounting. Returns false once we have collected all frames we needed. 545 // and accounting. Returns false once we have collected all frames we needed.
545 bool HandleEncodedFrame(bool keyframe); 546 bool HandleEncodedFrame(bool keyframe);
546 547
547 // Verify that stream bitrate has been close to current_requested_bitrate_, 548 // Verify that stream bitrate has been close to current_requested_bitrate_,
(...skipping 14 matching lines...) Expand all
562 563
563 // Prepare and return a frame wrapping the data at |position| bytes in 564 // Prepare and return a frame wrapping the data at |position| bytes in
564 // the input stream, ready to be sent to encoder. 565 // the input stream, ready to be sent to encoder.
565 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position); 566 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position);
566 567
567 // Update the parameters according to |mid_stream_bitrate_switch| and 568 // Update the parameters according to |mid_stream_bitrate_switch| and
568 // |mid_stream_framerate_switch|. 569 // |mid_stream_framerate_switch|.
569 void UpdateTestStreamData(bool mid_stream_bitrate_switch, 570 void UpdateTestStreamData(bool mid_stream_bitrate_switch,
570 bool mid_stream_framerate_switch); 571 bool mid_stream_framerate_switch);
571 572
573 // Callback function of the |input_timer_|.
574 void OnInputTimer();
575
572 ClientState state_; 576 ClientState state_;
573 scoped_ptr<VideoEncodeAccelerator> encoder_; 577 scoped_ptr<VideoEncodeAccelerator> encoder_;
574 578
575 TestStream* test_stream_; 579 TestStream* test_stream_;
580
576 // Used to notify another thread about the state. VEAClient does not own this. 581 // Used to notify another thread about the state. VEAClient does not own this.
577 ClientStateNotification<ClientState>* note_; 582 ClientStateNotification<ClientState>* note_;
578 583
579 // Ids assigned to VideoFrames (start at 1 for easy comparison with 584 // Ids assigned to VideoFrames (start at 1 for easy comparison with
580 // num_encoded_frames_). 585 // num_encoded_frames_).
581 std::set<int32> inputs_at_client_; 586 std::set<int32> inputs_at_client_;
582 int32 next_input_id_; 587 int32 next_input_id_;
583 588
584 // Ids for output BitstreamBuffers. 589 // Ids for output BitstreamBuffers.
585 typedef std::map<int32, base::SharedMemory*> IdToSHM; 590 typedef std::map<int32, base::SharedMemory*> IdToSHM;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 unsigned int requested_bitrate_; 652 unsigned int requested_bitrate_;
648 653
649 // Requested initial framerate. 654 // Requested initial framerate.
650 unsigned int requested_framerate_; 655 unsigned int requested_framerate_;
651 656
652 // Bitrate to switch to in the middle of the stream. 657 // Bitrate to switch to in the middle of the stream.
653 unsigned int requested_subsequent_bitrate_; 658 unsigned int requested_subsequent_bitrate_;
654 659
655 // Framerate to switch to in the middle of the stream. 660 // Framerate to switch to in the middle of the stream.
656 unsigned int requested_subsequent_framerate_; 661 unsigned int requested_subsequent_framerate_;
662
663 // The timer used to feed the encoder with the input frames.
664 scoped_ptr<base::RepeatingTimer<VEAClient>> input_timer_;
665
666 // Feed the encoder with the input buffers at the |requested_framerate_|. If
667 // false, feed as fast as possible. This is set by the command line switch
668 // "--run_at_fps".
669 bool run_at_fps_;
657 }; 670 };
658 671
659 VEAClient::VEAClient(TestStream* test_stream, 672 VEAClient::VEAClient(TestStream* test_stream,
660 ClientStateNotification<ClientState>* note, 673 ClientStateNotification<ClientState>* note,
661 bool save_to_file, 674 bool save_to_file,
662 unsigned int keyframe_period, 675 unsigned int keyframe_period,
663 bool force_bitrate, 676 bool force_bitrate,
664 bool test_perf, 677 bool test_perf,
665 bool mid_stream_bitrate_switch, 678 bool mid_stream_bitrate_switch,
666 bool mid_stream_framerate_switch) 679 bool mid_stream_framerate_switch,
680 bool run_at_fps)
667 : state_(CS_CREATED), 681 : state_(CS_CREATED),
668 test_stream_(test_stream), 682 test_stream_(test_stream),
669 note_(note), 683 note_(note),
670 next_input_id_(1), 684 next_input_id_(1),
671 next_output_buffer_id_(0), 685 next_output_buffer_id_(0),
672 pos_in_input_stream_(0), 686 pos_in_input_stream_(0),
673 num_required_input_buffers_(0), 687 num_required_input_buffers_(0),
674 output_buffer_size_(0), 688 output_buffer_size_(0),
675 num_frames_to_encode_(0), 689 num_frames_to_encode_(0),
676 num_encoded_frames_(0), 690 num_encoded_frames_(0),
677 num_frames_since_last_check_(0), 691 num_frames_since_last_check_(0),
678 seen_keyframe_in_this_buffer_(false), 692 seen_keyframe_in_this_buffer_(false),
679 save_to_file_(save_to_file), 693 save_to_file_(save_to_file),
680 keyframe_period_(keyframe_period), 694 keyframe_period_(keyframe_period),
681 keyframe_requested_at_(kMaxFrameNum), 695 keyframe_requested_at_(kMaxFrameNum),
682 force_bitrate_(force_bitrate), 696 force_bitrate_(force_bitrate),
683 current_requested_bitrate_(0), 697 current_requested_bitrate_(0),
684 current_framerate_(0), 698 current_framerate_(0),
685 encoded_stream_size_since_last_check_(0), 699 encoded_stream_size_since_last_check_(0),
686 test_perf_(test_perf), 700 test_perf_(test_perf),
687 requested_bitrate_(0), 701 requested_bitrate_(0),
688 requested_framerate_(0), 702 requested_framerate_(0),
689 requested_subsequent_bitrate_(0), 703 requested_subsequent_bitrate_(0),
690 requested_subsequent_framerate_(0) { 704 requested_subsequent_framerate_(0),
705 run_at_fps_(run_at_fps) {
691 if (keyframe_period_) 706 if (keyframe_period_)
692 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); 707 CHECK_LT(kMaxKeyframeDelay, keyframe_period_);
693 708
694 validator_ = StreamValidator::Create( 709 validator_ = StreamValidator::Create(
695 test_stream_->requested_profile, 710 test_stream_->requested_profile,
696 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); 711 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this)));
697 712
698 CHECK(validator_.get()); 713 CHECK(validator_.get());
699 714
700 if (save_to_file_) { 715 if (save_to_file_) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 755
741 SetStreamParameters(requested_bitrate_, requested_framerate_); 756 SetStreamParameters(requested_bitrate_, requested_framerate_);
742 SetState(CS_INITIALIZED); 757 SetState(CS_INITIALIZED);
743 } 758 }
744 759
745 void VEAClient::DestroyEncoder() { 760 void VEAClient::DestroyEncoder() {
746 DCHECK(thread_checker_.CalledOnValidThread()); 761 DCHECK(thread_checker_.CalledOnValidThread());
747 if (!has_encoder()) 762 if (!has_encoder())
748 return; 763 return;
749 encoder_.reset(); 764 encoder_.reset();
765 input_timer_.reset();
750 } 766 }
751 767
752 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, 768 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch,
753 bool mid_stream_framerate_switch) { 769 bool mid_stream_framerate_switch) {
754 // Use defaults for bitrate/framerate if they are not provided. 770 // Use defaults for bitrate/framerate if they are not provided.
755 if (test_stream_->requested_bitrate == 0) 771 if (test_stream_->requested_bitrate == 0)
756 requested_bitrate_ = kDefaultBitrate; 772 requested_bitrate_ = kDefaultBitrate;
757 else 773 else
758 requested_bitrate_ = test_stream_->requested_bitrate; 774 requested_bitrate_ = test_stream_->requested_bitrate;
759 775
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 ASSERT_GT(output_buffer_size_, 0UL); 846 ASSERT_GT(output_buffer_size_, 0UL);
831 847
832 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { 848 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) {
833 base::SharedMemory* shm = new base::SharedMemory(); 849 base::SharedMemory* shm = new base::SharedMemory();
834 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); 850 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_));
835 output_shms_.push_back(shm); 851 output_shms_.push_back(shm);
836 FeedEncoderWithOutput(shm); 852 FeedEncoderWithOutput(shm);
837 } 853 }
838 854
839 encode_start_time_ = base::TimeTicks::Now(); 855 encode_start_time_ = base::TimeTicks::Now();
840 FeedEncoderWithInputs(); 856 if (run_at_fps_) {
857 input_timer_.reset(new base::RepeatingTimer<VEAClient>());
858 input_timer_->Start(
859 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_,
860 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this)));
861 } else {
862 while (inputs_at_client_.size() <
863 num_required_input_buffers_ + kNumExtraInputFrames)
864 FeedEncoderWithOneInput();
865 }
841 } 866 }
842 867
843 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, 868 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id,
844 size_t payload_size, 869 size_t payload_size,
845 bool key_frame) { 870 bool key_frame) {
846 DCHECK(thread_checker_.CalledOnValidThread()); 871 DCHECK(thread_checker_.CalledOnValidThread());
847 ASSERT_LE(payload_size, output_buffer_size_); 872 ASSERT_LE(payload_size, output_buffer_size_);
848 873
849 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); 874 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id);
850 ASSERT_NE(it, output_buffers_at_client_.end()); 875 ASSERT_NE(it, output_buffers_at_client_.end());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, 922 encoder_->RequestEncodingParametersChange(current_requested_bitrate_,
898 current_framerate_); 923 current_framerate_);
899 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ 924 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_
900 << " bps @ " << current_framerate_ << " FPS"; 925 << " bps @ " << current_framerate_ << " FPS";
901 } 926 }
902 927
903 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { 928 void VEAClient::InputNoLongerNeededCallback(int32 input_id) {
904 std::set<int32>::iterator it = inputs_at_client_.find(input_id); 929 std::set<int32>::iterator it = inputs_at_client_.find(input_id);
905 ASSERT_NE(it, inputs_at_client_.end()); 930 ASSERT_NE(it, inputs_at_client_.end());
906 inputs_at_client_.erase(it); 931 inputs_at_client_.erase(it);
907 FeedEncoderWithInputs(); 932 if (!run_at_fps_)
933 FeedEncoderWithOneInput();
908 } 934 }
909 935
910 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { 936 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) {
911 CHECK_LE(position + test_stream_->aligned_buffer_size, 937 CHECK_LE(position + test_stream_->aligned_buffer_size,
912 test_stream_->mapped_aligned_in_file.length()); 938 test_stream_->mapped_aligned_in_file.length());
913 939
914 uint8* frame_data_y = const_cast<uint8*>( 940 uint8* frame_data_y = const_cast<uint8*>(
915 test_stream_->mapped_aligned_in_file.data() + position); 941 test_stream_->mapped_aligned_in_file.data() + position);
916 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; 942 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0];
917 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1]; 943 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1];
(...skipping 18 matching lines...) Expand all
936 base::Bind(&VEAClient::InputNoLongerNeededCallback, 962 base::Bind(&VEAClient::InputNoLongerNeededCallback,
937 base::Unretained(this), 963 base::Unretained(this),
938 next_input_id_))); 964 next_input_id_)));
939 965
940 CHECK(inputs_at_client_.insert(next_input_id_).second); 966 CHECK(inputs_at_client_.insert(next_input_id_).second);
941 ++next_input_id_; 967 ++next_input_id_;
942 968
943 return frame; 969 return frame;
944 } 970 }
945 971
946 void VEAClient::FeedEncoderWithInputs() { 972 void VEAClient::OnInputTimer() {
947 if (!has_encoder()) 973 if (!has_encoder() || state_ != CS_ENCODING)
974 input_timer_.reset();
975 else if (inputs_at_client_.size() <
976 num_required_input_buffers_ + kNumExtraInputFrames)
977 FeedEncoderWithOneInput();
978 else
979 DVLOG(1) << "Dropping input frame";
980 }
981
982 void VEAClient::FeedEncoderWithOneInput() {
983 if (!has_encoder() || state_ != CS_ENCODING)
948 return; 984 return;
949 985
950 if (state_ != CS_ENCODING) 986 size_t bytes_left =
951 return; 987 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_;
988 if (bytes_left < test_stream_->aligned_buffer_size) {
989 DCHECK_EQ(bytes_left, 0UL);
990 // Rewind if at the end of stream and we are still encoding.
991 // This is to flush the encoder with additional frames from the beginning
992 // of the stream, or if the stream is shorter that the number of frames
993 // we require for bitrate tests.
994 pos_in_input_stream_ = 0;
995 }
952 996
953 while (inputs_at_client_.size() < 997 bool force_keyframe = false;
954 num_required_input_buffers_ + kNumExtraInputFrames) { 998 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) {
955 size_t bytes_left = 999 keyframe_requested_at_ = next_input_id_;
956 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; 1000 force_keyframe = true;
957 if (bytes_left < test_stream_->aligned_buffer_size) { 1001 }
958 DCHECK_EQ(bytes_left, 0UL);
959 // Rewind if at the end of stream and we are still encoding.
960 // This is to flush the encoder with additional frames from the beginning
961 // of the stream, or if the stream is shorter that the number of frames
962 // we require for bitrate tests.
963 pos_in_input_stream_ = 0;
964 continue;
965 }
966 1002
967 bool force_keyframe = false; 1003 scoped_refptr<media::VideoFrame> video_frame =
968 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { 1004 PrepareInputFrame(pos_in_input_stream_);
969 keyframe_requested_at_ = next_input_id_; 1005 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
970 force_keyframe = true;
971 }
972 1006
973 scoped_refptr<media::VideoFrame> video_frame = 1007 encoder_->Encode(video_frame, force_keyframe);
974 PrepareInputFrame(pos_in_input_stream_);
975 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
976
977 encoder_->Encode(video_frame, force_keyframe);
978 }
979 } 1008 }
980 1009
981 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { 1010 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) {
982 if (!has_encoder()) 1011 if (!has_encoder())
983 return; 1012 return;
984 1013
985 if (state_ != CS_ENCODING) 1014 if (state_ != CS_ENCODING)
986 return; 1015 return;
987 1016
988 base::SharedMemoryHandle dup_handle; 1017 base::SharedMemoryHandle dup_handle;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 // kMaxKeyframeDelay frames after the frame, for which we requested 1051 // kMaxKeyframeDelay frames after the frame, for which we requested
1023 // it, comes back encoded. 1052 // it, comes back encoded.
1024 EXPECT_LE(num_encoded_frames_, keyframe_requested_at_ + kMaxKeyframeDelay); 1053 EXPECT_LE(num_encoded_frames_, keyframe_requested_at_ + kMaxKeyframeDelay);
1025 1054
1026 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { 1055 if (num_encoded_frames_ == num_frames_to_encode_ / 2) {
1027 VerifyStreamProperties(); 1056 VerifyStreamProperties();
1028 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || 1057 if (requested_subsequent_bitrate_ != current_requested_bitrate_ ||
1029 requested_subsequent_framerate_ != current_framerate_) { 1058 requested_subsequent_framerate_ != current_framerate_) {
1030 SetStreamParameters(requested_subsequent_bitrate_, 1059 SetStreamParameters(requested_subsequent_bitrate_,
1031 requested_subsequent_framerate_); 1060 requested_subsequent_framerate_);
1061 if (run_at_fps_ && input_timer_)
1062 input_timer_->Start(
1063 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_,
1064 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this)));
1032 } 1065 }
1033 } else if (num_encoded_frames_ == num_frames_to_encode_) { 1066 } else if (num_encoded_frames_ == num_frames_to_encode_) {
1034 VerifyPerf(); 1067 VerifyPerf();
1035 VerifyStreamProperties(); 1068 VerifyStreamProperties();
1036 SetState(CS_FINISHED); 1069 SetState(CS_FINISHED);
1037 return false; 1070 return false;
1038 } 1071 }
1039 1072
1040 return true; 1073 return true;
1041 } 1074 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 EXPECT_TRUE(base::AppendToFile( 1133 EXPECT_TRUE(base::AppendToFile(
1101 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), 1134 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename),
1102 reinterpret_cast<char*>(&header), sizeof(header))); 1135 reinterpret_cast<char*>(&header), sizeof(header)));
1103 } 1136 }
1104 1137
1105 // Setup test stream data and delete temporary aligned files at the beginning 1138 // Setup test stream data and delete temporary aligned files at the beginning
1106 // and end of unittest. We only need to setup once for all test cases. 1139 // and end of unittest. We only need to setup once for all test cases.
1107 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { 1140 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment {
1108 public: 1141 public:
1109 VideoEncodeAcceleratorTestEnvironment( 1142 VideoEncodeAcceleratorTestEnvironment(
1110 scoped_ptr<base::FilePath::StringType> data) { 1143 scoped_ptr<base::FilePath::StringType> data,
1144 bool run_at_fps) {
1111 test_stream_data_ = data.Pass(); 1145 test_stream_data_ = data.Pass();
1146 run_at_fps_ = run_at_fps;
1112 } 1147 }
1113 1148
1114 virtual void SetUp() { 1149 virtual void SetUp() {
1115 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); 1150 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_);
1116 } 1151 }
1117 1152
1118 virtual void TearDown() { 1153 virtual void TearDown() {
1119 for (size_t i = 0; i < test_streams_.size(); i++) { 1154 for (size_t i = 0; i < test_streams_.size(); i++) {
1120 base::DeleteFile(test_streams_[i]->aligned_in_file, false); 1155 base::DeleteFile(test_streams_[i]->aligned_in_file, false);
1121 } 1156 }
1122 } 1157 }
1123 1158
1124 ScopedVector<TestStream> test_streams_; 1159 ScopedVector<TestStream> test_streams_;
1160 bool run_at_fps_;
1125 1161
1126 private: 1162 private:
1127 scoped_ptr<base::FilePath::StringType> test_stream_data_; 1163 scoped_ptr<base::FilePath::StringType> test_stream_data_;
1128 }; 1164 };
1129 1165
1130 // Test parameters: 1166 // Test parameters:
1131 // - Number of concurrent encoders. The value takes effect when there is only 1167 // - Number of concurrent encoders. The value takes effect when there is only
1132 // one input stream; otherwise, one encoder per input stream will be 1168 // one input stream; otherwise, one encoder per input stream will be
1133 // instantiated. 1169 // instantiated.
1134 // - If true, save output to file (provided an output filename was supplied). 1170 // - If true, save output to file (provided an output filename was supplied).
(...skipping 26 matching lines...) Expand all
1161 1197
1162 // Create all encoders. 1198 // Create all encoders.
1163 for (size_t i = 0; i < num_concurrent_encoders; i++) { 1199 for (size_t i = 0; i < num_concurrent_encoders; i++) {
1164 size_t test_stream_index = i % g_env->test_streams_.size(); 1200 size_t test_stream_index = i % g_env->test_streams_.size();
1165 // Disregard save_to_file if we didn't get an output filename. 1201 // Disregard save_to_file if we didn't get an output filename.
1166 bool encoder_save_to_file = 1202 bool encoder_save_to_file =
1167 (save_to_file && 1203 (save_to_file &&
1168 !g_env->test_streams_[test_stream_index]->out_filename.empty()); 1204 !g_env->test_streams_[test_stream_index]->out_filename.empty());
1169 1205
1170 notes.push_back(new ClientStateNotification<ClientState>()); 1206 notes.push_back(new ClientStateNotification<ClientState>());
1171 clients.push_back(new VEAClient(g_env->test_streams_[test_stream_index], 1207 clients.push_back(
1172 notes.back(), 1208 new VEAClient(g_env->test_streams_[test_stream_index], notes.back(),
1173 encoder_save_to_file, 1209 encoder_save_to_file, keyframe_period, force_bitrate,
1174 keyframe_period, 1210 test_perf, mid_stream_bitrate_switch,
1175 force_bitrate, 1211 mid_stream_framerate_switch, g_env->run_at_fps_));
1176 test_perf,
1177 mid_stream_bitrate_switch,
1178 mid_stream_framerate_switch));
1179 1212
1180 encoder_thread.message_loop()->PostTask( 1213 encoder_thread.message_loop()->PostTask(
1181 FROM_HERE, 1214 FROM_HERE,
1182 base::Bind(&VEAClient::CreateEncoder, 1215 base::Bind(&VEAClient::CreateEncoder,
1183 base::Unretained(clients.back()))); 1216 base::Unretained(clients.back())));
1184 } 1217 }
1185 1218
1186 // All encoders must pass through states in this order. 1219 // All encoders must pass through states in this order.
1187 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, 1220 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED,
1188 CS_ENCODING, CS_FINISHED}; 1221 CS_ENCODING, CS_FINISHED};
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 content::g_default_in_parameters)); 1298 content::g_default_in_parameters));
1266 1299
1267 // Needed to enable DVLOG through --vmodule. 1300 // Needed to enable DVLOG through --vmodule.
1268 logging::LoggingSettings settings; 1301 logging::LoggingSettings settings;
1269 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 1302 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
1270 CHECK(logging::InitLogging(settings)); 1303 CHECK(logging::InitLogging(settings));
1271 1304
1272 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 1305 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
1273 DCHECK(cmd_line); 1306 DCHECK(cmd_line);
1274 1307
1308 bool run_at_fps = false;
1275 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); 1309 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
1276 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); 1310 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
1277 it != switches.end(); 1311 it != switches.end();
1278 ++it) { 1312 ++it) {
1279 if (it->first == "test_stream_data") { 1313 if (it->first == "test_stream_data") {
1280 test_stream_data->assign(it->second.c_str()); 1314 test_stream_data->assign(it->second.c_str());
1281 continue; 1315 continue;
1282 } 1316 }
1283 if (it->first == "num_frames_to_encode") { 1317 if (it->first == "num_frames_to_encode") {
1284 std::string input(it->second.begin(), it->second.end()); 1318 std::string input(it->second.begin(), it->second.end());
1285 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); 1319 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode));
1286 continue; 1320 continue;
1287 } 1321 }
1322 if (it->first == "run_at_fps") {
1323 run_at_fps = true;
1324 continue;
1325 }
1288 if (it->first == "v" || it->first == "vmodule") 1326 if (it->first == "v" || it->first == "vmodule")
1289 continue; 1327 continue;
1290 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; 1328 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
1291 } 1329 }
1292 1330
1293 content::g_env = 1331 content::g_env =
1294 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( 1332 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>(
1295 testing::AddGlobalTestEnvironment( 1333 testing::AddGlobalTestEnvironment(
1296 new content::VideoEncodeAcceleratorTestEnvironment( 1334 new content::VideoEncodeAcceleratorTestEnvironment(
1297 test_stream_data.Pass()))); 1335 test_stream_data.Pass(), run_at_fps)));
1298 1336
1299 return RUN_ALL_TESTS(); 1337 return RUN_ALL_TESTS();
1300 } 1338 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698