[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 | |
---|
[1493] | 27 | #ifdef ROAR_SUPPORT_META |
---|
| 28 | |
---|
[90] | 29 | int stream_meta_set (int id, int type, char * name, char * val) { |
---|
| 30 | int i; |
---|
| 31 | struct roar_stream_server * s = g_streams[id]; |
---|
| 32 | |
---|
| 33 | if ( s == NULL ) |
---|
| 34 | return -1; |
---|
| 35 | |
---|
| 36 | for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) |
---|
| 37 | if ( s->meta[i].type == type ) { |
---|
| 38 | s->meta[i].type = ROAR_META_TYPE_NONE; |
---|
| 39 | if ( s->meta[i].value ) |
---|
| 40 | free(s->meta[i].value); |
---|
| 41 | s->meta[i].value = NULL; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | return stream_meta_add(id, type, name, val); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | int stream_meta_add (int id, int type, char * name, char * val) { |
---|
| 48 | int i; |
---|
| 49 | char * c; |
---|
| 50 | struct roar_stream_server * s = g_streams[id]; |
---|
| 51 | |
---|
| 52 | if ( s == NULL ) |
---|
| 53 | return -1; |
---|
| 54 | |
---|
| 55 | for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) { |
---|
| 56 | if ( s->meta[i].type == ROAR_META_TYPE_NONE ) { |
---|
| 57 | s->meta[i].type = type; |
---|
| 58 | |
---|
| 59 | if ( name == NULL ) { |
---|
| 60 | s->meta[i].key[0] = 0; |
---|
| 61 | } else { |
---|
| 62 | strncpy(s->meta[i].key, name, ROAR_META_MAX_NAMELEN); |
---|
| 63 | } |
---|
| 64 | |
---|
[107] | 65 | if ( (c = malloc(strlen(val)+1)) == NULL ) { |
---|
[90] | 66 | s->meta[i].type = ROAR_META_TYPE_NONE; |
---|
| 67 | s->meta[i].key[0] = 0; |
---|
| 68 | return -1; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | strcpy(c, val); |
---|
| 72 | s->meta[i].value = c; |
---|
| 73 | |
---|
[96] | 74 | ROAR_DBG("stream_meta_add(id=%i, type=%i, name='%s', val='%s') = 0", id, type, name, val); |
---|
| 75 | |
---|
[90] | 76 | return 0; |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | return -1; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | int stream_meta_get (int id, int type, char * name, char * val, size_t len) { |
---|
[107] | 84 | int i, vallen; |
---|
[90] | 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 | |
---|
[113] | 96 | if ( s->meta[i].value == NULL ) |
---|
| 97 | return -1; |
---|
| 98 | |
---|
[107] | 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); |
---|
[90] | 101 | return -1; |
---|
[107] | 102 | } |
---|
[90] | 103 | |
---|
[107] | 104 | strncpy(val, s->meta[i].value, vallen); |
---|
| 105 | val[vallen] = 0; |
---|
[90] | 106 | |
---|
| 107 | return 0; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | return -1; |
---|
| 112 | } |
---|
| 113 | |
---|
[113] | 114 | int 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 | |
---|
[90] | 143 | int stream_meta_clear (int id) { |
---|
| 144 | int i; |
---|
[486] | 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]; |
---|
[90] | 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 | |
---|
[1038] | 168 | int stream_meta_finalize(int id) { |
---|
[1040] | 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 | } |
---|
[1238] | 227 | |
---|
| 228 | // ask the codec filter to update meta data: |
---|
| 229 | streams_ctl(co, ROAR_CODECFILTER_CTL_META_UPDATE, NULL); // ignore errors... |
---|
[1040] | 230 | } |
---|
| 231 | |
---|
[1038] | 232 | return 0; |
---|
| 233 | } |
---|
| 234 | |
---|
[1493] | 235 | #endif |
---|
| 236 | |
---|
[88] | 237 | //ll |
---|