Changeset 3869:c63e1367041c in roaraudio


Ignore:
Timestamp:
05/19/10 22:14:22 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

fixed long outstanding Con vs. VIO bug

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r3810 r3869  
    66        * Fixed some problems with minimal builds 
    77        * Some Copyright fixes 
     8        * much better VIO support for connections 
    89 
    910v. 0.3beta5 - Sun May 02 2010 12:41 CEST 
  • include/libroar/basic.h

    r3836 r3869  
    4747#endif 
    4848 
     49#define ROAR_CON_FLAGS_NONE        0x00 
     50#define ROAR_CON_FLAGS_FH          0x01 
     51#define ROAR_CON_FLAGS_VIO         0x02 
     52 
    4953struct roar_message { 
    5054 int cmd; 
     
    7276int roar_get_connection_fh  (struct roar_connection * con); 
    7377int roar_get_connection_vio (struct roar_connection * con, struct roar_vio_calls * vio); 
     78struct roar_vio_calls * roar_get_connection_vio2 (struct roar_connection * con); 
    7479int roar_disconnect   (struct roar_connection * con); 
    7580 
  • libroar/basic.c

    r3836 r3869  
    231231 memset(con, 0, sizeof(struct roar_connection)); 
    232232 
    233  con->__fh = fh; 
     233 con->flags = ROAR_CON_FLAGS_FH; 
     234 con->__fh  = fh; 
     235 
     236 if ( roar_vio_open_fh_socket(&(con->viocon), fh) != -1 ) 
     237  con->flags |= ROAR_CON_FLAGS_VIO; 
    234238 
    235239 roar_errno = ROAR_ERROR_NONE; 
     
    238242 
    239243int roar_get_connection_fh (struct roar_connection * con) { 
    240  roar_debug_warn_sysio("roar_get_connection_fh", "roar_get_connection_vio", NULL); 
     244 roar_debug_warn_sysio("roar_get_connection_fh", "roar_get_connection_vio2", NULL); 
    241245 
    242246 if ( con == NULL ) 
    243247  return -1; 
    244248 
     249 if ( !(con->flags & ROAR_CON_FLAGS_FH) ) 
     250  return -1; 
     251 
    245252 return con->__fh; 
    246253} 
    247254 
    248255int roar_get_connection_vio (struct roar_connection * con, struct roar_vio_calls * vio) { 
     256 roar_debug_warn_obsolete("roar_get_connection_vio", "roar_get_connection_vio2", NULL); 
     257 
    249258 if ( con == NULL || vio == NULL ) 
    250259  return -1; 
    251260 
     261 if ( !(con->flags & ROAR_CON_FLAGS_FH) ) 
     262  return -1; 
     263 
    252264 return roar_vio_open_fh_socket(vio, con->__fh); 
    253265} 
    254266 
     267struct roar_vio_calls * roar_get_connection_vio2 (struct roar_connection * con) { 
     268 if ( con == NULL ) 
     269  return NULL; 
     270 
     271 if ( con->flags & ROAR_CON_FLAGS_VIO ) 
     272  return &(con->viocon); 
     273 
     274// TODO: try to open the VIO. 
     275 
     276 return NULL; 
     277} 
     278 
    255279int roar_disconnect (struct roar_connection * con) { 
    256  struct roar_vio_calls vio; 
     280 struct roar_vio_calls * vio; 
    257281 struct roar_message m; 
    258282 
     
    264288 roar_req(con, &m, NULL); 
    265289 
    266  if ( roar_get_connection_vio(con, &vio) != -1 ) { 
    267   roar_vio_close(&vio); 
     290 if ( (vio = roar_get_connection_vio2(con)) != NULL ) { 
     291  roar_vio_close(vio); 
    268292 } 
    269293 
     
    329353#define _ROAR_MESS_BUF_LEN (1 /* version */ + 1 /* cmd */ + 2 /* stream */ + 4 /* pos */ + 2 /* datalen */) 
    330354int roar_send_message (struct roar_connection * con, struct roar_message * mes, char * data) { 
    331  struct roar_vio_calls vio; 
    332  
    333  if ( roar_get_connection_vio(con, &vio) == -1 ) 
    334   return -1; 
    335  
    336  return roar_vsend_message(&vio, mes, data); 
     355 struct roar_vio_calls * vio; 
     356 
     357 if ( (vio = roar_get_connection_vio2(con)) == NULL ) 
     358  return -1; 
     359 
     360 return roar_vsend_message(vio, mes, data); 
    337361} 
    338362 
     
    369393 
    370394int roar_recv_message (struct roar_connection * con, struct roar_message * mes, char ** data) { 
    371  struct roar_vio_calls vio; 
    372  
    373  if ( roar_get_connection_vio(con, &vio) == -1 ) 
    374   return -1; 
    375  
    376  return roar_vrecv_message(&vio, mes, data); 
     395 struct roar_vio_calls * vio; 
     396 
     397 if ( (vio = roar_get_connection_vio2(con)) == NULL ) 
     398  return -1; 
     399 
     400 return roar_vrecv_message(vio, mes, data); 
    377401} 
    378402 
     
    464488 
    465489int roar_req (struct roar_connection * con, struct roar_message * mes, char ** data) { 
    466  struct roar_vio_calls vio; 
    467  
    468  if ( roar_get_connection_vio(con, &vio) == -1 ) 
    469   return -1; 
    470  
    471  return roar_vreq(&vio, mes, data); 
     490 struct roar_vio_calls * vio; 
     491 
     492 if ( (vio = roar_get_connection_vio2(con)) == NULL ) 
     493  return -1; 
     494 
     495 return roar_vreq(vio, mes, data); 
    472496} 
    473497 
  • roard/driver_portaudio.c

    r3751 r3869  
    3333#ifdef ROAR_HAVE_LIBPABLIO 
    3434 long flags = PABLIO_WRITE; 
     35#elif defined(ROAR_HAVE_LIBPORTAUDIO_V0_19) 
     36 PaError err; 
     37 PaStreamParameters params; 
    3538#endif 
    3639 
     
    102105 
    103106 return 0; 
     107#elif defined(ROAR_HAVE_LIBPORTAUDIO_V0_19) 
     108 params.device                    = Pa_GetDefaultOutputDevice(); 
     109 params.channelCount              = info->channels; 
     110 params.sampleFormat              = fmt; 
     111 params.suggestedLatency          = Pa_GetDeviceInfo(params.device)->defaultLowOutputLatency; 
     112 params.hostApiSpecificStreamInfo = NULL; 
     113 
     114 // TODO: FIXME: use libroar for this. 
     115 self->framesize = info->bits * info->channels / 8; 
     116 
     117 // Sets up blocking I/O stream. 
     118#if 0 
     119 err = Pa_OpenStream(&(self->stream), 
     120                     NULL, 
     121                     &params, 
     122                     info->rate, 
     123                     128 /*FIXME:frames*/, 
     124                     paClipOff, 
     125                     NULL, 
     126                     NULL 
     127                    ); 
     128#endif 
     129 
     130 if ( err != paNoError ) { 
     131  ROAR_ERR("driver_portaudio_open(*): Could not open PortAudio device: \"%s\".", Pa_GetErrorText(err)); 
     132  roar_mm_free(self); 
     133  return -1; 
     134 } 
     135 
     136 err = Pa_StartStream(self->stream); 
     137 
     138 if ( err != paNoError ) { 
     139  ROAR_ERR("driver_portaudio_open(*): Could not start stream: \"%s\".", Pa_GetErrorText(err)); 
     140  roar_mm_free(self); 
     141  return -1; 
     142 } 
     143 
     144 return 0; 
    104145#else 
    105146 return -1; 
     
    110151 struct driver_portaudio * self = vio->inst; 
    111152 
     153 // TODO: cleanup common code. 
     154 
    112155#ifdef ROAR_HAVE_LIBPABLIO 
    113156 CloseAudioStream(self->ostream); 
     
    116159 
    117160 roar_mm_free(self); 
     161 
     162 return 0; 
     163#elif defined(ROAR_HAVE_LIBPORTAUDIO_V0_19) 
     164 if ( (self != NULL) && (self->stream != NULL) ) { 
     165  Pa_StopStream(self->stream); 
     166  Pa_CloseStream(self->stream); 
     167 } 
     168 
     169 roar_mm_free(self); 
     170 
     171 Pa_Terminate(); 
    118172 
    119173 return 0; 
     
    132186 ROAR_DBG("driver_portaudio_write(vio=%p, buf=%p, count=%llu) = ? // PABLIO mode", vio, buf, (long long unsigned int)count); 
    133187 return WriteAudioStream(self->ostream, buf, count) * self->ostream->bytesPerFrame; 
     188#elif defined(ROAR_HAVE_LIBPORTAUDIO_V0_19) 
     189 size_t write_frames = count / self->framesize; 
     190 PaError err; 
     191 
     192 ROAR_DBG("driver_portaudio_write(vio=%p, buf=%p, size=%llu) = ?", vio, buf, (long long unsigned int)size); 
     193 
     194 // I'm not 100% sure if you could write arbitrary number of frames to Pa_WriteStream(), but it seems to be backend dependent. 
     195 err = Pa_WriteStream(self->stream, buf, write_frames); 
     196 
     197 if ( err < 0 && err != paOutputUnderflowed ) 
     198  return -1; 
     199 
     200 // PA always seems to write requested size, or it will error out. 
     201 return count; 
    134202#else 
    135203 return -1; 
  • roard/include/driver_portaudio.h

    r3751 r3869  
    2727#define _DRIVER_PORTAUDIO_H_ 
    2828 
     29//#undef ROAR_HAVE_LIBPABLIO 
     30//#define ROAR_HAVE_LIBPORTAUDIO_V0_19 
     31 
    2932#ifdef ROAR_HAVE_LIBPORTAUDIO 
    30 #if defined(ROAR_HAVE_LIBPABLIO) 
     33#if defined(ROAR_HAVE_LIBPABLIO) || defined(ROAR_HAVE_LIBPORTAUDIO_V0_19) 
    3134#define _DRIVER_PORTAUDIO_CAN_OPERATE 
    3235#endif 
     
    3841#ifdef ROAR_HAVE_LIBPABLIO 
    3942 PABLIO_Stream * ostream; 
     43#elif defined(ROAR_HAVE_LIBPORTAUDIO_V0_19) 
     44 PaStream *stream; 
     45 int framesize; 
    4046#endif 
    4147}; 
     48 
     49typedef struct { 
     50/* 
     51 params.device                    = Pa_GetDefaultOutputDevice(); 
     52 params.channelCount              = info->channels; 
     53 params.sampleFormat              = fmt; 
     54 params.suggestedLatency          = Pa_GetDeviceInfo(params.device)->defaultLowOutputLatency; 
     55 params.hostApiSpecificStreamInfo = NULL; 
     56*/ 
     57 void * device; 
     58 int channelCount; 
     59 PaSampleFormat sampleFormat; 
     60 int suggestedLatency; 
     61 void * hostApiSpecificStreamInfo; 
     62} PaStreamParameters; 
     63 
     64#define paOutputUnderflowed -1 
     65 
     66void *  Pa_GetDefaultOutputDevice(void); 
     67// Pa_WriteStream(device->stream, buf, write_frames); 
     68PaError  Pa_WriteStream(PaStream * stream, void *, size_t); 
     69PaError Pa_StartStream(PaStream * stream); 
     70PaError Pa_StopStream(PaStream * stream); 
     71PaError Pa_CloseStream(PaStream * stream); 
    4272 
    4373int driver_portaudio_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream); 
Note: See TracChangeset for help on using the changeset viewer.