[88] | 1 | //meta.c: |
---|
| 2 | |
---|
[668] | 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 | |
---|
[88] | 25 | #include "roard.h" |
---|
| 26 | |
---|
[90] | 27 | int 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 | |
---|
| 45 | int 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 | |
---|
[107] | 63 | if ( (c = malloc(strlen(val)+1)) == NULL ) { |
---|
[90] | 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 | |
---|
[96] | 72 | ROAR_DBG("stream_meta_add(id=%i, type=%i, name='%s', val='%s') = 0", id, type, name, val); |
---|
| 73 | |
---|
[90] | 74 | return 0; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | return -1; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | int stream_meta_get (int id, int type, char * name, char * val, size_t len) { |
---|
[107] | 82 | int i, vallen; |
---|
[90] | 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 | |
---|
[113] | 94 | if ( s->meta[i].value == NULL ) |
---|
| 95 | return -1; |
---|
| 96 | |
---|
[107] | 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); |
---|
[90] | 99 | return -1; |
---|
[107] | 100 | } |
---|
[90] | 101 | |
---|
[107] | 102 | strncpy(val, s->meta[i].value, vallen); |
---|
| 103 | val[vallen] = 0; |
---|
[90] | 104 | |
---|
| 105 | return 0; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | return -1; |
---|
| 110 | } |
---|
| 111 | |
---|
[113] | 112 | int 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 | |
---|
[90] | 141 | int stream_meta_clear (int id) { |
---|
| 142 | int i; |
---|
[486] | 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]; |
---|
[90] | 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 | |
---|
[88] | 166 | //ll |
---|