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

Side by Side Diff: source/libvpx/vp8/encoder/onyx_if.c

Issue 756673003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years 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 | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp8/encoder/ethreading.c ('k') | source/libvpx/vp8/encoder/quantize.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
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 /* No fast FDCT defined for any platform at this time. */ 1076 /* No fast FDCT defined for any platform at this time. */
1077 cpi->mb.short_fdct8x4 = vp8_short_fdct8x4; 1077 cpi->mb.short_fdct8x4 = vp8_short_fdct8x4;
1078 cpi->mb.short_fdct4x4 = vp8_short_fdct4x4; 1078 cpi->mb.short_fdct4x4 = vp8_short_fdct4x4;
1079 } 1079 }
1080 1080
1081 cpi->mb.short_walsh4x4 = vp8_short_walsh4x4; 1081 cpi->mb.short_walsh4x4 = vp8_short_walsh4x4;
1082 1082
1083 if (cpi->sf.improved_quant) 1083 if (cpi->sf.improved_quant)
1084 { 1084 {
1085 cpi->mb.quantize_b = vp8_regular_quantize_b; 1085 cpi->mb.quantize_b = vp8_regular_quantize_b;
1086 cpi->mb.quantize_b_pair = vp8_regular_quantize_b_pair;
1087 } 1086 }
1088 else 1087 else
1089 { 1088 {
1090 cpi->mb.quantize_b = vp8_fast_quantize_b; 1089 cpi->mb.quantize_b = vp8_fast_quantize_b;
1091 cpi->mb.quantize_b_pair = vp8_fast_quantize_b_pair;
1092 } 1090 }
1093 if (cpi->sf.improved_quant != last_improved_quant) 1091 if (cpi->sf.improved_quant != last_improved_quant)
1094 vp8cx_init_quantizer(cpi); 1092 vp8cx_init_quantizer(cpi);
1095 1093
1096 if (cpi->sf.iterative_sub_pixel == 1) 1094 if (cpi->sf.iterative_sub_pixel == 1)
1097 { 1095 {
1098 cpi->find_fractional_mv_step = vp8_find_best_sub_pixel_step_iteratively; 1096 cpi->find_fractional_mv_step = vp8_find_best_sub_pixel_step_iteratively;
1099 } 1097 }
1100 else if (cpi->sf.quarter_pixel_search) 1098 else if (cpi->sf.quarter_pixel_search)
1101 { 1099 {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 VP8_COMMON *cm = &cpi->common; 1354 VP8_COMMON *cm = &cpi->common;
1357 1355
1358 cpi->oxcf = *oxcf; 1356 cpi->oxcf = *oxcf;
1359 1357
1360 cpi->auto_gold = 1; 1358 cpi->auto_gold = 1;
1361 cpi->auto_adjust_gold_quantizer = 1; 1359 cpi->auto_adjust_gold_quantizer = 1;
1362 1360
1363 cm->version = oxcf->Version; 1361 cm->version = oxcf->Version;
1364 vp8_setup_version(cm); 1362 vp8_setup_version(cm);
1365 1363
1366 /* frame rate is not available on the first frame, as it's derived from 1364 /* Frame rate is not available on the first frame, as it's derived from
1367 * the observed timestamps. The actual value used here doesn't matter 1365 * the observed timestamps. The actual value used here doesn't matter
1368 * too much, as it will adapt quickly. If the reciprocal of the timebase 1366 * too much, as it will adapt quickly.
1369 * seems like a reasonable framerate, then use that as a guess, otherwise
1370 * use 30.
1371 */ 1367 */
1372 cpi->framerate = (double)(oxcf->timebase.den) / 1368 if (oxcf->timebase.num > 0) {
1373 (double)(oxcf->timebase.num); 1369 cpi->framerate = (double)(oxcf->timebase.den) /
1370 (double)(oxcf->timebase.num);
1371 } else {
1372 cpi->framerate = 30;
1373 }
1374 1374
1375 /* If the reciprocal of the timebase seems like a reasonable framerate,
1376 * then use that as a guess, otherwise use 30.
1377 */
1375 if (cpi->framerate > 180) 1378 if (cpi->framerate > 180)
1376 cpi->framerate = 30; 1379 cpi->framerate = 30;
1377 1380
1378 cpi->ref_framerate = cpi->framerate; 1381 cpi->ref_framerate = cpi->framerate;
1379 1382
1380 /* change includes all joint functionality */ 1383 /* change includes all joint functionality */
1381 vp8_change_config(cpi, oxcf); 1384 vp8_change_config(cpi, oxcf);
1382 1385
1383 /* Initialize active best and worst q and average q values. */ 1386 /* Initialize active best and worst q and average q values. */
1384 cpi->active_worst_quality = cpi->oxcf.worst_allowed_q; 1387 cpi->active_worst_quality = cpi->oxcf.worst_allowed_q;
(...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after
3298 const VP8_COMMON *const cm = &cpi->common; 3301 const VP8_COMMON *const cm = &cpi->common;
3299 int i, j; 3302 int i, j;
3300 int total = 0; 3303 int total = 0;
3301 int num_blocks = 0; 3304 int num_blocks = 0;
3302 // Number of blocks skipped along row/column in computing the 3305 // Number of blocks skipped along row/column in computing the
3303 // nmse (normalized mean square error) of source. 3306 // nmse (normalized mean square error) of source.
3304 int skip = 2; 3307 int skip = 2;
3305 // Only select blocks for computing nmse that have been encoded 3308 // Only select blocks for computing nmse that have been encoded
3306 // as ZERO LAST min_consec_zero_last frames in a row. 3309 // as ZERO LAST min_consec_zero_last frames in a row.
3307 // Scale with number of temporal layers. 3310 // Scale with number of temporal layers.
3308 int min_consec_zero_last = 8 / cpi->oxcf.number_of_layers; 3311 int min_consec_zero_last = 12 / cpi->oxcf.number_of_layers;
3309 // Decision is tested for changing the denoising mode every 3312 // Decision is tested for changing the denoising mode every
3310 // num_mode_change times this function is called. Note that this 3313 // num_mode_change times this function is called. Note that this
3311 // function called every 8 frames, so (8 * num_mode_change) is number 3314 // function called every 8 frames, so (8 * num_mode_change) is number
3312 // of frames where denoising mode change is tested for switch. 3315 // of frames where denoising mode change is tested for switch.
3313 int num_mode_change = 15; 3316 int num_mode_change = 20;
3314 // Framerate factor, to compensate for larger mse at lower framerates. 3317 // Framerate factor, to compensate for larger mse at lower framerates.
3315 // Use ref_framerate, which is full source framerate for temporal layers. 3318 // Use ref_framerate, which is full source framerate for temporal layers.
3316 // TODO(marpan): Adjust this factor. 3319 // TODO(marpan): Adjust this factor.
3317 int fac_framerate = cpi->ref_framerate < 25.0f ? 80 : 100; 3320 int fac_framerate = cpi->ref_framerate < 25.0f ? 80 : 100;
3318 int tot_num_blocks = cm->mb_rows * cm->mb_cols; 3321 int tot_num_blocks = cm->mb_rows * cm->mb_cols;
3319 int ystride = cpi->Source->y_stride; 3322 int ystride = cpi->Source->y_stride;
3320 unsigned char *src = cpi->Source->y_buffer; 3323 unsigned char *src = cpi->Source->y_buffer;
3321 unsigned char *dst = cpi->denoiser.yv12_last_source.y_buffer; 3324 unsigned char *dst = cpi->denoiser.yv12_last_source.y_buffer;
3322 static const unsigned char const_source[16] = { 3325 static const unsigned char const_source[16] = {
3323 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 3326 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
3324 128, 128, 128}; 3327 128, 128, 128};
3325 3328 int bandwidth = (int)(cpi->target_bandwidth);
3329 // For temporal layers, use full bandwidth (top layer).
3330 if (cpi->oxcf.number_of_layers > 1) {
3331 LAYER_CONTEXT *lc = &cpi->layer_context[cpi->oxcf.number_of_layers - 1];
3332 bandwidth = (int)(lc->target_bandwidth);
3333 }
3326 // Loop through the Y plane, every skip blocks along rows and columns, 3334 // Loop through the Y plane, every skip blocks along rows and columns,
3327 // summing the normalized mean square error, only for blocks that have 3335 // summing the normalized mean square error, only for blocks that have
3328 // been encoded as ZEROMV LAST at least min_consec_zero_last least frames in 3336 // been encoded as ZEROMV LAST at least min_consec_zero_last least frames in
3329 // a row and have small sum difference between current and previous frame. 3337 // a row and have small sum difference between current and previous frame.
3330 // Normalization here is by the contrast of the current frame block. 3338 // Normalization here is by the contrast of the current frame block.
3331 for (i = 0; i < cm->Height; i += 16 * skip) { 3339 for (i = 0; i < cm->Height; i += 16 * skip) {
3332 int block_index_row = (i >> 4) * cm->mb_cols; 3340 int block_index_row = (i >> 4) * cm->mb_cols;
3333 for (j = 0; j < cm->Width; j += 16 * skip) { 3341 for (j = 0; j < cm->Width; j += 16 * skip) {
3334 int index = block_index_row + (j >> 4); 3342 int index = block_index_row + (j >> 4);
3335 if (cpi->consec_zero_last[index] >= min_consec_zero_last) { 3343 if (cpi->consec_zero_last[index] >= min_consec_zero_last) {
3336 unsigned int sse; 3344 unsigned int sse;
3337 const unsigned int mse = vp8_mse16x16(src + j,
3338 ystride,
3339 dst + j,
3340 ystride,
3341 &sse);
3342 const unsigned int var = vp8_variance16x16(src + j, 3345 const unsigned int var = vp8_variance16x16(src + j,
3343 ystride, 3346 ystride,
3344 dst + j, 3347 dst + j,
3345 ystride, 3348 ystride,
3346 &sse); 3349 &sse);
3347 // Only consider this block as valid for noise measurement 3350 // Only consider this block as valid for noise measurement
3348 // if the sum_diff average of the current and previous frame 3351 // if the sum_diff average of the current and previous frame
3349 // is small (to avoid effects from lighting change). 3352 // is small (to avoid effects from lighting change).
3350 if ((mse - var) < 256) { 3353 if ((sse - var) < 256) {
3354 unsigned int sse2;
3351 const unsigned int act = vp8_variance16x16(src + j, 3355 const unsigned int act = vp8_variance16x16(src + j,
3352 ystride, 3356 ystride,
3353 const_source, 3357 const_source,
3354 0, 3358 0,
3355 &sse); 3359 &sse2);
3356 if (act > 0) 3360 if (act > 0)
3357 total += mse / act; 3361 total += sse / act;
3358 num_blocks++; 3362 num_blocks++;
3359 } 3363 }
3360 } 3364 }
3361 } 3365 }
3362 src += 16 * skip * ystride; 3366 src += 16 * skip * ystride;
3363 dst += 16 * skip * ystride; 3367 dst += 16 * skip * ystride;
3364 } 3368 }
3365 total = total * fac_framerate / 100; 3369 total = total * fac_framerate / 100;
3366 3370
3367 // Only consider this frame as valid sample if we have computed nmse over 3371 // Only consider this frame as valid sample if we have computed nmse over
3368 // at least ~1/16 blocks, and Total > 0 (Total == 0 can happen if the 3372 // at least ~1/16 blocks, and Total > 0 (Total == 0 can happen if the
3369 // application inputs duplicate frames, or contrast is all zero). 3373 // application inputs duplicate frames, or contrast is all zero).
3370 if (total > 0 && 3374 if (total > 0 &&
3371 (num_blocks > (tot_num_blocks >> 4))) { 3375 (num_blocks > (tot_num_blocks >> 4))) {
3372 // Update the recursive mean square source_diff. 3376 // Update the recursive mean square source_diff.
3377 total = (total << 8) / num_blocks;
3373 if (cpi->denoiser.nmse_source_diff_count == 0) { 3378 if (cpi->denoiser.nmse_source_diff_count == 0) {
3374 // First sample in new interval. 3379 // First sample in new interval.
3375 cpi->denoiser.nmse_source_diff = total; 3380 cpi->denoiser.nmse_source_diff = total;
3376 cpi->denoiser.qp_avg = cm->base_qindex; 3381 cpi->denoiser.qp_avg = cm->base_qindex;
3377 } else { 3382 } else {
3378 // For subsequent samples, use average with weight ~1/4 for new sample. 3383 // For subsequent samples, use average with weight ~1/4 for new sample.
3379 cpi->denoiser.nmse_source_diff = (int)((total >> 2) + 3384 cpi->denoiser.nmse_source_diff = (int)((total +
3380 3 * (cpi->denoiser.nmse_source_diff >> 2)); 3385 3 * cpi->denoiser.nmse_source_diff) >> 2);
3381 cpi->denoiser.qp_avg = (int)((cm->base_qindex >> 2) + 3386 cpi->denoiser.qp_avg = (int)((cm->base_qindex +
3382 3 * (cpi->denoiser.qp_avg >> 2)); 3387 3 * cpi->denoiser.qp_avg) >> 2);
3383 } 3388 }
3384 cpi->denoiser.nmse_source_diff_count++; 3389 cpi->denoiser.nmse_source_diff_count++;
3385 } 3390 }
3386 // Check for changing the denoiser mode, when we have obtained #samples = 3391 // Check for changing the denoiser mode, when we have obtained #samples =
3387 // num_mode_change. Condition the change also on the bitrate and QP. 3392 // num_mode_change. Condition the change also on the bitrate and QP.
3388 if (cpi->denoiser.nmse_source_diff_count == num_mode_change) { 3393 if (cpi->denoiser.nmse_source_diff_count == num_mode_change) {
3389 // Check for going up: from normal to aggressive mode. 3394 // Check for going up: from normal to aggressive mode.
3390 if ((cpi->denoiser.denoiser_mode == kDenoiserOnYUV) && 3395 if ((cpi->denoiser.denoiser_mode == kDenoiserOnYUV) &&
3391 (cpi->denoiser.nmse_source_diff > 3396 (cpi->denoiser.nmse_source_diff >
3392 cpi->denoiser.threshold_aggressive_mode) && 3397 cpi->denoiser.threshold_aggressive_mode) &&
3393 (cpi->denoiser.qp_avg < cpi->denoiser.qp_threshold_up && 3398 (cpi->denoiser.qp_avg < cpi->denoiser.qp_threshold_up &&
3394 cpi->target_bandwidth > cpi->denoiser.bitrate_threshold)) { 3399 bandwidth > cpi->denoiser.bitrate_threshold)) {
3395 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUVAggressive); 3400 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUVAggressive);
3396 } else { 3401 } else {
3397 // Check for going down: from aggressive to normal mode. 3402 // Check for going down: from aggressive to normal mode.
3398 if (((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) && 3403 if (((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) &&
3399 (cpi->denoiser.nmse_source_diff < 3404 (cpi->denoiser.nmse_source_diff <
3400 cpi->denoiser.threshold_aggressive_mode)) || 3405 cpi->denoiser.threshold_aggressive_mode)) ||
3401 ((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) && 3406 ((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) &&
3402 (cpi->denoiser.qp_avg > cpi->denoiser.qp_threshold_down || 3407 (cpi->denoiser.qp_avg > cpi->denoiser.qp_threshold_down ||
3403 cpi->target_bandwidth < cpi->denoiser.bitrate_threshold))) { 3408 bandwidth < cpi->denoiser.bitrate_threshold))) {
3404 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV); 3409 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV);
3405 } 3410 }
3406 } 3411 }
3407 // Reset metric and counter for next interval. 3412 // Reset metric and counter for next interval.
3408 cpi->denoiser.nmse_source_diff = 0; 3413 cpi->denoiser.nmse_source_diff = 0;
3409 cpi->denoiser.qp_avg = 0; 3414 cpi->denoiser.qp_avg = 0;
3410 cpi->denoiser.nmse_source_diff_count = 0; 3415 cpi->denoiser.nmse_source_diff_count = 0;
3411 } 3416 }
3412 } 3417 }
3413 #endif 3418 #endif
(...skipping 2339 matching lines...) Expand 10 before | Expand all | Expand 10 after
5753 } 5758 }
5754 5759
5755 return Total; 5760 return Total;
5756 } 5761 }
5757 5762
5758 5763
5759 int vp8_get_quantizer(VP8_COMP *cpi) 5764 int vp8_get_quantizer(VP8_COMP *cpi)
5760 { 5765 {
5761 return cpi->common.base_qindex; 5766 return cpi->common.base_qindex;
5762 } 5767 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/encoder/ethreading.c ('k') | source/libvpx/vp8/encoder/quantize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698