ReactOS  r74622
mpg123 file input and decoding

Functions

MPG123_EXPORT int mpg123_open (mpg123_handle *mh, const char *path)
 
MPG123_EXPORT int mpg123_open_fd (mpg123_handle *mh, int fd)
 
MPG123_EXPORT int mpg123_open_handle (mpg123_handle *mh, void *iohandle)
 
MPG123_EXPORT int mpg123_open_feed (mpg123_handle *mh)
 
MPG123_EXPORT int mpg123_close (mpg123_handle *mh)
 
MPG123_EXPORT int mpg123_read (mpg123_handle *mh, unsigned char *outmemory, size_t outmemsize, size_t *done)
 
MPG123_EXPORT int mpg123_feed (mpg123_handle *mh, const unsigned char *in, size_t size)
 
MPG123_EXPORT int mpg123_decode (mpg123_handle *mh, const unsigned char *inmemory, size_t inmemsize, unsigned char *outmemory, size_t outmemsize, size_t *done)
 
MPG123_EXPORT int mpg123_decode_frame (mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes)
 
MPG123_EXPORT int mpg123_framebyframe_decode (mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes)
 
MPG123_EXPORT int mpg123_framebyframe_next (mpg123_handle *mh)
 
MPG123_EXPORT int mpg123_framedata (mpg123_handle *mh, unsigned long *header, unsigned char **bodydata, size_t *bodybytes)
 
MPG123_EXPORT off_t mpg123_framepos (mpg123_handle *mh)
 

Detailed Description

Functions for input bitstream and decoding operations. Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE (please read up on these on how to react!).

Function Documentation

MPG123_EXPORT int mpg123_close ( mpg123_handle mh)

Closes the source, if libmpg123 opened it.

Returns
MPG123_OK on success

Definition at line 1557 of file libmpg123.c.

Referenced by mpg123_delete(), mpg123_open(), mpg123_open_fd(), mpg123_open_feed(), mpg123_open_handle(), mpg123_replace_reader(), and mpg123_replace_reader_handle().

1558 {
1559  if(mh == NULL) return MPG123_BAD_HANDLE;
1560 
1561  /* mh->rd is never NULL! */
1562  if(mh->rd->close != NULL) mh->rd->close(mh);
1563 
1564  if(mh->new_format)
1565  {
1566  debug("Hey, we are closing a track before the new format has been queried...");
1567  invalidate_format(&mh->af);
1568  mh->new_format = 0;
1569  }
1570  /* Always reset the frame buffers on close, so we cannot forget it in funky opening routines (wrappers, even). */
1571  frame_reset(mh);
1572  return MPG123_OK;
1573 }
#define frame_reset
Definition: intsym.h:158
#define invalidate_format
Definition: intsym.h:152
smooth NULL
Definition: ftsmooth.c:464
#define debug(s)
Definition: debug.h:44
struct audioformat af
Definition: frame.h:265
struct reader * rd
Definition: frame.h:284
MPG123_EXPORT int mpg123_decode ( mpg123_handle mh,
const unsigned char inmemory,
size_t  inmemsize,
unsigned char outmemory,
size_t  outmemsize,
size_t done 
)

Decode MPEG Audio from inmemory to outmemory. This is very close to a drop-in replacement for old mpglib. When you give zero-sized output buffer the input will be parsed until decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it) without taking decoded data. Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-). You can actually always decide if you want those specialized functions in separate steps or one call this one here.

Parameters
inmemoryinput buffer
inmemsizenumber of input bytes
outmemoryoutput buffer
outmemsizemaximum number of output bytes
doneaddress to store the number of actually decoded bytes to
Returns
error/message code (watch out especially for MPG123_NEED_MORE)

Definition at line 905 of file libmpg123.c.

Referenced by mpg123_read().

