decklink-device-instance.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include "decklink-device.hpp"
  3. class AudioRepacker;
  4. class DeckLinkDeviceInstance : public IDeckLinkInputCallback {
  5. protected:
  6. struct obs_source_frame currentFrame;
  7. struct obs_source_audio currentPacket;
  8. DeckLink *decklink = nullptr;
  9. DeckLinkDevice *device = nullptr;
  10. DeckLinkDeviceMode *mode = nullptr;
  11. BMDDisplayMode displayMode = bmdModeNTSC;
  12. BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
  13. video_colorspace colorSpace = VIDEO_CS_DEFAULT;
  14. video_colorspace activeColorSpace = VIDEO_CS_DEFAULT;
  15. video_range_type colorRange = VIDEO_RANGE_DEFAULT;
  16. ComPtr<IDeckLinkInput> input;
  17. volatile long refCount = 1;
  18. int64_t audioOffset = 0;
  19. uint64_t nextAudioTS = 0;
  20. uint64_t lastVideoTS = 0;
  21. AudioRepacker *audioRepacker = nullptr;
  22. speaker_layout channelFormat = SPEAKERS_STEREO;
  23. void FinalizeStream();
  24. void SetupVideoFormat(DeckLinkDeviceMode *mode_);
  25. void HandleAudioPacket(IDeckLinkAudioInputPacket *audioPacket,
  26. const uint64_t timestamp);
  27. void HandleVideoFrame(IDeckLinkVideoInputFrame *videoFrame,
  28. const uint64_t timestamp);
  29. public:
  30. DeckLinkDeviceInstance(DeckLink *decklink, DeckLinkDevice *device);
  31. virtual ~DeckLinkDeviceInstance();
  32. inline DeckLinkDevice *GetDevice() const {return device;}
  33. inline long long GetActiveModeId() const
  34. {
  35. return mode ? mode->GetId() : 0;
  36. }
  37. inline BMDPixelFormat GetActivePixelFormat() const {return pixelFormat;}
  38. inline video_colorspace GetActiveColorSpace() const {return colorSpace;}
  39. inline video_range_type GetActiveColorRange() const {return colorRange;}
  40. inline speaker_layout GetActiveChannelFormat() const {return channelFormat;}
  41. inline DeckLinkDeviceMode *GetMode() const {return mode;}
  42. bool StartCapture(DeckLinkDeviceMode *mode);
  43. bool StopCapture(void);
  44. HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
  45. IDeckLinkVideoInputFrame *videoFrame,
  46. IDeckLinkAudioInputPacket *audioPacket);
  47. HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
  48. BMDVideoInputFormatChangedEvents events,
  49. IDeckLinkDisplayMode *newMode,
  50. BMDDetectedVideoInputFormatFlags detectedSignalFlags);
  51. ULONG STDMETHODCALLTYPE AddRef(void);
  52. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv);
  53. ULONG STDMETHODCALLTYPE Release(void);
  54. };