source: roaraudio/roard/meta.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

File size: 5.7 KB
Line 
1//meta.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard 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 *  RoarAudio 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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28#ifdef ROAR_SUPPORT_META
29
30int stream_meta_set   (int id, int type, char * name, char * val) {
31 int i;
32 struct roar_stream_server * s = g_streams[id];
33
34 if ( s == NULL )
35  return -1;
36
37 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++)
38  if ( s->meta[i].type == type ) {
39   s->meta[i].type = ROAR_META_TYPE_NONE;
40   if ( s->meta[i].value )
41    free(s->meta[i].value);
42   s->meta[i].value = NULL;
43  }
44
45 return stream_meta_add(id, type, name, val);
46}
47
48int stream_meta_add   (int id, int type, char * name, char * val) {
49 int i;
50 char * c;
51 struct roar_stream_server * s = g_streams[id];
52
53 if ( s == NULL )
54  return -1;
55
56 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
57  if ( s->meta[i].type == ROAR_META_TYPE_NONE ) {
58   s->meta[i].type = type;
59
60   if ( name == NULL ) {
61    s->meta[i].key[0] = 0;
62   } else {
63    strncpy(s->meta[i].key, name, ROAR_META_MAX_NAMELEN);
64   }
65
66   if ( (c = malloc(strlen(val)+1)) == NULL ) {
67    s->meta[i].type = ROAR_META_TYPE_NONE;
68    s->meta[i].key[0] = 0;
69    return -1;
70   }
71
72   strcpy(c, val);
73   s->meta[i].value = c;
74
75   ROAR_DBG("stream_meta_add(id=%i, type=%i, name='%s', val='%s') = 0", id, type, name, val);
76
77   return 0;
78  }
79 }
80
81 return -1;
82}
83
84int stream_meta_get   (int id, int type, char * name, char * val, size_t len) {
85 int i, vallen;
86 struct roar_stream_server * s = g_streams[id];
87
88 if ( s == NULL )
89  return -1;
90
91 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
92  if ( s->meta[i].type == type ) {
93   if ( name != NULL )
94    if ( strncmp(s->meta[i].key, name, ROAR_META_MAX_NAMELEN) != 0 )
95     continue;
96
97   if ( s->meta[i].value == NULL )
98    return -1;
99
100   if ( (vallen = strlen(s->meta[i].value)) > (len - 1) ) {
101    ROAR_DBG("stream_meta_get(*): val too small: need %i have %i", vallen, len);
102    return -1;
103   }
104
105   strncpy(val, s->meta[i].value, vallen);
106   val[vallen] = 0;
107
108   return 0;
109  }
110 }
111
112 return -1;
113}
114
115int stream_meta_list  (int id, int * types, size_t len) {
116 int i, j;
117 int have = 0;
118 int found;
119 struct roar_stream_server * s = g_streams[id];
120
121 if ( s == NULL )
122  return -1;
123
124 if ( len < ROAR_META_MAX_PER_STREAM ) // TODO: find a way we do not need this
125  return -1;
126
127 types[0] = -1;
128
129 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
130  found = 0;
131  for (j = 0; j < have; j++)
132   if ( types[j] == s->meta[i].type ) {
133    found = 1;
134    break;
135   }
136
137  if ( !found )
138   types[have++] = s->meta[i].type;
139 }
140
141 return have;
142}
143
144int stream_meta_clear (int id) {
145 int i;
146 struct roar_stream_server * s = NULL;
147
148 if ( id < 0 || id > ROAR_STREAMS_MAX ) {
149  ROAR_ERR("stream_meta_clear(id=%i): Can not clear meta data on stream: invalid stream ID", id);
150  return -1;
151 }
152
153 s = g_streams[id];
154
155 if ( s == NULL )
156  return -1;
157
158 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
159  s->meta[i].type   = ROAR_META_TYPE_NONE;
160  if ( s->meta[i].value )
161   free(s->meta[i].value);
162  s->meta[i].value  = NULL;
163  s->meta[i].key[0] = 0;
164 }
165
166 return 0;
167}
168
169int stream_meta_finalize(int id) {
170 register int dir;
171 register int co, ci, i;
172 struct roar_stream_server * s;
173
174 if ( streams_get_flag(id, ROAR_FLAG_META) != 1 ) // ignore non meta streams
175  return 0;
176
177 dir = ROAR_STREAM(g_streams[id])->dir;
178
179 if ( dir != ROAR_DIR_PLAY   && dir != ROAR_DIR_META &&  // ignore on non input streams
180      dir != ROAR_DIR_FILTER && dir != ROAR_DIR_BIDIR )
181  return 0;
182
183 ROAR_DBG("stream_meta_finalize(id=%i) = ?", id);
184
185 for (co = 0; co < ROAR_STREAMS_MAX; co++) {
186  if ( g_streams[co] == NULL )
187   continue;
188
189  dir = ROAR_STREAM(g_streams[co])->dir;
190
191  if ( dir != ROAR_DIR_MONITOR && dir != ROAR_DIR_FILTER &&
192       dir != ROAR_DIR_META    && dir != ROAR_DIR_BIDIR  &&
193       dir != ROAR_DIR_OUTPUT                             )
194   continue;
195
196  if ( streams_get_flag(co, ROAR_FLAG_META) != 1 )
197   continue;
198
199  ROAR_DBG("stream_meta_finalize(id=%i): found output stream: id=%i", id, co);
200  stream_meta_clear(co);
201
202  for (ci = 0; ci < ROAR_STREAMS_MAX; ci++) {
203   if ( g_streams[ci] == NULL )
204    continue;
205
206   dir = ROAR_STREAM(g_streams[ci])->dir;
207
208   if ( dir != ROAR_DIR_PLAY   && dir != ROAR_DIR_META &&
209        dir != ROAR_DIR_FILTER && dir != ROAR_DIR_BIDIR )
210    continue;
211
212   if ( streams_get_flag(ci, ROAR_FLAG_META) != 1 )
213    continue;
214
215   ROAR_DBG("stream_meta_finalize(id=%i): found input stream: id=%i", id, ci);
216
217   // ok, next we copy the date of ci to co:
218   s = g_streams[ci];
219
220   for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
221    if ( s->meta[i].type == ROAR_META_TYPE_NONE )
222     continue;
223
224    ROAR_DBG("stream_meta_finalize(id=%i): found meta data, copy: %i->%i", id, ci, co);
225    stream_meta_add(co, s->meta[i].type, s->meta[i].key, s->meta[i].value); // ignore errors
226   }
227  }
228
229  // ask the codec filter to update meta data:
230  ROAR_DBG("stream_meta_finalize(id=%i): Asking stream %i to update meta data", id, co);
231  streams_ctl(co, ROAR_CODECFILTER_CTL_META_UPDATE, NULL); // ignore errors...
232 }
233
234 return 0;
235}
236
237#endif
238
239//ll
Note: See TracBrowser for help on using the repository browser.