source: roaraudio/roarclients/roarvorbis.c @ 117:b3b15c6ff97d

Last change on this file since 117:b3b15c6ff97d was 117:b3b15c6ff97d, checked in by phi, 16 years ago

get channels and rate form the file, a bit better output of meta data

File size: 3.1 KB
Line 
1//roarvorbis.c:
2
3#include <roaraudio.h>
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <math.h>
8#include <vorbis/codec.h>
9#include <vorbis/vorbisfile.h>
10
11#ifdef _WIN32
12#include <io.h>
13#include <fcntl.h>
14#endif
15
16#define BUFSIZE 1024
17
18void usage (void) {
19 printf("roarvorbis [OPTIONS]... FILE\n");
20
21 printf("\nOptions:\n\n");
22
23 printf("  --server SERVER    - Set server hostname\n"
24        "  --help             - Show this help\n"
25       );
26
27}
28
29int main (int argc, char * argv[]) {
30 int    bits     = 16;
31 int    codec    = ROAR_CODEC_DEFAULT;
32 char * server   = NULL;
33 char * file     = NULL;
34 char * k;
35 int    i;
36 FILE * in;
37 struct roar_connection con;
38 struct roar_stream     s;
39 OggVorbis_File vf;
40 int eof=0;
41 int current_section;
42 char pcmout[4096];
43
44
45 for (i = 1; i < argc; i++) {
46  k = argv[i];
47
48  if ( strcmp(k, "--server") == 0 ) {
49   server = argv[++i];
50  } else if ( strcmp(k, "--help") == 0 ) {
51   usage();
52   return 0;
53  } else if ( file == NULL ) {
54   file = k;
55  } else {
56   fprintf(stderr, "Error: unknown argument: %s\n", k);
57   usage();
58   return 1;
59  }
60 }
61
62 if ( roar_simple_connect(&con, server, "roarvorbis") == -1 ) {
63  ROAR_DBG("roar_simple_play(*): roar_simple_connect() faild!");
64  return -1;
65 }
66
67 if ( (in = fopen(file, "rb")) == NULL ) {
68  roar_disconnect(&con);
69  return -1;
70 }
71
72#ifdef _WIN32
73  _setmode(_fileno(in), _O_BINARY);
74#endif
75
76 if(ov_open(in, &vf, NULL, 0) < 0) {
77  fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
78  roar_disconnect(&con);
79  return -1;
80 }
81
82 {
83  char **ptr=ov_comment(&vf,-1)->user_comments;
84  char key[80], value[80];
85  int j, h = 0;
86  vorbis_info *vi=ov_info(&vf,-1);
87  struct roar_meta   meta;
88
89  fprintf(stderr, "Audio: %i channel, %liHz\n\n", vi->channels, vi->rate);
90
91  if ( roar_stream_new(&s, vi->rate, vi->channels, bits, codec) == -1 ) {
92   roar_disconnect(&con);
93   return -1;
94  }
95
96  if ( roar_stream_connect(&con, &s, ROAR_DIR_PLAY) == -1 ) {
97   roar_disconnect(&con);
98   return -1;
99  }
100
101  meta.value = value;
102  meta.key[0] = 0;
103
104  meta.type = ROAR_META_TYPE_FILENAME;
105  strncpy(value, file, 79);
106  roar_stream_meta_set(&con, &s, ROAR_META_MODE_SET, &meta);
107
108
109
110  while(*ptr){
111    for (j = 0; (*ptr)[j] != 0 && (*ptr)[j] != '='; j++)
112     key[j] = (*ptr)[j];
113     key[j] = 0;
114
115    for (j++, h = 0; (*ptr)[j] != 0 && (*ptr)[j] != '='; j++)
116     value[h++] = (*ptr)[j];
117     value[h]   = 0;
118
119    meta.type = roar_meta_inttype(key);
120    if ( meta.type != -1 )
121     roar_stream_meta_set(&con, &s, ROAR_META_MODE_SET, &meta);
122
123    fprintf(stderr, "Meta %-16s: %s\n", key, value);
124    ++ptr;
125  }
126
127 }
128
129 if ( roar_stream_exec(&con, &s) == -1 ) {
130  roar_disconnect(&con);
131  return -1;
132 }
133 
134 while (!eof) {
135  long ret = ov_read(&vf, pcmout, sizeof(pcmout), 0, 2, 1, &current_section);
136  if (ret == 0) {
137   /* EOF */
138   eof=1;
139  } else if (ret < 0) {
140   /* error in the stream.  Not a problem, just reporting it in
141      case we (the app) cares.  In this case, we don't. */
142  } else {
143     /* we don't bother dealing with sample rate changes, etc, but
144        you'll have to */
145    write(con.fh, pcmout, ret);
146  }
147 }
148
149  ov_clear(&vf);
150
151// fclose(in);
152 close(con.fh);
153
154 return 0;
155}
156
157//ll
Note: See TracBrowser for help on using the repository browser.