This source file includes following definitions.
- encode_cb_split
- analyze
#include "libde265/encoder/algo/cb-split.h"
#include "libde265/encoder/algo/coding-options.h"
#include "libde265/encoder/encoder-context.h"
#include "libde265/encoder/encoder-syntax.h"
#include <assert.h>
#include <limits>
#include <math.h>
#include <iostream>
enc_cb* Algo_CB_Split::encode_cb_split(encoder_context* ectx,
context_model_table& ctxModel,
enc_cb* cb)
{
int w = ectx->imgdata->input->get_width();
int h = ectx->imgdata->input->get_height();
cb->split_cu_flag = true;
for (int i=0;i<4;i++) {
cb->children[i] = NULL;
}
for (int i=0;i<4;i++) {
int child_x = cb->x + ((i&1) << (cb->log2Size-1));
int child_y = cb->y + ((i>>1) << (cb->log2Size-1));
if (child_x>=w || child_y>=h) {
}
else {
enc_cb* childCB = new enc_cb;
childCB->log2Size = cb->log2Size-1;
childCB->ctDepth = cb->ctDepth+1;
childCB->x = child_x;
childCB->y = child_y;
childCB->parent = cb;
childCB->downPtr = &cb->children[i];
descend(cb,"yes %d/4",i+1);
cb->children[i] = analyze(ectx, ctxModel, childCB);
ascend();
cb->distortion += cb->children[i]->distortion;
cb->rate += cb->children[i]->rate;
}
}
return cb;
}
enc_cb* Algo_CB_Split_BruteForce::analyze(encoder_context* ectx,
context_model_table& ctxModel,
enc_cb* cb_input)
{
assert(cb_input->pcm_flag==0);
const SplitType split_type = get_split_type(&ectx->get_sps(),
cb_input->x, cb_input->y,
cb_input->log2Size);
bool can_split_CB = (split_type != ForcedNonSplit);
bool can_nosplit_CB = (split_type != ForcedSplit);
CodingOptions<enc_cb> options(ectx, cb_input, ctxModel);
CodingOption<enc_cb> option_no_split = options.new_option(can_nosplit_CB);
CodingOption<enc_cb> option_split = options.new_option(can_split_CB);
options.start();
if (option_no_split) {
CodingOption<enc_cb>& opt = option_no_split;
opt.begin();
enc_cb* cb = opt.get_node();
*cb_input->downPtr = cb;
cb->qp = ectx->active_qp;
assert(mChildAlgo);
descend(cb,"no");
cb = mChildAlgo->analyze(ectx, opt.get_context(), cb);
ascend();
if (split_type == OptionalSplit) {
encode_split_cu_flag(ectx,opt.get_cabac(), cb->x,cb->y, cb->ctDepth, 0);
cb->rate += opt.get_cabac_rate();
}
opt.set_node(cb);
opt.end();
}
if (option_split) {
option_split.begin();
enc_cb* cb = option_split.get_node();
*cb_input->downPtr = cb;
cb = encode_cb_split(ectx, option_split.get_context(), cb);
if (split_type == OptionalSplit) {
encode_split_cu_flag(ectx,option_split.get_cabac(), cb->x,cb->y, cb->ctDepth, 1);
cb->rate += option_split.get_cabac_rate();
}
option_split.set_node(cb);
option_split.end();
}
options.compute_rdo_costs();
enc_cb* bestCB = options.return_best_rdo_node();
return bestCB;
}