Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members  

dec_ogg.cpp

00001 /* MuSE - Multiple Streaming Engine
00002  * Copyright (C) 2000-2002 Denis Roio aka jaromil <jaromil@dyne.org>
00003  *
00004  * This source code is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Public License as published 
00006  * by the Free Software Foundation; either version 2 of the License,
00007  * or (at your option) any later version.
00008  *
00009  * This source code is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00012  * Please refer to the GNU Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Public License along with
00015  * this source code; if not, write to:
00016  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  *
00018  * "$Id: dec_ogg.cpp,v 1.4 2004/12/13 00:26:36 jaromil Exp $"
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 /* ----- OggVorbis input channel ----- */
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     /* we check the position here 'cause ov_pcm_tell returns the NEXT frame */
00056     framepos = ov_pcm_tell(&vf);
00057     fps = samplerate;
00058   }
00059 
00060   do {
00061     res = 
00062       //      env  buffer  length    BENDIAN WORD SIGNED  bitstream
00063       ov_read(&vf, _inbuf, IN_CHUNK, 0,      2,   1,      &current_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     // with this we check when entering into a new logical bitstream
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   /* pcm position */
00106   framepos = 0;
00107 
00108   /* check if seekable */
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 /* HAVE VORBIS */

Generated on Thu Dec 16 12:28:20 2004 for MuSE by doxygen1.3