ReactOS  0.4.15-dev-1367-g07cc0b5
frame.h
Go to the documentation of this file.
1 /*
2  frame: Central data structures and opmitization hooks.
3 
4  copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
5  see COPYING and AUTHORS files in distribution or http://mpg123.org
6  initially written by Thomas Orgis
7 */
8 
9 #ifndef MPG123_FRAME_H
10 #define MPG123_FRAME_H
11 
12 #include <stdio.h>
13 #include "config.h"
14 #include "mpg123.h"
15 #include "optimize.h"
16 #include "id3.h"
17 #include "icy.h"
18 #include "reader.h"
19 #ifdef FRAME_INDEX
20 #include "index.h"
21 #endif
22 #include "synths.h"
23 
24 #ifdef OPT_DITHER
25 #include "dither.h"
27 #endif
28 
29 /* max = 1728 */
30 #define MAXFRAMESIZE 3456
31 
32 struct al_table
33 {
34  short bits;
35  short d;
36 };
37 
38 /* the output buffer, used to be pcm_sample, pcm_point and audiobufsize */
39 struct outbuffer
40 {
41  unsigned char *data; /* main data pointer, aligned */
42  unsigned char *p; /* read pointer */
43  size_t fill; /* fill from read pointer */
44  size_t size;
45  unsigned char *rdata; /* unaligned base pointer */
46 };
47 
49 {
50  int encoding; /* Final encoding, after post-processing. */
51  int encsize; /* Size of one sample in bytes, plain int should be fine here... */
52  int dec_enc; /* Encoding of decoder synth. */
53  int dec_encsize; /* Size of one decoder sample. */
54  int channels;
55  long rate;
56 };
57 
58 void invalidate_format(struct audioformat *af);
59 
61 {
62  int verbose; /* verbose level */
63  long flags; /* combination of above */
64 #ifndef NO_NTOM
65  long force_rate;
66 #endif
68  int rva; /* (which) rva to do: 0: nothing, 1: radio/mix/track 2: album/audiophile */
69  long halfspeed;
71  long timeout;
72 #define NUM_CHANNELS 2
74 /* long start_frame; */ /* frame offset to begin with */
75 /* long frame_number;*/ /* number of frames to decode */
76 #ifndef NO_ICY
78 #endif
79  double outscale;
81  long index_size; /* Long, because: negative values have a meaning. */
82  long preframes;
83 #ifndef NO_FEEDER
84  long feedpool;
85  long feedbuffer;
86 #endif
88 };
89 
91 {
95 };
96 
97 /* There is a lot to condense here... many ints can be merged as flags; though the main space is still consumed by buffers. */
99 {
100  int fresh; /* to be moved into flags */
103  int hybrid_blc[2];
104  /* the scratch vars for the decoders, sometimes real, sometimes short... sometimes int/long */
105  short *short_buffs[2][2];
106  real *real_buffs[2][2];
107  unsigned char *rawbuffs;
109 #ifdef OPT_I486
110  int i486bo[2];
111 #endif
112  int bo; /* Just have it always here. */
113 #ifdef OPT_DITHER
114  int ditherindex;
115  float *dithernoise;
116 #endif
117  unsigned char* rawdecwin; /* the block with all decwins */
118  int rawdecwins; /* size of rawdecwin memory */
119  real *decwin; /* _the_ decode table */
120 #ifdef OPT_MMXORSSE
121  /* I am not really sure that I need both of them... used in assembler */
122  float *decwin_mmx;
123  float *decwins;
124 #endif
125 #ifndef NO_EQUALIZER
127  real equalizer[2][32];
128 #endif
129  /* for halfspeed mode */
130  unsigned char ssave[34];
132 #ifndef NO_8BIT
133  /* a raw buffer and a pointer into the middle for signed short conversion, only allocated on demand */
134  unsigned char *conv16to8_buf;
135  unsigned char *conv16to8;
136 #endif
137  /* There's some possible memory saving for stuff that is not _really_ dynamic. */
138 
139  /* layer3 */
140  int longLimit[9][23];
141  int shortLimit[9][14];
142  real gainpow2[256+118+4]; /* not really dynamic, just different for mmx */
143 
144  /* layer2 */
145  real muls[27][64]; /* also used by layer 1 */
146 
147 #ifndef NO_NTOM
148  /* decode_ntom */
149  unsigned long ntom_val[2];
150  unsigned long ntom_step;
151 #endif
152  /* special i486 fun */
153 #ifdef OPT_I486
154  int *int_buffs[2][2];
155 #endif
156  /* special altivec... */
157 #ifdef OPT_ALTIVEC
158  real *areal_buffs[4][4];
159 #endif
160  struct synth_s synths;
161  struct
162  {
163 #ifdef OPT_MULTI
164 
165 #ifndef NO_LAYER3
166 #if (defined OPT_3DNOW_VINTAGE || defined OPT_3DNOWEXT_VINTAGE || defined OPT_SSE || defined OPT_X86_64 || defined OPT_AVX || defined OPT_NEON || defined OPT_NEON64)
167  void (*the_dct36)(real *,real *,real *,real *,real *);
168 #endif
169 #endif
170 
171 #endif
172  enum optdec type;
173  enum optcla class;
174  } cpu_opts;
175 
176  int verbose; /* 0: nothing, 1: just print chosen decoder, 2: be verbose */
177 
178  const struct al_table *alloc;
179  /* The runtime-chosen decoding, based on input and output format. */
183  /* Yes, this function is runtime-switched, too. */
184  void (*make_decode_tables)(mpg123_handle *fr); /* That is the volume control. */
185 
186  int stereo; /* I _think_ 1 for mono and 2 for stereo */
187  int jsbound;
188 #define SINGLE_STEREO -1
189 #define SINGLE_LEFT 0
190 #define SINGLE_RIGHT 1
191 #define SINGLE_MIX 3
192  int single;
195  int lsf; /* 0: MPEG 1.0; 1: MPEG 2.0/2.5 -- both used as bool and array index! */
196  /* Many flags in disguise as integers... wasting bytes. */
197  int mpeg25;
200  int lay;
201  long spf; /* cached count of samples per frame */
206  int padding;
208  int mode;
209  int mode_ext;
211  int original;
212  int emphasis;
213  int framesize; /* computed framesize */
214  int freesize; /* free format frame size */
215  enum mpg123_vbr vbr; /* 1 if variable bitrate was detected */
216  off_t num; /* frame offset ... */
217  off_t input_offset; /* byte offset of this frame in input stream */
218  off_t playnum; /* playback offset... includes repetitions, reset at seeks */
219  off_t audio_start; /* The byte offset in the file where audio data begins. */
221  char silent_resync; /* Do not complain for the next n resyncs. */
222  unsigned char* xing_toc; /* The seek TOC from Xing header. */
225 
226  /* bitstream info; bsi */
227  int bitindex;
229  unsigned char *wordpointer;
230  /* temporary storage for getbits stuff */
231  unsigned long ultmp;
232  unsigned char uctmp;
233 
234  /* rva data, used in common.c, set in id3.c */
235 
236  double maxoutburst; /* The maximum amplitude in current sample represenation. */
237  double lastscale;
238  struct
239  {
240  int level[2];
241  float gain[2];
242  float peak[2];
243  } rva;
244 
245  /* input data */
250  int fsizeold;
251  int ssize;
252  unsigned int bitreservoir;
253  unsigned char bsspace[2][MAXFRAMESIZE+512+4]; /* MAXFRAMESIZE */
254  unsigned char *bsbuf;
255  unsigned char *bsbufold;
256  int bsnum;
257  /* That is the header matching the last read frame body. */
258  unsigned long oldhead;
259  /* That is the header that is supposedly the first of the stream. */
260  unsigned long firsthead;
261  int abr_rate;
262 #ifdef FRAME_INDEX
264 #endif
265 
266  /* output data */
268  struct audioformat af;
270  size_t outblock; /* number of bytes that this frame produces (upper bound) */
271  int to_decode; /* this frame holds data to be decoded */
272  int to_ignore; /* the same, somehow */
273  off_t firstframe; /* start decoding from here */
274  off_t lastframe; /* last frame to decode (for gapless or num_frames limit) */
275  off_t ignoreframe; /* frames to decode but discard before firstframe */
276 #ifdef GAPLESS
277  off_t gapless_frames; /* frame count for the gapless part */
278  off_t firstoff; /* number of samples to ignore from firstframe */
279  off_t lastoff; /* number of samples to use from lastframe */
280  off_t begin_s; /* overall begin offset in samples */
282  off_t end_s; /* overall end offset in samples */
284  off_t fullend_os; /* gapless_frames translated to output samples */
285 #endif
286  unsigned int crc; /* Well, I need a safe 16bit type, actually. But wider doesn't hurt. */
287  struct reader *rd; /* pointer to the reading functions */
288  struct reader_data rdat; /* reader data and state info */
290  int err;
293  long clip;
294  /* the meta crap */
296  unsigned char id3buf[128];
297 #ifndef NO_ID3V2
299 #endif
300  unsigned char *id3v2_raw;
301  size_t id3v2_size;
302 #ifndef NO_ICY
303  struct icy_meta icy;
304 #endif
305  /*
306  More variables needed for decoders, layerX.c.
307  This time it is not about static variables but about the need for alignment which cannot be guaranteed on the stack by certain compilers (Sun Studio).
308  We do not require the compiler to align stuff for our hand-written assembly. We only hope that it's able to align stuff for SSE and similar ops it generates itself.
309  */
310  /*
311  Those layer-specific structs could actually share memory, as they are not in use simultaneously. One might allocate on decoder switch, too.
312  They all reside in one lump of memory (after each other), allocated to layerscratch.
313  */
315 #ifndef NO_LAYER1
316  struct
317  {
318  real (*fraction)[SBLIMIT]; /* ALIGNED(16) real fraction[2][SBLIMIT]; */
319  } layer1;
320 #endif
321 #ifndef NO_LAYER2
322  struct
323  {
324  real (*fraction)[4][SBLIMIT]; /* ALIGNED(16) real fraction[2][4][SBLIMIT] */
325  } layer2;
326 #endif
327 #ifndef NO_LAYER3
328  /* These are significant chunks of memory already... */
329  struct
330  {
331  real (*hybrid_in)[SBLIMIT][SSLIMIT]; /* ALIGNED(16) real hybridIn[2][SBLIMIT][SSLIMIT]; */
332  real (*hybrid_out)[SSLIMIT][SBLIMIT]; /* ALIGNED(16) real hybridOut[2][SSLIMIT][SBLIMIT]; */
333  } layer3;
334 #endif
335  /* A place for storing additional data for the large file wrapper.
336  This is cruft! */
337  void *wrapperdata;
338  /* A callback used to properly destruct the wrapper data. */
339  void (*wrapperclean)(void*);
342 #ifndef NO_MOREINFO
344 #endif
345 };
346 
347 /* generic init, does not include dynamic buffers */
348 void frame_init(mpg123_handle *fr);
350 /* output buffer and format */
353 
354 int frame_buffers(mpg123_handle *fr); /* various decoder buffers, needed once */
355 int frame_reset(mpg123_handle* fr); /* reset for next track */
357 void frame_exit(mpg123_handle *fr); /* end, free all buffers */
358 
359 /* Index functions... */
360 /* Well... print it... */
362 /* Find a seek position in index. */
363 off_t frame_index_find(mpg123_handle *fr, off_t want_frame, off_t* get_frame);
364 /* Apply index_size setting. */
366 
367 void do_volume(mpg123_handle *fr, double factor);
368 void do_rva(mpg123_handle *fr);
369 
370 /* samples per frame ...
371 Layer I
372 Layer II
373 Layer III
374 MPEG-1
375 384
376 1152
377 1152
378 MPEG-2 LSF
379 384
380 1152
381 576
382 MPEG 2.5
383 384
384 1152
385 576
386 */
387 
388 // Well, I take that one for granted... at least layer3.
389 // The value is needed for mpg123_getstate() in any build.
390 #define GAPLESS_DELAY 529
391 #ifdef GAPLESS
392 void frame_gapless_init(mpg123_handle *fr, off_t framecount, off_t bskip, off_t eskip);
394 void frame_gapless_update(mpg123_handle *mh, off_t total_samples);
395 /*void frame_gapless_position(mpg123_handle* fr);
396 void frame_gapless_bytify(mpg123_handle *fr);
397 void frame_gapless_ignore(mpg123_handle *fr, off_t frames);*/
398 /* void frame_gapless_buffercheck(mpg123_handle *fr); */
399 #endif
400 
401 /* Number of samples the decoding of the current frame should yield. */
403 
404 /* Skip this frame... do some fake action to get away without actually decoding it. */
405 void frame_skip(mpg123_handle *fr);
406 
407 /*
408  Seeking core functions:
409  - convert input sample offset to output sample offset
410  - convert frame offset to output sample offset
411  - get leading frame offset for output sample offset
412  The offsets are "unadjusted"/internal; resampling is being taken care of.
413 */
416 /* This one just computes the expected sample count for _this_ frame. */
422 /* Take a copy of the Xing VBR TOC for fuzzy seeking. */
423 int frame_fill_toc(mpg123_handle *fr, unsigned char* in);
424 #endif
real equalizer[2][32]
Definition: frame.h:127
void invalidate_format(struct audioformat *af)
Definition: format.c:550
float gain[2]
Definition: frame.h:241
long index_size
Definition: frame.h:81
void frame_gapless_init(mpg123_handle *fr, off_t framecount, off_t bskip, off_t eskip)
GLint level
Definition: gl.h:1546
Definition: synths.h:44
Definition: icy.h:16
off_t frame_ins2outs(mpg123_handle *fr, off_t ins)
Definition: frame.c:751
int frame_outbuffer(mpg123_handle *fr)
Definition: frame.c:183
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
unsigned char * data
Definition: frame.h:41
long preframes
Definition: frame.h:82
real * layerscratch
Definition: frame.h:314
off_t frame_outs(mpg123_handle *fr, off_t num)
Definition: frame.c:773
int(* func_synth_stereo)(real *, real *, mpg123_handle *)
Definition: synths.h:12
int longLimit[9][23]
Definition: frame.h:140
long feedbuffer
Definition: frame.h:85
int(* func_synth_mono)(real *, mpg123_handle *)
Definition: synths.h:11
void frame_set_frameseek(mpg123_handle *fr, off_t fe)
Definition: frame.c:913
long freeformat_framesize
Definition: frame.h:224
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint factor
Definition: glfuncs.h:178
size_t size
Definition: frame.h:44
size_t id3v2_size
Definition: frame.h:301
void * wrapperdata
Definition: frame.h:337
unsigned char * bsbufold
Definition: frame.h:255
__kernel_off_t off_t
Definition: linux.h:201
short bits
Definition: frame.h:34
#define SBLIMIT
unsigned char * id3v2_raw
Definition: frame.h:300
struct synth_s synths
Definition: frame.h:160
double mean_framesize
Definition: frame.h:248
_Tp _STLP_CALL real(const complex< _Tp > &__z)
Definition: _complex.h:727
GLuint buffer
Definition: glext.h:5915
size_t fill
Definition: frame.h:43
unsigned char * wordpointer
Definition: frame.h:229
int encoding
Definition: frame.h:50
char audio_caps[NUM_CHANNELS][MPG123_RATES+1][MPG123_ENCODINGS]
Definition: frame.h:73
long icy_interval
Definition: frame.h:77
unsigned char * p
Definition: frame.h:42
off_t input_offset
Definition: frame.h:217
long doublespeed
Definition: frame.h:70
unsigned char uctmp
Definition: frame.h:232
const struct al_table * alloc
Definition: frame.h:178
struct reader_data rdat
Definition: frame.h:288
unsigned long ultmp
Definition: frame.h:231
void(* wrapperclean)(void *)
Definition: frame.h:339
long halfspeed
Definition: frame.h:69
unsigned char * xing_toc
Definition: frame.h:222
struct mpg123_handle_struct::@3434 layer3
int frame_buffers(mpg123_handle *fr)
Definition: frame.c:268
int down_sample_sblimit
Definition: frame.h:194
off_t track_frames
Definition: frame.h:246
struct mpg123_handle_struct::@3430 cpu_opts
unsigned char bsspace[2][MAXFRAMESIZE+512+4]
Definition: frame.h:253
int(* func_synth)(real *, int, mpg123_handle *, int)
Definition: synths.h:10
off_t frame_expect_outsampels(mpg123_handle *fr)
int channels
Definition: frame.h:54
real(* fraction)[SBLIMIT]
Definition: frame.h:318
long rate
Definition: frame.h:55
real * real_buffs[2][2]
Definition: frame.h:106
int sampling_frequency
Definition: frame.h:205
void(* make_decode_tables)(mpg123_handle *fr)
Definition: frame.h:184
struct icy_meta icy
Definition: frame.h:303
unsigned char * rdata
Definition: frame.h:45
Definition: frame.h:32
unsigned char * conv16to8
Definition: frame.h:135
func_synth_mono synth_mono
Definition: frame.h:182
real muls[27][64]
Definition: frame.h:145
GLuint index
Definition: glext.h:6031
void do_volume(mpg123_handle *fr, double factor)
int(* do_layer)(mpg123_handle *)
Definition: frame.h:202
struct mpg123_moreinfo * pinfo
Definition: frame.h:343
unsigned int crc
Definition: frame.h:286
off_t gapless_frames
Definition: frame.h:277
enum optdec type
Definition: frame.h:172
int dec_enc
Definition: frame.h:52
float peak[2]
Definition: frame.h:242
off_t frame_offset(mpg123_handle *fr, off_t outs)
Definition: frame.c:819
static FILE * out
Definition: regtests2xml.c:44
long force_rate
Definition: frame.h:65
struct mpg123_handle_struct::@3431 rva
GLuint GLuint num
Definition: glext.h:9618
short d
Definition: frame.h:35
int dec_encsize
Definition: frame.h:53
#define SSLIMIT
#define MAXFRAMESIZE
Definition: frame.h:30
#define NUM_CHANNELS
Definition: frame.h:72
optdec
Definition: optimize.h:94
real hybrid_block[2][2][SBLIMIT *SSLIMIT]
Definition: frame.h:102
long freeformat_framesize
Definition: frame.h:87
int frame_index_setup(mpg123_handle *fr)
func_synth_stereo synth_stereo
Definition: frame.h:181
int mpg123_print_index(mpg123_handle *fr, FILE *out)
#define MPG123_RATES
unsigned long ntom_val[2]
Definition: frame.h:149
off_t frame_tell_seek(mpg123_handle *fr)
void frame_gapless_realinit(mpg123_handle *fr)
struct mpg123_handle_struct::@3432 layer1
short * short_buffs[2][2]
Definition: frame.h:105
long resync_limit
Definition: frame.h:80
int frame_buffers_reset(mpg123_handle *fr)
Definition: frame.c:441
mpg123_id3v2 id3v2
Definition: frame.h:298
int shortLimit[9][14]
Definition: frame.h:141
real(* hybrid_in)[SBLIMIT][SSLIMIT]
Definition: frame.h:331
func_synth synth
Definition: frame.h:180
double maxoutburst
Definition: frame.h:236
real gainpow2[256+118+4]
Definition: frame.h:142
unsigned long firsthead
Definition: frame.h:260
void frame_skip(mpg123_handle *fr)
Definition: frame.c:946
struct audioformat af
Definition: frame.h:268
GLuint in
Definition: glext.h:9616
unsigned char id3buf[128]
Definition: frame.h:296
double lastscale
Definition: frame.h:237
unsigned int bitreservoir
Definition: frame.h:252
void do_rva(mpg123_handle *fr)
Definition: frame.c:1014
int encsize
Definition: frame.h:51
int frame_reset(mpg123_handle *fr)
Definition: frame.c:494
unsigned char * rawbuffs
Definition: frame.h:107
Definition: reader.h:83
off_t frame_index_find(mpg123_handle *fr, off_t want_frame, off_t *get_frame)
Definition: frame.c:706
off_t frame_expect_outsamples(mpg123_handle *fr)
Definition: frame.c:797
double outscale
Definition: frame.h:79
int hybrid_blc[2]
Definition: frame.h:103
optcla
Definition: optimize.h:166
real(* hybrid_out)[SSLIMIT][SBLIMIT]
Definition: frame.h:332
mpg123_vbr
Definition: mpg123.h:1005
static const WCHAR sp[]
Definition: suminfo.c:288
unsigned long ntom_step
Definition: frame.h:150
struct reader * rd
Definition: frame.h:287
void frame_init_par(mpg123_handle *fr, mpg123_pars *mp)
Definition: frame.c:75
void frame_gapless_update(mpg123_handle *mh, off_t total_samples)
unsigned char * conv16to8_buf
Definition: frame.h:134
#define MPG123_ENCODINGS
GLfloat GLfloat p
Definition: glext.h:8902
off_t track_samples
Definition: frame.h:247
unsigned char ssave[34]
Definition: frame.h:130
#define frame_dither_init
Definition: intsym.h:177
unsigned char * rawdecwin
Definition: frame.h:117
struct mpg123_handle_struct::@3433 layer2
void frame_set_seek(mpg123_handle *fr, off_t sp)
Definition: frame.c:955
int frame_fill_toc(mpg123_handle *fr, unsigned char *in)
Definition: frame.c:473
unsigned long oldhead
Definition: frame.h:258
int frame_output_format(mpg123_handle *fr)
Definition: format.c:226
void frame_init(mpg123_handle *fr)
Definition: frame.c:70
enum mpg123_vbr vbr
Definition: frame.h:215
frame_state_flags
Definition: frame.h:90
unsigned char * bsbuf
Definition: frame.h:254
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
void frame_exit(mpg123_handle *fr)
Definition: frame.c:593