Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.         libmpg123: MPEG Audio Decoder library (version 1.9.0)
  3.  
  4.         copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
  5.         see COPYING and AUTHORS files in distribution or http://mpg123.org
  6. */
  7.  
  8. #ifndef MPG123_LIB_H
  9. #define MPG123_LIB_H
  10.  
  11. /** \file mpg123.h The header file for the libmpg123 MPEG Audio decoder */
  12.  
  13. /* These aren't actually in use... seems to work without using libtool. */
  14. #ifdef BUILD_MPG123_DLL
  15. /* The dll exports. */
  16. #define EXPORT __declspec(dllexport)
  17. #else
  18. #ifdef LINK_MPG123_DLL
  19. /* The exe imports. */
  20. #define EXPORT __declspec(dllimport)
  21. #else
  22. /* Nothing on normal/UNIX builds */
  23. #define EXPORT
  24. #endif
  25. #endif
  26.  
  27. #ifndef MPG123_NO_CONFIGURE /* Enable use of this file without configure. */
  28. #include <stdlib.h>
  29. #include <sys/types.h>
  30.  
  31. #if 0 /* If we need trickery for large file support. */
  32.  
  33. /* Check for compiling programs agains this libmpg123. */
  34. #if (defined _FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS+0 == )
  35. /* ...all is fine, having enabled large file support and also the correct sort of which. */
  36. #else
  37. #error "Mismatch in large file setup! Enable/disable large file support appropriately to use libmpg123."
  38. #endif
  39.  
  40. /* Redefine names of functions dealing with file and file offsets
  41.    ...everything handling off_t, for example, which can be 32 or 64 bits. */
  42.  
  43. #define mpg123_open                 mpg123_open
  44. #define mpg123_open_fd           mpg123_open_fd
  45. #define mpg123_decode_frame mpg123_decode_frame
  46. #define mpg123_tell                 mpg123_tell
  47. #define mpg123_tellframe       mpg123_tellframe
  48. #define mpg123_tell_stream   mpg123_tell_stream
  49. #define mpg123_seek                 mpg123_seek
  50. #define mpg123_feedseek         mpg123_feedseek
  51. #define mpg123_seek_frame     mpg123_seek_frame
  52. #define mpg123_timeframe       mpg123_timeframe
  53. #define mpg123_index               mpg123_index
  54. #define mpg123_position         mpg123_position
  55. #define mpg123_length             mpg123_length
  56. #define mpg123_set_filesize mpg123_set_filesize
  57.  
  58. #endif /* LARGEFILE_SWITCH */
  59.  
  60. #endif /* MPG123_NO_CONFIGURE */
  61.  
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65.  
  66. /** \defgroup mpg123_init mpg123 library and handle setup
  67.  *
  68.  * Functions to initialise and shutdown the mpg123 library and handles.
  69.  * The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-)
  70.  * Tip: Use a RVA setting...
  71.  *
  72.  * @{
  73.  */
  74.  
  75. /** Opaque structure for the libmpg123 decoder handle. */
  76. struct mpg123_handle_struct;
  77.  
  78. /** Opaque structure for the libmpg123 decoder handle.
  79.  *  Most functions take a pointer to a mpg123_handle as first argument and operate on its data in an object-oriented manner.
  80.  */
  81. typedef struct mpg123_handle_struct mpg123_handle;
  82.  
  83. /** Function to initialise the mpg123 library.
  84.  *      This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library.
  85.  *
  86.  *      \return MPG123_OK if successful, otherwise an error number.
  87.  */
  88. EXPORT int  mpg123_init(void);
  89.  
  90. /** Function to close down the mpg123 library.
  91.  *      This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. */
  92. EXPORT void mpg123_exit(void);
  93.  
  94. /** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()).
  95.  *  and optional retrieval of an error code to feed to mpg123_plain_strerror().
  96.  *  Optional means: Any of or both the parameters may be NULL.
  97.  *
  98.  *  \return Non-NULL pointer when successful.
  99.  */
  100. EXPORT mpg123_handle *mpg123_new(const char* decoder, int *error);
  101.  
  102. /** Delete handle, mh is either a valid mpg123 handle or NULL. */
  103. EXPORT void mpg123_delete(mpg123_handle *mh);
  104.  
  105. /** Enumeration of the parameters types that it is possible to set/get. */
  106. enum mpg123_parms
  107. {
  108.         MPG123_VERBOSE,        /**< set verbosity value for enabling messages to stderr, >= 0 makes sense (integer) */
  109.         MPG123_FLAGS,          /**< set all flags, p.ex val = MPG123_GAPLESS|MPG123_MONO_MIX (integer) */
  110.         MPG123_ADD_FLAGS,      /**< add some flags (integer) */
  111.         MPG123_FORCE_RATE,     /**< when value > 0, force output rate to that value (integer) */
  112.         MPG123_DOWN_SAMPLE,    /**< 0=native rate, 1=half rate, 2=quarter rate (integer) */
  113.         MPG123_RVA,            /**< one of the RVA choices above (integer) */
  114.         MPG123_DOWNSPEED,      /**< play a frame N times (integer) */
  115.         MPG123_UPSPEED,        /**< play every Nth frame (integer) */
  116.         MPG123_START_FRAME,    /**< start with this frame (skip frames before that, integer) */
  117.         MPG123_DECODE_FRAMES,  /**< decode only this number of frames (integer) */
  118.         MPG123_ICY_INTERVAL,   /**< stream contains ICY metadata with this interval (integer) */
  119.         MPG123_OUTSCALE,       /**< the scale for output samples (amplitude - integer or float according to mpg123 output format, normally integer) */
  120.         MPG123_TIMEOUT,        /**< timeout for reading from a stream (not supported on win32, integer) */
  121.         MPG123_REMOVE_FLAGS,   /**< remove some flags (inverse of MPG123_ADD_FLAGS, integer) */
  122.         MPG123_RESYNC_LIMIT,   /**< Try resync on frame parsing for that many bytes or until end of stream (<0 ... integer). */
  123.         MPG123_INDEX_SIZE      /**< Set the frame index size (if supported). Values <0 mean that the index is allowed to grow dynamically in these steps (in positive direction, of course) -- Use this when you really want a full index with every individual frame. */
  124.         ,MPG123_PREFRAMES /**< Decode/ignore that many frames in advance for layer 3. This is needed to fill bit reservoir after seeking, for example (but also at least one frame in advance is needed to have all "normal" data for layer 3). Give a positive integer value, please.*/
  125. };
  126.  
  127. /** Flag bits for MPG123_FLAGS, use the usual binary or to combine. */
  128. enum mpg123_param_flags
  129. {
  130.          MPG123_FORCE_MONO   = 0x7  /**<     0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. */
  131.         ,MPG123_MONO_LEFT    = 0x1  /**<     0001 Force playback of left channel only.  */
  132.         ,MPG123_MONO_RIGHT   = 0x2  /**<     0010 Force playback of right channel only. */
  133.         ,MPG123_MONO_MIX     = 0x4  /**<     0100 Force playback of mixed mono.         */
  134.         ,MPG123_FORCE_STEREO = 0x8  /**<     1000 Force stereo output.                  */
  135.         ,MPG123_FORCE_8BIT   = 0x10 /**< 00010000 Force 8bit formats.                   */
  136.         ,MPG123_QUIET        = 0x20 /**< 00100000 Suppress any printouts (overrules verbose).                    */
  137.         ,MPG123_GAPLESS      = 0x40 /**< 01000000 Enable gapless decoding (default on if libmpg123 has support). */
  138.         ,MPG123_NO_RESYNC    = 0x80 /**< 10000000 Disable resync stream after error.                             */
  139.         ,MPG123_SEEKBUFFER   = 0x100 /**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). */
  140.         ,MPG123_FUZZY        = 0x200 /**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) */
  141.         ,MPG123_FORCE_FLOAT  = 0x400 /**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). */
  142.         ,MPG123_PLAIN_ID3TEXT = 0x800 /**< 100000000000 Do not translate ID3 text data to UTF-8. ID3 strings will contain the raw text data, with the first byte containing the ID3 encoding code. */
  143. };
  144.  
  145. /** choices for MPG123_RVA */
  146. enum mpg123_param_rva
  147. {
  148.          MPG123_RVA_OFF   = 0 /**< RVA disabled (default).   */
  149.         ,MPG123_RVA_MIX   = 1 /**< Use mix/track/radio gain. */
  150.         ,MPG123_RVA_ALBUM = 2 /**< Use album/audiophile gain */
  151.         ,MPG123_RVA_MAX   = MPG123_RVA_ALBUM /**< The maximum RVA code, may increase in future. */
  152. };
  153.  
  154. /* TODO: Assess the possibilities and troubles of changing parameters during playback. */
  155.  
  156. /** Set a specific parameter, for a specific mpg123_handle, using a parameter
  157.  *  type key chosen from the mpg123_parms enumeration, to the specified value. */
  158. EXPORT int mpg123_param(mpg123_handle *mh, enum mpg123_parms type, long value, double fvalue);
  159.  
  160. /** Get a specific parameter, for a specific mpg123_handle.
  161.  *  See the mpg123_parms enumeration for a list of available parameters. */
  162. EXPORT int mpg123_getparam(mpg123_handle *mh, enum mpg123_parms type, long *val, double *fval);
  163.  
  164. /* @} */
  165.  
  166.  
  167. /** \defgroup mpg123_error mpg123 error handling
  168.  *
  169.  * Functions to get text version of the error numbers and an enumeration
  170.  * of the error codes returned by libmpg123.
  171.  *
  172.  * Most functions operating on a mpg123_handle simply return MPG123_OK on success and MPG123_ERR on failure (setting the internal error variable of the handle to the specific error code).
  173.  * Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE (please read up on these on how to react!).
  174.  * The positive range of return values is used for "useful" values when appropriate.
  175.  *
  176.  * @{
  177.  */
  178.  
  179. /** Enumeration of the message and error codes and returned by libmpg123 functions. */
  180. enum mpg123_errors
  181. {
  182.         MPG123_DONE=-12,        /**< Message: Track ended. Stop decoding. */
  183.         MPG123_NEW_FORMAT=-11/**< Message: Output format will be different on next call. Note that some libmpg123 versions between 1.4.3 and 1.8.0 insist on you calling mpg123_getformat() after getting this message code. Newer verisons behave like advertised: You have the chance to call mpg123_getformat(), but you can also just continue decoding and get your data. */
  184.         MPG123_NEED_MORE=-10,   /**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). */
  185.         MPG123_ERR=-1,                  /**< Generic Error */
  186.         MPG123_OK=0,                    /**< Success */
  187.         MPG123_BAD_OUTFORMAT,   /**< Unable to set up output format! */
  188.         MPG123_BAD_CHANNEL,             /**< Invalid channel number specified. */
  189.         MPG123_BAD_RATE,                /**< Invalid sample rate specified.  */
  190.         MPG123_ERR_16TO8TABLE,  /**< Unable to allocate memory for 16 to 8 converter table! */
  191.         MPG123_BAD_PARAM,               /**< Bad parameter id! */
  192.         MPG123_BAD_BUFFER,              /**< Bad buffer given -- invalid pointer or too small size. */
  193.         MPG123_OUT_OF_MEM,              /**< Out of memory -- some malloc() failed. */
  194.         MPG123_NOT_INITIALIZED, /**< You didn't initialize the library! */
  195.         MPG123_BAD_DECODER,             /**< Invalid decoder choice. */
  196.         MPG123_BAD_HANDLE,              /**< Invalid mpg123 handle. */
  197.         MPG123_NO_BUFFERS,              /**< Unable to initialize frame buffers (out of memory?). */
  198.         MPG123_BAD_RVA,                 /**< Invalid RVA mode. */
  199.         MPG123_NO_GAPLESS,              /**< This build doesn't support gapless decoding. */
  200.         MPG123_NO_SPACE,                /**< Not enough buffer space. */
  201.         MPG123_BAD_TYPES,               /**< Incompatible numeric data types. */
  202.         MPG123_BAD_BAND,                /**< Bad equalizer band. */
  203.         MPG123_ERR_NULL,                /**< Null pointer given where valid storage address needed. */
  204.         MPG123_ERR_READER,              /**< Error reading the stream. */
  205.         MPG123_NO_SEEK_FROM_END,/**< Cannot seek from end (end is not known). */
  206.         MPG123_BAD_WHENCE,              /**< Invalid 'whence' for seek function.*/
  207.         MPG123_NO_TIMEOUT,              /**< Build does not support stream timeouts. */
  208.         MPG123_BAD_FILE,                /**< File access error. */
  209.         MPG123_NO_SEEK,                 /**< Seek not supported by stream. */
  210.         MPG123_NO_READER,               /**< No stream opened. */
  211.         MPG123_BAD_PARS,                /**< Bad parameter handle. */
  212.         MPG123_BAD_INDEX_PAR,   /**< Bad parameters to mpg123_index() */
  213.         MPG123_OUT_OF_SYNC,     /**< Lost track in bytestream and did not try to resync. */
  214.         MPG123_RESYNC_FAIL,     /**< Resync failed to find valid MPEG data. */
  215.         MPG123_NO_8BIT, /**< No 8bit encoding possible. */
  216.         MPG123_BAD_ALIGN,       /**< Stack aligmnent error */
  217.         MPG123_NULL_BUFFER,     /**< NULL input buffer with non-zero size... */
  218.         MPG123_NO_RELSEEK,      /**< Relative seek not possible (screwed up file offset) */
  219.         MPG123_NULL_POINTER, /**< You gave a null pointer somewhere where you shouldn't have. */
  220.         MPG123_BAD_KEY, /**< Bad key value given. */
  221.         MPG123_NO_INDEX,        /**< No frame index in this build. */
  222.         MPG123_INDEX_FAIL,      /**< Something with frame index went wrong. */
  223.         MPG123_BAD_DECODER_SETUP,       /**< Something prevents a proper decoder setup */
  224.         MPG123_MISSING_FEATURE  /**< This feature has not been built into libmpg123. */
  225.         ,MPG123_BAD_VALUE /**< A bad value has been given, somewhere. */
  226.         ,MPG123_LSEEK_FAILED /**< Low-level seek failed. */
  227. };
  228.  
  229. /** Return a string describing that error errcode means. */
  230. EXPORT const char* mpg123_plain_strerror(int errcode);
  231.  
  232. /** Give string describing what error has occured in the context of handle mh.
  233.  *  When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via
  234.  *  char *errmsg = mpg123_strerror(mh)
  235.  *  This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE. */
  236. EXPORT const char* mpg123_strerror(mpg123_handle *mh);
  237.  
  238. /** Return the plain errcode intead of a string. */
  239. EXPORT int mpg123_errcode(mpg123_handle *mh);
  240.  
  241. /*@}*/
  242.  
  243.  
  244. /** \defgroup mpg123_decoder mpg123 decoder selection
  245.  *
  246.  * Functions to list and select the available decoders.
  247.  * Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is).
  248.  *
  249.  * @{
  250.  */
  251.  
  252. /** Return a NULL-terminated array of generally available decoder names (plain 8bit ASCII). */
  253. EXPORT const char **mpg123_decoders();
  254.  
  255. /** Return a NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII). */
  256. EXPORT const char **mpg123_supported_decoders();
  257.  
  258. /** Set the chosen decoder to 'decoder_name' */
  259. EXPORT int mpg123_decoder(mpg123_handle *mh, const char* decoder_name);
  260.  
  261. /** Get the currently active decoder engine name.
  262.     The active decoder engine can vary depening on output constraints,
  263.     mostly non-resampling, integer output is accelerated via 3DNow & Co. but for other modes a fallback engine kicks in.
  264.     Note that this can return a decoder that is ony active in the hidden and not available as decoder choice from the outside.
  265.     \return The decoder name or NULL on error. */
  266. EXPORT const char* mpg123_current_decoder(mpg123_handle *mh);
  267.  
  268. /*@}*/
  269.  
  270.  
  271. /** \defgroup mpg123_output mpg123 output audio format
  272.  *
  273.  * Functions to get and select the format of the decoded audio.
  274.  *
  275.  * @{
  276.  */
  277.  
  278. /** An enum over all sample types possibly known to mpg123.
  279.  *  The values are designed as bit flags to allow bitmasking for encoding families.
  280.  *
  281.  *  Note that (your build of) libmpg123 does not necessarily support all these.
  282.  *  Usually, you can expect the 8bit encodings and signed 16 bit.
  283.  *  Also 32bit float will be usual beginning with mpg123-1.7.0 .
  284.  *  What you should bear in mind is that (SSE, etc) optimized routines are just for
  285.  *  signed 16bit (and 8bit derived from that). Other formats use plain C code.
  286.  *
  287.  *  All formats are in native byte order. On a little endian machine this should mean
  288.  *  that you can just feed the MPG123_ENC_SIGNED_32 data to common 24bit hardware that
  289.  *  ignores the lowest byte (or you could choose to do rounding with these lower bits).
  290.  */
  291. enum mpg123_enc_enum
  292. {
  293.          MPG123_ENC_8      = 0x00f  /**< 0000 0000 1111 Some 8 bit  integer encoding. */
  294.         ,MPG123_ENC_16     = 0x040  /**< 0000 0100 0000 Some 16 bit integer encoding. */
  295.         ,MPG123_ENC_32     = 0x100  /**< 0001 0000 0000 Some 32 bit integer encoding. */
  296.         ,MPG123_ENC_SIGNED = 0x080  /**< 0000 1000 0000 Some signed integer encoding. */
  297.         ,MPG123_ENC_FLOAT  = 0xe00  /**< 1110 0000 0000 Some float encoding. */
  298.         ,MPG123_ENC_SIGNED_16   = (MPG123_ENC_16|MPG123_ENC_SIGNED|0x10) /**<           1101 0000 signed 16 bit */
  299.         ,MPG123_ENC_UNSIGNED_16 = (MPG123_ENC_16|0x20)                   /**<           0110 0000 unsigned 16 bit */
  300.         ,MPG123_ENC_UNSIGNED_8  = 0x01                                   /**<           0000 0001 unsigned 8 bit */
  301.         ,MPG123_ENC_SIGNED_8    = (MPG123_ENC_SIGNED|0x02)               /**<           1000 0010 signed 8 bit */
  302.         ,MPG123_ENC_ULAW_8      = 0x04                                   /**<           0000 0100 ulaw 8 bit */
  303.         ,MPG123_ENC_ALAW_8      = 0x08                                   /**<           0000 1000 alaw 8 bit */
  304.         ,MPG123_ENC_SIGNED_32   = MPG123_ENC_32|MPG123_ENC_SIGNED|0x1000 /**< 0001 0001 1000 0000 signed 32 bit */
  305.         ,MPG123_ENC_UNSIGNED_32 = MPG123_ENC_32|0x2000                   /**< 0010 0001 0000 0000 unsigned 32 bit */
  306.         ,MPG123_ENC_FLOAT_32    = 0x200                                  /**<      0010 0000 0000 32bit float */
  307.         ,MPG123_ENC_FLOAT_64    = 0x400                                  /**<      0100 0000 0000 64bit float */
  308.         ,MPG123_ENC_ANY = ( MPG123_ENC_SIGNED_16  | MPG123_ENC_UNSIGNED_16 | MPG123_ENC_UNSIGNED_8
  309.                           | MPG123_ENC_SIGNED_8   | MPG123_ENC_ULAW_8      | MPG123_ENC_ALAW_8
  310.                           | MPG123_ENC_SIGNED_32  | MPG123_ENC_UNSIGNED_32
  311.                           | MPG123_ENC_FLOAT_32   | MPG123_ENC_FLOAT_64 ) /**< any encoding */
  312. };
  313.  
  314. /** They can be combined into one number (3) to indicate mono and stereo... */
  315. enum mpg123_channelcount
  316. {
  317.          MPG123_MONO   = 1
  318.         ,MPG123_STEREO = 2
  319. };
  320.  
  321. /** An array of supported standard sample rates
  322.  *  These are possible native sample rates of MPEG audio files.
  323.  *  You can still force mpg123 to resample to a different one, but by default you will only get audio in one of these samplings.
  324.  *  \param list Store a pointer to the sample rates array there.
  325.  *  \param number Store the number of sample rates there. */
  326. EXPORT void mpg123_rates(const long **list, size_t *number);
  327.  
  328. /** An array of supported audio encodings.
  329.  *  An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED).
  330.  *  \param list Store a pointer to the encodings array there.
  331.  *  \param number Store the number of encodings there. */
  332. EXPORT void mpg123_encodings(const int **list, size_t *number);
  333.  
  334. /** Configure a mpg123 handle to accept no output format at all,
  335.  *  use before specifying supported formats with mpg123_format */
  336. EXPORT int mpg123_format_none(mpg123_handle *mh);
  337.  
  338. /** Configure mpg123 handle to accept all formats
  339.  *  (also any custom rate you may set) -- this is default. */
  340. EXPORT int mpg123_format_all(mpg123_handle *mh);
  341.  
  342. /** Set the audio format support of a mpg123_handle in detail:
  343.  *  \param mh audio decoder handle
  344.  *  \param rate The sample rate value (in Hertz).
  345.  *  \param channels A combination of MPG123_STEREO and MPG123_MONO.
  346.  *  \param encodings A combination of accepted encodings for rate and channels, p.ex MPG123_ENC_SIGNED16 | MPG123_ENC_ULAW_8 (or 0 for no support). Please note that some encodings may not be supported in the library build and thus will be ignored here.
  347.  *  \return MPG123_OK on success, MPG123_ERR if there was an error. */
  348. EXPORT int mpg123_format(mpg123_handle *mh, long rate, int channels, int encodings);
  349.  
  350. /** Check to see if a specific format at a specific rate is supported
  351.  *  by mpg123_handle.
  352.  *  \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
  353.  *          MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
  354. EXPORT int mpg123_format_support(mpg123_handle *mh, long rate, int encoding);
  355.  
  356. /** Get the current output format written to the addresses givenr. */
  357. EXPORT int mpg123_getformat(mpg123_handle *mh, long *rate, int *channels, int *encoding);
  358.  
  359. /*@}*/
  360.  
  361.  
  362. /** \defgroup mpg123_input mpg123 file input and decoding
  363.  *
  364.  * Functions for input bitstream and decoding operations.
  365.  * Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE (please read up on these on how to react!).
  366.  * @{
  367.  */
  368.  
  369. /* reading samples / triggering decoding, possible return values: */
  370. /** Enumeration of the error codes returned by libmpg123 functions. */
  371.  
  372. /** Open and prepare to decode the specified file by filesystem path.
  373.  *  This does not open HTTP urls; libmpg123 contains no networking code.
  374.  *  If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().
  375.  */
  376. EXPORT int mpg123_open(mpg123_handle *mh, const char *path);
  377.  
  378. /** Use an already opened file descriptor as the bitstream input
  379.  *  mpg123_close() will _not_ close the file descriptor.
  380.  */
  381. EXPORT int mpg123_open_fd(mpg123_handle *mh, int fd);
  382.  
  383. /** Open a new bitstream and prepare for direct feeding
  384.  *  This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.
  385.  */
  386. EXPORT int mpg123_open_feed(mpg123_handle *mh);
  387.  
  388. /** Closes the source, if libmpg123 opened it. */
  389. EXPORT int mpg123_close(mpg123_handle *mh);
  390.  
  391. /** Read from stream and decode up to outmemsize bytes.
  392.  *  \param outmemory address of output buffer to write to
  393.  *  \param outmemsize maximum number of bytes to write
  394.  *  \param done address to store the number of actually decoded bytes to
  395.  *  \return error/message code (watch out for MPG123_DONE and friends!) */
  396. EXPORT int mpg123_read(mpg123_handle *mh, unsigned char *outmemory, size_t outmemsize, size_t *done);
  397.  
  398. /** Feed data for a stream that has been opened with mpg123_open_feed().
  399.  *  It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.
  400.  *  \param in input buffer
  401.  *  \param size number of input bytes
  402.  *  \return error/message code. */
  403. EXPORT int mpg123_feed(mpg123_handle *mh, const unsigned char *in, size_t size);
  404.  
  405. /** Decode MPEG Audio from inmemory to outmemory.
  406.  *  This is very close to a drop-in replacement for old mpglib.
  407.  *  When you give zero-sized output buffer the input will be parsed until
  408.  *  decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it)
  409.  *  without taking decoded data.
  410.  *  Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-).
  411.  *  You can actually always decide if you want those specialized functions in separate steps or one call this one here.
  412.  *  \param inmemory input buffer
  413.  *  \param inmemsize number of input bytes
  414.  *  \param outmemory output buffer
  415.  *  \param outmemsize maximum number of output bytes
  416.  *  \param done address to store the number of actually decoded bytes to
  417.  *  \return error/message code (watch out especially for MPG123_NEED_MORE)
  418.  */
  419. EXPORT int mpg123_decode(mpg123_handle *mh, const unsigned char *inmemory, size_t inmemsize,
  420.                          unsigned char *outmemory, size_t outmemsize, size_t *done);
  421.  
  422. /** Decode next MPEG frame to internal buffer
  423.  *  or read a frame and return after setting a new format.
  424.  *  \param num current frame offset gets stored there
  425.  *  \param audio This pointer is set to the internal buffer to read the decoded audio from.
  426.  *  \param bytes number of output bytes ready in the buffer
  427.  */
  428. EXPORT int mpg123_decode_frame(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes);
  429.  
  430. /*@}*/
  431.  
  432.  
  433. /** \defgroup mpg123_seek mpg123 position and seeking
  434.  *
  435.  * Functions querying and manipulating position in the decoded audio bitstream.
  436.  * The position is measured in decoded audio samples, or MPEG frame offset for the specific functions.
  437.  * If gapless code is in effect, the positions are adjusted to compensate the skipped padding/delay - meaning, you should not care about that at all and just use the position defined for the samples you get out of the decoder;-)
  438.  * The general usage is modelled after stdlib's ftell() and fseek().
  439.  * Especially, the whence parameter for the seek functions has the same meaning as the one for fseek() and needs the same constants from stdlib.h:
  440.  * - SEEK_SET: set position to (or near to) specified offset
  441.  * - SEEK_CUR: change position by offset from now
  442.  * - SEEK_END: set position to offset from end
  443.  *
  444.  * Note that sample-accurate seek only works when gapless support has been enabled at compile time; seek is frame-accurate otherwise.
  445.  * Also, really sample-accurate seeking (meaning that you get the identical sample value after seeking compared to plain decoding up to the position) is only guaranteed when you do not mess with the position code by using MPG123_UPSPEED, MPG123_DOWNSPEED or MPG123_START_FRAME. The first two mainly should cause trouble with NtoM resampling, but in any case with these options in effect, you have to keep in mind that the sample offset is not the same as counting the samples you get from decoding since mpg123 counts the skipped samples, too (or the samples played twice only once)!
  446.  * Short: When you care about the sample position, don't mess with those parameters;-)
  447.  * Also, seeking is not guaranteed to work for all streams (underlying stream may not support it).
  448.  *
  449.  * @{
  450.  */
  451.  
  452. /** Returns the current position in samples.
  453.  *  On the next read, you'd get that sample. */
  454. EXPORT off_t mpg123_tell(mpg123_handle *mh);
  455.  
  456. /** Returns the frame number that the next read will give you data from. */
  457. EXPORT off_t mpg123_tellframe(mpg123_handle *mh);
  458.  
  459. /** Returns the current byte offset in the input stream. */
  460. EXPORT off_t mpg123_tell_stream(mpg123_handle *mh);
  461.  
  462. /** Seek to a desired sample offset.
  463.  *  Set whence to SEEK_SET, SEEK_CUR or SEEK_END.
  464.  *  \return The resulting offset >= 0 or error/message code */
  465. EXPORT off_t mpg123_seek(mpg123_handle *mh, off_t sampleoff, int whence);
  466.  
  467. /** Seek to a desired sample offset in data feeding mode.
  468.  *  This just prepares things to be right only if you ensure that the next chunk of input data will be from input_offset byte position.
  469.  *  \param input_offset The position it expects to be at the
  470.  *                      next time data is fed to mpg123_decode().
  471.  *  \return The resulting offset >= 0 or error/message code */
  472. EXPORT off_t mpg123_feedseek(mpg123_handle *mh, off_t sampleoff, int whence, off_t *input_offset);
  473.  
  474. /** Seek to a desired MPEG frame index.
  475.  *  Set whence to SEEK_SET, SEEK_CUR or SEEK_END.
  476.  *  \return The resulting offset >= 0 or error/message code */
  477. EXPORT off_t mpg123_seek_frame(mpg123_handle *mh, off_t frameoff, int whence);
  478.  
  479. /** Return a MPEG frame offset corresponding to an offset in seconds.
  480.  *  This assumes that the samples per frame do not change in the file/stream, which is a good assumption for any sane file/stream only.
  481.  *  \return frame offset >= 0 or error/message code */
  482. EXPORT off_t mpg123_timeframe(mpg123_handle *mh, double sec);
  483.  
  484. /** Give access to the frame index table that is managed for seeking.
  485.  *  You are asked not to modify the values... unless you are really aware of what you are doing.
  486.  *  \param offsets pointer to the index array
  487.  *  \param step    one index byte offset advances this many MPEG frames
  488.  *  \param fill    number of recorded index offsets; size of the array */
  489. EXPORT int mpg123_index(mpg123_handle *mh, off_t **offsets, off_t *step, size_t *fill);
  490.  
  491. /** Get information about current and remaining frames/seconds.
  492.  *  WARNING: This function is there because of special usage by standalone mpg123 and may be removed in the final version of libmpg123!
  493.  *  You provide an offset (in frames) from now and a number of output bytes
  494.  *  served by libmpg123 but not yet played. You get the projected current frame
  495.  *  and seconds, as well as the remaining frames/seconds. This does _not_ care
  496.  *  about skipped samples due to gapless playback. */
  497. EXPORT int mpg123_position( mpg123_handle *mh, off_t frame_offset,
  498.                             off_t buffered_bytes,  off_t *current_frame,  
  499.                             off_t *frames_left, double *current_seconds,
  500.                             double *seconds_left);
  501.  
  502. /*@}*/
  503.  
  504.  
  505. /** \defgroup mpg123_voleq mpg123 volume and equalizer
  506.  *
  507.  * @{
  508.  */
  509.  
  510. enum mpg123_channels
  511. {
  512.          MPG123_LEFT=0x1        /**< The Left Channel. */
  513.         ,MPG123_RIGHT=0x2       /**< The Right Channel. */
  514.         ,MPG123_LR=0x3  /**< Both left and right channel; same as MPG123_LEFT|MPG123_RIGHT */
  515. };
  516.  
  517. /** Set the 32 Band Audio Equalizer settings.
  518.  *  \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for both.
  519.  *  \param band The equaliser band to change (from 0 to 31)
  520.  *  \param val The (linear) adjustment factor. */
  521. EXPORT int mpg123_eq(mpg123_handle *mh, enum mpg123_channels channel, int band, double val);
  522.  
  523. /** Get the 32 Band Audio Equalizer settings.
  524.  *  \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.
  525.  *  \param band The equaliser band to change (from 0 to 31)
  526.  *  \return The (linear) adjustment factor. */
  527. EXPORT double mpg123_geteq(mpg123_handle *mh, enum mpg123_channels channel, int band);
  528.  
  529. /** Reset the 32 Band Audio Equalizer settings to flat */
  530. EXPORT int mpg123_reset_eq(mpg123_handle *mh);
  531.  
  532. /** Set the absolute output volume including the RVA setting,
  533.  *  vol<0 just applies (a possibly changed) RVA setting. */
  534. EXPORT int mpg123_volume(mpg123_handle *mh, double vol);
  535.  
  536. /** Adjust output volume including the RVA setting by chosen amount */
  537. EXPORT int mpg123_volume_change(mpg123_handle *mh, double change);
  538.  
  539. /** Return current volume setting, the actual value due to RVA, and the RVA
  540.  *  adjustment itself. It's all as double float value to abstract the sample
  541.  *  format. The volume values are linear factors / amplitudes (not percent)
  542.  *  and the RVA value is in decibels. */
  543. EXPORT int mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db);
  544.  
  545. /* TODO: Set some preamp in addition / to replace internal RVA handling? */
  546.  
  547. /*@}*/
  548.  
  549.  
  550. /** \defgroup mpg123_status mpg123 status and information
  551.  *
  552.  * @{
  553.  */
  554.  
  555. /** Enumeration of the mode types of Variable Bitrate */
  556. enum mpg123_vbr {
  557.         MPG123_CBR=0,   /**< Constant Bitrate Mode (default) */
  558.         MPG123_VBR,             /**< Variable Bitrate Mode */
  559.         MPG123_ABR              /**< Average Bitrate Mode */
  560. };
  561.  
  562. /** Enumeration of the MPEG Versions */
  563. enum mpg123_version {
  564.         MPG123_1_0=0,   /**< MPEG Version 1.0 */
  565.         MPG123_2_0,             /**< MPEG Version 2.0 */
  566.         MPG123_2_5              /**< MPEG Version 2.5 */
  567. };
  568.  
  569.  
  570. /** Enumeration of the MPEG Audio mode.
  571.  *  Only the mono mode has 1 channel, the others have 2 channels. */
  572. enum mpg123_mode {
  573.         MPG123_M_STEREO=0,      /**< Standard Stereo. */
  574.         MPG123_M_JOINT,         /**< Joint Stereo. */
  575.         MPG123_M_DUAL,          /**< Dual Channel. */
  576.         MPG123_M_MONO           /**< Single Channel. */
  577. };
  578.  
  579.  
  580. /** Enumeration of the MPEG Audio flag bits */
  581. enum mpg123_flags {
  582.         MPG123_CRC=0x1,                 /**< The bitstream is error protected using 16-bit CRC. */
  583.         MPG123_COPYRIGHT=0x2,   /**< The bitstream is copyrighted. */
  584.         MPG123_PRIVATE=0x4,             /**< The private bit has been set. */
  585.         MPG123_ORIGINAL=0x8     /**< The bitstream is an original, not a copy. */
  586. };
  587.  
  588. /** Data structure for storing information about a frame of MPEG Audio */
  589. struct mpg123_frameinfo
  590. {
  591.         enum mpg123_version version;    /**< The MPEG version (1.0/2.0/2.5). */
  592.         int layer;                                              /**< The MPEG Audio Layer (MP1/MP2/MP3). */
  593.         long rate;                                              /**< The sampling rate in Hz. */
  594.         enum mpg123_mode mode;                  /**< The audio mode (Mono, Stereo, Joint-stero, Dual Channel). */
  595.         int mode_ext;                                   /**< The mode extension bit flag. */
  596.         int framesize;                                  /**< The size of the frame (in bytes). */
  597.         enum mpg123_flags flags;                /**< MPEG Audio flag bits. */
  598.         int emphasis;                                   /**< The emphasis type. */
  599.         int bitrate;                                    /**< Bitrate of the frame (kbps). */
  600.         int abr_rate;                                   /**< The target average bitrate. */
  601.         enum mpg123_vbr vbr;                    /**< The VBR mode. */
  602. };
  603.  
  604. /** Get frame information about the MPEG audio bitstream and store it in a mpg123_frameinfo structure. */
  605. EXPORT int mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi);
  606.  
  607. /** Get the safe output buffer size for all cases (when you want to replace the internal buffer) */
  608. EXPORT size_t mpg123_safe_buffer();
  609.  
  610. /** Make a full parsing scan of each frame in the file. ID3 tags are found. An accurate length
  611.  *  value is stored. Seek index will be filled. A seek back to current position
  612.  *  is performed. At all, this function refuses work when stream is
  613.  *  not seekable.
  614.  *  \return MPG123_OK or MPG123_ERR.
  615.  */
  616. EXPORT int mpg123_scan(mpg123_handle *mh);
  617.  
  618. /** Return, if possible, the full (expected) length of current track in samples.
  619.   * \return length >= 0 or MPG123_ERR if there is no length guess possible. */
  620. EXPORT off_t mpg123_length(mpg123_handle *mh);
  621.  
  622. /** Override the value for file size in bytes.
  623.   * Useful for getting sensible track length values in feed mode or for HTTP streams.
  624.   * \return MPG123_OK or MPG123_ERR */
  625. EXPORT int mpg123_set_filesize(mpg123_handle *mh, off_t size);
  626.  
  627. /** Returns the time (seconds) per frame; <0 is error. */
  628. EXPORT double mpg123_tpf(mpg123_handle *mh);
  629.  
  630. /** Get and reset the clip count. */
  631. EXPORT long mpg123_clip(mpg123_handle *mh);
  632.  
  633.  
  634. /** The key values for state information from mpg123_getstate(). */
  635. enum mpg123_state
  636. {
  637.          MPG123_ACCURATE = 1 /**< Query if positons are currently accurate (integer value, 0 if false, 1 if true) */
  638. };
  639.  
  640. /** Get various current decoder/stream state information.
  641.  *  \param key the key to identify the information to give.
  642.  *  \param val the address to return (long) integer values to
  643.  *  \param fval the address to return floating point values to
  644.  *  \return MPG123_OK or MPG123_ERR for success
  645.  */
  646. EXPORT int mpg123_getstate(mpg123_handle *mh, enum mpg123_state key, long *val, double *fval);
  647.  
  648. /*@}*/
  649.  
  650.  
  651. /** \defgroup mpg123_metadata mpg123 metadata handling
  652.  *
  653.  * Functions to retrieve the metadata from MPEG Audio files and streams.
  654.  * Also includes string handling functions.
  655.  *
  656.  * @{
  657.  */
  658.  
  659. /** Data structure for storing strings in a safer way than a standard C-String.
  660.  *  Can also hold a number of null-terminated strings. */
  661. typedef struct
  662. {
  663.         char* p;     /**< pointer to the string data */
  664.         size_t size; /**< raw number of bytes allocated */
  665.         size_t fill; /**< number of used bytes (including closing zero byte) */
  666. } mpg123_string;
  667.  
  668. /** Create and allocate memory for a new mpg123_string */
  669. EXPORT void mpg123_init_string(mpg123_string* sb);
  670.  
  671. /** Free-up mempory for an existing mpg123_string */
  672. EXPORT void mpg123_free_string(mpg123_string* sb);
  673.  
  674. /** Change the size of a mpg123_string
  675.  *  \return 0 on error, 1 on success */
  676. EXPORT int  mpg123_resize_string(mpg123_string* sb, size_t news);
  677.  
  678. /** Increase size of a mpg123_string if necessary (it may stay larger).
  679.  *  Note that the functions for adding and setting in current libmpg123 use this instead of mpg123_resize_string().
  680.  *  That way, you can preallocate memory and safely work afterwards with pieces.
  681.  *  \return 0 on error, 1 on success */
  682. EXPORT int  mpg123_grow_string(mpg123_string* sb, size_t news);
  683.  
  684. /** Copy the contents of one mpg123_string string to another.
  685.  *  \return 0 on error, 1 on success */
  686. EXPORT int  mpg123_copy_string(mpg123_string* from, mpg123_string* to);
  687.  
  688. /** Append a C-String to an mpg123_string
  689.  *  \return 0 on error, 1 on success */
  690. EXPORT int  mpg123_add_string(mpg123_string* sb, const char* stuff);
  691.  
  692. /** Append a C-substring to an mpg123 string
  693.  *  \return 0 on error, 1 on success
  694.  *  \param from offset to copy from
  695.  *  \param count number of characters to copy (a null-byte is always appended) */
  696. EXPORT int  mpg123_add_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count);
  697.  
  698. /** Set the conents of a mpg123_string to a C-string
  699.  *  \return 0 on error, 1 on success */
  700. EXPORT int  mpg123_set_string(mpg123_string* sb, const char* stuff);
  701.  
  702. /** Set the contents of a mpg123_string to a C-substring
  703.  *  \return 0 on error, 1 on success
  704.  *  \param from offset to copy from
  705.  *  \param count number of characters to copy (a null-byte is always appended) */
  706. EXPORT int  mpg123_set_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count);
  707.  
  708. /** The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info. */
  709. enum mpg123_text_encoding
  710. {
  711.          mpg123_text_unknown  = 0 /**< Unkown encoding... mpg123_id3_encoding can return that on invalid codes. */
  712.         ,mpg123_text_utf8     = 1 /**< UTF-8 */
  713.         ,mpg123_text_latin1   = 2 /**< ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings. */
  714.         ,mpg123_text_icy      = 3 /**< ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such. */
  715.         ,mpg123_text_cp1252   = 4 /**< Really CP-1252 without any guessing. */
  716.         ,mpg123_text_utf16    = 5 /**< Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.
  717.                                    *   When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when
  718.                                    *   you don't mess with the reserved code points. If you want to decode little endian data
  719.                                    *   without BOM you need to prepend 0xff 0xfe yourself. */
  720.         ,mpg123_text_utf16bom = 6 /**< Just an alias for UTF-16, ID3v2 has this as distinct code. */
  721.         ,mpg123_text_utf16be  = 7 /**< Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,
  722.                                    *   BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123
  723.                                    *   One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16
  724.                                    *   types (we expect a BOM before real data there), not so for utf16be!*/
  725.         ,mpg123_text_max      = 7 /**< Placeholder for the maximum encoding value. */
  726. };
  727.  
  728. /** The encoding byte values from ID3v2. */
  729. enum mpg123_id3_enc
  730. {
  731.          mpg123_id3_latin1   = 0 /**< Note: This sometimes can mean anything in practice... */
  732.         ,mpg123_id3_utf16bom = 1 /**< UTF16, UCS-2 ... it's all the same for practical purposes. */
  733.         ,mpg123_id3_utf16be  = 2 /**< Big-endian UTF-16, BOM see note for mpg123_text_utf16be. */
  734.         ,mpg123_id3_utf8     = 3 /**< Our lovely overly ASCII-compatible 8 byte encoding for the world. */
  735.         ,mpg123_id3_enc_max  = 3 /**< Placeholder to check valid range of encoding byte. */
  736. };
  737.  
  738. /** Convert ID3 encoding byte to mpg123 encoding index. */
  739. EXPORT enum mpg123_text_encoding mpg123_enc_from_id3(unsigned char id3_enc_byte);
  740.  
  741. /** Store text data in string, after converting to UTF-8 from indicated encoding
  742.  *  \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)
  743.  *  \param sb  target string
  744.  *  \param enc mpg123 text encoding value
  745.  *  \param source source buffer with plain unsigned bytes (you might need to cast from char *)
  746.  *  \param source_size number of bytes in the source buffer
  747.  *
  748.  *  A prominent error can be that you provided an unknown encoding value, or this build of libmpg123 lacks support for certain encodings (ID3 or ICY stuff missing).
  749.  *  Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).
  750.  */
  751. EXPORT int mpg123_store_utf8(mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size);
  752.  
  753. /** Sub data structure for ID3v2, for storing various text fields (including comments).
  754.  *  This is for ID3v2 COMM, TXXX and all the other text fields.
  755.  *  Only COMM and TXXX have a description, only COMM and USLT have a language.
  756.  *  You should consult the ID3v2 specification for the use of the various text fields ("frames" in ID3v2 documentation, I use "fields" here to separate from MPEG frames). */
  757. typedef struct
  758. {
  759.         char lang[3]; /**< Three-letter language code (not terminated). */
  760.         char id[4];   /**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). */
  761.         mpg123_string description; /**< Empty for the generic comment... */
  762.         mpg123_string text;        /**< ... */
  763. } mpg123_text;
  764.  
  765. /** Data structure for storing IDV3v2 tags.
  766.  *  This structure is not a direct binary mapping with the file contents.
  767.  *  The ID3v2 text frames are allowed to contain multiple strings.
  768.  *  So check for null bytes until you reach the mpg123_string fill.
  769.  *  All text is encoded in UTF-8. */
  770. typedef struct
  771. {
  772.         unsigned char version; /**< 3 or 4 for ID3v2.3 or ID3v2.4. */
  773.         mpg123_string *title;   /**< Title string (pointer into text_list). */
  774.         mpg123_string *artist;  /**< Artist string (pointer into text_list). */
  775.         mpg123_string *album;   /**< Album string (pointer into text_list). */
  776.         mpg123_string *year;    /**< The year as a string (pointer into text_list). */
  777.         mpg123_string *genre;   /**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. */
  778.         mpg123_string *comment; /**< Pointer to last encountered comment text with empty description. */
  779.         /* Encountered ID3v2 fields are appended to these lists.
  780.            There can be multiple occurences, the pointers above always point to the last encountered data. */
  781.         mpg123_text    *comment_list; /**< Array of comments. */
  782.         size_t          comments;     /**< Number of comments. */
  783.         mpg123_text    *text;         /**< Array of ID3v2 text fields (including USLT) */
  784.         size_t          texts;        /**< Numer of text fields. */
  785.         mpg123_text    *extra;        /**< The array of extra (TXXX) fields. */
  786.         size_t          extras;       /**< Number of extra text (TXXX) fields. */
  787. } mpg123_id3v2;
  788.  
  789. /** Data structure for ID3v1 tags (the last 128 bytes of a file).
  790.  *  Don't take anything for granted (like string termination)!
  791.  *  Also note the change ID3v1.1 did: comment[28] = 0; comment[19] = track_number
  792.  *  It is your task to support ID3v1 only or ID3v1.1 ...*/
  793. typedef struct
  794. {
  795.         char tag[3];         /**< Always the string "TAG", the classic intro. */
  796.         char title[30];      /**< Title string.  */
  797.         char artist[30];     /**< Artist string. */
  798.         char album[30];      /**< Album string. */
  799.         char year[4];        /**< Year string. */
  800.         char comment[30];    /**< Comment string. */
  801.         unsigned char genre; /**< Genre index. */
  802. } mpg123_id3v1;
  803.  
  804. #define MPG123_ID3     0x3 /**< 0011 There is some ID3 info. Also matches 0010 or NEW_ID3. */
  805. #define MPG123_NEW_ID3 0x1 /**< 0001 There is ID3 info that changed since last call to mpg123_id3. */
  806. #define MPG123_ICY     0xc /**< 1100 There is some ICY info. Also matches 0100 or NEW_ICY.*/
  807. #define MPG123_NEW_ICY 0x4 /**< 0100 There is ICY info that changed since last call to mpg123_icy. */
  808.  
  809. /** Query if there is (new) meta info, be it ID3 or ICY (or something new in future).
  810.    The check function returns a combination of flags. */
  811. EXPORT int mpg123_meta_check(mpg123_handle *mh); /* On error (no valid handle) just 0 is returned. */
  812.  
  813. /** Point v1 and v2 to existing data structures wich may change on any next read/decode function call.
  814.  *  v1 and/or v2 can be set to NULL when there is no corresponding data.
  815.  *  \return Return value is MPG123_OK or MPG123_ERR,  */
  816. EXPORT int mpg123_id3(mpg123_handle *mh, mpg123_id3v1 **v1, mpg123_id3v2 **v2);
  817.  
  818. /** Point icy_meta to existing data structure wich may change on any next read/decode function call.
  819.  *  \return Return value is MPG123_OK or MPG123_ERR,  */
  820. EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta); /* same for ICY meta string */
  821.  
  822. /** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8.
  823.  *  Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .
  824.  *  \param icy_text The input data in ICY encoding
  825.  *  \return pointer to newly allocated buffer with UTF-8 data (You free() it!) */
  826. EXPORT char* mpg123_icy2utf8(const char* icy_text);
  827.  
  828.  
  829. /* @} */
  830.  
  831.  
  832. /** \defgroup mpg123_advpar mpg123 advanced parameter API
  833.  *
  834.  *  Direct access to a parameter set without full handle around it.
  835.  *      Possible uses:
  836.  *    - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE).
  837.  *    - Use one set of parameters for multiple handles.
  838.  *
  839.  *      The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt()
  840.  *  family) directly return a fully qualified mpg123 error code, the ones
  841.  *  operating on full handles normally MPG123_OK or MPG123_ERR, storing the
  842.  *  specific error code itseld inside the handle.
  843.  *
  844.  * @{
  845.  */
  846.  
  847. /** Opaque structure for the libmpg123 decoder parameters. */
  848. struct mpg123_pars_struct;
  849.  
  850. /** Opaque structure for the libmpg123 decoder parameters. */
  851. typedef struct mpg123_pars_struct   mpg123_pars;
  852.  
  853. /** Create a handle with preset parameters. */
  854. EXPORT mpg123_handle *mpg123_parnew(mpg123_pars *mp, const char* decoder, int *error);
  855.  
  856. /** Allocate memory for and return a pointer to a new mpg123_pars */
  857. EXPORT mpg123_pars *mpg123_new_pars(int *error);
  858.  
  859. /** Delete and free up memory used by a mpg123_pars data structure */
  860. EXPORT void         mpg123_delete_pars(mpg123_pars* mp);
  861.  
  862. /** Configure mpg123 parameters to accept no output format at all,
  863.  * use before specifying supported formats with mpg123_format */
  864. EXPORT int mpg123_fmt_none(mpg123_pars *mp);
  865.  
  866. /** Configure mpg123 parameters to accept all formats
  867.  *  (also any custom rate you may set) -- this is default. */
  868. EXPORT int mpg123_fmt_all(mpg123_pars *mp);
  869.  
  870. /** Set the audio format support of a mpg123_pars in detail:
  871.         \param rate The sample rate value (in Hertz).
  872.         \param channels A combination of MPG123_STEREO and MPG123_MONO.
  873.         \param encodings A combination of accepted encodings for rate and channels, p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no support).
  874.         \return 0 on success, -1 if there was an error. /
  875. */
  876. EXPORT int mpg123_fmt(mpg123_pars *mh, long rate, int channels, int encodings); /* 0 is good, -1 is error */
  877.  
  878. /** Check to see if a specific format at a specific rate is supported
  879.  *  by mpg123_pars.
  880.  *  \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
  881.  *          MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
  882. EXPORT int mpg123_fmt_support(mpg123_pars *mh,   long rate, int encoding);
  883.  
  884. /** Set a specific parameter, for a specific mpg123_pars, using a parameter
  885.  *  type key chosen from the mpg123_parms enumeration, to the specified value. */
  886. EXPORT int mpg123_par(mpg123_pars *mp, enum mpg123_parms type, long value, double fvalue);
  887.  
  888. /** Get a specific parameter, for a specific mpg123_pars.
  889.  *  See the mpg123_parms enumeration for a list of available parameters. */
  890. EXPORT int mpg123_getpar(mpg123_pars *mp, enum mpg123_parms type, long *val, double *fval);
  891.  
  892. /* @} */
  893.  
  894.  
  895. /** \defgroup mpg123_lowio mpg123 low level I/O
  896.   * You may want to do tricky stuff with I/O that does not work with mpg123's default file access or you want to make it decode into your own pocket...
  897.   *
  898.   * @{ */
  899.  
  900. /** Replace default internal buffer with user-supplied buffer.
  901.   * Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio. */
  902. EXPORT int mpg123_replace_buffer(mpg123_handle *mh, unsigned char *data, size_t size);
  903.  
  904. /** The max size of one frame's decoded output with current settings.
  905.  *  Use that to determine an appropriate minimum buffer size for decoding one frame. */
  906. EXPORT size_t mpg123_outblock(mpg123_handle *mh);
  907.  
  908. /** Replace low-level stream access functions; read and lseek as known in POSIX.
  909.  *  You can use this to make any fancy file opening/closing yourself,
  910.  *  using open_fd to set the file descriptor for your read/lseek (doesn't need to be a "real" file descriptor...).
  911.  *  Setting a function to NULL means that the default internal read is
  912.  *  used (active from next mpg123_open call on). */
  913. EXPORT int mpg123_replace_reader( mpg123_handle *mh,
  914.                                   ssize_t (*r_read) (int, void *, size_t),
  915.                                   off_t   (*r_lseek)(int, off_t, int) );
  916.  
  917. /* @} */
  918.  
  919.  
  920. #ifdef __cplusplus
  921. }
  922. #endif
  923.  
  924. #endif
  925.