Make seek and tell thread-safe (bug #245)

This commit is contained in:
Bart van Strien
2011-07-02 16:43:56 +02:00
parent f993fe99d3
commit 404a3d529c
7 changed files with 34 additions and 8 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ namespace audio
virtual float getVolume() const = 0;
virtual void seek(float offset, Unit unit) = 0;
virtual float tell(Unit unit) const = 0;
virtual float tell(Unit unit) = 0;
// all float * v must be of size 3
virtual void setPosition(float * v) = 0;
+1 -1
View File
@@ -105,7 +105,7 @@ namespace null
{
}
float Source::tell(Source::Unit) const
float Source::tell(Source::Unit)
{
return 0.0f;
}
+1 -1
View File
@@ -58,7 +58,7 @@ namespace null
virtual void setVolume(float volume);
virtual float getVolume() const;
virtual void seek(float offset, Unit unit);
virtual float tell(Unit unit) const;
virtual float tell(Unit unit);
virtual void setPosition(float * v);
virtual void getPosition(float * v) const;
virtual void setVelocity(float * v);
+12
View File
@@ -237,6 +237,18 @@ namespace openal
}
}
void Pool::seek(Source * source, float offset, void * unit)
{
thread::Lock lock(mutex);
return source->seekAtomic(offset, unit);
}
float Pool::tell(Source * source, void * unit)
{
thread::Lock lock(mutex);
return source->tellAtomic(unit);
}
ALuint Pool::findi(const Source * source) const
{
std::map<Source *, ALuint>::const_iterator i = playing.find((Source *)source);
+2
View File
@@ -103,6 +103,8 @@ namespace openal
void resume(Source * source);
void rewind();
void rewind(Source * source);
void seek(Source * source, float offset, void * unit);
float tell(Source * source, void * unit);
private:
+14 -4
View File
@@ -221,11 +221,11 @@ namespace openal
return volume;
}
void Source::seek(float offset, Source::Unit unit)
void Source::seekAtomic(float offset, void * unit)
{
if (valid)
{
switch (unit) {
switch (*((Source::Unit*) unit)) {
case Source::UNIT_SAMPLES:
if (type == TYPE_STREAM) {
ALint buffer;
@@ -249,13 +249,18 @@ namespace openal
}
}
}
void Source::seek(float offset, Source::Unit unit)
{
return pool->seek(this, offset, &unit);
}
float Source::tell(Source::Unit unit) const
float Source::tellAtomic(void * unit) const
{
if (valid)
{
float offset;
switch (unit) {
switch (*((Source::Unit*) unit)) {
case Source::UNIT_SAMPLES:
alGetSourcef(source, AL_SAMPLE_OFFSET, &offset);
if (type == TYPE_STREAM) offset += offsetSamples;
@@ -276,6 +281,11 @@ namespace openal
return 0.0f;
}
float Source::tell(Source::Unit unit)
{
return pool->tell(this, &unit);
}
void Source::setPosition(float * v)
{
if(valid)
+3 -1
View File
@@ -87,8 +87,10 @@ namespace openal
virtual float getPitch() const;
virtual void setVolume(float volume);
virtual float getVolume() const;
virtual void seekAtomic(float offset, void * unit);
virtual void seek(float offset, Unit unit);
virtual float tell(Unit unit) const;
virtual float tellAtomic(void * unit) const;
virtual float tell(Unit unit);
virtual void setPosition(float * v);
virtual void getPosition(float * v) const;
virtual void setVelocity(float * v);