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 <algorithm> | |
6 | |
5 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
6 #include "base/bind.h" | 8 #include "base/bind.h" |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
9 #include "base/files/memory_mapped_file.h" | 11 #include "base/files/memory_mapped_file.h" |
10 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
11 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
12 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 // Tolerance factor for how encoded bitrate can differ from requested bitrate. | 68 // Tolerance factor for how encoded bitrate can differ from requested bitrate. |
67 const double kBitrateTolerance = 0.1; | 69 const double kBitrateTolerance = 0.1; |
68 // Minimum required FPS throughput for the basic performance test. | 70 // Minimum required FPS throughput for the basic performance test. |
69 const uint32 kMinPerfFPS = 30; | 71 const uint32 kMinPerfFPS = 30; |
70 // Minimum (arbitrary) number of frames required to enforce bitrate requirements | 72 // Minimum (arbitrary) number of frames required to enforce bitrate requirements |
71 // over. Streams shorter than this may be too short to realistically require | 73 // over. Streams shorter than this may be too short to realistically require |
72 // an encoder to be able to converge to the requested bitrate over. | 74 // an encoder to be able to converge to the requested bitrate over. |
73 // The input stream will be looped as many times as needed in bitrate tests | 75 // The input stream will be looped as many times as needed in bitrate tests |
74 // to reach at least this number of frames before calculating final bitrate. | 76 // to reach at least this number of frames before calculating final bitrate. |
75 const unsigned int kMinFramesForBitrateTests = 300; | 77 const unsigned int kMinFramesForBitrateTests = 300; |
78 // The percentiles to measure for encode latency. | |
79 static uint32_t kLoggedLatencyPercentiles[] = {50, 75, 95}; | |
76 | 80 |
77 // The syntax of multiple test streams is: | 81 // The syntax of multiple test streams is: |
78 // test-stream1;test-stream2;test-stream3 | 82 // test-stream1;test-stream2;test-stream3 |
79 // The syntax of each test stream is: | 83 // The syntax of each test stream is: |
80 // "in_filename:width:height:out_filename:requested_bitrate:requested_framerate | 84 // "in_filename:width:height:out_filename:requested_bitrate:requested_framerate |
81 // :requested_subsequent_bitrate:requested_subsequent_framerate" | 85 // :requested_subsequent_bitrate:requested_subsequent_framerate" |
82 // - |in_filename| must be an I420 (YUV planar) raw stream | 86 // - |in_filename| must be an I420 (YUV planar) raw stream |
83 // (see http://www.fourcc.org/yuv.php#IYUV). | 87 // (see http://www.fourcc.org/yuv.php#IYUV). |
84 // - |width| and |height| are in pixels. | 88 // - |width| and |height| are in pixels. |
85 // - |profile| to encode into (values of media::VideoCodecProfile). | 89 // - |profile| to encode into (values of media::VideoCodecProfile). |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); | 382 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); |
379 } | 383 } |
380 | 384 |
381 virtual void TearDown() { | 385 virtual void TearDown() { |
382 for (size_t i = 0; i < test_streams_.size(); i++) { | 386 for (size_t i = 0; i < test_streams_.size(); i++) { |
383 base::DeleteFile(test_streams_[i]->aligned_in_file, false); | 387 base::DeleteFile(test_streams_[i]->aligned_in_file, false); |
384 } | 388 } |
385 log_file_.reset(); | 389 log_file_.reset(); |
386 } | 390 } |
387 | 391 |
388 // Log one entry of machine-readable data to file. | 392 // Log one entry of machine-readable data to file and LOG(INFO). |
389 // The log has one data entry per line in the format of "<key>: <value>". | 393 // The log has one data entry per line in the format of "<key>: <value>". |
394 // Note that Chrome OS Autotest parses the output key and value pairs. Be sure | |
395 // to keep the Autotest in sync. | |
Pawel Osciak
2015/05/11 03:43:56
Could we have the test name for which this needs t
Justin Chuang
2015/05/11 11:24:54
Add reference to video_VEAPerf here.
| |
390 void LogToFile(const std::string& key, const std::string& value) { | 396 void LogToFile(const std::string& key, const std::string& value) { |
397 std::string s = base::StringPrintf("%s: %s\n", key.c_str(), value.c_str()); | |
398 LOG(INFO) << s; | |
391 if (log_file_) { | 399 if (log_file_) { |
392 std::string s = | |
393 base::StringPrintf("%s: %s\n", key.c_str(), value.c_str()); | |
394 log_file_->WriteAtCurrentPos(s.data(), s.length()); | 400 log_file_->WriteAtCurrentPos(s.data(), s.length()); |
395 } | 401 } |
396 } | 402 } |
397 | 403 |
398 ScopedVector<TestStream> test_streams_; | 404 ScopedVector<TestStream> test_streams_; |
399 bool run_at_fps_; | 405 bool run_at_fps_; |
400 | 406 |
401 private: | 407 private: |
402 scoped_ptr<base::FilePath::StringType> test_stream_data_; | 408 scoped_ptr<base::FilePath::StringType> test_stream_data_; |
403 base::FilePath log_path_; | 409 base::FilePath log_path_; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 unsigned int keyframe_period, | 567 unsigned int keyframe_period, |
562 bool force_bitrate, | 568 bool force_bitrate, |
563 bool test_perf, | 569 bool test_perf, |
564 bool mid_stream_bitrate_switch, | 570 bool mid_stream_bitrate_switch, |
565 bool mid_stream_framerate_switch, | 571 bool mid_stream_framerate_switch, |
566 bool run_at_fps); | 572 bool run_at_fps); |
567 ~VEAClient() override; | 573 ~VEAClient() override; |
568 void CreateEncoder(); | 574 void CreateEncoder(); |
569 void DestroyEncoder(); | 575 void DestroyEncoder(); |
570 | 576 |
571 // Return the number of encoded frames per second. | |
572 double frames_per_second(); | |
573 | |
574 // VideoDecodeAccelerator::Client implementation. | 577 // VideoDecodeAccelerator::Client implementation. |
575 void RequireBitstreamBuffers(unsigned int input_count, | 578 void RequireBitstreamBuffers(unsigned int input_count, |
576 const gfx::Size& input_coded_size, | 579 const gfx::Size& input_coded_size, |
577 size_t output_buffer_size) override; | 580 size_t output_buffer_size) override; |
578 void BitstreamBufferReady(int32 bitstream_buffer_id, | 581 void BitstreamBufferReady(int32 bitstream_buffer_id, |
579 size_t payload_size, | 582 size_t payload_size, |
580 bool key_frame) override; | 583 bool key_frame) override; |
581 void NotifyError(VideoEncodeAccelerator::Error error) override; | 584 void NotifyError(VideoEncodeAccelerator::Error error) override; |
582 | 585 |
583 private: | 586 private: |
584 bool has_encoder() { return encoder_.get(); } | 587 bool has_encoder() { return encoder_.get(); } |
585 | 588 |
589 // Encode latency can only be measured with run_at_fps_. Otherwise, we get | |
590 // skewed results since it may queue too many frames at once with the same | |
591 // encode start time. | |
592 bool needs_encode_latency() { return run_at_fps_; } | |
Pawel Osciak
2015/05/11 03:43:57
We may not always want encode latency when we run_
Justin Chuang
2015/05/11 11:24:54
The problem is that run_at_fps_ is controlled by c
Pawel Osciak
2015/05/13 03:21:18
We could if needed though, just for that test (and
Justin Chuang
2015/05/13 13:59:35
Done.
| |
593 | |
594 // Return the number of encoded frames per second. | |
595 double frames_per_second(); | |
596 | |
597 // Return the percentile from a sorted array. | |
Pawel Osciak
2015/05/11 03:43:56
s/percentile/|percentile|/
s/array/vector/
Justin Chuang
2015/05/11 11:24:54
Done
| |
598 static base::TimeDelta percentile( | |
599 const std::vector<base::TimeDelta>& sorted_values, | |
600 float percentage); | |
Pawel Osciak
2015/05/11 03:43:57
s/percentage/percentile/
Justin Chuang
2015/05/11 11:24:54
Done.
| |
601 | |
586 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA(); | 602 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA(); |
587 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); | 603 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); |
588 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); | 604 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); |
589 | 605 |
590 void SetState(ClientState new_state); | 606 void SetState(ClientState new_state); |
591 | 607 |
592 // Set current stream parameters to given |bitrate| at |framerate|. | 608 // Set current stream parameters to given |bitrate| at |framerate|. |
593 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 609 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
594 | 610 |
595 // Called when encoder is done with a VideoFrame. | 611 // Called when encoder is done with a VideoFrame. |
596 void InputNoLongerNeededCallback(int32 input_id); | 612 void InputNoLongerNeededCallback(int32 input_id); |
597 | 613 |
598 // Feed the encoder with one input frame. | 614 // Feed the encoder with one input frame. |
599 void FeedEncoderWithOneInput(); | 615 void FeedEncoderWithOneInput(); |
600 | 616 |
601 // Provide the encoder with a new output buffer. | 617 // Provide the encoder with a new output buffer. |
602 void FeedEncoderWithOutput(base::SharedMemory* shm); | 618 void FeedEncoderWithOutput(base::SharedMemory* shm); |
603 | 619 |
604 // Called on finding a complete frame (with |keyframe| set to true for | 620 // Called on finding a complete frame (with |keyframe| set to true for |
605 // keyframes) in the stream, to perform codec-independent, per-frame checks | 621 // keyframes) in the stream, to perform codec-independent, per-frame checks |
606 // and accounting. Returns false once we have collected all frames we needed. | 622 // and accounting. Returns false once we have collected all frames we needed. |
607 bool HandleEncodedFrame(bool keyframe); | 623 bool HandleEncodedFrame(bool keyframe); |
608 | 624 |
625 // Verify the minimum FPS requirement. | |
626 void VerifyMinFPS(); | |
627 | |
609 // Verify that stream bitrate has been close to current_requested_bitrate_, | 628 // Verify that stream bitrate has been close to current_requested_bitrate_, |
610 // assuming current_framerate_ since the last time VerifyStreamProperties() | 629 // assuming current_framerate_ since the last time VerifyStreamProperties() |
611 // was called. Fail the test if |force_bitrate_| is true and the bitrate | 630 // was called. Fail the test if |force_bitrate_| is true and the bitrate |
612 // is not within kBitrateTolerance. | 631 // is not within kBitrateTolerance. |
613 void VerifyStreamProperties(); | 632 void VerifyStreamProperties(); |
614 | 633 |
615 // Test codec performance, failing the test if we are currently running | 634 // Log the performance data. |
616 // the performance test. | 635 void LogPerf(); |
617 void VerifyPerf(); | |
618 | 636 |
619 // Write IVF file header to test_stream_->out_filename. | 637 // Write IVF file header to test_stream_->out_filename. |
620 void WriteIvfFileHeader(); | 638 void WriteIvfFileHeader(); |
621 | 639 |
622 // Write an IVF frame header to test_stream_->out_filename. | 640 // Write an IVF frame header to test_stream_->out_filename. |
623 void WriteIvfFrameHeader(int frame_index, size_t frame_size); | 641 void WriteIvfFrameHeader(int frame_index, size_t frame_size); |
624 | 642 |
625 // Prepare and return a frame wrapping the data at |position| bytes in | 643 // Prepare and return a frame wrapping the data at |position| bytes in the |
626 // the input stream, ready to be sent to encoder. | 644 // input stream, ready to be sent to encoder. |
627 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position); | 645 // The input frame id is returned in |input_id|. |
646 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position, | |
647 int32* input_id); | |
628 | 648 |
629 // Update the parameters according to |mid_stream_bitrate_switch| and | 649 // Update the parameters according to |mid_stream_bitrate_switch| and |
630 // |mid_stream_framerate_switch|. | 650 // |mid_stream_framerate_switch|. |
631 void UpdateTestStreamData(bool mid_stream_bitrate_switch, | 651 void UpdateTestStreamData(bool mid_stream_bitrate_switch, |
632 bool mid_stream_framerate_switch); | 652 bool mid_stream_framerate_switch); |
633 | 653 |
634 // Callback function of the |input_timer_|. | 654 // Callback function of the |input_timer_|. |
635 void OnInputTimer(); | 655 void OnInputTimer(); |
636 | 656 |
637 ClientState state_; | 657 ClientState state_; |
638 scoped_ptr<VideoEncodeAccelerator> encoder_; | 658 scoped_ptr<VideoEncodeAccelerator> encoder_; |
639 | 659 |
640 TestStream* test_stream_; | 660 TestStream* test_stream_; |
641 | 661 |
642 // Used to notify another thread about the state. VEAClient does not own this. | 662 // Used to notify another thread about the state. VEAClient does not own this. |
643 ClientStateNotification<ClientState>* note_; | 663 ClientStateNotification<ClientState>* note_; |
644 | 664 |
645 // Ids assigned to VideoFrames (start at 1 for easy comparison with | 665 // Ids assigned to VideoFrames. |
646 // num_encoded_frames_). | |
647 std::set<int32> inputs_at_client_; | 666 std::set<int32> inputs_at_client_; |
648 int32 next_input_id_; | 667 int32 next_input_id_; |
649 | 668 |
669 // Encode start time of all encoded frames. The array index is the frame input | |
Pawel Osciak
2015/05/11 03:43:57
s/array index/position in the vector/
Justin Chuang
2015/05/11 11:24:54
Done.
| |
670 // id. | |
671 std::vector<base::TimeTicks> encode_start_time_; | |
672 // The encode latencies of all encoded frames. We define encode latency as the | |
Pawel Osciak
2015/05/11 03:43:57
s/frames/frames in encode order/
Justin Chuang
2015/05/11 11:24:54
At first, the order is irrelevant.
Then the vector
| |
673 // time delay from input of each VideoFrame (VEA::Encode()) to output of the | |
674 // corresponding BitstreamBuffer (VEA::Client::BitstreamBufferReady()). | |
675 std::vector<base::TimeDelta> encode_latencies_; | |
676 | |
650 // Ids for output BitstreamBuffers. | 677 // Ids for output BitstreamBuffers. |
651 typedef std::map<int32, base::SharedMemory*> IdToSHM; | 678 typedef std::map<int32, base::SharedMemory*> IdToSHM; |
652 ScopedVector<base::SharedMemory> output_shms_; | 679 ScopedVector<base::SharedMemory> output_shms_; |
653 IdToSHM output_buffers_at_client_; | 680 IdToSHM output_buffers_at_client_; |
654 int32 next_output_buffer_id_; | 681 int32 next_output_buffer_id_; |
655 | 682 |
656 // Current offset into input stream. | 683 // Current offset into input stream. |
657 off_t pos_in_input_stream_; | 684 off_t pos_in_input_stream_; |
658 gfx::Size input_coded_size_; | 685 gfx::Size input_coded_size_; |
659 // Requested by encoder. | 686 // Requested by encoder. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 | 723 |
697 // Byte size of the encoded stream (for bitrate calculation) since last | 724 // Byte size of the encoded stream (for bitrate calculation) since last |
698 // time we checked bitrate. | 725 // time we checked bitrate. |
699 size_t encoded_stream_size_since_last_check_; | 726 size_t encoded_stream_size_since_last_check_; |
700 | 727 |
701 // If true, verify performance at the end of the test. | 728 // If true, verify performance at the end of the test. |
702 bool test_perf_; | 729 bool test_perf_; |
703 | 730 |
704 scoped_ptr<StreamValidator> validator_; | 731 scoped_ptr<StreamValidator> validator_; |
705 | 732 |
706 // The time when the encoding started. | |
707 base::TimeTicks encode_start_time_; | |
708 | |
709 // The time when the last encoded frame is ready. | 733 // The time when the last encoded frame is ready. |
710 base::TimeTicks last_frame_ready_time_; | 734 base::TimeTicks last_frame_ready_time_; |
711 | 735 |
712 // All methods of this class should be run on the same thread. | 736 // All methods of this class should be run on the same thread. |
713 base::ThreadChecker thread_checker_; | 737 base::ThreadChecker thread_checker_; |
714 | 738 |
715 // Requested bitrate in bits per second. | 739 // Requested bitrate in bits per second. |
716 unsigned int requested_bitrate_; | 740 unsigned int requested_bitrate_; |
717 | 741 |
718 // Requested initial framerate. | 742 // Requested initial framerate. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 requested_subsequent_framerate_ = | 928 requested_subsequent_framerate_ = |
905 test_stream_->requested_subsequent_framerate; | 929 test_stream_->requested_subsequent_framerate; |
906 } else { | 930 } else { |
907 requested_subsequent_framerate_ = requested_framerate_; | 931 requested_subsequent_framerate_ = requested_framerate_; |
908 } | 932 } |
909 if (requested_subsequent_framerate_ == 0) | 933 if (requested_subsequent_framerate_ == 0) |
910 requested_subsequent_framerate_ = 1; | 934 requested_subsequent_framerate_ = 1; |
911 } | 935 } |
912 | 936 |
913 double VEAClient::frames_per_second() { | 937 double VEAClient::frames_per_second() { |
914 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_; | 938 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_[0]; |
915 return num_encoded_frames_ / duration.InSecondsF(); | 939 return num_encoded_frames_ / duration.InSecondsF(); |
916 } | 940 } |
917 | 941 |
942 base::TimeDelta VEAClient::percentile( | |
943 const std::vector<base::TimeDelta>& sorted_values, | |
944 float percentage) { | |
945 size_t size = sorted_values.size(); | |
946 CHECK_GT(size, 0); | |
947 CHECK_GE(percentage, 0.0f); | |
948 CHECK_LE(percentage, 1.0f); | |
949 // Use Nearest Rank method in http://en.wikipedia.org/wiki/Percentile. | |
950 int32_t index = | |
951 std::max(static_cast<int32_t>(ceil(percentage * size)) - 1, 0); | |
952 return sorted_values[index]; | |
953 } | |
954 | |
918 void VEAClient::RequireBitstreamBuffers(unsigned int input_count, | 955 void VEAClient::RequireBitstreamBuffers(unsigned int input_count, |
919 const gfx::Size& input_coded_size, | 956 const gfx::Size& input_coded_size, |
920 size_t output_size) { | 957 size_t output_size) { |
921 DCHECK(thread_checker_.CalledOnValidThread()); | 958 DCHECK(thread_checker_.CalledOnValidThread()); |
922 ASSERT_EQ(state_, CS_INITIALIZED); | 959 ASSERT_EQ(state_, CS_INITIALIZED); |
923 SetState(CS_ENCODING); | 960 SetState(CS_ENCODING); |
924 | 961 |
925 CreateAlignedInputStreamFile(input_coded_size, test_stream_); | 962 CreateAlignedInputStreamFile(input_coded_size, test_stream_); |
926 | 963 |
927 num_frames_to_encode_ = test_stream_->num_frames; | 964 num_frames_to_encode_ = test_stream_->num_frames; |
928 if (g_num_frames_to_encode > 0) | 965 if (g_num_frames_to_encode > 0) |
929 num_frames_to_encode_ = g_num_frames_to_encode; | 966 num_frames_to_encode_ = g_num_frames_to_encode; |
930 | 967 |
968 // Speedup vector insertion. | |
wuchengli
2015/05/08 05:11:59
s/Speedup/Speed up/
Justin Chuang
2015/05/11 11:24:54
Done.
| |
969 encode_start_time_.reserve(num_frames_to_encode_); | |
970 if (needs_encode_latency()) | |
971 encode_latencies_.reserve(num_frames_to_encode_); | |
972 | |
931 // We may need to loop over the stream more than once if more frames than | 973 // We may need to loop over the stream more than once if more frames than |
932 // provided is required for bitrate tests. | 974 // provided is required for bitrate tests. |
933 if (force_bitrate_ && num_frames_to_encode_ < kMinFramesForBitrateTests) { | 975 if (force_bitrate_ && num_frames_to_encode_ < kMinFramesForBitrateTests) { |
934 DVLOG(1) << "Stream too short for bitrate test (" | 976 DVLOG(1) << "Stream too short for bitrate test (" |
935 << test_stream_->num_frames << " frames), will loop it to reach " | 977 << test_stream_->num_frames << " frames), will loop it to reach " |
936 << kMinFramesForBitrateTests << " frames"; | 978 << kMinFramesForBitrateTests << " frames"; |
937 num_frames_to_encode_ = kMinFramesForBitrateTests; | 979 num_frames_to_encode_ = kMinFramesForBitrateTests; |
938 } | 980 } |
939 if (save_to_file_ && IsVP8(test_stream_->requested_profile)) | 981 if (save_to_file_ && IsVP8(test_stream_->requested_profile)) |
940 WriteIvfFileHeader(); | 982 WriteIvfFileHeader(); |
941 | 983 |
942 input_coded_size_ = input_coded_size; | 984 input_coded_size_ = input_coded_size; |
943 num_required_input_buffers_ = input_count; | 985 num_required_input_buffers_ = input_count; |
944 ASSERT_GT(num_required_input_buffers_, 0UL); | 986 ASSERT_GT(num_required_input_buffers_, 0UL); |
945 | 987 |
946 output_buffer_size_ = output_size; | 988 output_buffer_size_ = output_size; |
947 ASSERT_GT(output_buffer_size_, 0UL); | 989 ASSERT_GT(output_buffer_size_, 0UL); |
948 | 990 |
949 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { | 991 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { |
950 base::SharedMemory* shm = new base::SharedMemory(); | 992 base::SharedMemory* shm = new base::SharedMemory(); |
951 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); | 993 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); |
952 output_shms_.push_back(shm); | 994 output_shms_.push_back(shm); |
953 FeedEncoderWithOutput(shm); | 995 FeedEncoderWithOutput(shm); |
954 } | 996 } |
955 | 997 |
956 encode_start_time_ = base::TimeTicks::Now(); | |
957 if (run_at_fps_) { | 998 if (run_at_fps_) { |
958 input_timer_.reset(new base::RepeatingTimer<VEAClient>()); | 999 input_timer_.reset(new base::RepeatingTimer<VEAClient>()); |
959 input_timer_->Start( | 1000 input_timer_->Start( |
960 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, | 1001 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, |
961 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); | 1002 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); |
962 } else { | 1003 } else { |
963 while (inputs_at_client_.size() < | 1004 while (inputs_at_client_.size() < |
964 num_required_input_buffers_ + kNumExtraInputFrames) | 1005 num_required_input_buffers_ + kNumExtraInputFrames) |
965 FeedEncoderWithOneInput(); | 1006 FeedEncoderWithOneInput(); |
966 } | 1007 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1031 } | 1072 } |
1032 | 1073 |
1033 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { | 1074 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { |
1034 std::set<int32>::iterator it = inputs_at_client_.find(input_id); | 1075 std::set<int32>::iterator it = inputs_at_client_.find(input_id); |
1035 ASSERT_NE(it, inputs_at_client_.end()); | 1076 ASSERT_NE(it, inputs_at_client_.end()); |
1036 inputs_at_client_.erase(it); | 1077 inputs_at_client_.erase(it); |
1037 if (!run_at_fps_) | 1078 if (!run_at_fps_) |
1038 FeedEncoderWithOneInput(); | 1079 FeedEncoderWithOneInput(); |
1039 } | 1080 } |
1040 | 1081 |
1041 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { | 1082 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position, |
1083 int32* input_id) { | |
1042 CHECK_LE(position + test_stream_->aligned_buffer_size, | 1084 CHECK_LE(position + test_stream_->aligned_buffer_size, |
1043 test_stream_->mapped_aligned_in_file.length()); | 1085 test_stream_->mapped_aligned_in_file.length()); |
1044 | 1086 |
1045 uint8* frame_data_y = const_cast<uint8*>( | 1087 uint8* frame_data_y = const_cast<uint8*>( |
1046 test_stream_->mapped_aligned_in_file.data() + position); | 1088 test_stream_->mapped_aligned_in_file.data() + position); |
1047 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; | 1089 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; |
1048 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1]; | 1090 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1]; |
1049 | 1091 |
1050 CHECK_GT(current_framerate_, 0U); | 1092 CHECK_GT(current_framerate_, 0U); |
1051 scoped_refptr<media::VideoFrame> frame = | 1093 scoped_refptr<media::VideoFrame> frame = |
(...skipping 10 matching lines...) Expand all Loading... | |
1062 frame_data_v, | 1104 frame_data_v, |
1063 base::TimeDelta().FromMilliseconds( | 1105 base::TimeDelta().FromMilliseconds( |
1064 next_input_id_ * base::Time::kMillisecondsPerSecond / | 1106 next_input_id_ * base::Time::kMillisecondsPerSecond / |
1065 current_framerate_), | 1107 current_framerate_), |
1066 media::BindToCurrentLoop( | 1108 media::BindToCurrentLoop( |
1067 base::Bind(&VEAClient::InputNoLongerNeededCallback, | 1109 base::Bind(&VEAClient::InputNoLongerNeededCallback, |
1068 base::Unretained(this), | 1110 base::Unretained(this), |
1069 next_input_id_))); | 1111 next_input_id_))); |
1070 | 1112 |
1071 CHECK(inputs_at_client_.insert(next_input_id_).second); | 1113 CHECK(inputs_at_client_.insert(next_input_id_).second); |
1072 ++next_input_id_; | |
1073 | 1114 |
1115 *input_id = next_input_id_++; | |
1074 return frame; | 1116 return frame; |
1075 } | 1117 } |
1076 | 1118 |
1077 void VEAClient::OnInputTimer() { | 1119 void VEAClient::OnInputTimer() { |
1078 if (!has_encoder() || state_ != CS_ENCODING) | 1120 if (!has_encoder() || state_ != CS_ENCODING) |
1079 input_timer_.reset(); | 1121 input_timer_.reset(); |
1080 else if (inputs_at_client_.size() < | 1122 else if (inputs_at_client_.size() < |
1081 num_required_input_buffers_ + kNumExtraInputFrames) | 1123 num_required_input_buffers_ + kNumExtraInputFrames) |
1082 FeedEncoderWithOneInput(); | 1124 FeedEncoderWithOneInput(); |
1083 else | 1125 else |
1084 DVLOG(1) << "Dropping input frame"; | 1126 DVLOG(1) << "Dropping input frame"; |
1085 } | 1127 } |
1086 | 1128 |
1087 void VEAClient::FeedEncoderWithOneInput() { | 1129 void VEAClient::FeedEncoderWithOneInput() { |
1088 if (!has_encoder() || state_ != CS_ENCODING) | 1130 if (!has_encoder() || state_ != CS_ENCODING) |
1089 return; | 1131 return; |
1090 | 1132 |
1091 size_t bytes_left = | 1133 size_t bytes_left = |
1092 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; | 1134 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; |
1093 if (bytes_left < test_stream_->aligned_buffer_size) { | 1135 if (bytes_left < test_stream_->aligned_buffer_size) { |
1094 DCHECK_EQ(bytes_left, 0UL); | 1136 DCHECK_EQ(bytes_left, 0UL); |
1095 // Rewind if at the end of stream and we are still encoding. | 1137 // Rewind if at the end of stream and we are still encoding. |
1096 // This is to flush the encoder with additional frames from the beginning | 1138 // This is to flush the encoder with additional frames from the beginning |
1097 // of the stream, or if the stream is shorter that the number of frames | 1139 // of the stream, or if the stream is shorter that the number of frames |
1098 // we require for bitrate tests. | 1140 // we require for bitrate tests. |
1099 pos_in_input_stream_ = 0; | 1141 pos_in_input_stream_ = 0; |
1100 } | 1142 } |
1101 | 1143 |
1144 int32 input_id; | |
1145 scoped_refptr<media::VideoFrame> video_frame = | |
1146 PrepareInputFrame(pos_in_input_stream_, &input_id); | |
1147 pos_in_input_stream_ += test_stream_->aligned_buffer_size; | |
1148 | |
1102 bool force_keyframe = false; | 1149 bool force_keyframe = false; |
1103 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { | 1150 if (keyframe_period_ && input_id % keyframe_period_ == 0) { |
1104 force_keyframe = true; | 1151 force_keyframe = true; |
1105 ++num_keyframes_requested_; | 1152 ++num_keyframes_requested_; |
1106 } | 1153 } |
1107 | 1154 |
1108 scoped_refptr<media::VideoFrame> video_frame = | 1155 CHECK_EQ(input_id, static_cast<int32>(encode_start_time_.size())); |
1109 PrepareInputFrame(pos_in_input_stream_); | 1156 encode_start_time_.push_back(base::TimeTicks::Now()); |
1110 pos_in_input_stream_ += test_stream_->aligned_buffer_size; | |
1111 | |
1112 encoder_->Encode(video_frame, force_keyframe); | 1157 encoder_->Encode(video_frame, force_keyframe); |
1113 } | 1158 } |
1114 | 1159 |
1115 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { | 1160 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { |
1116 if (!has_encoder()) | 1161 if (!has_encoder()) |
1117 return; | 1162 return; |
1118 | 1163 |
1119 if (state_ != CS_ENCODING) | 1164 if (state_ != CS_ENCODING) |
1120 return; | 1165 return; |
1121 | 1166 |
1122 base::SharedMemoryHandle dup_handle; | 1167 base::SharedMemoryHandle dup_handle; |
1123 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); | 1168 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); |
1124 | 1169 |
1125 media::BitstreamBuffer bitstream_buffer( | 1170 media::BitstreamBuffer bitstream_buffer( |
1126 next_output_buffer_id_++, dup_handle, output_buffer_size_); | 1171 next_output_buffer_id_++, dup_handle, output_buffer_size_); |
1127 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(), | 1172 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(), |
1128 shm)).second); | 1173 shm)).second); |
1129 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); | 1174 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); |
1130 } | 1175 } |
1131 | 1176 |
1132 bool VEAClient::HandleEncodedFrame(bool keyframe) { | 1177 bool VEAClient::HandleEncodedFrame(bool keyframe) { |
1133 // This would be a bug in the test, which should not ignore false | 1178 // This would be a bug in the test, which should not ignore false |
1134 // return value from this method. | 1179 // return value from this method. |
1135 CHECK_LE(num_encoded_frames_, num_frames_to_encode_); | 1180 CHECK_LE(num_encoded_frames_, num_frames_to_encode_); |
1136 | 1181 |
1182 last_frame_ready_time_ = base::TimeTicks::Now(); | |
1183 | |
1184 if (needs_encode_latency()) { | |
1185 base::TimeTicks start_time = encode_start_time_[num_encoded_frames_]; | |
1186 CHECK(!start_time.is_null()); | |
1187 encode_latencies_.push_back(last_frame_ready_time_ - start_time); | |
Pawel Osciak
2015/05/11 03:43:57
encode_latencies_ is pre-reserved at l.971, but th
Justin Chuang
2015/05/11 11:24:54
No, vector::reserve() only increase the capacity,
Pawel Osciak
2015/05/13 03:21:18
Acknowledged.
| |
1188 } | |
1189 | |
1137 ++num_encoded_frames_; | 1190 ++num_encoded_frames_; |
1138 ++num_frames_since_last_check_; | 1191 ++num_frames_since_last_check_; |
1139 | 1192 |
1140 last_frame_ready_time_ = base::TimeTicks::Now(); | |
1141 | |
1142 // Because the keyframe behavior requirements are loose, we give | 1193 // Because the keyframe behavior requirements are loose, we give |
1143 // the encoder more freedom here. It could either deliver a keyframe | 1194 // the encoder more freedom here. It could either deliver a keyframe |
1144 // immediately after we requested it, which could be for a frame number | 1195 // immediately after we requested it, which could be for a frame number |
1145 // before the one we requested it for (if the keyframe request | 1196 // before the one we requested it for (if the keyframe request |
1146 // is asynchronous, i.e. not bound to any concrete frame, and because | 1197 // is asynchronous, i.e. not bound to any concrete frame, and because |
1147 // the pipeline can be deeper than one frame), at that frame, or after. | 1198 // the pipeline can be deeper than one frame), at that frame, or after. |
1148 // So the only constraints we put here is that we get a keyframe not | 1199 // So the only constraints we put here is that we get a keyframe not |
1149 // earlier than we requested one (in time), and not later than | 1200 // earlier than we requested one (in time), and not later than |
1150 // kMaxKeyframeDelay frames after the frame, for which we requested | 1201 // kMaxKeyframeDelay frames after the frame, for which we requested |
1151 // it, comes back encoded. | 1202 // it, comes back encoded. |
(...skipping 14 matching lines...) Expand all Loading... | |
1166 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || | 1217 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || |
1167 requested_subsequent_framerate_ != current_framerate_) { | 1218 requested_subsequent_framerate_ != current_framerate_) { |
1168 SetStreamParameters(requested_subsequent_bitrate_, | 1219 SetStreamParameters(requested_subsequent_bitrate_, |
1169 requested_subsequent_framerate_); | 1220 requested_subsequent_framerate_); |
1170 if (run_at_fps_ && input_timer_) | 1221 if (run_at_fps_ && input_timer_) |
1171 input_timer_->Start( | 1222 input_timer_->Start( |
1172 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, | 1223 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, |
1173 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); | 1224 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); |
1174 } | 1225 } |
1175 } else if (num_encoded_frames_ == num_frames_to_encode_) { | 1226 } else if (num_encoded_frames_ == num_frames_to_encode_) { |
1176 VerifyPerf(); | 1227 LogPerf(); |
1228 VerifyMinFPS(); | |
1177 VerifyStreamProperties(); | 1229 VerifyStreamProperties(); |
1178 SetState(CS_FINISHED); | 1230 SetState(CS_FINISHED); |
1179 return false; | 1231 return false; |
1180 } | 1232 } |
1181 | 1233 |
1182 return true; | 1234 return true; |
1183 } | 1235 } |
1184 | 1236 |
1185 void VEAClient::VerifyPerf() { | 1237 void VEAClient::LogPerf() { |
1186 double measured_fps = frames_per_second(); | 1238 // Log measured FPS. |
1187 LOG(INFO) << "Measured encoder FPS: " << measured_fps; | |
1188 g_env->LogToFile("Measured encoder FPS", | 1239 g_env->LogToFile("Measured encoder FPS", |
1189 base::StringPrintf("%.3f", measured_fps)); | 1240 base::StringPrintf("%.3f", frames_per_second())); |
1241 | |
1242 // Log encode latencies. | |
1243 if (needs_encode_latency()) { | |
1244 std::sort(encode_latencies_.begin(), encode_latencies_.end()); | |
1245 for (size_t i = 0; i < arraysize(kLoggedLatencyPercentiles); i++) { | |
Pawel Osciak
2015/05/11 03:43:57
for (const auto& p : kLoggedLatencyPercentiles) {
Justin Chuang
2015/05/11 11:24:54
Done. Thanks. I didn't know this new style also wo
| |
1246 uint32_t p = kLoggedLatencyPercentiles[i]; | |
1247 base::TimeDelta latency = percentile(encode_latencies_, 0.01f * p); | |
1248 g_env->LogToFile( | |
1249 base::StringPrintf("Encode latency for the %dth percentile", p), | |
1250 base::StringPrintf("%" PRId64 " us", latency.InMicroseconds())); | |
1251 } | |
1252 } | |
1253 } | |
1254 | |
1255 void VEAClient::VerifyMinFPS() { | |
1190 if (test_perf_) | 1256 if (test_perf_) |
1191 EXPECT_GE(measured_fps, kMinPerfFPS); | 1257 EXPECT_GE(frames_per_second(), kMinPerfFPS); |
1192 } | 1258 } |
1193 | 1259 |
1194 void VEAClient::VerifyStreamProperties() { | 1260 void VEAClient::VerifyStreamProperties() { |
1195 CHECK_GT(num_frames_since_last_check_, 0UL); | 1261 CHECK_GT(num_frames_since_last_check_, 0UL); |
1196 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); | 1262 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); |
1197 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * | 1263 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * |
1198 current_framerate_ / num_frames_since_last_check_; | 1264 current_framerate_ / num_frames_since_last_check_; |
1199 DVLOG(1) << "Current chunk's bitrate: " << bitrate | 1265 DVLOG(1) << "Current chunk's bitrate: " << bitrate |
1200 << " (expected: " << current_requested_bitrate_ | 1266 << " (expected: " << current_requested_bitrate_ |
1201 << " @ " << current_framerate_ << " FPS," | 1267 << " @ " << current_framerate_ << " FPS," |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1441 } | 1507 } |
1442 | 1508 |
1443 content::g_env = | 1509 content::g_env = |
1444 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1510 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1445 testing::AddGlobalTestEnvironment( | 1511 testing::AddGlobalTestEnvironment( |
1446 new content::VideoEncodeAcceleratorTestEnvironment( | 1512 new content::VideoEncodeAcceleratorTestEnvironment( |
1447 test_stream_data.Pass(), log_path, run_at_fps))); | 1513 test_stream_data.Pass(), log_path, run_at_fps))); |
1448 | 1514 |
1449 return RUN_ALL_TESTS(); | 1515 return RUN_ALL_TESTS(); |
1450 } | 1516 } |
OLD | NEW |