sfxVorbisStream.h
Engine/source/sfx/media/sfxVorbisStream.h
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _SFXVORBISSTREAM_H_ 25#define _SFXVORBISSTREAM_H_ 26 27#ifdef TORQUE_OGGVORBIS 28 29#ifndef _SFXFILESTREAM_H_ 30# include "sfx/sfxFileStream.h" 31#endif 32#include "core/util/safeDelete.h" 33#include "vorbis/vorbisfile.h" 34 35 36/// An SFXFileStream that loads sample data from a Vorbis file. 37class SFXVorbisStream : public SFXFileStream, 38 public IPositionable< U32 > 39{ 40 public: 41 42 typedef SFXFileStream Parent; 43 44 protected: 45 46 /// The vorbis file. 47 OggVorbis_File *mVF; 48 49 /// The current bitstream index. 50 S32 mBitstream; 51 52 /// Total number of bytes read from the Vorbis stream so far. 53 U32 mBytesRead; 54 55 /// 56 bool _openVorbis(); 57 58 // The ov_callbacks. 59 static size_t _read_func( void *ptr, size_t size, size_t nmemb, void *datasource ); 60 static S32 _seek_func( void *datasource, ogg_int64_t offset, S32 whence ); 61 static long _tell_func( void *datasource ); 62 63 // SFXStream 64 virtual bool _readHeader(); 65 virtual void _close(); 66 67 public: 68 69 /// 70 static SFXVorbisStream* create( Stream *stream ); 71 72 /// 73 SFXVorbisStream(); 74 75 /// 76 SFXVorbisStream( const SFXVorbisStream& cloneFrom ); 77 78 virtual ~SFXVorbisStream(); 79 80 /// 81 const vorbis_info* getInfo( S32 link = -1 ); 82 83 /// 84 const vorbis_comment* getComment( S32 link = -1 ); 85 86 /// 87 // TODO: Deal with error cases... like for unseekable streams! 88 U64 getPcmTotal( S32 link = -1 ); 89 90 /// 91 S32 read( U8 *buffer, 92 U32 length, 93 S32 *bitstream ); 94 95 // SFXStream 96 virtual void reset(); 97 virtual U32 read( U8 *buffer, U32 length ); 98 virtual bool isEOS() const; 99 virtual SFXStream* clone() const 100 { 101 SFXVorbisStream* stream = new SFXVorbisStream( *this ); 102 if( !stream->mVF ) 103 SAFE_DELETE( stream ); 104 return stream; 105 } 106 107 // IPositionable 108 virtual U32 getPosition() const; 109 virtual void setPosition( U32 offset ); 110}; 111 112#endif // TORQUE_OGGVORBIS 113#endif // _SFXVORBISSTREAM_H_ 114