[LIBMPG123]
[reactos.git] / reactos / sdk / include / reactos / libs / libmpg123 / mpg123.h
1 /*
2 libmpg123: MPEG Audio Decoder library (version 1.23.0)
3
4 copyright 1995-2015 by the mpg123 project
5 free software under the terms of the LGPL 2.1
6 see COPYING and AUTHORS files in distribution or http://mpg123.org
7 */
8
9 #ifndef MPG123_LIB_H
10 #define MPG123_LIB_H
11
12 #include <fmt123.h>
13
14 /** \file mpg123.h The header file for the libmpg123 MPEG Audio decoder */
15
16 /** A macro to check at compile time which set of API functions to expect.
17 * This should be incremented at least each time a new symbol is added
18 * to the header.
19 */
20 #define MPG123_API_VERSION 42
21
22 /** Defines needed for MS Visual Studio(tm) DLL builds.
23 * Every public function must be prefixed with MPG123_EXPORT. When building
24 * the DLL ensure to define BUILD_MPG123_DLL. This makes the function accessible
25 * for clients and includes it in the import library which is created together
26 * with the DLL. When consuming the DLL ensure to define LINK_MPG123_DLL which
27 * imports the functions from the DLL.
28 */
29 #ifdef BUILD_MPG123_DLL
30 /* The dll exports. */
31 #define MPG123_EXPORT __declspec(dllexport)
32 #else
33 #ifdef LINK_MPG123_DLL
34 /* The exe imports. */
35 #define MPG123_EXPORT __declspec(dllimport)
36 #else
37 /* Nothing on normal/UNIX builds */
38 #define MPG123_EXPORT
39 #endif
40 #endif
41
42 #ifndef MPG123_NO_CONFIGURE /* Enable use of this file without configure. */
43 #include <stdlib.h>
44 #include <sys/types.h>
45
46 #ifndef ssize_t
47 typedef long ssize_t;
48 #endif
49
50 /* Simplified large file handling.
51 I used to have a check here that prevents building for a library with conflicting large file setup
52 (application that uses 32 bit offsets with library that uses 64 bits).
53 While that was perfectly fine in an environment where there is one incarnation of the library,
54 it hurt GNU/Linux and Solaris systems with multilib where the distribution fails to provide the
55 correct header matching the 32 bit library (where large files need explicit support) or
56 the 64 bit library (where there is no distinction).
57
58 New approach: When the app defines _FILE_OFFSET_BITS, it wants non-default large file support,
59 and thus functions with added suffix (mpg123_open_64).
60 Any mismatch will be caught at link time because of the _FILE_OFFSET_BITS setting used when
61 building libmpg123. Plus, there's dual mode large file support in mpg123 since 1.12 now.
62 Link failure is not the expected outcome of any half-sane usage anymore.
63
64 More complication: What about client code defining _LARGEFILE64_SOURCE? It might want direct access to the _64 functions, along with the ones without suffix. Well, that's possible now via defining MPG123_NO_LARGENAME and MPG123_LARGESUFFIX, respectively, for disabling or enforcing the suffix names.
65 */
66
67 /*
68 Now, the renaming of large file aware functions.
69 By default, it appends underscore _FILE_OFFSET_BITS (so, mpg123_seek_64 for mpg123_seek), if _FILE_OFFSET_BITS is defined. You can force a different suffix via MPG123_LARGESUFFIX (that must include the underscore), or you can just disable the whole mess by defining MPG123_NO_LARGENAME.
70 */
71 #if (!defined MPG123_NO_LARGENAME) && ((defined _FILE_OFFSET_BITS) || (defined MPG123_LARGESUFFIX))
72
73 /* Need some trickery to concatenate the value(s) of the given macro(s). */
74 #define MPG123_MACROCAT_REALLY(a, b) a ## b
75 #define MPG123_MACROCAT(a, b) MPG123_MACROCAT_REALLY(a, b)
76 #ifndef MPG123_LARGESUFFIX
77 #define MPG123_LARGESUFFIX MPG123_MACROCAT(_, _FILE_OFFSET_BITS)
78 #endif
79 #define MPG123_LARGENAME(func) MPG123_MACROCAT(func, MPG123_LARGESUFFIX)
80
81 #define mpg123_open MPG123_LARGENAME(mpg123_open)
82 #define mpg123_open_fd MPG123_LARGENAME(mpg123_open_fd)
83 #define mpg123_open_handle MPG123_LARGENAME(mpg123_open_handle)
84 #define mpg123_framebyframe_decode MPG123_LARGENAME(mpg123_framebyframe_decode)
85 #define mpg123_decode_frame MPG123_LARGENAME(mpg123_decode_frame)
86 #define mpg123_tell MPG123_LARGENAME(mpg123_tell)
87 #define mpg123_tellframe MPG123_LARGENAME(mpg123_tellframe)
88 #define mpg123_tell_stream MPG123_LARGENAME(mpg123_tell_stream)
89 #define mpg123_seek MPG123_LARGENAME(mpg123_seek)
90 #define mpg123_feedseek MPG123_LARGENAME(mpg123_feedseek)
91 #define mpg123_seek_frame MPG123_LARGENAME(mpg123_seek_frame)
92 #define mpg123_timeframe MPG123_LARGENAME(mpg123_timeframe)
93 #define mpg123_index MPG123_LARGENAME(mpg123_index)
94 #define mpg123_set_index MPG123_LARGENAME(mpg123_set_index)
95 #define mpg123_position MPG123_LARGENAME(mpg123_position)
96 #define mpg123_length MPG123_LARGENAME(mpg123_length)
97 #define mpg123_framelength MPG123_LARGENAME(mpg123_framelength)
98 #define mpg123_set_filesize MPG123_LARGENAME(mpg123_set_filesize)
99 #define mpg123_replace_reader MPG123_LARGENAME(mpg123_replace_reader)
100 #define mpg123_replace_reader_handle MPG123_LARGENAME(mpg123_replace_reader_handle)
101 #define mpg123_framepos MPG123_LARGENAME(mpg123_framepos)
102
103 #endif /* largefile hackery */
104
105 #endif /* MPG123_NO_CONFIGURE */
106
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110
111 /** \defgroup mpg123_init mpg123 library and handle setup
112 *
113 * Functions to initialise and shutdown the mpg123 library and handles.
114 * The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-)
115 * Tip: Use a RVA setting...
116 *
117 * @{
118 */
119
120 /** Opaque structure for the libmpg123 decoder handle. */
121 struct mpg123_handle_struct;
122
123 /** Opaque structure for the libmpg123 decoder handle.
124 * Most functions take a pointer to a mpg123_handle as first argument and operate on its data in an object-oriented manner.
125 */
126 typedef struct mpg123_handle_struct mpg123_handle;
127
128 /** Function to initialise the mpg123 library.
129 * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library.
130 *
131 * \return MPG123_OK if successful, otherwise an error number.
132 */
133 MPG123_EXPORT int mpg123_init(void);
134
135 /** Function to close down the mpg123 library.
136 * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. */
137 MPG123_EXPORT void mpg123_exit(void);
138
139 /** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()).
140 * and optional retrieval of an error code to feed to mpg123_plain_strerror().
141 * Optional means: Any of or both the parameters may be NULL.
142 *
143 * \param decoder optional choice of decoder variant (NULL for default)
144 * \param error optional address to store error codes
145 * \return Non-NULL pointer to fresh handle when successful.
146 */
147 MPG123_EXPORT mpg123_handle *mpg123_new(const char* decoder, int *error);
148
149 /** Delete handle, mh is either a valid mpg123 handle or NULL.
150 * \param mh handle
151 */
152 MPG123_EXPORT void mpg123_delete(mpg123_handle *mh);
153
154 /** Enumeration of the parameters types that it is possible to set/get. */
155 enum mpg123_parms
156 {
157 MPG123_VERBOSE = 0, /**< set verbosity value for enabling messages to stderr, >= 0 makes sense (integer) */
158 MPG123_FLAGS, /**< set all flags, p.ex val = MPG123_GAPLESS|MPG123_MONO_MIX (integer) */
159 MPG123_ADD_FLAGS, /**< add some flags (integer) */
160 MPG123_FORCE_RATE, /**< when value > 0, force output rate to that value (integer) */
161 MPG123_DOWN_SAMPLE, /**< 0=native rate, 1=half rate, 2=quarter rate (integer) */
162 MPG123_RVA, /**< one of the RVA choices above (integer) */
163 MPG123_DOWNSPEED, /**< play a frame N times (integer) */
164 MPG123_UPSPEED, /**< play every Nth frame (integer) */
165 MPG123_START_FRAME, /**< start with this frame (skip frames before that, integer) */
166 MPG123_DECODE_FRAMES, /**< decode only this number of frames (integer) */
167 MPG123_ICY_INTERVAL, /**< stream contains ICY metadata with this interval (integer) */
168 MPG123_OUTSCALE, /**< the scale for output samples (amplitude - integer or float according to mpg123 output format, normally integer) */
169 MPG123_TIMEOUT, /**< timeout for reading from a stream (not supported on win32, integer) */
170 MPG123_REMOVE_FLAGS, /**< remove some flags (inverse of MPG123_ADD_FLAGS, integer) */
171 MPG123_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). */
172 MPG123_INDEX_SIZE /**< Set the frame index size (if supported). Values <0 mean that the index is allowed to grow dynamically in these steps (in positive direction, of course) -- Use this when you really want a full index with every individual frame. */
173 ,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.*/
174 ,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) */
175 ,MPG123_FEEDBUFFER /**< Minimal size of one internal feeder buffer, again, the default value is subject to change. (integer) */
176 };
177
178 /** Flag bits for MPG123_FLAGS, use the usual binary or to combine. */
179 enum mpg123_param_flags
180 {
181 MPG123_FORCE_MONO = 0x7 /**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. */
182 ,MPG123_MONO_LEFT = 0x1 /**< 0001 Force playback of left channel only. */
183 ,MPG123_MONO_RIGHT = 0x2 /**< 0010 Force playback of right channel only. */
184 ,MPG123_MONO_MIX = 0x4 /**< 0100 Force playback of mixed mono. */
185 ,MPG123_FORCE_STEREO = 0x8 /**< 1000 Force stereo output. */
186 ,MPG123_FORCE_8BIT = 0x10 /**< 00010000 Force 8bit formats. */
187 ,MPG123_QUIET = 0x20 /**< 00100000 Suppress any printouts (overrules verbose). */
188 ,MPG123_GAPLESS = 0x40 /**< 01000000 Enable gapless decoding (default on if libmpg123 has support). */
189 ,MPG123_NO_RESYNC = 0x80 /**< 10000000 Disable resync stream after error. */
190 ,MPG123_SEEKBUFFER = 0x100 /**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). */
191 ,MPG123_FUZZY = 0x200 /**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) */
192 ,MPG123_FORCE_FLOAT = 0x400 /**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). */
193 ,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. */
194 ,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 */
195 ,MPG123_SKIP_ID3V2 = 0x2000 /**< 10 0000 0000 0000 Do not parse ID3v2 tags, just skip them. */
196 ,MPG123_IGNORE_INFOFRAME = 0x4000 /**< 100 0000 0000 0000 Do not parse the LAME/Xing info frame, treat it as normal MPEG data. */
197 ,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. */
198 ,MPG123_PICTURE = 0x10000 /**< 17th bit: Enable storage of pictures from tags (ID3v2 APIC). */
199 };
200
201 /** choices for MPG123_RVA */
202 enum mpg123_param_rva
203 {
204 MPG123_RVA_OFF = 0 /**< RVA disabled (default). */
205 ,MPG123_RVA_MIX = 1 /**< Use mix/track/radio gain. */
206 ,MPG123_RVA_ALBUM = 2 /**< Use album/audiophile gain */
207 ,MPG123_RVA_MAX = MPG123_RVA_ALBUM /**< The maximum RVA code, may increase in future. */
208 };
209
210 /** Set a specific parameter, for a specific mpg123_handle, using a parameter
211 * type key chosen from the mpg123_parms enumeration, to the specified value.
212 * \param mh handle
213 * \param type parameter choice
214 * \param value integer value
215 * \param fvalue floating point value
216 * \return MPG123_OK on success
217 */
218 MPG123_EXPORT int mpg123_param( mpg123_handle *mh
219 , enum mpg123_parms type, long value, double fvalue );
220
221 /** Get a specific parameter, for a specific mpg123_handle.
222 * See the mpg123_parms enumeration for a list of available parameters.
223 * \param mh handle
224 * \param type parameter choice
225 * \param value integer value return address
226 * \param fvalue floating point value return address
227 * \return MPG123_OK on success
228 */
229 MPG123_EXPORT int mpg123_getparam( mpg123_handle *mh
230 , enum mpg123_parms type, long *value, double *fvalue );
231
232 /** Feature set available for query with mpg123_feature. */
233 enum mpg123_feature_set
234 {
235 MPG123_FEATURE_ABI_UTF8OPEN = 0 /**< mpg123 expects path names to be given in UTF-8 encoding instead of plain native. */
236 ,MPG123_FEATURE_OUTPUT_8BIT /**< 8bit output */
237 ,MPG123_FEATURE_OUTPUT_16BIT /**< 16bit output */
238 ,MPG123_FEATURE_OUTPUT_32BIT /**< 32bit output */
239 ,MPG123_FEATURE_INDEX /**< support for building a frame index for accurate seeking */
240 ,MPG123_FEATURE_PARSE_ID3V2 /**< id3v2 parsing */
241 ,MPG123_FEATURE_DECODE_LAYER1 /**< mpeg layer-1 decoder enabled */
242 ,MPG123_FEATURE_DECODE_LAYER2 /**< mpeg layer-2 decoder enabled */
243 ,MPG123_FEATURE_DECODE_LAYER3 /**< mpeg layer-3 decoder enabled */
244 ,MPG123_FEATURE_DECODE_ACCURATE /**< accurate decoder rounding */
245 ,MPG123_FEATURE_DECODE_DOWNSAMPLE /**< downsample (sample omit) */
246 ,MPG123_FEATURE_DECODE_NTOM /**< flexible rate decoding */
247 ,MPG123_FEATURE_PARSE_ICY /**< ICY support */
248 ,MPG123_FEATURE_TIMEOUT_READ /**< Reader with timeout (network). */
249 ,MPG123_FEATURE_EQUALIZER /**< tunable equalizer */
250 };
251
252 /** Query libmpg123 features.
253 * \param key feature selection
254 * \return 1 for success, 0 for unimplemented functions
255 */
256 MPG123_EXPORT int mpg123_feature(const enum mpg123_feature_set key);
257
258 /* @} */
259
260
261 /** \defgroup mpg123_error mpg123 error handling
262 *
263 * Functions to get text version of the error numbers and an enumeration
264 * of the error codes returned by libmpg123.
265 *
266 * Most functions operating on a mpg123_handle simply return MPG123_OK (0)
267 * on success and MPG123_ERR (-1) on failure, setting the internal error
268 * variable of the handle to the specific error code. If there was not a valid
269 * (non-NULL) handle provided to a function operating on one, MPG123_BAD_HANDLE
270 * may be returned if this can not be confused with a valid positive return
271 * value.
272 * Meaning: A function expected to return positive integers on success will
273 * always indicate error or a special condition by returning a negative one.
274 *
275 * Decoding/seek functions may also return message codes MPG123_DONE,
276 * MPG123_NEW_FORMAT and MPG123_NEED_MORE (all negative, see below on how to
277 * react). Note that calls to those can be nested, so generally watch out
278 * for these codes after initial handle setup.
279 * Especially any function that needs information about the current stream
280 * to work will try to at least parse the beginning if that did not happen
281 * yet.
282 *
283 * On a function that is supposed to return MPG123_OK on success and
284 * MPG123_ERR on failure, make sure you check for != MPG123_OK, not
285 * == MPG123_ERR, as the error code could get more specific in future,
286 * or there is just a special message from a decoding routine as indicated
287 * above.
288 *
289 * @{
290 */
291
292 /** Enumeration of the message and error codes and returned by libmpg123 functions. */
293 enum mpg123_errors
294 {
295 MPG123_DONE=-12, /**< Message: Track ended. Stop decoding. */
296 MPG123_NEW_FORMAT=-11, /**< Message: Output format will be different on next call. Note that some libmpg123 versions between 1.4.3 and 1.8.0 insist on you calling mpg123_getformat() after getting this message code. Newer verisons behave like advertised: You have the chance to call mpg123_getformat(), but you can also just continue decoding and get your data. */
297 MPG123_NEED_MORE=-10, /**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). */
298 MPG123_ERR=-1, /**< Generic Error */
299 MPG123_OK=0, /**< Success */
300 MPG123_BAD_OUTFORMAT, /**< Unable to set up output format! */
301 MPG123_BAD_CHANNEL, /**< Invalid channel number specified. */
302 MPG123_BAD_RATE, /**< Invalid sample rate specified. */
303 MPG123_ERR_16TO8TABLE, /**< Unable to allocate memory for 16 to 8 converter table! */
304 MPG123_BAD_PARAM, /**< Bad parameter id! */
305 MPG123_BAD_BUFFER, /**< Bad buffer given -- invalid pointer or too small size. */
306 MPG123_OUT_OF_MEM, /**< Out of memory -- some malloc() failed. */
307 MPG123_NOT_INITIALIZED, /**< You didn't initialize the library! */
308 MPG123_BAD_DECODER, /**< Invalid decoder choice. */
309 MPG123_BAD_HANDLE, /**< Invalid mpg123 handle. */
310 MPG123_NO_BUFFERS, /**< Unable to initialize frame buffers (out of memory?). */
311 MPG123_BAD_RVA, /**< Invalid RVA mode. */
312 MPG123_NO_GAPLESS, /**< This build doesn't support gapless decoding. */
313 MPG123_NO_SPACE, /**< Not enough buffer space. */
314 MPG123_BAD_TYPES, /**< Incompatible numeric data types. */
315 MPG123_BAD_BAND, /**< Bad equalizer band. */
316 MPG123_ERR_NULL, /**< Null pointer given where valid storage address needed. */
317 MPG123_ERR_READER, /**< Error reading the stream. */
318 MPG123_NO_SEEK_FROM_END,/**< Cannot seek from end (end is not known). */
319 MPG123_BAD_WHENCE, /**< Invalid 'whence' for seek function.*/
320 MPG123_NO_TIMEOUT, /**< Build does not support stream timeouts. */
321 MPG123_BAD_FILE, /**< File access error. */
322 MPG123_NO_SEEK, /**< Seek not supported by stream. */
323 MPG123_NO_READER, /**< No stream opened. */
324 MPG123_BAD_PARS, /**< Bad parameter handle. */
325 MPG123_BAD_INDEX_PAR, /**< Bad parameters to mpg123_index() and mpg123_set_index() */
326 MPG123_OUT_OF_SYNC, /**< Lost track in bytestream and did not try to resync. */
327 MPG123_RESYNC_FAIL, /**< Resync failed to find valid MPEG data. */
328 MPG123_NO_8BIT, /**< No 8bit encoding possible. */
329 MPG123_BAD_ALIGN, /**< Stack aligmnent error */
330 MPG123_NULL_BUFFER, /**< NULL input buffer with non-zero size... */
331 MPG123_NO_RELSEEK, /**< Relative seek not possible (screwed up file offset) */
332 MPG123_NULL_POINTER, /**< You gave a null pointer somewhere where you shouldn't have. */
333 MPG123_BAD_KEY, /**< Bad key value given. */
334 MPG123_NO_INDEX, /**< No frame index in this build. */
335 MPG123_INDEX_FAIL, /**< Something with frame index went wrong. */
336 MPG123_BAD_DECODER_SETUP, /**< Something prevents a proper decoder setup */
337 MPG123_MISSING_FEATURE /**< This feature has not been built into libmpg123. */
338 ,MPG123_BAD_VALUE /**< A bad value has been given, somewhere. */
339 ,MPG123_LSEEK_FAILED /**< Low-level seek failed. */
340 ,MPG123_BAD_CUSTOM_IO /**< Custom I/O not prepared. */
341 ,MPG123_LFS_OVERFLOW /**< Offset value overflow during translation of large file API calls -- your client program cannot handle that large file. */
342 ,MPG123_INT_OVERFLOW /**< Some integer overflow. */
343 };
344
345 /** Look up error strings given integer code.
346 * \param errcode integer error code
347 * \return string describing what that error error code means
348 */
349 MPG123_EXPORT const char* mpg123_plain_strerror(int errcode);
350
351 /** Give string describing what error has occured in the context of handle mh.
352 * When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via
353 * char *errmsg = mpg123_strerror(mh)
354 * This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE.
355 * \param mh handle
356 * \return error message
357 */
358 MPG123_EXPORT const char* mpg123_strerror(mpg123_handle *mh);
359
360 /** Return the plain errcode intead of a string.
361 * \param mh handle
362 * \return error code recorded in handle or MPG123_BAD_HANDLE
363 */
364 MPG123_EXPORT int mpg123_errcode(mpg123_handle *mh);
365
366 /*@}*/
367
368
369 /** \defgroup mpg123_decoder mpg123 decoder selection
370 *
371 * Functions to list and select the available decoders.
372 * Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is).
373 *
374 * @{
375 */
376
377 /** Get available decoder list.
378 * \return NULL-terminated array of generally available decoder names (plain 8bit ASCII)
379 */
380 MPG123_EXPORT const char **mpg123_decoders(void);
381
382 /** Get supported decoder list.
383 * \return NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII)
384 */
385 MPG123_EXPORT const char **mpg123_supported_decoders(void);
386
387 /** Set the active decoder.
388 * \param mh handle
389 * \param decoder_name name of decoder
390 * \return MPG123_OK on success
391 */
392 MPG123_EXPORT int mpg123_decoder(mpg123_handle *mh, const char* decoder_name);
393
394 /** Get the currently active decoder name.
395 * The active decoder engine can vary depening on output constraints,
396 * mostly non-resampling, integer output is accelerated via 3DNow & Co. but for
397 * other modes a fallback engine kicks in.
398 * Note that this can return a decoder that is ony active in the hidden and not
399 * available as decoder choice from the outside.
400 * \param mh handle
401 * \return The decoder name or NULL on error.
402 */
403 MPG123_EXPORT const char* mpg123_current_decoder(mpg123_handle *mh);
404
405 /*@}*/
406
407
408 /** \defgroup mpg123_output mpg123 output audio format
409 *
410 * Functions to get and select the format of the decoded audio.
411 *
412 * Before you dive in, please be warned that you might get confused by this. This seems to happen a lot, therefore I am trying to explain in advance.
413 *
414 * 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 ptimized 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).
415 *
416 * 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.
417 *
418 * 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.
419 *
420 * 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.
421 *
422 * @{
423 */
424
425 /** They can be combined into one number (3) to indicate mono and stereo... */
426 enum mpg123_channelcount
427 {
428 MPG123_MONO = 1 /**< mono */
429 ,MPG123_STEREO = 2 /**< stereo */
430 };
431
432 /** An array of supported standard sample rates
433 * These are possible native sample rates of MPEG audio files.
434 * You can still force mpg123 to resample to a different one, but by default you will only get audio in one of these samplings.
435 * \param list Store a pointer to the sample rates array there.
436 * \param number Store the number of sample rates there. */
437 MPG123_EXPORT void mpg123_rates(const long **list, size_t *number);
438
439 /** An array of supported audio encodings.
440 * An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED).
441 * \param list Store a pointer to the encodings array there.
442 * \param number Store the number of encodings there. */
443 MPG123_EXPORT void mpg123_encodings(const int **list, size_t *number);
444
445 /** Return the size (in bytes) of one mono sample of the named encoding.
446 * \param encoding The encoding value to analyze.
447 * \return positive size of encoding in bytes, 0 on invalid encoding. */
448 MPG123_EXPORT int mpg123_encsize(int encoding);
449
450 /** Configure a mpg123 handle to accept no output format at all,
451 * use before specifying supported formats with mpg123_format
452 * \param mh handle
453 * \return MPG123_OK on success
454 */
455 MPG123_EXPORT int mpg123_format_none(mpg123_handle *mh);
456
457 /** Configure mpg123 handle to accept all formats
458 * (also any custom rate you may set) -- this is default.
459 * \param mh handle
460 * \return MPG123_OK on success
461 */
462 MPG123_EXPORT int mpg123_format_all(mpg123_handle *mh);
463
464 /** Set the audio format support of a mpg123_handle in detail:
465 * \param mh handle
466 * \param rate The sample rate value (in Hertz).
467 * \param channels A combination of MPG123_STEREO and MPG123_MONO.
468 * \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.
469 * \return MPG123_OK on success, MPG123_ERR if there was an error. */
470 MPG123_EXPORT int mpg123_format( mpg123_handle *mh
471 , long rate, int channels, int encodings );
472
473 /** Check to see if a specific format at a specific rate is supported
474 * by mpg123_handle.
475 * \param mh handle
476 * \param rate sampling rate
477 * \param encoding encoding
478 * \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
479 * MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
480 MPG123_EXPORT int mpg123_format_support( mpg123_handle *mh
481 , long rate, int encoding );
482
483 /** Get the current output format written to the addresses given.
484 * \param mh handle
485 * \param rate sampling rate return address
486 * \param channels channel count return address
487 * \param encoding encoding return address
488 * \return MPG123_OK on success
489 */
490 MPG123_EXPORT int mpg123_getformat( mpg123_handle *mh
491 , long *rate, int *channels, int *encoding );
492
493 /*@}*/
494
495
496 /** \defgroup mpg123_input mpg123 file input and decoding
497 *
498 * Functions for input bitstream and decoding operations.
499 * 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!).
500 * @{
501 */
502
503 /* reading samples / triggering decoding, possible return values: */
504 /** Enumeration of the error codes returned by libmpg123 functions. */
505
506 /** Open and prepare to decode the specified file by filesystem path.
507 * This does not open HTTP urls; libmpg123 contains no networking code.
508 * If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().
509 * \param mh handle
510 * \param path filesystem path
511 * \return MPG123_OK on success
512 */
513 MPG123_EXPORT int mpg123_open(mpg123_handle *mh, const char *path);
514
515 /** Use an already opened file descriptor as the bitstream input
516 * mpg123_close() will _not_ close the file descriptor.
517 * \param mh handle
518 * \param fd file descriptor
519 * \return MPG123_OK on success
520 */
521 MPG123_EXPORT int mpg123_open_fd(mpg123_handle *mh, int fd);
522
523 /** Use an opaque handle as bitstream input. This works only with the
524 * replaced I/O from mpg123_replace_reader_handle()!
525 * mpg123_close() will call the cleanup callback for your handle (if you gave one).
526 * \param mh handle
527 * \param iohandle your handle
528 * \return MPG123_OK on success
529 */
530 MPG123_EXPORT int mpg123_open_handle(mpg123_handle *mh, void *iohandle);
531
532 /** Open a new bitstream and prepare for direct feeding
533 * This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.
534 * \param mh handle
535 * \return MPG123_OK on success
536 */
537 MPG123_EXPORT int mpg123_open_feed(mpg123_handle *mh);
538
539 /** Closes the source, if libmpg123 opened it.
540 * \param mh handle
541 * \return MPG123_OK on success
542 */
543 MPG123_EXPORT int mpg123_close(mpg123_handle *mh);
544
545 /** Read from stream and decode up to outmemsize bytes.
546 * \param mh handle
547 * \param outmemory address of output buffer to write to
548 * \param outmemsize maximum number of bytes to write
549 * \param done address to store the number of actually decoded bytes to
550 * \return MPG123_OK or error/message code
551 */
552 MPG123_EXPORT int mpg123_read(mpg123_handle *mh
553 , unsigned char *outmemory, size_t outmemsize, size_t *done );
554
555 /** Feed data for a stream that has been opened with mpg123_open_feed().
556 * It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.
557 * \param mh handle
558 * \param in input buffer
559 * \param size number of input bytes
560 * \return MPG123_OK or error/message code.
561 */
562 MPG123_EXPORT int mpg123_feed( mpg123_handle *mh
563 , const unsigned char *in, size_t size );
564
565 /** Decode MPEG Audio from inmemory to outmemory.
566 * This is very close to a drop-in replacement for old mpglib.
567 * When you give zero-sized output buffer the input will be parsed until
568 * decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it)
569 * without taking decoded data.
570 * Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-).
571 * You can actually always decide if you want those specialized functions in separate steps or one call this one here.
572 * \param mh handle
573 * \param inmemory input buffer
574 * \param inmemsize number of input bytes
575 * \param outmemory output buffer
576 * \param outmemsize maximum number of output bytes
577 * \param done address to store the number of actually decoded bytes to
578 * \return error/message code (watch out especially for MPG123_NEED_MORE)
579 */
580 MPG123_EXPORT int mpg123_decode( mpg123_handle *mh
581 , const unsigned char *inmemory, size_t inmemsize
582 , unsigned char *outmemory, size_t outmemsize, size_t *done );
583
584 /** Decode next MPEG frame to internal buffer
585 * or read a frame and return after setting a new format.
586 * \param mh handle
587 * \param num current frame offset gets stored there
588 * \param audio This pointer is set to the internal buffer to read the decoded audio from.
589 * \param bytes number of output bytes ready in the buffer
590 * \return MPG123_OK or error/message code
591 */
592 MPG123_EXPORT int mpg123_decode_frame( mpg123_handle *mh
593 , off_t *num, unsigned char **audio, size_t *bytes );
594
595 /** Decode current MPEG frame to internal buffer.
596 * Warning: This is experimental API that might change in future releases!
597 * Please watch mpg123 development closely when using it.
598 * \param mh handle
599 * \param num last frame offset gets stored there
600 * \param audio this pointer is set to the internal buffer to read the decoded audio from.
601 * \param bytes number of output bytes ready in the buffer
602 * \return MPG123_OK or error/message code
603 */
604 MPG123_EXPORT int mpg123_framebyframe_decode( mpg123_handle *mh
605 , off_t *num, unsigned char **audio, size_t *bytes );
606
607 /** Find, read and parse the next mp3 frame
608 * Warning: This is experimental API that might change in future releases!
609 * Please watch mpg123 development closely when using it.
610 * \param mh handle
611 * \return MPG123_OK or error/message code
612 */
613 MPG123_EXPORT int mpg123_framebyframe_next(mpg123_handle *mh);
614
615 /** Get access to the raw input data for the last parsed frame.
616 * This gives you a direct look (and write access) to the frame body data.
617 * 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()).
618 * 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.
619 * You can provide NULL for a parameter pointer when you are not interested in the value.
620 *
621 * \param mh handle
622 * \param header the 4-byte MPEG header
623 * \param bodydata pointer to the frame body stored in the handle (without the header)
624 * \param bodybytes size of frame body in bytes (without the header)
625 * \return MPG123_OK if there was a yet un-decoded frame to get the
626 * data from, MPG123_BAD_HANDLE or MPG123_ERR otherwise (without further
627 * explanation, the error state of the mpg123_handle is not modified by
628 * this function).
629 */
630 MPG123_EXPORT int mpg123_framedata( mpg123_handle *mh
631 , unsigned long *header, unsigned char **bodydata, size_t *bodybytes );
632
633 /** Get the input position (byte offset in stream) of the last parsed frame.
634 * This can be used for external seek index building, for example.
635 * It just returns the internally stored offset, regardless of validity --
636 * you ensure that a valid frame has been parsed before!
637 * \param mh handle
638 * \return byte offset in stream
639 */
640 MPG123_EXPORT off_t mpg123_framepos(mpg123_handle *mh);
641
642 /*@}*/
643
644
645 /** \defgroup mpg123_seek mpg123 position and seeking
646 *
647 * Functions querying and manipulating position in the decoded audio bitstream.
648 * The position is measured in decoded audio samples, or MPEG frame offset for the specific functions.
649 * If gapless code is in effect, the positions are adjusted to compensate the skipped padding/delay - meaning, you should not care about that at all and just use the position defined for the samples you get out of the decoder;-)
650 * The general usage is modelled after stdlib's ftell() and fseek().
651 * Especially, the whence parameter for the seek functions has the same meaning as the one for fseek() and needs the same constants from stdlib.h:
652 * - SEEK_SET: set position to (or near to) specified offset
653 * - SEEK_CUR: change position by offset from now
654 * - SEEK_END: set position to offset from end
655 *
656 * Note that sample-accurate seek only works when gapless support has been enabled at compile time; seek is frame-accurate otherwise.
657 * Also, really sample-accurate seeking (meaning that you get the identical sample value after seeking compared to plain decoding up to the position) is only guaranteed when you do not mess with the position code by using MPG123_UPSPEED, MPG123_DOWNSPEED or MPG123_START_FRAME. The first two mainly should cause trouble with NtoM resampling, but in any case with these options in effect, you have to keep in mind that the sample offset is not the same as counting the samples you get from decoding since mpg123 counts the skipped samples, too (or the samples played twice only once)!
658 * Short: When you care about the sample position, don't mess with those parameters;-)
659 * Also, seeking is not guaranteed to work for all streams (underlying stream may not support it).
660 * And yet another caveat: If the stream is concatenated out of differing pieces (Frankenstein stream), seeking may suffer, too.
661 *
662 * @{
663 */
664
665 /** Returns the current position in samples.
666 * On the next successful read, you'd get that sample.
667 * \param mh handle
668 * \return sample offset or MPG123_ERR (null handle)
669 */
670 MPG123_EXPORT off_t mpg123_tell(mpg123_handle *mh);
671
672 /** Returns the frame number that the next read will give you data from.
673 * \param mh handle
674 * \return frame offset or MPG123_ERR (null handle)
675 */
676 MPG123_EXPORT off_t mpg123_tellframe(mpg123_handle *mh);
677
678 /** Returns the current byte offset in the input stream.
679 * \param mh handle
680 * \return byte offset or MPG123_ERR (null handle)
681 */
682 MPG123_EXPORT off_t mpg123_tell_stream(mpg123_handle *mh);
683
684 /** Seek to a desired sample offset.
685 * Usage is modelled afer the standard lseek().
686 * \param mh handle
687 * \param sampleoff offset in PCM samples
688 * \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
689 * \return The resulting offset >= 0 or error/message code
690 */
691 MPG123_EXPORT off_t mpg123_seek( mpg123_handle *mh
692 , off_t sampleoff, int whence );
693
694 /** Seek to a desired sample offset in data feeding mode.
695 * This just prepares things to be right only if you ensure that the next chunk of input data will be from input_offset byte position.
696 * \param mh handle
697 * \param sampleoff offset in PCM samples
698 * \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
699 * \param input_offset The position it expects to be at the
700 * next time data is fed to mpg123_decode().
701 * \return The resulting offset >= 0 or error/message code */
702 MPG123_EXPORT off_t mpg123_feedseek( mpg123_handle *mh
703 , off_t sampleoff, int whence, off_t *input_offset );
704
705 /** Seek to a desired MPEG frame offset.
706 * Usage is modelled afer the standard lseek().
707 * \param mh handle
708 * \param frameoff offset in MPEG frames
709 * \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
710 * \return The resulting offset >= 0 or error/message code */
711 MPG123_EXPORT off_t mpg123_seek_frame( mpg123_handle *mh
712 , off_t frameoff, int whence );
713
714 /** Return a MPEG frame offset corresponding to an offset in seconds.
715 * 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.
716 * \return frame offset >= 0 or error/message code */
717 MPG123_EXPORT off_t mpg123_timeframe(mpg123_handle *mh, double sec);
718
719 /** Give access to the frame index table that is managed for seeking.
720 * You are asked not to modify the values... Use mpg123_set_index to set the
721 * seek index
722 * \param mh handle
723 * \param offsets pointer to the index array
724 * \param step one index byte offset advances this many MPEG frames
725 * \param fill number of recorded index offsets; size of the array
726 * \return MPG123_OK on success
727 */
728 MPG123_EXPORT int mpg123_index( mpg123_handle *mh
729 , off_t **offsets, off_t *step, size_t *fill );
730
731 /** Set the frame index table
732 * Setting offsets to NULL and fill > 0 will allocate fill entries. Setting offsets
733 * to NULL and fill to 0 will clear the index and free the allocated memory used by the index.
734 * \param mh handle
735 * \param offsets pointer to the index array
736 * \param step one index byte offset advances this many MPEG frames
737 * \param fill number of recorded index offsets; size of the array
738 * \return MPG123_OK on success
739 */
740 MPG123_EXPORT int mpg123_set_index( mpg123_handle *mh
741 , off_t *offsets, off_t step, size_t fill );
742
743 /** An old crutch to keep old mpg123 binaries happy.
744 * WARNING: This function is there only to avoid runtime linking errors with
745 * standalone mpg123 before version 1.23.0 (if you strangely update the
746 * library but not the end-user program) and actually is broken
747 * for various cases (p.ex. 24 bit output). Do never use. It might eventually
748 * be purged from the library.
749 */
750 MPG123_EXPORT int mpg123_position( mpg123_handle *mh, off_t frame_offset, off_t buffered_bytes, off_t *current_frame, off_t *frames_left, double *current_seconds, double *seconds_left);
751
752 /*@}*/
753
754
755 /** \defgroup mpg123_voleq mpg123 volume and equalizer
756 *
757 * @{
758 */
759
760 /** another channel enumeration, for left/right choice */
761 enum mpg123_channels
762 {
763 MPG123_LEFT=0x1 /**< The Left Channel. */
764 ,MPG123_RIGHT=0x2 /**< The Right Channel. */
765 ,MPG123_LR=0x3 /**< Both left and right channel; same as MPG123_LEFT|MPG123_RIGHT */
766 };
767
768 /** Set the 32 Band Audio Equalizer settings.
769 * \param mh handle
770 * \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for both.
771 * \param band The equaliser band to change (from 0 to 31)
772 * \param val The (linear) adjustment factor.
773 * \return MPG123_OK on success
774 */
775 MPG123_EXPORT int mpg123_eq( mpg123_handle *mh
776 , enum mpg123_channels channel, int band, double val );
777
778 /** Get the 32 Band Audio Equalizer settings.
779 * \param mh handle
780 * \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.
781 * \param band The equaliser band to change (from 0 to 31)
782 * \return The (linear) adjustment factor (zero for pad parameters) */
783 MPG123_EXPORT double mpg123_geteq(mpg123_handle *mh
784 , enum mpg123_channels channel, int band);
785
786 /** Reset the 32 Band Audio Equalizer settings to flat
787 * \param mh handle
788 * \return MPG123_OK on success
789 */
790 MPG123_EXPORT int mpg123_reset_eq(mpg123_handle *mh);
791
792 /** Set the absolute output volume including the RVA setting,
793 * vol<0 just applies (a possibly changed) RVA setting.
794 * \param mh handle
795 * \param vol volume value (linear factor)
796 * \return MPG123_OK on success
797 */
798 MPG123_EXPORT int mpg123_volume(mpg123_handle *mh, double vol);
799
800 /** Adjust output volume including the RVA setting by chosen amount
801 * \param mh handle
802 * \param change volume value (linear factor increment)
803 * \return MPG123_OK on success
804 */
805 MPG123_EXPORT int mpg123_volume_change(mpg123_handle *mh, double change);
806
807 /** Return current volume setting, the actual value due to RVA, and the RVA
808 * adjustment itself. It's all as double float value to abstract the sample
809 * format. The volume values are linear factors / amplitudes (not percent)
810 * and the RVA value is in decibels.
811 * \param mh handle
812 * \param base return address for base volume (linear factor)
813 * \param really return address for actual volume (linear factor)
814 * \param rva_db return address for RVA value (decibels)
815 * \return MPG123_OK on success
816 */
817 MPG123_EXPORT int mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db);
818
819 /* TODO: Set some preamp in addition / to replace internal RVA handling? */
820
821 /*@}*/
822
823
824 /** \defgroup mpg123_status mpg123 status and information
825 *
826 * @{
827 */
828
829 /** Enumeration of the mode types of Variable Bitrate */
830 enum mpg123_vbr {
831 MPG123_CBR=0, /**< Constant Bitrate Mode (default) */
832 MPG123_VBR, /**< Variable Bitrate Mode */
833 MPG123_ABR /**< Average Bitrate Mode */
834 };
835
836 /** Enumeration of the MPEG Versions */
837 enum mpg123_version {
838 MPG123_1_0=0, /**< MPEG Version 1.0 */
839 MPG123_2_0, /**< MPEG Version 2.0 */
840 MPG123_2_5 /**< MPEG Version 2.5 */
841 };
842
843
844 /** Enumeration of the MPEG Audio mode.
845 * Only the mono mode has 1 channel, the others have 2 channels. */
846 enum mpg123_mode {
847 MPG123_M_STEREO=0, /**< Standard Stereo. */
848 MPG123_M_JOINT, /**< Joint Stereo. */
849 MPG123_M_DUAL, /**< Dual Channel. */
850 MPG123_M_MONO /**< Single Channel. */
851 };
852
853
854 /** Enumeration of the MPEG Audio flag bits */
855 enum mpg123_flags {
856 MPG123_CRC=0x1, /**< The bitstream is error protected using 16-bit CRC. */
857 MPG123_COPYRIGHT=0x2, /**< The bitstream is copyrighted. */
858 MPG123_PRIVATE=0x4, /**< The private bit has been set. */
859 MPG123_ORIGINAL=0x8 /**< The bitstream is an original, not a copy. */
860 };
861
862 /** Data structure for storing information about a frame of MPEG Audio */
863 struct mpg123_frameinfo
864 {
865 enum mpg123_version version; /**< The MPEG version (1.0/2.0/2.5). */
866 int layer; /**< The MPEG Audio Layer (MP1/MP2/MP3). */
867 long rate; /**< The sampling rate in Hz. */
868 enum mpg123_mode mode; /**< The audio mode (Mono, Stereo, Joint-stero, Dual Channel). */
869 int mode_ext; /**< The mode extension bit flag. */
870 int framesize; /**< The size of the frame (in bytes, including header). */
871 enum 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. */
872 int emphasis; /**< The emphasis type. */
873 int bitrate; /**< Bitrate of the frame (kbps). */
874 int abr_rate; /**< The target average bitrate. */
875 enum mpg123_vbr vbr; /**< The VBR mode. */
876 };
877
878 /** Get frame information about the MPEG audio bitstream and store it in a mpg123_frameinfo structure.
879 * \param mh handle
880 * \param mi address of existing frameinfo structure to write to
881 * \return MPG123_OK on success
882 */
883 MPG123_EXPORT int mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi);
884
885 /** Get the safe output buffer size for all cases
886 * (when you want to replace the internal buffer)
887 * \return safe buffer size
888 */
889 MPG123_EXPORT size_t mpg123_safe_buffer(void);
890
891 /** Make a full parsing scan of each frame in the file. ID3 tags are found. An
892 * accurate length value is stored. Seek index will be filled. A seek back to
893 * current position is performed. At all, this function refuses work when
894 * stream is not seekable.
895 * \param mh handle
896 * \return MPG123_OK on success
897 */
898 MPG123_EXPORT int mpg123_scan(mpg123_handle *mh);
899
900 /** Return, if possible, the full (expected) length of current track in frames.
901 * \param mh handle
902 * \return length >= 0 or MPG123_ERR if there is no length guess possible.
903 */
904 MPG123_EXPORT off_t mpg123_framelength(mpg123_handle *mh);
905
906 /** Return, if possible, the full (expected) length of current track in samples.
907 * \param mh handle
908 * \return length >= 0 or MPG123_ERR if there is no length guess possible.
909 */
910 MPG123_EXPORT off_t mpg123_length(mpg123_handle *mh);
911
912 /** Override the value for file size in bytes.
913 * Useful for getting sensible track length values in feed mode or for HTTP streams.
914 * \param mh handle
915 * \param size file size in bytes
916 * \return MPG123_OK on success
917 */
918 MPG123_EXPORT int mpg123_set_filesize(mpg123_handle *mh, off_t size);
919
920 /** Get MPEG frame duration in seconds.
921 * \param mh handle
922 * \return frame duration in seconds, <0 on error
923 */
924 MPG123_EXPORT double mpg123_tpf(mpg123_handle *mh);
925
926 /** Get MPEG frame duration in samples.
927 * \param mh handle
928 * \return samples per frame for the most recently parsed frame; <0 on errors
929 */
930 MPG123_EXPORT int mpg123_spf(mpg123_handle *mh);
931
932 /** Get and reset the clip count.
933 * \param mh handle
934 * \return count of clipped samples
935 */
936 MPG123_EXPORT long mpg123_clip(mpg123_handle *mh);
937
938
939 /** The key values for state information from mpg123_getstate(). */
940 enum mpg123_state
941 {
942 MPG123_ACCURATE = 1 /**< Query if positons are currently accurate (integer value, 0 if false, 1 if true). */
943 ,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. */
944 ,MPG123_FRANKENSTEIN /**< Stream consists of carelessly stitched together files. Seeking may yield unexpected results (also with MPG123_ACCURATE, it may be confused). */
945 ,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. */
946 };
947
948 /** Get various current decoder/stream state information.
949 * \param mh handle
950 * \param key the key to identify the information to give.
951 * \param val the address to return (long) integer values to
952 * \param fval the address to return floating point values to
953 * \return MPG123_OK on success
954 */
955 MPG123_EXPORT int mpg123_getstate( mpg123_handle *mh
956 , enum mpg123_state key, long *val, double *fval );
957
958 /*@}*/
959
960
961 /** \defgroup mpg123_metadata mpg123 metadata handling
962 *
963 * Functions to retrieve the metadata from MPEG Audio files and streams.
964 * Also includes string handling functions.
965 *
966 * @{
967 */
968
969 /** Data structure for storing strings in a safer way than a standard C-String.
970 * Can also hold a number of null-terminated strings. */
971 typedef struct
972 {
973 char* p; /**< pointer to the string data */
974 size_t size; /**< raw number of bytes allocated */
975 size_t fill; /**< number of used bytes (including closing zero byte) */
976 } mpg123_string;
977
978 /** Create and allocate memory for a new mpg123_string
979 * \param sb string handle (address of existing structure on your side)
980 */
981 MPG123_EXPORT void mpg123_init_string(mpg123_string* sb);
982
983 /** Free-up mempory for an existing mpg123_string
984 * \param sb string handle
985 */
986 MPG123_EXPORT void mpg123_free_string(mpg123_string* sb);
987
988 /** Change the size of a mpg123_string
989 * \param sb string handle
990 * \param news new size in bytes
991 * \return 0 on error, 1 on success
992 */
993 MPG123_EXPORT int mpg123_resize_string(mpg123_string* sb, size_t news);
994
995 /** Increase size of a mpg123_string if necessary (it may stay larger).
996 * Note that the functions for adding and setting in current libmpg123
997 * use this instead of mpg123_resize_string().
998 * That way, you can preallocate memory and safely work afterwards with
999 * pieces.
1000 * \param sb string handle
1001 * \param news new minimum size
1002 * \return 0 on error, 1 on success
1003 */
1004 MPG123_EXPORT int mpg123_grow_string(mpg123_string* sb, size_t news);
1005
1006 /** Copy the contents of one mpg123_string string to another.
1007 * Yes the order of arguments is reversed compated to memcpy().
1008 * \param from string handle
1009 * \param to string handle
1010 * \return 0 on error, 1 on success
1011 */
1012 MPG123_EXPORT int mpg123_copy_string(mpg123_string* from, mpg123_string* to);
1013
1014 /** Append a C-String to an mpg123_string
1015 * \param sb string handle
1016 * \param stuff to append
1017 * \return 0 on error, 1 on success
1018 */
1019 MPG123_EXPORT int mpg123_add_string(mpg123_string* sb, const char* stuff);
1020
1021 /** Append a C-substring to an mpg123 string
1022 * \param sb string handle
1023 * \param stuff content to copy
1024 * \param from offset to copy from
1025 * \param count number of characters to copy (a null-byte is always appended)
1026 * \return 0 on error, 1 on success
1027 */
1028 MPG123_EXPORT int mpg123_add_substring( mpg123_string *sb
1029 , const char *stuff, size_t from, size_t count );
1030
1031 /** Set the content of a mpg123_string to a C-string
1032 * \param sb string handle
1033 * \param stuff content to copy
1034 * \return 0 on error, 1 on success
1035 */
1036 MPG123_EXPORT int mpg123_set_string(mpg123_string* sb, const char* stuff);
1037
1038 /** Set the content of a mpg123_string to a C-substring
1039 * \param sb string handle
1040 * \param stuff the future content
1041 * \param from offset to copy from
1042 * \param count number of characters to copy (a null-byte is always appended)
1043 * \return 0 on error, 1 on success
1044 */
1045 MPG123_EXPORT int mpg123_set_substring( mpg123_string *sb
1046 , const char *stuff, size_t from, size_t count );
1047
1048 /** Count characters in a mpg123 string (non-null bytes or UTF-8 characters).
1049 * Even with the fill property, the character count is not obvious as there could be multiple trailing null bytes.
1050 * \param sb string handle
1051 * \param utf8 a flag to tell if the string is in utf8 encoding
1052 * \return character count
1053 */
1054 MPG123_EXPORT size_t mpg123_strlen(mpg123_string *sb, int utf8);
1055
1056 /** Remove trailing \\r and \\n, if present.
1057 * \param sb string handle
1058 * \return 0 on error, 1 on success
1059 */
1060 MPG123_EXPORT int mpg123_chomp_string(mpg123_string *sb);
1061
1062 /** The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info. */
1063 enum mpg123_text_encoding
1064 {
1065 mpg123_text_unknown = 0 /**< Unkown encoding... mpg123_id3_encoding can return that on invalid codes. */
1066 ,mpg123_text_utf8 = 1 /**< UTF-8 */
1067 ,mpg123_text_latin1 = 2 /**< ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings. */
1068 ,mpg123_text_icy = 3 /**< ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such. */
1069 ,mpg123_text_cp1252 = 4 /**< Really CP-1252 without any guessing. */
1070 ,mpg123_text_utf16 = 5 /**< Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.
1071 * When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when
1072 * you don't mess with the reserved code points. If you want to decode little endian data
1073 * without BOM you need to prepend 0xff 0xfe yourself. */
1074 ,mpg123_text_utf16bom = 6 /**< Just an alias for UTF-16, ID3v2 has this as distinct code. */
1075 ,mpg123_text_utf16be = 7 /**< Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,
1076 * BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123
1077 * One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16
1078 * types (we expect a BOM before real data there), not so for utf16be!*/
1079 ,mpg123_text_max = 7 /**< Placeholder for the maximum encoding value. */
1080 };
1081
1082 /** The encoding byte values from ID3v2. */
1083 enum mpg123_id3_enc
1084 {
1085 mpg123_id3_latin1 = 0 /**< Note: This sometimes can mean anything in practice... */
1086 ,mpg123_id3_utf16bom = 1 /**< UTF16, UCS-2 ... it's all the same for practical purposes. */
1087 ,mpg123_id3_utf16be = 2 /**< Big-endian UTF-16, BOM see note for mpg123_text_utf16be. */
1088 ,mpg123_id3_utf8 = 3 /**< Our lovely overly ASCII-compatible 8 byte encoding for the world. */
1089 ,mpg123_id3_enc_max = 3 /**< Placeholder to check valid range of encoding byte. */
1090 };
1091
1092 /** Convert ID3 encoding byte to mpg123 encoding index.
1093 * \param id3_enc_byte the ID3 encoding code
1094 * \return the mpg123 encoding index
1095 */
1096
1097 MPG123_EXPORT enum mpg123_text_encoding mpg123_enc_from_id3(unsigned char id3_enc_byte);
1098
1099 /** Store text data in string, after converting to UTF-8 from indicated encoding
1100 * 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).
1101 * Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).
1102 * \param sb target string
1103 * \param enc mpg123 text encoding value
1104 * \param source source buffer with plain unsigned bytes (you might need to cast from char *)
1105 * \param source_size number of bytes in the source buffer
1106 * \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)
1107 */
1108 MPG123_EXPORT int mpg123_store_utf8(mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size);
1109
1110 /** Sub data structure for ID3v2, for storing various text fields (including comments).
1111 * This is for ID3v2 COMM, TXXX and all the other text fields.
1112 * Only COMM and TXXX have a description, only COMM and USLT have a language.
1113 * You should consult the ID3v2 specification for the use of the various text fields ("frames" in ID3v2 documentation, I use "fields" here to separate from MPEG frames). */
1114 typedef struct
1115 {
1116 char lang[3]; /**< Three-letter language code (not terminated). */
1117 char id[4]; /**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). */
1118 mpg123_string description; /**< Empty for the generic comment... */
1119 mpg123_string text; /**< ... */
1120 } mpg123_text;
1121
1122 /** The picture type values from ID3v2. */
1123 enum mpg123_id3_pic_type
1124 {
1125 mpg123_id3_pic_other = 0 /**< see ID3v2 docs */
1126 ,mpg123_id3_pic_icon = 1 /**< see ID3v2 docs */
1127 ,mpg123_id3_pic_other_icon = 2 /**< see ID3v2 docs */
1128 ,mpg123_id3_pic_front_cover = 3 /**< see ID3v2 docs */
1129 ,mpg123_id3_pic_back_cover = 4 /**< see ID3v2 docs */
1130 ,mpg123_id3_pic_leaflet = 5 /**< see ID3v2 docs */
1131 ,mpg123_id3_pic_media = 6 /**< see ID3v2 docs */
1132 ,mpg123_id3_pic_lead = 7 /**< see ID3v2 docs */
1133 ,mpg123_id3_pic_artist = 8 /**< see ID3v2 docs */
1134 ,mpg123_id3_pic_conductor = 9 /**< see ID3v2 docs */
1135 ,mpg123_id3_pic_orchestra = 10 /**< see ID3v2 docs */
1136 ,mpg123_id3_pic_composer = 11 /**< see ID3v2 docs */
1137 ,mpg123_id3_pic_lyricist = 12 /**< see ID3v2 docs */
1138 ,mpg123_id3_pic_location = 13 /**< see ID3v2 docs */
1139 ,mpg123_id3_pic_recording = 14 /**< see ID3v2 docs */
1140 ,mpg123_id3_pic_performance = 15 /**< see ID3v2 docs */
1141 ,mpg123_id3_pic_video = 16 /**< see ID3v2 docs */
1142 ,mpg123_id3_pic_fish = 17 /**< see ID3v2 docs */
1143 ,mpg123_id3_pic_illustration = 18 /**< see ID3v2 docs */
1144 ,mpg123_id3_pic_artist_logo = 19 /**< see ID3v2 docs */
1145 ,mpg123_id3_pic_publisher_logo = 20 /**< see ID3v2 docs */
1146 };
1147
1148 /** Sub data structure for ID3v2, for storing picture data including comment.
1149 * This is for the ID3v2 APIC field. You should consult the ID3v2 specification
1150 * for the use of the APIC field ("frames" in ID3v2 documentation, I use "fields"
1151 * here to separate from MPEG frames). */
1152 typedef struct
1153 {
1154 char type; /**< mpg123_id3_pic_type value */
1155 mpg123_string description; /**< description string */
1156 mpg123_string mime_type; /**< MIME type */
1157 size_t size; /**< size in bytes */
1158 unsigned char* data; /**< pointer to the image data */
1159 } mpg123_picture;
1160
1161 /** Data structure for storing IDV3v2 tags.
1162 * This structure is not a direct binary mapping with the file contents.
1163 * The ID3v2 text frames are allowed to contain multiple strings.
1164 * So check for null bytes until you reach the mpg123_string fill.
1165 * All text is encoded in UTF-8. */
1166 typedef struct
1167 {
1168 unsigned char version; /**< 3 or 4 for ID3v2.3 or ID3v2.4. */
1169 mpg123_string *title; /**< Title string (pointer into text_list). */
1170 mpg123_string *artist; /**< Artist string (pointer into text_list). */
1171 mpg123_string *album; /**< Album string (pointer into text_list). */
1172 mpg123_string *year; /**< The year as a string (pointer into text_list). */
1173 mpg123_string *genre; /**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. */
1174 mpg123_string *comment; /**< Pointer to last encountered comment text with empty description. */
1175 /* Encountered ID3v2 fields are appended to these lists.
1176 There can be multiple occurences, the pointers above always point to the last encountered data. */
1177 mpg123_text *comment_list; /**< Array of comments. */
1178 size_t comments; /**< Number of comments. */
1179 mpg123_text *text; /**< Array of ID3v2 text fields (including USLT) */
1180 size_t texts; /**< Numer of text fields. */
1181 mpg123_text *extra; /**< The array of extra (TXXX) fields. */
1182 size_t extras; /**< Number of extra text (TXXX) fields. */
1183 mpg123_picture *picture; /**< Array of ID3v2 pictures fields (APIC). */
1184 size_t pictures; /**< Number of picture (APIC) fields. */
1185 } mpg123_id3v2;
1186
1187 /** Data structure for ID3v1 tags (the last 128 bytes of a file).
1188 * Don't take anything for granted (like string termination)!
1189 * Also note the change ID3v1.1 did: comment[28] = 0; comment[29] = track_number
1190 * It is your task to support ID3v1 only or ID3v1.1 ...*/
1191 typedef struct
1192 {
1193 char tag[3]; /**< Always the string "TAG", the classic intro. */
1194 char title[30]; /**< Title string. */
1195 char artist[30]; /**< Artist string. */
1196 char album[30]; /**< Album string. */
1197 char year[4]; /**< Year string. */
1198 char comment[30]; /**< Comment string. */
1199 unsigned char genre; /**< Genre index. */
1200 } mpg123_id3v1;
1201
1202 #define MPG123_ID3 0x3 /**< 0011 There is some ID3 info. Also matches 0010 or NEW_ID3. */
1203 #define MPG123_NEW_ID3 0x1 /**< 0001 There is ID3 info that changed since last call to mpg123_id3. */
1204 #define MPG123_ICY 0xc /**< 1100 There is some ICY info. Also matches 0100 or NEW_ICY.*/
1205 #define MPG123_NEW_ICY 0x4 /**< 0100 There is ICY info that changed since last call to mpg123_icy. */
1206
1207 /** Query if there is (new) meta info, be it ID3 or ICY (or something new in future).
1208 * \param mh handle
1209 * \return combination of flags, 0 on error (same as "nothing new")
1210 */
1211 MPG123_EXPORT int mpg123_meta_check(mpg123_handle *mh);
1212
1213 /** Clean up meta data storage (ID3v2 and ICY), freeing memory.
1214 * \param mh handle
1215 */
1216 MPG123_EXPORT void mpg123_meta_free(mpg123_handle *mh);
1217
1218 /** Point v1 and v2 to existing data structures wich may change on any next read/decode function call.
1219 * v1 and/or v2 can be set to NULL when there is no corresponding data.
1220 * \return MPG123_OK on success
1221 */
1222 MPG123_EXPORT int mpg123_id3( mpg123_handle *mh
1223 , mpg123_id3v1 **v1, mpg123_id3v2 **v2 );
1224
1225 /** Point icy_meta to existing data structure wich may change on any next read/decode function call.
1226 * \param mh handle
1227 * \param icy_meta return address for ICY meta string (set to NULL if nothing there)
1228 * \return MPG123_OK on success
1229 */
1230 MPG123_EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta);
1231
1232 /** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8.
1233 * Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .
1234 * \param icy_text The input data in ICY encoding
1235 * \return pointer to newly allocated buffer with UTF-8 data (You free() it!) */
1236 MPG123_EXPORT char* mpg123_icy2utf8(const char* icy_text);
1237
1238
1239 /* @} */
1240
1241
1242 /** \defgroup mpg123_advpar mpg123 advanced parameter API
1243 *
1244 * Direct access to a parameter set without full handle around it.
1245 * Possible uses:
1246 * - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE).
1247 * - Use one set of parameters for multiple handles.
1248 *
1249 * The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt()
1250 * family) directly return a fully qualified mpg123 error code, the ones
1251 * operating on full handles normally MPG123_OK or MPG123_ERR, storing the
1252 * specific error code itseld inside the handle.
1253 *
1254 * @{
1255 */
1256
1257 /** Opaque structure for the libmpg123 decoder parameters. */
1258 struct mpg123_pars_struct;
1259
1260 /** Opaque structure for the libmpg123 decoder parameters. */
1261 typedef struct mpg123_pars_struct mpg123_pars;
1262
1263 /** Create a handle with preset parameters.
1264 * \param mp parameter handle
1265 * \param decoder decoder choice
1266 * \param error error code return address
1267 * \return mpg123 handle
1268 */
1269 MPG123_EXPORT mpg123_handle *mpg123_parnew( mpg123_pars *mp
1270 , const char* decoder, int *error );
1271
1272 /** Allocate memory for and return a pointer to a new mpg123_pars
1273 * \param error error code return address
1274 * \return new parameter handle
1275 */
1276 MPG123_EXPORT mpg123_pars *mpg123_new_pars(int *error);
1277
1278 /** Delete and free up memory used by a mpg123_pars data structure
1279 * \param mp parameter handle
1280 */
1281 MPG123_EXPORT void mpg123_delete_pars(mpg123_pars* mp);
1282
1283 /** Configure mpg123 parameters to accept no output format at all,
1284 * use before specifying supported formats with mpg123_format
1285 * \param mp parameter handle
1286 * \return MPG123_OK on success
1287 */
1288 MPG123_EXPORT int mpg123_fmt_none(mpg123_pars *mp);
1289
1290 /** Configure mpg123 parameters to accept all formats
1291 * (also any custom rate you may set) -- this is default.
1292 * \param mp parameter handle
1293 * \return MPG123_OK on success
1294 */
1295 MPG123_EXPORT int mpg123_fmt_all(mpg123_pars *mp);
1296
1297 /** Set the audio format support of a mpg123_pars in detail:
1298 * \param mp parameter handle
1299 * \param rate The sample rate value (in Hertz).
1300 * \param channels A combination of MPG123_STEREO and MPG123_MONO.
1301 * \param encodings A combination of accepted encodings for rate and channels,
1302 * p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no
1303 * support).
1304 * \return MPG123_OK on success
1305 */
1306 MPG123_EXPORT int mpg123_fmt(mpg123_pars *mp
1307 , long rate, int channels, int encodings);
1308
1309 /** Check to see if a specific format at a specific rate is supported
1310 * by mpg123_pars.
1311 * \param mp parameter handle
1312 * \param rate sampling rate
1313 * \param encoding encoding
1314 * \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
1315 * MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
1316 MPG123_EXPORT int mpg123_fmt_support(mpg123_pars *mp, long rate, int encoding);
1317
1318 /** Set a specific parameter, for a specific mpg123_pars, using a parameter
1319 * type key chosen from the mpg123_parms enumeration, to the specified value.
1320 * \param mp parameter handle
1321 * \param type parameter choice
1322 * \param value integer value
1323 * \param fvalue floating point value
1324 * \return MPG123_OK on success
1325 */
1326 MPG123_EXPORT int mpg123_par( mpg123_pars *mp
1327 , enum mpg123_parms type, long value, double fvalue );
1328
1329 /** Get a specific parameter, for a specific mpg123_pars.
1330 * See the mpg123_parms enumeration for a list of available parameters.
1331 * \param mp parameter handle
1332 * \param type parameter choice
1333 * \param value integer value return address
1334 * \param fvalue floating point value return address
1335 * \return MPG123_OK on success
1336 */
1337 MPG123_EXPORT int mpg123_getpar( mpg123_pars *mp
1338 , enum mpg123_parms type, long *value, double *fvalue);
1339
1340 /* @} */
1341
1342
1343 /** \defgroup mpg123_lowio mpg123 low level I/O
1344 * 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...
1345 *
1346 * @{ */
1347
1348 /** Replace default internal buffer with user-supplied buffer.
1349 * Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio.
1350 * Note that the required buffer size could be bigger than expected from output
1351 * encoding if libmpg123 has to convert from primary decoder output (p.ex. 32 bit
1352 * storage for 24 bit output).
1353 * \param mh handle
1354 * \param data pointer to user buffer
1355 * \param size of buffer in bytes
1356 * \return MPG123_OK on success
1357 */
1358 MPG123_EXPORT int mpg123_replace_buffer(mpg123_handle *mh
1359 , unsigned char *data, size_t size);
1360
1361 /** The max size of one frame's decoded output with current settings.
1362 * Use that to determine an appropriate minimum buffer size for decoding one frame.
1363 * \param mh handle
1364 * \return maximum decoded data size in bytes
1365 */
1366 MPG123_EXPORT size_t mpg123_outblock(mpg123_handle *mh);
1367
1368 /** Replace low-level stream access functions; read and lseek as known in POSIX.
1369 * You can use this to make any fancy file opening/closing yourself,
1370 * using mpg123_open_fd() to set the file descriptor for your read/lseek
1371 * (doesn't need to be a "real" file descriptor...).
1372 * Setting a function to NULL means that the default internal read is
1373 * used (active from next mpg123_open call on).
1374 * Note: As it would be troublesome to mess with this while having a file open,
1375 * this implies mpg123_close().
1376 * \param mh handle
1377 * \param r_read callback for reading (behaviour like POSIX read)
1378 * \param r_lseek callback for seeking (like POSIX lseek)
1379 * \return MPG123_OK on success
1380 */
1381 MPG123_EXPORT int mpg123_replace_reader( mpg123_handle *mh
1382 , ssize_t (*r_read) (int, void *, size_t)
1383 , off_t (*r_lseek)(int, off_t, int)
1384 );
1385
1386 /** Replace I/O functions with your own ones operating on some kind of
1387 * handle instead of integer descriptors.
1388 * The handle is a void pointer, so you can pass any data you want...
1389 * mpg123_open_handle() is the call you make to use the I/O defined here.
1390 * There is no fallback to internal read/seek here.
1391 * Note: As it would be troublesome to mess with this while having a file open,
1392 * this mpg123_close() is implied here.
1393 * \param mh handle
1394 * \param r_read callback for reading (behaviour like POSIXread)
1395 * \param r_lseek callback for seeking (like POSIX lseek)
1396 * \param cleanup A callback to clean up an I/O handle on mpg123_close,
1397 * can be NULL for none (you take care of cleaning your handles).
1398 * \return MPG123_OK on success
1399 */
1400 MPG123_EXPORT int mpg123_replace_reader_handle( mpg123_handle *mh
1401 , ssize_t (*r_read) (void *, void *, size_t)
1402 , off_t (*r_lseek)(void *, off_t, int)
1403 , void (*cleanup)(void*) );
1404
1405 /* @} */
1406
1407 #ifdef __cplusplus
1408 }
1409 #endif
1410
1411 #undef MPG123_EXPORT
1412
1413 #endif