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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 encoded_frame_->_buffer = frame_buffer_.get(); | 69 encoded_frame_->_buffer = frame_buffer_.get(); |
70 encoded_frame_->_size = encoded_frame._length; | 70 encoded_frame_->_size = encoded_frame._length; |
71 } | 71 } |
72 memcpy(encoded_frame_->_buffer, encoded_frame._buffer, encoded_frame._length); | 72 memcpy(encoded_frame_->_buffer, encoded_frame._buffer, encoded_frame._length); |
73 encoded_frame_->_length = encoded_frame._length; | 73 encoded_frame_->_length = encoded_frame._length; |
74 encoded_frame_->_encodedWidth = encoded_frame._encodedWidth; | 74 encoded_frame_->_encodedWidth = encoded_frame._encodedWidth; |
75 encoded_frame_->_encodedHeight = encoded_frame._encodedHeight; | 75 encoded_frame_->_encodedHeight = encoded_frame._encodedHeight; |
76 encoded_frame_->_timeStamp = encoded_frame._timeStamp; | 76 encoded_frame_->_timeStamp = encoded_frame._timeStamp; |
77 encoded_frame_->_frameType = encoded_frame._frameType; | 77 encoded_frame_->_frameType = encoded_frame._frameType; |
78 encoded_frame_->_completeFrame = encoded_frame._completeFrame; | 78 encoded_frame_->_completeFrame = encoded_frame._completeFrame; |
79 encoded_frame_->qp_ = encoded_frame.qp_; | |
79 encode_complete_ = true; | 80 encode_complete_ = true; |
80 return Result(Result::OK, 0); | 81 return Result(Result::OK, 0); |
81 } | 82 } |
82 | 83 |
83 bool Vp8UnitTestEncodeCompleteCallback::EncodeComplete() { | 84 bool Vp8UnitTestEncodeCompleteCallback::EncodeComplete() { |
84 if (encode_complete_) { | 85 if (encode_complete_) { |
85 encode_complete_ = false; | 86 encode_complete_ = false; |
86 return true; | 87 return true; |
87 } | 88 } |
88 return false; | 89 return false; |
89 } | 90 } |
90 | 91 |
91 class Vp8UnitTestDecodeCompleteCallback : public webrtc::DecodedImageCallback { | 92 class Vp8UnitTestDecodeCompleteCallback : public webrtc::DecodedImageCallback { |
92 public: | 93 public: |
93 explicit Vp8UnitTestDecodeCompleteCallback(rtc::Optional<VideoFrame>* frame) | 94 explicit Vp8UnitTestDecodeCompleteCallback(rtc::Optional<VideoFrame>* frame, |
94 : decoded_frame_(frame), decode_complete(false) {} | 95 rtc::Optional<uint8_t>* qp) |
95 int32_t Decoded(VideoFrame& frame) override; | 96 : decoded_frame_(frame), decoded_qp_(qp), decode_complete(false) {} |
97 int32_t Decoded(VideoFrame& frame) override { | |
98 RTC_NOTREACHED(); | |
99 return -1; | |
100 } | |
96 int32_t Decoded(VideoFrame& frame, int64_t decode_time_ms) override { | 101 int32_t Decoded(VideoFrame& frame, int64_t decode_time_ms) override { |
97 RTC_NOTREACHED(); | 102 RTC_NOTREACHED(); |
98 return -1; | 103 return -1; |
99 } | 104 } |
100 void Decoded(VideoFrame& frame, | 105 void Decoded(VideoFrame& frame, |
101 rtc::Optional<int32_t> decode_time_ms, | 106 rtc::Optional<int32_t> decode_time_ms, |
102 rtc::Optional<uint8_t> qp) override { | 107 rtc::Optional<uint8_t> qp) override; |
103 RTC_NOTREACHED(); | |
104 } | |
105 bool DecodeComplete(); | 108 bool DecodeComplete(); |
106 | 109 |
107 private: | 110 private: |
108 rtc::Optional<VideoFrame>* decoded_frame_; | 111 rtc::Optional<VideoFrame>* decoded_frame_; |
112 rtc::Optional<uint8_t>* decoded_qp_; | |
109 bool decode_complete; | 113 bool decode_complete; |
110 }; | 114 }; |
111 | 115 |
112 bool Vp8UnitTestDecodeCompleteCallback::DecodeComplete() { | 116 bool Vp8UnitTestDecodeCompleteCallback::DecodeComplete() { |
113 if (decode_complete) { | 117 if (decode_complete) { |
114 decode_complete = false; | 118 decode_complete = false; |
115 return true; | 119 return true; |
116 } | 120 } |
117 return false; | 121 return false; |
118 } | 122 } |
119 | 123 |
120 int Vp8UnitTestDecodeCompleteCallback::Decoded(VideoFrame& image) { | 124 void Vp8UnitTestDecodeCompleteCallback::Decoded( |
121 *decoded_frame_ = rtc::Optional<VideoFrame>(image); | 125 VideoFrame& frame, |
126 rtc::Optional<int32_t> decode_time_ms, | |
127 rtc::Optional<uint8_t> qp) { | |
128 *decoded_frame_ = rtc::Optional<VideoFrame>(frame); | |
129 *decoded_qp_ = qp; | |
122 decode_complete = true; | 130 decode_complete = true; |
123 return 0; | |
124 } | 131 } |
125 | 132 |
126 class TestVp8Impl : public ::testing::Test { | 133 class TestVp8Impl : public ::testing::Test { |
127 protected: | 134 protected: |
128 virtual void SetUp() { | 135 virtual void SetUp() { |
129 encoder_.reset(VP8Encoder::Create()); | 136 encoder_.reset(VP8Encoder::Create()); |
130 decoder_.reset(VP8Decoder::Create()); | 137 decoder_.reset(VP8Decoder::Create()); |
131 memset(&codec_inst_, 0, sizeof(codec_inst_)); | 138 memset(&codec_inst_, 0, sizeof(codec_inst_)); |
132 encode_complete_callback_.reset( | 139 encode_complete_callback_.reset( |
133 new Vp8UnitTestEncodeCompleteCallback(&encoded_frame_, 0, NULL)); | 140 new Vp8UnitTestEncodeCompleteCallback(&encoded_frame_, 0, NULL)); |
134 decode_complete_callback_.reset( | 141 decode_complete_callback_.reset( |
135 new Vp8UnitTestDecodeCompleteCallback(&decoded_frame_)); | 142 new Vp8UnitTestDecodeCompleteCallback(&decoded_frame_, &decoded_qp_)); |
136 encoder_->RegisterEncodeCompleteCallback(encode_complete_callback_.get()); | 143 encoder_->RegisterEncodeCompleteCallback(encode_complete_callback_.get()); |
137 decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get()); | 144 decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get()); |
138 // Using a QCIF image (aligned stride (u,v planes) > width). | 145 // Using a QCIF image (aligned stride (u,v planes) > width). |
139 // Processing only one frame. | 146 // Processing only one frame. |
140 source_file_ = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb"); | 147 source_file_ = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb"); |
141 ASSERT_TRUE(source_file_ != NULL); | 148 ASSERT_TRUE(source_file_ != NULL); |
142 rtc::scoped_refptr<VideoFrameBuffer> compact_buffer( | 149 rtc::scoped_refptr<VideoFrameBuffer> compact_buffer( |
143 test::ReadI420Buffer(kWidth, kHeight, source_file_)); | 150 test::ReadI420Buffer(kWidth, kHeight, source_file_)); |
144 ASSERT_TRUE(compact_buffer); | 151 ASSERT_TRUE(compact_buffer); |
145 codec_inst_.width = kWidth; | 152 codec_inst_.width = kWidth; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 | 210 |
204 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; | 211 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; |
205 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; | 212 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; |
206 std::unique_ptr<uint8_t[]> source_buffer_; | 213 std::unique_ptr<uint8_t[]> source_buffer_; |
207 FILE* source_file_; | 214 FILE* source_file_; |
208 std::unique_ptr<VideoFrame> input_frame_; | 215 std::unique_ptr<VideoFrame> input_frame_; |
209 std::unique_ptr<VideoEncoder> encoder_; | 216 std::unique_ptr<VideoEncoder> encoder_; |
210 std::unique_ptr<VideoDecoder> decoder_; | 217 std::unique_ptr<VideoDecoder> decoder_; |
211 EncodedImage encoded_frame_; | 218 EncodedImage encoded_frame_; |
212 rtc::Optional<VideoFrame> decoded_frame_; | 219 rtc::Optional<VideoFrame> decoded_frame_; |
220 rtc::Optional<uint8_t> decoded_qp_; | |
213 VideoCodec codec_inst_; | 221 VideoCodec codec_inst_; |
214 TemporalLayersFactory tl_factory_; | 222 TemporalLayersFactory tl_factory_; |
215 }; | 223 }; |
216 | 224 |
217 TEST_F(TestVp8Impl, EncoderParameterTest) { | 225 TEST_F(TestVp8Impl, EncoderParameterTest) { |
218 strncpy(codec_inst_.plName, "VP8", 31); | 226 strncpy(codec_inst_.plName, "VP8", 31); |
219 codec_inst_.plType = 126; | 227 codec_inst_.plType = 126; |
220 codec_inst_.maxBitrate = 0; | 228 codec_inst_.maxBitrate = 0; |
221 codec_inst_.minBitrate = 0; | 229 codec_inst_.minBitrate = 0; |
222 codec_inst_.width = 1440; | 230 codec_inst_.width = 1440; |
(...skipping 14 matching lines...) Expand all Loading... | |
237 codec_inst_.maxFramerate)); | 245 codec_inst_.maxFramerate)); |
238 | 246 |
239 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->InitEncode(&codec_inst_, 1, 1440)); | 247 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->InitEncode(&codec_inst_, 1, 1440)); |
240 | 248 |
241 // Decoder parameter tests. | 249 // Decoder parameter tests. |
242 // Calls before InitDecode(). | 250 // Calls before InitDecode(). |
243 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); | 251 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
244 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); | 252 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); |
245 } | 253 } |
246 | 254 |
255 TEST_F(TestVp8Impl, DecodedQpEqualsEncodedQp) { | |
256 SetUpEncodeDecode(); | |
257 encoder_->Encode(*input_frame_, NULL, NULL); | |
sprang_webrtc
2017/02/17 12:31:59
nullptr for all new code
sakal
2017/02/17 12:41:41
Done.
| |
258 EXPECT_GT(WaitForEncodedFrame(), 0u); | |
259 // First frame should be a key frame. | |
260 encoded_frame_._frameType = kVideoFrameKey; | |
261 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
262 decoder_->Decode(encoded_frame_, false, NULL)); | |
263 EXPECT_GT(WaitForDecodedFrame(), 0u); | |
264 ASSERT_TRUE(decoded_frame_); | |
265 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); | |
266 EXPECT_EQ(encoded_frame_.qp_, *decoded_qp_); | |
sprang_webrtc
2017/02/17 12:31:59
I'd assert decoded_qp_ has a value first, or maybe
sakal
2017/02/17 12:41:41
Done.
| |
267 } | |
268 | |
247 #if defined(WEBRTC_ANDROID) | 269 #if defined(WEBRTC_ANDROID) |
248 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode | 270 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode |
249 #else | 271 #else |
250 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode | 272 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode |
251 #endif | 273 #endif |
252 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) { | 274 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) { |
253 SetUpEncodeDecode(); | 275 SetUpEncodeDecode(); |
254 encoder_->Encode(*input_frame_, NULL, NULL); | 276 encoder_->Encode(*input_frame_, NULL, NULL); |
255 EXPECT_GT(WaitForEncodedFrame(), 0u); | 277 EXPECT_GT(WaitForEncodedFrame(), 0u); |
256 // First frame should be a key frame. | 278 // First frame should be a key frame. |
(...skipping 29 matching lines...) Expand all Loading... | |
286 decoder_->Decode(encoded_frame_, false, NULL)); | 308 decoder_->Decode(encoded_frame_, false, NULL)); |
287 // Now setting a key frame. | 309 // Now setting a key frame. |
288 encoded_frame_._frameType = kVideoFrameKey; | 310 encoded_frame_._frameType = kVideoFrameKey; |
289 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 311 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
290 decoder_->Decode(encoded_frame_, false, NULL)); | 312 decoder_->Decode(encoded_frame_, false, NULL)); |
291 ASSERT_TRUE(decoded_frame_); | 313 ASSERT_TRUE(decoded_frame_); |
292 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); | 314 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); |
293 } | 315 } |
294 | 316 |
295 } // namespace webrtc | 317 } // namespace webrtc |
OLD | NEW |