source: roaraudio/roarclients/roarvorbis.c @ 120:85463285ddbe

Last change on this file since 120:85463285ddbe was 120:85463285ddbe, checked in by phi, 16 years ago

now using roar_simple_new_stream_obj(), not an execed stream so we can do meta updates

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 int    out = -1;
38 struct roar_connection con;
39 struct roar_stream     s;
40 OggVorbis_File vf;
41 int eof=0;
42 int current_section;
43 int last_section = -1;
44 char pcmout[4096];
45
46
47 for (i = 1; i < argc; i++) {
48  k = argv[i];
49
50  if ( strcmp(k, "--server") == 0 ) {
51   server = argv[++i];
52  } else if ( strcmp(k, "--help") == 0 ) {
53   usage();
54   return 0;
55  } else if ( file == NULL ) {
56   file = k;
57  } else {
58   fprintf(stderr, "Error: unknown argument: %s\n", k);
59   usage();
60   return 1;
61  }
62 }
63
64 if ( roar_simple_connect(&con, server, "roarvorbis") == -1 ) {
65  ROAR_DBG("roar_simple_play(*): roar_simple_connect() faild!");
66  return -1;
67 }
68
69 if ( (in = fopen(file, "rb")) == NULL ) {
70  roar_disconnect(&con);
71  return -1;
72 }
73
74#ifdef _WIN32
75  _setmode(_fileno(in), _O_BINARY);
76#endif
77
78 if(ov_open(in, &vf, NULL, 0) < 0) {
79  fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
80  roar_disconnect(&con);
81  return -1;
82 }
83
84 {
85  vorbis_info *vi = ov_info(&vf, -1);
86
87  fprintf(stderr, "Audio: %i channel, %liHz\n\n", vi->channels, vi->rate);
88
89  if ( (out = roar_simple_new_stream_obj(&con, &s, vi->rate, vi->channels, bits, codec, ROAR_DIR_PLAY)) == -1 ) {
90   roar_disconnect(&con);
91   return -1;
92  }
93 }
94
95 {
96  char **ptr = ov_comment(&vf, -1)->user_comments;
97  char key[80], value[80];
98  int j, h = 0;
99  struct roar_meta   meta;
100
101  meta.value = value;
102  meta.key[0] = 0;
103
104  roar_stream_meta_set(&con, &s, ROAR_META_MODE_CLEAR, &meta);
105
106  meta.type = ROAR_META_TYPE_FILENAME;
107  strncpy(value, file, 79);
108  roar_stream_meta_set(&con, &s, ROAR_META_MODE_SET, &meta);
109
110
111
112  while(*ptr){
113    for (j = 0; (*ptr)[j] != 0 && (*ptr)[j] != '='; j++)
114     key[j] = (*ptr)[j];
115     key[j] = 0;
116
117    for (j++, h = 0; (*ptr)[j] != 0 && (*ptr)[j] != '='; j++)
118     value[h++] = (*ptr)[j];
119     value[h]   = 0;
120
121    meta.type = roar_meta_inttype(key);
122    if ( meta.type != -1 )
123     roar_stream_meta_set(&con, &s, ROAR_META_MODE_SET, &meta);
124
125    fprintf(stderr, "Meta %-16s: %s\n", key, value);
126    ++ptr;
127  }
128
129 }
130
131 while (!eof) {
132  long ret = ov_read(&vf, pcmout, sizeof(pcmout), 0, 2, 1, &current_section);
133
134  last_section = current_section;
135
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(out, pcmout, ret);
146  }
147 }
148
149  ov_clear(&vf);
150
151// fclose(in);
152 close(out);
153 roar_disconnect(&con);
154
155 return 0;
156}
157
158//ll
Note: See TracBrowser for help on using the repository browser.