source: roaraudio/roarclients/roarcatad.c @ 488:2ec5358c785e

Last change on this file since 488:2ec5358c785e was 488:2ec5358c785e, checked in by phi, 16 years ago

use optimal block size

File size: 1.8 KB
Line 
1//roarcatad.c:
2
3#include <roaraudio.h>
4
5#define BUFSIZE (1024*2)
6
7void usage (void) {
8 printf("roarcatad [OPTIONS]...\n");
9
10 printf("\nOptions:\n\n");
11
12 printf("  --server SERVER    - Set server hostname\n"
13        "  --rate   RATE      - Set sample rate\n"
14        "  --bits   BITS      - Set bits per sample\n"
15        "  --chans  CHANNELS  - Set number of channels\n"
16        "  --help             - Show this help\n"
17       );
18
19}
20
21int main (int argc, char * argv[]) {
22 int    rate     = 44100;
23 int    bits     = 16;
24 int    channels = 2;
25 int    codec    = ROAR_CODEC_DEFAULT;
26 char * server   = NULL;
27 char * k;
28 int    i;
29 char buf[BUFSIZE];
30 struct roar_connection con;
31 struct roar_stream     s;
32 struct roar_stream_info info;
33
34
35 for (i = 1; i < argc; i++) {
36  k = argv[i];
37
38  if ( strcmp(k, "--server") == 0 ) {
39   server = argv[++i];
40  } else if ( strcmp(k, "--rate") == 0 ) {
41   rate = atoi(argv[++i]);
42  } else if ( strcmp(k, "--bits") == 0 ) {
43   bits = atoi(argv[++i]);
44  } else if ( strcmp(k, "--channels") == 0 ) {
45   channels = atoi(argv[++i]);
46  } else if ( strcmp(k, "--help") == 0 ) {
47   usage();
48   return 0;
49  } else {
50   fprintf(stderr, "Error: unknown argument: %s\n", k);
51   usage();
52   return 1;
53  }
54 }
55
56 if ( roar_simple_connect(&con, server, "roarcatad") == -1 ) {
57  ROAR_DBG("roar_simple_play(*): roar_simple_connect() faild!");
58  return -1;
59 }
60
61 if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) {
62  roar_disconnect(&con);
63  return -1;
64 }
65
66 if ( roar_stream_connect(&con, &s, ROAR_DIR_PLAY) == -1 ) {
67  roar_disconnect(&con);
68  return -1;
69 }
70
71 info.block_size = BUFSIZE;
72
73 roar_stream_get_info(&con, &s, &info);
74
75 if ( info.block_size > BUFSIZE )
76  info.block_size = BUFSIZE;
77
78 while((i = read(0, buf, info.block_size)))
79  if (roar_stream_add_data(&con, &s, buf, i) == -1)
80   break;
81
82 roar_disconnect(&con);
83
84 return 0;
85}
86
87//ll
Note: See TracBrowser for help on using the repository browser.