Changeset 569:b35e761f50f4 in roaraudio


Ignore:
Timestamp:
08/19/08 01:13:03 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

adding a lot thingss in preperation to encode vorbis :)

Location:
roard
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • roard/Makefile

    r561 r569  
    1111INCLUDE = -I../include -I./include 
    1212CFLAGS  = -g -Wall -O2 $(DEFINES) $(INCLUDE) $(INCPATH) 
    13 LDFLAGS = -g -L../lib/ $(LDPATH) -lroar $(lib_esd) $(lib_ao) $(lib_vorbisfile) -lm $(lib_celt) $(lib_speex) 
     13LDFLAGS = -g -L../lib/ $(LDPATH) -lroar $(lib_esd) $(lib_ao) $(lib_vorbisfile) $(lib_vorbisenc) -lm $(lib_celt) $(lib_speex) 
    1414 
    1515all: ${TARGETS} 
  • roard/codecfilter_vorbis.c

    r541 r569  
    99                                            struct roar_codecfilter   * filter) { 
    1010 struct codecfilter_vorbis_inst * self = malloc(sizeof(struct codecfilter_vorbis_inst)); 
     11 struct roar_stream * s = ROAR_STREAM(info); 
     12 ogg_packet header; 
     13 ogg_packet header_comm; 
     14 ogg_packet header_code; 
    1115 
    1216 if ( !self ) 
     
    1923 self->stream               = info; 
    2024// self->outlen               = ROAR_OUTPUT_BUFFER_SAMPLES * s->info.channels * s->info.bits / 8; // optimal size 
     25#ifdef ROAR_HAVE_LIBVORBISENC 
     26 self->encoding             = 0; 
     27#endif 
    2128 
    2229 ROAR_DBG("cf_vorbis_open(*): info->id=%i", ROAR_STREAM(info)->id); 
    2330 
    24  if ( (self->in = fdopen(((struct roar_stream*)info)->fh, "r")) == NULL ) { 
     31 if ( (self->in = fdopen(s->fh, "r")) == NULL ) { 
    2532  free((void*)self); 
    2633  return -1; 
     
    2936 *inst = (CODECFILTER_USERDATA_T) self; 
    3037 
    31  ((struct roar_stream*)info)->info.codec = ROAR_CODEC_DEFAULT; 
     38 s->info.codec = ROAR_CODEC_DEFAULT; 
     39 s->info.bits  = 16; 
     40 
     41 if ( s->dir == ROAR_DIR_PLAY ) { 
     42  return 0; 
     43 } else if ( s->dir == ROAR_DIR_MONITOR ) { 
     44#ifdef ROAR_HAVE_LIBVORBISENC 
     45  // set up the encoder here 
     46 
     47  memset(&(self->encoder), 0, sizeof(self->encoder)); 
     48 
     49  self->encoding = 1; 
     50 
     51  vorbis_info_init(&(self->encoder.vi)); 
     52  vorbis_comment_init(&(self->encoder.vc)); 
     53  vorbis_comment_add_tag(&(self->encoder.vc), "SERVER", "RoarAudio"); 
     54  vorbis_comment_add_tag(&(self->encoder.vc), "ENCODER", "RoarAudio Vorbis codecfilter"); 
     55 
     56  if( vorbis_encode_init_vbr(&(self->encoder.vi), (long) s->info.channels, (long) s->info.rate, 
     57                                                  self->encoder.v_base_quality) != 0 ) { 
     58   ROAR_ERR("cf_vorbis_open(*): Can not vorbis_encode_init_vbr(*)!"); 
     59   vorbis_info_clear(&(self->encoder.vi)); // TODO: do we need to free vc also? 
     60   free(self); 
     61   return -1; 
     62  } 
     63 
     64  vorbis_analysis_init(&(self->encoder.vd), &(self->encoder.vi)); 
     65  vorbis_block_init(&(self->encoder.vd), &(self->encoder.vb)); 
     66 
     67                                     //  "RA"<<16 + PID<<8 + Stream ID 
     68  ogg_stream_init(&(self->encoder.os), 0x52410000 + ((getpid() & 0xff)<<8) + s->id); 
     69 
     70  vorbis_analysis_headerout(&(self->encoder.vd), &(self->encoder.vc), &header, &header_comm, &header_code); 
     71 
     72  ogg_stream_packetin(&(self->encoder.os), &header); 
     73  ogg_stream_packetin(&(self->encoder.os), &header_comm); 
     74  ogg_stream_packetin(&(self->encoder.os), &header_code); 
     75 
     76  while (ogg_stream_flush(&(self->encoder.os), &(self->encoder.og))) { 
     77   if ( write(s->fh, self->encoder.og.header, self->encoder.og.header_len) != self->encoder.og.header_len || 
     78        write(s->fh, self->encoder.og.body,   self->encoder.og.body_len  ) != self->encoder.og.body_len     ) { 
     79    free(self); // TODO: do we need adtional cleanup? 
     80    return -1; 
     81   } 
     82  } 
     83 
     84#else 
     85 free(self); 
     86 return -1; 
     87#endif 
     88 } else { 
     89  free(self); 
     90  return -1; 
     91 } 
    3292 
    3393 return 0; 
     
    42102 if ( self->got_it_running ) 
    43103  ov_clear(&(self->vf)); 
     104 
     105#ifdef ROAR_HAVE_LIBVORBISENC 
     106 if ( self->encoding ) { 
     107  ogg_stream_clear(&(self->encoder.os)); 
     108  vorbis_block_clear(&(self->encoder.vb)); 
     109  vorbis_dsp_clear(&(self->encoder.vd)); 
     110  vorbis_info_clear(&(self->encoder.vi)); 
     111 } 
     112#endif 
    44113 
    45114 free(inst); 
  • roard/include/codecfilter_vorbis.h

    r382 r569  
    1212#include <math.h> 
    1313 
     14#ifdef ROAR_HAVE_LIBVORBISENC 
     15#include <vorbis/vorbisenc.h> 
     16#endif 
     17 
    1418struct codecfilter_vorbis_inst { 
    1519 int current_section; 
     
    2024 OggVorbis_File vf; 
    2125 int got_it_running; 
     26#ifdef ROAR_HAVE_LIBVORBISENC 
     27 int encoding; 
     28 struct { 
     29  float v_base_quality; 
     30  ogg_stream_state os; 
     31  ogg_page         og; 
     32  ogg_packet       op; 
     33 
     34  vorbis_dsp_state vd; 
     35  vorbis_block     vb; 
     36  vorbis_info      vi; 
     37  vorbis_comment   vc; 
     38 } encoder; 
     39#endif 
    2240}; 
    2341 
Note: See TracChangeset for help on using the changeset viewer.