AJAOutputUI.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #include "AJAOutputUI.h"
  2. #include "aja-ui-main.h"
  3. #include "../../../plugins/aja/aja-common.hpp"
  4. #include "../../../plugins/aja/aja-ui-props.hpp"
  5. #include "../../../plugins/aja/aja-enums.hpp"
  6. #include "../../../plugins/aja/aja-card-manager.hpp"
  7. #include <ajantv2/includes/ntv2card.h>
  8. #include <ajantv2/includes/ntv2devicefeatures.h>
  9. #include <ajantv2/includes/ntv2enums.h>
  10. #include <ajantv2/includes/ntv2utils.h>
  11. #include <obs-module.h>
  12. #include <util/platform.h>
  13. #include <util/util.hpp>
  14. AJAOutputUI::AJAOutputUI(QWidget *parent) : QDialog(parent), ui(new Ui_Output)
  15. {
  16. ui->setupUi(this);
  17. setSizeGripEnabled(true);
  18. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  19. propertiesView = nullptr;
  20. previewPropertiesView = nullptr;
  21. miscPropertiesView = nullptr;
  22. }
  23. void AJAOutputUI::ShowHideDialog()
  24. {
  25. SetupPropertiesView();
  26. SetupPreviewPropertiesView();
  27. SetupMiscPropertiesView();
  28. setVisible(!isVisible());
  29. }
  30. void AJAOutputUI::SetupPropertiesView()
  31. {
  32. if (propertiesView)
  33. delete propertiesView;
  34. obs_data_t *settings = obs_data_create();
  35. OBSData data = load_settings(kProgramPropsFilename);
  36. if (data) {
  37. obs_data_apply(settings, data);
  38. } else {
  39. // apply default settings
  40. obs_data_set_default_int(
  41. settings, kUIPropOutput.id,
  42. static_cast<long long>(IOSelection::Invalid));
  43. obs_data_set_default_int(
  44. settings, kUIPropVideoFormatSelect.id,
  45. static_cast<long long>(kDefaultAJAVideoFormat));
  46. obs_data_set_default_int(
  47. settings, kUIPropPixelFormatSelect.id,
  48. static_cast<long long>(kDefaultAJAPixelFormat));
  49. obs_data_set_default_int(
  50. settings, kUIPropSDITransport.id,
  51. static_cast<long long>(kDefaultAJASDITransport));
  52. obs_data_set_default_int(
  53. settings, kUIPropSDITransport4K.id,
  54. static_cast<long long>(kDefaultAJASDITransport4K));
  55. }
  56. // Assign an ID to the program output plugin instance for channel usage tracking
  57. obs_data_set_string(settings, kUIPropAJAOutputID.id, kProgramOutputID);
  58. propertiesView = new OBSPropertiesView(
  59. settings, "aja_output",
  60. (PropertiesReloadCallback)obs_get_output_properties, 170);
  61. ui->propertiesLayout->addWidget(propertiesView);
  62. obs_data_release(settings);
  63. connect(propertiesView, &OBSPropertiesView::Changed, this,
  64. &AJAOutputUI::PropertiesChanged);
  65. }
  66. void AJAOutputUI::SaveSettings(const char *filename, obs_data_t *settings)
  67. {
  68. BPtr<char> modulePath =
  69. obs_module_get_config_path(obs_current_module(), "");
  70. os_mkdirs(modulePath);
  71. BPtr<char> path =
  72. obs_module_get_config_path(obs_current_module(), filename);
  73. if (settings)
  74. obs_data_save_json_safe(settings, path, "tmp", "bak");
  75. }
  76. void AJAOutputUI::SetupPreviewPropertiesView()
  77. {
  78. if (previewPropertiesView)
  79. delete previewPropertiesView;
  80. obs_data_t *settings = obs_data_create();
  81. OBSData data = load_settings(kPreviewPropsFilename);
  82. if (data) {
  83. obs_data_apply(settings, data);
  84. } else {
  85. // apply default settings
  86. obs_data_set_default_int(
  87. settings, kUIPropOutput.id,
  88. static_cast<long long>(IOSelection::Invalid));
  89. obs_data_set_default_int(
  90. settings, kUIPropVideoFormatSelect.id,
  91. static_cast<long long>(kDefaultAJAVideoFormat));
  92. obs_data_set_default_int(
  93. settings, kUIPropPixelFormatSelect.id,
  94. static_cast<long long>(kDefaultAJAPixelFormat));
  95. obs_data_set_default_int(
  96. settings, kUIPropSDITransport.id,
  97. static_cast<long long>(kDefaultAJASDITransport));
  98. obs_data_set_default_int(
  99. settings, kUIPropSDITransport4K.id,
  100. static_cast<long long>(kDefaultAJASDITransport4K));
  101. }
  102. // Assign an ID to the program output plugin instance for channel usage tracking
  103. obs_data_set_string(settings, kUIPropAJAOutputID.id, kPreviewOutputID);
  104. previewPropertiesView = new OBSPropertiesView(
  105. settings, "aja_output",
  106. (PropertiesReloadCallback)obs_get_output_properties, 170);
  107. ui->previewPropertiesLayout->addWidget(previewPropertiesView);
  108. obs_data_release(settings);
  109. connect(previewPropertiesView, &OBSPropertiesView::Changed, this,
  110. &AJAOutputUI::PreviewPropertiesChanged);
  111. }
  112. void AJAOutputUI::on_outputButton_clicked()
  113. {
  114. SaveSettings(kProgramPropsFilename, propertiesView->GetSettings());
  115. output_toggle();
  116. }
  117. void AJAOutputUI::PropertiesChanged()
  118. {
  119. SaveSettings(kProgramPropsFilename, propertiesView->GetSettings());
  120. }
  121. void AJAOutputUI::OutputStateChanged(bool active)
  122. {
  123. QString text;
  124. if (active) {
  125. text = QString(obs_module_text("Stop"));
  126. } else {
  127. text = QString(obs_module_text("Start"));
  128. }
  129. ui->outputButton->setChecked(active);
  130. ui->outputButton->setText(text);
  131. }
  132. void AJAOutputUI::on_previewOutputButton_clicked()
  133. {
  134. SaveSettings(kPreviewPropsFilename,
  135. previewPropertiesView->GetSettings());
  136. preview_output_toggle();
  137. }
  138. void AJAOutputUI::PreviewPropertiesChanged()
  139. {
  140. SaveSettings(kPreviewPropsFilename,
  141. previewPropertiesView->GetSettings());
  142. }
  143. void AJAOutputUI::PreviewOutputStateChanged(bool active)
  144. {
  145. QString text;
  146. if (active) {
  147. text = QString(obs_module_text("Stop"));
  148. } else {
  149. text = QString(obs_module_text("Start"));
  150. }
  151. ui->previewOutputButton->setChecked(active);
  152. ui->previewOutputButton->setText(text);
  153. }
  154. static obs_properties_t *create_misc_props_ui(void *vp)
  155. {
  156. AJAOutputUI *outputUI = (AJAOutputUI *)vp;
  157. if (!outputUI)
  158. return nullptr;
  159. aja::CardManager *cardManager = outputUI->GetCardManager();
  160. if (!cardManager)
  161. return nullptr;
  162. bool haveMultiView = false;
  163. for (auto &c : *cardManager) {
  164. auto deviceID = c.second->GetDeviceID();
  165. for (const auto &id : aja::MultiViewCards()) {
  166. if (deviceID == id) {
  167. haveMultiView = true;
  168. break;
  169. }
  170. }
  171. }
  172. obs_properties_t *props = obs_properties_create();
  173. obs_property_t *deviceList = obs_properties_add_list(
  174. props, kUIPropDevice.id, obs_module_text(kUIPropDevice.text),
  175. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
  176. obs_property_t *multiViewEnable = obs_properties_add_bool(
  177. props, kUIPropMultiViewEnable.id,
  178. obs_module_text(kUIPropMultiViewEnable.text));
  179. obs_property_t *multiViewAudioSources = obs_properties_add_list(
  180. props, kUIPropMultiViewAudioSource.id,
  181. obs_module_text(kUIPropMultiViewAudioSource.text),
  182. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  183. obs_property_list_clear(deviceList);
  184. obs_property_list_clear(multiViewAudioSources);
  185. NTV2DeviceID firstDeviceID = DEVICE_ID_NOTFOUND;
  186. populate_misc_device_list(deviceList, cardManager, firstDeviceID);
  187. populate_multi_view_audio_sources(multiViewAudioSources, firstDeviceID);
  188. obs_property_set_modified_callback2(deviceList, on_misc_device_selected,
  189. cardManager);
  190. obs_property_set_modified_callback2(multiViewEnable,
  191. on_multi_view_toggle, cardManager);
  192. obs_property_set_modified_callback2(multiViewAudioSources,
  193. on_multi_view_toggle, cardManager);
  194. outputUI->ui->label_3->setVisible(haveMultiView);
  195. obs_property_set_visible(deviceList, haveMultiView);
  196. obs_property_set_visible(multiViewEnable, haveMultiView);
  197. obs_property_set_visible(multiViewAudioSources, haveMultiView);
  198. return props;
  199. }
  200. void AJAOutputUI::MiscPropertiesChanged()
  201. {
  202. SaveSettings(kMiscPropsFilename, miscPropertiesView->GetSettings());
  203. }
  204. void AJAOutputUI::SetCardManager(aja::CardManager *cm)
  205. {
  206. cardManager = cm;
  207. }
  208. aja::CardManager *AJAOutputUI::GetCardManager()
  209. {
  210. return cardManager;
  211. }
  212. void AJAOutputUI::SetupMiscPropertiesView()
  213. {
  214. if (miscPropertiesView)
  215. delete miscPropertiesView;
  216. obs_data_t *settings = obs_data_create();
  217. OBSData data = load_settings(kMiscPropsFilename);
  218. if (data) {
  219. obs_data_apply(settings, data);
  220. }
  221. miscPropertiesView = new OBSPropertiesView(
  222. settings, this, (PropertiesReloadCallback)create_misc_props_ui,
  223. nullptr, nullptr, 170);
  224. ui->miscPropertiesLayout->addWidget(miscPropertiesView);
  225. obs_data_release(settings);
  226. connect(miscPropertiesView, &OBSPropertiesView::Changed, this,
  227. &AJAOutputUI::MiscPropertiesChanged);
  228. }