Changeset 4626:bd2f6332d653 in roaraudio


Ignore:
Timestamp:
11/27/10 05:43:32 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support for buffered VS API (Closes: #2)

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4625 r4626  
    11v. 0.4beta2 - ? 
    22        * Announce standards via OpenSLP (Closes: #5) 
    3         * Updated VS API (Closes: #54, #3) 
     3        * Updated VS API (Closes: #54, #3, #2) 
    44        * Added support for CRC24 (RFC 4880) 
    55        * Added Base64 support. 
  • include/libroar/vs.h

    r4622 r4626  
    8282 */ 
    8383roar_vs_t * roar_vs_new_from_file(const char * server, const char * name, char * filename, int * error); 
     84 
     85int roar_vs_buffer(roar_vs_t * vss, size_t buffer, int * error); 
     86 
    8487 
    8588/* Boolean TRUE for VS functions */ 
     
    228231int     roar_vs_run           (roar_vs_t * vss, int * error); 
    229232 
     233ssize_t roar_vs_get_avail_read(roar_vs_t * vss, int * error); 
     234ssize_t roar_vs_get_avail_write(roar_vs_t * vss, int * error); 
     235 
    230236/* Misc controls. 
    231237 */ 
     
    243249int     roar_vs_ctl           (roar_vs_t * vss, roar_vs_ctlcmd cmd, void * argp, int * error); 
    244250 
     251 
    245252/* Get used connection object 
    246253 * This may be useful if you want to use functions from the main API. 
  • libroar/vs.c

    r4622 r4626  
    6363 struct roar_vio_calls    file_store; 
    6464 struct roar_vio_calls  * file; 
     65 struct roar_buffer     * readring, * writering; 
    6566}; 
    6667 
     
    340341} 
    341342 
     343int roar_vs_buffer(roar_vs_t * vss, size_t buffer, int * error) { 
     344 _ckvss(-1); 
     345 
     346 if ( vss->flags & FLAG_BUFFERED ) 
     347  return -1; 
     348 
     349 if ( roar_buffer_ring_new(&(vss->readring), buffer, 0) == -1 ) { 
     350  _seterrre(); 
     351  return -1; 
     352 } 
     353 
     354 if ( roar_buffer_ring_new(&(vss->writering), buffer, 0) == -1 ) { 
     355  _seterrre(); 
     356  roar_buffer_free(vss->readring); 
     357  vss->readring = NULL; 
     358  return -1; 
     359 } 
     360 
     361 vss->flags |= FLAG_BUFFERED; 
     362 
     363 return 0; 
     364} 
     365 
    342366int roar_vs_close(roar_vs_t * vss, int killit, int * error) { 
    343367 if ( killit != ROAR_VS_TRUE && killit != ROAR_VS_FALSE ) { 
     
    353377  roar_buffer_free(vss->writebuffer); 
    354378 
     379 if ( vss->readring != NULL ) 
     380  roar_buffer_free(vss->readring); 
     381 if ( vss->writering != NULL ) 
     382  roar_buffer_free(vss->writering); 
     383 
    355384 if ( vss->file != NULL && vss->flags & FLAG_CLOSEFILE ) 
    356385  roar_vio_close(vss->file); 
     
    372401} 
    373402 
    374 ssize_t roar_vs_write(roar_vs_t * vss, const void * buf, size_t len, int * error) { 
    375  ssize_t ret; 
    376  
    377  _ckvss(-1); 
    378  
    379  if ( !(vss->flags & FLAG_STREAM) ) { 
    380   _seterr(ROAR_ERROR_INVAL); 
    381   return -1; 
    382  } 
    383  
    384  _initerr(); 
    385  
    386  ret = roar_vio_write(&(vss->vio), (void*)buf, len); 
     403static ssize_t roar_vs_write_direct(roar_vs_t * vss, const void * buf, size_t len, int * error) { 
     404 ssize_t ret = roar_vio_write(&(vss->vio), (void*)buf, len); 
    387405 
    388406 if ( ret == -1 ) { 
     
    400418 } else { 
    401419  vss->writec += ret; 
     420 } 
     421 
     422 return ret; 
     423} 
     424 
     425ssize_t roar_vs_write(roar_vs_t * vss, const void * buf, size_t len, int * error) { 
     426 ssize_t ret; 
     427 size_t writelen; 
     428 
     429 _ckvss(-1); 
     430 
     431 if ( !(vss->flags & FLAG_STREAM) ) { 
     432  _seterr(ROAR_ERROR_INVAL); 
     433  return -1; 
     434 } 
     435 
     436 _initerr(); 
     437 
     438 if ( vss->flags & FLAG_BUFFERED ) { 
     439  writelen = len; 
     440 
     441  if ( roar_buffer_ring_write(vss->writering, (void*)buf, &writelen) == -1 ) { 
     442   _seterrre(); 
     443   return -1; 
     444  } 
     445 
     446  ret = writelen; 
     447  vss->writec += ret; 
     448 } else { 
     449  ret = roar_vs_write_direct(vss, buf, len, error); 
    402450 } 
    403451 
     
    905953 int is_eof = 0; 
    906954 void * data; 
     955 size_t tmp; 
     956 
     957 // TODO: fix error handling below. 
    907958 
    908959 _ckvss(-1); 
     
    938989// part 2 of above hack: 
    939990// emulate read handle. 
    940   vios[len].ud.vp   = vss->file; 
    941   vios[len].eventsa = ROAR_VIO_SELECT_WRITE|ROAR_VIO_SELECT_READ;; 
    942   len++; 
     991  if ( vss->file != NULL ) { 
     992   vios[len].ud.vp   = vss->file; 
     993   vios[len].eventsa = ROAR_VIO_SELECT_WRITE|ROAR_VIO_SELECT_READ; 
     994   len++; 
     995  } 
    943996 
    944997 // no error here nor EOF. 
     
    9601013  } else if ( vios[i].ud.vp == vss->con ) { 
    9611014   roar_sync(vss->con); 
    962   } else if ( vios[i].ud.vp == vss->file ) { 
     1015  } else if ( vss->file != NULL && vios[i].ud.vp == vss->file ) { 
    9631016   if ( vios[i].eventsa & ROAR_VIO_SELECT_READ ) 
    9641017    can_write++; 
     
    9711024 } 
    9721025 
     1026 if ( vss->flags & FLAG_BUFFERED ) { 
     1027  if ( roar_buffer_ring_avail(vss->readring, NULL, &tmp) != -1 ) 
     1028   if ( tmp > 0 ) 
     1029    can_read++; 
     1030 
     1031  if ( roar_buffer_ring_avail(vss->writering, &tmp, NULL) != -1 ) 
     1032   if ( tmp > 0 ) 
     1033    can_write++; 
     1034 } 
     1035 
     1036 ROAR_DBG("roar_vs_iterate(vss=%p, wait=%i, error=%p): can_read=%i, can_write=%i", vss, wait, error, can_read, can_write); 
     1037 
    9731038 // TODO: FIXME: Need to correct error handling here! 
    9741039 
     
    9801045   return -1; 
    9811046 
    982   ret = roar_vs_write(vss, data, len, error); 
     1047  ret = roar_vs_write_direct(vss, data, len, error); 
    9831048 
    9841049  if ( ret == -1 ) { 
     
    10341099    return -1; 
    10351100 
    1036    ret = roar_vio_write(vss->file, data, len); 
     1101   if ( vss->flags & FLAG_BUFFERED ) { 
     1102    tmp = len; 
     1103    if ( roar_buffer_ring_write(vss->readring, data, &tmp) == -1 ) { 
     1104     ret = -1; 
     1105    } else { 
     1106     ret = tmp; 
     1107    } 
     1108   } else { 
     1109    ret = roar_vio_write(vss->file, data, len); 
     1110   } 
    10371111 
    10381112   if ( ret == -1 ) { 
     
    10521126   return -1; 
    10531127 
    1054   ret = roar_vio_read(vss->file, data, len); 
     1128  if ( vss->flags & FLAG_BUFFERED ) { 
     1129   tmp = len; 
     1130   if ( roar_buffer_ring_read(vss->writering, data, &tmp) == -1 ) { 
     1131    ret = -1; 
     1132   } else { 
     1133    ret = tmp; 
     1134   } 
     1135  } else { 
     1136   ret = roar_vio_read(vss->file, data, len); 
     1137  } 
    10551138 
    10561139  ROAR_DBG("roar_vs_iterate(vss=%p, wait=%i, error=%p): ret=%lli", vss, wait, error, (long long int)ret); 
     
    10791162   ROAR_DBG("roar_vs_iterate(vss=%p, wait=%i, error=%p) = ?", vss, wait, error); 
    10801163 
    1081    ret = roar_vs_write(vss, data, len, error); 
     1164   ret = roar_vs_write_direct(vss, data, len, error); 
    10821165 
    10831166   if ( ret == -1 ) { 
     
    11161199} 
    11171200 
     1201ssize_t roar_vs_get_avail_read(roar_vs_t * vss, int * error) { 
     1202 size_t len; 
     1203 
     1204 _ckvss(-1); 
     1205 
     1206 if ( !(vss->flags & FLAG_BUFFERED) ) { 
     1207  _seterr(ROAR_ERROR_INVAL); 
     1208  return -1; 
     1209 } 
     1210 
     1211 if ( roar_buffer_ring_avail(vss->readring, &len, NULL) == -1 ) { 
     1212  _seterrre(); 
     1213  return -1; 
     1214 } 
     1215 
     1216 return len; 
     1217} 
     1218 
     1219ssize_t roar_vs_get_avail_write(roar_vs_t * vss, int * error) { 
     1220 size_t len; 
     1221 
     1222 _ckvss(-1); 
     1223 
     1224 if ( !(vss->flags & FLAG_BUFFERED) ) { 
     1225  _seterr(ROAR_ERROR_INVAL); 
     1226  return -1; 
     1227 } 
     1228 
     1229 if ( roar_buffer_ring_avail(vss->writering, NULL, &len) == -1 ) { 
     1230  _seterrre(); 
     1231  return -1; 
     1232 } 
     1233 
     1234 return len; 
     1235} 
     1236 
    11181237int     roar_vs_ctl           (roar_vs_t * vss, roar_vs_ctlcmd cmd, void * argp, int * error) { 
    11191238 _ckvss(-1); 
Note: See TracChangeset for help on using the changeset viewer.