ReactOS 0.4.15-dev-7953-g1f49173
mpg123 error handling
Collaboration diagram for mpg123 error handling:

Modules

 mpg123 decoder selection
 

Enumerations

enum  mpg123_errors {
  MPG123_DONE =-12 , MPG123_NEW_FORMAT =-11 , MPG123_NEED_MORE =-10 , MPG123_ERR =-1 ,
  MPG123_OK =0 , MPG123_BAD_OUTFORMAT , MPG123_BAD_CHANNEL , MPG123_BAD_RATE ,
  MPG123_ERR_16TO8TABLE , MPG123_BAD_PARAM , MPG123_BAD_BUFFER , MPG123_OUT_OF_MEM ,
  MPG123_NOT_INITIALIZED , MPG123_BAD_DECODER , MPG123_BAD_HANDLE , MPG123_NO_BUFFERS ,
  MPG123_BAD_RVA , MPG123_NO_GAPLESS , MPG123_NO_SPACE , MPG123_BAD_TYPES ,
  MPG123_BAD_BAND , MPG123_ERR_NULL , MPG123_ERR_READER , MPG123_NO_SEEK_FROM_END ,
  MPG123_BAD_WHENCE , MPG123_NO_TIMEOUT , MPG123_BAD_FILE , MPG123_NO_SEEK ,
  MPG123_NO_READER , MPG123_BAD_PARS , MPG123_BAD_INDEX_PAR , MPG123_OUT_OF_SYNC ,
  MPG123_RESYNC_FAIL , MPG123_NO_8BIT , MPG123_BAD_ALIGN , MPG123_NULL_BUFFER ,
  MPG123_NO_RELSEEK , MPG123_NULL_POINTER , MPG123_BAD_KEY , MPG123_NO_INDEX ,
  MPG123_INDEX_FAIL , MPG123_BAD_DECODER_SETUP , MPG123_MISSING_FEATURE , MPG123_BAD_VALUE ,
  MPG123_LSEEK_FAILED , MPG123_BAD_CUSTOM_IO , MPG123_LFS_OVERFLOW , MPG123_INT_OVERFLOW
}
 

Functions

MPG123_EXPORT const charmpg123_plain_strerror (int errcode)
 
MPG123_EXPORT const charmpg123_strerror (mpg123_handle *mh)
 
MPG123_EXPORT int mpg123_errcode (mpg123_handle *mh)
 

Detailed Description

Functions to get text version of the error numbers and an enumeration of the error codes returned by libmpg123.

Most functions operating on a mpg123_handle simply return MPG123_OK (0) on success and MPG123_ERR (-1) on failure, setting the internal error variable of the handle to the specific error code. If there was not a valid (non-NULL) handle provided to a function operating on one, MPG123_BAD_HANDLE may be returned if this can not be confused with a valid positive return value. Meaning: A function expected to return positive integers on success will always indicate error or a special condition by returning a negative one.

Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE (all negative, see below on how to react). Note that calls to those can be nested, so generally watch out for these codes after initial handle setup. Especially any function that needs information about the current stream to work will try to at least parse the beginning if that did not happen yet.

On a function that is supposed to return MPG123_OK on success and MPG123_ERR on failure, make sure you check for != MPG123_OK, not == MPG123_ERR, as the error code could get more specific in future, or there is just a special message from a decoding routine as indicated above.

Enumeration Type Documentation

◆ mpg123_errors

Enumeration of the message and error codes and returned by libmpg123 functions.

Enumerator
MPG123_DONE 

Message: Track ended. Stop decoding.

MPG123_NEW_FORMAT 

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.

MPG123_NEED_MORE 

Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data).

MPG123_ERR 

Generic Error

MPG123_OK 

Success

MPG123_BAD_OUTFORMAT 

Unable to set up output format!

MPG123_BAD_CHANNEL 

Invalid channel number specified.

MPG123_BAD_RATE 

Invalid sample rate specified.

MPG123_ERR_16TO8TABLE 

Unable to allocate memory for 16 to 8 converter table!

MPG123_BAD_PARAM 

Bad parameter id!

MPG123_BAD_BUFFER 

Bad buffer given – invalid pointer or too small size.

MPG123_OUT_OF_MEM 

Out of memory – some malloc() failed.

MPG123_NOT_INITIALIZED 

