yolobs-studio/UI/frontend-plugins/frontend-tools/captions-mssapi-stream.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
2.9 KiB
C++
Raw Permalink Normal View History

2017-06-29 19:01:10 +00:00
#pragma once
2017-04-19 19:54:15 +00:00
#include <windows.h>
#include <sapi.h>
#include <condition_variable>
#include <mutex>
#include <vector>
#include <obs.h>
#include <util/circlebuf.h>
#include <util/windows/WinHandle.hpp>
#include <fstream>
class CircleBuf {
circlebuf buf = {};
2019-09-22 21:19:10 +00:00
2017-04-19 19:54:15 +00:00
public:
2019-09-22 21:19:10 +00:00
inline ~CircleBuf() { circlebuf_free(&buf); }
inline operator circlebuf *() { return &buf; }
inline circlebuf *operator->() { return &buf; }
2017-04-19 19:54:15 +00:00
};
2017-06-29 19:01:10 +00:00
class mssapi_captions;
2017-04-19 19:54:15 +00:00
class CaptionStream : public ISpAudio {
volatile long refs = 1;
SPAUDIOBUFFERINFO buf_info = {};
2017-06-29 19:01:10 +00:00
mssapi_captions *handler;
2017-04-19 19:54:15 +00:00
ULONG notify_size = 0;
SPAUDIOSTATE state;
WinHandle event;
ULONG vol = 0;
std::condition_variable cv;
std::mutex m;
std::vector<int16_t> temp_buf;
WAVEFORMATEX format = {};
CircleBuf buf;
ULONG wait_size = 0;
DWORD samplerate = 0;
ULARGE_INTEGER pos = {};
ULONGLONG write_pos = 0;
public:
2017-06-29 19:01:10 +00:00
CaptionStream(DWORD samplerate, mssapi_captions *handler_);
2017-04-19 19:54:15 +00:00
void Stop();
2017-06-29 19:01:10 +00:00
void PushAudio(const void *data, size_t frames);
2017-04-19 19:54:15 +00:00
// IUnknown methods
STDMETHODIMP QueryInterface(REFIID riid, void **ppv) override;
STDMETHODIMP_(ULONG) AddRef() override;
STDMETHODIMP_(ULONG) Release() override;
// ISequentialStream methods
STDMETHODIMP Read(void *data, ULONG bytes, ULONG *read_bytes) override;
2019-09-22 21:19:10 +00:00
STDMETHODIMP Write(const void *data, ULONG bytes,
ULONG *written_bytes) override;
2017-04-19 19:54:15 +00:00
// IStream methods
STDMETHODIMP Seek(LARGE_INTEGER move, DWORD origin,
2019-09-22 21:19:10 +00:00
ULARGE_INTEGER *new_pos) override;
2017-04-19 19:54:15 +00:00
STDMETHODIMP SetSize(ULARGE_INTEGER new_size) override;
STDMETHODIMP CopyTo(IStream *stream, ULARGE_INTEGER bytes,
2019-09-22 21:19:10 +00:00
ULARGE_INTEGER *read_bytes,
ULARGE_INTEGER *written_bytes) override;
2017-04-19 19:54:15 +00:00
STDMETHODIMP Commit(DWORD commit_flags) override;
STDMETHODIMP Revert(void) override;
STDMETHODIMP LockRegion(ULARGE_INTEGER offset, ULARGE_INTEGER size,
2019-09-22 21:19:10 +00:00
DWORD type) override;
2017-04-19 19:54:15 +00:00
STDMETHODIMP UnlockRegion(ULARGE_INTEGER offset, ULARGE_INTEGER size,
2019-09-22 21:19:10 +00:00
DWORD type) override;
2017-04-19 19:54:15 +00:00
STDMETHODIMP Stat(STATSTG *stg, DWORD flags) override;
STDMETHODIMP Clone(IStream **stream) override;
// ISpStreamFormat methods
2019-09-22 21:19:10 +00:00
STDMETHODIMP GetFormat(GUID *guid,
WAVEFORMATEX **co_mem_wfex_out) override;
2017-04-19 19:54:15 +00:00
// ISpAudio methods
STDMETHODIMP SetState(SPAUDIOSTATE state, ULONGLONG reserved) override;
2019-09-22 21:19:10 +00:00
STDMETHODIMP SetFormat(REFGUID guid_ref,
const WAVEFORMATEX *wfex) override;
2017-04-19 19:54:15 +00:00
STDMETHODIMP GetStatus(SPAUDIOSTATUS *status) override;
STDMETHODIMP SetBufferInfo(const SPAUDIOBUFFERINFO *buf_info) override;
STDMETHODIMP GetBufferInfo(SPAUDIOBUFFERINFO *buf_info) override;
STDMETHODIMP GetDefaultFormat(GUID *format,
2019-09-22 21:19:10 +00:00
WAVEFORMATEX **co_mem_wfex_out) override;
2017-04-19 19:54:15 +00:00
STDMETHODIMP_(HANDLE) EventHandle(void) override;
STDMETHODIMP GetVolumeLevel(ULONG *level) override;
STDMETHODIMP SetVolumeLevel(ULONG level) override;
STDMETHODIMP GetBufferNotifySize(ULONG *size) override;
STDMETHODIMP SetBufferNotifySize(ULONG size) override;
};