ReactOS  r76032
mpg123 metadata handling

Classes

struct  mpg123_string
 
struct  mpg123_text
 
struct  mpg123_picture
 
struct  mpg123_id3v2
 
struct  mpg123_id3v1
 

Macros

#define MPG123_ID3   0x3
 
#define MPG123_NEW_ID3   0x1
 
#define MPG123_ICY   0xc
 
#define MPG123_NEW_ICY   0x4
 

Enumerations

enum  mpg123_text_encoding {
  mpg123_text_unknown = 0, mpg123_text_utf8 = 1, mpg123_text_latin1 = 2, mpg123_text_icy = 3,
  mpg123_text_cp1252 = 4, mpg123_text_utf16 = 5, mpg123_text_utf16bom = 6, mpg123_text_utf16be = 7,
  mpg123_text_max = 7
}
 
enum  mpg123_id3_enc {
  mpg123_id3_latin1 = 0, mpg123_id3_utf16bom = 1, mpg123_id3_utf16be = 2, mpg123_id3_utf8 = 3,
  mpg123_id3_enc_max = 3
}
 
enum  mpg123_id3_pic_type {
  mpg123_id3_pic_other = 0, mpg123_id3_pic_icon = 1, mpg123_id3_pic_other_icon = 2, mpg123_id3_pic_front_cover = 3,
  mpg123_id3_pic_back_cover = 4, mpg123_id3_pic_leaflet = 5, mpg123_id3_pic_media = 6, mpg123_id3_pic_lead = 7,
  mpg123_id3_pic_artist = 8, mpg123_id3_pic_conductor = 9, mpg123_id3_pic_orchestra = 10, mpg123_id3_pic_composer = 11,
  mpg123_id3_pic_lyricist = 12, mpg123_id3_pic_location = 13, mpg123_id3_pic_recording = 14, mpg123_id3_pic_performance = 15,
  mpg123_id3_pic_video = 16, mpg123_id3_pic_fish = 17, mpg123_id3_pic_illustration = 18, mpg123_id3_pic_artist_logo = 19,
  mpg123_id3_pic_publisher_logo = 20
}
 

Functions

MPG123_EXPORT void mpg123_init_string (mpg123_string *sb)
 
MPG123_EXPORT void mpg123_free_string (mpg123_string *sb)
 
MPG123_EXPORT int mpg123_resize_string (mpg123_string *sb, size_t news)
 
MPG123_EXPORT int mpg123_grow_string (mpg123_string *sb, size_t news)
 
MPG123_EXPORT int mpg123_copy_string (mpg123_string *from, mpg123_string *to)
 
MPG123_EXPORT int mpg123_add_string (mpg123_string *sb, const char *stuff)
 
MPG123_EXPORT int mpg123_add_substring (mpg123_string *sb, const char *stuff, size_t from, size_t count)
 
MPG123_EXPORT int mpg123_set_string (mpg123_string *sb, const char *stuff)
 
MPG123_EXPORT int mpg123_set_substring (mpg123_string *sb, const char *stuff, size_t from, size_t count)
 
MPG123_EXPORT size_t mpg123_strlen (mpg123_string *sb, int utf8)
 
MPG123_EXPORT int mpg123_chomp_string (mpg123_string *sb)
 
MPG123_EXPORT enum
mpg123_text_encoding 
mpg123_enc_from_id3 (unsigned char id3_enc_byte)
 
MPG123_EXPORT int mpg123_store_utf8 (mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size)
 
MPG123_EXPORT int mpg123_meta_check (mpg123_handle *mh)
 
MPG123_EXPORT void mpg123_meta_free (mpg123_handle *mh)
 
MPG123_EXPORT int mpg123_id3 (mpg123_handle *mh, mpg123_id3v1 **v1, mpg123_id3v2 **v2)
 
MPG123_EXPORT int mpg123_icy (mpg123_handle *mh, char **icy_meta)
 
MPG123_EXPORT charmpg123_icy2utf8 (const char *icy_text)
 

Detailed Description

Functions to retrieve the metadata from MPEG Audio files and streams. Also includes string handling functions.

