ReactOS  0.4.14-dev-552-g2fad488
parse.c File Reference
#include "mpg123lib_intern.h"
#include <sys/stat.h>
#include <fcntl.h>
#include "getbits.h"
#include "mpeghead.h"
#include "debug.h"
Include dependency graph for parse.c:

Go to the source code of this file.

Macros

#define ULONG_MAX   ((unsigned long)-1)
 
#define TRACK_MAX_FRAMES   ULONG_MAX/4/1152
 
#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) ) )
 
#define check_bytes_left(n)
 
#define JUMP_CONCLUSION(ret)
 
#define FORGET_INTERVAL   1024 /* Used by callers to set forget flag each <n> bytes. */
 

Enumerations

enum  parse_codes {
  PARSE_MORE = MPG123_NEED_MORE, PARSE_ERR = MPG123_ERR, PARSE_END = 10, PARSE_GOOD = 1,
  PARSE_BAD = 0, PARSE_RESYNC = 2, PARSE_AGAIN = 3
}
 

Functions

static int decode_header (mpg123_handle *fr, unsigned long newhead, int *freeformat_count)
 
static int skip_junk (mpg123_handle *fr, unsigned long *newheadp, long *headcount)
 
static int do_readahead (mpg123_handle *fr, unsigned long newhead)
 
static int wetwork (mpg123_handle *fr, unsigned long *newheadp)
 
int frame_bitrate (mpg123_handle *fr)
 
long frame_freq (mpg123_handle *fr)
 
static int head_check (unsigned long head)
 
static unsigned long bit_read_long (unsigned char *buf, int *offset)
 
static unsigned short bit_read_short (unsigned char *buf, int *offset)
 
static int check_lame_tag (mpg123_handle *fr)
 
static int header_mono (unsigned long newhead)
 
static int head_compatible (unsigned long fred, unsigned long bret)
 
static void halfspeed_prepare (mpg123_handle *fr)
 
static int halfspeed_do (mpg123_handle *fr)
 
int read_frame (mpg123_handle *fr)
 
static int guess_freeformat_framesize (mpg123_handle *fr, unsigned long oldhead)
 
void set_pointer (mpg123_handle *fr, long backstep)
 
double compute_bpf (mpg123_handle *fr)
 
int attribute_align_arg mpg123_spf (mpg123_handle *mh)
 
double attribute_align_arg mpg123_tpf (mpg123_handle *fr)
 
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 get_songlen (mpg123_handle *fr, int no)
 
static int handle_id3v2 (mpg123_handle *fr, unsigned long newhead)
 
static int handle_apetag (mpg123_handle *fr, unsigned long newhead)
 
static int forget_head_shift (mpg123_handle *fr, unsigned long *newheadp, int forget)
 

Variables

static const int tabsel_123 [2][3][16]
 
static const long freqs [9] = { 44100, 48000, 32000, 22050, 24000, 16000 , 11025 , 12000 , 8000 }
 

Macro Definition Documentation

◆ bsbufid

#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) ) )

Definition at line 35 of file parse.c.

◆ check_bytes_left

#define check_bytes_left (   n)
Value:
if(fr->framesize < lame_offset+n) \
goto check_lame_tag_yes
GLdouble n
Definition: glext.h:7729

◆ FORGET_INTERVAL

#define FORGET_INTERVAL   1024 /* Used by callers to set forget flag each <n> bytes. */

Definition at line 1120 of file parse.c.

◆ JUMP_CONCLUSION

#define JUMP_CONCLUSION (   ret)
Value:
{ \
if(ret < 0){ debug1("%s", ret == MPG123_NEED_MORE ? "need more" : "read error"); goto read_frame_bad; } \
else if(ret == PARSE_AGAIN) goto read_again; \
else if(ret == PARSE_RESYNC) goto init_resync; \
else if(ret == PARSE_END){ ret=0; goto read_frame_bad; } \
}
int ret
#define debug1(s, a)
Definition: debug.h:52

Definition at line 480 of file parse.c.

◆ TRACK_MAX_FRAMES

#define TRACK_MAX_FRAMES   ULONG_MAX/4/1152

Definition at line 29 of file parse.c.

◆ ULONG_MAX

#define ULONG_MAX   ((unsigned long)-1)

Definition at line 27 of file parse.c.

Enumeration Type Documentation

◆ parse_codes

Enumerator
PARSE_MORE 
PARSE_ERR 
PARSE_END 
PARSE_GOOD 
PARSE_BAD 
PARSE_RESYNC 
PARSE_AGAIN 

Definition at line 38 of file parse.c.

39 {
42  ,PARSE_END = 10 /* No more audio data to find. */
43  ,PARSE_GOOD = 1 /* Everything's fine. */
44  ,PARSE_BAD = 0 /* Not fine (invalid data). */
45  ,PARSE_RESYNC = 2 /* Header not good, go into resync. */
46  ,PARSE_AGAIN = 3 /* Really start over, throw away and read a new header, again. */
47 };

Function Documentation

◆ bit_read_long()

static unsigned long bit_read_long ( unsigned char buf,
int offset 
)
static

Definition at line 112 of file parse.c.

