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