alffmpeg.h 2.8 KB

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