static int read_buf_byte (struct mpstr *mp) { unsigned int b; int pos; pos = mp->tail->pos; while (pos >= mp->tail->size) { remove_buf (mp); pos = mp->tail->pos; if (!mp->tail) { fprintf (stderr, "Fatal error!\n"); exit (1); } } b = mp->tail->pnt[pos]; mp->bsize--; mp->tail->pos++; return b; }
static int read_buf_byte(struct mpstr *mp) { unsigned int b; int pos; pos = mp->tail->pos; while(pos >= mp->tail->size) { remove_buf(mp); if(!mp->tail) { #ifndef BE_QUIET fprintf(stderr,"Fatal error!\n"); #endif return 0; } pos = mp->tail->pos; } b = mp->tail->pnt[pos]; mp->bsize--; mp->tail->pos++; return b; }
DLLEXPORT INT MpgLib_Flush(VOID) { while (mp.head!=NULL && mp.tail!=NULL) { remove_buf(&mp); } mp.bsize=0; return (0); }
int decodeMP3 (struct mpstr *mp, char *in, int isize, char *out, int osize, int *done) { int len; gmp = mp; if (osize < 4608) { fprintf (stderr, "To less out space\n"); return MP3_ERR; } if (in) { if (addbuf (mp, in, isize) == NULL) { return MP3_ERR; } } /* First decode header */ if (mp->framesize == 0) { if (mp->bsize < 4) { return MP3_NEED_MORE; } read_head (mp); decode_header (&mp->fr, mp->header); mp->framesize = mp->fr.framesize; } if (mp->fr.framesize > mp->bsize) return MP3_NEED_MORE; wordpointer = mp->bsspace[mp->bsnum] + 512; mp->bsnum = (mp->bsnum + 1) & 0x1; bitindex = 0; len = 0; while (len < mp->framesize) { int nlen; int blen = mp->tail->size - mp->tail->pos; if ((mp->framesize - len) <= blen) { nlen = mp->framesize - len; } else { nlen = blen; } memcpy (wordpointer + len, mp->tail->pnt + mp->tail->pos, nlen); len += nlen; mp->tail->pos += nlen; mp->bsize -= nlen; if (mp->tail->pos == mp->tail->size) { remove_buf (mp); } } *done = 0; if (mp->fr.error_protection) getbits (16); switch (mp->fr.lay) { case 3: do_layer3 (&mp->fr, (unsigned char *) out, done); break; } mp->fsizeold = mp->framesize; mp->framesize = 0; return MP3_OK; }
int decodeMP3(struct mpstr *mp, char *in, int isize, char *out, int osize, int *done) { int len; if(osize < 4608) { #ifndef BE_QUIET fprintf(stderr,"To less out space\n"); #endif return MP3_ERR; } if(in) { if(addbuf(mp, in, isize) == NULL) { return MP3_ERR; } } /* First decode header */ if(mp->framesize == 0) { if(mp->bsize < 4) { return MP3_NEED_MORE; } read_head(mp); if(mp->tail) mp->ndatabegin = mp->tail->pos - 4; if (decode_header(mp, &mp->fr,mp->header) <= 0 ) return MP3_ERR; mp->framesize = mp->fr.framesize; } /* printf(" fr.framesize = %i \n",mp->fr.framesize); printf(" bsize = %i \n",mp->bsize); */ if(mp->fr.framesize > mp->bsize) { return MP3_NEED_MORE; } mp->psd.wordpointer = mp->bsspace[mp->bsnum] + 512; mp->bsnum = (mp->bsnum + 1) & 0x1; mp->psd.bitindex = 0; len = 0; while(len < mp->framesize) { int nlen; int blen = mp->tail->size - mp->tail->pos; if( (mp->framesize - len) <= blen) { nlen = mp->framesize-len; } else { nlen = blen; } memcpy(mp->psd.wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen); len += nlen; mp->tail->pos += nlen; mp->bsize -= nlen; if(mp->tail->pos == mp->tail->size) { remove_buf(mp); } } *done = 0; if(mp->fr.error_protection) getbits(&mp->psd, 16); // FOR mpglib.dll: see if error and return it if ((&mp->fr)->do_layer(&mp->psd, mp, &mp->fr, (unsigned char*) out, done) < 0) return MP3_ERR; mp->fsizeold = mp->framesize; mp->framesize = 0; return MP3_OK; }