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