collect.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: mode selection code
  13. last mod: $Id$
  14. ********************************************************************/
  15. #if !defined(_collect_H)
  16. # define _collect_H (1)
  17. # include "encint.h"
  18. # if defined(OC_COLLECT_METRICS)
  19. # include <stdio.h>
  20. typedef struct oc_mode_metrics oc_mode_metrics;
  21. /**Sets the file name to load/store mode metrics from/to.
  22. * The file name string is stored by reference, and so must be valid for the
  23. * lifetime of the encoder.
  24. * Mode metric collection uses global tables; do not attempt to perform
  25. * multiple collections at once.
  26. * \param[in] _buf <tt>char[]</tt> The file name.
  27. * \retval TH_EIMPL Not supported by this implementation.*/
  28. #define TH_ENCCTL_SET_METRICS_FILE (0x8000)
  29. /*Accumulates various weighted sums of the measurements.
  30. w -> weight
  31. s -> SATD
  32. q -> log quantizer
  33. r -> rate (in bits)
  34. d -> RMSE
  35. All of the single letters correspond to direct, weighted sums, e.g.,
  36. w=sum(w_i), s=sum(s_i*w_i), etc.
  37. The others correspond to central moments (or co-moments) of the given order,
  38. e.g., sq=sum((s_i-s/w)*(q_i-q/w)*w_i).
  39. Because we need some moments up to fourth order, we use central moments to
  40. minimize the dynamic range and prevent rounding error from dominating the
  41. calculations.*/
  42. struct oc_mode_metrics{
  43. double w;
  44. double s;
  45. double q;
  46. double r;
  47. double d;
  48. double s2;
  49. double sq;
  50. double q2;
  51. double sr;
  52. double qr;
  53. double r2;
  54. double sd;
  55. double qd;
  56. double d2;
  57. double s2q;
  58. double sq2;
  59. double sqr;
  60. double sqd;
  61. double s2q2;
  62. };
  63. # define OC_ZWEIGHT (0.25)
  64. /*TODO: It may be helpful (for block-level quantizers especially) to separate
  65. out the contributions from AC and DC into separate tables.*/
  66. extern ogg_int16_t OC_MODE_LOGQ[OC_LOGQ_BINS][3][2];
  67. extern oc_mode_rd OC_MODE_RD_SATD[OC_LOGQ_BINS][3][2][OC_COMP_BINS];
  68. extern oc_mode_rd OC_MODE_RD_SAD[OC_LOGQ_BINS][3][2][OC_COMP_BINS];
  69. extern int OC_HAS_MODE_METRICS;
  70. extern oc_mode_metrics OC_MODE_METRICS_SATD[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];
  71. extern oc_mode_metrics OC_MODE_METRICS_SAD[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];
  72. extern const char *OC_MODE_METRICS_FILENAME;
  73. void oc_mode_metrics_dump();
  74. void oc_mode_metrics_print(FILE *_fout);
  75. void oc_mode_metrics_add(oc_mode_metrics *_metrics,
  76. double _w,int _s,int _q,int _r,double _d);
  77. void oc_mode_metrics_merge(oc_mode_metrics *_dst,
  78. const oc_mode_metrics *_src,int _n);
  79. double oc_mode_metrics_solve(double *_r,double *_d,
  80. const oc_mode_metrics *_metrics,const int *_s0,const int *_s1,
  81. const int *_q0,const int *_q1,
  82. const double *_ra,const double *_rb,const double *_rc,
  83. const double *_da,const double *_db,const double *_dc,int _n);
  84. void oc_mode_metrics_update(oc_mode_metrics (*_metrics)[3][2][OC_COMP_BINS],
  85. int _niters_min,int _reweight,oc_mode_rd (*_table)[3][2][OC_COMP_BINS],
  86. int shift,double (*_weight)[3][2][OC_COMP_BINS]);
  87. void oc_enc_mode_metrics_load(oc_enc_ctx *_enc);
  88. void oc_enc_mode_metrics_collect(oc_enc_ctx *_enc);
  89. # endif
  90. #endif