decoder-ogg.h
author nathan
Fri, 13 Nov 2009 19:27:36 +0800
branchtrunk
changeset 33 65ed49cbc08b
parent 0 474a1293c3c0
child 35 efc694fccc45
permissions -rw-r--r--
add OGG streaming support
     1 /*
     2  * MP3/MPlayer plugin to VDR (C++)
     3  *
     4  * (C) 2001-2009 Stefan Huelswitt <s.huelswitt@gmx.de>
     5  *
     6  * This code is free software; you can redistribute it and/or
     7  * modify it under the terms of the GNU General Public License
     8  * as published by the Free Software Foundation; either version 2
     9  * of the License, or (at your option) any later version.
    10  *
    11  * This code is distributed in the hope that it will be useful,
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  * GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License
    17  * along with this program; if not, write to the Free Software
    18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    19  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
    20  */
    21 
    22 #ifndef ___DECODER_OGG_H
    23 #define ___DECODER_OGG_H
    24 
    25 #define DEC_OGG     DEC_ID('O','G','G',' ')
    26 #define DEC_OGG_STR "OGG"
    27 
    28 #ifdef HAVE_VORBISFILE
    29 
    30 #include <mad.h>
    31 #include <vorbis/vorbisfile.h>
    32 
    33 #include "decoder.h"
    34 #include "decoder-core.h"
    35 
    36 // ----------------------------------------------------------------
    37 
    38 class cOggInfo;
    39 
    40 class cOggFile : public cFileInfo {
    41 friend class cOggInfo;
    42 private:
    43   bool canSeek;
    44 protected:
    45   bool opened;
    46   OggVorbis_File vf;
    47   //
    48   void Error(const char *action, const int err);
    49 public:
    50   cOggFile(const char *Filename);
    51   ~cOggFile();
    52   virtual bool Open(bool log=true);
    53   void Close(void);
    54   long long Seek(long long posMs=0, bool relativ=false);
    55   int Stream(short *buffer, int samples);
    56   bool CanSeek(void) { return canSeek; }
    57   long long IndexMs(void);
    58   };
    59 
    60 // ----------------------------------------------------------------
    61 
    62 class cOggInfo : public cSongInfo {
    63 private:
    64   cOggFile *file;
    65   bool keepOpen;
    66   //
    67   bool Abort(bool result);
    68 public:
    69   cOggInfo(cOggFile *File);
    70   virtual bool DoScan(bool KeepOpen=false);
    71   virtual void InfoHook(void) {};
    72   };
    73 
    74 // ----------------------------------------------------------------
    75 
    76 class cOggDecoder : public cDecoder {
    77 private:
    78   struct Decode ds;
    79   struct mad_pcm *pcm;
    80   unsigned long long index;
    81   //
    82   void Init(void);
    83   bool Clean(void);
    84   bool GetInfo(bool keepOpen);
    85   struct Decode *Done(eDecodeStatus status);
    86 protected:
    87   cOggFile *file;
    88   cOggInfo *info;
    89 public:
    90   cOggDecoder(const char *Filename, bool preinit=true);
    91   ~cOggDecoder();
    92   virtual bool Valid(void);
    93   virtual cFileInfo *FileInfo(void);
    94   virtual cSongInfo *SongInfo(bool get);
    95   virtual cPlayInfo *PlayInfo(void);
    96   virtual bool Start(void);
    97   virtual bool Stop(void);
    98   virtual bool Skip(int Seconds, float bsecs);
    99   virtual struct Decode *Decode(void);
   100   };
   101 
   102 // ----------------------------------------------------------------
   103 
   104 #endif //HAVE_VORBISFILE
   105 #endif //___DECODER_OGG_H