2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-08-01 22:42:14 +02:00
|
|
|
#include "vpx_config.h"
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
#include "vp9/common/vp9_filter.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_onyxc_int.h"
|
Convert subpixel filters to use convolve framework
Update the code to call the new convolution functions to do subpixel
prediction rather than the existing functions. Remove the old C and
assembly code, since it is unused. This causes a 50% performance
reduction on the decoder, but that will be resolved when the asm for
the new functions is available.
There is no consensus for whether 6-tap or 2-tap predictors will be
supported in the final codec, so these filters are implemented in
terms of the 8-tap code, so that quality testing of these modes
can continue. Implementing the lower complexity algorithms is a
simple exercise, should it be necessary.
This code produces slightly better results in the EIGHTTAP_SMOOTH
case, since the filter is now applied in only one direction when
the subpel motion is only in one direction. Like the previous code,
the filtering is skipped entirely on full-pel MVs. This combination
seems to give the best quality gains, but this may be indicative of a
bug in the encoder's filter selection, since the encoder could
achieve the result of skipping the filtering on full-pel by selecting
one of the other filters. This should be revisited.
Quality gains on derf positive on almost all clips. The only clip
that seemed to be hurt at all datarates was football
(-0.115% PSNR average, -0.587% min). Overall averages 0.375% PSNR,
0.347% SSIM.
Change-Id: I7d469716091b1d89b4b08adde5863999319d69ff
2013-01-29 01:59:03 +01:00
|
|
|
#include "vp9/common/vp9_reconinter.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_onyx_int.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_systemdependent.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_quantize.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_alloccommon.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_mcomp.h"
|
|
|
|
#include "vp9/encoder/vp9_firstpass.h"
|
|
|
|
#include "vp9/encoder/vp9_psnr.h"
|
2012-12-03 23:19:49 +01:00
|
|
|
#include "vpx_scale/vpx_scale.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_extend.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_ratectrl.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_quant_common.h"
|
2013-02-07 00:30:21 +01:00
|
|
|
#include "vp9/common/vp9_tile_common.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_segmentation.h"
|
2012-11-25 04:33:58 +01:00
|
|
|
#include "./vp9_rtcd.h"
|
2012-12-03 21:26:51 +01:00
|
|
|
#include "./vpx_scale_rtcd.h"
|
2011-08-01 22:42:14 +02:00
|
|
|
#if CONFIG_POSTPROC
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_postproc.h"
|
2011-08-01 22:42:14 +02:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "vpx_mem/vpx_mem.h"
|
|
|
|
#include "vpx_ports/vpx_timer.h"
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_seg_common.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_mbgraph.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_pred_common.h"
|
|
|
|
#include "vp9/encoder/vp9_rdopt.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_bitstream.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/encoder/vp9_picklpf.h"
|
|
|
|
#include "vp9/common/vp9_mvref_common.h"
|
2012-11-29 19:10:51 +01:00
|
|
|
#include "vp9/encoder/vp9_temporal_filter.h"
|
2012-08-24 16:44:01 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
extern void print_tree_update_probs();
|
2012-10-30 22:25:33 +01:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void set_default_lf_deltas(VP9_COMP *cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-01-08 23:14:01 +01:00
|
|
|
#define DEFAULT_INTERP_FILTER SWITCHABLE
|
|
|
|
|
2012-07-28 02:46:33 +02:00
|
|
|
#define SEARCH_BEST_FILTER 0 /* to search exhaustively for
|
|
|
|
best filter */
|
2012-04-16 23:53:37 +02:00
|
|
|
#define RESET_FOREACH_FILTER 0 /* whether to reset the encoder state
|
2012-07-28 02:46:33 +02:00
|
|
|
before trying each new filter */
|
|
|
|
#define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */
|
|
|
|
|
|
|
|
#define ALTREF_HIGH_PRECISION_MV 1 /* whether to use high precision mv
|
|
|
|
for altref computation */
|
|
|
|
#define HIGH_PRECISION_MV_QTHRESH 200 /* Q threshold for use of high precision
|
|
|
|
mv. Choose a very high value for
|
|
|
|
now so that HIGH_PRECISION is always
|
|
|
|
chosen */
|
2012-02-27 19:22:38 +01:00
|
|
|
|
2011-04-29 18:37:59 +02:00
|
|
|
#if CONFIG_INTERNAL_STATS
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "math.h"
|
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
extern double vp9_calc_ssim(YV12_BUFFER_CONFIG *source,
|
2012-10-22 05:47:57 +02:00
|
|
|
YV12_BUFFER_CONFIG *dest, int lumamask,
|
|
|
|
double *weight);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-08 15:05:18 +01:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
extern double vp9_calc_ssimg(YV12_BUFFER_CONFIG *source,
|
2012-10-22 05:47:57 +02:00
|
|
|
YV12_BUFFER_CONFIG *dest, double *ssim_y,
|
|
|
|
double *ssim_u, double *ssim_v);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// #define OUTPUT_YUV_REC
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#ifdef OUTPUT_YUV_SRC
|
|
|
|
FILE *yuv_file;
|
|
|
|
#endif
|
2011-02-14 23:18:18 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
|
|
|
FILE *yuv_rec_file;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
FILE *framepsnr;
|
2011-07-20 23:21:24 +02:00
|
|
|
FILE *kf_list;
|
2010-05-18 17:58:33 +02:00
|
|
|
FILE *keyfile;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
extern int skip_true_count;
|
|
|
|
extern int skip_false_count;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENTROPY_STATS
|
2013-05-31 01:21:48 +02:00
|
|
|
extern int intra_mode_stats[VP9_INTRA_MODES]
|
|
|
|
[VP9_INTRA_MODES]
|
|
|
|
[VP9_INTRA_MODES];
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-26 22:42:07 +02:00
|
|
|
#ifdef NMV_STATS
|
|
|
|
extern void init_nmvstats();
|
|
|
|
extern void print_nmvstats();
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#ifdef SPEEDSTATS
|
|
|
|
unsigned int frames_at_speed[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
#endif
|
|
|
|
|
2011-02-14 23:18:18 +01:00
|
|
|
#if defined(SECTIONBITS_OUTPUT)
|
|
|
|
extern unsigned __int64 Sectionbits[500];
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
extern void vp9_init_quantizer(VP9_COMP *cpi);
|
2011-12-12 19:27:25 +01:00
|
|
|
|
2012-10-31 01:12:12 +01:00
|
|
|
static int base_skip_false_prob[QINDEX_RANGE][3];
|
2011-11-23 12:32:20 +01:00
|
|
|
|
2010-09-29 13:03:19 +02:00
|
|
|
// Tables relating active max Q to active min Q
|
2011-11-23 12:32:20 +01:00
|
|
|
static int kf_low_motion_minq[QINDEX_RANGE];
|
|
|
|
static int kf_high_motion_minq[QINDEX_RANGE];
|
|
|
|
static int gf_low_motion_minq[QINDEX_RANGE];
|
|
|
|
static int gf_high_motion_minq[QINDEX_RANGE];
|
|
|
|
static int inter_minq[QINDEX_RANGE];
|
|
|
|
|
|
|
|
// Functions to compute the active minq lookup table entries based on a
|
|
|
|
// formulaic approach to facilitate easier adjustment of the Q tables.
|
|
|
|
// The formulae were derived from computing a 3rd order polynomial best
|
|
|
|
// fit to the original data (after plotting real maxq vs minq (not q index))
|
2012-10-30 02:20:32 +01:00
|
|
|
static int calculate_minq_index(double maxq,
|
2013-03-27 22:22:30 +01:00
|
|
|
double x3, double x2, double x1, double c) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
2013-03-27 22:22:30 +01:00
|
|
|
const double minqtarget = MIN(((x3 * maxq + x2) * maxq + x1) * maxq + c,
|
|
|
|
maxq);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-04 18:40:39 +02:00
|
|
|
// Special case handling to deal with the step from q2.0
|
|
|
|
// down to lossless mode represented by q 1.0.
|
|
|
|
if (minqtarget <= 2.0)
|
|
|
|
return 0;
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < QINDEX_RANGE; i++) {
|
2012-10-30 20:58:42 +01:00
|
|
|
if (minqtarget <= vp9_convert_qindex_to_q(i))
|
2012-07-14 00:21:29 +02:00
|
|
|
return i;
|
|
|
|
}
|
2013-03-27 22:22:30 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return QINDEX_RANGE - 1;
|
2011-11-23 12:32:20 +01:00
|
|
|
}
|
2012-07-18 22:43:01 +02:00
|
|
|
|
2012-10-30 02:20:32 +01:00
|
|
|
static void init_minq_luts(void) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < QINDEX_RANGE; i++) {
|
2013-03-27 22:22:30 +01:00
|
|
|
const double maxq = vp9_convert_qindex_to_q(i);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
kf_low_motion_minq[i] = calculate_minq_index(maxq,
|
2013-04-16 19:59:39 +02:00
|
|
|
0.000001,
|
|
|
|
-0.0004,
|
|
|
|
0.15,
|
2012-07-14 00:21:29 +02:00
|
|
|
0.0);
|
|
|
|
kf_high_motion_minq[i] = calculate_minq_index(maxq,
|
2013-04-16 19:59:39 +02:00
|
|
|
0.000002,
|
|
|
|
-0.0012,
|
|
|
|
0.5,
|
2012-07-14 00:21:29 +02:00
|
|
|
0.0);
|
2013-04-16 19:59:39 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
gf_low_motion_minq[i] = calculate_minq_index(maxq,
|
|
|
|
0.0000015,
|
|
|
|
-0.0009,
|
|
|
|
0.33,
|
|
|
|
0.0);
|
|
|
|
gf_high_motion_minq[i] = calculate_minq_index(maxq,
|
|
|
|
0.0000021,
|
|
|
|
-0.00125,
|
|
|
|
0.45,
|
|
|
|
0.0);
|
|
|
|
inter_minq[i] = calculate_minq_index(maxq,
|
|
|
|
0.00000271,
|
|
|
|
-0.00113,
|
|
|
|
0.697,
|
|
|
|
0.0);
|
|
|
|
|
|
|
|
}
|
2011-11-23 12:32:20 +01:00
|
|
|
}
|
2012-11-07 15:50:25 +01:00
|
|
|
|
2012-11-09 00:44:39 +01:00
|
|
|
static void set_mvcost(MACROBLOCK *mb) {
|
|
|
|
if (mb->e_mbd.allow_high_precision_mv) {
|
|
|
|
mb->mvcost = mb->nmvcost_hp;
|
|
|
|
mb->mvsadcost = mb->nmvsadcost_hp;
|
|
|
|
} else {
|
|
|
|
mb->mvcost = mb->nmvcost;
|
|
|
|
mb->mvsadcost = mb->nmvsadcost;
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 02:20:32 +01:00
|
|
|
static void init_base_skip_probs(void) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
2011-12-12 19:27:25 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < QINDEX_RANGE; i++) {
|
2013-03-27 22:22:30 +01:00
|
|
|
const double q = vp9_convert_qindex_to_q(i);
|
2011-12-12 19:27:25 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Exponential decay caluclation of baseline skip prob with clamping
|
|
|
|
// Based on crude best fit of old table.
|
2013-03-27 22:22:30 +01:00
|
|
|
const int t = (int)(564.25 * pow(2.71828, (-0.012 * q)));
|
2012-03-19 19:02:04 +01:00
|
|
|
|
Consistently use get_prob(), clip_prob() and newly added clip_pixel().
Add a function clip_pixel() to clip a pixel value to the [0,255] range
of allowed values, and use this where-ever appropriate (e.g. prediction,
reconstruction). Likewise, consistently use the recently added function
clip_prob(), which calculates a binary probability in the [1,255] range.
If possible, try to use get_prob() or its sister get_binary_prob() to
calculate binary probabilities, for consistency.
Since in some places, this means that binary probability calculations
are changed (we use {255,256}*count0/(total) in a range of places,
and all of these are now changed to use 256*count0+(total>>1)/total),
this changes the encoding result, so this patch warrants some extensive
testing.
Change-Id: Ibeeff8d886496839b8e0c0ace9ccc552351f7628
2012-12-10 21:09:07 +01:00
|
|
|
base_skip_false_prob[i][1] = clip_prob(t);
|
|
|
|
base_skip_false_prob[i][2] = clip_prob(t * 3 / 4);
|
|
|
|
base_skip_false_prob[i][0] = clip_prob(t * 5 / 4);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-12-12 19:27:25 +01:00
|
|
|
}
|
2012-10-30 02:20:32 +01:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void update_base_skip_probs(VP9_COMP *cpi) {
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2013-04-02 19:24:56 +02:00
|
|
|
int k;
|
2012-04-11 15:37:48 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cm->frame_type != KEY_FRAME) {
|
2012-10-30 05:25:22 +01:00
|
|
|
vp9_update_skip_probs(cpi);
|
2012-04-11 15:37:48 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_alt_ref_frame) {
|
2012-07-14 00:21:29 +02:00
|
|
|
for (k = 0; k < MBSKIP_CONTEXTS; ++k)
|
|
|
|
cpi->last_skip_false_probs[2][k] = cm->mbskip_pred_probs[k];
|
|
|
|
cpi->last_skip_probs_q[2] = cm->base_qindex;
|
2013-01-15 22:49:44 +01:00
|
|
|
} else if (cpi->refresh_golden_frame) {
|
2012-07-14 00:21:29 +02:00
|
|
|
for (k = 0; k < MBSKIP_CONTEXTS; ++k)
|
|
|
|
cpi->last_skip_false_probs[1][k] = cm->mbskip_pred_probs[k];
|
|
|
|
cpi->last_skip_probs_q[1] = cm->base_qindex;
|
|
|
|
} else {
|
|
|
|
for (k = 0; k < MBSKIP_CONTEXTS; ++k)
|
|
|
|
cpi->last_skip_false_probs[0][k] = cm->mbskip_pred_probs[k];
|
|
|
|
cpi->last_skip_probs_q[0] = cm->base_qindex;
|
2012-04-11 15:37:48 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// update the baseline table for the current q
|
|
|
|
for (k = 0; k < MBSKIP_CONTEXTS; ++k)
|
|
|
|
cpi->base_skip_false_prob[cm->base_qindex][k] =
|
2013-04-02 19:24:56 +02:00
|
|
|
cm->mbskip_pred_probs[k];
|
2012-04-11 15:37:48 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2012-04-11 15:37:48 +02:00
|
|
|
}
|
2011-12-12 19:27:25 +01:00
|
|
|
|
2012-10-30 22:25:33 +01:00
|
|
|
void vp9_initialize_enc() {
|
2012-07-14 00:21:29 +02:00
|
|
|
static int init_done = 0;
|
|
|
|
|
|
|
|
if (!init_done) {
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_initialize_common();
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_tokenize_initialize();
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_init_quant_tables();
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_init_me_luts();
|
2012-07-14 00:21:29 +02:00
|
|
|
init_minq_luts();
|
|
|
|
init_base_skip_probs();
|
|
|
|
init_done = 1;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void setup_features(VP9_COMP *cpi) {
|
2012-07-14 00:21:29 +02:00
|
|
|
MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
2011-09-14 19:20:25 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Set up default state for MB feature flags
|
2013-04-30 01:07:17 +02:00
|
|
|
xd->segmentation_enabled = 0;
|
2011-11-08 16:40:32 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
|
|
|
vpx_memset(xd->mb_segment_tree_probs, 255, sizeof(xd->mb_segment_tree_probs));
|
2011-09-14 19:20:25 +02:00
|
|
|
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_clearall_segfeatures(xd);
|
2011-09-14 19:20:25 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
xd->mode_ref_lf_delta_enabled = 0;
|
|
|
|
xd->mode_ref_lf_delta_update = 0;
|
|
|
|
vpx_memset(xd->ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas));
|
|
|
|
vpx_memset(xd->mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas));
|
|
|
|
vpx_memset(xd->last_ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas));
|
|
|
|
vpx_memset(xd->last_mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
set_default_lf_deltas(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void dealloc_compressor_data(VP9_COMP *cpi) {
|
2012-07-14 00:21:29 +02:00
|
|
|
// Delete sementation map
|
|
|
|
vpx_free(cpi->segmentation_map);
|
|
|
|
cpi->segmentation_map = 0;
|
|
|
|
vpx_free(cpi->common.last_frame_seg_map);
|
|
|
|
cpi->common.last_frame_seg_map = 0;
|
|
|
|
vpx_free(cpi->coding_context.last_frame_seg_map_copy);
|
|
|
|
cpi->coding_context.last_frame_seg_map_copy = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_free(cpi->active_map);
|
|
|
|
cpi->active_map = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-02 03:23:04 +02:00
|
|
|
vp9_free_frame_buffers(&cpi->common);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-07 00:52:06 +02:00
|
|
|
vp9_free_frame_buffer(&cpi->last_frame_uf);
|
|
|
|
vp9_free_frame_buffer(&cpi->scaled_source);
|
|
|
|
vp9_free_frame_buffer(&cpi->alt_ref_buffer);
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_lookahead_destroy(cpi->lookahead);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_free(cpi->tok);
|
|
|
|
cpi->tok = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Activity mask based per mb zbin adjustments
|
|
|
|
vpx_free(cpi->mb_activity_map);
|
|
|
|
cpi->mb_activity_map = 0;
|
|
|
|
vpx_free(cpi->mb_norm_activity_map);
|
|
|
|
cpi->mb_norm_activity_map = 0;
|
2011-05-12 18:01:55 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_free(cpi->mb.pip);
|
|
|
|
cpi->mb.pip = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 15:48:52 +01:00
|
|
|
// Computes a q delta (in "q index" terms) to get from a starting q value
|
|
|
|
// to a target value
|
|
|
|
// target q value
|
2012-10-31 01:53:32 +01:00
|
|
|
static int compute_qdelta(VP9_COMP *cpi, double qstart, double qtarget) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
|
|
|
int start_index = cpi->worst_quality;
|
|
|
|
int target_index = cpi->worst_quality;
|
|
|
|
|
|
|
|
// Convert the average q value to an index.
|
|
|
|
for (i = cpi->best_quality; i < cpi->worst_quality; i++) {
|
|
|
|
start_index = i;
|
2012-10-30 20:58:42 +01:00
|
|
|
if (vp9_convert_qindex_to_q(i) >= qstart)
|
2012-07-14 00:21:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the q target to an index
|
|
|
|
for (i = cpi->best_quality; i < cpi->worst_quality; i++) {
|
|
|
|
target_index = i;
|
2012-10-30 20:58:42 +01:00
|
|
|
if (vp9_convert_qindex_to_q(i) >= qtarget)
|
2012-07-14 00:21:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return target_index - start_index;
|
2011-12-06 15:48:52 +01:00
|
|
|
}
|
|
|
|
|
2013-02-05 11:13:25 +01:00
|
|
|
static void configure_static_seg_features(VP9_COMP *cpi) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2012-07-14 00:21:29 +02:00
|
|
|
MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
2011-09-30 17:45:16 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
int high_q = (int)(cpi->avg_q > 48.0);
|
|
|
|
int qi_delta;
|
2011-10-28 16:27:23 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Disable and clear down for KF
|
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
|
|
|
// Clear down the global segmentation map
|
2013-04-26 20:57:17 +02:00
|
|
|
vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
|
2012-07-14 00:21:29 +02:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
|
|
|
cpi->static_mb_pct = 0;
|
2011-09-30 17:45:16 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Disable segmentation
|
2012-10-31 01:53:32 +01:00
|
|
|
vp9_disable_segmentation((VP9_PTR)cpi);
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Clear down the segment features.
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_clearall_segfeatures(xd);
|
2013-01-15 22:49:44 +01:00
|
|
|
} else if (cpi->refresh_alt_ref_frame) {
|
|
|
|
// If this is an alt ref frame
|
2012-07-14 00:21:29 +02:00
|
|
|
// Clear down the global segmentation map
|
2013-04-26 20:57:17 +02:00
|
|
|
vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
|
2012-07-14 00:21:29 +02:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
|
|
|
cpi->static_mb_pct = 0;
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Disable segmentation and individual segment features by default
|
2012-10-31 01:53:32 +01:00
|
|
|
vp9_disable_segmentation((VP9_PTR)cpi);
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_clearall_segfeatures(xd);
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Scan frames from current to arf frame.
|
|
|
|
// This function re-enables segmentation if appropriate.
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_update_mbgraph_stats(cpi);
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// If segmentation was enabled set those features needed for the
|
|
|
|
// arf itself.
|
|
|
|
if (xd->segmentation_enabled) {
|
|
|
|
xd->update_mb_segmentation_map = 1;
|
|
|
|
xd->update_mb_segmentation_data = 1;
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
qi_delta = compute_qdelta(cpi, cpi->avg_q, (cpi->avg_q * 0.875));
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_set_segdata(xd, 1, SEG_LVL_ALT_Q, (qi_delta - 2));
|
|
|
|
vp9_set_segdata(xd, 1, SEG_LVL_ALT_LF, -2);
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_enable_segfeature(xd, 1, SEG_LVL_ALT_Q);
|
|
|
|
vp9_enable_segfeature(xd, 1, SEG_LVL_ALT_LF);
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Where relevant assume segment data is delta data
|
|
|
|
xd->mb_segment_abs_delta = SEGMENT_DELTADATA;
|
2011-11-09 15:05:28 +01:00
|
|
|
|
2011-09-30 17:45:16 +02:00
|
|
|
}
|
2013-04-30 01:07:17 +02:00
|
|
|
} else if (xd->segmentation_enabled) {
|
|
|
|
// All other frames if segmentation has been enabled
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// First normal frame in a valid gf or alt ref group
|
|
|
|
if (cpi->common.frames_since_golden == 0) {
|
2013-01-28 16:22:53 +01:00
|
|
|
// Set up segment features for normal frames in an arf group
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->source_alt_ref_active) {
|
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 1;
|
|
|
|
xd->mb_segment_abs_delta = SEGMENT_DELTADATA;
|
2011-11-03 17:58:26 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
qi_delta = compute_qdelta(cpi, cpi->avg_q,
|
|
|
|
(cpi->avg_q * 1.125));
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_set_segdata(xd, 1, SEG_LVL_ALT_Q, (qi_delta + 2));
|
|
|
|
vp9_set_segdata(xd, 1, SEG_LVL_ALT_Q, 0);
|
|
|
|
vp9_enable_segfeature(xd, 1, SEG_LVL_ALT_Q);
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_set_segdata(xd, 1, SEG_LVL_ALT_LF, -2);
|
|
|
|
vp9_enable_segfeature(xd, 1, SEG_LVL_ALT_LF);
|
2011-11-03 17:58:26 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Segment coding disabled for compred testing
|
|
|
|
if (high_q || (cpi->static_mb_pct == 100)) {
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_set_segref(xd, 1, ALTREF_FRAME);
|
|
|
|
vp9_enable_segfeature(xd, 1, SEG_LVL_REF_FRAME);
|
2013-01-28 16:22:53 +01:00
|
|
|
vp9_enable_segfeature(xd, 1, SEG_LVL_SKIP);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2013-04-30 01:07:17 +02:00
|
|
|
} else {
|
|
|
|
// Disable segmentation and clear down features if alt ref
|
|
|
|
// is not active for this group
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
vp9_disable_segmentation((VP9_PTR)cpi);
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_clearall_segfeatures(xd);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2013-04-30 01:07:17 +02:00
|
|
|
} else if (cpi->is_src_frame_alt_ref) {
|
|
|
|
// Special case where we are coding over the top of a previous
|
|
|
|
// alt ref frame.
|
|
|
|
// Segment coding disabled for compred testing
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-01-28 16:22:53 +01:00
|
|
|
// Enable ref frame features for segment 0 as well
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_enable_segfeature(xd, 0, SEG_LVL_REF_FRAME);
|
|
|
|
vp9_enable_segfeature(xd, 1, SEG_LVL_REF_FRAME);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-01-28 16:22:53 +01:00
|
|
|
// All mbs should use ALTREF_FRAME
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_clear_segref(xd, 0);
|
|
|
|
vp9_set_segref(xd, 0, ALTREF_FRAME);
|
|
|
|
vp9_clear_segref(xd, 1);
|
|
|
|
vp9_set_segref(xd, 1, ALTREF_FRAME);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-01-28 16:22:53 +01:00
|
|
|
// Skip all MBs if high Q (0,0 mv and skip coeffs)
|
2012-07-14 00:21:29 +02:00
|
|
|
if (high_q) {
|
2013-01-28 16:22:53 +01:00
|
|
|
vp9_enable_segfeature(xd, 0, SEG_LVL_SKIP);
|
|
|
|
vp9_enable_segfeature(xd, 1, SEG_LVL_SKIP);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
// Enable data udpate
|
|
|
|
xd->update_mb_segmentation_data = 1;
|
2013-04-30 01:07:17 +02:00
|
|
|
} else {
|
|
|
|
// All other frames.
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// No updates.. leave things as they are.
|
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-09-30 17:45:16 +02:00
|
|
|
}
|
|
|
|
|
2013-05-16 12:27:12 +02:00
|
|
|
#ifdef ENTROPY_STATS
|
|
|
|
void vp9_update_mode_context_stats(VP9_COMP *cpi) {
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
|
|
|
int i, j;
|
2013-06-05 20:21:44 +02:00
|
|
|
unsigned int (*inter_mode_counts)[VP9_INTER_MODES - 1][2] =
|
2013-06-05 00:25:16 +02:00
|
|
|
cm->fc.inter_mode_counts;
|
2013-06-05 20:21:44 +02:00
|
|
|
int64_t (*mv_ref_stats)[VP9_INTER_MODES - 1][2] = cpi->mv_ref_stats;
|
2013-05-16 12:27:12 +02:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
// Read the past stats counters
|
|
|
|
f = fopen("mode_context.bin", "rb");
|
|
|
|
if (!f) {
|
|
|
|
vpx_memset(cpi->mv_ref_stats, 0, sizeof(cpi->mv_ref_stats));
|
|
|
|
} else {
|
|
|
|
fread(cpi->mv_ref_stats, sizeof(cpi->mv_ref_stats), 1, f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add in the values for this frame
|
|
|
|
for (i = 0; i < INTER_MODE_CONTEXTS; i++) {
|
2013-06-05 20:21:44 +02:00
|
|
|
for (j = 0; j < VP9_INTER_MODES - 1; j++) {
|
2013-06-05 00:25:16 +02:00
|
|
|
mv_ref_stats[i][j][0] += (int64_t)inter_mode_counts[i][j][0];
|
|
|
|
mv_ref_stats[i][j][1] += (int64_t)inter_mode_counts[i][j][1];
|
2013-05-16 12:27:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write back the accumulated stats
|
|
|
|
f = fopen("mode_context.bin", "wb");
|
|
|
|
fwrite(cpi->mv_ref_stats, sizeof(cpi->mv_ref_stats), 1, f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_mode_context(VP9_COMP *cpi) {
|
|
|
|
FILE *f = fopen("vp9_modecont.c", "a");
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
fprintf(f, "#include \"vp9_entropy.h\"\n");
|
2013-06-05 20:21:44 +02:00
|
|
|
fprintf(
|
|
|
|
f,
|
|
|
|
"const int inter_mode_probs[INTER_MODE_CONTEXTS][VP9_INTER_MODES - 1] =");
|
2013-05-16 12:27:12 +02:00
|
|
|
fprintf(f, "{\n");
|
|
|
|
for (j = 0; j < INTER_MODE_CONTEXTS; j++) {
|
|
|
|
fprintf(f, " {/* %d */ ", j);
|
|
|
|
fprintf(f, " ");
|
2013-06-05 20:21:44 +02:00
|
|
|
for (i = 0; i < VP9_INTER_MODES - 1; i++) {
|
2013-05-16 12:27:12 +02:00
|
|
|
int this_prob;
|
|
|
|
int64_t count = cpi->mv_ref_stats[j][i][0] + cpi->mv_ref_stats[j][i][1];
|
|
|
|
if (count)
|
|
|
|
this_prob = ((cpi->mv_ref_stats[j][i][0] * 256) + (count >> 1)) / count;
|
|
|
|
else
|
|
|
|
this_prob = 128;
|
|
|
|
|
|
|
|
// context probs
|
|
|
|
fprintf(f, "%5d, ", this_prob);
|
|
|
|
}
|
|
|
|
fprintf(f, " },\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(f, "};\n");
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
#endif // ENTROPY_STATS
|
|
|
|
|
2011-09-30 17:45:16 +02:00
|
|
|
// DEBUG: Print out the segment id of each MB in the current frame.
|
2012-10-31 01:53:32 +01:00
|
|
|
static void print_seg_map(VP9_COMP *cpi) {
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2012-07-14 00:21:29 +02:00
|
|
|
int row, col;
|
|
|
|
int map_index = 0;
|
2013-03-27 22:22:30 +01:00
|
|
|
FILE *statsfile = fopen("segmap.stt", "a");
|
2011-09-30 17:45:16 +02:00
|
|
|
|
2013-03-27 22:22:30 +01:00
|
|
|
fprintf(statsfile, "%10d\n", cm->current_video_frame);
|
2011-09-30 17:45:16 +02:00
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
for (row = 0; row < cpi->common.mi_rows; row++) {
|
|
|
|
for (col = 0; col < cpi->common.mi_cols; col++) {
|
2013-03-27 22:22:30 +01:00
|
|
|
fprintf(statsfile, "%10d", cpi->segmentation_map[map_index]);
|
2012-07-14 00:21:29 +02:00
|
|
|
map_index++;
|
2011-09-30 17:45:16 +02:00
|
|
|
}
|
|
|
|
fprintf(statsfile, "\n");
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
fprintf(statsfile, "\n");
|
2011-09-30 17:45:16 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fclose(statsfile);
|
2011-09-30 17:45:16 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void update_reference_segmentation_map(VP9_COMP *cpi) {
|
2013-01-06 03:20:25 +01:00
|
|
|
VP9_COMMON *const cm = &cpi->common;
|
|
|
|
int row, col;
|
|
|
|
MODE_INFO *mi, *mi_ptr = cm->mi;
|
|
|
|
uint8_t *cache_ptr = cm->last_frame_seg_map, *cache;
|
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
for (row = 0; row < cm->mi_rows; row++) {
|
2013-01-06 03:20:25 +01:00
|
|
|
mi = mi_ptr;
|
|
|
|
cache = cache_ptr;
|
2013-04-26 20:57:17 +02:00
|
|
|
for (col = 0; col < cm->mi_cols; col++, mi++, cache++)
|
2013-01-06 03:20:25 +01:00
|
|
|
cache[0] = mi->mbmi.segment_id;
|
|
|
|
mi_ptr += cm->mode_info_stride;
|
2013-04-26 20:57:17 +02:00
|
|
|
cache_ptr += cm->mi_cols;
|
2012-08-20 23:43:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void set_default_lf_deltas(VP9_COMP *cpi) {
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->mb.e_mbd.mode_ref_lf_delta_enabled = 1;
|
|
|
|
cpi->mb.e_mbd.mode_ref_lf_delta_update = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_memset(cpi->mb.e_mbd.ref_lf_deltas, 0, sizeof(cpi->mb.e_mbd.ref_lf_deltas));
|
|
|
|
vpx_memset(cpi->mb.e_mbd.mode_lf_deltas, 0, sizeof(cpi->mb.e_mbd.mode_lf_deltas));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Test of ref frame deltas
|
|
|
|
cpi->mb.e_mbd.ref_lf_deltas[INTRA_FRAME] = 2;
|
|
|
|
cpi->mb.e_mbd.ref_lf_deltas[LAST_FRAME] = 0;
|
|
|
|
cpi->mb.e_mbd.ref_lf_deltas[GOLDEN_FRAME] = -2;
|
|
|
|
cpi->mb.e_mbd.ref_lf_deltas[ALTREF_FRAME] = -2;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-11 21:16:35 +02:00
|
|
|
cpi->mb.e_mbd.mode_lf_deltas[0] = 4; // I4X4_PRED
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->mb.e_mbd.mode_lf_deltas[1] = -2; // Zero
|
|
|
|
cpi->mb.e_mbd.mode_lf_deltas[2] = 2; // New mv
|
|
|
|
cpi->mb.e_mbd.mode_lf_deltas[3] = 4; // Split mv
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-02-04 18:43:02 +01:00
|
|
|
static void set_rd_speed_thresholds(VP9_COMP *cpi, int mode, int speed) {
|
|
|
|
SPEED_FEATURES *sf = &cpi->sf;
|
|
|
|
int speed_multiplier = speed + 1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Set baseline threshold values
|
2013-04-02 19:24:56 +02:00
|
|
|
for (i = 0; i < MAX_MODES; ++i)
|
|
|
|
sf->thresh_mult[i] = mode == 0 ? -500 : 0;
|
2013-02-04 18:43:02 +01:00
|
|
|
|
|
|
|
sf->thresh_mult[THR_ZEROMV ] = 0;
|
|
|
|
sf->thresh_mult[THR_ZEROG ] = 0;
|
|
|
|
sf->thresh_mult[THR_ZEROA ] = 0;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_NEARESTMV] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTG ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTA ] = 0;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_NEARMV ] += speed_multiplier * 1000;
|
|
|
|
sf->thresh_mult[THR_NEARG ] += speed_multiplier * 1000;
|
|
|
|
sf->thresh_mult[THR_NEARA ] += speed_multiplier * 1000;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_DC ] = 0;
|
|
|
|
sf->thresh_mult[THR_TM ] += speed_multiplier * 1000;
|
|
|
|
sf->thresh_mult[THR_V_PRED ] += speed_multiplier * 1000;
|
|
|
|
sf->thresh_mult[THR_H_PRED ] += speed_multiplier * 1000;
|
2013-02-05 11:13:25 +01:00
|
|
|
sf->thresh_mult[THR_D45_PRED ] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_D135_PRED] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_D117_PRED] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_D153_PRED] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_D27_PRED ] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_D63_PRED ] += speed_multiplier * 1500;
|
2013-02-04 18:43:02 +01:00
|
|
|
|
|
|
|
sf->thresh_mult[THR_B_PRED ] += speed_multiplier * 2500;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_NEWMV ] += speed_multiplier * 1000;
|
|
|
|
sf->thresh_mult[THR_NEWG ] += speed_multiplier * 1000;
|
|
|
|
sf->thresh_mult[THR_NEWA ] += speed_multiplier * 1000;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_SPLITMV ] += speed_multiplier * 2500;
|
|
|
|
sf->thresh_mult[THR_SPLITG ] += speed_multiplier * 2500;
|
|
|
|
sf->thresh_mult[THR_SPLITA ] += speed_multiplier * 2500;
|
|
|
|
|
2013-02-05 11:13:25 +01:00
|
|
|
sf->thresh_mult[THR_COMP_ZEROLG ] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROLA ] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROGA ] += speed_multiplier * 1500;
|
2013-02-04 18:43:02 +01:00
|
|
|
|
2013-02-05 11:13:25 +01:00
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLG] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLA] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTGA] += speed_multiplier * 1500;
|
2013-02-04 18:43:02 +01:00
|
|
|
|
2013-02-05 11:13:25 +01:00
|
|
|
sf->thresh_mult[THR_COMP_NEARLG ] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLA ] += speed_multiplier * 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARGA ] += speed_multiplier * 1500;
|
2013-02-04 18:43:02 +01:00
|
|
|
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLG ] += speed_multiplier * 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLA ] += speed_multiplier * 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWGA ] += speed_multiplier * 2000;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITLA ] += speed_multiplier * 4500;
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITGA ] += speed_multiplier * 4500;
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITLG ] += speed_multiplier * 4500;
|
|
|
|
|
2013-05-31 00:13:08 +02:00
|
|
|
if (speed > 4) {
|
|
|
|
for (i = 0; i < MAX_MODES; ++i)
|
|
|
|
sf->thresh_mult[i] = INT_MAX;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_DC ] = 0;
|
|
|
|
sf->thresh_mult[THR_TM ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEWMV ] = 4000;
|
|
|
|
sf->thresh_mult[THR_NEWG ] = 4000;
|
|
|
|
sf->thresh_mult[THR_NEWA ] = 4000;
|
|
|
|
sf->thresh_mult[THR_NEARESTMV] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTG ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTA ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARMV ] = 2000;
|
|
|
|
sf->thresh_mult[THR_NEARG ] = 2000;
|
|
|
|
sf->thresh_mult[THR_NEARA ] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLA] = 2000;
|
|
|
|
sf->recode_loop = 0;
|
|
|
|
}
|
|
|
|
|
2013-02-05 11:13:25 +01:00
|
|
|
/* disable frame modes if flags not set */
|
|
|
|
if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) {
|
|
|
|
sf->thresh_mult[THR_NEWMV ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEARESTMV] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_ZEROMV ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEARMV ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_SPLITMV ] = INT_MAX;
|
|
|
|
}
|
|
|
|
if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) {
|
|
|
|
sf->thresh_mult[THR_NEARESTG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_ZEROG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEARG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEWG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_SPLITG ] = INT_MAX;
|
|
|
|
}
|
|
|
|
if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) {
|
|
|
|
sf->thresh_mult[THR_NEARESTA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_ZEROA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEARA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEWA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_SPLITA ] = INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_GOLD_FLAG)) !=
|
|
|
|
(VP9_LAST_FLAG | VP9_GOLD_FLAG)) {
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROLG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLG] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITLG ] = INT_MAX;
|
|
|
|
}
|
|
|
|
if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) !=
|
|
|
|
(VP9_LAST_FLAG | VP9_ALT_FLAG)) {
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROLA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLA] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITLA ] = INT_MAX;
|
|
|
|
}
|
|
|
|
if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) !=
|
|
|
|
(VP9_GOLD_FLAG | VP9_ALT_FLAG)) {
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROGA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTGA] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARGA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWGA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITGA ] = INT_MAX;
|
|
|
|
}
|
2013-02-04 18:43:02 +01:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
void vp9_set_speed_features(VP9_COMP *cpi) {
|
2012-07-14 00:21:29 +02:00
|
|
|
SPEED_FEATURES *sf = &cpi->sf;
|
2013-02-04 18:43:02 +01:00
|
|
|
int mode = cpi->compressor_speed;
|
2013-05-08 23:35:42 +02:00
|
|
|
int speed = cpi->speed;
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
// Only modes 0 and 1 supported for now in experimental code basae
|
2013-02-04 18:43:02 +01:00
|
|
|
if (mode > 1)
|
|
|
|
mode = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Initialise default mode frequency sampling variables
|
|
|
|
for (i = 0; i < MAX_MODES; i ++) {
|
|
|
|
cpi->mode_check_freq[i] = 0;
|
|
|
|
cpi->mode_test_hit_counts[i] = 0;
|
|
|
|
cpi->mode_chosen_counts[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// best quality defaults
|
|
|
|
sf->RD = 1;
|
|
|
|
sf->search_method = NSTEP;
|
|
|
|
sf->auto_filter = 1;
|
|
|
|
sf->recode_loop = 1;
|
|
|
|
sf->quarter_pixel_search = 1;
|
|
|
|
sf->half_pixel_search = 1;
|
|
|
|
sf->iterative_sub_pixel = 1;
|
2013-02-20 16:27:35 +01:00
|
|
|
sf->no_skip_block4x4_search = 1;
|
2013-04-02 19:24:56 +02:00
|
|
|
sf->optimize_coefficients = !cpi->oxcf.lossless;
|
2012-07-14 00:21:29 +02:00
|
|
|
sf->first_step = 0;
|
|
|
|
sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
|
2013-05-30 06:59:41 +02:00
|
|
|
sf->comp_inter_joint_search = 1;
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
// Switch segmentation off.
|
|
|
|
sf->static_segmentation = 0;
|
|
|
|
#else
|
2013-04-28 00:49:49 +02:00
|
|
|
sf->static_segmentation = 0;
|
2013-04-03 00:08:50 +02:00
|
|
|
#endif
|
2013-02-05 13:54:09 +01:00
|
|
|
sf->mb16_breakout = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-02-04 18:43:02 +01:00
|
|
|
switch (mode) {
|
2010-05-18 17:58:33 +02:00
|
|
|
case 0: // best quality mode
|
2012-07-14 00:21:29 +02:00
|
|
|
sf->search_best_filter = SEARCH_BEST_FILTER;
|
|
|
|
break;
|
|
|
|
|
2013-02-04 18:43:02 +01:00
|
|
|
case 1:
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
// Switch segmentation off.
|
|
|
|
sf->static_segmentation = 0;
|
2013-04-23 15:01:55 +02:00
|
|
|
#else
|
2013-04-28 00:49:49 +02:00
|
|
|
sf->static_segmentation = 0;
|
2013-04-03 00:08:50 +02:00
|
|
|
#endif
|
2013-02-05 13:54:09 +01:00
|
|
|
sf->mb16_breakout = 0;
|
2013-05-31 15:47:40 +02:00
|
|
|
|
|
|
|
if (speed > 0) {
|
|
|
|
sf->optimize_coefficients = 0;
|
|
|
|
sf->no_skip_block4x4_search = 0;
|
|
|
|
sf->comp_inter_joint_search = 0;
|
|
|
|
sf->first_step = 1;
|
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
break;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
}; /* switch */
|
2011-02-09 23:18:28 +01:00
|
|
|
|
2013-02-05 11:13:25 +01:00
|
|
|
// Set rd thresholds based on mode and speed setting
|
|
|
|
set_rd_speed_thresholds(cpi, mode, speed);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Slow quant, dct and trellis not worthwhile for first pass
|
|
|
|
// so make sure they are always turned off.
|
|
|
|
if (cpi->pass == 1) {
|
|
|
|
sf->optimize_coefficients = 0;
|
|
|
|
}
|
2011-01-06 18:10:07 +01:00
|
|
|
|
2013-02-12 06:14:46 +01:00
|
|
|
cpi->mb.fwd_txm16x16 = vp9_short_fdct16x16;
|
|
|
|
cpi->mb.fwd_txm8x8 = vp9_short_fdct8x8;
|
|
|
|
cpi->mb.fwd_txm8x4 = vp9_short_fdct8x4;
|
|
|
|
cpi->mb.fwd_txm4x4 = vp9_short_fdct4x4;
|
2013-02-13 23:22:15 +01:00
|
|
|
if (cpi->oxcf.lossless || cpi->mb.e_mbd.lossless) {
|
2013-03-12 19:24:04 +01:00
|
|
|
cpi->mb.fwd_txm8x4 = vp9_short_walsh8x4;
|
|
|
|
cpi->mb.fwd_txm4x4 = vp9_short_walsh4x4;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
cpi->mb.quantize_b_4x4 = vp9_regular_quantize_b_4x4;
|
2012-03-21 19:22:33 +01:00
|
|
|
|
2012-10-30 22:25:33 +01:00
|
|
|
vp9_init_quantizer(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->sf.iterative_sub_pixel == 1) {
|
2012-10-30 20:58:42 +01:00
|
|
|
cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_step_iteratively;
|
2012-07-14 00:21:29 +02:00
|
|
|
} else if (cpi->sf.quarter_pixel_search) {
|
2012-10-30 20:58:42 +01:00
|
|
|
cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_step;
|
2012-07-14 00:21:29 +02:00
|
|
|
} else if (cpi->sf.half_pixel_search) {
|
2012-10-30 20:58:42 +01:00
|
|
|
cpi->find_fractional_mv_step = vp9_find_best_half_pixel_step;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->mb.optimize = cpi->sf.optimize_coefficients == 1 && cpi->pass != 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#ifdef SPEEDSTATS
|
2013-05-08 23:35:42 +02:00
|
|
|
frames_at_speed[cpi->speed]++;
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
}
|
2013-02-04 18:43:02 +01:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void alloc_raw_frame_buffers(VP9_COMP *cpi) {
|
2013-05-07 00:52:06 +02:00
|
|
|
VP9_COMMON *cm = &cpi->common;
|
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
cpi->lookahead = vp9_lookahead_init(cpi->oxcf.width, cpi->oxcf.height,
|
2013-05-07 00:52:06 +02:00
|
|
|
cm->subsampling_x, cm->subsampling_y,
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->oxcf.lag_in_frames);
|
|
|
|
if (!cpi->lookahead)
|
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate lag buffers");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-07 00:52:06 +02:00
|
|
|
if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
|
|
|
|
cpi->oxcf.width, cpi->oxcf.height,
|
|
|
|
cm->subsampling_x, cm->subsampling_y,
|
|
|
|
VP9BORDERINPIXELS))
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate altref buffer");
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2010-09-02 22:17:52 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
static int alloc_partition_data(VP9_COMP *cpi) {
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_free(cpi->mb.pip);
|
2010-12-06 23:21:37 +01:00
|
|
|
|
2013-04-24 21:28:27 +02:00
|
|
|
cpi->mb.pip = vpx_calloc((cpi->common.mode_info_stride) *
|
2013-04-26 20:57:17 +02:00
|
|
|
(cpi->common.mi_rows + 1),
|
2012-07-14 00:21:29 +02:00
|
|
|
sizeof(PARTITION_INFO));
|
|
|
|
if (!cpi->mb.pip)
|
|
|
|
return 1;
|
2010-09-02 22:17:52 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->mb.pi = cpi->mb.pip + cpi->common.mode_info_stride + 1;
|
2010-09-02 22:17:52 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
2010-09-02 22:17:52 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
void vp9_alloc_compressor_data(VP9_COMP *cpi) {
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
if (vp9_alloc_frame_buffers(cm, cm->width, cm->height))
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate frame buffers");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (alloc_partition_data(cpi))
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate partition data");
|
2010-09-02 22:17:52 +02:00
|
|
|
|
2013-05-07 00:52:06 +02:00
|
|
|
if (vp9_alloc_frame_buffer(&cpi->last_frame_uf,
|
|
|
|
cm->width, cm->height,
|
|
|
|
cm->subsampling_x, cm->subsampling_y,
|
|
|
|
VP9BORDERINPIXELS))
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate last frame buffer");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-07 00:52:06 +02:00
|
|
|
if (vp9_alloc_frame_buffer(&cpi->scaled_source,
|
|
|
|
cm->width, cm->height,
|
|
|
|
cm->subsampling_x, cm->subsampling_y,
|
|
|
|
VP9BORDERINPIXELS))
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate scaled source buffer");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_free(cpi->tok);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
{
|
2013-03-28 18:42:23 +01:00
|
|
|
unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
CHECK_MEM_ERROR(cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok)));
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Data used for real time vc mode to see if gf needs refreshing
|
|
|
|
cpi->inter_zz_count = 0;
|
|
|
|
cpi->gf_bad_count = 0;
|
|
|
|
cpi->gf_update_recommended = 0;
|
2010-08-11 17:02:31 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_free(cpi->mb_activity_map);
|
|
|
|
CHECK_MEM_ERROR(cpi->mb_activity_map,
|
|
|
|
vpx_calloc(sizeof(unsigned int),
|
|
|
|
cm->mb_rows * cm->mb_cols));
|
2010-08-11 17:02:31 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_free(cpi->mb_norm_activity_map);
|
|
|
|
CHECK_MEM_ERROR(cpi->mb_norm_activity_map,
|
|
|
|
vpx_calloc(sizeof(unsigned int),
|
|
|
|
cm->mb_rows * cm->mb_cols));
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-06 23:22:17 +01:00
|
|
|
static void update_frame_size(VP9_COMP *cpi) {
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
|
|
|
|
2013-04-30 20:14:27 +02:00
|
|
|
vp9_update_frame_size(cm);
|
2013-02-06 23:22:17 +01:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
// Update size of buffers local to this frame
|
2013-05-07 00:52:06 +02:00
|
|
|
if (vp9_realloc_frame_buffer(&cpi->last_frame_uf,
|
|
|
|
cm->width, cm->height,
|
|
|
|
cm->subsampling_x, cm->subsampling_y,
|
|
|
|
VP9BORDERINPIXELS))
|
2013-02-06 23:22:17 +01:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to reallocate last frame buffer");
|
|
|
|
|
2013-05-07 00:52:06 +02:00
|
|
|
if (vp9_realloc_frame_buffer(&cpi->scaled_source,
|
|
|
|
cm->width, cm->height,
|
|
|
|
cm->subsampling_x, cm->subsampling_y,
|
|
|
|
VP9BORDERINPIXELS))
|
2013-02-06 23:22:17 +01:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to reallocate scaled source buffer");
|
2013-03-05 00:21:45 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
int y_stride = cpi->scaled_source.y_stride;
|
|
|
|
|
|
|
|
if (cpi->sf.search_method == NSTEP) {
|
|
|
|
vp9_init3smotion_compensation(&cpi->mb, y_stride);
|
|
|
|
} else if (cpi->sf.search_method == DIAMOND) {
|
|
|
|
vp9_init_dsmotion_compensation(&cpi->mb, y_stride);
|
|
|
|
}
|
|
|
|
}
|
2013-02-06 23:22:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-12 19:27:25 +01:00
|
|
|
// TODO perhaps change number of steps expose to outside world when setting
|
|
|
|
// max and min limits. Also this will likely want refining for the extended Q
|
|
|
|
// range.
|
|
|
|
//
|
|
|
|
// Table that converts 0-63 Q range values passed in outside to the Qindex
|
|
|
|
// range used internally.
|
2012-07-14 00:21:29 +02:00
|
|
|
static const int q_trans[] = {
|
|
|
|
0, 4, 8, 12, 16, 20, 24, 28,
|
|
|
|
32, 36, 40, 44, 48, 52, 56, 60,
|
|
|
|
64, 68, 72, 76, 80, 84, 88, 92,
|
|
|
|
96, 100, 104, 108, 112, 116, 120, 124,
|
|
|
|
128, 132, 136, 140, 144, 148, 152, 156,
|
|
|
|
160, 164, 168, 172, 176, 180, 184, 188,
|
|
|
|
192, 196, 200, 204, 208, 212, 216, 220,
|
|
|
|
224, 228, 232, 236, 240, 244, 249, 255,
|
2011-12-12 19:27:25 +01:00
|
|
|
};
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
int vp9_reverse_trans(int x) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 64; i++)
|
|
|
|
if (q_trans[i] >= x)
|
|
|
|
return i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return 63;
|
2010-05-18 17:58:33 +02:00
|
|
|
};
|
2012-10-31 01:53:32 +01:00
|
|
|
void vp9_new_frame_rate(VP9_COMP *cpi, double framerate) {
|
2013-04-02 19:24:56 +02:00
|
|
|
if (framerate < 0.1)
|
2012-07-14 00:21:29 +02:00
|
|
|
framerate = 30;
|
2010-10-14 22:19:06 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->oxcf.frame_rate = framerate;
|
|
|
|
cpi->output_frame_rate = cpi->oxcf.frame_rate;
|
|
|
|
cpi->per_frame_bandwidth = (int)(cpi->oxcf.target_bandwidth / cpi->output_frame_rate);
|
|
|
|
cpi->av_per_frame_bandwidth = (int)(cpi->oxcf.target_bandwidth / cpi->output_frame_rate);
|
|
|
|
cpi->min_frame_bandwidth = (int)(cpi->av_per_frame_bandwidth * cpi->oxcf.two_pass_vbrmin_section / 100);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
|
|
|
|
cpi->min_frame_bandwidth = MAX(cpi->min_frame_bandwidth, FRAME_OVERHEAD_BITS);
|
2012-03-02 02:24:30 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Set Maximum gf/arf interval
|
2013-03-06 12:33:43 +01:00
|
|
|
cpi->max_gf_interval = 16;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Extended interval for genuinely static scenes
|
|
|
|
cpi->twopass.static_scene_max_gf_interval = cpi->key_frame_frequency >> 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-06 12:33:43 +01:00
|
|
|
// Special conditions when alt ref frame enabled in lagged compress mode
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->oxcf.play_alternate && cpi->oxcf.lag_in_frames) {
|
|
|
|
if (cpi->max_gf_interval > cpi->oxcf.lag_in_frames - 1)
|
|
|
|
cpi->max_gf_interval = cpi->oxcf.lag_in_frames - 1;
|
2011-01-18 16:19:05 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->twopass.static_scene_max_gf_interval > cpi->oxcf.lag_in_frames - 1)
|
|
|
|
cpi->twopass.static_scene_max_gf_interval = cpi->oxcf.lag_in_frames - 1;
|
|
|
|
}
|
2011-01-18 16:19:05 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->max_gf_interval > cpi->twopass.static_scene_max_gf_interval)
|
|
|
|
cpi->max_gf_interval = cpi->twopass.static_scene_max_gf_interval;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-02-28 02:09:12 +01:00
|
|
|
static int64_t rescale(int val, int64_t num, int denom) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int64_t llnum = num;
|
|
|
|
int64_t llden = denom;
|
|
|
|
int64_t llval = val;
|
2010-08-20 17:04:10 +02:00
|
|
|
|
2013-02-28 02:09:12 +01:00
|
|
|
return (llval * llnum / llden);
|
2010-08-20 17:04:10 +02:00
|
|
|
}
|
|
|
|
|
2013-02-08 20:33:11 +01:00
|
|
|
static void set_tile_limits(VP9_COMP *cpi) {
|
|
|
|
VP9_COMMON *const cm = &cpi->common;
|
2013-02-07 00:30:21 +01:00
|
|
|
int min_log2_tiles, max_log2_tiles;
|
|
|
|
|
2013-02-08 20:33:11 +01:00
|
|
|
cm->log2_tile_columns = cpi->oxcf.tile_columns;
|
|
|
|
cm->log2_tile_rows = cpi->oxcf.tile_rows;
|
|
|
|
|
2013-02-07 00:30:21 +01:00
|
|
|
vp9_get_tile_n_bits(cm, &min_log2_tiles, &max_log2_tiles);
|
|
|
|
max_log2_tiles += min_log2_tiles;
|
2013-04-02 19:24:56 +02:00
|
|
|
|
|
|
|
cm->log2_tile_columns = clamp(cm->log2_tile_columns,
|
|
|
|
min_log2_tiles, max_log2_tiles);
|
|
|
|
|
2013-02-07 00:30:21 +01:00
|
|
|
cm->tile_columns = 1 << cm->log2_tile_columns;
|
2013-02-08 20:33:11 +01:00
|
|
|
cm->tile_rows = 1 << cm->log2_tile_rows;
|
2013-02-07 00:30:21 +01:00
|
|
|
}
|
2010-08-20 17:04:10 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
static void init_config(VP9_PTR ptr, VP9_CONFIG *oxcf) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *)(ptr);
|
[WIP] Add column-based tiling.
This patch adds column-based tiling. The idea is to make each tile
independently decodable (after reading the common frame header) and
also independendly encodable (minus within-frame cost adjustments in
the RD loop) to speed-up hardware & software en/decoders if they used
multi-threading. Column-based tiling has the added advantage (over
other tiling methods) that it minimizes realtime use-case latency,
since all threads can start encoding data as soon as the first SB-row
worth of data is available to the encoder.
There is some test code that does random tile ordering in the decoder,
to confirm that each tile is indeed independently decodable from other
tiles in the same frame. At tile edges, all contexts assume default
values (i.e. 0, 0 motion vector, no coefficients, DC intra4x4 mode),
and motion vector search and ordering do not cross tiles in the same
frame.
t log
Tile independence is not maintained between frames ATM, i.e. tile 0 of
frame 1 is free to use motion vectors that point into any tile of frame
0. We support 1 (i.e. no tiling), 2 or 4 column-tiles.
The loopfilter crosses tile boundaries. I discussed this briefly with Aki
and he says that's OK. An in-loop loopfilter would need to do some sync
between tile threads, but that shouldn't be a big issue.
Resuls: with tiling disabled, we go up slightly because of improved edge
use in the intra4x4 prediction. With 2 tiles, we lose about ~1% on derf,
~0.35% on HD and ~0.55% on STD/HD. With 4 tiles, we lose another ~1.5%
on derf ~0.77% on HD and ~0.85% on STD/HD. Most of this loss is
concentrated in the low-bitrate end of clips, and most of it is because
of the loss of edges at tile boundaries and the resulting loss of intra
predictors.
TODO:
- more tiles (perhaps allow row-based tiling also, and max. 8 tiles)?
- maybe optionally (for EC purposes), motion vectors themselves
should not cross tile edges, or we should emulate such borders as
if they were off-frame, to limit error propagation to within one
tile only. This doesn't have to be the default behaviour but could
be an optional bitstream flag.
Change-Id: I5951c3a0742a767b20bc9fb5af685d9892c2c96f
2013-02-01 18:35:28 +01:00
|
|
|
VP9_COMMON *const cm = &cpi->common;
|
2013-04-02 19:24:56 +02:00
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->oxcf = *oxcf;
|
|
|
|
cpi->goldfreq = 7;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
cm->version = oxcf->version;
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_setup_version(cm);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
cm->width = oxcf->width;
|
|
|
|
cm->height = oxcf->height;
|
2013-05-07 00:52:06 +02:00
|
|
|
cm->subsampling_x = 0;
|
|
|
|
cm->subsampling_y = 0;
|
|
|
|
vp9_alloc_compressor_data(cpi);
|
2013-03-14 22:36:08 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// change includes all joint functionality
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_change_config(ptr, oxcf);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Initialize active best and worst q and average q values.
|
|
|
|
cpi->active_worst_quality = cpi->oxcf.worst_allowed_q;
|
|
|
|
cpi->active_best_quality = cpi->oxcf.best_allowed_q;
|
|
|
|
cpi->avg_frame_qindex = cpi->oxcf.worst_allowed_q;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Initialise the starting buffer levels
|
|
|
|
cpi->buffer_level = cpi->oxcf.starting_buffer_level;
|
|
|
|
cpi->bits_off_target = cpi->oxcf.starting_buffer_level;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->rolling_target_bits = cpi->av_per_frame_bandwidth;
|
|
|
|
cpi->rolling_actual_bits = cpi->av_per_frame_bandwidth;
|
|
|
|
cpi->long_rolling_target_bits = cpi->av_per_frame_bandwidth;
|
|
|
|
cpi->long_rolling_actual_bits = cpi->av_per_frame_bandwidth;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->total_actual_bits = 0;
|
|
|
|
cpi->total_target_vs_actual = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->static_mb_pct = 0;
|
2012-01-11 15:05:57 +01:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->lst_fb_idx = 0;
|
|
|
|
cpi->gld_fb_idx = 1;
|
|
|
|
cpi->alt_fb_idx = 2;
|
|
|
|
|
2013-02-08 20:33:11 +01:00
|
|
|
set_tile_limits(cpi);
|
[WIP] Add column-based tiling.
This patch adds column-based tiling. The idea is to make each tile
independently decodable (after reading the common frame header) and
also independendly encodable (minus within-frame cost adjustments in
the RD loop) to speed-up hardware & software en/decoders if they used
multi-threading. Column-based tiling has the added advantage (over
other tiling methods) that it minimizes realtime use-case latency,
since all threads can start encoding data as soon as the first SB-row
worth of data is available to the encoder.
There is some test code that does random tile ordering in the decoder,
to confirm that each tile is indeed independently decodable from other
tiles in the same frame. At tile edges, all contexts assume default
values (i.e. 0, 0 motion vector, no coefficients, DC intra4x4 mode),
and motion vector search and ordering do not cross tiles in the same
frame.
t log
Tile independence is not maintained between frames ATM, i.e. tile 0 of
frame 1 is free to use motion vectors that point into any tile of frame
0. We support 1 (i.e. no tiling), 2 or 4 column-tiles.
The loopfilter crosses tile boundaries. I discussed this briefly with Aki
and he says that's OK. An in-loop loopfilter would need to do some sync
between tile threads, but that shouldn't be a big issue.
Resuls: with tiling disabled, we go up slightly because of improved edge
use in the intra4x4 prediction. With 2 tiles, we lose about ~1% on derf,
~0.35% on HD and ~0.55% on STD/HD. With 4 tiles, we lose another ~1.5%
on derf ~0.77% on HD and ~0.85% on STD/HD. Most of this loss is
concentrated in the low-bitrate end of clips, and most of it is because
of the loss of edges at tile boundaries and the resulting loss of intra
predictors.
TODO:
- more tiles (perhaps allow row-based tiling also, and max. 8 tiles)?
- maybe optionally (for EC purposes), motion vectors themselves
should not cross tile edges, or we should emulate such borders as
if they were off-frame, to limit error propagation to within one
tile only. This doesn't have to be the default behaviour but could
be an optional bitstream flag.
Change-Id: I5951c3a0742a767b20bc9fb5af685d9892c2c96f
2013-02-01 18:35:28 +01:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->fixed_divide[0] = 0;
|
|
|
|
for (i = 1; i < 512; i++)
|
|
|
|
cpi->fixed_divide[i] = 0x80000 / i;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *)(ptr);
|
[WIP] Add column-based tiling.
This patch adds column-based tiling. The idea is to make each tile
independently decodable (after reading the common frame header) and
also independendly encodable (minus within-frame cost adjustments in
the RD loop) to speed-up hardware & software en/decoders if they used
multi-threading. Column-based tiling has the added advantage (over
other tiling methods) that it minimizes realtime use-case latency,
since all threads can start encoding data as soon as the first SB-row
worth of data is available to the encoder.
There is some test code that does random tile ordering in the decoder,
to confirm that each tile is indeed independently decodable from other
tiles in the same frame. At tile edges, all contexts assume default
values (i.e. 0, 0 motion vector, no coefficients, DC intra4x4 mode),
and motion vector search and ordering do not cross tiles in the same
frame.
t log
Tile independence is not maintained between frames ATM, i.e. tile 0 of
frame 1 is free to use motion vectors that point into any tile of frame
0. We support 1 (i.e. no tiling), 2 or 4 column-tiles.
The loopfilter crosses tile boundaries. I discussed this briefly with Aki
and he says that's OK. An in-loop loopfilter would need to do some sync
between tile threads, but that shouldn't be a big issue.
Resuls: with tiling disabled, we go up slightly because of improved edge
use in the intra4x4 prediction. With 2 tiles, we lose about ~1% on derf,
~0.35% on HD and ~0.55% on STD/HD. With 4 tiles, we lose another ~1.5%
on derf ~0.77% on HD and ~0.85% on STD/HD. Most of this loss is
concentrated in the low-bitrate end of clips, and most of it is because
of the loss of edges at tile boundaries and the resulting loss of intra
predictors.
TODO:
- more tiles (perhaps allow row-based tiling also, and max. 8 tiles)?
- maybe optionally (for EC purposes), motion vectors themselves
should not cross tile edges, or we should emulate such borders as
if they were off-frame, to limit error propagation to within one
tile only. This doesn't have to be the default behaviour but could
be an optional bitstream flag.
Change-Id: I5951c3a0742a767b20bc9fb5af685d9892c2c96f
2013-02-01 18:35:28 +01:00
|
|
|
VP9_COMMON *const cm = &cpi->common;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-27 22:22:30 +01:00
|
|
|
if (!cpi || !oxcf)
|
2012-07-14 00:21:29 +02:00
|
|
|
return;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
if (cm->version != oxcf->version) {
|
|
|
|
cm->version = oxcf->version;
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_setup_version(cm);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->oxcf = *oxcf;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
switch (cpi->oxcf.Mode) {
|
|
|
|
// Real time and one pass deprecated in test code base
|
2010-05-18 17:58:33 +02:00
|
|
|
case MODE_FIRSTPASS:
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->pass = 1;
|
|
|
|
cpi->compressor_speed = 1;
|
|
|
|
break;
|
2012-02-16 18:02:17 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
case MODE_SECONDPASS:
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->pass = 2;
|
|
|
|
cpi->compressor_speed = 1;
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5);
|
2012-07-14 00:21:29 +02:00
|
|
|
break;
|
2012-02-16 18:02:17 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
case MODE_SECONDPASS_BEST:
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->pass = 2;
|
|
|
|
cpi->compressor_speed = 0;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->oxcf.worst_allowed_q = q_trans[oxcf->worst_allowed_q];
|
|
|
|
cpi->oxcf.best_allowed_q = q_trans[oxcf->best_allowed_q];
|
|
|
|
cpi->oxcf.cq_level = q_trans[cpi->oxcf.cq_level];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->oxcf.lossless = oxcf->lossless;
|
|
|
|
if (cpi->oxcf.lossless) {
|
2013-05-20 19:03:17 +02:00
|
|
|
cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_iwalsh4x4_1_add;
|
|
|
|
cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_iwalsh4x4_add;
|
2013-02-20 16:27:35 +01:00
|
|
|
} else {
|
2013-05-20 19:03:17 +02:00
|
|
|
cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_idct4x4_1_add;
|
|
|
|
cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_idct4x4_add;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
Add lossless compression mode.
This commit adds lossless compression capability to the experimental
branch. The lossless experiment can be enabled using --enable-lossless
in configure. When the experiment is enabled, the encoder will use
lossless compression mode by command line option --lossless, and the
decoder automatically recognizes a losslessly encoded clip and decodes
accordingly.
To achieve the lossless coding, this commit has changed the following:
1. To encode at lossless mode, encoder forces the use of unit
quantizer, i.e, Q 0, where effective quantization is 1. Encoder also
disables the usage of 8x8 transform and allows only 4x4 transform;
2. At Q 0, the first order 4x4 DCT/IDCT have been switched over
to a pair of forward and inverse Walsh-Hadamard Transform
(http://goo.gl/EIsfy), with proper scaling applied to match the range
of the original 4x4 DCT/IDCT pair;
3. At Q 0, the second order remains to use the previous
walsh-hadamard transform pair. However, to maintain the reversibility
in second order transform at Q 0, scaling down is applied to first
order DC coefficients prior to forward transform, and scaling up is
applied to the second order output prior to quantization. Symmetric
upscaling and downscaling are added around inverse second order
transform;
4. At lossless mode, encoder also disables a number of minor
features to ensure no loss is introduced, these features includes:
a. Trellis quantization optimization
b. Loop filtering
c. Aggressive zero-binning, rounding and zero-bin boosting
d. Mode based zero-bin boosting
Lossless coding test was performed on all clips within the derf set,
to verify that the commit has achieved lossless compression for all
clips. The average compression ratio is around 2.57 to 1.
(http://goo.gl/dEShs)
Change-Id: Ia3aba7dd09df40dd590f93b9aba134defbc64e34
2012-06-14 04:03:31 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->baseline_gf_interval = DEFAULT_GF_INTERVAL;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// cpi->use_golden_frame_only = 0;
|
|
|
|
// cpi->use_last_frame_only = 0;
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_golden_frame = 0;
|
|
|
|
cpi->refresh_last_frame = 1;
|
2013-04-26 23:39:58 +02:00
|
|
|
cm->refresh_frame_context = 1;
|
2013-05-30 02:16:00 +02:00
|
|
|
cm->reset_frame_context = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
setup_features(cpi);
|
|
|
|
cpi->mb.e_mbd.allow_high_precision_mv = 0; // Default mv precision adaptation
|
2012-11-09 00:44:39 +01:00
|
|
|
set_mvcost(&cpi->mb);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
{
|
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < MAX_MB_SEGMENTS; i++)
|
|
|
|
cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At the moment the first order values may not be > MAXQ
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->oxcf.fixed_q = MIN(cpi->oxcf.fixed_q, MAXQ);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// local file playback mode == really big buffer
|
|
|
|
if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK) {
|
|
|
|
cpi->oxcf.starting_buffer_level = 60000;
|
|
|
|
cpi->oxcf.optimal_buffer_level = 60000;
|
|
|
|
cpi->oxcf.maximum_buffer_size = 240000;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert target bandwidth from Kbit/s to Bit/s
|
|
|
|
cpi->oxcf.target_bandwidth *= 1000;
|
|
|
|
|
2013-03-27 22:22:30 +01:00
|
|
|
cpi->oxcf.starting_buffer_level = rescale(cpi->oxcf.starting_buffer_level,
|
|
|
|
cpi->oxcf.target_bandwidth, 1000);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Set or reset optimal and maximum buffer levels.
|
|
|
|
if (cpi->oxcf.optimal_buffer_level == 0)
|
|
|
|
cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
|
|
|
|
else
|
2013-03-27 22:22:30 +01:00
|
|
|
cpi->oxcf.optimal_buffer_level = rescale(cpi->oxcf.optimal_buffer_level,
|
|
|
|
cpi->oxcf.target_bandwidth, 1000);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
if (cpi->oxcf.maximum_buffer_size == 0)
|
|
|
|
cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8;
|
|
|
|
else
|
2013-03-27 22:22:30 +01:00
|
|
|
cpi->oxcf.maximum_buffer_size = rescale(cpi->oxcf.maximum_buffer_size,
|
|
|
|
cpi->oxcf.target_bandwidth, 1000);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Set up frame rate and related parameters rate control values.
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_new_frame_rate(cpi, cpi->oxcf.frame_rate);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Set absolute upper and lower quality limits
|
2013-03-27 22:22:30 +01:00
|
|
|
cpi->worst_quality = cpi->oxcf.worst_allowed_q;
|
|
|
|
cpi->best_quality = cpi->oxcf.best_allowed_q;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// active values should only be modified if out of new range
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->active_worst_quality = clamp(cpi->active_worst_quality,
|
|
|
|
cpi->oxcf.best_allowed_q,
|
|
|
|
cpi->oxcf.worst_allowed_q);
|
|
|
|
|
|
|
|
cpi->active_best_quality = clamp(cpi->active_best_quality,
|
|
|
|
cpi->oxcf.best_allowed_q,
|
|
|
|
cpi->oxcf.worst_allowed_q);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->buffered_mode = cpi->oxcf.optimal_buffer_level > 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
cpi->cq_target_quality = cpi->oxcf.cq_level;
|
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
cm->mcomp_filter_type = cm->use_bilinear_mc_filter ? BILINEAR
|
|
|
|
: DEFAULT_INTERP_FILTER;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->target_bandwidth = cpi->oxcf.target_bandwidth;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
cm->display_width = cpi->oxcf.width;
|
|
|
|
cm->display_height = cpi->oxcf.height;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs)
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->oxcf.Sharpness = MIN(7, cpi->oxcf.Sharpness);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->sharpness_level = cpi->oxcf.Sharpness;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-07 00:52:06 +02:00
|
|
|
if (cpi->initial_width) {
|
|
|
|
// Increasing the size of the frame beyond the first seen frame, or some
|
|
|
|
// otherwise signalled maximum size, is not supported.
|
|
|
|
// TODO(jkoleszar): exit gracefully.
|
|
|
|
assert(cm->width <= cpi->initial_width);
|
|
|
|
assert(cm->height <= cpi->initial_height);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2013-02-06 23:22:17 +01:00
|
|
|
update_frame_size(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->oxcf.fixed_q >= 0) {
|
|
|
|
cpi->last_q[0] = cpi->oxcf.fixed_q;
|
|
|
|
cpi->last_q[1] = cpi->oxcf.fixed_q;
|
|
|
|
cpi->last_boosted_qindex = cpi->oxcf.fixed_q;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-08 23:35:42 +02:00
|
|
|
cpi->speed = cpi->oxcf.cpu_used;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->oxcf.lag_in_frames == 0) {
|
2013-04-02 19:24:56 +02:00
|
|
|
// force to allowlag to 0 if lag_in_frames is 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->oxcf.allow_lag = 0;
|
2013-04-02 19:24:56 +02:00
|
|
|
} else if (cpi->oxcf.lag_in_frames > MAX_LAG_BUFFERS) {
|
|
|
|
// Limit on lag buffers as these are not currently dynamically allocated
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->oxcf.lag_in_frames = MAX_LAG_BUFFERS;
|
2013-04-02 19:24:56 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// YX Temp
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
vp9_zero(cpi->alt_ref_source);
|
|
|
|
#else
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->alt_ref_source = NULL;
|
2013-04-03 00:08:50 +02:00
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->is_src_frame_alt_ref = 0;
|
2011-05-11 04:57:51 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#if 0
|
2012-07-14 00:21:29 +02:00
|
|
|
// Experimental RD Code
|
|
|
|
cpi->frame_distortion = 0;
|
|
|
|
cpi->last_frame_distortion = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2013-02-08 20:33:11 +01:00
|
|
|
set_tile_limits(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define M_LOG2_E 0.693147180559945309417
|
|
|
|
#define log2f(x) (log (x) / (float) M_LOG2_E)
|
2012-07-26 22:42:07 +02:00
|
|
|
|
|
|
|
static void cal_nmvjointsadcost(int *mvjointsadcost) {
|
|
|
|
mvjointsadcost[0] = 600;
|
|
|
|
mvjointsadcost[1] = 300;
|
|
|
|
mvjointsadcost[2] = 300;
|
|
|
|
mvjointsadcost[0] = 300;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cal_nmvsadcosts(int *mvsadcost[2]) {
|
|
|
|
int i = 1;
|
|
|
|
|
2013-03-27 22:22:30 +01:00
|
|
|
mvsadcost[0][0] = 0;
|
|
|
|
mvsadcost[1][0] = 0;
|
2012-07-26 22:42:07 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
double z = 256 * (2 * (log2f(8 * i) + .6));
|
2013-03-27 22:22:30 +01:00
|
|
|
mvsadcost[0][i] = (int)z;
|
|
|
|
mvsadcost[1][i] = (int)z;
|
|
|
|
mvsadcost[0][-i] = (int)z;
|
|
|
|
mvsadcost[1][-i] = (int)z;
|
2012-07-26 22:42:07 +02:00
|
|
|
} while (++i <= MV_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cal_nmvsadcosts_hp(int *mvsadcost[2]) {
|
|
|
|
int i = 1;
|
|
|
|
|
2013-03-27 22:22:30 +01:00
|
|
|
mvsadcost[0][0] = 0;
|
|
|
|
mvsadcost[1][0] = 0;
|
2012-07-26 22:42:07 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
double z = 256 * (2 * (log2f(8 * i) + .6));
|
2013-03-27 22:22:30 +01:00
|
|
|
mvsadcost[0][i] = (int)z;
|
|
|
|
mvsadcost[1][i] = (int)z;
|
|
|
|
mvsadcost[0][-i] = (int)z;
|
|
|
|
mvsadcost[1][-i] = (int)z;
|
2012-07-26 22:42:07 +02:00
|
|
|
} while (++i <= MV_MAX);
|
|
|
|
}
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
|
|
|
volatile union {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi;
|
|
|
|
VP9_PTR ptr;
|
2012-07-14 00:21:29 +02:00
|
|
|
} ctx;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi;
|
|
|
|
VP9_COMMON *cm;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
cpi = ctx.cpi = vpx_memalign(32, sizeof(VP9_COMP));
|
2012-07-14 00:21:29 +02:00
|
|
|
// Check that the CPI instance is valid
|
|
|
|
if (!cpi)
|
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cm = &cpi->common;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
vpx_memset(cpi, 0, sizeof(VP9_COMP));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (setjmp(cm->error.jmp)) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_PTR ptr = ctx.ptr;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
ctx.cpi->common.error.setjmp = 0;
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_remove_compressor(&ptr);
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpi->common.error.setjmp = 1;
|
|
|
|
|
|
|
|
CHECK_MEM_ERROR(cpi->mb.ss, vpx_calloc(sizeof(search_site), (MAX_MVSEARCH_STEPS * 8) + 1));
|
|
|
|
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_create_common(&cpi->common);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
init_config((VP9_PTR)cpi, oxcf);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2012-10-31 01:12:12 +01:00
|
|
|
memcpy(cpi->base_skip_false_prob, base_skip_false_prob, sizeof(base_skip_false_prob));
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->common.current_video_frame = 0;
|
|
|
|
cpi->kf_overspend_bits = 0;
|
|
|
|
cpi->kf_bitrate_adjustment = 0;
|
2013-04-03 00:08:50 +02:00
|
|
|
cpi->frames_till_gf_update_due = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->gf_overspend_bits = 0;
|
2013-04-03 00:08:50 +02:00
|
|
|
cpi->non_gf_bitrate_adjustment = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->prob_last_coded = 128;
|
|
|
|
cm->prob_gf_coded = 128;
|
|
|
|
cm->prob_intra_coded = 63;
|
|
|
|
for (i = 0; i < COMP_PRED_CONTEXTS; i++)
|
|
|
|
cm->prob_comppred[i] = 128;
|
32x32 transform for superblocks.
This adds Debargha's DCT/DWT hybrid and a regular 32x32 DCT, and adds
code all over the place to wrap that in the bitstream/encoder/decoder/RD.
Some implementation notes (these probably need careful review):
- token range is extended by 1 bit, since the value range out of this
transform is [-16384,16383].
- the coefficients coming out of the FDCT are manually scaled back by
1 bit, or else they won't fit in int16_t (they are 17 bits). Because
of this, the RD error scoring does not right-shift the MSE score by
two (unlike for 4x4/8x8/16x16).
- to compensate for this loss in precision, the quantizer is halved
also. This is currently a little hacky.
- FDCT and IDCT is double-only right now. Needs a fixed-point impl.
- There are no default probabilities for the 32x32 transform yet; I'm
simply using the 16x16 luma ones. A future commit will add newly
generated probabilities for all transforms.
- No ADST version. I don't think we'll add one for this level; if an
ADST is desired, transform-size selection can scale back to 16x16
or lower, and use an ADST at that level.
Additional notes specific to Debargha's DWT/DCT hybrid:
- coefficient scale is different for the top/left 16x16 (DCT-over-DWT)
block than for the rest (DWT pixel differences) of the block. Therefore,
RD error scoring isn't easily scalable between coefficient and pixel
domain. Thus, unfortunately, we need to compute the RD distortion in
the pixel domain until we figure out how to scale these appropriately.
Change-Id: I00386f20f35d7fabb19aba94c8162f8aee64ef2b
2012-12-07 23:45:05 +01:00
|
|
|
for (i = 0; i < TX_SIZE_MAX_SB - 1; i++)
|
2012-10-09 18:18:21 +02:00
|
|
|
cm->prob_tx[i] = 128;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
// Prime the recent reference frame usage counters.
|
2012-07-14 00:21:29 +02:00
|
|
|
// Hereafter they will be maintained as a sort of moving average
|
|
|
|
cpi->recent_ref_frame_usage[INTRA_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[LAST_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[GOLDEN_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[ALTREF_FRAME] = 1;
|
|
|
|
|
|
|
|
// Set reference frame sign bias for ALTREF frame to 1 (for now)
|
|
|
|
cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1;
|
|
|
|
|
|
|
|
cpi->baseline_gf_interval = DEFAULT_GF_INTERVAL;
|
|
|
|
|
|
|
|
cpi->gold_is_last = 0;
|
|
|
|
cpi->alt_is_last = 0;
|
|
|
|
cpi->gold_is_alt = 0;
|
|
|
|
|
|
|
|
// Create the encoder segmentation map and set all entries to 0
|
2013-04-26 20:57:17 +02:00
|
|
|
CHECK_MEM_ERROR(cpi->segmentation_map,
|
|
|
|
vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols, 1));
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// And a copy in common for temporal coding
|
|
|
|
CHECK_MEM_ERROR(cm->last_frame_seg_map,
|
2013-04-26 20:57:17 +02:00
|
|
|
vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols, 1));
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// And a place holder structure is the coding context
|
|
|
|
// for use if we want to save and restore it
|
|
|
|
CHECK_MEM_ERROR(cpi->coding_context.last_frame_seg_map_copy,
|
2013-04-26 20:57:17 +02:00
|
|
|
vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols, 1));
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
CHECK_MEM_ERROR(cpi->active_map, vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols, 1));
|
|
|
|
vpx_memset(cpi->active_map, 1, (cpi->common.mb_rows * cpi->common.mb_cols));
|
|
|
|
cpi->active_map_enabled = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < (sizeof(cpi->mbgraph_stats) /
|
|
|
|
sizeof(cpi->mbgraph_stats[0])); i++) {
|
|
|
|
CHECK_MEM_ERROR(cpi->mbgraph_stats[i].mb_stats,
|
|
|
|
vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols *
|
|
|
|
sizeof(*cpi->mbgraph_stats[i].mb_stats),
|
|
|
|
1));
|
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#ifdef ENTROPY_STATS
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->pass != 1)
|
|
|
|
init_context_counters();
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2013-05-16 14:40:32 +02:00
|
|
|
|
2012-07-26 22:42:07 +02:00
|
|
|
#ifdef NMV_STATS
|
|
|
|
init_nmvstats();
|
2012-05-15 01:21:01 +02:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/*Initialize the feed-forward activity masking.*/
|
|
|
|
cpi->activity_avg = 90 << 12;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->frames_since_key = 8; // Give a sensible default for the first frame.
|
|
|
|
cpi->key_frame_frequency = cpi->oxcf.key_freq;
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->this_key_frame_forced = 0;
|
|
|
|
cpi->next_key_frame_forced = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->source_alt_ref_pending = 0;
|
|
|
|
cpi->source_alt_ref_active = 0;
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_alt_ref_frame = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
// Turn multiple ARF usage on/off. This is a quick hack for the initial test
|
|
|
|
// version. It should eventually be set via the codec API.
|
|
|
|
cpi->multi_arf_enabled = 1;
|
|
|
|
|
|
|
|
if (cpi->multi_arf_enabled) {
|
|
|
|
cpi->sequence_number = 0;
|
|
|
|
cpi->frame_coding_order_period = 0;
|
|
|
|
vp9_zero(cpi->frame_coding_order);
|
|
|
|
vp9_zero(cpi->arf_buffer_idx);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS;
|
2011-04-29 18:37:59 +02:00
|
|
|
#if CONFIG_INTERNAL_STATS
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->b_calculate_ssimg = 0;
|
|
|
|
|
|
|
|
cpi->count = 0;
|
|
|
|
cpi->bytes = 0;
|
|
|
|
|
|
|
|
if (cpi->b_calculate_psnr) {
|
|
|
|
cpi->total_sq_error = 0.0;
|
|
|
|
cpi->total_sq_error2 = 0.0;
|
|
|
|
cpi->total_y = 0.0;
|
|
|
|
cpi->total_u = 0.0;
|
|
|
|
cpi->total_v = 0.0;
|
|
|
|
cpi->total = 0.0;
|
|
|
|
cpi->totalp_y = 0.0;
|
|
|
|
cpi->totalp_u = 0.0;
|
|
|
|
cpi->totalp_v = 0.0;
|
|
|
|
cpi->totalp = 0.0;
|
|
|
|
cpi->tot_recode_hits = 0;
|
|
|
|
cpi->summed_quality = 0;
|
|
|
|
cpi->summed_weights = 0;
|
2013-04-01 18:10:27 +02:00
|
|
|
cpi->summedp_quality = 0;
|
|
|
|
cpi->summedp_weights = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->b_calculate_ssimg) {
|
|
|
|
cpi->total_ssimg_y = 0;
|
|
|
|
cpi->total_ssimg_u = 0;
|
|
|
|
cpi->total_ssimg_v = 0;
|
|
|
|
cpi->total_ssimg_all = 0;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-31 18:37:45 +02:00
|
|
|
#endif
|
|
|
|
|
2013-01-14 20:49:30 +01:00
|
|
|
cpi->first_time_stamp_ever = INT64_MAX;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->frames_till_gf_update_due = 0;
|
|
|
|
cpi->key_frame_count = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->ni_av_qi = cpi->oxcf.worst_allowed_q;
|
|
|
|
cpi->ni_tot_qi = 0;
|
|
|
|
cpi->ni_frames = 0;
|
|
|
|
cpi->tot_q = 0.0;
|
2012-10-30 20:58:42 +01:00
|
|
|
cpi->avg_q = vp9_convert_qindex_to_q(cpi->oxcf.worst_allowed_q);
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->total_byte_count = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->rate_correction_factor = 1.0;
|
|
|
|
cpi->key_frame_rate_correction_factor = 1.0;
|
|
|
|
cpi->gf_rate_correction_factor = 1.0;
|
|
|
|
cpi->twopass.est_max_qcorrection_factor = 1.0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-26 22:42:07 +02:00
|
|
|
cal_nmvjointsadcost(cpi->mb.nmvjointsadcost);
|
|
|
|
cpi->mb.nmvcost[0] = &cpi->mb.nmvcosts[0][MV_MAX];
|
|
|
|
cpi->mb.nmvcost[1] = &cpi->mb.nmvcosts[1][MV_MAX];
|
|
|
|
cpi->mb.nmvsadcost[0] = &cpi->mb.nmvsadcosts[0][MV_MAX];
|
|
|
|
cpi->mb.nmvsadcost[1] = &cpi->mb.nmvsadcosts[1][MV_MAX];
|
|
|
|
cal_nmvsadcosts(cpi->mb.nmvsadcost);
|
|
|
|
|
|
|
|
cpi->mb.nmvcost_hp[0] = &cpi->mb.nmvcosts_hp[0][MV_MAX];
|
|
|
|
cpi->mb.nmvcost_hp[1] = &cpi->mb.nmvcosts_hp[1][MV_MAX];
|
|
|
|
cpi->mb.nmvsadcost_hp[0] = &cpi->mb.nmvsadcosts_hp[0][MV_MAX];
|
|
|
|
cpi->mb.nmvsadcost_hp[1] = &cpi->mb.nmvsadcosts_hp[1][MV_MAX];
|
|
|
|
cal_nmvsadcosts_hp(cpi->mb.nmvsadcost_hp);
|
2012-02-27 19:22:38 +01:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
for (i = 0; i < KEY_FRAME_CONTEXT; i++)
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->prior_key_frame_distance[i] = (int)cpi->output_frame_rate;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#ifdef OUTPUT_YUV_SRC
|
2012-07-14 00:21:29 +02:00
|
|
|
yuv_file = fopen("bd.yuv", "ab");
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2011-02-14 23:18:18 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
2012-07-14 00:21:29 +02:00
|
|
|
yuv_rec_file = fopen("rec.yuv", "wb");
|
2011-02-14 23:18:18 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if 0
|
2012-07-14 00:21:29 +02:00
|
|
|
framepsnr = fopen("framepsnr.stt", "a");
|
|
|
|
kf_list = fopen("kf_list.stt", "w");
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->output_pkt_list = oxcf->output_pkt_list;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->pass == 1) {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_init_first_pass(cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
} else if (cpi->pass == 2) {
|
|
|
|
size_t packet_sz = sizeof(FIRSTPASS_STATS);
|
2012-11-05 23:22:59 +01:00
|
|
|
int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf;
|
|
|
|
cpi->twopass.stats_in = cpi->twopass.stats_in_start;
|
|
|
|
cpi->twopass.stats_in_end = (void *)((char *)cpi->twopass.stats_in
|
|
|
|
+ (packets - 1) * packet_sz);
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_init_second_pass(cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_set_speed_features(cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Set starting values of RD threshold multipliers (128 = *1)
|
2013-04-02 19:24:56 +02:00
|
|
|
for (i = 0; i < MAX_MODES; i++)
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->rd_thresh_mult[i] = 128;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-07 18:45:28 +02:00
|
|
|
#define BFP(BT, SDF, VF, SVF, SVAF, SVFHH, SVFHV, SVFHHV, SDX3F, SDX8F, SDX4DF)\
|
2012-10-22 05:47:57 +02:00
|
|
|
cpi->fn_ptr[BT].sdf = SDF; \
|
|
|
|
cpi->fn_ptr[BT].vf = VF; \
|
|
|
|
cpi->fn_ptr[BT].svf = SVF; \
|
2013-05-07 18:45:28 +02:00
|
|
|
cpi->fn_ptr[BT].svaf = SVAF; \
|
2012-10-22 05:47:57 +02:00
|
|
|
cpi->fn_ptr[BT].svf_halfpix_h = SVFHH; \
|
|
|
|
cpi->fn_ptr[BT].svf_halfpix_v = SVFHV; \
|
|
|
|
cpi->fn_ptr[BT].svf_halfpix_hv = SVFHHV; \
|
|
|
|
cpi->fn_ptr[BT].sdx3f = SDX3F; \
|
|
|
|
cpi->fn_ptr[BT].sdx8f = SDX8F; \
|
|
|
|
cpi->fn_ptr[BT].sdx4df = SDX4DF;
|
|
|
|
|
2013-04-15 19:00:34 +02:00
|
|
|
BFP(BLOCK_32X16, vp9_sad32x16, vp9_variance32x16, vp9_sub_pixel_variance32x16,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance32x16, NULL, NULL,
|
2013-04-15 19:00:34 +02:00
|
|
|
NULL, NULL, NULL,
|
|
|
|
vp9_sad32x16x4d)
|
|
|
|
|
|
|
|
BFP(BLOCK_16X32, vp9_sad16x32, vp9_variance16x32, vp9_sub_pixel_variance16x32,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance16x32, NULL, NULL,
|
2013-04-15 19:00:34 +02:00
|
|
|
NULL, NULL, NULL,
|
|
|
|
vp9_sad16x32x4d)
|
|
|
|
|
|
|
|
BFP(BLOCK_64X32, vp9_sad64x32, vp9_variance64x32, vp9_sub_pixel_variance64x32,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance64x32, NULL, NULL,
|
2013-04-15 19:00:34 +02:00
|
|
|
NULL, NULL, NULL,
|
|
|
|
vp9_sad64x32x4d)
|
|
|
|
|
|
|
|
BFP(BLOCK_32X64, vp9_sad32x64, vp9_variance32x64, vp9_sub_pixel_variance32x64,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance32x64, NULL, NULL,
|
2013-04-15 19:00:34 +02:00
|
|
|
NULL, NULL, NULL,
|
|
|
|
vp9_sad32x64x4d)
|
2012-10-22 05:47:57 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
BFP(BLOCK_32X32, vp9_sad32x32, vp9_variance32x32, vp9_sub_pixel_variance32x32,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance32x32, vp9_variance_halfpixvar32x32_h,
|
|
|
|
vp9_variance_halfpixvar32x32_v,
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_variance_halfpixvar32x32_hv, vp9_sad32x32x3, vp9_sad32x32x8,
|
|
|
|
vp9_sad32x32x4d)
|
2013-01-06 03:20:25 +01:00
|
|
|
|
|
|
|
BFP(BLOCK_64X64, vp9_sad64x64, vp9_variance64x64, vp9_sub_pixel_variance64x64,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance64x64, vp9_variance_halfpixvar64x64_h,
|
|
|
|
vp9_variance_halfpixvar64x64_v,
|
2013-01-06 03:20:25 +01:00
|
|
|
vp9_variance_halfpixvar64x64_hv, vp9_sad64x64x3, vp9_sad64x64x8,
|
|
|
|
vp9_sad64x64x4d)
|
2012-08-20 23:43:34 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
BFP(BLOCK_16X16, vp9_sad16x16, vp9_variance16x16, vp9_sub_pixel_variance16x16,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance16x16, vp9_variance_halfpixvar16x16_h,
|
|
|
|
vp9_variance_halfpixvar16x16_v,
|
|
|
|
vp9_variance_halfpixvar16x16_hv, vp9_sad16x16x3, vp9_sad16x16x8,
|
|
|
|
vp9_sad16x16x4d)
|
2012-10-22 05:47:57 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
BFP(BLOCK_16X8, vp9_sad16x8, vp9_variance16x8, vp9_sub_pixel_variance16x8,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance16x8, NULL, NULL, NULL,
|
|
|
|
vp9_sad16x8x3, vp9_sad16x8x8, vp9_sad16x8x4d)
|
2012-10-22 05:47:57 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
BFP(BLOCK_8X16, vp9_sad8x16, vp9_variance8x16, vp9_sub_pixel_variance8x16,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance8x16, NULL, NULL, NULL,
|
|
|
|
vp9_sad8x16x3, vp9_sad8x16x8, vp9_sad8x16x4d)
|
2012-10-22 05:47:57 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
BFP(BLOCK_8X8, vp9_sad8x8, vp9_variance8x8, vp9_sub_pixel_variance8x8,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance8x8, NULL, NULL, NULL,
|
|
|
|
vp9_sad8x8x3, vp9_sad8x8x8, vp9_sad8x8x4d)
|
2012-10-22 05:47:57 +02:00
|
|
|
|
2013-05-15 21:19:59 +02:00
|
|
|
BFP(BLOCK_8X4, vp9_sad8x4, vp9_variance8x4, vp9_sub_pixel_variance8x4,
|
|
|
|
vp9_sub_pixel_avg_variance8x4, NULL, NULL,
|
2013-05-22 06:28:42 +02:00
|
|
|
NULL, NULL, vp9_sad8x4x8,
|
2013-05-15 21:19:59 +02:00
|
|
|
vp9_sad8x4x4d)
|
2013-05-05 07:09:43 +02:00
|
|
|
|
2013-05-15 21:19:59 +02:00
|
|
|
BFP(BLOCK_4X8, vp9_sad4x8, vp9_variance4x8, vp9_sub_pixel_variance4x8,
|
|
|
|
vp9_sub_pixel_avg_variance4x8, NULL, NULL,
|
2013-05-22 06:28:42 +02:00
|
|
|
NULL, NULL, vp9_sad4x8x8,
|
2013-05-15 21:19:59 +02:00
|
|
|
vp9_sad4x8x4d)
|
2013-05-05 07:09:43 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
BFP(BLOCK_4X4, vp9_sad4x4, vp9_variance4x4, vp9_sub_pixel_variance4x4,
|
2013-05-07 18:45:28 +02:00
|
|
|
vp9_sub_pixel_avg_variance4x4, NULL, NULL, NULL,
|
|
|
|
vp9_sad4x4x3, vp9_sad4x4x8, vp9_sad4x4x4d)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-11-06 01:58:03 +01:00
|
|
|
cpi->full_search_sad = vp9_full_search_sad;
|
|
|
|
cpi->diamond_search_sad = vp9_diamond_search_sad;
|
|
|
|
cpi->refining_search_sad = vp9_refining_search_sad;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// make sure frame 1 is okay
|
|
|
|
cpi->error_bins[0] = cpi->common.MBs;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 22:25:33 +01:00
|
|
|
/* vp9_init_quantizer() is first called here. Add check in
|
|
|
|
* vp9_frame_init_quantizer() so that vp9_init_quantizer is only
|
|
|
|
* called later when needed. This will avoid unnecessary calls of
|
|
|
|
* vp9_init_quantizer() for every frame.
|
|
|
|
*/
|
|
|
|
vp9_init_quantizer(cpi);
|
2011-07-20 21:53:42 +02:00
|
|
|
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_loop_filter_init(cm);
|
2011-07-20 21:53:42 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->common.error.setjmp = 0;
|
2011-12-08 20:43:09 +01:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_zero(cpi->y_uv_mode_count)
|
2011-12-08 20:43:09 +01:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
return (VP9_PTR) cpi;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
void vp9_remove_compressor(VP9_PTR *ptr) {
|
|
|
|
VP9_COMP *cpi = (VP9_COMP *)(*ptr);
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (!cpi)
|
|
|
|
return;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi && (cpi->common.current_video_frame > 0)) {
|
|
|
|
if (cpi->pass == 2) {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_end_second_pass(cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#ifdef ENTROPY_STATS
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->pass != 1) {
|
|
|
|
print_context_counters();
|
|
|
|
print_tree_update_probs();
|
2013-05-16 12:27:12 +02:00
|
|
|
print_mode_context(cpi);
|
2012-05-08 21:38:39 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2012-07-26 22:42:07 +02:00
|
|
|
#ifdef NMV_STATS
|
|
|
|
if (cpi->pass != 1)
|
|
|
|
print_nmvstats();
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-04-29 18:37:59 +02:00
|
|
|
#if CONFIG_INTERNAL_STATS
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state();
|
2012-02-29 02:11:12 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count);
|
|
|
|
if (cpi->pass != 1) {
|
|
|
|
FILE *f = fopen("opsnr.stt", "a");
|
|
|
|
double time_encoded = (cpi->last_end_time_stamp_seen
|
|
|
|
- cpi->first_time_stamp_ever) / 10000000.000;
|
|
|
|
double total_encode_time = (cpi->time_receive_data + cpi->time_compress_data) / 1000.000;
|
|
|
|
double dr = (double)cpi->bytes * (double) 8 / (double)1000 / time_encoded;
|
2013-05-16 14:40:32 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->b_calculate_psnr) {
|
2013-01-15 22:49:44 +01:00
|
|
|
YV12_BUFFER_CONFIG *lst_yv12 =
|
2013-02-22 20:22:03 +01:00
|
|
|
&cpi->common.yv12_fb[cpi->common.ref_frame_map[cpi->lst_fb_idx]];
|
2013-04-01 18:10:27 +02:00
|
|
|
double samples = 3.0 / 2 * cpi->count *
|
|
|
|
lst_yv12->y_width * lst_yv12->y_height;
|
2012-10-30 20:58:42 +01:00
|
|
|
double total_psnr = vp9_mse2psnr(samples, 255.0, cpi->total_sq_error);
|
|
|
|
double total_psnr2 = vp9_mse2psnr(samples, 255.0, cpi->total_sq_error2);
|
2013-04-01 18:10:27 +02:00
|
|
|
double total_ssim = 100 * pow(cpi->summed_quality /
|
|
|
|
cpi->summed_weights, 8.0);
|
|
|
|
double total_ssimp = 100 * pow(cpi->summedp_quality /
|
|
|
|
cpi->summedp_weights, 8.0);
|
|
|
|
|
|
|
|
fprintf(f, "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t"
|
|
|
|
"VPXSSIM\tVPSSIMP\t Time(ms)\n");
|
|
|
|
fprintf(f, "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%8.0f\n",
|
|
|
|
dr, cpi->total / cpi->count, total_psnr,
|
|
|
|
cpi->totalp / cpi->count, total_psnr2, total_ssim, total_ssimp,
|
2012-07-14 00:21:29 +02:00
|
|
|
total_encode_time);
|
2013-04-01 18:10:27 +02:00
|
|
|
// fprintf(f, "%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%8.0f %10ld\n",
|
|
|
|
// dr, cpi->total / cpi->count, total_psnr,
|
|
|
|
// cpi->totalp / cpi->count, total_psnr2, total_ssim,
|
|
|
|
// total_encode_time, cpi->tot_recode_hits);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->b_calculate_ssimg) {
|
2012-08-11 02:05:46 +02:00
|
|
|
fprintf(f, "BitRate\tSSIM_Y\tSSIM_U\tSSIM_V\tSSIM_A\t Time(ms)\n");
|
|
|
|
fprintf(f, "%7.2f\t%6.4f\t%6.4f\t%6.4f\t%6.4f\t%8.0f\n", dr,
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->total_ssimg_y / cpi->count, cpi->total_ssimg_u / cpi->count,
|
|
|
|
cpi->total_ssimg_v / cpi->count, cpi->total_ssimg_all / cpi->count, total_encode_time);
|
2012-01-11 15:05:57 +01:00
|
|
|
// fprintf(f, "%7.3f\t%6.4f\t%6.4f\t%6.4f\t%6.4f\t%8.0f %10ld\n", dr,
|
|
|
|
// cpi->total_ssimg_y / cpi->count, cpi->total_ssimg_u / cpi->count,
|
|
|
|
// cpi->total_ssimg_v / cpi->count, cpi->total_ssimg_all / cpi->count, total_encode_time, cpi->tot_recode_hits);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fclose(f);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENTROPY_STATS
|
2012-07-14 00:21:29 +02:00
|
|
|
{
|
|
|
|
int i, j, k;
|
2012-11-27 22:59:17 +01:00
|
|
|
FILE *fmode = fopen("vp9_modecontext.c", "w");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-11-27 22:59:17 +01:00
|
|
|
fprintf(fmode, "\n#include \"vp9_entropymode.h\"\n\n");
|
2012-10-31 22:40:53 +01:00
|
|
|
fprintf(fmode, "const unsigned int vp9_kf_default_bmode_counts ");
|
2013-05-31 01:21:48 +02:00
|
|
|
fprintf(fmode, "[VP9_INTRA_MODES][VP9_INTRA_MODES]"
|
|
|
|
"[VP9_INTRA_MODES] =\n{\n");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-31 01:21:48 +02:00
|
|
|
for (i = 0; i < VP9_INTRA_MODES; i++) {
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fprintf(fmode, " { // Above Mode : %d\n", i);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-31 01:21:48 +02:00
|
|
|
for (j = 0; j < VP9_INTRA_MODES; j++) {
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fprintf(fmode, " {");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-31 01:21:48 +02:00
|
|
|
for (k = 0; k < VP9_INTRA_MODES; k++) {
|
2012-07-14 00:21:29 +02:00
|
|
|
if (!intra_mode_stats[i][j][k])
|
|
|
|
fprintf(fmode, " %5d, ", 1);
|
|
|
|
else
|
|
|
|
fprintf(fmode, " %5d, ", intra_mode_stats[i][j][k]);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fprintf(fmode, "}, // left_mode %d\n", j);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fprintf(fmode, " },\n");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fprintf(fmode, "};\n");
|
|
|
|
fclose(fmode);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(SECTIONBITS_OUTPUT)
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (0) {
|
|
|
|
int i;
|
|
|
|
FILE *f = fopen("tokenbits.stt", "a");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 28; i++)
|
|
|
|
fprintf(f, "%8d", (int)(Sectionbits[i] / 256));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fprintf(f, "\n");
|
|
|
|
fclose(f);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
2012-07-14 00:21:29 +02:00
|
|
|
{
|
|
|
|
printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000);
|
|
|
|
printf("\n_frames recive_data encod_mb_row compress_frame Total\n");
|
|
|
|
printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, cpi->time_receive_data / 1000, cpi->time_encode_mb_row / 1000, cpi->time_compress_data / 1000, (cpi->time_receive_data + cpi->time_compress_data) / 1000);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
dealloc_compressor_data(cpi);
|
|
|
|
vpx_free(cpi->mb.ss);
|
|
|
|
vpx_free(cpi->tok);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); i++) {
|
|
|
|
vpx_free(cpi->mbgraph_stats[i].mb_stats);
|
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_remove_common(&cpi->common);
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_free(cpi);
|
|
|
|
*ptr = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#ifdef OUTPUT_YUV_SRC
|
2012-07-14 00:21:29 +02:00
|
|
|
fclose(yuv_file);
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2011-02-14 23:18:18 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
2012-07-14 00:21:29 +02:00
|
|
|
fclose(yuv_rec_file);
|
2011-02-14 23:18:18 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (keyfile)
|
|
|
|
fclose(keyfile);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (framepsnr)
|
|
|
|
fclose(framepsnr);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (kf_list)
|
|
|
|
fclose(kf_list);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
static uint64_t calc_plane_error(uint8_t *orig, int orig_stride,
|
|
|
|
uint8_t *recon, int recon_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
unsigned int cols, unsigned int rows) {
|
2012-07-14 00:21:29 +02:00
|
|
|
unsigned int row, col;
|
|
|
|
uint64_t total_sse = 0;
|
|
|
|
int diff;
|
|
|
|
|
|
|
|
for (row = 0; row + 16 <= rows; row += 16) {
|
|
|
|
for (col = 0; col + 16 <= cols; col += 16) {
|
|
|
|
unsigned int sse;
|
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_mse16x16(orig + col, orig_stride, recon + col, recon_stride, &sse);
|
2012-07-14 00:21:29 +02:00
|
|
|
total_sse += sse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle odd-sized width */
|
|
|
|
if (col < cols) {
|
2012-12-19 00:31:19 +01:00
|
|
|
unsigned int border_row, border_col;
|
|
|
|
uint8_t *border_orig = orig;
|
|
|
|
uint8_t *border_recon = recon;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
for (border_row = 0; border_row < 16; border_row++) {
|
|
|
|
for (border_col = col; border_col < cols; border_col++) {
|
|
|
|
diff = border_orig[border_col] - border_recon[border_col];
|
|
|
|
total_sse += diff * diff;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
border_orig += orig_stride;
|
|
|
|
border_recon += recon_stride;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
orig += orig_stride * 16;
|
|
|
|
recon += recon_stride * 16;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/* Handle odd-sized height */
|
|
|
|
for (; row < rows; row++) {
|
|
|
|
for (col = 0; col < cols; col++) {
|
|
|
|
diff = orig[col] - recon[col];
|
|
|
|
total_sse += diff * diff;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
orig += orig_stride;
|
|
|
|
recon += recon_stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
return total_sse;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void generate_psnr_packet(VP9_COMP *cpi) {
|
2012-07-14 00:21:29 +02:00
|
|
|
YV12_BUFFER_CONFIG *orig = cpi->Source;
|
|
|
|
YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
|
|
|
|
struct vpx_codec_cx_pkt pkt;
|
|
|
|
uint64_t sse;
|
|
|
|
int i;
|
2013-03-21 00:41:30 +01:00
|
|
|
unsigned int width = cpi->common.width;
|
|
|
|
unsigned int height = cpi->common.height;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
pkt.kind = VPX_CODEC_PSNR_PKT;
|
|
|
|
sse = calc_plane_error(orig->y_buffer, orig->y_stride,
|
|
|
|
recon->y_buffer, recon->y_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
width, height);
|
2012-07-14 00:21:29 +02:00
|
|
|
pkt.data.psnr.sse[0] = sse;
|
|
|
|
pkt.data.psnr.sse[1] = sse;
|
|
|
|
pkt.data.psnr.samples[0] = width * height;
|
|
|
|
pkt.data.psnr.samples[1] = width * height;
|
|
|
|
|
2013-05-09 01:19:56 +02:00
|
|
|
width = orig->uv_width;
|
|
|
|
height = orig->uv_height;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
sse = calc_plane_error(orig->u_buffer, orig->uv_stride,
|
|
|
|
recon->u_buffer, recon->uv_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
width, height);
|
2012-07-14 00:21:29 +02:00
|
|
|
pkt.data.psnr.sse[0] += sse;
|
|
|
|
pkt.data.psnr.sse[2] = sse;
|
|
|
|
pkt.data.psnr.samples[0] += width * height;
|
|
|
|
pkt.data.psnr.samples[2] = width * height;
|
|
|
|
|
|
|
|
sse = calc_plane_error(orig->v_buffer, orig->uv_stride,
|
|
|
|
recon->v_buffer, recon->uv_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
width, height);
|
2012-07-14 00:21:29 +02:00
|
|
|
pkt.data.psnr.sse[0] += sse;
|
|
|
|
pkt.data.psnr.sse[3] = sse;
|
|
|
|
pkt.data.psnr.samples[0] += width * height;
|
|
|
|
pkt.data.psnr.samples[3] = width * height;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
2012-10-30 20:58:42 +01:00
|
|
|
pkt.data.psnr.psnr[i] = vp9_mse2psnr(pkt.data.psnr.samples[i], 255.0,
|
2012-11-05 23:22:59 +01:00
|
|
|
(double)pkt.data.psnr.sse[i]);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_use_as_reference(VP9_PTR ptr, int ref_frame_flags) {
|
|
|
|
VP9_COMP *cpi = (VP9_COMP *)(ptr);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (ref_frame_flags > 7)
|
|
|
|
return -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->ref_frame_flags = ref_frame_flags;
|
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_update_reference(VP9_PTR ptr, int ref_frame_flags) {
|
|
|
|
VP9_COMP *cpi = (VP9_COMP *)(ptr);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (ref_frame_flags > 7)
|
|
|
|
return -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_golden_frame = 0;
|
|
|
|
cpi->refresh_alt_ref_frame = 0;
|
|
|
|
cpi->refresh_last_frame = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (ref_frame_flags & VP9_LAST_FLAG)
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_last_frame = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (ref_frame_flags & VP9_GOLD_FLAG)
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_golden_frame = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (ref_frame_flags & VP9_ALT_FLAG)
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_alt_ref_frame = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 20:15:43 +01:00
|
|
|
int vp9_copy_reference_enc(VP9_PTR ptr, VP9_REFFRAME ref_frame_flag,
|
|
|
|
YV12_BUFFER_CONFIG *sd) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *)(ptr);
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2012-07-14 00:21:29 +02:00
|
|
|
int ref_fb_idx;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (ref_frame_flag == VP9_LAST_FLAG)
|
2013-02-22 20:22:03 +01:00
|
|
|
ref_fb_idx = cm->ref_frame_map[cpi->lst_fb_idx];
|
2012-10-31 22:40:53 +01:00
|
|
|
else if (ref_frame_flag == VP9_GOLD_FLAG)
|
2013-02-22 20:22:03 +01:00
|
|
|
ref_fb_idx = cm->ref_frame_map[cpi->gld_fb_idx];
|
2012-10-31 22:40:53 +01:00
|
|
|
else if (ref_frame_flag == VP9_ALT_FLAG)
|
2013-02-22 20:22:03 +01:00
|
|
|
ref_fb_idx = cm->ref_frame_map[cpi->alt_fb_idx];
|
2012-07-14 00:21:29 +02:00
|
|
|
else
|
|
|
|
return -1;
|
2010-07-22 14:07:32 +02:00
|
|
|
|
2012-11-02 01:53:44 +01:00
|
|
|
vp8_yv12_copy_frame(&cm->yv12_fb[ref_fb_idx], sd);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-10-30 22:25:33 +01:00
|
|
|
|
2013-03-13 20:15:43 +01:00
|
|
|
int vp9_get_reference_enc(VP9_PTR ptr, int index, YV12_BUFFER_CONFIG **fb) {
|
|
|
|
VP9_COMP *cpi = (VP9_COMP *)(ptr);
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
|
|
|
|
|
|
|
if (index < 0 || index >= NUM_REF_FRAMES)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*fb = &cm->yv12_fb[cm->ref_frame_map[index]];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
int vp9_set_reference_enc(VP9_PTR ptr, VP9_REFFRAME ref_frame_flag,
|
2012-10-30 22:25:33 +01:00
|
|
|
YV12_BUFFER_CONFIG *sd) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *)(ptr);
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
int ref_fb_idx;
|
2010-09-24 17:10:25 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
if (ref_frame_flag == VP9_LAST_FLAG)
|
2013-02-22 20:22:03 +01:00
|
|
|
ref_fb_idx = cm->ref_frame_map[cpi->lst_fb_idx];
|
2012-10-31 22:40:53 +01:00
|
|
|
else if (ref_frame_flag == VP9_GOLD_FLAG)
|
2013-02-22 20:22:03 +01:00
|
|
|
ref_fb_idx = cm->ref_frame_map[cpi->gld_fb_idx];
|
2012-10-31 22:40:53 +01:00
|
|
|
else if (ref_frame_flag == VP9_ALT_FLAG)
|
2013-02-22 20:22:03 +01:00
|
|
|
ref_fb_idx = cm->ref_frame_map[cpi->alt_fb_idx];
|
2012-07-14 00:21:29 +02:00
|
|
|
else
|
|
|
|
return -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-11-02 01:53:44 +01:00
|
|
|
vp8_yv12_copy_frame(sd, &cm->yv12_fb[ref_fb_idx]);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_update_entropy(VP9_PTR comp, int update) {
|
2013-04-26 23:39:58 +02:00
|
|
|
((VP9_COMP *)comp)->common.refresh_frame_context = update;
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
#ifdef OUTPUT_YUV_SRC
|
2012-10-31 22:40:53 +01:00
|
|
|
void vp9_write_yuv_frame(YV12_BUFFER_CONFIG *s) {
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *src = s->y_buffer;
|
2012-07-14 00:21:29 +02:00
|
|
|
int h = s->y_height;
|
|
|
|
|
|
|
|
do {
|
|
|
|
fwrite(src, s->y_width, 1, yuv_file);
|
|
|
|
src += s->y_stride;
|
|
|
|
} while (--h);
|
|
|
|
|
|
|
|
src = s->u_buffer;
|
|
|
|
h = s->uv_height;
|
|
|
|
|
|
|
|
do {
|
|
|
|
fwrite(src, s->uv_width, 1, yuv_file);
|
|
|
|
src += s->uv_stride;
|
|
|
|
} while (--h);
|
|
|
|
|
|
|
|
src = s->v_buffer;
|
|
|
|
h = s->uv_height;
|
|
|
|
|
|
|
|
do {
|
|
|
|
fwrite(src, s->uv_width, 1, yuv_file);
|
|
|
|
src += s->uv_stride;
|
|
|
|
} while (--h);
|
2011-02-14 23:18:18 +01:00
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-02-14 23:18:18 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
2012-10-31 22:40:53 +01:00
|
|
|
void vp9_write_yuv_rec_frame(VP9_COMMON *cm) {
|
2012-07-14 00:21:29 +02:00
|
|
|
YV12_BUFFER_CONFIG *s = cm->frame_to_show;
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *src = s->y_buffer;
|
2013-03-21 00:41:30 +01:00
|
|
|
int h = cm->height;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
fwrite(src, s->y_width, 1, yuv_rec_file);
|
|
|
|
src += s->y_stride;
|
|
|
|
} while (--h);
|
|
|
|
|
|
|
|
src = s->u_buffer;
|
2013-05-09 01:19:56 +02:00
|
|
|
h = s->uv_height;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
fwrite(src, s->uv_width, 1, yuv_rec_file);
|
|
|
|
src += s->uv_stride;
|
|
|
|
} while (--h);
|
|
|
|
|
|
|
|
src = s->v_buffer;
|
2013-05-09 01:19:56 +02:00
|
|
|
h = s->uv_height;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
fwrite(src, s->uv_width, 1, yuv_rec_file);
|
|
|
|
src += s->uv_stride;
|
|
|
|
} while (--h);
|
2013-05-16 02:55:08 +02:00
|
|
|
|
|
|
|
#if CONFIG_ALPHA
|
|
|
|
if (s->alpha_buffer) {
|
|
|
|
src = s->alpha_buffer;
|
|
|
|
h = s->alpha_height;
|
|
|
|
do {
|
|
|
|
fwrite(src, s->alpha_width, 1, yuv_rec_file);
|
|
|
|
src += s->alpha_stride;
|
|
|
|
} while (--h);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
[WIP] Add column-based tiling.
This patch adds column-based tiling. The idea is to make each tile
independently decodable (after reading the common frame header) and
also independendly encodable (minus within-frame cost adjustments in
the RD loop) to speed-up hardware & software en/decoders if they used
multi-threading. Column-based tiling has the added advantage (over
other tiling methods) that it minimizes realtime use-case latency,
since all threads can start encoding data as soon as the first SB-row
worth of data is available to the encoder.
There is some test code that does random tile ordering in the decoder,
to confirm that each tile is indeed independently decodable from other
tiles in the same frame. At tile edges, all contexts assume default
values (i.e. 0, 0 motion vector, no coefficients, DC intra4x4 mode),
and motion vector search and ordering do not cross tiles in the same
frame.
t log
Tile independence is not maintained between frames ATM, i.e. tile 0 of
frame 1 is free to use motion vectors that point into any tile of frame
0. We support 1 (i.e. no tiling), 2 or 4 column-tiles.
The loopfilter crosses tile boundaries. I discussed this briefly with Aki
and he says that's OK. An in-loop loopfilter would need to do some sync
between tile threads, but that shouldn't be a big issue.
Resuls: with tiling disabled, we go up slightly because of improved edge
use in the intra4x4 prediction. With 2 tiles, we lose about ~1% on derf,
~0.35% on HD and ~0.55% on STD/HD. With 4 tiles, we lose another ~1.5%
on derf ~0.77% on HD and ~0.85% on STD/HD. Most of this loss is
concentrated in the low-bitrate end of clips, and most of it is because
of the loss of edges at tile boundaries and the resulting loss of intra
predictors.
TODO:
- more tiles (perhaps allow row-based tiling also, and max. 8 tiles)?
- maybe optionally (for EC purposes), motion vectors themselves
should not cross tile edges, or we should emulate such borders as
if they were off-frame, to limit error propagation to within one
tile only. This doesn't have to be the default behaviour but could
be an optional bitstream flag.
Change-Id: I5951c3a0742a767b20bc9fb5af685d9892c2c96f
2013-02-01 18:35:28 +01:00
|
|
|
fflush(yuv_rec_file);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
#endif
|
2011-02-14 23:18:18 +01:00
|
|
|
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
static void scale_and_extend_frame(YV12_BUFFER_CONFIG *src_fb,
|
|
|
|
YV12_BUFFER_CONFIG *dst_fb) {
|
2013-03-14 01:09:05 +01:00
|
|
|
const int in_w = src_fb->y_crop_width;
|
|
|
|
const int in_h = src_fb->y_crop_height;
|
|
|
|
const int out_w = dst_fb->y_crop_width;
|
|
|
|
const int out_h = dst_fb->y_crop_height;
|
2013-05-14 01:02:29 +02:00
|
|
|
int x, y, i;
|
|
|
|
|
2013-05-16 02:55:08 +02:00
|
|
|
uint8_t *srcs[4] = {src_fb->y_buffer, src_fb->u_buffer, src_fb->v_buffer,
|
|
|
|
src_fb->alpha_buffer};
|
|
|
|
int src_strides[4] = {src_fb->y_stride, src_fb->uv_stride, src_fb->uv_stride,
|
|
|
|
src_fb->alpha_stride};
|
2013-05-14 01:02:29 +02:00
|
|
|
|
2013-05-16 02:55:08 +02:00
|
|
|
uint8_t *dsts[4] = {dst_fb->y_buffer, dst_fb->u_buffer, dst_fb->v_buffer,
|
|
|
|
dst_fb->alpha_buffer};
|
|
|
|
int dst_strides[4] = {dst_fb->y_stride, dst_fb->uv_stride, dst_fb->uv_stride,
|
|
|
|
dst_fb->alpha_stride};
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
|
|
|
|
for (y = 0; y < out_h; y += 16) {
|
|
|
|
for (x = 0; x < out_w; x += 16) {
|
2013-05-14 01:02:29 +02:00
|
|
|
for (i = 0; i < MAX_MB_PLANE; ++i) {
|
|
|
|
const int factor = i == 0 ? 1 : 2;
|
|
|
|
const int x_q4 = x * (16 / factor) * in_w / out_w;
|
|
|
|
const int y_q4 = y * (16 / factor) * in_h / out_h;
|
|
|
|
const int src_stride = src_strides[i];
|
|
|
|
const int dst_stride = dst_strides[i];
|
|
|
|
uint8_t *src = srcs[i] + y / factor * in_h / out_h * src_stride +
|
|
|
|
x / factor * in_w / out_w;
|
|
|
|
uint8_t *dst = dsts[i] + y * dst_stride + x;
|
|
|
|
|
|
|
|
vp9_convolve8(src, src_stride, dst, dst_stride,
|
|
|
|
vp9_sub_pel_filters_8[x_q4 & 0xf], 16 * in_w / out_w,
|
|
|
|
vp9_sub_pel_filters_8[y_q4 & 0xf], 16 * in_h / out_h,
|
|
|
|
16 / factor, 16 / factor);
|
|
|
|
}
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vp8_yv12_extend_frame_borders(dst_fb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void update_alt_ref_frame_stats(VP9_COMP *cpi) {
|
2012-07-14 00:21:29 +02:00
|
|
|
// this frame refreshes means next frames don't unless specified by user
|
|
|
|
cpi->common.frames_since_golden = 0;
|
2011-02-14 23:18:18 +01:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
if (!cpi->multi_arf_enabled)
|
|
|
|
#endif
|
|
|
|
// Clear the alternate reference update pending flag.
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->source_alt_ref_pending = 0;
|
2011-02-14 23:18:18 +01:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
// Set the alternate reference frame active flag
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->source_alt_ref_active = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2012-10-31 01:53:32 +01:00
|
|
|
static void update_golden_frame_stats(VP9_COMP *cpi) {
|
2012-07-14 00:21:29 +02:00
|
|
|
// Update the Golden frame usage counts.
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_golden_frame) {
|
2011-01-10 10:14:10 +01:00
|
|
|
// this frame refreshes means next frames don't unless specified by user
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_golden_frame = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->common.frames_since_golden = 0;
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// if ( cm->frame_type == KEY_FRAME )
|
|
|
|
// {
|
|
|
|
cpi->recent_ref_frame_usage[INTRA_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[LAST_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[GOLDEN_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[ALTREF_FRAME] = 1;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
2013-04-03 00:08:50 +02:00
|
|
|
// // Carry a portion of count over to beginning of next gf sequence
|
2012-07-14 00:21:29 +02:00
|
|
|
// cpi->recent_ref_frame_usage[INTRA_FRAME] >>= 5;
|
|
|
|
// cpi->recent_ref_frame_usage[LAST_FRAME] >>= 5;
|
|
|
|
// cpi->recent_ref_frame_usage[GOLDEN_FRAME] >>= 5;
|
|
|
|
// cpi->recent_ref_frame_usage[ALTREF_FRAME] >>= 5;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// ******** Fixed Q test code only ************
|
|
|
|
// If we are going to use the ALT reference for the next group of frames set a flag to say so.
|
|
|
|
if (cpi->oxcf.fixed_q >= 0 &&
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->oxcf.play_alternate && !cpi->refresh_alt_ref_frame) {
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->source_alt_ref_pending = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cpi->source_alt_ref_pending)
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->source_alt_ref_active = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Decrement count down till next gf
|
|
|
|
if (cpi->frames_till_gf_update_due > 0)
|
|
|
|
cpi->frames_till_gf_update_due--;
|
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
} else if (!cpi->refresh_alt_ref_frame) {
|
2012-07-14 00:21:29 +02:00
|
|
|
// Decrement count down till next gf
|
|
|
|
if (cpi->frames_till_gf_update_due > 0)
|
|
|
|
cpi->frames_till_gf_update_due--;
|
|
|
|
|
|
|
|
if (cpi->common.frames_till_alt_ref_frame)
|
|
|
|
cpi->common.frames_till_alt_ref_frame--;
|
|
|
|
|
|
|
|
cpi->common.frames_since_golden++;
|
|
|
|
|
|
|
|
if (cpi->common.frames_since_golden > 1) {
|
|
|
|
cpi->recent_ref_frame_usage[INTRA_FRAME] += cpi->count_mb_ref_frame_usage[INTRA_FRAME];
|
|
|
|
cpi->recent_ref_frame_usage[LAST_FRAME] += cpi->count_mb_ref_frame_usage[LAST_FRAME];
|
|
|
|
cpi->recent_ref_frame_usage[GOLDEN_FRAME] += cpi->count_mb_ref_frame_usage[GOLDEN_FRAME];
|
|
|
|
cpi->recent_ref_frame_usage[ALTREF_FRAME] += cpi->count_mb_ref_frame_usage[ALTREF_FRAME];
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-30 02:20:32 +01:00
|
|
|
static int find_fp_qindex() {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
2011-12-02 15:57:21 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < QINDEX_RANGE; i++) {
|
2012-10-30 20:58:42 +01:00
|
|
|
if (vp9_convert_qindex_to_q(i) >= 30.0) {
|
2012-07-14 00:21:29 +02:00
|
|
|
break;
|
2011-12-02 15:57:21 +01:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-12-02 00:50:14 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (i == QINDEX_RANGE)
|
|
|
|
i--;
|
2011-12-02 15:57:21 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return i;
|
2011-12-02 15:57:21 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void Pass1Encode(VP9_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned int *frame_flags) {
|
2012-07-14 00:21:29 +02:00
|
|
|
(void) size;
|
|
|
|
(void) dest;
|
|
|
|
(void) frame_flags;
|
2011-12-02 15:57:21 +01:00
|
|
|
|
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_set_quantizer(cpi, find_fp_qindex());
|
|
|
|
vp9_first_pass(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-04-07 01:38:34 +02:00
|
|
|
|
2012-08-14 01:50:03 +02:00
|
|
|
#define WRITE_RECON_BUFFER 0
|
2011-11-16 01:16:30 +01:00
|
|
|
#if WRITE_RECON_BUFFER
|
2012-07-14 00:21:29 +02:00
|
|
|
void write_cx_frame_to_file(YV12_BUFFER_CONFIG *frame, int this_frame) {
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// write the frame
|
|
|
|
FILE *yframe;
|
|
|
|
int i;
|
|
|
|
char filename[255];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
sprintf(filename, "cx\\y%04d.raw", this_frame);
|
|
|
|
yframe = fopen(filename, "wb");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < frame->y_height; i++)
|
|
|
|
fwrite(frame->y_buffer + i * frame->y_stride,
|
|
|
|
frame->y_width, 1, yframe);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fclose(yframe);
|
|
|
|
sprintf(filename, "cx\\u%04d.raw", this_frame);
|
|
|
|
yframe = fopen(filename, "wb");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < frame->uv_height; i++)
|
|
|
|
fwrite(frame->u_buffer + i * frame->uv_stride,
|
|
|
|
frame->uv_width, 1, yframe);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fclose(yframe);
|
|
|
|
sprintf(filename, "cx\\v%04d.raw", this_frame);
|
|
|
|
yframe = fopen(filename, "wb");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < frame->uv_height; i++)
|
|
|
|
fwrite(frame->v_buffer + i * frame->uv_stride,
|
|
|
|
frame->uv_width, 1, yframe);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
fclose(yframe);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
static double compute_edge_pixel_proportion(YV12_BUFFER_CONFIG *frame) {
|
2012-03-19 15:53:05 +01:00
|
|
|
#define EDGE_THRESH 128
|
2012-07-14 00:21:29 +02:00
|
|
|
int i, j;
|
|
|
|
int num_edge_pels = 0;
|
|
|
|
int num_pels = (frame->y_height - 2) * (frame->y_width - 2);
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *prev = frame->y_buffer + 1;
|
|
|
|
uint8_t *curr = frame->y_buffer + 1 + frame->y_stride;
|
|
|
|
uint8_t *next = frame->y_buffer + 1 + 2 * frame->y_stride;
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 1; i < frame->y_height - 1; i++) {
|
|
|
|
for (j = 1; j < frame->y_width - 1; j++) {
|
|
|
|
/* Sobel hor and ver gradients */
|
|
|
|
int v = 2 * (curr[1] - curr[-1]) + (prev[1] - prev[-1]) + (next[1] - next[-1]);
|
|
|
|
int h = 2 * (prev[0] - next[0]) + (prev[1] - next[1]) + (prev[-1] - next[-1]);
|
|
|
|
h = (h < 0 ? -h : h);
|
|
|
|
v = (v < 0 ? -v : v);
|
2013-04-02 19:24:56 +02:00
|
|
|
if (h > EDGE_THRESH || v > EDGE_THRESH)
|
|
|
|
num_edge_pels++;
|
2012-07-14 00:21:29 +02:00
|
|
|
curr++;
|
|
|
|
prev++;
|
|
|
|
next++;
|
|
|
|
}
|
|
|
|
curr += frame->y_stride - frame->y_width + 2;
|
|
|
|
prev += frame->y_stride - frame->y_width + 2;
|
|
|
|
next += frame->y_stride - frame->y_width + 2;
|
|
|
|
}
|
2013-04-02 19:24:56 +02:00
|
|
|
return (double)num_edge_pels / num_pels;
|
2012-03-19 15:53:05 +01:00
|
|
|
}
|
|
|
|
|
2012-04-07 01:38:34 +02:00
|
|
|
// Function to test for conditions that indicate we should loop
|
2010-11-17 16:12:04 +01:00
|
|
|
// back and recode a frame.
|
2012-12-14 21:35:33 +01:00
|
|
|
static int recode_loop_test(VP9_COMP *cpi,
|
|
|
|
int high_limit, int low_limit,
|
|
|
|
int q, int maxq, int minq) {
|
2013-04-16 00:24:39 +02:00
|
|
|
int force_recode = 0;
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Is frame recode allowed at all
|
2013-04-03 00:08:50 +02:00
|
|
|
// Yes if either recode mode 1 is selected or mode two is selected
|
2012-07-14 00:21:29 +02:00
|
|
|
// and the frame is a key frame. golden frame or alt_ref_frame
|
|
|
|
if ((cpi->sf.recode_loop == 1) ||
|
|
|
|
((cpi->sf.recode_loop == 2) &&
|
|
|
|
((cm->frame_type == KEY_FRAME) ||
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_golden_frame ||
|
|
|
|
cpi->refresh_alt_ref_frame))) {
|
2012-07-14 00:21:29 +02:00
|
|
|
// General over and under shoot tests
|
|
|
|
if (((cpi->projected_frame_size > high_limit) && (q < maxq)) ||
|
|
|
|
((cpi->projected_frame_size < low_limit) && (q > minq))) {
|
2013-04-16 00:24:39 +02:00
|
|
|
force_recode = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
// Special Constrained quality tests
|
|
|
|
else if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) {
|
|
|
|
// Undershoot and below auto cq level
|
2013-04-02 19:24:56 +02:00
|
|
|
if (q > cpi->cq_target_quality &&
|
|
|
|
cpi->projected_frame_size < ((cpi->this_frame_target * 7) >> 3)) {
|
2013-04-16 00:24:39 +02:00
|
|
|
force_recode = 1;
|
2013-04-02 19:24:56 +02:00
|
|
|
} else if (q > cpi->oxcf.cq_level &&
|
|
|
|
cpi->projected_frame_size < cpi->min_frame_bandwidth &&
|
|
|
|
cpi->active_best_quality > cpi->oxcf.cq_level) {
|
|
|
|
// Severe undershoot and between auto and user cq level
|
2013-04-16 00:24:39 +02:00
|
|
|
force_recode = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->active_best_quality = cpi->oxcf.cq_level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return force_recode;
|
2010-11-17 16:12:04 +01:00
|
|
|
}
|
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
static void update_reference_frames(VP9_COMP * const cpi) {
|
|
|
|
VP9_COMMON * const cm = &cpi->common;
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// At this point the new frame has been encoded.
|
|
|
|
// If any buffer copy / swapping is signaled it should be done here.
|
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
2013-01-15 22:49:44 +01:00
|
|
|
ref_cnt_fb(cm->fb_idx_ref_cnt,
|
2013-02-22 20:22:03 +01:00
|
|
|
&cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
|
2013-01-15 22:49:44 +01:00
|
|
|
ref_cnt_fb(cm->fb_idx_ref_cnt,
|
2013-02-22 20:22:03 +01:00
|
|
|
&cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
|
2013-04-03 00:08:50 +02:00
|
|
|
}
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
else if (!cpi->multi_arf_enabled && cpi->refresh_golden_frame &&
|
|
|
|
!cpi->refresh_alt_ref_frame) {
|
|
|
|
#else
|
|
|
|
else if (cpi->refresh_golden_frame && !cpi->refresh_alt_ref_frame) {
|
|
|
|
#endif
|
2013-01-16 21:19:42 +01:00
|
|
|
/* Preserve the previously existing golden frame and update the frame in
|
|
|
|
* the alt ref slot instead. This is highly specific to the current use of
|
|
|
|
* alt-ref as a forward reference, and this needs to be generalized as
|
|
|
|
* other uses are implemented (like RTC/temporal scaling)
|
|
|
|
*
|
2013-04-03 00:08:50 +02:00
|
|
|
* The update to the buffer in the alt ref slot was signaled in
|
2013-01-16 21:19:42 +01:00
|
|
|
* vp9_pack_bitstream(), now swap the buffer pointers so that it's treated
|
|
|
|
* as the golden frame next time.
|
|
|
|
*/
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
ref_cnt_fb(cm->fb_idx_ref_cnt,
|
2013-02-22 20:22:03 +01:00
|
|
|
&cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
|
2013-01-16 21:19:42 +01:00
|
|
|
|
|
|
|
tmp = cpi->alt_fb_idx;
|
|
|
|
cpi->alt_fb_idx = cpi->gld_fb_idx;
|
|
|
|
cpi->gld_fb_idx = tmp;
|
2013-04-03 00:08:50 +02:00
|
|
|
} else { /* For non key/golden frames */
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_alt_ref_frame) {
|
2013-04-03 00:08:50 +02:00
|
|
|
int arf_idx = cpi->alt_fb_idx;
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
if (cpi->multi_arf_enabled) {
|
|
|
|
arf_idx = cpi->arf_buffer_idx[cpi->sequence_number + 1];
|
|
|
|
}
|
|
|
|
#endif
|
2013-01-15 22:49:44 +01:00
|
|
|
ref_cnt_fb(cm->fb_idx_ref_cnt,
|
2013-04-03 00:08:50 +02:00
|
|
|
&cm->ref_frame_map[arf_idx], cm->new_fb_idx);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-04-20 14:12:23 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_golden_frame) {
|
|
|
|
ref_cnt_fb(cm->fb_idx_ref_cnt,
|
2013-02-22 20:22:03 +01:00
|
|
|
&cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
|
2011-04-20 14:12:23 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-04-20 14:12:23 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_last_frame) {
|
|
|
|
ref_cnt_fb(cm->fb_idx_ref_cnt,
|
2013-02-22 20:22:03 +01:00
|
|
|
&cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-04-20 14:12:23 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) {
|
2013-02-20 16:27:35 +01:00
|
|
|
if (cm->no_lpf || cpi->mb.e_mbd.lossless) {
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->filter_level = 0;
|
2013-02-20 16:27:35 +01:00
|
|
|
} else {
|
2012-07-14 00:21:29 +02:00
|
|
|
struct vpx_usec_timer timer;
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state();
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_usec_timer_start(&timer);
|
2013-04-10 22:45:22 +02:00
|
|
|
|
|
|
|
vp9_pick_filter_level(cpi->Source, cpi);
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_usec_timer_mark(&timer);
|
|
|
|
cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer);
|
|
|
|
}
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cm->filter_level > 0) {
|
2012-10-30 22:25:33 +01:00
|
|
|
vp9_set_alt_lf_level(cpi, cm->filter_level);
|
2013-05-24 16:40:20 +02:00
|
|
|
vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, cm->filter_level, 0);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2013-05-09 01:18:44 +02:00
|
|
|
vp9_extend_frame_borders(cm->frame_to_show,
|
|
|
|
cm->subsampling_x, cm->subsampling_y);
|
2011-02-25 12:42:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-28 22:18:02 +01:00
|
|
|
void vp9_select_interp_filter_type(VP9_COMP *cpi) {
|
2012-12-20 23:56:19 +01:00
|
|
|
int i;
|
2013-01-08 23:14:01 +01:00
|
|
|
int high_filter_index = 0;
|
2012-12-20 23:56:19 +01:00
|
|
|
unsigned int thresh;
|
|
|
|
unsigned int high_count = 0;
|
|
|
|
unsigned int count_sum = 0;
|
|
|
|
unsigned int *hist = cpi->best_switchable_interp_count;
|
|
|
|
|
|
|
|
if (DEFAULT_INTERP_FILTER != SWITCHABLE) {
|
|
|
|
cpi->common.mcomp_filter_type = DEFAULT_INTERP_FILTER;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(agrange): Look at using RD criteria to select the interpolation
|
|
|
|
// filter to use for the next frame rather than this simpler counting scheme.
|
|
|
|
|
|
|
|
// Select the interpolation filter mode for the next frame
|
|
|
|
// based on the selection frequency seen in the current frame.
|
|
|
|
for (i = 0; i < VP9_SWITCHABLE_FILTERS; ++i) {
|
|
|
|
unsigned int count = hist[i];
|
|
|
|
count_sum += count;
|
|
|
|
if (count > high_count) {
|
|
|
|
high_count = count;
|
|
|
|
high_filter_index = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
thresh = (unsigned int)(0.80 * count_sum);
|
|
|
|
|
|
|
|
if (high_count > thresh) {
|
|
|
|
// One filter accounts for 80+% of cases so force the next
|
|
|
|
// frame to use this filter exclusively using frame-level flag.
|
|
|
|
cpi->common.mcomp_filter_type = vp9_switchable_interp[high_filter_index];
|
|
|
|
} else {
|
|
|
|
// Use a MB-level switchable filter selection strategy.
|
|
|
|
cpi->common.mcomp_filter_type = SWITCHABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:34:31 +01:00
|
|
|
static void scale_references(VP9_COMP *cpi) {
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2013-02-22 20:22:03 +01:00
|
|
|
YV12_BUFFER_CONFIG *ref = &cm->yv12_fb[cm->ref_frame_map[i]];
|
2013-02-20 21:34:31 +01:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
if (ref->y_crop_width != cm->width ||
|
|
|
|
ref->y_crop_height != cm->height) {
|
2013-02-20 21:34:31 +01:00
|
|
|
int new_fb = get_free_fb(cm);
|
|
|
|
|
2013-05-07 00:52:06 +02:00
|
|
|
vp9_realloc_frame_buffer(&cm->yv12_fb[new_fb],
|
|
|
|
cm->width, cm->height,
|
|
|
|
cm->subsampling_x, cm->subsampling_y,
|
|
|
|
VP9BORDERINPIXELS);
|
2013-02-20 21:34:31 +01:00
|
|
|
scale_and_extend_frame(ref, &cm->yv12_fb[new_fb]);
|
|
|
|
cpi->scaled_ref_idx[i] = new_fb;
|
|
|
|
} else {
|
2013-02-22 20:22:03 +01:00
|
|
|
cpi->scaled_ref_idx[i] = cm->ref_frame_map[i];
|
|
|
|
cm->fb_idx_ref_cnt[cm->ref_frame_map[i]]++;
|
2013-02-20 21:34:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_scaled_references(VP9_COMP *cpi) {
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
|
|
|
int i;
|
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
for (i = 0; i < 3; i++)
|
2013-02-20 21:34:31 +01:00
|
|
|
cm->fb_idx_ref_cnt[cpi->scaled_ref_idx[i]]--;
|
|
|
|
}
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
static void encode_frame_to_data_rate(VP9_COMP *cpi,
|
|
|
|
unsigned long *size,
|
|
|
|
unsigned char *dest,
|
|
|
|
unsigned int *frame_flags) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2012-07-14 00:21:29 +02:00
|
|
|
MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
2013-05-31 18:18:59 +02:00
|
|
|
TX_SIZE t;
|
2013-04-02 19:24:56 +02:00
|
|
|
int q;
|
2012-07-14 00:21:29 +02:00
|
|
|
int frame_over_shoot_limit;
|
|
|
|
int frame_under_shoot_limit;
|
|
|
|
|
2013-04-16 00:24:39 +02:00
|
|
|
int loop = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
int loop_count;
|
|
|
|
|
|
|
|
int q_low;
|
|
|
|
int q_high;
|
|
|
|
|
|
|
|
int top_index;
|
|
|
|
int bottom_index;
|
2013-04-16 00:24:39 +02:00
|
|
|
int active_worst_qchanged = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-16 00:24:39 +02:00
|
|
|
int overshoot_seen = 0;
|
|
|
|
int undershoot_seen = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
SPEED_FEATURES *sf = &cpi->sf;
|
2012-04-16 23:53:37 +02:00
|
|
|
#if RESET_FOREACH_FILTER
|
2012-07-14 00:21:29 +02:00
|
|
|
int q_low0;
|
|
|
|
int q_high0;
|
|
|
|
int Q0;
|
|
|
|
int active_best_quality0;
|
|
|
|
int active_worst_quality0;
|
|
|
|
double rate_correction_factor0;
|
|
|
|
double gf_rate_correction_factor0;
|
2012-04-16 23:53:37 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/* list of filters to search over */
|
2012-07-18 22:43:01 +02:00
|
|
|
int mcomp_filters_to_search[] = {
|
2013-05-07 17:19:25 +02:00
|
|
|
EIGHTTAP, EIGHTTAP_SHARP, EIGHTTAP_SMOOTH, SWITCHABLE
|
2012-07-18 22:43:01 +02:00
|
|
|
};
|
2012-10-22 23:43:01 +02:00
|
|
|
int mcomp_filters = sizeof(mcomp_filters_to_search) /
|
|
|
|
sizeof(*mcomp_filters_to_search);
|
2012-07-14 00:21:29 +02:00
|
|
|
int mcomp_filter_index = 0;
|
2012-12-14 21:35:33 +01:00
|
|
|
int64_t mcomp_filter_cost[4];
|
2012-04-16 23:53:37 +02:00
|
|
|
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
/* Scale the source buffer, if required */
|
2013-02-28 19:52:04 +01:00
|
|
|
if (cm->mb_cols * 16 != cpi->un_scaled_source->y_width ||
|
|
|
|
cm->mb_rows * 16 != cpi->un_scaled_source->y_height) {
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
scale_and_extend_frame(cpi->un_scaled_source, &cpi->scaled_source);
|
|
|
|
cpi->Source = &cpi->scaled_source;
|
|
|
|
} else {
|
|
|
|
cpi->Source = cpi->un_scaled_source;
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:34:31 +01:00
|
|
|
scale_references(cpi);
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Clear down mmx registers to allow floating point in what follows
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state();
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-09-10 07:42:35 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// For an alt ref frame in 2 pass we skip the call to the second
|
|
|
|
// pass function that sets the target bandwidth so must set it here
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_alt_ref_frame) {
|
2013-04-03 00:08:50 +02:00
|
|
|
// Per frame bit target for the alt ref frame
|
|
|
|
cpi->per_frame_bandwidth = cpi->twopass.gf_bits;
|
2012-11-05 23:22:59 +01:00
|
|
|
// per second target bitrate
|
|
|
|
cpi->target_bandwidth = (int)(cpi->twopass.gf_bits *
|
|
|
|
cpi->output_frame_rate);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Clear zbin over-quant value and mode boost values.
|
|
|
|
cpi->zbin_mode_boost = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Enable or disable mode based tweaking of the zbin
|
|
|
|
// For 2 Pass Only used where GF/ARF prediction quality
|
|
|
|
// is above a threshold
|
|
|
|
cpi->zbin_mode_boost = 0;
|
2013-02-20 16:27:35 +01:00
|
|
|
|
2013-03-22 16:47:17 +01:00
|
|
|
// if (cpi->oxcf.lossless)
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->zbin_mode_boost_enabled = 0;
|
2013-03-22 16:47:17 +01:00
|
|
|
// else
|
2013-04-16 00:24:39 +02:00
|
|
|
// cpi->zbin_mode_boost_enabled = 1;
|
2013-02-20 16:27:35 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Current default encoder behaviour for the altref sign bias
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = cpi->source_alt_ref_active;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
// Check to see if a key frame is signaled
|
2012-07-14 00:21:29 +02:00
|
|
|
// For two pass with auto key frame enabled cm->frame_type may already be set, but not for one pass.
|
|
|
|
if ((cm->current_video_frame == 0) ||
|
|
|
|
(cm->frame_flags & FRAMEFLAGS_KEY) ||
|
|
|
|
(cpi->oxcf.auto_key && (cpi->frames_since_key % cpi->key_frame_frequency == 0))) {
|
|
|
|
// Key frame from VFW/auto-keyframe/first frame
|
|
|
|
cm->frame_type = KEY_FRAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set default state for segment based loop filter update flags
|
|
|
|
xd->mode_ref_lf_delta_update = 0;
|
|
|
|
|
2012-11-09 19:52:08 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Set various flags etc to special state if it is a key frame
|
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Reset the loop filter deltas and segmentation map
|
|
|
|
setup_features(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// If segmentation is enabled force a map update for key frames
|
|
|
|
if (xd->segmentation_enabled) {
|
|
|
|
xd->update_mb_segmentation_map = 1;
|
|
|
|
xd->update_mb_segmentation_data = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// The alternate reference frame cannot be active for a key frame
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->source_alt_ref_active = 0;
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Reset the RD threshold multipliers to default of * 1 (128)
|
2013-04-02 19:24:56 +02:00
|
|
|
for (i = 0; i < MAX_MODES; i++)
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->rd_thresh_mult[i] = 128;
|
2013-01-15 15:43:35 +01:00
|
|
|
|
|
|
|
cm->error_resilient_mode = (cpi->oxcf.error_resilient_mode != 0);
|
2013-01-25 20:30:28 +01:00
|
|
|
cm->frame_parallel_decoding_mode =
|
|
|
|
(cpi->oxcf.frame_parallel_decoding_mode != 0);
|
|
|
|
if (cm->error_resilient_mode) {
|
|
|
|
cm->frame_parallel_decoding_mode = 1;
|
2013-05-30 02:16:00 +02:00
|
|
|
cm->reset_frame_context = 0;
|
2013-04-26 23:39:58 +02:00
|
|
|
cm->refresh_frame_context = 0;
|
2013-01-25 20:30:28 +01:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-23 15:01:55 +02:00
|
|
|
// Configure experimental use of segmentation for enhanced coding of
|
|
|
|
// static regions if indicated.
|
2013-02-05 11:13:25 +01:00
|
|
|
// Only allowed for now in second pass of two pass (as requires lagged coding)
|
2013-04-03 00:08:50 +02:00
|
|
|
// and if the relevant speed feature flag is set.
|
2013-02-05 11:13:25 +01:00
|
|
|
if ((cpi->pass == 2) && (cpi->sf.static_segmentation)) {
|
|
|
|
configure_static_seg_features(cpi);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Decide how big to make the frame
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_pick_frame_size(cpi);
|
2012-06-07 14:39:20 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state();
|
2012-06-07 14:39:20 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Set an active best quality and if necessary active worst quality
|
2013-04-02 19:24:56 +02:00
|
|
|
q = cpi->active_worst_quality;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
2013-04-16 19:59:39 +02:00
|
|
|
#if !CONFIG_MULTIPLE_ARF
|
2012-07-14 00:21:29 +02:00
|
|
|
// Special case for key frames forced because we have reached
|
|
|
|
// the maximum key frame interval. Here force the Q to a range
|
|
|
|
// based on the ambient Q to reduce the risk of popping
|
|
|
|
if (cpi->this_key_frame_forced) {
|
2013-03-28 20:46:35 +01:00
|
|
|
int delta_qindex;
|
|
|
|
int qindex = cpi->last_boosted_qindex;
|
|
|
|
double last_boosted_q = vp9_convert_qindex_to_q(qindex);
|
|
|
|
|
|
|
|
delta_qindex = compute_qdelta(cpi, last_boosted_q,
|
|
|
|
(last_boosted_q * 0.75));
|
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->active_best_quality = MAX(qindex + delta_qindex, cpi->best_quality);
|
2013-04-16 19:59:39 +02:00
|
|
|
} else {
|
|
|
|
int high = 5000;
|
|
|
|
int low = 400;
|
|
|
|
double q_adj_factor = 1.0;
|
|
|
|
double q_val;
|
|
|
|
|
|
|
|
// Baseline value derived from cpi->active_worst_quality and kf boost
|
|
|
|
if (cpi->kf_boost > high) {
|
|
|
|
cpi->active_best_quality = kf_low_motion_minq[q];
|
|
|
|
} else if (cpi->kf_boost < low) {
|
|
|
|
cpi->active_best_quality = kf_high_motion_minq[q];
|
|
|
|
} else {
|
|
|
|
const int gap = high - low;
|
|
|
|
const int offset = high - cpi->kf_boost;
|
|
|
|
const int qdiff = kf_high_motion_minq[q] - kf_low_motion_minq[q];
|
|
|
|
const int adjustment = ((offset * qdiff) + (gap >> 1)) / gap;
|
|
|
|
|
|
|
|
cpi->active_best_quality = kf_low_motion_minq[q] + adjustment;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Allow somewhat lower kf minq with small image formats.
|
|
|
|
if ((cm->width * cm->height) <= (352 * 288)) {
|
|
|
|
q_adj_factor -= 0.25;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a further adjustment based on the kf zero motion measure.
|
|
|
|
q_adj_factor += 0.05 - (0.001 * (double)cpi->kf_zeromotion_pct);
|
|
|
|
|
|
|
|
// Convert the adjustment factor to a qindex delta on active_best_quality.
|
|
|
|
q_val = vp9_convert_qindex_to_q(cpi->active_best_quality);
|
|
|
|
cpi->active_best_quality +=
|
|
|
|
compute_qdelta(cpi, q_val, (q_val * q_adj_factor));
|
2012-01-11 15:05:57 +01:00
|
|
|
}
|
2013-04-16 19:59:39 +02:00
|
|
|
#else
|
|
|
|
double current_q;
|
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
// Force the KF quantizer to be 30% of the active_worst_quality.
|
|
|
|
current_q = vp9_convert_qindex_to_q(cpi->active_worst_quality);
|
|
|
|
cpi->active_best_quality = cpi->active_worst_quality
|
|
|
|
+ compute_qdelta(cpi, current_q, current_q * 0.3);
|
|
|
|
#endif
|
2013-01-15 22:49:44 +01:00
|
|
|
} else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int high = 2000;
|
|
|
|
int low = 400;
|
|
|
|
|
|
|
|
// Use the lower of cpi->active_worst_quality and recent
|
|
|
|
// average Q as basis for GF/ARF Q limit unless last frame was
|
|
|
|
// a key frame.
|
2013-04-02 19:24:56 +02:00
|
|
|
if (cpi->frames_since_key > 1 &&
|
|
|
|
cpi->avg_frame_qindex < cpi->active_worst_quality) {
|
|
|
|
q = cpi->avg_frame_qindex;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// For constrained quality dont allow Q less than the cq level
|
2013-04-02 19:24:56 +02:00
|
|
|
if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY &&
|
|
|
|
q < cpi->cq_target_quality) {
|
|
|
|
q = cpi->cq_target_quality;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
if (cpi->gfu_boost > high) {
|
|
|
|
cpi->active_best_quality = gf_low_motion_minq[q];
|
|
|
|
} else if (cpi->gfu_boost < low) {
|
|
|
|
cpi->active_best_quality = gf_high_motion_minq[q];
|
|
|
|
} else {
|
|
|
|
const int gap = high - low;
|
|
|
|
const int offset = high - cpi->gfu_boost;
|
|
|
|
const int qdiff = gf_high_motion_minq[q] - gf_low_motion_minq[q];
|
|
|
|
const int adjustment = ((offset * qdiff) + (gap >> 1)) / gap;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->active_best_quality = gf_low_motion_minq[q] + adjustment;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Constrained quality use slightly lower active best.
|
2013-04-02 19:24:56 +02:00
|
|
|
if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
|
|
|
|
cpi->active_best_quality = cpi->active_best_quality * 15 / 16;
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
2013-02-26 17:53:03 +01:00
|
|
|
#ifdef ONE_SHOT_Q_ESTIMATE
|
|
|
|
#ifdef STRICT_ONE_SHOT_Q
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->active_best_quality = q;
|
2013-02-26 17:53:03 +01:00
|
|
|
#else
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->active_best_quality = inter_minq[q];
|
2013-02-26 17:53:03 +01:00
|
|
|
#endif
|
|
|
|
#else
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->active_best_quality = inter_minq[q];
|
2013-02-26 17:53:03 +01:00
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
// For the constant/constrained quality mode we don't want
|
2012-07-14 00:21:29 +02:00
|
|
|
// q to fall below the cq level.
|
|
|
|
if ((cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
|
|
|
|
(cpi->active_best_quality < cpi->cq_target_quality)) {
|
|
|
|
// If we are strongly undershooting the target rate in the last
|
|
|
|
// frames then use the user passed in cq value not the auto
|
|
|
|
// cq value.
|
|
|
|
if (cpi->rolling_actual_bits < cpi->min_frame_bandwidth)
|
|
|
|
cpi->active_best_quality = cpi->oxcf.cq_level;
|
|
|
|
else
|
|
|
|
cpi->active_best_quality = cpi->cq_target_quality;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clip the active best and worst quality values to limits
|
|
|
|
if (cpi->active_worst_quality > cpi->worst_quality)
|
|
|
|
cpi->active_worst_quality = cpi->worst_quality;
|
|
|
|
|
|
|
|
if (cpi->active_best_quality < cpi->best_quality)
|
|
|
|
cpi->active_best_quality = cpi->best_quality;
|
|
|
|
|
|
|
|
if (cpi->active_best_quality > cpi->worst_quality)
|
|
|
|
cpi->active_best_quality = cpi->worst_quality;
|
|
|
|
|
|
|
|
if (cpi->active_worst_quality < cpi->active_best_quality)
|
|
|
|
cpi->active_worst_quality = cpi->active_best_quality;
|
|
|
|
|
2012-12-20 23:56:19 +01:00
|
|
|
// Special case code to try and match quality with forced key frames
|
2012-07-14 00:21:29 +02:00
|
|
|
if ((cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced) {
|
2013-04-02 19:24:56 +02:00
|
|
|
q = cpi->last_boosted_qindex;
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
|
|
|
// Determine initial Q to try
|
2013-04-02 19:24:56 +02:00
|
|
|
q = vp9_regulate_q(cpi, cpi->this_frame_target);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
2012-10-30 22:25:33 +01:00
|
|
|
vp9_compute_frame_size_bounds(cpi, &frame_under_shoot_limit,
|
|
|
|
&frame_over_shoot_limit);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
// Force the quantizer determined by the coding order pattern.
|
|
|
|
if (cpi->multi_arf_enabled && (cm->frame_type != KEY_FRAME)) {
|
|
|
|
double new_q;
|
|
|
|
double current_q = vp9_convert_qindex_to_q(cpi->active_worst_quality);
|
|
|
|
int level = cpi->this_frame_weight;
|
|
|
|
assert(level >= 0);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
// Set quantizer steps at 10% increments.
|
|
|
|
new_q = current_q * (1.0 - (0.2 * (cpi->max_arf_level - level)));
|
|
|
|
q = cpi->active_worst_quality + compute_qdelta(cpi, current_q, new_q);
|
|
|
|
|
|
|
|
bottom_index = q;
|
|
|
|
top_index = q;
|
|
|
|
q_low = q;
|
|
|
|
q_high = q;
|
|
|
|
|
|
|
|
printf("frame:%d q:%d\n", cm->current_video_frame, q);
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
// Limit Q range for the adaptive loop.
|
|
|
|
bottom_index = cpi->active_best_quality;
|
|
|
|
top_index = cpi->active_worst_quality;
|
|
|
|
q_low = cpi->active_best_quality;
|
|
|
|
q_high = cpi->active_worst_quality;
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
}
|
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
loop_count = 0;
|
2013-05-24 20:11:06 +02:00
|
|
|
vpx_memset(cpi->rd_tx_select_threshes, 0, sizeof(cpi->rd_tx_select_threshes));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cm->frame_type != KEY_FRAME) {
|
|
|
|
/* TODO: Decide this more intelligently */
|
|
|
|
if (sf->search_best_filter) {
|
|
|
|
cm->mcomp_filter_type = mcomp_filters_to_search[0];
|
|
|
|
mcomp_filter_index = 0;
|
2012-07-18 22:43:01 +02:00
|
|
|
} else {
|
2012-10-22 23:43:01 +02:00
|
|
|
cm->mcomp_filter_type = DEFAULT_INTERP_FILTER;
|
2012-07-18 22:43:01 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
/* TODO: Decide this more intelligently */
|
2013-04-02 19:24:56 +02:00
|
|
|
xd->allow_high_precision_mv = q < HIGH_PRECISION_MV_QTHRESH;
|
2012-11-09 00:44:39 +01:00
|
|
|
set_mvcost(&cpi->mb);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2012-02-27 19:22:38 +01:00
|
|
|
|
2012-02-13 18:05:26 +01:00
|
|
|
#if CONFIG_POSTPROC
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->oxcf.noise_sensitivity > 0) {
|
|
|
|
int l = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
switch (cpi->oxcf.noise_sensitivity) {
|
|
|
|
case 1:
|
|
|
|
l = 20;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
l = 40;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
l = 60;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
l = 100;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
l = 150;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-14 20:01:57 +02:00
|
|
|
vp9_denoise(cpi->Source, cpi->Source, l);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OUTPUT_YUV_SRC
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_write_yuv_frame(cpi->Source);
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-28 02:46:33 +02:00
|
|
|
#if RESET_FOREACH_FILTER
|
2012-07-14 00:21:29 +02:00
|
|
|
if (sf->search_best_filter) {
|
|
|
|
q_low0 = q_low;
|
|
|
|
q_high0 = q_high;
|
|
|
|
Q0 = Q;
|
|
|
|
rate_correction_factor0 = cpi->rate_correction_factor;
|
|
|
|
gf_rate_correction_factor0 = cpi->gf_rate_correction_factor;
|
|
|
|
active_best_quality0 = cpi->active_best_quality;
|
|
|
|
active_worst_quality0 = cpi->active_worst_quality;
|
|
|
|
}
|
2012-04-16 23:53:37 +02:00
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
do {
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state(); // __asm emms;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
vp9_set_quantizer(cpi, q);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (loop_count == 0) {
|
2013-04-09 19:54:19 +02:00
|
|
|
int k;
|
2012-04-16 23:53:37 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// setup skip prob for costing in mode/mv decision
|
2013-04-09 19:54:19 +02:00
|
|
|
for (k = 0; k < MBSKIP_CONTEXTS; k++)
|
|
|
|
cm->mbskip_pred_probs[k] = cpi->base_skip_false_prob[q][k];
|
|
|
|
|
|
|
|
if (cm->frame_type != KEY_FRAME) {
|
|
|
|
if (cpi->refresh_alt_ref_frame) {
|
|
|
|
for (k = 0; k < MBSKIP_CONTEXTS; k++) {
|
|
|
|
if (cpi->last_skip_false_probs[2][k] != 0)
|
|
|
|
cm->mbskip_pred_probs[k] = cpi->last_skip_false_probs[2][k];
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2013-04-09 19:54:19 +02:00
|
|
|
} else if (cpi->refresh_golden_frame) {
|
|
|
|
for (k = 0; k < MBSKIP_CONTEXTS; k++) {
|
|
|
|
if (cpi->last_skip_false_probs[1][k] != 0)
|
|
|
|
cm->mbskip_pred_probs[k] = cpi->last_skip_false_probs[1][k];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int k;
|
|
|
|
for (k = 0; k < MBSKIP_CONTEXTS; k++) {
|
|
|
|
if (cpi->last_skip_false_probs[0][k] != 0)
|
|
|
|
cm->mbskip_pred_probs[k] = cpi->last_skip_false_probs[0][k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// as this is for cost estimate, let's make sure it does not
|
|
|
|
// get extreme either way
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
for (k = 0; k < MBSKIP_CONTEXTS; ++k) {
|
|
|
|
cm->mbskip_pred_probs[k] = clamp(cm->mbskip_pred_probs[k],
|
|
|
|
5, 250);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-09 19:54:19 +02:00
|
|
|
if (cpi->is_src_frame_alt_ref)
|
|
|
|
cm->mbskip_pred_probs[k] = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2012-04-11 16:44:14 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-12-08 20:43:09 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Set up entropy depending on frame type.
|
2013-01-15 15:43:35 +01:00
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
|
|
|
/* Choose which entropy context to use. When using a forward reference
|
2013-03-26 16:34:56 +01:00
|
|
|
* frame, it immediately follows the keyframe, and thus benefits from
|
2013-04-03 00:08:50 +02:00
|
|
|
* using the same entropy context established by the keyframe.
|
|
|
|
* Otherwise, use the default context 0.
|
2013-03-26 16:34:56 +01:00
|
|
|
*/
|
2013-01-15 15:43:35 +01:00
|
|
|
cm->frame_context_idx = cpi->oxcf.play_alternate;
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_setup_key_frame(cpi);
|
2013-01-15 15:43:35 +01:00
|
|
|
} else {
|
2013-03-26 16:34:56 +01:00
|
|
|
/* Choose which entropy context to use. Currently there are only two
|
|
|
|
* contexts used, one for normal frames and one for alt ref frames.
|
|
|
|
*/
|
2013-01-15 15:43:35 +01:00
|
|
|
cpi->common.frame_context_idx = cpi->refresh_alt_ref_frame;
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_setup_inter_frame(cpi);
|
2013-01-15 15:43:35 +01:00
|
|
|
}
|
2013-04-28 00:49:49 +02:00
|
|
|
}
|
2013-04-23 15:01:55 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// transform / motion compensation build reconstruction frame
|
2012-04-16 23:53:37 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_encode_frame(cpi);
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Update the skip mb flag probabilities based on the distribution
|
|
|
|
// seen in the last encoder iteration.
|
|
|
|
update_base_skip_probs(cpi);
|
2012-04-11 15:37:48 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state(); // __asm emms;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Dummy pack of the bitstream using up to date stats to get an
|
|
|
|
// accurate estimate of output frame size to determine if we need
|
|
|
|
// to recode.
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_save_coding_context(cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->dummy_packing = 1;
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_pack_bitstream(cpi, dest, size);
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->projected_frame_size = (*size) << 3;
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_restore_coding_context(cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
if (frame_over_shoot_limit == 0)
|
|
|
|
frame_over_shoot_limit = 1;
|
2013-04-16 00:24:39 +02:00
|
|
|
active_worst_qchanged = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Special case handling for forced key frames
|
|
|
|
if ((cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced) {
|
2013-04-02 19:24:56 +02:00
|
|
|
int last_q = q;
|
2012-10-30 20:58:42 +01:00
|
|
|
int kf_err = vp9_calc_ss_err(cpi->Source,
|
2012-10-22 05:47:57 +02:00
|
|
|
&cm->yv12_fb[cm->new_fb_idx]);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
int high_err_target = cpi->ambient_err;
|
2013-04-02 19:24:56 +02:00
|
|
|
int low_err_target = cpi->ambient_err >> 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Prevent possible divide by zero error below for perfect KF
|
2013-04-02 19:24:56 +02:00
|
|
|
kf_err += !kf_err;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// The key frame is not good enough or we can afford
|
|
|
|
// to make it better without undue risk of popping.
|
2013-04-02 19:24:56 +02:00
|
|
|
if ((kf_err > high_err_target &&
|
|
|
|
cpi->projected_frame_size <= frame_over_shoot_limit) ||
|
|
|
|
(kf_err > low_err_target &&
|
|
|
|
cpi->projected_frame_size <= frame_under_shoot_limit)) {
|
2012-07-14 00:21:29 +02:00
|
|
|
// Lower q_high
|
2013-04-02 19:24:56 +02:00
|
|
|
q_high = q > q_low ? q - 1 : q_low;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Adjust Q
|
2013-04-02 19:24:56 +02:00
|
|
|
q = (q * high_err_target) / kf_err;
|
|
|
|
q = MIN(q, (q_high + q_low) >> 1);
|
|
|
|
} else if (kf_err < low_err_target &&
|
|
|
|
cpi->projected_frame_size >= frame_under_shoot_limit) {
|
|
|
|
// The key frame is much better than the previous frame
|
2012-07-14 00:21:29 +02:00
|
|
|
// Raise q_low
|
2013-04-02 19:24:56 +02:00
|
|
|
q_low = q < q_high ? q + 1 : q_high;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Adjust Q
|
2013-04-02 19:24:56 +02:00
|
|
|
q = (q * low_err_target) / kf_err;
|
|
|
|
q = MIN(q, (q_high + q_low + 1) >> 1);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clamp Q to upper and lower limits:
|
2013-04-02 19:24:56 +02:00
|
|
|
q = clamp(q, q_low, q_high);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
loop = q != last_q;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Is the projected frame size out of range and are we allowed to attempt to recode.
|
|
|
|
else if (recode_loop_test(cpi,
|
|
|
|
frame_over_shoot_limit, frame_under_shoot_limit,
|
2013-04-02 19:24:56 +02:00
|
|
|
q, top_index, bottom_index)) {
|
|
|
|
int last_q = q;
|
|
|
|
int retries = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Frame size out of permitted range:
|
|
|
|
// Update correction factor & compute new Q to try...
|
|
|
|
|
|
|
|
// Frame is too large
|
|
|
|
if (cpi->projected_frame_size > cpi->this_frame_target) {
|
2013-04-02 19:24:56 +02:00
|
|
|
// Raise Qlow as to at least the current value
|
|
|
|
q_low = q < q_high ? q + 1 : q_high;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
if (undershoot_seen || loop_count > 1) {
|
|
|
|
// Update rate_correction_factor unless cpi->active_worst_quality
|
|
|
|
// has changed.
|
2012-07-14 00:21:29 +02:00
|
|
|
if (!active_worst_qchanged)
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_update_rate_correction_factors(cpi, 1);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
q = (q_high + q_low + 1) / 2;
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
|
|
|
// Update rate_correction_factor unless cpi->active_worst_quality has changed.
|
|
|
|
if (!active_worst_qchanged)
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_update_rate_correction_factors(cpi, 0);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
q = vp9_regulate_q(cpi, cpi->this_frame_target);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
while (q < q_low && retries < 10) {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_update_rate_correction_factors(cpi, 0);
|
2013-04-02 19:24:56 +02:00
|
|
|
q = vp9_regulate_q(cpi, cpi->this_frame_target);
|
|
|
|
retries++;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-01-17 18:23:11 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-16 00:24:39 +02:00
|
|
|
overshoot_seen = 1;
|
2013-04-02 19:24:56 +02:00
|
|
|
} else {
|
|
|
|
// Frame is too small
|
|
|
|
q_high = q > q_low ? q - 1 : q_low;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
if (overshoot_seen || loop_count > 1) {
|
2012-07-14 00:21:29 +02:00
|
|
|
// Update rate_correction_factor unless cpi->active_worst_quality has changed.
|
|
|
|
if (!active_worst_qchanged)
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_update_rate_correction_factors(cpi, 1);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
q = (q_high + q_low) / 2;
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
|
|
|
// Update rate_correction_factor unless cpi->active_worst_quality has changed.
|
|
|
|
if (!active_worst_qchanged)
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_update_rate_correction_factors(cpi, 0);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
q = vp9_regulate_q(cpi, cpi->this_frame_target);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Special case reset for qlow for constrained quality.
|
|
|
|
// This should only trigger where there is very substantial
|
|
|
|
// undershoot on a frame and the auto cq level is above
|
|
|
|
// the user passsed in value.
|
2013-04-02 19:24:56 +02:00
|
|
|
if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY && q < q_low) {
|
|
|
|
q_low = q;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
while (q > q_high && retries < 10) {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_update_rate_correction_factors(cpi, 0);
|
2013-04-02 19:24:56 +02:00
|
|
|
q = vp9_regulate_q(cpi, cpi->this_frame_target);
|
|
|
|
retries++;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
}
|
2010-11-17 16:12:04 +01:00
|
|
|
|
2013-04-16 00:24:39 +02:00
|
|
|
undershoot_seen = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Clamp Q to upper and lower limits:
|
2013-04-02 19:24:56 +02:00
|
|
|
q = clamp(q, q_low, q_high);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
loop = q != last_q;
|
|
|
|
} else {
|
2013-04-16 00:24:39 +02:00
|
|
|
loop = 0;
|
2013-04-02 19:24:56 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->is_src_frame_alt_ref)
|
2013-04-16 00:24:39 +02:00
|
|
|
loop = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
if (!loop && cm->frame_type != KEY_FRAME && sf->search_best_filter) {
|
2012-07-14 00:21:29 +02:00
|
|
|
if (mcomp_filter_index < mcomp_filters) {
|
2012-12-14 21:35:33 +01:00
|
|
|
int64_t err = vp9_calc_ss_err(cpi->Source,
|
2012-10-22 05:47:57 +02:00
|
|
|
&cm->yv12_fb[cm->new_fb_idx]);
|
2012-12-14 21:35:33 +01:00
|
|
|
int64_t rate = cpi->projected_frame_size << 8;
|
2012-07-14 00:21:29 +02:00
|
|
|
mcomp_filter_cost[mcomp_filter_index] =
|
|
|
|
(RDCOST(cpi->RDMULT, cpi->RDDIV, rate, err));
|
|
|
|
mcomp_filter_index++;
|
|
|
|
if (mcomp_filter_index < mcomp_filters) {
|
|
|
|
cm->mcomp_filter_type = mcomp_filters_to_search[mcomp_filter_index];
|
|
|
|
loop_count = -1;
|
2013-04-16 00:24:39 +02:00
|
|
|
loop = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
|
|
|
int f;
|
2012-12-14 21:35:33 +01:00
|
|
|
int64_t best_cost = mcomp_filter_cost[0];
|
2012-07-14 00:21:29 +02:00
|
|
|
int mcomp_best_filter = mcomp_filters_to_search[0];
|
|
|
|
for (f = 1; f < mcomp_filters; f++) {
|
|
|
|
if (mcomp_filter_cost[f] < best_cost) {
|
|
|
|
mcomp_best_filter = mcomp_filters_to_search[f];
|
|
|
|
best_cost = mcomp_filter_cost[f];
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
if (mcomp_best_filter != mcomp_filters_to_search[mcomp_filters - 1]) {
|
|
|
|
loop_count = -1;
|
2013-04-16 00:24:39 +02:00
|
|
|
loop = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->mcomp_filter_type = mcomp_best_filter;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
printf(" best filter = %d, ( ", mcomp_best_filter);
|
|
|
|
for (f=0;f<mcomp_filters; f++) printf("%d ", mcomp_filter_cost[f]);
|
|
|
|
printf(")\n");
|
|
|
|
*/
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-04-16 23:53:37 +02:00
|
|
|
#if RESET_FOREACH_FILTER
|
2013-04-02 19:24:56 +02:00
|
|
|
if (loop) {
|
2013-04-16 00:24:39 +02:00
|
|
|
overshoot_seen = 0;
|
|
|
|
undershoot_seen = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
q_low = q_low0;
|
|
|
|
q_high = q_high0;
|
2013-04-02 19:24:56 +02:00
|
|
|
q = Q0;
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->rate_correction_factor = rate_correction_factor0;
|
|
|
|
cpi->gf_rate_correction_factor = gf_rate_correction_factor0;
|
|
|
|
cpi->active_best_quality = active_best_quality0;
|
|
|
|
cpi->active_worst_quality = active_worst_quality0;
|
2012-04-16 23:53:37 +02:00
|
|
|
}
|
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-16 23:53:37 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
if (loop) {
|
2012-07-14 00:21:29 +02:00
|
|
|
loop_count++;
|
2012-12-20 23:56:19 +01:00
|
|
|
|
2011-04-29 18:37:59 +02:00
|
|
|
#if CONFIG_INTERNAL_STATS
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->tot_recode_hits++;
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2011-01-17 18:23:11 +01:00
|
|
|
}
|
2013-04-02 19:24:56 +02:00
|
|
|
} while (loop);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Special case code to reduce pulsing when key frames are forced at a
|
|
|
|
// fixed interval. Note the reconstruction error if it is the frame before
|
|
|
|
// the force key frame
|
|
|
|
if (cpi->next_key_frame_forced && (cpi->twopass.frames_to_key == 0)) {
|
2012-10-30 20:58:42 +01:00
|
|
|
cpi->ambient_err = vp9_calc_ss_err(cpi->Source,
|
2012-10-22 05:47:57 +02:00
|
|
|
&cm->yv12_fb[cm->new_fb_idx]);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_last_frame = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->frame_to_show = &cm->yv12_fb[cm->new_fb_idx];
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2011-11-16 01:16:30 +01:00
|
|
|
#if WRITE_RECON_BUFFER
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cm->show_frame)
|
|
|
|
write_cx_frame_to_file(cm->frame_to_show,
|
|
|
|
cm->current_video_frame);
|
|
|
|
else
|
|
|
|
write_cx_frame_to_file(cm->frame_to_show,
|
|
|
|
cm->current_video_frame + 1000);
|
2011-11-16 01:16:30 +01:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Pick the loop filter level for the frame.
|
|
|
|
loopfilter_frame(cpi, cm);
|
2012-01-28 13:20:14 +01:00
|
|
|
|
2013-05-17 21:50:40 +02:00
|
|
|
#if WRITE_RECON_BUFFER
|
|
|
|
if (cm->show_frame)
|
|
|
|
write_cx_frame_to_file(cm->frame_to_show,
|
|
|
|
cm->current_video_frame + 2000);
|
|
|
|
else
|
|
|
|
write_cx_frame_to_file(cm->frame_to_show,
|
|
|
|
cm->current_video_frame + 3000);
|
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// build the bitstream
|
|
|
|
cpi->dummy_packing = 0;
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_pack_bitstream(cpi, dest, size);
|
2011-02-18 14:46:07 +01:00
|
|
|
|
2013-04-23 15:01:55 +02:00
|
|
|
if (xd->update_mb_segmentation_map) {
|
2012-08-20 23:43:34 +02:00
|
|
|
update_reference_segmentation_map(cpi);
|
2013-04-23 15:01:55 +02:00
|
|
|
}
|
2012-08-20 23:43:34 +02:00
|
|
|
|
2013-02-20 21:34:31 +01:00
|
|
|
release_scaled_references(cpi);
|
2013-01-15 22:49:44 +01:00
|
|
|
update_reference_frames(cpi);
|
2013-05-17 15:40:25 +02:00
|
|
|
|
2013-05-31 18:18:59 +02:00
|
|
|
for (t = TX_4X4; t <= TX_32X32; t++)
|
|
|
|
vp9_full_to_model_counts(cpi->common.fc.coef_counts[t],
|
|
|
|
cpi->coef_counts[t]);
|
2013-01-25 20:30:28 +01:00
|
|
|
if (!cpi->common.error_resilient_mode &&
|
2013-02-20 19:16:24 +01:00
|
|
|
!cpi->common.frame_parallel_decoding_mode) {
|
2013-01-15 15:43:35 +01:00
|
|
|
vp9_adapt_coef_probs(&cpi->common);
|
2013-02-20 19:16:24 +01:00
|
|
|
}
|
2013-04-26 20:57:17 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->common.frame_type != KEY_FRAME) {
|
2013-05-30 18:58:53 +02:00
|
|
|
vp9_copy(cpi->common.fc.y_mode_counts, cpi->y_mode_count);
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_copy(cpi->common.fc.uv_mode_counts, cpi->y_uv_mode_count);
|
2013-04-16 09:18:02 +02:00
|
|
|
vp9_copy(cpi->common.fc.partition_counts, cpi->partition_count);
|
2012-07-26 22:42:07 +02:00
|
|
|
cpi->common.fc.NMVcount = cpi->NMVcount;
|
2013-01-25 20:30:28 +01:00
|
|
|
if (!cpi->common.error_resilient_mode &&
|
|
|
|
!cpi->common.frame_parallel_decoding_mode) {
|
|
|
|
vp9_adapt_mode_probs(&cpi->common);
|
|
|
|
vp9_adapt_mode_context(&cpi->common);
|
2013-01-15 15:43:35 +01:00
|
|
|
vp9_adapt_nmv_probs(&cpi->common, cpi->mb.e_mbd.allow_high_precision_mv);
|
2013-01-25 20:30:28 +01:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2012-02-27 19:22:38 +01:00
|
|
|
|
2013-05-16 12:27:12 +02:00
|
|
|
#ifdef ENTROPY_STATS
|
|
|
|
vp9_update_mode_context_stats(cpi);
|
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/* Move storing frame_type out of the above loop since it is also
|
|
|
|
* needed in motion search besides loopfilter */
|
|
|
|
cm->last_frame_type = cm->frame_type;
|
|
|
|
|
|
|
|
// Update rate control heuristics
|
|
|
|
cpi->total_byte_count += (*size);
|
|
|
|
cpi->projected_frame_size = (*size) << 3;
|
|
|
|
|
|
|
|
if (!active_worst_qchanged)
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_update_rate_correction_factors(cpi, 2);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
cpi->last_q[cm->frame_type] = cm->base_qindex;
|
|
|
|
|
|
|
|
// Keep record of last boosted (KF/KF/ARF) Q value.
|
|
|
|
// If the current frame is coded at a lower Q then we also update it.
|
|
|
|
// If all mbs in this group are skipped only update if the Q value is
|
|
|
|
// better than that already stored.
|
|
|
|
// This is used to help set quality in forced key frames to reduce popping
|
|
|
|
if ((cm->base_qindex < cpi->last_boosted_qindex) ||
|
|
|
|
((cpi->static_mb_pct < 100) &&
|
|
|
|
((cm->frame_type == KEY_FRAME) ||
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_alt_ref_frame ||
|
|
|
|
(cpi->refresh_golden_frame && !cpi->is_src_frame_alt_ref)))) {
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->last_boosted_qindex = cm->base_qindex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_adjust_key_frame_context(cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Keep a record of ambient average Q.
|
|
|
|
if (cm->frame_type != KEY_FRAME)
|
|
|
|
cpi->avg_frame_qindex = (2 + 3 * cpi->avg_frame_qindex + cm->base_qindex) >> 2;
|
|
|
|
|
|
|
|
// Keep a record from which we can calculate the average Q excluding GF updates and key frames
|
2013-04-02 19:24:56 +02:00
|
|
|
if (cm->frame_type != KEY_FRAME &&
|
|
|
|
!cpi->refresh_golden_frame &&
|
|
|
|
!cpi->refresh_alt_ref_frame) {
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->ni_frames++;
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->tot_q += vp9_convert_qindex_to_q(q);
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->avg_q = cpi->tot_q / (double)cpi->ni_frames;
|
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
// Calculate the average Q for normal inter frames (not key or GFU frames).
|
|
|
|
cpi->ni_tot_qi += q;
|
|
|
|
cpi->ni_av_qi = cpi->ni_tot_qi / cpi->ni_frames;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the buffer level variable.
|
|
|
|
// Non-viewable frames are a special case and are treated as pure overhead.
|
|
|
|
if (!cm->show_frame)
|
|
|
|
cpi->bits_off_target -= cpi->projected_frame_size;
|
|
|
|
else
|
|
|
|
cpi->bits_off_target += cpi->av_per_frame_bandwidth - cpi->projected_frame_size;
|
|
|
|
|
|
|
|
// Clip the buffer level at the maximum buffer size
|
|
|
|
if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
|
|
|
|
cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
|
|
|
|
|
2013-02-25 13:36:38 +01:00
|
|
|
// Rolling monitors of whether we are over or underspending used to help
|
|
|
|
// regulate min and Max Q in two pass.
|
|
|
|
if (cm->frame_type != KEY_FRAME) {
|
|
|
|
cpi->rolling_target_bits =
|
|
|
|
((cpi->rolling_target_bits * 3) + cpi->this_frame_target + 2) / 4;
|
|
|
|
cpi->rolling_actual_bits =
|
|
|
|
((cpi->rolling_actual_bits * 3) + cpi->projected_frame_size + 2) / 4;
|
|
|
|
cpi->long_rolling_target_bits =
|
|
|
|
((cpi->long_rolling_target_bits * 31) + cpi->this_frame_target + 16) / 32;
|
|
|
|
cpi->long_rolling_actual_bits =
|
|
|
|
((cpi->long_rolling_actual_bits * 31) +
|
|
|
|
cpi->projected_frame_size + 16) / 32;
|
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Actual bits spent
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->total_actual_bits += cpi->projected_frame_size;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Debug stats
|
|
|
|
cpi->total_target_vs_actual += (cpi->this_frame_target - cpi->projected_frame_size);
|
|
|
|
|
|
|
|
cpi->buffer_level = cpi->bits_off_target;
|
|
|
|
|
|
|
|
// Update bits left to the kf and gf groups to account for overshoot or undershoot on these frames
|
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
|
|
|
cpi->twopass.kf_group_bits += cpi->this_frame_target - cpi->projected_frame_size;
|
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->twopass.kf_group_bits = MAX(cpi->twopass.kf_group_bits, 0);
|
2013-01-15 22:49:44 +01:00
|
|
|
} else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) {
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->twopass.gf_group_bits += cpi->this_frame_target - cpi->projected_frame_size;
|
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->twopass.gf_group_bits = MAX(cpi->twopass.gf_group_bits, 0);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the skip mb flag probabilities based on the distribution seen
|
|
|
|
// in this frame.
|
|
|
|
update_base_skip_probs(cpi);
|
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
#if 0 && CONFIG_INTERNAL_STATS
|
2012-07-14 00:21:29 +02:00
|
|
|
{
|
|
|
|
FILE *f = fopen("tmp.stt", "a");
|
|
|
|
int recon_err;
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state(); // __asm emms;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
recon_err = vp9_calc_ss_err(cpi->Source,
|
2012-10-22 05:47:57 +02:00
|
|
|
&cm->yv12_fb[cm->new_fb_idx]);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-05-25 20:41:25 +02:00
|
|
|
if (cpi->twopass.total_left_stats.coded_error != 0.0)
|
2012-07-14 00:21:29 +02:00
|
|
|
fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d"
|
|
|
|
"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f"
|
2013-03-12 16:33:40 +01:00
|
|
|
"%6d %6d %5d %5d %5d %8.2f %10d %10.3f"
|
2012-07-14 00:21:29 +02:00
|
|
|
"%10.3f %8d %10d %10d %10d\n",
|
|
|
|
cpi->common.current_video_frame, cpi->this_frame_target,
|
2012-12-23 16:20:10 +01:00
|
|
|
cpi->projected_frame_size, 0, //loop_size_estimate,
|
2012-07-14 00:21:29 +02:00
|
|
|
(cpi->projected_frame_size - cpi->this_frame_target),
|
|
|
|
(int)cpi->total_target_vs_actual,
|
2013-03-12 16:33:40 +01:00
|
|
|
(int)(cpi->oxcf.starting_buffer_level - cpi->bits_off_target),
|
2012-07-14 00:21:29 +02:00
|
|
|
(int)cpi->total_actual_bits,
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_convert_qindex_to_q(cm->base_qindex),
|
2012-10-31 00:25:53 +01:00
|
|
|
(double)vp9_dc_quant(cm->base_qindex, 0) / 4.0,
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_convert_qindex_to_q(cpi->active_best_quality),
|
|
|
|
vp9_convert_qindex_to_q(cpi->active_worst_quality),
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->avg_q,
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_convert_qindex_to_q(cpi->ni_av_qi),
|
|
|
|
vp9_convert_qindex_to_q(cpi->cq_target_quality),
|
2013-03-12 16:33:40 +01:00
|
|
|
cpi->refresh_last_frame,
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame,
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->frame_type, cpi->gfu_boost,
|
|
|
|
cpi->twopass.est_max_qcorrection_factor,
|
|
|
|
(int)cpi->twopass.bits_left,
|
2013-05-25 20:41:25 +02:00
|
|
|
cpi->twopass.total_left_stats.coded_error,
|
2012-07-14 00:21:29 +02:00
|
|
|
(double)cpi->twopass.bits_left /
|
2013-05-25 20:41:25 +02:00
|
|
|
cpi->twopass.total_left_stats.coded_error,
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->tot_recode_hits, recon_err, cpi->kf_boost,
|
|
|
|
cpi->kf_zeromotion_pct);
|
2011-08-12 20:51:36 +02:00
|
|
|
else
|
2012-07-14 00:21:29 +02:00
|
|
|
fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d"
|
|
|
|
"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f"
|
2013-03-12 16:33:40 +01:00
|
|
|
"%5d %5d %5d %8d %8d %8.2f %10d %10.3f"
|
2012-07-14 00:21:29 +02:00
|
|
|
"%8d %10d %10d %10d\n",
|
|
|
|
cpi->common.current_video_frame,
|
|
|
|
cpi->this_frame_target, cpi->projected_frame_size,
|
2012-12-23 16:20:10 +01:00
|
|
|
0, //loop_size_estimate,
|
2012-07-14 00:21:29 +02:00
|
|
|
(cpi->projected_frame_size - cpi->this_frame_target),
|
|
|
|
(int)cpi->total_target_vs_actual,
|
2013-03-12 16:33:40 +01:00
|
|
|
(int)(cpi->oxcf.starting_buffer_level - cpi->bits_off_target),
|
2012-07-14 00:21:29 +02:00
|
|
|
(int)cpi->total_actual_bits,
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_convert_qindex_to_q(cm->base_qindex),
|
2012-10-31 00:25:53 +01:00
|
|
|
(double)vp9_dc_quant(cm->base_qindex, 0) / 4.0,
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_convert_qindex_to_q(cpi->active_best_quality),
|
|
|
|
vp9_convert_qindex_to_q(cpi->active_worst_quality),
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->avg_q,
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_convert_qindex_to_q(cpi->ni_av_qi),
|
|
|
|
vp9_convert_qindex_to_q(cpi->cq_target_quality),
|
2013-03-12 16:33:40 +01:00
|
|
|
cpi->refresh_last_frame,
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame,
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->frame_type, cpi->gfu_boost,
|
|
|
|
cpi->twopass.est_max_qcorrection_factor,
|
|
|
|
(int)cpi->twopass.bits_left,
|
2013-05-25 20:41:25 +02:00
|
|
|
cpi->twopass.total_left_stats.coded_error,
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->tot_recode_hits, recon_err, cpi->kf_boost,
|
|
|
|
cpi->kf_zeromotion_pct);
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
FILE *fmodes = fopen("Modes.stt", "a");
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fprintf(fmodes, "%6d:%1d:%1d:%1d ",
|
|
|
|
cpi->common.current_video_frame,
|
2013-01-15 22:49:44 +01:00
|
|
|
cm->frame_type, cpi->refresh_golden_frame,
|
|
|
|
cpi->refresh_alt_ref_frame);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_MODES; i++)
|
|
|
|
fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]);
|
|
|
|
|
|
|
|
fprintf(fmodes, "\n");
|
|
|
|
|
|
|
|
fclose(fmodes);
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-09-30 17:45:16 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
2012-07-14 00:21:29 +02:00
|
|
|
// Debug stats for segment feature experiments.
|
|
|
|
print_seg_map(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// If this was a kf or Gf note the Q
|
2013-01-15 22:49:44 +01:00
|
|
|
if ((cm->frame_type == KEY_FRAME)
|
|
|
|
|| cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->last_kf_gf_q = cm->base_qindex;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_golden_frame == 1)
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->frame_flags = cm->frame_flags | FRAMEFLAGS_GOLDEN;
|
|
|
|
else
|
|
|
|
cm->frame_flags = cm->frame_flags&~FRAMEFLAGS_GOLDEN;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_alt_ref_frame == 1)
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->frame_flags = cm->frame_flags | FRAMEFLAGS_ALTREF;
|
|
|
|
else
|
|
|
|
cm->frame_flags = cm->frame_flags&~FRAMEFLAGS_ALTREF;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_last_frame & cpi->refresh_golden_frame)
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->gold_is_last = 1;
|
2013-01-15 22:49:44 +01:00
|
|
|
else if (cpi->refresh_last_frame ^ cpi->refresh_golden_frame)
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->gold_is_last = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_last_frame & cpi->refresh_alt_ref_frame)
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->alt_is_last = 1;
|
2013-01-15 22:49:44 +01:00
|
|
|
else if (cpi->refresh_last_frame ^ cpi->refresh_alt_ref_frame)
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->alt_is_last = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->refresh_alt_ref_frame & cpi->refresh_golden_frame)
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->gold_is_alt = 1;
|
2013-01-15 22:49:44 +01:00
|
|
|
else if (cpi->refresh_alt_ref_frame ^ cpi->refresh_golden_frame)
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->gold_is_alt = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->gold_is_last)
|
2012-10-31 22:40:53 +01:00
|
|
|
cpi->ref_frame_flags &= ~VP9_GOLD_FLAG;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->alt_is_last)
|
2012-10-31 22:40:53 +01:00
|
|
|
cpi->ref_frame_flags &= ~VP9_ALT_FLAG;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->gold_is_alt)
|
2012-10-31 22:40:53 +01:00
|
|
|
cpi->ref_frame_flags &= ~VP9_ALT_FLAG;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (cpi->oxcf.play_alternate && cpi->refresh_alt_ref_frame
|
|
|
|
&& (cm->frame_type != KEY_FRAME))
|
2012-07-14 00:21:29 +02:00
|
|
|
// Update the alternate reference frame stats as appropriate.
|
|
|
|
update_alt_ref_frame_stats(cpi);
|
|
|
|
else
|
|
|
|
// Update the Golden frame stats as appropriate.
|
|
|
|
update_golden_frame_stats(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
|
|
|
// Tell the caller that the frame was coded as a key frame
|
|
|
|
*frame_flags = cm->frame_flags | FRAMEFLAGS_KEY;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
// Reset the sequence number.
|
|
|
|
if (cpi->multi_arf_enabled) {
|
|
|
|
cpi->sequence_number = 0;
|
|
|
|
cpi->frame_coding_order_period = cpi->new_frame_coding_order_period;
|
|
|
|
cpi->new_frame_coding_order_period = -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// As this frame is a key frame the next defaults to an inter frame.
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->frame_type = INTER_FRAME;
|
|
|
|
} else {
|
|
|
|
*frame_flags = cm->frame_flags&~FRAMEFLAGS_KEY;
|
2013-04-03 00:08:50 +02:00
|
|
|
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
/* Increment position in the coded frame sequence. */
|
|
|
|
if (cpi->multi_arf_enabled) {
|
|
|
|
++cpi->sequence_number;
|
|
|
|
if (cpi->sequence_number >= cpi->frame_coding_order_period) {
|
|
|
|
cpi->sequence_number = 0;
|
|
|
|
cpi->frame_coding_order_period = cpi->new_frame_coding_order_period;
|
|
|
|
cpi->new_frame_coding_order_period = -1;
|
|
|
|
}
|
|
|
|
cpi->this_frame_weight = cpi->arf_weight[cpi->sequence_number];
|
|
|
|
assert(cpi->this_frame_weight >= 0);
|
|
|
|
}
|
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Clear the one shot update flags for segmentation map and mode/ref loop filter deltas.
|
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
|
|
|
xd->mode_ref_lf_delta_update = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-02-20 21:34:31 +01:00
|
|
|
// keep track of the last coded dimensions
|
2013-03-21 00:41:30 +01:00
|
|
|
cm->last_width = cm->width;
|
|
|
|
cm->last_height = cm->height;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
// Don't increment frame counters if this was an altref buffer
|
|
|
|
// update not a real frame
|
2013-05-26 23:40:49 +02:00
|
|
|
cm->last_show_frame = cm->show_frame;
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cm->show_frame) {
|
2013-04-03 00:08:50 +02:00
|
|
|
++cm->current_video_frame;
|
|
|
|
++cpi->frames_since_key;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// reset to normal state now that we are done.
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-09-24 17:10:25 +02:00
|
|
|
#if 0
|
2012-07-14 00:21:29 +02:00
|
|
|
{
|
|
|
|
char filename[512];
|
|
|
|
FILE *recon_file;
|
|
|
|
sprintf(filename, "enc%04d.yuv", (int) cm->current_video_frame);
|
|
|
|
recon_file = fopen(filename, "wb");
|
2013-02-22 20:22:03 +01:00
|
|
|
fwrite(cm->yv12_fb[cm->ref_frame_map[cpi->lst_fb_idx]].buffer_alloc,
|
|
|
|
cm->yv12_fb[cm->ref_frame_map[cpi->lst_fb_idx]].frame_size,
|
2013-01-15 22:49:44 +01:00
|
|
|
1, recon_file);
|
2012-07-14 00:21:29 +02:00
|
|
|
fclose(recon_file);
|
|
|
|
}
|
2010-09-24 17:10:25 +02:00
|
|
|
#endif
|
2012-02-27 19:22:38 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_write_yuv_rec_frame(cm);
|
2010-12-02 00:50:14 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cm->show_frame) {
|
|
|
|
vpx_memcpy(cm->prev_mip, cm->mip,
|
2013-04-26 20:57:17 +02:00
|
|
|
cm->mode_info_stride * (cm->mi_rows + 1) *
|
|
|
|
sizeof(MODE_INFO));
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
|
|
|
vpx_memset(cm->prev_mip, 0,
|
2013-04-26 20:57:17 +02:00
|
|
|
cm->mode_info_stride * (cm->mi_rows + 1) *
|
|
|
|
sizeof(MODE_INFO));
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2013-05-29 22:42:23 +02:00
|
|
|
// restore prev_mi
|
|
|
|
cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void Pass2Encode(VP9_COMP *cpi, unsigned long *size,
|
2012-10-30 22:25:33 +01:00
|
|
|
unsigned char *dest, unsigned int *frame_flags) {
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (!cpi->refresh_alt_ref_frame)
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_second_pass(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
encode_frame_to_data_rate(cpi, size, dest, frame_flags);
|
2013-02-25 13:36:38 +01:00
|
|
|
|
|
|
|
#ifdef DISABLE_RC_LONG_TERM_MEM
|
|
|
|
cpi->twopass.bits_left -= cpi->this_frame_target;
|
|
|
|
#else
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->twopass.bits_left -= 8 * *size;
|
2013-02-25 13:36:38 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-01-15 22:49:44 +01:00
|
|
|
if (!cpi->refresh_alt_ref_frame) {
|
2012-07-14 00:21:29 +02:00
|
|
|
double lower_bounds_min_rate = FRAME_OVERHEAD_BITS * cpi->oxcf.frame_rate;
|
|
|
|
double two_pass_min_rate = (double)(cpi->oxcf.target_bandwidth
|
|
|
|
* cpi->oxcf.two_pass_vbrmin_section / 100);
|
2012-03-02 02:24:30 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (two_pass_min_rate < lower_bounds_min_rate)
|
|
|
|
two_pass_min_rate = lower_bounds_min_rate;
|
2012-03-02 02:24:30 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->twopass.bits_left += (int64_t)(two_pass_min_rate / cpi->oxcf.frame_rate);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_receive_raw_frame(VP9_PTR ptr, unsigned int frame_flags,
|
2012-10-30 22:25:33 +01:00
|
|
|
YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
|
|
|
|
int64_t end_time) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *) ptr;
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2012-07-14 00:21:29 +02:00
|
|
|
struct vpx_usec_timer timer;
|
|
|
|
int res = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-07 00:52:06 +02:00
|
|
|
if (!cpi->initial_width) {
|
|
|
|
// TODO(jkoleszar): Support 1/4 subsampling?
|
|
|
|
cm->subsampling_x = sd->uv_width < sd->y_width;
|
|
|
|
cm->subsampling_y = sd->uv_height < sd->y_height;
|
|
|
|
alloc_raw_frame_buffers(cpi);
|
|
|
|
|
|
|
|
cpi->initial_width = cm->width;
|
|
|
|
cpi->initial_height = cm->height;
|
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_usec_timer_start(&timer);
|
2012-10-30 22:25:33 +01:00
|
|
|
if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags,
|
|
|
|
cpi->active_map_enabled ? cpi->active_map : NULL))
|
2012-07-14 00:21:29 +02:00
|
|
|
res = -1;
|
|
|
|
cm->clr_type = sd->clrtype;
|
|
|
|
vpx_usec_timer_mark(&timer);
|
|
|
|
cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return res;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-04-13 20:00:18 +02:00
|
|
|
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static int frame_is_reference(const VP9_COMP *cpi) {
|
|
|
|
const VP9_COMMON *cm = &cpi->common;
|
2013-04-02 19:24:56 +02:00
|
|
|
const MACROBLOCKD *mb = &cpi->mb.e_mbd;
|
2011-07-07 16:38:23 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
return cm->frame_type == KEY_FRAME ||
|
|
|
|
cpi->refresh_last_frame ||
|
|
|
|
cpi->refresh_golden_frame ||
|
|
|
|
cpi->refresh_alt_ref_frame ||
|
2013-04-26 23:39:58 +02:00
|
|
|
cm->refresh_frame_context ||
|
2013-04-02 19:24:56 +02:00
|
|
|
mb->mode_ref_lf_delta_update ||
|
|
|
|
mb->update_mb_segmentation_map ||
|
|
|
|
mb->update_mb_segmentation_data;
|
2011-07-07 16:38:23 +02:00
|
|
|
}
|
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
int is_next_frame_arf(VP9_COMP *cpi) {
|
|
|
|
// Negative entry in frame_coding_order indicates an ARF at this position.
|
|
|
|
return cpi->frame_coding_order[cpi->sequence_number + 1] < 0 ? 1 : 0;
|
|
|
|
}
|
|
|
|
#endif
|
2011-07-07 16:38:23 +02:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
|
2012-10-30 22:25:33 +01:00
|
|
|
unsigned long *size, unsigned char *dest,
|
|
|
|
int64_t *time_stamp, int64_t *time_end, int flush) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *) ptr;
|
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2012-07-14 00:21:29 +02:00
|
|
|
struct vpx_usec_timer cmptimer;
|
|
|
|
YV12_BUFFER_CONFIG *force_src_buffer = NULL;
|
2013-04-03 21:22:50 +02:00
|
|
|
int i;
|
2013-04-03 00:08:50 +02:00
|
|
|
// FILE *fp_out = fopen("enc_frame_type.txt", "a");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (!cpi)
|
|
|
|
return -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_usec_timer_start(&cmptimer);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->source = NULL;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->mb.e_mbd.allow_high_precision_mv = ALTREF_HIGH_PRECISION_MV;
|
2012-11-09 00:44:39 +01:00
|
|
|
set_mvcost(&cpi->mb);
|
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
// Should we code an alternate reference frame.
|
|
|
|
if (cpi->oxcf.play_alternate && cpi->source_alt_ref_pending) {
|
|
|
|
int frames_to_arf;
|
|
|
|
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
assert(!cpi->multi_arf_enabled ||
|
|
|
|
cpi->frame_coding_order[cpi->sequence_number] < 0);
|
|
|
|
|
|
|
|
if (cpi->multi_arf_enabled && (cpi->pass == 2))
|
|
|
|
frames_to_arf = (-cpi->frame_coding_order[cpi->sequence_number])
|
|
|
|
- cpi->next_frame_in_order;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
frames_to_arf = cpi->frames_till_gf_update_due;
|
|
|
|
|
|
|
|
assert(frames_to_arf < cpi->twopass.frames_to_key);
|
|
|
|
|
|
|
|
if ((cpi->source = vp9_lookahead_peek(cpi->lookahead, frames_to_arf))) {
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
cpi->alt_ref_source[cpi->arf_buffered] = cpi->source;
|
|
|
|
#else
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->alt_ref_source = cpi->source;
|
2013-04-03 00:08:50 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->oxcf.arnr_max_frames > 0) {
|
2013-04-03 00:08:50 +02:00
|
|
|
// Produce the filtered ARF frame.
|
|
|
|
// TODO(agrange) merge these two functions.
|
|
|
|
configure_arnr_filter(cpi, cm->current_video_frame + frames_to_arf,
|
|
|
|
cpi->gfu_boost);
|
|
|
|
vp9_temporal_filter_prepare(cpi, frames_to_arf);
|
2012-07-14 00:21:29 +02:00
|
|
|
force_src_buffer = &cpi->alt_ref_buffer;
|
|
|
|
}
|
2013-04-03 00:08:50 +02:00
|
|
|
|
|
|
|
cm->show_frame = 0;
|
2013-05-30 02:16:00 +02:00
|
|
|
cm->intra_only = 0;
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_alt_ref_frame = 1;
|
|
|
|
cpi->refresh_golden_frame = 0;
|
|
|
|
cpi->refresh_last_frame = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->is_src_frame_alt_ref = 0;
|
2013-04-03 00:08:50 +02:00
|
|
|
|
|
|
|
// TODO(agrange) This needs to vary depending on where the next ARF is.
|
|
|
|
cm->frames_till_alt_ref_frame = frames_to_arf;
|
|
|
|
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
if (!cpi->multi_arf_enabled)
|
|
|
|
#endif
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->source_alt_ref_pending = 0; // Clear Pending altf Ref flag.
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cpi->source) {
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
int i;
|
|
|
|
#endif
|
2012-10-30 20:58:42 +01:00
|
|
|
if ((cpi->source = vp9_lookahead_pop(cpi->lookahead, flush))) {
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->show_frame = 1;
|
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
// Is this frame the ARF overlay.
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->is_src_frame_alt_ref = 0;
|
2013-04-03 00:08:50 +02:00
|
|
|
for (i = 0; i < cpi->arf_buffered; ++i) {
|
|
|
|
if (cpi->source == cpi->alt_ref_source[i]) {
|
2013-04-16 00:24:39 +02:00
|
|
|
cpi->is_src_frame_alt_ref = 1;
|
|
|
|
cpi->refresh_golden_frame = 1;
|
2013-04-03 00:08:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->is_src_frame_alt_ref = cpi->alt_ref_source
|
|
|
|
&& (cpi->source == cpi->alt_ref_source);
|
2013-04-03 00:08:50 +02:00
|
|
|
#endif
|
2013-03-12 16:33:40 +01:00
|
|
|
if (cpi->is_src_frame_alt_ref) {
|
2013-04-03 00:08:50 +02:00
|
|
|
// Current frame is an ARF overlay frame.
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
cpi->alt_ref_source[i] = NULL;
|
|
|
|
#else
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->alt_ref_source = NULL;
|
2013-04-03 00:08:50 +02:00
|
|
|
#endif
|
|
|
|
// Don't refresh the last buffer for an ARF overlay frame. It will
|
|
|
|
// become the GF so preserve last as an alternative prediction option.
|
|
|
|
cpi->refresh_last_frame = 0;
|
2013-03-12 16:33:40 +01:00
|
|
|
}
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
++cpi->next_frame_in_order;
|
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->source) {
|
2013-04-02 19:24:56 +02:00
|
|
|
cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer
|
|
|
|
: &cpi->source->img;
|
2012-07-14 00:21:29 +02:00
|
|
|
*time_stamp = cpi->source->ts_start;
|
|
|
|
*time_end = cpi->source->ts_end;
|
|
|
|
*frame_flags = cpi->source->flags;
|
2013-04-03 00:08:50 +02:00
|
|
|
|
|
|
|
// fprintf(fp_out, " Frame:%d", cm->current_video_frame);
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
if (cpi->multi_arf_enabled) {
|
|
|
|
// fprintf(fp_out, " seq_no:%d this_frame_weight:%d",
|
|
|
|
// cpi->sequence_number, cpi->this_frame_weight);
|
|
|
|
} else {
|
|
|
|
// fprintf(fp_out, "\n");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// fprintf(fp_out, "\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
if ((cm->frame_type != KEY_FRAME) && (cpi->pass == 2))
|
|
|
|
cpi->source_alt_ref_pending = is_next_frame_arf(cpi);
|
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
|
|
|
*size = 0;
|
|
|
|
if (flush && cpi->pass == 1 && !cpi->twopass.first_pass_done) {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_end_first_pass(cpi); /* get last stats packet */
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->twopass.first_pass_done = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
// fclose(fp_out);
|
2012-07-14 00:21:29 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->source->ts_start < cpi->first_time_stamp_ever) {
|
|
|
|
cpi->first_time_stamp_ever = cpi->source->ts_start;
|
|
|
|
cpi->last_end_time_stamp_seen = cpi->source->ts_start;
|
|
|
|
}
|
2011-05-12 21:04:06 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// adjust frame rates based on timestamps given
|
2013-01-15 22:49:44 +01:00
|
|
|
if (!cpi->refresh_alt_ref_frame) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int64_t this_duration;
|
|
|
|
int step = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->source->ts_start == cpi->first_time_stamp_ever) {
|
|
|
|
this_duration = cpi->source->ts_end - cpi->source->ts_start;
|
|
|
|
step = 1;
|
|
|
|
} else {
|
2013-04-02 19:24:56 +02:00
|
|
|
int64_t last_duration = cpi->last_end_time_stamp_seen
|
|
|
|
- cpi->last_time_stamp_seen;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
this_duration = cpi->source->ts_end - cpi->last_end_time_stamp_seen;
|
2013-04-02 19:24:56 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// do a step update if the duration changes by 10%
|
|
|
|
if (last_duration)
|
2012-11-05 23:22:59 +01:00
|
|
|
step = (int)((this_duration - last_duration) * 10 / last_duration);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (this_duration) {
|
2013-04-02 19:24:56 +02:00
|
|
|
if (step) {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_new_frame_rate(cpi, 10000000.0 / this_duration);
|
2013-04-02 19:24:56 +02:00
|
|
|
} else {
|
|
|
|
// Average this frame's rate into the last second's average
|
|
|
|
// frame rate. If we haven't seen 1 second yet, then average
|
|
|
|
// over the whole interval seen.
|
|
|
|
const double interval = MIN((double)(cpi->source->ts_end
|
|
|
|
- cpi->first_time_stamp_ever), 10000000.0);
|
|
|
|
double avg_duration = 10000000.0 / cpi->oxcf.frame_rate;
|
2012-07-14 00:21:29 +02:00
|
|
|
avg_duration *= (interval - avg_duration + this_duration);
|
|
|
|
avg_duration /= interval;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_new_frame_rate(cpi, 10000000.0 / avg_duration);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->last_time_stamp_seen = cpi->source->ts_start;
|
|
|
|
cpi->last_end_time_stamp_seen = cpi->source->ts_end;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// start with a 0 size frame
|
|
|
|
*size = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Clear down mmx registers
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state(); // __asm emms;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-01-15 00:52:20 +01:00
|
|
|
/* find a free buffer for the new frame, releasing the reference previously
|
|
|
|
* held.
|
|
|
|
*/
|
|
|
|
cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
|
|
|
|
cm->new_fb_idx = get_free_fb(cm);
|
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
#if CONFIG_MULTIPLE_ARF
|
|
|
|
/* Set up the correct ARF frame. */
|
|
|
|
if (cpi->refresh_alt_ref_frame) {
|
|
|
|
++cpi->arf_buffered;
|
|
|
|
}
|
|
|
|
if (cpi->multi_arf_enabled && (cm->frame_type != KEY_FRAME) &&
|
|
|
|
(cpi->pass == 2)) {
|
|
|
|
cpi->alt_fb_idx = cpi->arf_buffer_idx[cpi->sequence_number];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-22 20:22:03 +01:00
|
|
|
/* Get the mapping of L/G/A to the reference buffer pool */
|
|
|
|
cm->active_ref_idx[0] = cm->ref_frame_map[cpi->lst_fb_idx];
|
|
|
|
cm->active_ref_idx[1] = cm->ref_frame_map[cpi->gld_fb_idx];
|
|
|
|
cm->active_ref_idx[2] = cm->ref_frame_map[cpi->alt_fb_idx];
|
|
|
|
|
2013-04-03 00:08:50 +02:00
|
|
|
#if 0 // CONFIG_MULTIPLE_ARF
|
|
|
|
if (cpi->multi_arf_enabled) {
|
|
|
|
fprintf(fp_out, " idx(%d, %d, %d, %d) active(%d, %d, %d)",
|
|
|
|
cpi->lst_fb_idx, cpi->gld_fb_idx, cpi->alt_fb_idx, cm->new_fb_idx,
|
|
|
|
cm->active_ref_idx[0], cm->active_ref_idx[1], cm->active_ref_idx[2]);
|
|
|
|
if (cpi->refresh_alt_ref_frame)
|
|
|
|
fprintf(fp_out, " type:ARF");
|
|
|
|
if (cpi->is_src_frame_alt_ref)
|
|
|
|
fprintf(fp_out, " type:OVERLAY[%d]", cpi->alt_fb_idx);
|
|
|
|
fprintf(fp_out, "\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cm->frame_type = INTER_FRAME;
|
|
|
|
cm->frame_flags = *frame_flags;
|
|
|
|
|
2013-04-17 20:45:35 +02:00
|
|
|
// Reset the frame pointers to the current frame size
|
2013-05-07 00:52:06 +02:00
|
|
|
vp9_realloc_frame_buffer(&cm->yv12_fb[cm->new_fb_idx],
|
|
|
|
cm->width, cm->height,
|
|
|
|
cm->subsampling_x, cm->subsampling_y,
|
|
|
|
VP9BORDERINPIXELS);
|
2013-02-06 23:22:17 +01:00
|
|
|
|
2013-04-17 20:45:35 +02:00
|
|
|
// Calculate scaling factors for each of the 3 available references
|
2013-05-15 02:10:17 +02:00
|
|
|
for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i)
|
|
|
|
vp9_setup_scale_factors(cm, i);
|
2013-04-03 21:22:50 +02:00
|
|
|
|
Convert subpixel filters to use convolve framework
Update the code to call the new convolution functions to do subpixel
prediction rather than the existing functions. Remove the old C and
assembly code, since it is unused. This causes a 50% performance
reduction on the decoder, but that will be resolved when the asm for
the new functions is available.
There is no consensus for whether 6-tap or 2-tap predictors will be
supported in the final codec, so these filters are implemented in
terms of the 8-tap code, so that quality testing of these modes
can continue. Implementing the lower complexity algorithms is a
simple exercise, should it be necessary.
This code produces slightly better results in the EIGHTTAP_SMOOTH
case, since the filter is now applied in only one direction when
the subpel motion is only in one direction. Like the previous code,
the filtering is skipped entirely on full-pel MVs. This combination
seems to give the best quality gains, but this may be indicative of a
bug in the encoder's filter selection, since the encoder could
achieve the result of skipping the filtering on full-pel by selecting
one of the other filters. This should be revisited.
Quality gains on derf positive on almost all clips. The only clip
that seemed to be hurt at all datarates was football
(-0.115% PSNR average, -0.587% min). Overall averages 0.375% PSNR,
0.347% SSIM.
Change-Id: I7d469716091b1d89b4b08adde5863999319d69ff
2013-01-29 01:59:03 +01:00
|
|
|
vp9_setup_interp_filters(&cpi->mb.e_mbd, DEFAULT_INTERP_FILTER, cm);
|
2013-04-03 21:22:50 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->pass == 1) {
|
|
|
|
Pass1Encode(cpi, size, dest, frame_flags);
|
|
|
|
} else if (cpi->pass == 2) {
|
|
|
|
Pass2Encode(cpi, size, dest, frame_flags);
|
2012-09-10 07:42:35 +02:00
|
|
|
} else {
|
2012-07-14 00:21:29 +02:00
|
|
|
encode_frame_to_data_rate(cpi, size, dest, frame_flags);
|
2012-09-10 07:42:35 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-26 23:39:58 +02:00
|
|
|
if (cm->refresh_frame_context)
|
|
|
|
cm->frame_contexts[cm->frame_context_idx] = cm->fc;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (*size > 0) {
|
2013-03-12 16:33:40 +01:00
|
|
|
// if its a dropped frame honor the requests on subsequent frames
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->droppable = !frame_is_reference(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// return to normal state
|
2013-05-30 02:16:00 +02:00
|
|
|
cm->reset_frame_context = 0;
|
2013-04-26 23:39:58 +02:00
|
|
|
cm->refresh_frame_context = 1;
|
2013-01-15 22:49:44 +01:00
|
|
|
cpi->refresh_alt_ref_frame = 0;
|
|
|
|
cpi->refresh_golden_frame = 0;
|
|
|
|
cpi->refresh_last_frame = 1;
|
2012-07-14 00:21:29 +02:00
|
|
|
cm->frame_type = INTER_FRAME;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_usec_timer_mark(&cmptimer);
|
|
|
|
cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer);
|
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame)
|
2012-07-14 00:21:29 +02:00
|
|
|
generate_psnr_packet(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-04-29 18:37:59 +02:00
|
|
|
#if CONFIG_INTERNAL_STATS
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->pass != 1) {
|
|
|
|
cpi->bytes += *size;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cm->show_frame) {
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->count++;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->b_calculate_psnr) {
|
|
|
|
double ye, ue, ve;
|
|
|
|
double frame_psnr;
|
|
|
|
YV12_BUFFER_CONFIG *orig = cpi->Source;
|
|
|
|
YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
|
|
|
|
YV12_BUFFER_CONFIG *pp = &cm->post_proc_buffer;
|
|
|
|
int y_samples = orig->y_height * orig->y_width;
|
|
|
|
int uv_samples = orig->uv_height * orig->uv_width;
|
|
|
|
int t_samples = y_samples + 2 * uv_samples;
|
2012-11-05 23:22:59 +01:00
|
|
|
double sq_error;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2012-11-05 23:22:59 +01:00
|
|
|
ye = (double)calc_plane_error(orig->y_buffer, orig->y_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
recon->y_buffer, recon->y_stride, orig->y_width,
|
|
|
|
orig->y_height);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2012-11-05 23:22:59 +01:00
|
|
|
ue = (double)calc_plane_error(orig->u_buffer, orig->uv_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
recon->u_buffer, recon->uv_stride, orig->uv_width,
|
|
|
|
orig->uv_height);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2012-11-05 23:22:59 +01:00
|
|
|
ve = (double)calc_plane_error(orig->v_buffer, orig->uv_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
recon->v_buffer, recon->uv_stride, orig->uv_width,
|
|
|
|
orig->uv_height);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
sq_error = ye + ue + ve;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
frame_psnr = vp9_mse2psnr(t_samples, 255.0, sq_error);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
cpi->total_y += vp9_mse2psnr(y_samples, 255.0, ye);
|
|
|
|
cpi->total_u += vp9_mse2psnr(uv_samples, 255.0, ue);
|
|
|
|
cpi->total_v += vp9_mse2psnr(uv_samples, 255.0, ve);
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->total_sq_error += sq_error;
|
|
|
|
cpi->total += frame_psnr;
|
|
|
|
{
|
|
|
|
double frame_psnr2, frame_ssim2 = 0;
|
|
|
|
double weight = 0;
|
2012-10-14 03:49:44 +02:00
|
|
|
#if CONFIG_POSTPROC
|
2012-11-28 19:00:25 +01:00
|
|
|
vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer,
|
2013-05-14 20:01:57 +02:00
|
|
|
cm->filter_level * 10 / 6);
|
2012-10-14 03:49:44 +02:00
|
|
|
#endif
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state();
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2012-11-05 23:22:59 +01:00
|
|
|
ye = (double)calc_plane_error(orig->y_buffer, orig->y_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
pp->y_buffer, pp->y_stride, orig->y_width,
|
|
|
|
orig->y_height);
|
2011-03-08 21:23:40 +01:00
|
|
|
|
2012-11-05 23:22:59 +01:00
|
|
|
ue = (double)calc_plane_error(orig->u_buffer, orig->uv_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
pp->u_buffer, pp->uv_stride, orig->uv_width,
|
|
|
|
orig->uv_height);
|
2011-03-08 21:23:40 +01:00
|
|
|
|
2012-11-05 23:22:59 +01:00
|
|
|
ve = (double)calc_plane_error(orig->v_buffer, orig->uv_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
pp->v_buffer, pp->uv_stride, orig->uv_width,
|
|
|
|
orig->uv_height);
|
2011-03-08 21:23:40 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
sq_error = ye + ue + ve;
|
2011-03-08 21:23:40 +01:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
frame_psnr2 = vp9_mse2psnr(t_samples, 255.0, sq_error);
|
2011-03-08 15:05:18 +01:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
cpi->totalp_y += vp9_mse2psnr(y_samples, 255.0, ye);
|
|
|
|
cpi->totalp_u += vp9_mse2psnr(uv_samples, 255.0, ue);
|
|
|
|
cpi->totalp_v += vp9_mse2psnr(uv_samples, 255.0, ve);
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->total_sq_error2 += sq_error;
|
|
|
|
cpi->totalp += frame_psnr2;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
frame_ssim2 = vp9_calc_ssim(cpi->Source,
|
2013-04-01 18:10:27 +02:00
|
|
|
recon, 1, &weight);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
cpi->summed_quality += frame_ssim2 * weight;
|
|
|
|
cpi->summed_weights += weight;
|
2013-04-01 18:10:27 +02:00
|
|
|
|
|
|
|
frame_ssim2 = vp9_calc_ssim(cpi->Source,
|
|
|
|
&cm->post_proc_buffer, 1, &weight);
|
|
|
|
|
|
|
|
cpi->summedp_quality += frame_ssim2 * weight;
|
|
|
|
cpi->summedp_weights += weight;
|
2010-12-02 00:50:14 +01:00
|
|
|
#if 0
|
2012-07-14 00:21:29 +02:00
|
|
|
{
|
|
|
|
FILE *f = fopen("q_used.stt", "a");
|
|
|
|
fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n",
|
|
|
|
cpi->common.current_video_frame, y2, u2, v2,
|
|
|
|
frame_psnr2, frame_ssim2);
|
|
|
|
fclose(f);
|
|
|
|
}
|
2010-12-02 00:50:14 +01:00
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->b_calculate_ssimg) {
|
|
|
|
double y, u, v, frame_all;
|
2012-10-30 20:58:42 +01:00
|
|
|
frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show,
|
2012-10-22 05:47:57 +02:00
|
|
|
&y, &u, &v);
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->total_ssimg_y += y;
|
|
|
|
cpi->total_ssimg_u += u;
|
|
|
|
cpi->total_ssimg_v += v;
|
|
|
|
cpi->total_ssimg_all += frame_all;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#endif
|
2013-04-03 00:08:50 +02:00
|
|
|
// fclose(fp_out);
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_get_preview_raw_frame(VP9_PTR comp, YV12_BUFFER_CONFIG *dest,
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_ppflags_t *flags) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *) comp;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-05 21:23:34 +01:00
|
|
|
if (!cpi->common.show_frame)
|
2012-07-14 00:21:29 +02:00
|
|
|
return -1;
|
|
|
|
else {
|
|
|
|
int ret;
|
2010-05-18 17:58:33 +02:00
|
|
|
#if CONFIG_POSTPROC
|
2012-10-31 00:25:53 +01:00
|
|
|
ret = vp9_post_proc_frame(&cpi->common, dest, flags);
|
2010-05-18 17:58:33 +02:00
|
|
|
#else
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->common.frame_to_show) {
|
|
|
|
*dest = *cpi->common.frame_to_show;
|
2013-03-21 00:41:30 +01:00
|
|
|
dest->y_width = cpi->common.width;
|
|
|
|
dest->y_height = cpi->common.height;
|
|
|
|
dest->uv_height = cpi->common.height / 2;
|
2012-07-14 00:21:29 +02:00
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
ret = -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
#endif // !CONFIG_POSTPROC
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_clear_system_state();
|
2012-07-14 00:21:29 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_set_roimap(VP9_PTR comp, unsigned char *map, unsigned int rows,
|
2013-04-24 14:04:45 +02:00
|
|
|
unsigned int cols, int delta_q[MAX_MB_SEGMENTS],
|
|
|
|
int delta_lf[MAX_MB_SEGMENTS],
|
|
|
|
unsigned int threshold[MAX_MB_SEGMENTS]) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *) comp;
|
2012-07-14 00:21:29 +02:00
|
|
|
signed char feature_data[SEG_LVL_MAX][MAX_MB_SEGMENTS];
|
|
|
|
MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (cpi->common.mb_rows != rows || cpi->common.mb_cols != cols)
|
|
|
|
return -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (!map) {
|
2012-10-31 01:53:32 +01:00
|
|
|
vp9_disable_segmentation((VP9_PTR)cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the segmentation Map
|
2012-10-31 01:53:32 +01:00
|
|
|
vp9_set_segmentation_map((VP9_PTR)cpi, map);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Activate segmentation.
|
2012-10-31 01:53:32 +01:00
|
|
|
vp9_enable_segmentation((VP9_PTR)cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-24 14:04:45 +02:00
|
|
|
// Set up the quan, LF and breakout threshold segment data
|
|
|
|
for (i = 0; i < MAX_MB_SEGMENTS; i++) {
|
|
|
|
feature_data[SEG_LVL_ALT_Q][i] = delta_q[i];
|
|
|
|
feature_data[SEG_LVL_ALT_LF][i] = delta_lf[i];
|
|
|
|
cpi->segment_encode_breakout[i] = threshold[i];
|
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Enable the loop and quant changes in the feature mask
|
2013-04-24 14:04:45 +02:00
|
|
|
for (i = 0; i < MAX_MB_SEGMENTS; i++) {
|
2012-07-14 00:21:29 +02:00
|
|
|
if (delta_q[i])
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_enable_segfeature(xd, i, SEG_LVL_ALT_Q);
|
2012-07-14 00:21:29 +02:00
|
|
|
else
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_disable_segfeature(xd, i, SEG_LVL_ALT_Q);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (delta_lf[i])
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_enable_segfeature(xd, i, SEG_LVL_ALT_LF);
|
2012-07-14 00:21:29 +02:00
|
|
|
else
|
2012-10-30 06:15:27 +01:00
|
|
|
vp9_disable_segfeature(xd, i, SEG_LVL_ALT_LF);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Initialise the feature data structure
|
|
|
|
// SEGMENT_DELTADATA 0, SEGMENT_ABSDATA 1
|
2012-10-31 01:53:32 +01:00
|
|
|
vp9_set_segment_data((VP9_PTR)cpi, &feature_data[0][0], SEGMENT_DELTADATA);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_set_active_map(VP9_PTR comp, unsigned char *map,
|
2012-10-30 22:25:33 +01:00
|
|
|
unsigned int rows, unsigned int cols) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *) comp;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) {
|
|
|
|
if (map) {
|
|
|
|
vpx_memcpy(cpi->active_map, map, rows * cols);
|
|
|
|
cpi->active_map_enabled = 1;
|
2013-04-02 19:24:56 +02:00
|
|
|
} else {
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->active_map_enabled = 0;
|
2013-04-02 19:24:56 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
// cpi->active_map_enabled = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_set_internal_size(VP9_PTR comp,
|
2012-10-30 22:25:33 +01:00
|
|
|
VPX_SCALING horiz_mode, VPX_SCALING vert_mode) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi = (VP9_COMP *) comp;
|
2013-02-20 21:34:31 +01:00
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2013-03-14 22:36:08 +01:00
|
|
|
int hr = 0, hs = 0, vr = 0, vs = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-02 19:24:56 +02:00
|
|
|
if (horiz_mode > ONETWO || vert_mode > ONETWO)
|
2012-07-14 00:21:29 +02:00
|
|
|
return -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-14 22:36:08 +01:00
|
|
|
Scale2Ratio(horiz_mode, &hr, &hs);
|
|
|
|
Scale2Ratio(vert_mode, &vr, &vs);
|
2013-02-21 19:38:27 +01:00
|
|
|
|
2013-03-14 22:36:08 +01:00
|
|
|
// always go to the next whole number
|
2013-03-21 00:41:30 +01:00
|
|
|
cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs;
|
|
|
|
cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs;
|
2013-02-20 21:34:31 +01:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
assert(cm->width <= cpi->initial_width);
|
|
|
|
assert(cm->height <= cpi->initial_height);
|
2013-02-20 21:34:31 +01:00
|
|
|
update_frame_size(cpi);
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
int vp9_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i, j;
|
2013-03-27 22:22:30 +01:00
|
|
|
int total = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
uint8_t *src = source->y_buffer;
|
|
|
|
uint8_t *dst = dest->y_buffer;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-27 22:22:30 +01:00
|
|
|
// Loop through the Y plane raw and reconstruction data summing
|
|
|
|
// (square differences)
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < source->y_height; i += 16) {
|
|
|
|
for (j = 0; j < source->y_width; j += 16) {
|
|
|
|
unsigned int sse;
|
2013-03-27 22:22:30 +01:00
|
|
|
total += vp9_mse16x16(src + j, source->y_stride, dst + j, dest->y_stride,
|
2012-10-22 05:47:57 +02:00
|
|
|
&sse);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
src += 16 * source->y_stride;
|
|
|
|
dst += 16 * dest->y_stride;
|
|
|
|
}
|
|
|
|
|
2013-03-27 22:22:30 +01:00
|
|
|
return total;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-03-17 22:07:59 +01:00
|
|
|
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_get_quantizer(VP9_PTR c) {
|
2013-04-02 19:24:56 +02:00
|
|
|
return ((VP9_COMP *)c)->common.base_qindex;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|