aja-card-manager.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #include "aja-props.hpp"
  3. #include <obs-module.h>
  4. #include <ajantv2/includes/ntv2enums.h>
  5. #include <ajantv2/includes/ntv2publicinterface.h>
  6. #include <memory>
  7. #include <map>
  8. #include <mutex>
  9. #include <vector>
  10. class CNTV2Card;
  11. class AJAOutput;
  12. class AJASource;
  13. namespace aja {
  14. using ChannelPwnz = std::map<std::string, int32_t>;
  15. /* A CardEntry for each physical AJA card is added to a map retained by the CardManager.
  16. * Each CardEntry itself maintains a map representing the AJA card "Channels" the are
  17. * owned by a particular capture or output plugin instance. The Channel ownership map is
  18. * then used to determine which "IOSelection" (i.e. SDI1, SDI3+4, HDMI Monitor Output, etc.)
  19. * drop-down menu items are either accessible or grayed out in the capture and output plugin UIs.
  20. */
  21. class CardEntry {
  22. public:
  23. CardEntry(uint32_t cardIndex, const std::string &cardID);
  24. virtual ~CardEntry();
  25. CNTV2Card *GetCard();
  26. virtual bool Initialize();
  27. virtual uint32_t GetCardIndex() const;
  28. virtual std::string GetCardID() const;
  29. virtual std::string GetDisplayName() const;
  30. virtual std::string GetSerial() const;
  31. virtual NTV2DeviceID GetDeviceID() const;
  32. virtual bool ChannelReady(NTV2Channel chan, const std::string &owner) const;
  33. virtual bool AcquireChannel(NTV2Channel chan, NTV2Mode mode, const std::string &owner);
  34. virtual bool ReleaseChannel(NTV2Channel chan, NTV2Mode mode, const std::string &owner);
  35. virtual bool InputSelectionReady(IOSelection io, NTV2DeviceID id, const std::string &owner) const;
  36. virtual bool OutputSelectionReady(IOSelection io, NTV2DeviceID id, const std::string &owner) const;
  37. virtual bool AcquireInputSelection(IOSelection io, NTV2DeviceID id, const std::string &owner);
  38. virtual bool ReleaseInputSelection(IOSelection io, NTV2DeviceID id, const std::string &owner);
  39. virtual bool AcquireOutputSelection(IOSelection io, NTV2DeviceID id, const std::string &owner);
  40. virtual bool ReleaseOutputSelection(IOSelection io, NTV2DeviceID id, const std::string &owner);
  41. virtual bool UpdateChannelOwnerName(const std::string &oldName, const std::string &newName);
  42. private:
  43. virtual bool isAutoCirculateRunning(NTV2Channel);
  44. protected:
  45. uint32_t mCardIndex;
  46. std::string mCardID;
  47. std::unique_ptr<CNTV2Card> mCard;
  48. ChannelPwnz mChannelPwnz;
  49. mutable std::mutex mMutex;
  50. };
  51. using CardEntryPtr = std::shared_ptr<CardEntry>;
  52. using CardEntries = std::map<std::string, CardEntryPtr>;
  53. /* The CardManager enumerates the physical AJA cards in the system, reverts them to a default
  54. * state on exit, and maintains a map of CardEntry objects corresponding to each physical card.
  55. * Each CardEntry object holds a pointer to the CNTV2Card instance and a map of NTV2Channels
  56. * that are "owned" by each plugin instance. NTV2Channels are essentially treated as indices
  57. * for various firwmare Widgets and sub-systems throughout the AJA NTV2 SDK.
  58. */
  59. class CardManager {
  60. public:
  61. static CardManager &Instance();
  62. void ClearCardEntries();
  63. void EnumerateCards();
  64. size_t NumCardEntries() const;
  65. CNTV2Card *GetCard(const std::string &cardID);
  66. const CardEntryPtr GetCardEntry(const std::string &cardID) const;
  67. const CardEntries &GetCardEntries() const;
  68. const CardEntries::iterator begin();
  69. const CardEntries::iterator end();
  70. private:
  71. CardManager() = default;
  72. ~CardManager() = default;
  73. CardManager(const CardManager &) = delete;
  74. CardManager(const CardManager &&) = delete;
  75. CardManager &operator=(const CardManager &) = delete;
  76. CardManager &operator=(const CardManager &&) = delete;
  77. CardEntries mCardEntries;
  78. mutable std::mutex mMutex;
  79. };
  80. } // namespace aja