906 {
907  int ret = MPG123_OK;
908  size_t mdone = 0;
909 
910  if(done != NULL) *done = 0;
911  if(mh == NULL) return MPG123_BAD_HANDLE;
912 #ifndef NO_FEEDER
913  if(inmemsize > 0 && mpg123_feed(mh, inmemory, inmemsize) != MPG123_OK)
914  {
915  ret = MPG123_ERR;
916  goto decodeend;
917  }
918  if(outmemory == NULL) outmemsize = 0; /* Not just give error, give chance to get a status message. */
919 
920  while(ret == MPG123_OK)
921  {
922  debug4("decode loop, fill %i (%li vs. %li); to_decode: %i", (int)mh->buffer.fill, (long)mh->num, (long)mh->firstframe, mh->to_decode);
923  /* Decode a frame that has been read before.
924  This only happens when buffer is empty! */
925  if(mh->to_decode)
926  {
927  if(mh->new_format)
928  {
929  debug("notifiying new format");
930  mh->new_format = 0;
931  ret = MPG123_NEW_FORMAT;
932  goto decodeend;
933  }
934  if(mh->buffer.size - mh->buffer.fill < mh->outblock)
935  {
936  ret = MPG123_NO_SPACE;
937  goto decodeend;
938  }
939  decode_the_frame(mh);
940  mh->to_decode = mh->to_ignore = FALSE;
941  mh->buffer.p = mh->buffer.data;
942  debug2("decoded frame %li, got %li samples in buffer", (long)mh->num, (long)(mh->buffer.fill / (samples_to_bytes(mh, 1))));
943  FRAME_BUFFERCHECK(mh);
944  }
945  if(mh->buffer.fill) /* Copy (part of) the decoded data to the caller's buffer. */
946  {
947  /* get what is needed - or just what is there */
948  int a = mh->buffer.fill > (outmemsize - mdone) ? outmemsize - mdone : mh->buffer.fill;
949  debug4("buffer fill: %i; copying %i (%i - %li)", (int)mh->buffer.fill, a, (int)outmemsize, (long)mdone);
950  memcpy(outmemory, mh->buffer.p, a);
951  /* less data in frame buffer, less needed, output pointer increase, more data given... */
952  mh->buffer.fill -= a;
953  outmemory += a;
954  mdone += a;
955  mh->buffer.p += a;
956  if(!(outmemsize > mdone)) goto decodeend;
957  }
958  else /* If we didn't have data, get a new frame. */
959  {
960  int b = get_next_frame(mh);
961  if(b < 0){ ret = b; goto decodeend; }
962  }
963  }
964 decodeend:
965  if(done != NULL) *done = mdone;
966  return ret;
967 #else
969  return MPG123_ERR;
970 #endif
971 }
#define debug4(s, a, b, c, d)
Definition: debug.h:48
struct outbuffer buffer
Definition: frame.h:264
GLuint buffer
Definition: glext.h:5915
#define debug2(s, a, b)
Definition: debug.h:46
static void decode_the_frame(mpg123_handle *fr)
Definition: libmpg123.c:694
int attribute_align_arg mpg123_feed(mpg123_handle *mh, const unsigned char *in, size_t size)
Definition: libmpg123.c:860
#define a
Definition: ke_i.h:78
smooth NULL
Definition: ftsmooth.c:464
#define debug(s)
Definition: debug.h:44
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
if(!(yy_init))
Definition: macro.lex.yy.c:704
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
#define samples_to_bytes
Definition: intsym.h:201
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static int get_next_frame(mpg123_handle *mh)
Definition: libmpg123.c:579
#define FALSE
Definition: numbers.c:16
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLfloat GLfloat p
Definition: glext.h:8902
#define FRAME_BUFFERCHECK(mh)
Definition: gapless.h:111
else
Definition: s_aatritemp.h:84
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29
MPG123_EXPORT int mpg123_decode_frame ( mpg123_handle mh,
off_t num,
unsigned char **  audio,
size_t bytes 
)

Decode next MPEG frame to internal buffer or read a frame and return after setting a new format.

Parameters
numcurrent frame offset gets stored there
audioThis pointer is set to the internal buffer to read the decoded audio from.
bytesnumber of output bytes ready in the buffer
Returns
MPG123_OK or error/message code

Definition at line 166 of file lfs_wrap.c.

