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

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

Issue 769133003: vea_unittest - Control the rate of input frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Pawel's comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/memory_mapped_file.h" 9 #include "base/files/memory_mapped_file.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/process/process_handle.h" 12 #include "base/process/process_handle.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/timer/timer.h"
16 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" 17 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h"
17 #include "media/base/bind_to_current_loop.h" 18 #include "media/base/bind_to_current_loop.h"
18 #include "media/base/bitstream_buffer.h" 19 #include "media/base/bitstream_buffer.h"
19 #include "media/base/test_data_util.h" 20 #include "media/base/test_data_util.h"
20 #include "media/filters/h264_parser.h" 21 #include "media/filters/h264_parser.h"
21 #include "media/video/video_encode_accelerator.h" 22 #include "media/video/video_encode_accelerator.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 #if defined(USE_X11) 25 #if defined(USE_X11)
25 #include "ui/gfx/x/x11_types.h" 26 #include "ui/gfx/x/x11_types.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; 95 const char* g_default_in_parameters = ":320:192:1:out.h264:200000";
95 // Environment to store test stream data for all test cases. 96 // Environment to store test stream data for all test cases.
96 class VideoEncodeAcceleratorTestEnvironment; 97 class VideoEncodeAcceleratorTestEnvironment;
97 VideoEncodeAcceleratorTestEnvironment* g_env; 98 VideoEncodeAcceleratorTestEnvironment* g_env;
98 99
99 struct TestStream { 100 struct TestStream {
100 TestStream() 101 TestStream()
101 : num_frames(0), 102 : num_frames(0),
102 aligned_buffer_size(0), 103 aligned_buffer_size(0),
103 requested_bitrate(0), 104 requested_bitrate(0),
105 input_framerate(0),
104 requested_framerate(0), 106 requested_framerate(0),
105 requested_subsequent_bitrate(0), 107 requested_subsequent_bitrate(0),
106 requested_subsequent_framerate(0) {} 108 requested_subsequent_framerate(0) {}
107 ~TestStream() {} 109 ~TestStream() {}
108 110
109 gfx::Size visible_size; 111 gfx::Size visible_size;
110 gfx::Size coded_size; 112 gfx::Size coded_size;
111 unsigned int num_frames; 113 unsigned int num_frames;
112 114
113 // Original unaligned input file name provided as an argument to the test. 115 // Original unaligned input file name provided as an argument to the test.
114 // And the file must be an I420 (YUV planar) raw stream. 116 // And the file must be an I420 (YUV planar) raw stream.
115 std::string in_filename; 117 std::string in_filename;
116 118
117 // A temporary file used to prepare aligned input buffers of |in_filename|. 119 // A temporary file used to prepare aligned input buffers of |in_filename|.
118 // The file makes sure starting address of YUV planes are 64 byte-aligned. 120 // The file makes sure starting address of YUV planes are 64 byte-aligned.
119 base::FilePath aligned_in_file; 121 base::FilePath aligned_in_file;
120 122
121 // The memory mapping of |aligned_in_file| 123 // The memory mapping of |aligned_in_file|
122 base::MemoryMappedFile mapped_aligned_in_file; 124 base::MemoryMappedFile mapped_aligned_in_file;
123 125
124 // Byte size of a frame of |aligned_in_file|. 126 // Byte size of a frame of |aligned_in_file|.
125 size_t aligned_buffer_size; 127 size_t aligned_buffer_size;
126 128
127 // Byte size for each aligned plane of a frame 129 // Byte size for each aligned plane of a frame
128 std::vector<size_t> aligned_plane_size; 130 std::vector<size_t> aligned_plane_size;
129 131
130 std::string out_filename; 132 std::string out_filename;
131 media::VideoCodecProfile requested_profile; 133 media::VideoCodecProfile requested_profile;
132 unsigned int requested_bitrate; 134 unsigned int requested_bitrate;
135 unsigned int input_framerate;
Pawel Osciak 2014/12/18 04:54:10 Hm, now it becomes more visible that we have a dup
Owen Lin 2014/12/18 08:38:11 Done.
133 unsigned int requested_framerate; 136 unsigned int requested_framerate;
134 unsigned int requested_subsequent_bitrate; 137 unsigned int requested_subsequent_bitrate;
135 unsigned int requested_subsequent_framerate; 138 unsigned int requested_subsequent_framerate;
136 }; 139 };
137 140
138 inline static size_t Align64Bytes(size_t value) { 141 inline static size_t Align64Bytes(size_t value) {
139 return (value + 63) & ~63; 142 return (value + 63) & ~63;
140 } 143 }
141 144
142 // Write |data| of |size| bytes at |offset| bytes into |file|. 145 // Write |data| of |size| bytes at |offset| bytes into |file|.
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 test_stream->requested_profile = 290 test_stream->requested_profile =
288 static_cast<media::VideoCodecProfile>(profile); 291 static_cast<media::VideoCodecProfile>(profile);
289 292
290 if (fields.size() >= 5 && !fields[4].empty()) 293 if (fields.size() >= 5 && !fields[4].empty())
291 test_stream->out_filename = fields[4]; 294 test_stream->out_filename = fields[4];
292 295
293 if (fields.size() >= 6 && !fields[5].empty()) 296 if (fields.size() >= 6 && !fields[5].empty())
294 CHECK(base::StringToUint(fields[5], &test_stream->requested_bitrate)); 297 CHECK(base::StringToUint(fields[5], &test_stream->requested_bitrate));
295 298
296 if (fields.size() >= 7 && !fields[6].empty()) 299 if (fields.size() >= 7 && !fields[6].empty())
297 CHECK(base::StringToUint(fields[6], &test_stream->requested_framerate)); 300 CHECK(base::StringToUint(fields[6], &test_stream->input_framerate));
298 301
299 if (fields.size() >= 8 && !fields[7].empty()) { 302 if (fields.size() >= 8 && !fields[7].empty())
300 CHECK(base::StringToUint(fields[7], 303 CHECK(base::StringToUint(fields[7], &test_stream->requested_framerate));
304
305 if (fields.size() >= 9 && !fields[8].empty()) {
306 CHECK(base::StringToUint(fields[8],
301 &test_stream->requested_subsequent_bitrate)); 307 &test_stream->requested_subsequent_bitrate));
302 } 308 }
303 309
304 if (fields.size() >= 9 && !fields[8].empty()) { 310 if (fields.size() >= 10 && !fields[9].empty()) {
305 CHECK(base::StringToUint(fields[8], 311 CHECK(base::StringToUint(fields[9],
306 &test_stream->requested_subsequent_framerate)); 312 &test_stream->requested_subsequent_framerate));
307 } 313 }
308 test_streams->push_back(test_stream); 314 test_streams->push_back(test_stream);
309 } 315 }
310 } 316 }
311 317
312 enum ClientState { 318 enum ClientState {
313 CS_CREATED, 319 CS_CREATED,
314 CS_ENCODER_SET, 320 CS_ENCODER_SET,
315 CS_INITIALIZED, 321 CS_INITIALIZED,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 bool has_encoder() { return encoder_.get(); } 496 bool has_encoder() { return encoder_.get(); }
491 497
492 void SetState(ClientState new_state); 498 void SetState(ClientState new_state);
493 499
494 // Set current stream parameters to given |bitrate| at |framerate|. 500 // Set current stream parameters to given |bitrate| at |framerate|.
495 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); 501 void SetStreamParameters(unsigned int bitrate, unsigned int framerate);
496 502
497 // Called when encoder is done with a VideoFrame. 503 // Called when encoder is done with a VideoFrame.
498 void InputNoLongerNeededCallback(int32 input_id); 504 void InputNoLongerNeededCallback(int32 input_id);
499 505
500 // Ensure encoder has at least as many inputs as it asked for 506 // Feed the encoder with one input frame unless it has as many input buffers
501 // via RequireBitstreamBuffers(). 507 // as it asked for via RequireBitstreamBuffers(). Return false if no input
502 void FeedEncoderWithInputs(); 508 // frame was fed.
509 void FeedEncoderWithOneInput();
503 510
504 // Provide the encoder with a new output buffer. 511 // Provide the encoder with a new output buffer.
505 void FeedEncoderWithOutput(base::SharedMemory* shm); 512 void FeedEncoderWithOutput(base::SharedMemory* shm);
506 513
507 // Called on finding a complete frame (with |keyframe| set to true for 514 // Called on finding a complete frame (with |keyframe| set to true for
508 // keyframes) in the stream, to perform codec-independent, per-frame checks 515 // keyframes) in the stream, to perform codec-independent, per-frame checks
509 // and accounting. Returns false once we have collected all frames we needed. 516 // and accounting. Returns false once we have collected all frames we needed.
510 bool HandleEncodedFrame(bool keyframe); 517 bool HandleEncodedFrame(bool keyframe);
511 518
512 // Verify that stream bitrate has been close to current_requested_bitrate_, 519 // Verify that stream bitrate has been close to current_requested_bitrate_,
513 // assuming current_framerate_ since the last time VerifyStreamProperties() 520 // assuming current_framerate_ since the last time VerifyStreamProperties()
514 // was called. Fail the test if |force_bitrate_| is true and the bitrate 521 // was called. Fail the test if |force_bitrate_| is true and the bitrate
515 // is not within kBitrateTolerance. 522 // is not within kBitrateTolerance.
516 void VerifyStreamProperties(); 523 void VerifyStreamProperties();
517 524
518 // Test codec performance, failing the test if we are currently running 525 // Test codec performance, failing the test if we are currently running
519 // the performance test. 526 // the performance test.
520 void VerifyPerf(); 527 void VerifyPerf();
521 528
522 // Prepare and return a frame wrapping the data at |position| bytes in 529 // Prepare and return a frame wrapping the data at |position| bytes in
523 // the input stream, ready to be sent to encoder. 530 // the input stream, ready to be sent to encoder.
524 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position); 531 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position);
525 532
526 // Update the parameters according to |mid_stream_bitrate_switch| and 533 // Update the parameters according to |mid_stream_bitrate_switch| and
527 // |mid_stream_framerate_switch|. 534 // |mid_stream_framerate_switch|.
528 void UpdateTestStreamData(bool mid_stream_bitrate_switch, 535 void UpdateTestStreamData(bool mid_stream_bitrate_switch,
529 bool mid_stream_framerate_switch); 536 bool mid_stream_framerate_switch);
530 537
538 // Callback function of the |input_timer_|.
539 void OnInputTimer();
540
531 ClientState state_; 541 ClientState state_;
532 scoped_ptr<VideoEncodeAccelerator> encoder_; 542 scoped_ptr<VideoEncodeAccelerator> encoder_;
533 543
534 TestStream* test_stream_; 544 TestStream* test_stream_;
545
535 // Used to notify another thread about the state. VEAClient does not own this. 546 // Used to notify another thread about the state. VEAClient does not own this.
536 ClientStateNotification<ClientState>* note_; 547 ClientStateNotification<ClientState>* note_;
537 548
538 // Ids assigned to VideoFrames (start at 1 for easy comparison with 549 // Ids assigned to VideoFrames (start at 1 for easy comparison with
539 // num_encoded_frames_). 550 // num_encoded_frames_).
540 std::set<int32> inputs_at_client_; 551 std::set<int32> inputs_at_client_;
541 int32 next_input_id_; 552 int32 next_input_id_;
542 553
543 // Ids for output BitstreamBuffers. 554 // Ids for output BitstreamBuffers.
544 typedef std::map<int32, base::SharedMemory*> IdToSHM; 555 typedef std::map<int32, base::SharedMemory*> IdToSHM;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 unsigned int requested_bitrate_; 617 unsigned int requested_bitrate_;
607 618
608 // Requested initial framerate. 619 // Requested initial framerate.
609 unsigned int requested_framerate_; 620 unsigned int requested_framerate_;
610 621
611 // Bitrate to switch to in the middle of the stream. 622 // Bitrate to switch to in the middle of the stream.
612 unsigned int requested_subsequent_bitrate_; 623 unsigned int requested_subsequent_bitrate_;
613 624
614 // Framerate to switch to in the middle of the stream. 625 // Framerate to switch to in the middle of the stream.
615 unsigned int requested_subsequent_framerate_; 626 unsigned int requested_subsequent_framerate_;
627
628 // The timer used to feed the encoder with the input frames.
629 scoped_ptr<base::RepeatingTimer<VEAClient>> input_timer_;
630
631 // The interval between two input frames.
632 base::TimeDelta input_duration_;
616 }; 633 };
617 634
618 VEAClient::VEAClient(TestStream* test_stream, 635 VEAClient::VEAClient(TestStream* test_stream,
619 ClientStateNotification<ClientState>* note, 636 ClientStateNotification<ClientState>* note,
620 bool save_to_file, 637 bool save_to_file,
621 unsigned int keyframe_period, 638 unsigned int keyframe_period,
622 bool force_bitrate, 639 bool force_bitrate,
623 bool test_perf, 640 bool test_perf,
624 bool mid_stream_bitrate_switch, 641 bool mid_stream_bitrate_switch,
625 bool mid_stream_framerate_switch) 642 bool mid_stream_framerate_switch)
(...skipping 23 matching lines...) Expand all
649 requested_subsequent_framerate_(0) { 666 requested_subsequent_framerate_(0) {
650 if (keyframe_period_) 667 if (keyframe_period_)
651 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); 668 CHECK_LT(kMaxKeyframeDelay, keyframe_period_);
652 669
653 validator_ = StreamValidator::Create( 670 validator_ = StreamValidator::Create(
654 test_stream_->requested_profile, 671 test_stream_->requested_profile,
655 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); 672 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this)));
656 673
657 CHECK(validator_.get()); 674 CHECK(validator_.get());
658 675
676 if (test_stream_->input_framerate > 0)
677 input_duration_ =
678 base::TimeDelta::FromSeconds(1) / test_stream->input_framerate;
679
659 if (save_to_file_) { 680 if (save_to_file_) {
660 CHECK(!test_stream_->out_filename.empty()); 681 CHECK(!test_stream_->out_filename.empty());
661 base::FilePath out_filename(test_stream_->out_filename); 682 base::FilePath out_filename(test_stream_->out_filename);
662 // This creates or truncates out_filename. 683 // This creates or truncates out_filename.
663 // Without it, AppendToFile() will not work. 684 // Without it, AppendToFile() will not work.
664 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); 685 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0));
665 } 686 }
666 687
667 // Initialize the parameters of the test streams. 688 // Initialize the parameters of the test streams.
668 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); 689 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch);
(...skipping 30 matching lines...) Expand all
699 720
700 SetStreamParameters(requested_bitrate_, requested_framerate_); 721 SetStreamParameters(requested_bitrate_, requested_framerate_);
701 SetState(CS_INITIALIZED); 722 SetState(CS_INITIALIZED);
702 } 723 }
703 724
704 void VEAClient::DestroyEncoder() { 725 void VEAClient::DestroyEncoder() {
705 DCHECK(thread_checker_.CalledOnValidThread()); 726 DCHECK(thread_checker_.CalledOnValidThread());
706 if (!has_encoder()) 727 if (!has_encoder())
707 return; 728 return;
708 encoder_.reset(); 729 encoder_.reset();
730 input_timer_.reset();
709 } 731 }
710 732
711 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, 733 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch,
712 bool mid_stream_framerate_switch) { 734 bool mid_stream_framerate_switch) {
713 // Use defaults for bitrate/framerate if they are not provided. 735 // Use defaults for bitrate/framerate if they are not provided.
714 if (test_stream_->requested_bitrate == 0) 736 if (test_stream_->requested_bitrate == 0)
715 requested_bitrate_ = kDefaultBitrate; 737 requested_bitrate_ = kDefaultBitrate;
716 else 738 else
717 requested_bitrate_ = test_stream_->requested_bitrate; 739 requested_bitrate_ = test_stream_->requested_bitrate;
718 740
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 ASSERT_GT(output_buffer_size_, 0UL); 807 ASSERT_GT(output_buffer_size_, 0UL);
786 808
787 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { 809 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) {
788 base::SharedMemory* shm = new base::SharedMemory(); 810 base::SharedMemory* shm = new base::SharedMemory();
789 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); 811 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_));
790 output_shms_.push_back(shm); 812 output_shms_.push_back(shm);
791 FeedEncoderWithOutput(shm); 813 FeedEncoderWithOutput(shm);
792 } 814 }
793 815
794 encode_start_time_ = base::TimeTicks::Now(); 816 encode_start_time_ = base::TimeTicks::Now();
795 FeedEncoderWithInputs(); 817 if (input_duration_ == base::TimeDelta()) {
818 while (inputs_at_client_.size() <
819 num_required_input_buffers_ + kNumExtraInputFrames)
820 FeedEncoderWithOneInput();
821 } else {
822 input_timer_.reset(new base::RepeatingTimer<VEAClient>());
823 input_timer_->Start(
824 FROM_HERE, input_duration_,
825 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this)));
826 }
796 } 827 }
797 828
798 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, 829 void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id,
799 size_t payload_size, 830 size_t payload_size,
800 bool key_frame) { 831 bool key_frame) {
801 DCHECK(thread_checker_.CalledOnValidThread()); 832 DCHECK(thread_checker_.CalledOnValidThread());
802 ASSERT_LE(payload_size, output_buffer_size_); 833 ASSERT_LE(payload_size, output_buffer_size_);
803 834
804 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); 835 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id);
805 ASSERT_NE(it, output_buffers_at_client_.end()); 836 ASSERT_NE(it, output_buffers_at_client_.end());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, 880 encoder_->RequestEncodingParametersChange(current_requested_bitrate_,
850 current_framerate_); 881 current_framerate_);
851 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ 882 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_
852 << " bps @ " << current_framerate_ << " FPS"; 883 << " bps @ " << current_framerate_ << " FPS";
853 } 884 }
854 885
855 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { 886 void VEAClient::InputNoLongerNeededCallback(int32 input_id) {
856 std::set<int32>::iterator it = inputs_at_client_.find(input_id); 887 std::set<int32>::iterator it = inputs_at_client_.find(input_id);
857 ASSERT_NE(it, inputs_at_client_.end()); 888 ASSERT_NE(it, inputs_at_client_.end());
858 inputs_at_client_.erase(it); 889 inputs_at_client_.erase(it);
859 FeedEncoderWithInputs(); 890 if (input_duration_ == base::TimeDelta())
891 FeedEncoderWithOneInput();
860 } 892 }
861 893
862 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { 894 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) {
863 CHECK_LE(position + test_stream_->aligned_buffer_size, 895 CHECK_LE(position + test_stream_->aligned_buffer_size,
864 test_stream_->mapped_aligned_in_file.length()); 896 test_stream_->mapped_aligned_in_file.length());
865 897
866 uint8* frame_data_y = const_cast<uint8*>( 898 uint8* frame_data_y = const_cast<uint8*>(
867 test_stream_->mapped_aligned_in_file.data() + position); 899 test_stream_->mapped_aligned_in_file.data() + position);
868 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0]; 900 uint8* frame_data_u = frame_data_y + test_stream_->aligned_plane_size[0];
869 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1]; 901 uint8* frame_data_v = frame_data_u + test_stream_->aligned_plane_size[1];
(...skipping 18 matching lines...) Expand all
888 base::Bind(&VEAClient::InputNoLongerNeededCallback, 920 base::Bind(&VEAClient::InputNoLongerNeededCallback,
889 base::Unretained(this), 921 base::Unretained(this),
890 next_input_id_))); 922 next_input_id_)));
891 923
892 CHECK(inputs_at_client_.insert(next_input_id_).second); 924 CHECK(inputs_at_client_.insert(next_input_id_).second);
893 ++next_input_id_; 925 ++next_input_id_;
894 926
895 return frame; 927 return frame;
896 } 928 }
897 929
898 void VEAClient::FeedEncoderWithInputs() { 930 void VEAClient::OnInputTimer() {
899 if (!has_encoder()) 931 if (!has_encoder() || state_ != CS_ENCODING)
932 // Destructor will also stop the timer.
933 input_timer_.reset();
934 else if (inputs_at_client_.size() <
935 num_required_input_buffers_ + kNumExtraInputFrames)
936 FeedEncoderWithOneInput();
937 else
938 DVLOG(1) << "Dropping input frame";
939 }
940
941 void VEAClient::FeedEncoderWithOneInput() {
942 if (!has_encoder() || state_ != CS_ENCODING)
900 return; 943 return;
901 944
902 if (state_ != CS_ENCODING) 945 size_t bytes_left =
903 return; 946 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_;
947 if (bytes_left < test_stream_->aligned_buffer_size) {
948 DCHECK_EQ(bytes_left, 0UL);
949 // Rewind if at the end of stream and we are still encoding.
950 // This is to flush the encoder with additional frames from the beginning
951 // of the stream, or if the stream is shorter that the number of frames
952 // we require for bitrate tests.
953 pos_in_input_stream_ = 0;
954 }
904 955
905 while (inputs_at_client_.size() < 956 bool force_keyframe = false;
906 num_required_input_buffers_ + kNumExtraInputFrames) { 957 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) {
907 size_t bytes_left = 958 keyframe_requested_at_ = next_input_id_;
908 test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; 959 force_keyframe = true;
909 if (bytes_left < test_stream_->aligned_buffer_size) { 960 }
910 DCHECK_EQ(bytes_left, 0UL);
911 // Rewind if at the end of stream and we are still encoding.
912 // This is to flush the encoder with additional frames from the beginning
913 // of the stream, or if the stream is shorter that the number of frames
914 // we require for bitrate tests.
915 pos_in_input_stream_ = 0;
916 continue;
917 }
918 961
919 bool force_keyframe = false; 962 scoped_refptr<media::VideoFrame> video_frame =
920 if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { 963 PrepareInputFrame(pos_in_input_stream_);
921 keyframe_requested_at_ = next_input_id_; 964 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
922 force_keyframe = true;
923 }
924 965
925 scoped_refptr<media::VideoFrame> video_frame = 966 encoder_->Encode(video_frame, force_keyframe);
926 PrepareInputFrame(pos_in_input_stream_);
927 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
928
929 encoder_->Encode(video_frame, force_keyframe);
930 }
931 } 967 }
932 968
933 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { 969 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) {
934 if (!has_encoder()) 970 if (!has_encoder())
935 return; 971 return;
936 972
937 if (state_ != CS_ENCODING) 973 if (state_ != CS_ENCODING)
938 return; 974 return;
939 975
940 base::SharedMemoryHandle dup_handle; 976 base::SharedMemoryHandle dup_handle;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 } 1234 }
1199 1235
1200 content::g_env = 1236 content::g_env =
1201 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( 1237 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>(
1202 testing::AddGlobalTestEnvironment( 1238 testing::AddGlobalTestEnvironment(
1203 new content::VideoEncodeAcceleratorTestEnvironment( 1239 new content::VideoEncodeAcceleratorTestEnvironment(
1204 test_stream_data.Pass()))); 1240 test_stream_data.Pass())));
1205 1241
1206 return RUN_ALL_TESTS(); 1242 return RUN_ALL_TESTS();
1207 } 1243 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698