ReactOS  r76032
mpg123 low level I/O

Functions

MPG123_EXPORT int mpg123_replace_buffer (mpg123_handle *mh, unsigned char *data, size_t size)
 
MPG123_EXPORT size_t mpg123_outblock (mpg123_handle *mh)
 
MPG123_EXPORT int mpg123_replace_reader (mpg123_handle *mh, ssize_t(*r_read)(int, void *, size_t), off_t(*r_lseek)(int, off_t, int))
 
MPG123_EXPORT int mpg123_replace_reader_handle (mpg123_handle *mh, ssize_t(*r_read)(void *, void *, size_t), off_t(*r_lseek)(void *, off_t, int), void(*cleanup)(void *))
 

Detailed Description

You may want to do tricky stuff with I/O that does not work with mpg123's default file access or you want to make it decode into your own pocket...

Function Documentation

MPG123_EXPORT size_t mpg123_outblock ( mpg123_handle mh)

The max size of one frame's decoded output with current settings. Use that to determine an appropriate minimum buffer size for decoding one frame.

Parameters
mhhandle
Returns
maximum decoded data size in bytes

Definition at line 583 of file libmpg123.c.

584 {
585  /* Try to be helpful and never return zero output block size. */
586  if(mh != NULL && mh->outblock > 0) return mh->outblock;
587  else return mpg123_safe_buffer();
588 }
smooth NULL
Definition: ftsmooth.c:557
size_t attribute_align_arg mpg123_safe_buffer(void)
Definition: libmpg123.c:577
MPG123_EXPORT int mpg123_replace_buffer ( mpg123_handle mh,
unsigned char data,
size_t  size 
)

Replace default internal buffer with user-supplied buffer. Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio. Note that the required buffer size could be bigger than expected from output encoding if libmpg123 has to convert from primary decoder output (p.ex. 32 bit storage for 24 bit output).

Parameters
mhhandle
datapointer to user buffer
sizeof buffer in bytes
Returns
MPG123_OK on success

Definition at line 213 of file frame.c.

