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 18054a18752835e938142be1e9cedf39f7a24b02..73e319afb47afa7875fd62a7416e127e45f98118 100644 |
--- a/content/common/gpu/media/video_encode_accelerator_unittest.cc |
+++ b/content/common/gpu/media/video_encode_accelerator_unittest.cc |
@@ -494,9 +494,7 @@ scoped_ptr<StreamValidator> StreamValidator::Create( |
const FrameFoundCallback& frame_cb) { |
scoped_ptr<StreamValidator> validator; |
- if (g_fake_encoder) { |
- validator.reset(NULL); |
- } else if (IsH264(profile)) { |
+ if (IsH264(profile)) { |
validator.reset(new H264Validator(frame_cb)); |
} else if (IsVP8(profile)) { |
validator.reset(new VP8Validator(frame_cb)); |
@@ -633,8 +631,11 @@ class VEAClient : public VideoEncodeAccelerator::Client { |
// Request a keyframe every keyframe_period_ frames. |
const unsigned int keyframe_period_; |
- // Frame number for which we requested a keyframe. |
- unsigned int keyframe_requested_at_; |
+ // Number of keyframes requested by now. |
+ unsigned int num_keyframes_requested_; |
+ |
+ // Next keyframe expected before next_keyframe_at_ + kMaxKeyframeDelay. |
+ unsigned int next_keyframe_at_; |
// True if we are asking encoder for a particular bitrate. |
bool force_bitrate_; |
@@ -696,7 +697,7 @@ VEAClient::VEAClient(TestStream* test_stream, |
: state_(CS_CREATED), |
test_stream_(test_stream), |
note_(note), |
- next_input_id_(1), |
+ next_input_id_(0), |
next_output_buffer_id_(0), |
pos_in_input_stream_(0), |
num_required_input_buffers_(0), |
@@ -707,7 +708,8 @@ VEAClient::VEAClient(TestStream* test_stream, |
seen_keyframe_in_this_buffer_(false), |
save_to_file_(save_to_file), |
keyframe_period_(keyframe_period), |
- keyframe_requested_at_(kMaxFrameNum), |
+ num_keyframes_requested_(0), |
+ next_keyframe_at_(kMaxFrameNum), |
force_bitrate_(force_bitrate), |
current_requested_bitrate_(0), |
current_framerate_(0), |
@@ -721,12 +723,13 @@ VEAClient::VEAClient(TestStream* test_stream, |
if (keyframe_period_) |
CHECK_LT(kMaxKeyframeDelay, keyframe_period_); |
- validator_ = StreamValidator::Create( |
- test_stream_->requested_profile, |
- base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
- |
- |
- CHECK(g_fake_encoder || validator_.get()); |
+ // Fake encoder produces an invalid stream, so skip validating it. |
+ if (!g_fake_encoder) { |
+ validator_ = StreamValidator::Create( |
+ test_stream_->requested_profile, |
+ base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
+ CHECK(validator_); |
+ } |
if (save_to_file_) { |
CHECK(!test_stream_->out_filename.empty()); |
@@ -1050,8 +1053,8 @@ void VEAClient::FeedEncoderWithOneInput() { |
bool force_keyframe = false; |
if (keyframe_period_ && next_input_id_ % keyframe_period_ == 0) { |
- keyframe_requested_at_ = next_input_id_; |
force_keyframe = true; |
+ ++num_keyframes_requested_; |
} |
scoped_refptr<media::VideoFrame> video_frame = |
@@ -1087,12 +1090,6 @@ bool VEAClient::HandleEncodedFrame(bool keyframe) { |
++num_frames_since_last_check_; |
last_frame_ready_time_ = base::TimeTicks::Now(); |
- if (keyframe) { |
- // Got keyframe, reset keyframe detection regardless of whether we |
- // got a frame in time or not. |
- keyframe_requested_at_ = kMaxFrameNum; |
- seen_keyframe_in_this_buffer_ = true; |
- } |
// Because the keyframe behavior requirements are loose, we give |
// the encoder more freedom here. It could either deliver a keyframe |
@@ -1104,7 +1101,14 @@ bool VEAClient::HandleEncodedFrame(bool keyframe) { |
// earlier than we requested one (in time), and not later than |
// kMaxKeyframeDelay frames after the frame, for which we requested |
// it, comes back encoded. |
- EXPECT_LE(num_encoded_frames_, keyframe_requested_at_ + kMaxKeyframeDelay); |
+ EXPECT_LE(num_encoded_frames_, next_keyframe_at_ + kMaxKeyframeDelay); |
+ |
+ if (keyframe) { |
+ if (num_keyframes_requested_ > 0) |
+ --num_keyframes_requested_; |
+ next_keyframe_at_ += keyframe_period_; |
+ seen_keyframe_in_this_buffer_ = true; |
+ } |
if (num_encoded_frames_ == num_frames_to_encode_ / 2) { |
VerifyStreamProperties(); |
@@ -1152,6 +1156,14 @@ void VEAClient::VerifyStreamProperties() { |
current_requested_bitrate_, |
kBitrateTolerance * current_requested_bitrate_); |
} |
+ |
+ // All requested keyframes should've been provided. Allow the last requested |
+ // frame to remain undelivered if we haven't reached the maximum frame number |
+ // by which it should have arrived. |
+ if (num_encoded_frames_ < next_keyframe_at_ + kMaxKeyframeDelay) |
+ EXPECT_LE(num_keyframes_requested_, 1UL); |
+ else |
+ EXPECT_EQ(num_keyframes_requested_, 0UL); |
} |
void VEAClient::WriteIvfFileHeader() { |