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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, |
| 466 ClientStateNotification<ClientState>* note, | 467 ClientStateNotification<ClientState>* note, |
| 467 bool save_to_file, | 468 bool save_to_file, |
| 468 unsigned int keyframe_period, | 469 unsigned int keyframe_period, |
| 469 bool force_bitrate, | 470 bool force_bitrate, |
| 470 bool test_perf, | 471 bool test_perf, |
| 471 bool mid_stream_bitrate_switch, | 472 bool mid_stream_bitrate_switch, |
| 472 bool mid_stream_framerate_switch); | 473 bool mid_stream_framerate_switch, |
| 474 bool real_time_clock); | |
| 473 virtual ~VEAClient(); | 475 virtual ~VEAClient(); |
| 474 void CreateEncoder(); | 476 void CreateEncoder(); |
| 475 void DestroyEncoder(); | 477 void DestroyEncoder(); |
| 476 | 478 |
| 477 // Return the number of encoded frames per second. | 479 // Return the number of encoded frames per second. |
| 478 double frames_per_second(); | 480 double frames_per_second(); |
| 479 | 481 |
| 480 // VideoDecodeAccelerator::Client implementation. | 482 // VideoDecodeAccelerator::Client implementation. |
| 481 virtual void RequireBitstreamBuffers(unsigned int input_count, | 483 virtual void RequireBitstreamBuffers(unsigned int input_count, |
| 482 const gfx::Size& input_coded_size, | 484 const gfx::Size& input_coded_size, |
| 483 size_t output_buffer_size) override; | 485 size_t output_buffer_size) override; |
| 484 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, | 486 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, |
| 485 size_t payload_size, | 487 size_t payload_size, |
| 486 bool key_frame) override; | 488 bool key_frame) override; |
| 487 virtual void NotifyError(VideoEncodeAccelerator::Error error) override; | 489 virtual void NotifyError(VideoEncodeAccelerator::Error error) override; |
| 488 | 490 |
| 489 private: | 491 private: |
| 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. |
| 501 // via RequireBitstreamBuffers(). | 503 void FeedEncoderWithOneInput(); |
| 502 void FeedEncoderWithInputs(); | |
| 503 | 504 |
| 504 // Provide the encoder with a new output buffer. | 505 // Provide the encoder with a new output buffer. |
| 505 void FeedEncoderWithOutput(base::SharedMemory* shm); | 506 void FeedEncoderWithOutput(base::SharedMemory* shm); |
| 506 | 507 |
| 507 // Called on finding a complete frame (with |keyframe| set to true for | 508 // Called on finding a complete frame (with |keyframe| set to true for |
| 508 // keyframes) in the stream, to perform codec-independent, per-frame checks | 509 // keyframes) in the stream, to perform codec-independent, per-frame checks |
| 509 // and accounting. Returns false once we have collected all frames we needed. | 510 // and accounting. Returns false once we have collected all frames we needed. |
| 510 bool HandleEncodedFrame(bool keyframe); | 511 bool HandleEncodedFrame(bool keyframe); |
| 511 | 512 |
| 512 // Verify that stream bitrate has been close to current_requested_bitrate_, | 513 // Verify that stream bitrate has been close to current_requested_bitrate_, |
| 513 // assuming current_framerate_ since the last time VerifyStreamProperties() | 514 // assuming current_framerate_ since the last time VerifyStreamProperties() |
| 514 // was called. Fail the test if |force_bitrate_| is true and the bitrate | 515 // was called. Fail the test if |force_bitrate_| is true and the bitrate |
| 515 // is not within kBitrateTolerance. | 516 // is not within kBitrateTolerance. |
| 516 void VerifyStreamProperties(); | 517 void VerifyStreamProperties(); |
| 517 | 518 |
| 518 // Test codec performance, failing the test if we are currently running | 519 // Test codec performance, failing the test if we are currently running |
| 519 // the performance test. | 520 // the performance test. |
| 520 void VerifyPerf(); | 521 void VerifyPerf(); |
| 521 | 522 |
| 522 // Prepare and return a frame wrapping the data at |position| bytes in | 523 // Prepare and return a frame wrapping the data at |position| bytes in |
| 523 // the input stream, ready to be sent to encoder. | 524 // the input stream, ready to be sent to encoder. |
| 524 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position); | 525 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position); |
| 525 | 526 |
| 526 // Update the parameters according to |mid_stream_bitrate_switch| and | 527 // Update the parameters according to |mid_stream_bitrate_switch| and |
| 527 // |mid_stream_framerate_switch|. | 528 // |mid_stream_framerate_switch|. |
| 528 void UpdateTestStreamData(bool mid_stream_bitrate_switch, | 529 void UpdateTestStreamData(bool mid_stream_bitrate_switch, |
| 529 bool mid_stream_framerate_switch); | 530 bool mid_stream_framerate_switch); |
| 530 | 531 |
| 532 // Callback function of the |input_timer_|. | |
| 533 void OnInputTimer(); | |
| 534 | |
| 531 ClientState state_; | 535 ClientState state_; |
| 532 scoped_ptr<VideoEncodeAccelerator> encoder_; | 536 scoped_ptr<VideoEncodeAccelerator> encoder_; |
| 533 | 537 |
| 534 TestStream* test_stream_; | 538 TestStream* test_stream_; |
| 539 | |
| 535 // Used to notify another thread about the state. VEAClient does not own this. | 540 // Used to notify another thread about the state. VEAClient does not own this. |
| 536 ClientStateNotification<ClientState>* note_; | 541 ClientStateNotification<ClientState>* note_; |
| 537 | 542 |
| 538 // Ids assigned to VideoFrames (start at 1 for easy comparison with | 543 // Ids assigned to VideoFrames (start at 1 for easy comparison with |
| 539 // num_encoded_frames_). | 544 // num_encoded_frames_). |
| 540 std::set<int32> inputs_at_client_; | 545 std::set<int32> inputs_at_client_; |
| 541 int32 next_input_id_; | 546 int32 next_input_id_; |
| 542 | 547 |
| 543 // Ids for output BitstreamBuffers. | 548 // Ids for output BitstreamBuffers. |
| 544 typedef std::map<int32, base::SharedMemory*> IdToSHM; | 549 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_; | 611 unsigned int requested_bitrate_; |
| 607 | 612 |
| 608 // Requested initial framerate. | 613 // Requested initial framerate. |
| 609 unsigned int requested_framerate_; | 614 unsigned int requested_framerate_; |
| 610 | 615 |
| 611 // Bitrate to switch to in the middle of the stream. | 616 // Bitrate to switch to in the middle of the stream. |
| 612 unsigned int requested_subsequent_bitrate_; | 617 unsigned int requested_subsequent_bitrate_; |
| 613 | 618 |
| 614 // Framerate to switch to in the middle of the stream. | 619 // Framerate to switch to in the middle of the stream. |
| 615 unsigned int requested_subsequent_framerate_; | 620 unsigned int requested_subsequent_framerate_; |
| 621 | |
| 622 // The timer used to feed the encoder with the input frames. | |
| 623 scoped_ptr<base::RepeatingTimer<VEAClient>> input_timer_; | |
| 624 | |
| 625 // Feed the encoder with the input buffers at the |requested_framerate_|. If | |
| 626 // false, feed as fast as possible. This is set by the command line switch | |
| 627 // "--real_time_clock". | |
| 628 bool real_time_clock_; | |
| 616 }; | 629 }; |
| 617 | 630 |
| 618 VEAClient::VEAClient(TestStream* test_stream, | 631 VEAClient::VEAClient(TestStream* test_stream, |
| 619 ClientStateNotification<ClientState>* note, | 632 ClientStateNotification<ClientState>* note, |
| 620 bool save_to_file, | 633 bool save_to_file, |
| 621 unsigned int keyframe_period, | 634 unsigned int keyframe_period, |
| 622 bool force_bitrate, | 635 bool force_bitrate, |
| 623 bool test_perf, | 636 bool test_perf, |
| 624 bool mid_stream_bitrate_switch, | 637 bool mid_stream_bitrate_switch, |
| 625 bool mid_stream_framerate_switch) | 638 bool mid_stream_framerate_switch, |
| 639 bool real_time_clock) | |
| 626 : state_(CS_CREATED), | 640 : state_(CS_CREATED), |
| 627 test_stream_(test_stream), | 641 test_stream_(test_stream), |
| 628 note_(note), | 642 note_(note), |
| 629 next_input_id_(1), | 643 next_input_id_(1), |
| 630 next_output_buffer_id_(0), | 644 next_output_buffer_id_(0), |
| 631 pos_in_input_stream_(0), | 645 pos_in_input_stream_(0), |
| 632 num_required_input_buffers_(0), | 646 num_required_input_buffers_(0), |
| 633 output_buffer_size_(0), | 647 output_buffer_size_(0), |
| 634 num_frames_to_encode_(0), | 648 num_frames_to_encode_(0), |
| 635 num_encoded_frames_(0), | 649 num_encoded_frames_(0), |
| 636 num_frames_since_last_check_(0), | 650 num_frames_since_last_check_(0), |
| 637 seen_keyframe_in_this_buffer_(false), | 651 seen_keyframe_in_this_buffer_(false), |
| 638 save_to_file_(save_to_file), | 652 save_to_file_(save_to_file), |
| 639 keyframe_period_(keyframe_period), | 653 keyframe_period_(keyframe_period), |
| 640 keyframe_requested_at_(kMaxFrameNum), | 654 keyframe_requested_at_(kMaxFrameNum), |
| 641 force_bitrate_(force_bitrate), | 655 force_bitrate_(force_bitrate), |
| 642 current_requested_bitrate_(0), | 656 current_requested_bitrate_(0), |
| 643 current_framerate_(0), | 657 current_framerate_(0), |
| 644 encoded_stream_size_since_last_check_(0), | 658 encoded_stream_size_since_last_check_(0), |
| 645 test_perf_(test_perf), | 659 test_perf_(test_perf), |
| 646 requested_bitrate_(0), | 660 requested_bitrate_(0), |
| 647 requested_framerate_(0), | 661 requested_framerate_(0), |
| 648 requested_subsequent_bitrate_(0), | 662 requested_subsequent_bitrate_(0), |
| 649 requested_subsequent_framerate_(0) { | 663 requested_subsequent_framerate_(0), |
| 664 real_time_clock_(real_time_clock) { | |
| 650 if (keyframe_period_) | 665 if (keyframe_period_) |
| 651 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); | 666 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); |
| 652 | 667 |
| 653 validator_ = StreamValidator::Create( | 668 validator_ = StreamValidator::Create( |
| 654 test_stream_->requested_profile, | 669 test_stream_->requested_profile, |
| 655 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 670 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
| 656 | 671 |
| 657 CHECK(validator_.get()); | 672 CHECK(validator_.get()); |
| 658 | 673 |
| 659 if (save_to_file_) { | 674 if (save_to_file_) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 | 714 |
| 700 SetStreamParameters(requested_bitrate_, requested_framerate_); | 715 SetStreamParameters(requested_bitrate_, requested_framerate_); |
| 701 SetState(CS_INITIALIZED); | 716 SetState(CS_INITIALIZED); |
| 702 } | 717 } |
| 703 | 718 |
| 704 void VEAClient::DestroyEncoder() { | 719 void VEAClient::DestroyEncoder() { |
| 705 DCHECK(thread_checker_.CalledOnValidThread()); | 720 DCHECK(thread_checker_.CalledOnValidThread()); |
| 706 if (!has_encoder()) | 721 if (!has_encoder()) |
| 707 return; | 722 return; |
| 708 encoder_.reset(); | 723 encoder_.reset(); |
| 724 input_timer_.reset(); | |
| 709 } | 725 } |
| 710 | 726 |
| 711 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, | 727 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, |
| 712 bool mid_stream_framerate_switch) { | 728 bool mid_stream_framerate_switch) { |
| 713 // Use defaults for bitrate/framerate if they are not provided. | 729 // Use defaults for bitrate/framerate if they are not provided. |
| 714 if (test_stream_->requested_bitrate == 0) | 730 if (test_stream_->requested_bitrate == 0) |
| 715 requested_bitrate_ = kDefaultBitrate; | 731 requested_bitrate_ = kDefaultBitrate; |
| 716 else | 732 else |
| 717 requested_bitrate_ = test_stream_->requested_bitrate; | 733 requested_bitrate_ = test_stream_->requested_bitrate; |
| 718 | 734 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 ASSERT_GT(output_buffer_size_, 0UL); | 801 ASSERT_GT(output_buffer_size_, 0UL); |
| 786 | 802 |
| 787 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { | 803 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { |
| 788 base::SharedMemory* shm = new base::SharedMemory(); | 804 base::SharedMemory* shm = new base::SharedMemory(); |
| 789 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); | 805 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); |
| 790 output_shms_.push_back(shm); | 806 output_shms_.push_back(shm); |
| 791 FeedEncoderWithOutput(shm); | 807 FeedEncoderWithOutput(shm); |
| 792 } | 808 } |
| 793 | 809 |
| 794 encode_start_time_ = base::TimeTicks::Now(); | 810 encode_start_time_ = base::TimeTicks::Now(); |
| 795 FeedEncoderWithInputs(); | 811 if (real_time_clock_) { |
| 812 input_timer_.reset(new base::RepeatingTimer<VEAClient>()); | |
| 813 input_timer_->Start( | |
| 814 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, | |
| 815 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); | |
| 816 } else { | |
| 817 while (inputs_at_client_.size() < | |
| 818 num_required_input_buffers_ + kNumExtraInputFrames) | |
| 819 FeedEncoderWithOneInput(); | |
| 820 } | |
| 796 } | 821 } |
| 797 | 822 |
| 798 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, | 823 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, |
| 799 size_t payload_size, | 824 size_t payload_size, |
| 800 bool key_frame) { | 825 bool key_frame) { |
| 801 DCHECK(thread_checker_.CalledOnValidThread()); | 826 DCHECK(thread_checker_.CalledOnValidThread()); |
| 802 ASSERT_LE(payload_size, output_buffer_size_); | 827 ASSERT_LE(payload_size, output_buffer_size_); |
| 803 | 828 |
| 804 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); | 829 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); |
| 805 ASSERT_NE(it, output_buffers_at_client_.end()); | 830 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_, | 874 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, |
| 850 current_framerate_); | 875 current_framerate_); |
| 851 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ | 876 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ |
| 852 << " bps @ " << current_framerate_ << " FPS"; | 877 << " bps @ " << current_framerate_ << " FPS"; |
| 853 } | 878 } |
| 854 | 879 |
| 855 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { | 880 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { |
| 856 std::set<int32>::iterator it = inputs_at_client_.find(input_id); | 881 std::set<int32>::iterator it = inputs_at_client_.find(input_id); |
| 857 ASSERT_NE(it, inputs_at_client_.end()); | 882 ASSERT_NE(it, inputs_at_client_.end()); |
| 858 inputs_at_client_.erase(it); | 883 inputs_at_client_.erase(it); |
| 859 FeedEncoderWithInputs(); | 884 if (!real_time_clock_) |
| 885 FeedEncoderWithOneInput(); | |
| 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 void VEAClient::OnInputTimer() { |
| 899 if (!has_encoder()) | 925 if (!has_encoder() || state_ != CS_ENCODING) |
| 926 input_timer_.reset(); | |
| 927 else if (inputs_at_client_.size() < | |
| 928 num_required_input_buffers_ + kNumExtraInputFrames) | |
| 929 FeedEncoderWithOneInput(); | |
| 930 else | |
| 931 DVLOG(1) << "Dropping input frame"; | |
| 932 } | |
| 933 | |
| 934 void VEAClient::FeedEncoderWithOneInput() { | |
| 935 if (!has_encoder() || state_ != CS_ENCODING) | |
| 900 return; | 936 return; |
| 901 | 937 |
| 902 if (state_ != CS_ENCODING) | 938 size_t bytes_left = |
| 903 return; | 939 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; |
| 940 if (bytes_left < test_stream_->aligned_buffer_size) { | |
| 941 DCHECK_EQ(bytes_left, 0UL); | |
| 942 // Rewind if at the end of stream and we are still encoding. | |
| 943 // This is to flush the encoder with additional frames from the beginning | |
| 944 // of the stream, or if the stream is shorter that the number of frames | |
| 945 // we require for bitrate tests. | |
| 946 pos_in_input_stream_ = 0; | |
| 947 } | |
| 904 | 948 |
| 905 while (inputs_at_client_.size() < | 949 bool force_keyframe = false; |
| 906 num_required_input_buffers_ + kNumExtraInputFrames) { | 950 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { |
| 907 size_t bytes_left = | 951 keyframe_requested_at_ = next_input_id_; |
| 908 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; | 952 force_keyframe = true; |
| 909 if (bytes_left < test_stream_->aligned_buffer_size) { | 953 } |
| 910 DCHECK_EQ(bytes_left, 0UL); | |
| 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 | 954 |
| 919 bool force_keyframe = false; | 955 scoped_refptr<media::VideoFrame> video_frame = |
| 920 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { | 956 PrepareInputFrame(pos_in_input_stream_); |
| 921 keyframe_requested_at_ = next_input_id_; | 957 pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
| 922 force_keyframe = true; | |
| 923 } | |
| 924 | 958 |
| 925 scoped_refptr<media::VideoFrame> video_frame = | 959 encoder_->Encode(video_frame, force_keyframe); |
| 926 PrepareInputFrame(pos_in_input_stream_); | |
| 927 pos_in_input_stream_ += test_stream_->aligned_buffer_size; | |
| 928 | |
| 929 encoder_->Encode(video_frame, force_keyframe); | |
| 930 } | |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 // kMaxKeyframeDelay frames after the frame, for which we requested | 1003 // kMaxKeyframeDelay frames after the frame, for which we requested |
| 975 // it, comes back encoded. | 1004 // it, comes back encoded. |
| 976 EXPECT_LE(num_encoded_frames_, keyframe_requested_at_ + kMaxKeyframeDelay); | 1005 EXPECT_LE(num_encoded_frames_, keyframe_requested_at_ + kMaxKeyframeDelay); |
| 977 | 1006 |
| 978 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { | 1007 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { |
| 979 VerifyStreamProperties(); | 1008 VerifyStreamProperties(); |
| 980 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || | 1009 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || |
| 981 requested_subsequent_framerate_ != current_framerate_) { | 1010 requested_subsequent_framerate_ != current_framerate_) { |
| 982 SetStreamParameters(requested_subsequent_bitrate_, | 1011 SetStreamParameters(requested_subsequent_bitrate_, |
| 983 requested_subsequent_framerate_); | 1012 requested_subsequent_framerate_); |
| 1013 if (real_time_clock_ && input_timer_) | |
| 1014 input_timer_->Start( | |
| 1015 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, | |
| 1016 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); | |
| 984 } | 1017 } |
| 985 } else if (num_encoded_frames_ == num_frames_to_encode_) { | 1018 } else if (num_encoded_frames_ == num_frames_to_encode_) { |
| 986 VerifyPerf(); | 1019 VerifyPerf(); |
| 987 VerifyStreamProperties(); | 1020 VerifyStreamProperties(); |
| 988 SetState(CS_FINISHED); | 1021 SetState(CS_FINISHED); |
| 989 return false; | 1022 return false; |
| 990 } | 1023 } |
| 991 | 1024 |
| 992 return true; | 1025 return true; |
| 993 } | 1026 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1017 current_requested_bitrate_, | 1050 current_requested_bitrate_, |
| 1018 kBitrateTolerance * current_requested_bitrate_); | 1051 kBitrateTolerance * current_requested_bitrate_); |
| 1019 } | 1052 } |
| 1020 } | 1053 } |
| 1021 | 1054 |
| 1022 // Setup test stream data and delete temporary aligned files at the beginning | 1055 // 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. | 1056 // and end of unittest. We only need to setup once for all test cases. |
| 1024 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { | 1057 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { |
| 1025 public: | 1058 public: |
| 1026 VideoEncodeAcceleratorTestEnvironment( | 1059 VideoEncodeAcceleratorTestEnvironment( |
| 1027 scoped_ptr<base::FilePath::StringType> data) { | 1060 scoped_ptr<base::FilePath::StringType> data, |
| 1061 bool real_time_clock) { | |
| 1028 test_stream_data_ = data.Pass(); | 1062 test_stream_data_ = data.Pass(); |
| 1063 real_time_clock_ = real_time_clock; | |
| 1029 } | 1064 } |
| 1030 | 1065 |
| 1031 virtual void SetUp() { | 1066 virtual void SetUp() { |
| 1032 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); | 1067 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); |
| 1033 } | 1068 } |
| 1034 | 1069 |
| 1035 virtual void TearDown() { | 1070 virtual void TearDown() { |
| 1036 for (size_t i = 0; i < test_streams_.size(); i++) { | 1071 for (size_t i = 0; i < test_streams_.size(); i++) { |
| 1037 base::DeleteFile(test_streams_[i]->aligned_in_file, false); | 1072 base::DeleteFile(test_streams_[i]->aligned_in_file, false); |
| 1038 } | 1073 } |
| 1039 } | 1074 } |
| 1040 | 1075 |
| 1041 ScopedVector<TestStream> test_streams_; | 1076 ScopedVector<TestStream> test_streams_; |
| 1077 bool real_time_clock_; | |
| 1042 | 1078 |
| 1043 private: | 1079 private: |
| 1044 scoped_ptr<base::FilePath::StringType> test_stream_data_; | 1080 scoped_ptr<base::FilePath::StringType> test_stream_data_; |
| 1045 }; | 1081 }; |
| 1046 | 1082 |
| 1047 // Test parameters: | 1083 // Test parameters: |
| 1048 // - Number of concurrent encoders. | 1084 // - Number of concurrent encoders. |
| 1049 // - If true, save output to file (provided an output filename was supplied). | 1085 // - If true, save output to file (provided an output filename was supplied). |
| 1050 // - Force a keyframe every n frames. | 1086 // - Force a keyframe every n frames. |
| 1051 // - Force bitrate; the actual required value is provided as a property | 1087 // - Force bitrate; the actual required value is provided as a property |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1073 | 1109 |
| 1074 // Create all encoders. | 1110 // Create all encoders. |
| 1075 for (size_t i = 0; i < num_concurrent_encoders; i++) { | 1111 for (size_t i = 0; i < num_concurrent_encoders; i++) { |
| 1076 size_t test_stream_index = i % g_env->test_streams_.size(); | 1112 size_t test_stream_index = i % g_env->test_streams_.size(); |
| 1077 // Disregard save_to_file if we didn't get an output filename. | 1113 // Disregard save_to_file if we didn't get an output filename. |
| 1078 bool encoder_save_to_file = | 1114 bool encoder_save_to_file = |
| 1079 (save_to_file && | 1115 (save_to_file && |
| 1080 !g_env->test_streams_[test_stream_index]->out_filename.empty()); | 1116 !g_env->test_streams_[test_stream_index]->out_filename.empty()); |
| 1081 | 1117 |
| 1082 notes.push_back(new ClientStateNotification<ClientState>()); | 1118 notes.push_back(new ClientStateNotification<ClientState>()); |
| 1083 clients.push_back(new VEAClient(g_env->test_streams_[test_stream_index], | 1119 clients.push_back( |
| 1084 notes.back(), | 1120 new VEAClient(g_env->test_streams_[test_stream_index], notes.back(), |
| 1085 encoder_save_to_file, | 1121 encoder_save_to_file, keyframe_period, force_bitrate, |
| 1086 keyframe_period, | 1122 test_perf, mid_stream_bitrate_switch, |
| 1087 force_bitrate, | 1123 mid_stream_framerate_switch, g_env->real_time_clock_)); |
| 1088 test_perf, | |
| 1089 mid_stream_bitrate_switch, | |
| 1090 mid_stream_framerate_switch)); | |
| 1091 | 1124 |
| 1092 encoder_thread.message_loop()->PostTask( | 1125 encoder_thread.message_loop()->PostTask( |
| 1093 FROM_HERE, | 1126 FROM_HERE, |
| 1094 base::Bind(&VEAClient::CreateEncoder, | 1127 base::Bind(&VEAClient::CreateEncoder, |
| 1095 base::Unretained(clients.back()))); | 1128 base::Unretained(clients.back()))); |
| 1096 } | 1129 } |
| 1097 | 1130 |
| 1098 // All encoders must pass through states in this order. | 1131 // All encoders must pass through states in this order. |
| 1099 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, | 1132 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, |
| 1100 CS_ENCODING, CS_FINISHED}; | 1133 CS_ENCODING, CS_FINISHED}; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 content::g_default_in_parameters)); | 1210 content::g_default_in_parameters)); |
| 1178 | 1211 |
| 1179 // Needed to enable DVLOG through --vmodule. | 1212 // Needed to enable DVLOG through --vmodule. |
| 1180 logging::LoggingSettings settings; | 1213 logging::LoggingSettings settings; |
| 1181 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 1214 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 1182 CHECK(logging::InitLogging(settings)); | 1215 CHECK(logging::InitLogging(settings)); |
| 1183 | 1216 |
| 1184 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 1217 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 1185 DCHECK(cmd_line); | 1218 DCHECK(cmd_line); |
| 1186 | 1219 |
| 1220 bool real_time_clock = false; | |
| 1187 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | 1221 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
| 1188 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1222 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
| 1189 it != switches.end(); | 1223 it != switches.end(); |
| 1190 ++it) { | 1224 ++it) { |
| 1191 if (it->first == "test_stream_data") { | 1225 if (it->first == "test_stream_data") { |
| 1192 test_stream_data->assign(it->second.c_str()); | 1226 test_stream_data->assign(it->second.c_str()); |
| 1193 continue; | 1227 continue; |
| 1194 } | 1228 } |
| 1229 if (it->first == "real_time_clock") { | |
|
Pawel Osciak
2014/12/21 08:07:05
Hm, I know I proposed RealTime, but this doesn't t
| |
| 1230 real_time_clock = true; | |
| 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(), real_time_clock))); |
| 1205 | 1243 |
| 1206 return RUN_ALL_TESTS(); | 1244 return RUN_ALL_TESTS(); |
| 1207 } | 1245 } |
| OLD | NEW |