18#if defined (WANT_WIN32_SOCKETS)
33#define ULONG_MAX ((unsigned long)-1)
35#define TRACK_MAX_FRAMES ULONG_MAX/4/1152
41#define bsbufid(fr) (fr)->bsbuf==(fr)->bsspace[0] ? 0 : ((fr)->bsbuf==fr->bsspace[1] ? 1 : ( (fr)->bsbuf==(fr)->bsspace[0]+512 ? 2 : ((fr)->bsbuf==fr->bsspace[1]+512 ? 3 : -1) ) )
59 {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
60 {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
61 {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,}
64 {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
65 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
66 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,}
70static const long freqs[9] = { 44100, 48000, 32000, 22050, 24000, 16000 , 11025 , 12000 , 8000 };
122 | (((
unsigned long)
buf[*
offset+1]) << 16)
141 unsigned long xing_flags;
142 unsigned long long_tmp;
149 int lame_offset = (fr->
stereo == 2)
150 ? (fr->
lsf ? 17 : 32)
151 : (fr->
lsf ? 9 : 17);
155 debug(
"do we have lame tag?");
163 if(fr->
framesize < lame_offset+8)
goto check_lame_tag_no;
166 for(
i=2;
i < lame_offset; ++
i)
if(fr->
bsbuf[
i] != 0)
goto check_lame_tag_no;
168 debug(
"possibly...");
171 (fr->
bsbuf[lame_offset] ==
'I')
172 && (fr->
bsbuf[lame_offset+1] ==
'n')
173 && (fr->
bsbuf[lame_offset+2] ==
'f')
174 && (fr->
bsbuf[lame_offset+3] ==
'o')
181 (fr->
bsbuf[lame_offset] ==
'X')
182 && (fr->
bsbuf[lame_offset+1] ==
'i')
183 && (fr->
bsbuf[lame_offset+2] ==
'n')
184 && (fr->
bsbuf[lame_offset+3] ==
'g')
189 else goto check_lame_tag_no;
195 debug1(
"Xing: flags 0x%08lx", xing_flags);
199 #define check_bytes_left(n) if(fr->framesize < lame_offset+n) \
200 goto check_lame_tag_yes
207 ,
"Note: Ignoring Xing frames because of MPG123_IGNORE_STREAMLENGTH\n");
228 ,
"Note: Ignoring Xing bytes because of MPG123_IGNORE_STREAMLENGTH\n");
236 if(fr->
rdat.filelen < 1)
242 double diff = 100.0/fr->
rdat.filelen
245 if(diff < 0.) diff = -diff;
248 ,
"Note: Xing stream size %lu differs by %f%% from determined/given file size!\n"
252 ,
"Warning: Xing stream size off by more than 1%%, fuzzy seeking may be even more fuzzy than by design!\n");
281 if(fr->bsbuf[lame_offset] != 0)
283 unsigned char lame_vbr;
284 float replay_gain[2] = {0,0};
286 float gain_offset = 0;
290 memcpy(nb, fr->bsbuf+lame_offset, 9);
311 ,
"Note: Info: Old LAME detected, using ReplayGain preamp of %f dB.\n"
316 ,
"Note: Info: Cannot determine LAME version.\n");
321 lame_vbr = fr->bsbuf[lame_offset] & 15;
325 fprintf(
stderr,
"Note: Info: rev %u\n", fr->bsbuf[lame_offset] >> 4);
344 (fr->bsbuf[lame_offset] != 0)
345 || (fr->bsbuf[lame_offset+1] != 0)
346 || (fr->bsbuf[lame_offset+2] != 0)
347 || (fr->bsbuf[lame_offset+3] != 0)
350 debug(
"Wow! Is there _really_ a non-zero peak value? Now is it stored as float or int - how should I know?");
357 ,
"Note: Info: peak = %f (I won't use this)\n", peak);
367 for(
i =0;
i < 2; ++
i)
369 unsigned char gt = fr->bsbuf[lame_offset] >> 5;
370 unsigned char origin = (fr->bsbuf[lame_offset] >> 2) & 0x7;
371 float factor = (fr->bsbuf[lame_offset] & 0x2) ? -0.1f : 0.1f;
372 unsigned short gain =
bit_read_short(fr->bsbuf, &lame_offset) & 0x1ff;
373 if(
origin == 0 || gt < 1 || gt > 2)
continue;
378 if(
origin == 3) replay_gain[gt] += gain_offset;
389 if(fr->rva.level[
i] <= 0)
392 fr->rva.gain[
i] = replay_gain[
i];
393 fr->rva.level[
i] = 0;
402 fr->abr_rate = fr->bsbuf[lame_offset];
410 pad_in = ( (((
int) fr->bsbuf[lame_offset]) << 4)
411 | (((
int) fr->bsbuf[lame_offset+1]) >> 4) );
412 pad_out = ( (((
int) fr->bsbuf[lame_offset+1]) << 8)
413 | ((
int) fr->bsbuf[lame_offset+2]) ) & 0xfff;
416 , (
int)pad_in, (
int)pad_out);
418 fr->enc_delay = (
int)pad_in;
419 fr->enc_padding = (
int)pad_out;
429 fr->bsbuf = fr->bsspace[fr->bsnum]+512;
430 fr->bsnum = (fr->bsnum + 1) & 1;
452 if(fr->
p.halfspeed && fr->
lay == 3)
454 debug(
"halfspeed - reusing old bsbuf ");
488#define JUMP_CONCLUSION(ret) \
490if(ret < 0){ debug1("%s", ret == MPG123_NEED_MORE ? "need more" : "read error"); goto read_frame_bad; } \
491else if(ret == PARSE_AGAIN) goto read_again; \
492else if(ret == PARSE_RESYNC) goto init_resync; \
493else if(ret == PARSE_END){ ret=0; goto read_frame_bad; } \
503 int freeformat_count = 0;
504 unsigned long newhead;
531 " frames as indicated fixed track length"
539 if(fr->
rd->forget !=
NULL) fr->
rd->forget(fr);
542 if((
ret = fr->
rd->head_read(fr,&newhead)) <= 0){
debug1(
"need more? (%i)",
ret);
goto read_frame_bad;}
572 if(
ret < 0) fr->
rd->back_bytes(fr, 4);
583 " as its header indicates Frankenstein coming for you", (
off_p)fr->
num );
589 framepos = fr->
rd->tell(fr) - 4;
619 if(fr->
rd->forget !=
NULL) fr->
rd->forget(fr);
670 if(fr->
rd->forget !=
NULL) fr->
rd->forget(fr);
699 fprintf(
stderr,
"\nWarning: Big change (MPEG version, layer, rate). Frankenstein stream?\n");
706 fprintf(
stderr,
"\nWarning: Big change from first (MPEG version, layer, rate). Frankenstein stream?\n");
716 if(fr->
rd->forget !=
NULL) fr->
rd->forget(fr);
741 if(
NOQUIET)
error(
"Cannot look for freeformat frame size with non-seekable and non-buffered stream!");
756 fr->
rd->back_bytes(fr,
i+1);
761 fr->
rd->back_bytes(fr,
i);
780 error1(
"trying to decode obviously invalid header 0x%08lx", newhead);
828 error(
"Got no free-format frame size and am not allowed to read ahead.");
831 *freeformat_count += 1;
832 if(*freeformat_count > 5)
834 if(
VERBOSE3)
error(
"You fooled me too often. Refusing to guess free format frame size _again_.");
847 debug(
"Need more data to guess free format frame size.");
849 error(
"Encountered free format header, but failed to guess frame size.");
892 fr->
spf = fr->
lsf ? 576 : 1152;
912 error2(
"Frame smaller than mandatory side info (%i < %i)!"
982 static int bs[4] = { 0,384,1152,1152 };
993 double *current_seconds,
double *seconds_left)
1005 if(buffsize > 0 && fr->
af.rate > 0 && fr->
af.channels > 0)
1007 dt = (
double) buffsize / fr->
af.rate / fr->
af.channels;
1015 if(fr->
rdat.filelen >= 0)
1039 curs = curs < 0 ? 0.0 : curs;
1041 if(
left < 0 || lefts < 0)
1046 if(current_frame !=
NULL) *current_frame =
cur;
1047 if(frames_left !=
NULL) *frames_left =
left;
1048 if(current_seconds !=
NULL) *current_seconds = curs;
1049 if(seconds_left !=
NULL) *seconds_left = lefts;
1061 if(!fr->
rd || fr->
rdat.filelen < 0)
1067 return (
int) (
no*tpf);
1073 unsigned long nexthead = 0;
1085 if((oret=fr->
rd->skip_bytes(fr, fr->
framesize))<0)
1093 hd = fr->
rd->head_read(fr,&nexthead);
1094 if( fr->
rd->back_bytes(fr, fr->
rd->tell(fr)-
start) < 0 )
1105 if(
NOQUIET)
warning(
"Cannot read next header, a one-frame stream? Duh...");
1109 debug2(
"does next header 0x%08lx match first 0x%08lx?", nexthead, newhead);
1112 debug(
"No, the header was not valid, start from beginning...");
1115 if((
ret=fr->
rd->back_bytes(fr, 3))<0)
1134 else debug(
"no useful ID3v2");
1141 unsigned char apebuf[28];
1151 if((
ret=fr->
rd->fullread(fr,apebuf,28)) < 0)
1159 if(
strncmp((
char *)apebuf,
"AGEX",4) != 0)
1163 val = ((
unsigned long)apebuf[7]<<24)
1164 | ((
unsigned long)apebuf[6]<<16)
1165 | ((
unsigned long)apebuf[5]<<8)
1171 for(
i=20;
i<28;
i++)
1176 val = ((
unsigned long)apebuf[11]<<24)
1177 | ((
unsigned long)apebuf[10]<<16)
1178 | ((
unsigned long)apebuf[9]<<8)
1180 debug2(
"skipping %lu bytes of APE data at %"OFF_P
1183 if((
ret=fr->
rd->skip_bytes(fr,
val)) < 0)
1189 debug(
"no proper APE tag found, seeking back");
1190 if(fr->
rd->back_bytes(fr,back_bytes) < 0 &&
NOQUIET)
1191 error1(
"Cannot seek %d bytes back!", back_bytes);
1198#define FORGET_INTERVAL 1024
1202 if((
ret=fr->
rd->head_shift(fr,newheadp))<=0)
return ret;
1206 if(forget && fr->
rd->forget !=
NULL)
1210 if(!fr->
rd->back_bytes(fr, 4))
1213 fr->
rd->back_bytes(fr, -4);
1223 int freeformat_count = 0;
1225 unsigned long newhead = *newheadp;
1226 unsigned int forgetcount = 0;
1228 if((newhead & (
unsigned long) 0xffffff00) == (
unsigned long) 0x49443300)
1235 if(newhead == (
'R'<<24)+(
'I'<<16)+(
'F'<<8)+
'F')
1239 if((
ret=fr->
rd->head_read(fr,&newhead))<=0)
return ret;
1241 while(newhead != (
'd'<<24)+(
'a'<<16)+(
't'<<8)+
'a')
1246 if((
ret=fr->
rd->head_read(fr,&newhead))<=0)
return ret;
1251 *newheadp = newhead;
1259 debug(
"searching for header...");
1265 if(fr->
p.resync_limit < 0 || fr->
p.resync_limit >
limit)
1266 limit = fr->
p.resync_limit;
1282 if(
NOQUIET)
error1(
"Giving up searching valid MPEG header after %li bytes of junk.", *headcount);
1289 *newheadp = newhead;
1297 unsigned long newhead = *newheadp;
1301 if((newhead & 0xffffff00) == (
'T'<<24)+(
'A'<<16)+(
'G'<<8))
1303 fr->
id3buf[0] = (
unsigned char) ((newhead >> 24) & 0xff);
1304 fr->
id3buf[1] = (
unsigned char) ((newhead >> 16) & 0xff);
1305 fr->
id3buf[2] = (
unsigned char) ((newhead >> 8) & 0xff);
1306 fr->
id3buf[3] = (
unsigned char) ( newhead & 0xff);
1318 if((newhead & (
unsigned long) 0xffffff00) == (
unsigned long) 0x49443300)
1323 if(newhead == (
'A'<<24)+(
'P'<<16)+(
'E'<<8)+
'T')
1330 newhead, (
off_p)fr->
rd->tell(fr)-4);
1335 if(
NOQUIET && (newhead & 0xffffff00) == (
'b'<<24)+(
'm'<<16)+(
'p'<<8))
fprintf(
stderr,
"Note: Could be a BMP album art.\n");
1340 long limit = fr->
p.resync_limit;
1341 unsigned int forgetcount = 0;
1356 *newheadp = newhead;
1364 *newheadp = newhead;
1371 error1(
"Giving up resync after %li bytes - your stream is not nice... (maybe increasing resync limit could help).",
try);
1378 debug1(
"Found possibly valid header 0x%lx... unsetting oldhead to reinit stream.", newhead);
#define attribute_align_arg
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
struct outqueuenode * head
static WCHAR no[MAX_STRING_RESOURCE_LEN]
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
static unsigned int getbits(mpg123_handle *fr, int number_of_bits)
GLenum GLuint GLenum GLsizei const GLchar * buf
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
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 GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
@ MPG123_IGNORE_STREAMLENGTH
@ MPG123_IGNORE_INFOFRAME
int attribute_align_arg mpg123_position(mpg123_handle *fr, off_t no, off_t buffsize, off_t *current_frame, off_t *frames_left, double *current_seconds, double *seconds_left)
int attribute_align_arg mpg123_spf(mpg123_handle *mh)
double attribute_align_arg mpg123_tpf(mpg123_handle *fr)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define FI_NEXT(fi, framenum)
#define frame_gapless_init
static struct msdos_boot_sector bs
#define memcpy(s1, s2, n)
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
static float(__cdecl *square_half_float)(float x
#define HDR_BITRATE_VAL(h)
#define HDR_ORIGINAL_VAL(h)
#define HDR_EMPHASIS_VAL(h)
#define HDR_PRIVATE_VAL(h)
#define HDR_VERSION_VAL(h)
#define HDR_CHANEX_VAL(h)
#define HDR_CHANNEL_VAL(h)
#define HDR_SAMPLERATE_VAL(h)
#define HDR_COPYRIGHT_VAL(h)
#define HDR_PADDING_VAL(h)
#define debug4(s, a, b, c, d)
#define debug3(s, a, b, c)
static int do_readahead(mpg123_handle *fr, unsigned long newhead)
static unsigned short bit_read_short(unsigned char *buf, int *offset)
#define JUMP_CONCLUSION(ret)
static int head_compatible(unsigned long fred, unsigned long bret)
#define check_bytes_left(n)
static int decode_header(mpg123_handle *fr, unsigned long newhead, int *freeformat_count)
static int handle_apetag(mpg123_handle *fr, unsigned long newhead)
static int forget_head_shift(mpg123_handle *fr, unsigned long *newheadp, int forget)
static int handle_id3v2(mpg123_handle *fr, unsigned long newhead)
static void halfspeed_prepare(mpg123_handle *fr)
static unsigned long bit_read_long(unsigned char *buf, int *offset)
static int halfspeed_do(mpg123_handle *fr)
static const long freqs[9]
static int header_mono(unsigned long newhead)
static int check_lame_tag(mpg123_handle *fr)
static const int tabsel_123[2][3][16]
static int head_check(unsigned long head)
static int guess_freeformat_framesize(mpg123_handle *fr, unsigned long oldhead)
static int wetwork(mpg123_handle *fr, unsigned long *newheadp)
static int skip_junk(mpg123_handle *fr, unsigned long *newheadp, long *headcount)
struct mpg123_pars_struct p
unsigned int bitreservoir
unsigned char id3buf[128]
int(* do_layer)(mpg123_handle *)
unsigned char * wordpointer
long freeformat_framesize
unsigned char bsspace[2][MAXFRAMESIZE+512+4]