FLAC  1.3.4
Free Lossless Audio Codec
Classes | Typedefs | Variables
FLAC/callback.h: I/O callback structures

Classes

struct  FLAC__IOCallbacks
 

Typedefs

typedef void * FLAC__IOHandle
 
typedef size_t(* FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
 
typedef size_t(* FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
 
typedef int(* FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence)
 
typedef FLAC__int64(* FLAC__IOCallback_Tell) (FLAC__IOHandle handle)
 
typedef int(* FLAC__IOCallback_Eof) (FLAC__IOHandle handle)
 
typedef int(* FLAC__IOCallback_Close) (FLAC__IOHandle handle)
 

Variables

FLAC__IOCallback_Read FLAC__IOCallbacks::read
 
FLAC__IOCallback_Write FLAC__IOCallbacks::write
 
FLAC__IOCallback_Seek FLAC__IOCallbacks::seek
 
FLAC__IOCallback_Tell FLAC__IOCallbacks::tell
 
FLAC__IOCallback_Eof FLAC__IOCallbacks::eof
 
FLAC__IOCallback_Close FLAC__IOCallbacks::close
 

Detailed Description

This module defines the structures for describing I/O callbacks to the other FLAC interfaces.

The purpose of the I/O callback functions is to create a common way for the metadata interfaces to handle I/O.

Originally the metadata interfaces required filenames as the way of specifying FLAC files to operate on. This is problematic in some environments so there is an additional option to specify a set of callbacks for doing I/O on the FLAC file, instead of the filename.

In addition to the callbacks, a FLAC__IOHandle type is defined as an opaque structure for a data source.

The callback function prototypes are similar (but not identical) to the stdio functions fread, fwrite, fseek, ftell, feof, and fclose. If you use stdio streams to implement the callbacks, you can pass fread, fwrite, and fclose anywhere a FLAC__IOCallback_Read, FLAC__IOCallback_Write, or FLAC__IOCallback_Close is required, and a FILE* anywhere a FLAC__IOHandle is required.

Warning
You generally CANNOT directly use fseek or ftell for FLAC__IOCallback_Seek or FLAC__IOCallback_Tell since on most systems these use 32-bit offsets and FLAC requires 64-bit offsets to deal with large files. You will have to find an equivalent function (e.g. ftello), or write a wrapper. The same is true for feof() since this is usually implemented as a macro, not as a function whose address can be taken.

Typedef Documentation

◆ FLAC__IOHandle

typedef void* FLAC__IOHandle

This is the opaque handle type used by the callbacks. Typically this is a FILE* or address of a file descriptor.

◆ FLAC__IOCallback_Read

typedef size_t(* FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)

Signature for the read callback. The signature and semantics match POSIX fread() implementations and can generally be used interchangeably.

Parameters
ptrThe address of the read buffer.
sizeThe size of the records to be read.
nmembThe number of records to be read.
handleThe handle to the data source.
Return values
size_tThe number of records read.

◆ FLAC__IOCallback_Write

typedef size_t(* FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)

Signature for the write callback. The signature and semantics match POSIX fwrite() implementations and can generally be used interchangeably.

Parameters
ptrThe address of the write buffer.
sizeThe size of the records to be written.
nmembThe number of records to be written.
handleThe handle to the data source.
Return values
size_tThe number of records written.

◆ FLAC__IOCallback_Seek

typedef int(* FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence)

Signature for the seek callback. The signature and semantics mostly match POSIX fseek() WITH ONE IMPORTANT EXCEPTION: the offset is a 64-bit type whereas fseek() is generally 'long' and 32-bits wide.

Parameters
handleThe handle to the data source.
offsetThe new position, relative to whence
whenceSEEK_SET, SEEK_CUR, or SEEK_END
Return values
int0 on success, -1 on error.

◆ FLAC__IOCallback_Tell

typedef FLAC__int64(* FLAC__IOCallback_Tell) (FLAC__IOHandle handle)

Signature for the tell callback. The signature and semantics mostly match POSIX ftell() WITH ONE IMPORTANT EXCEPTION: the offset is a 64-bit type whereas ftell() is generally 'long' and 32-bits wide.

Parameters
handleThe handle to the data source.
Return values
FLAC__int64The current position on success, -1 on error.

◆ FLAC__IOCallback_Eof

typedef int(* FLAC__IOCallback_Eof) (FLAC__IOHandle handle)

Signature for the EOF callback. The signature and semantics mostly match POSIX feof() but WATCHOUT: on many systems, feof() is a macro, so in this case a wrapper function must be provided instead.

Parameters
handleThe handle to the data source.
Return values
int0 if not at end of file, nonzero if at end of file.

◆ FLAC__IOCallback_Close

typedef int(* FLAC__IOCallback_Close) (FLAC__IOHandle handle)

Signature for the close callback. The signature and semantics match POSIX fclose() implementations and can generally be used interchangeably.

Parameters
handleThe handle to the data source.
Return values
int0 on success, EOF on error.