File: OBSVideoFrame.h

package info (click to toggle)
obs-studio 30.2.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 47,852 kB
  • sloc: ansic: 202,137; cpp: 112,402; makefile: 868; python: 599; sh: 275; javascript: 19
file content (145 lines) | stat: -rw-r--r-- 4,177 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once

#include "platform.hpp"
#include "obs.hpp"
#include <atomic>

class OBSVideoFrame : public IDeckLinkMutableVideoFrame {
private:
	BMDFrameFlags flags = bmdFrameFlagDefault;
	BMDPixelFormat pixelFormat = bmdFormat8BitYUV;

	long width;
	long height;
	long rowBytes;

	unsigned char *data;

public:
	OBSVideoFrame(long width, long height, BMDPixelFormat pixelFormat);
	~OBSVideoFrame();

	HRESULT STDMETHODCALLTYPE SetFlags(BMDFrameFlags newFlags) override;

	HRESULT STDMETHODCALLTYPE SetTimecode(
		BMDTimecodeFormat format, IDeckLinkTimecode *timecode) override;

	HRESULT STDMETHODCALLTYPE SetTimecodeFromComponents(
		BMDTimecodeFormat format, uint8_t hours, uint8_t minutes,
		uint8_t seconds, uint8_t frames,
		BMDTimecodeFlags flags) override;

	HRESULT
	STDMETHODCALLTYPE
	SetAncillaryData(IDeckLinkVideoFrameAncillary *ancillary) override;

	HRESULT STDMETHODCALLTYPE
	SetTimecodeUserBits(BMDTimecodeFormat format,
			    BMDTimecodeUserBits userBits) override;

	long STDMETHODCALLTYPE GetWidth() override;

	long STDMETHODCALLTYPE GetHeight() override;

	long STDMETHODCALLTYPE GetRowBytes() override;

	BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat() override;

	BMDFrameFlags STDMETHODCALLTYPE GetFlags() override;

	HRESULT STDMETHODCALLTYPE GetBytes(void **buffer) override;

	//Dummy implementations of remaining virtual methods
	virtual HRESULT STDMETHODCALLTYPE
	GetTimecode(/* in */ BMDTimecodeFormat format,
		    /* out */ IDeckLinkTimecode **timecode) override
	{
		UNUSED_PARAMETER(format);
		UNUSED_PARAMETER(timecode);
		return E_NOINTERFACE;
	};
	virtual HRESULT STDMETHODCALLTYPE GetAncillaryData(
		/* out */ IDeckLinkVideoFrameAncillary **ancillary) override
	{
		UNUSED_PARAMETER(ancillary);
		return E_NOINTERFACE;
	};

	// IUnknown interface (dummy implementation)
	virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,
							 LPVOID *ppv) override
	{
		UNUSED_PARAMETER(iid);
		UNUSED_PARAMETER(ppv);
		return E_NOINTERFACE;
	}
	virtual ULONG STDMETHODCALLTYPE AddRef() override { return 1; }
	virtual ULONG STDMETHODCALLTYPE Release() override { return 1; }
};

class HDRVideoFrame : public IDeckLinkVideoFrame,
		      public IDeckLinkVideoFrameMetadataExtensions {
public:
	HDRVideoFrame(IDeckLinkMutableVideoFrame *frame);
	virtual ~HDRVideoFrame() {}

	// IUnknown interface
	virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,
							 LPVOID *ppv);
	virtual ULONG STDMETHODCALLTYPE AddRef(void);
	virtual ULONG STDMETHODCALLTYPE Release(void);

	// IDeckLinkVideoFrame interface
	virtual long STDMETHODCALLTYPE GetWidth(void)
	{
		return m_videoFrame->GetWidth();
	}
	virtual long STDMETHODCALLTYPE GetHeight(void)
	{
		return m_videoFrame->GetHeight();
	}
	virtual long STDMETHODCALLTYPE GetRowBytes(void)
	{
		return m_videoFrame->GetRowBytes();
	}
	virtual BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat(void)
	{
		return m_videoFrame->GetPixelFormat();
	}
	virtual BMDFrameFlags STDMETHODCALLTYPE GetFlags(void)
	{
		return m_videoFrame->GetFlags() | bmdFrameContainsHDRMetadata;
	}
	virtual HRESULT STDMETHODCALLTYPE GetBytes(void **buffer)
	{
		return m_videoFrame->GetBytes(buffer);
	}
	virtual HRESULT STDMETHODCALLTYPE
	GetTimecode(BMDTimecodeFormat format, IDeckLinkTimecode **timecode)
	{
		return m_videoFrame->GetTimecode(format, timecode);
	}
	virtual HRESULT STDMETHODCALLTYPE
	GetAncillaryData(IDeckLinkVideoFrameAncillary **ancillary)
	{
		return m_videoFrame->GetAncillaryData(ancillary);
	}

	// IDeckLinkVideoFrameMetadataExtensions interface
	virtual HRESULT STDMETHODCALLTYPE
	GetInt(BMDDeckLinkFrameMetadataID metadataID, int64_t *value);
	virtual HRESULT STDMETHODCALLTYPE
	GetFloat(BMDDeckLinkFrameMetadataID metadataID, double *value);
	virtual HRESULT STDMETHODCALLTYPE
	GetFlag(BMDDeckLinkFrameMetadataID metadataID, decklink_bool_t *value);
	virtual HRESULT STDMETHODCALLTYPE
	GetString(BMDDeckLinkFrameMetadataID metadataID,
		  decklink_string_t *value);
	virtual HRESULT STDMETHODCALLTYPE
	GetBytes(BMDDeckLinkFrameMetadataID metadataID, void *buffer,
		 uint32_t *bufferSize);

private:
	ComPtr<IDeckLinkMutableVideoFrame> m_videoFrame;
	std::atomic<ULONG> m_refCount;
};