Index: webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc |
diff --git a/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc b/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc |
index 18c2077d45dd2751432e04c8c0e75a959c7e4143..a02ec6c6e3a637d616c4ef21afa9fdb7f8d8f6d4 100644 |
--- a/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc |
+++ b/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc |
@@ -33,7 +33,8 @@ constexpr int64_t kMaxWaitEncTimeMs = 100; |
constexpr int64_t kMaxWaitDecTimeMs = 25; |
constexpr uint32_t kTestTimestamp = 123; |
brandtr
2017/08/30 09:08:17
kInitialRtpTimestamp?
åsapersson
2017/08/30 10:53:49
Done.
|
constexpr int64_t kTestNtpTimeMs = 456; |
-constexpr uint32_t kTimestampIncrementPerFrame = 3000; |
+constexpr int64_t kTimestampMs = 789; |
brandtr
2017/08/30 09:08:17
kInitialTimestampMs?
åsapersson
2017/08/30 10:53:49
Done.
|
+constexpr uint32_t kTimestampIncrement = 3000; |
constexpr int kNumCores = 1; |
constexpr size_t kMaxPayloadSize = 1440; |
constexpr int kMinPixelsPerFrame = 12345; |
@@ -67,6 +68,7 @@ class EncodedImageCallbackTestImpl : public webrtc::EncodedImageCallback { |
// Skip |codec_name|, to avoid allocating. |
EXPECT_STREQ("libvpx", codec_specific_info->codec_name); |
EXPECT_EQ(kVideoCodecVP8, codec_specific_info->codecType); |
+ EXPECT_EQ(0u, codec_specific_info->codecSpecific.VP8.simulcastIdx); |
codec_specific_info_.codecType = codec_specific_info->codecType; |
codec_specific_info_.codecSpecific = codec_specific_info->codecSpecific; |
complete_ = true; |
@@ -165,7 +167,9 @@ class TestVp8Impl : public ::testing::Test { |
// No scaling in our case, just a copy, to add stride to the image. |
stride_buffer->ScaleFrom(*compact_buffer); |
- input_frame_.reset(new VideoFrame(stride_buffer, kVideoRotation_0, 0)); |
+ input_frame_.reset( |
+ new VideoFrame(stride_buffer, kVideoRotation_0, |
brandtr
2017/08/30 09:08:17
Change to "preferred" ctor? Then you don't need to
åsapersson
2017/08/30 10:53:49
Done.
|
+ kTimestampMs * rtc::kNumMicrosecsPerMillisec)); |
input_frame_->set_timestamp(kTestTimestamp); |
fclose(file); |
} |
@@ -190,6 +194,11 @@ class TestVp8Impl : public ::testing::Test { |
decoder_->InitDecode(&codec_settings_, kNumCores)); |
} |
+ void EncodeFrame() { |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ } |
+ |
void WaitForEncodedFrame() { |
int64_t start_ms = rtc::TimeMillis(); |
while (rtc::TimeMillis() - start_ms < kMaxWaitEncTimeMs) { |
@@ -212,9 +221,9 @@ class TestVp8Impl : public ::testing::Test { |
int tl0_pic_idx, |
uint8_t temporal_idx) { |
WaitForEncodedFrame(); |
- EXPECT_EQ(picture_id, |
+ EXPECT_EQ(picture_id % (1 << 15), |
encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId); |
- EXPECT_EQ(tl0_pic_idx, |
+ EXPECT_EQ(tl0_pic_idx % (1 << 8), |
encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx); |
EXPECT_EQ(temporal_idx, |
encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); |
@@ -230,54 +239,61 @@ class TestVp8Impl : public ::testing::Test { |
TemporalLayersFactory tl_factory_; |
}; |
-TEST_F(TestVp8Impl, EncodeFrame) { |
- InitEncodeDecode(); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- WaitForEncodedFrame(); |
-} |
- |
-TEST_F(TestVp8Impl, EncoderParameterTest) { |
- codec_settings_.maxBitrate = 0; |
- codec_settings_.width = 1440; |
- codec_settings_.height = 1080; |
- |
- // Calls before InitEncode(). |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
+TEST_F(TestVp8Impl, SetRateAllocation) { |
const int kBitrateBps = 300000; |
BitrateAllocation bitrate_allocation; |
bitrate_allocation.SetBitrate(0, 0, kBitrateBps); |
EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, |
encoder_->SetRateAllocation(bitrate_allocation, |
codec_settings_.maxFramerate)); |
+ InitEncodeDecode(); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->SetRateAllocation(bitrate_allocation, |
+ codec_settings_.maxFramerate)); |
+} |
+ |
+TEST_F(TestVp8Impl, EncodeFrameAndRelease) { |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ WaitForEncodedFrame(); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
} |
-TEST_F(TestVp8Impl, DecoderParameterTest) { |
- // Calls before InitDecode(). |
+TEST_F(TestVp8Impl, InitDecode) { |
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
decoder_->InitDecode(&codec_settings_, kNumCores)); |
} |
+TEST_F(TestVp8Impl, OnEncodedImageReportsInfo) { |
+ InitEncodeDecode(); |
+ EncodeFrame(); |
+ EXPECT_EQ(kTestTimestamp, encoded_cb_.encoded_frame_._timeStamp); |
+ EXPECT_EQ(kTimestampMs, encoded_cb_.encoded_frame_.capture_time_ms_); |
+ EXPECT_EQ(kWidth, static_cast<int>(encoded_cb_.encoded_frame_._encodedWidth)); |
+ EXPECT_EQ(kHeight, |
+ static_cast<int>(encoded_cb_.encoded_frame_._encodedHeight)); |
+ EXPECT_EQ(-1, |
+ encoded_cb_.encoded_frame_.adapt_reason_.bw_resolutions_disabled); |
brandtr
2017/08/30 09:08:17
Is this field set/related to VP8Impl?
åsapersson
2017/08/30 10:53:49
Should be disabled for a single stream.
|
+} |
+ |
// We only test the encoder here, since the decoded frame rotation is set based |
// on the CVO RTP header extension in VCMDecodedFrameCallback::Decoded. |
// TODO(brandtr): Consider passing through the rotation flag through the decoder |
// in the same way as done in the encoder. |
TEST_F(TestVp8Impl, EncodedRotationEqualsInputRotation) { |
InitEncodeDecode(); |
- |
input_frame_->set_rotation(kVideoRotation_0); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- WaitForEncodedFrame(); |
+ EncodeFrame(); |
brandtr
2017/08/30 09:08:18
is WaitForEncodedFrame() not needed here?
Is it e
åsapersson
2017/08/30 10:53:49
Do not think it is ever needed, removed WaitForEnc
|
EXPECT_EQ(kVideoRotation_0, encoded_cb_.encoded_frame_.rotation_); |
input_frame_->set_rotation(kVideoRotation_90); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- WaitForEncodedFrame(); |
+ EncodeFrame(); |
brandtr
2017/08/30 09:08:18
and here.
|
EXPECT_EQ(kVideoRotation_90, encoded_cb_.encoded_frame_.rotation_); |
} |
@@ -342,44 +358,28 @@ TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) { |
} |
TEST_F(TestVp8Impl, EncoderRetainsRtpStateAfterRelease) { |
- InitEncodeDecode(); |
- // Override default settings. |
codec_settings_.VP8()->numberOfTemporalLayers = 2; |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
+ InitEncodeDecode(); |
// Temporal layer 0. |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- WaitForEncodedFrame(); |
+ EncodeFrame(); |
brandtr
2017/08/30 09:08:17
and here
|
EXPECT_EQ(0, encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); |
int16_t picture_id = |
encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId; |
int tl0_pic_idx = |
encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx; |
- |
// Temporal layer 1. |
- input_frame_->set_timestamp(input_frame_->timestamp() + |
- kTimestampIncrementPerFrame); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- ExpectFrameWith((picture_id + 1) % (1 << 15), tl0_pic_idx, 1); |
- |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 1, tl0_pic_idx + 0, 1); |
// Temporal layer 0. |
- input_frame_->set_timestamp(input_frame_->timestamp() + |
- kTimestampIncrementPerFrame); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- ExpectFrameWith((picture_id + 2) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8), |
- 0); |
- |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 2, tl0_pic_idx + 1, 0); |
// Temporal layer 1. |
- input_frame_->set_timestamp(input_frame_->timestamp() + |
- kTimestampIncrementPerFrame); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- ExpectFrameWith((picture_id + 3) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8), |
- 1); |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 3, tl0_pic_idx + 1, 1); |
// Reinit. |
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
@@ -387,36 +387,62 @@ TEST_F(TestVp8Impl, EncoderRetainsRtpStateAfterRelease) { |
encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
// Temporal layer 0. |
- input_frame_->set_timestamp(input_frame_->timestamp() + |
- kTimestampIncrementPerFrame); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- ExpectFrameWith((picture_id + 4) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8), |
- 0); |
- |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 4, tl0_pic_idx + 2, 0); |
// Temporal layer 1. |
- input_frame_->set_timestamp(input_frame_->timestamp() + |
- kTimestampIncrementPerFrame); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- ExpectFrameWith((picture_id + 5) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8), |
- 1); |
- |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 5, tl0_pic_idx + 2, 1); |
// Temporal layer 0. |
- input_frame_->set_timestamp(input_frame_->timestamp() + |
- kTimestampIncrementPerFrame); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- ExpectFrameWith((picture_id + 6) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8), |
- 0); |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 6, tl0_pic_idx + 3, 0); |
+ // Temporal layer 1. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 7, tl0_pic_idx + 3, 1); |
+} |
+ |
+TEST_F(TestVp8Impl, EncodeWithThreeTemporalLayers) { |
+ codec_settings_.VP8()->numberOfTemporalLayers = 3; |
+ InitEncodeDecode(); |
+ // Temporal layer 0. |
+ EncodeFrame(); |
+ EXPECT_EQ(0, encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); |
+ int16_t picture_id = |
+ encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId; |
+ int tl0_pic_idx = |
+ encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx; |
+ // Temporal layer 2. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 1, tl0_pic_idx + 0, 2); |
// Temporal layer 1. |
- input_frame_->set_timestamp(input_frame_->timestamp() + |
- kTimestampIncrementPerFrame); |
- EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
- encoder_->Encode(*input_frame_, nullptr, nullptr)); |
- ExpectFrameWith((picture_id + 7) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8), |
- 1); |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 2, tl0_pic_idx + 0, 1); |
+ // Temporal layer 2. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 3, tl0_pic_idx + 0, 2); |
+ // Temporal layer 0. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 4, tl0_pic_idx + 1, 0); |
+ // Temporal layer 2. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 5, tl0_pic_idx + 1, 2); |
+ // Temporal layer 1. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 6, tl0_pic_idx + 1, 1); |
+ // Temporal layer 2. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
+ EncodeFrame(); |
+ ExpectFrameWith(picture_id + 7, tl0_pic_idx + 1, 2); |
} |
brandtr
2017/08/30 09:08:17
Might as well add a reinit here, and make this tes
åsapersson
2017/08/30 10:53:49
Done.
|
TEST_F(TestVp8Impl, ScalingDisabledIfAutomaticResizeOff) { |