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

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

Issue 1117853002: vea_unittest: Calculate per-frame encode latency (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Owen's comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <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
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 percentages of the percentiles to measure for encode latency.
79 static float kLoggedLatencyPercentages[] = {0.50, 0.75, 0.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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 unsigned int keyframe_period, 565 unsigned int keyframe_period,
562 bool force_bitrate, 566 bool force_bitrate,
563 bool test_perf, 567 bool test_perf,
564 bool mid_stream_bitrate_switch, 568 bool mid_stream_bitrate_switch,
565 bool mid_stream_framerate_switch, 569 bool mid_stream_framerate_switch,
566 bool run_at_fps); 570 bool run_at_fps);
567 ~VEAClient() override; 571 ~VEAClient() override;
568 void CreateEncoder(); 572 void CreateEncoder();
569 void DestroyEncoder(); 573 void DestroyEncoder();
570 574
571 // Return the number of encoded frames per second.
572 double frames_per_second();
573
574 // VideoDecodeAccelerator::Client implementation. 575 // VideoDecodeAccelerator::Client implementation.
575 void RequireBitstreamBuffers(unsigned int input_count, 576 void RequireBitstreamBuffers(unsigned int input_count,
576 const gfx::Size& input_coded_size, 577 const gfx::Size& input_coded_size,
577 size_t output_buffer_size) override; 578 size_t output_buffer_size) override;
578 void BitstreamBufferReady(int32 bitstream_buffer_id, 579 void BitstreamBufferReady(int32 bitstream_buffer_id,
579 size_t payload_size, 580 size_t payload_size,
580 bool key_frame) override; 581 bool key_frame) override;
581 void NotifyError(VideoEncodeAccelerator::Error error) override; 582 void NotifyError(VideoEncodeAccelerator::Error error) override;
582 583
583 private: 584 private:
584 bool has_encoder() { return encoder_.get(); } 585 bool has_encoder() { return encoder_.get(); }
585 586
587 // Return the number of encoded frames per second.
588 double frames_per_second();
589
590 // Return the percentile from a sorted array.
591 static base::TimeDelta percentile(
592 const std::vector<base::TimeDelta>& sorted_values,
593 float percentage);
594
586 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA(); 595 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA();
587 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); 596 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA();
588 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); 597 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA();
589 598
590 void SetState(ClientState new_state); 599 void SetState(ClientState new_state);
591 600
592 // Set current stream parameters to given |bitrate| at |framerate|. 601 // Set current stream parameters to given |bitrate| at |framerate|.
593 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); 602 void SetStreamParameters(unsigned int bitrate, unsigned int framerate);
594 603
595 // Called when encoder is done with a VideoFrame. 604 // Called when encoder is done with a VideoFrame.
(...skipping 19 matching lines...) Expand all
615 // Test codec performance, failing the test if we are currently running 624 // Test codec performance, failing the test if we are currently running
616 // the performance test. 625 // the performance test.
617 void VerifyPerf(); 626 void VerifyPerf();
618 627
619 // Write IVF file header to test_stream_->out_filename. 628 // Write IVF file header to test_stream_->out_filename.
620 void WriteIvfFileHeader(); 629 void WriteIvfFileHeader();
621 630
622 // Write an IVF frame header to test_stream_->out_filename. 631 // Write an IVF frame header to test_stream_->out_filename.
623 void WriteIvfFrameHeader(int frame_index, size_t frame_size); 632 void WriteIvfFrameHeader(int frame_index, size_t frame_size);
624 633
625 // Prepare and return a frame wrapping the data at |position| bytes in 634 // Prepare and return a frame wrapping the data at |position| bytes in the
626 // the input stream, ready to be sent to encoder. 635 // input stream, ready to be sent to encoder.
627 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position); 636 // The input frame id is returned in |input_id|.
637 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position,
638 int32* input_id);
628 639
629 // Update the parameters according to |mid_stream_bitrate_switch| and 640 // Update the parameters according to |mid_stream_bitrate_switch| and
630 // |mid_stream_framerate_switch|. 641 // |mid_stream_framerate_switch|.
631 void UpdateTestStreamData(bool mid_stream_bitrate_switch, 642 void UpdateTestStreamData(bool mid_stream_bitrate_switch,
632 bool mid_stream_framerate_switch); 643 bool mid_stream_framerate_switch);
633 644
634 // Callback function of the |input_timer_|. 645 // Callback function of the |input_timer_|.
635 void OnInputTimer(); 646 void OnInputTimer();
636 647
637 ClientState state_; 648 ClientState state_;
638 scoped_ptr<VideoEncodeAccelerator> encoder_; 649 scoped_ptr<VideoEncodeAccelerator> encoder_;
639 650
640 TestStream* test_stream_; 651 TestStream* test_stream_;
641 652
642 // Used to notify another thread about the state. VEAClient does not own this. 653 // Used to notify another thread about the state. VEAClient does not own this.
643 ClientStateNotification<ClientState>* note_; 654 ClientStateNotification<ClientState>* note_;
644 655
645 // Ids assigned to VideoFrames (start at 1 for easy comparison with 656 // Ids assigned to VideoFrames.
646 // num_encoded_frames_).
647 std::set<int32> inputs_at_client_; 657 std::set<int32> inputs_at_client_;
648 int32 next_input_id_; 658 int32 next_input_id_;
649 659
660 typedef std::map<int32, base::TimeTicks> IdToTicks;
661 // A map from input frame id to the encode start time of the frame.
662 IdToTicks encode_start_time_per_frame_;
wuchengli 2015/05/07 05:39:09 s/encode_start_time_per_frame_/frame_encode_start_
Justin Chuang 2015/05/07 08:33:45 Done. Use a slightly different name.
663 // The encode latencies of all encoded frames.
664 std::vector<base::TimeDelta> encode_latencies_;
665
650 // Ids for output BitstreamBuffers. 666 // Ids for output BitstreamBuffers.
651 typedef std::map<int32, base::SharedMemory*> IdToSHM; 667 typedef std::map<int32, base::SharedMemory*> IdToSHM;
652 ScopedVector<base::SharedMemory> output_shms_; 668 ScopedVector<base::SharedMemory> output_shms_;
653 IdToSHM output_buffers_at_client_; 669 IdToSHM output_buffers_at_client_;
654 int32 next_output_buffer_id_; 670 int32 next_output_buffer_id_;
655 671
656 // Current offset into input stream. 672 // Current offset into input stream.
657 off_t pos_in_input_stream_; 673 off_t pos_in_input_stream_;
658 gfx::Size input_coded_size_; 674 gfx::Size input_coded_size_;
659 // Requested by encoder. 675 // Requested by encoder.
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 } 924 }
909 if (requested_subsequent_framerate_ == 0) 925 if (requested_subsequent_framerate_ == 0)
910 requested_subsequent_framerate_ = 1; 926 requested_subsequent_framerate_ = 1;
911 } 927 }
912 928
913 double VEAClient::frames_per_second() { 929 double VEAClient::frames_per_second() {
914 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_; 930 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_;
915 return num_encoded_frames_ / duration.InSecondsF(); 931 return num_encoded_frames_ / duration.InSecondsF();
916 } 932 }
917 933
934 base::TimeDelta VEAClient::percentile(
935 const std::vector<base::TimeDelta>& sorted_values,
936 float percentage) {
937 size_t size = sorted_values.size();
938 if (size == 0) {
Owen Lin 2015/05/07 06:29:53 I think we should not return 0 when size == 0. How
Justin Chuang 2015/05/07 08:33:45 Done.
939 return base::TimeDelta();
940 } else {
941 CHECK_GE(percentage, 0.0f);
942 CHECK_LE(percentage, 1.0f);
943 // Use Nearest Rank method.
944 size_t index =
945 std::min(base::checked_cast<size_t>(percentage * size), size - 1);
946 return sorted_values[index];
947 }
948 }
949
918 void VEAClient::RequireBitstreamBuffers(unsigned int input_count, 950 void VEAClient::RequireBitstreamBuffers(unsigned int input_count,
919 const gfx::Size& input_coded_size, 951 const gfx::Size& input_coded_size,
920 size_t output_size) { 952 size_t output_size) {
921 DCHECK(thread_checker_.CalledOnValidThread()); 953 DCHECK(thread_checker_.CalledOnValidThread());
922 ASSERT_EQ(state_, CS_INITIALIZED); 954 ASSERT_EQ(state_, CS_INITIALIZED);
923 SetState(CS_ENCODING); 955 SetState(CS_ENCODING);
924 956
925 CreateAlignedInputStreamFile(input_coded_size, test_stream_); 957 CreateAlignedInputStreamFile(input_coded_size, test_stream_);
926 958
927 num_frames_to_encode_ = test_stream_->num_frames; 959 num_frames_to_encode_ = test_stream_->num_frames;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 } 1063 }
1032 1064
1033 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { 1065 void VEAClient::InputNoLongerNeededCallback(int32 input_id) {
1034 std::set<int32>::iterator it = inputs_at_client_.find(input_id); 1066 std::set<int32>::iterator it = inputs_at_client_.find(input_id);
1035 ASSERT_NE(it, inputs_at_client_.end()); 1067 ASSERT_NE(it, inputs_at_client_.end());
1036 inputs_at_client_.erase(it); 1068 inputs_at_client_.erase(it);
1037 if (!run_at_fps_) 1069 if (!run_at_fps_)
1038 FeedEncoderWithOneInput(); 1070 FeedEncoderWithOneInput();
1039 } 1071 }
1040 1072
1041 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { 1073 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position,
1074 int32* input_id) {
1042 CHECK_LE(position + test_stream_->aligned_buffer_size, 1075 CHECK_LE(position + test_stream_->aligned_buffer_size,
1043 test_stream_->mapped_aligned_in_file.length()); 1076 test_stream_->mapped_aligned_in_file.length());
1044 1077
1045 uint8* frame_data_y = const_cast<uint8*>( 1078 uint8* frame_data_y = const_cast<uint8*>(
1046 test_stream_->mapped_aligned_in_file.data() + position); 1079 test_stream_->mapped_aligned_in_file.data() + position);
1047 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; 1080 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]; 1081 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1];
1049 1082
1050 CHECK_GT(current_framerate_, 0U); 1083 CHECK_GT(current_framerate_, 0U);
1051 scoped_refptr<media::VideoFrame> frame = 1084 scoped_refptr<media::VideoFrame> frame =
(...skipping 10 matching lines...) Expand all
1062 frame_data_v, 1095 frame_data_v,
1063 base::TimeDelta().FromMilliseconds( 1096 base::TimeDelta().FromMilliseconds(
1064 next_input_id_ * base::Time::kMillisecondsPerSecond / 1097 next_input_id_ * base::Time::kMillisecondsPerSecond /
1065 current_framerate_), 1098 current_framerate_),
1066 media::BindToCurrentLoop( 1099 media::BindToCurrentLoop(
1067 base::Bind(&VEAClient::InputNoLongerNeededCallback, 1100 base::Bind(&VEAClient::InputNoLongerNeededCallback,
1068 base::Unretained(this), 1101 base::Unretained(this),
1069 next_input_id_))); 1102 next_input_id_)));
1070 1103
1071 CHECK(inputs_at_client_.insert(next_input_id_).second); 1104 CHECK(inputs_at_client_.insert(next_input_id_).second);
1072 ++next_input_id_;
1073 1105
1106 *input_id = next_input_id_++;
1074 return frame; 1107 return frame;
1075 } 1108 }
1076 1109
1077 void VEAClient::OnInputTimer() { 1110 void VEAClient::OnInputTimer() {
1078 if (!has_encoder() || state_ != CS_ENCODING) 1111 if (!has_encoder() || state_ != CS_ENCODING)
1079 input_timer_.reset(); 1112 input_timer_.reset();
1080 else if (inputs_at_client_.size() < 1113 else if (inputs_at_client_.size() <
1081 num_required_input_buffers_ + kNumExtraInputFrames) 1114 num_required_input_buffers_ + kNumExtraInputFrames)
1082 FeedEncoderWithOneInput(); 1115 FeedEncoderWithOneInput();
1083 else 1116 else
1084 DVLOG(1) << "Dropping input frame"; 1117 DVLOG(1) << "Dropping input frame";
1085 } 1118 }
1086 1119
1087 void VEAClient::FeedEncoderWithOneInput() { 1120 void VEAClient::FeedEncoderWithOneInput() {
1088 if (!has_encoder() || state_ != CS_ENCODING) 1121 if (!has_encoder() || state_ != CS_ENCODING)
1089 return; 1122 return;
1090 1123
1091 size_t bytes_left = 1124 size_t bytes_left =
1092 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; 1125 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_;
1093 if (bytes_left < test_stream_->aligned_buffer_size) { 1126 if (bytes_left < test_stream_->aligned_buffer_size) {
1094 DCHECK_EQ(bytes_left, 0UL); 1127 DCHECK_EQ(bytes_left, 0UL);
1095 // Rewind if at the end of stream and we are still encoding. 1128 // 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 1129 // 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 1130 // of the stream, or if the stream is shorter that the number of frames
1098 // we require for bitrate tests. 1131 // we require for bitrate tests.
1099 pos_in_input_stream_ = 0; 1132 pos_in_input_stream_ = 0;
1100 } 1133 }
1101 1134
1135 int32 input_id;
1136 scoped_refptr<media::VideoFrame> video_frame =
1137 PrepareInputFrame(pos_in_input_stream_, &input_id);
1138 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
1139
1102 bool force_keyframe = false; 1140 bool force_keyframe = false;
1103 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { 1141 if (keyframe_period_ && input_id % keyframe_period_ == 0) {
1104 force_keyframe = true; 1142 force_keyframe = true;
1105 ++num_keyframes_requested_; 1143 ++num_keyframes_requested_;
1106 } 1144 }
1107 1145
1108 scoped_refptr<media::VideoFrame> video_frame = 1146 CHECK(encode_start_time_per_frame_.insert(
wuchengli 2015/05/07 05:39:09 Why do we need to CHECK the return value of insert
Owen Lin 2015/05/07 06:29:53 second is true iff the key wasn't in the map.
wuchengli 2015/05/07 07:05:20 I see. I didn't see .second. :)
1109 PrepareInputFrame(pos_in_input_stream_); 1147 std::make_pair(input_id, base::TimeTicks::Now())).second);
1110 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
1111
1112 encoder_->Encode(video_frame, force_keyframe); 1148 encoder_->Encode(video_frame, force_keyframe);
1113 } 1149 }
1114 1150
1115 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { 1151 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) {
1116 if (!has_encoder()) 1152 if (!has_encoder())
1117 return; 1153 return;
1118 1154
1119 if (state_ != CS_ENCODING) 1155 if (state_ != CS_ENCODING)
1120 return; 1156 return;
1121 1157
1122 base::SharedMemoryHandle dup_handle; 1158 base::SharedMemoryHandle dup_handle;
1123 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); 1159 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle));
1124 1160
1125 media::BitstreamBuffer bitstream_buffer( 1161 media::BitstreamBuffer bitstream_buffer(
1126 next_output_buffer_id_++, dup_handle, output_buffer_size_); 1162 next_output_buffer_id_++, dup_handle, output_buffer_size_);
1127 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(), 1163 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(),
1128 shm)).second); 1164 shm)).second);
1129 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); 1165 encoder_->UseOutputBitstreamBuffer(bitstream_buffer);
1130 } 1166 }
1131 1167
1132 bool VEAClient::HandleEncodedFrame(bool keyframe) { 1168 bool VEAClient::HandleEncodedFrame(bool keyframe) {
1133 // This would be a bug in the test, which should not ignore false 1169 // This would be a bug in the test, which should not ignore false
1134 // return value from this method. 1170 // return value from this method.
1135 CHECK_LE(num_encoded_frames_, num_frames_to_encode_); 1171 CHECK_LE(num_encoded_frames_, num_frames_to_encode_);
1136 1172
1173 last_frame_ready_time_ = base::TimeTicks::Now();
1174
1175 // Record encode latency of this frame.
1176 IdToTicks::iterator it =
1177 encode_start_time_per_frame_.find(num_encoded_frames_);
1178 CHECK_NE(it, encode_start_time_per_frame_.end());
1179 encode_latencies_.push_back(last_frame_ready_time_ - it->second);
1180 encode_start_time_per_frame_.erase(it);
1181
1137 ++num_encoded_frames_; 1182 ++num_encoded_frames_;
1138 ++num_frames_since_last_check_; 1183 ++num_frames_since_last_check_;
1139 1184
1140 last_frame_ready_time_ = base::TimeTicks::Now();
1141
1142 // Because the keyframe behavior requirements are loose, we give 1185 // Because the keyframe behavior requirements are loose, we give
1143 // the encoder more freedom here. It could either deliver a keyframe 1186 // the encoder more freedom here. It could either deliver a keyframe
1144 // immediately after we requested it, which could be for a frame number 1187 // immediately after we requested it, which could be for a frame number
1145 // before the one we requested it for (if the keyframe request 1188 // before the one we requested it for (if the keyframe request
1146 // is asynchronous, i.e. not bound to any concrete frame, and because 1189 // 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. 1190 // 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 1191 // 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 1192 // earlier than we requested one (in time), and not later than
1150 // kMaxKeyframeDelay frames after the frame, for which we requested 1193 // kMaxKeyframeDelay frames after the frame, for which we requested
1151 // it, comes back encoded. 1194 // it, comes back encoded.
(...skipping 23 matching lines...) Expand all
1175 } else if (num_encoded_frames_ == num_frames_to_encode_) { 1218 } else if (num_encoded_frames_ == num_frames_to_encode_) {
1176 VerifyPerf(); 1219 VerifyPerf();
1177 VerifyStreamProperties(); 1220 VerifyStreamProperties();
1178 SetState(CS_FINISHED); 1221 SetState(CS_FINISHED);
1179 return false; 1222 return false;
1180 } 1223 }
1181 1224
1182 return true; 1225 return true;
1183 } 1226 }
1184 1227
1185 void VEAClient::VerifyPerf() { 1228 void VEAClient::VerifyPerf() {
wuchengli 2015/05/07 05:39:09 s/VerifyPerf/LogPerf/ and move line 1234-1235 out
Justin Chuang 2015/05/07 08:33:45 Done.
1229 // Log measured FPS.
1186 double measured_fps = frames_per_second(); 1230 double measured_fps = frames_per_second();
1187 LOG(INFO) << "Measured encoder FPS: " << measured_fps; 1231 LOG(INFO) << "Measured encoder FPS: " << measured_fps;
1188 g_env->LogToFile("Measured encoder FPS", 1232 g_env->LogToFile("Measured encoder FPS",
1189 base::StringPrintf("%.3f", measured_fps)); 1233 base::StringPrintf("%.3f", measured_fps));
1190 if (test_perf_) 1234 if (test_perf_)
1191 EXPECT_GE(measured_fps, kMinPerfFPS); 1235 EXPECT_GE(measured_fps, kMinPerfFPS);
1236
1237 // Log encode latencies.
1238 std::sort(encode_latencies_.begin(), encode_latencies_.end());
1239 for (size_t i = 0; i < sizeof(kLoggedLatencyPercentages) / sizeof(float);
wuchengli 2015/05/07 05:39:09 can use arraysize of base/macros.h
Justin Chuang 2015/05/07 08:33:45 Done. Thanks
1240 i++) {
1241 float percentage_f = kLoggedLatencyPercentages[i];
1242 base::TimeDelta latency = percentile(encode_latencies_, percentage_f);
1243 int percentage = static_cast<int>(percentage_f * 100 + .5);
Owen Lin 2015/05/07 06:29:53 After a second thought, I think we should use roun
Justin Chuang 2015/05/07 08:33:45 I removed the typecast completely. No need to wast
1244 LOG(INFO) << "Encode latency at " << percentage
wuchengli 2015/05/07 05:39:09 Store the string in std::string and use it for bot
Justin Chuang 2015/05/07 08:33:45 I moved the LOG(INFO) to LogToFile(), saving a few
1245 << "%: " << latency.InMicroseconds() << " us";
1246 g_env->LogToFile(
wuchengli 2015/05/07 05:39:09 Add a comment saying the string have to match CrOS
Justin Chuang 2015/05/07 08:33:45 Added the comment on the LogToFile() method. Thx
1247 base::StringPrintf("Encode latency at %d%%", percentage),
1248 base::StringPrintf("%" PRId64 " us", latency.InMicroseconds()));
1249 }
1192 } 1250 }
1193 1251
1194 void VEAClient::VerifyStreamProperties() { 1252 void VEAClient::VerifyStreamProperties() {
1195 CHECK_GT(num_frames_since_last_check_, 0UL); 1253 CHECK_GT(num_frames_since_last_check_, 0UL);
1196 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); 1254 CHECK_GT(encoded_stream_size_since_last_check_, 0UL);
1197 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * 1255 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 *
1198 current_framerate_ / num_frames_since_last_check_; 1256 current_framerate_ / num_frames_since_last_check_;
1199 DVLOG(1) << "Current chunk's bitrate: " << bitrate 1257 DVLOG(1) << "Current chunk's bitrate: " << bitrate
1200 << " (expected: " << current_requested_bitrate_ 1258 << " (expected: " << current_requested_bitrate_
1201 << " @ " << current_framerate_ << " FPS," 1259 << " @ " << current_framerate_ << " FPS,"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1499 }
1442 1500
1443 content::g_env = 1501 content::g_env =
1444 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( 1502 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>(
1445 testing::AddGlobalTestEnvironment( 1503 testing::AddGlobalTestEnvironment(
1446 new content::VideoEncodeAcceleratorTestEnvironment( 1504 new content::VideoEncodeAcceleratorTestEnvironment(
1447 test_stream_data.Pass(), log_path, run_at_fps))); 1505 test_stream_data.Pass(), log_path, run_at_fps)));
1448 1506
1449 return RUN_ALL_TESTS(); 1507 return RUN_ALL_TESTS();
1450 } 1508 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698