Macro Definition Documentation

#define MPG123_ICY   0xc

1100 There is some ICY info. Also matches 0100 or NEW_ICY.

Definition at line 1242 of file mpg123.h.

Referenced by mpg123_icy().

#define MPG123_ID3   0x3

0011 There is some ID3 info. Also matches 0010 or NEW_ID3.

Definition at line 1240 of file mpg123.h.

Referenced by handle_id3v2(), mpg123_id3(), and wetwork().

#define MPG123_NEW_ICY   0x4

0100 There is ICY info that changed since last call to mpg123_icy.

Definition at line 1243 of file mpg123.h.

Referenced by icy_fullread(), and mpg123_icy().

#define MPG123_NEW_ID3   0x1

0001 There is ID3 info that changed since last call to mpg123_id3.

Definition at line 1241 of file mpg123.h.

Referenced by default_init(), handle_id3v2(), mpg123_id3(), and wetwork().

Enumeration Type Documentation

The encoding byte values from ID3v2.

Enumerator
mpg123_id3_latin1 

Note: This sometimes can mean anything in practice...

mpg123_id3_utf16bom 

UTF16, UCS-2 ... it's all the same for practical purposes.

mpg123_id3_utf16be 

Big-endian UTF-16, BOM see note for mpg123_text_utf16be.

mpg123_id3_utf8 

Our lovely overly ASCII-compatible 8 byte encoding for the world.

mpg123_id3_enc_max 

Placeholder to check valid range of encoding byte.

Definition at line 1121 of file mpg123.h.

The picture type values from ID3v2.

Enumerator
mpg123_id3_pic_other 

see ID3v2 docs

mpg123_id3_pic_icon 

see ID3v2 docs

mpg123_id3_pic_other_icon 

see ID3v2 docs

mpg123_id3_pic_front_cover 

see ID3v2 docs

mpg123_id3_pic_back_cover 

see ID3v2 docs

mpg123_id3_pic_leaflet 

see ID3v2 docs

mpg123_id3_pic_media 

see ID3v2 docs

mpg123_id3_pic_lead 

see ID3v2 docs

mpg123_id3_pic_artist 

see ID3v2 docs

mpg123_id3_pic_conductor 

see ID3v2 docs

mpg123_id3_pic_orchestra 

see ID3v2 docs

mpg123_id3_pic_composer 

see ID3v2 docs

mpg123_id3_pic_lyricist 

see ID3v2 docs

mpg123_id3_pic_location 

see ID3v2 docs

mpg123_id3_pic_recording 

see ID3v2 docs

mpg123_id3_pic_performance 

see ID3v2 docs

mpg123_id3_pic_video 

see ID3v2 docs

mpg123_id3_pic_fish 

see ID3v2 docs

mpg123_id3_pic_illustration 

see ID3v2 docs

mpg123_id3_pic_artist_logo 

see ID3v2 docs

mpg123_id3_pic_publisher_logo 

see ID3v2 docs

Definition at line 1161 of file mpg123.h.

1162 {
1164  ,mpg123_id3_pic_icon = 1
1169  ,mpg123_id3_pic_media = 6
1170  ,mpg123_id3_pic_lead = 7
1171  ,mpg123_id3_pic_artist = 8
1179  ,mpg123_id3_pic_video = 16
1180  ,mpg123_id3_pic_fish = 17
1184 };

The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info.

Enumerator
mpg123_text_unknown 

Unkown encoding... mpg123_id3_encoding can return that on invalid codes.

mpg123_text_utf8 

UTF-8

mpg123_text_latin1 

ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings.

mpg123_text_icy 

ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such.

mpg123_text_cp1252 

Really CP-1252 without any guessing.

mpg123_text_utf16 

Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules. When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when you don't mess with the reserved code points. If you want to decode little endian data without BOM you need to prepend 0xff 0xfe yourself.

mpg123_text_utf16bom 

Just an alias for UTF-16, ID3v2 has this as distinct code.

mpg123_text_utf16be 

Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality, BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123 One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16 types (we expect a BOM before real data there), not so for utf16be!

