obs-studio/plugins/decklink/decklink.hpp
jp9000 4330021617 decklink: Use unbuffered by default, and decouple
Use unbuffered async mode by default, and when in unbuffered mode,
decouple audio/video so that audio plays as soon as it's received.

This is a workaround for decklink device drivers having unreliable
video/audio timestamps (audio/video sync drifting over time).  From
testing, it seems that the handling of video and audio is completely
separate in the driver; along with the timestamp calculations.  For
example, when the thread of the decklink audio callback is stalled, it
would cause the timestamps of the audio alone to go out of sync, which
indicates timestamps are calculated more or less on the spot independent
of what video is doing (which is how we replicated the issue fixed by
b63e4b055e68a).  Because decklink drivers treats the audio and video as
essentially decoupled, we must also treat it as decoupled.  This is what
was causing video/audio to drift out of sync over time.
2017-10-10 07:04:21 -07:00

68 lines
1.8 KiB
C++

#pragma once
#include "platform.hpp"
#include <obs-module.h>
#include <map>
#include <vector>
#include <mutex>
class DeckLinkDeviceDiscovery;
class DeckLinkDeviceInstance;
class DeckLinkDevice;
class DeckLinkDeviceMode;
class DeckLink {
protected:
ComPtr<DeckLinkDeviceInstance> instance;
DeckLinkDeviceDiscovery *discovery;
bool isCapturing = false;
obs_source_t *source;
volatile long activateRefs = 0;
std::recursive_mutex deviceMutex;
BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
video_colorspace colorSpace = VIDEO_CS_DEFAULT;
video_range_type colorRange = VIDEO_RANGE_DEFAULT;
speaker_layout channelFormat = SPEAKERS_STEREO;
void SaveSettings();
static void DevicesChanged(void *param, DeckLinkDevice *device,
bool added);
public:
DeckLink(obs_source_t *source, DeckLinkDeviceDiscovery *discovery);
virtual ~DeckLink(void);
DeckLinkDevice *GetDevice() const;
long long GetActiveModeId(void) const;
obs_source_t *GetSource(void) const;
inline BMDPixelFormat GetPixelFormat() const {return pixelFormat;}
inline void SetPixelFormat(BMDPixelFormat format)
{
pixelFormat = format;
}
inline video_colorspace GetColorSpace() const {return colorSpace;}
inline void SetColorSpace(video_colorspace format)
{
colorSpace = format;
}
inline video_range_type GetColorRange() const {return colorRange;}
inline void SetColorRange(video_range_type format)
{
colorRange = format;
}
inline speaker_layout GetChannelFormat() const {return channelFormat;}
inline void SetChannelFormat(speaker_layout format)
{
channelFormat = format;
}
bool Activate(DeckLinkDevice *device, long long modeId);
void Deactivate();
bool buffering = false;
};