Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(589)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc

Issue 2510583002: Reland #2 of Issue 2434073003: Extract bitrate allocation ... (Closed)
Patch Set: Addressed comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include <stdio.h> 11 #include <stdio.h>
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/timeutils.h" 16 #include "webrtc/base/timeutils.h"
17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
18 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 18 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
19 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
19 #include "webrtc/test/frame_utils.h" 20 #include "webrtc/test/frame_utils.h"
20 #include "webrtc/test/gtest.h" 21 #include "webrtc/test/gtest.h"
21 #include "webrtc/test/testsupport/fileutils.h" 22 #include "webrtc/test/testsupport/fileutils.h"
22 23
23 namespace webrtc { 24 namespace webrtc {
24 25
25 namespace { 26 namespace {
26 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { 27 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) {
27 *stride_y = 16 * ((width + 15) / 16); 28 *stride_y = 16 * ((width + 15) / 16);
28 *stride_uv = 16 * ((width + 31) / 32); 29 *stride_uv = 16 * ((width + 31) / 32);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 input_frame_.reset( 155 input_frame_.reset(
155 new VideoFrame(stride_buffer, kVideoRotation_0, 0)); 156 new VideoFrame(stride_buffer, kVideoRotation_0, 0));
156 input_frame_->set_timestamp(kTestTimestamp); 157 input_frame_->set_timestamp(kTestTimestamp);
157 } 158 }
158 159
159 void SetUpEncodeDecode() { 160 void SetUpEncodeDecode() {
160 codec_inst_.startBitrate = 300; 161 codec_inst_.startBitrate = 300;
161 codec_inst_.maxBitrate = 4000; 162 codec_inst_.maxBitrate = 4000;
162 codec_inst_.qpMax = 56; 163 codec_inst_.qpMax = 56;
163 codec_inst_.VP8()->denoisingOn = true; 164 codec_inst_.VP8()->denoisingOn = true;
165 codec_inst_.VP8()->tl_factory = &tl_factory_;
166 codec_inst_.VP8()->numberOfTemporalLayers = 1;
164 167
165 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 168 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
166 encoder_->InitEncode(&codec_inst_, 1, 1440)); 169 encoder_->InitEncode(&codec_inst_, 1, 1440));
167 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); 170 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1));
168 } 171 }
169 172
170 size_t WaitForEncodedFrame() const { 173 size_t WaitForEncodedFrame() const {
171 int64_t startTime = rtc::TimeMillis(); 174 int64_t startTime = rtc::TimeMillis();
172 while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) { 175 while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) {
173 if (encode_complete_callback_->EncodeComplete()) { 176 if (encode_complete_callback_->EncodeComplete()) {
(...skipping 20 matching lines...) Expand all
194 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; 197 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_;
195 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; 198 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_;
196 std::unique_ptr<uint8_t[]> source_buffer_; 199 std::unique_ptr<uint8_t[]> source_buffer_;
197 FILE* source_file_; 200 FILE* source_file_;
198 std::unique_ptr<VideoFrame> input_frame_; 201 std::unique_ptr<VideoFrame> input_frame_;
199 std::unique_ptr<VideoEncoder> encoder_; 202 std::unique_ptr<VideoEncoder> encoder_;
200 std::unique_ptr<VideoDecoder> decoder_; 203 std::unique_ptr<VideoDecoder> decoder_;
201 EncodedImage encoded_frame_; 204 EncodedImage encoded_frame_;
202 VideoFrame decoded_frame_; 205 VideoFrame decoded_frame_;
203 VideoCodec codec_inst_; 206 VideoCodec codec_inst_;
207 TemporalLayersFactory tl_factory_;
204 }; 208 };
205 209
206 TEST_F(TestVp8Impl, EncoderParameterTest) { 210 TEST_F(TestVp8Impl, EncoderParameterTest) {
207 strncpy(codec_inst_.plName, "VP8", 31); 211 strncpy(codec_inst_.plName, "VP8", 31);
208 codec_inst_.plType = 126; 212 codec_inst_.plType = 126;
209 codec_inst_.maxBitrate = 0; 213 codec_inst_.maxBitrate = 0;
210 codec_inst_.minBitrate = 0; 214 codec_inst_.minBitrate = 0;
211 codec_inst_.width = 1440; 215 codec_inst_.width = 1440;
212 codec_inst_.height = 1080; 216 codec_inst_.height = 1080;
213 codec_inst_.maxFramerate = 30; 217 codec_inst_.maxFramerate = 30;
214 codec_inst_.startBitrate = 300; 218 codec_inst_.startBitrate = 300;
215 codec_inst_.qpMax = 56; 219 codec_inst_.qpMax = 56;
216 codec_inst_.VP8()->complexity = kComplexityNormal; 220 codec_inst_.VP8()->complexity = kComplexityNormal;
217 codec_inst_.VP8()->numberOfTemporalLayers = 1; 221 codec_inst_.VP8()->numberOfTemporalLayers = 1;
222 codec_inst_.VP8()->tl_factory = &tl_factory_;
218 // Calls before InitEncode(). 223 // Calls before InitEncode().
219 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); 224 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
220 int bit_rate = 300; 225 int bit_rate = 300;
226 BitrateAllocation bitrate_allocation;
227 bitrate_allocation.SetBitrate(0, 0, bit_rate * 1000);
221 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, 228 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
222 encoder_->SetRates(bit_rate, codec_inst_.maxFramerate)); 229 encoder_->SetRateAllocation(bitrate_allocation,
230 codec_inst_.maxFramerate));
223 231
224 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->InitEncode(&codec_inst_, 1, 1440)); 232 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->InitEncode(&codec_inst_, 1, 1440));
225 233
226 // Decoder parameter tests. 234 // Decoder parameter tests.
227 // Calls before InitDecode(). 235 // Calls before InitDecode().
228 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); 236 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release());
229 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); 237 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1));
230 } 238 }
231 239
232 #if defined(WEBRTC_ANDROID) 240 #if defined(WEBRTC_ANDROID)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, 277 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
270 decoder_->Decode(encoded_frame_, false, NULL)); 278 decoder_->Decode(encoded_frame_, false, NULL));
271 // Now setting a key frame. 279 // Now setting a key frame.
272 encoded_frame_._frameType = kVideoFrameKey; 280 encoded_frame_._frameType = kVideoFrameKey;
273 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 281 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
274 decoder_->Decode(encoded_frame_, false, NULL)); 282 decoder_->Decode(encoded_frame_, false, NULL));
275 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36); 283 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36);
276 } 284 }
277 285
278 } // namespace webrtc 286 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codecs/vp8/temporal_layers.h ('k') | webrtc/modules/video_coding/codecs/vp8/vp8_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698