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, 100UL); |
| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 requested_subsequent_framerate_ = | 933 requested_subsequent_framerate_ = |
901 test_stream_->requested_subsequent_framerate; | 934 test_stream_->requested_subsequent_framerate; |
902 } else { | 935 } else { |
903 requested_subsequent_framerate_ = requested_framerate_; | 936 requested_subsequent_framerate_ = requested_framerate_; |
904 } | 937 } |
905 if (requested_subsequent_framerate_ == 0) | 938 if (requested_subsequent_framerate_ == 0) |
906 requested_subsequent_framerate_ = 1; | 939 requested_subsequent_framerate_ = 1; |
907 } | 940 } |
908 | 941 |
909 double VEAClient::frames_per_second() { | 942 double VEAClient::frames_per_second() { |
910 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_; | 943 CHECK(!encode_start_time_.empty()); |
| 944 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_[0]; |
911 return num_encoded_frames_ / duration.InSecondsF(); | 945 return num_encoded_frames_ / duration.InSecondsF(); |
912 } | 946 } |
913 | 947 |
914 void VEAClient::RequireBitstreamBuffers(unsigned int input_count, | 948 void VEAClient::RequireBitstreamBuffers(unsigned int input_count, |
915 const gfx::Size& input_coded_size, | 949 const gfx::Size& input_coded_size, |
916 size_t output_size) { | 950 size_t output_size) { |
917 DCHECK(thread_checker_.CalledOnValidThread()); | 951 DCHECK(thread_checker_.CalledOnValidThread()); |
918 ASSERT_EQ(state_, CS_INITIALIZED); | 952 ASSERT_EQ(state_, CS_INITIALIZED); |
919 SetState(CS_ENCODING); | 953 SetState(CS_ENCODING); |
920 | 954 |
921 CreateAlignedInputStreamFile(input_coded_size, test_stream_); | 955 CreateAlignedInputStreamFile(input_coded_size, test_stream_); |
922 | 956 |
923 num_frames_to_encode_ = test_stream_->num_frames; | 957 num_frames_to_encode_ = test_stream_->num_frames; |
924 if (g_num_frames_to_encode > 0) | 958 if (g_num_frames_to_encode > 0) |
925 num_frames_to_encode_ = g_num_frames_to_encode; | 959 num_frames_to_encode_ = g_num_frames_to_encode; |
926 | 960 |
| 961 // Speed up vector insertion. |
| 962 encode_start_time_.reserve(num_frames_to_encode_); |
| 963 if (g_env->needs_encode_latency()) |
| 964 encode_latencies_.reserve(num_frames_to_encode_); |
| 965 |
927 // We may need to loop over the stream more than once if more frames than | 966 // We may need to loop over the stream more than once if more frames than |
928 // provided is required for bitrate tests. | 967 // provided is required for bitrate tests. |
929 if (force_bitrate_ && num_frames_to_encode_ < kMinFramesForBitrateTests) { | 968 if (force_bitrate_ && num_frames_to_encode_ < kMinFramesForBitrateTests) { |
930 DVLOG(1) << "Stream too short for bitrate test (" | 969 DVLOG(1) << "Stream too short for bitrate test (" |
931 << test_stream_->num_frames << " frames), will loop it to reach " | 970 << test_stream_->num_frames << " frames), will loop it to reach " |
932 << kMinFramesForBitrateTests << " frames"; | 971 << kMinFramesForBitrateTests << " frames"; |
933 num_frames_to_encode_ = kMinFramesForBitrateTests; | 972 num_frames_to_encode_ = kMinFramesForBitrateTests; |
934 } | 973 } |
935 if (save_to_file_ && IsVP8(test_stream_->requested_profile)) | 974 if (save_to_file_ && IsVP8(test_stream_->requested_profile)) |
936 WriteIvfFileHeader(); | 975 WriteIvfFileHeader(); |
937 | 976 |
938 input_coded_size_ = input_coded_size; | 977 input_coded_size_ = input_coded_size; |
939 num_required_input_buffers_ = input_count; | 978 num_required_input_buffers_ = input_count; |
940 ASSERT_GT(num_required_input_buffers_, 0UL); | 979 ASSERT_GT(num_required_input_buffers_, 0UL); |
941 | 980 |
942 output_buffer_size_ = output_size; | 981 output_buffer_size_ = output_size; |
943 ASSERT_GT(output_buffer_size_, 0UL); | 982 ASSERT_GT(output_buffer_size_, 0UL); |
944 | 983 |
945 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { | 984 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { |
946 base::SharedMemory* shm = new base::SharedMemory(); | 985 base::SharedMemory* shm = new base::SharedMemory(); |
947 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); | 986 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); |
948 output_shms_.push_back(shm); | 987 output_shms_.push_back(shm); |
949 FeedEncoderWithOutput(shm); | 988 FeedEncoderWithOutput(shm); |
950 } | 989 } |
951 | 990 |
952 encode_start_time_ = base::TimeTicks::Now(); | 991 if (g_env->run_at_fps()) { |
953 if (run_at_fps_) { | |
954 input_timer_.reset(new base::RepeatingTimer<VEAClient>()); | 992 input_timer_.reset(new base::RepeatingTimer<VEAClient>()); |
955 input_timer_->Start( | 993 input_timer_->Start( |
956 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, | 994 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, |
957 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); | 995 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); |
958 } else { | 996 } else { |
959 while (inputs_at_client_.size() < | 997 while (inputs_at_client_.size() < |
960 num_required_input_buffers_ + kNumExtraInputFrames) | 998 num_required_input_buffers_ + kNumExtraInputFrames) |
961 FeedEncoderWithOneInput(); | 999 FeedEncoderWithOneInput(); |
962 } | 1000 } |
963 } | 1001 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, | 1061 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, |
1024 current_framerate_); | 1062 current_framerate_); |
1025 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ | 1063 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ |
1026 << " bps @ " << current_framerate_ << " FPS"; | 1064 << " bps @ " << current_framerate_ << " FPS"; |
1027 } | 1065 } |
1028 | 1066 |
1029 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { | 1067 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { |
1030 std::set<int32>::iterator it = inputs_at_client_.find(input_id); | 1068 std::set<int32>::iterator it = inputs_at_client_.find(input_id); |
1031 ASSERT_NE(it, inputs_at_client_.end()); | 1069 ASSERT_NE(it, inputs_at_client_.end()); |
1032 inputs_at_client_.erase(it); | 1070 inputs_at_client_.erase(it); |
1033 if (!run_at_fps_) | 1071 if (!g_env->run_at_fps()) |
1034 FeedEncoderWithOneInput(); | 1072 FeedEncoderWithOneInput(); |
1035 } | 1073 } |
1036 | 1074 |
1037 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { | 1075 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position, |
| 1076 int32* input_id) { |
1038 CHECK_LE(position + test_stream_->aligned_buffer_size, | 1077 CHECK_LE(position + test_stream_->aligned_buffer_size, |
1039 test_stream_->mapped_aligned_in_file.length()); | 1078 test_stream_->mapped_aligned_in_file.length()); |
1040 | 1079 |
1041 uint8* frame_data_y = const_cast<uint8*>( | 1080 uint8* frame_data_y = const_cast<uint8*>( |
1042 test_stream_->mapped_aligned_in_file.data() + position); | 1081 test_stream_->mapped_aligned_in_file.data() + position); |
1043 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; | 1082 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]; | 1083 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1]; |
1045 | 1084 |
1046 CHECK_GT(current_framerate_, 0U); | 1085 CHECK_GT(current_framerate_, 0U); |
1047 scoped_refptr<media::VideoFrame> frame = | 1086 scoped_refptr<media::VideoFrame> frame = |
(...skipping 10 matching lines...) Expand all Loading... |
1058 frame_data_v, | 1097 frame_data_v, |
1059 base::TimeDelta().FromMilliseconds( | 1098 base::TimeDelta().FromMilliseconds( |
1060 next_input_id_ * base::Time::kMillisecondsPerSecond / | 1099 next_input_id_ * base::Time::kMillisecondsPerSecond / |
1061 current_framerate_), | 1100 current_framerate_), |
1062 media::BindToCurrentLoop( | 1101 media::BindToCurrentLoop( |
1063 base::Bind(&VEAClient::InputNoLongerNeededCallback, | 1102 base::Bind(&VEAClient::InputNoLongerNeededCallback, |
1064 base::Unretained(this), | 1103 base::Unretained(this), |
1065 next_input_id_))); | 1104 next_input_id_))); |
1066 | 1105 |
1067 CHECK(inputs_at_client_.insert(next_input_id_).second); | 1106 CHECK(inputs_at_client_.insert(next_input_id_).second); |
1068 ++next_input_id_; | |
1069 | 1107 |
| 1108 *input_id = next_input_id_++; |
1070 return frame; | 1109 return frame; |
1071 } | 1110 } |
1072 | 1111 |
1073 void VEAClient::OnInputTimer() { | 1112 void VEAClient::OnInputTimer() { |
1074 if (!has_encoder() || state_ != CS_ENCODING) | 1113 if (!has_encoder() || state_ != CS_ENCODING) |
1075 input_timer_.reset(); | 1114 input_timer_.reset(); |
1076 else if (inputs_at_client_.size() < | 1115 else if (inputs_at_client_.size() < |
1077 num_required_input_buffers_ + kNumExtraInputFrames) | 1116 num_required_input_buffers_ + kNumExtraInputFrames) |
1078 FeedEncoderWithOneInput(); | 1117 FeedEncoderWithOneInput(); |
1079 else | 1118 else |
1080 DVLOG(1) << "Dropping input frame"; | 1119 DVLOG(1) << "Dropping input frame"; |
1081 } | 1120 } |
1082 | 1121 |
1083 void VEAClient::FeedEncoderWithOneInput() { | 1122 void VEAClient::FeedEncoderWithOneInput() { |
1084 if (!has_encoder() || state_ != CS_ENCODING) | 1123 if (!has_encoder() || state_ != CS_ENCODING) |
1085 return; | 1124 return; |
1086 | 1125 |
1087 size_t bytes_left = | 1126 size_t bytes_left = |
1088 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; | 1127 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; |
1089 if (bytes_left < test_stream_->aligned_buffer_size) { | 1128 if (bytes_left < test_stream_->aligned_buffer_size) { |
1090 DCHECK_EQ(bytes_left, 0UL); | 1129 DCHECK_EQ(bytes_left, 0UL); |
1091 // Rewind if at the end of stream and we are still encoding. | 1130 // 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 | 1131 // 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 | 1132 // of the stream, or if the stream is shorter that the number of frames |
1094 // we require for bitrate tests. | 1133 // we require for bitrate tests. |
1095 pos_in_input_stream_ = 0; | 1134 pos_in_input_stream_ = 0; |
1096 } | 1135 } |
1097 | 1136 |
| 1137 int32 input_id; |
| 1138 scoped_refptr<media::VideoFrame> video_frame = |
| 1139 PrepareInputFrame(pos_in_input_stream_, &input_id); |
| 1140 pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
| 1141 |
1098 bool force_keyframe = false; | 1142 bool force_keyframe = false; |
1099 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { | 1143 if (keyframe_period_ && input_id % keyframe_period_ == 0) { |
1100 force_keyframe = true; | 1144 force_keyframe = true; |
1101 ++num_keyframes_requested_; | 1145 ++num_keyframes_requested_; |
1102 } | 1146 } |
1103 | 1147 |
1104 scoped_refptr<media::VideoFrame> video_frame = | 1148 CHECK_EQ(input_id, static_cast<int32>(encode_start_time_.size())); |
1105 PrepareInputFrame(pos_in_input_stream_); | 1149 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); | 1150 encoder_->Encode(video_frame, force_keyframe); |
1109 } | 1151 } |
1110 | 1152 |
1111 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { | 1153 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { |
1112 if (!has_encoder()) | 1154 if (!has_encoder()) |
1113 return; | 1155 return; |
1114 | 1156 |
1115 if (state_ != CS_ENCODING) | 1157 if (state_ != CS_ENCODING) |
1116 return; | 1158 return; |
1117 | 1159 |
1118 base::SharedMemoryHandle dup_handle; | 1160 base::SharedMemoryHandle dup_handle; |
1119 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); | 1161 CHECK(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); |
1120 | 1162 |
1121 media::BitstreamBuffer bitstream_buffer( | 1163 media::BitstreamBuffer bitstream_buffer( |
1122 next_output_buffer_id_++, dup_handle, output_buffer_size_); | 1164 next_output_buffer_id_++, dup_handle, output_buffer_size_); |
1123 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(), | 1165 CHECK(output_buffers_at_client_.insert(std::make_pair(bitstream_buffer.id(), |
1124 shm)).second); | 1166 shm)).second); |
1125 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); | 1167 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); |
1126 } | 1168 } |
1127 | 1169 |
1128 bool VEAClient::HandleEncodedFrame(bool keyframe) { | 1170 bool VEAClient::HandleEncodedFrame(bool keyframe) { |
1129 // This would be a bug in the test, which should not ignore false | 1171 // This would be a bug in the test, which should not ignore false |
1130 // return value from this method. | 1172 // return value from this method. |
1131 CHECK_LE(num_encoded_frames_, num_frames_to_encode_); | 1173 CHECK_LE(num_encoded_frames_, num_frames_to_encode_); |
1132 | 1174 |
| 1175 last_frame_ready_time_ = base::TimeTicks::Now(); |
| 1176 |
| 1177 if (g_env->needs_encode_latency()) { |
| 1178 CHECK_LT(num_encoded_frames_, encode_start_time_.size()); |
| 1179 base::TimeTicks start_time = encode_start_time_[num_encoded_frames_]; |
| 1180 CHECK(!start_time.is_null()); |
| 1181 encode_latencies_.push_back(last_frame_ready_time_ - start_time); |
| 1182 } |
| 1183 |
1133 ++num_encoded_frames_; | 1184 ++num_encoded_frames_; |
1134 ++num_frames_since_last_check_; | 1185 ++num_frames_since_last_check_; |
1135 | 1186 |
1136 last_frame_ready_time_ = base::TimeTicks::Now(); | |
1137 | |
1138 // Because the keyframe behavior requirements are loose, we give | 1187 // Because the keyframe behavior requirements are loose, we give |
1139 // the encoder more freedom here. It could either deliver a keyframe | 1188 // the encoder more freedom here. It could either deliver a keyframe |
1140 // immediately after we requested it, which could be for a frame number | 1189 // immediately after we requested it, which could be for a frame number |
1141 // before the one we requested it for (if the keyframe request | 1190 // before the one we requested it for (if the keyframe request |
1142 // is asynchronous, i.e. not bound to any concrete frame, and because | 1191 // 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. | 1192 // 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 | 1193 // 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 | 1194 // earlier than we requested one (in time), and not later than |
1146 // kMaxKeyframeDelay frames after the frame, for which we requested | 1195 // kMaxKeyframeDelay frames after the frame, for which we requested |
1147 // it, comes back encoded. | 1196 // it, comes back encoded. |
1148 if (keyframe) { | 1197 if (keyframe) { |
1149 if (num_keyframes_requested_ > 0 && | 1198 if (num_keyframes_requested_ > 0 && |
1150 num_encoded_frames_ > next_keyframe_at_) { | 1199 num_encoded_frames_ > next_keyframe_at_) { |
1151 --num_keyframes_requested_; | 1200 --num_keyframes_requested_; |
1152 next_keyframe_at_ += keyframe_period_; | 1201 next_keyframe_at_ += keyframe_period_; |
1153 } | 1202 } |
1154 seen_keyframe_in_this_buffer_ = true; | 1203 seen_keyframe_in_this_buffer_ = true; |
1155 } | 1204 } |
1156 | 1205 |
1157 if (num_keyframes_requested_ > 0) | 1206 if (num_keyframes_requested_ > 0) |
1158 EXPECT_LE(num_encoded_frames_, next_keyframe_at_ + kMaxKeyframeDelay); | 1207 EXPECT_LE(num_encoded_frames_, next_keyframe_at_ + kMaxKeyframeDelay); |
1159 | 1208 |
1160 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { | 1209 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { |
1161 VerifyStreamProperties(); | 1210 VerifyStreamProperties(); |
1162 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || | 1211 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || |
1163 requested_subsequent_framerate_ != current_framerate_) { | 1212 requested_subsequent_framerate_ != current_framerate_) { |
1164 SetStreamParameters(requested_subsequent_bitrate_, | 1213 SetStreamParameters(requested_subsequent_bitrate_, |
1165 requested_subsequent_framerate_); | 1214 requested_subsequent_framerate_); |
1166 if (run_at_fps_ && input_timer_) | 1215 if (g_env->run_at_fps() && input_timer_) |
1167 input_timer_->Start( | 1216 input_timer_->Start( |
1168 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, | 1217 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, |
1169 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); | 1218 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); |
1170 } | 1219 } |
1171 } else if (num_encoded_frames_ == num_frames_to_encode_) { | 1220 } else if (num_encoded_frames_ == num_frames_to_encode_) { |
1172 VerifyPerf(); | 1221 LogPerf(); |
| 1222 VerifyMinFPS(); |
1173 VerifyStreamProperties(); | 1223 VerifyStreamProperties(); |
1174 SetState(CS_FINISHED); | 1224 SetState(CS_FINISHED); |
1175 return false; | 1225 return false; |
1176 } | 1226 } |
1177 | 1227 |
1178 return true; | 1228 return true; |
1179 } | 1229 } |
1180 | 1230 |
1181 void VEAClient::VerifyPerf() { | 1231 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", | 1232 g_env->LogToFile("Measured encoder FPS", |
1185 base::StringPrintf("%.3f", measured_fps)); | 1233 base::StringPrintf("%.3f", frames_per_second())); |
| 1234 |
| 1235 // Log encode latencies. |
| 1236 if (g_env->needs_encode_latency()) { |
| 1237 std::sort(encode_latencies_.begin(), encode_latencies_.end()); |
| 1238 for (const auto& percentile : kLoggedLatencyPercentiles) { |
| 1239 base::TimeDelta latency = Percentile(encode_latencies_, percentile); |
| 1240 g_env->LogToFile( |
| 1241 base::StringPrintf("Encode latency for the %dth percentile", |
| 1242 percentile), |
| 1243 base::StringPrintf("%" PRId64 " us", latency.InMicroseconds())); |
| 1244 } |
| 1245 } |
| 1246 } |
| 1247 |
| 1248 void VEAClient::VerifyMinFPS() { |
1186 if (test_perf_) | 1249 if (test_perf_) |
1187 EXPECT_GE(measured_fps, kMinPerfFPS); | 1250 EXPECT_GE(frames_per_second(), kMinPerfFPS); |
1188 } | 1251 } |
1189 | 1252 |
1190 void VEAClient::VerifyStreamProperties() { | 1253 void VEAClient::VerifyStreamProperties() { |
1191 CHECK_GT(num_frames_since_last_check_, 0UL); | 1254 CHECK_GT(num_frames_since_last_check_, 0UL); |
1192 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); | 1255 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); |
1193 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * | 1256 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * |
1194 current_framerate_ / num_frames_since_last_check_; | 1257 current_framerate_ / num_frames_since_last_check_; |
1195 DVLOG(1) << "Current chunk's bitrate: " << bitrate | 1258 DVLOG(1) << "Current chunk's bitrate: " << bitrate |
1196 << " (expected: " << current_requested_bitrate_ | 1259 << " (expected: " << current_requested_bitrate_ |
1197 << " @ " << current_framerate_ << " FPS," | 1260 << " @ " << current_framerate_ << " FPS," |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 | 1347 |
1285 // Create all encoders. | 1348 // Create all encoders. |
1286 for (size_t i = 0; i < num_concurrent_encoders; i++) { | 1349 for (size_t i = 0; i < num_concurrent_encoders; i++) { |
1287 size_t test_stream_index = i % g_env->test_streams_.size(); | 1350 size_t test_stream_index = i % g_env->test_streams_.size(); |
1288 // Disregard save_to_file if we didn't get an output filename. | 1351 // Disregard save_to_file if we didn't get an output filename. |
1289 bool encoder_save_to_file = | 1352 bool encoder_save_to_file = |
1290 (save_to_file && | 1353 (save_to_file && |
1291 !g_env->test_streams_[test_stream_index]->out_filename.empty()); | 1354 !g_env->test_streams_[test_stream_index]->out_filename.empty()); |
1292 | 1355 |
1293 notes.push_back(new ClientStateNotification<ClientState>()); | 1356 notes.push_back(new ClientStateNotification<ClientState>()); |
1294 clients.push_back( | 1357 clients.push_back(new VEAClient( |
1295 new VEAClient(g_env->test_streams_[test_stream_index], notes.back(), | 1358 g_env->test_streams_[test_stream_index], notes.back(), |
1296 encoder_save_to_file, keyframe_period, force_bitrate, | 1359 encoder_save_to_file, keyframe_period, force_bitrate, test_perf, |
1297 test_perf, mid_stream_bitrate_switch, | 1360 mid_stream_bitrate_switch, mid_stream_framerate_switch)); |
1298 mid_stream_framerate_switch, g_env->run_at_fps_)); | |
1299 | 1361 |
1300 encoder_thread.message_loop()->PostTask( | 1362 encoder_thread.message_loop()->PostTask( |
1301 FROM_HERE, | 1363 FROM_HERE, |
1302 base::Bind(&VEAClient::CreateEncoder, | 1364 base::Bind(&VEAClient::CreateEncoder, |
1303 base::Unretained(clients.back()))); | 1365 base::Unretained(clients.back()))); |
1304 } | 1366 } |
1305 | 1367 |
1306 // All encoders must pass through states in this order. | 1368 // All encoders must pass through states in this order. |
1307 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, | 1369 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, |
1308 CS_ENCODING, CS_FINISHED}; | 1370 CS_ENCODING, CS_FINISHED}; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 | 1450 |
1389 // Needed to enable DVLOG through --vmodule. | 1451 // Needed to enable DVLOG through --vmodule. |
1390 logging::LoggingSettings settings; | 1452 logging::LoggingSettings settings; |
1391 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 1453 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
1392 CHECK(logging::InitLogging(settings)); | 1454 CHECK(logging::InitLogging(settings)); |
1393 | 1455 |
1394 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 1456 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
1395 DCHECK(cmd_line); | 1457 DCHECK(cmd_line); |
1396 | 1458 |
1397 bool run_at_fps = false; | 1459 bool run_at_fps = false; |
| 1460 bool needs_encode_latency = false; |
1398 base::FilePath log_path; | 1461 base::FilePath log_path; |
1399 | 1462 |
1400 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | 1463 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
1401 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1464 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
1402 it != switches.end(); | 1465 it != switches.end(); |
1403 ++it) { | 1466 ++it) { |
1404 if (it->first == "test_stream_data") { | 1467 if (it->first == "test_stream_data") { |
1405 test_stream_data->assign(it->second.c_str()); | 1468 test_stream_data->assign(it->second.c_str()); |
1406 continue; | 1469 continue; |
1407 } | 1470 } |
1408 // Output machine-readable logs with fixed formats to a file. | 1471 // Output machine-readable logs with fixed formats to a file. |
1409 if (it->first == "output_log") { | 1472 if (it->first == "output_log") { |
1410 log_path = base::FilePath( | 1473 log_path = base::FilePath( |
1411 base::FilePath::StringType(it->second.begin(), it->second.end())); | 1474 base::FilePath::StringType(it->second.begin(), it->second.end())); |
1412 continue; | 1475 continue; |
1413 } | 1476 } |
1414 if (it->first == "num_frames_to_encode") { | 1477 if (it->first == "num_frames_to_encode") { |
1415 std::string input(it->second.begin(), it->second.end()); | 1478 std::string input(it->second.begin(), it->second.end()); |
1416 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); | 1479 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); |
1417 continue; | 1480 continue; |
1418 } | 1481 } |
| 1482 if (it->first == "measure_latency") { |
| 1483 needs_encode_latency = true; |
| 1484 continue; |
| 1485 } |
1419 if (it->first == "fake_encoder") { | 1486 if (it->first == "fake_encoder") { |
1420 content::g_fake_encoder = true; | 1487 content::g_fake_encoder = true; |
1421 continue; | 1488 continue; |
1422 } | 1489 } |
1423 if (it->first == "run_at_fps") { | 1490 if (it->first == "run_at_fps") { |
1424 run_at_fps = true; | 1491 run_at_fps = true; |
1425 continue; | 1492 continue; |
1426 } | 1493 } |
1427 if (it->first == "v" || it->first == "vmodule") | 1494 if (it->first == "v" || it->first == "vmodule") |
1428 continue; | 1495 continue; |
1429 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") | 1496 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") |
1430 continue; | 1497 continue; |
1431 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1498 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1432 } | 1499 } |
1433 | 1500 |
| 1501 if (needs_encode_latency && !run_at_fps) { |
| 1502 // Encode latency can only be measured with --run_at_fps. Otherwise, we get |
| 1503 // skewed results since it may queue too many frames at once with the same |
| 1504 // encode start time. |
| 1505 LOG(FATAL) << "--measure_latency requires --run_at_fps enabled to work."; |
| 1506 } |
| 1507 |
1434 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 1508 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
1435 content::VaapiWrapper::PreSandboxInitialization(); | 1509 content::VaapiWrapper::PreSandboxInitialization(); |
1436 #endif | 1510 #endif |
1437 | 1511 |
1438 content::g_env = | 1512 content::g_env = |
1439 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1513 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1440 testing::AddGlobalTestEnvironment( | 1514 testing::AddGlobalTestEnvironment( |
1441 new content::VideoEncodeAcceleratorTestEnvironment( | 1515 new content::VideoEncodeAcceleratorTestEnvironment( |
1442 test_stream_data.Pass(), log_path, run_at_fps))); | 1516 test_stream_data.Pass(), log_path, run_at_fps, |
| 1517 needs_encode_latency))); |
1443 | 1518 |
1444 return RUN_ALL_TESTS(); | 1519 return RUN_ALL_TESTS(); |
1445 } | 1520 } |
OLD | NEW |