aja-routing.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #pragma once
  2. #include "aja-props.hpp"
  3. #include <ajantv2/includes/ntv2enums.h>
  4. #include <iostream>
  5. #include <string>
  6. #include <map>
  7. #include <vector>
  8. class CNTV2Card;
  9. /* The AJA hardware and NTV2 SDK uses a concept called "Signal Routing" to connect high-level firmware
  10. * blocks known as "Widgets" to one another via "crosspoint" connections. This facilitates streaming
  11. * data from one Widget to another to achieve specific functionality.
  12. * Such functionality may include SDI/HDMI capture/output, colorspace conversion, hardware LUTs, etc.
  13. *
  14. * This code references a table of RoutingConfig entries, where each entry contains the settings required
  15. * to configure an AJA device for a particular capture or output task. These settings include the number of
  16. * physical IO Widgets (SDI or HDMI) required, number of framestore Widgets required, register settings
  17. * that must be enabled or disabled, and a special short-hand "route string".
  18. * Of special note is the route string, which is parsed into a map of NTV2XptConnections. These connections
  19. * are then applied as the "signal route", connecting the Widget's crosspoints together.
  20. */
  21. struct RoutingConfig {
  22. NTV2Mode mode; // capture or playout?
  23. uint32_t num_wires; // number of physical connections
  24. uint32_t num_framestores; // number of framestores used
  25. bool enable_3g_out; // enable register for 3G SDI Output?
  26. bool enable_6g_out; // enable register for 6G SDI Output?
  27. bool enable_12g_out; // enable register for 12G SDI Output?
  28. bool convert_3g_in; // enable register for 3G level-B -> level-A SDI input conversion?
  29. bool convert_3g_out; // enable register for 3G level-A -> level-B SDI output conversion?
  30. bool enable_rgb_3ga_convert; // enable register for RGB 3G level-B -> level-A SDI output conversion?
  31. bool enable_3gb_out; // enable register for 3G level-B SDI output?
  32. bool enable_4k_squares; // enable register for 4K square division?
  33. bool enable_8k_squares; // enable register for 8K square division?
  34. bool enable_tsi; // enable register for two-sample interleave (UHD/4K/8K)
  35. std::string
  36. route_string; // signal routing shorthand string to parse into crosspoint connections
  37. };
  38. /* This table is used to correlate a particular "raster definition" (i.e. SD/HD/4K/etc.)
  39. * and SMPTE VPID transport byte (VPIDStandard) to an SDIWireFormat enum.
  40. * This allows mapping SDI video signals to the correct format, particularly in the case
  41. * where multiple SDI formats share the same VPID transport value.
  42. * For example: VPIDStandard_1080 (0x85) is used on the wire for both single-link (1x SDI wire)
  43. * 1080-line HD SDI video AND quad-link (4x SDI wires) UHD/4K "square-division" video.
  44. */
  45. using VPIDSpec = std::pair<RasterDefinition, VPIDStandard>;
  46. static inline const std::map<VPIDSpec, SDIWireFormat> kSDIWireFormats = {
  47. {{RasterDefinition::SD, VPIDStandard_483_576}, SDIWireFormat::SD_ST352},
  48. {{RasterDefinition::HD, VPIDStandard_720},
  49. SDIWireFormat::HD_720p_ST292},
  50. {{RasterDefinition::HD, VPIDStandard_1080},
  51. SDIWireFormat::HD_1080_ST292},
  52. {{RasterDefinition::HD, VPIDStandard_1080_DualLink},
  53. SDIWireFormat::HD_1080_ST372_Dual},
  54. {{RasterDefinition::HD, VPIDStandard_720_3Ga},
  55. SDIWireFormat::HD_720p_ST425_3Ga},
  56. {{RasterDefinition::HD, VPIDStandard_1080_3Ga},
  57. SDIWireFormat::HD_1080p_ST425_3Ga},
  58. {{RasterDefinition::HD, VPIDStandard_1080_DualLink_3Gb},
  59. SDIWireFormat::HD_1080p_ST425_3Gb_DL},
  60. {{RasterDefinition::HD, VPIDStandard_720_3Gb},
  61. SDIWireFormat::HD_720p_ST425_3Gb},
  62. {{RasterDefinition::HD, VPIDStandard_1080_3Gb},
  63. SDIWireFormat::HD_1080p_ST425_3Gb},
  64. {{RasterDefinition::HD, VPIDStandard_1080_Dual_3Ga},
  65. SDIWireFormat::HD_1080p_ST425_Dual_3Ga},
  66. {{RasterDefinition::HD, VPIDStandard_1080_Dual_3Gb},
  67. SDIWireFormat::HD_1080p_ST425_Dual_3Gb},
  68. {{RasterDefinition::UHD_4K, VPIDStandard_1080_3Gb},
  69. SDIWireFormat::UHD4K_ST292_Dual_1_5_Squares},
  70. {{RasterDefinition::UHD_4K, VPIDStandard_1080},
  71. SDIWireFormat::UHD4K_ST292_Quad_1_5_Squares},
  72. {{RasterDefinition::UHD_4K, VPIDStandard_1080_3Ga},
  73. SDIWireFormat::UHD4K_ST425_Quad_3Ga_Squares},
  74. {{RasterDefinition::UHD_4K, VPIDStandard_1080_DualLink_3Gb},
  75. SDIWireFormat::UHD4K_ST425_Quad_3Gb_Squares},
  76. {{RasterDefinition::UHD_4K, VPIDStandard_2160_DualLink},
  77. SDIWireFormat::UHD4K_ST425_Dual_3Gb_2SI},
  78. {{RasterDefinition::UHD_4K, VPIDStandard_2160_QuadLink_3Ga},
  79. SDIWireFormat::UHD4K_ST425_Quad_3Ga_2SI},
  80. {{RasterDefinition::UHD_4K, VPIDStandard_2160_QuadDualLink_3Gb},
  81. SDIWireFormat::UHD4K_ST425_Quad_3Gb_2SI},
  82. {{RasterDefinition::UHD_4K, VPIDStandard_2160_Single_6Gb},
  83. SDIWireFormat::UHD4K_ST2018_6G_Squares_2SI},
  84. {{RasterDefinition::UHD_4K_Retail_12G, VPIDStandard_2160_Single_6Gb},
  85. SDIWireFormat::UHD4K_ST2018_6G_Squares_2SI_Kona5_io4KPlus},
  86. {{RasterDefinition::UHD_4K, VPIDStandard_2160_Single_12Gb},
  87. SDIWireFormat::UHD4K_ST2018_12G_Squares_2SI},
  88. {{RasterDefinition::UHD_4K_Retail_12G, VPIDStandard_2160_Single_12Gb},
  89. SDIWireFormat::UHD4K_ST2018_12G_Squares_2SI_Kona5_io4KPlus},
  90. {{RasterDefinition::UHD2_8K, VPIDStandard_4320_DualLink_12Gb},
  91. SDIWireFormat::UHD28K_ST2082_Dual_12G},
  92. {{RasterDefinition::UHD2_8K, VPIDStandard_2160_DualLink_12Gb},
  93. SDIWireFormat::UHD28K_ST2082_RGB_Dual_12G},
  94. {{RasterDefinition::UHD2_8K, VPIDStandard_4320_QuadLink_12Gb},
  95. SDIWireFormat::UHD28K_ST2082_Quad_12G},
  96. };
  97. extern RasterDefinition
  98. GetRasterDefinition(IOSelection io, NTV2VideoFormat vf,
  99. NTV2DeviceID deviceID = DEVICE_ID_NOTFOUND);
  100. extern std::string RasterDefinitionToString(RasterDefinition rd);
  101. // Applies RoutingConfig settings to the card to configure a specific SDI/HDMI capture/output mode.
  102. class Routing {
  103. public:
  104. static bool ParseRouteString(const std::string &route,
  105. NTV2XptConnections &cnx);
  106. static bool DetermineSDIWireFormat(NTV2DeviceID deviceID, VPIDSpec spec,
  107. SDIWireFormat &swf);
  108. static bool FindRoutingConfigHDMI(HDMIWireFormat hwf, NTV2Mode mode,
  109. bool isRGB, NTV2DeviceID deviceID,
  110. RoutingConfig &routing);
  111. static bool FindRoutingConfigSDI(SDIWireFormat swf, NTV2Mode mode,
  112. bool isRGB, NTV2DeviceID deviceID,
  113. RoutingConfig &routing);
  114. static void StartSourceAudio(const SourceProps &props, CNTV2Card *card);
  115. static void StopSourceAudio(const SourceProps &props, CNTV2Card *card);
  116. static bool ConfigureSourceRoute(const SourceProps &props,
  117. NTV2Mode mode, CNTV2Card *card);
  118. static bool ConfigureOutputRoute(const OutputProps &props,
  119. NTV2Mode mode, CNTV2Card *card);
  120. static ULWord initial_framestore_output_index(NTV2DeviceID deviceID,
  121. IOSelection io,
  122. NTV2Channel init_channel);
  123. static void ConfigureOutputAudio(const OutputProps &props,
  124. CNTV2Card *card);
  125. };