mpg123_text_max 

Placeholder for the maximum encoding value.

Definition at line 1101 of file mpg123.h.

Function Documentation

MPG123_EXPORT int mpg123_add_string ( mpg123_string sb,
const char stuff 
)

Append a C-String to an mpg123_string

Parameters
sbstring handle
stuffto append
Returns
0 on error, 1 on success

Definition at line 98 of file stringbuf.c.

Referenced by mpg123_set_string().

99 {
100  debug1("adding %s", stuff);
101  return mpg123_add_substring(sb, stuff, 0, stuff ? strlen(stuff) : 0);
102 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define debug1(s, a)
Definition: debug.h:52
int attribute_align_arg mpg123_add_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count)
Definition: stringbuf.c:104
MPG123_EXPORT int mpg123_add_substring ( mpg123_string sb,
const char stuff,
size_t  from,
size_t  count 
)

Append a C-substring to an mpg123 string

Parameters
sbstring handle
stuffcontent to copy
fromoffset to copy from
countnumber of characters to copy (a null-byte is always appended)
Returns
0 on error, 1 on success

Definition at line 104 of file stringbuf.c.

Referenced by mpg123_add_string(), and mpg123_set_substring().

105 {
106  debug("adding a substring");
107  if(!sb || !stuff)
108  return 0;
109  if(sb->fill) /* includes zero byte... */
110  {
111  if( (SIZE_MAX - sb->fill >= count) /* Avoid overflow. */
112  && (sb->size >= sb->fill+count || mpg123_grow_string(sb, sb->fill+count)) )
113  {
114  memcpy(sb->p+sb->fill-1, stuff+from, count);
115  sb->fill += count;
116  sb->p[sb->fill-1] = 0; /* Terminate! */
117  }
118  else return 0;
119  }
120  else
121  {
122  if( count < SIZE_MAX && mpg123_grow_string(sb, count+1) )
123  {
124  memcpy(sb->p, stuff+from, count);
125  sb->fill = count+1;
126  sb->p[sb->fill-1] = 0; /* Terminate! */
127  }
128  else return 0;
129  }
130  return 1;
131 }
#define SIZE_MAX
Definition: limits.h:75
size_t size
Definition: mpg123.h:1012
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define debug(msg)
Definition: key_call.c:71
CardRegion * from
Definition: spigame.cpp:19
size_t fill
Definition: mpg123.h:1013
int attribute_align_arg mpg123_grow_string(mpg123_string *sb, size_t new)
Definition: stringbuf.c:33
char * p
Definition: mpg123.h:1011
MPG123_EXPORT int mpg123_chomp_string ( mpg123_string sb)

Remove trailing \r and \n, if present.

Parameters
sbstring handle
Returns
0 on error, 1 on success

Definition at line 181 of file stringbuf.c.

