Chromium Code Reviews| Index: content/common/gpu/media/video_encode_accelerator_unittest.cc |
| diff --git a/content/common/gpu/media/video_encode_accelerator_unittest.cc b/content/common/gpu/media/video_encode_accelerator_unittest.cc |
| index b1fb59226668a32f193cab0b3021bc9ac5b04df7..3502b0fd0901865dae72ff54fc9394daaa89a45f 100644 |
| --- a/content/common/gpu/media/video_encode_accelerator_unittest.cc |
| +++ b/content/common/gpu/media/video_encode_accelerator_unittest.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| #include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" |
| #include "media/base/bind_to_current_loop.h" |
| #include "media/base/bitstream_buffer.h" |
| @@ -95,6 +96,7 @@ const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; |
| // Environment to store test stream data for all test cases. |
| class VideoEncodeAcceleratorTestEnvironment; |
| VideoEncodeAcceleratorTestEnvironment* g_env; |
| +double g_input_fps = 0; |
|
wuchengli
2014/12/09 05:26:32
Document this and move it to VideoEncodeAccelerato
Owen Lin
2014/12/09 08:29:15
Done.
|
| struct TestStream { |
| TestStream() |
| @@ -501,6 +503,8 @@ class VEAClient : public VideoEncodeAccelerator::Client { |
| // via RequireBitstreamBuffers(). |
| void FeedEncoderWithInputs(); |
| + void FeedEncoderWithOneInputIfPossible(); |
|
wuchengli
2014/12/09 05:26:33
Document this. Since FeedEncoderWithInputs doesn't
Owen Lin
2014/12/09 08:29:15
The postfix "IfPossible" is because we may not fee
wuchengli
2014/12/10 02:29:14
Then FeedEncoderWithInputs should be changed to Fe
Owen Lin
2014/12/10 05:59:51
I was consider 0 as an example of multiple.
|
| + |
| // Provide the encoder with a new output buffer. |
| void FeedEncoderWithOutput(base::SharedMemory* shm); |
| @@ -613,6 +617,9 @@ class VEAClient : public VideoEncodeAccelerator::Client { |
| // Framerate to switch to in the middle of the stream. |
| unsigned int requested_subsequent_framerate_; |
| + |
| + scoped_ptr<base::RepeatingTimer<VEAClient>> input_timer_; |
| + base::TimeDelta input_duration_; |
|
wuchengli
2014/12/09 05:26:32
Document these two variables.
Owen Lin
2014/12/09 08:29:15
Done.
|
| }; |
| VEAClient::VEAClient(TestStream* test_stream, |
| @@ -656,6 +663,9 @@ VEAClient::VEAClient(TestStream* test_stream, |
| CHECK(validator_.get()); |
| + if (g_input_fps > 0) |
|
wuchengli
2014/12/09 05:26:33
This should be passed from the constructor.
Owen Lin
2014/12/09 08:29:15
Done.
|
| + input_duration_ = base::TimeDelta::FromSeconds(1) / g_input_fps; |
| + |
| if (save_to_file_) { |
| CHECK(!test_stream_->out_filename.empty()); |
| base::FilePath out_filename(test_stream_->out_filename); |
| @@ -706,6 +716,7 @@ void VEAClient::DestroyEncoder() { |
| if (!has_encoder()) |
| return; |
| encoder_.reset(); |
| + input_timer_.reset(); |
| } |
| void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, |
| @@ -792,7 +803,13 @@ void VEAClient::RequireBitstreamBuffers(unsigned int input_count, |
| } |
| encode_start_time_ = base::TimeTicks::Now(); |
| - FeedEncoderWithInputs(); |
| + if (input_duration_ == base::TimeDelta()) { |
| + FeedEncoderWithInputs(); |
| + } else { |
| + input_timer_.reset(new base::RepeatingTimer<VEAClient>()); |
| + input_timer_->Start(FROM_HERE, input_duration_, this, |
| + &VEAClient::FeedEncoderWithOneInputIfPossible); |
| + } |
| } |
| void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, |
| @@ -856,7 +873,8 @@ void VEAClient::InputNoLongerNeededCallback(int32 input_id) { |
| std::set<int32>::iterator it = inputs_at_client_.find(input_id); |
| ASSERT_NE(it, inputs_at_client_.end()); |
| inputs_at_client_.erase(it); |
| - FeedEncoderWithInputs(); |
| + if (input_duration_ == base::TimeDelta()) |
| + FeedEncoderWithInputs(); |
| } |
| scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { |
| @@ -930,6 +948,44 @@ void VEAClient::FeedEncoderWithInputs() { |
| } |
| } |
| +void VEAClient::FeedEncoderWithOneInputIfPossible() { |
| + if (!has_encoder() || state_ != CS_ENCODING) { |
| + // Destroctor will also stop the timer. |
|
wuchengli
2014/12/09 05:26:33
Destructor
Owen Lin
2014/12/09 08:29:15
Done.
|
| + input_timer_.reset(); |
| + return; |
| + } |
| + |
| + size_t bytes_left = |
| + test_stream_->mapped_aligned_in_file.length() - pos_in_input_stream_; |
| + if (bytes_left < test_stream_->aligned_buffer_size) { |
| + DCHECK_EQ(bytes_left, 0UL); |
| + // Rewind if at the end of stream and we are still encoding. |
| + // This is to flush the encoder with additional frames from the beginning |
| + // of the stream, or if the stream is shorter that the number of frames |
| + // we require for bitrate tests. |
| + pos_in_input_stream_ = 0; |
| + } |
| + |
| + if (inputs_at_client_.size() >= |
| + num_required_input_buffers_ + kNumExtraInputFrames) { |
| + DVLOG(1) << "Drop Input Frame: " + pos_in_input_stream_; |
| + pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
| + return; |
| + } |
| + |
| + bool force_keyframe = false; |
| + if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { |
| + keyframe_requested_at_ = next_input_id_; |
| + force_keyframe = true; |
| + } |
| + |
| + scoped_refptr<media::VideoFrame> video_frame = |
| + PrepareInputFrame(pos_in_input_stream_); |
| + pos_in_input_stream_ += test_stream_->aligned_buffer_size; |
| + |
| + encoder_->Encode(video_frame, force_keyframe); |
| +} |
| + |
| void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { |
| if (!has_encoder()) |
| return; |
| @@ -1192,6 +1248,13 @@ int main(int argc, char** argv) { |
| test_stream_data->assign(it->second.c_str()); |
| continue; |
| } |
| + if (it->first == "input_fps") { |
| + // On Windows, CommandLine::StringType is wstring. We need to convert |
| + // it to std::string first |
| + std::string input(it->second.begin(), it->second.end()); |
| + CHECK(base::StringToDouble(input, &content::g_input_fps)); |
| + continue; |
| + } |
| if (it->first == "v" || it->first == "vmodule") |
| continue; |
| LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |