csplugincommon/sndsys/sndstream.h
00001 /* 00002 Copyright (C) 2006 by Andrew Mann 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library 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. See the GNU 00012 General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 00020 00021 #ifndef SNDSTREAM_H 00022 #define SNDSTREAM_H 00023 00024 #include "iutil/databuff.h" 00025 #include "isndsys/ss_structs.h" 00026 #include "isndsys/ss_stream.h" 00027 #include "csplugincommon/sndsys/convert.h" 00028 #include "csplugincommon/sndsys/cyclicbuf.h" 00029 #include "csplugincommon/sndsys/queue.h" 00030 #include "csutil/refarr.h" 00031 #include "csutil/scf_implementation.h" 00032 00033 00034 namespace CS 00035 { 00036 namespace SndSys 00037 { 00038 00039 class CS_CRYSTALSPACE_EXPORT SndSysBasicStream : 00040 public scfImplementation1<SndSysBasicStream, iSndSysStream> 00041 { 00042 public: 00043 SndSysBasicStream(csSndSysSoundFormat *pRenderFormat, int Mode3D); 00044 virtual ~SndSysBasicStream(); 00045 00047 static const size_t InvalidPosition = (size_t)~0; 00048 00050 // Structure/enum definitions 00052 00054 typedef enum 00055 { 00056 STREAM_NOTIFY_PAUSED=0, 00057 STREAM_NOTIFY_UNPAUSED, 00058 STREAM_NOTIFY_LOOP, 00059 STREAM_NOTIFY_FRAME 00060 } StreamNotificationType; 00061 00063 struct StreamNotificationEvent 00064 { 00066 StreamNotificationType m_Type; 00068 // This is currently only valid for 00069 // STREAM_NOTIFY_FRAME event types 00070 size_t m_Frame; 00071 }; 00072 00073 00075 // Interface implementation 00077 00078 //------------------------ 00079 // iSndSysStream 00080 //------------------------ 00081 public: 00082 00084 virtual const char *GetDescription() = 0; 00085 00090 virtual const csSndSysSoundFormat *GetRenderedFormat(); 00091 00093 virtual int Get3dMode(); 00094 00101 virtual size_t GetFrameCount() = 0; 00102 00103 00114 virtual size_t GetPosition(); 00115 00121 virtual bool ResetPosition(); 00122 00128 virtual bool SetPosition (size_t newposition); 00129 00142 virtual bool Pause(); 00143 00148 virtual bool Unpause(); 00149 00156 virtual int GetPauseState(); 00157 00163 virtual bool SetLoopState(int loopstate); 00164 00169 virtual int GetLoopState(); 00170 00175 virtual void SetPlayRatePercent(int percent); 00176 00181 virtual int GetPlayRatePercent(); 00182 00187 virtual void SetAutoUnregister(bool autounreg); 00188 00193 virtual bool GetAutoUnregister(); 00194 00199 virtual bool GetAutoUnregisterRequested(); 00200 00215 virtual void AdvancePosition(size_t frame_delta) = 0; 00216 00253 virtual void GetDataPointers (size_t *position_marker, size_t max_requested_length, 00254 void **buffer1, size_t *buffer1_bytes, void **buffer2, size_t *buffer2_bytes); 00255 00262 virtual void InitializeSourcePositionMarker (size_t* position_marker); 00263 00271 virtual void ProcessNotifications(); 00272 00273 00275 virtual bool RegisterCallback(iSndSysStreamCallback *pCallback); 00276 00278 virtual bool UnregisterCallback(iSndSysStreamCallback *pCallback); 00279 00282 virtual bool RegisterFrameNotification(size_t frame_number); 00283 00285 virtual bool AlwaysStream() const { return false; } 00286 00288 // Internal functions 00290 protected: 00293 // 00294 size_t CopyBufferBytes (size_t max_dest_bytes); 00295 00297 void QueueNotificationEvent(StreamNotificationType NotifyType, size_t FrameNum); 00298 00299 00301 // Member variables 00303 protected: 00305 csSndSysSoundFormat m_RenderFormat; 00306 00308 // 00309 // The cyclic buffer is used to hold recently decoded sound. It 00310 // provides functionality which allows us to add new data at any point 00311 // without a lot of excess copying. 00312 SoundCyclicBuffer *m_pCyclicBuffer; 00313 00315 bool m_bPaused; 00316 00318 // of the data? 00319 bool m_bLooping; 00320 00322 // 00323 // This is set to true once we have completed reading the underlying data 00324 // only if we are not looping. If we are looping, then we'll just start 00325 // back at the beginning of the data and we will never be finished reading. 00326 bool m_bPlaybackReadComplete; 00327 00329 // furthest ahead in reading. 00330 size_t m_MostAdvancedReadPointer; 00331 00336 size_t m_NewPosition; 00337 00342 PCMSampleConverter *m_pPCMConverter; 00343 00345 // for addition to the cyclic buffer. 00346 char *m_pPreparedDataBuffer; 00347 00349 int m_PreparedDataBufferSize; 00350 00352 size_t m_PreparedDataBufferUsage; 00353 00355 // data buffer 00356 size_t m_PreparedDataBufferStart; 00357 00359 int m_RenderFrameSize; 00360 00362 int m_PlaybackPercent; 00363 00368 int m_OutputFrequency; 00369 00374 int m_NewOutputFrequency; 00375 00380 int m_3DMode; 00381 00386 bool m_bAutoUnregisterRequested; 00387 00389 bool m_bAutoUnregisterReady; 00390 00392 csRefArray<iSndSysStreamCallback> m_CallbackList; 00393 00395 Queue<StreamNotificationEvent> m_NotificationQueue; 00396 }; 00397 00398 00399 } 00400 // END namespace CS::SndSys 00401 } 00402 // END namespace CS 00403 00404 00405 00406 00407 #endif // #ifndef SNDSTREAM_H 00408
Generated for Crystal Space 1.4.0 by doxygen 1.5.8