Exemplo n.º 1
0
int attribute_align_arg mpg123_open_handle(mpg123_handle *mh, void *handle)
{
	struct wrap_data* ioh;

	if(mh == NULL) return MPG123_ERR;

	mpg123_close(mh);
	ioh = mh->wrapperdata;
	if(ioh != NULL && ioh->iotype == IO_HANDLE && ioh->r_h_read != NULL)
	{
		/* Wrap the custom handle into my handle. */
		int err;
		err = MPG123_LARGENAME(mpg123_replace_reader_handle)(mh, wrap_read, wrap_lseek, wrap_io_cleanup);
		if(err != MPG123_OK) return MPG123_ERR;

		ioh->handle = handle;
		/* No extra error handling, keep behaviour of the original open_handle. */
		return open_stream_handle(mh, ioh);
	}
	else
	{
		/* This is an error ... you need to prepare the I/O before using it. */
		mh->err = MPG123_BAD_CUSTOM_IO;
		return MPG123_ERR;
	}
}
Exemplo n.º 2
0
int attribute_align_arg mpg123_open_fd(mpg123_handle *mh, int fd)
{
	struct wrap_data* ioh;

	if(mh == NULL) return MPG123_ERR;

	mpg123_close(mh);
	ioh = mh->wrapperdata;
	if(ioh != NULL && ioh->iotype == IO_FD)
	{
		int err;
		err = MPG123_LARGENAME(mpg123_replace_reader_handle)(mh, wrap_read, wrap_lseek, wrap_io_cleanup);
		if(err != MPG123_OK) return MPG123_ERR;

		/* The above call implied mpg123_close() already */

		/* Store the real file descriptor inside the handle. */
		ioh->fd = fd;
		/* Initiate I/O operating on my handle now. */
		err = open_stream_handle(mh, ioh);
		if(err != MPG123_OK)
		{
			wrap_io_cleanup(ioh);
			return MPG123_ERR;
		}
		/* All fine... */
		return MPG123_OK;
	}
	else return MPG123_LARGENAME(mpg123_open_fd)(mh, fd);
}
Exemplo n.º 3
0
int attribute_align_arg mpg123_open_handle(mpg123_handle *mh, void *iohandle)
{
	if(mh == NULL) return MPG123_ERR;

	mpg123_close(mh);
	if(mh->rdat.r_read_handle == NULL)
	{
		mh->err = MPG123_BAD_CUSTOM_IO;
		return MPG123_ERR;
	}
	return open_stream_handle(mh, iohandle);
}
Exemplo n.º 4
0
/*
	The open routines always need to watch out for a prepared wrapper handle to use replaced normal I/O.
	Two cases to consider:
	1. Plain normal open using internal I/O.
	2. Client called mpg123_replace_reader() before.
	The second case needs hackery to activate the client I/O callbacks. For that, we create a custom I/O handle and use the guts of mpg123_open_fd() on it.
*/
int attribute_align_arg mpg123_open(mpg123_handle *mh, const char *path)
{
	struct wrap_data* ioh;

	if(mh == NULL) return MPG123_ERR;

	ioh = mh->wrapperdata;
	/* Mimic the use of mpg123_replace_reader() functions by lower levels...
	   IO_HANDLE is not valid here, though. Only IO_FD. */
	if(ioh != NULL && ioh->iotype == IO_FD)
	{
		int err;
		err = MPG123_LARGENAME(mpg123_replace_reader_handle)(mh, wrap_read, wrap_lseek, wrap_io_cleanup);
		if(err != MPG123_OK) return MPG123_ERR;

		/* The above call implied mpg123_close() already */
		/*
			I really need to open the file here... to be able to use the replacer handle I/O ...
			my_fd is used to indicate closing of the descriptor on cleanup.
		*/
		ioh->my_fd = compat_open(path, O_RDONLY|O_BINARY);
		if(ioh->my_fd < 0)
		{
			if(!(mh->p.flags & MPG123_QUIET)) error2("Cannot open file %s: %s", path, strerror(errno));

			mh->err = MPG123_BAD_FILE;
			return MPG123_ERR;
		}
		/* Store a copy of the descriptor where it is actually used. */
		ioh->fd = ioh->my_fd;
		/* Initiate I/O operating on my handle now. */
		err = open_stream_handle(mh, ioh);
		if(err != MPG123_OK)
		{
			wrap_io_cleanup(ioh);
			return MPG123_ERR;
		}
		/* All fine... */
		return MPG123_OK;
	}
	else return MPG123_LARGENAME(mpg123_open)(mh, path);
}