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

Side by Side Diff: source/libvpx/vp9/encoder/vp9_firstpass.c

Issue 1162573005: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 6 months 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
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_firstpass.h ('k') | source/libvpx/vp9/encoder/vp9_mcomp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 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 <limits.h> 11 #include <limits.h>
12 #include <math.h> 12 #include <math.h>
13 #include <stdio.h> 13 #include <stdio.h>
14 14
15 #include "./vpx_dsp_rtcd.h"
15 #include "./vpx_scale_rtcd.h" 16 #include "./vpx_scale_rtcd.h"
16 17
17 #include "vpx_mem/vpx_mem.h" 18 #include "vpx_mem/vpx_mem.h"
19 #include "vpx_ports/mem.h"
18 #include "vpx_scale/vpx_scale.h" 20 #include "vpx_scale/vpx_scale.h"
19 #include "vpx_scale/yv12config.h" 21 #include "vpx_scale/yv12config.h"
20 22
21 #include "vp9/common/vp9_entropymv.h" 23 #include "vp9/common/vp9_entropymv.h"
22 #include "vp9/common/vp9_quant_common.h" 24 #include "vp9/common/vp9_quant_common.h"
23 #include "vp9/common/vp9_reconinter.h" // vp9_setup_dst_planes() 25 #include "vp9/common/vp9_reconinter.h" // vp9_setup_dst_planes()
24 #include "vp9/common/vp9_systemdependent.h" 26 #include "vp9/common/vp9_systemdependent.h"
25 #include "vp9/encoder/vp9_aq_variance.h" 27 #include "vp9/encoder/vp9_aq_variance.h"
26 #include "vp9/encoder/vp9_block.h" 28 #include "vp9/encoder/vp9_block.h"
27 #include "vp9/encoder/vp9_encodeframe.h" 29 #include "vp9/encoder/vp9_encodeframe.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 cpi->output_pkt_list); 261 cpi->output_pkt_list);
260 } 262 }
261 } else { 263 } else {
262 output_stats(&cpi->twopass.total_stats, cpi->output_pkt_list); 264 output_stats(&cpi->twopass.total_stats, cpi->output_pkt_list);
263 } 265 }
264 } 266 }
265 267
266 static vp9_variance_fn_t get_block_variance_fn(BLOCK_SIZE bsize) { 268 static vp9_variance_fn_t get_block_variance_fn(BLOCK_SIZE bsize) {
267 switch (bsize) { 269 switch (bsize) {
268 case BLOCK_8X8: 270 case BLOCK_8X8:
269 return vp9_mse8x8; 271 return vpx_mse8x8;
270 case BLOCK_16X8: 272 case BLOCK_16X8:
271 return vp9_mse16x8; 273 return vpx_mse16x8;
272 case BLOCK_8X16: 274 case BLOCK_8X16:
273 return vp9_mse8x16; 275 return vpx_mse8x16;
274 default: 276 default:
275 return vp9_mse16x16; 277 return vpx_mse16x16;
276 } 278 }
277 } 279 }
278 280
279 static unsigned int get_prediction_error(BLOCK_SIZE bsize, 281 static unsigned int get_prediction_error(BLOCK_SIZE bsize,
280 const struct buf_2d *src, 282 const struct buf_2d *src,
281 const struct buf_2d *ref) { 283 const struct buf_2d *ref) {
282 unsigned int sse; 284 unsigned int sse;
283 const vp9_variance_fn_t fn = get_block_variance_fn(bsize); 285 const vp9_variance_fn_t fn = get_block_variance_fn(bsize);
284 fn(src->buf, src->stride, ref->buf, ref->stride, &sse); 286 fn(src->buf, src->stride, ref->buf, ref->stride, &sse);
285 return sse; 287 return sse;
286 } 288 }
287 289
288 #if CONFIG_VP9_HIGHBITDEPTH 290 #if CONFIG_VP9_HIGHBITDEPTH
289 static vp9_variance_fn_t highbd_get_block_variance_fn(BLOCK_SIZE bsize, 291 static vp9_variance_fn_t highbd_get_block_variance_fn(BLOCK_SIZE bsize,
290 int bd) { 292 int bd) {
291 switch (bd) { 293 switch (bd) {
292 default: 294 default:
293 switch (bsize) { 295 switch (bsize) {
294 case BLOCK_8X8: 296 case BLOCK_8X8:
295 return vp9_highbd_mse8x8; 297 return vpx_highbd_8_mse8x8;
296 case BLOCK_16X8: 298 case BLOCK_16X8:
297 return vp9_highbd_mse16x8; 299 return vpx_highbd_8_mse16x8;
298 case BLOCK_8X16: 300 case BLOCK_8X16:
299 return vp9_highbd_mse8x16; 301 return vpx_highbd_8_mse8x16;
300 default: 302 default:
301 return vp9_highbd_mse16x16; 303 return vpx_highbd_8_mse16x16;
302 } 304 }
303 break; 305 break;
304 case 10: 306 case 10:
305 switch (bsize) { 307 switch (bsize) {
306 case BLOCK_8X8: 308 case BLOCK_8X8:
307 return vp9_highbd_10_mse8x8; 309 return vpx_highbd_10_mse8x8;
308 case BLOCK_16X8: 310 case BLOCK_16X8:
309 return vp9_highbd_10_mse16x8; 311 return vpx_highbd_10_mse16x8;
310 case BLOCK_8X16: 312 case BLOCK_8X16:
311 return vp9_highbd_10_mse8x16; 313 return vpx_highbd_10_mse8x16;
312 default: 314 default:
313 return vp9_highbd_10_mse16x16; 315 return vpx_highbd_10_mse16x16;
314 } 316 }
315 break; 317 break;
316 case 12: 318 case 12:
317 switch (bsize) { 319 switch (bsize) {
318 case BLOCK_8X8: 320 case BLOCK_8X8:
319 return vp9_highbd_12_mse8x8; 321 return vpx_highbd_12_mse8x8;
320 case BLOCK_16X8: 322 case BLOCK_16X8:
321 return vp9_highbd_12_mse16x8; 323 return vpx_highbd_12_mse16x8;
322 case BLOCK_8X16: 324 case BLOCK_8X16:
323 return vp9_highbd_12_mse8x16; 325 return vpx_highbd_12_mse8x16;
324 default: 326 default:
325 return vp9_highbd_12_mse16x16; 327 return vpx_highbd_12_mse16x16;
326 } 328 }
327 break; 329 break;
328 } 330 }
329 } 331 }
330 332
331 static unsigned int highbd_get_prediction_error(BLOCK_SIZE bsize, 333 static unsigned int highbd_get_prediction_error(BLOCK_SIZE bsize,
332 const struct buf_2d *src, 334 const struct buf_2d *src,
333 const struct buf_2d *ref, 335 const struct buf_2d *ref,
334 int bd) { 336 int bd) {
335 unsigned int sse; 337 unsigned int sse;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 mb_row << 1, num_8x8_blocks_high_lookup[bsize], 628 mb_row << 1, num_8x8_blocks_high_lookup[bsize],
627 mb_col << 1, num_8x8_blocks_wide_lookup[bsize], 629 mb_col << 1, num_8x8_blocks_wide_lookup[bsize],
628 cm->mi_rows, cm->mi_cols); 630 cm->mi_rows, cm->mi_cols);
629 631
630 // Do intra 16x16 prediction. 632 // Do intra 16x16 prediction.
631 x->skip_encode = 0; 633 x->skip_encode = 0;
632 xd->mi[0]->mbmi.mode = DC_PRED; 634 xd->mi[0]->mbmi.mode = DC_PRED;
633 xd->mi[0]->mbmi.tx_size = use_dc_pred ? 635 xd->mi[0]->mbmi.tx_size = use_dc_pred ?
634 (bsize >= BLOCK_16X16 ? TX_16X16 : TX_8X8) : TX_4X4; 636 (bsize >= BLOCK_16X16 ? TX_16X16 : TX_8X8) : TX_4X4;
635 vp9_encode_intra_block_plane(x, bsize, 0); 637 vp9_encode_intra_block_plane(x, bsize, 0);
636 this_error = vp9_get_mb_ss(x->plane[0].src_diff); 638 this_error = vpx_get_mb_ss(x->plane[0].src_diff);
637 #if CONFIG_VP9_HIGHBITDEPTH 639 #if CONFIG_VP9_HIGHBITDEPTH
638 if (cm->use_highbitdepth) { 640 if (cm->use_highbitdepth) {
639 switch (cm->bit_depth) { 641 switch (cm->bit_depth) {
640 case VPX_BITS_8: 642 case VPX_BITS_8:
641 break; 643 break;
642 case VPX_BITS_10: 644 case VPX_BITS_10:
643 this_error >>= 4; 645 this_error >>= 4;
644 break; 646 break;
645 case VPX_BITS_12: 647 case VPX_BITS_12:
646 this_error >>= 8; 648 this_error >>= 8;
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 oxcf->two_pass_vbrmin_section) / 100; 1241 oxcf->two_pass_vbrmin_section) / 100;
1240 twopass->modified_error_max = (avg_error * 1242 twopass->modified_error_max = (avg_error *
1241 oxcf->two_pass_vbrmax_section) / 100; 1243 oxcf->two_pass_vbrmax_section) / 100;
1242 while (s < twopass->stats_in_end) { 1244 while (s < twopass->stats_in_end) {
1243 modified_error_total += calculate_modified_err(twopass, oxcf, s); 1245 modified_error_total += calculate_modified_err(twopass, oxcf, s);
1244 ++s; 1246 ++s;
1245 } 1247 }
1246 twopass->modified_error_left = modified_error_total; 1248 twopass->modified_error_left = modified_error_total;
1247 } 1249 }
1248 1250
1249 // Reset the vbr bits off target counter 1251 // Reset the vbr bits off target counters
1250 cpi->rc.vbr_bits_off_target = 0; 1252 cpi->rc.vbr_bits_off_target = 0;
1253 cpi->rc.vbr_bits_off_target_fast = 0;
1251 1254
1252 cpi->rc.rate_error_estimate = 0; 1255 cpi->rc.rate_error_estimate = 0;
1253 1256
1254 // Static sequence monitor variables. 1257 // Static sequence monitor variables.
1255 twopass->kf_zeromotion_pct = 100; 1258 twopass->kf_zeromotion_pct = 100;
1256 twopass->last_kfgroup_zeromotion_pct = 100; 1259 twopass->last_kfgroup_zeromotion_pct = 100;
1257 1260
1258 if (oxcf->resize_mode != RESIZE_NONE) { 1261 if (oxcf->resize_mode != RESIZE_NONE) {
1259 vp9_init_subsampling(cpi); 1262 vp9_init_subsampling(cpi);
1260 } 1263 }
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 gf_group->arf_update_idx[frame_index] = arf_buffer_indices[1]; 1691 gf_group->arf_update_idx[frame_index] = arf_buffer_indices[1];
1689 gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0]; 1692 gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0];
1690 ++frame_index; 1693 ++frame_index;
1691 } 1694 }
1692 } 1695 }
1693 1696
1694 // Define middle frame 1697 // Define middle frame
1695 mid_frame_idx = frame_index + (rc->baseline_gf_interval >> 1) - 1; 1698 mid_frame_idx = frame_index + (rc->baseline_gf_interval >> 1) - 1;
1696 1699
1697 // Allocate bits to the other frames in the group. 1700 // Allocate bits to the other frames in the group.
1698 for (i = 0; i < rc->baseline_gf_interval - 1; ++i) { 1701 for (i = 0; i < rc->baseline_gf_interval - rc->source_alt_ref_pending; ++i) {
1699 int arf_idx = 0; 1702 int arf_idx = 0;
1700 if (EOF == input_stats(twopass, &frame_stats)) 1703 if (EOF == input_stats(twopass, &frame_stats))
1701 break; 1704 break;
1702 1705
1703 if (has_temporal_layers && frame_index == alt_frame_index) { 1706 if (has_temporal_layers && frame_index == alt_frame_index) {
1704 ++frame_index; 1707 ++frame_index;
1705 } 1708 }
1706 1709
1707 modified_err = calculate_modified_err(twopass, oxcf, &frame_stats); 1710 modified_err = calculate_modified_err(twopass, oxcf, &frame_stats);
1708 1711
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1926 1929
1927 *this_frame = next_frame; 1930 *this_frame = next_frame;
1928 old_boost_score = boost_score; 1931 old_boost_score = boost_score;
1929 } 1932 }
1930 1933
1931 twopass->gf_zeromotion_pct = (int)(zero_motion_accumulator * 1000.0); 1934 twopass->gf_zeromotion_pct = (int)(zero_motion_accumulator * 1000.0);
1932 1935
1933 // Was the group length constrained by the requirement for a new KF? 1936 // Was the group length constrained by the requirement for a new KF?
1934 rc->constrained_gf_group = (i >= rc->frames_to_key) ? 1 : 0; 1937 rc->constrained_gf_group = (i >= rc->frames_to_key) ? 1 : 0;
1935 1938
1939 // Should we use the alternate reference frame.
1940 if (allow_alt_ref &&
1941 (i < cpi->oxcf.lag_in_frames) &&
1942 (i >= rc->min_gf_interval)) {
1943 // Calculate the boost for alt ref.
1944 rc->gfu_boost = calc_arf_boost(cpi, 0, (i - 1), (i - 1), &f_boost,
1945 &b_boost);
1946 rc->source_alt_ref_pending = 1;
1947
1948 // Test to see if multi arf is appropriate.
1949 cpi->multi_arf_enabled =
1950 (cpi->multi_arf_allowed && (rc->baseline_gf_interval >= 6) &&
1951 (zero_motion_accumulator < 0.995)) ? 1 : 0;
1952 } else {
1953 rc->gfu_boost = MAX((int)boost_score, MIN_ARF_GF_BOOST);
1954 rc->source_alt_ref_pending = 0;
1955 }
1956
1936 // Set the interval until the next gf. 1957 // Set the interval until the next gf.
1937 if (is_key_frame || rc->source_alt_ref_active) 1958 if (is_key_frame || rc->source_alt_ref_pending)
1938 rc->baseline_gf_interval = i - 1; 1959 rc->baseline_gf_interval = i - 1;
1939 else 1960 else
1940 rc->baseline_gf_interval = i; 1961 rc->baseline_gf_interval = i;
1941 1962
1942 // Only encode alt reference frame in temporal base layer. So 1963 // Only encode alt reference frame in temporal base layer. So
1943 // baseline_gf_interval should be multiple of a temporal layer group 1964 // baseline_gf_interval should be multiple of a temporal layer group
1944 // (typically the frame distance between two base layer frames) 1965 // (typically the frame distance between two base layer frames)
1945 if (is_two_pass_svc(cpi) && cpi->svc.number_temporal_layers > 1) { 1966 if (is_two_pass_svc(cpi) && cpi->svc.number_temporal_layers > 1) {
1946 int count = (1 << (cpi->svc.number_temporal_layers - 1)) - 1; 1967 int count = (1 << (cpi->svc.number_temporal_layers - 1)) - 1;
1947 int new_gf_interval = (rc->baseline_gf_interval + count) & (~count); 1968 int new_gf_interval = (rc->baseline_gf_interval + count) & (~count);
1948 int j; 1969 int j;
1949 for (j = 0; j < new_gf_interval - rc->baseline_gf_interval; ++j) { 1970 for (j = 0; j < new_gf_interval - rc->baseline_gf_interval; ++j) {
1950 if (EOF == input_stats(twopass, this_frame)) 1971 if (EOF == input_stats(twopass, this_frame))
1951 break; 1972 break;
1952 gf_group_err += calculate_modified_err(twopass, oxcf, this_frame); 1973 gf_group_err += calculate_modified_err(twopass, oxcf, this_frame);
1953 #if GROUP_ADAPTIVE_MAXQ 1974 #if GROUP_ADAPTIVE_MAXQ
1954 gf_group_raw_error += this_frame->coded_error; 1975 gf_group_raw_error += this_frame->coded_error;
1955 #endif 1976 #endif
1956 } 1977 }
1957 rc->baseline_gf_interval = new_gf_interval; 1978 rc->baseline_gf_interval = new_gf_interval;
1958 } 1979 }
1959 1980
1960 rc->frames_till_gf_update_due = rc->baseline_gf_interval; 1981 rc->frames_till_gf_update_due = rc->baseline_gf_interval;
1961 1982
1962 // Should we use the alternate reference frame.
1963 if (allow_alt_ref &&
1964 (i < cpi->oxcf.lag_in_frames) &&
1965 (i >= rc->min_gf_interval)) {
1966 // Calculate the boost for alt ref.
1967 rc->gfu_boost = calc_arf_boost(cpi, 0, (i - 1), (i - 1), &f_boost,
1968 &b_boost);
1969 rc->source_alt_ref_pending = 1;
1970
1971 // Test to see if multi arf is appropriate.
1972 cpi->multi_arf_enabled =
1973 (cpi->multi_arf_allowed && (rc->baseline_gf_interval >= 6) &&
1974 (zero_motion_accumulator < 0.995)) ? 1 : 0;
1975 } else {
1976 rc->gfu_boost = MAX((int)boost_score, MIN_ARF_GF_BOOST);
1977 rc->source_alt_ref_pending = 0;
1978 }
1979
1980 // Reset the file position. 1983 // Reset the file position.
1981 reset_fpf_position(twopass, start_pos); 1984 reset_fpf_position(twopass, start_pos);
1982 1985
1983 // Calculate the bits to be allocated to the gf/arf group as a whole 1986 // Calculate the bits to be allocated to the gf/arf group as a whole
1984 gf_group_bits = calculate_total_gf_group_bits(cpi, gf_group_err); 1987 gf_group_bits = calculate_total_gf_group_bits(cpi, gf_group_err);
1985 1988
1986 #if GROUP_ADAPTIVE_MAXQ 1989 #if GROUP_ADAPTIVE_MAXQ
1987 // Calculate an estimate of the maxq needed for the group. 1990 // Calculate an estimate of the maxq needed for the group.
1988 // We are more agressive about correcting for sections 1991 // We are more agressive about correcting for sections
1989 // where there could be significant overshoot than for easier 1992 // where there could be significant overshoot than for easier
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
2406 // sizes. 2409 // sizes.
2407 twopass->modified_error_left -= kf_group_err; 2410 twopass->modified_error_left -= kf_group_err;
2408 2411
2409 if (oxcf->resize_mode == RESIZE_DYNAMIC) { 2412 if (oxcf->resize_mode == RESIZE_DYNAMIC) {
2410 // Default to normal-sized frame on keyframes. 2413 // Default to normal-sized frame on keyframes.
2411 cpi->rc.next_frame_size_selector = UNSCALED; 2414 cpi->rc.next_frame_size_selector = UNSCALED;
2412 } 2415 }
2413 } 2416 }
2414 2417
2415 // Define the reference buffers that will be updated post encode. 2418 // Define the reference buffers that will be updated post encode.
2416 void configure_buffer_updates(VP9_COMP *cpi) { 2419 static void configure_buffer_updates(VP9_COMP *cpi) {
2417 TWO_PASS *const twopass = &cpi->twopass; 2420 TWO_PASS *const twopass = &cpi->twopass;
2418 2421
2419 cpi->rc.is_src_frame_alt_ref = 0; 2422 cpi->rc.is_src_frame_alt_ref = 0;
2420 switch (twopass->gf_group.update_type[twopass->gf_group.index]) { 2423 switch (twopass->gf_group.update_type[twopass->gf_group.index]) {
2421 case KF_UPDATE: 2424 case KF_UPDATE:
2422 cpi->refresh_last_frame = 1; 2425 cpi->refresh_last_frame = 1;
2423 cpi->refresh_golden_frame = 1; 2426 cpi->refresh_golden_frame = 1;
2424 cpi->refresh_alt_ref_frame = 1; 2427 cpi->refresh_alt_ref_frame = 1;
2425 break; 2428 break;
2426 case LF_UPDATE: 2429 case LF_UPDATE:
(...skipping 26 matching lines...) Expand all
2453 cpi->refresh_last_frame = 0; 2456 cpi->refresh_last_frame = 0;
2454 cpi->refresh_golden_frame = 0; 2457 cpi->refresh_golden_frame = 0;
2455 } 2458 }
2456 if (cpi->svc.layer_context[cpi->svc.spatial_layer_id].gold_ref_idx < 0) 2459 if (cpi->svc.layer_context[cpi->svc.spatial_layer_id].gold_ref_idx < 0)
2457 cpi->refresh_golden_frame = 0; 2460 cpi->refresh_golden_frame = 0;
2458 if (cpi->alt_ref_source == NULL) 2461 if (cpi->alt_ref_source == NULL)
2459 cpi->refresh_alt_ref_frame = 0; 2462 cpi->refresh_alt_ref_frame = 0;
2460 } 2463 }
2461 } 2464 }
2462 2465
2463 int is_skippable_frame(const VP9_COMP *cpi) { 2466 static int is_skippable_frame(const VP9_COMP *cpi) {
2464 // If the current frame does not have non-zero motion vector detected in the 2467 // If the current frame does not have non-zero motion vector detected in the
2465 // first pass, and so do its previous and forward frames, then this frame 2468 // first pass, and so do its previous and forward frames, then this frame
2466 // can be skipped for partition check, and the partition size is assigned 2469 // can be skipped for partition check, and the partition size is assigned
2467 // according to the variance 2470 // according to the variance
2468 const SVC *const svc = &cpi->svc; 2471 const SVC *const svc = &cpi->svc;
2469 const TWO_PASS *const twopass = is_two_pass_svc(cpi) ? 2472 const TWO_PASS *const twopass = is_two_pass_svc(cpi) ?
2470 &svc->layer_context[svc->spatial_layer_id].twopass : &cpi->twopass; 2473 &svc->layer_context[svc->spatial_layer_id].twopass : &cpi->twopass;
2471 2474
2472 return (!frame_is_intra_only(&cpi->common) && 2475 return (!frame_is_intra_only(&cpi->common) &&
2473 twopass->stats_in - 2 > twopass->stats_in_start && 2476 twopass->stats_in - 2 > twopass->stats_in_start &&
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 cm->frame_type = INTER_FRAME; 2576 cm->frame_type = INTER_FRAME;
2574 } 2577 }
2575 2578
2576 if (lc != NULL) { 2579 if (lc != NULL) {
2577 if (cpi->svc.spatial_layer_id == 0) { 2580 if (cpi->svc.spatial_layer_id == 0) {
2578 lc->is_key_frame = (cm->frame_type == KEY_FRAME); 2581 lc->is_key_frame = (cm->frame_type == KEY_FRAME);
2579 if (lc->is_key_frame) { 2582 if (lc->is_key_frame) {
2580 cpi->ref_frame_flags &= 2583 cpi->ref_frame_flags &=
2581 (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG); 2584 (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
2582 lc->frames_from_key_frame = 0; 2585 lc->frames_from_key_frame = 0;
2583 // Reset the empty frame resolution since we have a key frame. 2586 // Encode an intra only empty frame since we have a key frame.
2584 cpi->svc.empty_frame_width = cm->width; 2587 cpi->svc.encode_intra_empty_frame = 1;
2585 cpi->svc.empty_frame_height = cm->height;
2586 } 2588 }
2587 } else { 2589 } else {
2588 cm->frame_type = INTER_FRAME; 2590 cm->frame_type = INTER_FRAME;
2589 lc->is_key_frame = cpi->svc.layer_context[0].is_key_frame; 2591 lc->is_key_frame = cpi->svc.layer_context[0].is_key_frame;
2590 2592
2591 if (lc->is_key_frame) { 2593 if (lc->is_key_frame) {
2592 cpi->ref_frame_flags &= (~VP9_LAST_FLAG); 2594 cpi->ref_frame_flags &= (~VP9_LAST_FLAG);
2593 lc->frames_from_key_frame = 0; 2595 lc->frames_from_key_frame = 0;
2594 } 2596 }
2595 } 2597 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2642 twopass->mb_av_energy = 2644 twopass->mb_av_energy =
2643 log(((this_frame.intra_error * 256.0) / num_mbs) + 1.0); 2645 log(((this_frame.intra_error * 256.0) / num_mbs) + 1.0);
2644 } 2646 }
2645 2647
2646 // Update the total stats remaining structure. 2648 // Update the total stats remaining structure.
2647 subtract_stats(&twopass->total_left_stats, &this_frame); 2649 subtract_stats(&twopass->total_left_stats, &this_frame);
2648 } 2650 }
2649 2651
2650 #define MINQ_ADJ_LIMIT 48 2652 #define MINQ_ADJ_LIMIT 48
2651 #define MINQ_ADJ_LIMIT_CQ 20 2653 #define MINQ_ADJ_LIMIT_CQ 20
2654 #define HIGH_UNDERSHOOT_RATIO 2
2652 void vp9_twopass_postencode_update(VP9_COMP *cpi) { 2655 void vp9_twopass_postencode_update(VP9_COMP *cpi) {
2653 TWO_PASS *const twopass = &cpi->twopass; 2656 TWO_PASS *const twopass = &cpi->twopass;
2654 RATE_CONTROL *const rc = &cpi->rc; 2657 RATE_CONTROL *const rc = &cpi->rc;
2655 const int bits_used = rc->base_frame_target; 2658 const int bits_used = rc->base_frame_target;
2656 2659
2657 // VBR correction is done through rc->vbr_bits_off_target. Based on the 2660 // VBR correction is done through rc->vbr_bits_off_target. Based on the
2658 // sign of this value, a limited % adjustment is made to the target rate 2661 // sign of this value, a limited % adjustment is made to the target rate
2659 // of subsequent frames, to try and push it back towards 0. This method 2662 // of subsequent frames, to try and push it back towards 0. This method
2660 // is designed to prevent extreme behaviour at the end of a clip 2663 // is designed to prevent extreme behaviour at the end of a clip
2661 // or group of frames. 2664 // or group of frames.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2708 2711
2709 // Unwind undershoot or overshoot adjustment. 2712 // Unwind undershoot or overshoot adjustment.
2710 if (rc->rolling_target_bits < rc->rolling_actual_bits) 2713 if (rc->rolling_target_bits < rc->rolling_actual_bits)
2711 --twopass->extend_minq; 2714 --twopass->extend_minq;
2712 else if (rc->rolling_target_bits > rc->rolling_actual_bits) 2715 else if (rc->rolling_target_bits > rc->rolling_actual_bits)
2713 --twopass->extend_maxq; 2716 --twopass->extend_maxq;
2714 } 2717 }
2715 2718
2716 twopass->extend_minq = clamp(twopass->extend_minq, 0, minq_adj_limit); 2719 twopass->extend_minq = clamp(twopass->extend_minq, 0, minq_adj_limit);
2717 twopass->extend_maxq = clamp(twopass->extend_maxq, 0, maxq_adj_limit); 2720 twopass->extend_maxq = clamp(twopass->extend_maxq, 0, maxq_adj_limit);
2721
2722 // If there is a big and undexpected undershoot then feed the extra
2723 // bits back in quickly. One situation where this may happen is if a
2724 // frame is unexpectedly almost perfectly predicted by the ARF or GF
2725 // but not very well predcited by the previous frame.
2726 if (!frame_is_kf_gf_arf(cpi) && !cpi->rc.is_src_frame_alt_ref) {
2727 int fast_extra_thresh = rc->base_frame_target / HIGH_UNDERSHOOT_RATIO;
2728 if (rc->projected_frame_size < fast_extra_thresh) {
2729 rc->vbr_bits_off_target_fast +=
2730 fast_extra_thresh - rc->projected_frame_size;
2731 rc->vbr_bits_off_target_fast =
2732 MIN(rc->vbr_bits_off_target_fast, (4 * rc->avg_frame_bandwidth));
2733
2734 // Fast adaptation of minQ if necessary to use up the extra bits.
2735 if (rc->avg_frame_bandwidth) {
2736 twopass->extend_minq_fast =
2737 (int)(rc->vbr_bits_off_target_fast * 8 / rc->avg_frame_bandwidth);
2738 }
2739 twopass->extend_minq_fast = MIN(twopass->extend_minq_fast,
2740 minq_adj_limit - twopass->extend_minq);
2741 } else if (rc->vbr_bits_off_target_fast) {
2742 twopass->extend_minq_fast = MIN(twopass->extend_minq_fast,
2743 minq_adj_limit - twopass->extend_minq);
2744 } else {
2745 twopass->extend_minq_fast = 0;
2746 }
2747 }
2718 } 2748 }
2719 } 2749 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_firstpass.h ('k') | source/libvpx/vp9/encoder/vp9_mcomp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698