You didn't initialize the library!

MPG123_BAD_DECODER 

Invalid decoder choice.

MPG123_BAD_HANDLE 

Invalid mpg123 handle.

MPG123_NO_BUFFERS 

Unable to initialize frame buffers (out of memory?).

MPG123_BAD_RVA 

Invalid RVA mode.

MPG123_NO_GAPLESS 

This build doesn't support gapless decoding.

MPG123_NO_SPACE 

Not enough buffer space.

MPG123_BAD_TYPES 

Incompatible numeric data types.

MPG123_BAD_BAND 

Bad equalizer band.

MPG123_ERR_NULL 

Null pointer given where valid storage address needed.

MPG123_ERR_READER 

Error reading the stream.

MPG123_NO_SEEK_FROM_END 

Cannot seek from end (end is not known).

MPG123_BAD_WHENCE 

Invalid 'whence' for seek function.

MPG123_NO_TIMEOUT 

Build does not support stream timeouts.

MPG123_BAD_FILE 

File access error.

MPG123_NO_SEEK 

Seek not supported by stream.

MPG123_NO_READER 

No stream opened.

MPG123_BAD_PARS 

Bad parameter handle.

MPG123_BAD_INDEX_PAR 

Bad parameters to mpg123_index() and mpg123_set_index()

MPG123_OUT_OF_SYNC 

Lost track in bytestream and did not try to resync.

MPG123_RESYNC_FAIL 

Resync failed to find valid MPEG data.

MPG123_NO_8BIT 

No 8bit encoding possible.

MPG123_BAD_ALIGN 

Stack aligmnent error

MPG123_NULL_BUFFER 

NULL input buffer with non-zero size...

MPG123_NO_RELSEEK 

Relative seek not possible (screwed up file offset)

MPG123_NULL_POINTER 

You gave a null pointer somewhere where you shouldn't have.

MPG123_BAD_KEY 

Bad key value given.

MPG123_NO_INDEX 

No frame index in this build.

MPG123_INDEX_FAIL 

Something with frame index went wrong.

MPG123_BAD_DECODER_SETUP 

Something prevents a proper decoder setup

MPG123_MISSING_FEATURE 

This feature has not been built into libmpg123.

MPG123_BAD_VALUE 

A bad value has been given, somewhere.

MPG123_LSEEK_FAILED 

Low-level seek failed.

MPG123_BAD_CUSTOM_IO 

Custom I/O not prepared.

MPG123_LFS_OVERFLOW 

Offset value overflow during translation of large file API calls – your client program cannot handle that large file.

MPG123_INT_OVERFLOW 

Some integer overflow.

Definition at line 377 of file mpg123.h.

