Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libtheora/collect.h
9902 views
1
/********************************************************************
2
* *
3
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7
* *
8
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
9
* by the Xiph.Org Foundation https://www.xiph.org/ *
10
* *
11
********************************************************************
12
13
function: mode selection code
14
15
********************************************************************/
16
#if !defined(_collect_H)
17
# define _collect_H (1)
18
# include "encint.h"
19
# if defined(OC_COLLECT_METRICS)
20
# include <stdio.h>
21
22
23
24
typedef struct oc_mode_metrics oc_mode_metrics;
25
26
27
28
/**Sets the file name to load/store mode metrics from/to.
29
* The file name string is stored by reference, and so must be valid for the
30
* lifetime of the encoder.
31
* Mode metric collection uses global tables; do not attempt to perform
32
* multiple collections at once.
33
* \param[in] _buf <tt>char[]</tt> The file name.
34
* \retval TH_EIMPL Not supported by this implementation.*/
35
#define TH_ENCCTL_SET_METRICS_FILE (0x8000)
36
37
38
39
/*Accumulates various weighted sums of the measurements.
40
w -> weight
41
s -> SATD
42
q -> log quantizer
43
r -> rate (in bits)
44
d -> RMSE
45
All of the single letters correspond to direct, weighted sums, e.g.,
46
w=sum(w_i), s=sum(s_i*w_i), etc.
47
The others correspond to central moments (or co-moments) of the given order,
48
e.g., sq=sum((s_i-s/w)*(q_i-q/w)*w_i).
49
Because we need some moments up to fourth order, we use central moments to
50
minimize the dynamic range and prevent rounding error from dominating the
51
calculations.*/
52
struct oc_mode_metrics{
53
double w;
54
double s;
55
double q;
56
double r;
57
double d;
58
double s2;
59
double sq;
60
double q2;
61
double sr;
62
double qr;
63
double r2;
64
double sd;
65
double qd;
66
double d2;
67
double s2q;
68
double sq2;
69
double sqr;
70
double sqd;
71
double s2q2;
72
};
73
74
75
# define OC_ZWEIGHT (0.25)
76
77
/*TODO: It may be helpful (for block-level quantizers especially) to separate
78
out the contributions from AC and DC into separate tables.*/
79
80
extern ogg_int16_t OC_MODE_LOGQ[OC_LOGQ_BINS][3][2];
81
extern oc_mode_rd OC_MODE_RD_SATD[OC_LOGQ_BINS][3][2][OC_COMP_BINS];
82
extern oc_mode_rd OC_MODE_RD_SAD[OC_LOGQ_BINS][3][2][OC_COMP_BINS];
83
84
extern int OC_HAS_MODE_METRICS;
85
extern oc_mode_metrics OC_MODE_METRICS_SATD[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];
86
extern oc_mode_metrics OC_MODE_METRICS_SAD[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];
87
extern const char *OC_MODE_METRICS_FILENAME;
88
89
void oc_mode_metrics_dump();
90
void oc_mode_metrics_print(FILE *_fout);
91
92
void oc_mode_metrics_add(oc_mode_metrics *_metrics,
93
double _w,int _s,int _q,int _r,double _d);
94
void oc_mode_metrics_merge(oc_mode_metrics *_dst,
95
const oc_mode_metrics *_src,int _n);
96
double oc_mode_metrics_solve(double *_r,double *_d,
97
const oc_mode_metrics *_metrics,const int *_s0,const int *_s1,
98
const int *_q0,const int *_q1,
99
const double *_ra,const double *_rb,const double *_rc,
100
const double *_da,const double *_db,const double *_dc,int _n);
101
void oc_mode_metrics_update(oc_mode_metrics (*_metrics)[3][2][OC_COMP_BINS],
102
int _niters_min,int _reweight,oc_mode_rd (*_table)[3][2][OC_COMP_BINS],
103
int shift,double (*_weight)[3][2][OC_COMP_BINS]);
104
void oc_enc_mode_metrics_load(oc_enc_ctx *_enc);
105
void oc_enc_mode_metrics_collect(oc_enc_ctx *_enc);
106
107
# endif
108
#endif
109
110