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

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 WuCheng and 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 int32 kLoggedLatencyPercentages[] = {50, 75, 95};
Owen Lin 2015/05/07 09:53:45 Please change it back to using float. We have the
Justin Chuang 2015/05/07 10:13:18 Interesting. I'd prefer to keep the current code b
Pawel Osciak 2015/05/07 11:31:50 s/Percentages/Percentiles/ Do we need to use int3
Justin Chuang 2015/05/08 03:57:52 Done. also changed to uint32_t. Thx There are othe
Owen Lin 2015/05/08 05:59:52 I am OK with the code it is now. But my point is t
Pawel Osciak 2015/05/11 03:43:56 Thanks, but my point was we didn't explicitly need
Justin Chuang 2015/05/11 11:24:54 Got it. Changed. I thought we're using LP64 in arm
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
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 is parsing the output key and value pairs. Be
wuchengli 2015/05/07 09:22:17 s/is parsing/parses/
Justin Chuang 2015/05/07 10:01:16 Done.
395 // sure to keep the Autotest in sync.
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;
Pawel Osciak 2015/05/07 11:31:51 Is this to make it convenient for humans running t
Justin Chuang 2015/05/08 03:57:52 for human running the test manually. (even when --
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
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 // Return the number of encoded frames per second.
590 double frames_per_second();
591
592 // Return the percentile from a sorted array.
593 static base::TimeDelta percentile(
594 const std::vector<base::TimeDelta>& sorted_values,
595 float percentage);
596
586 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA(); 597 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA();
587 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); 598 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA();
588 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); 599 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA();
589 600
590 void SetState(ClientState new_state); 601 void SetState(ClientState new_state);
591 602
592 // Set current stream parameters to given |bitrate| at |framerate|. 603 // Set current stream parameters to given |bitrate| at |framerate|.
593 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); 604 void SetStreamParameters(unsigned int bitrate, unsigned int framerate);
594 605
595 // Called when encoder is done with a VideoFrame. 606 // Called when encoder is done with a VideoFrame.
596 void InputNoLongerNeededCallback(int32 input_id); 607 void InputNoLongerNeededCallback(int32 input_id);
597 608
598 // Feed the encoder with one input frame. 609 // Feed the encoder with one input frame.
599 void FeedEncoderWithOneInput(); 610 void FeedEncoderWithOneInput();
600 611
601 // Provide the encoder with a new output buffer. 612 // Provide the encoder with a new output buffer.
602 void FeedEncoderWithOutput(base::SharedMemory* shm); 613 void FeedEncoderWithOutput(base::SharedMemory* shm);
603 614
604 // Called on finding a complete frame (with |keyframe| set to true for 615 // Called on finding a complete frame (with |keyframe| set to true for
605 // keyframes) in the stream, to perform codec-independent, per-frame checks 616 // keyframes) in the stream, to perform codec-independent, per-frame checks
606 // and accounting. Returns false once we have collected all frames we needed. 617 // and accounting. Returns false once we have collected all frames we needed.
607 bool HandleEncodedFrame(bool keyframe); 618 bool HandleEncodedFrame(bool keyframe);
608 619
609 // Verify that stream bitrate has been close to current_requested_bitrate_, 620 // Verify that stream bitrate has been close to current_requested_bitrate_,
610 // assuming current_framerate_ since the last time VerifyStreamProperties() 621 // assuming current_framerate_ since the last time VerifyStreamProperties()
611 // was called. Fail the test if |force_bitrate_| is true and the bitrate 622 // was called. Fail the test if |force_bitrate_| is true and the bitrate
612 // is not within kBitrateTolerance. 623 // is not within kBitrateTolerance.
613 void VerifyStreamProperties(); 624 void VerifyStreamProperties();
614 625
615 // Test codec performance, failing the test if we are currently running 626 // Log the performance data.
616 // the performance test. 627 void LogPerf();
617 void VerifyPerf();
618 628
619 // Write IVF file header to test_stream_->out_filename. 629 // Write IVF file header to test_stream_->out_filename.
620 void WriteIvfFileHeader(); 630 void WriteIvfFileHeader();
621 631
622 // Write an IVF frame header to test_stream_->out_filename. 632 // Write an IVF frame header to test_stream_->out_filename.
623 void WriteIvfFrameHeader(int frame_index, size_t frame_size); 633 void WriteIvfFrameHeader(int frame_index, size_t frame_size);
624 634
625 // Prepare and return a frame wrapping the data at |position| bytes in 635 // Prepare and return a frame wrapping the data at |position| bytes in the
626 // the input stream, ready to be sent to encoder. 636 // input stream, ready to be sent to encoder.
627 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position); 637 // The input frame id is returned in |input_id|.
638 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position,
639 int32* input_id);
628 640
629 // Update the parameters according to |mid_stream_bitrate_switch| and 641 // Update the parameters according to |mid_stream_bitrate_switch| and
630 // |mid_stream_framerate_switch|. 642 // |mid_stream_framerate_switch|.
631 void UpdateTestStreamData(bool mid_stream_bitrate_switch, 643 void UpdateTestStreamData(bool mid_stream_bitrate_switch,
632 bool mid_stream_framerate_switch); 644 bool mid_stream_framerate_switch);
633 645
634 // Callback function of the |input_timer_|. 646 // Callback function of the |input_timer_|.
635 void OnInputTimer(); 647 void OnInputTimer();
636 648
637 ClientState state_; 649 ClientState state_;
638 scoped_ptr<VideoEncodeAccelerator> encoder_; 650 scoped_ptr<VideoEncodeAccelerator> encoder_;
639 651
640 TestStream* test_stream_; 652 TestStream* test_stream_;
641 653
642 // Used to notify another thread about the state. VEAClient does not own this. 654 // Used to notify another thread about the state. VEAClient does not own this.
643 ClientStateNotification<ClientState>* note_; 655 ClientStateNotification<ClientState>* note_;
644 656
645 // Ids assigned to VideoFrames (start at 1 for easy comparison with 657 // Ids assigned to VideoFrames.
646 // num_encoded_frames_).
647 std::set<int32> inputs_at_client_; 658 std::set<int32> inputs_at_client_;
648 int32 next_input_id_; 659 int32 next_input_id_;
649 660
661 typedef std::map<int32, base::TimeTicks> IdToTicks;
Pawel Osciak 2015/05/07 11:31:50 s/Id/InputId/
Justin Chuang 2015/05/08 03:57:52 Removed this typedef after changing data structure
662 // A map from input frame id to the encode start time of the frame.
663 IdToTicks frame_encode_start_ticks_;
wuchengli 2015/05/07 09:22:17 Hmm. The name is not consistent with |encode_start
Justin Chuang 2015/05/07 10:01:16 Done. Thanks. The code looks simpler.
Pawel Osciak 2015/05/07 11:31:50 Since we use input ids starting from 0 and increme
Justin Chuang 2015/05/08 03:57:52 Yes, already changed in patchset 6.
664 // The encode latencies of all encoded frames.
Pawel Osciak 2015/05/07 11:31:51 We should describe how we define latency. Maybe ",
Justin Chuang 2015/05/08 03:57:52 Yes, it's in commit message. Copied over here.
Pawel Osciak 2015/05/11 03:43:56 Thanks. Better to have it here for people reading
665 std::vector<base::TimeDelta> encode_latencies_;
666
650 // Ids for output BitstreamBuffers. 667 // Ids for output BitstreamBuffers.
651 typedef std::map<int32, base::SharedMemory*> IdToSHM; 668 typedef std::map<int32, base::SharedMemory*> IdToSHM;
652 ScopedVector<base::SharedMemory> output_shms_; 669 ScopedVector<base::SharedMemory> output_shms_;
653 IdToSHM output_buffers_at_client_; 670 IdToSHM output_buffers_at_client_;
654 int32 next_output_buffer_id_; 671 int32 next_output_buffer_id_;
655 672
656 // Current offset into input stream. 673 // Current offset into input stream.
657 off_t pos_in_input_stream_; 674 off_t pos_in_input_stream_;
658 gfx::Size input_coded_size_; 675 gfx::Size input_coded_size_;
659 // Requested by encoder. 676 // Requested by encoder.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 // Current requested bitrate. 708 // Current requested bitrate.
692 unsigned int current_requested_bitrate_; 709 unsigned int current_requested_bitrate_;
693 710
694 // Current expected framerate. 711 // Current expected framerate.
695 unsigned int current_framerate_; 712 unsigned int current_framerate_;
696 713
697 // Byte size of the encoded stream (for bitrate calculation) since last 714 // Byte size of the encoded stream (for bitrate calculation) since last
698 // time we checked bitrate. 715 // time we checked bitrate.
699 size_t encoded_stream_size_since_last_check_; 716 size_t encoded_stream_size_since_last_check_;
700 717
701 // If true, verify performance at the end of the test. 718 // If true, verify performance at the end of the test.
Pawel Osciak 2015/05/07 11:31:51 We should probably call this something like ensure
Pawel Osciak 2015/05/11 03:43:56 Could we do this please?
702 bool test_perf_; 719 bool test_perf_;
703 720
704 scoped_ptr<StreamValidator> validator_; 721 scoped_ptr<StreamValidator> validator_;
705 722
706 // The time when the encoding started. 723 // The time when the encoding started.
707 base::TimeTicks encode_start_time_; 724 base::TimeTicks encode_start_time_;
708 725
709 // The time when the last encoded frame is ready. 726 // The time when the last encoded frame is ready.
710 base::TimeTicks last_frame_ready_time_; 727 base::TimeTicks last_frame_ready_time_;
711 728
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 next_keyframe_at_(0), 777 next_keyframe_at_(0),
761 force_bitrate_(force_bitrate), 778 force_bitrate_(force_bitrate),
762 current_requested_bitrate_(0), 779 current_requested_bitrate_(0),
763 current_framerate_(0), 780 current_framerate_(0),
764 encoded_stream_size_since_last_check_(0), 781 encoded_stream_size_since_last_check_(0),
765 test_perf_(test_perf), 782 test_perf_(test_perf),
766 requested_bitrate_(0), 783 requested_bitrate_(0),
767 requested_framerate_(0), 784 requested_framerate_(0),
768 requested_subsequent_bitrate_(0), 785 requested_subsequent_bitrate_(0),
769 requested_subsequent_framerate_(0), 786 requested_subsequent_framerate_(0),
770 run_at_fps_(run_at_fps) { 787 run_at_fps_(run_at_fps) {
Pawel Osciak 2015/05/07 11:31:51 We should have a CHECK here that verifies that if
771 if (keyframe_period_) 788 if (keyframe_period_)
772 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); 789 CHECK_LT(kMaxKeyframeDelay, keyframe_period_);
773 790
774 // Fake encoder produces an invalid stream, so skip validating it. 791 // Fake encoder produces an invalid stream, so skip validating it.
775 if (!g_fake_encoder) { 792 if (!g_fake_encoder) {
776 validator_ = StreamValidator::Create( 793 validator_ = StreamValidator::Create(
777 test_stream_->requested_profile, 794 test_stream_->requested_profile,
778 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); 795 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this)));
779 CHECK(validator_); 796 CHECK(validator_);
780 } 797 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 } 925 }
909 if (requested_subsequent_framerate_ == 0) 926 if (requested_subsequent_framerate_ == 0)
910 requested_subsequent_framerate_ = 1; 927 requested_subsequent_framerate_ = 1;
911 } 928 }
912 929
913 double VEAClient::frames_per_second() { 930 double VEAClient::frames_per_second() {
914 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_; 931 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_;
915 return num_encoded_frames_ / duration.InSecondsF(); 932 return num_encoded_frames_ / duration.InSecondsF();
916 } 933 }
917 934
935 base::TimeDelta VEAClient::percentile(
Pawel Osciak 2015/05/07 11:31:51 I think this doesn't have to be a member method?
Justin Chuang 2015/05/08 03:57:52 It's class static private method. Shall I move to
Pawel Osciak 2015/05/11 03:43:56 Yes please.
Justin Chuang 2015/05/11 11:24:54 Done. BTW, I see many static functions in this fil
936 const std::vector<base::TimeDelta>& sorted_values,
937 float percentage) {
938 size_t size = sorted_values.size();
939 CHECK_NE(0, size);
Pawel Osciak 2015/05/07 11:31:51 CHECK_GT(size, 0) ?
Justin Chuang 2015/05/08 03:57:52 Done.
940 CHECK_GE(percentage, 0.0f);
941 CHECK_LE(percentage, 1.0f);
942 // Use Nearest Rank method.
943 size_t index =
944 std::min(base::checked_cast<size_t>(percentage * size), size - 1);
Pawel Osciak 2015/05/07 11:31:51 Is this to guard ourselves from getting a percenta
Justin Chuang 2015/05/08 03:57:52 Can't change to that. It overflows even when perce
945 return sorted_values[index];
946 }
947
918 void VEAClient::RequireBitstreamBuffers(unsigned int input_count, 948 void VEAClient::RequireBitstreamBuffers(unsigned int input_count,
919 const gfx::Size& input_coded_size, 949 const gfx::Size& input_coded_size,
920 size_t output_size) { 950 size_t output_size) {
921 DCHECK(thread_checker_.CalledOnValidThread()); 951 DCHECK(thread_checker_.CalledOnValidThread());
922 ASSERT_EQ(state_, CS_INITIALIZED); 952 ASSERT_EQ(state_, CS_INITIALIZED);
923 SetState(CS_ENCODING); 953 SetState(CS_ENCODING);
924 954
925 CreateAlignedInputStreamFile(input_coded_size, test_stream_); 955 CreateAlignedInputStreamFile(input_coded_size, test_stream_);
926 956
927 num_frames_to_encode_ = test_stream_->num_frames; 957 num_frames_to_encode_ = test_stream_->num_frames;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 } 1061 }
1032 1062
1033 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { 1063 void VEAClient::InputNoLongerNeededCallback(int32 input_id) {
1034 std::set<int32>::iterator it = inputs_at_client_.find(input_id); 1064 std::set<int32>::iterator it = inputs_at_client_.find(input_id);
1035 ASSERT_NE(it, inputs_at_client_.end()); 1065 ASSERT_NE(it, inputs_at_client_.end());
1036 inputs_at_client_.erase(it); 1066 inputs_at_client_.erase(it);
1037 if (!run_at_fps_) 1067 if (!run_at_fps_)
1038 FeedEncoderWithOneInput(); 1068 FeedEncoderWithOneInput();
1039 } 1069 }
1040 1070
1041 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { 1071 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position,
1072 int32* input_id) {
1042 CHECK_LE(position + test_stream_->aligned_buffer_size, 1073 CHECK_LE(position + test_stream_->aligned_buffer_size,
1043 test_stream_->mapped_aligned_in_file.length()); 1074 test_stream_->mapped_aligned_in_file.length());
1044 1075
1045 uint8* frame_data_y = const_cast<uint8*>( 1076 uint8* frame_data_y = const_cast<uint8*>(
1046 test_stream_->mapped_aligned_in_file.data() + position); 1077 test_stream_->mapped_aligned_in_file.data() + position);
1047 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; 1078 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]; 1079 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1];
1049 1080
1050 CHECK_GT(current_framerate_, 0U); 1081 CHECK_GT(current_framerate_, 0U);
1051 scoped_refptr<media::VideoFrame> frame = 1082 scoped_refptr<media::VideoFrame> frame =
(...skipping 10 matching lines...) Expand all
1062 frame_data_v, 1093 frame_data_v,
1063 base::TimeDelta().FromMilliseconds( 1094 base::TimeDelta().FromMilliseconds(
1064 next_input_id_ * base::Time::kMillisecondsPerSecond / 1095 next_input_id_ * base::Time::kMillisecondsPerSecond /
1065 current_framerate_), 1096 current_framerate_),
1066 media::BindToCurrentLoop( 1097 media::BindToCurrentLoop(
1067 base::Bind(&VEAClient::InputNoLongerNeededCallback, 1098 base::Bind(&VEAClient::InputNoLongerNeededCallback,
1068 base::Unretained(this), 1099 base::Unretained(this),
1069 next_input_id_))); 1100 next_input_id_)));
1070 1101
1071 CHECK(inputs_at_client_.insert(next_input_id_).second); 1102 CHECK(inputs_at_client_.insert(next_input_id_).second);
1072 ++next_input_id_;
1073 1103
1104 *input_id = next_input_id_++;
1074 return frame; 1105 return frame;
1075 } 1106 }
1076 1107
1077 void VEAClient::OnInputTimer() { 1108 void VEAClient::OnInputTimer() {
1078 if (!has_encoder() || state_ != CS_ENCODING) 1109 if (!has_encoder() || state_ != CS_ENCODING)
1079 input_timer_.reset(); 1110 input_timer_.reset();
1080 else if (inputs_at_client_.size() < 1111 else if (inputs_at_client_.size() <
1081 num_required_input_buffers_ + kNumExtraInputFrames) 1112 num_required_input_buffers_ + kNumExtraInputFrames)
1082 FeedEncoderWithOneInput(); 1113 FeedEncoderWithOneInput();
1083 else 1114 else
1084 DVLOG(1) << "Dropping input frame"; 1115 DVLOG(1) << "Dropping input frame";
1085 } 1116 }
1086 1117
1087 void VEAClient::FeedEncoderWithOneInput() { 1118 void VEAClient::FeedEncoderWithOneInput() {
1088 if (!has_encoder() || state_ != CS_ENCODING) 1119 if (!has_encoder() || state_ != CS_ENCODING)
1089 return; 1120 return;
1090 1121
1091 size_t bytes_left = 1122 size_t bytes_left =
1092 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; 1123 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_;
1093 if (bytes_left < test_stream_->aligned_buffer_size) { 1124 if (bytes_left < test_stream_->aligned_buffer_size) {
1094 DCHECK_EQ(bytes_left, 0UL); 1125 DCHECK_EQ(bytes_left, 0UL);
1095 // Rewind if at the end of stream and we are still encoding. 1126 // 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 1127 // 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 1128 // of the stream, or if the stream is shorter that the number of frames
1098 // we require for bitrate tests. 1129 // we require for bitrate tests.
1099 pos_in_input_stream_ = 0; 1130 pos_in_input_stream_ = 0;
1100 } 1131 }
1101 1132
1133 int32 input_id;
1134 scoped_refptr<media::VideoFrame> video_frame =
1135 PrepareInputFrame(pos_in_input_stream_, &input_id);
1136 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
1137
1102 bool force_keyframe = false; 1138 bool force_keyframe = false;
1103 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { 1139 if (keyframe_period_ && input_id % keyframe_period_ == 0) {
1104 force_keyframe = true; 1140 force_keyframe = true;
1105 ++num_keyframes_requested_; 1141 ++num_keyframes_requested_;
1106 } 1142 }
1107 1143
1108 scoped_refptr<media::VideoFrame> video_frame = 1144 CHECK(frame_encode_start_ticks_.insert(
1109 PrepareInputFrame(pos_in_input_stream_); 1145 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); 1146 encoder_->Encode(video_frame, force_keyframe);
1113 } 1147 }
1114 1148
1115 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { 1149 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) {
1116 if (!has_encoder()) 1150 if (!has_encoder())
1117 return; 1151 return;
1118 1152
1119 if (state_ != CS_ENCODING) 1153 if (state_ != CS_ENCODING)
1120 return; 1154 return;
1121 1155
1122 base::SharedMemoryHandle dup_handle; 1156 base::SharedMemoryHandle dup_handle;
1123 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); 1157 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle));
1124 1158
1125 media::BitstreamBuffer bitstream_buffer( 1159 media::BitstreamBuffer bitstream_buffer(
1126 next_output_buffer_id_++, dup_handle, output_buffer_size_); 1160 next_output_buffer_id_++, dup_handle, output_buffer_size_);
1127 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(), 1161 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(),
1128 shm)).second); 1162 shm)).second);
1129 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); 1163 encoder_->UseOutputBitstreamBuffer(bitstream_buffer);
1130 } 1164 }
1131 1165
1132 bool VEAClient::HandleEncodedFrame(bool keyframe) { 1166 bool VEAClient::HandleEncodedFrame(bool keyframe) {
1133 // This would be a bug in the test, which should not ignore false 1167 // This would be a bug in the test, which should not ignore false
1134 // return value from this method. 1168 // return value from this method.
1135 CHECK_LE(num_encoded_frames_, num_frames_to_encode_); 1169 CHECK_LE(num_encoded_frames_, num_frames_to_encode_);
1136 1170
1171 last_frame_ready_time_ = base::TimeTicks::Now();
1172
1173 // Record encode latency of this frame.
Pawel Osciak 2015/05/07 11:31:51 We should CHECK that run_at_fps is true if we are
Justin Chuang 2015/05/08 03:57:52 You're right! This value is used in autotest only
Pawel Osciak 2015/05/11 03:43:56 Why can't we CHECK it?
Justin Chuang 2015/05/11 11:24:54 Please see below.
1174 IdToTicks::iterator it = frame_encode_start_ticks_.find(num_encoded_frames_);
1175 CHECK_NE(it, frame_encode_start_ticks_.end());
1176 encode_latencies_.push_back(last_frame_ready_time_ - it->second);
1177 frame_encode_start_ticks_.erase(it);
1178
1137 ++num_encoded_frames_; 1179 ++num_encoded_frames_;
1138 ++num_frames_since_last_check_; 1180 ++num_frames_since_last_check_;
1139 1181
1140 last_frame_ready_time_ = base::TimeTicks::Now();
1141
1142 // Because the keyframe behavior requirements are loose, we give 1182 // Because the keyframe behavior requirements are loose, we give
1143 // the encoder more freedom here. It could either deliver a keyframe 1183 // the encoder more freedom here. It could either deliver a keyframe
1144 // immediately after we requested it, which could be for a frame number 1184 // immediately after we requested it, which could be for a frame number
1145 // before the one we requested it for (if the keyframe request 1185 // before the one we requested it for (if the keyframe request
1146 // is asynchronous, i.e. not bound to any concrete frame, and because 1186 // 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. 1187 // 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 1188 // 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 1189 // earlier than we requested one (in time), and not later than
1150 // kMaxKeyframeDelay frames after the frame, for which we requested 1190 // kMaxKeyframeDelay frames after the frame, for which we requested
1151 // it, comes back encoded. 1191 // it, comes back encoded.
(...skipping 14 matching lines...) Expand all
1166 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || 1206 if (requested_subsequent_bitrate_ != current_requested_bitrate_ ||
1167 requested_subsequent_framerate_ != current_framerate_) { 1207 requested_subsequent_framerate_ != current_framerate_) {
1168 SetStreamParameters(requested_subsequent_bitrate_, 1208 SetStreamParameters(requested_subsequent_bitrate_,
1169 requested_subsequent_framerate_); 1209 requested_subsequent_framerate_);
1170 if (run_at_fps_ && input_timer_) 1210 if (run_at_fps_ && input_timer_)
1171 input_timer_->Start( 1211 input_timer_->Start(
1172 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, 1212 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_,
1173 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); 1213 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this)));
1174 } 1214 }
1175 } else if (num_encoded_frames_ == num_frames_to_encode_) { 1215 } else if (num_encoded_frames_ == num_frames_to_encode_) {
1176 VerifyPerf(); 1216 LogPerf();
1177 VerifyStreamProperties(); 1217 VerifyStreamProperties();
1218 if (test_perf_)
Justin Chuang 2015/05/08 03:57:52 Added VerifyMinFPS() method
1219 EXPECT_GE(frames_per_second(), kMinPerfFPS);
1178 SetState(CS_FINISHED); 1220 SetState(CS_FINISHED);
1179 return false; 1221 return false;
1180 } 1222 }
1181 1223
1182 return true; 1224 return true;
1183 } 1225 }
1184 1226
1185 void VEAClient::VerifyPerf() { 1227 void VEAClient::LogPerf() {
1186 double measured_fps = frames_per_second(); 1228 // Log measured FPS.
1187 LOG(INFO) << "Measured encoder FPS: " << measured_fps;
1188 g_env->LogToFile("Measured encoder FPS", 1229 g_env->LogToFile("Measured encoder FPS",
1189 base::StringPrintf("%.3f", measured_fps)); 1230 base::StringPrintf("%.3f", frames_per_second()));
1190 if (test_perf_) 1231
1191 EXPECT_GE(measured_fps, kMinPerfFPS); 1232 // Log encode latencies.
1233 std::sort(encode_latencies_.begin(), encode_latencies_.end());
1234 for (size_t i = 0; i < arraysize(kLoggedLatencyPercentages); i++) {
1235 int32 percentage = kLoggedLatencyPercentages[i];
Pawel Osciak 2015/05/07 11:31:51 percentiles, also, no need for int32 specifically?
Justin Chuang 2015/05/08 03:57:52 Changed to p. percentile is method name.
1236 base::TimeDelta latency = percentile(encode_latencies_, 0.01f * percentage);
1237 g_env->LogToFile(
1238 base::StringPrintf("Encode latency at %d%%", percentage),
Owen Lin 2015/05/07 09:53:45 We can just use base::StringPrintf("Encode laten
Pawel Osciak 2015/05/07 11:31:50 Encode latency for %dth percentile:
Justin Chuang 2015/05/08 03:57:52 Done. Added 'the' since it's full sentence.
1239 base::StringPrintf("%" PRId64 " us", latency.InMicroseconds()));
1240 }
1192 } 1241 }
1193 1242
1194 void VEAClient::VerifyStreamProperties() { 1243 void VEAClient::VerifyStreamProperties() {
1195 CHECK_GT(num_frames_since_last_check_, 0UL); 1244 CHECK_GT(num_frames_since_last_check_, 0UL);
1196 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); 1245 CHECK_GT(encoded_stream_size_since_last_check_, 0UL);
1197 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * 1246 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 *
1198 current_framerate_ / num_frames_since_last_check_; 1247 current_framerate_ / num_frames_since_last_check_;
1199 DVLOG(1) << "Current chunk's bitrate: " << bitrate 1248 DVLOG(1) << "Current chunk's bitrate: " << bitrate
1200 << " (expected: " << current_requested_bitrate_ 1249 << " (expected: " << current_requested_bitrate_
1201 << " @ " << current_framerate_ << " FPS," 1250 << " @ " << current_framerate_ << " FPS,"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1490 }
1442 1491
1443 content::g_env = 1492 content::g_env =
1444 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( 1493 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>(
1445 testing::AddGlobalTestEnvironment( 1494 testing::AddGlobalTestEnvironment(
1446 new content::VideoEncodeAcceleratorTestEnvironment( 1495 new content::VideoEncodeAcceleratorTestEnvironment(
1447 test_stream_data.Pass(), log_path, run_at_fps))); 1496 test_stream_data.Pass(), log_path, run_at_fps)));
1448 1497
1449 return RUN_ALL_TESTS(); 1498 return RUN_ALL_TESTS();
1450 } 1499 }
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