00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <dec_ogg.h>
00024 #include <jutils.h>
00025 #include <config.h>
00026
00027 #include "httpstream.h"
00028
00029
00030 #ifdef HAVE_VORBIS
00031
00032
00033
00034 MuseDecOgg::MuseDecOgg() : MuseDec() {
00035 func("MuseDecOgg::MuseDecOgg()");
00036
00037 old_section = current_section = -1;
00038
00039 oggfile = NULL;
00040
00041 strncpy(name,"Ogg",4);
00042 }
00043
00044 MuseDecOgg::~MuseDecOgg() {
00045 func("MuseDecOgg::~MuseDecOgg()");
00046 ov_clear(&vf);
00047 }
00048
00049 IN_DATATYPE *MuseDecOgg::get_audio() {
00050 int res;
00051
00052 old_section = current_section;
00053
00054 if(seekable) {
00055
00056 framepos = ov_pcm_tell(&vf);
00057 fps = samplerate;
00058 }
00059
00060 do {
00061 res =
00062
00063 ov_read(&vf, _inbuf, IN_CHUNK, 0, 2, 1, ¤t_section);
00064 } while (res == OV_HOLE);
00065
00066 if(res<0) {
00067 warning("MuseDecOgg:_get_audio() : bitstream error %d", res);
00068 err = true;
00069 return(NULL);
00070 }
00071
00072 if((res==0)||(old_section != current_section && old_section != -1)) {
00073
00074 eos = true;
00075 return(NULL);
00076 }
00077
00078 frames = res>>1;
00079
00080 return((IN_DATATYPE *)_inbuf);
00081 }
00082
00083 int MuseDecOgg::load(char *file) {
00084 int res = 0;
00085
00086 oggfile = hopen(file,"rb");
00087 if(oggfile==NULL) {
00088 error("MuseDecOgg::open(%s) : can't open file",file);
00089 return(res);
00090 }
00091
00092 if(ov_open(oggfile,&vf,NULL,0) < 0) {
00093 error("MuseDecOgg::open(%s): not a valid OggVorbis audio stream",file);
00094 fclose(oggfile);
00095 return(res);
00096 }
00097
00098 vc = ov_comment(&vf, -1);
00099 vi = ov_info(&vf, -1);
00100
00101 samplerate = vi->rate;
00102 channels = vi->channels;
00103 seekable = ov_seekable(&vf);
00104
00105
00106 framepos = 0;
00107
00108
00109 res = (ov_seekable(&vf)) ? 1 : 2;
00110 seekable = (res>1) ? false : true;
00111
00112 if(seekable)
00113 frametot = ov_pcm_total(&vf,-1);
00114
00115 return(res);
00116 }
00117
00118 bool MuseDecOgg::seek(float pos) {
00119
00120 if(pos==0.0) {
00121 if(ov_pcm_seek(&vf,1)!=0) {
00122 error("MuseDecOgg::pos : error in ov_pcm_seek(%p,1)",&vf);
00123 return(false);
00124 }
00125
00126 } else {
00127
00128 if(ov_pcm_seek_page(&vf,(ogg_int64_t)((double)frametot * pos))!=0) {
00129 error("MuseDecOgg::play : error in ov_pcm_seek_page(%p,%u)",
00130 (ogg_int64_t)((double)frametot * pos));
00131 return(false);
00132 }
00133 }
00134
00135 return(true);
00136 }
00137
00138 #endif