Release 1.14
[openal-soft.git] / examples / alffmpeg.h
blob7fa88e6521bb9c2f776c246ce052e63aeaf9ada5
1 #ifndef ALFFMPEG_H
2 #define ALFFMPEG_H
4 #ifdef __cplusplus
5 extern "C" {
6 #endif /* __cplusplus */
8 #include <libavcodec/avcodec.h>
9 #include <libavformat/avformat.h>
11 /* Opaque handles to files and streams. Apps don't need to concern themselves
12 * with the internals */
13 typedef struct MyFile *FilePtr;
14 typedef struct MyStream *StreamPtr;
16 /* Opens a file with ffmpeg and sets up the streams' information */
17 FilePtr openAVFile(const char *fname);
19 /* Opens a named file image with ffmpeg and sets up the streams' information */
20 FilePtr openAVData(const char *name, char *buffer, size_t buffer_len);
22 /* Opens a named data stream with ffmpeg, using the specified data pointer and
23 * callbacks, and sets up the streams' information */
24 FilePtr openAVCustom(const char *name, void *user_data,
25 int (*read_packet)(void *user_data, uint8_t *buf, int buf_size),
26 int (*write_packet)(void *user_data, uint8_t *buf, int buf_size),
27 int64_t (*seek)(void *user_data, int64_t offset, int whence));
29 /* Closes/frees an opened file and any of its streams */
30 void closeAVFile(FilePtr file);
32 /* Reports certain information from the file, eg, the number of audio
33 * streams. Returns 0 on success. */
34 int getAVFileInfo(FilePtr file, int *numaudiostreams);
36 /* Retrieves a handle for the given audio stream number (generally 0, but some
37 * files can have multiple audio streams in one file). */
38 StreamPtr getAVAudioStream(FilePtr file, int streamnum);
40 /* Returns information about the given audio stream. Returns 0 on success. */
41 int getAVAudioInfo(StreamPtr stream, ALuint *rate, ALenum *channels, ALenum *type);
43 /* Returns a pointer to the next available packet of decoded audio. Any data
44 * from a previously-decoded packet is dropped. The size (in bytes) of the
45 * returned data buffer is stored in 'length', and the returned pointer is only
46 * valid until the next call to getAVAudioData or readAVAudioData. */
47 void *getAVAudioData(StreamPtr stream, size_t *length);
49 /* The "meat" function. Decodes audio and writes, at most, length bytes into
50 * the provided data buffer. Will only return less for end-of-stream or error
51 * conditions. Returns the number of bytes written. */
52 size_t readAVAudioData(StreamPtr stream, void *data, size_t length);
54 /* Decodes all remaining data from the stream and returns a buffer containing
55 * the audio data, with the size stored in 'length'. The returned pointer must
56 * be freed with a call to free(). Note that since this decodes the whole
57 * stream, using it on lengthy streams (eg, music) will use a lot of memory.
58 * Such streams are better handled using getAVAudioData or readAVAudioData to
59 * keep smaller chunks in memory at any given time. */
60 void *decodeAVAudioStream(StreamPtr stream, size_t *length);
62 #ifdef __cplusplus
64 #endif /* __cplusplus */
66 #endif /* ALFFMPEG_H */