378{
379 MPG123_DONE=-12,
381 MPG123_NEED_MORE=-10,
382 MPG123_ERR=-1,
383 MPG123_OK=0,
427};
@ MPG123_NEED_MORE
Definition: mpg123.h:381
@ MPG123_LSEEK_FAILED
Definition: mpg123.h:423
@ MPG123_BAD_PARAM
Definition: mpg123.h:388
@ MPG123_ERR_16TO8TABLE
Definition: mpg123.h:387
@ MPG123_BAD_CHANNEL
Definition: mpg123.h:385
@ MPG123_NO_SEEK
Definition: mpg123.h:406
@ MPG123_BAD_PARS
Definition: mpg123.h:408
@ MPG123_INT_OVERFLOW
Definition: mpg123.h:426
@ MPG123_BAD_HANDLE
Definition: mpg123.h:393
@ MPG123_RESYNC_FAIL
Definition: mpg123.h:411
@ MPG123_BAD_OUTFORMAT
Definition: mpg123.h:384
@ MPG123_NO_TIMEOUT
Definition: mpg123.h:404
@ MPG123_INDEX_FAIL
Definition: mpg123.h:419
@ MPG123_BAD_BUFFER
Definition: mpg123.h:389
@ MPG123_ERR
Definition: mpg123.h:382
@ MPG123_NULL_POINTER
Definition: mpg123.h:416
@ MPG123_BAD_RVA
Definition: mpg123.h:395
@ MPG123_BAD_FILE
Definition: mpg123.h:405
@ MPG123_ERR_READER
Definition: mpg123.h:401
@ MPG123_NO_SEEK_FROM_END
Definition: mpg123.h:402
@ MPG123_NOT_INITIALIZED
Definition: mpg123.h:391
@ MPG123_OUT_OF_MEM
Definition: mpg123.h:390
@ MPG123_NULL_BUFFER
Definition: mpg123.h:414
@ MPG123_OUT_OF_SYNC
Definition: mpg123.h:410
@ MPG123_NO_SPACE
Definition: mpg123.h:397
@ MPG123_ERR_NULL
Definition: mpg123.h:400
@ MPG123_BAD_TYPES
Definition: mpg123.h:398
@ MPG123_LFS_OVERFLOW
Definition: mpg123.h:425
@ MPG123_NEW_FORMAT
Definition: mpg123.h:380
@ MPG123_BAD_KEY
Definition: mpg123.h:417
@ MPG123_NO_READER
Definition: mpg123.h:407
@ MPG123_BAD_CUSTOM_IO
Definition: mpg123.h:424
@ MPG123_BAD_WHENCE
Definition: mpg123.h:403
@ MPG123_BAD_ALIGN
Definition: mpg123.h:413
@ MPG123_NO_BUFFERS
Definition: mpg123.h:394
@ MPG123_NO_INDEX
Definition: mpg123.h:418
@ MPG123_DONE
Definition: mpg123.h:379
@ MPG123_BAD_DECODER_SETUP
Definition: mpg123.h:420
@ MPG123_NO_RELSEEK
Definition: mpg123.h:415
@ MPG123_NO_GAPLESS
Definition: mpg123.h:396
@ MPG123_BAD_INDEX_PAR
Definition: mpg123.h:409
@ MPG123_BAD_VALUE
Definition: mpg123.h:422
@ MPG123_MISSING_FEATURE
Definition: mpg123.h:421
@ MPG123_BAD_BAND
Definition: mpg123.h:399
@ MPG123_OK
Definition: mpg123.h:383
@ MPG123_BAD_RATE
Definition: mpg123.h:386
@ MPG123_BAD_DECODER
Definition: mpg123.h:392
@ MPG123_NO_8BIT
Definition: mpg123.h:412

Function Documentation

◆ mpg123_errcode()

MPG123_EXPORT int mpg123_errcode ( mpg123_handle mh)

Return the plain errcode intead of a string.

Parameters
mhhandle
Returns
error code recorded in handle or MPG123_BAD_HANDLE

Definition at line 1794 of file libmpg123.c.

1795{
1796 if(mh != NULL) return mh->err;
1797 return MPG123_BAD_HANDLE;
1798}
#define NULL
Definition: types.h:112

Referenced by mpg123_strerror().

◆ mpg123_plain_strerror()

MPG123_EXPORT const char * mpg123_plain_strerror ( int  errcode)

Look up error strings given integer code.

Parameters
errcodeinteger error code
Returns
string describing what that error error code means

Definition at line 1775 of file libmpg123.c.

1776{
1777 if(errcode >= 0 && errcode < sizeof(mpg123_error)/sizeof(char*))
1778 return mpg123_error[errcode];
1779 else switch(errcode)
1780 {
1781 case MPG123_ERR:
1782 return "A generic mpg123 error.";
1783 case MPG123_DONE:
1784 return "Message: I am done with this track.";
1785 case MPG123_NEED_MORE:
1786 return "Message: Feed me more input data!";
1787 case MPG123_NEW_FORMAT:
1788 return "Message: Prepare for a changed audio format (query the new one)!";
1789 default:
1790 return "I have no idea - an unknown error code!";
1791 }
1792}
int errcode
Definition: crtdefs.h:373
static const char * mpg123_error[]
Definition: libmpg123.c:1727

Referenced by mpg123_strerror().

◆ mpg123_strerror()

MPG123_EXPORT const char * mpg123_strerror ( mpg123_handle mh)

Give string describing what error has occured in the context of handle mh. When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via char *errmsg = mpg123_strerror(mh) This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE.

Parameters
mhhandle
Returns
error message

Definition at line 1800 of file libmpg123.c.

1801{
1803}
const char *attribute_align_arg mpg123_plain_strerror(int errcode)
Definition: libmpg123.c:1775
int attribute_align_arg mpg123_errcode(mpg123_handle *mh)
Definition: libmpg123.c:1794