113 {
114  unsigned long val = /* 32 bit value */
115  (((unsigned long) buf[*offset]) << 24)
116  | (((unsigned long) buf[*offset+1]) << 16)
117  | (((unsigned long) buf[*offset+2]) << 8)
118  | ((unsigned long) buf[*offset+3]);
119  *offset += 4;
120  return val;
121 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLintptr offset
Definition: glext.h:5920
GLuint GLfloat * val
Definition: glext.h:7180
#define long
Definition: qsort.c:33

Referenced by check_lame_tag().

◆ bit_read_short()

static unsigned short bit_read_short ( unsigned char buf,
int offset 
)
static

Definition at line 123 of file parse.c.

124 {
125  unsigned short val = /* 16 bit value */
126  (((unsigned short) buf[*offset] ) << 8)
127  | ((unsigned short) buf[*offset+1]);
128  *offset += 2;
129  return val;
130 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLintptr offset
Definition: glext.h:5920
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:93
GLuint GLfloat * val
Definition: glext.h:7180

◆ check_lame_tag()

static int check_lame_tag ( mpg123_handle fr)
static

Definition at line 132 of file parse.c.

133 {
134  int i;
135  unsigned long xing_flags;
136  unsigned long long_tmp;
137  /*
138  going to look for Xing or Info at some position after the header
139  MPEG 1 MPEG 2/2.5 (LSF)
140  Stereo, Joint Stereo, Dual Channel 32 17
141  Mono 17 9
142  */
143  int lame_offset = (fr->stereo == 2)
144  ? (fr->lsf ? 17 : 32)
145  : (fr->lsf ? 9 : 17);
146 
147  if(fr->p.flags & MPG123_IGNORE_INFOFRAME) goto check_lame_tag_no;
148 
149  debug("do we have lame tag?");
150  /*
151  Note: CRC or not, that does not matter here.
152  But, there is any combination of Xing flags in the wild. There are headers
153  without the search index table! I cannot assume a reasonable minimal size
154  for the actual data, have to check if each byte of information is present.
155  But: 4 B Info/Xing + 4 B flags is bare minimum.
156  */
157  if(fr->framesize < lame_offset+8) goto check_lame_tag_no;
158 
159  /* only search for tag when all zero before it (apart from checksum) */
160  for(i=2; i < lame_offset; ++i) if(fr->bsbuf[i] != 0) goto check_lame_tag_no;
161 
162  debug("possibly...");
163  if
164  (
165  (fr->bsbuf[lame_offset] == 'I')
166  && (fr->bsbuf[lame_offset+1] == 'n')
167  && (fr->bsbuf[lame_offset+2] == 'f')
168  && (fr->bsbuf[lame_offset+3] == 'o')
169  )
170  {
171  /* We still have to see what there is */
172  }
173  else if
174  (
175  (fr->bsbuf[lame_offset] == 'X')
176  && (fr->bsbuf[lame_offset+1] == 'i')
177  && (fr->bsbuf[lame_offset+2] == 'n')
178  && (fr->bsbuf[lame_offset+3] == 'g')
179  )
180  {
181  fr->vbr = MPG123_VBR; /* Xing header means always VBR */
182  }
183  else goto check_lame_tag_no;
184 
185  /* we have one of these headers... */
186  if(VERBOSE2) fprintf(stderr, "Note: Xing/Lame/Info header detected\n");
187  lame_offset += 4;
188  xing_flags = bit_read_long(fr->bsbuf, &lame_offset);
189  debug1("Xing: flags 0x%08lx", xing_flags);
190 
191  /* From now on, I have to carefully check if the announced data is actually
192  there! I'm always returning 'yes', though. */
193  #define check_bytes_left(n) if(fr->framesize < lame_offset+n) \
194  goto check_lame_tag_yes
195  if(xing_flags & 1) /* total bitstream frames */
196  {
197  check_bytes_left(4); long_tmp = bit_read_long(fr->bsbuf, &lame_offset);
198  if(fr->p.flags & MPG123_IGNORE_STREAMLENGTH)
199  {
201  , "Note: Ignoring Xing frames because of MPG123_IGNORE_STREAMLENGTH\n");
202  }
203  else
204  {
205  /* Check for endless stream, but: TRACK_MAX_FRAMES sensible at all? */
206  fr->track_frames = long_tmp > TRACK_MAX_FRAMES ? 0 : (off_t) long_tmp;
207 #ifdef GAPLESS
208  /* All or nothing: Only if encoder delay/padding is known, we'll cut
209  samples for gapless. */
210  if(fr->p.flags & MPG123_GAPLESS)
211  frame_gapless_init(fr, fr->track_frames, 0, 0);
212 #endif
213  if(VERBOSE3) fprintf(stderr, "Note: Xing: %lu frames\n", long_tmp);
214  }
215  }
216  if(xing_flags & 0x2) /* total bitstream bytes */
217  {
218  check_bytes_left(4); long_tmp = bit_read_long(fr->bsbuf, &lame_offset);
219  if(fr->p.flags & MPG123_IGNORE_STREAMLENGTH)
220  {
222  , "Note: Ignoring Xing bytes because of MPG123_IGNORE_STREAMLENGTH\n");
223  }
224  else
225  {
226  /* The Xing bitstream length, at least as interpreted by the Lame
227  encoder, encompasses all data from the Xing header frame on,
228  ignoring leading ID3v2 data. Trailing tags (ID3v1) seem to be
229  included, though. */
230  if(fr->rdat.filelen < 1)
231  fr->rdat.filelen = (off_t) long_tmp + fr->audio_start; /* Overflow? */
232  else
233  {
234  if((off_t)long_tmp != fr->rdat.filelen - fr->audio_start && NOQUIET)
235  { /* 1/filelen instead of 1/(filelen-start), my decision */
236  double diff = 100.0/fr->rdat.filelen
237  * ( fr->rdat.filelen - fr->audio_start
238  - (off_t)long_tmp );
239  if(diff < 0.) diff = -diff;
240 
242  , "Note: Xing stream size %lu differs by %f%% from determined/given file size!\n"
243  , long_tmp, diff);
244 
245  if(diff > 1. && NOQUIET) fprintf(stderr
246  , "Warning: Xing stream size off by more than 1%%, fuzzy seeking may be even more fuzzy than by design!\n");
247  }
248  }
249 
250  if(VERBOSE3) fprintf(stderr, "Note: Xing: %lu bytes\n", long_tmp);
251  }
252  }
253  if(xing_flags & 0x4) /* TOC */
254  {
255  check_bytes_left(100);
256  frame_fill_toc(fr, fr->bsbuf+lame_offset);
257  lame_offset += 100;
258  }
259  if(xing_flags & 0x8) /* VBR quality */
260  {
261  check_bytes_left(4); long_tmp = bit_read_long(fr->bsbuf, &lame_offset);
262  if(VERBOSE3) fprintf(stderr, "Note: Xing: quality = %lu\n", long_tmp);
263  }
264  /*
265  Either zeros/nothing, or:
266  0-8: LAME3.90a
267  9: revision/VBR method
268  10: lowpass
269  11-18: ReplayGain
270  19: encoder flags
271  20: ABR
272  21-23: encoder delays
273  */
274  check_bytes_left(24); /* I'm interested in 24 B of extra info. */
275  if(fr->bsbuf[lame_offset] != 0)
276  {
277  unsigned char lame_vbr;
278  float replay_gain[2] = {0,0};
279  float peak = 0;
280  float gain_offset = 0; /* going to be +6 for old lame that used 83dB */
281  char nb[10];
282  off_t pad_in;
283  off_t pad_out;
284  memcpy(nb, fr->bsbuf+lame_offset, 9);
285  nb[9] = 0;
286  if(VERBOSE3) fprintf(stderr, "Note: Info: Encoder: %s\n", nb);
287  if(!strncmp("LAME", nb, 4))
288  {
289  /* Lame versions before 3.95.1 used 83 dB reference level, later
290  versions 89 dB. We stick with 89 dB as being "normal", adding
291  6 dB. */
292  unsigned int major, minor;
293  char rest[6];
294  rest[0] = 0;
295  if(sscanf(nb+4, "%u.%u%s", &major, &minor, rest) >= 2)
296  {
297  debug3("LAME: %u/%u/%s", major, minor, rest);
298  /* We cannot detect LAME 3.95 reliably (same version string as
299  3.95.1), so this is a blind spot. Everything < 3.95 is safe,
300  though. */
301  if(major < 3 || (major == 3 && minor < 95))
302  {
303  gain_offset = 6;
305  , "Note: Info: Old LAME detected, using ReplayGain preamp of %f dB.\n"
306  , gain_offset);
307  }
308  }
309  else if(VERBOSE3) fprintf(stderr
310  , "Note: Info: Cannot determine LAME version.\n");
311  }
312  lame_offset += 9; /* 9 in */
313 
314  /* The 4 big bits are tag revision, the small bits vbr method. */
315  lame_vbr = fr->bsbuf[lame_offset] & 15;
316  lame_offset += 1; /* 10 in */
317  if(VERBOSE3)
318  {
319  fprintf(stderr, "Note: Info: rev %u\n", fr->bsbuf[lame_offset] >> 4);
320  fprintf(stderr, "Note: Info: vbr mode %u\n", lame_vbr);
321  }
322  switch(lame_vbr)
323  {
324  /* from rev1 proposal... not sure if all good in practice */
325  case 1:
326  case 8: fr->vbr = MPG123_CBR; break;
327  case 2:
328  case 9: fr->vbr = MPG123_ABR; break;
329  default: fr->vbr = MPG123_VBR; /* 00==unknown is taken as VBR */
330  }
331  lame_offset += 1; /* 11 in, skipping lowpass filter value */
332 
333  /* ReplayGain peak ampitude, 32 bit float -- why did I parse it as int
334  before?? Ah, yes, Lame seems to store it as int since some day in 2003;
335  I've only seen zeros anyway until now, bah! */
336  if
337  (
338  (fr->bsbuf[lame_offset] != 0)
339  || (fr->bsbuf[lame_offset+1] != 0)
340  || (fr->bsbuf[lame_offset+2] != 0)
341  || (fr->bsbuf[lame_offset+3] != 0)
342  )
343  {
344  debug("Wow! Is there _really_ a non-zero peak value? Now is it stored as float or int - how should I know?");
345  /* byte*peak_bytes = (byte*) &peak;
346  ... endianess ... just copy bytes to avoid floating point operation on unaligned memory?
347  peak_bytes[0] = ...
348  peak = *(float*) (fr->bsbuf+lame_offset); */
349  }
351  , "Note: Info: peak = %f (I won't use this)\n", peak);
352  peak = 0; /* until better times arrived */
353  lame_offset += 4; /* 15 in */
354 
355  /* ReplayGain values - lame only writes radio mode gain...
356  16bit gain, 3 bits name, 3 bits originator, sign (1=-, 0=+),
357  dB value*10 in 9 bits (fixed point) ignore the setting if name or
358  originator == 000!
359  radio 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1
360  audiophile 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0 */
361  for(i =0; i < 2; ++i)
362  {
363  unsigned char gt = fr->bsbuf[lame_offset] >> 5;
364  unsigned char origin = (fr->bsbuf[lame_offset] >> 2) & 0x7;
365  float factor = (fr->bsbuf[lame_offset] & 0x2) ? -0.1f : 0.1f;
366  unsigned short gain = bit_read_short(fr->bsbuf, &lame_offset) & 0x1ff; /* 19 in (2 cycles) */
367  if(origin == 0 || gt < 1 || gt > 2) continue;
368 
369  --gt;
370  replay_gain[gt] = factor * (float) gain;
371  /* Apply gain offset for automatic origin. */
372  if(origin == 3) replay_gain[gt] += gain_offset;
373  }
374  if(VERBOSE3)
375  {
376  fprintf(stderr, "Note: Info: Radio Gain = %03.1fdB\n"
377  , replay_gain[0]);
378  fprintf(stderr, "Note: Info: Audiophile Gain = %03.1fdB\n"
379  , replay_gain[1]);
380  }
381  for(i=0; i < 2; ++i)
382  {
383  if(fr->rva.level[i] <= 0)
384  {
385  fr->rva.peak[i] = 0; /* TODO: use parsed peak? */
386  fr->rva.gain[i] = replay_gain[i];
387  fr->rva.level[i] = 0;
388  }
389  }
390 
391  lame_offset += 1; /* 20 in, skipping encoding flags byte */
392 
393  /* ABR rate */
394  if(fr->vbr == MPG123_ABR)
395  {
396  fr->abr_rate = fr->bsbuf[lame_offset];
397  if(VERBOSE3) fprintf(stderr, "Note: Info: ABR rate = %u\n"
398  , fr->abr_rate);
399  }
400  lame_offset += 1; /* 21 in */
401 
402  /* Encoder delay and padding, two 12 bit values
403  ... lame does write them from int. */
404  pad_in = ( (((int) fr->bsbuf[lame_offset]) << 4)
405  | (((int) fr->bsbuf[lame_offset+1]) >> 4) );
406  pad_out = ( (((int) fr->bsbuf[lame_offset+1]) << 8)
407  | ((int) fr->bsbuf[lame_offset+2]) ) & 0xfff;
408  lame_offset += 3; /* 24 in */
409  if(VERBOSE3) fprintf(stderr, "Note: Encoder delay = %i; padding = %i\n"
410  , (int)pad_in, (int)pad_out);
411  #ifdef GAPLESS
412  if(fr->p.flags & MPG123_GAPLESS)
413  frame_gapless_init(fr, fr->track_frames, pad_in, pad_out);
414  #endif
415  /* final: 24 B LAME data */
416  }
417 
418 check_lame_tag_yes:
419  /* switch buffer back ... */
420  fr->bsbuf = fr->bsspace[fr->bsnum]+512;
421  fr->bsnum = (fr->bsnum + 1) & 1;
422  return 1;
423 check_lame_tag_no:
424  return 0;
425 }
void frame_gapless_init(mpg123_handle *fr, off_t framecount, off_t bskip, off_t eskip)
struct mpg123_pars_struct p
Definition: frame.h:287
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
__kernel_off_t off_t
Definition: linux.h:201
voidpf uLong int origin
Definition: ioapi.h:142
struct reader_data rdat
Definition: frame.h:286
#define debug3(s, a, b, c)
Definition: debug.h:54
static unsigned long bit_read_long(unsigned char *buf, int *offset)
Definition: parse.c:112
off_t track_frames
Definition: frame.h:244
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
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define VERBOSE2
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define off_t
Definition: dosfsck.h:5
#define VERBOSE3
#define frame_fill_toc
Definition: intsym.h:194
GLfloat f
Definition: glext.h:7540
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define NOQUIET
unsigned char bsspace[2][MAXFRAMESIZE+512]
Definition: frame.h:251
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static float(__cdecl *square_half_float)(float x
#define major(rdev)
Definition: propsheet.cpp:916
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
#define TRACK_MAX_FRAMES
Definition: parse.c:29
FILE * stderr
#define minor(rdev)
Definition: propsheet.cpp:917
#define debug(msg)
Definition: key_call.c:71
#define check_bytes_left(n)
#define debug1(s, a)
Definition: debug.h:52
struct mpg123_handle_struct::@3323 rva
static unsigned short bit_read_short(unsigned char *buf, int *offset)
Definition: parse.c:123
enum mpg123_vbr vbr
Definition: frame.h:214
unsigned char * bsbuf
Definition: frame.h:252
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by read_frame().

◆ compute_bpf()

double compute_bpf ( mpg123_handle fr)

Definition at line 890 of file parse.c.

891 {
892  return (fr->framesize > 0) ? fr->framesize + 4.0 : 1.0;
893 }

Referenced by get_songlen(), mpg123_position(), and read_frame().

◆ decode_header()

static int decode_header ( mpg123_handle fr,
unsigned long  newhead,
int freeformat_count 
)
static

Definition at line 738 of file parse.c.

739 {
740 #ifdef DEBUG /* Do not waste cycles checking the header twice all the time. */
741  if(!head_check(newhead))
742  {
743  error1("trying to decode obviously invalid header 0x%08lx", newhead);
744  }
745 #endif
746  /* For some reason, the layer and sampling freq settings used to be wrapped
747  in a weird conditional including MPG123_NO_RESYNC. What was I thinking?
748  This information has to be consistent. */
749  fr->lay = 4 - HDR_LAYER_VAL(newhead);
750 
751  if(HDR_VERSION_VAL(newhead) & 0x2)
752  {
753  fr->lsf = (HDR_VERSION_VAL(newhead) & 0x1) ? 0 : 1;
754  fr->mpeg25 = 0;
755  fr->sampling_frequency = HDR_SAMPLERATE_VAL(newhead) + (fr->lsf*3);
756  }
757  else
758  {
759  fr->lsf = 1;
760  fr->mpeg25 = 1;
761  fr->sampling_frequency = 6 + HDR_SAMPLERATE_VAL(newhead);
762  }
763 
764  #ifdef DEBUG
765  /* seen a file where this varies (old lame tag without crc, track with crc) */
766  if((HDR_CRC_VAL(newhead)^0x1) != fr->error_protection) debug("changed crc bit!");
767  #endif
768  fr->error_protection = HDR_CRC_VAL(newhead)^0x1;
769  fr->bitrate_index = HDR_BITRATE_VAL(newhead);
770  fr->padding = HDR_PADDING_VAL(newhead);
771  fr->extension = HDR_PRIVATE_VAL(newhead);
772  fr->mode = HDR_CHANNEL_VAL(newhead);
773  fr->mode_ext = HDR_CHANEX_VAL(newhead);
774  fr->copyright = HDR_COPYRIGHT_VAL(newhead);
775  fr->original = HDR_ORIGINAL_VAL(newhead);
776  fr->emphasis = HDR_EMPHASIS_VAL(newhead);
777  fr->freeformat = !(newhead & HDR_BITRATE);
778 
779  fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
780 
781  /* we can't use tabsel_123 for freeformat, so trying to guess framesize... */
782  if(fr->freeformat)
783  {
784  /* when we first encounter the frame with freeformat, guess framesize */
785  if(fr->freeformat_framesize < 0)
786  {
787  int ret;
788  *freeformat_count += 1;
789  if(*freeformat_count > 5)
790  {
791  if(VERBOSE3) error("You fooled me too often. Refusing to guess free format frame size _again_.");
792  return PARSE_BAD;
793  }
794  ret = guess_freeformat_framesize(fr, newhead);
795  if(ret == PARSE_GOOD)
796  {
797  fr->freeformat_framesize = fr->framesize - fr->padding;
798  if(VERBOSE2)
799  fprintf(stderr, "Note: free format frame size %li\n", fr->freeformat_framesize);
800  }
801  else
802  {
803  if(ret == MPG123_NEED_MORE)
804  debug("Need more data to guess free format frame size.");
805  else if(VERBOSE3)
806  error("Encountered free format header, but failed to guess frame size.");
807 
808  return ret;
809  }
810  }
811  /* freeformat should be CBR, so the same framesize can be used at the 2nd reading or later */
812  else
813  {
814  fr->framesize = fr->freeformat_framesize + fr->padding;
815  }
816  }
817 
818  switch(fr->lay)
819  {
820 #ifndef NO_LAYER1
821  case 1:
822  fr->spf = 384;
823  fr->do_layer = do_layer1;
824  if(!fr->freeformat)
825  {
826  fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
827  fr->framesize /= freqs[fr->sampling_frequency];
828  fr->framesize = ((fr->framesize+fr->padding)<<2)-4;
829  }
830  break;
831 #endif
832 #ifndef NO_LAYER2
833  case 2:
834  fr->spf = 1152;
835  fr->do_layer = do_layer2;
836  if(!fr->freeformat)
837  {
838  debug2("bitrate index: %i (%i)", fr->bitrate_index, tabsel_123[fr->lsf][1][fr->bitrate_index] );
839  fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
840  fr->framesize /= freqs[fr->sampling_frequency];
841  fr->framesize += fr->padding - 4;
842  }
843  break;
844 #endif
845 #ifndef NO_LAYER3
846  case 3:
847  fr->spf = fr->lsf ? 576 : 1152; /* MPEG 2.5 implies LSF.*/
848  fr->do_layer = do_layer3;
849  if(fr->lsf)
850  fr->ssize = (fr->stereo == 1) ? 9 : 17;
851  else
852  fr->ssize = (fr->stereo == 1) ? 17 : 32;
853 
854  if(fr->error_protection)
855  fr->ssize += 2;
856 
857  if(!fr->freeformat)
858  {
859  fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
860  fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf);
861  fr->framesize = fr->framesize + fr->padding - 4;
862  }
863  break;
864 #endif
865  default:
866  if(NOQUIET) error1("Layer type %i not supported in this build!", fr->lay);
867 
868  return PARSE_BAD;
869  }
870  if (fr->framesize > MAXFRAMESIZE)
871  {
872  if(NOQUIET) error1("Frame size too big: %d", fr->framesize+4-fr->padding);
873 
874  return PARSE_BAD;
875  }
876  return PARSE_GOOD;
877 }
#define HDR_EMPHASIS_VAL(h)
Definition: mpeghead.h:69
#define error(str)
Definition: mkdosfs.c:1605
#define do_layer3
Definition: intsym.h:161
long freeformat_framesize
Definition: frame.h:223
#define error1(s, a)
Definition: debug.h:109
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
#define HDR_PADDING_VAL(h)
Definition: mpeghead.h:51
#define do_layer2
Definition: intsym.h:162
#define debug2(s, a, b)
Definition: debug.h:53
#define HDR_ORIGINAL_VAL(h)
Definition: mpeghead.h:66
#define HDR_VERSION_VAL(h)
Definition: mpeghead.h:36
#define MPG_MD_MONO
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define HDR_SAMPLERATE_VAL(h)
Definition: mpeghead.h:48
int sampling_frequency
Definition: frame.h:204
#define VERBOSE2
#define HDR_LAYER_VAL(h)
Definition: mpeghead.h:39
#define VERBOSE3
#define HDR_CHANEX_VAL(h)
Definition: mpeghead.h:60
int(* do_layer)(mpg123_handle *)
Definition: frame.h:201
#define MAXFRAMESIZE
Definition: frame.h:30
#define NOQUIET
int ret
static int guess_freeformat_framesize(mpg123_handle *fr, unsigned long oldhead)
Definition: parse.c:697
static const int tabsel_123[2][3][16]
Definition: parse.c:50
#define long
Definition: qsort.c:33
#define do_layer1
Definition: intsym.h:163
#define HDR_BITRATE
Definition: mpeghead.h:44
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
#define HDR_CHANNEL_VAL(h)
Definition: mpeghead.h:57
static const long freqs[9]
Definition: parse.c:64
FILE * stderr
#define HDR_BITRATE_VAL(h)
Definition: mpeghead.h:45
#define debug(msg)
Definition: key_call.c:71
static int head_check(unsigned long head)
Definition: parse.c:85
#define HDR_CRC_VAL(h)
Definition: mpeghead.h:42
#define HDR_PRIVATE_VAL(h)
Definition: mpeghead.h:54
#define HDR_COPYRIGHT_VAL(h)
Definition: mpeghead.h:63

