Changeset 5022:b2a2e896974d in roaraudio for roarclients


Ignore:
Timestamp:
05/27/11 17:13:54 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Converted most roarclients to to use VS API (See: #87)

Location:
roarclients
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarbidir.c

    r4997 r5022  
    5050 char * server   = NULL; 
    5151 char * k; 
    52  int    fh; 
    5352 int    i; 
    54  int    in  = -1; 
    55  int    out = -1; 
     53 struct roar_vio_defaults  def; 
     54 struct roar_vio_calls in_store; 
     55 struct roar_vio_calls * in = NULL, * out = NULL; 
     56 struct roar_vio_calls * vss_vio = NULL; 
     57 roar_vs_t * vss; 
     58 struct roar_vio_select vios[2]; 
    5659 char buf[BUFSIZE]; 
    57  fd_set sl; 
    58  struct timeval tv; 
    59  int max_fh; 
     60 int err; 
     61 ssize_t ret; 
     62 
     63 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) 
     64  return 1; 
    6065 
    6166 for (i = 1; i < argc; i++) { 
     
    7580   usage(); 
    7681   return 0; 
    77   } else if ( in == -1 ) { 
    78    if ( (in = open(k, O_RDONLY, 0644)) == -1 ) { 
    79     fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); 
     82  } else if ( in == NULL ) { 
     83   if ( roar_vio_open_dstr(&in_store, k, &def, 1) == -1 ) { 
     84    fprintf(stderr, "Error: can not open file: %s: %s\n", k, roar_error2str(roar_error)); 
    8085    return 1; 
    8186   } 
     87   in = &in_store; 
    8288  } else { 
    8389   fprintf(stderr, "Error: unknown argument: %s\n", k); 
     
    8793 } 
    8894 
    89  if ( (fh = roar_simple_stream(rate, channels, bits, codec, server, ROAR_DIR_BIDIR, "roarbidir")) == -1 ) { 
    90   fprintf(stderr, "Error: can not start playback: %s\n", roar_error2str(roar_error)); 
    91   if ( in != -1 ) 
    92    close(in); 
     95 if ( (vss = roar_vs_new_simple(server, "roarbidir", rate, channels, codec, bits, ROAR_DIR_BIDIR, &err)) == NULL ) { 
     96  fprintf(stderr, "Error: can not start playback: %s\n", roar_error2str(err)); 
     97  if ( in != NULL ) 
     98   roar_vio_close(in); 
    9399  return 1; 
    94100 } 
    95101 
    96  if ( in  == -1 ) 
    97   in  = ROAR_STDIN; 
    98  if ( out == -1 ) 
    99   out = ROAR_STDOUT; 
     102 if ( in  == NULL ) 
     103  in  = roar_stdin; 
     104 if ( out == NULL ) 
     105  out = roar_stdout; 
    100106 
    101  max_fh = (in > fh ? in : fh) + 1; 
    102  i      = 1; 
     107 vss_vio = roar_vs_vio_obj(vss, NULL); 
    103108 
    104  while (i > 0) { 
    105   FD_ZERO(&sl); 
    106   FD_SET(in, &sl); 
    107   FD_SET(fh, &sl); 
     109 while (1) { 
     110  memset(vios, 0, sizeof(vios)); 
    108111 
    109   tv.tv_sec  = 0; 
    110   tv.tv_usec = 50000; 
     112  ROAR_VIO_SELECT_SETVIO(&(vios[0]), vss_vio, ROAR_VIO_SELECT_READ); 
     113  ROAR_VIO_SELECT_SETVIO(&(vios[1]), in, ROAR_VIO_SELECT_READ); 
    111114 
    112   if (select(max_fh, &sl, NULL, NULL, &tv) > 0) { 
    113    if ( FD_ISSET(fh, &sl) ) { 
    114     if ( (i = read(fh, buf, BUFSIZE)) == -1 ) 
    115      return -1; 
    116     if ( write(out, buf, i) != i ) 
    117      return -1; 
    118    } 
    119    if ( FD_ISSET(in, &sl) ) { 
    120     if ( (i = read(in, buf, BUFSIZE)) == -1 ) 
    121      return -1; 
    122     if ( write(fh, buf, i) != i ) 
    123      return -1; 
    124    } 
     115  if ( (ret = roar_vio_select(vios, 2, NULL, NULL)) == -1 ) 
     116   break; 
     117 
     118  if ( ret < 0 ) 
     119   continue; 
     120 
     121  if ( vios[0].eventsa & ROAR_VIO_SELECT_READ ) { 
     122   if ( (ret = roar_vs_read(vss, buf, sizeof(buf), NULL)) == -1 ) 
     123    break; 
     124   if ( roar_vio_write(out, buf, ret) != ret ) 
     125    break; 
     126  } 
     127  if ( vios[1].eventsa & ROAR_VIO_SELECT_READ ) { 
     128   if ( (ret = roar_vio_read(in, buf, sizeof(buf))) == -1 ) 
     129    break; 
     130   if ( roar_vs_write(vss, buf, ret, NULL) != ret ) 
     131    break; 
    125132  } 
    126133 } 
    127134 
    128  roar_simple_close(fh); 
     135 roar_vs_close(vss, ROAR_VS_TRUE, NULL); 
    129136 
    130  close(in); 
     137 roar_vio_close(in); 
    131138 
    132139 return 0; 
  • roarclients/roarcatplay.c

    r4914 r5022  
    5454 int    bg      = 0; 
    5555 int    verbose = 0; 
     56 roar_vs_t * vss; 
     57 int err; 
    5658#ifdef ROAR_HAVE_UNIX 
    5759 struct roar_connection con[1]; 
     
    121123 } else { // MODE_SIMPLE 
    122124#endif 
    123   if ( roar_simple_play_file(file, server, "roarcatplay") == -1 ) { 
    124    ROAR_ERR("Can not start playback"); 
     125  if ( (vss = roar_vs_new_from_file(server, "roarcatplay", file, &err)) == NULL ) { 
     126   ROAR_ERR("Can not start playback: %s", roar_error2str(err)); 
    125127   return 1; 
    126128  } 
     129  roar_vs_run(vss, NULL); 
     130  roar_vs_sync(vss, ROAR_VS_WAIT, NULL); 
     131  roar_vs_close(vss, ROAR_VS_FALSE, NULL); 
    127132#ifdef ROAR_HAVE_UNIX 
    128133 } 
  • roarclients/roarcatvio.c

    r4708 r5022  
    4444 
    4545int main (int argc, char * argv[]) { 
    46  int    rate     = ROAR_RATE_DEFAULT; 
    47  int    bits     = ROAR_BITS_DEFAULT; 
    48  int    channels = ROAR_CHANNELS_DEFAULT; 
     46 struct roar_audio_info info = {.rate = ROAR_RATE_DEFAULT, .bits = ROAR_BITS_DEFAULT, .channels = ROAR_CHANNELS_DEFAULT}; 
    4947 int    codec    = -1; 
     48 int    auinfo_changed = 0; 
    5049 char * server   = NULL; 
    5150 char * k; 
    5251 int    i; 
    5352 char * name = "roarcatvio"; 
    54  struct roar_vio_calls file, stream; 
    55  struct roar_vio_defaults def; 
    56  int file_opened = 0; 
    57  const char * content_type; 
    58  
    59  if ( roar_vio_open_fh(&file, ROAR_STDIN) == -1 ) 
    60   return 1; 
    61  
    62  if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) 
    63   return 1; 
     53 roar_vs_t * vss; 
     54 char * filename = NULL; 
     55 int err; 
    6456 
    6557 for (i = 1; i < argc; i++) { 
     
    7163   name = argv[++i]; 
    7264  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") ) { 
    73    rate = atoi(argv[++i]); 
     65   info.rate = roar_str2rate(argv[++i]); 
     66   auinfo_changed = 1; 
    7467  } else if ( !strcmp(k, "--bits") ) { 
    75    bits = atoi(argv[++i]); 
     68   info.bits = roar_str2bits(argv[++i]); 
     69   auinfo_changed = 1; 
    7670  } else if ( !strcmp(k, "-b") ) { 
    77    bits = 8; 
     71   info.bits = 8; 
     72   auinfo_changed = 1; 
    7873  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") ) { 
    79    channels = atoi(argv[++i]); 
     74   info.channels = roar_str2channels(argv[++i]); 
     75   auinfo_changed = 1; 
    8076  } else if ( !strcmp(k, "-m") ) { 
    81    channels = 1; 
     77   info.channels = 1; 
     78   auinfo_changed = 1; 
    8279  } else if ( !strcmp(k, "--codec") ) { 
    8380   codec = roar_str2codec(argv[++i]); 
     81   auinfo_changed = 1; 
    8482  } else if ( !strcmp(k, "--help") ) { 
    8583   usage(); 
    8684   return 0; 
    87   } else if ( !file_opened ) { 
    88    file_opened = 1; 
    89    if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) { 
    90     fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); 
    91     return 1; 
    92    } 
    93  
    94    if ( codec == -1 ) { 
    95     if ( roar_vio_ctl(&file, ROAR_VIO_CTL_GET_MIMETYPE, &content_type) != -1 ) { 
    96      codec = roar_mime2codec(content_type); 
    97     } 
    98    } 
     85  } else if ( filename == NULL ) { 
     86   filename    = k; 
    9987  } else { 
    10088   fprintf(stderr, "Error: unknown argument: %s\n", k); 
     
    10795  codec = ROAR_CODEC_DEFAULT; 
    10896 
    109  if ( roar_vio_simple_stream(&stream, rate, channels, bits, codec, server, ROAR_DIR_PLAY, name) == -1 ) { 
    110   fprintf(stderr, "Error: can not start playback\n"); 
    111   return 1; 
     97 info.codec = codec; 
     98 
     99 if ( (vss = roar_vs_new(server, name, &err)) == NULL ) { 
     100  fprintf(stderr, "Error: can not connect to server: %s: %s\n", 
     101   server == NULL ? "(default)" : server, roar_error2str(err)); 
     102  return 10; 
    112103 } 
    113104 
    114  roar_vio_copy_data(&stream, &file); 
     105 if ( auinfo_changed ) { 
     106  if ( roar_vs_stream(vss, &info, ROAR_DIR_PLAY, &err) == -1 ) { 
     107   fprintf(stderr, "Error: can not create new stream: %s\n", roar_error2str(err)); 
     108   roar_vs_close(vss, ROAR_VS_TRUE, NULL); 
     109   return 10; 
     110  } 
     111 } 
    115112 
    116  roar_vio_close(&file); 
    117  roar_vio_close(&stream); 
     113 if ( roar_vs_file_simple(vss, filename, &err) == -1 ) { 
     114  fprintf(stderr, "Error: can not open file: %s: %s\n", filename, roar_error2str(err)); 
     115  roar_vs_close(vss, ROAR_VS_TRUE, NULL); 
     116  return 10; 
     117 } 
     118 
     119 roar_vs_run(vss, NULL); 
     120 
     121 roar_vs_sync(vss, ROAR_VS_WAIT, NULL); 
     122 roar_vs_close(vss, ROAR_VS_FALSE, NULL); 
    118123 
    119124 return 0; 
Note: See TracChangeset for help on using the changeset viewer.