OBSVideoFrame.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #include "OBSVideoFrame.h"
  2. OBSVideoFrame::OBSVideoFrame(long width, long height,
  3. BMDPixelFormat pixelFormat)
  4. {
  5. int bpp = 2;
  6. this->width = width;
  7. this->height = height;
  8. this->rowBytes = width * bpp;
  9. this->data = new unsigned char[width * height * bpp + 1];
  10. this->pixelFormat = pixelFormat;
  11. }
  12. OBSVideoFrame::~OBSVideoFrame()
  13. {
  14. delete this->data;
  15. }
  16. HRESULT OBSVideoFrame::SetFlags(BMDFrameFlags newFlags)
  17. {
  18. flags = newFlags;
  19. return S_OK;
  20. }
  21. HRESULT OBSVideoFrame::SetTimecode(BMDTimecodeFormat format,
  22. IDeckLinkTimecode *timecode)
  23. {
  24. UNUSED_PARAMETER(format);
  25. UNUSED_PARAMETER(timecode);
  26. return 0;
  27. }
  28. HRESULT
  29. OBSVideoFrame::SetTimecodeFromComponents(BMDTimecodeFormat format,
  30. uint8_t hours, uint8_t minutes,
  31. uint8_t seconds, uint8_t frames,
  32. BMDTimecodeFlags flags)
  33. {
  34. UNUSED_PARAMETER(format);
  35. UNUSED_PARAMETER(hours);
  36. UNUSED_PARAMETER(minutes);
  37. UNUSED_PARAMETER(seconds);
  38. UNUSED_PARAMETER(frames);
  39. UNUSED_PARAMETER(flags);
  40. return 0;
  41. }
  42. HRESULT OBSVideoFrame::SetAncillaryData(IDeckLinkVideoFrameAncillary *ancillary)
  43. {
  44. UNUSED_PARAMETER(ancillary);
  45. return 0;
  46. }
  47. HRESULT OBSVideoFrame::SetTimecodeUserBits(BMDTimecodeFormat format,
  48. BMDTimecodeUserBits userBits)
  49. {
  50. UNUSED_PARAMETER(format);
  51. UNUSED_PARAMETER(userBits);
  52. return 0;
  53. }
  54. long OBSVideoFrame::GetWidth()
  55. {
  56. return width;
  57. }
  58. long OBSVideoFrame::GetHeight()
  59. {
  60. return height;
  61. }
  62. long OBSVideoFrame::GetRowBytes()
  63. {
  64. return rowBytes;
  65. }
  66. BMDPixelFormat OBSVideoFrame::GetPixelFormat()
  67. {
  68. return pixelFormat;
  69. }
  70. BMDFrameFlags OBSVideoFrame::GetFlags()
  71. {
  72. return flags;
  73. }
  74. HRESULT OBSVideoFrame::GetBytes(void **buffer)
  75. {
  76. *buffer = this->data;
  77. return S_OK;
  78. }
  79. #define CompareREFIID(iid1, iid2) (memcmp(&iid1, &iid2, sizeof(REFIID)) == 0)
  80. HDRVideoFrame::HDRVideoFrame(IDeckLinkMutableVideoFrame *frame)
  81. : m_videoFrame(frame),
  82. m_refCount(1)
  83. {
  84. }
  85. HRESULT HDRVideoFrame::QueryInterface(REFIID iid, LPVOID *ppv)
  86. {
  87. if (ppv == nullptr)
  88. return E_INVALIDARG;
  89. CFUUIDBytes unknown = CFUUIDGetUUIDBytes(IUnknownUUID);
  90. if (CompareREFIID(iid, unknown))
  91. *ppv = static_cast<IDeckLinkVideoFrame *>(this);
  92. else if (CompareREFIID(iid, IID_IDeckLinkVideoFrame))
  93. *ppv = static_cast<IDeckLinkVideoFrame *>(this);
  94. else if (CompareREFIID(iid, IID_IDeckLinkVideoFrameMetadataExtensions))
  95. *ppv = static_cast<IDeckLinkVideoFrameMetadataExtensions *>(
  96. this);
  97. else {
  98. *ppv = nullptr;
  99. return E_NOINTERFACE;
  100. }
  101. AddRef();
  102. return S_OK;
  103. }
  104. ULONG HDRVideoFrame::AddRef(void)
  105. {
  106. return ++m_refCount;
  107. }
  108. ULONG HDRVideoFrame::Release(void)
  109. {
  110. ULONG newRefValue = --m_refCount;
  111. if (newRefValue == 0)
  112. delete this;
  113. return newRefValue;
  114. }
  115. HRESULT HDRVideoFrame::GetInt(BMDDeckLinkFrameMetadataID metadataID,
  116. int64_t *value)
  117. {
  118. HRESULT result = S_OK;
  119. switch (metadataID) {
  120. case bmdDeckLinkFrameMetadataHDRElectroOpticalTransferFunc:
  121. *value = 2;
  122. break;
  123. case bmdDeckLinkFrameMetadataColorspace:
  124. // Colorspace is fixed for this sample
  125. *value = bmdColorspaceRec2020;
  126. break;
  127. default:
  128. result = E_INVALIDARG;
  129. }
  130. return result;
  131. }
  132. HRESULT HDRVideoFrame::GetFloat(BMDDeckLinkFrameMetadataID metadataID,
  133. double *value)
  134. {
  135. HRESULT result = S_OK;
  136. switch (metadataID) {
  137. case bmdDeckLinkFrameMetadataHDRDisplayPrimariesRedX:
  138. *value = 0.708;
  139. break;
  140. case bmdDeckLinkFrameMetadataHDRDisplayPrimariesRedY:
  141. *value = 0.292;
  142. break;
  143. case bmdDeckLinkFrameMetadataHDRDisplayPrimariesGreenX:
  144. *value = 0.17;
  145. break;
  146. case bmdDeckLinkFrameMetadataHDRDisplayPrimariesGreenY:
  147. *value = 0.797;
  148. break;
  149. case bmdDeckLinkFrameMetadataHDRDisplayPrimariesBlueX:
  150. *value = 0.131;
  151. break;
  152. case bmdDeckLinkFrameMetadataHDRDisplayPrimariesBlueY:
  153. *value = 0.046;
  154. break;
  155. case bmdDeckLinkFrameMetadataHDRWhitePointX:
  156. *value = 0.3127;
  157. break;
  158. case bmdDeckLinkFrameMetadataHDRWhitePointY:
  159. *value = 0.329;
  160. break;
  161. case bmdDeckLinkFrameMetadataHDRMaxDisplayMasteringLuminance:
  162. *value = obs_get_video_hdr_nominal_peak_level();
  163. break;
  164. case bmdDeckLinkFrameMetadataHDRMinDisplayMasteringLuminance:
  165. *value = 0.00001;
  166. break;
  167. case bmdDeckLinkFrameMetadataHDRMaximumContentLightLevel:
  168. *value = obs_get_video_hdr_nominal_peak_level();
  169. break;
  170. case bmdDeckLinkFrameMetadataHDRMaximumFrameAverageLightLevel:
  171. *value = obs_get_video_hdr_nominal_peak_level();
  172. break;
  173. default:
  174. result = E_INVALIDARG;
  175. }
  176. return result;
  177. }
  178. HRESULT HDRVideoFrame::GetFlag(BMDDeckLinkFrameMetadataID, decklink_bool_t *)
  179. {
  180. // Not expecting GetFlag
  181. return E_INVALIDARG;
  182. }
  183. HRESULT HDRVideoFrame::GetString(BMDDeckLinkFrameMetadataID,
  184. decklink_string_t *)
  185. {
  186. // Not expecting GetString
  187. return E_INVALIDARG;
  188. }
  189. HRESULT HDRVideoFrame::GetBytes(BMDDeckLinkFrameMetadataID, void *,
  190. uint32_t *bufferSize)
  191. {
  192. *bufferSize = 0;
  193. // Not expecting GetBytes
  194. return E_INVALIDARG;
  195. }