Referenced by read_frame(), and skip_junk().

◆ do_readahead()

static int do_readahead ( mpg123_handle fr,
unsigned long  newhead 
)
static

Definition at line 993 of file parse.c.

994 {
995  unsigned long nexthead = 0;
996  int hd = 0;
997  off_t start, oret;
998  int ret;
999 
1000  if( ! (!fr->firsthead && fr->rdat.flags & (READER_SEEKABLE|READER_BUFFERED)) )
1001  return PARSE_GOOD;
1002 
1003  start = fr->rd->tell(fr);
1004 
1005  debug2("doing ahead check with BPF %d at %"OFF_P, fr->framesize+4, (off_p)start);
1006  /* step framesize bytes forward and read next possible header*/
1007  if((oret=fr->rd->skip_bytes(fr, fr->framesize))<0)
1008  {
1009  if(oret==READER_ERROR && NOQUIET) error("cannot seek!");
1010 
1011  return oret == MPG123_NEED_MORE ? PARSE_MORE : PARSE_ERR;
1012  }
1013 
1014  /* Read header, seek back. */
1015  hd = fr->rd->head_read(fr,&nexthead);
1016  if( fr->rd->back_bytes(fr, fr->rd->tell(fr)-start) < 0 )
1017  {
1018  if(NOQUIET) error("Cannot seek back!");
1019 
1020  return PARSE_ERR;
1021  }
1022  if(hd == MPG123_NEED_MORE) return PARSE_MORE;
1023 
1024  debug1("After fetching next header, at %"OFF_P, (off_p)fr->rd->tell(fr));
1025  if(!hd)
1026  {
1027  if(NOQUIET) warning("Cannot read next header, a one-frame stream? Duh...");
1028  return PARSE_END;
1029  }
1030 
1031  debug2("does next header 0x%08lx match first 0x%08lx?", nexthead, newhead);
1032  if(!head_check(nexthead) || !head_compatible(newhead, nexthead))
1033  {
1034  debug("No, the header was not valid, start from beginning...");
1035  fr->oldhead = 0; /* start over */
1036  /* try next byte for valid header */
1037  if((ret=fr->rd->back_bytes(fr, 3))<0)
1038  {
1039  if(NOQUIET) error("Cannot seek 3 bytes back!");
1040 
1041  return PARSE_ERR;
1042  }
1043  return PARSE_AGAIN;
1044  }
1045  else return PARSE_GOOD;
1046 }
#define READER_SEEKABLE
Definition: reader.h:115
#define error(str)
Definition: mkdosfs.c:1605
__kernel_off_t off_t
Definition: linux.h:201
#define debug2(s, a, b)
Definition: debug.h:53
struct reader_data rdat
Definition: frame.h:286
#define READER_ERROR
Definition: reader.h:134
static int head_compatible(unsigned long fred, unsigned long bret)
Definition: parse.c:434
#define NOQUIET
int ret
#define READER_BUFFERED
Definition: reader.h:116
unsigned long firsthead
Definition: frame.h:258
GLuint start
Definition: gl.h:1545
long off_p
Definition: compat.h:130
#define debug(msg)
Definition: key_call.c:71
struct reader * rd
Definition: frame.h:285
#define debug1(s, a)
Definition: debug.h:52
static int head_check(unsigned long head)
Definition: parse.c:85
unsigned long oldhead
Definition: frame.h:256
#define OFF_P
Definition: compat.h:129
#define warning(s)
Definition: debug.h:71

