Changeset 1238:3c0eaf049201 in roaraudio for roard/codecfilter_vorbis.c
- Timestamp:
- 02/26/09 03:05:26 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roard/codecfilter_vorbis.c
r1226 r1238 77 77 self->encoding = 0; 78 78 self->encoder.v_base_quality = 0.3; 79 self->encoder.srn = -1; 79 80 #endif 80 81 … … 180 181 vorbis_analysis_wrote(&(self->encoder.vd), i); 181 182 182 while ( vorbis_analysis_blockout(&(self->encoder.vd), &(self->encoder.vb)) == 1 ) { 183 vorbis_analysis(&(self->encoder.vb), &(self->encoder.op)); 184 vorbis_bitrate_addblock(&(self->encoder.vb)); 185 186 while ( vorbis_bitrate_flushpacket(&(self->encoder.vd), &(self->encoder.op)) ) { 187 ogg_stream_packetin(&(self->encoder.os), &(self->encoder.op)); 188 189 while( ogg_stream_pageout(&(self->encoder.os), &(self->encoder.og)) ) { 190 if ( 191 stream_vio_s_write(self->stream, self->encoder.og.header, self->encoder.og.header_len) == -1 || 192 stream_vio_s_write(self->stream, self->encoder.og.body, self->encoder.og.body_len ) == -1 ) { 193 return -1; 194 } 195 } 196 } 197 } 183 if ( cf_vorbis_encode_flushout(self) == -1 ) 184 return -1; 198 185 } 199 186 … … 342 329 int cf_vorbis_encode_start (struct codecfilter_vorbis_inst * self) { 343 330 #ifdef ROAR_HAVE_LIBVORBISENC 331 int srn = self->encoder.srn; // this value is allrady inited... 332 int len = 0; 333 int i; 334 int types[ROAR_META_MAX_PER_STREAM]; 335 int sid = ROAR_STREAM(self->stream)->id; 336 char val[LIBROAR_BUFFER_MSGDATA]; 337 338 val[LIBROAR_BUFFER_MSGDATA-1] = 0; 339 344 340 memset(&(self->encoder), 0, sizeof(self->encoder)); 345 341 346 342 self->encoding = 1; 343 self->encoder.srn = srn + 1;; 347 344 348 345 vorbis_info_init(&(self->encoder.vi)); … … 350 347 vorbis_comment_add_tag(&(self->encoder.vc), "SERVER", "RoarAudio"); 351 348 vorbis_comment_add_tag(&(self->encoder.vc), "ENCODER", "RoarAudio Vorbis codecfilter"); 349 350 if ( (len = stream_meta_list(sid, types, ROAR_META_MAX_PER_STREAM)) != -1 ) { 351 for (i = 0; i < len; i++) { 352 //int stream_meta_get (int id, int type, char * name, char * val, size_t len); 353 if ( stream_meta_get(sid, types[i], NULL, val, LIBROAR_BUFFER_MSGDATA-1) == 0 ) 354 vorbis_comment_add_tag(&(self->encoder.vc), roar_meta_strtype(types[i]), val); 355 } 356 } 352 357 353 358 if( vorbis_encode_init_vbr(&(self->encoder.vi), (long) ROAR_STREAM(self->stream)->info.channels, … … 362 367 vorbis_block_init(&(self->encoder.vd), &(self->encoder.vb)); 363 368 369 ROAR_WARN("cf_vorbis_encode_start(*): srn=%i", self->encoder.srn); 364 370 // "RA"<<16 + PID<<8 + Stream ID 365 ogg_stream_init(&(self->encoder.os), 0x52410000 + ((getpid() & 0xff)<<8) + (ROAR_STREAM(self->stream)->id & 0xff)); 371 ogg_stream_init(&(self->encoder.os), 372 ((0x5241 + self->encoder.srn)<<16) + 373 ((getpid() & 0xff )<< 8) + 374 ( sid & 0xff )); 366 375 return 0; 367 376 #else … … 373 382 #ifdef ROAR_HAVE_LIBVORBISENC 374 383 if ( self->encoding ) { 384 // try to flush up to an EOS page... 385 vorbis_analysis_buffer(&(self->encoder.vd), 2*ROAR_MAX_CHANNELS); 386 vorbis_analysis_wrote(&(self->encoder.vd), 0); 387 cf_vorbis_encode_flushout(self); 388 389 // clean up... 375 390 ogg_stream_clear(&(self->encoder.os)); 376 391 vorbis_block_clear(&(self->encoder.vb)); … … 386 401 } 387 402 403 int cf_vorbis_encode_flushout(struct codecfilter_vorbis_inst * self) { 404 #ifdef ROAR_HAVE_LIBVORBISENC 405 while ( vorbis_analysis_blockout(&(self->encoder.vd), &(self->encoder.vb)) == 1 ) { 406 vorbis_analysis(&(self->encoder.vb), &(self->encoder.op)); 407 vorbis_bitrate_addblock(&(self->encoder.vb)); 408 409 while ( vorbis_bitrate_flushpacket(&(self->encoder.vd), &(self->encoder.op)) ) { 410 ogg_stream_packetin(&(self->encoder.os), &(self->encoder.op)); 411 412 while( ogg_stream_pageout(&(self->encoder.os), &(self->encoder.og)) ) { 413 if ( 414 stream_vio_s_write(self->stream, self->encoder.og.header, self->encoder.og.header_len) == -1 || 415 stream_vio_s_write(self->stream, self->encoder.og.body, self->encoder.og.body_len ) == -1 ) { 416 return -1; 417 } 418 } 419 } 420 } 421 422 return 0; 423 #else 424 return -1; 425 #endif 426 } 427 428 int cf_vorbis_ctl(CODECFILTER_USERDATA_T inst, int cmd, void * data) { 429 struct codecfilter_vorbis_inst * self = (struct codecfilter_vorbis_inst *) inst; 430 431 switch (cmd) { 432 case ROAR_CODECFILTER_CTL2CMD(ROAR_CODECFILTER_CTL_META_UPDATE): 433 ROAR_WARN("stoping stream..."); 434 if ( cf_vorbis_encode_end(self) == -1 ) 435 return -1; 436 ROAR_WARN("restarting stream..."); 437 if ( cf_vorbis_encode_start(self) == -1 ) 438 return -1; 439 440 return 0; 441 break; 442 default: 443 return -1; 444 } 445 446 return -1; 447 } 448 388 449 #endif 389 450 //ll
Note: See TracChangeset
for help on using the changeset viewer.