decklink-device-instance.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
  12. ComPtr<IDeckLinkInput> input;
  13. volatile long refCount = 1;
  14. int64_t audioOffset = 0;
  15. uint64_t nextAudioTS = 0;
  16. uint64_t lastVideoTS = 0;
  17. AudioRepacker *audioRepacker = nullptr;
  18. speaker_layout channelFormat = SPEAKERS_STEREO;
  19. void FinalizeStream();
  20. void HandleAudioPacket(IDeckLinkAudioInputPacket *audioPacket,
  21. const uint64_t timestamp);
  22. void HandleVideoFrame(IDeckLinkVideoInputFrame *videoFrame,
  23. const uint64_t timestamp);
  24. public:
  25. DeckLinkDeviceInstance(DeckLink *decklink, DeckLinkDevice *device);
  26. virtual ~DeckLinkDeviceInstance();
  27. inline DeckLinkDevice *GetDevice() const {return device;}
  28. inline long long GetActiveModeId() const
  29. {
  30. return mode ? mode->GetId() : 0;
  31. }
  32. inline BMDPixelFormat GetActivePixelFormat() const {return pixelFormat;}
  33. inline speaker_layout GetActiveChannelFormat() const {return channelFormat;}
  34. inline DeckLinkDeviceMode *GetMode() const {return mode;}
  35. bool StartCapture(DeckLinkDeviceMode *mode);
  36. bool StopCapture(void);
  37. HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
  38. IDeckLinkVideoInputFrame *videoFrame,
  39. IDeckLinkAudioInputPacket *audioPacket);
  40. HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
  41. BMDVideoInputFormatChangedEvents events,
  42. IDeckLinkDisplayMode *newMode,
  43. BMDDetectedVideoInputFormatFlags detectedSignalFlags);
  44. ULONG STDMETHODCALLTYPE AddRef(void);
  45. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv);
  46. ULONG STDMETHODCALLTYPE Release(void);
  47. };