mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Make seek and tell thread-safe (bug #245)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace null
|
||||
{
|
||||
}
|
||||
|
||||
float Source::tell(Source::Unit) const
|
||||
float Source::tell(Source::Unit)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user