vp9_bitstream.c 48.68 KiB
/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
#include <assert.h>
#include <stdio.h>
#include <limits.h>
#include "vpx/vpx_encoder.h"
#include "vpx_mem/vpx_mem.h"
#include "vp9/common/vp9_entropymode.h"
#include "vp9/common/vp9_entropymv.h"
#include "vp9/common/vp9_findnearmv.h"
#include "vp9/common/vp9_tile_common.h"
#include "vp9/common/vp9_seg_common.h"
#include "vp9/common/vp9_pred_common.h"
#include "vp9/common/vp9_entropy.h"
#include "vp9/common/vp9_entropymv.h"
#include "vp9/common/vp9_mvref_common.h"
#include "vp9/common/vp9_treecoder.h"
#include "vp9/common/vp9_systemdependent.h"
#include "vp9/common/vp9_pragmas.h"
#include "vp9/encoder/vp9_mcomp.h"
#include "vp9/encoder/vp9_encodemv.h"
#include "vp9/encoder/vp9_bitstream.h"
#include "vp9/encoder/vp9_segmentation.h"
#include "vp9/encoder/vp9_subexp.h"
#include "vp9/encoder/vp9_write_bit_buffer.h"
#if defined(SECTIONBITS_OUTPUT)
unsigned __int64 Sectionbits[500];
#endif
#ifdef ENTROPY_STATS
int intra_mode_stats[VP9_INTRA_MODES]
                    [VP9_INTRA_MODES]
                    [VP9_INTRA_MODES];
vp9_coeff_stats tree_update_hist[TX_SIZES][BLOCK_TYPES];
extern unsigned int active_section;
#endif
#ifdef MODE_STATS
int64_t tx_count_32x32p_stats[TX_SIZE_CONTEXTS][TX_SIZES];
int64_t tx_count_16x16p_stats[TX_SIZE_CONTEXTS][TX_SIZES - 1];
int64_t tx_count_8x8p_stats[TX_SIZE_CONTEXTS][TX_SIZES - 2];
int64_t switchable_interp_stats[VP9_SWITCHABLE_FILTERS+1]
                               [VP9_SWITCHABLE_FILTERS];
void init_tx_count_stats() {
  vp9_zero(tx_count_32x32p_stats);
  vp9_zero(tx_count_16x16p_stats);
  vp9_zero(tx_count_8x8p_stats);
void init_switchable_interp_stats() {
  vp9_zero(switchable_interp_stats);
static void update_tx_count_stats(VP9_COMMON *cm) {
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
int i, j; for (i = 0; i < TX_SIZE_CONTEXTS; i++) { for (j = 0; j < TX_SIZES; j++) { tx_count_32x32p_stats[i][j] += cm->fc.tx_count_32x32p[i][j]; } } for (i = 0; i < TX_SIZE_CONTEXTS; i++) { for (j = 0; j < TX_SIZES - 1; j++) { tx_count_16x16p_stats[i][j] += cm->fc.tx_count_16x16p[i][j]; } } for (i = 0; i < TX_SIZE_CONTEXTS; i++) { for (j = 0; j < TX_SIZES - 2; j++) { tx_count_8x8p_stats[i][j] += cm->fc.tx_count_8x8p[i][j]; } } } static void update_switchable_interp_stats(VP9_COMMON *cm) { int i, j; for (i = 0; i < VP9_SWITCHABLE_FILTERS+1; ++i) for (j = 0; j < VP9_SWITCHABLE_FILTERS; ++j) { switchable_interp_stats[i][j] += cm->fc.switchable_interp_count[i][j]; } } void write_tx_count_stats() { int i, j; FILE *fp = fopen("tx_count.bin", "wb"); fwrite(tx_count_32x32p_stats, sizeof(tx_count_32x32p_stats), 1, fp); fwrite(tx_count_16x16p_stats, sizeof(tx_count_16x16p_stats), 1, fp); fwrite(tx_count_8x8p_stats, sizeof(tx_count_8x8p_stats), 1, fp); fclose(fp); printf( "vp9_default_tx_count_32x32p[TX_SIZE_CONTEXTS][TX_SIZES] = {\n"); for (i = 0; i < TX_SIZE_CONTEXTS; i++) { printf(" { "); for (j = 0; j < TX_SIZES; j++) { printf("%"PRId64", ", tx_count_32x32p_stats[i][j]); } printf("},\n"); } printf("};\n"); printf( "vp9_default_tx_count_16x16p[TX_SIZE_CONTEXTS][TX_SIZES-1] = {\n"); for (i = 0; i < TX_SIZE_CONTEXTS; i++) { printf(" { "); for (j = 0; j < TX_SIZES - 1; j++) { printf("%"PRId64", ", tx_count_16x16p_stats[i][j]); } printf("},\n"); } printf("};\n"); printf( "vp9_default_tx_count_8x8p[TX_SIZE_CONTEXTS][TX_SIZES-2] = {\n"); for (i = 0; i < TX_SIZE_CONTEXTS; i++) { printf(" { "); for (j = 0; j < TX_SIZES - 2; j++) { printf("%"PRId64", ", tx_count_8x8p_stats[i][j]); } printf("},\n"); } printf("};\n"); } void write_switchable_interp_stats() { int i, j; FILE *fp = fopen("switchable_interp.bin", "wb"); fwrite(switchable_interp_stats, sizeof(switchable_interp_stats), 1, fp);