aja-card-manager.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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,
  33. const std::string &owner) const;
  34. virtual bool AcquireChannel(NTV2Channel chan, NTV2Mode mode,
  35. const std::string &owner);
  36. virtual bool ReleaseChannel(NTV2Channel chan, NTV2Mode mode,
  37. const std::string &owner);
  38. virtual bool InputSelectionReady(IOSelection io, NTV2DeviceID id,
  39. const std::string &owner) const;
  40. virtual bool OutputSelectionReady(IOSelection io, NTV2DeviceID id,
  41. const std::string &owner) const;
  42. virtual bool AcquireInputSelection(IOSelection io, NTV2DeviceID id,
  43. const std::string &owner);
  44. virtual bool ReleaseInputSelection(IOSelection io, NTV2DeviceID id,
  45. const std::string &owner);
  46. virtual bool AcquireOutputSelection(IOSelection io, NTV2DeviceID id,
  47. const std::string &owner);
  48. virtual bool ReleaseOutputSelection(IOSelection io, NTV2DeviceID id,
  49. const std::string &owner);
  50. virtual bool UpdateChannelOwnerName(const std::string &oldName,
  51. const std::string &newName);
  52. private:
  53. virtual bool isAutoCirculateRunning(NTV2Channel);
  54. protected:
  55. uint32_t mCardIndex;
  56. std::string mCardID;
  57. std::unique_ptr<CNTV2Card> mCard;
  58. ChannelPwnz mChannelPwnz;
  59. mutable std::mutex mMutex;
  60. };
  61. using CardEntryPtr = std::shared_ptr<CardEntry>;
  62. using CardEntries = std::map<std::string, CardEntryPtr>;
  63. /* The CardManager enumerates the physical AJA cards in the system, reverts them to a default
  64. * state on exit, and maintains a map of CardEntry objects corresponding to each physical card.
  65. * Each CardEntry object holds a pointer to the CNTV2Card instance and a map of NTV2Channels
  66. * that are "owned" by each plugin instance. NTV2Channels are essentially treated as indices
  67. * for various firwmare Widgets and sub-systems throughout the AJA NTV2 SDK.
  68. */
  69. class CardManager {
  70. public:
  71. static CardManager &Instance();
  72. void ClearCardEntries();
  73. void EnumerateCards();
  74. size_t NumCardEntries() const;
  75. CNTV2Card *GetCard(const std::string &cardID);
  76. const CardEntryPtr GetCardEntry(const std::string &cardID) const;
  77. const CardEntries &GetCardEntries() const;
  78. const CardEntries::iterator begin();
  79. const CardEntries::iterator end();
  80. private:
  81. CardManager() = default;
  82. ~CardManager() = default;
  83. CardManager(const CardManager &) = delete;
  84. CardManager(const CardManager &&) = delete;
  85. CardManager &operator=(const CardManager &) = delete;
  86. CardManager &operator=(const CardManager &&) = delete;
  87. CardEntries mCardEntries;
  88. mutable std::mutex mMutex;
  89. };
  90. } // aja