Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/mpg123/src/include/mpg123.h
4392 views
1
/*
2
libmpg123: MPEG Audio Decoder library
3
4
copyright 1995-2023 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
/** \defgroup mpg123_h mpg123 header general settings and notes
17
* @{
18
*/
19
20
/** A macro to check at compile time which set of API functions to expect.
21
* This must be incremented at least each time a new symbol is added
22
* to the header.
23
*/
24
#define MPG123_API_VERSION 49
25
/** library patch level at client build time */
26
#define MPG123_PATCHLEVEL 3
27
28
#ifndef MPG123_EXPORT
29
/** Defines needed for MS Visual Studio(tm) DLL builds.
30
* Every public function must be prefixed with MPG123_EXPORT. When building
31
* the DLL ensure to define BUILD_MPG123_DLL. This makes the function accessible
32
* for clients and includes it in the import library which is created together
33
* with the DLL. When consuming the DLL ensure to define LINK_MPG123_DLL which
34
* imports the functions from the DLL.
35
*/
36
#ifdef BUILD_MPG123_DLL
37
/* The dll exports. */
38
#define MPG123_EXPORT __declspec(dllexport)
39
#else
40
#ifdef LINK_MPG123_DLL
41
/* The exe imports. */
42
#define MPG123_EXPORT __declspec(dllimport)
43
#else
44
/* Nothing on normal/UNIX builds */
45
#define MPG123_EXPORT
46
#endif
47
#endif
48
#endif
49
50
/** \page enumapi About enum API
51
*
52
* Earlier versions of libmpg123 put enums into public API calls,
53
* which is not exactly safe. There are ABI rules, but you can use
54
* compiler switches to change the sizes of enums. It is safer not
55
* to have them in API calls. Thus, the default is to remap calls and
56
* structs to variants that use plain ints. Define MPG123_ENUM_API to
57
* prevent that remapping.
58
*
59
* You might want to define this to increase the chance of your binary
60
* working with an older version of the library. But if that is your goal,
61
* you should better build with an older version to begin with.
62
*
63
* You can avoid renamed symbols by using the non-enum names directly:
64
*
65
* - mpg123_param2()
66
* - mpg123_getparam2()
67
* - mpg123_feature2()
68
* - mpg123_eq2()
69
* - mpg123_geteq2()
70
* - mpg123_frameinfo2()
71
* - mpg123_info2()
72
* - mpg123_getstate2()
73
* - mpg123_enc_from_id3_2()
74
* - mpg123_store_utf8_2()
75
* - mpg123_par2()
76
* - mpg123_getpar2()
77
*/
78
#ifndef MPG123_ENUM_API
79
80
#define mpg123_param mpg123_param2
81
#define mpg123_getparam mpg123_getparam2
82
#define mpg123_feature mpg123_feature2
83
#define mpg123_eq mpg123_eq2
84
#define mpg123_geteq mpg123_geteq2
85
#define mpg123_frameinfo mpg123_frameinfo2
86
#define mpg123_info mpg123_info2
87
#define mpg123_getstate mpg123_getstate2
88
#define mpg123_enc_from_id3 mpg123_enc_from_id3_2
89
#define mpg123_store_utf8 mpg123_store_utf8_2
90
#define mpg123_par mpg123_par2
91
#define mpg123_getpar mpg123_getpar2
92
93
#endif
94
95
#include <stddef.h>
96
#include <stdint.h>
97
98
#ifndef MPG123_PORTABLE_API
99
#include <sys/types.h>
100
/** A little hack to help MSVC not having ssize_t. */
101
#ifdef _MSC_VER
102
typedef ptrdiff_t mpg123_ssize_t;
103
#else
104
typedef ssize_t mpg123_ssize_t;
105
#endif
106
#endif
107
108
109
/** \page lfs Handling of large file offsets
110
*
111
* When client code defines _FILE_OFFSET_BITS, it wants non-default large file
112
* support, and thus functions with added suffix (mpg123_open_64). The default
113
* library build provides wrapper and alias functions to accomodate client code
114
* variations (dual-mode library like glibc).
115
*
116
* Client code can definie MPG123_NO_LARGENAME and MPG123_LARGESUFFIX,
117
* respectively, for disabling or enforcing the suffixes. You should *not* do
118
* this, though, unless you *really* want to deal with symbol ABI yourself.
119
* If explicit usage of 64 bit offsets is desired, the int64_t API
120
* consisting of functions with 64 suffix without underscore, notably
121
* mpg123_reader64(), can be used since API version 48 (mpg123 1.32). A matching
122
* mpg123_open64(), stripped-down mpg123_open_handle_64() is present since API
123
* version 49 (mpg123 1.33).
124
*
125
* When in doubt, use the explicit 64 bit functions and avoid off_t in the API.
126
* You can define MPG123_PORTABLE_API to ensure that. That being said, if you
127
* and your compiler do not have problems with the concept of off_t, just use
128
* the normal AP like the I/O API of the standard C library. Both 32 and 64 bit
129
* versions of functions will be present where appropriate.
130
*
131
* If your toolchain enforces _FILE_OFFSET_BITS also during build of libmpg123,
132
* only that setting will be supported for client code.
133
*/
134
135
#ifndef MPG123_PORTABLE_API
136
/** \page lfs_names Renaming of functions for largefile support
137
*
138
* Now, the renaming of large file aware functions.
139
* By default, it appends underscore _FILE_OFFSET_BITS (so, mpg123_seek_64() for mpg123_seek()),
140
* if _FILE_OFFSET_BITS is defined. These are the affected API functions:
141
*
142
* - mpg123_open_fixed()
143
* - mpg123_open()
144
* - mpg123_open_fd()
145
* - mpg123_open_handle()
146
* - mpg123_framebyframe_decode()
147
* - mpg123_decode_frame()
148
* - mpg123_tell()
149
* - mpg123_tellframe()
150
* - mpg123_tell_stream()
151
* - mpg123_seek()
152
* - mpg123_feedseek()
153
* - mpg123_seek_frame()
154
* - mpg123_timeframe()
155
* - mpg123_index()
156
* - mpg123_set_index()
157
* - mpg123_position()
158
* - mpg123_length()
159
* - mpg123_framelength()
160
* - mpg123_set_filesize()
161
* - mpg123_replace_reader()
162
* - mpg123_replace_reader_handle()
163
* - mpg123_framepos()
164
*/
165
#if (!defined MPG123_NO_LARGENAME) && ((defined _FILE_OFFSET_BITS) || (defined MPG123_LARGESUFFIX))
166
167
/* Need some trickery to concatenate the value(s) of the given macro(s). */
168
#define MPG123_MACROCAT_REALLY(a, b) a ## b
169
#define MPG123_MACROCAT(a, b) MPG123_MACROCAT_REALLY(a, b)
170
#ifndef MPG123_LARGESUFFIX
171
#define MPG123_LARGESUFFIX MPG123_MACROCAT(_, _FILE_OFFSET_BITS)
172
#endif
173
#define MPG123_LARGENAME(func) MPG123_MACROCAT(func, MPG123_LARGESUFFIX)
174
175
#define mpg123_open_fixed MPG123_LARGENAME(mpg123_open_fixed)
176
#define mpg123_open MPG123_LARGENAME(mpg123_open)
177
#define mpg123_open_fd MPG123_LARGENAME(mpg123_open_fd)
178
#define mpg123_open_handle MPG123_LARGENAME(mpg123_open_handle)
179
#define mpg123_framebyframe_decode MPG123_LARGENAME(mpg123_framebyframe_decode)
180
#define mpg123_decode_frame MPG123_LARGENAME(mpg123_decode_frame)
181
#define mpg123_tell MPG123_LARGENAME(mpg123_tell)
182
#define mpg123_tellframe MPG123_LARGENAME(mpg123_tellframe)
183
#define mpg123_tell_stream MPG123_LARGENAME(mpg123_tell_stream)
184
#define mpg123_seek MPG123_LARGENAME(mpg123_seek)
185
#define mpg123_feedseek MPG123_LARGENAME(mpg123_feedseek)
186
#define mpg123_seek_frame MPG123_LARGENAME(mpg123_seek_frame)
187
#define mpg123_timeframe MPG123_LARGENAME(mpg123_timeframe)
188
#define mpg123_index MPG123_LARGENAME(mpg123_index)
189
#define mpg123_set_index MPG123_LARGENAME(mpg123_set_index)
190
#define mpg123_position MPG123_LARGENAME(mpg123_position)
191
#define mpg123_length MPG123_LARGENAME(mpg123_length)
192
#define mpg123_framelength MPG123_LARGENAME(mpg123_framelength)
193
#define mpg123_set_filesize MPG123_LARGENAME(mpg123_set_filesize)
194
#define mpg123_replace_reader MPG123_LARGENAME(mpg123_replace_reader)
195
#define mpg123_replace_reader_handle MPG123_LARGENAME(mpg123_replace_reader_handle)
196
#define mpg123_framepos MPG123_LARGENAME(mpg123_framepos)
197
198
#endif /* largefile hackery */
199
#endif
200
201
/** @} */
202
203
#ifdef __cplusplus
204
extern "C" {
205
#endif
206
207
/** \defgroup mpg123_init mpg123 library and handle setup
208
*
209
* Functions to initialise and shutdown the mpg123 library and handles.
210
* The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-)
211
* Tip: Use a RVA setting...
212
*
213
* @{
214
*/
215
216
/** Opaque structure for the libmpg123 decoder handle. */
217
struct mpg123_handle_struct;
218
219
/** Opaque structure for the libmpg123 decoder handle.
220
* Most functions take a pointer to a mpg123_handle as first argument and operate on its data in an object-oriented manner.
221
*/
222
typedef struct mpg123_handle_struct mpg123_handle;
223
224
/** Get version of the mpg123 distribution this library build came with.
225
* (optional means non-NULL)
226
* \param major optional address to store major version number
227
* \param minor optional address to store minor version number
228
* \param patch optional address to store patchlevel version number
229
* \return full version string (like "1.2.3-beta4 (experimental)")
230
*/
231
const char *mpg123_distversion(unsigned int *major, unsigned int *minor, unsigned int *patch);
232
233
/** Get API version of library build.
234
* \param patch optional address to store patchlevel
235
* \return API version of library
236
*/
237
unsigned int mpg123_libversion(unsigned int *patch);
238
239
/** Useless no-op that used to do initialization work.
240
*
241
* For API version before 46 (mpg123 1.27.0), you had to ensure to have
242
* this called once before creating a handle. To be pure, this had to
243
* happen in a single-threaded context, too (while in practice, there was no
244
* harm done possibly racing to compute the same numbers again).
245
*
246
* Now this function really does nothing anymore. The only reason to call
247
* it is to be compatible with old versions of the library that still require
248
* it.
249
*
250
* \return MPG123_OK if successful, otherwise an error number.
251
*/
252
MPG123_EXPORT int mpg123_init(void);
253
254
/** Superfluous Function to close down the mpg123 library.
255
* This was created with the thought that there sometime will be cleanup code
256
* to be run after library use. This never materialized. You can forget about
257
* this function and it is only here for old programs that do call it.
258
*/
259
MPG123_EXPORT void mpg123_exit(void);
260
261
/** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()).
262
* and optional retrieval of an error code to feed to mpg123_plain_strerror().
263
* Optional means: Any of or both the parameters may be NULL.
264
*
265
* \param decoder optional choice of decoder variant (NULL for default)
266
* \param error optional address to store error codes
267
* \return Non-NULL pointer to fresh handle when successful.
268
*/
269
MPG123_EXPORT mpg123_handle *mpg123_new(const char* decoder, int *error);
270
271
/** Delete handle, mh is either a valid mpg123 handle or NULL.
272
* \param mh handle
273
*/
274
MPG123_EXPORT void mpg123_delete(mpg123_handle *mh);
275
276
/** Free plain memory allocated within libmpg123.
277
* This is for library users that are not sure to use the same underlying
278
* memory allocator as libmpg123. It is just a wrapper over free() in
279
* the underlying C library.
280
*/
281
MPG123_EXPORT void mpg123_free(void *ptr);
282
283
/** Enumeration of the parameters types that it is possible to set/get. */
284
enum mpg123_parms
285
{
286
MPG123_VERBOSE = 0, /**< set verbosity value for enabling messages to stderr, >= 0 makes sense (integer) */
287
MPG123_FLAGS, /**< set all flags, p.ex val = MPG123_GAPLESS|MPG123_MONO_MIX (integer) */
288
MPG123_ADD_FLAGS, /**< add some flags (integer) */
289
MPG123_FORCE_RATE, /**< when value > 0, force output rate to that value (integer) */
290
MPG123_DOWN_SAMPLE, /**< 0=native rate, 1=half rate, 2=quarter rate (integer) */
291
MPG123_RVA, /**< one of the RVA choices above (integer) */
292
MPG123_DOWNSPEED, /**< play a frame N times (integer) */
293
MPG123_UPSPEED, /**< play every Nth frame (integer) */
294
MPG123_START_FRAME, /**< start with this frame (skip frames before that, integer) */
295
MPG123_DECODE_FRAMES, /**< decode only this number of frames (integer) */
296
MPG123_ICY_INTERVAL, /**< Stream contains ICY metadata with this interval (integer).
297
Make sure to set this _before_ opening a stream.*/
298
MPG123_OUTSCALE, /**< the scale for output samples (amplitude - integer or float according to mpg123 output format, normally integer) */
299
MPG123_TIMEOUT, /**< timeout for reading from a stream (not supported on win32, integer) */
300
MPG123_REMOVE_FLAGS, /**< remove some flags (inverse of MPG123_ADD_FLAGS, integer) */
301
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). */
302
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. */
303
,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.*/
304
,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) */
305
,MPG123_FEEDBUFFER /**< Minimal size of one internal feeder buffer, again, the default value is subject to change. (integer) */
306
,MPG123_FREEFORMAT_SIZE /**< Tell the parser a free-format frame size to
307
* avoid read-ahead to get it. A value of -1 (default) means that the parser
308
* will determine it. The parameter value is applied during decoder setup
309
* for a freshly opened stream only.
310
*/
311
};
312
313
/** Flag bits for MPG123_FLAGS, use the usual binary or to combine. */
314
enum mpg123_param_flags
315
{
316
MPG123_FORCE_MONO = 0x7 /**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. */
317
,MPG123_MONO_LEFT = 0x1 /**< 0001 Force playback of left channel only. */
318
,MPG123_MONO_RIGHT = 0x2 /**< 0010 Force playback of right channel only. */
319
,MPG123_MONO_MIX = 0x4 /**< 0100 Force playback of mixed mono. */
320
,MPG123_FORCE_STEREO = 0x8 /**< 1000 Force stereo output. */
321
,MPG123_FORCE_8BIT = 0x10 /**< 00010000 Force 8bit formats. */
322
,MPG123_QUIET = 0x20 /**< 00100000 Suppress any printouts (overrules verbose). */
323
,MPG123_GAPLESS = 0x40 /**< 01000000 Enable gapless decoding (default on if libmpg123 has support). */
324
,MPG123_NO_RESYNC = 0x80 /**< 10000000 Disable resync stream after error. */
325
,MPG123_SEEKBUFFER = 0x100 /**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). */
326
,MPG123_FUZZY = 0x200 /**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) */
327
,MPG123_FORCE_FLOAT = 0x400 /**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). */
328
,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. */
329
,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 */
330
,MPG123_SKIP_ID3V2 = 0x2000 /**< 10 0000 0000 0000 Do not parse ID3v2 tags, just skip them. */
331
,MPG123_IGNORE_INFOFRAME = 0x4000 /**< 100 0000 0000 0000 Do not parse the LAME/Xing info frame, treat it as normal MPEG data. */
332
,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. */
333
,MPG123_PICTURE = 0x10000 /**< 17th bit: Enable storage of pictures from tags (ID3v2 APIC). */
334
,MPG123_NO_PEEK_END = 0x20000 /**< 18th bit: Do not seek to the end of
335
* the stream in order to probe
336
* the stream length and search for the id3v1 field. This also means
337
* the file size is unknown unless set using mpg123_set_filesize() and
338
* the stream is assumed as non-seekable unless overridden.
339
*/
340
,MPG123_FORCE_SEEKABLE = 0x40000 /**< 19th bit: Force the stream to be seekable. */
341
,MPG123_STORE_RAW_ID3 = 0x80000 /**< store raw ID3 data (even if skipping) */
342
,MPG123_FORCE_ENDIAN = 0x100000 /**< Enforce endianess of output samples.
343
* This is not reflected in the format codes. If this flag is set along with
344
* MPG123_BIG_ENDIAN, MPG123_ENC_SIGNED16 means s16be, without
345
* MPG123_BIG_ENDIAN, it means s16le. Normal operation without
346
* MPG123_FORCE_ENDIAN produces output in native byte order.
347
*/
348
,MPG123_BIG_ENDIAN = 0x200000 /**< Choose big endian instead of little. */
349
,MPG123_NO_READAHEAD = 0x400000 /**< Disable read-ahead in parser. If
350
* you know you provide full frames to the feeder API, this enables
351
* decoder output from the first one on, instead of having to wait for
352
* the next frame to confirm that the stream is healthy. It also disables
353
* free format support unless you provide a frame size using
354
* MPG123_FREEFORMAT_SIZE.
355
*/
356
,MPG123_FLOAT_FALLBACK = 0x800000 /**< Consider floating point output encoding only after
357
* trying other (possibly downsampled) rates and encodings first. This is to
358
* support efficient playback where floating point output is only configured for
359
* an external resampler, bypassing that resampler when the desired rate can
360
* be produced directly. This is enabled by default to be closer to older versions
361
* of libmpg123 which did not enable float automatically at all. If disabled,
362
* float is considered after the 16 bit default and higher-bit integer encodings
363
* for any rate. */
364
,MPG123_NO_FRANKENSTEIN = 0x1000000 /**< Disable support for Frankenstein streams
365
* (different MPEG streams stiched together). Do not accept serious change of MPEG
366
* header inside a single stream. With this flag, the audio output format cannot
367
* change during decoding unless you open a new stream. This also stops decoding
368
* after an announced end of stream (Info header contained a number of frames
369
* and this number has been reached). This makes your MP3 files behave more like
370
* ordinary media files with defined structure, rather than stream dumps with
371
* some sugar. */
372
};
373
374
/** choices for MPG123_RVA */
375
enum mpg123_param_rva
376
{
377
MPG123_RVA_OFF = 0 /**< RVA disabled (default). */
378
,MPG123_RVA_MIX = 1 /**< Use mix/track/radio gain. */
379
,MPG123_RVA_ALBUM = 2 /**< Use album/audiophile gain */
380
,MPG123_RVA_MAX = MPG123_RVA_ALBUM /**< The maximum RVA code, may increase in future. */
381
};
382
383
#ifdef MPG123_ENUM_API
384
/** Set a specific parameter on a handle.
385
*
386
* Note that this name is mapped to mpg123_param2() instead unless
387
* MPG123_ENUM_API is defined.
388
*
389
* \param mh handle
390
* \param type parameter choice
391
* \param value integer value
392
* \param fvalue floating point value
393
* \return MPG123_OK on success
394
*/
395
MPG123_EXPORT int mpg123_param( mpg123_handle *mh
396
, enum mpg123_parms type, long value, double fvalue );
397
#endif
398
399
/** Set a specific parameter on a handle. No enums.
400
*
401
* This is actually called instead of mpg123_param()
402
* unless MPG123_ENUM_API is defined.
403
*
404
* \param mh handle
405
* \param type parameter choice (from enum #mpg123_parms)
406
* \param value integer value
407
* \param fvalue floating point value
408
* \return MPG123_OK on success
409
*/
410
MPG123_EXPORT int mpg123_param2( mpg123_handle *mh
411
, int type, long value, double fvalue );
412
413
#ifdef MPG123_ENUM_API
414
/** Get a specific parameter from a handle.
415
*
416
* Note that this name is mapped to mpg123_getparam2() instead unless
417
* MPG123_ENUM_API is defined.
418
*
419
* \param mh handle
420
* \param type parameter choice
421
* \param value integer value return address
422
* \param fvalue floating point value return address
423
* \return MPG123_OK on success
424
*/
425
MPG123_EXPORT int mpg123_getparam( mpg123_handle *mh
426
, enum mpg123_parms type, long *value, double *fvalue );
427
#endif
428
429
/** Get a specific parameter from a handle. No enums.
430
*
431
* This is actually called instead of mpg123_getparam() unless MPG123_ENUM_API
432
* is defined.
433
*
434
* \param mh handle
435
* \param type parameter choice (from enum #mpg123_parms)
436
* \param value integer value return address
437
* \param fvalue floating point value return address
438
* \return MPG123_OK on success
439
*/
440
MPG123_EXPORT int mpg123_getparam2( mpg123_handle *mh
441
, int type, long *value, double *fvalue );
442
443
/** Feature set available for query with mpg123_feature. */
444
enum mpg123_feature_set
445
{
446
MPG123_FEATURE_ABI_UTF8OPEN = 0 /**< mpg123 expects path names to be given in UTF-8 encoding instead of plain native. */
447
,MPG123_FEATURE_OUTPUT_8BIT /**< 8bit output */
448
,MPG123_FEATURE_OUTPUT_16BIT /**< 16bit output */
449
,MPG123_FEATURE_OUTPUT_32BIT /**< 32bit output */
450
,MPG123_FEATURE_INDEX /**< support for building a frame index for accurate seeking */
451
,MPG123_FEATURE_PARSE_ID3V2 /**< id3v2 parsing */
452
,MPG123_FEATURE_DECODE_LAYER1 /**< mpeg layer-1 decoder enabled */
453
,MPG123_FEATURE_DECODE_LAYER2 /**< mpeg layer-2 decoder enabled */
454
,MPG123_FEATURE_DECODE_LAYER3 /**< mpeg layer-3 decoder enabled */
455
,MPG123_FEATURE_DECODE_ACCURATE /**< accurate decoder rounding */
456
,MPG123_FEATURE_DECODE_DOWNSAMPLE /**< downsample (sample omit) */
457
,MPG123_FEATURE_DECODE_NTOM /**< flexible rate decoding */
458
,MPG123_FEATURE_PARSE_ICY /**< ICY support */
459
,MPG123_FEATURE_TIMEOUT_READ /**< Reader with timeout (network). */
460
,MPG123_FEATURE_EQUALIZER /**< tunable equalizer */
461
,MPG123_FEATURE_MOREINFO /**< more info extraction (for frame analyzer) */
462
,MPG123_FEATURE_OUTPUT_FLOAT32 /**< 32 bit float output */
463
,MPG123_FEATURE_OUTPUT_FLOAT64 /**< 64 bit float output (as of now: never!) */
464
};
465
466
#ifdef MPG123_ENUM_API
467
/** Query libmpg123 features.
468
*
469
* Note that this name is mapped to mpg123_feature2() instead unless
470
* MPG123_ENUM_API is defined.
471
*
472
* \param key feature selection
473
* \return 1 for success, 0 for unimplemented functions
474
*/
475
MPG123_EXPORT int mpg123_feature(const enum mpg123_feature_set key);
476
#endif
477
478
/** Query libmpg123 features. No enums.
479
*
480
* This is actually called instead of mpg123_feature() unless MPG123_ENUM_API
481
* is defined.
482
*
483
* \param key feature selection (from enum #mpg123_feature_set)
484
* \return 1 for success, 0 for unimplemented functions
485
*/
486
MPG123_EXPORT int mpg123_feature2(int key);
487
488
/** @} */
489
490
491
/** \defgroup mpg123_error mpg123 error handling
492
*
493
* Functions to get text version of the error numbers and an enumeration
494
* of the error codes returned by libmpg123.
495
*
496
* Most functions operating on a mpg123_handle simply return MPG123_OK (0)
497
* on success and MPG123_ERR (-1) on failure, setting the internal error
498
* variable of the handle to the specific error code. If there was not a valid
499
* (non-NULL) handle provided to a function operating on one, MPG123_BAD_HANDLE
500
* may be returned if this can not be confused with a valid positive return
501
* value.
502
* Meaning: A function expected to return positive integers on success will
503
* always indicate error or a special condition by returning a negative one.
504
*
505
* Decoding/seek functions may also return message codes MPG123_DONE,
506
* MPG123_NEW_FORMAT and MPG123_NEED_MORE (all negative, see below on how to
507
* react). Note that calls to those can be nested, so generally watch out
508
* for these codes after initial handle setup.
509
* Especially any function that needs information about the current stream
510
* to work will try to at least parse the beginning if that did not happen
511
* yet.
512
*
513
* On a function that is supposed to return MPG123_OK on success and
514
* MPG123_ERR on failure, make sure you check for != MPG123_OK, not
515
* == MPG123_ERR, as the error code could get more specific in future,
516
* or there is just a special message from a decoding routine as indicated
517
* above.
518
*
519
* @{
520
*/
521
522
/** Enumeration of the message and error codes and returned by libmpg123 functions. */
523
enum mpg123_errors
524
{
525
MPG123_DONE=-12, /**< Message: Track ended. Stop decoding. */
526
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. */
527
MPG123_NEED_MORE=-10, /**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). */
528
MPG123_ERR=-1, /**< Generic Error */
529
MPG123_OK=0, /**< Success */
530
MPG123_BAD_OUTFORMAT, /**< Unable to set up output format! */
531
MPG123_BAD_CHANNEL, /**< Invalid channel number specified. */
532
MPG123_BAD_RATE, /**< Invalid sample rate specified. */
533
MPG123_ERR_16TO8TABLE, /**< Unable to allocate memory for 16 to 8 converter table! */
534
MPG123_BAD_PARAM, /**< Bad parameter id! */
535
MPG123_BAD_BUFFER, /**< Bad buffer given -- invalid pointer or too small size. */
536
MPG123_OUT_OF_MEM, /**< Out of memory -- some malloc() failed. */
537
MPG123_NOT_INITIALIZED, /**< You didn't initialize the library! */
538
MPG123_BAD_DECODER, /**< Invalid decoder choice. */
539
MPG123_BAD_HANDLE, /**< Invalid mpg123 handle. */
540
MPG123_NO_BUFFERS, /**< Unable to initialize frame buffers (out of memory?). */
541
MPG123_BAD_RVA, /**< Invalid RVA mode. */
542
MPG123_NO_GAPLESS, /**< This build doesn't support gapless decoding. */
543
MPG123_NO_SPACE, /**< Not enough buffer space. */
544
MPG123_BAD_TYPES, /**< Incompatible numeric data types. */
545
MPG123_BAD_BAND, /**< Bad equalizer band. */
546
MPG123_ERR_NULL, /**< Null pointer given where valid storage address needed. */
547
MPG123_ERR_READER, /**< Error reading the stream. */
548
MPG123_NO_SEEK_FROM_END,/**< Cannot seek from end (end is not known). */
549
MPG123_BAD_WHENCE, /**< Invalid 'whence' for seek function.*/
550
MPG123_NO_TIMEOUT, /**< Build does not support stream timeouts. */
551
MPG123_BAD_FILE, /**< File access error. */
552
MPG123_NO_SEEK, /**< Seek not supported by stream. */
553
MPG123_NO_READER, /**< No stream opened or no reader callback setup. */
554
MPG123_BAD_PARS, /**< Bad parameter handle. */
555
MPG123_BAD_INDEX_PAR, /**< Bad parameters to mpg123_index() and mpg123_set_index() */
556
MPG123_OUT_OF_SYNC, /**< Lost track in bytestream and did not try to resync. */
557
MPG123_RESYNC_FAIL, /**< Resync failed to find valid MPEG data. */
558
MPG123_NO_8BIT, /**< No 8bit encoding possible. */
559
MPG123_BAD_ALIGN, /**< Stack aligmnent error */
560
MPG123_NULL_BUFFER, /**< NULL input buffer with non-zero size... */
561
MPG123_NO_RELSEEK, /**< Relative seek not possible (screwed up file offset) */
562
MPG123_NULL_POINTER, /**< You gave a null pointer somewhere where you shouldn't have. */
563
MPG123_BAD_KEY, /**< Bad key value given. */
564
MPG123_NO_INDEX, /**< No frame index in this build. */
565
MPG123_INDEX_FAIL, /**< Something with frame index went wrong. */
566
MPG123_BAD_DECODER_SETUP, /**< Something prevents a proper decoder setup */
567
MPG123_MISSING_FEATURE /**< This feature has not been built into libmpg123. */
568
,MPG123_BAD_VALUE /**< A bad value has been given, somewhere. */
569
,MPG123_LSEEK_FAILED /**< Low-level seek failed. */
570
,MPG123_BAD_CUSTOM_IO /**< Custom I/O not prepared. */
571
,MPG123_LFS_OVERFLOW /**< Offset value overflow during translation of large file API calls -- your client program cannot handle that large file. */
572
,MPG123_INT_OVERFLOW /**< Some integer overflow. */
573
,MPG123_BAD_FLOAT /**< Floating-point computations work not as expected. */
574
};
575
576
/** Look up error strings given integer code.
577
* \param errcode integer error code
578
* \return string describing what that error error code means
579
*/
580
MPG123_EXPORT const char* mpg123_plain_strerror(int errcode);
581
582
/** Give string describing what error has occured in the context of handle mh.
583
* When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via
584
* char *errmsg = mpg123_strerror(mh)
585
* This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE.
586
* \param mh handle
587
* \return error message
588
*/
589
MPG123_EXPORT const char* mpg123_strerror(mpg123_handle *mh);
590
591
/** Return the plain errcode intead of a string.
592
* \param mh handle
593
* \return error code recorded in handle or MPG123_BAD_HANDLE
594
*/
595
MPG123_EXPORT int mpg123_errcode(mpg123_handle *mh);
596
597
/** @} */
598
599
600
/** \defgroup mpg123_decoder mpg123 decoder selection
601
*
602
* Functions to list and select the available decoders.
603
* Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is).
604
*
605
* @{
606
*/
607
608
/** Get available decoder list.
609
* \return NULL-terminated array of generally available decoder names (plain 8bit ASCII)
610
*/
611
MPG123_EXPORT const char **mpg123_decoders(void);
612
613
/** Get supported decoder list.
614
*
615
* This possibly writes to static storage in the library, so avoid
616
* calling concurrently, please.
617
*
618
* \return NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII)
619
*/
620
MPG123_EXPORT const char **mpg123_supported_decoders(void);
621
622
/** Set the active decoder.
623
* \param mh handle
624
* \param decoder_name name of decoder
625
* \return MPG123_OK on success
626
*/
627
MPG123_EXPORT int mpg123_decoder(mpg123_handle *mh, const char* decoder_name);
628
629
/** Get the currently active decoder name.
630
* The active decoder engine can vary depening on output constraints,
631
* mostly non-resampling, integer output is accelerated via 3DNow & Co. but for
632
* other modes a fallback engine kicks in.
633
* Note that this can return a decoder that is only active in the hidden and not
634
* available as decoder choice from the outside.
635
* \param mh handle
636
* \return The decoder name or NULL on error.
637
*/
638
MPG123_EXPORT const char* mpg123_current_decoder(mpg123_handle *mh);
639
640
/** @} */
641
642
643
/** \defgroup mpg123_output mpg123 output audio format
644
*
645
* Functions to get and select the format of the decoded audio.
646
*
647
* Before you dive in, please be warned that you might get confused by this.
648
* This seems to happen a lot, therefore I am trying to explain in advance.
649
* If you do feel confused and just want to decode your normal MPEG audio files that
650
* don't alter properties in the middle, just use mpg123_open_fixed() with a fixed encoding
651
* and channel count and forget about a matrix of audio formats. If you want to get funky,
652
* read ahead ...
653
*
654
* 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).
655
*
656
* 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.
657
*
658
* 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.
659
*
660
* 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.
661
*
662
* @{
663
*/
664
665
/** They can be combined into one number (3) to indicate mono and stereo... */
666
enum mpg123_channelcount
667
{
668
MPG123_MONO = 1 /**< mono */
669
,MPG123_STEREO = 2 /**< stereo */
670
};
671
672
/** An array of supported standard sample rates
673
* These are possible native sample rates of MPEG audio files.
674
* You can still force mpg123 to resample to a different one, but by
675
* default you will only get audio in one of these samplings.
676
* This list is in ascending order.
677
* \param list Store a pointer to the sample rates array there.
678
* \param number Store the number of sample rates there. */
679
MPG123_EXPORT void mpg123_rates(const long **list, size_t *number);
680
681
/** An array of supported audio encodings.
682
* An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED).
683
* \param list Store a pointer to the encodings array there.
684
* \param number Store the number of encodings there. */
685
MPG123_EXPORT void mpg123_encodings(const int **list, size_t *number);
686
687
/** Return the size (in bytes) of one mono sample of the named encoding.
688
* \param encoding The encoding value to analyze.
689
* \return positive size of encoding in bytes, 0 on invalid encoding. */
690
MPG123_EXPORT int mpg123_encsize(int encoding);
691
692
/** Configure a mpg123 handle to accept no output format at all,
693
* use before specifying supported formats with mpg123_format
694
* \param mh handle
695
* \return MPG123_OK on success
696
*/
697
MPG123_EXPORT int mpg123_format_none(mpg123_handle *mh);
698
699
/** Configure mpg123 handle to accept all formats
700
* (also any custom rate you may set) -- this is default.
701
* \param mh handle
702
* \return MPG123_OK on success
703
*/
704
MPG123_EXPORT int mpg123_format_all(mpg123_handle *mh);
705
706
/** Set the audio format support of a mpg123_handle in detail:
707
* \param mh handle
708
* \param rate The sample rate value (in Hertz).
709
* \param channels A combination of MPG123_STEREO and MPG123_MONO.
710
* \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.
711
* \return MPG123_OK on success, MPG123_ERR if there was an error. */
712
MPG123_EXPORT int mpg123_format( mpg123_handle *mh
713
, long rate, int channels, int encodings );
714
715
/** Set the audio format support of a mpg123_handle in detail:
716
* \param mh handle
717
* \param rate The sample rate value (in Hertz). Special value 0 means
718
* all rates (the reason for this variant of mpg123_format()).
719
* \param channels A combination of MPG123_STEREO and MPG123_MONO.
720
* \param encodings A combination of accepted encodings for rate and channels,
721
* p.ex MPG123_ENC_SIGNED16 | MPG123_ENC_ULAW_8 (or 0 for no support).
722
* Please note that some encodings may not be supported in the library build
723
* and thus will be ignored here.
724
* \return MPG123_OK on success, MPG123_ERR if there was an error. */
725
MPG123_EXPORT int mpg123_format2( mpg123_handle *mh
726
, long rate, int channels, int encodings );
727
728
/** Check to see if a specific format at a specific rate is supported
729
* by mpg123_handle.
730
* \param mh handle
731
* \param rate sampling rate
732
* \param encoding encoding
733
* \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
734
* MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
735
MPG123_EXPORT int mpg123_format_support( mpg123_handle *mh
736
, long rate, int encoding );
737
738
/** Get the current output format written to the addresses given.
739
* If the stream is freshly loaded, this will try to parse enough
740
* of it to give you the format to come. This clears the flag that
741
* would otherwise make the first decoding call return
742
* MPG123_NEW_FORMAT.
743
* \param mh handle
744
* \param rate sampling rate return address
745
* \param channels channel count return address
746
* \param encoding encoding return address
747
* \return MPG123_OK on success
748
*/
749
MPG123_EXPORT int mpg123_getformat( mpg123_handle *mh
750
, long *rate, int *channels, int *encoding );
751
752
/** Get the current output format written to the addresses given.
753
* This differs from plain mpg123_getformat() in that you can choose
754
* _not_ to clear the flag that would trigger the next decoding call
755
* to return MPG123_NEW_FORMAT in case of a new format arriving.
756
* \param mh handle
757
* \param rate sampling rate return address
758
* \param channels channel count return address
759
* \param encoding encoding return address
760
* \param clear_flag if true, clear internal format flag
761
* \return MPG123_OK on success
762
*/
763
MPG123_EXPORT int mpg123_getformat2( mpg123_handle *mh
764
, long *rate, int *channels, int *encoding, int clear_flag );
765
766
/** @} */
767
768
769
/** \defgroup mpg123_input mpg123 file input and decoding
770
*
771
* Functions for input bitstream and decoding operations.
772
* 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!).
773
* @{
774
*/
775
776
#ifndef MPG123_PORTABLE_API
777
/** Open a simple MPEG file with fixed properties.
778
*
779
* This function shall simplify the common use case of a plain MPEG
780
* file on disk that you want to decode, with one fixed sample
781
* rate and channel count, and usually a length defined by a Lame/Info/Xing
782
* tag. It will:
783
*
784
* - set the MPG123_NO_FRANKENSTEIN flag
785
* - set up format support according to given parameters,
786
* - open the file,
787
* - query audio format,
788
* - fix the audio format support table to ensure the format stays the same,
789
* - call mpg123_scan() if there is no header frame to tell the track length.
790
*
791
* From that on, you can call mpg123_getformat() for querying the sample
792
* rate (and channel count in case you allowed both) and mpg123_length()
793
* to get a pretty safe number for the duration.
794
* Only the sample rate is left open as that indeed is a fixed property of
795
* MPEG files. You could set MPG123_FORCE_RATE beforehand, but that may trigger
796
* low-quality resampling in the decoder, only do so if in dire need.
797
* The library will convert mono files to stereo for you, and vice versa.
798
* If any constraint cannot be satisified (most likely because of a non-default
799
* build of libmpg123), you get MPG123_ERR returned and can query the detailed
800
* cause from the handle. Only on MPG123_OK there will an open file that you
801
* then close using mpg123_close(), or implicitly on mpg123_delete() or the next
802
* call to open another file.
803
*
804
* So, for your usual CD rip collection, you could use
805
*
806
* mpg123_open_fixed(mh, path, MPG123_STEREO, MPG123_ENC_SIGNED_16)
807
*
808
* and be happy calling mpg123_getformat() to verify 44100 Hz rate, then just
809
* playing away with mpg123_read(). The occasional mono file, or MP2 file,
810
* will also be decoded without you really noticing. Just the speed could be
811
* wrong if you do not care about sample rate at all.
812
* \param mh handle
813
* \param path filesystem path (see mpg123_open())
814
* \param channels allowed channel count, either 1 (MPG123_MONO) or
815
* 2 (MPG123_STEREO), or bitwise or of them, but then you're halfway back to
816
* calling mpg123_format() again;-)
817
* \param encoding a definite encoding from enum mpg123_enc_enum
818
* or a bitmask like for mpg123_format(), defeating the purpose somewhat
819
*/
820
MPG123_EXPORT int mpg123_open_fixed(mpg123_handle *mh, const char *path
821
, int channels, int encoding);
822
823
/** Open and prepare to decode the specified file by filesystem path.
824
* This does not open HTTP urls; libmpg123 contains no networking code.
825
* If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().
826
*
827
* The path parameter usually is just a string that is handed to the underlying
828
* OS routine for opening, treated as a blob of binary data. On platforms
829
* where encoding needs to be involved, something like _wopen() is called
830
* underneath and the path argument to libmpg123 is assumed to be encoded in UTF-8.
831
* So, if you have to ask yourself which encoding is needed, the answer is
832
* UTF-8, which also fits any sane modern install of Unix-like systems.
833
*
834
* \param mh handle
835
* \param path filesystem path
836
* \return MPG123_OK on success
837
*/
838
MPG123_EXPORT int mpg123_open(mpg123_handle *mh, const char *path);
839
840
/** Use an already opened file descriptor as the bitstream input
841
* mpg123_close() will _not_ close the file descriptor.
842
* \param mh handle
843
* \param fd file descriptor
844
* \return MPG123_OK on success
845
*/
846
MPG123_EXPORT int mpg123_open_fd(mpg123_handle *mh, int fd);
847
848
/** Use an opaque handle as bitstream input. This works only with the
849
* replaced I/O from mpg123_replace_reader_handle() or mpg123_reader64()!
850
* mpg123_close() will call the cleanup callback for your non-NULL
851
* handle (if you gave one).
852
* Note that this used to be usable with MPG123_PORTABLE_API defined in
853
* mpg123 1.32.x and was in fact the only entry point for handle I/O.
854
* Since mpg123 1.33.0 and API version 49, there is
855
* mpg123_open_handle64() for the portable case and has to be used
856
* instead of this function here, even if it _would_ work just fine,
857
* the inclusion of a largefile-renamed symbol in the portable set was wrong.
858
*
859
* \param mh handle
860
* \param iohandle your handle
861
* \return MPG123_OK on success
862
*/
863
MPG123_EXPORT int mpg123_open_handle(mpg123_handle *mh, void *iohandle);
864
#endif
865
866
/** Open and prepare to decode the specified file by filesystem path.
867
* This works exactly like mpg123_open() in modern libmpg123, see there
868
* for more description. This name is not subject to largefile symbol renaming.
869
* You can also use it with MPG123_PORTABLE_API.
870
*
871
* \param mh handle
872
* \param path filesystem path of your resource
873
* \return MPG123_OK on success
874
*/
875
MPG123_EXPORT int mpg123_open64(mpg123_handle *mh, const char *path);
876
877
/** Open a simple MPEG file with fixed properties.
878
* This is the same as mpg123_open_fixed(), just with a stable
879
* symbol name for int64_t portable API.
880
*
881
* \param mh handle
882
* \param path filesystem path (see mpg123_open())
883
* \param channels allowed channel count, either 1 (MPG123_MONO) or
884
* 2 (MPG123_STEREO), or bitwise or of them, but then you're halfway back to
885
* calling mpg123_format() again;-)
886
* \param encoding a definite encoding from enum mpg123_enc_enum
887
* or a bitmask like for mpg123_format(), defeating the purpose somewhat
888
*/
889
MPG123_EXPORT int mpg123_open_fixed64(mpg123_handle *mh, const char *path
890
, int channels, int encoding);
891
892
/** Use an opaque handle as bitstream input. This works only with the
893
* replaced I/O from mpg123_reader64()!
894
* mpg123_close() will call the cleanup callback for your non-NULL
895
* handle (if you gave one).
896
* This is a simplified variant of mpg123_open_handle() that only
897
* supports the int64_t API, available with MPG123_PORTABLE_API.
898
*
899
* \param mh handle
900
* \param iohandle your handle
901
* \return MPG123_OK on success
902
*/
903
MPG123_EXPORT int mpg123_open_handle64(mpg123_handle *mh, void *iohandle);
904
905
/** Open a new bitstream and prepare for direct feeding
906
* This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.
907
* Also, you are expected to handle ICY metadata extraction yourself. This
908
* input method does not handle MPG123_ICY_INTERVAL. It does parse ID3 frames, though.
909
* \param mh handle
910
* \return MPG123_OK on success
911
*/
912
MPG123_EXPORT int mpg123_open_feed(mpg123_handle *mh);
913
914
/** Closes the source, if libmpg123 opened it.
915
* \param mh handle
916
* \return MPG123_OK on success
917
*/
918
MPG123_EXPORT int mpg123_close(mpg123_handle *mh);
919
920
/** Read from stream and decode up to outmemsize bytes.
921
*
922
* Note: The type of outmemory changed to a void pointer in mpg123 1.26.0
923
* (API version 45).
924
*
925
* \param mh handle
926
* \param outmemory address of output buffer to write to
927
* \param outmemsize maximum number of bytes to write
928
* \param done address to store the number of actually decoded bytes to
929
* \return MPG123_OK or error/message code
930
*/
931
MPG123_EXPORT int mpg123_read(mpg123_handle *mh
932
, void *outmemory, size_t outmemsize, size_t *done );
933
934
/** Feed data for a stream that has been opened with mpg123_open_feed().
935
* It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.
936
* \param mh handle
937
* \param in input buffer
938
* \param size number of input bytes
939
* \return MPG123_OK or error/message code.
940
*/
941
MPG123_EXPORT int mpg123_feed( mpg123_handle *mh
942
, const unsigned char *in, size_t size );
943
944
/** Decode MPEG Audio from inmemory to outmemory.
945
* This is very close to a drop-in replacement for old mpglib.
946
* When you give zero-sized output buffer the input will be parsed until
947
* decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it)
948
* without taking decoded data.
949
* Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-).
950
* You can actually always decide if you want those specialized functions in separate steps or one call this one here.
951
*
952
* Note: The type of outmemory changed to a void pointer in mpg123 1.26.0
953
* (API version 45).
954
*
955
* \param mh handle
956
* \param inmemory input buffer
957
* \param inmemsize number of input bytes
958
* \param outmemory output buffer
959
* \param outmemsize maximum number of output bytes
960
* \param done address to store the number of actually decoded bytes to
961
* \return error/message code (watch out especially for MPG123_NEED_MORE)
962
*/
963
MPG123_EXPORT int mpg123_decode( mpg123_handle *mh
964
, const unsigned char *inmemory, size_t inmemsize
965
, void *outmemory, size_t outmemsize, size_t *done );
966
967
#ifndef MPG123_PORTABLE_API
968
/** Decode next MPEG frame to internal buffer
969
* or read a frame and return after setting a new format.
970
* \param mh handle
971
* \param num current frame offset gets stored there
972
* \param audio This pointer is set to the internal buffer to read the decoded audio from.
973
* \param bytes number of output bytes ready in the buffer
974
* \return MPG123_OK or error/message code
975
*/
976
MPG123_EXPORT int mpg123_decode_frame( mpg123_handle *mh
977
, off_t *num, unsigned char **audio, size_t *bytes );
978
979
/** Decode current MPEG frame to internal buffer.
980
* Warning: This is experimental API that might change in future releases!
981
* Please watch mpg123 development closely when using it.
982
* \param mh handle
983
* \param num last frame offset gets stored there
984
* \param audio this pointer is set to the internal buffer to read the decoded audio from.
985
* \param bytes number of output bytes ready in the buffer
986
* \return MPG123_OK or error/message code
987
*/
988
MPG123_EXPORT int mpg123_framebyframe_decode( mpg123_handle *mh
989
, off_t *num, unsigned char **audio, size_t *bytes );
990
#endif /* un-portable API */
991
992
/** Decode next MPEG frame to internal buffer
993
* or read a frame and return after setting a new format.
994
* \param mh handle
995
* \param num current frame offset gets stored there
996
* \param audio This pointer is set to the internal buffer to read the decoded audio from.
997
* \param bytes number of output bytes ready in the buffer
998
* \return MPG123_OK or error/message code
999
*/
1000
MPG123_EXPORT int mpg123_decode_frame64( mpg123_handle *mh
1001
, int64_t *num, unsigned char **audio, size_t *bytes );
1002
1003
/** Decode current MPEG frame to internal buffer.
1004
* Warning: This is experimental API that might change in future releases!
1005
* Please watch mpg123 development closely when using it.
1006
* \param mh handle
1007
* \param num last frame offset gets stored there
1008
* \param audio this pointer is set to the internal buffer to read the decoded audio from.
1009
* \param bytes number of output bytes ready in the buffer
1010
* \return MPG123_OK or error/message code
1011
*/
1012
MPG123_EXPORT int mpg123_framebyframe_decode64( mpg123_handle *mh
1013
, int64_t *num, unsigned char **audio, size_t *bytes );
1014
1015
/** Find, read and parse the next mp3 frame
1016
* Warning: This is experimental API that might change in future releases!
1017
* Please watch mpg123 development closely when using it.
1018
* \param mh handle
1019
* \return MPG123_OK or error/message code
1020
*/
1021
MPG123_EXPORT int mpg123_framebyframe_next(mpg123_handle *mh);
1022
1023
/** Get access to the raw input data for the last parsed frame.
1024
* This gives you a direct look (and write access) to the frame body data.
1025
* 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()).
1026
* 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.
1027
* You can provide NULL for a parameter pointer when you are not interested in the value.
1028
*
1029
* \param mh handle
1030
* \param header the 4-byte MPEG header
1031
* \param bodydata pointer to the frame body stored in the handle (without the header)
1032
* \param bodybytes size of frame body in bytes (without the header)
1033
* \return MPG123_OK if there was a yet un-decoded frame to get the
1034
* data from, MPG123_BAD_HANDLE or MPG123_ERR otherwise (without further
1035
* explanation, the error state of the mpg123_handle is not modified by
1036
* this function).
1037
*/
1038
MPG123_EXPORT int mpg123_framedata( mpg123_handle *mh
1039
, unsigned long *header, unsigned char **bodydata, size_t *bodybytes );
1040
1041
#ifndef MPG123_PORTABLE_API
1042
/** Get the input position (byte offset in stream) of the last parsed frame.
1043
* This can be used for external seek index building, for example.
1044
* It just returns the internally stored offset, regardless of validity --
1045
* you ensure that a valid frame has been parsed before!
1046
* \param mh handle
1047
* \return byte offset in stream
1048
*/
1049
MPG123_EXPORT off_t mpg123_framepos(mpg123_handle *mh);
1050
#endif
1051
1052
/** Get the 64 bit input position (byte offset in stream) of the last parsed frame.
1053
* This can be used for external seek index building, for example.
1054
* It just returns the internally stored offset, regardless of validity --
1055
* you ensure that a valid frame has been parsed before!
1056
* \param mh handle
1057
* \return byte offset in stream
1058
*/
1059
MPG123_EXPORT int64_t mpg123_framepos64(mpg123_handle *mh);
1060
1061
/** @} */
1062
1063
1064
/** \defgroup mpg123_seek mpg123 position and seeking
1065
*
1066
* Functions querying and manipulating position in the decoded audio bitstream.
1067
* The position is measured in decoded audio samples or MPEG frame offset for
1068
* the specific functions. The term sample refers to a group of samples for
1069
* multiple channels, normally dubbed PCM frames. The latter term is
1070
* avoided here because frame means something different in the context of MPEG
1071
* audio. Since all samples of a PCM frame occur at the same time, there is only
1072
* very limited ambiguity when talking about playback offset, as counting each
1073
* channel sample individually does not make sense.
1074
*
1075
* If gapless code is in effect, the positions are adjusted to compensate the
1076
* skipped padding/delay - meaning, you should not care about that at all and
1077
* just use the position defined for the samples you get out of the decoder;-)
1078
* The general usage is modelled after stdlib's ftell() and fseek().
1079
* Especially, the whence parameter for the seek functions has the same meaning
1080
* as the one for fseek() and needs the same constants from stdlib.h:
1081
*
1082
* - SEEK_SET: set position to (or near to) specified offset
1083
* - SEEK_CUR: change position by offset from now
1084
* - SEEK_END: set position to offset from end
1085
*
1086
* Since API version 48 (mpg123 1.32), the offset given with SEEK_END is always
1087
* taken to be negative in the terms of standard lseek(). You can only seek from
1088
* the end towards the beginning. All earlier versions had the sign wrong, positive
1089
* was towards the beginning, negative past the end (which results in error,
1090
* anyway).
1091
*
1092
* Note that sample-accurate seek only works when gapless support has been
1093
* enabled at compile time; seek is frame-accurate otherwise.
1094
* Also, really sample-accurate seeking (meaning that you get the identical
1095
* sample value after seeking compared to plain decoding up to the position)
1096
* is only guaranteed when you do not mess with the position code by using
1097
* #MPG123_UPSPEED, #MPG123_DOWNSPEED or #MPG123_START_FRAME. The first two mainly
1098
* should cause trouble with NtoM resampling, but in any case with these options
1099
* in effect, you have to keep in mind that the sample offset is not the same
1100
* as counting the samples you get from decoding since mpg123 counts the skipped
1101
* samples, too (or the samples played twice only once)!
1102
*
1103
* Short: When you care about the sample position, don't mess with those
1104
* parameters;-)
1105
*
1106
* Streams may be openend in ways that do not support seeking. Also, consider
1107
* the effect of #MPG123_FUZZY.
1108
*
1109
* @{
1110
*/
1111
1112
#ifndef MPG123_PORTABLE_API
1113
/** Returns the current position in samples.
1114
* On the next successful read, you'd get audio data with that offset.
1115
* \param mh handle
1116
* \return sample (PCM frame) offset or MPG123_ERR (null handle)
1117
*/
1118
MPG123_EXPORT off_t mpg123_tell(mpg123_handle *mh);
1119
#endif
1120
1121
/** Returns the current 64 bit position in samples.
1122
* On the next successful read, you'd get audio data with that offset.
1123
* \param mh handle
1124
* \return sample (PCM frame) offset or MPG123_ERR (null handle)
1125
*/
1126
MPG123_EXPORT int64_t mpg123_tell64(mpg123_handle *mh);
1127
1128
#ifndef MPG123_PORTABLE_API
1129
/** Returns the frame number that the next read will give you data from.
1130
* \param mh handle
1131
* \return frame offset or MPG123_ERR (null handle)
1132
*/
1133
MPG123_EXPORT off_t mpg123_tellframe(mpg123_handle *mh);
1134
#endif
1135
1136
/** Returns the 64 bit frame number that the next read will give you data from.
1137
* \param mh handle
1138
* \return frame offset or MPG123_ERR (null handle)
1139
*/
1140
MPG123_EXPORT int64_t mpg123_tellframe64(mpg123_handle *mh);
1141
1142
#ifndef MPG123_PORTABLE_API
1143
/** Returns the current byte offset in the input stream.
1144
* \param mh handle
1145
* \return byte offset or MPG123_ERR (null handle)
1146
*/
1147
MPG123_EXPORT off_t mpg123_tell_stream(mpg123_handle *mh);
1148
#endif
1149
1150
/** Returns the current 64 bit byte offset in the input stream.
1151
* \param mh handle
1152
* \return byte offset or MPG123_ERR (null handle)
1153
*/
1154
MPG123_EXPORT int64_t mpg123_tell_stream64(mpg123_handle *mh);
1155
1156
1157
#ifndef MPG123_PORTABLE_API
1158
/** Seek to a desired sample offset.
1159
* Usage is modelled afer the standard lseek().
1160
* \param mh handle
1161
* \param sampleoff offset in samples (PCM frames)
1162
* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
1163
* (Offset for SEEK_END is always effectively negative since API
1164
* version 48, was inverted from lseek() usage since ever before.)
1165
* \return The resulting offset >= 0 or error/message code
1166
*/
1167
MPG123_EXPORT off_t mpg123_seek( mpg123_handle *mh
1168
, off_t sampleoff, int whence );
1169
#endif
1170
1171
/** Seek to a desired 64 bit sample offset.
1172
* Usage is modelled afer the standard lseek().
1173
* \param mh handle
1174
* \param sampleoff offset in samples (PCM frames)
1175
* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
1176
* (Offset for SEEK_END is always effectively negative.)
1177
* \return The resulting offset >= 0 or error/message code
1178
*/
1179
MPG123_EXPORT int64_t mpg123_seek64( mpg123_handle *mh
1180
, int64_t sampleoff, int whence );
1181
1182
#ifndef MPG123_PORTABLE_API
1183
/** Seek to a desired sample offset in data feeding mode.
1184
* This just prepares things to be right only if you ensure that the next chunk
1185
* of input data will be from input_offset byte position.
1186
* \param mh handle
1187
* \param sampleoff offset in samples (PCM frames)
1188
* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
1189
* (Offset for SEEK_END is always effectively negative since API
1190
* version 48, was inverted from lseek() usage since ever before.)
1191
* \param input_offset The position it expects to be at the
1192
* next time data is fed to mpg123_decode().
1193
* \return The resulting offset >= 0 or error/message code
1194
*/
1195
MPG123_EXPORT off_t mpg123_feedseek( mpg123_handle *mh
1196
, off_t sampleoff, int whence, off_t *input_offset );
1197
#endif
1198
1199
/** Seek to a desired 64 bit sample offset in data feeding mode.
1200
* This just prepares things to be right only if you ensure that the next chunk
1201
* of input data will be from input_offset byte position.
1202
* \param mh handle
1203
* \param sampleoff offset in samples (PCM frames)
1204
* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
1205
* (Offset for SEEK_END is always effectively negative.)
1206
* \param input_offset The position it expects to be at the
1207
* next time data is fed to mpg123_decode().
1208
* \return The resulting offset >= 0 or error/message code
1209
*/
1210
MPG123_EXPORT int64_t mpg123_feedseek64( mpg123_handle *mh
1211
, int64_t sampleoff, int whence, int64_t *input_offset );
1212
1213
#ifndef MPG123_PORTABLE_API
1214
/** Seek to a desired MPEG frame offset.
1215
* Usage is modelled afer the standard lseek().
1216
* \param mh handle
1217
* \param frameoff offset in MPEG frames
1218
* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
1219
* (Offset for SEEK_END is always effectively negative since API
1220
* version 48, was inverted from lseek() usage since ever before.)
1221
* \return The resulting offset >= 0 or error/message code */
1222
MPG123_EXPORT off_t mpg123_seek_frame( mpg123_handle *mh
1223
, off_t frameoff, int whence );
1224
#endif
1225
1226
/** Seek to a desired 64 bit MPEG frame offset.
1227
* Usage is modelled afer the standard lseek().
1228
* \param mh handle
1229
* \param frameoff offset in MPEG frames
1230
* \param whence one of SEEK_SET, SEEK_CUR or SEEK_END
1231
* (Offset for SEEK_END is always effectively negative.)
1232
* \return The resulting offset >= 0 or error/message code */
1233
MPG123_EXPORT int64_t mpg123_seek_frame64( mpg123_handle *mh
1234
, int64_t frameoff, int whence );
1235
1236
#ifndef MPG123_PORTABLE_API
1237
/** Return a MPEG frame offset corresponding to an offset in seconds.
1238
* 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.
1239
* \return frame offset >= 0 or error/message code */
1240
MPG123_EXPORT off_t mpg123_timeframe(mpg123_handle *mh, double sec);
1241
1242
/** Give access to the frame index table that is managed for seeking.
1243
* You are asked not to modify the values... Use mpg123_set_index to set the
1244
* seek index.
1245
* Note: This can be just a copy of the data in case a conversion is done
1246
* from the internal 64 bit values.
1247
* \param mh handle
1248
* \param offsets pointer to the index array
1249
* \param step one index byte offset advances this many MPEG frames
1250
* \param fill number of recorded index offsets; size of the array
1251
* \return MPG123_OK on success
1252
*/
1253
MPG123_EXPORT int mpg123_index( mpg123_handle *mh
1254
, off_t **offsets, off_t *step, size_t *fill );
1255
#endif
1256
1257
/** Return a 64 bit MPEG frame offset corresponding to an offset in seconds.
1258
* 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.
1259
* \return frame offset >= 0 or error/message code */
1260
MPG123_EXPORT int64_t mpg123_timeframe64(mpg123_handle *mh, double sec);
1261
1262
/** Give access to the 64 bit frame index table that is managed for seeking.
1263
* You are asked not to modify the values... Use mpg123_set_index to set the
1264
* seek index.
1265
* \param mh handle
1266
* \param offsets pointer to the index array
1267
* \param step one index byte offset advances this many MPEG frames
1268
* \param fill number of recorded index offsets; size of the array
1269
* \return MPG123_OK on success
1270
*/
1271
MPG123_EXPORT int mpg123_index64( mpg123_handle *mh
1272
, int64_t **offsets, int64_t *step, size_t *fill );
1273
1274
#ifndef MPG123_PORTABLE_API
1275
/** Set the frame index table
1276
* Setting offsets to NULL and fill > 0 will allocate fill entries. Setting offsets
1277
* to NULL and fill to 0 will clear the index and free the allocated memory used by the index.
1278
* Note that this function might involve conversion/copying of data because of
1279
* the varying nature of off_t. Better use mpg123_set_index64().
1280
* \param mh handle
1281
* \param offsets pointer to the index array
1282
* \param step one index byte offset advances this many MPEG frames
1283
* \param fill number of recorded index offsets; size of the array
1284
* \return MPG123_OK on success
1285
*/
1286
MPG123_EXPORT int mpg123_set_index( mpg123_handle *mh
1287
, off_t *offsets, off_t step, size_t fill );
1288
#endif
1289
1290
/** Set the 64 bit frame index table
1291
* Setting offsets to NULL and fill > 0 will allocate fill entries. Setting offsets
1292
* to NULL and fill to 0 will clear the index and free the allocated memory used by the index.
1293
* \param mh handle
1294
* \param offsets pointer to the index array
1295
* \param step one index byte offset advances this many MPEG frames
1296
* \param fill number of recorded index offsets; size of the array
1297
* \return MPG123_OK on success
1298
*/
1299
MPG123_EXPORT int mpg123_set_index64( mpg123_handle *mh
1300
, int64_t *offsets, int64_t step, size_t fill );
1301
1302
1303
#ifndef MPG123_PORTABLE_API
1304
/** An old crutch to keep old mpg123 binaries happy.
1305
* WARNING: This function is there only to avoid runtime linking errors with
1306
* standalone mpg123 before version 1.32.0 (if you strangely update the
1307
* library but not the end-user program) and actually is broken
1308
* for various cases (p.ex. 24 bit output). Do never use. It might eventually
1309
* be purged from the library.
1310
*/
1311
MPG123_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);
1312
#endif
1313
1314
/** @} */
1315
1316
1317
/** \defgroup mpg123_voleq mpg123 volume and equalizer
1318
*
1319
* @{
1320
*/
1321
1322
/** another channel enumeration, for left/right choice */
1323
enum mpg123_channels
1324
{
1325
MPG123_LEFT=0x1 /**< The Left Channel. */
1326
,MPG123_RIGHT=0x2 /**< The Right Channel. */
1327
,MPG123_LR=0x3 /**< Both left and right channel; same as MPG123_LEFT|MPG123_RIGHT */
1328
};
1329
1330
#ifdef MPG123_ENUM_API
1331
/** Set the 32 Band Audio Equalizer settings.
1332
*
1333
* Note that this name is mapped to mpg123_eq2() instead unless
1334
* MPG123_ENUM_API is defined.
1335
*
1336
* \param mh handle
1337
* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or
1338
* #MPG123_LEFT|#MPG123_RIGHT for both.
1339
* \param band The equaliser band to change (from 0 to 31)
1340
* \param val The (linear) adjustment factor.
1341
* \return MPG123_OK on success
1342
*/
1343
MPG123_EXPORT int mpg123_eq( mpg123_handle *mh
1344
, enum mpg123_channels channel, int band, double val );
1345
#endif
1346
1347
/** Set the 32 Band Audio Equalizer settings. No enums.
1348
*
1349
* This is actually called instead of mpg123_eq() unless MPG123_ENUM_API
1350
* is defined.
1351
*
1352
* \param mh handle
1353
* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or
1354
* #MPG123_LEFT|#MPG123_RIGHT for both.
1355
* \param band The equaliser band to change (from 0 to 31)
1356
* \param val The (linear) adjustment factor.
1357
* \return MPG123_OK on success
1358
*/
1359
MPG123_EXPORT int mpg123_eq2( mpg123_handle *mh
1360
, int channel, int band, double val );
1361
1362
/** Set a range of equalizer bands
1363
* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or
1364
* #MPG123_LEFT|#MPG123_RIGHT for both.
1365
* \param mh handle
1366
* \param a The first equalizer band to set (from 0 to 31)
1367
* \param b The last equalizer band to set (from 0 to 31)
1368
* \param factor The (linear) adjustment factor, 1 being neutral.
1369
* \return MPG123_OK on success
1370
*/
1371
MPG123_EXPORT int mpg123_eq_bands( mpg123_handle *mh
1372
, int channel, int a, int b, double factor );
1373
1374
/** Change a range of equalizer bands
1375
* \param mh handle
1376
* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or
1377
* #MPG123_LEFT|#MPG123_RIGHT for both.
1378
* \param a The first equalizer band to change (from 0 to 31)
1379
* \param b The last equalizer band to change (from 0 to 31)
1380
* \param db The adjustment in dB (limited to +/- 60 dB).
1381
* \return MPG123_OK on success
1382
*/
1383
MPG123_EXPORT int mpg123_eq_change( mpg123_handle *mh
1384
, int channel, int a, int b, double db );
1385
1386
#ifdef MPG123_ENUM_API
1387
/** Get the 32 Band Audio Equalizer settings.
1388
*
1389
* Note that this name is mapped to mpg123_geteq2() instead unless
1390
* MPG123_ENUM_API is defined.
1391
*
1392
* \param mh handle
1393
* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or
1394
* #MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.
1395
* \param band The equaliser band to change (from 0 to 31)
1396
* \return The (linear) adjustment factor (zero for pad parameters) */
1397
MPG123_EXPORT double mpg123_geteq(mpg123_handle *mh
1398
, enum mpg123_channels channel, int band);
1399
#endif
1400
1401
/** Get the 32 Band Audio Equalizer settings.
1402
*
1403
* This is actually called instead of mpg123_geteq() unless MPG123_ENUM_API
1404
* is defined.
1405
*
1406
* \param mh handle
1407
* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or
1408
* #MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.
1409
* \param band The equaliser band to change (from 0 to 31)
1410
* \return The (linear) adjustment factor (zero for pad parameters) */
1411
MPG123_EXPORT double mpg123_geteq2(mpg123_handle *mh, int channel, int band);
1412
1413
/** Reset the 32 Band Audio Equalizer settings to flat
1414
* \param mh handle
1415
* \return MPG123_OK on success
1416
*/
1417
MPG123_EXPORT int mpg123_reset_eq(mpg123_handle *mh);
1418
1419
/** Set the absolute output volume including the RVA setting,
1420
* vol<0 just applies (a possibly changed) RVA setting.
1421
* \param mh handle
1422
* \param vol volume value (linear factor)
1423
* \return MPG123_OK on success
1424
*/
1425
MPG123_EXPORT int mpg123_volume(mpg123_handle *mh, double vol);
1426
1427
/** Adjust output volume including the RVA setting by chosen amount
1428
* \param mh handle
1429
* \param change volume value (linear factor increment)
1430
* \return MPG123_OK on success
1431
*/
1432
MPG123_EXPORT int mpg123_volume_change(mpg123_handle *mh, double change);
1433
1434
/** Adjust output volume including the RVA setting by chosen amount
1435
* \param mh handle
1436
* \param db volume adjustment in decibels (limited to +/- 60 dB)
1437
* \return MPG123_OK on success
1438
*/
1439
MPG123_EXPORT int mpg123_volume_change_db(mpg123_handle *mh, double db);
1440
1441
/** Return current volume setting, the actual value due to RVA, and the RVA
1442
* adjustment itself. It's all as double float value to abstract the sample
1443
* format. The volume values are linear factors / amplitudes (not percent)
1444
* and the RVA value is in decibels.
1445
* \param mh handle
1446
* \param base return address for base volume (linear factor)
1447
* \param really return address for actual volume (linear factor)
1448
* \param rva_db return address for RVA value (decibels)
1449
* \return MPG123_OK on success
1450
*/
1451
MPG123_EXPORT int mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db);
1452
1453
/* TODO: Set some preamp in addition / to replace internal RVA handling? */
1454
1455
/** @} */
1456
1457
1458
/** \defgroup mpg123_status mpg123 status and information
1459
*
1460
* @{
1461
*/
1462
1463
/** Enumeration of the mode types of Variable Bitrate */
1464
enum mpg123_vbr {
1465
MPG123_CBR=0, /**< Constant Bitrate Mode (default) */
1466
MPG123_VBR, /**< Variable Bitrate Mode */
1467
MPG123_ABR /**< Average Bitrate Mode */
1468
};
1469
1470
/** Enumeration of the MPEG Versions */
1471
enum mpg123_version {
1472
MPG123_1_0=0, /**< MPEG Version 1.0 */
1473
MPG123_2_0, /**< MPEG Version 2.0 */
1474
MPG123_2_5 /**< MPEG Version 2.5 */
1475
};
1476
1477
1478
/** Enumeration of the MPEG Audio mode.
1479
* Only the mono mode has 1 channel, the others have 2 channels. */
1480
enum mpg123_mode {
1481
MPG123_M_STEREO=0, /**< Standard Stereo. */
1482
MPG123_M_JOINT, /**< Joint Stereo. */
1483
MPG123_M_DUAL, /**< Dual Channel. */
1484
MPG123_M_MONO /**< Single Channel. */
1485
};
1486
1487
1488
/** Enumeration of the MPEG Audio flag bits */
1489
enum mpg123_flags {
1490
MPG123_CRC=0x1, /**< The bitstream is error protected using 16-bit CRC. */
1491
MPG123_COPYRIGHT=0x2, /**< The bitstream is copyrighted. */
1492
MPG123_PRIVATE=0x4, /**< The private bit has been set. */
1493
MPG123_ORIGINAL=0x8 /**< The bitstream is an original, not a copy. */
1494
};
1495
1496
#ifdef MPG123_ENUM_API
1497
/** Data structure for storing information about a frame of MPEG Audio */
1498
struct mpg123_frameinfo
1499
{
1500
enum mpg123_version version; /**< The MPEG version (1.0/2.0/2.5). */
1501
int layer; /**< The MPEG Audio Layer (MP1/MP2/MP3). */
1502
long rate; /**< The sampling rate in Hz. */
1503
enum mpg123_mode mode; /**< The audio mode (Mono, Stereo, Joint-stero, Dual Channel). */
1504
int mode_ext; /**< The mode extension bit flag. */
1505
int framesize; /**< The size of the frame (in bytes, including header). */
1506
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. */
1507
int emphasis; /**< The emphasis type. */
1508
int bitrate; /**< Bitrate of the frame (kbps). */
1509
int abr_rate; /**< The target average bitrate. */
1510
enum mpg123_vbr vbr; /**< The VBR mode. */
1511
};
1512
#endif
1513
1514
/** Data structure for storing information about a frame of MPEG Audio without enums */
1515
struct mpg123_frameinfo2
1516
{
1517
int version; /**< The MPEG version (1.0/2.0/2.5), enum mpg123_version. */
1518
int layer; /**< The MPEG Audio Layer (MP1/MP2/MP3). */
1519
long rate; /**< The sampling rate in Hz. */
1520
int mode; /**< The audio mode (enum mpg123_mode, Mono, Stereo, Joint-stero, Dual Channel). */
1521
int mode_ext; /**< The mode extension bit flag. */
1522
int framesize; /**< The size of the frame (in bytes, including header). */
1523
int flags; /**< MPEG Audio flag bits. Bitwise combination of enum mpg123_flags values. */
1524
int emphasis; /**< The emphasis type. */
1525
int bitrate; /**< Bitrate of the frame (kbps). */
1526
int abr_rate; /**< The target average bitrate. */
1527
int vbr; /**< The VBR mode, enum mpg123_vbr. */
1528
};
1529
1530
/** Data structure for even more detailed information out of the decoder,
1531
* for MPEG layer III only.
1532
* This was added to support the frame analyzer by the Lame project and
1533
* just follows what was used there before. You know what the fields mean
1534
* if you want use this structure. */
1535
struct mpg123_moreinfo
1536
{
1537
double xr[2][2][576]; /**< internal data */
1538
double sfb[2][2][22]; /**< [2][2][SBMAX_l] */
1539
double sfb_s[2][2][3*13]; /**< [2][2][3*SBMAX_s] */
1540
int qss[2][2]; /**< internal data */
1541
int big_values[2][2]; /**< internal data */
1542
int sub_gain[2][2][3]; /**< internal data */
1543
int scalefac_scale[2][2]; /**< internal data */
1544
int preflag[2][2]; /**< internal data */
1545
int blocktype[2][2]; /**< internal data */
1546
int mixed[2][2]; /**< internal data */
1547
int mainbits[2][2]; /**< internal data */
1548
int sfbits[2][2]; /**< internal data */
1549
int scfsi[2]; /**< internal data */
1550
int maindata; /**< internal data */
1551
int padding; /**< internal data */
1552
};
1553
1554
#ifdef MPG123_ENUM_API
1555
/** Get frame information about the MPEG audio bitstream and store
1556
* it in a mpg123_frameinfo structure.
1557
*
1558
* Note that this name is mapped to mpg123_info2() instead unless
1559
* MPG123_ENUM_API is defined.
1560
*
1561
* \param mh handle
1562
* \param mi address of existing frameinfo structure to write to
1563
* \return MPG123_OK on success
1564
*/
1565
MPG123_EXPORT int mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi);
1566
#endif
1567
1568
/** Get frame information about the MPEG audio bitstream and store
1569
* it in a mpg123_frameinfo2 structure.
1570
*
1571
* This is actually called instead of mpg123_info()
1572
* unless MPG123_ENUM_API is defined.
1573
*
1574
* \param mh handle
1575
* \param mi address of existing frameinfo structure to write to
1576
* \return MPG123_OK on success
1577
*/
1578
MPG123_EXPORT int mpg123_info2(mpg123_handle *mh, struct mpg123_frameinfo2 *mi);
1579
1580
/** Trigger collection of additional decoder information while decoding.
1581
* \param mh handle
1582
* \param mi pointer to data storage (NULL to disable collection)
1583
* \return MPG123_OK if the collection was enabled/disabled as desired, MPG123_ERR
1584
* otherwise (e.g. if the feature is disabled)
1585
*/
1586
MPG123_EXPORT int mpg123_set_moreinfo( mpg123_handle *mh
1587
, struct mpg123_moreinfo *mi );
1588
1589
/** Get the safe output buffer size for all cases
1590
* (when you want to replace the internal buffer)
1591
* \return safe buffer size
1592
*/
1593
MPG123_EXPORT size_t mpg123_safe_buffer(void);
1594
1595
/** Make a full parsing scan of each frame in the file. ID3 tags are found. An
1596
* accurate length value is stored. Seek index will be filled. A seek back to
1597
* current position is performed. At all, this function refuses work when
1598
* stream is not seekable.
1599
* \param mh handle
1600
* \return MPG123_OK on success
1601
*/
1602
MPG123_EXPORT int mpg123_scan(mpg123_handle *mh);
1603
1604
#ifndef MPG123_PORTABLE_API
1605
/** Return, if possible, the full (expected) length of current track in
1606
* MPEG frames.
1607
* \param mh handle
1608
* \return length >= 0 or MPG123_ERR if there is no length guess possible.
1609
*/
1610
MPG123_EXPORT off_t mpg123_framelength(mpg123_handle *mh);
1611
1612
/** Return, if possible, the full (expected) length of current
1613
* track in samples (PCM frames).
1614
*
1615
* This relies either on an Info frame at the beginning or a previous
1616
* call to mpg123_scan() to get the real number of MPEG frames in a
1617
* file. It will guess based on file size if neither Info frame nor
1618
* scan data are present. In any case, there is no guarantee that the
1619
* decoder will not give you more data, for example in case the open
1620
* file gets appended to during decoding.
1621
* \param mh handle
1622
* \return length >= 0 or MPG123_ERR if there is no length guess possible.
1623
*/
1624
MPG123_EXPORT off_t mpg123_length(mpg123_handle *mh);
1625
1626
/** Override the value for file size in bytes.
1627
* Useful for getting sensible track length values in feed mode or for HTTP streams.
1628
* \param mh handle
1629
* \param size file size in bytes
1630
* \return MPG123_OK on success
1631
*/
1632
MPG123_EXPORT int mpg123_set_filesize(mpg123_handle *mh, off_t size);
1633
#endif
1634
1635
/** Return, if possible, the full (expected) length of current track in
1636
* MPEG frames as 64 bit number.
1637
* \param mh handle
1638
* \return length >= 0 or MPG123_ERR if there is no length guess possible.
1639
*/
1640
MPG123_EXPORT int64_t mpg123_framelength64(mpg123_handle *mh);
1641
1642
/** Return, if possible, the full (expected) length of current
1643
* track in samples (PCM frames) as 64 bit value.
1644
*
1645
* This relies either on an Info frame at the beginning or a previous
1646
* call to mpg123_scan() to get the real number of MPEG frames in a
1647
* file. It will guess based on file size if neither Info frame nor
1648
* scan data are present. In any case, there is no guarantee that the
1649
* decoder will not give you more data, for example in case the open
1650
* file gets appended to during decoding.
1651
* \param mh handle
1652
* \return length >= 0 or MPG123_ERR if there is no length guess possible.
1653
*/
1654
MPG123_EXPORT int64_t mpg123_length64(mpg123_handle *mh);
1655
1656
/** Override the 64 bit value for file size in bytes.
1657
* Useful for getting sensible track length values in feed mode or for HTTP streams.
1658
* \param mh handle
1659
* \param size file size in bytes
1660
* \return MPG123_OK on success
1661
*/
1662
MPG123_EXPORT int mpg123_set_filesize64(mpg123_handle *mh, int64_t size);
1663
1664
/** Get MPEG frame duration in seconds.
1665
* \param mh handle
1666
* \return frame duration in seconds, <0 on error
1667
*/
1668
MPG123_EXPORT double mpg123_tpf(mpg123_handle *mh);
1669
1670
/** Get MPEG frame duration in samples.
1671
* \param mh handle
1672
* \return samples per frame for the most recently parsed frame; <0 on errors
1673
*/
1674
MPG123_EXPORT int mpg123_spf(mpg123_handle *mh);
1675
1676
/** Get and reset the clip count.
1677
* \param mh handle
1678
* \return count of clipped samples
1679
*/
1680
MPG123_EXPORT long mpg123_clip(mpg123_handle *mh);
1681
1682
1683
/** The key values for state information from mpg123_getstate(). */
1684
enum mpg123_state
1685
{
1686
MPG123_ACCURATE = 1 /**< Query if positons are currently accurate (integer value, 0 if false, 1 if true). */
1687
,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. */
1688
,MPG123_FRANKENSTEIN /**< Stream consists of carelessly stitched together files. Seeking may yield unexpected results (also with MPG123_ACCURATE, it may be confused). */
1689
,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. */
1690
,MPG123_ENC_DELAY /** Encoder delay read from Info tag (layer III, -1 if unknown). */
1691
,MPG123_ENC_PADDING /** Encoder padding read from Info tag (layer III, -1 if unknown). */
1692
,MPG123_DEC_DELAY /** Decoder delay (for layer III only, -1 otherwise). */
1693
};
1694
1695
#ifdef MPG123_ENUM_API
1696
/** Get various current decoder/stream state information.
1697
*
1698
* Note that this name is mapped to mpg123_getstate2() instead unless
1699
* MPG123_ENUM_API is defined.
1700
*
1701
* \param mh handle
1702
* \param key the key to identify the information to give.
1703
* \param val the address to return (long) integer values to
1704
* \param fval the address to return floating point values to
1705
* \return MPG123_OK on success
1706
*/
1707
MPG123_EXPORT int mpg123_getstate( mpg123_handle *mh
1708
, enum mpg123_state key, long *val, double *fval );
1709
#endif
1710
1711
/** Get various current decoder/stream state information. No enums.
1712
*
1713
* This is actually called instead of mpg123_getstate()
1714
* unless MPG123_ENUM_API is defined.
1715
*
1716
* \param mh handle
1717
* \param key the key to identify the information to give (enum mpg123_state)
1718
* \param val the address to return (long) integer values to
1719
* \param fval the address to return floating point values to
1720
* \return MPG123_OK on success
1721
*/
1722
MPG123_EXPORT int mpg123_getstate2( mpg123_handle *mh
1723
, int key, long *val, double *fval );
1724
1725
/** @} */
1726
1727
1728
/** \defgroup mpg123_metadata mpg123 metadata handling
1729
*
1730
* Functions to retrieve the metadata from MPEG Audio files and streams.
1731
* Also includes string handling functions.
1732
*
1733
* @{
1734
*/
1735
1736
/** Data structure for storing strings in a safer way than a standard C-String.
1737
* Can also hold a number of null-terminated strings. */
1738
typedef struct
1739
{
1740
char* p; /**< pointer to the string data */
1741
size_t size; /**< raw number of bytes allocated */
1742
size_t fill; /**< number of used bytes (including closing zero byte) */
1743
} mpg123_string;
1744
1745
/** Allocate and intialize a new string.
1746
* \param val optional initial string value (can be NULL)
1747
*/
1748
MPG123_EXPORT mpg123_string* mpg123_new_string(const char* val);
1749
1750
/** Free memory of contents and the string structure itself.
1751
* \param sb string handle
1752
*/
1753
MPG123_EXPORT void mpg123_delete_string(mpg123_string* sb);
1754
1755
/** Initialize an existing mpg123_string structure to {NULL, 0, 0}.
1756
* If you hand in a NULL pointer here, your program should crash. The other
1757
* string functions are more forgiving, but this one here is too basic.
1758
* \param sb string handle (address of existing structure on your side)
1759
*/
1760
MPG123_EXPORT void mpg123_init_string(mpg123_string* sb);
1761
1762
/** Free-up memory of the contents of an mpg123_string (not the struct itself).
1763
* This also calls mpg123_init_string() and hence is safe to be called
1764
* repeatedly.
1765
* \param sb string handle
1766
*/
1767
MPG123_EXPORT void mpg123_free_string(mpg123_string* sb);
1768
1769
/** Change the size of a mpg123_string
1770
* \param sb string handle
1771
* \param news new size in bytes
1772
* \return 0 on error, 1 on success
1773
*/
1774
MPG123_EXPORT int mpg123_resize_string(mpg123_string* sb, size_t news);
1775
1776
/** Increase size of a mpg123_string if necessary (it may stay larger).
1777
* Note that the functions for adding and setting in current libmpg123
1778
* use this instead of mpg123_resize_string().
1779
* That way, you can preallocate memory and safely work afterwards with
1780
* pieces.
1781
* \param sb string handle
1782
* \param news new minimum size
1783
* \return 0 on error, 1 on success
1784
*/
1785
MPG123_EXPORT int mpg123_grow_string(mpg123_string* sb, size_t news);
1786
1787
/** Copy the contents of one mpg123_string string to another.
1788
* Yes the order of arguments is reversed compated to memcpy().
1789
* \param from string handle
1790
* \param to string handle
1791
* \return 0 on error, 1 on success
1792
*/
1793
MPG123_EXPORT int mpg123_copy_string(mpg123_string* from, mpg123_string* to);
1794
1795
/** Move the contents of one mpg123_string string to another.
1796
* This frees any memory associated with the target and moves over the
1797
* pointers from the source, leaving the source without content after
1798
* that. The only possible error is that you hand in NULL pointers.
1799
* If you handed in a valid source, its contents will be gone, even if
1800
* there was no target to move to. If you hand in a valid target, its
1801
* original contents will also always be gone, to be replaced with the
1802
* source's contents if there was some.
1803
* \param from source string handle
1804
* \param to target string handle
1805
* \return 0 on error, 1 on success
1806
*/
1807
MPG123_EXPORT int mpg123_move_string(mpg123_string* from, mpg123_string* to);
1808
1809
/** Append a C-String to an mpg123_string
1810
* \param sb string handle
1811
* \param stuff to append
1812
* \return 0 on error, 1 on success
1813
*/
1814
MPG123_EXPORT int mpg123_add_string(mpg123_string* sb, const char* stuff);
1815
1816
/** Append a C-substring to an mpg123 string
1817
* \param sb string handle
1818
* \param stuff content to copy
1819
* \param from offset to copy from
1820
* \param count number of characters to copy (a null-byte is always appended)
1821
* \return 0 on error, 1 on success
1822
*/
1823
MPG123_EXPORT int mpg123_add_substring( mpg123_string *sb
1824
, const char *stuff, size_t from, size_t count );
1825
1826
/** Set the content of a mpg123_string to a C-string
1827
* \param sb string handle
1828
* \param stuff content to copy
1829
* \return 0 on error, 1 on success
1830
*/
1831
MPG123_EXPORT int mpg123_set_string(mpg123_string* sb, const char* stuff);
1832
1833
/** Set the content of a mpg123_string to a C-substring
1834
* \param sb string handle
1835
* \param stuff the future content
1836
* \param from offset to copy from
1837
* \param count number of characters to copy (a null-byte is always appended)
1838
* \return 0 on error, 1 on success
1839
*/
1840
MPG123_EXPORT int mpg123_set_substring( mpg123_string *sb
1841
, const char *stuff, size_t from, size_t count );
1842
1843
/** Count characters in a mpg123 string (non-null bytes or Unicode points).
1844
* This function is of limited use, as it does just count code points
1845
* encoded in an UTF-8 string, only loosely related to the count of visible
1846
* characters. Get your full Unicode handling support elsewhere.
1847
* \param sb string handle
1848
* \param utf8 a flag to tell if the string is in utf8 encoding
1849
* \return character count
1850
*/
1851
MPG123_EXPORT size_t mpg123_strlen(mpg123_string *sb, int utf8);
1852
1853
/** Remove trailing \\r and \\n, if present.
1854
* \param sb string handle
1855
* \return 0 on error, 1 on success
1856
*/
1857
MPG123_EXPORT int mpg123_chomp_string(mpg123_string *sb);
1858
1859
/** Determine if two strings contain the same data.
1860
* This only returns 1 if both given handles are non-NULL and
1861
* if they are filled with the same bytes.
1862
* \param a first string handle
1863
* \param b second string handle
1864
* \return 0 for different strings, 1 for identical
1865
*/
1866
MPG123_EXPORT int mpg123_same_string(mpg123_string *a, mpg123_string *b);
1867
1868
/** The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info. */
1869
enum mpg123_text_encoding
1870
{
1871
mpg123_text_unknown = 0 /**< Unkown encoding... mpg123_id3_encoding can return that on invalid codes. */
1872
,mpg123_text_utf8 = 1 /**< UTF-8 */
1873
,mpg123_text_latin1 = 2 /**< ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings. */
1874
,mpg123_text_icy = 3 /**< ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such. */
1875
,mpg123_text_cp1252 = 4 /**< Really CP-1252 without any guessing. */
1876
,mpg123_text_utf16 = 5 /**< Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.
1877
* When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when
1878
* you don't mess with the reserved code points. If you want to decode little endian data
1879
* without BOM you need to prepend 0xff 0xfe yourself. */
1880
,mpg123_text_utf16bom = 6 /**< Just an alias for UTF-16, ID3v2 has this as distinct code. */
1881
,mpg123_text_utf16be = 7 /**< Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,
1882
* BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123
1883
* One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16
1884
* types (we expect a BOM before real data there), not so for utf16be!*/
1885
,mpg123_text_max = 7 /**< Placeholder for the maximum encoding value. */
1886
};
1887
1888
/** The encoding byte values from ID3v2. */
1889
enum mpg123_id3_enc
1890
{
1891
mpg123_id3_latin1 = 0 /**< Note: This sometimes can mean anything in practice... */
1892
,mpg123_id3_utf16bom = 1 /**< UTF16, UCS-2 ... it's all the same for practical purposes. */
1893
,mpg123_id3_utf16be = 2 /**< Big-endian UTF-16, BOM see note for mpg123_text_utf16be. */
1894
,mpg123_id3_utf8 = 3 /**< Our lovely overly ASCII-compatible 8 byte encoding for the world. */
1895
,mpg123_id3_enc_max = 3 /**< Placeholder to check valid range of encoding byte. */
1896
};
1897
1898
#ifdef MPG123_ENUM_API
1899
/** Convert ID3 encoding byte to mpg123 encoding index.
1900
*
1901
* Note that this name is mapped to mpg123_enc_from_id3_2() instead unless
1902
* MPG123_ENUM_API is defined.
1903
*
1904
* \param id3_enc_byte the ID3 encoding code
1905
* \return the mpg123 encoding index
1906
*/
1907
MPG123_EXPORT enum mpg123_text_encoding mpg123_enc_from_id3(unsigned char id3_enc_byte);
1908
#endif
1909
1910
/** Convert ID3 encoding byte to mpg123 encoding index. No enums.
1911
*
1912
* This is actually called instead of mpg123_enc_from_id3()
1913
* unless MPG123_ENUM_API is defined.
1914
*
1915
* \param id3_enc_byte the ID3 encoding code
1916
* \return the mpg123 encoding index
1917
*/
1918
MPG123_EXPORT int mpg123_enc_from_id3_2(unsigned char id3_enc_byte);
1919
1920
#ifdef MPG123_ENUM_API
1921
/** Store text data in string, after converting to UTF-8 from indicated encoding.
1922
*
1923
* Note that this name is mapped to mpg123_store_utf8_2() instead unless
1924
* MPG123_ENUM_API is defined.
1925
*
1926
* 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).
1927
* Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).
1928
* \param sb target string
1929
* \param enc mpg123 text encoding value
1930
* \param source source buffer with plain unsigned bytes (you might need to cast from signed char)
1931
* \param source_size number of bytes in the source buffer
1932
* \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)
1933
*/
1934
MPG123_EXPORT int mpg123_store_utf8(mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size);
1935
#endif
1936
1937
/** Store text data in string, after converting to UTF-8 from indicated encoding. No enums.
1938
*
1939
* This is actually called instead of mpg123_store_utf8()
1940
* unless MPG123_ENUM_API is defined.
1941
*
1942
* 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).
1943
* Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).
1944
* \param sb target string
1945
* \param enc mpg123 text encoding value (enum mpg123_text_encoding)
1946
* \param source source buffer with plain unsigned bytes (you might need to cast from signed char)
1947
* \param source_size number of bytes in the source buffer
1948
* \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)
1949
*/
1950
MPG123_EXPORT int mpg123_store_utf8_2(mpg123_string *sb
1951
, int enc, const unsigned char *source, size_t source_size);
1952
1953
/** Sub data structure for ID3v2, for storing various text fields (including comments).
1954
* This is for ID3v2 COMM, TXXX and all the other text fields.
1955
* Only COMM, TXXX and USLT may have a description, only COMM and USLT
1956
* have a language.
1957
* You should consult the ID3v2 specification for the use of the various text fields
1958
* ("frames" in ID3v2 documentation, I use "fields" here to separate from MPEG frames). */
1959
typedef struct
1960
{
1961
char lang[3]; /**< Three-letter language code (not terminated). */
1962
char id[4]; /**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). */
1963
mpg123_string description; /**< Empty for the generic comment... */
1964
mpg123_string text; /**< ... */
1965
} mpg123_text;
1966
1967
/** The picture type values from ID3v2. */
1968
enum mpg123_id3_pic_type
1969
{
1970
mpg123_id3_pic_other = 0 /**< see ID3v2 docs */
1971
,mpg123_id3_pic_icon = 1 /**< see ID3v2 docs */
1972
,mpg123_id3_pic_other_icon = 2 /**< see ID3v2 docs */
1973
,mpg123_id3_pic_front_cover = 3 /**< see ID3v2 docs */
1974
,mpg123_id3_pic_back_cover = 4 /**< see ID3v2 docs */
1975
,mpg123_id3_pic_leaflet = 5 /**< see ID3v2 docs */
1976
,mpg123_id3_pic_media = 6 /**< see ID3v2 docs */
1977
,mpg123_id3_pic_lead = 7 /**< see ID3v2 docs */
1978
,mpg123_id3_pic_artist = 8 /**< see ID3v2 docs */
1979
,mpg123_id3_pic_conductor = 9 /**< see ID3v2 docs */
1980
,mpg123_id3_pic_orchestra = 10 /**< see ID3v2 docs */
1981
,mpg123_id3_pic_composer = 11 /**< see ID3v2 docs */
1982
,mpg123_id3_pic_lyricist = 12 /**< see ID3v2 docs */
1983
,mpg123_id3_pic_location = 13 /**< see ID3v2 docs */
1984
,mpg123_id3_pic_recording = 14 /**< see ID3v2 docs */
1985
,mpg123_id3_pic_performance = 15 /**< see ID3v2 docs */
1986
,mpg123_id3_pic_video = 16 /**< see ID3v2 docs */
1987
,mpg123_id3_pic_fish = 17 /**< see ID3v2 docs */
1988
,mpg123_id3_pic_illustration = 18 /**< see ID3v2 docs */
1989
,mpg123_id3_pic_artist_logo = 19 /**< see ID3v2 docs */
1990
,mpg123_id3_pic_publisher_logo = 20 /**< see ID3v2 docs */
1991
};
1992
1993
/** Sub data structure for ID3v2, for storing picture data including comment.
1994
* This is for the ID3v2 APIC field. You should consult the ID3v2 specification
1995
* for the use of the APIC field ("frames" in ID3v2 documentation, I use "fields"
1996
* here to separate from MPEG frames). */
1997
typedef struct
1998
{
1999
char type; /**< mpg123_id3_pic_type value */
2000
mpg123_string description; /**< description string */
2001
mpg123_string mime_type; /**< MIME type */
2002
size_t size; /**< size in bytes */
2003
unsigned char* data; /**< pointer to the image data */
2004
} mpg123_picture;
2005
2006
/** Data structure for storing IDV3v2 tags.
2007
* This structure is not a direct binary mapping with the file contents.
2008
* The ID3v2 text frames are allowed to contain multiple strings.
2009
* So check for null bytes until you reach the mpg123_string fill.
2010
* All text is encoded in UTF-8. */
2011
typedef struct
2012
{
2013
unsigned char version; /**< 3 or 4 for ID3v2.3 or ID3v2.4. */
2014
mpg123_string *title; /**< Title string (pointer into text_list). */
2015
mpg123_string *artist; /**< Artist string (pointer into text_list). */
2016
mpg123_string *album; /**< Album string (pointer into text_list). */
2017
mpg123_string *year; /**< The year as a string (pointer into text_list). */
2018
mpg123_string *genre; /**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. */
2019
mpg123_string *comment; /**< Pointer to last encountered comment text with empty description. */
2020
/* Encountered ID3v2 fields are appended to these lists.
2021
There can be multiple occurences, the pointers above always point to the last encountered data. */
2022
mpg123_text *comment_list; /**< Array of comments. */
2023
size_t comments; /**< Number of comments. */
2024
mpg123_text *text; /**< Array of ID3v2 text fields (including USLT) */
2025
size_t texts; /**< Numer of text fields. */
2026
mpg123_text *extra; /**< The array of extra (TXXX) fields. */
2027
size_t extras; /**< Number of extra text (TXXX) fields. */
2028
mpg123_picture *picture; /**< Array of ID3v2 pictures fields (APIC).
2029
Only populated if MPG123_PICTURE flag is set! */
2030
size_t pictures; /**< Number of picture (APIC) fields. */
2031
} mpg123_id3v2;
2032
2033
/** Data structure for ID3v1 tags (the last 128 bytes of a file).
2034
* Don't take anything for granted (like string termination)!
2035
* Also note the change ID3v1.1 did: comment[28] = 0; comment[29] = track_number
2036
* It is your task to support ID3v1 only or ID3v1.1 ...*/
2037
typedef struct
2038
{
2039
char tag[3]; /**< Always the string "TAG", the classic intro. */
2040
char title[30]; /**< Title string. */
2041
char artist[30]; /**< Artist string. */
2042
char album[30]; /**< Album string. */
2043
char year[4]; /**< Year string. */
2044
char comment[30]; /**< Comment string. */
2045
unsigned char genre; /**< Genre index. */
2046
} mpg123_id3v1;
2047
2048
#define MPG123_ID3 0x3 /**< 0011 There is some ID3 info. Also matches 0010 or NEW_ID3. */
2049
#define MPG123_NEW_ID3 0x1 /**< 0001 There is ID3 info that changed since last call to mpg123_id3. */
2050
#define MPG123_ICY 0xc /**< 1100 There is some ICY info. Also matches 0100 or NEW_ICY.*/
2051
#define MPG123_NEW_ICY 0x4 /**< 0100 There is ICY info that changed since last call to mpg123_icy. */
2052
2053
/** Query if there is (new) meta info, be it ID3 or ICY (or something new in future).
2054
* \param mh handle
2055
* \return combination of flags, 0 on error (same as "nothing new")
2056
*/
2057
MPG123_EXPORT int mpg123_meta_check(mpg123_handle *mh);
2058
2059
/** Clean up meta data storage (ID3v2 and ICY), freeing memory.
2060
* \param mh handle
2061
*/
2062
MPG123_EXPORT void mpg123_meta_free(mpg123_handle *mh);
2063
2064
/** Point v1 and v2 to existing data structures wich may change on any next read/decode function call.
2065
* v1 and/or v2 can be set to NULL when there is no corresponding data.
2066
* \return MPG123_OK on success
2067
*/
2068
MPG123_EXPORT int mpg123_id3( mpg123_handle *mh
2069
, mpg123_id3v1 **v1, mpg123_id3v2 **v2 );
2070
2071
/** Return pointers to and size of stored raw ID3 data if storage has
2072
* been configured with MPG123_STORE_RAW_ID3 and stream parsing passed the
2073
* metadata already. Null value with zero size is a possibility!
2074
* The storage can change at any next API call.
2075
*
2076
* \param mh mpg123 handle
2077
* \param v1 address to store pointer to v1 tag
2078
* \param v1_size size of v1 data in bytes
2079
* \param v2 address to store pointer to v2 tag
2080
* \param v2_size size of v2 data in bytes
2081
* \return MPG123_OK or MPG123_ERR. Only on MPG123_OK the output
2082
* values are set.
2083
*/
2084
MPG123_EXPORT int mpg123_id3_raw( mpg123_handle *mh
2085
, unsigned char **v1, size_t *v1_size
2086
, unsigned char **v2, size_t *v2_size );
2087
2088
/** Point icy_meta to existing data structure wich may change on any next read/decode function call.
2089
* \param mh handle
2090
* \param icy_meta return address for ICY meta string (set to NULL if nothing there)
2091
* \return MPG123_OK on success
2092
*/
2093
MPG123_EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta);
2094
2095
/** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8.
2096
* Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .
2097
* \param icy_text The input data in ICY encoding
2098
* \return pointer to newly allocated buffer with UTF-8 data (You free() it!) */
2099
MPG123_EXPORT char* mpg123_icy2utf8(const char* icy_text);
2100
2101
2102
/** @} */
2103
2104
2105
/** \defgroup mpg123_advpar mpg123 advanced parameter API
2106
*
2107
* Direct access to a parameter set without full handle around it.
2108
* Possible uses:
2109
* - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE).
2110
* - Use one set of parameters for multiple handles.
2111
*
2112
* The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt()
2113
* family) directly return a fully qualified mpg123 error code, the ones
2114
* operating on full handles normally MPG123_OK or MPG123_ERR, storing the
2115
* specific error code itseld inside the handle.
2116
*
2117
* @{
2118
*/
2119
2120
/** Opaque structure for the libmpg123 decoder parameters. */
2121
struct mpg123_pars_struct;
2122
2123
/** Opaque structure for the libmpg123 decoder parameters. */
2124
typedef struct mpg123_pars_struct mpg123_pars;
2125
2126
/** Create a handle with preset parameters.
2127
* \param mp parameter handle
2128
* \param decoder decoder choice
2129
* \param error error code return address
2130
* \return mpg123 handle
2131
*/
2132
MPG123_EXPORT mpg123_handle *mpg123_parnew( mpg123_pars *mp
2133
, const char* decoder, int *error );
2134
2135
/** Allocate memory for and return a pointer to a new mpg123_pars
2136
* \param error error code return address
2137
* \return new parameter handle
2138
*/
2139
MPG123_EXPORT mpg123_pars *mpg123_new_pars(int *error);
2140
2141
/** Delete and free up memory used by a mpg123_pars data structure
2142
* \param mp parameter handle
2143
*/
2144
MPG123_EXPORT void mpg123_delete_pars(mpg123_pars* mp);
2145
2146
/** Configure mpg123 parameters to accept no output format at all,
2147
* use before specifying supported formats with mpg123_format
2148
* \param mp parameter handle
2149
* \return MPG123_OK on success
2150
*/
2151
MPG123_EXPORT int mpg123_fmt_none(mpg123_pars *mp);
2152
2153
/** Configure mpg123 parameters to accept all formats
2154
* (also any custom rate you may set) -- this is default.
2155
* \param mp parameter handle
2156
* \return MPG123_OK on success
2157
*/
2158
MPG123_EXPORT int mpg123_fmt_all(mpg123_pars *mp);
2159
2160
/** Set the audio format support of a mpg123_pars in detail:
2161
* \param mp parameter handle
2162
* \param rate The sample rate value (in Hertz).
2163
* \param channels A combination of MPG123_STEREO and MPG123_MONO.
2164
* \param encodings A combination of accepted encodings for rate and channels,
2165
* p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no
2166
* support).
2167
* \return MPG123_OK on success
2168
*/
2169
MPG123_EXPORT int mpg123_fmt(mpg123_pars *mp
2170
, long rate, int channels, int encodings);
2171
2172
/** Set the audio format support of a mpg123_pars in detail:
2173
* \param mp parameter handle
2174
* \param rate The sample rate value (in Hertz). Special value 0 means
2175
* all rates (reason for this variant of mpg123_fmt).
2176
* \param channels A combination of MPG123_STEREO and MPG123_MONO.
2177
* \param encodings A combination of accepted encodings for rate and channels,
2178
* p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no
2179
* support).
2180
* \return MPG123_OK on success
2181
*/
2182
MPG123_EXPORT int mpg123_fmt2(mpg123_pars *mp
2183
, long rate, int channels, int encodings);
2184
2185
/** Check to see if a specific format at a specific rate is supported
2186
* by mpg123_pars.
2187
* \param mp parameter handle
2188
* \param rate sampling rate
2189
* \param encoding encoding
2190
* \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
2191
* MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
2192
MPG123_EXPORT int mpg123_fmt_support(mpg123_pars *mp, long rate, int encoding);
2193
2194
#ifdef MPG123_ENUM_API
2195
/** Set a specific parameter in a par handle.
2196
*
2197
* Note that this name is mapped to mpg123_par2() instead unless
2198
* MPG123_ENUM_API is defined.
2199
*
2200
* \param mp parameter handle
2201
* \param type parameter choice
2202
* \param value integer value
2203
* \param fvalue floating point value
2204
* \return MPG123_OK on success
2205
*/
2206
MPG123_EXPORT int mpg123_par( mpg123_pars *mp
2207
, enum mpg123_parms type, long value, double fvalue );
2208
#endif
2209
2210
/** Set a specific parameter in a par handle. No enums.
2211
*
2212
* This is actually called instead of mpg123_par()
2213
* unless MPG123_ENUM_API is defined.
2214
*
2215
* \param mp parameter handle
2216
* \param type parameter choice (enum mpg123_parms)
2217
* \param value integer value
2218
* \param fvalue floating point value
2219
* \return MPG123_OK on success
2220
*/
2221
MPG123_EXPORT int mpg123_par2( mpg123_pars *mp
2222
, int type, long value, double fvalue );
2223
2224
#ifdef MPG123_ENUM_API
2225
/** Get a specific parameter from a par handle.
2226
*
2227
* Note that this name is mapped to mpg123_getpar2() instead unless
2228
* MPG123_ENUM_API is defined.
2229
*
2230
* \param mp parameter handle
2231
* \param type parameter choice
2232
* \param value integer value return address
2233
* \param fvalue floating point value return address
2234
* \return MPG123_OK on success
2235
*/
2236
MPG123_EXPORT int mpg123_getpar( mpg123_pars *mp
2237
, enum mpg123_parms type, long *value, double *fvalue );
2238
#endif
2239
2240
/** Get a specific parameter from a par handle. No enums.
2241
*
2242
* This is actually called instead of mpg123_getpar()
2243
* unless MPG123_ENUM_API is defined.
2244
*
2245
* \param mp parameter handle
2246
* \param type parameter choice (enum mpg123_parms)
2247
* \param value integer value return address
2248
* \param fvalue floating point value return address
2249
* \return MPG123_OK on success
2250
*/
2251
MPG123_EXPORT int mpg123_getpar2( mpg123_pars *mp
2252
, int type, long *value, double *fvalue );
2253
2254
/** @} */
2255
2256
2257
/** \defgroup mpg123_lowio mpg123 low level I/O
2258
* 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...
2259
*
2260
* @{ */
2261
2262
/** Replace default internal buffer with user-supplied buffer.
2263
* Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio.
2264
* Note that the required buffer size could be bigger than expected from output
2265
* encoding if libmpg123 has to convert from primary decoder output (p.ex. 32 bit
2266
* storage for 24 bit output).
2267
*
2268
* Note: The type of data changed to a void pointer in mpg123 1.26.0
2269
* (API version 45).
2270
*
2271
* \param mh handle
2272
* \param data pointer to user buffer
2273
* \param size of buffer in bytes
2274
* \return MPG123_OK on success
2275
*/
2276
MPG123_EXPORT int mpg123_replace_buffer(mpg123_handle *mh
2277
, void *data, size_t size);
2278
2279
/** The max size of one frame's decoded output with current settings.
2280
* Use that to determine an appropriate minimum buffer size for decoding one frame.
2281
* \param mh handle
2282
* \return maximum decoded data size in bytes
2283
*/
2284
MPG123_EXPORT size_t mpg123_outblock(mpg123_handle *mh);
2285
2286
#ifndef MPG123_PORTABLE_API
2287
/** Replace low-level stream access functions; read and lseek as known in POSIX.
2288
* You can use this to make any fancy file opening/closing yourself,
2289
* using mpg123_open_fd() to set the file descriptor for your read/lseek
2290
* (doesn't need to be a "real" file descriptor...).
2291
* Setting a function to NULL means that just a call to POSIX read/lseek is
2292
* done (without handling signals).
2293
* Note: As it would be troublesome to mess with this while having a file open,
2294
* this implies mpg123_close().
2295
* \param mh handle
2296
* \param r_read callback for reading (behaviour like POSIX read)
2297
* \param r_lseek callback for seeking (like POSIX lseek)
2298
* \return MPG123_OK on success
2299
*/
2300
MPG123_EXPORT int mpg123_replace_reader( mpg123_handle *mh
2301
, mpg123_ssize_t (*r_read) (int, void *, size_t)
2302
, off_t (*r_lseek)(int, off_t, int)
2303
);
2304
2305
/** Replace I/O functions with your own ones operating on some kind of
2306
* handle instead of integer descriptors.
2307
* The handle is a void pointer, so you can pass any data you want...
2308
* mpg123_open_handle() is the call you make to use the I/O defined here.
2309
* There is no fallback to internal read/seek here.
2310
* Note: As it would be troublesome to mess with this while having a file open,
2311
* this mpg123_close() is implied here.
2312
* \param mh handle
2313
* \param r_read callback for reading (behaviour like POSIX read)
2314
* \param r_lseek callback for seeking (like POSIX lseek)
2315
* \param cleanup A callback to clean up a non-NULL I/O handle on mpg123_close,
2316
* can be NULL for none (you take care of cleaning your handles).
2317
* \return MPG123_OK on success
2318
*/
2319
MPG123_EXPORT int mpg123_replace_reader_handle( mpg123_handle *mh
2320
, mpg123_ssize_t (*r_read) (void *, void *, size_t)
2321
, off_t (*r_lseek)(void *, off_t, int)
2322
, void (*cleanup)(void*) );
2323
#endif
2324
2325
/** Set up portable read functions on an opaque handle.
2326
* The handle is a void pointer, so you can pass any data you want...
2327
* mpg123_open64() (since API 49) or mpg123_open_handle() is the call you make
2328
* to use the I/O defined here.
2329
* There is no fallback to internal read/seek here.
2330
* Note: As it would be troublesome to mess with this while having a file open,
2331
* this mpg123_close() is implied here.
2332
* \param mh handle
2333
* \param r_read callback for reading
2334
* The parameters are the handle, the buffer to read into, a byte count to read,
2335
* address to store the returned byte count. Return value is zero for
2336
* no issue, non-zero for some error. Recoverable signal handling has to happen
2337
* inside the callback.
2338
* \param r_lseek callback for seeking (like POSIX lseek), maybe NULL for
2339
* non-seekable streams
2340
* \param cleanup A callback to clean up a non-NULL I/O handle on mpg123_close,
2341
* maybe NULL for none
2342
* \return MPG123_OK on success
2343
*/
2344
MPG123_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*) );
2345
2346
/** @} */
2347
2348
#ifdef __cplusplus
2349
}
2350
#endif
2351
2352
#endif
2353
2354