ReactOS  r75214
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.

Parameters
mhhandle
Returns
MPG123_OK on success

Definition at line 1602 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().

1603 {
1604  if(mh == NULL) return MPG123_BAD_HANDLE;
1605 
1606  /* mh->rd is never NULL! */
1607  if(mh->rd->close != NULL) mh->rd->close(mh);
1608 
1609  if(mh->new_format)
1610  {
1611  debug("Hey, we are closing a track before the new format has been queried...");
1612  invalidate_format(&mh->af);
1613  mh->new_format = 0;
1614  }
1615  /* Always reset the frame buffers on close, so we cannot forget it in funky opening routines (wrappers, even). */
1616  frame_reset(mh);
1617  return MPG123_OK;
1618 }
#define frame_reset
Definition: intsym.h:173
#define invalidate_format
Definition: intsym.h:167
smooth NULL
Definition: ftsmooth.c:513
struct audioformat af
Definition: frame.h:266
#define debug(msg)
Definition: key_call.c:71
struct reader * rd
Definition: frame.h:285
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
mhhandle
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 918 of file libmpg123.c.

Referenced by mpg123_read().

919 {
920  int ret = MPG123_OK;
921  size_t mdone = 0;
922 
923  if(done != NULL) *done = 0;
924  if(mh == NULL) return MPG123_BAD_HANDLE;
925 #ifndef NO_FEEDER
926  if(inmemsize > 0 && mpg123_feed(mh, inmemory, inmemsize) != MPG123_OK)
927  {
928  ret = MPG123_ERR;
929  goto decodeend;
930  }
931  if(outmemory == NULL) outmemsize = 0; /* Not just give error, give chance to get a status message. */
932 
933  while(ret == MPG123_OK)
934  {
935  debug4("decode loop, fill %i (%li vs. %li); to_decode: %i", (int)mh->buffer.fill, (long)mh->num, (long)mh->firstframe, mh->to_decode);
936  /* Decode a frame that has been read before.
937  This only happens when buffer is empty! */
938  if(mh->to_decode)
939  {
940  if(mh->new_format)
941  {
942  debug("notifiying new format");
943  mh->new_format = 0;
944  ret = MPG123_NEW_FORMAT;
945  goto decodeend;
946  }
947  if(mh->buffer.size - mh->buffer.fill < mh->outblock)
948  {
949  ret = MPG123_NO_SPACE;
950  goto decodeend;
951  }
952  decode_the_frame(mh);
953  mh->to_decode = mh->to_ignore = FALSE;
954  mh->buffer.p = mh->buffer.data;
955  debug2("decoded frame %li, got %li samples in buffer", (long)mh->num, (long)(mh->buffer.fill / (samples_to_bytes(mh, 1))));
956  FRAME_BUFFERCHECK(mh);
957  }
958  if(mh->buffer.fill) /* Copy (part of) the decoded data to the caller's buffer. */
959  {
960  /* get what is needed - or just what is there */
961  int a = mh->buffer.fill > (outmemsize - mdone) ? outmemsize - mdone : mh->buffer.fill;
962  debug4("buffer fill: %i; copying %i (%i - %li)", (int)mh->buffer.fill, a, (int)outmemsize, (long)mdone);
963  memcpy(outmemory, mh->buffer.p, a);
964  /* less data in frame buffer, less needed, output pointer increase, more data given... */
965  mh->buffer.fill -= a;
966  outmemory += a;
967  mdone += a;
968  mh->buffer.p += a;
969  if(!(outmemsize > mdone)) goto decodeend;
970  }
971  else /* If we didn't have data, get a new frame. */
972  {
973  int b = get_next_frame(mh);
974  if(b < 0){ ret = b; goto decodeend; }
975  }
976  }
977 decodeend:
978  if(done != NULL) *done = mdone;
979  return ret;
980 #else
982  return MPG123_ERR;
983 #endif
984 }
#define debug4(s, a, b, c, d)
Definition: debug.h:55
struct outbuffer buffer
Definition: frame.h:265
GLuint buffer
Definition: glext.h:5915
#define debug2(s, a, b)
Definition: debug.h:53
static void decode_the_frame(mpg123_handle *fr)
Definition: libmpg123.c:707
#define FALSE
Definition: types.h:117
int attribute_align_arg mpg123_feed(mpg123_handle *mh, const unsigned char *in, size_t size)
Definition: libmpg123.c:873
#define a
Definition: ke_i.h:78
smooth NULL
Definition: ftsmooth.c:513
#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:217
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static int get_next_frame(mpg123_handle *mh)
Definition: libmpg123.c:592
#define debug(msg)
Definition: key_call.c:71
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
mhhandle
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:513
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
mhhandle
ininput buffer
sizenumber of input bytes
Returns
MPG123_OK or error/message code.

