2014-07-09 16:22:49 +02:00
|
|
|
// Copyright (c) 2014, Thomas Goyne <plorkyeran@aegisub.org>
|
2012-08-18 05:13:39 +02:00
|
|
|
//
|
|
|
|
// 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.
|
2014-07-09 16:22:49 +02:00
|
|
|
//
|
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2012-08-18 05:13:39 +02:00
|
|
|
|
2014-07-09 16:22:49 +02:00
|
|
|
#include "libaegisub/audio/provider.h"
|
2012-08-18 05:13:39 +02:00
|
|
|
|
2014-04-23 22:53:24 +02:00
|
|
|
#include <libaegisub/make_unique.h>
|
2014-03-24 03:30:03 +01:00
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
namespace {
|
2014-07-09 16:22:49 +02:00
|
|
|
class LockAudioProvider final : public agi::AudioProviderWrapper {
|
2014-03-24 03:30:03 +01:00
|
|
|
mutable std::mutex mutex;
|
2012-08-18 05:13:39 +02:00
|
|
|
|
2014-03-24 03:30:03 +01:00
|
|
|
void FillBuffer(void *buf, int64_t start, int64_t count) const override {
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
source->GetAudio(buf, start, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
LockAudioProvider(std::unique_ptr<AudioProvider> src)
|
|
|
|
: AudioProviderWrapper(std::move(src))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2012-08-18 05:13:39 +02:00
|
|
|
}
|
2014-03-24 03:30:03 +01:00
|
|
|
|
2014-07-09 16:22:49 +02:00
|
|
|
namespace agi {
|
2014-03-24 03:30:03 +01:00
|
|
|
std::unique_ptr<AudioProvider> CreateLockAudioProvider(std::unique_ptr<AudioProvider> src) {
|
2014-04-23 22:53:24 +02:00
|
|
|
return agi::make_unique<LockAudioProvider>(std::move(src));
|
2014-03-25 17:51:38 +01:00
|
|
|
}
|
2014-07-09 16:22:49 +02:00
|
|
|
}
|