forked from mia/Aegisub
Guard uses of audio providers with a mutex when not using a cache as they aren't thread-safe. Updates #1509.
Originally committed to SVN as r6959.
This commit is contained in:
parent
5a38d69921
commit
037d385419
5 changed files with 84 additions and 1 deletions
|
@ -493,6 +493,14 @@
|
|||
RelativePath="..\..\src\audio_provider_hd.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\audio_provider_lock.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\audio_provider_lock.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\audio_provider_pcm.cpp"
|
||||
>
|
||||
|
|
|
@ -145,6 +145,7 @@ SRC += \
|
|||
audio_provider.cpp \
|
||||
audio_provider_convert.cpp \
|
||||
audio_provider_hd.cpp \
|
||||
audio_provider_lock.cpp \
|
||||
audio_provider_pcm.cpp \
|
||||
audio_provider_ram.cpp \
|
||||
audio_renderer.cpp \
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "audio_provider_ffmpegsource.h"
|
||||
#endif
|
||||
#include "audio_provider_hd.h"
|
||||
#include "audio_provider_lock.h"
|
||||
#include "audio_provider_pcm.h"
|
||||
#include "audio_provider_ram.h"
|
||||
#include "compat.h"
|
||||
|
@ -152,7 +153,7 @@ AudioProvider *AudioProviderFactory::GetProvider(wxString const& filename, int c
|
|||
// Change provider to RAM/HD cache if needed
|
||||
if (cache == -1) cache = OPT_GET("Audio/Cache/Type")->GetInt();
|
||||
if (!cache || !needsCache) {
|
||||
return provider;
|
||||
return new LockAudioProvider(provider);
|
||||
}
|
||||
|
||||
DialogProgress progress(wxGetApp().frame, _("Load audio"));
|
||||
|
|
36
aegisub/src/audio_provider_lock.cpp
Normal file
36
aegisub/src/audio_provider_lock.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/// @file audio_provider_lock.cpp
|
||||
/// @brief An audio provider adapter for un-threadsafe audio providers
|
||||
/// @ingroup audio_input
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "audio_provider_lock.h"
|
||||
|
||||
LockAudioProvider::LockAudioProvider(AudioProvider *source) : source(source) {
|
||||
channels = source->GetChannels();
|
||||
num_samples = source->GetNumSamples();
|
||||
sample_rate = source->GetSampleRate();
|
||||
bytes_per_sample = source->GetBytesPerSample();
|
||||
float_samples = source->AreSamplesFloat();
|
||||
}
|
||||
|
||||
void LockAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) const {
|
||||
wxMutexLocker lock(mutex);
|
||||
source->GetAudio(buf, start, count);
|
||||
}
|
37
aegisub/src/audio_provider_lock.h
Normal file
37
aegisub/src/audio_provider_lock.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/// @file audio_provider_lock.h
|
||||
/// @brief An audio provider adapter for un-threadsafe audio providers
|
||||
/// @ingroup audio_input
|
||||
|
||||
#include "include/aegisub/audio_provider.h"
|
||||
|
||||
#include <libaegisub/scoped_ptr.h>
|
||||
|
||||
#ifndef AGI_PRE
|
||||
#include <wx/mutex.h>
|
||||
#endif
|
||||
|
||||
class LockAudioProvider : public AudioProvider {
|
||||
agi::scoped_ptr<const AudioProvider> source;
|
||||
mutable wxMutex mutex;
|
||||
|
||||
public:
|
||||
LockAudioProvider(AudioProvider *source);
|
||||
void GetAudio(void *buf, int64_t start, int64_t count) const;
|
||||
bool AreSamplesNativeEndian() const { return source->AreSamplesNativeEndian(); }
|
||||
};
|
Loading…
Reference in a new issue