ReactOS  0.4.15-dev-1177-g6cb3b62
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, int part2, 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 968 of file parse.c.

969 {
970  return (fr->framesize > 0) ? fr->framesize + 4.0 : 1.0;
971 }

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

◆ frame_bitrate()

int frame_bitrate ( mpg123_handle fr)

Definition at line 80 of file parse.c.

81 {
82  return tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
83 }
static const int tabsel_123[2][3][16]
Definition: parse.c:56

◆ frame_freq()

long frame_freq ( mpg123_handle fr)

Definition at line 85 of file parse.c.

86 {
87  return freqs[fr->sampling_frequency];
88 }
int sampling_frequency
Definition: frame.h:205
static const long freqs[9]
Definition: parse.c:70

◆ get_songlen()

int get_songlen ( mpg123_handle fr,
int  no 
)

Definition at line 1053 of file parse.c.

1054 {
1055  double tpf;
1056 
1057  if(!fr)
1058  return 0;
1059 
1060  if(no < 0) {
1061  if(!fr->rd || fr->rdat.filelen < 0)
1062  return 0;
1063  no = (int) ((double) fr->rdat.filelen / compute_bpf(fr));
1064  }
1065 
1066  tpf = mpg123_tpf(fr);
1067  return (int) (no*tpf);
1068 }
double compute_bpf(mpg123_handle *fr)
Definition: parse.c:968
struct reader_data rdat
Definition: frame.h:288
double attribute_align_arg mpg123_tpf(mpg123_handle *fr)
Definition: parse.c:980
static WCHAR no[MAX_STRING_RESOURCE_LEN]
Definition: object.c:2340
struct reader * rd
Definition: frame.h:287
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 500 of file parse.c.