214 {
215  debug2("replace buffer with %p size %"SIZE_P, data, (size_p)size);
216  if(mh == NULL) return MPG123_BAD_HANDLE;
217  /* Will accept any size, the error comes later... */
218  if(data == NULL)
219  {
220  mh->err = MPG123_BAD_BUFFER;
221  return MPG123_ERR;
222  }
223  if(mh->buffer.rdata != NULL) free(mh->buffer.rdata);
224  mh->own_buffer = FALSE;
225  mh->buffer.rdata = NULL;
226  mh->buffer.data = data;
227  mh->buffer.size = size;
228  mh->buffer.fill = 0;
229  return MPG123_OK;
230 }
#define free
Definition: debug_ros.c:5
struct outbuffer buffer
Definition: frame.h:265
#define debug2(s, a, b)
Definition: debug.h:53
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:557
unsigned long size_p
Definition: compat.h:138
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
#define SIZE_P
Definition: compat.h:137
MPG123_EXPORT int mpg123_replace_reader ( mpg123_handle mh,
ssize_t(*)(int, void *, size_t r_read,
off_t(*)(int, off_t, int r_lseek 
)

Replace low-level stream access functions; read and lseek as known in POSIX. You can use this to make any fancy file opening/closing yourself, using mpg123_open_fd() to set the file descriptor for your read/lseek (doesn't need to be a "real" file descriptor...). Setting a function to NULL means that the default internal read is used (active from next mpg123_open call on). Note: As it would be troublesome to mess with this while having a file open, this implies mpg123_close().

Parameters
mhhandle
r_readcallback for reading (behaviour like POSIX read)
r_lseekcallback for seeking (like POSIX lseek)
Returns
MPG123_OK on success

Definition at line 601 of file lfs_wrap.c.

602 {
603  struct wrap_data* ioh;
604 
605  if(mh == NULL) return MPG123_ERR;
606 
607  mpg123_close(mh);
608  ioh = wrap_get(mh);
609  if(ioh == NULL) return MPG123_ERR;
610 
611  /* If both callbacks are NULL, switch totally to internal I/O, else just use fallback for at most half of them. */
612  if(r_read == NULL && r_lseek == NULL)
613  {
614  /* Only the type is actually important to disable the code. */
615  ioh->iotype = 0;
616  ioh->fd = -1;
617  ioh->r_read = NULL;
618  ioh->r_lseek = NULL;
619  }
620  else
621  {
622  ioh->iotype = IO_FD;
623  ioh->fd = -1; /* On next mpg123_open_fd(), this gets a value. */
624  ioh->r_read = r_read != NULL ? r_read : fallback_read;
625  ioh->r_lseek = r_lseek != NULL ? r_lseek : fallback_lseek;
626  }
627 
628  /* The real reader replacement will happen while opening. */
629  return MPG123_OK;
630 }
long(* r_lseek)(int, long, int)
Definition: lfs_wrap.c:86
MPG123_EXPORT int mpg123_close(mpg123_handle *mh)
Definition: libmpg123.c:1602
static ssize_t fallback_read(int fd, void *buf, size_t count)
Definition: lfs_wrap.c:579
smooth NULL
Definition: ftsmooth.c:557
ssize_t(* r_read)(int, void *, size_t)
Definition: lfs_wrap.c:85
int fd
Definition: lfs_wrap.c:82
int iotype
Definition: lfs_wrap.c:80
#define IO_FD
Definition: lfs_wrap.c:72
static struct wrap_data * wrap_get(mpg123_handle *mh)
Definition: lfs_wrap.c:126
static long fallback_lseek(int fd, long offset, int whence)
Definition: lfs_wrap.c:584
MPG123_EXPORT int mpg123_replace_reader_handle ( mpg123_handle mh,
ssize_t(*)(void *, void *, size_t r_read,
off_t(*)(void *, off_t, int r_lseek,
void(*)(void *)  cleanup 
)

Replace I/O functions with your own ones operating on some kind of handle instead of integer descriptors. The handle is a void pointer, so you can pass any data you want... mpg123_open_handle() is the call you make to use the I/O defined here. There is no fallback to internal read/seek here. Note: As it would be troublesome to mess with this while having a file open, this mpg123_close() is implied here.

Parameters
mhhandle
r_readcallback for reading (behaviour like POSIX read)
r_lseekcallback for seeking (like POSIX lseek)
cleanupA callback to clean up an I/O handle on mpg123_close, can be NULL for none (you take care of cleaning your handles).
Returns
MPG123_OK on success

Definition at line 632 of file lfs_wrap.c.

Referenced by mpg123_open(), mpg123_open_fd(), and mpg123_open_handle().

633 {
634  struct wrap_data* ioh;
635 
636  if(mh == NULL) return MPG123_ERR;
637 
638  mpg123_close(mh);
639  ioh = wrap_get(mh);
640  if(ioh == NULL) return MPG123_ERR;
641 
642  ioh->iotype = IO_HANDLE;
643  ioh->handle = NULL;
644  ioh->r_h_read = r_read;
645  ioh->r_h_lseek = r_lseek;
646  ioh->h_cleanup = cleanup;
647 
648  /* The real reader replacement will happen while opening. */
649  return MPG123_OK;
650 }
#define IO_HANDLE
Definition: lfs_wrap.c:73
long(* r_lseek)(int, long, int)
Definition: lfs_wrap.c:86
long(* r_h_lseek)(void *, long, int)
Definition: lfs_wrap.c:90
void(* h_cleanup)(void *)
Definition: lfs_wrap.c:91
MPG123_EXPORT int mpg123_close(mpg123_handle *mh)
Definition: libmpg123.c:1602
smooth NULL
Definition: ftsmooth.c:557
ssize_t(* r_h_read)(void *, void *, size_t)
Definition: lfs_wrap.c:89
ssize_t(* r_read)(int, void *, size_t)
Definition: lfs_wrap.c:85
void * handle
Definition: lfs_wrap.c:88
int iotype
Definition: lfs_wrap.c:80
char * cleanup(char *str)
Definition: wpickclick.c:99
static struct wrap_data * wrap_get(mpg123_handle *mh)
Definition: lfs_wrap.c:126