/********************************************************************1* *2* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *3* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *4* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *5* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *6* *7* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *8* by the Xiph.Org Foundation https://www.xiph.org/ *9* *10********************************************************************1112function: mode selection code1314********************************************************************/15#if !defined(_collect_H)16# define _collect_H (1)17# include "encint.h"18# if defined(OC_COLLECT_METRICS)19# include <stdio.h>20212223typedef struct oc_mode_metrics oc_mode_metrics;24252627/**Sets the file name to load/store mode metrics from/to.28* The file name string is stored by reference, and so must be valid for the29* lifetime of the encoder.30* Mode metric collection uses global tables; do not attempt to perform31* multiple collections at once.32* \param[in] _buf <tt>char[]</tt> The file name.33* \retval TH_EIMPL Not supported by this implementation.*/34#define TH_ENCCTL_SET_METRICS_FILE (0x8000)35363738/*Accumulates various weighted sums of the measurements.39w -> weight40s -> SATD41q -> log quantizer42r -> rate (in bits)43d -> RMSE44All of the single letters correspond to direct, weighted sums, e.g.,45w=sum(w_i), s=sum(s_i*w_i), etc.46The others correspond to central moments (or co-moments) of the given order,47e.g., sq=sum((s_i-s/w)*(q_i-q/w)*w_i).48Because we need some moments up to fourth order, we use central moments to49minimize the dynamic range and prevent rounding error from dominating the50calculations.*/51struct oc_mode_metrics{52double w;53double s;54double q;55double r;56double d;57double s2;58double sq;59double q2;60double sr;61double qr;62double r2;63double sd;64double qd;65double d2;66double s2q;67double sq2;68double sqr;69double sqd;70double s2q2;71};727374# define OC_ZWEIGHT (0.25)7576/*TODO: It may be helpful (for block-level quantizers especially) to separate77out the contributions from AC and DC into separate tables.*/7879extern ogg_int16_t OC_MODE_LOGQ[OC_LOGQ_BINS][3][2];80extern oc_mode_rd OC_MODE_RD_SATD[OC_LOGQ_BINS][3][2][OC_COMP_BINS];81extern oc_mode_rd OC_MODE_RD_SAD[OC_LOGQ_BINS][3][2][OC_COMP_BINS];8283extern int OC_HAS_MODE_METRICS;84extern oc_mode_metrics OC_MODE_METRICS_SATD[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];85extern oc_mode_metrics OC_MODE_METRICS_SAD[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];86extern const char *OC_MODE_METRICS_FILENAME;8788void oc_mode_metrics_dump();89void oc_mode_metrics_print(FILE *_fout);9091void oc_mode_metrics_add(oc_mode_metrics *_metrics,92double _w,int _s,int _q,int _r,double _d);93void oc_mode_metrics_merge(oc_mode_metrics *_dst,94const oc_mode_metrics *_src,int _n);95double oc_mode_metrics_solve(double *_r,double *_d,96const oc_mode_metrics *_metrics,const int *_s0,const int *_s1,97const int *_q0,const int *_q1,98const double *_ra,const double *_rb,const double *_rc,99const double *_da,const double *_db,const double *_dc,int _n);100void oc_mode_metrics_update(oc_mode_metrics (*_metrics)[3][2][OC_COMP_BINS],101int _niters_min,int _reweight,oc_mode_rd (*_table)[3][2][OC_COMP_BINS],102int shift,double (*_weight)[3][2][OC_COMP_BINS]);103void oc_enc_mode_metrics_load(oc_enc_ctx *_enc);104void oc_enc_mode_metrics_collect(oc_enc_ctx *_enc);105106# endif107#endif108109110