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