Referenced by jread(), and read_frame().

◆ forget_head_shift()

static int forget_head_shift ( mpg123_handle fr,
unsigned long newheadp,
int  forget 
)
static

Definition at line 1121 of file parse.c.

1122 {
1123  int ret;
1124  if((ret=fr->rd->head_shift(fr,newheadp))<=0) return ret;
1125  /* Try to forget buffered data as early as possible to speed up parsing where
1126  new data needs to be added for resync (and things would be re-parsed again
1127  and again because of the start from beginning after hitting end). */
1128  if(forget && fr->rd->forget != NULL)
1129  {
1130  /* Ensure that the last 4 bytes stay in buffers for reading the header
1131  anew. */
1132  if(!fr->rd->back_bytes(fr, 4))
1133  {
1134  fr->rd->forget(fr);
1135  fr->rd->back_bytes(fr, -4);
1136  }
1137  }
1138  return ret; /* No surprise here, error already triggered early return. */
1139 }
smooth NULL
Definition: ftsmooth.c:416
int ret
struct reader * rd
Definition: frame.h:285

Referenced by skip_junk(), and wetwork().

◆ frame_bitrate()

int frame_bitrate ( mpg123_handle fr)

Definition at line 74 of file parse.c.

75 {
76  return tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
77 }
static const int tabsel_123[2][3][16]
Definition: parse.c:50

◆ frame_freq()

long frame_freq ( mpg123_handle fr)

Definition at line 79 of file parse.c.

80 {
81  return freqs[fr->sampling_frequency];
82 }
int sampling_frequency
Definition: frame.h:204
static const long freqs[9]
Definition: parse.c:64

