1
0
mirror of https://github.com/signalwire/freeswitch.git synced 2025-08-13 17:38:59 +00:00
Files
.github
build
clients
cmake_modules
conf
debian
docker
docs
dtd
fonts
fscomm
htdocs
images
libs
apr
esl
iksemel
libnatpmp
libscgi
libsndfile
libteletone
libvpx
build
examples
test
third_party
tools
vp8
vp9
common
decoder
encoder
arm
mips
ppc
x86
vp9_alt_ref_aq.c
vp9_alt_ref_aq.h
vp9_aq_360.c
vp9_aq_360.h
vp9_aq_complexity.c
vp9_aq_complexity.h
vp9_aq_cyclicrefresh.c
vp9_aq_cyclicrefresh.h
vp9_aq_variance.c
vp9_aq_variance.h
vp9_bitstream.c
vp9_bitstream.h
vp9_block.h
vp9_blockiness.c
vp9_blockiness.h
vp9_context_tree.c
vp9_context_tree.h
vp9_cost.c
vp9_cost.h
vp9_dct.c
vp9_denoiser.c
vp9_denoiser.h
vp9_encodeframe.c
vp9_encodeframe.h
vp9_encodemb.c
vp9_encodemb.h
vp9_encodemv.c
vp9_encodemv.h
vp9_encoder.c
vp9_encoder.h
vp9_ethread.c
vp9_ethread.h
vp9_extend.c
vp9_extend.h
vp9_firstpass.c
vp9_firstpass.h
vp9_frame_scale.c
vp9_job_queue.h
vp9_lookahead.c
vp9_lookahead.h
vp9_mbgraph.c
vp9_mbgraph.h
vp9_mcomp.c
vp9_mcomp.h
vp9_multi_thread.c
vp9_multi_thread.h
vp9_noise_estimate.c
vp9_noise_estimate.h
vp9_partition_models.h
vp9_picklpf.c
vp9_picklpf.h
vp9_pickmode.c
vp9_pickmode.h
vp9_quantize.c
vp9_quantize.h
vp9_ratectrl.c
vp9_ratectrl.h
vp9_rd.c
vp9_rd.h
vp9_rdopt.c
vp9_rdopt.h
vp9_resize.c
vp9_resize.h
vp9_segmentation.c
vp9_segmentation.h
vp9_skin_detection.c
vp9_skin_detection.h
vp9_speed_features.c
vp9_speed_features.h
vp9_subexp.c
vp9_subexp.h
vp9_svc_layercontext.c
vp9_svc_layercontext.h
vp9_temporal_filter.c
vp9_temporal_filter.h
vp9_tokenize.c
vp9_tokenize.h
vp9_treewriter.c
vp9_treewriter.h
exports_dec
exports_enc
vp9_common.mk
vp9_cx_iface.c
vp9_dx_iface.c
vp9_dx_iface.h
vp9_iface_common.h
vp9cx.mk
vp9dx.mk
vpx
vpx_dsp
vpx_mem
vpx_ports
vpx_scale
vpx_util
.gitignore
.update
AUTHORS
CHANGELOG
LICENSE
PATENTS
README
args.c
args.h
codereview.settings
configure
docs.mk
examples.mk
ivfdec.c
ivfdec.h
ivfenc.c
ivfenc.h
keywords.dox
libs.doxy_template
libs.mk
mainpage.dox
md5_utils.c
md5_utils.h
rate_hist.c
rate_hist.h
solution.mk
tools.mk
tools_common.c
tools_common.h
usage.dox
usage_cx.dox
usage_dx.dox
video_common.h
video_reader.c
video_reader.h
video_writer.c
video_writer.h
vpxdec.c
vpxenc.c
vpxenc.h
vpxstats.c
vpxstats.h
warnings.c
warnings.h
webmdec.cc
webmdec.h
webmenc.cc
webmenc.h
y4menc.c
y4menc.h
y4minput.c
y4minput.h
libyuv
miniupnpc
srtp
stb
win32
xmlrpc-c
.gitignore
scripts
src
support-d
tests
w32
web
yum
.clang-format
.drone.yml
.gitattributes
.gitconfig
.gitignore
.mailmap
Freeswitch.2017.sln
Freeswitch.2017.sln.bat
INSTALL
LICENSE
Makefile.am
README.md
SECURITY.md
acinclude.m4
bootstrap.sh
cc.sh
cluecon.tmpl
cluecon2.tmpl
cluecon2_small.tmpl
cluecon_small.tmpl
configure.ac
devel-bootstrap.sh
freeswitch-config-rayo.spec
freeswitch-sounds-en-ca-june.spec
freeswitch-sounds-en-us-allison.spec
freeswitch-sounds-en-us-callie.spec
freeswitch-sounds-fr-ca-june.spec
freeswitch-sounds-music.spec
freeswitch-sounds-pt-BR-karina.spec
freeswitch-sounds-ru-RU-elena.spec
freeswitch-sounds-sv-se-jakob.spec
freeswitch.spec
msbuild.cmd
swig_common.i
freeswitch/libs/libvpx/vp9/encoder/vp9_context_tree.c

