decklink-device-instance.hpp 2.7 KB
Newer Older
1 2
#pragma once

C
Colin Edwards 已提交
3 4 5
#define LOG(level, message, ...) blog(level, "%s: " message, "decklink", ##__VA_ARGS__)

#include <obs-module.h>
6
#include "decklink-device.hpp"
C
Colin Edwards 已提交
7
#include "../../libobs/media-io/video-scaler.h"
8

9
class AudioRepacker;
C
Colin Edwards 已提交
10
class DecklinkBase;
11

12 13 14 15
class DeckLinkDeviceInstance : public IDeckLinkInputCallback {
protected:
	struct obs_source_frame currentFrame;
	struct obs_source_audio currentPacket;
C
Colin Edwards 已提交
16
	DecklinkBase            *decklink = nullptr;
17 18
	DeckLinkDevice          *device = nullptr;
	DeckLinkDeviceMode      *mode = nullptr;
19
	BMDDisplayMode          displayMode = bmdModeNTSC;
20
	BMDPixelFormat          pixelFormat = bmdFormat8BitYUV;
21 22 23
	video_colorspace        colorSpace = VIDEO_CS_DEFAULT;
	video_colorspace        activeColorSpace = VIDEO_CS_DEFAULT;
	video_range_type        colorRange = VIDEO_RANGE_DEFAULT;
24
	ComPtr<IDeckLinkInput>  input;
C
Colin Edwards 已提交
25
	ComPtr<IDeckLinkOutput> output;
26
	volatile long           refCount = 1;
27 28 29
	int64_t                 audioOffset = 0;
	uint64_t                nextAudioTS = 0;
	uint64_t                lastVideoTS = 0;
30 31 32
	AudioRepacker           *audioRepacker = nullptr;
	speaker_layout          channelFormat = SPEAKERS_STEREO;

C
Colin Edwards 已提交
33 34
	IDeckLinkMutableVideoFrame *decklinkOutputFrame;

35
	void FinalizeStream();
36
	void SetupVideoFormat(DeckLinkDeviceMode *mode_);
37

38 39 40 41 42 43
	void HandleAudioPacket(IDeckLinkAudioInputPacket *audioPacket,
			const uint64_t timestamp);
	void HandleVideoFrame(IDeckLinkVideoInputFrame *videoFrame,
			const uint64_t timestamp);

public:
C
Colin Edwards 已提交
44
	DeckLinkDeviceInstance(DecklinkBase *decklink, DeckLinkDevice *device);
J
jp9000 已提交
45
	virtual ~DeckLinkDeviceInstance();
46 47 48 49 50 51 52

	inline DeckLinkDevice *GetDevice() const {return device;}
	inline long long GetActiveModeId() const
	{
		return mode ? mode->GetId() : 0;
	}

53
	inline BMDPixelFormat GetActivePixelFormat() const {return pixelFormat;}
54 55
	inline video_colorspace GetActiveColorSpace() const {return colorSpace;}
	inline video_range_type GetActiveColorRange() const {return colorRange;}
56
	inline speaker_layout GetActiveChannelFormat() const {return channelFormat;}
57

58 59 60 61 62
	inline DeckLinkDeviceMode *GetMode() const {return mode;}

	bool StartCapture(DeckLinkDeviceMode *mode);
	bool StopCapture(void);

C
Colin Edwards 已提交
63 64 65
	bool StartOutput(DeckLinkDeviceMode *mode_);
	bool StopOutput(void);

66 67 68 69 70 71 72 73 74 75 76
	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);
C
Colin Edwards 已提交
77 78 79

	void DisplayVideoFrame(video_data *frame);
	void WriteAudio(audio_data *frames);
80
};