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

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

Issue 1137643003: Revert of vea_unittest: Calculate per-frame encode latency (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
7 #include "base/at_exit.h" 5 #include "base/at_exit.h"
8 #include "base/bind.h" 6 #include "base/bind.h"
9 #include "base/command_line.h" 7 #include "base/command_line.h"
10 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
11 #include "base/files/memory_mapped_file.h" 9 #include "base/files/memory_mapped_file.h"
12 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
13 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
14 #include "base/process/process_handle.h" 12 #include "base/process/process_handle.h"
15 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Tolerance factor for how encoded bitrate can differ from requested bitrate. 63 // Tolerance factor for how encoded bitrate can differ from requested bitrate.
66 const double kBitrateTolerance = 0.1; 64 const double kBitrateTolerance = 0.1;
67 // Minimum required FPS throughput for the basic performance test. 65 // Minimum required FPS throughput for the basic performance test.
68 const uint32 kMinPerfFPS = 30; 66 const uint32 kMinPerfFPS = 30;
69 // Minimum (arbitrary) number of frames required to enforce bitrate requirements 67 // Minimum (arbitrary) number of frames required to enforce bitrate requirements
70 // over. Streams shorter than this may be too short to realistically require 68 // over. Streams shorter than this may be too short to realistically require
71 // an encoder to be able to converge to the requested bitrate over. 69 // an encoder to be able to converge to the requested bitrate over.
72 // The input stream will be looped as many times as needed in bitrate tests 70 // The input stream will be looped as many times as needed in bitrate tests
73 // to reach at least this number of frames before calculating final bitrate. 71 // to reach at least this number of frames before calculating final bitrate.
74 const unsigned int kMinFramesForBitrateTests = 300; 72 const unsigned int kMinFramesForBitrateTests = 300;
75 // The percentiles to measure for encode latency.
76 const unsigned int kLoggedLatencyPercentiles[] = {50, 75, 95};
77 73
78 // The syntax of multiple test streams is: 74 // The syntax of multiple test streams is:
79 // test-stream1;test-stream2;test-stream3 75 // test-stream1;test-stream2;test-stream3
80 // The syntax of each test stream is: 76 // The syntax of each test stream is:
81 // "in_filename:width:height:out_filename:requested_bitrate:requested_framerate 77 // "in_filename:width:height:out_filename:requested_bitrate:requested_framerate
82 // :requested_subsequent_bitrate:requested_subsequent_framerate" 78 // :requested_subsequent_bitrate:requested_subsequent_framerate"
83 // - |in_filename| must be an I420 (YUV planar) raw stream 79 // - |in_filename| must be an I420 (YUV planar) raw stream
84 // (see http://www.fourcc.org/yuv.php#IYUV). 80 // (see http://www.fourcc.org/yuv.php#IYUV).
85 // - |width| and |height| are in pixels. 81 // - |width| and |height| are in pixels.
86 // - |profile| to encode into (values of media::VideoCodecProfile). 82 // - |profile| to encode into (values of media::VideoCodecProfile).
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 int bytes = file->Write(offset + written_bytes, 183 int bytes = file->Write(offset + written_bytes,
188 reinterpret_cast<const char*>(data + written_bytes), 184 reinterpret_cast<const char*>(data + written_bytes),
189 size - written_bytes); 185 size - written_bytes);
190 if (bytes <= 0) 186 if (bytes <= 0)
191 return false; 187 return false;
192 written_bytes += bytes; 188 written_bytes += bytes;
193 } 189 }
194 return true; 190 return true;
195 } 191 }
196 192
197 // Return the |percentile| from a sorted vector.
198 static base::TimeDelta Percentile(
199 const std::vector<base::TimeDelta>& sorted_values,
200 unsigned int percentile) {
201 size_t size = sorted_values.size();
202 CHECK_GT(size, 0);
203 CHECK_LE(percentile, 100);
204 // Use Nearest Rank method in http://en.wikipedia.org/wiki/Percentile.
205 int index =
206 std::max(static_cast<int>(ceil(0.01f * percentile * size)) - 1, 0);
207 return sorted_values[index];
208 }
209
210 static bool IsH264(media::VideoCodecProfile profile) { 193 static bool IsH264(media::VideoCodecProfile profile) {
211 return profile >= media::H264PROFILE_MIN && profile <= media::H264PROFILE_MAX; 194 return profile >= media::H264PROFILE_MIN && profile <= media::H264PROFILE_MAX;
212 } 195 }
213 196
214 static bool IsVP8(media::VideoCodecProfile profile) { 197 static bool IsVP8(media::VideoCodecProfile profile) {
215 return profile >= media::VP8PROFILE_MIN && profile <= media::VP8PROFILE_MAX; 198 return profile >= media::VP8PROFILE_MIN && profile <= media::VP8PROFILE_MAX;
216 } 199 }
217 200
218 // ARM performs CPU cache management with CPU cache line granularity. We thus 201 // ARM performs CPU cache management with CPU cache line granularity. We thus
219 // need to ensure our buffers are CPU cache line-aligned (64 byte-aligned). 202 // need to ensure our buffers are CPU cache line-aligned (64 byte-aligned).
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // setup it once for all test cases. 354 // setup it once for all test cases.
372 // It helps 355 // It helps
373 // - maintain test stream data and other test settings. 356 // - maintain test stream data and other test settings.
374 // - clean up temporary aligned files. 357 // - clean up temporary aligned files.
375 // - output log to file. 358 // - output log to file.
376 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { 359 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment {
377 public: 360 public:
378 VideoEncodeAcceleratorTestEnvironment( 361 VideoEncodeAcceleratorTestEnvironment(
379 scoped_ptr<base::FilePath::StringType> data, 362 scoped_ptr<base::FilePath::StringType> data,
380 const base::FilePath& log_path, 363 const base::FilePath& log_path,
381 bool run_at_fps, 364 bool run_at_fps)
382 bool needs_encode_latency) 365 : run_at_fps_(run_at_fps),
383 : test_stream_data_(data.Pass()), 366 test_stream_data_(data.Pass()),
384 log_path_(log_path), 367 log_path_(log_path) {}
385 run_at_fps_(run_at_fps),
386 needs_encode_latency_(needs_encode_latency) {}
387 368
388 virtual void SetUp() { 369 virtual void SetUp() {
389 if (!log_path_.empty()) { 370 if (!log_path_.empty()) {
390 log_file_.reset(new base::File( 371 log_file_.reset(new base::File(
391 log_path_, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); 372 log_path_, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE));
392 CHECK(log_file_->IsValid()); 373 CHECK(log_file_->IsValid());
393 } 374 }
394 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); 375 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_);
395 } 376 }
396 377
397 virtual void TearDown() { 378 virtual void TearDown() {
398 for (size_t i = 0; i < test_streams_.size(); i++) { 379 for (size_t i = 0; i < test_streams_.size(); i++) {
399 base::DeleteFile(test_streams_[i]->aligned_in_file, false); 380 base::DeleteFile(test_streams_[i]->aligned_in_file, false);
400 } 381 }
401 log_file_.reset(); 382 log_file_.reset();
402 } 383 }
403 384
404 // Log one entry of machine-readable data to file and LOG(INFO). 385 // Log one entry of machine-readable data to file.
405 // The log has one data entry per line in the format of "<key>: <value>". 386 // The log has one data entry per line in the format of "<key>: <value>".
406 // Note that Chrome OS video_VEAPerf autotest parses the output key and value
407 // pairs. Be sure to keep the autotest in sync.
408 void LogToFile(const std::string& key, const std::string& value) { 387 void LogToFile(const std::string& key, const std::string& value) {
409 std::string s = base::StringPrintf("%s: %s\n", key.c_str(), value.c_str());
410 LOG(INFO) << s;
411 if (log_file_) { 388 if (log_file_) {
389 std::string s =
390 base::StringPrintf("%s: %s\n", key.c_str(), value.c_str());
412 log_file_->WriteAtCurrentPos(s.data(), s.length()); 391 log_file_->WriteAtCurrentPos(s.data(), s.length());
413 } 392 }
414 } 393 }
415 394
416 // Feed the encoder with the input buffers at the requested framerate. If
417 // false, feed as fast as possible. This is set by the command line switch
418 // "--run_at_fps".
419 bool run_at_fps() const { return run_at_fps_; }
420
421 // Whether to measure encode latency. This is set by the command line switch
422 // "--measure_latency".
423 bool needs_encode_latency() const { return needs_encode_latency_; }
424
425 ScopedVector<TestStream> test_streams_; 395 ScopedVector<TestStream> test_streams_;
396 bool run_at_fps_;
426 397
427 private: 398 private:
428 scoped_ptr<base::FilePath::StringType> test_stream_data_; 399 scoped_ptr<base::FilePath::StringType> test_stream_data_;
429 base::FilePath log_path_; 400 base::FilePath log_path_;
430 scoped_ptr<base::File> log_file_; 401 scoped_ptr<base::File> log_file_;
431 bool run_at_fps_;
432 bool needs_encode_latency_;
433 }; 402 };
434 403
435 enum ClientState { 404 enum ClientState {
436 CS_CREATED, 405 CS_CREATED,
437 CS_ENCODER_SET, 406 CS_ENCODER_SET,
438 CS_INITIALIZED, 407 CS_INITIALIZED,
439 CS_ENCODING, 408 CS_ENCODING,
440 CS_FINISHED, 409 CS_FINISHED,
441 CS_ERROR, 410 CS_ERROR,
442 }; 411 };
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 552
584 class VEAClient : public VideoEncodeAccelerator::Client { 553 class VEAClient : public VideoEncodeAccelerator::Client {
585 public: 554 public:
586 VEAClient(TestStream* test_stream, 555 VEAClient(TestStream* test_stream,
587 ClientStateNotification<ClientState>* note, 556 ClientStateNotification<ClientState>* note,
588 bool save_to_file, 557 bool save_to_file,
589 unsigned int keyframe_period, 558 unsigned int keyframe_period,
590 bool force_bitrate, 559 bool force_bitrate,
591 bool test_perf, 560 bool test_perf,
592 bool mid_stream_bitrate_switch, 561 bool mid_stream_bitrate_switch,
593 bool mid_stream_framerate_switch); 562 bool mid_stream_framerate_switch,
563 bool run_at_fps);
594 ~VEAClient() override; 564 ~VEAClient() override;
595 void CreateEncoder(); 565 void CreateEncoder();
596 void DestroyEncoder(); 566 void DestroyEncoder();
597 567
568 // Return the number of encoded frames per second.
569 double frames_per_second();
570
598 // VideoDecodeAccelerator::Client implementation. 571 // VideoDecodeAccelerator::Client implementation.
599 void RequireBitstreamBuffers(unsigned int input_count, 572 void RequireBitstreamBuffers(unsigned int input_count,
600 const gfx::Size& input_coded_size, 573 const gfx::Size& input_coded_size,
601 size_t output_buffer_size) override; 574 size_t output_buffer_size) override;
602 void BitstreamBufferReady(int32 bitstream_buffer_id, 575 void BitstreamBufferReady(int32 bitstream_buffer_id,
603 size_t payload_size, 576 size_t payload_size,
604 bool key_frame) override; 577 bool key_frame) override;
605 void NotifyError(VideoEncodeAccelerator::Error error) override; 578 void NotifyError(VideoEncodeAccelerator::Error error) override;
606 579
607 private: 580 private:
608 bool has_encoder() { return encoder_.get(); } 581 bool has_encoder() { return encoder_.get(); }
609 582
610 // Return the number of encoded frames per second.
611 double frames_per_second();
612
613 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA(); 583 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA();
614 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); 584 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA();
615 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); 585 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA();
616 586
617 void SetState(ClientState new_state); 587 void SetState(ClientState new_state);
618 588
619 // Set current stream parameters to given |bitrate| at |framerate|. 589 // Set current stream parameters to given |bitrate| at |framerate|.
620 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); 590 void SetStreamParameters(unsigned int bitrate, unsigned int framerate);
621 591
622 // Called when encoder is done with a VideoFrame. 592 // Called when encoder is done with a VideoFrame.
623 void InputNoLongerNeededCallback(int32 input_id); 593 void InputNoLongerNeededCallback(int32 input_id);
624 594
625 // Feed the encoder with one input frame. 595 // Feed the encoder with one input frame.
626 void FeedEncoderWithOneInput(); 596 void FeedEncoderWithOneInput();
627 597
628 // Provide the encoder with a new output buffer. 598 // Provide the encoder with a new output buffer.
629 void FeedEncoderWithOutput(base::SharedMemory* shm); 599 void FeedEncoderWithOutput(base::SharedMemory* shm);
630 600
631 // Called on finding a complete frame (with |keyframe| set to true for 601 // Called on finding a complete frame (with |keyframe| set to true for
632 // keyframes) in the stream, to perform codec-independent, per-frame checks 602 // keyframes) in the stream, to perform codec-independent, per-frame checks
633 // and accounting. Returns false once we have collected all frames we needed. 603 // and accounting. Returns false once we have collected all frames we needed.
634 bool HandleEncodedFrame(bool keyframe); 604 bool HandleEncodedFrame(bool keyframe);
635 605
636 // Verify the minimum FPS requirement.
637 void VerifyMinFPS();
638
639 // Verify that stream bitrate has been close to current_requested_bitrate_, 606 // Verify that stream bitrate has been close to current_requested_bitrate_,
640 // assuming current_framerate_ since the last time VerifyStreamProperties() 607 // assuming current_framerate_ since the last time VerifyStreamProperties()
641 // was called. Fail the test if |force_bitrate_| is true and the bitrate 608 // was called. Fail the test if |force_bitrate_| is true and the bitrate
642 // is not within kBitrateTolerance. 609 // is not within kBitrateTolerance.
643 void VerifyStreamProperties(); 610 void VerifyStreamProperties();
644 611
645 // Log the performance data. 612 // Test codec performance, failing the test if we are currently running
646 void LogPerf(); 613 // the performance test.
614 void VerifyPerf();
647 615
648 // Write IVF file header to test_stream_->out_filename. 616 // Write IVF file header to test_stream_->out_filename.
649 void WriteIvfFileHeader(); 617 void WriteIvfFileHeader();
650 618
651 // Write an IVF frame header to test_stream_->out_filename. 619 // Write an IVF frame header to test_stream_->out_filename.
652 void WriteIvfFrameHeader(int frame_index, size_t frame_size); 620 void WriteIvfFrameHeader(int frame_index, size_t frame_size);
653 621
654 // Prepare and return a frame wrapping the data at |position| bytes in the 622 // Prepare and return a frame wrapping the data at |position| bytes in
655 // input stream, ready to be sent to encoder. 623 // the input stream, ready to be sent to encoder.
656 // The input frame id is returned in |input_id|. 624 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position);
657 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position,
658 int32* input_id);
659 625
660 // Update the parameters according to |mid_stream_bitrate_switch| and 626 // Update the parameters according to |mid_stream_bitrate_switch| and
661 // |mid_stream_framerate_switch|. 627 // |mid_stream_framerate_switch|.
662 void UpdateTestStreamData(bool mid_stream_bitrate_switch, 628 void UpdateTestStreamData(bool mid_stream_bitrate_switch,
663 bool mid_stream_framerate_switch); 629 bool mid_stream_framerate_switch);
664 630
665 // Callback function of the |input_timer_|. 631 // Callback function of the |input_timer_|.
666 void OnInputTimer(); 632 void OnInputTimer();
667 633
668 ClientState state_; 634 ClientState state_;
669 scoped_ptr<VideoEncodeAccelerator> encoder_; 635 scoped_ptr<VideoEncodeAccelerator> encoder_;
670 636
671 TestStream* test_stream_; 637 TestStream* test_stream_;
672 638
673 // Used to notify another thread about the state. VEAClient does not own this. 639 // Used to notify another thread about the state. VEAClient does not own this.
674 ClientStateNotification<ClientState>* note_; 640 ClientStateNotification<ClientState>* note_;
675 641
676 // Ids assigned to VideoFrames. 642 // Ids assigned to VideoFrames (start at 1 for easy comparison with
643 // num_encoded_frames_).
677 std::set<int32> inputs_at_client_; 644 std::set<int32> inputs_at_client_;
678 int32 next_input_id_; 645 int32 next_input_id_;
679 646
680 // Encode start time of all encoded frames. The position in the vector is the
681 // frame input id.
682 std::vector<base::TimeTicks> encode_start_time_;
683 // The encode latencies of all encoded frames. We define encode latency as the
684 // time delay from input of each VideoFrame (VEA::Encode()) to output of the
685 // corresponding BitstreamBuffer (VEA::Client::BitstreamBufferReady()).
686 std::vector<base::TimeDelta> encode_latencies_;
687
688 // Ids for output BitstreamBuffers. 647 // Ids for output BitstreamBuffers.
689 typedef std::map<int32, base::SharedMemory*> IdToSHM; 648 typedef std::map<int32, base::SharedMemory*> IdToSHM;
690 ScopedVector<base::SharedMemory> output_shms_; 649 ScopedVector<base::SharedMemory> output_shms_;
691 IdToSHM output_buffers_at_client_; 650 IdToSHM output_buffers_at_client_;
692 int32 next_output_buffer_id_; 651 int32 next_output_buffer_id_;
693 652
694 // Current offset into input stream. 653 // Current offset into input stream.
695 off_t pos_in_input_stream_; 654 off_t pos_in_input_stream_;
696 gfx::Size input_coded_size_; 655 gfx::Size input_coded_size_;
697 // Requested by encoder. 656 // Requested by encoder.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 693
735 // Byte size of the encoded stream (for bitrate calculation) since last 694 // Byte size of the encoded stream (for bitrate calculation) since last
736 // time we checked bitrate. 695 // time we checked bitrate.
737 size_t encoded_stream_size_since_last_check_; 696 size_t encoded_stream_size_since_last_check_;
738 697
739 // If true, verify performance at the end of the test. 698 // If true, verify performance at the end of the test.
740 bool test_perf_; 699 bool test_perf_;
741 700
742 scoped_ptr<StreamValidator> validator_; 701 scoped_ptr<StreamValidator> validator_;
743 702
703 // The time when the encoding started.
704 base::TimeTicks encode_start_time_;
705
744 // The time when the last encoded frame is ready. 706 // The time when the last encoded frame is ready.
745 base::TimeTicks last_frame_ready_time_; 707 base::TimeTicks last_frame_ready_time_;
746 708
747 // All methods of this class should be run on the same thread. 709 // All methods of this class should be run on the same thread.
748 base::ThreadChecker thread_checker_; 710 base::ThreadChecker thread_checker_;
749 711
750 // Requested bitrate in bits per second. 712 // Requested bitrate in bits per second.
751 unsigned int requested_bitrate_; 713 unsigned int requested_bitrate_;
752 714
753 // Requested initial framerate. 715 // Requested initial framerate.
754 unsigned int requested_framerate_; 716 unsigned int requested_framerate_;
755 717
756 // Bitrate to switch to in the middle of the stream. 718 // Bitrate to switch to in the middle of the stream.
757 unsigned int requested_subsequent_bitrate_; 719 unsigned int requested_subsequent_bitrate_;
758 720
759 // Framerate to switch to in the middle of the stream. 721 // Framerate to switch to in the middle of the stream.
760 unsigned int requested_subsequent_framerate_; 722 unsigned int requested_subsequent_framerate_;
761 723
762 // The timer used to feed the encoder with the input frames. 724 // The timer used to feed the encoder with the input frames.
763 scoped_ptr<base::RepeatingTimer<VEAClient>> input_timer_; 725 scoped_ptr<base::RepeatingTimer<VEAClient>> input_timer_;
726
727 // Feed the encoder with the input buffers at the |requested_framerate_|. If
728 // false, feed as fast as possible. This is set by the command line switch
729 // "--run_at_fps".
730 bool run_at_fps_;
764 }; 731 };
765 732
766 VEAClient::VEAClient(TestStream* test_stream, 733 VEAClient::VEAClient(TestStream* test_stream,
767 ClientStateNotification<ClientState>* note, 734 ClientStateNotification<ClientState>* note,
768 bool save_to_file, 735 bool save_to_file,
769 unsigned int keyframe_period, 736 unsigned int keyframe_period,
770 bool force_bitrate, 737 bool force_bitrate,
771 bool test_perf, 738 bool test_perf,
772 bool mid_stream_bitrate_switch, 739 bool mid_stream_bitrate_switch,
773 bool mid_stream_framerate_switch) 740 bool mid_stream_framerate_switch,
741 bool run_at_fps)
774 : state_(CS_CREATED), 742 : state_(CS_CREATED),
775 test_stream_(test_stream), 743 test_stream_(test_stream),
776 note_(note), 744 note_(note),
777 next_input_id_(0), 745 next_input_id_(0),
778 next_output_buffer_id_(0), 746 next_output_buffer_id_(0),
779 pos_in_input_stream_(0), 747 pos_in_input_stream_(0),
780 num_required_input_buffers_(0), 748 num_required_input_buffers_(0),
781 output_buffer_size_(0), 749 output_buffer_size_(0),
782 num_frames_to_encode_(0), 750 num_frames_to_encode_(0),
783 num_encoded_frames_(0), 751 num_encoded_frames_(0),
784 num_frames_since_last_check_(0), 752 num_frames_since_last_check_(0),
785 seen_keyframe_in_this_buffer_(false), 753 seen_keyframe_in_this_buffer_(false),
786 save_to_file_(save_to_file), 754 save_to_file_(save_to_file),
787 keyframe_period_(keyframe_period), 755 keyframe_period_(keyframe_period),
788 num_keyframes_requested_(0), 756 num_keyframes_requested_(0),
789 next_keyframe_at_(0), 757 next_keyframe_at_(0),
790 force_bitrate_(force_bitrate), 758 force_bitrate_(force_bitrate),
791 current_requested_bitrate_(0), 759 current_requested_bitrate_(0),
792 current_framerate_(0), 760 current_framerate_(0),
793 encoded_stream_size_since_last_check_(0), 761 encoded_stream_size_since_last_check_(0),
794 test_perf_(test_perf), 762 test_perf_(test_perf),
795 requested_bitrate_(0), 763 requested_bitrate_(0),
796 requested_framerate_(0), 764 requested_framerate_(0),
797 requested_subsequent_bitrate_(0), 765 requested_subsequent_bitrate_(0),
798 requested_subsequent_framerate_(0) { 766 requested_subsequent_framerate_(0),
767 run_at_fps_(run_at_fps) {
799 if (keyframe_period_) 768 if (keyframe_period_)
800 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); 769 CHECK_LT(kMaxKeyframeDelay, keyframe_period_);
801 770
802 // Fake encoder produces an invalid stream, so skip validating it. 771 // Fake encoder produces an invalid stream, so skip validating it.
803 if (!g_fake_encoder) { 772 if (!g_fake_encoder) {
804 validator_ = StreamValidator::Create( 773 validator_ = StreamValidator::Create(
805 test_stream_->requested_profile, 774 test_stream_->requested_profile,
806 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); 775 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this)));
807 CHECK(validator_); 776 CHECK(validator_);
808 } 777 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 requested_subsequent_framerate_ = 901 requested_subsequent_framerate_ =
933 test_stream_->requested_subsequent_framerate; 902 test_stream_->requested_subsequent_framerate;
934 } else { 903 } else {
935 requested_subsequent_framerate_ = requested_framerate_; 904 requested_subsequent_framerate_ = requested_framerate_;
936 } 905 }
937 if (requested_subsequent_framerate_ == 0) 906 if (requested_subsequent_framerate_ == 0)
938 requested_subsequent_framerate_ = 1; 907 requested_subsequent_framerate_ = 1;
939 } 908 }
940 909
941 double VEAClient::frames_per_second() { 910 double VEAClient::frames_per_second() {
942 CHECK(!encode_start_time_.empty()); 911 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_;
943 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_[0];
944 return num_encoded_frames_ / duration.InSecondsF(); 912 return num_encoded_frames_ / duration.InSecondsF();
945 } 913 }
946 914
947 void VEAClient::RequireBitstreamBuffers(unsigned int input_count, 915 void VEAClient::RequireBitstreamBuffers(unsigned int input_count,
948 const gfx::Size& input_coded_size, 916 const gfx::Size& input_coded_size,
949 size_t output_size) { 917 size_t output_size) {
950 DCHECK(thread_checker_.CalledOnValidThread()); 918 DCHECK(thread_checker_.CalledOnValidThread());
951 ASSERT_EQ(state_, CS_INITIALIZED); 919 ASSERT_EQ(state_, CS_INITIALIZED);
952 SetState(CS_ENCODING); 920 SetState(CS_ENCODING);
953 921
954 CreateAlignedInputStreamFile(input_coded_size, test_stream_); 922 CreateAlignedInputStreamFile(input_coded_size, test_stream_);
955 923
956 num_frames_to_encode_ = test_stream_->num_frames; 924 num_frames_to_encode_ = test_stream_->num_frames;
957 if (g_num_frames_to_encode > 0) 925 if (g_num_frames_to_encode > 0)
958 num_frames_to_encode_ = g_num_frames_to_encode; 926 num_frames_to_encode_ = g_num_frames_to_encode;
959 927
960 // Speed up vector insertion.
961 encode_start_time_.reserve(num_frames_to_encode_);
962 if (g_env->needs_encode_latency())
963 encode_latencies_.reserve(num_frames_to_encode_);
964
965 // We may need to loop over the stream more than once if more frames than 928 // We may need to loop over the stream more than once if more frames than
966 // provided is required for bitrate tests. 929 // provided is required for bitrate tests.
967 if (force_bitrate_ && num_frames_to_encode_ < kMinFramesForBitrateTests) { 930 if (force_bitrate_ && num_frames_to_encode_ < kMinFramesForBitrateTests) {
968 DVLOG(1) << "Stream too short for bitrate test (" 931 DVLOG(1) << "Stream too short for bitrate test ("
969 << test_stream_->num_frames << " frames), will loop it to reach " 932 << test_stream_->num_frames << " frames), will loop it to reach "
970 << kMinFramesForBitrateTests << " frames"; 933 << kMinFramesForBitrateTests << " frames";
971 num_frames_to_encode_ = kMinFramesForBitrateTests; 934 num_frames_to_encode_ = kMinFramesForBitrateTests;
972 } 935 }
973 if (save_to_file_ && IsVP8(test_stream_->requested_profile)) 936 if (save_to_file_ && IsVP8(test_stream_->requested_profile))
974 WriteIvfFileHeader(); 937 WriteIvfFileHeader();
975 938
976 input_coded_size_ = input_coded_size; 939 input_coded_size_ = input_coded_size;
977 num_required_input_buffers_ = input_count; 940 num_required_input_buffers_ = input_count;
978 ASSERT_GT(num_required_input_buffers_, 0UL); 941 ASSERT_GT(num_required_input_buffers_, 0UL);
979 942
980 output_buffer_size_ = output_size; 943 output_buffer_size_ = output_size;
981 ASSERT_GT(output_buffer_size_, 0UL); 944 ASSERT_GT(output_buffer_size_, 0UL);
982 945
983 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { 946 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) {
984 base::SharedMemory* shm = new base::SharedMemory(); 947 base::SharedMemory* shm = new base::SharedMemory();
985 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); 948 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_));
986 output_shms_.push_back(shm); 949 output_shms_.push_back(shm);
987 FeedEncoderWithOutput(shm); 950 FeedEncoderWithOutput(shm);
988 } 951 }
989 952
990 if (g_env->run_at_fps()) { 953 encode_start_time_ = base::TimeTicks::Now();
954 if (run_at_fps_) {
991 input_timer_.reset(new base::RepeatingTimer<VEAClient>()); 955 input_timer_.reset(new base::RepeatingTimer<VEAClient>());
992 input_timer_->Start( 956 input_timer_->Start(
993 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, 957 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_,
994 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); 958 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this)));
995 } else { 959 } else {
996 while (inputs_at_client_.size() < 960 while (inputs_at_client_.size() <
997 num_required_input_buffers_ + kNumExtraInputFrames) 961 num_required_input_buffers_ + kNumExtraInputFrames)
998 FeedEncoderWithOneInput(); 962 FeedEncoderWithOneInput();
999 } 963 }
1000 } 964 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, 1024 encoder_->RequestEncodingParametersChange(current_requested_bitrate_,
1061 current_framerate_); 1025 current_framerate_);
1062 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ 1026 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_
1063 << " bps @ " << current_framerate_ << " FPS"; 1027 << " bps @ " << current_framerate_ << " FPS";
1064 } 1028 }
1065 1029
1066 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { 1030 void VEAClient::InputNoLongerNeededCallback(int32 input_id) {
1067 std::set<int32>::iterator it = inputs_at_client_.find(input_id); 1031 std::set<int32>::iterator it = inputs_at_client_.find(input_id);
1068 ASSERT_NE(it, inputs_at_client_.end()); 1032 ASSERT_NE(it, inputs_at_client_.end());
1069 inputs_at_client_.erase(it); 1033 inputs_at_client_.erase(it);
1070 if (!g_env->run_at_fps()) 1034 if (!run_at_fps_)
1071 FeedEncoderWithOneInput(); 1035 FeedEncoderWithOneInput();
1072 } 1036 }
1073 1037
1074 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position, 1038 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) {
1075 int32* input_id) {
1076 CHECK_LE(position + test_stream_->aligned_buffer_size, 1039 CHECK_LE(position + test_stream_->aligned_buffer_size,
1077 test_stream_->mapped_aligned_in_file.length()); 1040 test_stream_->mapped_aligned_in_file.length());
1078 1041
1079 uint8* frame_data_y = const_cast<uint8*>( 1042 uint8* frame_data_y = const_cast<uint8*>(
1080 test_stream_->mapped_aligned_in_file.data() + position); 1043 test_stream_->mapped_aligned_in_file.data() + position);
1081 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; 1044 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0];
1082 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1]; 1045 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1];
1083 1046
1084 CHECK_GT(current_framerate_, 0U); 1047 CHECK_GT(current_framerate_, 0U);
1085 scoped_refptr<media::VideoFrame> frame = 1048 scoped_refptr<media::VideoFrame> frame =
(...skipping 10 matching lines...) Expand all
1096 frame_data_v, 1059 frame_data_v,
1097 base::TimeDelta().FromMilliseconds( 1060 base::TimeDelta().FromMilliseconds(
1098 next_input_id_ * base::Time::kMillisecondsPerSecond / 1061 next_input_id_ * base::Time::kMillisecondsPerSecond /
1099 current_framerate_), 1062 current_framerate_),
1100 media::BindToCurrentLoop( 1063 media::BindToCurrentLoop(
1101 base::Bind(&VEAClient::InputNoLongerNeededCallback, 1064 base::Bind(&VEAClient::InputNoLongerNeededCallback,
1102 base::Unretained(this), 1065 base::Unretained(this),
1103 next_input_id_))); 1066 next_input_id_)));
1104 1067
1105 CHECK(inputs_at_client_.insert(next_input_id_).second); 1068 CHECK(inputs_at_client_.insert(next_input_id_).second);
1069 ++next_input_id_;
1106 1070
1107 *input_id = next_input_id_++;
1108 return frame; 1071 return frame;
1109 } 1072 }
1110 1073
1111 void VEAClient::OnInputTimer() { 1074 void VEAClient::OnInputTimer() {
1112 if (!has_encoder() || state_ != CS_ENCODING) 1075 if (!has_encoder() || state_ != CS_ENCODING)
1113 input_timer_.reset(); 1076 input_timer_.reset();
1114 else if (inputs_at_client_.size() < 1077 else if (inputs_at_client_.size() <
1115 num_required_input_buffers_ + kNumExtraInputFrames) 1078 num_required_input_buffers_ + kNumExtraInputFrames)
1116 FeedEncoderWithOneInput(); 1079 FeedEncoderWithOneInput();
1117 else 1080 else
1118 DVLOG(1) << "Dropping input frame"; 1081 DVLOG(1) << "Dropping input frame";
1119 } 1082 }
1120 1083
1121 void VEAClient::FeedEncoderWithOneInput() { 1084 void VEAClient::FeedEncoderWithOneInput() {
1122 if (!has_encoder() || state_ != CS_ENCODING) 1085 if (!has_encoder() || state_ != CS_ENCODING)
1123 return; 1086 return;
1124 1087
1125 size_t bytes_left = 1088 size_t bytes_left =
1126 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; 1089 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_;
1127 if (bytes_left < test_stream_->aligned_buffer_size) { 1090 if (bytes_left < test_stream_->aligned_buffer_size) {
1128 DCHECK_EQ(bytes_left, 0UL); 1091 DCHECK_EQ(bytes_left, 0UL);
1129 // Rewind if at the end of stream and we are still encoding. 1092 // Rewind if at the end of stream and we are still encoding.
1130 // This is to flush the encoder with additional frames from the beginning 1093 // This is to flush the encoder with additional frames from the beginning
1131 // of the stream, or if the stream is shorter that the number of frames 1094 // of the stream, or if the stream is shorter that the number of frames
1132 // we require for bitrate tests. 1095 // we require for bitrate tests.
1133 pos_in_input_stream_ = 0; 1096 pos_in_input_stream_ = 0;
1134 } 1097 }
1135 1098
1136 int32 input_id;
1137 scoped_refptr<media::VideoFrame> video_frame =
1138 PrepareInputFrame(pos_in_input_stream_, &input_id);
1139 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
1140
1141 bool force_keyframe = false; 1099 bool force_keyframe = false;
1142 if (keyframe_period_ && input_id % keyframe_period_ == 0) { 1100 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) {
1143 force_keyframe = true; 1101 force_keyframe = true;
1144 ++num_keyframes_requested_; 1102 ++num_keyframes_requested_;
1145 } 1103 }
1146 1104
1147 CHECK_EQ(input_id, static_cast<int32>(encode_start_time_.size())); 1105 scoped_refptr<media::VideoFrame> video_frame =
1148 encode_start_time_.push_back(base::TimeTicks::Now()); 1106 PrepareInputFrame(pos_in_input_stream_);
1107 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
1108
1149 encoder_->Encode(video_frame, force_keyframe); 1109 encoder_->Encode(video_frame, force_keyframe);
1150 } 1110 }
1151 1111
1152 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { 1112 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) {
1153 if (!has_encoder()) 1113 if (!has_encoder())
1154 return; 1114 return;
1155 1115
1156 if (state_ != CS_ENCODING) 1116 if (state_ != CS_ENCODING)
1157 return; 1117 return;
1158 1118
1159 base::SharedMemoryHandle dup_handle; 1119 base::SharedMemoryHandle dup_handle;
1160 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); 1120 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle));
1161 1121
1162 media::BitstreamBuffer bitstream_buffer( 1122 media::BitstreamBuffer bitstream_buffer(
1163 next_output_buffer_id_++, dup_handle, output_buffer_size_); 1123 next_output_buffer_id_++, dup_handle, output_buffer_size_);
1164 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(), 1124 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(),
1165 shm)).second); 1125 shm)).second);
1166 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); 1126 encoder_->UseOutputBitstreamBuffer(bitstream_buffer);
1167 } 1127 }
1168 1128
1169 bool VEAClient::HandleEncodedFrame(bool keyframe) { 1129 bool VEAClient::HandleEncodedFrame(bool keyframe) {
1170 // This would be a bug in the test, which should not ignore false 1130 // This would be a bug in the test, which should not ignore false
1171 // return value from this method. 1131 // return value from this method.
1172 CHECK_LE(num_encoded_frames_, num_frames_to_encode_); 1132 CHECK_LE(num_encoded_frames_, num_frames_to_encode_);
1173 1133
1174 last_frame_ready_time_ = base::TimeTicks::Now();
1175
1176 if (g_env->needs_encode_latency()) {
1177 CHECK_LT(num_encoded_frames_, encode_start_time_.size());
1178 base::TimeTicks start_time = encode_start_time_[num_encoded_frames_];
1179 CHECK(!start_time.is_null());
1180 encode_latencies_.push_back(last_frame_ready_time_ - start_time);
1181 }
1182
1183 ++num_encoded_frames_; 1134 ++num_encoded_frames_;
1184 ++num_frames_since_last_check_; 1135 ++num_frames_since_last_check_;
1185 1136
1137 last_frame_ready_time_ = base::TimeTicks::Now();
1138
1186 // Because the keyframe behavior requirements are loose, we give 1139 // Because the keyframe behavior requirements are loose, we give
1187 // the encoder more freedom here. It could either deliver a keyframe 1140 // the encoder more freedom here. It could either deliver a keyframe
1188 // immediately after we requested it, which could be for a frame number 1141 // immediately after we requested it, which could be for a frame number
1189 // before the one we requested it for (if the keyframe request 1142 // before the one we requested it for (if the keyframe request
1190 // is asynchronous, i.e. not bound to any concrete frame, and because 1143 // is asynchronous, i.e. not bound to any concrete frame, and because
1191 // the pipeline can be deeper than one frame), at that frame, or after. 1144 // the pipeline can be deeper than one frame), at that frame, or after.
1192 // So the only constraints we put here is that we get a keyframe not 1145 // So the only constraints we put here is that we get a keyframe not
1193 // earlier than we requested one (in time), and not later than 1146 // earlier than we requested one (in time), and not later than
1194 // kMaxKeyframeDelay frames after the frame, for which we requested 1147 // kMaxKeyframeDelay frames after the frame, for which we requested
1195 // it, comes back encoded. 1148 // it, comes back encoded.
1196 if (keyframe) { 1149 if (keyframe) {
1197 if (num_keyframes_requested_ > 0 && 1150 if (num_keyframes_requested_ > 0 &&
1198 num_encoded_frames_ > next_keyframe_at_) { 1151 num_encoded_frames_ > next_keyframe_at_) {
1199 --num_keyframes_requested_; 1152 --num_keyframes_requested_;
1200 next_keyframe_at_ += keyframe_period_; 1153 next_keyframe_at_ += keyframe_period_;
1201 } 1154 }
1202 seen_keyframe_in_this_buffer_ = true; 1155 seen_keyframe_in_this_buffer_ = true;
1203 } 1156 }
1204 1157
1205 if (num_keyframes_requested_ > 0) 1158 if (num_keyframes_requested_ > 0)
1206 EXPECT_LE(num_encoded_frames_, next_keyframe_at_ + kMaxKeyframeDelay); 1159 EXPECT_LE(num_encoded_frames_, next_keyframe_at_ + kMaxKeyframeDelay);
1207 1160
1208 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { 1161 if (num_encoded_frames_ == num_frames_to_encode_ / 2) {
1209 VerifyStreamProperties(); 1162 VerifyStreamProperties();
1210 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || 1163 if (requested_subsequent_bitrate_ != current_requested_bitrate_ ||
1211 requested_subsequent_framerate_ != current_framerate_) { 1164 requested_subsequent_framerate_ != current_framerate_) {
1212 SetStreamParameters(requested_subsequent_bitrate_, 1165 SetStreamParameters(requested_subsequent_bitrate_,
1213 requested_subsequent_framerate_); 1166 requested_subsequent_framerate_);
1214 if (g_env->run_at_fps() && input_timer_) 1167 if (run_at_fps_ && input_timer_)
1215 input_timer_->Start( 1168 input_timer_->Start(
1216 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, 1169 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_,
1217 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); 1170 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this)));
1218 } 1171 }
1219 } else if (num_encoded_frames_ == num_frames_to_encode_) { 1172 } else if (num_encoded_frames_ == num_frames_to_encode_) {
1220 LogPerf(); 1173 VerifyPerf();
1221 VerifyMinFPS();
1222 VerifyStreamProperties(); 1174 VerifyStreamProperties();
1223 SetState(CS_FINISHED); 1175 SetState(CS_FINISHED);
1224 return false; 1176 return false;
1225 } 1177 }
1226 1178
1227 return true; 1179 return true;
1228 } 1180 }
1229 1181
1230 void VEAClient::LogPerf() { 1182 void VEAClient::VerifyPerf() {
1183 double measured_fps = frames_per_second();
1184 LOG(INFO) << "Measured encoder FPS: " << measured_fps;
1231 g_env->LogToFile("Measured encoder FPS", 1185 g_env->LogToFile("Measured encoder FPS",
1232 base::StringPrintf("%.3f", frames_per_second())); 1186 base::StringPrintf("%.3f", measured_fps));
1233
1234 // Log encode latencies.
1235 if (g_env->needs_encode_latency()) {
1236 std::sort(encode_latencies_.begin(), encode_latencies_.end());
1237 for (const auto& percentile : kLoggedLatencyPercentiles) {
1238 base::TimeDelta latency = Percentile(encode_latencies_, percentile);
1239 g_env->LogToFile(
1240 base::StringPrintf("Encode latency for the %dth percentile",
1241 percentile),
1242 base::StringPrintf("%" PRId64 " us", latency.InMicroseconds()));
1243 }
1244 }
1245 }
1246
1247 void VEAClient::VerifyMinFPS() {
1248 if (test_perf_) 1187 if (test_perf_)
1249 EXPECT_GE(frames_per_second(), kMinPerfFPS); 1188 EXPECT_GE(measured_fps, kMinPerfFPS);
1250 } 1189 }
1251 1190
1252 void VEAClient::VerifyStreamProperties() { 1191 void VEAClient::VerifyStreamProperties() {
1253 CHECK_GT(num_frames_since_last_check_, 0UL); 1192 CHECK_GT(num_frames_since_last_check_, 0UL);
1254 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); 1193 CHECK_GT(encoded_stream_size_since_last_check_, 0UL);
1255 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * 1194 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 *
1256 current_framerate_ / num_frames_since_last_check_; 1195 current_framerate_ / num_frames_since_last_check_;
1257 DVLOG(1) << "Current chunk's bitrate: " << bitrate 1196 DVLOG(1) << "Current chunk's bitrate: " << bitrate
1258 << " (expected: " << current_requested_bitrate_ 1197 << " (expected: " << current_requested_bitrate_
1259 << " @ " << current_framerate_ << " FPS," 1198 << " @ " << current_framerate_ << " FPS,"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 1285
1347 // Create all encoders. 1286 // Create all encoders.
1348 for (size_t i = 0; i < num_concurrent_encoders; i++) { 1287 for (size_t i = 0; i < num_concurrent_encoders; i++) {
1349 size_t test_stream_index = i % g_env->test_streams_.size(); 1288 size_t test_stream_index = i % g_env->test_streams_.size();
1350 // Disregard save_to_file if we didn't get an output filename. 1289 // Disregard save_to_file if we didn't get an output filename.
1351 bool encoder_save_to_file = 1290 bool encoder_save_to_file =
1352 (save_to_file && 1291 (save_to_file &&
1353 !g_env->test_streams_[test_stream_index]->out_filename.empty()); 1292 !g_env->test_streams_[test_stream_index]->out_filename.empty());
1354 1293
1355 notes.push_back(new ClientStateNotification<ClientState>()); 1294 notes.push_back(new ClientStateNotification<ClientState>());
1356 clients.push_back(new VEAClient( 1295 clients.push_back(
1357 g_env->test_streams_[test_stream_index], notes.back(), 1296 new VEAClient(g_env->test_streams_[test_stream_index], notes.back(),
1358 encoder_save_to_file, keyframe_period, force_bitrate, test_perf, 1297 encoder_save_to_file, keyframe_period, force_bitrate,
1359 mid_stream_bitrate_switch, mid_stream_framerate_switch)); 1298 test_perf, mid_stream_bitrate_switch,
1299 mid_stream_framerate_switch, g_env->run_at_fps_));
1360 1300
1361 encoder_thread.message_loop()->PostTask( 1301 encoder_thread.message_loop()->PostTask(
1362 FROM_HERE, 1302 FROM_HERE,
1363 base::Bind(&VEAClient::CreateEncoder, 1303 base::Bind(&VEAClient::CreateEncoder,
1364 base::Unretained(clients.back()))); 1304 base::Unretained(clients.back())));
1365 } 1305 }
1366 1306
1367 // All encoders must pass through states in this order. 1307 // All encoders must pass through states in this order.
1368 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, 1308 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED,
1369 CS_ENCODING, CS_FINISHED}; 1309 CS_ENCODING, CS_FINISHED};
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 1389
1450 // Needed to enable DVLOG through --vmodule. 1390 // Needed to enable DVLOG through --vmodule.
1451 logging::LoggingSettings settings; 1391 logging::LoggingSettings settings;
1452 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 1392 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
1453 CHECK(logging::InitLogging(settings)); 1393 CHECK(logging::InitLogging(settings));
1454 1394
1455 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 1395 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
1456 DCHECK(cmd_line); 1396 DCHECK(cmd_line);
1457 1397
1458 bool run_at_fps = false; 1398 bool run_at_fps = false;
1459 bool needs_encode_latency = false;
1460 base::FilePath log_path; 1399 base::FilePath log_path;
1461 1400
1462 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); 1401 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
1463 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); 1402 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
1464 it != switches.end(); 1403 it != switches.end();
1465 ++it) { 1404 ++it) {
1466 if (it->first == "test_stream_data") { 1405 if (it->first == "test_stream_data") {
1467 test_stream_data->assign(it->second.c_str()); 1406 test_stream_data->assign(it->second.c_str());
1468 continue; 1407 continue;
1469 } 1408 }
1470 // Output machine-readable logs with fixed formats to a file. 1409 // Output machine-readable logs with fixed formats to a file.
1471 if (it->first == "output_log") { 1410 if (it->first == "output_log") {
1472 log_path = base::FilePath( 1411 log_path = base::FilePath(
1473 base::FilePath::StringType(it->second.begin(), it->second.end())); 1412 base::FilePath::StringType(it->second.begin(), it->second.end()));
1474 continue; 1413 continue;
1475 } 1414 }
1476 if (it->first == "num_frames_to_encode") { 1415 if (it->first == "num_frames_to_encode") {
1477 std::string input(it->second.begin(), it->second.end()); 1416 std::string input(it->second.begin(), it->second.end());
1478 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); 1417 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode));
1479 continue; 1418 continue;
1480 } 1419 }
1481 if (it->first == "measure_latency") {
1482 needs_encode_latency = true;
1483 continue;
1484 }
1485 if (it->first == "fake_encoder") { 1420 if (it->first == "fake_encoder") {
1486 content::g_fake_encoder = true; 1421 content::g_fake_encoder = true;
1487 continue; 1422 continue;
1488 } 1423 }
1489 if (it->first == "run_at_fps") { 1424 if (it->first == "run_at_fps") {
1490 run_at_fps = true; 1425 run_at_fps = true;
1491 continue; 1426 continue;
1492 } 1427 }
1493 if (it->first == "v" || it->first == "vmodule") 1428 if (it->first == "v" || it->first == "vmodule")
1494 continue; 1429 continue;
1495 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") 1430 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless")
1496 continue; 1431 continue;
1497 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; 1432 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
1498 } 1433 }
1499 1434
1500 if (needs_encode_latency && !run_at_fps) {
1501 // Encode latency can only be measured with --run_at_fps. Otherwise, we get
1502 // skewed results since it may queue too many frames at once with the same
1503 // encode start time.
1504 LOG(FATAL) << "--measure_latency requires --run_at_fps enabled to work.";
1505 }
1506
1507 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 1435 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
1508 content::VaapiWrapper::PreSandboxInitialization(); 1436 content::VaapiWrapper::PreSandboxInitialization();
1509 #endif 1437 #endif
1510 1438
1511 content::g_env = 1439 content::g_env =
1512 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( 1440 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>(
1513 testing::AddGlobalTestEnvironment( 1441 testing::AddGlobalTestEnvironment(
1514 new content::VideoEncodeAcceleratorTestEnvironment( 1442 new content::VideoEncodeAcceleratorTestEnvironment(
1515 test_stream_data.Pass(), log_path, run_at_fps, 1443 test_stream_data.Pass(), log_path, run_at_fps)));
1516 needs_encode_latency)));
1517 1444
1518 return RUN_ALL_TESTS(); 1445 return RUN_ALL_TESTS();
1519 } 1446 }
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