yolobs-studio/plugins/decklink/decklink-device-instance.hpp

89 lines
3.1 KiB
C++
Raw Normal View History

2016-02-23 23:16:51 +00:00
#pragma once
2019-07-27 12:47:10 +00:00
#define LOG(level, message, ...) blog(level, "%s: " message, "decklink", ##__VA_ARGS__)
#include <obs-module.h>
2016-02-23 23:16:51 +00:00
#include "decklink-device.hpp"
2019-07-27 12:47:10 +00:00
#include "../../libobs/media-io/video-scaler.h"
2016-02-23 23:16:51 +00:00
2017-06-29 19:01:10 +00:00
class AudioRepacker;
2019-07-27 12:47:10 +00:00
class DecklinkBase;
2017-06-29 19:01:10 +00:00
2016-02-23 23:16:51 +00:00
class DeckLinkDeviceInstance : public IDeckLinkInputCallback {
protected:
2019-07-27 12:47:10 +00:00
struct obs_source_frame2 currentFrame;
2016-02-23 23:16:51 +00:00
struct obs_source_audio currentPacket;
2019-07-27 12:47:10 +00:00
DecklinkBase *decklink = nullptr;
2016-02-23 23:16:51 +00:00
DeckLinkDevice *device = nullptr;
DeckLinkDeviceMode *mode = nullptr;
2019-07-27 12:47:10 +00:00
BMDVideoConnection videoConnection;
BMDAudioConnection audioConnection;
2018-02-19 19:54:37 +00:00
BMDDisplayMode displayMode = bmdModeNTSC;
2016-02-23 23:16:51 +00:00
BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
2018-02-19 19:54:37 +00:00
video_colorspace colorSpace = VIDEO_CS_DEFAULT;
video_colorspace activeColorSpace = VIDEO_CS_DEFAULT;
video_range_type colorRange = VIDEO_RANGE_DEFAULT;
2016-02-23 23:16:51 +00:00
ComPtr<IDeckLinkInput> input;
2019-07-27 12:47:10 +00:00
ComPtr<IDeckLinkOutput> output;
2016-02-23 23:16:51 +00:00
volatile long refCount = 1;
2017-06-29 19:01:10 +00:00
int64_t audioOffset = 0;
uint64_t nextAudioTS = 0;
uint64_t lastVideoTS = 0;
AudioRepacker *audioRepacker = nullptr;
speaker_layout channelFormat = SPEAKERS_STEREO;
2019-07-27 12:47:10 +00:00
bool swap;
IDeckLinkMutableVideoFrame *decklinkOutputFrame = nullptr;
2017-06-29 19:01:10 +00:00
void FinalizeStream();
2018-02-19 19:54:37 +00:00
void SetupVideoFormat(DeckLinkDeviceMode *mode_);
2016-02-23 23:16:51 +00:00
void HandleAudioPacket(IDeckLinkAudioInputPacket *audioPacket,
const uint64_t timestamp);
void HandleVideoFrame(IDeckLinkVideoInputFrame *videoFrame,
const uint64_t timestamp);
public:
2019-07-27 12:47:10 +00:00
DeckLinkDeviceInstance(DecklinkBase *decklink, DeckLinkDevice *device);
2016-02-23 23:16:51 +00:00
virtual ~DeckLinkDeviceInstance();
inline DeckLinkDevice *GetDevice() const {return device;}
inline long long GetActiveModeId() const
{
return mode ? mode->GetId() : 0;
}
inline BMDPixelFormat GetActivePixelFormat() const {return pixelFormat;}
2018-02-19 19:54:37 +00:00
inline video_colorspace GetActiveColorSpace() const {return colorSpace;}
inline video_range_type GetActiveColorRange() const {return colorRange;}
2017-06-29 19:01:10 +00:00
inline speaker_layout GetActiveChannelFormat() const {return channelFormat;}
2019-07-27 12:47:10 +00:00
inline bool GetActiveSwapState() const {return swap;}
inline BMDVideoConnection GetVideoConnection() const {return videoConnection;}
inline BMDAudioConnection GetAudioConnection() const {return audioConnection;}
2016-02-23 23:16:51 +00:00
inline DeckLinkDeviceMode *GetMode() const {return mode;}
2019-07-27 12:47:10 +00:00
bool StartCapture(DeckLinkDeviceMode *mode,
BMDVideoConnection bmdVideoConnection,
BMDAudioConnection bmdAudioConnection);
2016-02-23 23:16:51 +00:00
bool StopCapture(void);
2019-07-27 12:47:10 +00:00
bool StartOutput(DeckLinkDeviceMode *mode_);
bool StopOutput(void);
2016-02-23 23:16:51 +00:00
HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
IDeckLinkVideoInputFrame *videoFrame,
IDeckLinkAudioInputPacket *audioPacket);
HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
BMDVideoInputFormatChangedEvents events,
IDeckLinkDisplayMode *newMode,
BMDDetectedVideoInputFormatFlags detectedSignalFlags);
ULONG STDMETHODCALLTYPE AddRef(void);
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv);
ULONG STDMETHODCALLTYPE Release(void);
2019-07-27 12:47:10 +00:00
void DisplayVideoFrame(video_data *frame);
void WriteAudio(audio_data *frames);
2016-02-23 23:16:51 +00:00
};