123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- #include "OBSVideoFrame.h"
- OBSVideoFrame::OBSVideoFrame(long width, long height, BMDPixelFormat pixelFormat)
- {
- int bpp = 2;
- this->width = width;
- this->height = height;
- this->rowBytes = width * bpp;
- this->data = new unsigned char[width * height * bpp + 1];
- this->pixelFormat = pixelFormat;
- }
- OBSVideoFrame::~OBSVideoFrame()
- {
- delete this->data;
- }
- HRESULT OBSVideoFrame::SetFlags(BMDFrameFlags newFlags)
- {
- flags = newFlags;
- return S_OK;
- }
- HRESULT OBSVideoFrame::SetTimecode(BMDTimecodeFormat format, IDeckLinkTimecode *timecode)
- {
- UNUSED_PARAMETER(format);
- UNUSED_PARAMETER(timecode);
- return 0;
- }
- HRESULT
- OBSVideoFrame::SetTimecodeFromComponents(BMDTimecodeFormat format, uint8_t hours, uint8_t minutes, uint8_t seconds,
- uint8_t frames, BMDTimecodeFlags flags)
- {
- UNUSED_PARAMETER(format);
- UNUSED_PARAMETER(hours);
- UNUSED_PARAMETER(minutes);
- UNUSED_PARAMETER(seconds);
- UNUSED_PARAMETER(frames);
- UNUSED_PARAMETER(flags);
- return 0;
- }
- HRESULT OBSVideoFrame::SetAncillaryData(IDeckLinkVideoFrameAncillary *ancillary)
- {
- UNUSED_PARAMETER(ancillary);
- return 0;
- }
- HRESULT OBSVideoFrame::SetTimecodeUserBits(BMDTimecodeFormat format, BMDTimecodeUserBits userBits)
- {
- UNUSED_PARAMETER(format);
- UNUSED_PARAMETER(userBits);
- return 0;
- }
- long OBSVideoFrame::GetWidth()
- {
- return width;
- }
- long OBSVideoFrame::GetHeight()
- {
- return height;
- }
- long OBSVideoFrame::GetRowBytes()
- {
- return rowBytes;
- }
- BMDPixelFormat OBSVideoFrame::GetPixelFormat()
- {
- return pixelFormat;
- }
- BMDFrameFlags OBSVideoFrame::GetFlags()
- {
- return flags;
- }
- HRESULT OBSVideoFrame::GetBytes(void **buffer)
- {
- *buffer = this->data;
- return S_OK;
- }
- #define CompareREFIID(iid1, iid2) (memcmp(&iid1, &iid2, sizeof(REFIID)) == 0)
- HDRVideoFrame::HDRVideoFrame(IDeckLinkMutableVideoFrame *frame) : m_videoFrame(frame), m_refCount(1) {}
- HRESULT HDRVideoFrame::QueryInterface(REFIID iid, LPVOID *ppv)
- {
- if (ppv == nullptr)
- return E_INVALIDARG;
- CFUUIDBytes unknown = CFUUIDGetUUIDBytes(IUnknownUUID);
- if (CompareREFIID(iid, unknown))
- *ppv = static_cast<IDeckLinkVideoFrame *>(this);
- else if (CompareREFIID(iid, IID_IDeckLinkVideoFrame))
- *ppv = static_cast<IDeckLinkVideoFrame *>(this);
- else if (CompareREFIID(iid, IID_IDeckLinkVideoFrameMetadataExtensions))
- *ppv = static_cast<IDeckLinkVideoFrameMetadataExtensions *>(this);
- else {
- *ppv = nullptr;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
- }
- ULONG HDRVideoFrame::AddRef(void)
- {
- return ++m_refCount;
- }
- ULONG HDRVideoFrame::Release(void)
- {
- ULONG newRefValue = --m_refCount;
- if (newRefValue == 0)
- delete this;
- return newRefValue;
- }
- HRESULT HDRVideoFrame::GetInt(BMDDeckLinkFrameMetadataID metadataID, int64_t *value)
- {
- HRESULT result = S_OK;
- switch (metadataID) {
- case bmdDeckLinkFrameMetadataHDRElectroOpticalTransferFunc:
- *value = 2;
- break;
- case bmdDeckLinkFrameMetadataColorspace:
- // Colorspace is fixed for this sample
- *value = bmdColorspaceRec2020;
- break;
- default:
- result = E_INVALIDARG;
- }
- return result;
- }
- HRESULT HDRVideoFrame::GetFloat(BMDDeckLinkFrameMetadataID metadataID, double *value)
- {
- HRESULT result = S_OK;
- switch (metadataID) {
- case bmdDeckLinkFrameMetadataHDRDisplayPrimariesRedX:
- *value = 0.708;
- break;
- case bmdDeckLinkFrameMetadataHDRDisplayPrimariesRedY:
- *value = 0.292;
- break;
- case bmdDeckLinkFrameMetadataHDRDisplayPrimariesGreenX:
- *value = 0.17;
- break;
- case bmdDeckLinkFrameMetadataHDRDisplayPrimariesGreenY:
- *value = 0.797;
- break;
- case bmdDeckLinkFrameMetadataHDRDisplayPrimariesBlueX:
- *value = 0.131;
- break;
- case bmdDeckLinkFrameMetadataHDRDisplayPrimariesBlueY:
- *value = 0.046;
- break;
- case bmdDeckLinkFrameMetadataHDRWhitePointX:
- *value = 0.3127;
- break;
- case bmdDeckLinkFrameMetadataHDRWhitePointY:
- *value = 0.329;
- break;
- case bmdDeckLinkFrameMetadataHDRMaxDisplayMasteringLuminance:
- *value = obs_get_video_hdr_nominal_peak_level();
- break;
- case bmdDeckLinkFrameMetadataHDRMinDisplayMasteringLuminance:
- *value = 0.0001;
- break;
- case bmdDeckLinkFrameMetadataHDRMaximumContentLightLevel:
- *value = obs_get_video_hdr_nominal_peak_level();
- break;
- case bmdDeckLinkFrameMetadataHDRMaximumFrameAverageLightLevel:
- *value = obs_get_video_hdr_nominal_peak_level();
- break;
- default:
- result = E_INVALIDARG;
- }
- return result;
- }
- HRESULT HDRVideoFrame::GetFlag(BMDDeckLinkFrameMetadataID, decklink_bool_t *)
- {
- // Not expecting GetFlag
- return E_INVALIDARG;
- }
- HRESULT HDRVideoFrame::GetString(BMDDeckLinkFrameMetadataID, decklink_string_t *)
- {
- // Not expecting GetString
- return E_INVALIDARG;
- }
- HRESULT HDRVideoFrame::GetBytes(BMDDeckLinkFrameMetadataID, void *, uint32_t *bufferSize)
- {
- *bufferSize = 0;
- // Not expecting GetBytes
- return E_INVALIDARG;
- }
|