source: roaraudio/roard/meta.c @ 113:a032ff209b90

Last change on this file since 113:a032ff209b90 was 113:a032ff209b90, checked in by phi, 16 years ago

added stream_meta_list() and done other support for listing meta tags on streams

File size: 2.7 KB
Line 
1//meta.c:
2
3#include "roard.h"
4
5int stream_meta_set   (int id, int type, char * name, char * val) {
6 int i;
7 struct roar_stream_server * s = g_streams[id];
8
9 if ( s == NULL )
10  return -1;
11
12 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++)
13  if ( s->meta[i].type == type ) {
14   s->meta[i].type = ROAR_META_TYPE_NONE;
15   if ( s->meta[i].value )
16    free(s->meta[i].value);
17   s->meta[i].value = NULL;
18  }
19
20 return stream_meta_add(id, type, name, val);
21}
22
23int stream_meta_add   (int id, int type, char * name, char * val) {
24 int i;
25 char * c;
26 struct roar_stream_server * s = g_streams[id];
27
28 if ( s == NULL )
29  return -1;
30
31 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
32  if ( s->meta[i].type == ROAR_META_TYPE_NONE ) {
33   s->meta[i].type = type;
34
35   if ( name == NULL ) {
36    s->meta[i].key[0] = 0;
37   } else {
38    strncpy(s->meta[i].key, name, ROAR_META_MAX_NAMELEN);
39   }
40
41   if ( (c = malloc(strlen(val)+1)) == NULL ) {
42    s->meta[i].type = ROAR_META_TYPE_NONE;
43    s->meta[i].key[0] = 0;
44    return -1;
45   }
46
47   strcpy(c, val);
48   s->meta[i].value = c;
49
50   ROAR_DBG("stream_meta_add(id=%i, type=%i, name='%s', val='%s') = 0", id, type, name, val);
51
52   return 0;
53  }
54 }
55
56 return -1;
57}
58
59int stream_meta_get   (int id, int type, char * name, char * val, size_t len) {
60 int i, vallen;
61 struct roar_stream_server * s = g_streams[id];
62
63 if ( s == NULL )
64  return -1;
65
66 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
67  if ( s->meta[i].type == type ) {
68   if ( name != NULL )
69    if ( strncmp(s->meta[i].key, name, ROAR_META_MAX_NAMELEN) != 0 )
70     continue;
71
72   if ( s->meta[i].value == NULL )
73    return -1;
74
75   if ( (vallen = strlen(s->meta[i].value)) > (len - 1) ) {
76    ROAR_DBG("stream_meta_get(*): val too small: need %i have %i", vallen, len);
77    return -1;
78   }
79
80   strncpy(val, s->meta[i].value, vallen);
81   val[vallen] = 0;
82
83   return 0;
84  }
85 }
86
87 return -1;
88}
89
90int stream_meta_list  (int id, int * types, size_t len) {
91 int i, j;
92 int have = 0;
93 int found;
94 struct roar_stream_server * s = g_streams[id];
95
96 if ( s == NULL )
97  return -1;
98
99 if ( len < ROAR_META_MAX_PER_STREAM ) // TODO: find a way we do not need this
100  return -1;
101
102 types[0] = -1;
103
104 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
105  found = 0;
106  for (j = 0; j < have; j++)
107   if ( types[j] == s->meta[i].type ) {
108    found = 1;
109    break;
110   }
111
112  if ( !found )
113   types[have++] = s->meta[i].type;
114 }
115
116 return have;
117}
118
119int stream_meta_clear (int id) {
120 int i;
121 struct roar_stream_server * s = g_streams[id];
122
123 if ( s == NULL )
124  return -1;
125
126 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
127  s->meta[i].type   = ROAR_META_TYPE_NONE;
128  if ( s->meta[i].value )
129   free(s->meta[i].value);
130  s->meta[i].value  = NULL;
131  s->meta[i].key[0] = 0;
132 }
133
134 return 0;
135}
136
137//ll
Note: See TracBrowser for help on using the repository browser.