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

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

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