source: roaraudio/roard/codecfilter_vorbis.c @ 205:1053e00bbeb7

Last change on this file since 205:1053e00bbeb7 was 205:1053e00bbeb7, checked in by phi, 16 years ago

playing around with cf_vorbis*

File size: 1.5 KB
Line 
1//codecfilter_vorbis.c:
2
3#include "roard.h"
4
5int cf_vorbis_open(CODECFILTER_USERDATA_T * inst, int codec,
6                                            struct roar_stream_server * info,
7                                            struct roar_codecfilter   * filter) {
8 struct codecfilter_vorbis_inst * self = malloc(sizeof(struct codecfilter_vorbis_inst));
9
10 if ( !self )
11  return -1;
12
13 self->current_section      = -1;
14 self->last_section         = -1;
15 self->opened               = 0;
16 self->stream               = info;
17// self->outlen               = ROAR_OUTPUT_BUFFER_SAMPLES * s->info.channels * s->info.bits / 8; // optimal size
18
19 if ( (self->in = fdopen(((struct roar_stream*)info)->fh, "r")) == NULL ) {
20  free((void*)self);
21  return -1;
22 }
23
24 *inst = (CODECFILTER_USERDATA_T) self;
25
26 return -1;
27}
28
29int cf_vorbis_close(CODECFILTER_USERDATA_T   inst) {
30 struct codecfilter_vorbis_inst * self = (struct codecfilter_vorbis_inst *) inst;
31
32 if ( !inst )
33  return -1;
34
35 ov_clear(&(self->vf));
36
37 free(inst);
38 return -1;
39}
40
41int cf_vorbis_read(CODECFILTER_USERDATA_T   inst, char * buf, int len) {
42 struct codecfilter_vorbis_inst * self = (struct codecfilter_vorbis_inst *) inst;
43 long r;
44
45 if ( !self->opened == 2 ) {
46  if ( ov_open(self->in, &(self->vf), NULL, 0) < 0 ) {
47   free((void*)self);
48   return -1;
49  }
50 }
51 self->opened++;
52
53 r = ov_read(&(self->vf), buf, len, 0, 2, 1, &(self->current_section));
54
55 if ( r == 0 ) {
56  // do some EOF handling...
57  return -1;
58 } else if ( r < 0 ) {
59  return -1; // error in stream
60 } else {
61  return r;
62 }
63}
64
65//ll
Note: See TracBrowser for help on using the repository browser.