source: roaraudio/roard/meta.c @ 4708:c9d40761088a

Last change on this file since 4708:c9d40761088a was 4708:c9d40761088a, checked in by phi, 13 years ago

updated copyright statements

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