182 {
183  ssize_t i;
184  if(!sb || !sb->fill) return 0;
185 
186  /* Ensure that it is zero-terminated. */
187  sb->p[sb->fill-1] = 0;
188  for(i=sb->fill-2; i>=0; --i)
189  {
190  char *c = sb->p+i;
191  /* Stop at the first proper character. */
192  if(*c && *c != '\r' && *c != '\n') break;
193  else *c = 0;
194  }
195  /* initial fill at least 1, so i at least -1,
196  +2 means nothing happened for fill=1 .
197  With i=0, we got one non-null character, fill shall be 2
198  to accomodate the trailing zero. */
199  sb->fill = (size_t)i+2;
200 
201  return 1;
202 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
__kernel_size_t size_t
Definition: linux.h:237
const GLubyte * c
Definition: glext.h:8905
int ssize_t
Definition: rosdhcp.h:48
size_t fill
Definition: mpg123.h:1013
char * p
Definition: mpg123.h:1011
MPG123_EXPORT int mpg123_copy_string ( mpg123_string from,
mpg123_string to 
)

Copy the contents of one mpg123_string string to another. Yes the order of arguments is reversed compated to memcpy().

Parameters
fromstring handle
tostring handle
Returns
0 on error, 1 on success

Definition at line 69 of file stringbuf.c.

70 {
71  size_t fill;
72  char *text;
73 
74  debug2("called copy_string with %p -> %p", (void*)from, (void*)to);
75  if(to == NULL)
76  return 0;
77  if(from == NULL)
78  {
79  fill = 0;
80  text = NULL;
81  }
82  else
83  {
84  fill = from->fill;
85  text = from->p;
86  }
87 
88  if(mpg123_resize_string(to, fill))
89  {
90  if(fill) /* Avoid memcpy(NULL, NULL, 0) */
91  memcpy(to->p, text, fill);
92  to->fill = fill;
93  return 1;
94  }
95  else return 0;
96 }
#define debug2(s, a, b)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:557
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
LPCSTR text
Definition: menu.c:130
int attribute_align_arg mpg123_resize_string(mpg123_string *sb, size_t new)
Definition: stringbuf.c:41
size_t fill
Definition: mpg123.h:1013
char * p
Definition: mpg123.h:1011
MPG123_EXPORT enum mpg123_text_encoding mpg123_enc_from_id3 ( unsigned char  id3_enc_byte)

Convert ID3 encoding byte to mpg123 encoding index.

Parameters
id3_enc_bytethe ID3 encoding code
Returns
the mpg123 encoding index

Definition at line 1499 of file libmpg123.c.

1500 {
1501  switch(id3_enc_byte)
1502  {
1504  case mpg123_id3_utf16bom: return mpg123_text_utf16bom; /* ID3v2.3 has UCS-2 with BOM here. */
1506  case mpg123_id3_utf8: return mpg123_text_utf8;
1507  default: return mpg123_text_unknown;
1508  }
1509 }
MPG123_EXPORT void mpg123_free_string ( mpg123_string sb)

Free-up mempory for an existing mpg123_string

Parameters
sbstring handle

Definition at line 25 of file stringbuf.c.

Referenced by convert_latin1(), convert_utf16bom(), convert_utf8(), free_mpg123_picture(), free_mpg123_text(), mpg123_store_utf8(), and store_id3_text().

26 {
27  if(!sb)
28  return;
29  if(sb->p != NULL) free(sb->p);
31 }
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:557
void attribute_align_arg mpg123_init_string(mpg123_string *sb)
Definition: stringbuf.c:17
char * p
Definition: mpg123.h:1011
MPG123_EXPORT int mpg123_grow_string ( mpg123_string sb,
size_t  news 
)

Increase size of a mpg123_string if necessary (it may stay larger). Note that the functions for adding and setting in current libmpg123 use this instead of mpg123_resize_string(). That way, you can preallocate memory and safely work afterwards with pieces.

Parameters
sbstring handle
newsnew minimum size
Returns
0 on error, 1 on success

Definition at line 33 of file stringbuf.c.

Referenced by mpg123_add_substring().

34 {
35  if(!sb)
36  return 0;
37  if(sb->size < new) return mpg123_resize_string(sb, new);
38  else return 1;
39 }
size_t size
Definition: mpg123.h:1012
int attribute_align_arg mpg123_resize_string(mpg123_string *sb, size_t new)
Definition: stringbuf.c:41
MPG123_EXPORT int mpg123_icy ( mpg123_handle mh,
char **  icy_meta 
)

Point icy_meta to existing data structure wich may change on any next read/decode function call.

Parameters
mhhandle
icy_metareturn address for ICY meta string (set to NULL if nothing there)
Returns
MPG123_OK on success

Definition at line 1465 of file libmpg123.c.

1466 {
1467  if(mh == NULL) return MPG123_BAD_HANDLE;
1468 #ifndef NO_ICY
1469  if(icy_meta == NULL)
1470  {
1471  mh->err = MPG123_NULL_POINTER;
1472  return MPG123_ERR;
1473  }
1474  *icy_meta = NULL;
1475 
1476  if(mh->metaflags & MPG123_ICY)
1477  {
1478  *icy_meta = mh->icy.data;
1479  mh->metaflags |= MPG123_ICY;
1480  mh->metaflags &= ~MPG123_NEW_ICY;
1481  }
1482  return MPG123_OK;
1483 #else
1485  return MPG123_ERR;
1486 #endif
1487 }
Definition: icy.h:16
#define MPG123_NEW_ICY
Definition: mpg123.h:1243
struct icy_meta icy
Definition: frame.h:299
smooth NULL
Definition: ftsmooth.c:557
#define MPG123_ICY
Definition: mpg123.h:1242
MPG123_EXPORT char* mpg123_icy2utf8 ( const char icy_text)

Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8. Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .

Parameters
icy_textThe input data in ICY encoding
Returns
pointer to newly allocated buffer with UTF-8 data (You free() it!)

Definition at line 1489 of file libmpg123.c.

1490 {
1491 #ifndef NO_ICY
1492  return icy2utf8(icy_text, 0);
1493 #else
1494  return NULL;
1495 #endif
1496 }
smooth NULL
Definition: ftsmooth.c:557
#define icy2utf8
Definition: intsym.h:197
MPG123_EXPORT int mpg123_id3 ( mpg123_handle mh,
mpg123_id3v1 **  v1,
mpg123_id3v2 **  v2 
)

Point v1 and v2 to existing data structures wich may change on any next read/decode function call. v1 and/or v2 can be set to NULL when there is no corresponding data.

Returns
MPG123_OK on success

Definition at line 1442 of file libmpg123.c.

1443 {
1444  if(v1 != NULL) *v1 = NULL;
1445  if(v2 != NULL) *v2 = NULL;
1446  if(mh == NULL) return MPG123_BAD_HANDLE;
1447 
1448  if(mh->metaflags & MPG123_ID3)
1449  {
1450  id3_link(mh);
1451  if(v1 != NULL && mh->rdat.flags & READER_ID3TAG) *v1 = (mpg123_id3v1*) mh->id3buf;
1452  if(v2 != NULL)
1453 #ifdef NO_ID3V2
1454  *v2 = NULL;
1455 #else
1456  *v2 = &mh->id3v2;
1457 #endif
1458 
1459  mh->metaflags |= MPG123_ID3;
1460  mh->metaflags &= ~MPG123_NEW_ID3;
1461  }
1462  return MPG123_OK;
1463 }
struct reader_data rdat
Definition: frame.h:286
#define id3_link
Definition: intsym.h:204
#define MPG123_NEW_ID3
Definition: mpg123.h:1241
smooth NULL
Definition: ftsmooth.c:557
#define READER_ID3TAG
Definition: reader.h:114
#define MPG123_ID3
Definition: mpg123.h:1240
mpg123_id3v2 id3v2
Definition: frame.h:296
unsigned char id3buf[128]
Definition: frame.h:294
MPG123_EXPORT void mpg123_init_string ( mpg123_string sb)

Create and allocate memory for a new mpg123_string

Parameters
sbstring handle (address of existing structure on your side)

Definition at line 17 of file stringbuf.c.

Referenced by init_mpg123_picture(), init_mpg123_text(), mpg123_free_string(), and mpg123_resize_string().

18 {
19  /* Handing in NULL here is a fatal mistake and rightfully so. */
20  sb->p = NULL;
21  sb->size = 0;
22  sb->fill = 0;
23 }
size_t size
Definition: mpg123.h:1012
smooth NULL
Definition: ftsmooth.c:557
size_t fill
Definition: mpg123.h:1013
char * p
Definition: mpg123.h:1011
MPG123_EXPORT int mpg123_meta_check ( mpg123_handle mh)

Query if there is (new) meta info, be it ID3 or ICY (or something new in future).

Parameters
mhhandle
Returns
combination of flags, 0 on error (same as "nothing new")

Definition at line 1428 of file libmpg123.c.

1429 {
1430  if(mh != NULL) return mh->metaflags;
1431  else return 0;
1432 }
smooth NULL
Definition: ftsmooth.c:557
MPG123_EXPORT void mpg123_meta_free ( mpg123_handle mh)

Clean up meta data storage (ID3v2 and ICY), freeing memory.

Parameters
mhhandle

Definition at line 1434 of file libmpg123.c.

1435 {
1436  if(mh == NULL) return;
1437 
1438  reset_id3(mh);
1439  reset_icy(&mh->icy);
1440 }
#define reset_id3
Definition: intsym.h:203
#define reset_icy
Definition: intsym.h:200
struct icy_meta icy
Definition: frame.h:299
smooth NULL
Definition: ftsmooth.c:557
MPG123_EXPORT int mpg123_resize_string ( mpg123_string sb,
size_t  news 
)

Change the size of a mpg123_string

Parameters
sbstring handle
newsnew size in bytes
Returns
0 on error, 1 on success

Definition at line 41 of file stringbuf.c.

Referenced by convert_latin1(), convert_utf16bom(), convert_utf8(), mpg123_copy_string(), mpg123_grow_string(), and store_id3_text().

42 {
43  if(!sb)
44  return 0;
45  debug3("resizing string pointer %p from %lu to %lu", (void*) sb->p, (unsigned long)sb->size, (unsigned long)new);
46  if(new == 0)
47  {
48  if(sb->size && sb->p != NULL) free(sb->p);
50  return 1;
51  }
52  if(sb->size != new)
53  {
54  char* t;
55  debug("really!");
56  t = (char*) safe_realloc(sb->p, new*sizeof(char));
57  debug1("safe_realloc returned %p", (void*) t);
58  if(t != NULL)
59  {
60  sb->p = t;
61  sb->size = new;
62  return 1;
63  }
64  else return 0;
65  }
66  else return 1; /* success */
67 }
#define free
Definition: debug_ros.c:5
GLdouble GLdouble t
Definition: gl.h:2047
#define safe_realloc
Definition: intsym.h:10
size_t size
Definition: mpg123.h:1012
#define debug3(s, a, b, c)
Definition: debug.h:54
smooth NULL
Definition: ftsmooth.c:557
void attribute_align_arg mpg123_init_string(mpg123_string *sb)
Definition: stringbuf.c:17
#define debug(msg)
Definition: key_call.c:71
#define debug1(s, a)
Definition: debug.h:52
char * p
Definition: mpg123.h:1011
MPG123_EXPORT int mpg123_set_string ( mpg123_string sb,
const char stuff 
)

Set the content of a mpg123_string to a C-string

Parameters
sbstring handle
stuffcontent to copy
Returns
0 on error, 1 on success

Definition at line 141 of file stringbuf.c.

Referenced by mpg123_store_utf8().

142 {
143  if(!sb)
144  return 0;
145  sb->fill = 0;
146  return mpg123_add_string(sb, stuff);
147 }
int attribute_align_arg mpg123_add_string(mpg123_string *sb, const char *stuff)
Definition: stringbuf.c:98
size_t fill
Definition: mpg123.h:1013
MPG123_EXPORT int mpg123_set_substring ( mpg123_string sb,
const char stuff,
size_t  from,
size_t  count 
)

Set the content of a mpg123_string to a C-substring

Parameters
sbstring handle
stuffthe future content
fromoffset to copy from
countnumber of characters to copy (a null-byte is always appended)
Returns
0 on error, 1 on success

Definition at line 133 of file stringbuf.c.

134 {
135  if(!sb)
136  return 0;
137  sb->fill = 0;
138  return mpg123_add_substring(sb, stuff, from, count);
139 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
CardRegion * from
Definition: spigame.cpp:19
size_t fill
Definition: mpg123.h:1013
int attribute_align_arg mpg123_add_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count)
Definition: stringbuf.c:104
MPG123_EXPORT int mpg123_store_utf8 ( mpg123_string sb,
enum mpg123_text_encoding  enc,
const unsigned char source,
size_t  source_size 
)

Store text data in string, after converting to UTF-8 from indicated encoding 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). Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).

