bitrate management bugfixes and tuning
[platform/upstream/libvorbis.git] / lib / bitrate.h
1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE OggVorbis 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 OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
9  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
10  *                                                                  *
11  ********************************************************************
12
13  function: bitrate tracking and management
14  last mod: $Id: bitrate.h,v 1.4 2001/12/23 10:12:03 xiphmont Exp $
15
16  ********************************************************************/
17
18 #ifndef _V_BITRATE_H_
19 #define _V_BITRATE_H_
20
21 #include "vorbis/codec.h"
22 #include "codec_internal.h"
23 #include "os.h"
24
25 /* encode side bitrate tracking */
26 #define BITTRACK_DIVISOR 16
27 #define BITTRACK_BPT     6
28 typedef struct bitrate_manager_state {
29   ogg_uint32_t  *queue_binned;
30   ogg_uint32_t  *queue_actual;
31   int            queue_size;
32
33   int            queue_head;
34   int            queue_bins;
35
36   long          *avg_binacc;
37   int            avg_center;
38   int            avg_tail;
39   ogg_uint32_t   avg_centeracc;
40   ogg_uint32_t   avg_sampleacc;
41   ogg_uint32_t   avg_sampledesired;
42   ogg_uint32_t   avg_centerdesired;
43
44   long          *minmax_binstack;
45   long          *minmax_posstack;
46   long          *minmax_limitstack;
47   long           minmax_stackptr;
48
49   long           minmax_acctotal;
50   int            minmax_tail;
51   ogg_uint32_t   minmax_sampleacc;
52   ogg_uint32_t   minmax_sampledesired;
53
54   int            next_to_flush;
55   int            last_to_flush;
56   
57   double         avgfloat;
58   double         avgnoise;
59   long           noisetrigger_postpone;
60   double         noisetrigger_request;
61
62   /* unfortunately, we need to hold queued packet data somewhere */
63   oggpack_buffer *queue_packet_buffers;
64   ogg_packet     *queue_packets;
65
66 } bitrate_manager_state;
67
68 typedef struct bitrate_manager_info{
69   /* detailed bitrate management setup */
70   double queue_avg_time;
71   double queue_avg_center;
72   double queue_minmax_time;
73   double queue_hardmin;
74   double queue_hardmax;
75   double queue_avgmin;
76   double queue_avgmax;
77
78   double avgfloat_initial; /* set by mode */
79   double avgfloat_minimum; /* set by mode */
80   double avgfloat_downslew_max;
81   double avgfloat_upslew_max;
82   double avgfloat_downhyst;
83   double avgfloat_uphyst;
84   double avgfloat_noise_lowtrigger;
85   double avgfloat_noise_hightrigger;
86   double avgfloat_noise_minval;
87   double avgfloat_noise_maxval;
88 } bitrate_manager_info;
89
90 extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
91 extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
92 extern int vorbis_bitrate_managed(vorbis_block *vb);
93 extern int vorbis_bitrate_maxmarkers(void);
94 extern int vorbis_bitrate_addblock(vorbis_block *vb);
95 extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
96
97 #endif