chromium/third_party/libvpx/source/libvpx/vp8/encoder/encodeframe.c

/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
#include <limits.h>
#include <stdio.h>

#include "vpx_config.h"

#include "vp8/common/common.h"
#include "vp8/common/entropymode.h"
#include "vp8/common/extend.h"
#include "vp8/common/invtrans.h"
#include "vp8/common/quant_common.h"
#include "vp8/common/reconinter.h"
#include "vp8/common/setupintrarecon.h"
#include "vp8/common/threading.h"
#include "vp8/encoder/bitstream.h"
#include "vp8/encoder/encodeframe.h"
#include "vp8/encoder/encodeintra.h"
#include "vp8/encoder/encodemb.h"
#include "vp8/encoder/onyx_int.h"
#include "vp8/encoder/pickinter.h"
#include "vp8/encoder/rdopt.h"
#include "vp8_rtcd.h"
#include "vpx/internal/vpx_codec_internal.h"
#include "vpx_dsp_rtcd.h"
#include "vpx_mem/vpx_mem.h"
#include "vpx_ports/vpx_timer.h"

#if CONFIG_MULTITHREAD
#include "vp8/encoder/ethreading.h"
#endif

extern void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t);
static void adjust_act_zbin(VP8_COMP *cpi, MACROBLOCK *x);

#ifdef MODE_STATS
unsigned int inter_y_modes[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
unsigned int inter_uv_modes[4] = { 0, 0, 0, 0 };
unsigned int inter_b_modes[15] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
unsigned int y_modes[5] = { 0, 0, 0, 0, 0 };
unsigned int uv_modes[4] = { 0, 0, 0, 0 };
unsigned int b_modes[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
#endif

/* activity_avg must be positive, or flat regions could get a zero weight
 *  (infinite lambda), which confounds analysis.
 * This also avoids the need for divide by zero checks in
 *  vp8_activity_masking().
 */
#define VP8_ACTIVITY_AVG_MIN

/* This is used as a reference when computing the source variance for the
 *  purposes of activity masking.
 * Eventually this should be replaced by custom no-reference routines,
 *  which will be faster.
 */
static const unsigned char VP8_VAR_OFFS[16] =;

/* Original activity measure from Tim T's code. */
static unsigned int tt_activity_measure(MACROBLOCK *x) {}

/* Measure the activity of the current macroblock
 * What we measure here is TBD so abstracted to this function
 */
#define ALT_ACT_MEASURE
static unsigned int mb_activity_measure(MACROBLOCK *x, int mb_row, int mb_col) {}

/* Calculate an "average" mb activity value for the frame */
#define ACT_MEDIAN
static void calc_av_activity(VP8_COMP *cpi, int64_t activity_sum) {}

#define USE_ACT_INDEX
#define OUTPUT_NORM_ACT_STATS

#if USE_ACT_INDEX
/* Calculate and activity index for each mb */
static void calc_activity_index(VP8_COMP *cpi, MACROBLOCK *x) {
  VP8_COMMON *const cm = &cpi->common;
  int mb_row, mb_col;

  int64_t act;
  int64_t a;
  int64_t b;

#if OUTPUT_NORM_ACT_STATS
  FILE *f = fopen("norm_act.stt", "a");
  fprintf(f, "\n%12d\n", cpi->activity_avg);
#endif

  /* Reset pointers to start of activity map */
  x->mb_activity_ptr = cpi->mb_activity_map;

  /* Calculate normalized mb activity number. */
  for (mb_row = 0; mb_row < cm->mb_rows; ++mb_row) {
    /* for each macroblock col in image */
    for (mb_col = 0; mb_col < cm->mb_cols; ++mb_col) {
      /* Read activity from the map */
      act = *(x->mb_activity_ptr);

      /* Calculate a normalized activity number */
      a = act + 4 * cpi->activity_avg;
      b = 4 * act + cpi->activity_avg;

      if (b >= a)
        *(x->activity_ptr) = (int)((b + (a >> 1)) / a) - 1;
      else
        *(x->activity_ptr) = 1 - (int)((a + (b >> 1)) / b);

#if OUTPUT_NORM_ACT_STATS
      fprintf(f, " %6d", *(x->mb_activity_ptr));
#endif
      /* Increment activity map pointers */
      x->mb_activity_ptr++;
    }

#if OUTPUT_NORM_ACT_STATS
    fprintf(f, "\n");
#endif
  }

#if OUTPUT_NORM_ACT_STATS
  fclose(f);
#endif
}
#endif

/* Loop through all MBs. Note activity of each, average activity and
 * calculate a normalized activity for each
 */
static void build_activity_map(VP8_COMP *cpi) {}

/* Macroblock activity masking */
void vp8_activity_masking(VP8_COMP *cpi, MACROBLOCK *x) {}

static void encode_mb_row(VP8_COMP *cpi, VP8_COMMON *cm, int mb_row,
                          MACROBLOCK *x, MACROBLOCKD *xd, TOKENEXTRA **tp,
                          int *segment_counts, int *totalrate) {}

static void init_encode_frame_mb_context(VP8_COMP *cpi) {}

#if CONFIG_MULTITHREAD
static void sum_coef_counts(MACROBLOCK *x, MACROBLOCK *x_thread) {}
#endif  // CONFIG_MULTITHREAD

void vp8_encode_frame(VP8_COMP *cpi) {}
void vp8_setup_block_ptrs(MACROBLOCK *x) {}

void vp8_build_block_offsets(MACROBLOCK *x) {}

static void sum_intra_stats(VP8_COMP *cpi, MACROBLOCK *x) {}

/* Experimental stub function to create a per MB zbin adjustment based on
 * some previously calculated measure of MB activity.
 */
static void adjust_act_zbin(VP8_COMP *cpi, MACROBLOCK *x) {}

int vp8cx_encode_intra_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
                                  TOKENEXTRA **t) {}
#ifdef SPEEDSTATS
extern int cnt_pm;
#endif

extern void vp8_fix_contexts(MACROBLOCKD *x);

int vp8cx_encode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t,
                                  int recon_yoffset, int recon_uvoffset,
                                  int mb_row, int mb_col) {}