Changeset 2816:b9e357b0dc43 in roaraudio


Ignore:
Timestamp:
09/29/09 18:04:39 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added prethru support and updated list of codecs a bit

Location:
roard
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • roard/codecfilter.c

    r2701 r2816  
    3636 {-1,                     "null", "null codec filter", NULL, NULL, ROAR_CODECFILTER_NONE, ROAR_SUBSYS_NONE, 
    3737                                          NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, 
     38 {-1,                     "PCM", "Native PCM Support", NULL, NULL, 
     39                          ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU_NN, ROAR_SUBSYS_WAVEFORM, 
     40                                          NULL, NULL, NULL, NULL, NULL, NULL, cf_alaw_delay, NULL}, 
     41 {ROAR_CODEC_MIDI,        "MIDI", "Native MIDI Support", NULL, NULL, 
     42                          ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU_NN, ROAR_SUBSYS_MIDI, 
     43                                          NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, 
     44 {ROAR_CODEC_DMX512,      "DMX512", "Native DMX512 Support", NULL, NULL, 
     45                          ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU_NN, ROAR_SUBSYS_LIGHT, 
     46                                          NULL, NULL, NULL, NULL, NULL, NULL, cf_alaw_delay, NULL}, 
    3847 
    3948/* 
     
    4554#ifndef ROAR_WITHOUT_CF_WAVE 
    4655 {ROAR_CODEC_RIFF_WAVE, "RIFF/WAVE", "RIFF/WAVE", NULL, NULL, 
    47   ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, ROAR_SUBSYS_WAVEFORM, 
     56  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU, ROAR_SUBSYS_WAVEFORM, 
    4857  cf_wave_open, cf_wave_close, NULL, cf_wave_write, cf_wave_read, NULL, NULL, cf_wave_ctl}, 
    4958#endif 
     
    5665#endif 
    5766 
     67#ifdef ROAR_HAVE_LIBOGG 
     68 {ROAR_CODEC_OGG, "Ogg", "Ogg Container Format", NULL, NULL, ROAR_CODECFILTER_NONE, 
     69  ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI, 
     70  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, 
     71#endif 
     72 
    5873#ifdef ROAR_SUPPORT_ALAW 
    5974 {ROAR_CODEC_ALAW, "alaw", "A-Law", NULL, NULL, 
    6075#ifdef ROAR_SUPPORT_ALAW_RW 
    61   ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, 
    62 #else 
    63   ROAR_CODECFILTER_READ, 
     76  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU_NN, 
     77#else 
     78  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_PRETHRU_NN, 
    6479#endif 
    6580  ROAR_SUBSYS_WAVEFORM, 
     
    7691 {ROAR_CODEC_MULAW, "mulaw", "mu-Law", NULL, NULL, 
    7792#ifdef ROAR_SUPPORT_MULAW_RW 
    78   ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, 
    79 #else 
    80   ROAR_CODECFILTER_READ, 
     93  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU_NN, 
     94#else 
     95  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_PRETHRU_NN, 
    8196#endif 
    8297  ROAR_SUBSYS_WAVEFORM, 
     
    101116 {ROAR_CODEC_OGG_VORBIS, "oggvorbis", "Ogg Vorbis decoder", NULL, NULL, 
    102117#ifdef ROAR_HAVE_LIBVORBISENC 
    103  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, 
     118 ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU, 
    104119#else 
    105120 ROAR_CODECFILTER_READ, 
     
    136151 
    137152#ifdef ROAR_HAVE_LIBCELT 
    138  {ROAR_CODEC_ROAR_CELT, "RoarCELT", "RoarAudio CELT", NULL, NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, 
     153 {ROAR_CODEC_ROAR_CELT, "RoarCELT", "RoarAudio CELT", NULL, NULL, 
     154  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU, 
    139155  ROAR_SUBSYS_WAVEFORM, 
    140156  cf_celt_open, cf_celt_close, NULL, cf_celt_write, cf_celt_read, NULL, cf_celt_delay, NULL}, 
     
    142158 
    143159#ifdef ROAR_HAVE_LIBSPEEX 
    144  {ROAR_CODEC_ROAR_SPEEX, "RoarSpeex", "RoarAudio Speex", NULL, NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, 
     160 {ROAR_CODEC_ROAR_SPEEX, "RoarSpeex", "RoarAudio Speex", NULL, NULL, 
     161  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU, 
    145162  ROAR_SUBSYS_WAVEFORM, 
    146163  cf_speex_open, cf_speex_close, NULL, cf_speex_write, cf_speex_read, NULL, NULL, NULL}, 
     
    161178#endif 
    162179#endif 
     180 
     181 {ROAR_CODEC_ROARDMX, "RoarDMX", "Native RoarDMX Support", NULL, NULL, 
     182                          ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE|ROAR_CODECFILTER_PRETHRU_NN, ROAR_SUBSYS_LIGHT, 
     183                                          NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, 
    163184 
    164185 {-1, NULL, NULL, NULL, NULL, ROAR_CODECFILTER_NONE, ROAR_SUBSYS_NONE, 
     
    203224   if ( flags & ROAR_CODECFILTER_WRITE ) 
    204225    mode[1] = 'w'; 
     226   if ( flags & ROAR_CODECFILTER_PRETHRU ) 
     227    mode[2] = 'P'; 
     228   if ( flags & ROAR_CODECFILTER_PRETHRU_NN ) 
     229    mode[2] = 'p'; 
    205230  } 
    206231 
  • roard/codecfilter_celt.c

    r2204 r2816  
    225225 int diff; 
    226226 int fs2 = self->frame_size * 2 * ROAR_STREAM(self->stream)->info.channels; 
     227 int sid; 
    227228 uint16_t pkglen_net, pkglen; 
    228229 unsigned char cbits[BS+2]; 
     230 void * prethru; 
    229231 
    230232 if ( !self->opened_encoder ) { 
     233  sid = ROAR_STREAM(self->stream)->id; 
     234 
     235  if ( stream_prethru_destroy(sid) == -1 ) { 
     236   return -1; 
     237  } 
     238 
     239  if ( stream_prethru_add_data(sid, &prethru, ROAR_CELT_MAGIC_LEN) == -1 ) { 
     240   return -1; 
     241  } 
     242 
     243  memcpy(prethru, ROAR_CELT_MAGIC, ROAR_CELT_MAGIC_LEN); 
     244 
    231245  if ( stream_vio_s_write(self->stream, ROAR_CELT_MAGIC, ROAR_CELT_MAGIC_LEN) != ROAR_CELT_MAGIC_LEN ) 
    232246   return -1; 
  • roard/codecfilter_speex.c

    r2310 r2816  
    261261 int ret = 0; 
    262262 int need_extra; 
     263 int sid; 
     264 void * prethru; 
    263265 
    264266/* 
     
    271273 
    272274 if ( ! self->encoder ) { 
     275  sid = ROAR_STREAM(self->stream)->id; 
     276 
     277  if ( stream_prethru_destroy(sid) == -1 ) { 
     278   return -1; 
     279  } 
     280 
     281  if ( stream_prethru_add_data(sid, &prethru, ROAR_SPEEX_MAGIC_LEN) == -1 ) { 
     282   return -1; 
     283  } 
     284 
     285  memcpy(prethru, ROAR_SPEEX_MAGIC, ROAR_SPEEX_MAGIC_LEN); 
     286 
    273287  if ( stream_vio_s_write(self->stream, ROAR_SPEEX_MAGIC, ROAR_SPEEX_MAGIC_LEN) != ROAR_SPEEX_MAGIC_LEN ) 
    274288   return -1; 
     
    282296  } 
    283297 
     298 
    284299  mode = ROAR_HOST2NET16(mode); 
     300 
     301  if ( stream_prethru_add_data(sid, &prethru, 2) == -1 ) { 
     302   return -1; 
     303  } 
     304 
     305  *(uint16_t*)prethru = mode; 
    285306 
    286307  if ( stream_vio_s_write(self->stream, &mode, 2) != 2 ) 
  • roard/codecfilter_vorbis.c

    r2107 r2816  
    144144 int chans; 
    145145 int end; 
     146 int sid; 
     147 void * prethrubuf; 
    146148#if ROAR_VORBIS_BITS == 8 
    147149 int8_t  * data = (int8_t  *) buf; 
     
    161163  } 
    162164 
     165  sid = ROAR_STREAM(self->stream)->id; 
     166 
    163167  vorbis_analysis_headerout(&(self->encoder.vd), &(self->encoder.vc), &header, &header_comm, &header_code); 
    164168 
     
    166170  ogg_stream_packetin(&(self->encoder.os), &header_comm); 
    167171  ogg_stream_packetin(&(self->encoder.os), &header_code); 
     172 
     173  stream_prethru_destroy(sid); 
    168174 
    169175  while (ogg_stream_flush(&(self->encoder.os), &(self->encoder.og))) { 
     
    174180    free(self); // TODO: do we need addional cleanup? 
    175181    return -1; 
     182   } 
     183   // we ignore errors at the moment... 
     184   if ( stream_prethru_add_data(sid, &prethrubuf, self->encoder.og.header_len + self->encoder.og.body_len) != -1 ) { 
     185    memcpy(prethrubuf,                               self->encoder.og.header, self->encoder.og.header_len); 
     186    memcpy(prethrubuf + self->encoder.og.header_len, self->encoder.og.body,   self->encoder.og.body_len  ); 
    176187   } 
    177188  } 
  • roard/codecfilter_wave.c

    r2607 r2816  
    154154 struct codecfilter_wave_inst * self = (struct codecfilter_wave_inst *) inst; 
    155155 struct roar_stream           * s    = ROAR_STREAM(self->stream); 
    156  char header[44]; 
     156 void   * header; 
    157157 int32_t  tmp32; 
    158158 int16_t  tmp16; 
    159159 int16_t  bits; 
    160160 int16_t  codec; 
     161 int      sid; 
    161162 
    162163 ROAR_DBG("cf_wave_write(inst=%p, buf=%p, len=%i) = ?", inst, buf, len); 
     
    169170  if ( s->fh == -1 ) { 
    170171   errno = EAGAIN; 
     172   return -1; 
     173  } 
     174 
     175  sid = ROAR_STREAM(self->stream)->id; 
     176 
     177  if ( stream_prethru_destroy(sid) == -1 ) { 
     178   return -1; 
     179  } 
     180 
     181  if ( stream_prethru_add_data(sid, &header, 44) == -1 ) { 
    171182   return -1; 
    172183  } 
  • roard/include/codecfilter.h

    r2686 r2816  
    3232struct roar_stream_server; 
    3333 
    34 #define ROAR_CODECFILTER_NONE  0 
    35 #define ROAR_CODECFILTER_READ  1 
    36 #define ROAR_CODECFILTER_WRITE 2 
     34#define ROAR_CODECFILTER_NONE        0x00 
     35#define ROAR_CODECFILTER_READ        0x01 
     36#define ROAR_CODECFILTER_WRITE       0x02 
     37#define ROAR_CODECFILTER_PRETHRU     0x04 /* we have support for prethru */ 
     38#define ROAR_CODECFILTER_PRETHRU_NN  0x08 /* prethru Not Needed          */ 
    3739 
    3840 
  • roard/include/streams.h

    r2625 r2816  
    8080 struct roar_buffer * outputbuffer; 
    8181 int state; 
     82 struct roar_buffer * prethru; 
    8283} * g_streams[ROAR_STREAMS_MAX]; 
    8384 
     
    135136int stream_outputbuffer_destroy(int id); 
    136137 
     138int stream_prethru_add(int id, struct roar_buffer * buf); 
     139int stream_prethru_add_data(int id, void ** buf, size_t len); 
     140int stream_prethru_destroy(int id); 
     141int stream_prethru_send(int dst, int src); 
     142 
    137143int streams_check      (int id); 
    138144int streams_send_mon   (int id); 
  • roard/streams.c

    r2766 r2816  
    104104   s->ready           =  0; 
    105105   s->outputbuffer    = NULL; 
     106   s->prethru         = NULL; 
    106107 
    107108   s->mixer.scale     = 65535; 
     
    228229 
    229230 stream_outputbuffer_destroy(id); 
     231 stream_prethru_destroy(id); 
    230232 
    231233 if ( s->buffer != NULL ) 
     
    421423  return -1; 
    422424 
     425 dir = ROAR_STREAM(ss)->dir; 
     426 
    423427 ROAR_DBG("streams_set_fh(id=%i): g_streams[id]->id=%i", id, s->id); 
    424428 
     
    435439 } 
    436440 
    437  if ( codecfilter_open(&(ss->codecfilter_inst), &(ss->codecfilter), NULL, 
    438                   s->info.codec, ss) == -1 ) { 
    439   return streams_delete(id); // TODO: FIXME: is this correct? shoudn't we return -1 in any case here? 
    440  } 
     441 ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); 
     442 
     443 if ( dir != ROAR_DIR_THRU ) { 
     444  if ( codecfilter_open(&(ss->codecfilter_inst), &(ss->codecfilter), NULL, 
     445                   s->info.codec, ss) == -1 ) { 
     446   return streams_delete(id); // TODO: FIXME: is this correct? shoudn't we return -1 in any case here? 
     447  } 
     448 } 
     449 
     450 ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); 
    441451 
    442452 if ( fh == -2 ) { 
     
    454464 } 
    455465 
     466 ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); 
     467 
    456468 if ( fh == -1 || fh == -2 ) { // yes, this is valid, indecats full vio! 
    457469  ss->ready = 1; 
     
    460472 } 
    461473 
     474 ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); 
     475 
    462476// roar_socket_recvbuf(fh, ROAR_OUTPUT_CALC_OUTBUFSIZE( &(ROAR_STREAM(g_streams[id])->info) )); // set recv buffer to minimum 
    463  
    464  dir = ROAR_STREAM(ss)->dir; 
    465477 
    466478 switch (dir) { 
     
    493505  ss->ready = 1; 
    494506  ss->state = ROAR_STREAMSTATE_NEW; 
     507 
     508  ROAR_DBG("streams_set_fh(id=%i, fh=%i) = 0", id, fh); 
    495509  return 0; 
    496510 } else { 
     
    502516  ss->ready = 1; 
    503517  ss->state = ROAR_STREAMSTATE_NEW; 
     518 
     519  ROAR_DBG("streams_set_fh(id=%i, fh=%i) = 0", id, fh); 
    504520  return 0; 
    505521 } 
     
    11711187 } 
    11721188 
     1189 return 0; 
     1190} 
     1191 
     1192int stream_prethru_add(int id, struct roar_buffer * buf) { 
     1193 register struct roar_stream_server *  ss; 
     1194 
     1195 _CHECK_SID(id); 
     1196 
     1197 if ( (ss = g_streams[id]) == NULL ) 
     1198  return -1; 
     1199 
     1200 if ( ss->prethru == NULL ) { 
     1201  ss->prethru = buf; 
     1202  return 0; 
     1203 } 
     1204 
     1205 if ( roar_buffer_add(ss->prethru, buf) == -1 ) { 
     1206  return -1; 
     1207 } 
     1208 
     1209 return 0; 
     1210} 
     1211 
     1212int stream_prethru_add_data(int id, void ** buf, size_t len) { 
     1213 struct roar_buffer * buffer; 
     1214 
     1215 _CHECK_SID(id); 
     1216 
     1217 if ( roar_buffer_new(&buffer, len) == -1 ) 
     1218  return -1; 
     1219 
     1220 if ( roar_buffer_get_data(buffer, buf) == -1 ) { 
     1221  roar_buffer_free(buffer); 
     1222  return -1; 
     1223 } 
     1224 
     1225 if ( stream_prethru_add(id, buffer) == -1 ) { 
     1226  roar_buffer_free(buffer); 
     1227  return -1; 
     1228 } 
     1229 
     1230 return 0; 
     1231} 
     1232 
     1233int stream_prethru_destroy(int id) { 
     1234 int ret; 
     1235 register struct roar_stream_server *  ss; 
     1236 
     1237 _CHECK_SID(id); 
     1238 
     1239 if ( (ss = g_streams[id]) == NULL ) 
     1240  return -1; 
     1241 
     1242 if ( ss->prethru != NULL ) { 
     1243  ret = roar_buffer_free(ss->prethru); 
     1244  ss->prethru = NULL; 
     1245  return ret; 
     1246 } 
     1247 
     1248 return 0; 
     1249} 
     1250 
     1251int stream_prethru_send(int dst, int src) { 
     1252 struct roar_stream_server *  dst_ss, * src_ss; 
     1253 struct roar_buffer * bufbuf; 
     1254 void * bufdata; 
     1255 size_t buflen; 
     1256 
     1257 ROAR_DBG("stream_prethru_send(dst=%i, src=%i) = ?", dst, src); 
     1258 
     1259 _CHECK_SID(dst); 
     1260 _CHECK_SID(src); 
     1261 
     1262 if ( (dst_ss = g_streams[dst]) == NULL ) 
     1263  return -1; 
     1264 
     1265 if ( (src_ss = g_streams[src]) == NULL ) 
     1266  return -1; 
     1267 
     1268 bufbuf = src_ss->prethru; 
     1269 
     1270 ROAR_DBG("stream_prethru_send(dst=%i, src=%i): prethru buffer at %p", dst, src, bufbuf); 
     1271 
     1272 while (bufbuf != NULL) { 
     1273  ROAR_DBG("stream_prethru_send(dst=%i, src=%i): looping with buffer at %p", dst, src, bufbuf); 
     1274 
     1275  if ( roar_buffer_get_data(bufbuf, &bufdata) == -1 ) 
     1276   return -1; 
     1277 
     1278  if ( roar_buffer_get_len(bufbuf, &buflen) == -1 ) 
     1279   return -1; 
     1280 
     1281  if ( stream_vio_s_write(dst_ss, bufdata, buflen) != buflen ) 
     1282   return -1; 
     1283 
     1284  if ( roar_buffer_get_next(bufbuf, &bufbuf) == -1 ) 
     1285   return -1; 
     1286 } 
     1287 
     1288 ROAR_DBG("stream_prethru_send(dst=%i, src=%i) = 0", dst, src); 
    11731289 return 0; 
    11741290} 
     
    16141730  return -1; 
    16151731 
    1616  if ( streams_thru_num ) 
    1617   for (i = 0; i < ROAR_STREAMS_MAX; i++) 
    1618    if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == ROAR_STREAM(stream)->id ) 
    1619     if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) 
    1620      if ( g_streams[i]->ready ) 
     1732 if ( streams_thru_num ) { 
     1733  for (i = 0; i < ROAR_STREAMS_MAX; i++) { 
     1734   if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == ROAR_STREAM(stream)->id ) { 
     1735    if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) { 
     1736     if ( g_streams[i]->ready ) { 
    16211737      if ( stream_vio_write(i, orig_buf, len) != len ) 
    16221738       streams_delete(i); 
     1739 
     1740      if ( g_streams[i] != NULL ) 
     1741       g_streams[i]->state = ROAR_STREAMSTATE_OLD; 
     1742     } 
     1743    } 
     1744   } 
     1745  } 
     1746 } 
    16231747 
    16241748 return len; 
     
    16401764// ROAR_WARN("stream_vio_s_write(*): writing..."); 
    16411765 
    1642  if ( streams_thru_num ) 
    1643   for (i = 0; i < ROAR_STREAMS_MAX; i++) 
    1644    if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == ROAR_STREAM(stream)->id ) 
    1645     if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) 
    1646      if ( g_streams[i]->ready ) 
    1647       if ( stream_vio_write(i, buf, count) != count ) 
     1766 if ( streams_thru_num ) { 
     1767  for (i = 0; i < ROAR_STREAMS_MAX; i++) { 
     1768   if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == ROAR_STREAM(stream)->id ) { 
     1769    if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) { 
     1770     if ( g_streams[i]->ready ) { 
     1771      if ( g_streams[i]->state == ROAR_STREAMSTATE_NEW ) { 
     1772       if ( streams_get_flag(i, ROAR_FLAG_PRETHRU) == 1 ) { 
     1773         if ( stream_prethru_send(i, ROAR_STREAM(stream)->id) == -1 ) { 
     1774         streams_delete(i); 
     1775        } 
     1776       } 
     1777      } 
     1778 
     1779      if ( stream_vio_write(i, buf, count) != count ) { 
    16481780       streams_delete(i); 
     1781      } 
     1782 
     1783      if ( g_streams[i] != NULL ) 
     1784       g_streams[i]->state = ROAR_STREAMSTATE_OLD; 
     1785     } 
     1786    } 
     1787   } 
     1788  } 
     1789 } 
    16491790 
    16501791 return roar_vio_write(&(stream->vio), buf, count); 
Note: See TracChangeset for help on using the changeset viewer.