[204] | 1 | //codecfilter_vorbis.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 | |
---|
[1185] | 25 | #define ROAR_REQUIRE_LIBVORBISFILE |
---|
| 26 | |
---|
[204] | 27 | #include "roard.h" |
---|
| 28 | |
---|
[362] | 29 | #ifdef ROAR_HAVE_LIBVORBISFILE |
---|
| 30 | |
---|
[741] | 31 | int _g_cf_vorbis_vfvio_return_err (void) { |
---|
| 32 | return -1; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | ov_callbacks _g_cf_vorbis_vfvio = { |
---|
| 36 | .read_func = cf_vorbis_vfvio_read, |
---|
[743] | 37 | .seek_func = (int (*)(void *, ogg_int64_t, int )) _g_cf_vorbis_vfvio_return_err, |
---|
| 38 | .close_func = (int (*)(void * )) _g_cf_vorbis_vfvio_return_err, |
---|
| 39 | .tell_func = (long (*)(void * )) _g_cf_vorbis_vfvio_return_err |
---|
[741] | 40 | }; |
---|
| 41 | |
---|
| 42 | size_t cf_vorbis_vfvio_read (void *ptr, size_t size, size_t nmemb, void *datasource) { |
---|
| 43 | ssize_t r; |
---|
[746] | 44 | |
---|
[741] | 45 | r = stream_vio_s_read(ROAR_STREAM_SERVER(datasource), ptr, size*nmemb); |
---|
| 46 | |
---|
[745] | 47 | ROAR_DBG("cf_vorbis_vfvio_read(ptr=%p, size=%lu, nmemb=%lu, datasource=%p): r=%i", ptr, size, nmemb, datasource, r); |
---|
[741] | 48 | |
---|
| 49 | if ( r == -1 ) |
---|
| 50 | return 0; |
---|
| 51 | |
---|
| 52 | if ( r > 0 ) |
---|
| 53 | errno = 0; |
---|
[744] | 54 | |
---|
| 55 | r /= size; |
---|
[741] | 56 | |
---|
[745] | 57 | ROAR_DBG("cf_vorbis_vfvio_read(ptr=%p, size=%lu, nmemb=%lu, datasource=%p) = %i", ptr, size, nmemb, datasource, r); |
---|
[744] | 58 | return r; |
---|
[741] | 59 | } |
---|
| 60 | |
---|
[205] | 61 | int cf_vorbis_open(CODECFILTER_USERDATA_T * inst, int codec, |
---|
| 62 | struct roar_stream_server * info, |
---|
| 63 | struct roar_codecfilter * filter) { |
---|
| 64 | struct codecfilter_vorbis_inst * self = malloc(sizeof(struct codecfilter_vorbis_inst)); |
---|
[569] | 65 | struct roar_stream * s = ROAR_STREAM(info); |
---|
[205] | 66 | |
---|
| 67 | if ( !self ) |
---|
| 68 | return -1; |
---|
| 69 | |
---|
| 70 | self->current_section = -1; |
---|
| 71 | self->last_section = -1; |
---|
[382] | 72 | self->opened = 0; |
---|
| 73 | self->got_it_running = 0; |
---|
[205] | 74 | self->stream = info; |
---|
| 75 | // self->outlen = ROAR_OUTPUT_BUFFER_SAMPLES * s->info.channels * s->info.bits / 8; // optimal size |
---|
[569] | 76 | #ifdef ROAR_HAVE_LIBVORBISENC |
---|
[1226] | 77 | self->encoding = 0; |
---|
| 78 | self->encoder.v_base_quality = 0.3; |
---|
[1238] | 79 | self->encoder.srn = -1; |
---|
[569] | 80 | #endif |
---|
[205] | 81 | |
---|
[486] | 82 | ROAR_DBG("cf_vorbis_open(*): info->id=%i", ROAR_STREAM(info)->id); |
---|
| 83 | |
---|
[205] | 84 | *inst = (CODECFILTER_USERDATA_T) self; |
---|
| 85 | |
---|
[569] | 86 | s->info.codec = ROAR_CODEC_DEFAULT; |
---|
| 87 | s->info.bits = 16; |
---|
| 88 | |
---|
| 89 | if ( s->dir == ROAR_DIR_PLAY ) { |
---|
| 90 | return 0; |
---|
[634] | 91 | } else if ( s->dir == ROAR_DIR_MONITOR || s->dir == ROAR_DIR_OUTPUT ) { |
---|
[569] | 92 | #ifdef ROAR_HAVE_LIBVORBISENC |
---|
| 93 | // set up the encoder here |
---|
[1226] | 94 | if ( cf_vorbis_encode_start(self) == -1 ) { |
---|
| 95 | free(self); |
---|
| 96 | return -1; |
---|
| 97 | } |
---|
[569] | 98 | #else |
---|
| 99 | free(self); |
---|
| 100 | return -1; |
---|
| 101 | #endif |
---|
| 102 | } else { |
---|
| 103 | free(self); |
---|
| 104 | return -1; |
---|
| 105 | } |
---|
[206] | 106 | |
---|
| 107 | return 0; |
---|
[205] | 108 | } |
---|
| 109 | |
---|
| 110 | int cf_vorbis_close(CODECFILTER_USERDATA_T inst) { |
---|
| 111 | struct codecfilter_vorbis_inst * self = (struct codecfilter_vorbis_inst *) inst; |
---|
| 112 | |
---|
| 113 | if ( !inst ) |
---|
| 114 | return -1; |
---|
| 115 | |
---|
[382] | 116 | if ( self->got_it_running ) |
---|
| 117 | ov_clear(&(self->vf)); |
---|
[205] | 118 | |
---|
[569] | 119 | #ifdef ROAR_HAVE_LIBVORBISENC |
---|
| 120 | if ( self->encoding ) { |
---|
[1226] | 121 | cf_vorbis_encode_end(self); |
---|
[569] | 122 | } |
---|
| 123 | #endif |
---|
| 124 | |
---|
[205] | 125 | free(inst); |
---|
[206] | 126 | return 0; |
---|
[205] | 127 | } |
---|
| 128 | |
---|
[582] | 129 | int cf_vorbis_write(CODECFILTER_USERDATA_T inst, char * buf, int len) { |
---|
| 130 | #ifdef ROAR_HAVE_LIBVORBISENC |
---|
| 131 | struct codecfilter_vorbis_inst * self = (struct codecfilter_vorbis_inst *) inst; |
---|
| 132 | struct roar_stream * s = ROAR_STREAM(self->stream); |
---|
| 133 | ogg_packet header; |
---|
| 134 | ogg_packet header_comm; |
---|
| 135 | ogg_packet header_code; |
---|
[586] | 136 | float ** encbuf; |
---|
| 137 | int i, c; |
---|
| 138 | int chans; |
---|
| 139 | int end; |
---|
| 140 | int16_t * data = (int16_t *) buf; |
---|
[582] | 141 | |
---|
[584] | 142 | if ( ! self->opened ) { |
---|
[582] | 143 | vorbis_analysis_headerout(&(self->encoder.vd), &(self->encoder.vc), &header, &header_comm, &header_code); |
---|
| 144 | |
---|
| 145 | ogg_stream_packetin(&(self->encoder.os), &header); |
---|
| 146 | ogg_stream_packetin(&(self->encoder.os), &header_comm); |
---|
| 147 | ogg_stream_packetin(&(self->encoder.os), &header_code); |
---|
| 148 | |
---|
| 149 | while (ogg_stream_flush(&(self->encoder.os), &(self->encoder.og))) { |
---|
[598] | 150 | if ( stream_vio_s_write(self->stream, self->encoder.og.header, self->encoder.og.header_len) |
---|
| 151 | != self->encoder.og.header_len || |
---|
| 152 | stream_vio_s_write(self->stream, self->encoder.og.body, self->encoder.og.body_len ) |
---|
| 153 | != self->encoder.og.body_len ) { |
---|
[582] | 154 | free(self); // TODO: do we need addional cleanup? |
---|
| 155 | return -1; |
---|
| 156 | } |
---|
| 157 | } |
---|
[584] | 158 | self->opened = 1; |
---|
[586] | 159 | } else { |
---|
| 160 | encbuf = vorbis_analysis_buffer(&(self->encoder.vd), len /* TODO: need to lookup the menaing of this */); |
---|
| 161 | chans = s->info.channels; |
---|
| 162 | end = len/(2*chans); |
---|
| 163 | |
---|
| 164 | if ( chans == 1 ) { // use optimized code |
---|
| 165 | for (i = 0; i < end; i++) |
---|
| 166 | encbuf[0][i] = data[i]/32768.0; |
---|
| 167 | |
---|
| 168 | } else if ( chans == 2 ) { // use optimized code |
---|
| 169 | for (i = 0; i < end; i++) { |
---|
| 170 | encbuf[0][i] = data[2*i ]/32768.0; |
---|
| 171 | encbuf[1][i] = data[2*i+1]/32768.0; |
---|
| 172 | } |
---|
| 173 | } else { // use generic multi channel code |
---|
| 174 | for (i = 0; i < end; i++) { |
---|
| 175 | for (c = 0; c < chans; c++) { |
---|
| 176 | encbuf[c][i] = data[chans*i+c]/32768.0; |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | } |
---|
[587] | 180 | |
---|
| 181 | vorbis_analysis_wrote(&(self->encoder.vd), i); |
---|
| 182 | |
---|
[1238] | 183 | if ( cf_vorbis_encode_flushout(self) == -1 ) |
---|
| 184 | return -1; |
---|
[584] | 185 | } |
---|
[582] | 186 | |
---|
| 187 | return len; // we assume every thing was written (at least into our dsp anaylises buffer |
---|
| 188 | #else |
---|
| 189 | errno = ENOSYS; |
---|
| 190 | return -1; |
---|
| 191 | #endif |
---|
| 192 | } |
---|
[205] | 193 | int cf_vorbis_read(CODECFILTER_USERDATA_T inst, char * buf, int len) { |
---|
| 194 | struct codecfilter_vorbis_inst * self = (struct codecfilter_vorbis_inst *) inst; |
---|
| 195 | long r; |
---|
[206] | 196 | long todo = len; |
---|
| 197 | long done = 0; |
---|
[205] | 198 | |
---|
[206] | 199 | // printf("cf_vorbis_read(inst=%p, buf=%p, len=%i) = ?\n", inst, buf, len); |
---|
| 200 | |
---|
| 201 | self->opened++; |
---|
| 202 | if ( self->opened == 16 ) { |
---|
[744] | 203 | |
---|
[206] | 204 | //printf("cf_vorbis_read(*): opening...\n"); |
---|
[741] | 205 | if ( ov_open_callbacks((void*)self->stream, &(self->vf), NULL, 0, _g_cf_vorbis_vfvio) < 0 ) { |
---|
[206] | 206 | return 0; |
---|
[205] | 207 | } |
---|
[742] | 208 | errno = EAGAIN; |
---|
| 209 | return -1; |
---|
[205] | 210 | } |
---|
[206] | 211 | |
---|
| 212 | if ( self->opened < 16 ) { |
---|
[541] | 213 | errno = EAGAIN; |
---|
[206] | 214 | return -1; |
---|
| 215 | } |
---|
[205] | 216 | |
---|
[382] | 217 | |
---|
| 218 | self->got_it_running = 1; |
---|
| 219 | |
---|
[206] | 220 | while (todo) { |
---|
| 221 | r = ov_read(&(self->vf), buf+done, todo, 0, 2, 1, &(self->current_section)); |
---|
[744] | 222 | if ( r == OV_HOLE ) { |
---|
[745] | 223 | ROAR_DBG("cf_vorbis_read(*): Hole in stream"); |
---|
[744] | 224 | } else if ( r < 1 ) { |
---|
[206] | 225 | break; |
---|
| 226 | } else { |
---|
[207] | 227 | if ( self->last_section != self->current_section ) |
---|
| 228 | if ( cf_vorbis_update_stream(self) == -1 ) |
---|
| 229 | return 0; |
---|
| 230 | |
---|
| 231 | self->last_section = self->current_section; |
---|
[206] | 232 | todo -= r; |
---|
| 233 | done += r; |
---|
| 234 | } |
---|
| 235 | } |
---|
[205] | 236 | |
---|
[744] | 237 | //printf("ov_read(*) = %i\n", done); |
---|
[206] | 238 | |
---|
| 239 | if ( done == 0 ) { |
---|
[205] | 240 | // do some EOF handling... |
---|
[206] | 241 | return 0; |
---|
[205] | 242 | } else { |
---|
[206] | 243 | return len; |
---|
[205] | 244 | } |
---|
| 245 | } |
---|
| 246 | |
---|
[207] | 247 | int cf_vorbis_update_stream (struct codecfilter_vorbis_inst * self) { |
---|
[1493] | 248 | #ifdef ROAR_SUPPORT_META |
---|
[207] | 249 | vorbis_info *vi = ov_info(&(self->vf), -1); |
---|
| 250 | char **ptr = ov_comment(&(self->vf), -1)->user_comments; |
---|
[716] | 251 | char key[ROAR_META_MAX_NAMELEN] = {0}, value[LIBROAR_BUFFER_MSGDATA] = {0}; |
---|
[583] | 252 | struct roar_stream * s = ROAR_STREAM(self->stream); |
---|
[207] | 253 | int type; |
---|
| 254 | int j, h = 0; |
---|
[222] | 255 | float rpg_track = 0, rpg_album = 0; |
---|
[716] | 256 | int meta_ok; |
---|
[207] | 257 | |
---|
| 258 | s->info.channels = vi->channels; |
---|
| 259 | s->info.rate = vi->rate; |
---|
| 260 | s->info.bits = 16; |
---|
| 261 | s->info.codec = ROAR_CODEC_DEFAULT; |
---|
| 262 | |
---|
| 263 | stream_meta_clear(s->id); |
---|
| 264 | |
---|
| 265 | while(*ptr){ |
---|
[716] | 266 | meta_ok = 1; |
---|
[207] | 267 | |
---|
[716] | 268 | for (j = 0; (*ptr)[j] != 0 && (*ptr)[j] != '='; j++) { |
---|
| 269 | if ( j == ROAR_META_MAX_NAMELEN ) { |
---|
| 270 | ROAR_ERR("cf_vorbis_update_stream(*): invalid meta data on stream %i: meta data key too long", s->id); |
---|
| 271 | meta_ok = 0; |
---|
| 272 | j = 0; |
---|
| 273 | break; |
---|
| 274 | } |
---|
| 275 | key[j] = (*ptr)[j]; |
---|
| 276 | } |
---|
| 277 | key[j] = 0; |
---|
[222] | 278 | |
---|
[716] | 279 | if ( meta_ok ) { |
---|
| 280 | for (j++, h = 0; (*ptr)[j] != 0 && (*ptr)[j] != '='; j++) { |
---|
| 281 | if ( h == LIBROAR_BUFFER_MSGDATA ) { |
---|
| 282 | ROAR_ERR("update_stream(*): invalid meta data on stream %i: meta data value for key '%s' too long", s->id, key); |
---|
[717] | 283 | meta_ok = 0; |
---|
[716] | 284 | h = 0; |
---|
| 285 | break; |
---|
| 286 | } |
---|
| 287 | value[h++] = (*ptr)[j]; |
---|
| 288 | } |
---|
| 289 | value[h] = 0; |
---|
[222] | 290 | } |
---|
| 291 | |
---|
[716] | 292 | if ( meta_ok ) { |
---|
| 293 | type = roar_meta_inttype(key); |
---|
| 294 | if ( type != -1 ) |
---|
| 295 | stream_meta_set(s->id, type, "", value); |
---|
| 296 | |
---|
| 297 | ROAR_DBG("cf_vorbis_update_stream(*): Meta %-16s: %s", key, value); |
---|
| 298 | |
---|
| 299 | if ( strcmp(key, "REPLAYGAIN_TRACK_PEAK") == 0 ) { |
---|
| 300 | rpg_track = 1/atof(value); |
---|
| 301 | /* |
---|
| 302 | } else if ( strcmp(key, "REPLAYGAIN_TRACK_GAIN") == 0 ) { |
---|
| 303 | rpg_track = powf(10, atof(value)/20); |
---|
| 304 | */ |
---|
| 305 | } else if ( strcmp(key, "REPLAYGAIN_ALBUM_PEAK") == 0 ) { |
---|
| 306 | rpg_album = 1/atof(value); |
---|
| 307 | /* |
---|
| 308 | } else if ( strcmp(key, "REPLAYGAIN_ALBUM_GAIN") == 0 ) { |
---|
| 309 | rpg_album = powf(10, atof(value)/20); |
---|
| 310 | */ |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | ptr++; |
---|
[207] | 315 | } |
---|
| 316 | |
---|
[222] | 317 | if ( rpg_album ) { |
---|
| 318 | self->stream->mixer.rpg_div = 2718; // = int(exp(1)*1000) |
---|
| 319 | self->stream->mixer.rpg_mul = (float)rpg_album*2718; |
---|
| 320 | } else if ( rpg_track ) { |
---|
| 321 | self->stream->mixer.rpg_div = 2718; |
---|
| 322 | self->stream->mixer.rpg_mul = (float)rpg_track*2718; |
---|
| 323 | } |
---|
| 324 | |
---|
[1041] | 325 | stream_meta_finalize(s->id); |
---|
[1493] | 326 | #endif |
---|
[223] | 327 | //printf("RPG: mul=%i, div=%i\n", self->stream->mixer.rpg_mul, self->stream->mixer.rpg_div); |
---|
[207] | 328 | return 0; |
---|
| 329 | } |
---|
| 330 | |
---|
[1226] | 331 | int cf_vorbis_encode_start (struct codecfilter_vorbis_inst * self) { |
---|
| 332 | #ifdef ROAR_HAVE_LIBVORBISENC |
---|
[1238] | 333 | int srn = self->encoder.srn; // this value is allrady inited... |
---|
[1493] | 334 | #ifdef ROAR_SUPPORT_META |
---|
[1238] | 335 | int len = 0; |
---|
| 336 | int i; |
---|
| 337 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
[1493] | 338 | #endif |
---|
[1238] | 339 | int sid = ROAR_STREAM(self->stream)->id; |
---|
| 340 | char val[LIBROAR_BUFFER_MSGDATA]; |
---|
| 341 | |
---|
| 342 | val[LIBROAR_BUFFER_MSGDATA-1] = 0; |
---|
| 343 | |
---|
[1226] | 344 | memset(&(self->encoder), 0, sizeof(self->encoder)); |
---|
| 345 | |
---|
| 346 | self->encoding = 1; |
---|
[1238] | 347 | self->encoder.srn = srn + 1;; |
---|
[1226] | 348 | |
---|
| 349 | vorbis_info_init(&(self->encoder.vi)); |
---|
| 350 | vorbis_comment_init(&(self->encoder.vc)); |
---|
| 351 | vorbis_comment_add_tag(&(self->encoder.vc), "SERVER", "RoarAudio"); |
---|
| 352 | vorbis_comment_add_tag(&(self->encoder.vc), "ENCODER", "RoarAudio Vorbis codecfilter"); |
---|
| 353 | |
---|
[1493] | 354 | #ifdef ROAR_SUPPORT_META |
---|
[1238] | 355 | if ( (len = stream_meta_list(sid, types, ROAR_META_MAX_PER_STREAM)) != -1 ) { |
---|
| 356 | for (i = 0; i < len; i++) { |
---|
| 357 | //int stream_meta_get (int id, int type, char * name, char * val, size_t len); |
---|
| 358 | if ( stream_meta_get(sid, types[i], NULL, val, LIBROAR_BUFFER_MSGDATA-1) == 0 ) |
---|
| 359 | vorbis_comment_add_tag(&(self->encoder.vc), roar_meta_strtype(types[i]), val); |
---|
| 360 | } |
---|
| 361 | } |
---|
[1493] | 362 | #endif |
---|
[1238] | 363 | |
---|
[1226] | 364 | if( vorbis_encode_init_vbr(&(self->encoder.vi), (long) ROAR_STREAM(self->stream)->info.channels, |
---|
| 365 | (long) ROAR_STREAM(self->stream)->info.rate, |
---|
| 366 | self->encoder.v_base_quality) != 0 ) { |
---|
| 367 | ROAR_ERR("cf_vorbis_encode_start(*): Can not vorbis_encode_init_vbr(*)!"); |
---|
| 368 | vorbis_info_clear(&(self->encoder.vi)); // TODO: do we need to free vc also? |
---|
| 369 | return -1; |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | vorbis_analysis_init(&(self->encoder.vd), &(self->encoder.vi)); |
---|
| 373 | vorbis_block_init(&(self->encoder.vd), &(self->encoder.vb)); |
---|
[362] | 374 | |
---|
[1239] | 375 | ROAR_DBG("cf_vorbis_encode_start(*): srn=%i", self->encoder.srn); |
---|
[1226] | 376 | // "RA"<<16 + PID<<8 + Stream ID |
---|
[1238] | 377 | ogg_stream_init(&(self->encoder.os), |
---|
[1239] | 378 | (((0x5241 + self->encoder.srn) & 0xffff)<<16) + |
---|
| 379 | ( (getpid() & 0x00ff)<< 8) + |
---|
| 380 | ( sid & 0x00ff)); |
---|
[1226] | 381 | return 0; |
---|
| 382 | #else |
---|
| 383 | return -1; |
---|
| 384 | #endif |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | int cf_vorbis_encode_end (struct codecfilter_vorbis_inst * self) { |
---|
| 388 | #ifdef ROAR_HAVE_LIBVORBISENC |
---|
| 389 | if ( self->encoding ) { |
---|
[1238] | 390 | // try to flush up to an EOS page... |
---|
| 391 | vorbis_analysis_buffer(&(self->encoder.vd), 2*ROAR_MAX_CHANNELS); |
---|
| 392 | vorbis_analysis_wrote(&(self->encoder.vd), 0); |
---|
| 393 | cf_vorbis_encode_flushout(self); |
---|
| 394 | |
---|
| 395 | // clean up... |
---|
[1226] | 396 | ogg_stream_clear(&(self->encoder.os)); |
---|
| 397 | vorbis_block_clear(&(self->encoder.vb)); |
---|
| 398 | vorbis_dsp_clear(&(self->encoder.vd)); |
---|
| 399 | vorbis_info_clear(&(self->encoder.vi)); |
---|
| 400 | self->opened = 0; |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | return 0; |
---|
| 404 | #else |
---|
| 405 | return -1; |
---|
| 406 | #endif |
---|
| 407 | } |
---|
| 408 | |
---|
[1238] | 409 | int cf_vorbis_encode_flushout(struct codecfilter_vorbis_inst * self) { |
---|
| 410 | #ifdef ROAR_HAVE_LIBVORBISENC |
---|
| 411 | while ( vorbis_analysis_blockout(&(self->encoder.vd), &(self->encoder.vb)) == 1 ) { |
---|
| 412 | vorbis_analysis(&(self->encoder.vb), &(self->encoder.op)); |
---|
| 413 | vorbis_bitrate_addblock(&(self->encoder.vb)); |
---|
| 414 | |
---|
| 415 | while ( vorbis_bitrate_flushpacket(&(self->encoder.vd), &(self->encoder.op)) ) { |
---|
| 416 | ogg_stream_packetin(&(self->encoder.os), &(self->encoder.op)); |
---|
| 417 | |
---|
| 418 | while( ogg_stream_pageout(&(self->encoder.os), &(self->encoder.og)) ) { |
---|
| 419 | if ( |
---|
| 420 | stream_vio_s_write(self->stream, self->encoder.og.header, self->encoder.og.header_len) == -1 || |
---|
| 421 | stream_vio_s_write(self->stream, self->encoder.og.body, self->encoder.og.body_len ) == -1 ) { |
---|
| 422 | return -1; |
---|
| 423 | } |
---|
| 424 | } |
---|
| 425 | } |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | return 0; |
---|
| 429 | #else |
---|
| 430 | return -1; |
---|
| 431 | #endif |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | int cf_vorbis_ctl(CODECFILTER_USERDATA_T inst, int cmd, void * data) { |
---|
| 435 | struct codecfilter_vorbis_inst * self = (struct codecfilter_vorbis_inst *) inst; |
---|
| 436 | |
---|
| 437 | switch (cmd) { |
---|
| 438 | case ROAR_CODECFILTER_CTL2CMD(ROAR_CODECFILTER_CTL_META_UPDATE): |
---|
[1239] | 439 | ROAR_DBG("cf_vorbis_ctl(*): stoping stream..."); |
---|
[1238] | 440 | if ( cf_vorbis_encode_end(self) == -1 ) |
---|
| 441 | return -1; |
---|
[1239] | 442 | ROAR_DBG("cf_vorbis_ctl(*): restarting stream..."); |
---|
[1238] | 443 | if ( cf_vorbis_encode_start(self) == -1 ) |
---|
| 444 | return -1; |
---|
| 445 | |
---|
| 446 | return 0; |
---|
| 447 | break; |
---|
| 448 | default: |
---|
| 449 | return -1; |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | return -1; |
---|
| 453 | } |
---|
| 454 | |
---|
[1226] | 455 | #endif |
---|
[204] | 456 | //ll |
---|