OfflineAudioContext.h [plain text]
#pragma once
#include "BaseAudioContext.h"
#include "JSDOMPromiseDeferred.h"
#include "OfflineAudioContextOptions.h"
#include "OfflineAudioDestinationNode.h"
#include <wtf/HashMap.h>
#include <wtf/Lock.h>
namespace WebCore {
class OfflineAudioContext final : public BaseAudioContext {
WTF_MAKE_ISO_ALLOCATED(OfflineAudioContext);
public:
static ExceptionOr<Ref<OfflineAudioContext>> create(ScriptExecutionContext&, unsigned numberOfChannels, size_t length, float sampleRate);
static ExceptionOr<Ref<OfflineAudioContext>> create(ScriptExecutionContext&, const OfflineAudioContextOptions&);
void startOfflineRendering(Ref<DeferredPromise>&&);
void suspendOfflineRendering(double suspendTime, Ref<DeferredPromise>&&);
void resumeOfflineRendering(Ref<DeferredPromise>&&);
unsigned length() const;
bool shouldSuspend() final;
OfflineAudioDestinationNode* destination() { return static_cast<OfflineAudioDestinationNode*>(BaseAudioContext::destination()); }
void offlineLock(bool& mustReleaseLock);
class OfflineAutoLocker {
public:
explicit OfflineAutoLocker(OfflineAudioContext& context)
: m_context(context)
{
m_context.offlineLock(m_mustReleaseLock);
}
~OfflineAutoLocker()
{
if (m_mustReleaseLock)
m_context.unlock();
}
private:
OfflineAudioContext& m_context;
bool m_mustReleaseLock;
};
private:
OfflineAudioContext(Document&, AudioBuffer* renderTarget);
void didFinishOfflineRendering(ExceptionOr<Ref<AudioBuffer>>&&) final;
void didSuspendRendering(size_t frame) final;
void uninitialize() final;
RefPtr<DeferredPromise> m_pendingOfflineRenderingPromise;
HashMap<unsigned , RefPtr<DeferredPromise>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> m_suspendRequests;
bool m_didStartOfflineRendering { false };
};
}