ReactOS  0.4.13-dev-551-gf37fb1f
parse.h File Reference
#include "frame.h"
Include dependency graph for parse.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int read_frame_init (mpg123_handle *fr)
 
int frame_bitrate (mpg123_handle *fr)
 
long frame_freq (mpg123_handle *fr)
 
int read_frame_recover (mpg123_handle *fr)
 
int read_frame (mpg123_handle *fr)
 
void set_pointer (mpg123_handle *fr, long backstep)
 
int position_info (mpg123_handle *fr, unsigned long no, long buffsize, unsigned long *frames_left, double *current_seconds, double *seconds_left)
 
double compute_bpf (mpg123_handle *fr)
 
long time_to_frame (mpg123_handle *fr, double seconds)
 
int get_songlen (mpg123_handle *fr, int no)
 

Function Documentation

◆ 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().

◆ 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

◆ position_info()

int position_info ( mpg123_handle fr,
unsigned long  no,
long  buffsize,
unsigned long frames_left,
double current_seconds,
double seconds_left 
)

◆ 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:1123
_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:1196
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

◆ read_frame_init()

int read_frame_init ( mpg123_handle fr)

◆ read_frame_recover()

int read_frame_recover ( mpg123_handle fr)

◆ 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

◆ time_to_frame()

long time_to_frame ( mpg123_handle fr,
double  seconds 
)