167 {
168  off_t largenum;
169  int err;
170 
171  err = MPG123_LARGENAME(mpg123_decode_frame)(mh, &largenum, audio, bytes);
172  if(err == MPG123_OK && num != NULL)
173  {
174  *num = largenum;
175  if(*num != largenum)
176  {
177  mh->err = MPG123_LFS_OVERFLOW;
178  err = MPG123_ERR;
179  }
180  }
181  return err;
182 }
__kernel_off_t off_t
Definition: linux.h:201
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
smooth NULL
Definition: ftsmooth.c:464
GLuint GLuint num
Definition: glext.h:9618
#define err(...)
int attribute_align_arg mpg123_decode_frame(mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
Definition: lfs_wrap.c:166
MPG123_EXPORT int mpg123_feed ( mpg123_handle mh,
const unsigned char in,
size_t  size 
)

Feed data for a stream that has been opened with mpg123_open_feed(). It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.

Parameters
ininput buffer
sizenumber of input bytes
Returns
MPG123_OK or error/message code.

Definition at line 860 of file libmpg123.c.

Referenced by mpg123_decode().

861 {
862  if(mh == NULL) return MPG123_BAD_HANDLE;
863 #ifndef NO_FEEDER
864  if(size > 0)
865  {
866  if(in != NULL)
867  {
868  if(feed_more(mh, in, size) != 0) return MPG123_ERR;
869  else
870  {
871  /* The need for more data might have triggered an error.
872  This one is outdated now with the new data. */
873  if(mh->err == MPG123_ERR_READER) mh->err = MPG123_OK;
874 
875  return MPG123_OK;
876  }
877  }
878  else
879  {
880  mh->err = MPG123_NULL_BUFFER;
881  return MPG123_ERR;
882  }
883  }
884  return MPG123_OK;
885 #else
887  return MPG123_ERR;
888 #endif
889 }
smooth NULL
Definition: ftsmooth.c:464
#define feed_more
Definition: intsym.h:222
GLfloat CONST GLvector4f * in
Definition: m_xform.h:122
GLsizeiptr size
Definition: glext.h:5919
MPG123_EXPORT int mpg123_framebyframe_decode ( mpg123_handle mh,
off_t num,
unsigned char **  audio,
size_t bytes 
)

Decode current MPEG frame to internal buffer. Warning: This is experimental API that might change in future releases! Please watch mpg123 development closely when using it.

Parameters
numlast frame offset gets stored there
audiothis pointer is set to the internal buffer to read the decoded audio from.
bytesnumber of output bytes ready in the buffer
Returns
MPG123_OK or error/message code

Definition at line 186 of file lfs_wrap.c.

187 {
188  off_t largenum;
189  int err;
190 
191  err = MPG123_LARGENAME(mpg123_framebyframe_decode)(mh, &largenum, audio, bytes);
192  if(err == MPG123_OK && num != NULL)
193  {
194  *num = largenum;
195  if(*num != largenum)
196  {
197  mh->err = MPG123_LFS_OVERFLOW;
198  err = MPG123_ERR;
199  }
200  }
201  return err;
202 }
__kernel_off_t off_t
Definition: linux.h:201
int attribute_align_arg mpg123_framebyframe_decode(mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
Definition: lfs_wrap.c:186
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
smooth NULL
Definition: ftsmooth.c:464
GLuint GLuint num
Definition: glext.h:9618
#define err(...)
MPG123_EXPORT int mpg123_framebyframe_next ( mpg123_handle mh)

Find, read and parse the next mp3 frame Warning: This is experimental API that might change in future releases! Please watch mpg123 development closely when using it.

Returns
MPG123_OK or error/message code

Definition at line 778 of file libmpg123.c.

779 {
780  int b;
781  if(mh == NULL) return MPG123_BAD_HANDLE;
782 
783  mh->to_decode = mh->to_ignore = FALSE;
784  mh->buffer.fill = 0;
785 
786  b = get_next_frame(mh);
787  if(b < 0) return b;
788  debug1("got next frame, %i", mh->to_decode);
789 
790  /* mpg123_framebyframe_decode will return MPG123_OK with 0 bytes decoded if mh->to_decode is 0 */
791  if(!mh->to_decode)
792  return MPG123_OK;
793 
794  if(mh->new_format)
795  {
796  debug("notifiying new format");
797  mh->new_format = 0;
798  return MPG123_NEW_FORMAT;
799  }
800 
801  return MPG123_OK;
802 }
struct outbuffer buffer
Definition: frame.h:264
smooth NULL
Definition: ftsmooth.c:464
#define debug(s)
Definition: debug.h:44
#define b
Definition: ke_i.h:79
static int get_next_frame(mpg123_handle *mh)
Definition: libmpg123.c:579
#define FALSE
Definition: numbers.c:16
#define debug1(s, a)
Definition: debug.h:45
MPG123_EXPORT int mpg123_framedata ( mpg123_handle mh,
unsigned long header,
unsigned char **  bodydata,
size_t bodybytes 
)

Get access to the raw input data for the last parsed frame. This gives you a direct look (and write access) to the frame body data. Together with the raw header, you can reconstruct the whole raw MPEG stream without junk and meta data, or play games by actually modifying the frame body data before decoding this frame (mpg123_framebyframe_decode()). A more sane use would be to use this for CRC checking (see mpg123_info() and MPG123_CRC), the first two bytes of the body make up the CRC16 checksum, if present. You can provide NULL for a parameter pointer when you are not interested in the value.

Parameters
headerthe 4-byte MPEG header
bodydatapointer to the frame body stored in the handle (without the header)
bodybytessize of frame body in bytes (without the header)
Returns
MPG123_OK if there was a yet un-decoded frame to get the data from, MPG123_BAD_HANDLE or MPG123_ERR otherwise (without further explanation, the error state of the mpg123_handle is not modified by this function).

Definition at line 612 of file frame.c.

613 {
614  if(mh == NULL) return MPG123_BAD_HANDLE;
615  if(!mh->to_decode) return MPG123_ERR;
616 
617  if(header != NULL) *header = mh->oldhead;
618  if(bodydata != NULL) *bodydata = mh->bsbuf;
619  if(bodybytes != NULL) *bodybytes = mh->framesize;
620 
621  return MPG123_OK;
622 }
smooth NULL
Definition: ftsmooth.c:464
unsigned long oldhead
Definition: frame.h:255
struct CFHEADER header
Definition: fdi.c:109
unsigned char * bsbuf
Definition: frame.h:251
MPG123_EXPORT off_t mpg123_framepos ( mpg123_handle mh)

Get the input position (byte offset in stream) of the last parsed frame. This can be used for external seek index building, for example. It just returns the internally stored offset, regardless of validity – you ensure that a valid frame has been parsed before!

Definition at line 1016 of file frame.c.

1017 {
1018  if(mh == NULL) return MPG123_ERR;
1019 
1020  return mh->input_offset;
1021 }
off_t input_offset
Definition: frame.h:215
smooth NULL
Definition: ftsmooth.c:464
MPG123_EXPORT int mpg123_open ( mpg123_handle mh,
const char path 
)

Enumeration of the error codes returned by libmpg123 functions. Open and prepare to decode the specified file by filesystem path. This does not open HTTP urls; libmpg123 contains no networking code. If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().

Parameters
pathfilesystem path
Returns
MPG123_OK on success

Definition at line 104 of file lfs_alias.c.

105 {
106  return NATIVE_NAME(mpg123_open)(mh, path);
107 }
GLsizei const GLchar ** path
Definition: glext.h:7234
int NATIVE_NAME() mpg123_open(mpg123_handle *mh, const char *path)
Definition: lfs_alias.c:104
#define NATIVE_NAME(func)
Definition: lfs_alias.c:52
MPG123_EXPORT int mpg123_open_fd ( mpg123_handle mh,
int  fd 
)

Use an already opened file descriptor as the bitstream input mpg123_close() will not close the file descriptor.

Definition at line 110 of file lfs_alias.c.

111 {
112  return NATIVE_NAME(mpg123_open_fd)(mh, fd);
113 }
static HANDLE fd
Definition: io.c:55
int NATIVE_NAME() mpg123_open_fd(mpg123_handle *mh, int fd)
Definition: lfs_alias.c:110
#define NATIVE_NAME(func)
Definition: lfs_alias.c:52
MPG123_EXPORT int mpg123_open_feed ( mpg123_handle mh)

Open a new bitstream and prepare for direct feeding This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.

Returns
MPG123_OK on success

Definition at line 455 of file libmpg123.c.

456 {
457  if(mh == NULL) return MPG123_BAD_HANDLE;
458 
459  mpg123_close(mh);
460  return open_feed(mh);
461 }
#define open_feed
Definition: intsym.h:221
int attribute_align_arg mpg123_close(mpg123_handle *mh)
Definition: libmpg123.c:1557
smooth NULL
Definition: ftsmooth.c:464
MPG123_EXPORT int mpg123_open_handle ( mpg123_handle mh,
void iohandle 
)

Use an opaque handle as bitstream input. This works only with the replaced I/O from mpg123_replace_reader_handle()! mpg123_close() will call the cleanup callback for your handle (if you gave one).

Returns
MPG123_OK on success

Definition at line 116 of file lfs_alias.c.

117 {
118  return NATIVE_NAME(mpg123_open_handle)(mh, iohandle);
119 }
int NATIVE_NAME() mpg123_open_handle(mpg123_handle *mh, void *iohandle)
Definition: lfs_alias.c:116
#define NATIVE_NAME(func)
Definition: lfs_alias.c:52
MPG123_EXPORT int mpg123_read ( mpg123_handle mh,
unsigned char outmemory,
size_t  outmemsize,
size_t done 
)

Read from stream and decode up to outmemsize bytes.

Parameters
outmemoryaddress of output buffer to write to
outmemsizemaximum number of bytes to write
doneaddress to store the number of actually decoded bytes to
Returns
MPG123_OK or error/message code

Definition at line 855 of file libmpg123.c.

856 {
857  return mpg123_decode(mh, NULL, 0, out, size, done);
858 }
int attribute_align_arg mpg123_decode(mpg123_handle *mh, const unsigned char *inmemory, size_t inmemsize, unsigned char *outmemory, size_t outmemsize, size_t *done)
Definition: libmpg123.c:905
smooth NULL
Definition: ftsmooth.c:464
static FILE * out
Definition: regtests2xml.c:44
GLsizeiptr size
Definition: glext.h:5919