source: roaraudio/libroar/meta.c @ 3044:b954d2ac330b

Last change on this file since 3044:b954d2ac330b was 3044:b954d2ac330b, checked in by phi, 14 years ago

added meta data tags SIGNALINFO (with alias AUDIOINFO) and OFFSET

File size: 6.7 KB
Line 
1//meta.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 *  NOTE for everyone want's to change something and send patches:
24 *  read README and HACKING! There a addition information on
25 *  the license of this document you need to read before you send
26 *  any patches.
27 *
28 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
29 *  or libpulse*:
30 *  The libs libroaresd, libroararts and libroarpulse link this lib
31 *  and are therefore GPL. Because of this it may be illigal to use
32 *  them with any software that uses libesd, libartsc or libpulse*.
33 */
34
35#include "libroar.h"
36
37/*
38
39grep ^'#define ROAR_META_TYPE_' meta.h | cut -d' ' -f2 | while read line; do printf ' {%-30s     "%-16s},\n' $line, $(echo $line | cut -d_ -f4)\"; done
40
41*/
42
43struct {
44 int    id;
45 char * name;
46} _libroar_meta_typelist[] = {
47 {ROAR_META_TYPE_NONE,               "NONE"           },
48 {ROAR_META_TYPE_TITLE,              "TITLE"          },
49 {ROAR_META_TYPE_ALBUM,              "ALBUM"          },
50 {ROAR_META_TYPE_AUTHOR,             "AUTHOR"         },
51 {ROAR_META_TYPE_AUTOR,              "AUTOR"          },
52 {ROAR_META_TYPE_ARTIST,             "ARTIST"         },
53 {ROAR_META_TYPE_VERSION,            "VERSION"        },
54 {ROAR_META_TYPE_DATE,               "DATE"           },
55 {ROAR_META_TYPE_LICENSE,            "LICENSE"        },
56 {ROAR_META_TYPE_TRACKNUMBER,        "TRACKNUMBER"    },
57 {ROAR_META_TYPE_ORGANIZATION,       "ORGANIZATION"   },
58 {ROAR_META_TYPE_DESCRIPTION,        "DESCRIPTION"    },
59 {ROAR_META_TYPE_GENRE,              "GENRE"          },
60 {ROAR_META_TYPE_LOCATION,           "LOCATION"       },
61 {ROAR_META_TYPE_CONTACT,            "CONTACT"        },
62 {ROAR_META_TYPE_STREAMURL,          "STREAMURL"      },
63 {ROAR_META_TYPE_HOMEPAGE,           "HOMEPAGE"       },
64 {ROAR_META_TYPE_THUMBNAIL,          "THUMBNAIL"      },
65 {ROAR_META_TYPE_LENGTH,             "LENGTH"         },
66 {ROAR_META_TYPE_COMMENT,            "COMMENT"        },
67 {ROAR_META_TYPE_OTHER,              "OTHER"          },
68 {ROAR_META_TYPE_FILENAME,           "FILENAME"       },
69 {ROAR_META_TYPE_FILEURL,            "FILEURL"        },
70 {ROAR_META_TYPE_SERVER,             "SERVER"         },
71 {ROAR_META_TYPE_DURATION,           "DURATION"       },
72 {ROAR_META_TYPE_WWW,                "WWW"            },
73 {ROAR_META_TYPE_WOAF,               "WOAF"           },
74 {ROAR_META_TYPE_ENCODER,            "ENCODER"        },
75 {ROAR_META_TYPE_ENCODEDBY,          "ENCODEDBY"      },
76 {ROAR_META_TYPE_YEAR,               "YEAR"           },
77 {ROAR_META_TYPE_DISCID,             "DISCID"         },
78 {ROAR_META_TYPE_RPG_TRACK_PEAK,     "REPLAYGAIN_TRACK_PEAK" },
79 {ROAR_META_TYPE_RPG_TRACK_GAIN,     "REPLAYGAIN_TRACK_GAIN" },
80 {ROAR_META_TYPE_RPG_ALBUM_PEAK,     "REPLAYGAIN_ALBUM_PEAK" },
81 {ROAR_META_TYPE_RPG_ALBUM_GAIN,     "REPLAYGAIN_ALBUM_GAIN" },
82 {ROAR_META_TYPE_HASH,               "HASH"           },
83 {ROAR_META_TYPE_SIGNALINFO,         "SIGNALINFO"     },
84 {ROAR_META_TYPE_AUDIOINFO,          "AUDIOINFO"      },
85 {ROAR_META_TYPE_OFFSET,             "OFFSET"         },
86 
87 {-1, "EOL"}
88};
89
90char * roar_meta_strtype(int type) {
91 int i;
92 static char name[ROAR_META_MAX_NAMELEN];
93
94 for (i = 0; _libroar_meta_typelist[i].id != -1; i++)
95  if ( _libroar_meta_typelist[i].id == type ) {
96   strncpy(name, _libroar_meta_typelist[i].name, ROAR_META_MAX_NAMELEN);
97   return name;
98  }
99
100 return NULL;
101}
102
103int    roar_meta_inttype(char * type) {
104 int i;
105
106 for (i = 0; _libroar_meta_typelist[i].id != -1; i++)
107  if ( strcasecmp(_libroar_meta_typelist[i].name, type) == 0 ) {
108   return _libroar_meta_typelist[i].id;
109  }
110
111 return -1;
112}
113
114int roar_stream_meta_set (struct roar_connection * con, struct roar_stream * s, int mode, struct roar_meta * meta) {
115 struct roar_message m;
116 int len;
117
118 memset(&m, 0, sizeof(struct roar_message)); // make valgrind happy!
119
120 m.cmd     = ROAR_CMD_SET_META;
121 m.stream  = s->id;
122// m.datalen = len;
123
124 if ( (mode == ROAR_META_MODE_FINALIZE || mode == ROAR_META_MODE_CLEAR) && meta->value == NULL )
125  meta->value = "";
126
127 if ( meta->value == NULL )
128   return -1;
129
130 m.data[0] = 0;
131 m.data[1] = mode;
132 m.data[2] = meta->type;
133
134 m.data[3] = strlen(meta->key);
135 m.data[4] = len = strlen(meta->value);
136
137 if ( len > 255 )
138  return -1;
139
140 m.datalen = (int) 5 + (int) m.data[3] + len;
141 if ( m.datalen > LIBROAR_BUFFER_MSGDATA )
142  return -1;
143
144 strncpy(&(m.data[5]), meta->key, ROAR_META_MAX_NAMELEN);
145 strncpy(&(m.data[5+m.data[3]]), meta->value, len);
146
147 ROAR_DBG("roar_stream_meta_set(*): meta value length is %i byte", len);
148 ROAR_DBG("roar_stream_meta_set(*): message data length is %i byte", m.datalen);
149
150 if ( roar_req(con, &m, NULL) == -1 )
151  return -1;
152
153 if ( m.cmd == ROAR_CMD_OK )
154  return 0;
155 return -1;
156}
157
158int roar_stream_meta_get (struct roar_connection * con, struct roar_stream * s, struct roar_meta * meta) {
159 struct roar_message m;
160 char * c;
161
162 m.cmd     = ROAR_CMD_GET_META;
163 m.stream  = s->id;
164// m.datalen = len;
165
166 m.data[0] = 0;
167 m.data[1] = meta->type;
168 m.datalen = 2;
169
170 if ( roar_req(con, &m, NULL) == -1 )
171  return -1;
172
173 if ( m.cmd != ROAR_CMD_OK )
174  return -1;
175
176 if ( m.datalen < 2 )
177  return -1;
178
179 if ( m.data[0] != 0 )
180  return -1;
181
182 if ( (c = malloc(((unsigned) m.data[1]) + 1)) == NULL )
183  return -1;
184
185 strncpy(c, &(m.data[2]), (unsigned) m.data[1]);
186 c[(unsigned) m.data[1]] = 0;
187
188 meta->value  = c;
189 meta->key[0] = 0;
190
191 return 0;
192}
193
194int roar_stream_meta_list (struct roar_connection * con, struct roar_stream * s, int * types, size_t len) {
195 int i;
196 struct roar_message m;
197
198 m.cmd     = ROAR_CMD_LIST_META;
199 m.stream  = s->id;
200 m.pos     = 0;
201
202 m.data[0] = 0;
203 m.datalen = 1;
204
205 if ( roar_req(con, &m, NULL) == -1 )
206  return -1;
207
208 if ( m.cmd != ROAR_CMD_OK )
209  return -1;
210
211 if ( m.datalen < 1 )
212  return -1;
213
214 if ( m.data[0] != 0 )
215  return -1;
216
217 if ( len < (m.datalen - 1 ) )
218  return -1;
219
220 for (i = 1; i < m.datalen; i++)
221  types[i-1] = (unsigned) m.data[i];
222
223 return m.datalen - 1;
224}
225
226int roar_meta_free (struct roar_meta * meta) {
227 if ( meta->value )
228  free(meta->value);
229
230 return 0;
231}
232
233//ll
Note: See TracBrowser for help on using the repository browser.