◆ get_songlen()

int get_songlen ( mpg123_handle fr,
int  no 
)

Definition at line 975 of file parse.c.

976 {
977  double tpf;
978 
979  if(!fr)
980  return 0;
981 
982  if(no < 0) {
983  if(!fr->rd || fr->rdat.filelen < 0)
984  return 0;
985  no = (int) ((double) fr->rdat.filelen / compute_bpf(fr));
986  }
987 
988  tpf = mpg123_tpf(fr);
989  return (int) (no*tpf);
990 }
double compute_bpf(mpg123_handle *fr)
Definition: parse.c:890
struct reader_data rdat
Definition: frame.h:286
double attribute_align_arg mpg123_tpf(mpg123_handle *fr)
Definition: parse.c:902
static WCHAR no[MAX_STRING_RESOURCE_LEN]
Definition: object.c:2340
struct reader * rd
Definition: frame.h:285
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

◆ guess_freeformat_framesize()

static int guess_freeformat_framesize ( mpg123_handle fr,
unsigned long  oldhead 
)
static

Definition at line 697 of file parse.c.

698 {
699  long i;
700  int ret;
701  unsigned long head;
702  if(!(fr->rdat.flags & (READER_SEEKABLE|READER_BUFFERED)))
703  {
704  if(NOQUIET) error("Cannot look for freeformat frame size with non-seekable and non-buffered stream!");
705 
706  return PARSE_BAD;
707  }
708  if((ret=fr->rd->head_read(fr,&head))<=0)
709  return ret;
710 
711  /* We are already 4 bytes into it */
712  for(i=4;i<MAXFRAMESIZE+4;i++)
713  {
714  if((ret=fr->rd->head_shift(fr,&head))<=0) return ret;
715 
716  /* No head_check needed, the mask contains all relevant bits. */
717  if((head & HDR_SAMEMASK) == (oldhead & HDR_SAMEMASK))
718  {
719  fr->rd->back_bytes(fr,i+1);
720  fr->framesize = i-3;
721  return PARSE_GOOD; /* Success! */
722  }
723  }
724  fr->rd->back_bytes(fr,i);
725  return PARSE_BAD;
726 }
#define READER_SEEKABLE
Definition: reader.h:115
#define error(str)
Definition: mkdosfs.c:1605
struct outqueuenode * head
Definition: adnsresfilter.c:66
struct reader_data rdat
Definition: frame.h:286
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
Definition: glfuncs.h:248
#define MAXFRAMESIZE
Definition: frame.h:30
#define NOQUIET
int ret
#define READER_BUFFERED
Definition: reader.h:116
#define HDR_SAMEMASK
Definition: mpeghead.h:81
struct reader * rd
Definition: frame.h:285

Referenced by decode_header().

◆ halfspeed_do()

static int halfspeed_do ( mpg123_handle fr)
static

Definition at line 451 of file parse.c.

452 {
453  /* Speed-down hack: Play it again, Sam (the frame, I mean). */
454  if (fr->p.halfspeed)
455  {
456  if(fr->halfphase) /* repeat last frame */
457  {
458  debug("repeat!");
459  fr->to_decode = fr->to_ignore = TRUE;
460  --fr->halfphase;
461  fr->bitindex = 0;
462  fr->wordpointer = (unsigned char *) fr->bsbuf;
463  if(fr->lay == 3) memcpy (fr->bsbuf, fr->ssave, fr->ssize);
464  if(fr->error_protection) fr->crc = getbits(fr, 16); /* skip crc */
465  return 1;
466  }
467  else
468  {
469  fr->halfphase = fr->p.halfspeed - 1;
470  }
471  }
472  return 0;
473 }
#define TRUE
Definition: types.h:120
struct mpg123_pars_struct p
Definition: frame.h:287
unsigned char * wordpointer
Definition: frame.h:227
unsigned int crc
Definition: frame.h:284
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define debug(msg)
Definition: key_call.c:71
unsigned char ssave[34]
Definition: frame.h:129
#define getbits
Definition: intsym.h:195
unsigned char * bsbuf
Definition: frame.h:252

Referenced by read_frame().

◆ halfspeed_prepare()

static void halfspeed_prepare ( mpg123_handle fr)
static

Definition at line 440 of file parse.c.

441 {
442  /* save for repetition */
443  if(fr->p.halfspeed && fr->lay == 3)
444  {
445  debug("halfspeed - reusing old bsbuf ");
446  memcpy (fr->ssave, fr->bsbuf, fr->ssize);
447  }
448 }
struct mpg123_pars_struct p
Definition: frame.h:287
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define debug(msg)
Definition: key_call.c:71
unsigned char ssave[34]
Definition: frame.h:129
unsigned char * bsbuf
Definition: frame.h:252

Referenced by read_frame().

◆ handle_apetag()

static int handle_apetag ( mpg123_handle fr,
unsigned long  newhead 
)
static

Definition at line 1061 of file parse.c.

1062 {
1063  unsigned char apebuf[28];
1064  unsigned long val;
1065  int i, ret;
1066  /* How many bytes to backpedal to get back to just after the first byte of */
1067  /* the supposed header. */
1068  int back_bytes = 3;
1069  fr->oldhead = 0;
1070 
1071  debug1("trying to read remaining APE header at %"OFF_P, (off_p)fr->rd->tell(fr));
1072  /* Apetag headers are 32 bytes, newhead contains 4, read the rest */
1073  if((ret=fr->rd->fullread(fr,apebuf,28)) < 0)
1074  return ret;
1075  back_bytes += ret;
1076  if(ret < 28)
1077  goto apetag_bad;
1078 
1079  debug1("trying to parse APE header at %"OFF_P, (off_p)fr->rd->tell(fr));
1080  /* Apetags start with "APETAGEX", "APET" is already tested. */
1081  if(strncmp((char *)apebuf,"AGEX",4) != 0)
1082  goto apetag_bad;
1083 
1084  /* Version must be 2.000 / 2000 */
1085  val = ((unsigned long)apebuf[7]<<24)
1086  | ((unsigned long)apebuf[6]<<16)
1087  | ((unsigned long)apebuf[5]<<8)
1088  | apebuf[4];
1089  if(val != 2000)
1090  goto apetag_bad;
1091 
1092  /* Last 8 bytes must be 0 */
1093  for(i=20; i<28; i++)
1094  if(apebuf[i])
1095  goto apetag_bad;
1096 
1097  /* Looks good, skip the rest. */
1098  val = ((unsigned long)apebuf[11]<<24)
1099  | ((unsigned long)apebuf[10]<<16)
1100  | ((unsigned long)apebuf[9]<<8)
1101  | apebuf[8];
1102  debug2( "skipping %lu bytes of APE data at %"OFF_P
1103  , val, (off_p)fr->rd->tell(fr) );
1104  /* If encountering EOF here, things are just at an end. */
1105  if((ret=fr->rd->skip_bytes(fr,val)) < 0)
1106  return ret;
1107 
1108  return PARSE_AGAIN;
1109 
1110 apetag_bad:
1111  debug("no proper APE tag found, seeking back");
1112  if(fr->rd->back_bytes(fr,back_bytes) < 0 && NOQUIET)
1113  error1("Cannot seek %d bytes back!", back_bytes);
1114 
1115  return PARSE_AGAIN; /* Give the resync code a chance to fix things */
1116 }
#define error1(s, a)
Definition: debug.h:109
#define debug2(s, a, b)
Definition: debug.h:53
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
Definition: glfuncs.h:248
GLuint GLfloat * val
Definition: glext.h:7180
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define NOQUIET
int ret
#define long
Definition: qsort.c:33
long off_p
Definition: compat.h:130
#define debug(msg)
Definition: key_call.c:71
struct reader * rd
Definition: frame.h:285
#define debug1(s, a)
Definition: debug.h:52
unsigned long oldhead
Definition: frame.h:256
#define OFF_P
Definition: compat.h:129

Referenced by wetwork().

◆ handle_id3v2()

static int handle_id3v2 ( mpg123_handle fr,
unsigned long  newhead 
)
static

Definition at line 1048 of file parse.c.

