Changeset 5116:ec18cb54f717 in roaraudio for libroar


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

rewrote roar_vio_simple_stream() to not use any deprecated functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/vio_stream.c

    r5115 r5116  
    3636#include "libroar.h" 
    3737 
     38static ssize_t _vio_stream_read    (struct roar_vio_calls * vio, void *buf, size_t count) { 
     39 return roar_vio_read(roar_get_connection_vio2(vio->inst), buf, count); 
     40} 
     41 
     42static ssize_t _vio_stream_write   (struct roar_vio_calls * vio, void *buf, size_t count) { 
     43 return roar_vio_write(roar_get_connection_vio2(vio->inst), buf, count); 
     44} 
     45 
     46static off_t   _vio_stream_lseek   (struct roar_vio_calls * vio, off_t offset, int whence) { 
     47 return roar_vio_lseek(roar_get_connection_vio2(vio->inst), offset, whence); 
     48} 
     49static int     _vio_stream_nonblock(struct roar_vio_calls * vio, int state) { 
     50 return roar_vio_nonblock(roar_get_connection_vio2(vio->inst), state); 
     51} 
     52static int     _vio_stream_sync    (struct roar_vio_calls * vio) { 
     53 return roar_vio_sync(roar_get_connection_vio2(vio->inst)); 
     54} 
     55static int     _vio_stream_ctl     (struct roar_vio_calls * vio, int cmd, void * data) { 
     56 if (vio == NULL) { 
     57  roar_err_set(ROAR_ERROR_FAULT); 
     58  return -1; 
     59 } 
     60 
     61 if (cmd == -1) { 
     62  roar_err_set(ROAR_ERROR_INVAL); 
     63  return -1; 
     64 } 
     65 
     66 switch (cmd) { 
     67  case ROAR_VIO_CTL_GET_NAME: 
     68    if ( data == NULL ) { 
     69     roar_err_set(ROAR_ERROR_FAULT); 
     70     return -1; 
     71    } 
     72 
     73    *(char**)data = "stream"; 
     74    return 0; 
     75   break; 
     76  case ROAR_VIO_CTL_GET_NEXT: 
     77    *(struct roar_vio_calls **)data = roar_get_connection_vio2(vio->inst); 
     78    return 0; 
     79   break; 
     80  case ROAR_VIO_CTL_SET_NEXT: 
     81    roar_err_set(ROAR_ERROR_NOTSUP); 
     82    return -1; 
     83   break; 
     84 } 
     85 
     86 return roar_vio_ctl(roar_get_connection_vio2(vio->inst), cmd, data); 
     87} 
     88 
     89static int     _vio_stream_close   (struct roar_vio_calls * vio) { 
     90 roar_vio_close(roar_get_connection_vio2(vio->inst)); 
     91 roar_mm_free(vio->inst); 
     92 
     93 return 0; 
     94} 
    3895 
    3996int     roar_vio_simple_stream (struct roar_vio_calls * calls, int rate, int channels, int bits, int codec, 
    4097                                                               const char * server, int dir, const char * name) { 
    41  int fh; 
     98 struct roar_connection * con = NULL; 
     99 struct roar_stream       stream; 
     100 int err; 
    42101 
    43102 if ( calls == NULL ) { 
     
    46105 } 
    47106 
    48  roar_libroar_nowarn(); 
    49  if ( (fh = roar_simple_stream(rate, channels, bits, codec, server, dir, name)) == -1 ) { 
    50   roar_libroar_warn(); 
     107 if ( roar_stream_new(&stream, rate, channels, bits, codec) == -1 ) 
     108  return -1; 
     109 
     110 con = roar_mm_malloc(sizeof(struct roar_connection)); 
     111 if ( con == NULL ) 
     112  return -1; 
     113 
     114 memset(con, 0, sizeof(struct roar_connection)); 
     115 
     116 if ( roar_simple_connect(con, server, name) == -1 ) { 
     117  err = roar_error; 
     118  roar_mm_free(con); 
     119  roar_error = err; 
    51120  return -1; 
    52121 } 
    53  roar_libroar_warn(); 
    54122 
    55  return roar_vio_open_fh_socket(calls, fh); 
     123 if ( roar_stream_connect(con, &stream, dir) == -1 ) { 
     124  err = roar_error; 
     125  roar_disconnect(con); 
     126  roar_mm_free(con); 
     127  roar_error = err; 
     128  return -1; 
     129 } 
     130 
     131 if ( roar_stream_exec(con, &stream) == -1 ) { 
     132  err = roar_error; 
     133  roar_disconnect(con); 
     134  roar_mm_free(con); 
     135  roar_error = err; 
     136  return -1; 
     137 } 
     138 
     139 roar_vio_clear_calls(calls); 
     140 
     141 calls->inst       = con; 
     142 calls->read       = _vio_stream_read; 
     143 calls->write      = _vio_stream_write; 
     144 calls->lseek      = _vio_stream_lseek; 
     145 calls->nonblock   = _vio_stream_nonblock; 
     146 calls->sync       = _vio_stream_sync; 
     147 calls->ctl        = _vio_stream_ctl; 
     148 calls->close      = _vio_stream_close; 
     149 
     150 if ( dir == ROAR_DIR_PLAY ) { 
     151  roar_vio_shutdown(calls, SHUT_RD); 
     152 } else if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD ) { 
     153  roar_vio_shutdown(calls, SHUT_WR); 
     154 } 
     155 
     156 return 0; 
    56157} 
    57158 
Note: See TracChangeset for help on using the changeset viewer.