Changeset 5022:b2a2e896974d in roaraudio for roarclients/roarcatvio.c


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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.