-
Notifications
You must be signed in to change notification settings - Fork 10
/
MutableVideoFrame.cpp
132 lines (103 loc) · 2.32 KB
/
MutableVideoFrame.cpp
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
#include "MutableVideoFrame.h"
#include "util.h"
#include <string.h>
#include <cstddef>
#include <iostream>
#define CompareREFIID(iid1, iid2) (memcmp(&iid1, &iid2, sizeof(REFIID)) == 0)
MutableVideoFrame::MutableVideoFrame(long width, long height, BMDPixelFormat pixelFormat) :
m_width(width),
m_height(height),
m_pixelFormat(pixelFormat),
m_refCount(1)
{
long bytes = GetBytesPerPixel(m_pixelFormat) * m_width * m_height;
m_buf = new char[bytes];
if(m_buf == NULL) {
std::cerr << "Unable to allocate Mutable FrameBuffer" << std::endl;
exit(1);
}
}
int MutableVideoFrame::GetBytesPerPixel(BMDPixelFormat pixelFormat)
{
int bytesPerPixel = 2;
switch(pixelFormat)
{
case bmdFormat8BitYUV:
bytesPerPixel = 2;
break;
case bmdFormat8BitARGB:
case bmdFormat8BitBGRA:
case bmdFormat10BitYUV:
case bmdFormat10BitRGB:
bytesPerPixel = 4;
break;
}
return bytesPerPixel;
}
long MutableVideoFrame::GetWidth (void)
{
return m_width;
}
long MutableVideoFrame::GetHeight (void)
{
return m_height;
}
long MutableVideoFrame::GetRowBytes (void)
{
return GetBytesPerPixel(m_pixelFormat) * m_width;
}
BMDPixelFormat MutableVideoFrame::GetPixelFormat (void)
{
return m_pixelFormat;
}
BMDFrameFlags MutableVideoFrame::GetFlags (void)
{
return bmdFrameFlagDefault;
}
HRESULT MutableVideoFrame::GetBytes (/* out */ void **buffer)
{
*buffer = m_buf;
return S_OK;
}
HRESULT MutableVideoFrame::QueryInterface(REFIID iid, LPVOID *ppv)
{
CFUUIDBytes iunknown = CFUUIDGetUUIDBytes(IUnknownUUID);
if (CompareREFIID(iid, iunknown))
{
*ppv = static_cast<IDeckLinkVideoFrame*>(this);
}
else if (CompareREFIID(iid, IID_IDeckLinkVideoFrame))
{
*ppv = static_cast<IDeckLinkVideoFrame*>(this);
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
HRESULT MutableVideoFrame::GetTimecode (/* in */ UNUSED BMDTimecodeFormat format, /* out */ UNUSED IDeckLinkTimecode **timecode)
{
return E_NOTIMPL;
}
HRESULT MutableVideoFrame::GetAncillaryData (/* out */ UNUSED IDeckLinkVideoFrameAncillary **ancillary)
{
return E_NOTIMPL;
}
ULONG MutableVideoFrame::AddRef(void)
{
return __sync_add_and_fetch(&m_refCount, 1);
}
ULONG MutableVideoFrame::Release(void)
{
int32_t newRefValue = __sync_sub_and_fetch(&m_refCount, 1);
if (newRefValue == 0)
{
delete[] m_buf;
delete this;
return 0;
}
return newRefValue;
}