| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebM 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 vpx_codec_enc_config_default(codec_iface_, &codec_enc_, 0); | 53 vpx_codec_enc_config_default(codec_iface_, &codec_enc_, 0); |
| 54 EXPECT_EQ(VPX_CODEC_OK, res); | 54 EXPECT_EQ(VPX_CODEC_OK, res); |
| 55 | 55 |
| 56 codec_enc_.g_w = kWidth; | 56 codec_enc_.g_w = kWidth; |
| 57 codec_enc_.g_h = kHeight; | 57 codec_enc_.g_h = kHeight; |
| 58 codec_enc_.g_timebase.num = 1; | 58 codec_enc_.g_timebase.num = 1; |
| 59 codec_enc_.g_timebase.den = 60; | 59 codec_enc_.g_timebase.den = 60; |
| 60 codec_enc_.kf_min_dist = 100; | 60 codec_enc_.kf_min_dist = 100; |
| 61 codec_enc_.kf_max_dist = 100; | 61 codec_enc_.kf_max_dist = 100; |
| 62 | 62 |
| 63 vpx_codec_dec_cfg_t dec_cfg = {0}; | 63 vpx_codec_dec_cfg_t dec_cfg = vpx_codec_dec_cfg_t(); |
| 64 VP9CodecFactory codec_factory; | 64 VP9CodecFactory codec_factory; |
| 65 decoder_ = codec_factory.CreateDecoder(dec_cfg, 0); | 65 decoder_ = codec_factory.CreateDecoder(dec_cfg, 0); |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual void TearDown() { | 68 virtual void TearDown() { |
| 69 ReleaseEncoder(); | 69 ReleaseEncoder(); |
| 70 delete(decoder_); | 70 delete(decoder_); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void InitializeEncoder() { | 73 void InitializeEncoder() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 video.duration(), VPX_DL_GOOD_QUALITY); | 105 video.duration(), VPX_DL_GOOD_QUALITY); |
| 106 ASSERT_EQ(VPX_CODEC_OK, res); | 106 ASSERT_EQ(VPX_CODEC_OK, res); |
| 107 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); | 107 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
| 108 EXPECT_GT(stats_size, 0U); | 108 EXPECT_GT(stats_size, 0U); |
| 109 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); | 109 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
| 110 ASSERT_TRUE(stats_data != NULL); | 110 ASSERT_TRUE(stats_data != NULL); |
| 111 stats_buf->append(stats_data, stats_size); | 111 stats_buf->append(stats_data, stats_size); |
| 112 video.Next(); | 112 video.Next(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Flush encoder and test EOS packet | 115 // Flush encoder and test EOS packet. |
| 116 res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(), | 116 res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(), |
| 117 video.duration(), VPX_DL_GOOD_QUALITY); | 117 video.duration(), VPX_DL_GOOD_QUALITY); |
| 118 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); | 118 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
| 119 EXPECT_GT(stats_size, 0U); | 119 EXPECT_GT(stats_size, 0U); |
| 120 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); | 120 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
| 121 ASSERT_TRUE(stats_data != NULL); | 121 ASSERT_TRUE(stats_data != NULL); |
| 122 stats_buf->append(stats_data, stats_size); | 122 stats_buf->append(stats_data, stats_size); |
| 123 | 123 |
| 124 ReleaseEncoder(); | 124 ReleaseEncoder(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void StoreFrames(const size_t max_frame_received, | 127 void StoreFrames(const size_t max_frame_received, |
| 128 struct vpx_fixed_buf *const outputs, | 128 struct vpx_fixed_buf *const outputs, |
| 129 size_t *const frame_received) { | 129 size_t *const frame_received) { |
| 130 size_t frame_size; | 130 size_t frame_size; |
| 131 while ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { | 131 while ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { |
| 132 ASSERT_LT(*frame_received, max_frame_received); | 132 ASSERT_LT(*frame_received, max_frame_received); |
| 133 | 133 |
| 134 if (*frame_received == 0) { | 134 if (*frame_received == 0) { |
| 135 EXPECT_EQ(1, vpx_svc_is_keyframe(&svc_)); | 135 EXPECT_EQ(1, vpx_svc_is_keyframe(&svc_)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 outputs[*frame_received].buf = malloc(frame_size); | 138 outputs[*frame_received].buf = malloc(frame_size + 16); |
| 139 ASSERT_TRUE(outputs[*frame_received].buf != NULL); | 139 ASSERT_TRUE(outputs[*frame_received].buf != NULL); |
| 140 memcpy(outputs[*frame_received].buf, vpx_svc_get_buffer(&svc_), | 140 memcpy(outputs[*frame_received].buf, vpx_svc_get_buffer(&svc_), |
| 141 frame_size); | 141 frame_size); |
| 142 outputs[*frame_received].sz = frame_size; | 142 outputs[*frame_received].sz = frame_size; |
| 143 ++(*frame_received); | 143 ++(*frame_received); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 void Pass2EncodeNFrames(std::string *const stats_buf, | 147 void Pass2EncodeNFrames(std::string *const stats_buf, |
| 148 const int n, const int layers, | 148 const int n, const int layers, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 169 video.Begin(); | 169 video.Begin(); |
| 170 | 170 |
| 171 for (int i = 0; i < n; ++i) { | 171 for (int i = 0; i < n; ++i) { |
| 172 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | 172 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
| 173 video.duration(), VPX_DL_GOOD_QUALITY); | 173 video.duration(), VPX_DL_GOOD_QUALITY); |
| 174 ASSERT_EQ(VPX_CODEC_OK, res); | 174 ASSERT_EQ(VPX_CODEC_OK, res); |
| 175 StoreFrames(n, outputs, &frame_received); | 175 StoreFrames(n, outputs, &frame_received); |
| 176 video.Next(); | 176 video.Next(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Flush Encoder | 179 // Flush encoder. |
| 180 res = vpx_svc_encode(&svc_, &codec_, NULL, 0, | 180 res = vpx_svc_encode(&svc_, &codec_, NULL, 0, |
| 181 video.duration(), VPX_DL_GOOD_QUALITY); | 181 video.duration(), VPX_DL_GOOD_QUALITY); |
| 182 EXPECT_EQ(VPX_CODEC_OK, res); | 182 EXPECT_EQ(VPX_CODEC_OK, res); |
| 183 StoreFrames(n, outputs, &frame_received); | 183 StoreFrames(n, outputs, &frame_received); |
| 184 | 184 |
| 185 EXPECT_EQ(frame_received, (size_t)n); | 185 EXPECT_EQ(frame_received, static_cast<size_t>(n)); |
| 186 | 186 |
| 187 ReleaseEncoder(); | 187 ReleaseEncoder(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void DecodeNFrames(const struct vpx_fixed_buf *const inputs, const int n) { | 190 void DecodeNFrames(const struct vpx_fixed_buf *const inputs, const int n) { |
| 191 int decoded_frames = 0; | 191 int decoded_frames = 0; |
| 192 int received_frames = 0; | 192 int received_frames = 0; |
| 193 | 193 |
| 194 ASSERT_TRUE(inputs != NULL); | 194 ASSERT_TRUE(inputs != NULL); |
| 195 ASSERT_GT(n, 0); | 195 ASSERT_GT(n, 0); |
| 196 | 196 |
| 197 for (int i = 0; i < n; ++i) { | 197 for (int i = 0; i < n; ++i) { |
| 198 ASSERT_TRUE(inputs[i].buf != NULL); | 198 ASSERT_TRUE(inputs[i].buf != NULL); |
| 199 ASSERT_GT(inputs[i].sz, 0U); | 199 ASSERT_GT(inputs[i].sz, 0U); |
| 200 const vpx_codec_err_t res_dec = | 200 const vpx_codec_err_t res_dec = |
| 201 decoder_->DecodeFrame(static_cast<const uint8_t *>(inputs[i].buf), | 201 decoder_->DecodeFrame(static_cast<const uint8_t *>(inputs[i].buf), |
| 202 inputs[i].sz); | 202 inputs[i].sz); |
| 203 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | 203 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); |
| 204 ++decoded_frames; | 204 ++decoded_frames; |
| 205 | 205 |
| 206 DxDataIterator dec_iter = decoder_->GetDxData(); | 206 DxDataIterator dec_iter = decoder_->GetDxData(); |
| 207 while (dec_iter.Next()) { | 207 while (dec_iter.Next() != NULL) { |
| 208 ++received_frames; | 208 ++received_frames; |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 EXPECT_EQ(decoded_frames, n); | 211 EXPECT_EQ(decoded_frames, n); |
| 212 EXPECT_EQ(received_frames, n); | 212 EXPECT_EQ(received_frames, n); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void DropEnhancementLayers(struct vpx_fixed_buf *const inputs, | 215 void DropLayersAndMakeItVP9Comaptible(struct vpx_fixed_buf *const inputs, |
| 216 const int num_super_frames, | 216 const int num_super_frames, |
| 217 const int remained_layers) { | 217 const int remained_spatial_layers, |
| 218 const bool is_multiple_frame_contexts) { |
| 218 ASSERT_TRUE(inputs != NULL); | 219 ASSERT_TRUE(inputs != NULL); |
| 219 ASSERT_GT(num_super_frames, 0); | 220 ASSERT_GT(num_super_frames, 0); |
| 220 ASSERT_GT(remained_layers, 0); | 221 ASSERT_GT(remained_spatial_layers, 0); |
| 221 | 222 |
| 222 for (int i = 0; i < num_super_frames; ++i) { | 223 for (int i = 0; i < num_super_frames; ++i) { |
| 223 uint32_t frame_sizes[8] = {0}; | 224 uint32_t frame_sizes[8] = {0}; |
| 224 int frame_count = 0; | 225 int frame_count = 0; |
| 225 int frames_found = 0; | 226 int frames_found = 0; |
| 226 int frame; | 227 int frame; |
| 227 ASSERT_TRUE(inputs[i].buf != NULL); | 228 ASSERT_TRUE(inputs[i].buf != NULL); |
| 228 ASSERT_GT(inputs[i].sz, 0U); | 229 ASSERT_GT(inputs[i].sz, 0U); |
| 229 | 230 |
| 230 vpx_codec_err_t res = | 231 vpx_codec_err_t res = |
| 231 vp9_parse_superframe_index(static_cast<const uint8_t*>(inputs[i].buf), | 232 vp9_parse_superframe_index(static_cast<const uint8_t*>(inputs[i].buf), |
| 232 inputs[i].sz, frame_sizes, &frame_count, | 233 inputs[i].sz, frame_sizes, &frame_count, |
| 233 NULL, NULL); | 234 NULL, NULL); |
| 234 ASSERT_EQ(VPX_CODEC_OK, res); | 235 ASSERT_EQ(VPX_CODEC_OK, res); |
| 235 | 236 |
| 236 uint8_t *frame_data = static_cast<uint8_t *>(inputs[i].buf); | 237 if (frame_count == 0) { |
| 237 uint8_t *frame_start = frame_data; | 238 // There's no super frame but only a single frame. |
| 238 for (frame = 0; frame < frame_count; ++frame) { | 239 ASSERT_EQ(1, remained_spatial_layers); |
| 239 // Looking for a visible frame | 240 if (is_multiple_frame_contexts) { |
| 240 if (frame_data[0] & 0x02) { | 241 // Make a new super frame. |
| 241 ++frames_found; | 242 uint8_t marker = 0xc1; |
| 242 if (frames_found == remained_layers) | 243 unsigned int mask; |
| 243 break; | 244 int mag; |
| 245 |
| 246 // Choose the magnitude. |
| 247 for (mag = 0, mask = 0xff; mag < 4; ++mag) { |
| 248 if (inputs[i].sz < mask) |
| 249 break; |
| 250 mask <<= 8; |
| 251 mask |= 0xff; |
| 252 } |
| 253 marker |= mag << 3; |
| 254 int index_sz = 2 + (mag + 1) * 2; |
| 255 |
| 256 inputs[i].buf = realloc(inputs[i].buf, inputs[i].sz + index_sz + 16); |
| 257 ASSERT_TRUE(inputs[i].buf != NULL); |
| 258 uint8_t *frame_data = static_cast<uint8_t*>(inputs[i].buf); |
| 259 frame_data[0] &= ~2; // Set the show_frame flag to 0. |
| 260 frame_data += inputs[i].sz; |
| 261 // Add an one byte frame with show_existing_frame. |
| 262 *frame_data++ = 0x88; |
| 263 |
| 264 // Write the super frame index. |
| 265 *frame_data++ = marker; |
| 266 |
| 267 frame_sizes[0] = inputs[i].sz; |
| 268 frame_sizes[1] = 1; |
| 269 for (int j = 0; j < 2; ++j) { |
| 270 unsigned int this_sz = frame_sizes[j]; |
| 271 for (int k = 0; k <= mag; k++) { |
| 272 *frame_data++ = this_sz & 0xff; |
| 273 this_sz >>= 8; |
| 274 } |
| 275 } |
| 276 *frame_data++ = marker; |
| 277 inputs[i].sz += index_sz + 1; |
| 244 } | 278 } |
| 279 } else { |
| 280 // Found a super frame. |
| 281 uint8_t *frame_data = static_cast<uint8_t*>(inputs[i].buf); |
| 282 uint8_t *frame_start = frame_data; |
| 283 for (frame = 0; frame < frame_count; ++frame) { |
| 284 // Looking for a visible frame. |
| 285 if (frame_data[0] & 0x02) { |
| 286 ++frames_found; |
| 287 if (frames_found == remained_spatial_layers) |
| 288 break; |
| 289 } |
| 290 frame_data += frame_sizes[frame]; |
| 291 } |
| 292 ASSERT_LT(frame, frame_count) << "Couldn't find a visible frame. " |
| 293 << "remained_spatial_layers: " << remained_spatial_layers |
| 294 << " super_frame: " << i |
| 295 << " is_multiple_frame_context: " << is_multiple_frame_contexts; |
| 296 if (frame == frame_count - 1 && !is_multiple_frame_contexts) |
| 297 continue; |
| 298 |
| 245 frame_data += frame_sizes[frame]; | 299 frame_data += frame_sizes[frame]; |
| 300 |
| 301 // We need to add one more frame for multiple frame contexts. |
| 302 if (is_multiple_frame_contexts) |
| 303 ++frame; |
| 304 uint8_t marker = |
| 305 static_cast<const uint8_t*>(inputs[i].buf)[inputs[i].sz - 1]; |
| 306 const uint32_t mag = ((marker >> 3) & 0x3) + 1; |
| 307 const size_t index_sz = 2 + mag * frame_count; |
| 308 const size_t new_index_sz = 2 + mag * (frame + 1); |
| 309 marker &= 0x0f8; |
| 310 marker |= frame; |
| 311 |
| 312 // Copy existing frame sizes. |
| 313 memmove(frame_data + (is_multiple_frame_contexts ? 2 : 1), |
| 314 frame_start + inputs[i].sz - index_sz + 1, new_index_sz - 2); |
| 315 if (is_multiple_frame_contexts) { |
| 316 // Add a one byte frame with flag show_existing_frame. |
| 317 *frame_data++ = 0x88 | (remained_spatial_layers - 1); |
| 318 } |
| 319 // New marker. |
| 320 frame_data[0] = marker; |
| 321 frame_data += (mag * (frame + 1) + 1); |
| 322 |
| 323 if (is_multiple_frame_contexts) { |
| 324 // Write the frame size for the one byte frame. |
| 325 frame_data -= mag; |
| 326 *frame_data++ = 1; |
| 327 for (uint32_t j = 1; j < mag; ++j) { |
| 328 *frame_data++ = 0; |
| 329 } |
| 330 } |
| 331 |
| 332 *frame_data++ = marker; |
| 333 inputs[i].sz = frame_data - frame_start; |
| 334 |
| 335 if (is_multiple_frame_contexts) { |
| 336 // Change the show frame flag to 0 for all frames. |
| 337 for (int j = 0; j < frame; ++j) { |
| 338 frame_start[0] &= ~2; |
| 339 frame_start += frame_sizes[j]; |
| 340 } |
| 341 } |
| 246 } | 342 } |
| 247 ASSERT_LT(frame, frame_count); | |
| 248 if (frame == frame_count - 1) | |
| 249 continue; | |
| 250 | |
| 251 frame_data += frame_sizes[frame]; | |
| 252 uint8_t marker = | |
| 253 static_cast<const uint8_t *>(inputs[i].buf)[inputs[i].sz - 1]; | |
| 254 const uint32_t mag = ((marker >> 3) & 0x3) + 1; | |
| 255 const size_t index_sz = 2 + mag * frame_count; | |
| 256 const size_t new_index_sz = 2 + mag * (frame + 1); | |
| 257 marker &= 0x0f8; | |
| 258 marker |= frame; | |
| 259 frame_data[0] = marker; | |
| 260 memcpy(frame_data + 1, frame_start + inputs[i].sz - index_sz + 1, | |
| 261 new_index_sz - 2); | |
| 262 frame_data[new_index_sz - 1] = marker; | |
| 263 inputs[i].sz = frame_data - frame_start + new_index_sz; | |
| 264 } | 343 } |
| 265 } | 344 } |
| 266 | 345 |
| 267 void FreeBitstreamBuffers(struct vpx_fixed_buf *const inputs, const int n) { | 346 void FreeBitstreamBuffers(struct vpx_fixed_buf *const inputs, const int n) { |
| 268 ASSERT_TRUE(inputs != NULL); | 347 ASSERT_TRUE(inputs != NULL); |
| 269 ASSERT_GT(n, 0); | 348 ASSERT_GT(n, 0); |
| 270 | 349 |
| 271 for (int i = 0; i < n; ++i) { | 350 for (int i = 0; i < n; ++i) { |
| 272 free(inputs[i].buf); | 351 free(inputs[i].buf); |
| 273 inputs[i].buf = NULL; | 352 inputs[i].buf = NULL; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 vpx_codec_err_t res = vpx_svc_set_options(&svc_, NULL); | 398 vpx_codec_err_t res = vpx_svc_set_options(&svc_, NULL); |
| 320 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 399 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
| 321 | 400 |
| 322 res = vpx_svc_set_options(&svc_, "not-an-option=1"); | 401 res = vpx_svc_set_options(&svc_, "not-an-option=1"); |
| 323 EXPECT_EQ(VPX_CODEC_OK, res); | 402 EXPECT_EQ(VPX_CODEC_OK, res); |
| 324 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 403 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
| 325 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 404 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
| 326 } | 405 } |
| 327 | 406 |
| 328 TEST_F(SvcTest, SetLayersOption) { | 407 TEST_F(SvcTest, SetLayersOption) { |
| 329 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "layers=3"); | 408 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "spatial-layers=3"); |
| 330 EXPECT_EQ(VPX_CODEC_OK, res); | 409 EXPECT_EQ(VPX_CODEC_OK, res); |
| 331 InitializeEncoder(); | 410 InitializeEncoder(); |
| 332 EXPECT_EQ(3, svc_.spatial_layers); | 411 EXPECT_EQ(3, svc_.spatial_layers); |
| 333 } | 412 } |
| 334 | 413 |
| 335 TEST_F(SvcTest, SetMultipleOptions) { | 414 TEST_F(SvcTest, SetMultipleOptions) { |
| 336 vpx_codec_err_t res = | 415 vpx_codec_err_t res = |
| 337 vpx_svc_set_options(&svc_, "layers=2 scale-factors=1/3,2/3"); | 416 vpx_svc_set_options(&svc_, "spatial-layers=2 scale-factors=1/3,2/3"); |
| 338 EXPECT_EQ(VPX_CODEC_OK, res); | 417 EXPECT_EQ(VPX_CODEC_OK, res); |
| 339 InitializeEncoder(); | 418 InitializeEncoder(); |
| 340 EXPECT_EQ(2, svc_.spatial_layers); | 419 EXPECT_EQ(2, svc_.spatial_layers); |
| 341 } | 420 } |
| 342 | 421 |
| 343 TEST_F(SvcTest, SetScaleFactorsOption) { | 422 TEST_F(SvcTest, SetScaleFactorsOption) { |
| 344 svc_.spatial_layers = 2; | 423 svc_.spatial_layers = 2; |
| 345 vpx_codec_err_t res = | 424 vpx_codec_err_t res = |
| 346 vpx_svc_set_options(&svc_, "scale-factors=not-scale-factors"); | 425 vpx_svc_set_options(&svc_, "scale-factors=not-scale-factors"); |
| 347 EXPECT_EQ(VPX_CODEC_OK, res); | 426 EXPECT_EQ(VPX_CODEC_OK, res); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 // Second pass encode | 568 // Second pass encode |
| 490 codec_enc_.g_pass = VPX_RC_LAST_PASS; | 569 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 491 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1"); | 570 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1"); |
| 492 vpx_fixed_buf outputs[20]; | 571 vpx_fixed_buf outputs[20]; |
| 493 memset(&outputs[0], 0, sizeof(outputs)); | 572 memset(&outputs[0], 0, sizeof(outputs)); |
| 494 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]); | 573 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]); |
| 495 DecodeNFrames(&outputs[0], 20); | 574 DecodeNFrames(&outputs[0], 20); |
| 496 FreeBitstreamBuffers(&outputs[0], 20); | 575 FreeBitstreamBuffers(&outputs[0], 20); |
| 497 } | 576 } |
| 498 | 577 |
| 499 TEST_F(SvcTest, TwoPassEncode2LayersDecodeBaseLayerOnly) { | 578 TEST_F(SvcTest, TwoPassEncode2SpatialLayersDecodeBaseLayerOnly) { |
| 500 // First pass encode | 579 // First pass encode |
| 501 std::string stats_buf; | 580 std::string stats_buf; |
| 502 Pass1EncodeNFrames(10, 2, &stats_buf); | 581 Pass1EncodeNFrames(10, 2, &stats_buf); |
| 503 | 582 |
| 504 // Second pass encode | 583 // Second pass encode |
| 505 codec_enc_.g_pass = VPX_RC_LAST_PASS; | 584 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 506 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1"); | 585 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1"); |
| 507 vpx_fixed_buf outputs[10]; | 586 vpx_fixed_buf outputs[10]; |
| 508 memset(&outputs[0], 0, sizeof(outputs)); | 587 memset(&outputs[0], 0, sizeof(outputs)); |
| 509 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]); | 588 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]); |
| 510 DropEnhancementLayers(&outputs[0], 10, 1); | 589 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, false); |
| 511 DecodeNFrames(&outputs[0], 10); | 590 DecodeNFrames(&outputs[0], 10); |
| 512 FreeBitstreamBuffers(&outputs[0], 10); | 591 FreeBitstreamBuffers(&outputs[0], 10); |
| 513 } | 592 } |
| 514 | 593 |
| 515 TEST_F(SvcTest, TwoPassEncode5LayersDecode54321Layers) { | 594 TEST_F(SvcTest, TwoPassEncode5SpatialLayersDecode54321Layers) { |
| 516 // First pass encode | 595 // First pass encode |
| 517 std::string stats_buf; | 596 std::string stats_buf; |
| 518 Pass1EncodeNFrames(10, 5, &stats_buf); | 597 Pass1EncodeNFrames(10, 5, &stats_buf); |
| 519 | 598 |
| 520 // Second pass encode | 599 // Second pass encode |
| 521 codec_enc_.g_pass = VPX_RC_LAST_PASS; | 600 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 522 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0"); | 601 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0"); |
| 523 vpx_fixed_buf outputs[10]; | 602 vpx_fixed_buf outputs[10]; |
| 524 memset(&outputs[0], 0, sizeof(outputs)); | 603 memset(&outputs[0], 0, sizeof(outputs)); |
| 525 Pass2EncodeNFrames(&stats_buf, 10, 5, &outputs[0]); | 604 Pass2EncodeNFrames(&stats_buf, 10, 5, &outputs[0]); |
| 526 | 605 |
| 527 DecodeNFrames(&outputs[0], 10); | 606 DecodeNFrames(&outputs[0], 10); |
| 528 DropEnhancementLayers(&outputs[0], 10, 4); | 607 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 4, false); |
| 529 DecodeNFrames(&outputs[0], 10); | 608 DecodeNFrames(&outputs[0], 10); |
| 530 DropEnhancementLayers(&outputs[0], 10, 3); | 609 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 3, false); |
| 531 DecodeNFrames(&outputs[0], 10); | 610 DecodeNFrames(&outputs[0], 10); |
| 532 DropEnhancementLayers(&outputs[0], 10, 2); | 611 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 2, false); |
| 533 DecodeNFrames(&outputs[0], 10); | 612 DecodeNFrames(&outputs[0], 10); |
| 534 DropEnhancementLayers(&outputs[0], 10, 1); | 613 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, false); |
| 535 DecodeNFrames(&outputs[0], 10); | 614 DecodeNFrames(&outputs[0], 10); |
| 536 | 615 |
| 537 FreeBitstreamBuffers(&outputs[0], 10); | 616 FreeBitstreamBuffers(&outputs[0], 10); |
| 538 } | 617 } |
| 539 | 618 |
| 540 TEST_F(SvcTest, TwoPassEncode2SNRLayers) { | 619 TEST_F(SvcTest, TwoPassEncode2SNRLayers) { |
| 541 // First pass encode | 620 // First pass encode |
| 542 std::string stats_buf; | 621 std::string stats_buf; |
| 543 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1"); | 622 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1"); |
| 544 Pass1EncodeNFrames(20, 2, &stats_buf); | 623 Pass1EncodeNFrames(20, 2, &stats_buf); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 561 Pass1EncodeNFrames(20, 3, &stats_buf); | 640 Pass1EncodeNFrames(20, 3, &stats_buf); |
| 562 | 641 |
| 563 // Second pass encode | 642 // Second pass encode |
| 564 codec_enc_.g_pass = VPX_RC_LAST_PASS; | 643 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 565 vpx_svc_set_options(&svc_, | 644 vpx_svc_set_options(&svc_, |
| 566 "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1"); | 645 "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1"); |
| 567 vpx_fixed_buf outputs[20]; | 646 vpx_fixed_buf outputs[20]; |
| 568 memset(&outputs[0], 0, sizeof(outputs)); | 647 memset(&outputs[0], 0, sizeof(outputs)); |
| 569 Pass2EncodeNFrames(&stats_buf, 20, 3, &outputs[0]); | 648 Pass2EncodeNFrames(&stats_buf, 20, 3, &outputs[0]); |
| 570 DecodeNFrames(&outputs[0], 20); | 649 DecodeNFrames(&outputs[0], 20); |
| 571 DropEnhancementLayers(&outputs[0], 20, 2); | 650 DropLayersAndMakeItVP9Comaptible(&outputs[0], 20, 2, false); |
| 572 DecodeNFrames(&outputs[0], 20); | 651 DecodeNFrames(&outputs[0], 20); |
| 573 DropEnhancementLayers(&outputs[0], 20, 1); | 652 DropLayersAndMakeItVP9Comaptible(&outputs[0], 20, 1, false); |
| 574 DecodeNFrames(&outputs[0], 20); | 653 DecodeNFrames(&outputs[0], 20); |
| 575 | 654 |
| 576 FreeBitstreamBuffers(&outputs[0], 20); | 655 FreeBitstreamBuffers(&outputs[0], 20); |
| 577 } | 656 } |
| 578 | 657 |
| 658 TEST_F(SvcTest, SetMultipleFrameContextsOption) { |
| 659 svc_.spatial_layers = 5; |
| 660 vpx_codec_err_t res = |
| 661 vpx_svc_set_options(&svc_, "multi-frame-contexts=1"); |
| 662 EXPECT_EQ(VPX_CODEC_OK, res); |
| 663 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
| 664 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
| 665 |
| 666 svc_.spatial_layers = 2; |
| 667 res = vpx_svc_set_options(&svc_, "multi-frame-contexts=1"); |
| 668 InitializeEncoder(); |
| 669 } |
| 670 |
| 671 TEST_F(SvcTest, TwoPassEncode2SpatialLayersWithMultipleFrameContexts) { |
| 672 // First pass encode |
| 673 std::string stats_buf; |
| 674 Pass1EncodeNFrames(10, 2, &stats_buf); |
| 675 |
| 676 // Second pass encode |
| 677 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 678 codec_enc_.g_error_resilient = 0; |
| 679 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 multi-frame-contexts=1"); |
| 680 vpx_fixed_buf outputs[10]; |
| 681 memset(&outputs[0], 0, sizeof(outputs)); |
| 682 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]); |
| 683 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 2, true); |
| 684 DecodeNFrames(&outputs[0], 10); |
| 685 FreeBitstreamBuffers(&outputs[0], 10); |
| 686 } |
| 687 |
| 688 TEST_F(SvcTest, |
| 689 TwoPassEncode2SpatialLayersWithMultipleFrameContextsDecodeBaselayer) { |
| 690 // First pass encode |
| 691 std::string stats_buf; |
| 692 Pass1EncodeNFrames(10, 2, &stats_buf); |
| 693 |
| 694 // Second pass encode |
| 695 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 696 codec_enc_.g_error_resilient = 0; |
| 697 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 multi-frame-contexts=1"); |
| 698 vpx_fixed_buf outputs[10]; |
| 699 memset(&outputs[0], 0, sizeof(outputs)); |
| 700 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]); |
| 701 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, true); |
| 702 DecodeNFrames(&outputs[0], 10); |
| 703 FreeBitstreamBuffers(&outputs[0], 10); |
| 704 } |
| 705 |
| 706 TEST_F(SvcTest, TwoPassEncode2SNRLayersWithMultipleFrameContexts) { |
| 707 // First pass encode |
| 708 std::string stats_buf; |
| 709 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1"); |
| 710 Pass1EncodeNFrames(10, 2, &stats_buf); |
| 711 |
| 712 // Second pass encode |
| 713 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 714 codec_enc_.g_error_resilient = 0; |
| 715 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 scale-factors=1/1,1/1 " |
| 716 "multi-frame-contexts=1"); |
| 717 vpx_fixed_buf outputs[10]; |
| 718 memset(&outputs[0], 0, sizeof(outputs)); |
| 719 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]); |
| 720 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 2, true); |
| 721 DecodeNFrames(&outputs[0], 10); |
| 722 FreeBitstreamBuffers(&outputs[0], 10); |
| 723 } |
| 724 |
| 725 TEST_F(SvcTest, |
| 726 TwoPassEncode3SNRLayersWithMultipleFrameContextsDecode321Layer) { |
| 727 // First pass encode |
| 728 std::string stats_buf; |
| 729 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1,1/1"); |
| 730 Pass1EncodeNFrames(10, 3, &stats_buf); |
| 731 |
| 732 // Second pass encode |
| 733 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 734 codec_enc_.g_error_resilient = 0; |
| 735 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1 " |
| 736 "multi-frame-contexts=1"); |
| 737 vpx_fixed_buf outputs[10]; |
| 738 memset(&outputs[0], 0, sizeof(outputs)); |
| 739 Pass2EncodeNFrames(&stats_buf, 10, 3, &outputs[0]); |
| 740 |
| 741 vpx_fixed_buf outputs_new[10]; |
| 742 for (int i = 0; i < 10; ++i) { |
| 743 outputs_new[i].buf = malloc(outputs[i].sz + 16); |
| 744 ASSERT_TRUE(outputs_new[i].buf != NULL); |
| 745 memcpy(outputs_new[i].buf, outputs[i].buf, outputs[i].sz); |
| 746 outputs_new[i].sz = outputs[i].sz; |
| 747 } |
| 748 DropLayersAndMakeItVP9Comaptible(&outputs_new[0], 10, 3, true); |
| 749 DecodeNFrames(&outputs_new[0], 10); |
| 750 |
| 751 for (int i = 0; i < 10; ++i) { |
| 752 memcpy(outputs_new[i].buf, outputs[i].buf, outputs[i].sz); |
| 753 outputs_new[i].sz = outputs[i].sz; |
| 754 } |
| 755 DropLayersAndMakeItVP9Comaptible(&outputs_new[0], 10, 2, true); |
| 756 DecodeNFrames(&outputs_new[0], 10); |
| 757 |
| 758 for (int i = 0; i < 10; ++i) { |
| 759 memcpy(outputs_new[i].buf, outputs[i].buf, outputs[i].sz); |
| 760 outputs_new[i].sz = outputs[i].sz; |
| 761 } |
| 762 DropLayersAndMakeItVP9Comaptible(&outputs_new[0], 10, 1, true); |
| 763 DecodeNFrames(&outputs_new[0], 10); |
| 764 |
| 765 FreeBitstreamBuffers(&outputs[0], 10); |
| 766 FreeBitstreamBuffers(&outputs_new[0], 10); |
| 767 } |
| 768 |
| 769 TEST_F(SvcTest, TwoPassEncode2TemporalLayers) { |
| 770 // First pass encode |
| 771 std::string stats_buf; |
| 772 vpx_svc_set_options(&svc_, "scale-factors=1/1"); |
| 773 svc_.temporal_layers = 2; |
| 774 Pass1EncodeNFrames(10, 1, &stats_buf); |
| 775 |
| 776 // Second pass encode |
| 777 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 778 svc_.temporal_layers = 2; |
| 779 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1"); |
| 780 vpx_fixed_buf outputs[10]; |
| 781 memset(&outputs[0], 0, sizeof(outputs)); |
| 782 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]); |
| 783 DecodeNFrames(&outputs[0], 10); |
| 784 FreeBitstreamBuffers(&outputs[0], 10); |
| 785 } |
| 786 |
| 787 TEST_F(SvcTest, TwoPassEncode2TemporalLayersWithMultipleFrameContexts) { |
| 788 // First pass encode |
| 789 std::string stats_buf; |
| 790 vpx_svc_set_options(&svc_, "scale-factors=1/1"); |
| 791 svc_.temporal_layers = 2; |
| 792 Pass1EncodeNFrames(10, 1, &stats_buf); |
| 793 |
| 794 // Second pass encode |
| 795 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 796 svc_.temporal_layers = 2; |
| 797 codec_enc_.g_error_resilient = 0; |
| 798 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1 " |
| 799 "multi-frame-contexts=1"); |
| 800 vpx_fixed_buf outputs[10]; |
| 801 memset(&outputs[0], 0, sizeof(outputs)); |
| 802 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]); |
| 803 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, true); |
| 804 DecodeNFrames(&outputs[0], 10); |
| 805 FreeBitstreamBuffers(&outputs[0], 10); |
| 806 } |
| 807 |
| 808 TEST_F(SvcTest, TwoPassEncode2TemporalLayersDecodeBaseLayer) { |
| 809 // First pass encode |
| 810 std::string stats_buf; |
| 811 vpx_svc_set_options(&svc_, "scale-factors=1/1"); |
| 812 svc_.temporal_layers = 2; |
| 813 Pass1EncodeNFrames(10, 1, &stats_buf); |
| 814 |
| 815 // Second pass encode |
| 816 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 817 svc_.temporal_layers = 2; |
| 818 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1"); |
| 819 vpx_fixed_buf outputs[10]; |
| 820 memset(&outputs[0], 0, sizeof(outputs)); |
| 821 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]); |
| 822 |
| 823 vpx_fixed_buf base_layer[5]; |
| 824 for (int i = 0; i < 5; ++i) |
| 825 base_layer[i] = outputs[i * 2]; |
| 826 |
| 827 DecodeNFrames(&base_layer[0], 5); |
| 828 FreeBitstreamBuffers(&outputs[0], 10); |
| 829 } |
| 830 |
| 831 TEST_F(SvcTest, |
| 832 TwoPassEncode2TemporalLayersWithMultipleFrameContextsDecodeBaseLayer) { |
| 833 // First pass encode |
| 834 std::string stats_buf; |
| 835 vpx_svc_set_options(&svc_, "scale-factors=1/1"); |
| 836 svc_.temporal_layers = 2; |
| 837 Pass1EncodeNFrames(10, 1, &stats_buf); |
| 838 |
| 839 // Second pass encode |
| 840 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 841 svc_.temporal_layers = 2; |
| 842 codec_enc_.g_error_resilient = 0; |
| 843 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1 " |
| 844 "multi-frame-contexts=1"); |
| 845 vpx_fixed_buf outputs[10]; |
| 846 memset(&outputs[0], 0, sizeof(outputs)); |
| 847 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]); |
| 848 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, true); |
| 849 |
| 850 vpx_fixed_buf base_layer[5]; |
| 851 for (int i = 0; i < 5; ++i) |
| 852 base_layer[i] = outputs[i * 2]; |
| 853 |
| 854 DecodeNFrames(&base_layer[0], 5); |
| 855 FreeBitstreamBuffers(&outputs[0], 10); |
| 856 } |
| 857 |
| 579 } // namespace | 858 } // namespace |
| OLD | NEW |