decklink-device-instance.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. IDeckLinkMutableVideoFrame *decklinkOutputFrame;
  29. void FinalizeStream();
  30. void SetupVideoFormat(DeckLinkDeviceMode *mode_);
  31. void HandleAudioPacket(IDeckLinkAudioInputPacket *audioPacket,
  32. const uint64_t timestamp);
  33. void HandleVideoFrame(IDeckLinkVideoInputFrame *videoFrame,
  34. const uint64_t timestamp);
  35. public:
  36. DeckLinkDeviceInstance(DecklinkBase *decklink, DeckLinkDevice *device);
  37. virtual ~DeckLinkDeviceInstance();
  38. inline DeckLinkDevice *GetDevice() const {return device;}
  39. inline long long GetActiveModeId() const
  40. {
  41. return mode ? mode->GetId() : 0;
  42. }
  43. inline BMDPixelFormat GetActivePixelFormat() const {return pixelFormat;}
  44. inline video_colorspace GetActiveColorSpace() const {return colorSpace;}
  45. inline video_range_type GetActiveColorRange() const {return colorRange;}
  46. inline speaker_layout GetActiveChannelFormat() const {return channelFormat;}
  47. inline DeckLinkDeviceMode *GetMode() const {return mode;}
  48. bool StartCapture(DeckLinkDeviceMode *mode);
  49. bool StopCapture(void);
  50. bool StartOutput(DeckLinkDeviceMode *mode_);
  51. bool StopOutput(void);
  52. HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
  53. IDeckLinkVideoInputFrame *videoFrame,
  54. IDeckLinkAudioInputPacket *audioPacket);
  55. HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
  56. BMDVideoInputFormatChangedEvents events,
  57. IDeckLinkDisplayMode *newMode,
  58. BMDDetectedVideoInputFormatFlags detectedSignalFlags);
  59. ULONG STDMETHODCALLTYPE AddRef(void);
  60. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv);
  61. ULONG STDMETHODCALLTYPE Release(void);
  62. void DisplayVideoFrame(video_data *frame);
  63. void WriteAudio(audio_data *frames);
  64. };