501 {
502  /* TODO: rework this thing */
503  int freeformat_count = 0;
504  unsigned long newhead;
505  off_t framepos;
506  int ret;
507  /* stuff that needs resetting if complete frame reading fails */
508  int oldsize = fr->framesize;
509  int oldphase = fr->halfphase;
510 
511  /* The counter for the search-first-header loop.
512  It is persistent outside the loop to prevent seemingly endless loops
513  when repeatedly headers are found that do not have valid followup headers. */
514  long headcount = 0;
515 
516  fr->fsizeold=fr->framesize; /* for Layer3 */
517 
518  if(halfspeed_do(fr) == 1) return 1;
519 
520  /* From now on, old frame data is tainted by parsing attempts. */
521  fr->to_decode = fr->to_ignore = FALSE;
522 
523  if( fr->p.flags & MPG123_NO_FRANKENSTEIN &&
524  ( (fr->track_frames > 0 && fr->num >= fr->track_frames-1)
525 #ifdef GAPLESS
526  || (fr->gapless_frames > 0 && fr->num >= fr->gapless_frames-1)
527 #endif
528  ) )
529  {
530  mdebug( "stopping parsing at %"OFF_P
531  " frames as indicated fixed track length"
532  , (off_p)fr->num+1 );
533  return 0;
534  }
535 
536 read_again:
537  /* In case we are looping to find a valid frame, discard any buffered data before the current position.
538  This is essential to prevent endless looping, always going back to the beginning when feeder buffer is exhausted. */
539  if(fr->rd->forget != NULL) fr->rd->forget(fr);
540 
541  debug2("trying to get frame %"OFF_P" at %"OFF_P, (off_p)fr->num+1, (off_p)fr->rd->tell(fr));
542  if((ret = fr->rd->head_read(fr,&newhead)) <= 0){ debug1("need more? (%i)", ret); goto read_frame_bad;}
543 
544 init_resync:
545 
546 #ifdef SKIP_JUNK
547  if(!fr->firsthead && !head_check(newhead))
548  {
549  ret = skip_junk(fr, &newhead, &headcount);
551  }
552 #endif
553 
554  ret = head_check(newhead);
555  if(ret) ret = decode_header(fr, newhead, &freeformat_count);
556 
557  JUMP_CONCLUSION(ret); /* That only continues for ret == PARSE_BAD or PARSE_GOOD. */
558  if(ret == PARSE_BAD)
559  { /* Header was not good. */
560  ret = wetwork(fr, &newhead); /* Messy stuff, handle junk, resync ... */
562  /* Normally, we jumped already. If for some reason everything's fine to continue, do continue. */
563  if(ret != PARSE_GOOD) goto read_frame_bad;
564  }
565 
566  if(!fr->firsthead)
567  {
568  ret = fr->p.flags & MPG123_NO_READAHEAD
569  ? PARSE_GOOD
570  : do_readahead(fr, newhead);
571  /* readahead can fail mit NEED_MORE, in which case we must also make the just read header available again for next go */
572  if(ret < 0) fr->rd->back_bytes(fr, 4);
574  }
575 
576  /* Now we should have our valid header and proceed to reading the frame. */
577 
578  if(fr->p.flags & MPG123_NO_FRANKENSTEIN)
579  {
580  if(fr->firsthead && !head_compatible(fr->firsthead, newhead))
581  {
582  mdebug( "stopping before reading frame %"OFF_P
583  " as its header indicates Frankenstein coming for you", (off_p)fr->num );
584  return 0;
585  }
586  }
587 
588  /* if filepos is invalid, so is framepos */
589  framepos = fr->rd->tell(fr) - 4;
590  /* flip/init buffer for Layer 3 */
591  {
592  unsigned char *newbuf = fr->bsspace[fr->bsnum]+512;
593  /* read main data into memory */
594  debug2("read frame body of %i at %"OFF_P, fr->framesize, framepos+4);
595  if((ret=fr->rd->read_frame_body(fr,newbuf,fr->framesize))<0)
596  {
597  /* if failed: flip back */
598  debug1("%s", ret == MPG123_NEED_MORE ? "need more" : "read error");
599  goto read_frame_bad;
600  }
601  fr->bsbufold = fr->bsbuf;
602  fr->bsbuf = newbuf;
603  }
604  fr->bsnum = (fr->bsnum + 1) & 1;
605 
606  if(!fr->firsthead)
607  {
608  fr->firsthead = newhead; /* _now_ it's time to store it... the first real header */
609  /* This is the first header of our current stream segment.
610  It is only the actual first header of the whole stream when fr->num is still below zero!
611  Think of resyncs where firsthead has been reset for format flexibility. */
612  if(fr->num < 0)
613  {
614  fr->audio_start = framepos;
615  /* Only check for LAME tag at beginning of whole stream
616  ... when there indeed is one in between, it's the user's problem. */
617  if(fr->lay == 3 && check_lame_tag(fr) == 1)
618  { /* ...in practice, Xing/LAME tags are layer 3 only. */
619  if(fr->rd->forget != NULL) fr->rd->forget(fr);
620 
621  fr->oldhead = 0;
622  goto read_again;
623  }
624  /* now adjust volume */
625  do_rva(fr);
626  }
627 
628  debug2("fr->firsthead: %08lx, audio_start: %li", fr->firsthead, (long int)fr->audio_start);
629  }
630 
631  set_pointer(fr, 0, 0);
632 
633  /* Question: How bad does the floating point value get with repeated recomputation?
634  Also, considering that we can play the file or parts of many times. */
635  if(++fr->mean_frames != 0)
636  {
637  fr->mean_framesize = ((fr->mean_frames-1)*fr->mean_framesize+compute_bpf(fr)) / fr->mean_frames ;
638  }
639  ++fr->num; /* 0 for first frame! */
640  debug4("Frame %"OFF_P" %08lx %i, next filepos=%"OFF_P,
641  (off_p)fr->num, newhead, fr->framesize, (off_p)fr->rd->tell(fr));
642  if(!(fr->state_flags & FRAME_FRANKENSTEIN) && (
643  (fr->track_frames > 0 && fr->num >= fr->track_frames)
644 #ifdef GAPLESS
645  || (fr->gapless_frames > 0 && fr->num >= fr->gapless_frames)
646 #endif
647  ))
648  {
650  if(NOQUIET) fprintf(stderr, "\nWarning: Encountered more data after announced end of track (frame %"OFF_P"/%"OFF_P"). Frankenstein!\n", (off_p)fr->num,
651 #ifdef GAPLESS
652  fr->gapless_frames > 0 ? (off_p)fr->gapless_frames :
653 #endif
654  (off_p)fr->track_frames);
655  }
656 
657  halfspeed_prepare(fr);
658 
659  /* index the position */
660  fr->input_offset = framepos;
661 #ifdef FRAME_INDEX
662  /* Keep track of true frame positions in our frame index.
663  but only do so when we are sure that the frame number is accurate... */
664  if((fr->state_flags & FRAME_ACCURATE) && FI_NEXT(fr->index, fr->num))
665  fi_add(&fr->index, framepos);
666 #endif
667 
668  if(fr->silent_resync > 0) --fr->silent_resync;
669 
670  if(fr->rd->forget != NULL) fr->rd->forget(fr);
671 
672  fr->to_decode = fr->to_ignore = TRUE;
673  if(fr->error_protection) fr->crc = getbits(fr, 16); /* skip crc */
674 
675  /*
676  Let's check for header change after deciding that the new one is good
677  and actually having read a frame.
678 
679  header_change > 1: decoder structure has to be updated
680  Preserve header_change value from previous runs if it is serious.
681  If we still have a big change pending, it should be dealt with outside,
682  fr->header_change set to zero afterwards.
683  */
684  if(fr->header_change < 2)
685  {
686  fr->header_change = 2; /* output format change is possible... */
687  if(fr->oldhead) /* check a following header for change */
688  {
689  if(fr->oldhead == newhead) fr->header_change = 0;
690  else
691  /* Headers that match in this test behave the same for the outside world.
692  namely: same decoding routines, same amount of decoded data. */
693  if(head_compatible(fr->oldhead, newhead))
694  fr->header_change = 1;
695  else
696  {
698  if(NOQUIET)
699  fprintf(stderr, "\nWarning: Big change (MPEG version, layer, rate). Frankenstein stream?\n");
700  }
701  }
702  else if(fr->firsthead && !head_compatible(fr->firsthead, newhead))
703  {
705  if(NOQUIET)
706  fprintf(stderr, "\nWarning: Big change from first (MPEG version, layer, rate). Frankenstein stream?\n");
707  }
708  }
709 
710  fr->oldhead = newhead;
711 
712  return 1;
713 read_frame_bad:
714  /* Also if we searched for valid data in vein, we can forget skipped data.
715  Otherwise, the feeder would hold every dead old byte in memory until the first valid frame! */
716  if(fr->rd->forget != NULL) fr->rd->forget(fr);
717 
718  fr->silent_resync = 0;
719  if(fr->err == MPG123_OK) fr->err = MPG123_ERR_READER;
720  fr->framesize = oldsize;
721  fr->halfphase = oldphase;
722  /* That return code might be inherited from some feeder action, or reader error. */
723  return ret;
724 }
#define JUMP_CONCLUSION(ret)
Definition: parse.c:488
struct mpg123_pars_struct p
Definition: frame.h:289
static int decode_header(mpg123_handle *fr, unsigned long newhead, int *freeformat_count)
Definition: parse.c:775
#define TRUE
Definition: types.h:120
unsigned char * bsbufold
Definition: frame.h:255
__kernel_off_t off_t
Definition: linux.h:201
double mean_framesize
Definition: frame.h:248
#define debug4(s, a, b, c, d)
Definition: debug.h:64
double compute_bpf(mpg123_handle *fr)
Definition: parse.c:968
#define debug2(s, a, b)
Definition: debug.h:62
off_t input_offset
Definition: frame.h:217
#define GAPLESS
Definition: config.h:45
off_t track_frames
Definition: frame.h:246
unsigned char bsspace[2][MAXFRAMESIZE+512+4]
Definition: frame.h:253
#define FALSE
Definition: types.h:117
static int skip_junk(mpg123_handle *fr, unsigned long *newheadp, long *headcount)
Definition: parse.c:1220
_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:443
#define fi_add
Definition: intsym.h:220
unsigned int crc
Definition: frame.h:286
off_t gapless_frames
Definition: frame.h:277
static unsigned int getbits(mpg123_handle *fr, int number_of_bits)
Definition: getbits.h:32
#define NOQUIET
int ret
#define mdebug(s,...)
Definition: debug.h:58
void set_pointer(mpg123_handle *fr, int part2, long backstep)
Definition: parse.c:940
static int do_readahead(mpg123_handle *fr, unsigned long newhead)
Definition: parse.c:1071
static void halfspeed_prepare(mpg123_handle *fr)
Definition: parse.c:449
unsigned long firsthead
Definition: frame.h:260
static int halfspeed_do(mpg123_handle *fr)
Definition: parse.c:460
static int wetwork(mpg123_handle *fr, unsigned long *newheadp)
Definition: parse.c:1294
struct frame_index index
Definition: frame.h:263
static int check_lame_tag(mpg123_handle *fr)
Definition: parse.c:138
long off_p
Definition: compat.h:132
FILE * stderr
struct reader * rd
Definition: frame.h:287
#define do_rva
Definition: intsym.h:190
#define debug1(s, a)
Definition: debug.h:61
static int head_check(unsigned long head)
Definition: parse.c:91
unsigned long oldhead
Definition: frame.h:258
#define OFF_P
Definition: compat.h:131
unsigned char * bsbuf
Definition: frame.h:254
#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,
int  part2,
long  backstep 
)

Definition at line 940 of file parse.c.

941 {
942  fr->bitindex = 0;
943  if(fr->lay == 3)
944  {
945  if(part2)
946  {
947  fr->wordpointer = fr->bsbuf + fr->ssize - backstep;
948  if(backstep)
949  memcpy( fr->wordpointer, fr->bsbufold+fr->fsizeold-backstep
950  , backstep );
951  fr->bits_avail = (long)(fr->framesize - fr->ssize + backstep)*8;
952  }
953  else
954  {
955  fr->wordpointer = fr->bsbuf;
956  fr->bits_avail = fr->ssize*8;
957  }
958  }
959  else
960  {
961  fr->wordpointer = fr->bsbuf;
962  fr->bits_avail = fr->framesize*8;
963  }
964 }
unsigned char * bsbufold
Definition: frame.h:255
unsigned char * wordpointer
Definition: frame.h:229
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define long
Definition: qsort.c:33
unsigned char * bsbuf
Definition: frame.h:254

Referenced by halfspeed_do(), and read_frame().

◆ time_to_frame()

long time_to_frame ( mpg123_handle fr,
double  seconds 
)