Parameters
sbtarget string
encmpg123 text encoding value
sourcesource buffer with plain unsigned bytes (you might need to cast from signed char)
source_sizenumber of bytes in the source buffer
Returns
0 on error, 1 on success (on error, mpg123_free_string is called on sb)

Definition at line 1512 of file libmpg123.c.

1513 {
1514  switch(enc)
1515  {
1516 #ifndef NO_ID3V2
1517  /* The encodings we get from ID3v2 tags. */
1518  case mpg123_text_utf8:
1519  id3_to_utf8(sb, mpg123_id3_utf8, source, source_size, 0);
1520  break;
1521  case mpg123_text_latin1:
1522  id3_to_utf8(sb, mpg123_id3_latin1, source, source_size, 0);
1523  break;
1524  case mpg123_text_utf16bom:
1525  case mpg123_text_utf16:
1526  id3_to_utf8(sb, mpg123_id3_utf16bom, source, source_size, 0);
1527  break;
1528  /* Special because one cannot skip zero bytes here. */
1529  case mpg123_text_utf16be:
1530  id3_to_utf8(sb, mpg123_id3_utf16be, source, source_size, 0);
1531  break;
1532 #endif
1533 #ifndef NO_ICY
1534  /* ICY encoding... */
1535  case mpg123_text_icy:
1536  case mpg123_text_cp1252:
1537  {
1538  mpg123_free_string(sb);
1539  /* Paranoia: Make sure that the string ends inside the buffer... */
1540  if(source[source_size-1] == 0)
1541  {
1542  /* Convert from ICY encoding... with force applied or not. */
1543  char *tmpstring = icy2utf8((const char*)source, enc == mpg123_text_cp1252 ? 1 : 0);
1544  if(tmpstring != NULL)
1545  {
1546  mpg123_set_string(sb, tmpstring);
1547  free(tmpstring);
1548  }
1549  }
1550  }
1551  break;
1552 #endif
1553  default:
1554  mpg123_free_string(sb);
1555  }
1556  /* At least a trailing null of some form should be there... */
1557  return (sb->fill > 0) ? 1 : 0;
1558 }
#define free
Definition: debug_ros.c:5
MPG123_EXPORT void mpg123_free_string(mpg123_string *sb)
Definition: stringbuf.c:25
#define id3_to_utf8
Definition: intsym.h:206
smooth NULL
Definition: ftsmooth.c:557
MPG123_EXPORT int mpg123_set_string(mpg123_string *sb, const char *stuff)
Definition: stringbuf.c:141
#define icy2utf8
Definition: intsym.h:197
size_t fill
Definition: mpg123.h:1013
MPG123_EXPORT size_t mpg123_strlen ( mpg123_string sb,
int  utf8 
)

