decklink-device-instance.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_frame currentFrame;
  11. struct obs_source_audio currentPacket;
  12. DecklinkBase *decklink = nullptr;
  13. DeckLinkDevice *device = nullptr;
  14. DeckLinkDeviceMode *mode = nullptr;
  15. BMDDisplayMode displayMode = bmdModeNTSC;
  16. BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
  17. video_colorspace colorSpace = VIDEO_CS_DEFAULT;
  18. video_colorspace activeColorSpace = VIDEO_CS_DEFAULT;
  19. video_range_type colorRange = VIDEO_RANGE_DEFAULT;
  20. ComPtr<IDeckLinkInput> input;
  21. ComPtr<IDeckLinkOutput> output;
  22. volatile long refCount = 1;
  23. int64_t audioOffset = 0;
  24. uint64_t nextAudioTS = 0;
  25. uint64_t lastVideoTS = 0;
  26. AudioRepacker *audioRepacker = nullptr;
  27. speaker_layout channelFormat = SPEAKERS_STEREO;
  28. bool swap;
  29. IDeckLinkMutableVideoFrame *decklinkOutputFrame = nullptr;
  30. void FinalizeStream();
  31. void SetupVideoFormat(DeckLinkDeviceMode *mode_);
  32. void HandleAudioPacket(IDeckLinkAudioInputPacket *audioPacket,
  33. const uint64_t timestamp);
  34. void HandleVideoFrame(IDeckLinkVideoInputFrame *videoFrame,
  35. const uint64_t timestamp);
  36. public:
  37. DeckLinkDeviceInstance(DecklinkBase *decklink, DeckLinkDevice *device);
  38. virtual ~DeckLinkDeviceInstance();
  39. inline DeckLinkDevice *GetDevice() const {return device;}
  40. inline long long GetActiveModeId() const
  41. {
  42. return mode ? mode->GetId() : 0;
  43. }
  44. inline BMDPixelFormat GetActivePixelFormat() const {return pixelFormat;}
  45. inline video_colorspace GetActiveColorSpace() const {return colorSpace;}
  46. inline video_range_type GetActiveColorRange() const {return colorRange;}
  47. inline speaker_layout GetActiveChannelFormat() const {return channelFormat;}
  48. inline bool GetActiveSwapState() const {return swap;}
  49. inline DeckLinkDeviceMode *GetMode() const {return mode;}
  50. bool StartCapture(DeckLinkDeviceMode *mode);
  51. bool StopCapture(void);
  52. bool StartOutput(DeckLinkDeviceMode *mode_);
  53. bool StopOutput(void);
  54. HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
  55. IDeckLinkVideoInputFrame *videoFrame,
  56. IDeckLinkAudioInputPacket *audioPacket);
  57. HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
  58. BMDVideoInputFormatChangedEvents events,
  59. IDeckLinkDisplayMode *newMode,
  60. BMDDetectedVideoInputFormatFlags detectedSignalFlags);
  61. ULONG STDMETHODCALLTYPE AddRef(void);
  62. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv);
  63. ULONG STDMETHODCALLTYPE Release(void);
  64. void DisplayVideoFrame(video_data *frame);
  65. void WriteAudio(audio_data *frames);
  66. };