Blame include/oggz/oggz_io.h

Packit a38265
/*
Packit a38265
   Copyright (C) 2003 Commonwealth Scientific and Industrial Research
Packit a38265
   Organisation (CSIRO) Australia
Packit a38265
Packit a38265
   Redistribution and use in source and binary forms, with or without
Packit a38265
   modification, are permitted provided that the following conditions
Packit a38265
   are met:
Packit a38265
Packit a38265
   - Redistributions of source code must retain the above copyright
Packit a38265
   notice, this list of conditions and the following disclaimer.
Packit a38265
Packit a38265
   - Redistributions in binary form must reproduce the above copyright
Packit a38265
   notice, this list of conditions and the following disclaimer in the
Packit a38265
   documentation and/or other materials provided with the distribution.
Packit a38265
Packit a38265
   - Neither the name of CSIRO Australia nor the names of its
Packit a38265
   contributors may be used to endorse or promote products derived from
Packit a38265
   this software without specific prior written permission.
Packit a38265
Packit a38265
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit a38265
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit a38265
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
Packit a38265
   PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
Packit a38265
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Packit a38265
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Packit a38265
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit a38265
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit a38265
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit a38265
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit a38265
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit a38265
*/
Packit a38265
Packit a38265
#ifndef __OGGZ_IO_H__
Packit a38265
#define __OGGZ_IO_H__
Packit a38265
Packit a38265
/** \file
Packit a38265
 * Overriding the functions used for input and output of raw data.
Packit a38265
 *
Packit a38265
 * OggzIO provides a way of overriding the functions Oggz uses to access
Packit a38265
 * its raw input or output data. This is required in many situations where
Packit a38265
 * the raw stream cannot be accessed via stdio, but can be accessed by
Packit a38265
 * other means. This is typically useful within media frameworks, where
Packit a38265
 * accessing and moving around in the data is possible only using methods
Packit a38265
 * provided by the framework.
Packit a38265
 *
Packit a38265
 * The functions you provide for overriding IO will be used by Oggz
Packit a38265
 * whenever you call oggz_read() or oggz_write(). They will also be
Packit a38265
 * used repeatedly by Oggz when you call oggz_seek().
Packit a38265
 *
Packit a38265
 * \note Opening a file with oggz_open() or oggz_open_stdio() is equivalent
Packit a38265
 * to calling oggz_new() and setting stdio based functions for data IO.
Packit a38265
 */
Packit a38265
Packit a38265
/**
Packit a38265
 * This is the signature of a function which you provide for Oggz
Packit a38265
 * to call when it needs to acquire raw input data.
Packit a38265
 *
Packit a38265
 * \param user_handle A generic pointer you have provided earlier
Packit a38265
 * \param n The length in bytes that Oggz wants to read
Packit a38265
 * \param buf The buffer that you read data into
Packit a38265
 * \retval ">  0" The number of bytes successfully read into the buffer
Packit a38265
 * \retval 0 to indicate that there is no more data to read (End of file)
Packit a38265
 * \retval "<  0" An error condition
Packit a38265
 */
Packit a38265
typedef size_t (*OggzIORead) (void * user_handle, void * buf, size_t n);
Packit a38265
Packit a38265
/**
Packit a38265
 * This is the signature of a function which you provide for Oggz
Packit a38265
 * to call when it needs to output raw data.
Packit a38265
 *
Packit a38265
 * \param user_handle A generic pointer you have provided earlier
Packit a38265
 * \param n The length in bytes of the data
Packit a38265
 * \param buf A buffer containing data to write
Packit a38265
 * \retval ">= 0" The number of bytes successfully written (may be less than
Packit a38265
 * \a n if a write error has occurred)
Packit a38265
 * \retval "<  0" An error condition
Packit a38265
 */
Packit a38265
typedef size_t (*OggzIOWrite) (void * user_handle, void * buf, size_t n);
Packit a38265
Packit a38265
/**
Packit a38265
 * This is the signature of a function which you provide for Oggz
Packit a38265
 * to call when it needs to seek on the raw input or output data.
Packit a38265
 *
Packit a38265
 * \param user_handle A generic pointer you have provided earlier
Packit a38265
 * \param offset The offset in bytes to seek to
Packit a38265
 * \param whence SEEK_SET, SEEK_CUR or SEEK_END (as for stdio.h)
Packit a38265
 * \retval ">= 0" The offset seeked to
Packit a38265
 * \retval "<  0" An error condition
Packit a38265
 *
Packit a38265
 * \note If you provide an OggzIOSeek function, you MUST also provide
Packit a38265
 * an OggzIOTell function, or else all your seeks will fail.
Packit a38265
 */
Packit a38265
typedef int (*OggzIOSeek) (void * user_handle, long offset, int whence);
Packit a38265
Packit a38265
/**
Packit a38265
 * This is the signature of a function which you provide for Oggz
Packit a38265
 * to call when it needs to determine the current offset of the raw
Packit a38265
 * input or output data.
Packit a38265
 *
Packit a38265
 * \param user_handle A generic pointer you have provided earlier
Packit a38265
 * \retval ">= 0" The offset
Packit a38265
 * \retval "<  0" An error condition
Packit a38265
 */
