An error occurred while loading the file. Please try again.
-
Jim Bankoski authored
This introduces base functions for introducing implicit segmentation. The code that actually stores the results to the segment map isn't here yet. This just prints out the segmentation map results if you call it. Uses connected component labeling technique on mbmi info so that only if 2 mbs are horizontally or vertically touching do they get the same segment. vp8next - plumbing for rotation code to produce taps for rotation ( tapify. py ), code for predicting using rotation ( predict_rotated.c ) , code for finding the best rotation find_rotation.c. didn't checkin code that uses this in the codec. still work in progress. Fixed copyright notice Change-Id: I450c13cfa41ab2fcb699f3897760370b4935fdf8
91325b8f
firstpass.c 86.28 KiB
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "math.h"
#include "limits.h"
#include "block.h"
#include "onyx_int.h"
#include "variance.h"
#include "encodeintra.h"
#include "vp8/common/setupintrarecon.h"
#include "mcomp.h"
#include "firstpass.h"
#include "vpx_scale/vpxscale.h"
#include "encodemb.h"
#include "vp8/common/extend.h"
#include "vp8/common/systemdependent.h"
#include "vpx_scale/yv12extend.h"
#include "vpx_mem/vpx_mem.h"
#include "vp8/common/swapyv12buffer.h"
#include <stdio.h>
#include "rdopt.h"
#include "ratectrl.h"
#include "vp8/common/quant_common.h"
#include "vp8/common/entropymv.h"
#include "encodemv.h"
#define OUTPUT_FPF 0
#if CONFIG_RUNTIME_CPU_DETECT
#define IF_RTCD(x) (x)
#else
#define IF_RTCD(x) NULL
#endif
extern void vp8_build_block_offsets(MACROBLOCK *x);
extern void vp8_setup_block_ptrs(MACROBLOCK *x);
extern void vp8cx_frame_init_quantizer(VP8_COMP *cpi);
extern void vp8_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv);
extern void vp8_alloc_compressor_data(VP8_COMP *cpi);
#define IIFACTOR 12.5
#define IIKFACTOR1 12.5
#define IIKFACTOR2 15.0
#define RMAX 128.0
#define GF_RMAX 96.0
#define ERR_DIVISOR 150.0
#define KF_MB_INTRA_MIN 300
#define GF_MB_INTRA_MIN 200
#define DOUBLE_DIVIDE_CHECK(X) ((X)<0?(X)-.000001:(X)+.000001)
#define POW1 (double)cpi->oxcf.two_pass_vbrbias/100.0
#define POW2 (double)cpi->oxcf.two_pass_vbrbias/100.0
static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame);
static int select_cq_level(int qindex) {
int ret_val = QINDEX_RANGE - 1;
int i;
double target_q = (vp8_convert_qindex_to_q(qindex) * 0.5847) + 1.0;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
for (i = 0; i < QINDEX_RANGE; i++) {
if (target_q <= vp8_convert_qindex_to_q(i)) {
ret_val = i;
break;
}
}
return ret_val;
}
// Resets the first pass file to the given position using a relative seek from the current position
static void reset_fpf_position(VP8_COMP *cpi, FIRSTPASS_STATS *Position) {
cpi->twopass.stats_in = Position;
}
static int lookup_next_frame_stats(VP8_COMP *cpi, FIRSTPASS_STATS *next_frame) {
if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end)
return EOF;
*next_frame = *cpi->twopass.stats_in;
return 1;
}
// Read frame stats at an offset from the current position
static int read_frame_stats(VP8_COMP *cpi,
FIRSTPASS_STATS *frame_stats,
int offset) {
FIRSTPASS_STATS *fps_ptr = cpi->twopass.stats_in;
// Check legality of offset
if (offset >= 0) {
if (&fps_ptr[offset] >= cpi->twopass.stats_in_end)
return EOF;
} else if (offset < 0) {
if (&fps_ptr[offset] < cpi->twopass.stats_in_start)
return EOF;
}
*frame_stats = fps_ptr[offset];
return 1;
}
static int input_stats(VP8_COMP *cpi, FIRSTPASS_STATS *fps) {
if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end)
return EOF;
*fps = *cpi->twopass.stats_in;
cpi->twopass.stats_in =
(void *)((char *)cpi->twopass.stats_in + sizeof(FIRSTPASS_STATS));
return 1;
}
static void output_stats(const VP8_COMP *cpi,
struct vpx_codec_pkt_list *pktlist,
FIRSTPASS_STATS *stats) {
struct vpx_codec_cx_pkt pkt;
pkt.kind = VPX_CODEC_STATS_PKT;
pkt.data.twopass_stats.buf = stats;
pkt.data.twopass_stats.sz = sizeof(FIRSTPASS_STATS);
vpx_codec_pkt_list_add(pktlist, &pkt);
// TEMP debug code
#if OUTPUT_FPF
{
FILE *fpfile;
fpfile = fopen("firstpass.stt", "a");
fprintf(fpfile, "%12.0f %12.0f %12.0f %12.0f %12.0f %12.4f %12.4f"
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
"%12.4f %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f"
"%12.0f %12.0f %12.4f %12.0f %12.0f %12.4f\n",
stats->frame,
stats->intra_error,
stats->coded_error,
stats->sr_coded_error,
stats->ssim_weighted_pred_err,
stats->pcnt_inter,
stats->pcnt_motion,
stats->pcnt_second_ref,
stats->pcnt_neutral,
stats->MVr,
stats->mvr_abs,
stats->MVc,
stats->mvc_abs,
stats->MVrv,
stats->MVcv,
stats->mv_in_out_count,
stats->new_mv_count,
stats->count,
stats->duration);
fclose(fpfile);
}
#endif
}
static void zero_stats(FIRSTPASS_STATS *section) {
section->frame = 0.0;
section->intra_error = 0.0;
section->coded_error = 0.0;
section->sr_coded_error = 0.0;
section->ssim_weighted_pred_err = 0.0;
section->pcnt_inter = 0.0;
section->pcnt_motion = 0.0;
section->pcnt_second_ref = 0.0;
section->pcnt_neutral = 0.0;
section->MVr = 0.0;
section->mvr_abs = 0.0;
section->MVc = 0.0;
section->mvc_abs = 0.0;
section->MVrv = 0.0;
section->MVcv = 0.0;
section->mv_in_out_count = 0.0;
section->new_mv_count = 0.0;
section->count = 0.0;
section->duration = 1.0;
}
static void accumulate_stats(FIRSTPASS_STATS *section, FIRSTPASS_STATS *frame) {
section->frame += frame->frame;
section->intra_error += frame->intra_error;
section->coded_error += frame->coded_error;
section->sr_coded_error += frame->sr_coded_error;
section->ssim_weighted_pred_err += frame->ssim_weighted_pred_err;
section->pcnt_inter += frame->pcnt_inter;
section->pcnt_motion += frame->pcnt_motion;
section->pcnt_second_ref += frame->pcnt_second_ref;
section->pcnt_neutral += frame->pcnt_neutral;
section->MVr += frame->MVr;
section->mvr_abs += frame->mvr_abs;
section->MVc += frame->MVc;
section->mvc_abs += frame->mvc_abs;
section->MVrv += frame->MVrv;
section->MVcv += frame->MVcv;
section->mv_in_out_count += frame->mv_in_out_count;
section->new_mv_count += frame->new_mv_count;
section->count += frame->count;
section->duration += frame->duration;
}