#ifndef CODING_OPTIONS_H
#define CODING_OPTIONS_H
#include "libde265/encoder/encoder-types.h"
template <class node> class CodingOption;
template <class node>
class CodingOptions
{
public:
CodingOptions(encoder_context*, node*, context_model_table& tab);
~CodingOptions();
typedef CodingOption<node> Option;
CodingOption<node> new_option(bool active=true);
enum RateEstimationMethod
{
Rate_Default,
Rate_AdaptiveContext,
Rate_FixedContext
};
void start(enum RateEstimationMethod = Rate_Default);
void compute_rdo_costs();
node* return_best_rdo_node();
private:
struct CodingOptionData
{
node* mNode;
context_model_table context;
bool mOptionActive;
bool computed;
float rdoCost;
};
encoder_context* mECtx;
bool mCBMode;
node* mInputNode;
context_model_table* mContextModelInput;
int mBestRDO;
std::vector<CodingOptionData> mOptions;
CABAC_encoder_estim cabac_adaptive;
CABAC_encoder_estim_constant cabac_constant;
CABAC_encoder_estim* cabac;
friend class CodingOption<node>;
int find_best_rdo_index();
};
template <class node>
class CodingOption
{
public:
CodingOption() {
mParent = nullptr;
mOptionIdx = 0;
}
node* get_node() { return mParent->mOptions[mOptionIdx].mNode; }
void set_node(node* _node) {
if (_node != mParent->mOptions[mOptionIdx].mNode) {
}
mParent->mOptions[mOptionIdx].mNode = _node;
}
context_model_table& get_context() { return mParent->mOptions[mOptionIdx].context; }
operator bool() const { return mParent; }
void begin();
void end();
void set_rdo_cost(float rdo) { mParent->mOptions[mOptionIdx].rdoCost=rdo; }
CABAC_encoder_estim* get_cabac() { return mParent->cabac; }
float get_cabac_rate() const { return mParent->cabac->getRDBits(); }
private:
CodingOption(class CodingOptions<node>* parent, int idx)
: mParent(parent), mOptionIdx(idx) { }
class CodingOptions<node>* mParent;
int mOptionIdx;
friend class CodingOptions<node>;
};
#endif