source: roaraudio/roard/meta.c @ 5586:5b82b3417705

Last change on this file since 5586:5b82b3417705 was 5586:5b82b3417705, checked in by phi, 12 years ago

general cleanup for -Wextra

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