source: roaraudio/roard/meta.c @ 1038:3b27c9b36f14

Last change on this file since 1038:3b27c9b36f14 was 1038:3b27c9b36f14, checked in by phi, 15 years ago

added stream_meta_finalize(), ROAR_META_MODE_FINALIZE

File size: 3.8 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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27int stream_meta_set   (int id, int type, char * name, char * val) {
28 int i;
29 struct roar_stream_server * s = g_streams[id];
30
31 if ( s == NULL )
32  return -1;
33
34 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++)
35  if ( s->meta[i].type == type ) {
36   s->meta[i].type = ROAR_META_TYPE_NONE;
37   if ( s->meta[i].value )
38    free(s->meta[i].value);
39   s->meta[i].value = NULL;
40  }
41
42 return stream_meta_add(id, type, name, val);
43}
44
45int stream_meta_add   (int id, int type, char * name, char * val) {
46 int i;
47 char * c;
48 struct roar_stream_server * s = g_streams[id];
49
50 if ( s == NULL )
51  return -1;
52
53 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
54  if ( s->meta[i].type == ROAR_META_TYPE_NONE ) {
55   s->meta[i].type = type;
56
57   if ( name == NULL ) {
58    s->meta[i].key[0] = 0;
59   } else {
60    strncpy(s->meta[i].key, name, ROAR_META_MAX_NAMELEN);
61   }
62
63   if ( (c = malloc(strlen(val)+1)) == NULL ) {
64    s->meta[i].type = ROAR_META_TYPE_NONE;
65    s->meta[i].key[0] = 0;
66    return -1;
67   }
68
69   strcpy(c, val);
70   s->meta[i].value = c;
71
72   ROAR_DBG("stream_meta_add(id=%i, type=%i, name='%s', val='%s') = 0", id, type, name, val);
73
74   return 0;
75  }
76 }
77
78 return -1;
79}
80
81int stream_meta_get   (int id, int type, char * name, char * val, size_t len) {
82 int i, vallen;
83 struct roar_stream_server * s = g_streams[id];
84
85 if ( s == NULL )
86  return -1;
87
88 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
89  if ( s->meta[i].type == type ) {
90   if ( name != NULL )
91    if ( strncmp(s->meta[i].key, name, ROAR_META_MAX_NAMELEN) != 0 )
92     continue;
93
94   if ( s->meta[i].value == NULL )
95    return -1;
96
97   if ( (vallen = strlen(s->meta[i].value)) > (len - 1) ) {
98    ROAR_DBG("stream_meta_get(*): val too small: need %i have %i", vallen, len);
99    return -1;
100   }
101
102   strncpy(val, s->meta[i].value, vallen);
103   val[vallen] = 0;
104
105   return 0;
106  }
107 }
108
109 return -1;
110}
111
112int stream_meta_list  (int id, int * types, size_t len) {
113 int i, j;
114 int have = 0;
115 int found;
116 struct roar_stream_server * s = g_streams[id];
117
118 if ( s == NULL )
119  return -1;
120
121 if ( len < ROAR_META_MAX_PER_STREAM ) // TODO: find a way we do not need this
122  return -1;
123
124 types[0] = -1;
125
126 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
127  found = 0;
128  for (j = 0; j < have; j++)
129   if ( types[j] == s->meta[i].type ) {
130    found = 1;
131    break;
132   }
133
134  if ( !found )
135   types[have++] = s->meta[i].type;
136 }
137
138 return have;
139}
140
141int stream_meta_clear (int id) {
142 int i;
143 struct roar_stream_server * s = NULL;
144
145 if ( id < 0 || id > ROAR_STREAMS_MAX ) {
146  ROAR_ERR("stream_meta_clear(id=%i): Can not clear meta data on stream: invalid stream ID", id);
147  return -1;
148 }
149
150 s = g_streams[id];
151
152 if ( s == NULL )
153  return -1;
154
155 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
156  s->meta[i].type   = ROAR_META_TYPE_NONE;
157  if ( s->meta[i].value )
158   free(s->meta[i].value);
159  s->meta[i].value  = NULL;
160  s->meta[i].key[0] = 0;
161 }
162
163 return 0;
164}
165
166int stream_meta_finalize(int id) {
167 return 0;
168}
169
170//ll
Note: See TracBrowser for help on using the repository browser.