1049 {
1050  int ret;
1051  fr->oldhead = 0; /* Think about that. Used to be present only for skipping of junk, not resync-style wetwork. */
1052  ret = parse_new_id3(fr, newhead);
1053  if (ret < 0) return ret;
1054 #ifndef NO_ID3V2
1055  else if(ret > 0){ debug("got ID3v2"); fr->metaflags |= MPG123_NEW_ID3|MPG123_ID3; }
1056  else debug("no useful ID3v2");
1057 #endif
1058  return PARSE_AGAIN;
1059 }
#define MPG123_NEW_ID3
Definition: mpg123.h:1241
#define MPG123_ID3
Definition: mpg123.h:1240
int ret
#define parse_new_id3
Definition: intsym.h:205
#define debug(msg)
Definition: key_call.c:71
unsigned long oldhead
Definition: frame.h:256

Referenced by skip_junk(), and wetwork().

◆ head_check()

static int head_check ( unsigned long  head)
static

Definition at line 85 of file parse.c.

86 {
87  if
88  (
89  ((head & HDR_SYNC) != HDR_SYNC)
90  ||
91  /* layer: 01,10,11 is 1,2,3; 00 is reserved */
92  (!(HDR_LAYER_VAL(head)))
93  ||
94  /* 1111 means bad bitrate */
95  (HDR_BITRATE_VAL(head) == 0xf)
96  ||
97  /* sampling freq: 11 is reserved */
98  (HDR_SAMPLERATE_VAL(head) == 0x3)
99  /* here used to be a mpeg 2.5 check... re-enabled 2.5 decoding due to lack of evidence that it is really not good */
100  )
101  {
102  return FALSE;
103  }
104  /* if no check failed, the header is valid (hopefully)*/
105  else
106  {
107  return TRUE;
108  }
109 }
#define TRUE
Definition: types.h:120
struct outqueuenode * head
Definition: adnsresfilter.c:66
#define HDR_SAMPLERATE_VAL(h)
Definition: mpeghead.h:48
#define HDR_LAYER_VAL(h)
Definition: mpeghead.h:39
#define HDR_SYNC
Definition: mpeghead.h:32
#define HDR_BITRATE_VAL(h)
Definition: mpeghead.h:45

Referenced by decode_header(), do_readahead(), read_frame(), skip_junk(), and wetwork().

◆ head_compatible()

static int head_compatible ( unsigned long  fred,
unsigned long  bret 
)
static

Definition at line 434 of file parse.c.

435 {
436  return ( (fred & HDR_CMPMASK) == (bret & HDR_CMPMASK)
437  && header_mono(fred) == header_mono(bret) );
438 }
static int header_mono(unsigned long newhead)
Definition: parse.c:428
#define HDR_CMPMASK
Definition: mpeghead.h:78

Referenced by do_readahead(), and read_frame().

◆ header_mono()

static int header_mono ( unsigned long  newhead)
static

Definition at line 428 of file parse.c.

429 {
430  return HDR_CHANNEL_VAL(newhead) == MPG_MD_MONO ? TRUE : FALSE;
431 }
#define TRUE
Definition: types.h:120
#define MPG_MD_MONO
#define HDR_CHANNEL_VAL(h)
Definition: mpeghead.h:57

Referenced by head_compatible().

◆ read_frame()

int read_frame ( mpg123_handle fr)

Definition at line 492 of file parse.c.

493 {
494  /* TODO: rework this thing */
495  int freeformat_count = 0;
496  unsigned long newhead;
497  off_t framepos;
498  int ret;
499  /* stuff that needs resetting if complete frame reading fails */
500  int oldsize = fr->framesize;
501  int oldphase = fr->halfphase;
502 
503  /* The counter for the search-first-header loop.
504  It is persistent outside the loop to prevent seemingly endless loops
505  when repeatedly headers are found that do not have valid followup headers. */
506  long headcount = 0;
507 
508  fr->fsizeold=fr->framesize; /* for Layer3 */
509 
510  if(halfspeed_do(fr) == 1) return 1;
511 
512 read_again:
513  /* In case we are looping to find a valid frame, discard any buffered data before the current position.
514  This is essential to prevent endless looping, always going back to the beginning when feeder buffer is exhausted. */
515  if(fr->rd->forget != NULL) fr->rd->forget(fr);
516 
517  debug2("trying to get frame %"OFF_P" at %"OFF_P, (off_p)fr->num+1, (off_p)fr->rd->tell(fr));
518  if((ret = fr->rd->head_read(fr,&newhead)) <= 0){ debug1("need more? (%i)", ret); goto read_frame_bad;}
519 
520 init_resync:
521 
522 #ifdef SKIP_JUNK
523  if(!fr->firsthead && !head_check(newhead))
524  {
525  ret = skip_junk(fr, &newhead, &headcount);
527  }
528 #endif
529 
530  ret = head_check(newhead);
531  if(ret) ret = decode_header(fr, newhead, &freeformat_count);
532 
533  JUMP_CONCLUSION(ret); /* That only continues for ret == PARSE_BAD or PARSE_GOOD. */
534  if(ret == PARSE_BAD)
535  { /* Header was not good. */
536  ret = wetwork(fr, &newhead); /* Messy stuff, handle junk, resync ... */
538  /* Normally, we jumped already. If for some reason everything's fine to continue, do continue. */
539  if(ret != PARSE_GOOD) goto read_frame_bad;
540  }
541 
542  if(!fr->firsthead)
543  {
544  ret = do_readahead(fr, newhead);
545  /* readahead can fail mit NEED_MORE, in which case we must also make the just read header available again for next go */
546  if(ret < 0) fr->rd->back_bytes(fr, 4);
548  }
549 
550  /* Now we should have our valid header and proceed to reading the frame. */
551 
552  /* if filepos is invalid, so is framepos */
553  framepos = fr->rd->tell(fr) - 4;
554  /* flip/init buffer for Layer 3 */
555  {
556  unsigned char *newbuf = fr->bsspace[fr->bsnum]+512;
557  /* read main data into memory */
558  if((ret=fr->rd->read_frame_body(fr,newbuf,fr->framesize))<0)
559  {
560  /* if failed: flip back */
561  debug("need more?");
562  goto read_frame_bad;
563  }
564  fr->bsbufold = fr->bsbuf;
565  fr->bsbuf = newbuf;
566  }
567  fr->bsnum = (fr->bsnum + 1) & 1;
568 
569  if(!fr->firsthead)
570  {
571  fr->firsthead = newhead; /* _now_ it's time to store it... the first real header */
572  /* This is the first header of our current stream segment.
573  It is only the actual first header of the whole stream when fr->num is still below zero!
574  Think of resyncs where firsthead has been reset for format flexibility. */
575  if(fr->num < 0)
576  {
577  fr->audio_start = framepos;
578  /* Only check for LAME tag at beginning of whole stream
579  ... when there indeed is one in between, it's the user's problem. */
580  if(fr->lay == 3 && check_lame_tag(fr) == 1)
581  { /* ...in practice, Xing/LAME tags are layer 3 only. */
582  if(fr->rd->forget != NULL) fr->rd->forget(fr);
583 
584  fr->oldhead = 0;
585  goto read_again;
586  }
587  /* now adjust volume */
588  do_rva(fr);
589  }
590 
591  debug2("fr->firsthead: %08lx, audio_start: %li", fr->firsthead, (long int)fr->audio_start);
592  }
593 
594  fr->bitindex = 0;
595  fr->wordpointer = (unsigned char *) fr->bsbuf;
596  /* Question: How bad does the floating point value get with repeated recomputation?
597  Also, considering that we can play the file or parts of many times. */
598  if(++fr->mean_frames != 0)
599  {
600  fr->mean_framesize = ((fr->mean_frames-1)*fr->mean_framesize+compute_bpf(fr)) / fr->mean_frames ;
601  }
602  ++fr->num; /* 0 for first frame! */
603  debug4("Frame %"OFF_P" %08lx %i, next filepos=%"OFF_P,
604  (off_p)fr->num, newhead, fr->framesize, (off_p)fr->rd->tell(fr));
605  if(!(fr->state_flags & FRAME_FRANKENSTEIN) && (
606  (fr->track_frames > 0 && fr->num >= fr->track_frames)
607 #ifdef GAPLESS
608  || (fr->gapless_frames > 0 && fr->num >= fr->gapless_frames)
609 #endif
610  ))
611  {
613  if(NOQUIET) fprintf(stderr, "\nWarning: Encountered more data after announced end of track (frame %"OFF_P"/%"OFF_P"). Frankenstein!\n", (off_p)fr->num,
614 #ifdef GAPLESS
615  fr->gapless_frames > 0 ? (off_p)fr->gapless_frames :
616 #endif
617  (off_p)fr->track_frames);
618  }
619 
620  halfspeed_prepare(fr);
621 
622  /* index the position */
623  fr->input_offset = framepos;
624 #ifdef FRAME_INDEX
625  /* Keep track of true frame positions in our frame index.
626  but only do so when we are sure that the frame number is accurate... */
627  if((fr->state_flags & FRAME_ACCURATE) && FI_NEXT(fr->index, fr->num))
628  fi_add(&fr->index, framepos);
629 #endif
630 
631  if(fr->silent_resync > 0) --fr->silent_resync;
632 
633  if(fr->rd->forget != NULL) fr->rd->forget(fr);
634 
635  fr->to_decode = fr->to_ignore = TRUE;
636  if(fr->error_protection) fr->crc = getbits(fr, 16); /* skip crc */
637 
638  /*
639  Let's check for header change after deciding that the new one is good
640  and actually having read a frame.
641 
642  header_change > 1: decoder structure has to be updated
643  Preserve header_change value from previous runs if it is serious.
644  If we still have a big change pending, it should be dealt with outside,
645  fr->header_change set to zero afterwards.
646  */
647  if(fr->header_change < 2)
648  {
649  fr->header_change = 2; /* output format change is possible... */
650  if(fr->oldhead) /* check a following header for change */
651  {
652  if(fr->oldhead == newhead) fr->header_change = 0;
653  else
654  /* Headers that match in this test behave the same for the outside world.
655  namely: same decoding routines, same amount of decoded data. */
656  if(head_compatible(fr->oldhead, newhead))
657  fr->header_change = 1;
658  else
659  {
661  if(NOQUIET)
662  fprintf(stderr, "\nWarning: Big change (MPEG version, layer, rate). Frankenstein stream?\n");
663  }
664  }
665  else if(fr->firsthead && !head_compatible(fr->firsthead, newhead))
666  {
668  if(NOQUIET)
669  fprintf(stderr, "\nWarning: Big change from first (MPEG version, layer, rate). Frankenstein stream?\n");
670  }
671  }
672 
673  fr->oldhead = newhead;
674 
675  return 1;
676 read_frame_bad:
677  /* Also if we searched for valid data in vein, we can forget skipped data.
678  Otherwise, the feeder would hold every dead old byte in memory until the first valid frame! */
679  if(fr->rd->forget != NULL) fr->rd->forget(fr);
680 
681  fr->silent_resync = 0;
682  if(fr->err == MPG123_OK) fr->err = MPG123_ERR_READER;
683  fr->framesize = oldsize;
684  fr->halfphase = oldphase;
685  /* That return code might be inherited from some feeder action, or reader error. */
686  return ret;
687 }
#define JUMP_CONCLUSION(ret)
Definition: parse.c:480
#define TRUE
Definition: types.h:120
static int decode_header(mpg123_handle *fr, unsigned long newhead, int *freeformat_count)
Definition: parse.c:738
unsigned char * bsbufold
Definition: frame.h:253
__kernel_off_t off_t
Definition: linux.h:201
double mean_framesize
Definition: frame.h:246
#define debug4(s, a, b, c, d)
Definition: debug.h:55
unsigned char * wordpointer
Definition: frame.h:227
double compute_bpf(mpg123_handle *fr)
Definition: parse.c:890
#define debug2(s, a, b)
Definition: debug.h:53
off_t input_offset
Definition: frame.h:216
#define GAPLESS
Definition: config.h:45
off_t track_frames
Definition: frame.h:244
static int skip_junk(mpg123_handle *fr, unsigned long *newheadp, long *headcount)
Definition: parse.c:1142
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
static int head_compatible(unsigned long fred, unsigned long bret)
Definition: parse.c:434
#define fi_add
Definition: intsym.h:210
unsigned int crc
Definition: frame.h:284
off_t gapless_frames
Definition: frame.h:275
#define NOQUIET
unsigned char bsspace[2][MAXFRAMESIZE+512]
Definition: frame.h:251
int ret
static int do_readahead(mpg123_handle *fr, unsigned long newhead)
Definition: parse.c:993
static void halfspeed_prepare(mpg123_handle *fr)
Definition: parse.c:440
unsigned long firsthead
Definition: frame.h:258
static int halfspeed_do(mpg123_handle *fr)
Definition: parse.c:451
static int wetwork(mpg123_handle *fr, unsigned long *newheadp)
Definition: parse.c:1215
struct frame_index index
Definition: frame.h:261
static int check_lame_tag(mpg123_handle *fr)
Definition: parse.c:132
long off_p
Definition: compat.h:130
FILE * stderr
#define debug(msg)
Definition: key_call.c:71
struct reader * rd
Definition: frame.h:285
#define do_rva
Definition: intsym.h:179
#define debug1(s, a)
Definition: debug.h:52
static int head_check(unsigned long head)
Definition: parse.c:85
unsigned long oldhead
Definition: frame.h:256
#define OFF_P
Definition: compat.h:129
#define getbits
Definition: intsym.h:195
unsigned char * bsbuf
Definition: frame.h:252
#define FI_NEXT(fi, framenum)
Definition: index.h:38

