/*1libmpg123: MPEG Audio Decoder library23copyright 1995-2023 by the mpg123 project4free software under the terms of the LGPL 2.15see COPYING and AUTHORS files in distribution or http://mpg123.org6*/78#ifndef MPG123_LIB_H9#define MPG123_LIB_H1011#include "fmt123.h"1213/** \file mpg123.h The header file for the libmpg123 MPEG Audio decoder */1415/** \defgroup mpg123_h mpg123 header general settings and notes16* @{17*/1819/** A macro to check at compile time which set of API functions to expect.20* This must be incremented at least each time a new symbol is added21* to the header.22*/23#define MPG123_API_VERSION 4924/** library patch level at client build time */25#define MPG123_PATCHLEVEL 32627#ifndef MPG123_EXPORT28/** Defines needed for MS Visual Studio(tm) DLL builds.29* Every public function must be prefixed with MPG123_EXPORT. When building30* the DLL ensure to define BUILD_MPG123_DLL. This makes the function accessible31* for clients and includes it in the import library which is created together32* with the DLL. When consuming the DLL ensure to define LINK_MPG123_DLL which33* imports the functions from the DLL.34*/35#ifdef BUILD_MPG123_DLL36/* The dll exports. */37#define MPG123_EXPORT __declspec(dllexport)38#else39#ifdef LINK_MPG123_DLL40/* The exe imports. */41#define MPG123_EXPORT __declspec(dllimport)42#else43/* Nothing on normal/UNIX builds */44#define MPG123_EXPORT45#endif46#endif47#endif4849/** \page enumapi About enum API50*51* Earlier versions of libmpg123 put enums into public API calls,52* which is not exactly safe. There are ABI rules, but you can use53* compiler switches to change the sizes of enums. It is safer not54* to have them in API calls. Thus, the default is to remap calls and55* structs to variants that use plain ints. Define MPG123_ENUM_API to56* prevent that remapping.57*58* You might want to define this to increase the chance of your binary59* working with an older version of the library. But if that is your goal,60* you should better build with an older version to begin with.61*62* You can avoid renamed symbols by using the non-enum names directly:63*64* - mpg123_param2()65* - mpg123_getparam2()66* - mpg123_feature2()67* - mpg123_eq2()68* - mpg123_geteq2()69* - mpg123_frameinfo2()70* - mpg123_info2()71* - mpg123_getstate2()72* - mpg123_enc_from_id3_2()73* - mpg123_store_utf8_2()74* - mpg123_par2()75* - mpg123_getpar2()76*/77#ifndef MPG123_ENUM_API7879#define mpg123_param mpg123_param280#define mpg123_getparam mpg123_getparam281#define mpg123_feature mpg123_feature282#define mpg123_eq mpg123_eq283#define mpg123_geteq mpg123_geteq284#define mpg123_frameinfo mpg123_frameinfo285#define mpg123_info mpg123_info286#define mpg123_getstate mpg123_getstate287#define mpg123_enc_from_id3 mpg123_enc_from_id3_288#define mpg123_store_utf8 mpg123_store_utf8_289#define mpg123_par mpg123_par290#define mpg123_getpar mpg123_getpar29192#endif9394#include <stddef.h>95#include <stdint.h>9697#ifndef MPG123_PORTABLE_API98#include <sys/types.h>99/** A little hack to help MSVC not having ssize_t. */100#ifdef _MSC_VER101typedef ptrdiff_t mpg123_ssize_t;102#else103typedef ssize_t mpg123_ssize_t;104#endif105#endif106107108/** \page lfs Handling of large file offsets109*110* When client code defines _FILE_OFFSET_BITS, it wants non-default large file111* support, and thus functions with added suffix (mpg123_open_64). The default112* library build provides wrapper and alias functions to accomodate client code113* variations (dual-mode library like glibc).114*115* Client code can definie MPG123_NO_LARGENAME and MPG123_LARGESUFFIX,116* respectively, for disabling or enforcing the suffixes. You should *not* do117* this, though, unless you *really* want to deal with symbol ABI yourself.118* If explicit usage of 64 bit offsets is desired, the int64_t API119* consisting of functions with 64 suffix without underscore, notably120* mpg123_reader64(), can be used since API version 48 (mpg123 1.32). A matching121* mpg123_open64(), stripped-down mpg123_open_handle_64() is present since API122* version 49 (mpg123 1.33).123*124* When in doubt, use the explicit 64 bit functions and avoid off_t in the API.125* You can define MPG123_PORTABLE_API to ensure that. That being said, if you126* and your compiler do not have problems with the concept of off_t, just use127* the normal AP like the I/O API of the standard C library. Both 32 and 64 bit128* versions of functions will be present where appropriate.129*130* If your toolchain enforces _FILE_OFFSET_BITS also during build of libmpg123,131* only that setting will be supported for client code.132*/133134#ifndef MPG123_PORTABLE_API135/** \page lfs_names Renaming of functions for largefile support136*137* Now, the renaming of large file aware functions.138* By default, it appends underscore _FILE_OFFSET_BITS (so, mpg123_seek_64() for mpg123_seek()),139* if _FILE_OFFSET_BITS is defined. These are the affected API functions:140*141* - mpg123_open_fixed()142* - mpg123_open()143* - mpg123_open_fd()144* - mpg123_open_handle()145* - mpg123_framebyframe_decode()146* - mpg123_decode_frame()147* - mpg123_tell()148* - mpg123_tellframe()149* - mpg123_tell_stream()150* - mpg123_seek()151* - mpg123_feedseek()152* - mpg123_seek_frame()153* - mpg123_timeframe()154* - mpg123_index()155* - mpg123_set_index()156* - mpg123_position()157* - mpg123_length()158* - mpg123_framelength()159* - mpg123_set_filesize()160* - mpg123_replace_reader()161* - mpg123_replace_reader_handle()162* - mpg123_framepos()163*/164#if (!defined MPG123_NO_LARGENAME) && ((defined _FILE_OFFSET_BITS) || (defined MPG123_LARGESUFFIX))165166/* Need some trickery to concatenate the value(s) of the given macro(s). */167#define MPG123_MACROCAT_REALLY(a, b) a ## b168#define MPG123_MACROCAT(a, b) MPG123_MACROCAT_REALLY(a, b)169#ifndef MPG123_LARGESUFFIX170#define MPG123_LARGESUFFIX MPG123_MACROCAT(_, _FILE_OFFSET_BITS)171#endif172#define MPG123_LARGENAME(func) MPG123_MACROCAT(func, MPG123_LARGESUFFIX)173174#define mpg123_open_fixed MPG123_LARGENAME(mpg123_open_fixed)175#define mpg123_open MPG123_LARGENAME(mpg123_open)176#define mpg123_open_fd MPG123_LARGENAME(mpg123_open_fd)177#define mpg123_open_handle MPG123_LARGENAME(mpg123_open_handle)178#define mpg123_framebyframe_decode MPG123_LARGENAME(mpg123_framebyframe_decode)179#define mpg123_decode_frame MPG123_LARGENAME(mpg123_decode_frame)180#define mpg123_tell MPG123_LARGENAME(mpg123_tell)181#define mpg123_tellframe MPG123_LARGENAME(mpg123_tellframe)182#define mpg123_tell_stream MPG123_LARGENAME(mpg123_tell_stream)183#define mpg123_seek MPG123_LARGENAME(mpg123_seek)184#define mpg123_feedseek MPG123_LARGENAME(mpg123_feedseek)185#define mpg123_seek_frame MPG123_LARGENAME(mpg123_seek_frame)186#define mpg123_timeframe MPG123_LARGENAME(mpg123_timeframe)187#define mpg123_index MPG123_LARGENAME(mpg123_index)188#define mpg123_set_index MPG123_LARGENAME(mpg123_set_index)189#define mpg123_position MPG123_LARGENAME(mpg123_position)190#define mpg123_length MPG123_LARGENAME(mpg123_length)191#define mpg123_framelength MPG123_LARGENAME(mpg123_framelength)192#define mpg123_set_filesize MPG123_LARGENAME(mpg123_set_filesize)193#define mpg123_replace_reader MPG123_LARGENAME(mpg123_replace_reader)194#define mpg123_replace_reader_handle MPG123_LARGENAME(mpg123_replace_reader_handle)195#define mpg123_framepos MPG123_LARGENAME(mpg123_framepos)196197#endif /* largefile hackery */198#endif199200/** @} */201202#ifdef __cplusplus203extern "C" {204#endif205206/** \defgroup mpg123_init mpg123 library and handle setup207*208* Functions to initialise and shutdown the mpg123 library and handles.209* The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-)210* Tip: Use a RVA setting...211*212* @{213*/214215/** Opaque structure for the libmpg123 decoder handle. */216struct mpg123_handle_struct;217218/** Opaque structure for the libmpg123 decoder handle.219* Most functions take a pointer to a mpg123_handle as first argument and operate on its data in an object-oriented manner.220*/221typedef struct mpg123_handle_struct mpg123_handle;222223/** Get version of the mpg123 distribution this library build came with.224* (optional means non-NULL)225* \param major optional address to store major version number226* \param minor optional address to store minor version number227* \param patch optional address to store patchlevel version number228* \return full version string (like "1.2.3-beta4 (experimental)")229*/230const char *mpg123_distversion(unsigned int *major, unsigned int *minor, unsigned int *patch);231232/** Get API version of library build.233* \param patch optional address to store patchlevel234* \return API version of library235*/236unsigned int mpg123_libversion(unsigned int *patch);237238/** Useless no-op that used to do initialization work.239*240* For API version before 46 (mpg123 1.27.0), you had to ensure to have241* this called once before creating a handle. To be pure, this had to242* happen in a single-threaded context, too (while in practice, there was no243* harm done possibly racing to compute the same numbers again).244*245* Now this function really does nothing anymore. The only reason to call246* it is to be compatible with old versions of the library that still require247* it.248*249* \return MPG123_OK if successful, otherwise an error number.250*/251MPG123_EXPORT int mpg123_init(void);252253/** Superfluous Function to close down the mpg123 library.254* This was created with the thought that there sometime will be cleanup code255* to be run after library use. This never materialized. You can forget about256* this function and it is only here for old programs that do call it.257*/258MPG123_EXPORT void mpg123_exit(void);259260/** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()).261* and optional retrieval of an error code to feed to mpg123_plain_strerror().262* Optional means: Any of or both the parameters may be NULL.263*264* \param decoder optional choice of decoder variant (NULL for default)265* \param error optional address to store error codes266* \return Non-NULL pointer to fresh handle when successful.267*/268MPG123_EXPORT mpg123_handle *mpg123_new(const char* decoder, int *error);269270/** Delete handle, mh is either a valid mpg123 handle or NULL.271* \param mh handle272*/273MPG123_EXPORT void mpg123_delete(mpg123_handle *mh);274275/** Free plain memory allocated within libmpg123.276* This is for library users that are not sure to use the same underlying277* memory allocator as libmpg123. It is just a wrapper over free() in278* the underlying C library.279*/280MPG123_EXPORT void mpg123_free(void *ptr);281282/** Enumeration of the parameters types that it is possible to set/get. */283enum mpg123_parms284{285MPG123_VERBOSE = 0, /**< set verbosity value for enabling messages to stderr, >= 0 makes sense (integer) */286MPG123_FLAGS, /**< set all flags, p.ex val = MPG123_GAPLESS|MPG123_MONO_MIX (integer) */287MPG123_ADD_FLAGS, /**< add some flags (integer) */288MPG123_FORCE_RATE, /**< when value > 0, force output rate to that value (integer) */289MPG123_DOWN_SAMPLE, /**< 0=native rate, 1=half rate, 2=quarter rate (integer) */290MPG123_RVA, /**< one of the RVA choices above (integer) */291MPG123_DOWNSPEED, /**< play a frame N times (integer) */292MPG123_UPSPEED, /**< play every Nth frame (integer) */293MPG123_START_FRAME, /**< start with this frame (skip frames before that, integer) */294MPG123_DECODE_FRAMES, /**< decode only this number of frames (integer) */295MPG123_ICY_INTERVAL, /**< Stream contains ICY metadata with this interval (integer).296Make sure to set this _before_ opening a stream.*/297MPG123_OUTSCALE, /**< the scale for output samples (amplitude - integer or float according to mpg123 output format, normally integer) */298MPG123_TIMEOUT, /**< timeout for reading from a stream (not supported on win32, integer) */299MPG123_REMOVE_FLAGS, /**< remove some flags (inverse of MPG123_ADD_FLAGS, integer) */300MPG123_RESYNC_LIMIT, /**< Try resync on frame parsing for that many bytes or until end of stream (<0 ... integer). This can enlarge the limit for skipping junk on beginning, too (but not reduce it). */301MPG123_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. */302,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.*/303,MPG123_FEEDPOOL /**< For feeder mode, keep that many buffers in a pool to avoid frequent malloc/free. The pool is allocated on mpg123_open_feed(). If you change this parameter afterwards, you can trigger growth and shrinkage during decoding. The default value could change any time. If you care about this, then set it. (integer) */304,MPG123_FEEDBUFFER /**< Minimal size of one internal feeder buffer, again, the default value is subject to change. (integer) */305,MPG123_FREEFORMAT_SIZE /**< Tell the parser a free-format frame size to306* avoid read-ahead to get it. A value of -1 (default) means that the parser307* will determine it. The parameter value is applied during decoder setup308* for a freshly opened stream only.309*/310};311312/** Flag bits for MPG123_FLAGS, use the usual binary or to combine. */313enum mpg123_param_flags314{315MPG123_FORCE_MONO = 0x7 /**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. */316,MPG123_MONO_LEFT = 0x1 /**< 0001 Force playback of left channel only. */317,MPG123_MONO_RIGHT = 0x2 /**< 0010 Force playback of right channel only. */318,MPG123_MONO_MIX = 0x4 /**< 0100 Force playback of mixed mono. */319,MPG123_FORCE_STEREO = 0x8 /**< 1000 Force stereo output. */320,MPG123_FORCE_8BIT = 0x10 /**< 00010000 Force 8bit formats. */321,MPG123_QUIET = 0x20 /**< 00100000 Suppress any printouts (overrules verbose). */322,MPG123_GAPLESS = 0x40 /**< 01000000 Enable gapless decoding (default on if libmpg123 has support). */323,MPG123_NO_RESYNC = 0x80 /**< 10000000 Disable resync stream after error. */324,MPG123_SEEKBUFFER = 0x100 /**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). */325,MPG123_FUZZY = 0x200 /**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) */326,MPG123_FORCE_FLOAT = 0x400 /**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). */327,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. */328,MPG123_IGNORE_STREAMLENGTH = 0x1000 /**< 1000000000000 Ignore any stream length information contained in the stream, which can be contained in a 'TLEN' frame of an ID3v2 tag or a Xing tag */329,MPG123_SKIP_ID3V2 = 0x2000 /**< 10 0000 0000 0000 Do not parse ID3v2 tags, just skip them. */330,MPG123_IGNORE_INFOFRAME = 0x4000 /**< 100 0000 0000 0000 Do not parse the LAME/Xing info frame, treat it as normal MPEG data. */331,MPG123_AUTO_RESAMPLE = 0x8000 /**< 1000 0000 0000 0000 Allow automatic internal resampling of any kind (default on if supported). Especially when going lowlevel with replacing output buffer, you might want to unset this flag. Setting MPG123_DOWNSAMPLE or MPG123_FORCE_RATE will override this. */332,MPG123_PICTURE = 0x10000 /**< 17th bit: Enable storage of pictures from tags (ID3v2 APIC). */333,MPG123_NO_PEEK_END = 0x20000 /**< 18th bit: Do not seek to the end of334* the stream in order to probe335* the stream length and search for the id3v1 field. This also means336* the file size is unknown unless set using mpg123_set_filesize() and337* the stream is assumed as non-seekable unless overridden.338*/339,MPG123_FORCE_SEEKABLE = 0x40000 /**< 19th bit: Force the stream to be seekable. */340,MPG123_STORE_RAW_ID3 = 0x80000 /**< store raw ID3 data (even if skipping) */341,MPG123_FORCE_ENDIAN = 0x100000 /**< Enforce endianess of output samples.342* This is not reflected in the format codes. If this flag is set along with343* MPG123_BIG_ENDIAN, MPG123_ENC_SIGNED16 means s16be, without344* MPG123_BIG_ENDIAN, it means s16le. Normal operation without345* MPG123_FORCE_ENDIAN produces output in native byte order.346*/347,MPG123_BIG_ENDIAN = 0x200000 /**< Choose big endian instead of little. */348,MPG123_NO_READAHEAD = 0x400000 /**< Disable read-ahead in parser. If349* you know you provide full frames to the feeder API, this enables350* decoder output from the first one on, instead of having to wait for351* the next frame to confirm that the stream is healthy. It also disables352* free format support unless you provide a frame size using353* MPG123_FREEFORMAT_SIZE.354*/355,MPG123_FLOAT_FALLBACK = 0x800000 /**< Consider floating point output encoding only after356* trying other (possibly downsampled) rates and encodings first. This is to357* support efficient playback where floating point output is only configured for358* an external resampler, bypassing that resampler when the desired rate can359* be produced directly. This is enabled by default to be closer to older versions360* of libmpg123 which did not enable float automatically at all. If disabled,361* float is considered after the 16 bit default and higher-bit integer encodings362* for any rate. */363,MPG123_NO_FRANKENSTEIN = 0x1000000 /**< Disable support for Frankenstein streams364* (different MPEG streams stiched together). Do not accept serious change of MPEG365* header inside a single stream. With this flag, the audio output format cannot366* change during decoding unless you open a new stream. This also stops decoding367* after an announced end of stream (Info header contained a number of frames368* and this number has been reached). This makes your MP3 files behave more like369* ordinary media files with defined structure, rather than stream dumps with370* some sugar. */371};372373/** choices for MPG123_RVA */374enum mpg123_param_rva375{376MPG123_RVA_OFF = 0 /**< RVA disabled (default). */377,MPG123_RVA_MIX = 1 /**< Use mix/track/radio gain. */378,MPG123_RVA_ALBUM = 2 /**< Use album/audiophile gain */379,MPG123_RVA_MAX = MPG123_RVA_ALBUM /**< The maximum RVA code, may increase in future. */380};381382#ifdef MPG123_ENUM_API383/** Set a specific parameter on a handle.384*385* Note that this name is mapped to mpg123_param2() instead unless386* MPG123_ENUM_API is defined.387*388* \param mh handle389* \param type parameter choice390* \param value integer value391* \param fvalue floating point value392* \return MPG123_OK on success393*/394MPG123_EXPORT int mpg123_param( mpg123_handle *mh395, enum mpg123_parms type, long value, double fvalue );396#endif397398/** Set a specific parameter on a handle. No enums.399*400* This is actually called instead of mpg123_param()401* unless MPG123_ENUM_API is defined.402*403* \param mh handle404* \param type parameter choice (from enum #mpg123_parms)405* \param value integer value406* \param fvalue floating point value407* \return MPG123_OK on success408*/409MPG123_EXPORT int mpg123_param2( mpg123_handle *mh410, int type, long value, double fvalue );411412#ifdef MPG123_ENUM_API413/** Get a specific parameter from a handle.414*415* Note that this name is mapped to mpg123_getparam2() instead unless416* MPG123_ENUM_API is defined.417*418* \param mh handle419* \param type parameter choice420* \param value integer value return address421* \param fvalue floating point value return address422* \return MPG123_OK on success423*/424MPG123_EXPORT int mpg123_getparam( mpg123_handle *mh425, enum mpg123_parms type, long *value, double *fvalue );426#endif427428/** Get a specific parameter from a handle. No enums.429*430* This is actually called instead of mpg123_getparam() unless MPG123_ENUM_API431* is defined.432*433* \param mh handle434* \param type parameter choice (from enum #mpg123_parms)435* \param value integer value return address436* \param fvalue floating point value return address437* \return MPG123_OK on success438*/439MPG123_EXPORT int mpg123_getparam2( mpg123_handle *mh440, int type, long *value, double *fvalue );441442/** Feature set available for query with mpg123_feature. */443enum mpg123_feature_set444{445MPG123_FEATURE_ABI_UTF8OPEN = 0 /**< mpg123 expects path names to be given in UTF-8 encoding instead of plain native. */446,MPG123_FEATURE_OUTPUT_8BIT /**< 8bit output */447,MPG123_FEATURE_OUTPUT_16BIT /**< 16bit output */448,MPG123_FEATURE_OUTPUT_32BIT /**< 32bit output */449,MPG123_FEATURE_INDEX /**< support for building a frame index for accurate seeking */450,MPG123_FEATURE_PARSE_ID3V2 /**< id3v2 parsing */451,MPG123_FEATURE_DECODE_LAYER1 /**< mpeg layer-1 decoder enabled */452,MPG123_FEATURE_DECODE_LAYER2 /**< mpeg layer-2 decoder enabled */453,MPG123_FEATURE_DECODE_LAYER3 /**< mpeg layer-3 decoder enabled */454,MPG123_FEATURE_DECODE_ACCURATE /**< accurate decoder rounding */455,MPG123_FEATURE_DECODE_DOWNSAMPLE /**< downsample (sample omit) */456,MPG123_FEATURE_DECODE_NTOM /**< flexible rate decoding */457,MPG123_FEATURE_PARSE_ICY /**< ICY support */458,MPG123_FEATURE_TIMEOUT_READ /**< Reader with timeout (network). */459,MPG123_FEATURE_EQUALIZER /**< tunable equalizer */460,MPG123_FEATURE_MOREINFO /**< more info extraction (for frame analyzer) */461,MPG123_FEATURE_OUTPUT_FLOAT32 /**< 32 bit float output */462,MPG123_FEATURE_OUTPUT_FLOAT64 /**< 64 bit float output (as of now: never!) */463};464465#ifdef MPG123_ENUM_API466/** Query libmpg123 features.467*468* Note that this name is mapped to mpg123_feature2() instead unless469* MPG123_ENUM_API is defined.470*471* \param key feature selection472* \return 1 for success, 0 for unimplemented functions473*/474MPG123_EXPORT int mpg123_feature(const enum mpg123_feature_set key);475#endif476477/** Query libmpg123 features. No enums.478*479* This is actually called instead of mpg123_feature() unless MPG123_ENUM_API480* is defined.481*482* \param key feature selection (from enum #mpg123_feature_set)483* \return 1 for success, 0 for unimplemented functions484*/485MPG123_EXPORT int mpg123_feature2(int key);486487/** @} */488489490/** \defgroup mpg123_error mpg123 error handling491*492* Functions to get text version of the error numbers and an enumeration493* of the error codes returned by libmpg123.494*495* Most functions operating on a mpg123_handle simply return MPG123_OK (0)496* on success and MPG123_ERR (-1) on failure, setting the internal error497* variable of the handle to the specific error code. If there was not a valid498* (non-NULL) handle provided to a function operating on one, MPG123_BAD_HANDLE499* may be returned if this can not be confused with a valid positive return500* value.501* Meaning: A function expected to return positive integers on success will502* always indicate error or a special condition by returning a negative one.503*504* Decoding/seek functions may also return message codes MPG123_DONE,505* MPG123_NEW_FORMAT and MPG123_NEED_MORE (all negative, see below on how to506* react). Note that calls to those can be nested, so generally watch out507* for these codes after initial handle setup.508* Especially any function that needs information about the current stream509* to work will try to at least parse the beginning if that did not happen510* yet.511*512* On a function that is supposed to return MPG123_OK on success and513* MPG123_ERR on failure, make sure you check for != MPG123_OK, not514* == MPG123_ERR, as the error code could get more specific in future,515* or there is just a special message from a decoding routine as indicated516* above.517*518* @{519*/520521/** Enumeration of the message and error codes and returned by libmpg123 functions. */522enum mpg123_errors523{524MPG123_DONE=-12, /**< Message: Track ended. Stop decoding. */525MPG123_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. */526MPG123_NEED_MORE=-10, /**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). */527MPG123_ERR=-1, /**< Generic Error */528MPG123_OK=0, /**< Success */529MPG123_BAD_OUTFORMAT, /**< Unable to set up output format! */530MPG123_BAD_CHANNEL, /**< Invalid channel number specified. */531MPG123_BAD_RATE, /**< Invalid sample rate specified. */532MPG123_ERR_16TO8TABLE, /**< Unable to allocate memory for 16 to 8 converter table! */533MPG123_BAD_PARAM, /**< Bad parameter id! */534MPG123_BAD_BUFFER, /**< Bad buffer given -- invalid pointer or too small size. */535MPG123_OUT_OF_MEM, /**< Out of memory -- some malloc() failed. */536MPG123_NOT_INITIALIZED, /**< You didn't initialize the library! */537MPG123_BAD_DECODER, /**< Invalid decoder choice. */538MPG123_BAD_HANDLE, /**< Invalid mpg123 handle. */539MPG123_NO_BUFFERS, /**< Unable to initialize frame buffers (out of memory?). */540MPG123_BAD_RVA, /**< Invalid RVA mode. */541MPG123_NO_GAPLESS, /**< This build doesn't support gapless decoding. */542MPG123_NO_SPACE, /**< Not enough buffer space. */543MPG123_BAD_TYPES, /**< Incompatible numeric data types. */544MPG123_BAD_BAND, /**< Bad equalizer band. */545MPG123_ERR_NULL, /**< Null pointer given where valid storage address needed. */546MPG123_ERR_READER, /**< Error reading the stream. */547MPG123_NO_SEEK_FROM_END,/**< Cannot seek from end (end is not known). */548MPG123_BAD_WHENCE, /**< Invalid 'whence' for seek function.*/549MPG123_NO_TIMEOUT, /**< Build does not support stream timeouts. */550MPG123_BAD_FILE, /**< File access error. */551MPG123_NO_SEEK, /**< Seek not supported by stream. */552MPG123_NO_READER, /**< No stream opened or no reader callback setup. */553MPG123_BAD_PARS, /**< Bad parameter handle. */554MPG123_BAD_INDEX_PAR, /**< Bad parameters to mpg123_index() and mpg123_set_index() */555MPG123_OUT_OF_SYNC, /**< Lost track in bytestream and did not try to resync. */556MPG123_RESYNC_FAIL, /**< Resync failed to find valid MPEG data. */557MPG123_NO_8BIT, /**< No 8bit encoding possible. */558MPG123_BAD_ALIGN, /**< Stack aligmnent error */559MPG123_NULL_BUFFER, /**< NULL input buffer with non-zero size... */560MPG123_NO_RELSEEK, /**< Relative seek not possible (screwed up file offset) */561MPG123_NULL_POINTER, /**< You gave a null pointer somewhere where you shouldn't have. */562MPG123_BAD_KEY, /**< Bad key value given. */563MPG123_NO_INDEX, /**< No frame index in this build. */564MPG123_INDEX_FAIL, /**< Something with frame index went wrong. */565MPG123_BAD_DECODER_SETUP, /**< Something prevents a proper decoder setup */566MPG123_MISSING_FEATURE /**< This feature has not been built into libmpg123. */567,MPG123_BAD_VALUE /**< A bad value has been given, somewhere. */568,MPG123_LSEEK_FAILED /**< Low-level seek failed. */569,MPG123_BAD_CUSTOM_IO /**< Custom I/O not prepared. */570,MPG123_LFS_OVERFLOW /**< Offset value overflow during translation of large file API calls -- your client program cannot handle that large file. */571,MPG123_INT_OVERFLOW /**< Some integer overflow. */572,MPG123_BAD_FLOAT /**< Floating-point computations work not as expected. */573};574575/** Look up error strings given integer code.576* \param errcode integer error code577* \return string describing what that error error code means578*/579MPG123_EXPORT const char* mpg123_plain_strerror(int errcode);580581/** Give string describing what error has occured in the context of handle mh.582* When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via583* char *errmsg = mpg123_strerror(mh)584* This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE.585* \param mh handle586* \return error message587*/588MPG123_EXPORT const char* mpg123_strerror(mpg123_handle *mh);589590/** Return the plain errcode intead of a string.591* \param mh handle592* \return error code recorded in handle or MPG123_BAD_HANDLE593*/594MPG123_EXPORT int mpg123_errcode(mpg123_handle *mh);595596/** @} */597598599/** \defgroup mpg123_decoder mpg123 decoder selection600*601* Functions to list and select the available decoders.602* Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is).603*604* @{605*/606607/** Get available decoder list.608* \return NULL-terminated array of generally available decoder names (plain 8bit ASCII)609*/610MPG123_EXPORT const char **mpg123_decoders(void);611612/** Get supported decoder list.613*614* This possibly writes to static storage in the library, so avoid615* calling concurrently, please.616*617* \return NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII)618*/619MPG123_EXPORT const char **mpg123_supported_decoders(void);620621/** Set the active decoder.622* \param mh handle623* \param decoder_name name of decoder624* \return MPG123_OK on success625*/626MPG123_EXPORT int mpg123_decoder(mpg123_handle *mh, const char* decoder_name);627628/** Get the currently active decoder name.629* The active decoder engine can vary depening on output constraints,630* mostly non-resampling, integer output is accelerated via 3DNow & Co. but for631* other modes a fallback engine kicks in.632* Note that this can return a decoder that is only active in the hidden and not633* available as decoder choice from the outside.634* \param mh handle635* \return The decoder name or NULL on error.636*/637MPG123_EXPORT const char* mpg123_current_decoder(mpg123_handle *mh);638639/** @} */640641642/** \defgroup mpg123_output mpg123 output audio format643*644* Functions to get and select the format of the decoded audio.645*646* Before you dive in, please be warned that you might get confused by this.647* This seems to happen a lot, therefore I am trying to explain in advance.648* If you do feel confused and just want to decode your normal MPEG audio files that649* don't alter properties in the middle, just use mpg123_open_fixed() with a fixed encoding650* and channel count and forget about a matrix of audio formats. If you want to get funky,651* read ahead ...652*653* The mpg123 library decides what output format to use when encountering the first frame in a stream, or actually any frame that is still valid but differs from the frames before in the prompted output format. At such a deciding point, an internal table of allowed encodings, sampling rates and channel setups is consulted. According to this table, an output format is chosen and the decoding engine set up accordingly (including optimized routines for different output formats). This might seem unusual but it just follows from the non-existence of "MPEG audio files" with defined overall properties. There are streams, streams are concatenations of (semi) independent frames. We store streams on disk and call them "MPEG audio files", but that does not change their nature as the decoder is concerned (the LAME/Xing header for gapless decoding makes things interesting again).654*655* To get to the point: What you do with mpg123_format() and friends is to fill the internal table of allowed formats before it is used. That includes removing support for some formats or adding your forced sample rate (see MPG123_FORCE_RATE) that will be used with the crude internal resampler. Also keep in mind that the sample encoding is just a question of choice -- the MPEG frames do only indicate their native sampling rate and channel count. If you want to decode to integer or float samples, 8 or 16 bit ... that is your decision. In a "clean" world, libmpg123 would always decode to 32 bit float and let you handle any sample conversion. But there are optimized routines that work faster by directly decoding to the desired encoding / accuracy. We prefer efficiency over conceptual tidyness.656*657* People often start out thinking that mpg123_format() should change the actual decoding format on the fly. That is wrong. It only has effect on the next natural change of output format, when libmpg123 will consult its format table again. To make life easier, you might want to call mpg123_format_none() before any thing else and then just allow one desired encoding and a limited set of sample rates / channel choices that you actually intend to deal with. You can force libmpg123 to decode everything to 44100 KHz, stereo, 16 bit integer ... it will duplicate mono channels and even do resampling if needed (unless that feature is disabled in the build, same with some encodings). But I have to stress that the resampling of libmpg123 is very crude and doesn't even contain any kind of "proper" interpolation.658*659* In any case, watch out for MPG123_NEW_FORMAT as return message from decoding routines and call mpg123_getformat() to get the currently active output format.660*661* @{662*/663664/** They can be combined into one number (3) to indicate mono and stereo... */665enum mpg123_channelcount666{667MPG123_MONO = 1 /**< mono */668,MPG123_STEREO = 2 /**< stereo */669};670671/** An array of supported standard sample rates672* These are possible native sample rates of MPEG audio files.673* You can still force mpg123 to resample to a different one, but by674* default you will only get audio in one of these samplings.675* This list is in ascending order.676* \param list Store a pointer to the sample rates array there.677* \param number Store the number of sample rates there. */678MPG123_EXPORT void mpg123_rates(const long **list, size_t *number);679680/** An array of supported audio encodings.681* An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED).682* \param list Store a pointer to the encodings array there.683* \param number Store the number of encodings there. */684MPG123_EXPORT void mpg123_encodings(const int **list, size_t *number);685686/** Return the size (in bytes) of one mono sample of the named encoding.687* \param encoding The encoding value to analyze.688* \return positive size of encoding in bytes, 0 on invalid encoding. */689MPG123_EXPORT int mpg123_encsize(int encoding);690691/** Configure a mpg123 handle to accept no output format at all,692* use before specifying supported formats with mpg123_format693* \param mh handle694* \return MPG123_OK on success695*/696MPG123_EXPORT int mpg123_format_none(mpg123_handle *mh);697698/** Configure mpg123 handle to accept all formats699* (also any custom rate you may set) -- this is default.700* \param mh handle701* \return MPG123_OK on success702*/703MPG123_EXPORT int mpg123_format_all(mpg123_handle *mh);704705/** Set the audio format support of a mpg123_handle in detail:706* \param mh handle707* \param rate The sample rate value (in Hertz).708* \param channels A combination of MPG123_STEREO and MPG123_MONO.709* \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.710* \return MPG123_OK on success, MPG123_ERR if there was an error. */711MPG123_EXPORT int mpg123_format( mpg123_handle *mh712, long rate, int channels, int encodings );713714/** Set the audio format support of a mpg123_handle in detail:715* \param mh handle716* \param rate The sample rate value (in Hertz). Special value 0 means717* all rates (the reason for this variant of mpg123_format()).718* \param channels A combination of MPG123_STEREO and MPG123_MONO.719* \param encodings A combination of accepted encodings for rate and channels,720* p.ex MPG123_ENC_SIGNED16 | MPG123_ENC_ULAW_8 (or 0 for no support).721* Please note that some encodings may not be supported in the library build722* and thus will be ignored here.723* \return MPG123_OK on success, MPG123_ERR if there was an error. */724MPG123_EXPORT int mpg123_format2( mpg123_handle *mh725, long rate, int channels, int encodings );726727/** Check to see if a specific format at a specific rate is supported728* by mpg123_handle.729* \param mh handle730* \param rate sampling rate731* \param encoding encoding732* \return 0 for no support (that includes invalid parameters), MPG123_STEREO,733* MPG123_MONO or MPG123_STEREO|MPG123_MONO. */734MPG123_EXPORT int mpg123_format_support( mpg123_handle *mh735, long rate, int encoding );736737/** Get the current output format written to the addresses given.738* If the stream is freshly loaded, this will try to parse enough739* of it to give you the format to come. This clears the flag that740* would otherwise make the first decoding call return741* MPG123_NEW_FORMAT.742* \param mh handle743* \param rate sampling rate return address744* \param channels channel count return address745* \param encoding encoding return address746* \return MPG123_OK on success747*/748MPG123_EXPORT int mpg123_getformat( mpg123_handle *mh749, long *rate, int *channels, int *encoding );750751/** Get the current output format written to the addresses given.752* This differs from plain mpg123_getformat() in that you can choose753* _not_ to clear the flag that would trigger the next decoding call754* to return MPG123_NEW_FORMAT in case of a new format arriving.755* \param mh handle756* \param rate sampling rate return address757* \param channels channel count return address758* \param encoding encoding return address759* \param clear_flag if true, clear internal format flag760* \return MPG123_OK on success761*/762MPG123_EXPORT int mpg123_getformat2( mpg123_handle *mh763, long *rate, int *channels, int *encoding, int clear_flag );764765/** @} */766767768/** \defgroup mpg123_input mpg123 file input and decoding769*770* Functions for input bitstream and decoding operations.771* 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!).772* @{773*/774775#ifndef MPG123_PORTABLE_API776/** Open a simple MPEG file with fixed properties.777*778* This function shall simplify the common use case of a plain MPEG779* file on disk that you want to decode, with one fixed sample780* rate and channel count, and usually a length defined by a Lame/Info/Xing781* tag. It will:782*783* - set the MPG123_NO_FRANKENSTEIN flag784* - set up format support according to given parameters,785* - open the file,786* - query audio format,787* - fix the audio format support table to ensure the format stays the same,788* - call mpg123_scan() if there is no header frame to tell the track length.789*790* From that on, you can call mpg123_getformat() for querying the sample791* rate (and channel count in case you allowed both) and mpg123_length()792* to get a pretty safe number for the duration.793* Only the sample rate is left open as that indeed is a fixed property of794* MPEG files. You could set MPG123_FORCE_RATE beforehand, but that may trigger795* low-quality resampling in the decoder, only do so if in dire need.796* The library will convert mono files to stereo for you, and vice versa.797* If any constraint cannot be satisified (most likely because of a non-default798* build of libmpg123), you get MPG123_ERR returned and can query the detailed799* cause from the handle. Only on MPG123_OK there will an open file that you800* then close using mpg123_close(), or implicitly on mpg123_delete() or the next801* call to open another file.802*803* So, for your usual CD rip collection, you could use804*805* mpg123_open_fixed(mh, path, MPG123_STEREO, MPG123_ENC_SIGNED_16)806*807* and be happy calling mpg123_getformat() to verify 44100 Hz rate, then just808* playing away with mpg123_read(). The occasional mono file, or MP2 file,809* will also be decoded without you really noticing. Just the speed could be810* wrong if you do not care about sample rate at all.811* \param mh handle812* \param path filesystem path (see mpg123_open())813* \param channels allowed channel count, either 1 (MPG123_MONO) or814* 2 (MPG123_STEREO), or bitwise or of them, but then you're halfway back to815* calling mpg123_format() again;-)816* \param encoding a definite encoding from enum mpg123_enc_enum817* or a bitmask like for mpg123_format(), defeating the purpose somewhat818*/819MPG123_EXPORT int mpg123_open_fixed(mpg123_handle *mh, const char *path820, int channels, int encoding);821822/** Open and prepare to decode the specified file by filesystem path.823* This does not open HTTP urls; libmpg123 contains no networking code.824* If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().825*826* The path parameter usually is just a string that is handed to the underlying827* OS routine for opening, treated as a blob of binary data. On platforms828* where encoding needs to be involved, something like _wopen() is called829* underneath and the path argument to libmpg123 is assumed to be encoded in UTF-8.830* So, if you have to ask yourself which encoding is needed, the answer is831* UTF-8, which also fits any sane modern install of Unix-like systems.832*833* \param mh handle834* \param path filesystem path835* \return MPG123_OK on success836*/837MPG123_EXPORT int mpg123_open(mpg123_handle *mh, const char *path);838839/** Use an already opened file descriptor as the bitstream input840* mpg123_close() will _not_ close the file descriptor.841* \param mh handle842* \param fd file descriptor843* \return MPG123_OK on success844*/845MPG123_EXPORT int mpg123_open_fd(mpg123_handle *mh, int fd);846847/** Use an opaque handle as bitstream input. This works only with the848* replaced I/O from mpg123_replace_reader_handle() or mpg123_reader64()!849* mpg123_close() will call the cleanup callback for your non-NULL850* handle (if you gave one).851* Note that this used to be usable with MPG123_PORTABLE_API defined in852* mpg123 1.32.x and was in fact the only entry point for handle I/O.853* Since mpg123 1.33.0 and API version 49, there is854* mpg123_open_handle64() for the portable case and has to be used855* instead of this function here, even if it _would_ work just fine,856* the inclusion of a largefile-renamed symbol in the portable set was wrong.857*858* \param mh handle859* \param iohandle your handle860* \return MPG123_OK on success861*/862MPG123_EXPORT int mpg123_open_handle(mpg123_handle *mh, void *iohandle);863#endif864865/** Open and prepare to decode the specified file by filesystem path.866* This works exactly like mpg123_open() in modern libmpg123, see there867* for more description. This name is not subject to largefile symbol renaming.868* You can also use it with MPG123_PORTABLE_API.869*870* \param mh handle871* \param path filesystem path of your resource872* \return MPG123_OK on success873*/874MPG123_EXPORT int mpg123_open64(mpg123_handle *mh, const char *path);875876/** Open a simple MPEG file with fixed properties.877* This is the same as mpg123_open_fixed(), just with a stable878* symbol name for int64_t portable API.879*880* \param mh handle881* \param path filesystem path (see mpg123_open())882* \param channels allowed channel count, either 1 (MPG123_MONO) or883* 2 (MPG123_STEREO), or bitwise or of them, but then you're halfway back to884* calling mpg123_format() again;-)885* \param encoding a definite encoding from enum mpg123_enc_enum886* or a bitmask like for mpg123_format(), defeating the purpose somewhat887*/888MPG123_EXPORT int mpg123_open_fixed64(mpg123_handle *mh, const char *path889, int channels, int encoding);890891/** Use an opaque handle as bitstream input. This works only with the892* replaced I/O from mpg123_reader64()!893* mpg123_close() will call the cleanup callback for your non-NULL894* handle (if you gave one).895* This is a simplified variant of mpg123_open_handle() that only896* supports the int64_t API, available with MPG123_PORTABLE_API.897*898* \param mh handle899* \param iohandle your handle900* \return MPG123_OK on success901*/902MPG123_EXPORT int mpg123_open_handle64(mpg123_handle *mh, void *iohandle);903904/** Open a new bitstream and prepare for direct feeding905* This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.906* Also, you are expected to handle ICY metadata extraction yourself. This907* input method does not handle MPG123_ICY_INTERVAL. It does parse ID3 frames, though.908* \param mh handle909* \return MPG123_OK on success910*/911MPG123_EXPORT int mpg123_open_feed(mpg123_handle *mh);912913/** Closes the source, if libmpg123 opened it.914* \param mh handle915* \return MPG123_OK on success916*/917MPG123_EXPORT int mpg123_close(mpg123_handle *mh);918919/** Read from stream and decode up to outmemsize bytes.920*921* Note: The type of outmemory changed to a void pointer in mpg123 1.26.0922* (API version 45).923*924* \param mh handle925* \param outmemory address of output buffer to write to926* \param outmemsize maximum number of bytes to write927* \param done address to store the number of actually decoded bytes to928* \return MPG123_OK or error/message code929*/930MPG123_EXPORT int mpg123_read(mpg123_handle *mh931, void *outmemory, size_t outmemsize, size_t *done );932933/** Feed data for a stream that has been opened with mpg123_open_feed().934* It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.935* \param mh handle936* \param in input buffer937* \param size number of input bytes938* \return MPG123_OK or error/message code.939*/940MPG123_EXPORT int mpg123_feed( mpg123_handle *mh941, const unsigned char *in, size_t size );942943/** Decode MPEG Audio from inmemory to outmemory.944* This is very close to a drop-in replacement for old mpglib.945* When you give zero-sized output buffer the input will be parsed until946* decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it)947* without taking decoded data.948* Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-).949* You can actually always decide if you want those specialized functions in separate steps or one call this one here.950*951* Note: The type of outmemory changed to a void pointer in mpg123 1.26.0952* (API version 45).953*954* \param mh handle955* \param inmemory input buffer956* \param inmemsize number of input bytes957* \param outmemory output buffer958* \param outmemsize maximum number of output bytes959* \param done address to store the number of actually decoded bytes to960* \return error/message code (watch out especially for MPG123_NEED_MORE)961*/962MPG123_EXPORT int mpg123_decode( mpg123_handle *mh963, const unsigned char *inmemory, size_t inmemsize964, void *outmemory, size_t outmemsize, size_t *done );965966#ifndef MPG123_PORTABLE_API967/** Decode next MPEG frame to internal buffer968* or read a frame and return after setting a new format.969* \param mh handle970* \param num current frame offset gets stored there971* \param audio This pointer is set to the internal buffer to read the decoded audio from.972* \param bytes number of output bytes ready in the buffer973* \return MPG123_OK or error/message code974*/975MPG123_EXPORT int mpg123_decode_frame( mpg123_handle *mh976, off_t *num, unsigned char **audio, size_t *bytes );977978/** Decode current MPEG frame to internal buffer.979* Warning: This is experimental API that might change in future releases!980* Please watch mpg123 development closely when using it.981* \param mh handle982* \param num last frame offset gets stored there983* \param audio this pointer is set to the internal buffer to read the decoded audio from.984* \param bytes number of output bytes ready in the buffer985* \return MPG123_OK or error/message code986*/987MPG123_EXPORT int mpg123_framebyframe_decode( mpg123_handle *mh988, off_t *num, unsigned char **audio, size_t *bytes );989#endif /* un-portable API */990991/** Decode next MPEG frame to internal buffer992* or read a frame and return after setting a new format.993* \param mh handle994* \param num current frame offset gets stored there995* \param audio This pointer is set to the internal buffer to read the decoded audio from.996* \param bytes number of output bytes ready in the buffer997* \return MPG123_OK or error/message code998*/999MPG123_EXPORT int mpg123_decode_frame64( mpg123_handle *mh1000, int64_t *num, unsigned char **audio, size_t *bytes );10011002/** Decode current MPEG frame to internal buffer.1003* Warning: This is experimental API that might change in future releases!1004* Please watch mpg123 development closely when using it.1005* \param mh handle1006* \param num last frame offset gets stored there1007* \param audio this pointer is set to the internal buffer to read the decoded audio from.1008* \param bytes number of output bytes ready in the buffer1009* \return MPG123_OK or error/message code1010*/1011MPG123_EXPORT int mpg123_framebyframe_decode64( mpg123_handle *mh1012, int64_t *num, unsigned char **audio, size_t *bytes );10131014/** Find, read and parse the next mp3 frame1015* Warning: This is experimental API that might change in future releases!1016* Please watch mpg123 development closely when using it.1017* \param mh handle1018* \return MPG123_OK or error/message code1019*/1020MPG123_EXPORT int mpg123_framebyframe_next(mpg123_handle *mh);10211022/** Get access to the raw input data for the last parsed frame.1023* This gives you a direct look (and write access) to the frame body data.1024* Together with the raw header, you can reconstruct the whole raw MPEG stream without junk and meta data, or play games by actually modifying the frame body data before decoding this frame (mpg123_framebyframe_decode()).1025* A more sane use would be to use this for CRC checking (see mpg123_info() and MPG123_CRC), the first two bytes of the body make up the CRC16 checksum, if present.1026* You can provide NULL for a parameter pointer when you are not interested in the value.1027*1028* \param mh handle1029* \param header the 4-byte MPEG header1030* \param bodydata pointer to the frame body stored in the handle (without the header)1031* \param bodybytes size of frame body in bytes (without the header)1032* \return MPG123_OK if there was a yet un-decoded frame to get the1033* data from, MPG123_BAD_HANDLE or MPG123_ERR otherwise (without further1034* explanation, the error state of the mpg123_handle is not modified by1035* this function).1036*/1037MPG123_EXPORT int mpg123_framedata( mpg123_handle *mh1038, unsigned long *header, unsigned char **bodydata, size_t *bodybytes );10391040#ifndef MPG123_PORTABLE_API1041/** Get the input position (byte offset in stream) of the last parsed frame.1042* This can be used for external seek index building, for example.1043* It just returns the internally stored offset, regardless of validity --1044* you ensure that a valid frame has been parsed before!1045* \param mh handle1046* \return byte offset in stream1047*/1048MPG123_EXPORT off_t mpg123_framepos(mpg123_handle *mh);1049#endif10501051/** Get the 64 bit input position (byte offset in stream) of the last parsed frame.1052* This can be used for external seek index building, for example.1053* It just returns the internally stored offset, regardless of validity --1054* you ensure that a valid frame has been parsed before!1055* \param mh handle1056* \return byte offset in stream1057*/1058MPG123_EXPORT int64_t mpg123_framepos64(mpg123_handle *mh);10591060/** @} */106110621063/** \defgroup mpg123_seek mpg123 position and seeking1064*1065* Functions querying and manipulating position in the decoded audio bitstream.1066* The position is measured in decoded audio samples or MPEG frame offset for1067* the specific functions. The term sample refers to a group of samples for1068* multiple channels, normally dubbed PCM frames. The latter term is1069* avoided here because frame means something different in the context of MPEG1070* audio. Since all samples of a PCM frame occur at the same time, there is only1071* very limited ambiguity when talking about playback offset, as counting each1072* channel sample individually does not make sense.1073*1074* If gapless code is in effect, the positions are adjusted to compensate the1075* skipped padding/delay - meaning, you should not care about that at all and1076* just use the position defined for the samples you get out of the decoder;-)1077* The general usage is modelled after stdlib's ftell() and fseek().1078* Especially, the whence parameter for the seek functions has the same meaning1079* as the one for fseek() and needs the same constants from stdlib.h:1080*1081* - SEEK_SET: set position to (or near to) specified offset1082* - SEEK_CUR: change position by offset from now1083* - SEEK_END: set position to offset from end1084*1085* Since API version 48 (mpg123 1.32), the offset given with SEEK_END is always1086* taken to be negative in the terms of standard lseek(). You can only seek from1087* the end towards the beginning. All earlier versions had the sign wrong, positive1088* was towards the beginning, negative past the end (which results in error,1089* anyway).1090*1091* Note that sample-accurate seek only works when gapless support has been1092* enabled at compile time; seek is frame-accurate otherwise.1093* Also, really sample-accurate seeking (meaning that you get the identical1094* sample value after seeking compared to plain decoding up to the position)1095* is only guaranteed when you do not mess with the position code by using1096* #MPG123_UPSPEED, #MPG123_DOWNSPEED or #MPG123_START_FRAME. The first two mainly1097* should cause trouble with NtoM resampling, but in any case with these options1098* in effect, you have to keep in mind that the sample offset is not the same1099* as counting the samples you get from decoding since mpg123 counts the skipped1100* samples, too (or the samples played twice only once)!1101*1102* Short: When you care about the sample position, don't mess with those1103* parameters;-)1104*1105* Streams may be openend in ways that do not support seeking. Also, consider1106* the effect of #MPG123_FUZZY.1107*1108* @{1109*/11101111#ifndef MPG123_PORTABLE_API1112/** Returns the current position in samples.1113* On the next successful read, you'd get audio data with that offset.1114* \param mh handle1115* \return sample (PCM frame) offset or MPG123_ERR (null handle)1116*/1117MPG123_EXPORT off_t mpg123_tell(mpg123_handle *mh);1118#endif11191120/** Returns the current 64 bit position in samples.1121* On the next successful read, you'd get audio data with that offset.1122* \param mh handle1123* \return sample (PCM frame) offset or MPG123_ERR (null handle)1124*/1125MPG123_EXPORT int64_t mpg123_tell64(mpg123_handle *mh);11261127#ifndef MPG123_PORTABLE_API1128/** Returns the frame number that the next read will give you data from.1129* \param mh handle1130* \return frame offset or MPG123_ERR (null handle)1131*/1132MPG123_EXPORT off_t mpg123_tellframe(mpg123_handle *mh);1133#endif11341135/** Returns the 64 bit frame number that the next read will give you data from.1136* \param mh handle1137* \return frame offset or MPG123_ERR (null handle)1138*/1139MPG123_EXPORT int64_t mpg123_tellframe64(mpg123_handle *mh);11401141#ifndef MPG123_PORTABLE_API1142/** Returns the current byte offset in the input stream.1143* \param mh handle1144* \return byte offset or MPG123_ERR (null handle)1145*/1146MPG123_EXPORT off_t mpg123_tell_stream(mpg123_handle *mh);1147#endif11481149/** Returns the current 64 bit byte offset in the input stream.1150* \param mh handle1151* \return byte offset or MPG123_ERR (null handle)1152*/1153MPG123_EXPORT int64_t mpg123_tell_stream64(mpg123_handle *mh);115411551156#ifndef MPG123_PORTABLE_API1157/** Seek to a desired sample offset.1158* Usage is modelled afer the standard lseek().1159* \param mh handle1160* \param sampleoff offset in samples (PCM frames)1161* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END1162* (Offset for SEEK_END is always effectively negative since API1163* version 48, was inverted from lseek() usage since ever before.)1164* \return The resulting offset >= 0 or error/message code1165*/1166MPG123_EXPORT off_t mpg123_seek( mpg123_handle *mh1167, off_t sampleoff, int whence );1168#endif11691170/** Seek to a desired 64 bit sample offset.1171* Usage is modelled afer the standard lseek().1172* \param mh handle1173* \param sampleoff offset in samples (PCM frames)1174* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END1175* (Offset for SEEK_END is always effectively negative.)1176* \return The resulting offset >= 0 or error/message code1177*/1178MPG123_EXPORT int64_t mpg123_seek64( mpg123_handle *mh1179, int64_t sampleoff, int whence );11801181#ifndef MPG123_PORTABLE_API1182/** Seek to a desired sample offset in data feeding mode.1183* This just prepares things to be right only if you ensure that the next chunk1184* of input data will be from input_offset byte position.1185* \param mh handle1186* \param sampleoff offset in samples (PCM frames)1187* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END1188* (Offset for SEEK_END is always effectively negative since API1189* version 48, was inverted from lseek() usage since ever before.)1190* \param input_offset The position it expects to be at the1191* next time data is fed to mpg123_decode().1192* \return The resulting offset >= 0 or error/message code1193*/1194MPG123_EXPORT off_t mpg123_feedseek( mpg123_handle *mh1195, off_t sampleoff, int whence, off_t *input_offset );1196#endif11971198/** Seek to a desired 64 bit sample offset in data feeding mode.1199* This just prepares things to be right only if you ensure that the next chunk1200* of input data will be from input_offset byte position.1201* \param mh handle1202* \param sampleoff offset in samples (PCM frames)1203* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END1204* (Offset for SEEK_END is always effectively negative.)1205* \param input_offset The position it expects to be at the1206* next time data is fed to mpg123_decode().1207* \return The resulting offset >= 0 or error/message code1208*/1209MPG123_EXPORT int64_t mpg123_feedseek64( mpg123_handle *mh1210, int64_t sampleoff, int whence, int64_t *input_offset );12111212#ifndef MPG123_PORTABLE_API1213/** Seek to a desired MPEG frame offset.1214* Usage is modelled afer the standard lseek().1215* \param mh handle1216* \param frameoff offset in MPEG frames1217* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END1218* (Offset for SEEK_END is always effectively negative since API1219* version 48, was inverted from lseek() usage since ever before.)1220* \return The resulting offset >= 0 or error/message code */1221MPG123_EXPORT off_t mpg123_seek_frame( mpg123_handle *mh1222, off_t frameoff, int whence );1223#endif12241225/** Seek to a desired 64 bit MPEG frame offset.1226* Usage is modelled afer the standard lseek().1227* \param mh handle1228* \param frameoff offset in MPEG frames1229* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END1230* (Offset for SEEK_END is always effectively negative.)1231* \return The resulting offset >= 0 or error/message code */1232MPG123_EXPORT int64_t mpg123_seek_frame64( mpg123_handle *mh1233, int64_t frameoff, int whence );12341235#ifndef MPG123_PORTABLE_API1236/** Return a MPEG frame offset corresponding to an offset in seconds.1237* 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.1238* \return frame offset >= 0 or error/message code */1239MPG123_EXPORT off_t mpg123_timeframe(mpg123_handle *mh, double sec);12401241/** Give access to the frame index table that is managed for seeking.1242* You are asked not to modify the values... Use mpg123_set_index to set the1243* seek index.1244* Note: This can be just a copy of the data in case a conversion is done1245* from the internal 64 bit values.1246* \param mh handle1247* \param offsets pointer to the index array1248* \param step one index byte offset advances this many MPEG frames1249* \param fill number of recorded index offsets; size of the array1250* \return MPG123_OK on success1251*/1252MPG123_EXPORT int mpg123_index( mpg123_handle *mh1253, off_t **offsets, off_t *step, size_t *fill );1254#endif12551256/** Return a 64 bit MPEG frame offset corresponding to an offset in seconds.1257* 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.1258* \return frame offset >= 0 or error/message code */1259MPG123_EXPORT int64_t mpg123_timeframe64(mpg123_handle *mh, double sec);12601261/** Give access to the 64 bit frame index table that is managed for seeking.1262* You are asked not to modify the values... Use mpg123_set_index to set the1263* seek index.1264* \param mh handle1265* \param offsets pointer to the index array1266* \param step one index byte offset advances this many MPEG frames1267* \param fill number of recorded index offsets; size of the array1268* \return MPG123_OK on success1269*/1270MPG123_EXPORT int mpg123_index64( mpg123_handle *mh1271, int64_t **offsets, int64_t *step, size_t *fill );12721273#ifndef MPG123_PORTABLE_API1274/** Set the frame index table1275* Setting offsets to NULL and fill > 0 will allocate fill entries. Setting offsets1276* to NULL and fill to 0 will clear the index and free the allocated memory used by the index.1277* Note that this function might involve conversion/copying of data because of1278* the varying nature of off_t. Better use mpg123_set_index64().1279* \param mh handle1280* \param offsets pointer to the index array1281* \param step one index byte offset advances this many MPEG frames1282* \param fill number of recorded index offsets; size of the array1283* \return MPG123_OK on success1284*/1285MPG123_EXPORT int mpg123_set_index( mpg123_handle *mh1286, off_t *offsets, off_t step, size_t fill );1287#endif12881289/** Set the 64 bit frame index table1290* Setting offsets to NULL and fill > 0 will allocate fill entries. Setting offsets1291* to NULL and fill to 0 will clear the index and free the allocated memory used by the index.1292* \param mh handle1293* \param offsets pointer to the index array1294* \param step one index byte offset advances this many MPEG frames1295* \param fill number of recorded index offsets; size of the array1296* \return MPG123_OK on success1297*/1298MPG123_EXPORT int mpg123_set_index64( mpg123_handle *mh1299, int64_t *offsets, int64_t step, size_t fill );130013011302#ifndef MPG123_PORTABLE_API1303/** An old crutch to keep old mpg123 binaries happy.1304* WARNING: This function is there only to avoid runtime linking errors with1305* standalone mpg123 before version 1.32.0 (if you strangely update the1306* library but not the end-user program) and actually is broken1307* for various cases (p.ex. 24 bit output). Do never use. It might eventually1308* be purged from the library.1309*/1310MPG123_EXPORT int mpg123_position( mpg123_handle *mh, off_t INT123_frame_offset, off_t buffered_bytes, off_t *current_frame, off_t *frames_left, double *current_seconds, double *seconds_left);1311#endif13121313/** @} */131413151316/** \defgroup mpg123_voleq mpg123 volume and equalizer1317*1318* @{1319*/13201321/** another channel enumeration, for left/right choice */1322enum mpg123_channels1323{1324MPG123_LEFT=0x1 /**< The Left Channel. */1325,MPG123_RIGHT=0x2 /**< The Right Channel. */1326,MPG123_LR=0x3 /**< Both left and right channel; same as MPG123_LEFT|MPG123_RIGHT */1327};13281329#ifdef MPG123_ENUM_API1330/** Set the 32 Band Audio Equalizer settings.1331*1332* Note that this name is mapped to mpg123_eq2() instead unless1333* MPG123_ENUM_API is defined.1334*1335* \param mh handle1336* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or1337* #MPG123_LEFT|#MPG123_RIGHT for both.1338* \param band The equaliser band to change (from 0 to 31)1339* \param val The (linear) adjustment factor.1340* \return MPG123_OK on success1341*/1342MPG123_EXPORT int mpg123_eq( mpg123_handle *mh1343, enum mpg123_channels channel, int band, double val );1344#endif13451346/** Set the 32 Band Audio Equalizer settings. No enums.1347*1348* This is actually called instead of mpg123_eq() unless MPG123_ENUM_API1349* is defined.1350*1351* \param mh handle1352* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or1353* #MPG123_LEFT|#MPG123_RIGHT for both.1354* \param band The equaliser band to change (from 0 to 31)1355* \param val The (linear) adjustment factor.1356* \return MPG123_OK on success1357*/1358MPG123_EXPORT int mpg123_eq2( mpg123_handle *mh1359, int channel, int band, double val );13601361/** Set a range of equalizer bands1362* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or1363* #MPG123_LEFT|#MPG123_RIGHT for both.1364* \param mh handle1365* \param a The first equalizer band to set (from 0 to 31)1366* \param b The last equalizer band to set (from 0 to 31)1367* \param factor The (linear) adjustment factor, 1 being neutral.1368* \return MPG123_OK on success1369*/1370MPG123_EXPORT int mpg123_eq_bands( mpg123_handle *mh1371, int channel, int a, int b, double factor );13721373/** Change a range of equalizer bands1374* \param mh handle1375* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or1376* #MPG123_LEFT|#MPG123_RIGHT for both.1377* \param a The first equalizer band to change (from 0 to 31)1378* \param b The last equalizer band to change (from 0 to 31)1379* \param db The adjustment in dB (limited to +/- 60 dB).1380* \return MPG123_OK on success1381*/1382MPG123_EXPORT int mpg123_eq_change( mpg123_handle *mh1383, int channel, int a, int b, double db );13841385#ifdef MPG123_ENUM_API1386/** Get the 32 Band Audio Equalizer settings.1387*1388* Note that this name is mapped to mpg123_geteq2() instead unless1389* MPG123_ENUM_API is defined.1390*1391* \param mh handle1392* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or1393* #MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.1394* \param band The equaliser band to change (from 0 to 31)1395* \return The (linear) adjustment factor (zero for pad parameters) */1396MPG123_EXPORT double mpg123_geteq(mpg123_handle *mh1397, enum mpg123_channels channel, int band);1398#endif13991400/** Get the 32 Band Audio Equalizer settings.1401*1402* This is actually called instead of mpg123_geteq() unless MPG123_ENUM_API1403* is defined.1404*1405* \param mh handle1406* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or1407* #MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.1408* \param band The equaliser band to change (from 0 to 31)1409* \return The (linear) adjustment factor (zero for pad parameters) */1410MPG123_EXPORT double mpg123_geteq2(mpg123_handle *mh, int channel, int band);14111412/** Reset the 32 Band Audio Equalizer settings to flat1413* \param mh handle1414* \return MPG123_OK on success1415*/1416MPG123_EXPORT int mpg123_reset_eq(mpg123_handle *mh);14171418/** Set the absolute output volume including the RVA setting,1419* vol<0 just applies (a possibly changed) RVA setting.1420* \param mh handle1421* \param vol volume value (linear factor)1422* \return MPG123_OK on success1423*/1424MPG123_EXPORT int mpg123_volume(mpg123_handle *mh, double vol);14251426/** Adjust output volume including the RVA setting by chosen amount1427* \param mh handle1428* \param change volume value (linear factor increment)1429* \return MPG123_OK on success1430*/1431MPG123_EXPORT int mpg123_volume_change(mpg123_handle *mh, double change);14321433/** Adjust output volume including the RVA setting by chosen amount1434* \param mh handle1435* \param db volume adjustment in decibels (limited to +/- 60 dB)1436* \return MPG123_OK on success1437*/1438MPG123_EXPORT int mpg123_volume_change_db(mpg123_handle *mh, double db);14391440/** Return current volume setting, the actual value due to RVA, and the RVA1441* adjustment itself. It's all as double float value to abstract the sample1442* format. The volume values are linear factors / amplitudes (not percent)1443* and the RVA value is in decibels.1444* \param mh handle1445* \param base return address for base volume (linear factor)1446* \param really return address for actual volume (linear factor)1447* \param rva_db return address for RVA value (decibels)1448* \return MPG123_OK on success1449*/1450MPG123_EXPORT int mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db);14511452/* TODO: Set some preamp in addition / to replace internal RVA handling? */14531454/** @} */145514561457/** \defgroup mpg123_status mpg123 status and information1458*1459* @{1460*/14611462/** Enumeration of the mode types of Variable Bitrate */1463enum mpg123_vbr {1464MPG123_CBR=0, /**< Constant Bitrate Mode (default) */1465MPG123_VBR, /**< Variable Bitrate Mode */1466MPG123_ABR /**< Average Bitrate Mode */1467};14681469/** Enumeration of the MPEG Versions */1470enum mpg123_version {1471MPG123_1_0=0, /**< MPEG Version 1.0 */1472MPG123_2_0, /**< MPEG Version 2.0 */1473MPG123_2_5 /**< MPEG Version 2.5 */1474};147514761477/** Enumeration of the MPEG Audio mode.1478* Only the mono mode has 1 channel, the others have 2 channels. */1479enum mpg123_mode {1480MPG123_M_STEREO=0, /**< Standard Stereo. */1481MPG123_M_JOINT, /**< Joint Stereo. */1482MPG123_M_DUAL, /**< Dual Channel. */1483MPG123_M_MONO /**< Single Channel. */1484};148514861487/** Enumeration of the MPEG Audio flag bits */1488enum mpg123_flags {1489MPG123_CRC=0x1, /**< The bitstream is error protected using 16-bit CRC. */1490MPG123_COPYRIGHT=0x2, /**< The bitstream is copyrighted. */1491MPG123_PRIVATE=0x4, /**< The private bit has been set. */1492MPG123_ORIGINAL=0x8 /**< The bitstream is an original, not a copy. */1493};14941495#ifdef MPG123_ENUM_API1496/** Data structure for storing information about a frame of MPEG Audio */1497struct mpg123_frameinfo1498{1499enum mpg123_version version; /**< The MPEG version (1.0/2.0/2.5). */1500int layer; /**< The MPEG Audio Layer (MP1/MP2/MP3). */1501long rate; /**< The sampling rate in Hz. */1502enum mpg123_mode mode; /**< The audio mode (Mono, Stereo, Joint-stero, Dual Channel). */1503int mode_ext; /**< The mode extension bit flag. */1504int framesize; /**< The size of the frame (in bytes, including header). */1505enum mpg123_flags flags; /**< MPEG Audio flag bits. Just now I realize that it should be declared as int, not enum. It's a bitwise combination of the enum values. */1506int emphasis; /**< The emphasis type. */1507int bitrate; /**< Bitrate of the frame (kbps). */1508int abr_rate; /**< The target average bitrate. */1509enum mpg123_vbr vbr; /**< The VBR mode. */1510};1511#endif15121513/** Data structure for storing information about a frame of MPEG Audio without enums */1514struct mpg123_frameinfo21515{1516int version; /**< The MPEG version (1.0/2.0/2.5), enum mpg123_version. */1517int layer; /**< The MPEG Audio Layer (MP1/MP2/MP3). */1518long rate; /**< The sampling rate in Hz. */1519int mode; /**< The audio mode (enum mpg123_mode, Mono, Stereo, Joint-stero, Dual Channel). */1520int mode_ext; /**< The mode extension bit flag. */1521int framesize; /**< The size of the frame (in bytes, including header). */1522int flags; /**< MPEG Audio flag bits. Bitwise combination of enum mpg123_flags values. */1523int emphasis; /**< The emphasis type. */1524int bitrate; /**< Bitrate of the frame (kbps). */1525int abr_rate; /**< The target average bitrate. */1526int vbr; /**< The VBR mode, enum mpg123_vbr. */1527};15281529/** Data structure for even more detailed information out of the decoder,1530* for MPEG layer III only.1531* This was added to support the frame analyzer by the Lame project and1532* just follows what was used there before. You know what the fields mean1533* if you want use this structure. */1534struct mpg123_moreinfo1535{1536double xr[2][2][576]; /**< internal data */1537double sfb[2][2][22]; /**< [2][2][SBMAX_l] */1538double sfb_s[2][2][3*13]; /**< [2][2][3*SBMAX_s] */1539int qss[2][2]; /**< internal data */1540int big_values[2][2]; /**< internal data */1541int sub_gain[2][2][3]; /**< internal data */1542int scalefac_scale[2][2]; /**< internal data */1543int preflag[2][2]; /**< internal data */1544int blocktype[2][2]; /**< internal data */1545int mixed[2][2]; /**< internal data */1546int mainbits[2][2]; /**< internal data */1547int sfbits[2][2]; /**< internal data */1548int scfsi[2]; /**< internal data */1549int maindata; /**< internal data */1550int padding; /**< internal data */1551};15521553#ifdef MPG123_ENUM_API1554/** Get frame information about the MPEG audio bitstream and store1555* it in a mpg123_frameinfo structure.1556*1557* Note that this name is mapped to mpg123_info2() instead unless1558* MPG123_ENUM_API is defined.1559*1560* \param mh handle1561* \param mi address of existing frameinfo structure to write to1562* \return MPG123_OK on success1563*/1564MPG123_EXPORT int mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi);1565#endif15661567/** Get frame information about the MPEG audio bitstream and store1568* it in a mpg123_frameinfo2 structure.1569*1570* This is actually called instead of mpg123_info()1571* unless MPG123_ENUM_API is defined.1572*1573* \param mh handle1574* \param mi address of existing frameinfo structure to write to1575* \return MPG123_OK on success1576*/1577MPG123_EXPORT int mpg123_info2(mpg123_handle *mh, struct mpg123_frameinfo2 *mi);15781579/** Trigger collection of additional decoder information while decoding.1580* \param mh handle1581* \param mi pointer to data storage (NULL to disable collection)1582* \return MPG123_OK if the collection was enabled/disabled as desired, MPG123_ERR1583* otherwise (e.g. if the feature is disabled)1584*/1585MPG123_EXPORT int mpg123_set_moreinfo( mpg123_handle *mh1586, struct mpg123_moreinfo *mi );15871588/** Get the safe output buffer size for all cases1589* (when you want to replace the internal buffer)1590* \return safe buffer size1591*/1592MPG123_EXPORT size_t mpg123_safe_buffer(void);15931594/** Make a full parsing scan of each frame in the file. ID3 tags are found. An1595* accurate length value is stored. Seek index will be filled. A seek back to1596* current position is performed. At all, this function refuses work when1597* stream is not seekable.1598* \param mh handle1599* \return MPG123_OK on success1600*/1601MPG123_EXPORT int mpg123_scan(mpg123_handle *mh);16021603#ifndef MPG123_PORTABLE_API1604/** Return, if possible, the full (expected) length of current track in1605* MPEG frames.1606* \param mh handle1607* \return length >= 0 or MPG123_ERR if there is no length guess possible.1608*/1609MPG123_EXPORT off_t mpg123_framelength(mpg123_handle *mh);16101611/** Return, if possible, the full (expected) length of current1612* track in samples (PCM frames).1613*1614* This relies either on an Info frame at the beginning or a previous1615* call to mpg123_scan() to get the real number of MPEG frames in a1616* file. It will guess based on file size if neither Info frame nor1617* scan data are present. In any case, there is no guarantee that the1618* decoder will not give you more data, for example in case the open1619* file gets appended to during decoding.1620* \param mh handle1621* \return length >= 0 or MPG123_ERR if there is no length guess possible.1622*/1623MPG123_EXPORT off_t mpg123_length(mpg123_handle *mh);16241625/** Override the value for file size in bytes.1626* Useful for getting sensible track length values in feed mode or for HTTP streams.1627* \param mh handle1628* \param size file size in bytes1629* \return MPG123_OK on success1630*/1631MPG123_EXPORT int mpg123_set_filesize(mpg123_handle *mh, off_t size);1632#endif16331634/** Return, if possible, the full (expected) length of current track in1635* MPEG frames as 64 bit number.1636* \param mh handle1637* \return length >= 0 or MPG123_ERR if there is no length guess possible.1638*/1639MPG123_EXPORT int64_t mpg123_framelength64(mpg123_handle *mh);16401641/** Return, if possible, the full (expected) length of current1642* track in samples (PCM frames) as 64 bit value.1643*1644* This relies either on an Info frame at the beginning or a previous1645* call to mpg123_scan() to get the real number of MPEG frames in a1646* file. It will guess based on file size if neither Info frame nor1647* scan data are present. In any case, there is no guarantee that the1648* decoder will not give you more data, for example in case the open1649* file gets appended to during decoding.1650* \param mh handle1651* \return length >= 0 or MPG123_ERR if there is no length guess possible.1652*/1653MPG123_EXPORT int64_t mpg123_length64(mpg123_handle *mh);16541655/** Override the 64 bit value for file size in bytes.1656* Useful for getting sensible track length values in feed mode or for HTTP streams.1657* \param mh handle1658* \param size file size in bytes1659* \return MPG123_OK on success1660*/1661MPG123_EXPORT int mpg123_set_filesize64(mpg123_handle *mh, int64_t size);16621663/** Get MPEG frame duration in seconds.1664* \param mh handle1665* \return frame duration in seconds, <0 on error1666*/1667MPG123_EXPORT double mpg123_tpf(mpg123_handle *mh);16681669/** Get MPEG frame duration in samples.1670* \param mh handle1671* \return samples per frame for the most recently parsed frame; <0 on errors1672*/1673MPG123_EXPORT int mpg123_spf(mpg123_handle *mh);16741675/** Get and reset the clip count.1676* \param mh handle1677* \return count of clipped samples1678*/1679MPG123_EXPORT long mpg123_clip(mpg123_handle *mh);168016811682/** The key values for state information from mpg123_getstate(). */1683enum mpg123_state1684{1685MPG123_ACCURATE = 1 /**< Query if positons are currently accurate (integer value, 0 if false, 1 if true). */1686,MPG123_BUFFERFILL /**< Get fill of internal (feed) input buffer as integer byte count returned as long and as double. An error is returned on integer overflow while converting to (signed) long, but the returned floating point value shold still be fine. */1687,MPG123_FRANKENSTEIN /**< Stream consists of carelessly stitched together files. Seeking may yield unexpected results (also with MPG123_ACCURATE, it may be confused). */1688,MPG123_FRESH_DECODER /**< Decoder structure has been updated, possibly indicating changed stream (integer value, 0 if false, 1 if true). Flag is cleared after retrieval. */1689,MPG123_ENC_DELAY /** Encoder delay read from Info tag (layer III, -1 if unknown). */1690,MPG123_ENC_PADDING /** Encoder padding read from Info tag (layer III, -1 if unknown). */1691,MPG123_DEC_DELAY /** Decoder delay (for layer III only, -1 otherwise). */1692};16931694#ifdef MPG123_ENUM_API1695/** Get various current decoder/stream state information.1696*1697* Note that this name is mapped to mpg123_getstate2() instead unless1698* MPG123_ENUM_API is defined.1699*1700* \param mh handle1701* \param key the key to identify the information to give.1702* \param val the address to return (long) integer values to1703* \param fval the address to return floating point values to1704* \return MPG123_OK on success1705*/1706MPG123_EXPORT int mpg123_getstate( mpg123_handle *mh1707, enum mpg123_state key, long *val, double *fval );1708#endif17091710/** Get various current decoder/stream state information. No enums.1711*1712* This is actually called instead of mpg123_getstate()1713* unless MPG123_ENUM_API is defined.1714*1715* \param mh handle1716* \param key the key to identify the information to give (enum mpg123_state)1717* \param val the address to return (long) integer values to1718* \param fval the address to return floating point values to1719* \return MPG123_OK on success1720*/1721MPG123_EXPORT int mpg123_getstate2( mpg123_handle *mh1722, int key, long *val, double *fval );17231724/** @} */172517261727/** \defgroup mpg123_metadata mpg123 metadata handling1728*1729* Functions to retrieve the metadata from MPEG Audio files and streams.1730* Also includes string handling functions.1731*1732* @{1733*/17341735/** Data structure for storing strings in a safer way than a standard C-String.1736* Can also hold a number of null-terminated strings. */1737typedef struct1738{1739char* p; /**< pointer to the string data */1740size_t size; /**< raw number of bytes allocated */1741size_t fill; /**< number of used bytes (including closing zero byte) */1742} mpg123_string;17431744/** Allocate and intialize a new string.1745* \param val optional initial string value (can be NULL)1746*/1747MPG123_EXPORT mpg123_string* mpg123_new_string(const char* val);17481749/** Free memory of contents and the string structure itself.1750* \param sb string handle1751*/1752MPG123_EXPORT void mpg123_delete_string(mpg123_string* sb);17531754/** Initialize an existing mpg123_string structure to {NULL, 0, 0}.1755* If you hand in a NULL pointer here, your program should crash. The other1756* string functions are more forgiving, but this one here is too basic.1757* \param sb string handle (address of existing structure on your side)1758*/1759MPG123_EXPORT void mpg123_init_string(mpg123_string* sb);17601761/** Free-up memory of the contents of an mpg123_string (not the struct itself).1762* This also calls mpg123_init_string() and hence is safe to be called1763* repeatedly.1764* \param sb string handle1765*/1766MPG123_EXPORT void mpg123_free_string(mpg123_string* sb);17671768/** Change the size of a mpg123_string1769* \param sb string handle1770* \param news new size in bytes1771* \return 0 on error, 1 on success1772*/1773MPG123_EXPORT int mpg123_resize_string(mpg123_string* sb, size_t news);17741775/** Increase size of a mpg123_string if necessary (it may stay larger).1776* Note that the functions for adding and setting in current libmpg1231777* use this instead of mpg123_resize_string().1778* That way, you can preallocate memory and safely work afterwards with1779* pieces.1780* \param sb string handle1781* \param news new minimum size1782* \return 0 on error, 1 on success1783*/1784MPG123_EXPORT int mpg123_grow_string(mpg123_string* sb, size_t news);17851786/** Copy the contents of one mpg123_string string to another.1787* Yes the order of arguments is reversed compated to memcpy().1788* \param from string handle1789* \param to string handle1790* \return 0 on error, 1 on success1791*/1792MPG123_EXPORT int mpg123_copy_string(mpg123_string* from, mpg123_string* to);17931794/** Move the contents of one mpg123_string string to another.1795* This frees any memory associated with the target and moves over the1796* pointers from the source, leaving the source without content after1797* that. The only possible error is that you hand in NULL pointers.1798* If you handed in a valid source, its contents will be gone, even if1799* there was no target to move to. If you hand in a valid target, its1800* original contents will also always be gone, to be replaced with the1801* source's contents if there was some.1802* \param from source string handle1803* \param to target string handle1804* \return 0 on error, 1 on success1805*/1806MPG123_EXPORT int mpg123_move_string(mpg123_string* from, mpg123_string* to);18071808/** Append a C-String to an mpg123_string1809* \param sb string handle1810* \param stuff to append1811* \return 0 on error, 1 on success1812*/1813MPG123_EXPORT int mpg123_add_string(mpg123_string* sb, const char* stuff);18141815/** Append a C-substring to an mpg123 string1816* \param sb string handle1817* \param stuff content to copy1818* \param from offset to copy from1819* \param count number of characters to copy (a null-byte is always appended)1820* \return 0 on error, 1 on success1821*/1822MPG123_EXPORT int mpg123_add_substring( mpg123_string *sb1823, const char *stuff, size_t from, size_t count );18241825/** Set the content of a mpg123_string to a C-string1826* \param sb string handle1827* \param stuff content to copy1828* \return 0 on error, 1 on success1829*/1830MPG123_EXPORT int mpg123_set_string(mpg123_string* sb, const char* stuff);18311832/** Set the content of a mpg123_string to a C-substring1833* \param sb string handle1834* \param stuff the future content1835* \param from offset to copy from1836* \param count number of characters to copy (a null-byte is always appended)1837* \return 0 on error, 1 on success1838*/1839MPG123_EXPORT int mpg123_set_substring( mpg123_string *sb1840, const char *stuff, size_t from, size_t count );18411842/** Count characters in a mpg123 string (non-null bytes or Unicode points).1843* This function is of limited use, as it does just count code points1844* encoded in an UTF-8 string, only loosely related to the count of visible1845* characters. Get your full Unicode handling support elsewhere.1846* \param sb string handle1847* \param utf8 a flag to tell if the string is in utf8 encoding1848* \return character count1849*/1850MPG123_EXPORT size_t mpg123_strlen(mpg123_string *sb, int utf8);18511852/** Remove trailing \\r and \\n, if present.1853* \param sb string handle1854* \return 0 on error, 1 on success1855*/1856MPG123_EXPORT int mpg123_chomp_string(mpg123_string *sb);18571858/** Determine if two strings contain the same data.1859* This only returns 1 if both given handles are non-NULL and1860* if they are filled with the same bytes.1861* \param a first string handle1862* \param b second string handle1863* \return 0 for different strings, 1 for identical1864*/1865MPG123_EXPORT int mpg123_same_string(mpg123_string *a, mpg123_string *b);18661867/** The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info. */1868enum mpg123_text_encoding1869{1870mpg123_text_unknown = 0 /**< Unkown encoding... mpg123_id3_encoding can return that on invalid codes. */1871,mpg123_text_utf8 = 1 /**< UTF-8 */1872,mpg123_text_latin1 = 2 /**< ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings. */1873,mpg123_text_icy = 3 /**< ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such. */1874,mpg123_text_cp1252 = 4 /**< Really CP-1252 without any guessing. */1875,mpg123_text_utf16 = 5 /**< Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.1876* When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when1877* you don't mess with the reserved code points. If you want to decode little endian data1878* without BOM you need to prepend 0xff 0xfe yourself. */1879,mpg123_text_utf16bom = 6 /**< Just an alias for UTF-16, ID3v2 has this as distinct code. */1880,mpg123_text_utf16be = 7 /**< Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,1881* BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg1231882* One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF161883* types (we expect a BOM before real data there), not so for utf16be!*/1884,mpg123_text_max = 7 /**< Placeholder for the maximum encoding value. */1885};18861887/** The encoding byte values from ID3v2. */1888enum mpg123_id3_enc1889{1890mpg123_id3_latin1 = 0 /**< Note: This sometimes can mean anything in practice... */1891,mpg123_id3_utf16bom = 1 /**< UTF16, UCS-2 ... it's all the same for practical purposes. */1892,mpg123_id3_utf16be = 2 /**< Big-endian UTF-16, BOM see note for mpg123_text_utf16be. */1893,mpg123_id3_utf8 = 3 /**< Our lovely overly ASCII-compatible 8 byte encoding for the world. */1894,mpg123_id3_enc_max = 3 /**< Placeholder to check valid range of encoding byte. */1895};18961897#ifdef MPG123_ENUM_API1898/** Convert ID3 encoding byte to mpg123 encoding index.1899*1900* Note that this name is mapped to mpg123_enc_from_id3_2() instead unless1901* MPG123_ENUM_API is defined.1902*1903* \param id3_enc_byte the ID3 encoding code1904* \return the mpg123 encoding index1905*/1906MPG123_EXPORT enum mpg123_text_encoding mpg123_enc_from_id3(unsigned char id3_enc_byte);1907#endif19081909/** Convert ID3 encoding byte to mpg123 encoding index. No enums.1910*1911* This is actually called instead of mpg123_enc_from_id3()1912* unless MPG123_ENUM_API is defined.1913*1914* \param id3_enc_byte the ID3 encoding code1915* \return the mpg123 encoding index1916*/1917MPG123_EXPORT int mpg123_enc_from_id3_2(unsigned char id3_enc_byte);19181919#ifdef MPG123_ENUM_API1920/** Store text data in string, after converting to UTF-8 from indicated encoding.1921*1922* Note that this name is mapped to mpg123_store_utf8_2() instead unless1923* MPG123_ENUM_API is defined.1924*1925* 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).1926* Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).1927* \param sb target string1928* \param enc mpg123 text encoding value1929* \param source source buffer with plain unsigned bytes (you might need to cast from signed char)1930* \param source_size number of bytes in the source buffer1931* \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)1932*/1933MPG123_EXPORT int mpg123_store_utf8(mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size);1934#endif19351936/** Store text data in string, after converting to UTF-8 from indicated encoding. No enums.1937*1938* This is actually called instead of mpg123_store_utf8()1939* unless MPG123_ENUM_API is defined.1940*1941* 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).1942* Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).1943* \param sb target string1944* \param enc mpg123 text encoding value (enum mpg123_text_encoding)1945* \param source source buffer with plain unsigned bytes (you might need to cast from signed char)1946* \param source_size number of bytes in the source buffer1947* \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)1948*/1949MPG123_EXPORT int mpg123_store_utf8_2(mpg123_string *sb1950, int enc, const unsigned char *source, size_t source_size);19511952/** Sub data structure for ID3v2, for storing various text fields (including comments).1953* This is for ID3v2 COMM, TXXX and all the other text fields.1954* Only COMM, TXXX and USLT may have a description, only COMM and USLT1955* have a language.1956* You should consult the ID3v2 specification for the use of the various text fields1957* ("frames" in ID3v2 documentation, I use "fields" here to separate from MPEG frames). */1958typedef struct1959{1960char lang[3]; /**< Three-letter language code (not terminated). */1961char id[4]; /**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). */1962mpg123_string description; /**< Empty for the generic comment... */1963mpg123_string text; /**< ... */1964} mpg123_text;19651966/** The picture type values from ID3v2. */1967enum mpg123_id3_pic_type1968{1969mpg123_id3_pic_other = 0 /**< see ID3v2 docs */1970,mpg123_id3_pic_icon = 1 /**< see ID3v2 docs */1971,mpg123_id3_pic_other_icon = 2 /**< see ID3v2 docs */1972,mpg123_id3_pic_front_cover = 3 /**< see ID3v2 docs */1973,mpg123_id3_pic_back_cover = 4 /**< see ID3v2 docs */1974,mpg123_id3_pic_leaflet = 5 /**< see ID3v2 docs */1975,mpg123_id3_pic_media = 6 /**< see ID3v2 docs */1976,mpg123_id3_pic_lead = 7 /**< see ID3v2 docs */1977,mpg123_id3_pic_artist = 8 /**< see ID3v2 docs */1978,mpg123_id3_pic_conductor = 9 /**< see ID3v2 docs */1979,mpg123_id3_pic_orchestra = 10 /**< see ID3v2 docs */1980,mpg123_id3_pic_composer = 11 /**< see ID3v2 docs */1981,mpg123_id3_pic_lyricist = 12 /**< see ID3v2 docs */1982,mpg123_id3_pic_location = 13 /**< see ID3v2 docs */1983,mpg123_id3_pic_recording = 14 /**< see ID3v2 docs */1984,mpg123_id3_pic_performance = 15 /**< see ID3v2 docs */1985,mpg123_id3_pic_video = 16 /**< see ID3v2 docs */1986,mpg123_id3_pic_fish = 17 /**< see ID3v2 docs */1987,mpg123_id3_pic_illustration = 18 /**< see ID3v2 docs */1988,mpg123_id3_pic_artist_logo = 19 /**< see ID3v2 docs */1989,mpg123_id3_pic_publisher_logo = 20 /**< see ID3v2 docs */1990};19911992/** Sub data structure for ID3v2, for storing picture data including comment.1993* This is for the ID3v2 APIC field. You should consult the ID3v2 specification1994* for the use of the APIC field ("frames" in ID3v2 documentation, I use "fields"1995* here to separate from MPEG frames). */1996typedef struct1997{1998char type; /**< mpg123_id3_pic_type value */1999mpg123_string description; /**< description string */2000mpg123_string mime_type; /**< MIME type */2001size_t size; /**< size in bytes */2002unsigned char* data; /**< pointer to the image data */2003} mpg123_picture;20042005/** Data structure for storing IDV3v2 tags.2006* This structure is not a direct binary mapping with the file contents.2007* The ID3v2 text frames are allowed to contain multiple strings.2008* So check for null bytes until you reach the mpg123_string fill.2009* All text is encoded in UTF-8. */2010typedef struct2011{2012unsigned char version; /**< 3 or 4 for ID3v2.3 or ID3v2.4. */2013mpg123_string *title; /**< Title string (pointer into text_list). */2014mpg123_string *artist; /**< Artist string (pointer into text_list). */2015mpg123_string *album; /**< Album string (pointer into text_list). */2016mpg123_string *year; /**< The year as a string (pointer into text_list). */2017mpg123_string *genre; /**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. */2018mpg123_string *comment; /**< Pointer to last encountered comment text with empty description. */2019/* Encountered ID3v2 fields are appended to these lists.2020There can be multiple occurences, the pointers above always point to the last encountered data. */2021mpg123_text *comment_list; /**< Array of comments. */2022size_t comments; /**< Number of comments. */2023mpg123_text *text; /**< Array of ID3v2 text fields (including USLT) */2024size_t texts; /**< Numer of text fields. */2025mpg123_text *extra; /**< The array of extra (TXXX) fields. */2026size_t extras; /**< Number of extra text (TXXX) fields. */2027mpg123_picture *picture; /**< Array of ID3v2 pictures fields (APIC).2028Only populated if MPG123_PICTURE flag is set! */2029size_t pictures; /**< Number of picture (APIC) fields. */2030} mpg123_id3v2;20312032/** Data structure for ID3v1 tags (the last 128 bytes of a file).2033* Don't take anything for granted (like string termination)!2034* Also note the change ID3v1.1 did: comment[28] = 0; comment[29] = track_number2035* It is your task to support ID3v1 only or ID3v1.1 ...*/2036typedef struct2037{2038char tag[3]; /**< Always the string "TAG", the classic intro. */2039char title[30]; /**< Title string. */2040char artist[30]; /**< Artist string. */2041char album[30]; /**< Album string. */2042char year[4]; /**< Year string. */2043char comment[30]; /**< Comment string. */2044unsigned char genre; /**< Genre index. */2045} mpg123_id3v1;20462047#define MPG123_ID3 0x3 /**< 0011 There is some ID3 info. Also matches 0010 or NEW_ID3. */2048#define MPG123_NEW_ID3 0x1 /**< 0001 There is ID3 info that changed since last call to mpg123_id3. */2049#define MPG123_ICY 0xc /**< 1100 There is some ICY info. Also matches 0100 or NEW_ICY.*/2050#define MPG123_NEW_ICY 0x4 /**< 0100 There is ICY info that changed since last call to mpg123_icy. */20512052/** Query if there is (new) meta info, be it ID3 or ICY (or something new in future).2053* \param mh handle2054* \return combination of flags, 0 on error (same as "nothing new")2055*/2056MPG123_EXPORT int mpg123_meta_check(mpg123_handle *mh);20572058/** Clean up meta data storage (ID3v2 and ICY), freeing memory.2059* \param mh handle2060*/2061MPG123_EXPORT void mpg123_meta_free(mpg123_handle *mh);20622063/** Point v1 and v2 to existing data structures wich may change on any next read/decode function call.2064* v1 and/or v2 can be set to NULL when there is no corresponding data.2065* \return MPG123_OK on success2066*/2067MPG123_EXPORT int mpg123_id3( mpg123_handle *mh2068, mpg123_id3v1 **v1, mpg123_id3v2 **v2 );20692070/** Return pointers to and size of stored raw ID3 data if storage has2071* been configured with MPG123_STORE_RAW_ID3 and stream parsing passed the2072* metadata already. Null value with zero size is a possibility!2073* The storage can change at any next API call.2074*2075* \param mh mpg123 handle2076* \param v1 address to store pointer to v1 tag2077* \param v1_size size of v1 data in bytes2078* \param v2 address to store pointer to v2 tag2079* \param v2_size size of v2 data in bytes2080* \return MPG123_OK or MPG123_ERR. Only on MPG123_OK the output2081* values are set.2082*/2083MPG123_EXPORT int mpg123_id3_raw( mpg123_handle *mh2084, unsigned char **v1, size_t *v1_size2085, unsigned char **v2, size_t *v2_size );20862087/** Point icy_meta to existing data structure wich may change on any next read/decode function call.2088* \param mh handle2089* \param icy_meta return address for ICY meta string (set to NULL if nothing there)2090* \return MPG123_OK on success2091*/2092MPG123_EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta);20932094/** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8.2095* Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .2096* \param icy_text The input data in ICY encoding2097* \return pointer to newly allocated buffer with UTF-8 data (You free() it!) */2098MPG123_EXPORT char* mpg123_icy2utf8(const char* icy_text);209921002101/** @} */210221032104/** \defgroup mpg123_advpar mpg123 advanced parameter API2105*2106* Direct access to a parameter set without full handle around it.2107* Possible uses:2108* - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE).2109* - Use one set of parameters for multiple handles.2110*2111* The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt()2112* family) directly return a fully qualified mpg123 error code, the ones2113* operating on full handles normally MPG123_OK or MPG123_ERR, storing the2114* specific error code itseld inside the handle.2115*2116* @{2117*/21182119/** Opaque structure for the libmpg123 decoder parameters. */2120struct mpg123_pars_struct;21212122/** Opaque structure for the libmpg123 decoder parameters. */2123typedef struct mpg123_pars_struct mpg123_pars;21242125/** Create a handle with preset parameters.2126* \param mp parameter handle2127* \param decoder decoder choice2128* \param error error code return address2129* \return mpg123 handle2130*/2131MPG123_EXPORT mpg123_handle *mpg123_parnew( mpg123_pars *mp2132, const char* decoder, int *error );21332134/** Allocate memory for and return a pointer to a new mpg123_pars2135* \param error error code return address2136* \return new parameter handle2137*/2138MPG123_EXPORT mpg123_pars *mpg123_new_pars(int *error);21392140/** Delete and free up memory used by a mpg123_pars data structure2141* \param mp parameter handle2142*/2143MPG123_EXPORT void mpg123_delete_pars(mpg123_pars* mp);21442145/** Configure mpg123 parameters to accept no output format at all,2146* use before specifying supported formats with mpg123_format2147* \param mp parameter handle2148* \return MPG123_OK on success2149*/2150MPG123_EXPORT int mpg123_fmt_none(mpg123_pars *mp);21512152/** Configure mpg123 parameters to accept all formats2153* (also any custom rate you may set) -- this is default.2154* \param mp parameter handle2155* \return MPG123_OK on success2156*/2157MPG123_EXPORT int mpg123_fmt_all(mpg123_pars *mp);21582159/** Set the audio format support of a mpg123_pars in detail:2160* \param mp parameter handle2161* \param rate The sample rate value (in Hertz).2162* \param channels A combination of MPG123_STEREO and MPG123_MONO.2163* \param encodings A combination of accepted encodings for rate and channels,2164* p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no2165* support).2166* \return MPG123_OK on success2167*/2168MPG123_EXPORT int mpg123_fmt(mpg123_pars *mp2169, long rate, int channels, int encodings);21702171/** Set the audio format support of a mpg123_pars in detail:2172* \param mp parameter handle2173* \param rate The sample rate value (in Hertz). Special value 0 means2174* all rates (reason for this variant of mpg123_fmt).2175* \param channels A combination of MPG123_STEREO and MPG123_MONO.2176* \param encodings A combination of accepted encodings for rate and channels,2177* p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no2178* support).2179* \return MPG123_OK on success2180*/2181MPG123_EXPORT int mpg123_fmt2(mpg123_pars *mp2182, long rate, int channels, int encodings);21832184/** Check to see if a specific format at a specific rate is supported2185* by mpg123_pars.2186* \param mp parameter handle2187* \param rate sampling rate2188* \param encoding encoding2189* \return 0 for no support (that includes invalid parameters), MPG123_STEREO,2190* MPG123_MONO or MPG123_STEREO|MPG123_MONO. */2191MPG123_EXPORT int mpg123_fmt_support(mpg123_pars *mp, long rate, int encoding);21922193#ifdef MPG123_ENUM_API2194/** Set a specific parameter in a par handle.2195*2196* Note that this name is mapped to mpg123_par2() instead unless2197* MPG123_ENUM_API is defined.2198*2199* \param mp parameter handle2200* \param type parameter choice2201* \param value integer value2202* \param fvalue floating point value2203* \return MPG123_OK on success2204*/2205MPG123_EXPORT int mpg123_par( mpg123_pars *mp2206, enum mpg123_parms type, long value, double fvalue );2207#endif22082209/** Set a specific parameter in a par handle. No enums.2210*2211* This is actually called instead of mpg123_par()2212* unless MPG123_ENUM_API is defined.2213*2214* \param mp parameter handle2215* \param type parameter choice (enum mpg123_parms)2216* \param value integer value2217* \param fvalue floating point value2218* \return MPG123_OK on success2219*/2220MPG123_EXPORT int mpg123_par2( mpg123_pars *mp2221, int type, long value, double fvalue );22222223#ifdef MPG123_ENUM_API2224/** Get a specific parameter from a par handle.2225*2226* Note that this name is mapped to mpg123_getpar2() instead unless2227* MPG123_ENUM_API is defined.2228*2229* \param mp parameter handle2230* \param type parameter choice2231* \param value integer value return address2232* \param fvalue floating point value return address2233* \return MPG123_OK on success2234*/2235MPG123_EXPORT int mpg123_getpar( mpg123_pars *mp2236, enum mpg123_parms type, long *value, double *fvalue );2237#endif22382239/** Get a specific parameter from a par handle. No enums.2240*2241* This is actually called instead of mpg123_getpar()2242* unless MPG123_ENUM_API is defined.2243*2244* \param mp parameter handle2245* \param type parameter choice (enum mpg123_parms)2246* \param value integer value return address2247* \param fvalue floating point value return address2248* \return MPG123_OK on success2249*/2250MPG123_EXPORT int mpg123_getpar2( mpg123_pars *mp2251, int type, long *value, double *fvalue );22522253/** @} */225422552256/** \defgroup mpg123_lowio mpg123 low level I/O2257* 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...2258*2259* @{ */22602261/** Replace default internal buffer with user-supplied buffer.2262* Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio.2263* Note that the required buffer size could be bigger than expected from output2264* encoding if libmpg123 has to convert from primary decoder output (p.ex. 32 bit2265* storage for 24 bit output).2266*2267* Note: The type of data changed to a void pointer in mpg123 1.26.02268* (API version 45).2269*2270* \param mh handle2271* \param data pointer to user buffer2272* \param size of buffer in bytes2273* \return MPG123_OK on success2274*/2275MPG123_EXPORT int mpg123_replace_buffer(mpg123_handle *mh2276, void *data, size_t size);22772278/** The max size of one frame's decoded output with current settings.2279* Use that to determine an appropriate minimum buffer size for decoding one frame.2280* \param mh handle2281* \return maximum decoded data size in bytes2282*/2283MPG123_EXPORT size_t mpg123_outblock(mpg123_handle *mh);22842285#ifndef MPG123_PORTABLE_API2286/** Replace low-level stream access functions; read and lseek as known in POSIX.2287* You can use this to make any fancy file opening/closing yourself,2288* using mpg123_open_fd() to set the file descriptor for your read/lseek2289* (doesn't need to be a "real" file descriptor...).2290* Setting a function to NULL means that just a call to POSIX read/lseek is2291* done (without handling signals).2292* Note: As it would be troublesome to mess with this while having a file open,2293* this implies mpg123_close().2294* \param mh handle2295* \param r_read callback for reading (behaviour like POSIX read)2296* \param r_lseek callback for seeking (like POSIX lseek)2297* \return MPG123_OK on success2298*/2299MPG123_EXPORT int mpg123_replace_reader( mpg123_handle *mh2300, mpg123_ssize_t (*r_read) (int, void *, size_t)2301, off_t (*r_lseek)(int, off_t, int)2302);23032304/** Replace I/O functions with your own ones operating on some kind of2305* handle instead of integer descriptors.2306* The handle is a void pointer, so you can pass any data you want...2307* mpg123_open_handle() is the call you make to use the I/O defined here.2308* There is no fallback to internal read/seek here.2309* Note: As it would be troublesome to mess with this while having a file open,2310* this mpg123_close() is implied here.2311* \param mh handle2312* \param r_read callback for reading (behaviour like POSIX read)2313* \param r_lseek callback for seeking (like POSIX lseek)2314* \param cleanup A callback to clean up a non-NULL I/O handle on mpg123_close,2315* can be NULL for none (you take care of cleaning your handles).2316* \return MPG123_OK on success2317*/2318MPG123_EXPORT int mpg123_replace_reader_handle( mpg123_handle *mh2319, mpg123_ssize_t (*r_read) (void *, void *, size_t)2320, off_t (*r_lseek)(void *, off_t, int)2321, void (*cleanup)(void*) );2322#endif23232324/** Set up portable read functions on an opaque handle.2325* The handle is a void pointer, so you can pass any data you want...2326* mpg123_open64() (since API 49) or mpg123_open_handle() is the call you make2327* to use the I/O defined here.2328* There is no fallback to internal read/seek here.2329* Note: As it would be troublesome to mess with this while having a file open,2330* this mpg123_close() is implied here.2331* \param mh handle2332* \param r_read callback for reading2333* The parameters are the handle, the buffer to read into, a byte count to read,2334* address to store the returned byte count. Return value is zero for2335* no issue, non-zero for some error. Recoverable signal handling has to happen2336* inside the callback.2337* \param r_lseek callback for seeking (like POSIX lseek), maybe NULL for2338* non-seekable streams2339* \param cleanup A callback to clean up a non-NULL I/O handle on mpg123_close,2340* maybe NULL for none2341* \return MPG123_OK on success2342*/2343MPG123_EXPORT int mpg123_reader64( mpg123_handle *mh, int (*r_read) (void *, void *, size_t, size_t *), int64_t (*r_lseek)(void *, int64_t, int), void (*cleanup)(void*) );23442345/** @} */23462347#ifdef __cplusplus2348}2349#endif23502351#endif235223532354