decklink-device-instance.hpp 3.1 KB

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