Count characters in a mpg123 string (non-null bytes or UTF-8 characters). Even with the fill property, the character count is not obvious as there could be multiple trailing null bytes.

Parameters
sbstring handle
utf8a flag to tell if the string is in utf8 encoding
Returns
character count

Definition at line 149 of file stringbuf.c.

150 {
151  size_t i;
152  size_t bytelen;
153 
154  /* Notions of empty string. If there's only a single character, it has to be the trailing zero, and if the first is the trailing zero anyway, we got empty. */
155  if(!sb || sb->fill < 2 || sb->p[0] == 0) return 0;
156 
157  /* Find the first non-null character from the back.
158  We already established that the first character is non-null
159  That at fill-2 has to be null, though. */
160  for(i=sb->fill-2; i>0; --i)
161  if(sb->p[i] != 0) break;
162 
163  /* For simple byte strings, we are done now. */
164  bytelen = i+1;
165 
166  if(!utf8) return bytelen;
167  else
168  {
169  /* Work out the actual count of UTF8 bytes.
170  This employs no particular encoding error checking. */
171  size_t len = 0;
172  for(i=0; i<bytelen; ++i)
173  {
174  /* Every byte that is not a continuation byte ( 0xc0 == 10xx xxxx ) stands for a character. */
175  if((sb->p[i] & 0xc0) != 0x80) len++;
176  }
177  return len;
178  }
179 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GLenum GLsizei len
Definition: glext.h:6722
size_t fill
Definition: mpg123.h:1013
char * p
Definition: mpg123.h:1011