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 00136 virtual bool PendingSeek (); 00137 00150 virtual bool Pause(); 00151 00156 virtual bool Unpause(); 00157 00168 virtual int GetPauseState(); 00169 00175 virtual bool SetLoopState(int loopstate); 00176 00181 virtual int GetLoopState(); 00182 00188 virtual size_t GetLoopStart(); 00189 00195 virtual size_t GetLoopEnd(); 00196 00208 virtual bool SetLoopBoundaries(size_t startPosition, size_t endPosition); 00209 00214 virtual void SetPlayRatePercent(int percent); 00215 00220 virtual int GetPlayRatePercent(); 00221 00226 virtual void SetAutoUnregister(bool autounreg); 00227 00232 virtual bool GetAutoUnregister(); 00233 00238 virtual bool GetAutoUnregisterRequested(); 00239 00254 virtual void AdvancePosition(size_t frame_delta) = 0; 00255 00292 virtual void GetDataPointers (size_t *position_marker, size_t max_requested_length, 00293 void **buffer1, size_t *buffer1_bytes, void **buffer2, size_t *buffer2_bytes); 00294 00301 virtual void InitializeSourcePositionMarker (size_t* position_marker); 00302 00310 virtual void ProcessNotifications(); 00311 00312 00314 virtual bool RegisterCallback(iSndSysStreamCallback *pCallback); 00315 00317 virtual bool UnregisterCallback(iSndSysStreamCallback *pCallback); 00318 00321 virtual bool RegisterFrameNotification(size_t frame_number); 00322 00324 virtual bool AlwaysStream() const { return false; } 00325 00327 // Internal functions 00329 protected: 00332 // 00333 size_t CopyBufferBytes (size_t max_dest_bytes); 00334 00336 void QueueNotificationEvent(StreamNotificationType NotifyType, size_t FrameNum); 00337 00338 00340 // Member variables 00342 protected: 00344 csSndSysSoundFormat m_RenderFormat; 00345 00347 // 00348 // The cyclic buffer is used to hold recently decoded sound. It 00349 // provides functionality which allows us to add new data at any point 00350 // without a lot of excess copying. 00351 SoundCyclicBuffer *m_pCyclicBuffer; 00352 00354 int16 m_PauseState; 00355 00357 // of the data? 00358 bool m_bLooping; 00359 00361 size_t m_startLoopFrame; 00362 00364 size_t m_endLoopFrame; 00365 00366 00368 // 00369 // This is set to true once we have completed reading the underlying data 00370 // only if we are not looping. If we are looping, then we'll just start 00371 // back at the beginning of the data and we will never be finished reading. 00372 bool m_bPlaybackReadComplete; 00373 00375 // furthest ahead in reading. 00376 size_t m_MostAdvancedReadPointer; 00377 00382 size_t m_NewPosition; 00383 00388 PCMSampleConverter *m_pPCMConverter; 00389 00391 // for addition to the cyclic buffer. 00392 char *m_pPreparedDataBuffer; 00393 00395 int m_PreparedDataBufferSize; 00396 00398 size_t m_PreparedDataBufferUsage; 00399 00401 // data buffer 00402 size_t m_PreparedDataBufferStart; 00403 00405 int m_RenderFrameSize; 00406 00408 int m_PlaybackPercent; 00409 00414 int m_OutputFrequency; 00415 00420 int m_NewOutputFrequency; 00421 00426 int m_3DMode; 00427 00432 bool m_bAutoUnregisterRequested; 00433 00435 bool m_bAutoUnregisterReady; 00436 00438 csRefArray<iSndSysStreamCallback> m_CallbackList; 00439 00441 Queue<StreamNotificationEvent> m_NotificationQueue; 00442 }; 00443 00444 00445 } 00446 // END namespace CS::SndSys 00447 } 00448 // END namespace CS 00449 00450 00451 00452 00453 #endif // #ifndef SNDSTREAM_H 00454
Generated for Crystal Space 2.0 by doxygen 1.6.1