Go to the documentation of this file.00001
00002
00003
00004
00005 #pragma once
00006
00007 #include "../base/Setup.h"
00008
00009 #ifdef MPMA_COMPILE_AUDIO
00010
00011 #include <list>
00012 #include <vector>
00013 #include "Source.h"
00014 #include "../base/ReferenceCount.h"
00015 #include "../base/Locks.h"
00016 #include "AL_Include.h"
00017
00018 namespace AUDIO_INTERNAL { class BackgroundProcessing; }
00019
00021 namespace AUDIO
00022 {
00024 enum BufferBehavior
00025 {
00027 STATIC_DATA=0x100,
00029 STREAM_DATA
00030 };
00031
00032
00033 struct InternalSharedBufferData
00034 {
00035 inline InternalSharedBufferData(): isReal(true), isStatic(true), streamingSource(0), staticBuffer(0)
00036 {}
00037
00038 bool isReal;
00039 bool isStatic;
00040 MPMA::RWSleepLock bufferLock;
00041
00042
00043 std::list<Source*> readySources;
00044 Source *streamingSource;
00045 float streamSeconds;
00046
00047 struct PlayerBuffers
00048 {
00049 ALuint playerResource;
00050 ALuint *buffers;
00051 nuint buffersFinished;
00052 Source *source;
00053 class Player *player;
00054 bool beingFreed;
00055 bool freeRequestAboutToOccur;
00056
00057
00058 uint8 *streamingBufferData;
00059 nuint streamingBufferSize;
00060 };
00061 std::list<PlayerBuffers> players;
00062
00063
00064 ALuint staticBuffer;
00065 };
00066
00068 class Buffer: public MPMA::ReferenceCountedData<InternalSharedBufferData>
00069 {
00070 public:
00072 Buffer(Source &source, BufferBehavior bufferBehavior, float streamSizeInSeconds=0.2f);
00073
00074 virtual ~Buffer();
00075
00077 inline Buffer()
00078 { Data().isReal=false; }
00079
00081 inline bool IsReal() const
00082 { return Data().isReal; }
00083
00084 protected:
00085
00086 inline bool IsStatic() const
00087 { return Data().isStatic; }
00088
00089
00090 bool SetupInitialPlayBuffers(ALuint playerResource, class Player *player);
00091
00092
00093 void FreePlayer(ALuint playerResource, class Player *player);
00094
00095 private:
00096
00097 bool ConstructInHardwareBuffer(Source *source);
00098
00099
00100 bool ConstructInSystemBuffer(Source *source);
00101
00102
00103 bool ConstructInStreamingBuffer(Source *source, float streamSizeInSeconds);
00104
00105
00106 void ConstructAsError(const char *msg);
00107
00108
00109 void ReadAllStaticSourceData(Source *source, std::vector<uint8> &data);
00110
00111
00112 void UpdateStreamingPlayerBuffer(InternalSharedBufferData::PlayerBuffers &pb, bool isInitialRead=false);
00113
00114
00115 void FreePlayerBuffer(InternalSharedBufferData::PlayerBuffers *pb);
00116
00117 friend class Player;
00118 friend class AUDIO_INTERNAL::BackgroundProcessing;
00119 };
00120
00121 }
00122
00123 #endif //#ifdef MPMA_COMPILE_AUDIO