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

108 lines
3 KiB
C++
Raw Normal View History

2016-02-23 23:16:51 +00:00
#pragma once
2019-09-22 21:19:10 +00:00
#define LOG(level, message, ...) \
blog(level, "%s: " message, "decklink", ##__VA_ARGS__)
2019-07-27 12:47:10 +00:00
#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-09-22 21:19:10 +00:00
DecklinkBase *decklink = nullptr;
DeckLinkDevice *device = nullptr;
DeckLinkDeviceMode *mode = nullptr;
BMDVideoConnection videoConnection;
BMDAudioConnection audioConnection;
BMDDisplayMode displayMode = bmdModeNTSC;
BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
video_colorspace colorSpace = VIDEO_CS_DEFAULT;
video_colorspace activeColorSpace = VIDEO_CS_DEFAULT;
video_range_type colorRange = VIDEO_RANGE_DEFAULT;
ComPtr<IDeckLinkInput> input;
2019-07-27 12:47:10 +00:00
ComPtr<IDeckLinkOutput> output;
2019-09-22 21:19:10 +00:00
volatile long refCount = 1;
int64_t audioOffset = 0;
uint64_t nextAudioTS = 0;
uint64_t lastVideoTS = 0;
AudioRepacker *audioRepacker = nullptr;
speaker_layout channelFormat = SPEAKERS_STEREO;
bool swap;
2019-07-27 12:47:10 +00:00
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,
2019-09-22 21:19:10 +00:00
const uint64_t timestamp);
2016-02-23 23:16:51 +00:00
void HandleVideoFrame(IDeckLinkVideoInputFrame *videoFrame,
2019-09-22 21:19:10 +00:00
const uint64_t timestamp);
2016-02-23 23:16:51 +00:00
public:
2019-07-27 12:47:10 +00:00
DeckLinkDeviceInstance(DecklinkBase *decklink, DeckLinkDevice *device);
2016-02-23 23:16:51 +00:00
virtual ~DeckLinkDeviceInstance();
2019-09-22 21:19:10 +00:00
inline DeckLinkDevice *GetDevice() const { return device; }
2016-02-23 23:16:51 +00:00
inline long long GetActiveModeId() const
{
return mode ? mode->GetId() : 0;
}
2019-09-22 21:19:10 +00:00
inline BMDPixelFormat GetActivePixelFormat() const
{
return pixelFormat;
}
inline video_colorspace GetActiveColorSpace() const
{
return colorSpace;
}
inline video_range_type GetActiveColorRange() const
{
return colorRange;
}
inline speaker_layout GetActiveChannelFormat() const
{
return channelFormat;
}
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
2019-09-22 21:19:10 +00:00
inline DeckLinkDeviceMode *GetMode() const { return mode; }
2016-02-23 23:16:51 +00:00
2019-07-27 12:47:10 +00:00
bool StartCapture(DeckLinkDeviceMode *mode,
2019-09-22 21:19:10 +00:00
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);
2019-09-22 21:19:10 +00:00
HRESULT STDMETHODCALLTYPE
VideoInputFrameArrived(IDeckLinkVideoInputFrame *videoFrame,
IDeckLinkAudioInputPacket *audioPacket);
2016-02-23 23:16:51 +00:00
HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
2019-09-22 21:19:10 +00:00
BMDVideoInputFormatChangedEvents events,
IDeckLinkDisplayMode *newMode,
BMDDetectedVideoInputFormatFlags detectedSignalFlags);
2016-02-23 23:16:51 +00:00
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
};