oggInputStream.h
Engine/source/core/ogg/oggInputStream.h
Classes:
class
Single substream in a multiplexed OGG stream.
class
A multiplexed OGG input stream feeding into stream decoders.
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 _OGGINPUTSTREAM_H_ 25#define _OGGINPUTSTREAM_H_ 26 27#ifndef _TVECTOR_H_ 28 #include "core/util/tVector.h" 29#endif 30#ifndef _TYPETRAITS_H_ 31 #include "platform/typetraits.h" 32#endif 33#ifndef _PLATFORM_THREADS_MUTEX_H_ 34 #include "platform/threads/mutex.h" 35#endif 36#ifndef _THREADSAFEREFCOUNT_H_ 37 #include "platform/threads/threadSafeRefCount.h" 38#endif 39#include "ogg/ogg.h" 40 41 42class Stream; 43class OggInputStream; 44 45 46/// Single substream in a multiplexed OGG stream. 47class OggDecoder 48{ 49 public: 50 51 typedef void Parent; 52 friend class OggInputStream; 53 54 protected: 55 56 /// The Ogg container stream. 57 OggInputStream* mOggStream; 58 59 /// The Ogg bitstream. 60 ogg_stream_state mOggStreamState; 61 62 /// Lock for synchronizing access to Ogg stream state. 63 Mutex mMutex; 64 65 /// Read the next packet in the stream. 66 /// @return false if there is no next packet. 67 bool _readNextPacket( ogg_packet* packet ); 68 69 /// 70 bool _nextPacket(); 71 72 /// 73 virtual bool _detect( ogg_page* startPage ) = 0; 74 75 /// 76 virtual bool _init() = 0; 77 78 /// 79 virtual bool _packetin( ogg_packet* packet ) = 0; 80 81 /// 82 void _setStartPage( ogg_page* startPage ); 83 84 public: 85 86 /// 87 OggDecoder( const ThreadSafeRef< OggInputStream>& stream ); 88 89 virtual ~OggDecoder(); 90 91 /// Return the serial number of the Ogg bitstream. 92 U32 getStreamSerialNo() const { return mOggStreamState.serialno; } 93 94 /// 95 virtual const char* getName() const = 0; 96}; 97 98/// A multiplexed OGG input stream feeding into stream decoders. 99class OggInputStream : public ThreadSafeRefCount< OggInputStream > 100{ 101 public: 102 103 typedef void Parent; 104 friend class OggDecoder; // _requestData 105 106 protected: 107 108 typedef OggDecoder* ( *Constructor )( const ThreadSafeRef< OggInputStream>& stream ); 109 110 template< typename T > 111 struct _SpellItOutForGCC 112 { 113 static OggDecoder* _fn( const ThreadSafeRef< OggInputStream>& stream ) 114 { 115 return constructSingle< T* >( stream ); 116 } 117 }; 118 119 /// 120 bool mIsAtEnd; 121 122 /// 123 Stream* mStream; 124 125 /// 126 Vector< Constructor> mConstructors; 127 128 /// 129 Vector< OggDecoder*> mDecoders; 130 131 /// 132 ogg_sync_state mOggSyncState; 133 134 /// 135 Mutex mMutex; 136 137 /// Pull the next page from the OGG stream. 138 bool _pullNextPage( ogg_page* page ); 139 140 /// Push the given page to the attached decoder streams. 141 void _pushNextPage( ogg_page* page ); 142 143 /// 144 bool _requestData(); 145 146 /// 147 void _freeDecoders(); 148 149 public: 150 151 /// 152 /// @note Ownership of "stream" is transferred to OggInputStream. 153 OggInputStream( Stream* stream ); 154 155 ~OggInputStream(); 156 157 /// Register a decoder class with the stream. 158 template< class T > 159 void addDecoder() 160 { 161 mConstructors.push_back( &_SpellItOutForGCC< T >::_fn ); 162 } 163 164 /// 165 OggDecoder* getDecoder( const String& name ) const; 166 167 /// 168 bool init(); 169 170 /// 171 bool isAtEnd(); 172}; 173 174#endif // !_OGGINPUTSTREAM_H_ 175