Chromium Code Reviews| 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 // then it asked for via RequireBitstreamBuffers(). Return false if no input |
|
wuchengli
2014/12/10 07:06:56
s/then/than/
Owen Lin
2014/12/11 03:53:48
Done.
| |
| 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 if (input_duration_ == base::TimeDelta()) |
| 884 while (FeedEncoderWithOneInput()) | |
|
wuchengli
2014/12/10 07:06:56
One one input buffer is released by line 882. So w
Owen Lin
2014/12/11 03:53:48
Done.
| |
| 885 ; | |
| 860 } | 886 } |
| 861 | 887 |
| 862 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { | 888 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { |
| 863 CHECK_LE(position + test_stream_->aligned_buffer_size, | 889 CHECK_LE(position + test_stream_->aligned_buffer_size, |
| 864 test_stream_->mapped_aligned_in_file.length()); | 890 test_stream_->mapped_aligned_in_file.length()); |
| 865 | 891 |
| 866 uint8* frame_data_y = const_cast<uint8*>( | 892 uint8* frame_data_y = const_cast<uint8*>( |
| 867 test_stream_->mapped_aligned_in_file.data() + position); | 893 test_stream_->mapped_aligned_in_file.data() + position); |
| 868 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; | 894 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]; | 895 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, | 914 base::Bind(&VEAClient::InputNoLongerNeededCallback, |
| 889 base::Unretained(this), | 915 base::Unretained(this), |
| 890 next_input_id_))); | 916 next_input_id_))); |
| 891 | 917 |
| 892 CHECK(inputs_at_client_.insert(next_input_id_).second); | 918 CHECK(inputs_at_client_.insert(next_input_id_).second); |
| 893 ++next_input_id_; | 919 ++next_input_id_; |
| 894 | 920 |
| 895 return frame; | 921 return frame; |
| 896 } | 922 } |
| 897 | 923 |
| 898 void VEAClient::FeedEncoderWithInputs() { | 924 bool VEAClient::FeedEncoderWithOneInput() { |
| 899 if (!has_encoder()) | 925 if (!has_encoder() || state_ != CS_ENCODING) { |
| 900 return; | 926 // Destructor will also stop the timer. |
| 927 input_timer_.reset(); | |
|
wuchengli
2014/12/10 07:06:56
Do we really need this here? No other clean-up is
Owen Lin
2014/12/11 03:53:48
Yes, it can be removed. But I prefer not.
This is
| |
| 928 return false; | |
| 929 } | |
| 901 | 930 |
| 902 if (state_ != CS_ENCODING) | 931 size_t bytes_left = |
| 903 return; | 932 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; |
| 933 if (bytes_left < test_stream_->aligned_buffer_size) { | |
| 934 DCHECK_EQ(bytes_left, 0UL); | |
| 935 // Rewind if at the end of stream and we are still encoding. | |
| 936 // This is to flush the encoder with additional frames from the beginning | |
| 937 // of the stream, or if the stream is shorter that the number of frames | |
| 938 // we require for bitrate tests. | |
| 939 pos_in_input_stream_ = 0; | |
| 940 } | |
| 904 | 941 |
| 905 while (inputs_at_client_.size() < | 942 if (inputs_at_client_.size() >= |
| 906 num_required_input_buffers_ + kNumExtraInputFrames) { | 943 num_required_input_buffers_ + kNumExtraInputFrames) { |
| 907 size_t bytes_left = | 944 DVLOG(1) << "Drop Input Frame: " + pos_in_input_stream_; |
|
wuchengli
2014/12/10 07:06:56
s/Input Frame/input frame/
Owen Lin
2014/12/11 03:53:48
Done.
| |
| 908 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; | 945 pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
| 909 if (bytes_left < test_stream_->aligned_buffer_size) { | 946 return false; |
| 910 DCHECK_EQ(bytes_left, 0UL); | 947 } |
| 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 | 948 |
| 919 bool force_keyframe = false; | 949 bool force_keyframe = false; |
| 920 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { | 950 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { |
| 921 keyframe_requested_at_ = next_input_id_; | 951 keyframe_requested_at_ = next_input_id_; |
| 922 force_keyframe = true; | 952 force_keyframe = true; |
| 923 } | 953 } |
| 924 | 954 |
| 925 scoped_refptr<media::VideoFrame> video_frame = | 955 scoped_refptr<media::VideoFrame> video_frame = |
| 926 PrepareInputFrame(pos_in_input_stream_); | 956 PrepareInputFrame(pos_in_input_stream_); |
| 927 pos_in_input_stream_ += test_stream_->aligned_buffer_size; | 957 pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
| 928 | 958 |
| 929 encoder_->Encode(video_frame, force_keyframe); | 959 encoder_->Encode(video_frame, force_keyframe); |
| 930 } | 960 return true; |
| 931 } | 961 } |
| 932 | 962 |
| 933 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { | 963 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { |
| 934 if (!has_encoder()) | 964 if (!has_encoder()) |
| 935 return; | 965 return; |
| 936 | 966 |
| 937 if (state_ != CS_ENCODING) | 967 if (state_ != CS_ENCODING) |
| 938 return; | 968 return; |
| 939 | 969 |
| 940 base::SharedMemoryHandle dup_handle; | 970 base::SharedMemoryHandle dup_handle; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1017 current_requested_bitrate_, | 1047 current_requested_bitrate_, |
| 1018 kBitrateTolerance * current_requested_bitrate_); | 1048 kBitrateTolerance * current_requested_bitrate_); |
| 1019 } | 1049 } |
| 1020 } | 1050 } |
| 1021 | 1051 |
| 1022 // Setup test stream data and delete temporary aligned files at the beginning | 1052 // 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. | 1053 // and end of unittest. We only need to setup once for all test cases. |
| 1024 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { | 1054 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { |
| 1025 public: | 1055 public: |
| 1026 VideoEncodeAcceleratorTestEnvironment( | 1056 VideoEncodeAcceleratorTestEnvironment( |
| 1027 scoped_ptr<base::FilePath::StringType> data) { | 1057 scoped_ptr<base::FilePath::StringType> data, |
| 1058 double input_fps) { | |
| 1028 test_stream_data_ = data.Pass(); | 1059 test_stream_data_ = data.Pass(); |
| 1060 input_fps_ = input_fps; | |
| 1029 } | 1061 } |
| 1030 | 1062 |
| 1031 virtual void SetUp() { | 1063 virtual void SetUp() { |
| 1032 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); | 1064 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); |
| 1033 } | 1065 } |
| 1034 | 1066 |
| 1035 virtual void TearDown() { | 1067 virtual void TearDown() { |
| 1036 for (size_t i = 0; i < test_streams_.size(); i++) { | 1068 for (size_t i = 0; i < test_streams_.size(); i++) { |
| 1037 base::DeleteFile(test_streams_[i]->aligned_in_file, false); | 1069 base::DeleteFile(test_streams_[i]->aligned_in_file, false); |
| 1038 } | 1070 } |
| 1039 } | 1071 } |
| 1040 | 1072 |
| 1041 ScopedVector<TestStream> test_streams_; | 1073 ScopedVector<TestStream> test_streams_; |
| 1042 | 1074 |
| 1075 // The input frame rate to the encoder. | |
| 1076 double input_fps_; | |
| 1077 | |
| 1043 private: | 1078 private: |
| 1044 scoped_ptr<base::FilePath::StringType> test_stream_data_; | 1079 scoped_ptr<base::FilePath::StringType> test_stream_data_; |
| 1045 }; | 1080 }; |
| 1046 | 1081 |
| 1047 // Test parameters: | 1082 // Test parameters: |
| 1048 // - Number of concurrent encoders. | 1083 // - Number of concurrent encoders. |
| 1049 // - If true, save output to file (provided an output filename was supplied). | 1084 // - If true, save output to file (provided an output filename was supplied). |
| 1050 // - Force a keyframe every n frames. | 1085 // - Force a keyframe every n frames. |
| 1051 // - Force bitrate; the actual required value is provided as a property | 1086 // - Force bitrate; the actual required value is provided as a property |
| 1052 // of the input stream, because it depends on stream type/resolution/etc. | 1087 // of the input stream, because it depends on stream type/resolution/etc. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1073 | 1108 |
| 1074 // Create all encoders. | 1109 // Create all encoders. |
| 1075 for (size_t i = 0; i < num_concurrent_encoders; i++) { | 1110 for (size_t i = 0; i < num_concurrent_encoders; i++) { |
| 1076 size_t test_stream_index = i % g_env->test_streams_.size(); | 1111 size_t test_stream_index = i % g_env->test_streams_.size(); |
| 1077 // Disregard save_to_file if we didn't get an output filename. | 1112 // Disregard save_to_file if we didn't get an output filename. |
| 1078 bool encoder_save_to_file = | 1113 bool encoder_save_to_file = |
| 1079 (save_to_file && | 1114 (save_to_file && |
| 1080 !g_env->test_streams_[test_stream_index]->out_filename.empty()); | 1115 !g_env->test_streams_[test_stream_index]->out_filename.empty()); |
| 1081 | 1116 |
| 1082 notes.push_back(new ClientStateNotification<ClientState>()); | 1117 notes.push_back(new ClientStateNotification<ClientState>()); |
| 1083 clients.push_back(new VEAClient(g_env->test_streams_[test_stream_index], | 1118 clients.push_back(new VEAClient( |
| 1084 notes.back(), | 1119 g_env->test_streams_[test_stream_index], g_env->input_fps_, |
| 1085 encoder_save_to_file, | 1120 notes.back(), encoder_save_to_file, keyframe_period, force_bitrate, |
| 1086 keyframe_period, | 1121 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 | 1122 |
| 1092 encoder_thread.message_loop()->PostTask( | 1123 encoder_thread.message_loop()->PostTask( |
| 1093 FROM_HERE, | 1124 FROM_HERE, |
| 1094 base::Bind(&VEAClient::CreateEncoder, | 1125 base::Bind(&VEAClient::CreateEncoder, |
| 1095 base::Unretained(clients.back()))); | 1126 base::Unretained(clients.back()))); |
| 1096 } | 1127 } |
| 1097 | 1128 |
| 1098 // All encoders must pass through states in this order. | 1129 // All encoders must pass through states in this order. |
| 1099 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, | 1130 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, |
| 1100 CS_ENCODING, CS_FINISHED}; | 1131 CS_ENCODING, CS_FINISHED}; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 content::g_default_in_parameters)); | 1208 content::g_default_in_parameters)); |
| 1178 | 1209 |
| 1179 // Needed to enable DVLOG through --vmodule. | 1210 // Needed to enable DVLOG through --vmodule. |
| 1180 logging::LoggingSettings settings; | 1211 logging::LoggingSettings settings; |
| 1181 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 1212 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 1182 CHECK(logging::InitLogging(settings)); | 1213 CHECK(logging::InitLogging(settings)); |
| 1183 | 1214 |
| 1184 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 1215 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 1185 DCHECK(cmd_line); | 1216 DCHECK(cmd_line); |
| 1186 | 1217 |
| 1218 double input_fps = 0; | |
| 1187 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | 1219 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
| 1188 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1220 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
| 1189 it != switches.end(); | 1221 it != switches.end(); |
| 1190 ++it) { | 1222 ++it) { |
| 1191 if (it->first == "test_stream_data") { | 1223 if (it->first == "test_stream_data") { |
| 1192 test_stream_data->assign(it->second.c_str()); | 1224 test_stream_data->assign(it->second.c_str()); |
| 1193 continue; | 1225 continue; |
| 1194 } | 1226 } |
| 1227 if (it->first == "input_fps") { | |
| 1228 // On Windows, CommandLine::StringType is wstring. We need to convert | |
| 1229 // it to std::string first | |
| 1230 std::string input(it->second.begin(), it->second.end()); | |
| 1231 CHECK(base::StringToDouble(input, &input_fps)); | |
| 1232 continue; | |
| 1233 } | |
| 1195 if (it->first == "v" || it->first == "vmodule") | 1234 if (it->first == "v" || it->first == "vmodule") |
| 1196 continue; | 1235 continue; |
| 1197 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1236 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
| 1198 } | 1237 } |
| 1199 | 1238 |
| 1200 content::g_env = | 1239 content::g_env = |
| 1201 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1240 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
| 1202 testing::AddGlobalTestEnvironment( | 1241 testing::AddGlobalTestEnvironment( |
| 1203 new content::VideoEncodeAcceleratorTestEnvironment( | 1242 new content::VideoEncodeAcceleratorTestEnvironment( |
| 1204 test_stream_data.Pass()))); | 1243 test_stream_data.Pass(), input_fps))); |
| 1205 | 1244 |
| 1206 return RUN_ALL_TESTS(); | 1245 return RUN_ALL_TESTS(); |
| 1207 } | 1246 } |
| OLD | NEW |