decklink-device-instance.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #define LOG(level, message, ...) \
  3. blog(level, "%s: " message, "decklink", ##__VA_ARGS__)
  4. #include <obs-module.h>
  5. #include "decklink-device.hpp"
  6. #include "../../libobs/media-io/video-scaler.h"
  7. #include "OBSVideoFrame.h"
  8. class AudioRepacker;
  9. class DecklinkBase;
  10. class DeckLinkDeviceInstance : public IDeckLinkInputCallback {
  11. protected:
  12. struct obs_source_frame2 currentFrame;
  13. struct obs_source_audio currentPacket;
  14. struct obs_source_cea_708 currentCaptions;
  15. DecklinkBase *decklink = nullptr;
  16. DeckLinkDevice *device = nullptr;
  17. DeckLinkDeviceMode *mode = nullptr;
  18. BMDVideoConnection videoConnection;
  19. BMDAudioConnection audioConnection;
  20. BMDDisplayMode displayMode = bmdModeNTSC;
  21. BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
  22. video_colorspace colorSpace = VIDEO_CS_DEFAULT;
  23. video_colorspace activeColorSpace = VIDEO_CS_DEFAULT;
  24. video_range_type colorRange = VIDEO_RANGE_DEFAULT;
  25. ComPtr<IDeckLinkInput> input;
  26. ComPtr<IDeckLinkOutput> output;
  27. volatile long refCount = 1;
  28. int64_t audioOffset = 0;
  29. uint64_t nextAudioTS = 0;
  30. uint64_t lastVideoTS = 0;
  31. AudioRepacker *audioRepacker = nullptr;
  32. speaker_layout channelFormat = SPEAKERS_STEREO;
  33. bool swap;
  34. bool allow10Bit;
  35. OBSVideoFrame *convertFrame = nullptr;
  36. IDeckLinkMutableVideoFrame *decklinkOutputFrame = nullptr;
  37. void FinalizeStream();
  38. void SetupVideoFormat(DeckLinkDeviceMode *mode_);
  39. void HandleAudioPacket(IDeckLinkAudioInputPacket *audioPacket,
  40. const uint64_t timestamp);
  41. void HandleVideoFrame(IDeckLinkVideoInputFrame *videoFrame,
  42. const uint64_t timestamp);
  43. public:
  44. DeckLinkDeviceInstance(DecklinkBase *decklink, DeckLinkDevice *device);
  45. virtual ~DeckLinkDeviceInstance();
  46. inline DeckLinkDevice *GetDevice() const { return device; }
  47. inline long long GetActiveModeId() const
  48. {
  49. return mode ? mode->GetId() : 0;
  50. }
  51. inline BMDPixelFormat GetActivePixelFormat() const
  52. {
  53. return pixelFormat;
  54. }
  55. inline video_colorspace GetActiveColorSpace() const
  56. {
  57. return colorSpace;
  58. }
  59. inline video_range_type GetActiveColorRange() const
  60. {
  61. return colorRange;
  62. }
  63. inline speaker_layout GetActiveChannelFormat() const
  64. {
  65. return channelFormat;
  66. }
  67. inline bool GetActiveSwapState() const { return swap; }
  68. inline BMDVideoConnection GetVideoConnection() const
  69. {
  70. return videoConnection;
  71. }
  72. inline BMDAudioConnection GetAudioConnection() const
  73. {
  74. return audioConnection;
  75. }
  76. inline DeckLinkDeviceMode *GetMode() const { return mode; }
  77. bool StartCapture(DeckLinkDeviceMode *mode, bool allow10Bit,
  78. BMDVideoConnection bmdVideoConnection,
  79. BMDAudioConnection bmdAudioConnection);
  80. bool StopCapture(void);
  81. bool StartOutput(DeckLinkDeviceMode *mode_);
  82. bool StopOutput(void);
  83. HRESULT STDMETHODCALLTYPE
  84. VideoInputFrameArrived(IDeckLinkVideoInputFrame *videoFrame,
  85. IDeckLinkAudioInputPacket *audioPacket);
  86. HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
  87. BMDVideoInputFormatChangedEvents events,
  88. IDeckLinkDisplayMode *newMode,
  89. BMDDetectedVideoInputFormatFlags detectedSignalFlags);
  90. ULONG STDMETHODCALLTYPE AddRef(void);
  91. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv);
  92. ULONG STDMETHODCALLTYPE Release(void);
  93. void DisplayVideoFrame(video_data *frame);
  94. void WriteAudio(audio_data *frames);
  95. void HandleCaptionPacket(IDeckLinkAncillaryPacket *packet,
  96. const uint64_t timestamp);
  97. };