Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenframe.h
Go to the documentation of this file.
00001 /* 00002 frame: Central data structures and opmitization hooks. 00003 00004 copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1 00005 see COPYING and AUTHORS files in distribution or http://mpg123.org 00006 initially written by Thomas Orgis 00007 */ 00008 00009 #ifndef MPG123_FRAME_H 00010 #define MPG123_FRAME_H 00011 00012 #include <stdio.h> 00013 #include "config.h" 00014 #include "mpg123.h" 00015 #include "optimize.h" 00016 #include "id3.h" 00017 #include "icy.h" 00018 #include "reader.h" 00019 #ifdef FRAME_INDEX 00020 #include "index.h" 00021 #endif 00022 #include "synths.h" 00023 00024 #ifdef OPT_DITHER 00025 #include "dither.h" 00026 int frame_dither_init(mpg123_handle *fr); 00027 #endif 00028 00029 /* max = 1728 */ 00030 #define MAXFRAMESIZE 3456 00031 00032 struct al_table 00033 { 00034 short bits; 00035 short d; 00036 }; 00037 00038 /* the output buffer, used to be pcm_sample, pcm_point and audiobufsize */ 00039 struct outbuffer 00040 { 00041 unsigned char *data; 00042 unsigned char *p; /* read pointer */ 00043 size_t fill; /* fill from read pointer */ 00044 size_t size; /* that's actually more like a safe size, after we have more than that, flush it */ 00045 }; 00046 00047 struct audioformat 00048 { 00049 int encoding; 00050 int encsize; /* Size of one sample in bytes, plain int should be fine here... */ 00051 int channels; 00052 long rate; 00053 }; 00054 00055 void invalidate_format(struct audioformat *af); 00056 00057 struct mpg123_pars_struct 00058 { 00059 int verbose; /* verbose level */ 00060 long flags; /* combination of above */ 00061 #ifndef NO_NTOM 00062 long force_rate; 00063 #endif 00064 int down_sample; 00065 int rva; /* (which) rva to do: 0: nothing, 1: radio/mix/track 2: album/audiophile */ 00066 long halfspeed; 00067 long doublespeed; 00068 long timeout; 00069 #define NUM_CHANNELS 2 00070 char audio_caps[NUM_CHANNELS][MPG123_RATES+1][MPG123_ENCODINGS]; 00071 /* long start_frame; */ /* frame offset to begin with */ 00072 /* long frame_number;*/ /* number of frames to decode */ 00073 #ifndef NO_ICY 00074 long icy_interval; 00075 #endif 00076 double outscale; 00077 long resync_limit; 00078 long index_size; /* Long, because: negative values have a meaning. */ 00079 long preframes; 00080 }; 00081 00082 00083 00084 /* There is a lot to condense here... many ints can be merged as flags; though the main space is still consumed by buffers. */ 00085 struct mpg123_handle_struct 00086 { 00087 int fresh; /* to be moved into flags */ 00088 int new_format; 00089 real hybrid_block[2][2][SBLIMIT*SSLIMIT]; 00090 int hybrid_blc[2]; 00091 /* the scratch vars for the decoders, sometimes real, sometimes short... sometimes int/long */ 00092 short *short_buffs[2][2]; 00093 real *real_buffs[2][2]; 00094 unsigned char *rawbuffs; 00095 int rawbuffss; 00096 #ifdef OPT_I486 00097 int i486bo[2]; 00098 #endif 00099 int bo; /* Just have it always here. */ 00100 #ifdef OPT_DITHER 00101 int ditherindex; 00102 float *dithernoise; 00103 #endif 00104 unsigned char* rawdecwin; /* the block with all decwins */ 00105 int rawdecwins; /* size of rawdecwin memory */ 00106 real *decwin; /* _the_ decode table */ 00107 #ifdef OPT_MMXORSSE 00108 /* I am not really sure that I need both of them... used in assembler */ 00109 float *decwin_mmx; 00110 float *decwins; 00111 #endif 00112 int have_eq_settings; 00113 real equalizer[2][32]; 00114 00115 /* for halfspeed mode */ 00116 unsigned char ssave[34]; 00117 int halfphase; 00118 #ifndef NO_8BIT 00119 /* a raw buffer and a pointer into the middle for signed short conversion, only allocated on demand */ 00120 unsigned char *conv16to8_buf; 00121 unsigned char *conv16to8; 00122 #endif 00123 /* There's some possible memory saving for stuff that is not _really_ dynamic. */ 00124 00125 /* layer3 */ 00126 int longLimit[9][23]; 00127 int shortLimit[9][14]; 00128 real gainpow2[256+118+4]; /* not really dynamic, just different for mmx */ 00129 00130 /* layer2 */ 00131 real muls[27][64]; /* also used by layer 1 */ 00132 00133 #ifndef NO_NTOM 00134 /* decode_ntom */ 00135 unsigned long ntom_val[2]; 00136 unsigned long ntom_step; 00137 #endif 00138 /* special i486 fun */ 00139 #ifdef OPT_I486 00140 int *int_buffs[2][2]; 00141 #endif 00142 /* special altivec... */ 00143 #ifdef OPT_ALTIVEC 00144 real *areal_buffs[4][4]; 00145 #endif 00146 struct synth_s synths; 00147 struct 00148 { 00149 #ifdef OPT_MULTI 00150 00151 #ifndef NO_LAYER3 00152 #if (defined OPT_3DNOW || defined OPT_3DNOWEXT) 00153 void (*the_dct36)(real *,real *,real *,real *,real *); 00154 #endif 00155 #endif 00156 00157 #endif 00158 enum optdec type; 00159 enum optcla class; 00160 } cpu_opts; 00161 00162 int verbose; /* 0: nothing, 1: just print chosen decoder, 2: be verbose */ 00163 00164 const struct al_table *alloc; 00165 /* The runtime-chosen decoding, based on input and output format. */ 00166 func_synth synth; 00167 func_synth_stereo synth_stereo; 00168 func_synth_mono synth_mono; 00169 /* Yes, this function is runtime-switched, too. */ 00170 void (*make_decode_tables)(mpg123_handle *fr); /* That is the volume control. */ 00171 00172 int stereo; /* I _think_ 1 for mono and 2 for stereo */ 00173 int jsbound; 00174 #define SINGLE_STEREO -1 00175 #define SINGLE_LEFT 0 00176 #define SINGLE_RIGHT 1 00177 #define SINGLE_MIX 3 00178 int single; 00179 int II_sblimit; 00180 int down_sample_sblimit; 00181 int lsf; /* 0: MPEG 1.0; 1: MPEG 2.0/2.5 -- both used as bool and array index! */ 00182 /* Many flags in disguise as integers... wasting bytes. */ 00183 int mpeg25; 00184 int down_sample; 00185 int header_change; 00186 int lay; 00187 int (*do_layer)(mpg123_handle *); 00188 int error_protection; 00189 int bitrate_index; 00190 int sampling_frequency; 00191 int padding; 00192 int extension; 00193 int mode; 00194 int mode_ext; 00195 int copyright; 00196 int original; 00197 int emphasis; 00198 int framesize; /* computed framesize */ 00199 int freesize; /* free format frame size */ 00200 enum mpg123_vbr vbr; /* 1 if variable bitrate was detected */ 00201 off_t num; /* frame offset ... */ 00202 off_t playnum; /* playback offset... includes repetitions, reset at seeks */ 00203 off_t audio_start; /* The byte offset in the file where audio data begins. */ 00204 char accurate; /* Flag to see if we trust the frame number. */ 00205 char silent_resync; /* Do not complain for the next n resyncs. */ 00206 unsigned char* xing_toc; /* The seek TOC from Xing header. */ 00207 int freeformat; 00208 long freeformat_framesize; 00209 00210 /* bitstream info; bsi */ 00211 int bitindex; 00212 unsigned char *wordpointer; 00213 /* temporary storage for getbits stuff */ 00214 unsigned long ultmp; 00215 unsigned char uctmp; 00216 00217 /* rva data, used in common.c, set in id3.c */ 00218 00219 double maxoutburst; /* The maximum amplitude in current sample represenation. */ 00220 double lastscale; 00221 struct 00222 { 00223 int level[2]; 00224 float gain[2]; 00225 float peak[2]; 00226 } rva; 00227 00228 /* input data */ 00229 off_t track_frames; 00230 off_t track_samples; 00231 double mean_framesize; 00232 off_t mean_frames; 00233 int fsizeold; 00234 int ssize; 00235 unsigned int bitreservoir; 00236 unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */ 00237 unsigned char *bsbuf; 00238 unsigned char *bsbufold; 00239 int bsnum; 00240 unsigned long oldhead; 00241 unsigned long firsthead; 00242 int abr_rate; 00243 #ifdef FRAME_INDEX 00244 struct frame_index index; 00245 #endif 00246 00247 /* output data */ 00248 struct outbuffer buffer; 00249 struct audioformat af; 00250 int own_buffer; 00251 size_t outblock; /* number of bytes that this frame produces (upper bound) */ 00252 int to_decode; /* this frame holds data to be decoded */ 00253 int to_ignore; /* the same, somehow */ 00254 off_t firstframe; /* start decoding from here */ 00255 off_t lastframe; /* last frame to decode (for gapless or num_frames limit) */ 00256 off_t ignoreframe; /* frames to decode but discard before firstframe */ 00257 #ifdef GAPLESS 00258 off_t firstoff; /* number of samples to ignore from firstframe */ 00259 off_t lastoff; /* number of samples to use from lastframe */ 00260 off_t begin_s; /* overall begin offset in samples */ 00261 off_t begin_os; 00262 off_t end_s; /* overall end offset in samples */ 00263 off_t end_os; 00264 #endif 00265 unsigned int crc; /* Well, I need a safe 16bit type, actually. But wider doesn't hurt. */ 00266 struct reader *rd; /* pointer to the reading functions */ 00267 struct reader_data rdat; /* reader data and state info */ 00268 struct mpg123_pars_struct p; 00269 int err; 00270 int decoder_change; 00271 int delayed_change; 00272 long clip; 00273 /* the meta crap */ 00274 int metaflags; 00275 unsigned char id3buf[128]; 00276 #ifndef NO_ID3V2 00277 mpg123_id3v2 id3v2; 00278 #endif 00279 #ifndef NO_ICY 00280 struct icy_meta icy; 00281 #endif 00282 /* 00283 More variables needed for decoders, layerX.c. 00284 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). 00285 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. 00286 */ 00287 /* 00288 Those layer-specific structs could actually share memory, as they are not in use simultaneously. One might allocate on decoder switch, too. 00289 They all reside in one lump of memory (after each other), allocated to layerscratch. 00290 */ 00291 real *layerscratch; 00292 #ifndef NO_LAYER1 00293 struct 00294 { 00295 real (*fraction)[SBLIMIT]; /* ALIGNED(16) real fraction[2][SBLIMIT]; */ 00296 } layer1; 00297 #endif 00298 #ifndef NO_LAYER2 00299 struct 00300 { 00301 real (*fraction)[4][SBLIMIT]; /* ALIGNED(16) real fraction[2][4][SBLIMIT] */ 00302 } layer2; 00303 #endif 00304 #ifndef NO_LAYER3 00305 /* These are significant chunks of memory already... */ 00306 struct 00307 { 00308 real (*hybrid_in)[SBLIMIT][SSLIMIT]; /* ALIGNED(16) real hybridIn[2][SBLIMIT][SSLIMIT]; */ 00309 real (*hybrid_out)[SSLIMIT][SBLIMIT]; /* ALIGNED(16) real hybridOut[2][SSLIMIT][SBLIMIT]; */ 00310 } layer3; 00311 #endif 00312 /* A place for storing additional data for the large file wrapper. 00313 This is cruft! */ 00314 void *wrapperdata; 00315 /* A callback used to properly destruct the wrapper data. */ 00316 void (*wrapperclean)(void*); 00317 }; 00318 00319 /* generic init, does not include dynamic buffers */ 00320 void frame_init(mpg123_handle *fr); 00321 void frame_init_par(mpg123_handle *fr, mpg123_pars *mp); 00322 /* output buffer and format */ 00323 int frame_outbuffer(mpg123_handle *fr); 00324 int frame_output_format(mpg123_handle *fr); 00325 00326 int frame_buffers(mpg123_handle *fr); /* various decoder buffers, needed once */ 00327 int frame_reset(mpg123_handle* fr); /* reset for next track */ 00328 int frame_buffers_reset(mpg123_handle *fr); 00329 void frame_exit(mpg123_handle *fr); /* end, free all buffers */ 00330 00331 /* Index functions... */ 00332 /* Well... print it... */ 00333 int mpg123_print_index(mpg123_handle *fr, FILE* out); 00334 /* Find a seek position in index. */ 00335 off_t frame_index_find(mpg123_handle *fr, off_t want_frame, off_t* get_frame); 00336 /* Apply index_size setting. */ 00337 int frame_index_setup(mpg123_handle *fr); 00338 00339 void do_volume(mpg123_handle *fr, double factor); 00340 void do_rva(mpg123_handle *fr); 00341 00342 /* samples per frame ... 00343 Layer I 00344 Layer II 00345 Layer III 00346 MPEG-1 00347 384 00348 1152 00349 1152 00350 MPEG-2 LSF 00351 384 00352 1152 00353 576 00354 MPEG 2.5 00355 384 00356 1152 00357 576 00358 */ 00359 #define spf(fr) ((fr)->lay == 1 ? 384 : ((fr)->lay==2 ? 1152 : ((fr)->lsf || (fr)->mpeg25 ? 576 : 1152))) 00360 00361 #ifdef GAPLESS 00362 /* well, I take that one for granted... at least layer3 */ 00363 #define GAPLESS_DELAY 529 00364 /* still fine-tuning the "real music" window... see read_frame */ 00365 void frame_gapless_init(mpg123_handle *fr, off_t b, off_t e); 00366 void frame_gapless_realinit(mpg123_handle *fr); 00367 void frame_gapless_update(mpg123_handle *mh, off_t total_samples); 00368 /*void frame_gapless_position(mpg123_handle* fr); 00369 void frame_gapless_bytify(mpg123_handle *fr); 00370 void frame_gapless_ignore(mpg123_handle *fr, off_t frames);*/ 00371 /* void frame_gapless_buffercheck(mpg123_handle *fr); */ 00372 #endif 00373 00374 /* Number of samples the decoding of the current frame should yield. */ 00375 off_t frame_expect_outsamples(mpg123_handle *fr); 00376 00377 /* Skip this frame... do some fake action to get away without actually decoding it. */ 00378 void frame_skip(mpg123_handle *fr); 00379 00380 /* 00381 Seeking core functions: 00382 - convert input sample offset to output sample offset 00383 - convert frame offset to output sample offset 00384 - get leading frame offset for output sample offset 00385 The offsets are "unadjusted"/internal; resampling is being taken care of. 00386 */ 00387 off_t frame_ins2outs(mpg123_handle *fr, off_t ins); 00388 off_t frame_outs(mpg123_handle *fr, off_t num); 00389 /* This one just computes the expected sample count for _this_ frame. */ 00390 off_t frame_expect_outsampels(mpg123_handle *fr); 00391 off_t frame_offset(mpg123_handle *fr, off_t outs); 00392 void frame_set_frameseek(mpg123_handle *fr, off_t fe); 00393 void frame_set_seek(mpg123_handle *fr, off_t sp); 00394 off_t frame_tell_seek(mpg123_handle *fr); 00395 /* Take a copy of the Xing VBR TOC for fuzzy seeking. */ 00396 int frame_fill_toc(mpg123_handle *fr, unsigned char* in); 00397 00398 00399 /* adjust volume to current outscale and rva values if wanted */ 00400 void do_rva(mpg123_handle *fr); 00401 #endif Generated on Mon May 28 2012 04:32:58 for ReactOS by
1.7.6.1
|