◆ set_pointer()

void set_pointer ( mpg123_handle fr,
long  backstep 
)

Definition at line 879 of file parse.c.

880 {
881  fr->wordpointer = fr->bsbuf + fr->ssize - backstep;
882  if (backstep)
883  memcpy(fr->wordpointer,fr->bsbufold+fr->fsizeold-backstep,backstep);
884 
885  fr->bitindex = 0;
886 }
unsigned char * bsbufold
Definition: frame.h:253
unsigned char * wordpointer
Definition: frame.h:227
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char * bsbuf
Definition: frame.h:252

◆ skip_junk()

static int skip_junk ( mpg123_handle fr,
unsigned long newheadp,
long headcount 
)
static

Definition at line 1142 of file parse.c.

1143 {
1144  int ret;
1145  int freeformat_count = 0;
1146  long limit = 65536;
1147  unsigned long newhead = *newheadp;
1148  unsigned int forgetcount = 0;
1149  /* check for id3v2; first three bytes (of 4) are "ID3" */
1150  if((newhead & (unsigned long) 0xffffff00) == (unsigned long) 0x49443300)
1151  {
1152  return handle_id3v2(fr, newhead);
1153  }
1154  else if(VERBOSE2 && fr->silent_resync == 0) fprintf(stderr,"Note: Junk at the beginning (0x%08lx)\n",newhead);
1155 
1156  /* I even saw RIFF headers at the beginning of MPEG streams ;( */
1157  if(newhead == ('R'<<24)+('I'<<16)+('F'<<8)+'F')
1158  {
1159  if(VERBOSE2 && fr->silent_resync == 0) fprintf(stderr, "Note: Looks like a RIFF header.\n");
1160 
1161  if((ret=fr->rd->head_read(fr,&newhead))<=0) return ret;
1162 
1163  while(newhead != ('d'<<24)+('a'<<16)+('t'<<8)+'a')
1164  {
1165  if(++forgetcount > FORGET_INTERVAL) forgetcount = 0;
1166  if((ret=forget_head_shift(fr,&newhead,!forgetcount))<=0) return ret;
1167  }
1168  if((ret=fr->rd->head_read(fr,&newhead))<=0) return ret;
1169 
1170  if(VERBOSE2 && fr->silent_resync == 0) fprintf(stderr,"Note: Skipped RIFF header!\n");
1171 
1172  fr->oldhead = 0;
1173  *newheadp = newhead;
1174  return PARSE_AGAIN;
1175  }
1176 
1177  /*
1178  Unhandled junk... just continue search for a header, stepping in single bytes through next 64K.
1179  This is rather identical to the resync loop.
1180  */
1181  debug("searching for header...");
1182  *newheadp = 0; /* Invalidate the external value. */
1183  ret = 0; /* We will check the value after the loop. */
1184 
1185  /* We prepare for at least the 64K bytes as usual, unless
1186  user explicitly wanted more (even infinity). Never less. */
1187  if(fr->p.resync_limit < 0 || fr->p.resync_limit > limit)
1188  limit = fr->p.resync_limit;
1189 
1190  do
1191  {
1192  ++(*headcount);
1193  if(limit >= 0 && *headcount >= limit) break;
1194 
1195  if(++forgetcount > FORGET_INTERVAL) forgetcount = 0;
1196  if((ret=forget_head_shift(fr, &newhead, !forgetcount))<=0) return ret;
1197 
1198  if(head_check(newhead) && (ret=decode_header(fr, newhead, &freeformat_count))) break;
1199  } while(1);
1200  if(ret<0) return ret;
1201 
1202  if(limit >= 0 && *headcount >= limit)
1203  {
1204  if(NOQUIET) error1("Giving up searching valid MPEG header after %li bytes of junk.", *headcount);
1205  return PARSE_END;
1206  }
1207  else debug1("hopefully found one at %"OFF_P, (off_p)fr->rd->tell(fr));
1208 
1209  /* If the new header ist good, it is already decoded. */
1210  *newheadp = newhead;
1211  return PARSE_GOOD;
1212 }
static int forget_head_shift(mpg123_handle *fr, unsigned long *newheadp, int forget)
Definition: parse.c:1121
struct mpg123_pars_struct p
Definition: frame.h:287
static int decode_header(mpg123_handle *fr, unsigned long newhead, int *freeformat_count)
Definition: parse.c:738
#define error1(s, a)
Definition: debug.h:109
#define FORGET_INTERVAL
Definition: parse.c:1120
GLint limit
Definition: glext.h:10326
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define VERBOSE2
#define NOQUIET
int ret
static int handle_id3v2(mpg123_handle *fr, unsigned long newhead)
Definition: parse.c:1048
long off_p
Definition: compat.h:130
FILE * stderr
#define debug(msg)
Definition: key_call.c:71
struct reader * rd
Definition: frame.h:285
#define debug1(s, a)
Definition: debug.h:52
static int head_check(unsigned long head)
Definition: parse.c:85
unsigned long oldhead
Definition: frame.h:256
#define OFF_P
Definition: compat.h:129

