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

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

Issue 958693004: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 10 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_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_ethread.c » ('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
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "vp9/encoder/vp9_ratectrl.h" 43 #include "vp9/encoder/vp9_ratectrl.h"
44 #include "vp9/encoder/vp9_rd.h" 44 #include "vp9/encoder/vp9_rd.h"
45 #include "vp9/encoder/vp9_segmentation.h" 45 #include "vp9/encoder/vp9_segmentation.h"
46 #include "vp9/encoder/vp9_speed_features.h" 46 #include "vp9/encoder/vp9_speed_features.h"
47 #if CONFIG_INTERNAL_STATS 47 #if CONFIG_INTERNAL_STATS
48 #include "vp9/encoder/vp9_ssim.h" 48 #include "vp9/encoder/vp9_ssim.h"
49 #endif 49 #endif
50 #include "vp9/encoder/vp9_temporal_filter.h" 50 #include "vp9/encoder/vp9_temporal_filter.h"
51 #include "vp9/encoder/vp9_resize.h" 51 #include "vp9/encoder/vp9_resize.h"
52 #include "vp9/encoder/vp9_svc_layercontext.h" 52 #include "vp9/encoder/vp9_svc_layercontext.h"
53 #include "vp9/encoder/vp9_skin_detection.h"
53 54
54 55
55 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ 56 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */
56 57
57 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv 58 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv
58 // for altref computation. 59 // for altref computation.
59 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision 60 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision
60 // mv. Choose a very high value for 61 // mv. Choose a very high value for
61 // now so that HIGH_PRECISION is always 62 // now so that HIGH_PRECISION is always
62 // chosen. 63 // chosen.
63
64 // #define OUTPUT_YUV_REC 64 // #define OUTPUT_YUV_REC
65 65
66 #ifdef OUTPUT_YUV_DENOISED 66 #ifdef OUTPUT_YUV_DENOISED
67 FILE *yuv_denoised_file = NULL; 67 FILE *yuv_denoised_file = NULL;
68 #endif 68 #endif
69 #ifdef OUTPUT_YUV_SKINMAP
70 FILE *yuv_skinmap_file = NULL;
71 #endif
69 #ifdef OUTPUT_YUV_REC 72 #ifdef OUTPUT_YUV_REC
70 FILE *yuv_rec_file; 73 FILE *yuv_rec_file;
71 #endif 74 #endif
72 75
73 #if 0 76 #if 0
74 FILE *framepsnr; 77 FILE *framepsnr;
75 FILE *kf_list; 78 FILE *kf_list;
76 FILE *keyfile; 79 FILE *keyfile;
77 #endif 80 #endif
78 81
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 static void dealloc_compressor_data(VP9_COMP *cpi) { 200 static void dealloc_compressor_data(VP9_COMP *cpi) {
198 VP9_COMMON *const cm = &cpi->common; 201 VP9_COMMON *const cm = &cpi->common;
199 int i; 202 int i;
200 203
201 vpx_free(cpi->tile_data); 204 vpx_free(cpi->tile_data);
202 cpi->tile_data = NULL; 205 cpi->tile_data = NULL;
203 206
204 // Delete sementation map 207 // Delete sementation map
205 vpx_free(cpi->segmentation_map); 208 vpx_free(cpi->segmentation_map);
206 cpi->segmentation_map = NULL; 209 cpi->segmentation_map = NULL;
207 vpx_free(cm->last_frame_seg_map);
208 cm->last_frame_seg_map = NULL;
209 vpx_free(cpi->coding_context.last_frame_seg_map_copy); 210 vpx_free(cpi->coding_context.last_frame_seg_map_copy);
210 cpi->coding_context.last_frame_seg_map_copy = NULL; 211 cpi->coding_context.last_frame_seg_map_copy = NULL;
211 212
212 vpx_free(cpi->nmvcosts[0]); 213 vpx_free(cpi->nmvcosts[0]);
213 vpx_free(cpi->nmvcosts[1]); 214 vpx_free(cpi->nmvcosts[1]);
214 cpi->nmvcosts[0] = NULL; 215 cpi->nmvcosts[0] = NULL;
215 cpi->nmvcosts[1] = NULL; 216 cpi->nmvcosts[1] = NULL;
216 217
217 vpx_free(cpi->nmvcosts_hp[0]); 218 vpx_free(cpi->nmvcosts_hp[0]);
218 vpx_free(cpi->nmvcosts_hp[1]); 219 vpx_free(cpi->nmvcosts_hp[1]);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 cache[0] = mi_8x8[0].src_mi->mbmi.segment_id; 465 cache[0] = mi_8x8[0].src_mi->mbmi.segment_id;
465 mi_8x8_ptr += cm->mi_stride; 466 mi_8x8_ptr += cm->mi_stride;
466 cache_ptr += cm->mi_cols; 467 cache_ptr += cm->mi_cols;
467 } 468 }
468 } 469 }
469 470
470 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { 471 static void alloc_raw_frame_buffers(VP9_COMP *cpi) {
471 VP9_COMMON *cm = &cpi->common; 472 VP9_COMMON *cm = &cpi->common;
472 const VP9EncoderConfig *oxcf = &cpi->oxcf; 473 const VP9EncoderConfig *oxcf = &cpi->oxcf;
473 474
474 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, 475 if (!cpi->lookahead)
475 cm->subsampling_x, cm->subsampling_y, 476 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height,
477 cm->subsampling_x, cm->subsampling_y,
476 #if CONFIG_VP9_HIGHBITDEPTH 478 #if CONFIG_VP9_HIGHBITDEPTH
477 cm->use_highbitdepth, 479 cm->use_highbitdepth,
478 #endif 480 #endif
479 oxcf->lag_in_frames); 481 oxcf->lag_in_frames);
480 if (!cpi->lookahead) 482 if (!cpi->lookahead)
481 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 483 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
482 "Failed to allocate lag buffers"); 484 "Failed to allocate lag buffers");
483 485
484 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, 486 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
485 oxcf->width, oxcf->height, 487 oxcf->width, oxcf->height,
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 vp9_new_framerate(cpi, cpi->framerate); 1307 vp9_new_framerate(cpi, cpi->framerate);
1306 1308
1307 // Set absolute upper and lower quality limits 1309 // Set absolute upper and lower quality limits
1308 rc->worst_quality = cpi->oxcf.worst_allowed_q; 1310 rc->worst_quality = cpi->oxcf.worst_allowed_q;
1309 rc->best_quality = cpi->oxcf.best_allowed_q; 1311 rc->best_quality = cpi->oxcf.best_allowed_q;
1310 1312
1311 cm->interp_filter = cpi->sf.default_interp_filter; 1313 cm->interp_filter = cpi->sf.default_interp_filter;
1312 1314
1313 cm->display_width = cpi->oxcf.width; 1315 cm->display_width = cpi->oxcf.width;
1314 cm->display_height = cpi->oxcf.height; 1316 cm->display_height = cpi->oxcf.height;
1317 cm->width = cpi->oxcf.width;
1318 cm->height = cpi->oxcf.height;
1315 1319
1316 if (cpi->initial_width) { 1320 if (cpi->initial_width) {
1317 // Increasing the size of the frame beyond the first seen frame, or some 1321 if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) {
1318 // otherwise signaled maximum size, is not supported. 1322 vp9_free_context_buffers(cm);
1319 // TODO(jkoleszar): exit gracefully. 1323 vp9_alloc_context_buffers(cm, cm->width, cm->height);
1320 assert(cm->width <= cpi->initial_width); 1324 cpi->initial_width = cpi->initial_height = 0;
1321 assert(cm->height <= cpi->initial_height); 1325 }
1322 } 1326 }
1323 update_frame_size(cpi); 1327 update_frame_size(cpi);
1324 1328
1325 if ((cpi->svc.number_temporal_layers > 1 && 1329 if ((cpi->svc.number_temporal_layers > 1 &&
1326 cpi->oxcf.rc_mode == VPX_CBR) || 1330 cpi->oxcf.rc_mode == VPX_CBR) ||
1327 ((cpi->svc.number_temporal_layers > 1 || 1331 ((cpi->svc.number_temporal_layers > 1 ||
1328 cpi->svc.number_spatial_layers > 1) && 1332 cpi->svc.number_spatial_layers > 1) &&
1329 cpi->oxcf.pass != 1)) { 1333 cpi->oxcf.pass != 1)) {
1330 vp9_update_layer_context_change_config(cpi, 1334 vp9_update_layer_context_change_config(cpi,
1331 (int)cpi->oxcf.target_bandwidth); 1335 (int)cpi->oxcf.target_bandwidth);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 do { 1390 do {
1387 double z = 256 * (2 * (log2f(8 * i) + .6)); 1391 double z = 256 * (2 * (log2f(8 * i) + .6));
1388 mvsadcost[0][i] = (int)z; 1392 mvsadcost[0][i] = (int)z;
1389 mvsadcost[1][i] = (int)z; 1393 mvsadcost[1][i] = (int)z;
1390 mvsadcost[0][-i] = (int)z; 1394 mvsadcost[0][-i] = (int)z;
1391 mvsadcost[1][-i] = (int)z; 1395 mvsadcost[1][-i] = (int)z;
1392 } while (++i <= MV_MAX); 1396 } while (++i <= MV_MAX);
1393 } 1397 }
1394 1398
1395 1399
1396 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { 1400 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
1401 BufferPool *const pool) {
1397 unsigned int i; 1402 unsigned int i;
1398 VP9_COMP *volatile const cpi = vpx_memalign(32, sizeof(VP9_COMP)); 1403 VP9_COMP *volatile const cpi = vpx_memalign(32, sizeof(VP9_COMP));
1399 VP9_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; 1404 VP9_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL;
1400 1405
1401 if (!cm) 1406 if (!cm)
1402 return NULL; 1407 return NULL;
1403 1408
1404 vp9_zero(*cpi); 1409 vp9_zero(*cpi);
1405 1410
1406 if (setjmp(cm->error.jmp)) { 1411 if (setjmp(cm->error.jmp)) {
1407 cm->error.setjmp = 0; 1412 cm->error.setjmp = 0;
1408 vp9_remove_compressor(cpi); 1413 vp9_remove_compressor(cpi);
1409 return 0; 1414 return 0;
1410 } 1415 }
1411 1416
1412 cm->error.setjmp = 1; 1417 cm->error.setjmp = 1;
1413 cm->alloc_mi = vp9_enc_alloc_mi; 1418 cm->alloc_mi = vp9_enc_alloc_mi;
1414 cm->free_mi = vp9_enc_free_mi; 1419 cm->free_mi = vp9_enc_free_mi;
1415 cm->setup_mi = vp9_enc_setup_mi; 1420 cm->setup_mi = vp9_enc_setup_mi;
1416 1421
1417 CHECK_MEM_ERROR(cm, cm->fc, 1422 CHECK_MEM_ERROR(cm, cm->fc,
1418 (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); 1423 (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc)));
1419 CHECK_MEM_ERROR(cm, cm->frame_contexts, 1424 CHECK_MEM_ERROR(cm, cm->frame_contexts,
1420 (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, 1425 (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS,
1421 sizeof(*cm->frame_contexts))); 1426 sizeof(*cm->frame_contexts)));
1422 1427
1423 cpi->use_svc = 0; 1428 cpi->use_svc = 0;
1429 cpi->common.buffer_pool = pool;
1424 1430
1425 init_config(cpi, oxcf); 1431 init_config(cpi, oxcf);
1426 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); 1432 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
1427 1433
1428 cm->current_video_frame = 0; 1434 cm->current_video_frame = 0;
1429 cpi->partition_search_skippable_frame = 0; 1435 cpi->partition_search_skippable_frame = 0;
1430 cpi->tile_data = NULL; 1436 cpi->tile_data = NULL;
1431 1437
1432 // Create the encoder segmentation map and set all entries to 0 1438 // Create the encoder segmentation map and set all entries to 0
1433 CHECK_MEM_ERROR(cm, cpi->segmentation_map, 1439 CHECK_MEM_ERROR(cm, cpi->segmentation_map,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 cpi->td.mb.nmvcost_hp[1] = &cpi->nmvcosts_hp[1][MV_MAX]; 1537 cpi->td.mb.nmvcost_hp[1] = &cpi->nmvcosts_hp[1][MV_MAX];
1532 cpi->td.mb.nmvsadcost_hp[0] = &cpi->nmvsadcosts_hp[0][MV_MAX]; 1538 cpi->td.mb.nmvsadcost_hp[0] = &cpi->nmvsadcosts_hp[0][MV_MAX];
1533 cpi->td.mb.nmvsadcost_hp[1] = &cpi->nmvsadcosts_hp[1][MV_MAX]; 1539 cpi->td.mb.nmvsadcost_hp[1] = &cpi->nmvsadcosts_hp[1][MV_MAX];
1534 cal_nmvsadcosts_hp(cpi->td.mb.nmvsadcost_hp); 1540 cal_nmvsadcosts_hp(cpi->td.mb.nmvsadcost_hp);
1535 1541
1536 #if CONFIG_VP9_TEMPORAL_DENOISING 1542 #if CONFIG_VP9_TEMPORAL_DENOISING
1537 #ifdef OUTPUT_YUV_DENOISED 1543 #ifdef OUTPUT_YUV_DENOISED
1538 yuv_denoised_file = fopen("denoised.yuv", "ab"); 1544 yuv_denoised_file = fopen("denoised.yuv", "ab");
1539 #endif 1545 #endif
1540 #endif 1546 #endif
1547 #ifdef OUTPUT_YUV_SKINMAP
1548 yuv_skinmap_file = fopen("skinmap.yuv", "ab");
1549 #endif
1541 #ifdef OUTPUT_YUV_REC 1550 #ifdef OUTPUT_YUV_REC
1542 yuv_rec_file = fopen("rec.yuv", "wb"); 1551 yuv_rec_file = fopen("rec.yuv", "wb");
1543 #endif 1552 #endif
1544 1553
1545 #if 0 1554 #if 0
1546 framepsnr = fopen("framepsnr.stt", "a"); 1555 framepsnr = fopen("framepsnr.stt", "a");
1547 kf_list = fopen("kf_list.stt", "w"); 1556 kf_list = fopen("kf_list.stt", "w");
1548 #endif 1557 #endif
1549 1558
1550 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; 1559 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED;
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 #endif 1828 #endif
1820 1829
1821 vp9_remove_common(cm); 1830 vp9_remove_common(cm);
1822 vpx_free(cpi); 1831 vpx_free(cpi);
1823 1832
1824 #if CONFIG_VP9_TEMPORAL_DENOISING 1833 #if CONFIG_VP9_TEMPORAL_DENOISING
1825 #ifdef OUTPUT_YUV_DENOISED 1834 #ifdef OUTPUT_YUV_DENOISED
1826 fclose(yuv_denoised_file); 1835 fclose(yuv_denoised_file);
1827 #endif 1836 #endif
1828 #endif 1837 #endif
1838 #ifdef OUTPUT_YUV_SKINMAP
1839 fclose(yuv_skinmap_file);
1840 #endif
1829 #ifdef OUTPUT_YUV_REC 1841 #ifdef OUTPUT_YUV_REC
1830 fclose(yuv_rec_file); 1842 fclose(yuv_rec_file);
1831 #endif 1843 #endif
1832 1844
1833 #if 0 1845 #if 0
1834 1846
1835 if (keyfile) 1847 if (keyfile)
1836 fclose(keyfile); 1848 fclose(keyfile);
1837 1849
1838 if (framepsnr) 1850 if (framepsnr)
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 return -1; 2118 return -1;
2107 } 2119 }
2108 } 2120 }
2109 2121
2110 int vp9_update_entropy(VP9_COMP * cpi, int update) { 2122 int vp9_update_entropy(VP9_COMP * cpi, int update) {
2111 cpi->ext_refresh_frame_context = update; 2123 cpi->ext_refresh_frame_context = update;
2112 cpi->ext_refresh_frame_context_pending = 1; 2124 cpi->ext_refresh_frame_context_pending = 1;
2113 return 0; 2125 return 0;
2114 } 2126 }
2115 2127
2116 #if CONFIG_VP9_TEMPORAL_DENOISING 2128 #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP)
2117 #if defined(OUTPUT_YUV_DENOISED)
2118 // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it 2129 // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it
2119 // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do 2130 // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do
2120 // not denoise the UV channels at this time. If ever we implement UV channel 2131 // not denoise the UV channels at this time. If ever we implement UV channel
2121 // denoising we will have to modify this. 2132 // denoising we will have to modify this.
2122 void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { 2133 void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) {
2123 uint8_t *src = s->y_buffer; 2134 uint8_t *src = s->y_buffer;
2124 int h = s->y_height; 2135 int h = s->y_height;
2125 2136
2126 do { 2137 do {
2127 fwrite(src, s->y_width, 1, f); 2138 fwrite(src, s->y_width, 1, f);
(...skipping 10 matching lines...) Expand all
2138 2149
2139 src = s->v_buffer; 2150 src = s->v_buffer;
2140 h = s->uv_height; 2151 h = s->uv_height;
2141 2152
2142 do { 2153 do {
2143 fwrite(src, s->uv_width, 1, f); 2154 fwrite(src, s->uv_width, 1, f);
2144 src += s->uv_stride; 2155 src += s->uv_stride;
2145 } while (--h); 2156 } while (--h);
2146 } 2157 }
2147 #endif 2158 #endif
2148 #endif
2149 2159
2150 #ifdef OUTPUT_YUV_REC 2160 #ifdef OUTPUT_YUV_REC
2151 void vp9_write_yuv_rec_frame(VP9_COMMON *cm) { 2161 void vp9_write_yuv_rec_frame(VP9_COMMON *cm) {
2152 YV12_BUFFER_CONFIG *s = cm->frame_to_show; 2162 YV12_BUFFER_CONFIG *s = cm->frame_to_show;
2153 uint8_t *src = s->y_buffer; 2163 uint8_t *src = s->y_buffer;
2154 int h = cm->height; 2164 int h = cm->height;
2155 2165
2156 #if CONFIG_VP9_HIGHBITDEPTH 2166 #if CONFIG_VP9_HIGHBITDEPTH
2157 if (s->flags & YV12_FLAG_HIGHBITDEPTH) { 2167 if (s->flags & YV12_FLAG_HIGHBITDEPTH) {
2158 uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); 2168 uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 kernel[y_q4 & 0xf], 16 * src_h / dst_h, 2307 kernel[y_q4 & 0xf], 16 * src_h / dst_h,
2298 16 / factor, 16 / factor); 2308 16 / factor, 16 / factor);
2299 #endif // CONFIG_VP9_HIGHBITDEPTH 2309 #endif // CONFIG_VP9_HIGHBITDEPTH
2300 } 2310 }
2301 } 2311 }
2302 } 2312 }
2303 2313
2304 vp9_extend_frame_borders(dst); 2314 vp9_extend_frame_borders(dst);
2305 } 2315 }
2306 2316
2317 static int scale_down(VP9_COMP *cpi, int q) {
2318 RATE_CONTROL *const rc = &cpi->rc;
2319 GF_GROUP *const gf_group = &cpi->twopass.gf_group;
2320 int scale = 0;
2321 assert(frame_is_kf_gf_arf(cpi));
2322
2323 if (rc->frame_size_selector == UNSCALED &&
2324 q >= rc->rf_level_maxq[gf_group->rf_level[gf_group->index]]) {
2325 const int max_size_thresh = (int)(rate_thresh_mult[SCALE_STEP1]
2326 * MAX(rc->this_frame_target, rc->avg_frame_bandwidth));
2327 scale = rc->projected_frame_size > max_size_thresh ? 1 : 0;
2328 }
2329 return scale;
2330 }
2331
2307 // Function to test for conditions that indicate we should loop 2332 // Function to test for conditions that indicate we should loop
2308 // back and recode a frame. 2333 // back and recode a frame.
2309 static int recode_loop_test(const VP9_COMP *cpi, 2334 static int recode_loop_test(VP9_COMP *cpi,
2310 int high_limit, int low_limit, 2335 int high_limit, int low_limit,
2311 int q, int maxq, int minq) { 2336 int q, int maxq, int minq) {
2312 const RATE_CONTROL *const rc = &cpi->rc; 2337 const RATE_CONTROL *const rc = &cpi->rc;
2313 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 2338 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
2339 const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi);
2314 int force_recode = 0; 2340 int force_recode = 0;
2315 2341
2316 // Special case trap if maximum allowed frame size exceeded. 2342 if ((cpi->sf.recode_loop == ALLOW_RECODE) ||
2317 if (rc->projected_frame_size > rc->max_frame_bandwidth) { 2343 (frame_is_kfgfarf &&
2318 force_recode = 1; 2344 (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) {
2345 if (frame_is_kfgfarf &&
2346 (oxcf->resize_mode == RESIZE_DYNAMIC) &&
2347 scale_down(cpi, q)) {
2348 // Code this group at a lower resolution.
2349 cpi->resize_pending = 1;
2350 return 1;
2351 }
2319 2352
2320 // Is frame recode allowed. 2353 // TODO(agrange) high_limit could be greater than the scale-down threshold.
2321 // Yes if either recode mode 1 is selected or mode 2 is selected
2322 // and the frame is a key frame, golden frame or alt_ref_frame
2323 } else if ((cpi->sf.recode_loop == ALLOW_RECODE) ||
2324 ((cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF) &&
2325 frame_is_kf_gf_arf(cpi))) {
2326 // General over and under shoot tests
2327 if ((rc->projected_frame_size > high_limit && q < maxq) || 2354 if ((rc->projected_frame_size > high_limit && q < maxq) ||
2328 (rc->projected_frame_size < low_limit && q > minq)) { 2355 (rc->projected_frame_size < low_limit && q > minq)) {
2329 force_recode = 1; 2356 force_recode = 1;
2330 } else if (cpi->oxcf.rc_mode == VPX_CQ) { 2357 } else if (cpi->oxcf.rc_mode == VPX_CQ) {
2331 // Deal with frame undershoot and whether or not we are 2358 // Deal with frame undershoot and whether or not we are
2332 // below the automatically set cq level. 2359 // below the automatically set cq level.
2333 if (q > oxcf->cq_level && 2360 if (q > oxcf->cq_level &&
2334 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { 2361 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) {
2335 force_recode = 1; 2362 force_recode = 1;
2336 } 2363 }
2337 } 2364 }
2338 } 2365 }
2339 return force_recode; 2366 return force_recode;
2340 } 2367 }
2341 2368
2342 void vp9_update_reference_frames(VP9_COMP *cpi) { 2369 void vp9_update_reference_frames(VP9_COMP *cpi) {
2343 VP9_COMMON * const cm = &cpi->common; 2370 VP9_COMMON * const cm = &cpi->common;
2371 BufferPool *const pool = cm->buffer_pool;
2344 2372
2345 // At this point the new frame has been encoded. 2373 // At this point the new frame has been encoded.
2346 // If any buffer copy / swapping is signaled it should be done here. 2374 // If any buffer copy / swapping is signaled it should be done here.
2347 if (cm->frame_type == KEY_FRAME) { 2375 if (cm->frame_type == KEY_FRAME) {
2348 ref_cnt_fb(cm->frame_bufs, 2376 ref_cnt_fb(pool->frame_bufs,
2349 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); 2377 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
2350 ref_cnt_fb(cm->frame_bufs, 2378 ref_cnt_fb(pool->frame_bufs,
2351 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); 2379 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
2352 } else if (vp9_preserve_existing_gf(cpi)) { 2380 } else if (vp9_preserve_existing_gf(cpi)) {
2353 // We have decided to preserve the previously existing golden frame as our 2381 // We have decided to preserve the previously existing golden frame as our
2354 // new ARF frame. However, in the short term in function 2382 // new ARF frame. However, in the short term in function
2355 // vp9_bitstream.c::get_refresh_mask() we left it in the GF slot and, if 2383 // vp9_bitstream.c::get_refresh_mask() we left it in the GF slot and, if
2356 // we're updating the GF with the current decoded frame, we save it to the 2384 // we're updating the GF with the current decoded frame, we save it to the
2357 // ARF slot instead. 2385 // ARF slot instead.
2358 // We now have to update the ARF with the current frame and swap gld_fb_idx 2386 // We now have to update the ARF with the current frame and swap gld_fb_idx
2359 // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF 2387 // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF
2360 // slot and, if we're updating the GF, the current frame becomes the new GF. 2388 // slot and, if we're updating the GF, the current frame becomes the new GF.
2361 int tmp; 2389 int tmp;
2362 2390
2363 ref_cnt_fb(cm->frame_bufs, 2391 ref_cnt_fb(pool->frame_bufs,
2364 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); 2392 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
2365 2393
2366 tmp = cpi->alt_fb_idx; 2394 tmp = cpi->alt_fb_idx;
2367 cpi->alt_fb_idx = cpi->gld_fb_idx; 2395 cpi->alt_fb_idx = cpi->gld_fb_idx;
2368 cpi->gld_fb_idx = tmp; 2396 cpi->gld_fb_idx = tmp;
2369 2397
2370 if (is_two_pass_svc(cpi)) { 2398 if (is_two_pass_svc(cpi)) {
2371 cpi->svc.layer_context[0].gold_ref_idx = cpi->gld_fb_idx; 2399 cpi->svc.layer_context[0].gold_ref_idx = cpi->gld_fb_idx;
2372 cpi->svc.layer_context[0].alt_ref_idx = cpi->alt_fb_idx; 2400 cpi->svc.layer_context[0].alt_ref_idx = cpi->alt_fb_idx;
2373 } 2401 }
2374 } else { /* For non key/golden frames */ 2402 } else { /* For non key/golden frames */
2375 if (cpi->refresh_alt_ref_frame) { 2403 if (cpi->refresh_alt_ref_frame) {
2376 int arf_idx = cpi->alt_fb_idx; 2404 int arf_idx = cpi->alt_fb_idx;
2377 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { 2405 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) {
2378 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; 2406 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
2379 arf_idx = gf_group->arf_update_idx[gf_group->index]; 2407 arf_idx = gf_group->arf_update_idx[gf_group->index];
2380 } 2408 }
2381 2409
2382 ref_cnt_fb(cm->frame_bufs, 2410 ref_cnt_fb(pool->frame_bufs,
2383 &cm->ref_frame_map[arf_idx], cm->new_fb_idx); 2411 &cm->ref_frame_map[arf_idx], cm->new_fb_idx);
2384 vpx_memcpy(cpi->interp_filter_selected[ALTREF_FRAME], 2412 vpx_memcpy(cpi->interp_filter_selected[ALTREF_FRAME],
2385 cpi->interp_filter_selected[0], 2413 cpi->interp_filter_selected[0],
2386 sizeof(cpi->interp_filter_selected[0])); 2414 sizeof(cpi->interp_filter_selected[0]));
2387 } 2415 }
2388 2416
2389 if (cpi->refresh_golden_frame) { 2417 if (cpi->refresh_golden_frame) {
2390 ref_cnt_fb(cm->frame_bufs, 2418 ref_cnt_fb(pool->frame_bufs,
2391 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); 2419 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
2392 if (!cpi->rc.is_src_frame_alt_ref) 2420 if (!cpi->rc.is_src_frame_alt_ref)
2393 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], 2421 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME],
2394 cpi->interp_filter_selected[0], 2422 cpi->interp_filter_selected[0],
2395 sizeof(cpi->interp_filter_selected[0])); 2423 sizeof(cpi->interp_filter_selected[0]));
2396 else 2424 else
2397 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], 2425 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME],
2398 cpi->interp_filter_selected[ALTREF_FRAME], 2426 cpi->interp_filter_selected[ALTREF_FRAME],
2399 sizeof(cpi->interp_filter_selected[ALTREF_FRAME])); 2427 sizeof(cpi->interp_filter_selected[ALTREF_FRAME]));
2400 } 2428 }
2401 } 2429 }
2402 2430
2403 if (cpi->refresh_last_frame) { 2431 if (cpi->refresh_last_frame) {
2404 ref_cnt_fb(cm->frame_bufs, 2432 ref_cnt_fb(pool->frame_bufs,
2405 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); 2433 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx);
2406 if (!cpi->rc.is_src_frame_alt_ref) 2434 if (!cpi->rc.is_src_frame_alt_ref)
2407 vpx_memcpy(cpi->interp_filter_selected[LAST_FRAME], 2435 vpx_memcpy(cpi->interp_filter_selected[LAST_FRAME],
2408 cpi->interp_filter_selected[0], 2436 cpi->interp_filter_selected[0],
2409 sizeof(cpi->interp_filter_selected[0])); 2437 sizeof(cpi->interp_filter_selected[0]));
2410 } 2438 }
2411 #if CONFIG_VP9_TEMPORAL_DENOISING 2439 #if CONFIG_VP9_TEMPORAL_DENOISING
2412 if (cpi->oxcf.noise_sensitivity > 0) { 2440 if (cpi->oxcf.noise_sensitivity > 0) {
2413 vp9_denoiser_update_frame_info(&cpi->denoiser, 2441 vp9_denoiser_update_frame_info(&cpi->denoiser,
2414 *cpi->Source, 2442 *cpi->Source,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 2481
2454 void vp9_scale_references(VP9_COMP *cpi) { 2482 void vp9_scale_references(VP9_COMP *cpi) {
2455 VP9_COMMON *cm = &cpi->common; 2483 VP9_COMMON *cm = &cpi->common;
2456 MV_REFERENCE_FRAME ref_frame; 2484 MV_REFERENCE_FRAME ref_frame;
2457 const VP9_REFFRAME ref_mask[3] = {VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG}; 2485 const VP9_REFFRAME ref_mask[3] = {VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG};
2458 2486
2459 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 2487 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
2460 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1). 2488 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1).
2461 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { 2489 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) {
2462 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; 2490 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
2463 const YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf; 2491 BufferPool *const pool = cm->buffer_pool;
2492 const YV12_BUFFER_CONFIG *const ref = &pool->frame_bufs[idx].buf;
2464 2493
2465 #if CONFIG_VP9_HIGHBITDEPTH 2494 #if CONFIG_VP9_HIGHBITDEPTH
2466 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { 2495 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
2467 const int new_fb = get_free_fb(cm); 2496 const int new_fb = get_free_fb(cm);
2468 cm->cur_frame = &cm->frame_bufs[new_fb]; 2497 cm->cur_frame = &pool->frame_bufs[new_fb];
2469 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, 2498 vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf,
2470 cm->width, cm->height, 2499 cm->width, cm->height,
2471 cm->subsampling_x, cm->subsampling_y, 2500 cm->subsampling_x, cm->subsampling_y,
2472 cm->use_highbitdepth, 2501 cm->use_highbitdepth,
2473 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, 2502 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
2474 NULL, NULL, NULL); 2503 NULL, NULL, NULL);
2475 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf, 2504 scale_and_extend_frame(ref, &pool->frame_bufs[new_fb].buf,
2476 (int)cm->bit_depth); 2505 (int)cm->bit_depth);
2477 #else 2506 #else
2478 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { 2507 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
2479 const int new_fb = get_free_fb(cm); 2508 const int new_fb = get_free_fb(cm);
2480 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, 2509 vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf,
2481 cm->width, cm->height, 2510 cm->width, cm->height,
2482 cm->subsampling_x, cm->subsampling_y, 2511 cm->subsampling_x, cm->subsampling_y,
2483 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, 2512 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
2484 NULL, NULL, NULL); 2513 NULL, NULL, NULL);
2485 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf); 2514 scale_and_extend_frame(ref, &pool->frame_bufs[new_fb].buf);
2486 #endif // CONFIG_VP9_HIGHBITDEPTH 2515 #endif // CONFIG_VP9_HIGHBITDEPTH
2487 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; 2516 cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
2488 if (cm->frame_bufs[new_fb].mvs == NULL || 2517 if (pool->frame_bufs[new_fb].mvs == NULL ||
2489 cm->frame_bufs[new_fb].mi_rows < cm->mi_rows || 2518 pool->frame_bufs[new_fb].mi_rows < cm->mi_rows ||
2490 cm->frame_bufs[new_fb].mi_cols < cm->mi_cols) { 2519 pool->frame_bufs[new_fb].mi_cols < cm->mi_cols) {
2491 vpx_free(cm->frame_bufs[new_fb].mvs); 2520 vpx_free(pool->frame_bufs[new_fb].mvs);
2492 cm->frame_bufs[new_fb].mvs = 2521 pool->frame_bufs[new_fb].mvs =
2493 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, 2522 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
2494 sizeof(*cm->frame_bufs[new_fb].mvs)); 2523 sizeof(*pool->frame_bufs[new_fb].mvs));
2495 cm->frame_bufs[new_fb].mi_rows = cm->mi_rows; 2524 pool->frame_bufs[new_fb].mi_rows = cm->mi_rows;
2496 cm->frame_bufs[new_fb].mi_cols = cm->mi_cols; 2525 pool->frame_bufs[new_fb].mi_cols = cm->mi_cols;
2497 } 2526 }
2498 } else { 2527 } else {
2499 cpi->scaled_ref_idx[ref_frame - 1] = idx; 2528 cpi->scaled_ref_idx[ref_frame - 1] = idx;
2500 ++cm->frame_bufs[idx].ref_count; 2529 ++pool->frame_bufs[idx].ref_count;
2501 } 2530 }
2502 } else { 2531 } else {
2503 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_REF_BUFFER_IDX; 2532 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_REF_BUFFER_IDX;
2504 } 2533 }
2505 } 2534 }
2506 } 2535 }
2507 2536
2508 static void release_scaled_references(VP9_COMP *cpi) { 2537 static void release_scaled_references(VP9_COMP *cpi) {
2509 VP9_COMMON *cm = &cpi->common; 2538 VP9_COMMON *cm = &cpi->common;
2510 int i; 2539 int i;
2511 for (i = 0; i < MAX_REF_FRAMES; ++i) { 2540 for (i = 0; i < MAX_REF_FRAMES; ++i) {
2512 const int idx = cpi->scaled_ref_idx[i]; 2541 const int idx = cpi->scaled_ref_idx[i];
2513 RefCntBuffer *const buf = 2542 RefCntBuffer *const buf = idx != INVALID_REF_BUFFER_IDX ?
2514 idx != INVALID_REF_BUFFER_IDX ? &cm->frame_bufs[idx] : NULL; 2543 &cm->buffer_pool->frame_bufs[idx] : NULL;
2515 if (buf != NULL) { 2544 if (buf != NULL) {
2516 --buf->ref_count; 2545 --buf->ref_count;
2517 cpi->scaled_ref_idx[i] = INVALID_REF_BUFFER_IDX; 2546 cpi->scaled_ref_idx[i] = INVALID_REF_BUFFER_IDX;
2518 } 2547 }
2519 } 2548 }
2520 } 2549 }
2521 2550
2522 static void full_to_model_count(unsigned int *model_count, 2551 static void full_to_model_count(unsigned int *model_count,
2523 unsigned int *full_count) { 2552 unsigned int *full_count) {
2524 int n; 2553 int n;
(...skipping 20 matching lines...) Expand all
2545 static void output_frame_level_debug_stats(VP9_COMP *cpi) { 2574 static void output_frame_level_debug_stats(VP9_COMP *cpi) {
2546 VP9_COMMON *const cm = &cpi->common; 2575 VP9_COMMON *const cm = &cpi->common;
2547 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); 2576 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w");
2548 int64_t recon_err; 2577 int64_t recon_err;
2549 2578
2550 vp9_clear_system_state(); 2579 vp9_clear_system_state();
2551 2580
2552 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 2581 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2553 2582
2554 if (cpi->twopass.total_left_stats.coded_error != 0.0) 2583 if (cpi->twopass.total_left_stats.coded_error != 0.0)
2555 fprintf(f, "%10u %10d %10d %10d %10d" 2584 fprintf(f, "%10u %dx%d %10d %10d %10d %10d"
2556 "%10"PRId64" %10"PRId64" %10"PRId64" %10"PRId64" %10d " 2585 "%10"PRId64" %10"PRId64" %10"PRId64" %10"PRId64" %10d "
2557 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" 2586 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf"
2558 "%6d %6d %5d %5d %5d " 2587 "%6d %6d %5d %5d %5d "
2559 "%10"PRId64" %10.3lf" 2588 "%10"PRId64" %10.3lf"
2560 "%10lf %8u %10"PRId64" %10d %10d\n", 2589 "%10lf %8u %10"PRId64" %10d %10d\n",
2561 cpi->common.current_video_frame, cpi->rc.this_frame_target, 2590 cpi->common.current_video_frame,
2591 cm->width, cm->height,
2592 cpi->rc.this_frame_target,
2562 cpi->rc.projected_frame_size, 2593 cpi->rc.projected_frame_size,
2563 cpi->rc.projected_frame_size / cpi->common.MBs, 2594 cpi->rc.projected_frame_size / cpi->common.MBs,
2564 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), 2595 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target),
2565 cpi->rc.vbr_bits_off_target, 2596 cpi->rc.vbr_bits_off_target,
2566 cpi->rc.total_target_vs_actual, 2597 cpi->rc.total_target_vs_actual,
2567 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), 2598 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target),
2568 cpi->rc.total_actual_bits, cm->base_qindex, 2599 cpi->rc.total_actual_bits, cm->base_qindex,
2569 vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth), 2600 vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth),
2570 (double)vp9_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0, 2601 (double)vp9_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0,
2571 vp9_convert_qindex_to_q(cpi->twopass.active_worst_quality, 2602 vp9_convert_qindex_to_q(cpi->twopass.active_worst_quality,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2687 if (cpi->sf.mv.search_method == NSTEP) { 2718 if (cpi->sf.mv.search_method == NSTEP) {
2688 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride); 2719 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride);
2689 } else if (cpi->sf.mv.search_method == DIAMOND) { 2720 } else if (cpi->sf.mv.search_method == DIAMOND) {
2690 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); 2721 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride);
2691 } 2722 }
2692 } 2723 }
2693 2724
2694 void set_frame_size(VP9_COMP *cpi) { 2725 void set_frame_size(VP9_COMP *cpi) {
2695 int ref_frame; 2726 int ref_frame;
2696 VP9_COMMON *const cm = &cpi->common; 2727 VP9_COMMON *const cm = &cpi->common;
2697 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 2728 VP9EncoderConfig *const oxcf = &cpi->oxcf;
2698 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; 2729 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
2699 2730
2700 if (oxcf->pass == 2 && 2731 if (oxcf->pass == 2 &&
2701 cm->current_video_frame == 0 && 2732 oxcf->rc_mode == VPX_VBR &&
2702 oxcf->resize_mode == RESIZE_FIXED && 2733 ((oxcf->resize_mode == RESIZE_FIXED && cm->current_video_frame == 0) ||
2703 oxcf->rc_mode == VPX_VBR) { 2734 (oxcf->resize_mode == RESIZE_DYNAMIC && cpi->resize_pending))) {
2704 // Internal scaling is triggered on the first frame. 2735 calculate_coded_size(
2736 cpi, &oxcf->scaled_frame_width, &oxcf->scaled_frame_height);
2737
2738 // There has been a change in frame size.
2705 vp9_set_size_literal(cpi, oxcf->scaled_frame_width, 2739 vp9_set_size_literal(cpi, oxcf->scaled_frame_width,
2706 oxcf->scaled_frame_height); 2740 oxcf->scaled_frame_height);
2707 } 2741 }
2708 2742
2709 if ((oxcf->pass == 2) && 2743 if ((oxcf->pass == 2) &&
2710 (!cpi->use_svc || 2744 (!cpi->use_svc ||
2711 (is_two_pass_svc(cpi) && 2745 (is_two_pass_svc(cpi) &&
2712 cpi->svc.encode_empty_frame_state != ENCODING))) { 2746 cpi->svc.encode_empty_frame_state != ENCODING))) {
2713 vp9_set_target_rate(cpi); 2747 vp9_set_target_rate(cpi);
2714 } 2748 }
2715 2749
2716 // Reset the frame pointers to the current frame size. 2750 // Reset the frame pointers to the current frame size.
2717 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), 2751 vp9_realloc_frame_buffer(get_frame_new_buffer(cm),
2718 cm->width, cm->height, 2752 cm->width, cm->height,
2719 cm->subsampling_x, cm->subsampling_y, 2753 cm->subsampling_x, cm->subsampling_y,
2720 #if CONFIG_VP9_HIGHBITDEPTH 2754 #if CONFIG_VP9_HIGHBITDEPTH
2721 cm->use_highbitdepth, 2755 cm->use_highbitdepth,
2722 #endif 2756 #endif
2723 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, 2757 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
2724 NULL, NULL, NULL); 2758 NULL, NULL, NULL);
2725 2759
2726 alloc_util_frame_buffers(cpi); 2760 alloc_util_frame_buffers(cpi);
2727 init_motion_estimation(cpi); 2761 init_motion_estimation(cpi);
2728 2762
2729 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 2763 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
2730 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; 2764 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
2731 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf; 2765 YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[idx].buf;
2732 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; 2766 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1];
2733 ref_buf->buf = buf; 2767 ref_buf->buf = buf;
2734 ref_buf->idx = idx; 2768 ref_buf->idx = idx;
2735 #if CONFIG_VP9_HIGHBITDEPTH 2769 #if CONFIG_VP9_HIGHBITDEPTH
2736 vp9_setup_scale_factors_for_frame(&ref_buf->sf, 2770 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
2737 buf->y_crop_width, buf->y_crop_height, 2771 buf->y_crop_width, buf->y_crop_height,
2738 cm->width, cm->height, 2772 cm->width, cm->height,
2739 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 2773 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ?
2740 1 : 0); 2774 1 : 0);
2741 #else 2775 #else
2742 vp9_setup_scale_factors_for_frame(&ref_buf->sf, 2776 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
2743 buf->y_crop_width, buf->y_crop_height, 2777 buf->y_crop_width, buf->y_crop_height,
2744 cm->width, cm->height); 2778 cm->width, cm->height);
2745 #endif // CONFIG_VP9_HIGHBITDEPTH 2779 #endif // CONFIG_VP9_HIGHBITDEPTH
2746 if (vp9_is_scaled(&ref_buf->sf)) 2780 if (vp9_is_scaled(&ref_buf->sf))
2747 vp9_extend_frame_borders(buf); 2781 vp9_extend_frame_borders(buf);
2748 } 2782 }
2749 2783
2750 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); 2784 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
2751 } 2785 }
2752 2786
2753 static void encode_without_recode_loop(VP9_COMP *cpi) { 2787 static void encode_without_recode_loop(VP9_COMP *cpi) {
2754 VP9_COMMON *const cm = &cpi->common; 2788 VP9_COMMON *const cm = &cpi->common;
2755 int q, bottom_index, top_index; // Dummy variables. 2789 int q = 0, bottom_index = 0, top_index = 0; // Dummy variables.
2756 2790
2757 vp9_clear_system_state(); 2791 vp9_clear_system_state();
2758 2792
2759 set_frame_size(cpi); 2793 set_frame_size(cpi);
2760 2794
2761 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source, 2795 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source,
2762 &cpi->scaled_source); 2796 &cpi->scaled_source);
2763 2797
2764 if (cpi->unscaled_last_source != NULL) 2798 if (cpi->unscaled_last_source != NULL)
2765 cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source, 2799 cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source,
2766 &cpi->scaled_last_source); 2800 &cpi->scaled_last_source);
2767 2801
2768 if (frame_is_intra_only(cm) == 0) { 2802 if (frame_is_intra_only(cm) == 0) {
2769 vp9_scale_references(cpi); 2803 vp9_scale_references(cpi);
2770 } 2804 }
2771 2805
2772 set_size_independent_vars(cpi); 2806 set_size_independent_vars(cpi);
2773 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); 2807 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
2774 2808
2775 vp9_set_quantizer(cm, q); 2809 vp9_set_quantizer(cm, q);
2810 vp9_set_vbp_thresholds(cpi, q);
2811
2776 setup_frame(cpi); 2812 setup_frame(cpi);
2813
2777 // Variance adaptive and in frame q adjustment experiments are mutually 2814 // Variance adaptive and in frame q adjustment experiments are mutually
2778 // exclusive. 2815 // exclusive.
2779 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { 2816 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
2780 vp9_vaq_frame_setup(cpi); 2817 vp9_vaq_frame_setup(cpi);
2781 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { 2818 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
2782 vp9_setup_in_frame_q_adj(cpi); 2819 vp9_setup_in_frame_q_adj(cpi);
2783 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { 2820 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
2784 vp9_cyclic_refresh_setup(cpi); 2821 vp9_cyclic_refresh_setup(cpi);
2785 } 2822 }
2786 // transform / motion compensation build reconstruction frame 2823 // transform / motion compensation build reconstruction frame
2787 vp9_encode_frame(cpi); 2824 vp9_encode_frame(cpi);
2788 2825
2789 // Update the skip mb flag probabilities based on the distribution 2826 // Update the skip mb flag probabilities based on the distribution
2790 // seen in the last encoder iteration. 2827 // seen in the last encoder iteration.
2791 // update_base_skip_probs(cpi); 2828 // update_base_skip_probs(cpi);
2792 vp9_clear_system_state(); 2829 vp9_clear_system_state();
2793 } 2830 }
2794 2831
2795 static void encode_with_recode_loop(VP9_COMP *cpi, 2832 static void encode_with_recode_loop(VP9_COMP *cpi,
2796 size_t *size, 2833 size_t *size,
2797 uint8_t *dest) { 2834 uint8_t *dest) {
2798 VP9_COMMON *const cm = &cpi->common; 2835 VP9_COMMON *const cm = &cpi->common;
2799 RATE_CONTROL *const rc = &cpi->rc; 2836 RATE_CONTROL *const rc = &cpi->rc;
2800 int bottom_index, top_index; 2837 int bottom_index, top_index;
2801 int loop_count = 0; 2838 int loop_count = 0;
2839 int loop_at_this_size = 0;
2802 int loop = 0; 2840 int loop = 0;
2803 int overshoot_seen = 0; 2841 int overshoot_seen = 0;
2804 int undershoot_seen = 0; 2842 int undershoot_seen = 0;
2805 int frame_over_shoot_limit; 2843 int frame_over_shoot_limit;
2806 int frame_under_shoot_limit; 2844 int frame_under_shoot_limit;
2807 int q = 0, q_low = 0, q_high = 0; 2845 int q = 0, q_low = 0, q_high = 0;
2808 int frame_size_changed = 0;
2809 2846
2810 set_size_independent_vars(cpi); 2847 set_size_independent_vars(cpi);
2811 2848
2812 do { 2849 do {
2813 vp9_clear_system_state(); 2850 vp9_clear_system_state();
2814 2851
2815 set_frame_size(cpi); 2852 set_frame_size(cpi);
2816 2853
2817 if (loop_count == 0 || frame_size_changed != 0) { 2854 if (loop_count == 0 || cpi->resize_pending != 0) {
2818 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); 2855 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
2856
2857 // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed.
2858 set_mv_search_params(cpi);
2859
2860 // Reset the loop state for new frame size.
2861 overshoot_seen = 0;
2862 undershoot_seen = 0;
2863
2864 // Reconfiguration for change in frame size has concluded.
2865 cpi->resize_pending = 0;
2866
2819 q_low = bottom_index; 2867 q_low = bottom_index;
2820 q_high = top_index; 2868 q_high = top_index;
2821 2869
2822 // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. 2870 loop_at_this_size = 0;
2823 set_mv_search_params(cpi);
2824 } 2871 }
2825 2872
2826 // Decide frame size bounds 2873 // Decide frame size bounds first time through.
2827 vp9_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, 2874 if (loop_count == 0) {
2828 &frame_under_shoot_limit, 2875 vp9_rc_compute_frame_size_bounds(cpi, rc->this_frame_target,
2829 &frame_over_shoot_limit); 2876 &frame_under_shoot_limit,
2877 &frame_over_shoot_limit);
2878 }
2830 2879
2831 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source, 2880 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source,
2832 &cpi->scaled_source); 2881 &cpi->scaled_source);
2833 2882
2834 if (cpi->unscaled_last_source != NULL) 2883 if (cpi->unscaled_last_source != NULL)
2835 cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source, 2884 cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source,
2836 &cpi->scaled_last_source); 2885 &cpi->scaled_last_source);
2837 2886
2838 if (frame_is_intra_only(cm) == 0) { 2887 if (frame_is_intra_only(cm) == 0) {
2839 if (loop_count > 0) { 2888 if (loop_count > 0) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2932 2981
2933 loop = q != last_q; 2982 loop = q != last_q;
2934 } else if (recode_loop_test( 2983 } else if (recode_loop_test(
2935 cpi, frame_over_shoot_limit, frame_under_shoot_limit, 2984 cpi, frame_over_shoot_limit, frame_under_shoot_limit,
2936 q, MAX(q_high, top_index), bottom_index)) { 2985 q, MAX(q_high, top_index), bottom_index)) {
2937 // Is the projected frame size out of range and are we allowed 2986 // Is the projected frame size out of range and are we allowed
2938 // to attempt to recode. 2987 // to attempt to recode.
2939 int last_q = q; 2988 int last_q = q;
2940 int retries = 0; 2989 int retries = 0;
2941 2990
2991 if (cpi->resize_pending == 1) {
2992 // Change in frame size so go back around the recode loop.
2993 cpi->rc.frame_size_selector =
2994 SCALE_STEP1 - cpi->rc.frame_size_selector;
2995 cpi->rc.next_frame_size_selector = cpi->rc.frame_size_selector;
2996
2997 #if CONFIG_INTERNAL_STATS
2998 ++cpi->tot_recode_hits;
2999 #endif
3000 ++loop_count;
3001 loop = 1;
3002 continue;
3003 }
3004
2942 // Frame size out of permitted range: 3005 // Frame size out of permitted range:
2943 // Update correction factor & compute new Q to try... 3006 // Update correction factor & compute new Q to try...
2944 3007
2945 // Frame is too large 3008 // Frame is too large
2946 if (rc->projected_frame_size > rc->this_frame_target) { 3009 if (rc->projected_frame_size > rc->this_frame_target) {
2947 // Special case if the projected size is > the max allowed. 3010 // Special case if the projected size is > the max allowed.
2948 if (rc->projected_frame_size >= rc->max_frame_bandwidth) 3011 if (rc->projected_frame_size >= rc->max_frame_bandwidth)
2949 q_high = rc->worst_quality; 3012 q_high = rc->worst_quality;
2950 3013
2951 // Raise Qlow as to at least the current value 3014 // Raise Qlow as to at least the current value
2952 q_low = q < q_high ? q + 1 : q_high; 3015 q_low = q < q_high ? q + 1 : q_high;
2953 3016
2954 if (undershoot_seen || loop_count > 1) { 3017 if (undershoot_seen || loop_at_this_size > 1) {
2955 // Update rate_correction_factor unless 3018 // Update rate_correction_factor unless
2956 vp9_rc_update_rate_correction_factors(cpi, 1); 3019 vp9_rc_update_rate_correction_factors(cpi);
2957 3020
2958 q = (q_high + q_low + 1) / 2; 3021 q = (q_high + q_low + 1) / 2;
2959 } else { 3022 } else {
2960 // Update rate_correction_factor unless 3023 // Update rate_correction_factor unless
2961 vp9_rc_update_rate_correction_factors(cpi, 0); 3024 vp9_rc_update_rate_correction_factors(cpi);
2962 3025
2963 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, 3026 q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
2964 bottom_index, MAX(q_high, top_index)); 3027 bottom_index, MAX(q_high, top_index));
2965 3028
2966 while (q < q_low && retries < 10) { 3029 while (q < q_low && retries < 10) {
2967 vp9_rc_update_rate_correction_factors(cpi, 0); 3030 vp9_rc_update_rate_correction_factors(cpi);
2968 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, 3031 q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
2969 bottom_index, MAX(q_high, top_index)); 3032 bottom_index, MAX(q_high, top_index));
2970 retries++; 3033 retries++;
2971 } 3034 }
2972 } 3035 }
2973 3036
2974 overshoot_seen = 1; 3037 overshoot_seen = 1;
2975 } else { 3038 } else {
2976 // Frame is too small 3039 // Frame is too small
2977 q_high = q > q_low ? q - 1 : q_low; 3040 q_high = q > q_low ? q - 1 : q_low;
2978 3041
2979 if (overshoot_seen || loop_count > 1) { 3042 if (overshoot_seen || loop_at_this_size > 1) {
2980 vp9_rc_update_rate_correction_factors(cpi, 1); 3043 vp9_rc_update_rate_correction_factors(cpi);
2981 q = (q_high + q_low) / 2; 3044 q = (q_high + q_low) / 2;
2982 } else { 3045 } else {
2983 vp9_rc_update_rate_correction_factors(cpi, 0); 3046 vp9_rc_update_rate_correction_factors(cpi);
2984 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, 3047 q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
2985 bottom_index, top_index); 3048 bottom_index, top_index);
2986 // Special case reset for qlow for constrained quality. 3049 // Special case reset for qlow for constrained quality.
2987 // This should only trigger where there is very substantial 3050 // This should only trigger where there is very substantial
2988 // undershoot on a frame and the auto cq level is above 3051 // undershoot on a frame and the auto cq level is above
2989 // the user passsed in value. 3052 // the user passsed in value.
2990 if (cpi->oxcf.rc_mode == VPX_CQ && 3053 if (cpi->oxcf.rc_mode == VPX_CQ &&
2991 q < q_low) { 3054 q < q_low) {
2992 q_low = q; 3055 q_low = q;
2993 } 3056 }
2994 3057
2995 while (q > q_high && retries < 10) { 3058 while (q > q_high && retries < 10) {
2996 vp9_rc_update_rate_correction_factors(cpi, 0); 3059 vp9_rc_update_rate_correction_factors(cpi);
2997 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, 3060 q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
2998 bottom_index, top_index); 3061 bottom_index, top_index);
2999 retries++; 3062 retries++;
3000 } 3063 }
3001 } 3064 }
3002 3065
3003 undershoot_seen = 1; 3066 undershoot_seen = 1;
3004 } 3067 }
3005 3068
3006 // Clamp Q to upper and lower limits: 3069 // Clamp Q to upper and lower limits:
3007 q = clamp(q, q_low, q_high); 3070 q = clamp(q, q_low, q_high);
3008 3071
3009 loop = q != last_q; 3072 loop = (q != last_q);
3010 } else { 3073 } else {
3011 loop = 0; 3074 loop = 0;
3012 } 3075 }
3013 } 3076 }
3014 3077
3015 // Special case for overlay frame. 3078 // Special case for overlay frame.
3016 if (rc->is_src_frame_alt_ref && 3079 if (rc->is_src_frame_alt_ref &&
3017 rc->projected_frame_size < rc->max_frame_bandwidth) 3080 rc->projected_frame_size < rc->max_frame_bandwidth)
3018 loop = 0; 3081 loop = 0;
3019 3082
3020 if (loop) { 3083 if (loop) {
3021 loop_count++; 3084 ++loop_count;
3085 ++loop_at_this_size;
3022 3086
3023 #if CONFIG_INTERNAL_STATS 3087 #if CONFIG_INTERNAL_STATS
3024 cpi->tot_recode_hits++; 3088 ++cpi->tot_recode_hits;
3025 #endif 3089 #endif
3026 } 3090 }
3027 } while (loop); 3091 } while (loop);
3028 } 3092 }
3029 3093
3030 static int get_ref_frame_flags(const VP9_COMP *cpi) { 3094 static int get_ref_frame_flags(const VP9_COMP *cpi) {
3031 const int *const map = cpi->common.ref_frame_map; 3095 const int *const map = cpi->common.ref_frame_map;
3032 const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; 3096 const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx];
3033 const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; 3097 const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx];
3034 const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; 3098 const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx];
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3235 } 3299 }
3236 3300
3237 #if CONFIG_VP9_TEMPORAL_DENOISING 3301 #if CONFIG_VP9_TEMPORAL_DENOISING
3238 #ifdef OUTPUT_YUV_DENOISED 3302 #ifdef OUTPUT_YUV_DENOISED
3239 if (oxcf->noise_sensitivity > 0) { 3303 if (oxcf->noise_sensitivity > 0) {
3240 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME], 3304 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME],
3241 yuv_denoised_file); 3305 yuv_denoised_file);
3242 } 3306 }
3243 #endif 3307 #endif
3244 #endif 3308 #endif
3245 3309 #ifdef OUTPUT_YUV_SKINMAP
3310 if (cpi->common.current_video_frame > 1) {
3311 vp9_compute_skin_map(cpi, yuv_skinmap_file);
3312 }
3313 #endif
3246 3314
3247 // Special case code to reduce pulsing when key frames are forced at a 3315 // Special case code to reduce pulsing when key frames are forced at a
3248 // fixed interval. Note the reconstruction error if it is the frame before 3316 // fixed interval. Note the reconstruction error if it is the frame before
3249 // the force key frame 3317 // the force key frame
3250 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { 3318 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) {
3251 #if CONFIG_VP9_HIGHBITDEPTH 3319 #if CONFIG_VP9_HIGHBITDEPTH
3252 if (cm->use_highbitdepth) { 3320 if (cm->use_highbitdepth) {
3253 cpi->ambient_err = vp9_highbd_get_y_sse(cpi->Source, 3321 cpi->ambient_err = vp9_highbd_get_y_sse(cpi->Source,
3254 get_frame_new_buffer(cm)); 3322 get_frame_new_buffer(cm));
3255 } else { 3323 } else {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
3430 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); 3498 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y);
3431 #else 3499 #else
3432 check_initial_width(cpi, subsampling_x, subsampling_y); 3500 check_initial_width(cpi, subsampling_x, subsampling_y);
3433 #endif // CONFIG_VP9_HIGHBITDEPTH 3501 #endif // CONFIG_VP9_HIGHBITDEPTH
3434 3502
3435 #if CONFIG_VP9_TEMPORAL_DENOISING 3503 #if CONFIG_VP9_TEMPORAL_DENOISING
3436 setup_denoiser_buffer(cpi); 3504 setup_denoiser_buffer(cpi);
3437 #endif 3505 #endif
3438 vpx_usec_timer_start(&timer); 3506 vpx_usec_timer_start(&timer);
3439 3507
3440 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags)) 3508 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time,
3509 #if CONFIG_VP9_HIGHBITDEPTH
3510 use_highbitdepth,
3511 #endif // CONFIG_VP9_HIGHBITDEPTH
3512 frame_flags))
3441 res = -1; 3513 res = -1;
3442 vpx_usec_timer_mark(&timer); 3514 vpx_usec_timer_mark(&timer);
3443 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); 3515 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
3444 3516
3445 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && 3517 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) &&
3446 (subsampling_x != 1 || subsampling_y != 1)) { 3518 (subsampling_x != 1 || subsampling_y != 1)) {
3447 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, 3519 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM,
3448 "Non-4:2:0 color format requires profile 1 or 3"); 3520 "Non-4:2:0 color format requires profile 1 or 3");
3449 res = -1; 3521 res = -1;
3450 } 3522 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3550 // become the GF so preserve last as an alternative prediction option. 3622 // become the GF so preserve last as an alternative prediction option.
3551 cpi->refresh_last_frame = 0; 3623 cpi->refresh_last_frame = 0;
3552 } 3624 }
3553 } 3625 }
3554 3626
3555 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, 3627 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
3556 size_t *size, uint8_t *dest, 3628 size_t *size, uint8_t *dest,
3557 int64_t *time_stamp, int64_t *time_end, int flush) { 3629 int64_t *time_stamp, int64_t *time_end, int flush) {
3558 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 3630 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
3559 VP9_COMMON *const cm = &cpi->common; 3631 VP9_COMMON *const cm = &cpi->common;
3632 BufferPool *const pool = cm->buffer_pool;
3560 RATE_CONTROL *const rc = &cpi->rc; 3633 RATE_CONTROL *const rc = &cpi->rc;
3561 struct vpx_usec_timer cmptimer; 3634 struct vpx_usec_timer cmptimer;
3562 YV12_BUFFER_CONFIG *force_src_buffer = NULL; 3635 YV12_BUFFER_CONFIG *force_src_buffer = NULL;
3563 struct lookahead_entry *last_source = NULL; 3636 struct lookahead_entry *last_source = NULL;
3564 struct lookahead_entry *source = NULL; 3637 struct lookahead_entry *source = NULL;
3565 int arf_src_index; 3638 int arf_src_index;
3566 int i; 3639 int i;
3567 3640
3568 if (is_two_pass_svc(cpi)) { 3641 if (is_two_pass_svc(cpi)) {
3569 #if CONFIG_SPATIAL_SVC 3642 #if CONFIG_SPATIAL_SVC
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3704 } 3777 }
3705 3778
3706 if (cpi->svc.number_temporal_layers > 1 && 3779 if (cpi->svc.number_temporal_layers > 1 &&
3707 oxcf->rc_mode == VPX_CBR) { 3780 oxcf->rc_mode == VPX_CBR) {
3708 vp9_update_temporal_layer_framerate(cpi); 3781 vp9_update_temporal_layer_framerate(cpi);
3709 vp9_restore_layer_context(cpi); 3782 vp9_restore_layer_context(cpi);
3710 } 3783 }
3711 3784
3712 // Find a free buffer for the new frame, releasing the reference previously 3785 // Find a free buffer for the new frame, releasing the reference previously
3713 // held. 3786 // held.
3714 cm->frame_bufs[cm->new_fb_idx].ref_count--; 3787 pool->frame_bufs[cm->new_fb_idx].ref_count--;
3715 cm->new_fb_idx = get_free_fb(cm); 3788 cm->new_fb_idx = get_free_fb(cm);
3716 cm->cur_frame = &cm->frame_bufs[cm->new_fb_idx]; 3789 cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
3717 3790
3718 if (!cpi->use_svc && cpi->multi_arf_allowed) { 3791 if (!cpi->use_svc && cpi->multi_arf_allowed) {
3719 if (cm->frame_type == KEY_FRAME) { 3792 if (cm->frame_type == KEY_FRAME) {
3720 init_buffer_indices(cpi); 3793 init_buffer_indices(cpi);
3721 } else if (oxcf->pass == 2) { 3794 } else if (oxcf->pass == 2) {
3722 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; 3795 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
3723 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; 3796 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index];
3724 } 3797 }
3725 } 3798 }
3726 3799
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
4098 if (flags & VP8_EFLAG_NO_UPD_ARF) 4171 if (flags & VP8_EFLAG_NO_UPD_ARF)
4099 upd ^= VP9_ALT_FLAG; 4172 upd ^= VP9_ALT_FLAG;
4100 4173
4101 vp9_update_reference(cpi, upd); 4174 vp9_update_reference(cpi, upd);
4102 } 4175 }
4103 4176
4104 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { 4177 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) {
4105 vp9_update_entropy(cpi, 0); 4178 vp9_update_entropy(cpi, 0);
4106 } 4179 }
4107 } 4180 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_ethread.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698