Definition at line 873 of file libmpg123.c.

Referenced by mpg123_decode().

874 {
875  if(mh == NULL) return MPG123_BAD_HANDLE;
876 #ifndef NO_FEEDER
877  if(size > 0)
878  {
879  if(in != NULL)
880  {
881  if(feed_more(mh, in, size) != 0) return MPG123_ERR;
882  else
883  {
884  /* The need for more data might have triggered an error.
885  This one is outdated now with the new data. */
886  if(mh->err == MPG123_ERR_READER) mh->err = MPG123_OK;
887 
888  return MPG123_OK;
889  }
890  }
891  else
892  {
893  mh->err = MPG123_NULL_BUFFER;
894  return MPG123_ERR;
895  }
896  }
897  return MPG123_OK;
898 #else
900  return MPG123_ERR;
901 #endif
902 }
smooth NULL
Definition: ftsmooth.c:513
#define feed_more
Definition: intsym.h:244
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
mhhandle
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:513
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.

Parameters
mhhandle
Returns
MPG123_OK or error/message code

Definition at line 791 of file libmpg123.c.

792 {
793  int b;
794  if(mh == NULL) return MPG123_BAD_HANDLE;
795 
796  mh->to_decode = mh->to_ignore = FALSE;
797  mh->buffer.fill = 0;
798 
799  b = get_next_frame(mh);
800  if(b < 0) return b;
801  debug1("got next frame, %i", mh->to_decode);
802 
803  /* mpg123_framebyframe_decode will return MPG123_OK with 0 bytes decoded if mh->to_decode is 0 */
804  if(!mh->to_decode)
805  return MPG123_OK;
806 
807  if(mh->new_format)
808  {
809  debug("notifiying new format");
810  mh->new_format = 0;
811  return MPG123_NEW_FORMAT;
812  }
813 
814  return MPG123_OK;
815 }
struct outbuffer buffer
Definition: frame.h:265
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:513
#define b
Definition: ke_i.h:79
static int get_next_frame(mpg123_handle *mh)
Definition: libmpg123.c:592
#define debug(msg)
Definition: key_call.c:71
#define debug1(s, a)
Definition: debug.h:52
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
mhhandle
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:513
unsigned long oldhead
Definition: frame.h:256
struct CFHEADER header
Definition: fdi.c:109
unsigned char * bsbuf
Definition: frame.h:252
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!

Parameters
mhhandle
Returns
byte offset in stream

Definition at line 1018 of file frame.c.

1019 {
1020  if(mh == NULL) return MPG123_ERR;
1021 
1022  return mh->input_offset;
1023 }
off_t input_offset
Definition: frame.h:216
smooth NULL
Definition: ftsmooth.c:513
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
mhhandle
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.

Parameters
mhhandle
fdfile descriptor
Returns
MPG123_OK on success

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.

Parameters
mhhandle
Returns
MPG123_OK on success

Definition at line 468 of file libmpg123.c.

469 {
470  if(mh == NULL) return MPG123_BAD_HANDLE;
471 
472  mpg123_close(mh);
473  return open_feed(mh);
474 }
#define open_feed
Definition: intsym.h:243
int attribute_align_arg mpg123_close(mpg123_handle *mh)
Definition: libmpg123.c:1602
smooth NULL
Definition: ftsmooth.c:513
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).

Parameters
mhhandle
iohandleyour handle
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
mhhandle
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 868 of file libmpg123.c.

869 {
870  return mpg123_decode(mh, NULL, 0, out, size, done);
871 }
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:918
smooth NULL
Definition: ftsmooth.c:513
static FILE * out
Definition: regtests2xml.c:44
GLsizeiptr size
Definition: glext.h:5919