ReactOS  0.4.14-dev-614-gbfd8a84
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 892 of file parse.c.

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

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 977 of file parse.c.

978 {
979  double tpf;
980 
981  if(!fr)
982  return 0;
983 
984  if(no < 0) {
985  if(!fr->rd || fr->rdat.filelen < 0)
986  return 0;
987  no = (int) ((double) fr->rdat.filelen / compute_bpf(fr));
988  }
989 
990  tpf = mpg123_tpf(fr);
991  return (int) (no*tpf);
992 }
double compute_bpf(mpg123_handle *fr)
Definition: parse.c:892
struct reader_data rdat
Definition: frame.h:286
double attribute_align_arg mpg123_tpf(mpg123_handle *fr)
Definition: parse.c:904
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  /* From now on, old frame data is tainted by parsing attempts. */
513  fr->to_decode = fr->to_ignore = FALSE;
514 read_again:
515  /* In case we are looping to find a valid frame, discard any buffered data before the current position.
516  This is essential to prevent endless looping, always going back to the beginning when feeder buffer is exhausted. */
517  if(fr->rd->forget != NULL) fr->rd->forget(fr);
518 
519  debug2("trying to get frame %"OFF_P" at %"OFF_P, (off_p)fr->num+1, (off_p)fr->rd->tell(fr));
520  if((ret = fr->rd->head_read(fr,&newhead)) <= 0){ debug1("need more? (%i)", ret); goto read_frame_bad;}
521 
522 init_resync:
523 
524 #ifdef SKIP_JUNK
525  if(!fr->firsthead && !head_check(newhead))
526  {
527  ret = skip_junk(fr, &newhead, &headcount);
529  }
530 #endif
531 
532  ret = head_check(newhead);
533  if(ret) ret = decode_header(fr, newhead, &freeformat_count);
534 
535  JUMP_CONCLUSION(ret); /* That only continues for ret == PARSE_BAD or PARSE_GOOD. */
536  if(ret == PARSE_BAD)
537  { /* Header was not good. */
538  ret = wetwork(fr, &newhead); /* Messy stuff, handle junk, resync ... */
540  /* Normally, we jumped already. If for some reason everything's fine to continue, do continue. */
541  if(ret != PARSE_GOOD) goto read_frame_bad;
542  }
543 
544  if(!fr->firsthead)
545  {
546  ret = do_readahead(fr, newhead);
547  /* readahead can fail mit NEED_MORE, in which case we must also make the just read header available again for next go */
548  if(ret < 0) fr->rd->back_bytes(fr, 4);
550  }
551 
552  /* Now we should have our valid header and proceed to reading the frame. */
553 
554  /* if filepos is invalid, so is framepos */
555  framepos = fr->rd->tell(fr) - 4;
556  /* flip/init buffer for Layer 3 */
557  {
558  unsigned char *newbuf = fr->bsspace[fr->bsnum]+512;
559  /* read main data into memory */
560  if((ret=fr->rd->read_frame_body(fr,newbuf,fr->framesize))<0)
561  {
562  /* if failed: flip back */
563  debug("need more?");
564  goto read_frame_bad;
565  }
566  fr->bsbufold = fr->bsbuf;
567  fr->bsbuf = newbuf;
568  }
569  fr->bsnum = (fr->bsnum + 1) & 1;
570 
571  if(!fr->firsthead)
572  {
573  fr->firsthead = newhead; /* _now_ it's time to store it... the first real header */
574  /* This is the first header of our current stream segment.
575  It is only the actual first header of the whole stream when fr->num is still below zero!
576  Think of resyncs where firsthead has been reset for format flexibility. */
577  if(fr->num < 0)
578  {
579  fr->audio_start = framepos;
580  /* Only check for LAME tag at beginning of whole stream
581  ... when there indeed is one in between, it's the user's problem. */
582  if(fr->lay == 3 && check_lame_tag(fr) == 1)
583  { /* ...in practice, Xing/LAME tags are layer 3 only. */
584  if(fr->rd->forget != NULL) fr->rd->forget(fr);
585 
586  fr->oldhead = 0;
587  goto read_again;
588  }
589  /* now adjust volume */
590  do_rva(fr);
591  }
592 
593  debug2("fr->firsthead: %08lx, audio_start: %li", fr->firsthead, (long int)fr->audio_start);
594  }
595 
596  fr->bitindex = 0;
597  fr->wordpointer = (unsigned char *) fr->bsbuf;
598  /* Question: How bad does the floating point value get with repeated recomputation?
599  Also, considering that we can play the file or parts of many times. */
600  if(++fr->mean_frames != 0)
601  {
602  fr->mean_framesize = ((fr->mean_frames-1)*fr->mean_framesize+compute_bpf(fr)) / fr->mean_frames ;
603  }
604  ++fr->num; /* 0 for first frame! */
605  debug4("Frame %"OFF_P" %08lx %i, next filepos=%"OFF_P,
606  (off_p)fr->num, newhead, fr->framesize, (off_p)fr->rd->tell(fr));
607  if(!(fr->state_flags & FRAME_FRANKENSTEIN) && (
608  (fr->track_frames > 0 && fr->num >= fr->track_frames)
609 #ifdef GAPLESS
610  || (fr->gapless_frames > 0 && fr->num >= fr->gapless_frames)
611 #endif
612  ))
613  {
615  if(NOQUIET) fprintf(stderr, "\nWarning: Encountered more data after announced end of track (frame %"OFF_P"/%"OFF_P"). Frankenstein!\n", (off_p)fr->num,
616 #ifdef GAPLESS
617  fr->gapless_frames > 0 ? (off_p)fr->gapless_frames :
618 #endif
619  (off_p)fr->track_frames);
620  }
621 
622  halfspeed_prepare(fr);
623 
624  /* index the position */
625  fr->input_offset = framepos;
626 #ifdef FRAME_INDEX
627  /* Keep track of true frame positions in our frame index.
628  but only do so when we are sure that the frame number is accurate... */
629  if((fr->state_flags & FRAME_ACCURATE) && FI_NEXT(fr->index, fr->num))
630  fi_add(&fr->index, framepos);
631 #endif
632 
633  if(fr->silent_resync > 0) --fr->silent_resync;
634 
635  if(fr->rd->forget != NULL) fr->rd->forget(fr);
636 
637  fr->to_decode = fr->to_ignore = TRUE;
638  if(fr->error_protection) fr->crc = getbits(fr, 16); /* skip crc */
639 
640  /*
641  Let's check for header change after deciding that the new one is good
642  and actually having read a frame.
643 
644  header_change > 1: decoder structure has to be updated
645  Preserve header_change value from previous runs if it is serious.
646  If we still have a big change pending, it should be dealt with outside,
647  fr->header_change set to zero afterwards.
648  */
649  if(fr->header_change < 2)
650  {
651  fr->header_change = 2; /* output format change is possible... */
652  if(fr->oldhead) /* check a following header for change */
653  {
654  if(fr->oldhead == newhead) fr->header_change = 0;
655  else
656  /* Headers that match in this test behave the same for the outside world.
657  namely: same decoding routines, same amount of decoded data. */
658  if(head_compatible(fr->oldhead, newhead))
659  fr->header_change = 1;
660  else
661  {
663  if(NOQUIET)
664  fprintf(stderr, "\nWarning: Big change (MPEG version, layer, rate). Frankenstein stream?\n");
665  }
666  }
667  else if(fr->firsthead && !head_compatible(fr->firsthead, newhead))
668  {
670  if(NOQUIET)
671  fprintf(stderr, "\nWarning: Big change from first (MPEG version, layer, rate). Frankenstein stream?\n");
672  }
673  }
674 
675  fr->oldhead = newhead;
676 
677  return 1;
678 read_frame_bad:
679  /* Also if we searched for valid data in vein, we can forget skipped data.
680  Otherwise, the feeder would hold every dead old byte in memory until the first valid frame! */
681  if(fr->rd->forget != NULL) fr->rd->forget(fr);
682 
683  fr->silent_resync = 0;
684  if(fr->err == MPG123_OK) fr->err = MPG123_ERR_READER;
685  fr->framesize = oldsize;
686  fr->halfphase = oldphase;
687  /* That return code might be inherited from some feeder action, or reader error. */
688  return ret;
689 }
#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:740
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:892
#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:1144
_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:995
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:1217
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 881 of file parse.c.

882 {
883  fr->wordpointer = fr->bsbuf + fr->ssize - backstep;
884  if (backstep)
885  memcpy(fr->wordpointer,fr->bsbufold+fr->fsizeold-backstep,backstep);
886 
887  fr->bitindex = 0;
888 }
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 
)