CrystalSpace

Public API Reference

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 
00269     virtual void ProcessNotifications();
00270 
00271 
00273     virtual bool RegisterCallback(iSndSysStreamCallback *pCallback);
00274 
00276     virtual bool UnregisterCallback(iSndSysStreamCallback *pCallback);
00277 
00279     //   it's crossed.
00280     virtual bool RegisterFrameNotification(size_t frame_number);
00281 
00283     // Internal functions
00285   protected:
00287     //
00288     size_t CopyBufferBytes (size_t max_dest_bytes);
00289 
00291     void QueueNotificationEvent(StreamNotificationType NotifyType, size_t FrameNum);
00292 
00293 
00295     //  Member variables
00297   protected:
00299     csSndSysSoundFormat m_RenderFormat;
00300 
00302     //
00303     //  The cyclic buffer is used to hold recently decoded sound.  It 
00304     //   provides functionality which allows us to add new data at any point
00305     //   without a lot of excess copying.
00306     SoundCyclicBuffer *m_pCyclicBuffer;
00307 
00309     bool m_bPaused;
00310 
00312     //   of the data?
00313     bool m_bLooping;
00314 
00316     //
00317     //  This is set to true once we have completed reading the underlying data
00318     //   only if we are not looping. If we are looping, then we'll just start
00319     //   back at the beginning of the data and we will never be finished reading.
00320     bool m_bPlaybackReadComplete;
00321 
00323     //   furthest ahead in reading.
00324     size_t m_MostAdvancedReadPointer;
00325 
00330     size_t m_NewPosition;
00331 
00336     PCMSampleConverter *m_pPCMConverter;
00337 
00339     //   for addition to the cyclic buffer.
00340     char *m_pPreparedDataBuffer;
00341 
00343     int m_PreparedDataBufferSize;
00344 
00346     size_t m_PreparedDataBufferUsage;
00347 
00349     //   data buffer
00350     size_t m_PreparedDataBufferStart;
00351 
00353     int m_RenderFrameSize;
00354 
00356     int m_PlaybackPercent;
00357 
00362     int m_OutputFrequency;
00363 
00368     int m_NewOutputFrequency;
00369 
00374     int m_3DMode;
00375 
00380     bool m_bAutoUnregisterRequested;
00381 
00383     bool m_bAutoUnregisterReady;
00384 
00386     csRefArray<iSndSysStreamCallback> m_CallbackList;
00387 
00389     Queue<StreamNotificationEvent> m_NotificationQueue;
00390   };
00391 
00392 
00393  }
00394  // END namespace CS::SndSys
00395 }
00396 // END namespace CS
00397 
00398 
00399 
00400 
00401 #endif // #ifndef SNDSTREAM_H
00402 

Generated for Crystal Space by doxygen 1.4.7