OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 |
11 #include <math.h> | 11 #include <math.h> |
12 | 12 |
13 #include "vp9/encoder/vp9_encoder.h" | 13 #include "vp9/encoder/vp9_encoder.h" |
14 #include "vp9/encoder/vp9_svc_layercontext.h" | 14 #include "vp9/encoder/vp9_svc_layercontext.h" |
15 #include "vp9/encoder/vp9_extend.h" | 15 #include "vp9/encoder/vp9_extend.h" |
16 | 16 |
17 #define SMALL_FRAME_FB_IDX 7 | 17 #define SMALL_FRAME_FB_IDX 7 |
| 18 #define SMALL_FRAME_WIDTH 16 |
| 19 #define SMALL_FRAME_HEIGHT 16 |
18 | 20 |
19 void vp9_init_layer_context(VP9_COMP *const cpi) { | 21 void vp9_init_layer_context(VP9_COMP *const cpi) { |
20 SVC *const svc = &cpi->svc; | 22 SVC *const svc = &cpi->svc; |
21 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 23 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
22 int layer; | 24 int layer; |
23 int layer_end; | 25 int layer_end; |
24 int alt_ref_idx = svc->number_spatial_layers; | 26 int alt_ref_idx = svc->number_spatial_layers; |
25 | 27 |
26 svc->spatial_layer_id = 0; | 28 svc->spatial_layer_id = 0; |
27 svc->temporal_layer_id = 0; | 29 svc->temporal_layer_id = 0; |
28 | 30 |
29 if (svc->number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) { | 31 if (svc->number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) { |
30 layer_end = svc->number_temporal_layers; | 32 layer_end = svc->number_temporal_layers; |
31 } else { | 33 } else { |
32 layer_end = svc->number_spatial_layers; | 34 layer_end = svc->number_spatial_layers; |
33 | 35 |
34 if (cpi->oxcf.error_resilient_mode == 0 && cpi->oxcf.pass == 2) { | 36 if (cpi->oxcf.error_resilient_mode == 0 && cpi->oxcf.pass == 2) { |
35 if (vp9_realloc_frame_buffer(&cpi->svc.empty_frame.img, | 37 if (vp9_realloc_frame_buffer(&cpi->svc.empty_frame.img, |
36 cpi->common.width, cpi->common.height, | 38 SMALL_FRAME_WIDTH, SMALL_FRAME_HEIGHT, |
37 cpi->common.subsampling_x, | 39 cpi->common.subsampling_x, |
38 cpi->common.subsampling_y, | 40 cpi->common.subsampling_y, |
39 #if CONFIG_VP9_HIGHBITDEPTH | 41 #if CONFIG_VP9_HIGHBITDEPTH |
40 cpi->common.use_highbitdepth, | 42 cpi->common.use_highbitdepth, |
41 #endif | 43 #endif |
42 VP9_ENC_BORDER_IN_PIXELS, | 44 VP9_ENC_BORDER_IN_PIXELS, |
43 cpi->common.byte_alignment, | 45 cpi->common.byte_alignment, |
44 NULL, NULL, NULL)) | 46 NULL, NULL, NULL)) |
45 vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, | 47 vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, |
46 "Failed to allocate empty frame for multiple frame " | 48 "Failed to allocate empty frame for multiple frame " |
47 "contexts"); | 49 "contexts"); |
48 | 50 |
49 memset(cpi->svc.empty_frame.img.buffer_alloc, 0x80, | 51 memset(cpi->svc.empty_frame.img.buffer_alloc, 0x80, |
50 cpi->svc.empty_frame.img.buffer_alloc_sz); | 52 cpi->svc.empty_frame.img.buffer_alloc_sz); |
51 cpi->svc.empty_frame_width = cpi->common.width; | |
52 cpi->svc.empty_frame_height = cpi->common.height; | |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 for (layer = 0; layer < layer_end; ++layer) { | 56 for (layer = 0; layer < layer_end; ++layer) { |
57 LAYER_CONTEXT *const lc = &svc->layer_context[layer]; | 57 LAYER_CONTEXT *const lc = &svc->layer_context[layer]; |
58 RATE_CONTROL *const lrc = &lc->rc; | 58 RATE_CONTROL *const lrc = &lc->rc; |
59 int i; | 59 int i; |
60 lc->current_video_frame_in_layer = 0; | 60 lc->current_video_frame_in_layer = 0; |
61 lc->layer_size = 0; | 61 lc->layer_size = 0; |
62 lc->frames_from_key_frame = 0; | 62 lc->frames_from_key_frame = 0; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 if (buf != NULL) { | 355 if (buf != NULL) { |
356 cpi->svc.empty_frame.ts_start = buf->ts_start; | 356 cpi->svc.empty_frame.ts_start = buf->ts_start; |
357 cpi->svc.empty_frame.ts_end = buf->ts_end; | 357 cpi->svc.empty_frame.ts_end = buf->ts_end; |
358 cpi->svc.encode_empty_frame_state = ENCODING; | 358 cpi->svc.encode_empty_frame_state = ENCODING; |
359 cpi->common.show_frame = 0; | 359 cpi->common.show_frame = 0; |
360 cpi->ref_frame_flags = 0; | 360 cpi->ref_frame_flags = 0; |
361 cpi->common.frame_type = INTER_FRAME; | 361 cpi->common.frame_type = INTER_FRAME; |
362 cpi->lst_fb_idx = | 362 cpi->lst_fb_idx = |
363 cpi->gld_fb_idx = cpi->alt_fb_idx = SMALL_FRAME_FB_IDX; | 363 cpi->gld_fb_idx = cpi->alt_fb_idx = SMALL_FRAME_FB_IDX; |
364 | 364 |
365 // Gradually make the empty frame smaller to save bits. Make it half of | 365 if (cpi->svc.encode_intra_empty_frame != 0) |
366 // its previous size because of the scaling factor restriction. | 366 cpi->common.intra_only = 1; |
367 cpi->svc.empty_frame_width >>= 1; | |
368 cpi->svc.empty_frame_width = (cpi->svc.empty_frame_width + 1) & ~1; | |
369 if (cpi->svc.empty_frame_width < 16) | |
370 cpi->svc.empty_frame_width = 16; | |
371 | 367 |
372 cpi->svc.empty_frame_height >>= 1; | 368 width = SMALL_FRAME_WIDTH; |
373 cpi->svc.empty_frame_height = (cpi->svc.empty_frame_height + 1) & ~1; | 369 height = SMALL_FRAME_HEIGHT; |
374 if (cpi->svc.empty_frame_height < 16) | |
375 cpi->svc.empty_frame_height = 16; | |
376 | |
377 width = cpi->svc.empty_frame_width; | |
378 height = cpi->svc.empty_frame_height; | |
379 } | 370 } |
380 } | 371 } |
381 } | 372 } |
382 | 373 |
383 cpi->oxcf.worst_allowed_q = vp9_quantizer_to_qindex(lc->max_q); | 374 cpi->oxcf.worst_allowed_q = vp9_quantizer_to_qindex(lc->max_q); |
384 cpi->oxcf.best_allowed_q = vp9_quantizer_to_qindex(lc->min_q); | 375 cpi->oxcf.best_allowed_q = vp9_quantizer_to_qindex(lc->min_q); |
385 | 376 |
386 vp9_change_config(cpi, &cpi->oxcf); | 377 vp9_change_config(cpi, &cpi->oxcf); |
387 | 378 |
388 if (vp9_set_size_literal(cpi, width, height) != 0) | 379 if (vp9_set_size_literal(cpi, width, height) != 0) |
(...skipping 17 matching lines...) Expand all Loading... |
406 // Only remove the buffer when pop the highest layer. | 397 // Only remove the buffer when pop the highest layer. |
407 if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) { | 398 if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) { |
408 vp9_lookahead_pop(ctx, drain); | 399 vp9_lookahead_pop(ctx, drain); |
409 } | 400 } |
410 } | 401 } |
411 } | 402 } |
412 | 403 |
413 return buf; | 404 return buf; |
414 } | 405 } |
415 #endif | 406 #endif |
OLD | NEW |