Changeset 5022:b2a2e896974d in roaraudio for roarclients/roarcatvio.c
- Timestamp:
- 05/27/11 17:13:54 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roarclients/roarcatvio.c
r4708 r5022 44 44 45 45 int 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}; 49 47 int codec = -1; 48 int auinfo_changed = 0; 50 49 char * server = NULL; 51 50 char * k; 52 51 int i; 53 52 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; 64 56 65 57 for (i = 1; i < argc; i++) { … … 71 63 name = argv[++i]; 72 64 } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") ) { 73 rate = atoi(argv[++i]); 65 info.rate = roar_str2rate(argv[++i]); 66 auinfo_changed = 1; 74 67 } else if ( !strcmp(k, "--bits") ) { 75 bits = atoi(argv[++i]); 68 info.bits = roar_str2bits(argv[++i]); 69 auinfo_changed = 1; 76 70 } else if ( !strcmp(k, "-b") ) { 77 bits = 8; 71 info.bits = 8; 72 auinfo_changed = 1; 78 73 } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") ) { 79 channels = atoi(argv[++i]); 74 info.channels = roar_str2channels(argv[++i]); 75 auinfo_changed = 1; 80 76 } else if ( !strcmp(k, "-m") ) { 81 channels = 1; 77 info.channels = 1; 78 auinfo_changed = 1; 82 79 } else if ( !strcmp(k, "--codec") ) { 83 80 codec = roar_str2codec(argv[++i]); 81 auinfo_changed = 1; 84 82 } else if ( !strcmp(k, "--help") ) { 85 83 usage(); 86 84 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; 99 87 } else { 100 88 fprintf(stderr, "Error: unknown argument: %s\n", k); … … 107 95 codec = ROAR_CODEC_DEFAULT; 108 96 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; 112 103 } 113 104 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 } 115 112 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); 118 123 119 124 return 0;
Note: See TracChangeset
for help on using the changeset viewer.