OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "webrtc/rtc_base/timeutils.h" | 22 #include "webrtc/rtc_base/timeutils.h" |
23 #include "webrtc/test/field_trial.h" | 23 #include "webrtc/test/field_trial.h" |
24 #include "webrtc/test/frame_utils.h" | 24 #include "webrtc/test/frame_utils.h" |
25 #include "webrtc/test/gtest.h" | 25 #include "webrtc/test/gtest.h" |
26 #include "webrtc/test/testsupport/fileutils.h" | 26 #include "webrtc/test/testsupport/fileutils.h" |
27 #include "webrtc/test/video_codec_settings.h" | 27 #include "webrtc/test/video_codec_settings.h" |
28 | 28 |
29 namespace webrtc { | 29 namespace webrtc { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | |
33 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { | |
34 *stride_y = 16 * ((width + 15) / 16); | |
35 *stride_uv = 16 * ((width + 31) / 32); | |
36 } | |
37 | |
38 constexpr int64_t kMaxWaitEncTimeMs = 100; | 32 constexpr int64_t kMaxWaitEncTimeMs = 100; |
39 constexpr int64_t kMaxWaitDecTimeMs = 25; | 33 constexpr int64_t kMaxWaitDecTimeMs = 25; |
40 constexpr uint32_t kTestTimestamp = 123; | 34 constexpr uint32_t kTestTimestamp = 123; |
41 constexpr int64_t kTestNtpTimeMs = 456; | 35 constexpr int64_t kTestNtpTimeMs = 456; |
42 constexpr uint32_t kTimestampIncrementPerFrame = 3000; | 36 constexpr uint32_t kTimestampIncrementPerFrame = 3000; |
43 constexpr int kNumCores = 1; | 37 constexpr int kNumCores = 1; |
44 constexpr size_t kMaxPayloadSize = 1440; | 38 constexpr size_t kMaxPayloadSize = 1440; |
45 constexpr int kMinPixelsPerFrame = 12345; | 39 constexpr int kMinPixelsPerFrame = 12345; |
46 constexpr int kDefaultMinPixelsPerFrame = 320 * 180; | 40 constexpr int kDefaultMinPixelsPerFrame = 320 * 180; |
47 constexpr int kWidth = 172; | 41 constexpr int kWidth = 172; |
48 constexpr int kHeight = 144; | 42 constexpr int kHeight = 144; |
| 43 |
| 44 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { |
| 45 *stride_y = 16 * ((width + 15) / 16); |
| 46 *stride_uv = 16 * ((width + 31) / 32); |
| 47 } |
49 } // namespace | 48 } // namespace |
50 | 49 |
51 class Vp8UnitTestEncodeCompleteCallback : public webrtc::EncodedImageCallback { | 50 class EncodedImageCallbackTestImpl : public webrtc::EncodedImageCallback { |
52 public: | 51 public: |
53 Vp8UnitTestEncodeCompleteCallback(EncodedImage* frame, | |
54 CodecSpecificInfo* codec_specific_info) | |
55 : encoded_frame_(frame), | |
56 codec_specific_info_(codec_specific_info), | |
57 encode_complete_(false) {} | |
58 | |
59 Result OnEncodedImage(const EncodedImage& encoded_frame, | 52 Result OnEncodedImage(const EncodedImage& encoded_frame, |
60 const CodecSpecificInfo* codec_specific_info, | 53 const CodecSpecificInfo* codec_specific_info, |
61 const RTPFragmentationHeader* fragmentation) override; | 54 const RTPFragmentationHeader* fragmentation) override { |
62 bool EncodeComplete(); | 55 EXPECT_GT(encoded_frame._length, 0u); |
| 56 VerifyQpParser(encoded_frame); |
| 57 |
| 58 if (encoded_frame_._size != encoded_frame._size) { |
| 59 delete[] encoded_frame_._buffer; |
| 60 frame_buffer_.reset(new uint8_t[encoded_frame._size]); |
| 61 } |
| 62 RTC_DCHECK(frame_buffer_); |
| 63 memcpy(frame_buffer_.get(), encoded_frame._buffer, encoded_frame._length); |
| 64 encoded_frame_ = encoded_frame; |
| 65 encoded_frame_._buffer = frame_buffer_.get(); |
| 66 |
| 67 // Skip |codec_name|, to avoid allocating. |
| 68 EXPECT_STREQ("libvpx", codec_specific_info->codec_name); |
| 69 EXPECT_EQ(kVideoCodecVP8, codec_specific_info->codecType); |
| 70 codec_specific_info_.codecType = codec_specific_info->codecType; |
| 71 codec_specific_info_.codecSpecific = codec_specific_info->codecSpecific; |
| 72 complete_ = true; |
| 73 return Result(Result::OK, 0); |
| 74 } |
63 | 75 |
64 void VerifyQpParser(const EncodedImage& encoded_frame) const { | 76 void VerifyQpParser(const EncodedImage& encoded_frame) const { |
65 int qp; | 77 int qp; |
66 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); | 78 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); |
67 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != parsed bitstream QP."; | 79 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != parsed bitstream QP."; |
68 } | 80 } |
69 | 81 |
70 private: | 82 bool EncodeComplete() { |
71 EncodedImage* const encoded_frame_; | 83 if (complete_) { |
72 CodecSpecificInfo* const codec_specific_info_; | 84 complete_ = false; |
| 85 return true; |
| 86 } |
| 87 return false; |
| 88 } |
| 89 |
| 90 EncodedImage encoded_frame_; |
| 91 CodecSpecificInfo codec_specific_info_; |
73 std::unique_ptr<uint8_t[]> frame_buffer_; | 92 std::unique_ptr<uint8_t[]> frame_buffer_; |
74 bool encode_complete_; | 93 bool complete_ = false; |
75 }; | 94 }; |
76 | 95 |
77 webrtc::EncodedImageCallback::Result | 96 class DecodedImageCallbackTestImpl : public webrtc::DecodedImageCallback { |
78 Vp8UnitTestEncodeCompleteCallback::OnEncodedImage( | |
79 const EncodedImage& encoded_frame, | |
80 const CodecSpecificInfo* codec_specific_info, | |
81 const RTPFragmentationHeader* fragmentation) { | |
82 EXPECT_GT(encoded_frame._length, 0u); | |
83 VerifyQpParser(encoded_frame); | |
84 | |
85 if (encoded_frame_->_size != encoded_frame._size) { | |
86 delete[] encoded_frame_->_buffer; | |
87 frame_buffer_.reset(new uint8_t[encoded_frame._size]); | |
88 } | |
89 memcpy(frame_buffer_.get(), encoded_frame._buffer, encoded_frame._length); | |
90 *encoded_frame_ = encoded_frame; | |
91 encoded_frame_->_buffer = frame_buffer_.get(); | |
92 | |
93 // Skip |codec_name|, to avoid allocating. | |
94 codec_specific_info_->codecType = codec_specific_info->codecType; | |
95 codec_specific_info_->codecSpecific = codec_specific_info->codecSpecific; | |
96 encode_complete_ = true; | |
97 return Result(Result::OK, 0); | |
98 } | |
99 | |
100 bool Vp8UnitTestEncodeCompleteCallback::EncodeComplete() { | |
101 if (encode_complete_) { | |
102 encode_complete_ = false; | |
103 return true; | |
104 } | |
105 return false; | |
106 } | |
107 | |
108 class Vp8UnitTestDecodeCompleteCallback : public webrtc::DecodedImageCallback { | |
109 public: | 97 public: |
110 explicit Vp8UnitTestDecodeCompleteCallback(rtc::Optional<VideoFrame>* frame, | |
111 rtc::Optional<uint8_t>* qp) | |
112 : decoded_frame_(frame), decoded_qp_(qp), decode_complete_(false) {} | |
113 int32_t Decoded(VideoFrame& frame) override { | 98 int32_t Decoded(VideoFrame& frame) override { |
114 RTC_NOTREACHED(); | 99 RTC_NOTREACHED(); |
115 return -1; | 100 return -1; |
116 } | 101 } |
117 int32_t Decoded(VideoFrame& frame, int64_t decode_time_ms) override { | 102 int32_t Decoded(VideoFrame& frame, int64_t decode_time_ms) override { |
118 RTC_NOTREACHED(); | 103 RTC_NOTREACHED(); |
119 return -1; | 104 return -1; |
120 } | 105 } |
121 void Decoded(VideoFrame& frame, | 106 void Decoded(VideoFrame& frame, |
122 rtc::Optional<int32_t> decode_time_ms, | 107 rtc::Optional<int32_t> decode_time_ms, |
123 rtc::Optional<uint8_t> qp) override; | 108 rtc::Optional<uint8_t> qp) override { |
124 bool DecodeComplete(); | 109 EXPECT_GT(frame.width(), 0); |
| 110 EXPECT_GT(frame.height(), 0); |
| 111 EXPECT_TRUE(qp); |
| 112 frame_ = rtc::Optional<VideoFrame>(frame); |
| 113 qp_ = qp; |
| 114 complete_ = true; |
| 115 } |
125 | 116 |
126 private: | 117 bool DecodeComplete() { |
127 rtc::Optional<VideoFrame>* decoded_frame_; | 118 if (complete_) { |
128 rtc::Optional<uint8_t>* decoded_qp_; | 119 complete_ = false; |
129 bool decode_complete_; | 120 return true; |
| 121 } |
| 122 return false; |
| 123 } |
| 124 |
| 125 rtc::Optional<VideoFrame> frame_; |
| 126 rtc::Optional<uint8_t> qp_; |
| 127 bool complete_ = false; |
130 }; | 128 }; |
131 | 129 |
132 bool Vp8UnitTestDecodeCompleteCallback::DecodeComplete() { | |
133 if (decode_complete_) { | |
134 decode_complete_ = false; | |
135 return true; | |
136 } | |
137 return false; | |
138 } | |
139 | |
140 void Vp8UnitTestDecodeCompleteCallback::Decoded( | |
141 VideoFrame& frame, | |
142 rtc::Optional<int32_t> decode_time_ms, | |
143 rtc::Optional<uint8_t> qp) { | |
144 EXPECT_GT(frame.width(), 0); | |
145 EXPECT_GT(frame.height(), 0); | |
146 *decoded_frame_ = rtc::Optional<VideoFrame>(frame); | |
147 *decoded_qp_ = qp; | |
148 decode_complete_ = true; | |
149 } | |
150 | |
151 class TestVp8Impl : public ::testing::Test { | 130 class TestVp8Impl : public ::testing::Test { |
152 protected: | 131 public: |
153 TestVp8Impl() : TestVp8Impl("") {} | 132 TestVp8Impl() : TestVp8Impl("") {} |
154 explicit TestVp8Impl(const std::string& field_trials) | 133 explicit TestVp8Impl(const std::string& field_trials) |
155 : override_field_trials_(field_trials) {} | 134 : override_field_trials_(field_trials), |
| 135 encoder_(VP8Encoder::Create()), |
| 136 decoder_(VP8Decoder::Create()) {} |
| 137 virtual ~TestVp8Impl() {} |
156 | 138 |
| 139 protected: |
157 virtual void SetUp() { | 140 virtual void SetUp() { |
158 encoder_.reset(VP8Encoder::Create()); | 141 encoder_->RegisterEncodeCompleteCallback(&encoded_cb_); |
159 decoder_.reset(VP8Decoder::Create()); | 142 decoder_->RegisterDecodeCompleteCallback(&decoded_cb_); |
160 encode_complete_callback_.reset(new Vp8UnitTestEncodeCompleteCallback( | 143 SetupCodecSettings(); |
161 &encoded_frame_, &codec_specific_info_)); | 144 SetupInputFrame(); |
162 decode_complete_callback_.reset( | 145 } |
163 new Vp8UnitTestDecodeCompleteCallback(&decoded_frame_, &decoded_qp_)); | |
164 encoder_->RegisterEncodeCompleteCallback(encode_complete_callback_.get()); | |
165 decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get()); | |
166 | 146 |
167 SetupCodecSettings(); | 147 void SetupInputFrame() { |
168 | |
169 // Using a QCIF image (aligned stride (u,v planes) > width). | 148 // Using a QCIF image (aligned stride (u,v planes) > width). |
170 // Processing only one frame. | 149 // Processing only one frame. |
171 FILE* file = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb"); | 150 FILE* file = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb"); |
172 ASSERT_TRUE(file != nullptr); | 151 ASSERT_TRUE(file != nullptr); |
173 rtc::scoped_refptr<I420BufferInterface> compact_buffer( | 152 rtc::scoped_refptr<I420BufferInterface> compact_buffer( |
174 test::ReadI420Buffer(kWidth, kHeight, file)); | 153 test::ReadI420Buffer(kWidth, kHeight, file)); |
175 ASSERT_TRUE(compact_buffer); | 154 ASSERT_TRUE(compact_buffer); |
| 155 |
176 // Setting aligned stride values. | 156 // Setting aligned stride values. |
177 int stride_uv; | 157 int stride_uv; |
178 int stride_y; | 158 int stride_y; |
179 Calc16ByteAlignedStride(kWidth, &stride_y, &stride_uv); | 159 Calc16ByteAlignedStride(kWidth, &stride_y, &stride_uv); |
180 EXPECT_EQ(stride_y, 176); | 160 EXPECT_EQ(stride_y, 176); |
181 EXPECT_EQ(stride_uv, 96); | 161 EXPECT_EQ(stride_uv, 96); |
182 | |
183 rtc::scoped_refptr<I420Buffer> stride_buffer( | 162 rtc::scoped_refptr<I420Buffer> stride_buffer( |
184 I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv)); | 163 I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv)); |
185 | 164 |
186 // No scaling in our case, just a copy, to add stride to the image. | 165 // No scaling in our case, just a copy, to add stride to the image. |
187 stride_buffer->ScaleFrom(*compact_buffer); | 166 stride_buffer->ScaleFrom(*compact_buffer); |
188 | 167 |
189 input_frame_.reset(new VideoFrame(stride_buffer, kVideoRotation_0, 0)); | 168 input_frame_.reset(new VideoFrame(stride_buffer, kVideoRotation_0, 0)); |
190 input_frame_->set_timestamp(kTestTimestamp); | 169 input_frame_->set_timestamp(kTestTimestamp); |
191 fclose(file); | 170 fclose(file); |
192 } | 171 } |
193 | 172 |
194 void SetupCodecSettings() { | 173 void SetupCodecSettings() { |
195 webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings_); | 174 webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings_); |
196 codec_settings_.maxBitrate = 4000; | 175 codec_settings_.maxBitrate = 4000; |
197 codec_settings_.width = kWidth; | 176 codec_settings_.width = kWidth; |
198 codec_settings_.height = kHeight; | 177 codec_settings_.height = kHeight; |
199 codec_settings_.VP8()->denoisingOn = true; | 178 codec_settings_.VP8()->denoisingOn = true; |
200 codec_settings_.VP8()->frameDroppingOn = false; | 179 codec_settings_.VP8()->frameDroppingOn = false; |
201 codec_settings_.VP8()->automaticResizeOn = false; | 180 codec_settings_.VP8()->automaticResizeOn = false; |
202 codec_settings_.VP8()->complexity = kComplexityNormal; | 181 codec_settings_.VP8()->complexity = kComplexityNormal; |
203 codec_settings_.VP8()->tl_factory = &tl_factory_; | 182 codec_settings_.VP8()->tl_factory = &tl_factory_; |
204 } | 183 } |
205 | 184 |
206 void SetUpEncodeDecode() { | 185 void InitEncodeDecode() { |
207 EXPECT_EQ( | 186 EXPECT_EQ( |
208 WEBRTC_VIDEO_CODEC_OK, | 187 WEBRTC_VIDEO_CODEC_OK, |
209 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | 188 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
210 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 189 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
211 decoder_->InitDecode(&codec_settings_, kNumCores)); | 190 decoder_->InitDecode(&codec_settings_, kNumCores)); |
212 } | 191 } |
213 | 192 |
214 void WaitForEncodedFrame() const { | 193 void WaitForEncodedFrame() { |
215 int64_t start_ms = rtc::TimeMillis(); | 194 int64_t start_ms = rtc::TimeMillis(); |
216 while (rtc::TimeMillis() - start_ms < kMaxWaitEncTimeMs) { | 195 while (rtc::TimeMillis() - start_ms < kMaxWaitEncTimeMs) { |
217 if (encode_complete_callback_->EncodeComplete()) { | 196 if (encoded_cb_.EncodeComplete()) |
218 return; | 197 return; |
219 } | |
220 } | 198 } |
221 ASSERT_TRUE(false); | 199 ASSERT_TRUE(false); |
222 } | 200 } |
223 | 201 |
224 void WaitForDecodedFrame() const { | 202 void WaitForDecodedFrame() { |
225 int64_t start_ms = rtc::TimeMillis(); | 203 int64_t start_ms = rtc::TimeMillis(); |
226 while (rtc::TimeMillis() - start_ms < kMaxWaitDecTimeMs) { | 204 while (rtc::TimeMillis() - start_ms < kMaxWaitDecTimeMs) { |
227 if (decode_complete_callback_->DecodeComplete()) { | 205 if (decoded_cb_.DecodeComplete()) |
228 return; | 206 return; |
229 } | |
230 } | 207 } |
231 ASSERT_TRUE(false); | 208 ASSERT_TRUE(false); |
232 } | 209 } |
233 | 210 |
234 void ExpectFrameWith(int16_t picture_id, | 211 void ExpectFrameWith(int16_t picture_id, |
235 int tl0_pic_idx, | 212 int tl0_pic_idx, |
236 uint8_t temporal_idx) { | 213 uint8_t temporal_idx) { |
237 WaitForEncodedFrame(); | 214 WaitForEncodedFrame(); |
238 EXPECT_EQ(picture_id, codec_specific_info_.codecSpecific.VP8.pictureId); | 215 EXPECT_EQ(picture_id, |
239 EXPECT_EQ(tl0_pic_idx, codec_specific_info_.codecSpecific.VP8.tl0PicIdx); | 216 encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId); |
240 EXPECT_EQ(temporal_idx, codec_specific_info_.codecSpecific.VP8.temporalIdx); | 217 EXPECT_EQ(tl0_pic_idx, |
| 218 encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx); |
| 219 EXPECT_EQ(temporal_idx, |
| 220 encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); |
241 } | 221 } |
242 | 222 |
243 test::ScopedFieldTrials override_field_trials_; | 223 test::ScopedFieldTrials override_field_trials_; |
244 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; | 224 EncodedImageCallbackTestImpl encoded_cb_; |
245 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; | 225 DecodedImageCallbackTestImpl decoded_cb_; |
246 std::unique_ptr<VideoFrame> input_frame_; | 226 std::unique_ptr<VideoFrame> input_frame_; |
247 std::unique_ptr<VideoEncoder> encoder_; | 227 const std::unique_ptr<VideoEncoder> encoder_; |
248 std::unique_ptr<VideoDecoder> decoder_; | 228 const std::unique_ptr<VideoDecoder> decoder_; |
249 EncodedImage encoded_frame_; | |
250 CodecSpecificInfo codec_specific_info_; | |
251 rtc::Optional<VideoFrame> decoded_frame_; | |
252 rtc::Optional<uint8_t> decoded_qp_; | |
253 VideoCodec codec_settings_; | 229 VideoCodec codec_settings_; |
254 TemporalLayersFactory tl_factory_; | 230 TemporalLayersFactory tl_factory_; |
255 }; | 231 }; |
256 | 232 |
257 TEST_F(TestVp8Impl, EncodeFrame) { | 233 TEST_F(TestVp8Impl, EncodeFrame) { |
258 SetUpEncodeDecode(); | 234 InitEncodeDecode(); |
259 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 235 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
260 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 236 encoder_->Encode(*input_frame_, nullptr, nullptr)); |
261 WaitForEncodedFrame(); | 237 WaitForEncodedFrame(); |
262 } | 238 } |
263 | 239 |
264 TEST_F(TestVp8Impl, EncoderParameterTest) { | 240 TEST_F(TestVp8Impl, EncoderParameterTest) { |
265 codec_settings_.maxBitrate = 0; | 241 codec_settings_.maxBitrate = 0; |
266 codec_settings_.width = 1440; | 242 codec_settings_.width = 1440; |
267 codec_settings_.height = 1080; | 243 codec_settings_.height = 1080; |
268 | 244 |
269 // Calls before InitEncode(). | 245 // Calls before InitEncode(). |
270 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | 246 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
271 const int kBitrateKbps = 300; | 247 const int kBitrateBps = 300000; |
272 BitrateAllocation bitrate_allocation; | 248 BitrateAllocation bitrate_allocation; |
273 bitrate_allocation.SetBitrate(0, 0, kBitrateKbps * 1000); | 249 bitrate_allocation.SetBitrate(0, 0, kBitrateBps); |
274 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, | 250 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, |
275 encoder_->SetRateAllocation(bitrate_allocation, | 251 encoder_->SetRateAllocation(bitrate_allocation, |
276 codec_settings_.maxFramerate)); | 252 codec_settings_.maxFramerate)); |
277 | |
278 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 253 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
279 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | 254 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
| 255 } |
280 | 256 |
281 // Decoder parameter tests. | 257 TEST_F(TestVp8Impl, DecoderParameterTest) { |
282 // Calls before InitDecode(). | 258 // Calls before InitDecode(). |
283 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); | 259 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
284 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 260 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
285 decoder_->InitDecode(&codec_settings_, kNumCores)); | 261 decoder_->InitDecode(&codec_settings_, kNumCores)); |
286 } | 262 } |
287 | 263 |
288 // We only test the encoder here, since the decoded frame rotation is set based | 264 // We only test the encoder here, since the decoded frame rotation is set based |
289 // on the CVO RTP header extension in VCMDecodedFrameCallback::Decoded. | 265 // on the CVO RTP header extension in VCMDecodedFrameCallback::Decoded. |
290 // TODO(brandtr): Consider passing through the rotation flag through the decoder | 266 // TODO(brandtr): Consider passing through the rotation flag through the decoder |
291 // in the same way as done in the encoder. | 267 // in the same way as done in the encoder. |
292 TEST_F(TestVp8Impl, EncodedRotationEqualsInputRotation) { | 268 TEST_F(TestVp8Impl, EncodedRotationEqualsInputRotation) { |
293 SetUpEncodeDecode(); | 269 InitEncodeDecode(); |
294 | 270 |
295 input_frame_->set_rotation(kVideoRotation_0); | 271 input_frame_->set_rotation(kVideoRotation_0); |
296 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 272 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
297 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 273 encoder_->Encode(*input_frame_, nullptr, nullptr)); |
298 WaitForEncodedFrame(); | 274 WaitForEncodedFrame(); |
299 EXPECT_EQ(kVideoRotation_0, encoded_frame_.rotation_); | 275 EXPECT_EQ(kVideoRotation_0, encoded_cb_.encoded_frame_.rotation_); |
300 | 276 |
301 input_frame_->set_rotation(kVideoRotation_90); | 277 input_frame_->set_rotation(kVideoRotation_90); |
302 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 278 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
303 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 279 encoder_->Encode(*input_frame_, nullptr, nullptr)); |
304 WaitForEncodedFrame(); | 280 WaitForEncodedFrame(); |
305 EXPECT_EQ(kVideoRotation_90, encoded_frame_.rotation_); | 281 EXPECT_EQ(kVideoRotation_90, encoded_cb_.encoded_frame_.rotation_); |
306 } | 282 } |
307 | 283 |
308 TEST_F(TestVp8Impl, DecodedQpEqualsEncodedQp) { | 284 TEST_F(TestVp8Impl, DecodedQpEqualsEncodedQp) { |
309 SetUpEncodeDecode(); | 285 InitEncodeDecode(); |
310 encoder_->Encode(*input_frame_, nullptr, nullptr); | 286 encoder_->Encode(*input_frame_, nullptr, nullptr); |
311 WaitForEncodedFrame(); | 287 WaitForEncodedFrame(); |
312 // First frame should be a key frame. | 288 // First frame should be a key frame. |
313 encoded_frame_._frameType = kVideoFrameKey; | 289 encoded_cb_.encoded_frame_._frameType = kVideoFrameKey; |
314 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 290 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
315 decoder_->Decode(encoded_frame_, false, nullptr)); | 291 decoder_->Decode(encoded_cb_.encoded_frame_, false, nullptr)); |
316 WaitForDecodedFrame(); | 292 WaitForDecodedFrame(); |
317 ASSERT_TRUE(decoded_frame_); | 293 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_cb_.frame_), 36); |
318 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); | 294 EXPECT_EQ(encoded_cb_.encoded_frame_.qp_, *decoded_cb_.qp_); |
319 ASSERT_TRUE(decoded_qp_); | |
320 EXPECT_EQ(encoded_frame_.qp_, *decoded_qp_); | |
321 } | 295 } |
322 | 296 |
323 #if defined(WEBRTC_ANDROID) | 297 #if defined(WEBRTC_ANDROID) |
324 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode | 298 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode |
325 #else | 299 #else |
326 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode | 300 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode |
327 #endif | 301 #endif |
328 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) { | 302 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) { |
329 SetUpEncodeDecode(); | 303 InitEncodeDecode(); |
330 encoder_->Encode(*input_frame_, nullptr, nullptr); | 304 encoder_->Encode(*input_frame_, nullptr, nullptr); |
331 WaitForEncodedFrame(); | 305 WaitForEncodedFrame(); |
332 // First frame should be a key frame. | 306 // First frame should be a key frame. |
333 encoded_frame_._frameType = kVideoFrameKey; | 307 encoded_cb_.encoded_frame_._frameType = kVideoFrameKey; |
334 encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs; | 308 encoded_cb_.encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs; |
335 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 309 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
336 decoder_->Decode(encoded_frame_, false, nullptr)); | 310 decoder_->Decode(encoded_cb_.encoded_frame_, false, nullptr)); |
337 WaitForDecodedFrame(); | 311 WaitForDecodedFrame(); |
338 ASSERT_TRUE(decoded_frame_); | |
339 // Compute PSNR on all planes (faster than SSIM). | 312 // Compute PSNR on all planes (faster than SSIM). |
340 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); | 313 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_cb_.frame_), 36); |
341 EXPECT_EQ(kTestTimestamp, decoded_frame_->timestamp()); | 314 EXPECT_EQ(kTestTimestamp, decoded_cb_.frame_->timestamp()); |
342 EXPECT_EQ(kTestNtpTimeMs, decoded_frame_->ntp_time_ms()); | 315 EXPECT_EQ(kTestNtpTimeMs, decoded_cb_.frame_->ntp_time_ms()); |
343 } | 316 } |
344 | 317 |
345 #if defined(WEBRTC_ANDROID) | 318 #if defined(WEBRTC_ANDROID) |
346 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame | 319 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame |
347 #else | 320 #else |
348 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame | 321 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame |
349 #endif | 322 #endif |
350 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) { | 323 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) { |
351 SetUpEncodeDecode(); | 324 InitEncodeDecode(); |
352 encoder_->Encode(*input_frame_, nullptr, nullptr); | 325 encoder_->Encode(*input_frame_, nullptr, nullptr); |
353 WaitForEncodedFrame(); | 326 WaitForEncodedFrame(); |
354 // Setting complete to false -> should return an error. | 327 // Setting complete to false -> should return an error. |
355 encoded_frame_._completeFrame = false; | 328 encoded_cb_.encoded_frame_._completeFrame = false; |
356 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | 329 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, |
357 decoder_->Decode(encoded_frame_, false, nullptr)); | 330 decoder_->Decode(encoded_cb_.encoded_frame_, false, nullptr)); |
358 // Setting complete back to true. Forcing a delta frame. | 331 // Setting complete back to true. Forcing a delta frame. |
359 encoded_frame_._frameType = kVideoFrameDelta; | 332 encoded_cb_.encoded_frame_._frameType = kVideoFrameDelta; |
360 encoded_frame_._completeFrame = true; | 333 encoded_cb_.encoded_frame_._completeFrame = true; |
361 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | 334 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, |
362 decoder_->Decode(encoded_frame_, false, nullptr)); | 335 decoder_->Decode(encoded_cb_.encoded_frame_, false, nullptr)); |
363 // Now setting a key frame. | 336 // Now setting a key frame. |
364 encoded_frame_._frameType = kVideoFrameKey; | 337 encoded_cb_.encoded_frame_._frameType = kVideoFrameKey; |
365 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 338 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
366 decoder_->Decode(encoded_frame_, false, nullptr)); | 339 decoder_->Decode(encoded_cb_.encoded_frame_, false, nullptr)); |
367 ASSERT_TRUE(decoded_frame_); | 340 ASSERT_TRUE(decoded_cb_.frame_); |
368 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); | 341 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_cb_.frame_), 36); |
369 } | 342 } |
370 | 343 |
371 TEST_F(TestVp8Impl, EncoderRetainsRtpStateAfterRelease) { | 344 TEST_F(TestVp8Impl, EncoderRetainsRtpStateAfterRelease) { |
372 SetUpEncodeDecode(); | 345 InitEncodeDecode(); |
373 // Override default settings. | 346 // Override default settings. |
374 codec_settings_.VP8()->numberOfTemporalLayers = 2; | 347 codec_settings_.VP8()->numberOfTemporalLayers = 2; |
375 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 348 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
376 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | 349 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
377 | 350 |
378 // Temporal layer 0. | 351 // Temporal layer 0. |
379 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 352 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
380 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 353 encoder_->Encode(*input_frame_, nullptr, nullptr)); |
381 WaitForEncodedFrame(); | 354 WaitForEncodedFrame(); |
382 EXPECT_EQ(0, codec_specific_info_.codecSpecific.VP8.temporalIdx); | 355 EXPECT_EQ(0, encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); |
383 int16_t picture_id = codec_specific_info_.codecSpecific.VP8.pictureId; | 356 int16_t picture_id = |
384 int tl0_pic_idx = codec_specific_info_.codecSpecific.VP8.tl0PicIdx; | 357 encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId; |
| 358 int tl0_pic_idx = |
| 359 encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx; |
385 | 360 |
386 // Temporal layer 1. | 361 // Temporal layer 1. |
387 input_frame_->set_timestamp(input_frame_->timestamp() + | 362 input_frame_->set_timestamp(input_frame_->timestamp() + |
388 kTimestampIncrementPerFrame); | 363 kTimestampIncrementPerFrame); |
389 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 364 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
390 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 365 encoder_->Encode(*input_frame_, nullptr, nullptr)); |
391 ExpectFrameWith((picture_id + 1) % (1 << 15), tl0_pic_idx, 1); | 366 ExpectFrameWith((picture_id + 1) % (1 << 15), tl0_pic_idx, 1); |
392 | 367 |
393 // Temporal layer 0. | 368 // Temporal layer 0. |
394 input_frame_->set_timestamp(input_frame_->timestamp() + | 369 input_frame_->set_timestamp(input_frame_->timestamp() + |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 codec_settings_.VP8()->automaticResizeOn = true; | 452 codec_settings_.VP8()->automaticResizeOn = true; |
478 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 453 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
479 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | 454 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
480 | 455 |
481 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings(); | 456 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings(); |
482 EXPECT_TRUE(settings.enabled); | 457 EXPECT_TRUE(settings.enabled); |
483 EXPECT_EQ(kMinPixelsPerFrame, settings.min_pixels_per_frame); | 458 EXPECT_EQ(kMinPixelsPerFrame, settings.min_pixels_per_frame); |
484 } | 459 } |
485 | 460 |
486 } // namespace webrtc | 461 } // namespace webrtc |
OLD | NEW |