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

81 lines
2.7 KiB
C++
Raw Normal View History

#pragma once
2018-09-25 15:51:32 -07:00
#define LOG(level, message, ...) blog(level, "%s: " message, "decklink", ##__VA_ARGS__)
#include <obs-module.h>
#include "decklink-device.hpp"
2018-09-25 15:51:32 -07:00
#include "../../libobs/media-io/video-scaler.h"
class AudioRepacker;
2018-09-25 15:51:32 -07:00
class DecklinkBase;
class DeckLinkDeviceInstance : public IDeckLinkInputCallback {
protected:
struct obs_source_frame currentFrame;
struct obs_source_audio currentPacket;
2018-09-25 15:51:32 -07:00
DecklinkBase *decklink = nullptr;
DeckLinkDevice *device = nullptr;
DeckLinkDeviceMode *mode = nullptr;
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;
2018-09-25 15:51:32 -07:00
ComPtr<IDeckLinkOutput> output;
volatile long refCount = 1;
int64_t audioOffset = 0;
uint64_t nextAudioTS = 0;
uint64_t lastVideoTS = 0;
AudioRepacker *audioRepacker = nullptr;
speaker_layout channelFormat = SPEAKERS_STEREO;
2018-09-25 15:51:32 -07:00
IDeckLinkMutableVideoFrame *decklinkOutputFrame;
void FinalizeStream();
void SetupVideoFormat(DeckLinkDeviceMode *mode_);
void HandleAudioPacket(IDeckLinkAudioInputPacket *audioPacket,
const uint64_t timestamp);
void HandleVideoFrame(IDeckLinkVideoInputFrame *videoFrame,
const uint64_t timestamp);
public:
2018-09-25 15:51:32 -07:00
DeckLinkDeviceInstance(DecklinkBase *decklink, DeckLinkDevice *device);
2015-07-11 14:22:14 -07: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;}
inline video_colorspace GetActiveColorSpace() const {return colorSpace;}
inline video_range_type GetActiveColorRange() const {return colorRange;}
inline speaker_layout GetActiveChannelFormat() const {return channelFormat;}
inline DeckLinkDeviceMode *GetMode() const {return mode;}
bool StartCapture(DeckLinkDeviceMode *mode);
bool StopCapture(void);
2018-09-25 15:51:32 -07:00
bool StartOutput(DeckLinkDeviceMode *mode_);
bool StopOutput(void);
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);
2018-09-25 15:51:32 -07:00
void DisplayVideoFrame(video_data *frame);
void WriteAudio(audio_data *frames);
};