Packit a38265
typedef long (*OggzIOTell) (void * user_handle);
Packit a38265
Packit a38265
/**
Packit a38265
 * This is the signature of a function which you provide for Oggz
Packit a38265
 * to call when it needs to flush the output data. The behaviour
Packit a38265
 * of this function is similar to that of fflush() in stdio.
Packit a38265
 *
Packit a38265
 * \param user_handle A generic pointer you have provided earlier
Packit a38265
 * \retval 0 Success
Packit a38265
 * \retval "<  0" An error condition
Packit a38265
 */
Packit a38265
typedef int (*OggzIOFlush) (void * user_handle);
Packit a38265
Packit a38265
Packit a38265
/**
Packit a38265
 * Set a function for Oggz to call when it needs to read input data.
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \param read Your reading function
Packit a38265
 * \param user_handle Any arbitrary data you wish to pass to the function
Packit a38265
 * \retval 0 Success
Packit a38265
 * \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ; \a oggz not
Packit a38265
 * open for reading.
Packit a38265
 * \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
Packit a38265
 */
Packit a38265
int oggz_io_set_read (OGGZ * oggz, OggzIORead read, void * user_handle);
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the user_handle associated with the function you have provided
Packit a38265
 * for reading input data.
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \returns the associated user_handle
Packit a38265
 */
Packit a38265
void * oggz_io_get_read_user_handle (OGGZ * oggz);
Packit a38265
Packit a38265
/**
Packit a38265
 * Set a function for Oggz to call when it needs to write output data.
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \param write Your writing function
Packit a38265
 * \param user_handle Any arbitrary data you wish to pass to the function
Packit a38265
 * \retval 0 Success
Packit a38265
 * \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ; \a oggz not
Packit a38265
 * open for writing.
Packit a38265
 * \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
Packit a38265
 */
Packit a38265
int oggz_io_set_write (OGGZ * oggz, OggzIOWrite write, void * user_handle);
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the user_handle associated with the function you have provided
Packit a38265
 * for writing output data.
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \returns the associated user_handle
Packit a38265
 */
Packit a38265
void * oggz_io_get_write_user_handle (OGGZ * oggz);
Packit a38265
Packit a38265
/**
Packit a38265
 * Set a function for Oggz to call when it needs to seek on its raw data.
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \param seek Your seeking function
Packit a38265
 * \param user_handle Any arbitrary data you wish to pass to the function
Packit a38265
 * \retval 0 Success
Packit a38265
 * \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
Packit a38265
 * \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
Packit a38265
 *
Packit a38265
 * \note If you provide an OggzIOSeek function, you MUST also provide
Packit a38265
 * an OggzIOTell function, or else all your seeks will fail.
Packit a38265
 */
Packit a38265
int oggz_io_set_seek (OGGZ * oggz, OggzIOSeek seek, void * user_handle);
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the user_handle associated with the function you have provided
Packit a38265
 * for seeking on input or output data.
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \returns the associated user_handle
Packit a38265
 */
Packit a38265
void * oggz_io_get_seek_user_handle (OGGZ * oggz);
Packit a38265
Packit a38265
/**
Packit a38265
 * Set a function for Oggz to call when it needs to determine the offset
Packit a38265
 * within its input data (if OGGZ_READ) or output data (if OGGZ_WRITE).
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \param tell Your tell function
Packit a38265
 * \param user_handle Any arbitrary data you wish to pass to the function
Packit a38265
 * \retval 0 Success
Packit a38265
 * \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
Packit a38265
 * \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
Packit a38265
 */
Packit a38265
int oggz_io_set_tell (OGGZ * oggz, OggzIOTell tell, void * user_handle);
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the user_handle associated with the function you have provided
Packit a38265
 * for determining the current offset in input or output data.
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \returns the associated user_handle
Packit a38265
 */
Packit a38265
void * oggz_io_get_tell_user_handle (OGGZ * oggz);
Packit a38265
Packit a38265
/**
Packit a38265
 * Set a function for Oggz to call when it needs to flush its output. The
Packit a38265
 * meaning of this is similar to that of fflush() in stdio.
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \param flush Your flushing function
Packit a38265
 * \param user_handle Any arbitrary data you wish to pass to the function
Packit a38265
 * \retval 0 Success
Packit a38265
 * \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ; \a oggz not
Packit a38265
 * open for writing.
Packit a38265
 * \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
Packit a38265
 */
Packit a38265
int oggz_io_set_flush (OGGZ * oggz, OggzIOFlush flush, void * user_handle);
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the user_handle associated with the function you have provided
Packit a38265
 * for flushing output.
Packit a38265
 *
Packit a38265
 * \param oggz An OGGZ handle
Packit a38265
 * \returns the associated user_handle
Packit a38265
 */
Packit a38265
void * oggz_io_get_flush_user_handle (OGGZ * oggz);
Packit a38265
Packit a38265
#endif /* __OGGZ_IO_H__ */