Referenced by read_frame().

◆ wetwork()

static int wetwork ( mpg123_handle fr,
unsigned long newheadp 
)
static

Definition at line 1215 of file parse.c.

1216 {
1217  int ret = PARSE_ERR;
1218  unsigned long newhead = *newheadp;
1219  *newheadp = 0;
1220 
1221  /* Classic ID3 tags. Read, then start parsing again. */
1222  if((newhead & 0xffffff00) == ('T'<<24)+('A'<<16)+('G'<<8))
1223  {
1224  fr->id3buf[0] = (unsigned char) ((newhead >> 24) & 0xff);
1225  fr->id3buf[1] = (unsigned char) ((newhead >> 16) & 0xff);
1226  fr->id3buf[2] = (unsigned char) ((newhead >> 8) & 0xff);
1227  fr->id3buf[3] = (unsigned char) ( newhead & 0xff);
1228 
1229  if((ret=fr->rd->fullread(fr,fr->id3buf+4,124)) < 0) return ret;
1230 
1232  fr->rdat.flags |= READER_ID3TAG; /* that marks id3v1 */
1233  if(VERBOSE3) fprintf(stderr,"Note: Skipped ID3v1 tag.\n");
1234 
1235  return PARSE_AGAIN;
1236  }
1237  /* This is similar to initial junk skipping code... */
1238  /* Check for id3v2; first three bytes (of 4) are "ID3" */
1239  if((newhead & (unsigned long) 0xffffff00) == (unsigned long) 0x49443300)
1240  {
1241  return handle_id3v2(fr, newhead);
1242  }
1243  /* Check for an apetag header */
1244  if(newhead == ('A'<<24)+('P'<<16)+('E'<<8)+'T')
1245  {
1246  return handle_apetag(fr, newhead);
1247  }
1248  else if(NOQUIET && fr->silent_resync == 0)
1249  {
1250  fprintf(stderr,"Note: Illegal Audio-MPEG-Header 0x%08lx at offset %"OFF_P".\n",
1251  newhead, (off_p)fr->rd->tell(fr)-4);
1252  }
1253 
1254  /* Now we got something bad at hand, try to recover. */
1255 
1256  if(NOQUIET && (newhead & 0xffffff00) == ('b'<<24)+('m'<<16)+('p'<<8)) fprintf(stderr,"Note: Could be a BMP album art.\n");
1257 
1258  if( !(fr->p.flags & MPG123_NO_RESYNC) )
1259  {
1260  long try = 0;
1261  long limit = fr->p.resync_limit;
1262  unsigned int forgetcount = 0;
1263 
1264  /* If a resync is needed the bitreservoir of previous frames is no longer valid */
1265  fr->bitreservoir = 0;
1266 
1267  if(NOQUIET && fr->silent_resync == 0) fprintf(stderr, "Note: Trying to resync...\n");
1268 
1269  do /* ... shift the header with additional single bytes until be found something that could be a header. */
1270  {
1271  ++try;
1272  if(limit >= 0 && try >= limit) break;
1273 
1274  if(++forgetcount > FORGET_INTERVAL) forgetcount = 0;
1275  if((ret=forget_head_shift(fr,&newhead,!forgetcount)) <= 0)
1276  {
1277  *newheadp = newhead;
1278  if(NOQUIET) fprintf (stderr, "Note: Hit end of (available) data during resync.\n");
1279 
1280  return ret ? ret : PARSE_END;
1281  }
1282  if(VERBOSE3) debug3("resync try %li at %"OFF_P", got newhead 0x%08lx", try, (off_p)fr->rd->tell(fr), newhead);
1283  } while(!head_check(newhead));
1284 
1285  *newheadp = newhead;
1286  if(NOQUIET && fr->silent_resync == 0) fprintf (stderr, "Note: Skipped %li bytes in input.\n", try);
1287 
1288  /* Now we either got something that could be a header, or we gave up. */
1289  if(limit >= 0 && try >= limit)
1290  {
1291  if(NOQUIET)
1292  error1("Giving up resync after %li bytes - your stream is not nice... (maybe increasing resync limit could help).", try);
1293 
1294  fr->err = MPG123_RESYNC_FAIL;
1295  return PARSE_ERR;
1296  }
1297  else
1298  {
1299  debug1("Found possibly valid header 0x%lx... unsetting oldhead to reinit stream.", newhead);
1300  fr->oldhead = 0;
1301  return PARSE_RESYNC;
1302  }
1303  }
1304  else
1305  {
1306  if(NOQUIET) error("not attempting to resync...");
1307 
1308  fr->err = MPG123_OUT_OF_SYNC;
1309  return PARSE_ERR;
1310  }
1311  /* Control never goes here... we return before that. */
1312 }
static int forget_head_shift(mpg123_handle *fr, unsigned long *newheadp, int forget)
Definition: parse.c:1121
struct mpg123_pars_struct p
Definition: frame.h:287
#define error(str)
Definition: mkdosfs.c:1605
#define error1(s, a)
Definition: debug.h:109
struct reader_data rdat
Definition: frame.h:286
#define debug3(s, a, b, c)
Definition: debug.h:54
#define FORGET_INTERVAL
Definition: parse.c:1120
GLint limit
Definition: glext.h:10326
#define MPG123_NEW_ID3
Definition: mpg123.h:1241
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
unsigned char
Definition: typeof.h:29
#define VERBOSE3
static int handle_apetag(mpg123_handle *fr, unsigned long newhead)
Definition: parse.c:1061
#define READER_ID3TAG
Definition: reader.h:114
#define MPG123_ID3
Definition: mpg123.h:1240
#define NOQUIET
int ret
static int handle_id3v2(mpg123_handle *fr, unsigned long newhead)
Definition: parse.c:1048
unsigned char id3buf[128]
Definition: frame.h:294
unsigned int bitreservoir
Definition: frame.h:250
long off_p
Definition: compat.h:130
FILE * stderr
struct reader * rd
Definition: frame.h:285
#define debug1(s, a)
Definition: debug.h:52
static int head_check(unsigned long head)
Definition: parse.c:85
unsigned long oldhead
Definition: frame.h:256
#define OFF_P
Definition: compat.h:129

Referenced by read_frame().

Variable Documentation

◆ freqs

const long freqs[9] = { 44100, 48000, 32000, 22050, 24000, 16000 , 11025 , 12000 , 8000 }
static

Definition at line 64 of file parse.c.

Referenced by decode_header(), frame_freq(), and mpg123_tpf().

◆ tabsel_123

const int tabsel_123[2][3][16]
static
Initial value:
=
{
{
{0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
{0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
{0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,}
},
{
{0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,}
}
}

Definition at line 50 of file parse.c.

Referenced by decode_header(), and frame_bitrate().