ReactOS  r73918
mpg123 low level I/O


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.

Definition at line 570 of file libmpg123.c.

571 {
572  /* Try to be helpful and never return zero output block size. */
573  if(mh != NULL && mh->outblock > 0) return mh->outblock;
574  else return mpg123_safe_buffer();
575 }
#define NULL
Definition: mystdio.h:57
size_t attribute_align_arg mpg123_safe_buffer(void)
Definition: libmpg123.c:564
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.

datapointer to user buffer
sizeof buffer in bytes
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-> = 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:264
#define debug2(s, a, b)
Definition: debug.h:46
#define NULL
Definition: mystdio.h:57
unsigned long size_p
Definition: compat.h:117
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:116
#define FALSE
Definition: numbers.c:16
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().

Definition at line 584 of file lfs_wrap.c.

585 {
586  struct wrap_data* ioh;
588  if(mh == NULL) return MPG123_ERR;
590  mpg123_close(mh);
591  ioh = wrap_get(mh);
592  if(ioh == NULL) return MPG123_ERR;
594  /* If both callbacks are NULL, switch totally to internal I/O, else just use fallback for at most half of them. */
595  if(r_read == NULL && r_lseek == NULL)
596  {
597  /* Only the type is actually important to disable the code. */
598  ioh->iotype = 0;
599  ioh->fd = -1;
600  ioh->r_read = NULL;
601  ioh->r_lseek = NULL;
602  }
603  else
604  {
605  ioh->iotype = IO_FD;
606  ioh->fd = -1; /* On next mpg123_open_fd(), this gets a value. */
607  ioh->r_read = r_read != NULL ? r_read : fallback_read;
608  ioh->r_lseek = r_lseek != NULL ? r_lseek : fallback_lseek;
609  }
611  /* The real reader replacement will happen while opening. */
612  return MPG123_OK;
613 }
long(* r_lseek)(int, long, int)
Definition: lfs_wrap.c:86
#define NULL
Definition: mystdio.h:57
MPG123_EXPORT int mpg123_close(mpg123_handle *mh)
Definition: libmpg123.c:1557
static ssize_t fallback_read(int fd, void *buf, size_t count)
Definition: lfs_wrap.c:562
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:567
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.

r_readThe callback for reading (behaviour like posix read).
r_lseekThe callback 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).

Definition at line 615 of file lfs_wrap.c.

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

616 {
617  struct wrap_data* ioh;
619  if(mh == NULL) return MPG123_ERR;
621  mpg123_close(mh);
622  ioh = wrap_get(mh);
623  if(ioh == NULL) return MPG123_ERR;
625  ioh->iotype = IO_HANDLE;
626  ioh->handle = NULL;
627  ioh->r_h_read = r_read;
628  ioh->r_h_lseek = r_lseek;
629  ioh->h_cleanup = cleanup;
631  /* The real reader replacement will happen while opening. */
632  return MPG123_OK;
633 }
#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
#define NULL
Definition: mystdio.h:57
void(* h_cleanup)(void *)
Definition: lfs_wrap.c:91
MPG123_EXPORT int mpg123_close(mpg123_handle *mh)
Definition: libmpg123.c:1557
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