OBSVideoFrame.cpp 4.6 KB

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