161 lines
5.4 KiB
C
Raw Normal View History

/*
* Copyright (c) 2014 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 "vp9/encoder/vp9_context_tree.h"
#include "vp9/encoder/vp9_encoder.h"
static const BLOCK_SIZE square[] = {
BLOCK_8X8,
BLOCK_16X16,
BLOCK_32X32,
BLOCK_64X64,
};
static void alloc_mode_context(VP9_COMMON *cm, int num_4x4_blk,
PICK_MODE_CONTEXT *ctx) {
const int num_blk = (num_4x4_blk < 4 ? 4 : num_4x4_blk);
const int num_pix = num_blk << 4;
int i, k;
ctx->num_4x4_blk = num_blk;
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk, vpx_calloc(num_blk, sizeof(uint8_t)));
for (i = 0; i < MAX_MB_PLANE; ++i) {
for (k = 0; k < 3; ++k) {
CHECK_MEM_ERROR(cm, ctx->coeff[i][k],
vpx_memalign(32, num_pix * sizeof(*ctx->coeff[i][k])));
CHECK_MEM_ERROR(cm, ctx->qcoeff[i][k],
vpx_memalign(32, num_pix * sizeof(*ctx->qcoeff[i][k])));
CHECK_MEM_ERROR(cm, ctx->dqcoeff[i][k],
vpx_memalign(32, num_pix * sizeof(*ctx->dqcoeff[i][k])));
CHECK_MEM_ERROR(cm, ctx->eobs[i][k],
vpx_memalign(32, num_blk * sizeof(*ctx->eobs[i][k])));
ctx->coeff_pbuf[i][k] = ctx->coeff[i][k];
ctx->qcoeff_pbuf[i][k] = ctx->qcoeff[i][k];
ctx->dqcoeff_pbuf[i][k] = ctx->dqcoeff[i][k];
ctx->eobs_pbuf[i][k] = ctx->eobs[i][k];
}
}
}
static void free_mode_context(PICK_MODE_CONTEXT *ctx) {
int i, k;
vpx_free(ctx->zcoeff_blk);
ctx->zcoeff_blk = 0;
for (i = 0; i < MAX_MB_PLANE; ++i) {
for (k = 0; k < 3; ++k) {
vpx_free(ctx->coeff[i][k]);
ctx->coeff[i][k] = 0;
vpx_free(ctx->qcoeff[i][k]);
ctx->qcoeff[i][k] = 0;
vpx_free(ctx->dqcoeff[i][k]);
ctx->dqcoeff[i][k] = 0;
vpx_free(ctx->eobs[i][k]);
ctx->eobs[i][k] = 0;
}
}
}
static void alloc_tree_contexts(VP9_COMMON *cm, PC_TREE *tree,
int num_4x4_blk) {
alloc_mode_context(cm, num_4x4_blk, &tree->none);
alloc_mode_context(cm, num_4x4_blk / 2, &tree->horizontal[0]);
alloc_mode_context(cm, num_4x4_blk / 2, &tree->vertical[0]);
if (num_4x4_blk > 4) {
alloc_mode_context(cm, num_4x4_blk / 2, &tree->horizontal[1]);
alloc_mode_context(cm, num_4x4_blk / 2, &tree->vertical[1]);
} else {
memset(&tree->horizontal[1], 0, sizeof(tree->horizontal[1]));
memset(&tree->vertical[1], 0, sizeof(tree->vertical[1]));
}
}
static void free_tree_contexts(PC_TREE *tree) {
free_mode_context(&tree->none);
free_mode_context(&tree->horizontal[0]);
free_mode_context(&tree->horizontal[1]);
free_mode_context(&tree->vertical[0]);
free_mode_context(&tree->vertical[1]);
}
// This function sets up a tree of contexts such that at each square
// partition level. There are contexts for none, horizontal, vertical, and
// split. Along with a block_size value and a selected block_size which
// represents the state of our search.
void vp9_setup_pc_tree(VP9_COMMON *cm, ThreadData *td) {
int i, j;
const int leaf_nodes = 64;
const int tree_nodes = 64 + 16 + 4 + 1;
int pc_tree_index = 0;
PC_TREE *this_pc;
PICK_MODE_CONTEXT *this_leaf;
int square_index = 1;
int nodes;
vpx_free(td->leaf_tree);
CHECK_MEM_ERROR(cm, td->leaf_tree,
vpx_calloc(leaf_nodes, sizeof(*td->leaf_tree)));
vpx_free(td->pc_tree);
CHECK_MEM_ERROR(cm, td->pc_tree,
vpx_calloc(tree_nodes, sizeof(*td->pc_tree)));
this_pc = &td->pc_tree[0];
this_leaf = &td->leaf_tree[0];
// 4x4 blocks smaller than 8x8 but in the same 8x8 block share the same
// context so we only need to allocate 1 for each 8x8 block.
for (i = 0; i < leaf_nodes; ++i) alloc_mode_context(cm, 1, &td->leaf_tree[i]);
// Sets up all the leaf nodes in the tree.
for (pc_tree_index = 0; pc_tree_index < leaf_nodes; ++pc_tree_index) {
PC_TREE *const tree = &td->pc_tree[pc_tree_index];
tree->block_size = square[0];
alloc_tree_contexts(cm, tree, 4);
tree->leaf_split[0] = this_leaf++;
for (j = 1; j < 4; j++) tree->leaf_split[j] = tree->leaf_split[0];
}
// Each node has 4 leaf nodes, fill each block_size level of the tree
// from leafs to the root.
for (nodes = 16; nodes > 0; nodes >>= 2) {
for (i = 0; i < nodes; ++i) {
PC_TREE *const tree = &td->pc_tree[pc_tree_index];
alloc_tree_contexts(cm, tree, 4 << (2 * square_index));
tree->block_size = square[square_index];
for (j = 0; j < 4; j++) tree->split[j] = this_pc++;
++pc_tree_index;
}
++square_index;
}
td->pc_root = &td->pc_tree[tree_nodes - 1];
td->pc_root[0].none.best_mode_index = 2;
}
void vp9_free_pc_tree(ThreadData *td) {
int i;
if (td == NULL) return;
if (td->leaf_tree != NULL) {
// Set up all 4x4 mode contexts
for (i = 0; i < 64; ++i) free_mode_context(&td->leaf_tree[i]);
vpx_free(td->leaf_tree);
td->leaf_tree = NULL;
}
if (td->pc_tree != NULL) {
const int tree_nodes = 64 + 16 + 4 + 1;
// Sets up all the leaf nodes in the tree.
for (i = 0; i < tree_nodes; ++i) free_tree_contexts(&td->pc_tree[i]);
vpx_free(td->pc_tree);
td->pc_tree = NULL;
}
}