AJAOutputUI.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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(settings, kUIPropOutput.id, static_cast<long long>(IOSelection::Invalid));
  41. obs_data_set_default_int(settings, kUIPropVideoFormatSelect.id,
  42. static_cast<long long>(kDefaultAJAVideoFormat));
  43. obs_data_set_default_int(settings, kUIPropPixelFormatSelect.id,
  44. static_cast<long long>(kDefaultAJAPixelFormat));
  45. obs_data_set_default_int(settings, kUIPropSDITransport.id,
  46. static_cast<long long>(kDefaultAJASDITransport));
  47. obs_data_set_default_int(settings, kUIPropSDITransport4K.id,
  48. static_cast<long long>(kDefaultAJASDITransport4K));
  49. }
  50. // Assign an ID to the program output plugin instance for channel usage tracking
  51. obs_data_set_string(settings, kUIPropAJAOutputID.id, kProgramOutputID);
  52. propertiesView =
  53. new OBSPropertiesView(settings, "aja_output", (PropertiesReloadCallback)obs_get_output_properties, 170);
  54. ui->propertiesLayout->addWidget(propertiesView);
  55. obs_data_release(settings);
  56. connect(propertiesView, &OBSPropertiesView::Changed, this, &AJAOutputUI::PropertiesChanged);
  57. }
  58. void AJAOutputUI::SaveSettings(const char *filename, obs_data_t *settings)
  59. {
  60. BPtr<char> modulePath = obs_module_get_config_path(obs_current_module(), "");
  61. os_mkdirs(modulePath);
  62. BPtr<char> path = obs_module_get_config_path(obs_current_module(), filename);
  63. if (settings)
  64. obs_data_save_json_safe(settings, path, "tmp", "bak");
  65. }
  66. void AJAOutputUI::SetupPreviewPropertiesView()
  67. {
  68. if (previewPropertiesView)
  69. delete previewPropertiesView;
  70. obs_data_t *settings = obs_data_create();
  71. OBSData data = load_settings(kPreviewPropsFilename);
  72. if (data) {
  73. obs_data_apply(settings, data);
  74. } else {
  75. // apply default settings
  76. obs_data_set_default_int(settings, kUIPropOutput.id, static_cast<long long>(IOSelection::Invalid));
  77. obs_data_set_default_int(settings, kUIPropVideoFormatSelect.id,
  78. static_cast<long long>(kDefaultAJAVideoFormat));
  79. obs_data_set_default_int(settings, kUIPropPixelFormatSelect.id,
  80. static_cast<long long>(kDefaultAJAPixelFormat));
  81. obs_data_set_default_int(settings, kUIPropSDITransport.id,
  82. static_cast<long long>(kDefaultAJASDITransport));
  83. obs_data_set_default_int(settings, kUIPropSDITransport4K.id,
  84. static_cast<long long>(kDefaultAJASDITransport4K));
  85. }
  86. // Assign an ID to the program output plugin instance for channel usage tracking
  87. obs_data_set_string(settings, kUIPropAJAOutputID.id, kPreviewOutputID);
  88. previewPropertiesView =
  89. new OBSPropertiesView(settings, "aja_output", (PropertiesReloadCallback)obs_get_output_properties, 170);
  90. ui->previewPropertiesLayout->addWidget(previewPropertiesView);
  91. obs_data_release(settings);
  92. connect(previewPropertiesView, &OBSPropertiesView::Changed, this, &AJAOutputUI::PreviewPropertiesChanged);
  93. }
  94. void AJAOutputUI::on_outputButton_clicked()
  95. {
  96. SaveSettings(kProgramPropsFilename, propertiesView->GetSettings());
  97. output_toggle();
  98. }
  99. void AJAOutputUI::PropertiesChanged()
  100. {
  101. SaveSettings(kProgramPropsFilename, propertiesView->GetSettings());
  102. }
  103. void AJAOutputUI::OutputStateChanged(bool active)
  104. {
  105. QString text;
  106. if (active) {
  107. text = QString(obs_module_text("Stop"));
  108. } else {
  109. text = QString(obs_module_text("Start"));
  110. }
  111. ui->outputButton->setChecked(active);
  112. ui->outputButton->setText(text);
  113. }
  114. void AJAOutputUI::on_previewOutputButton_clicked()
  115. {
  116. SaveSettings(kPreviewPropsFilename, previewPropertiesView->GetSettings());
  117. preview_output_toggle();
  118. }
  119. void AJAOutputUI::PreviewPropertiesChanged()
  120. {
  121. SaveSettings(kPreviewPropsFilename, previewPropertiesView->GetSettings());
  122. }
  123. void AJAOutputUI::PreviewOutputStateChanged(bool active)
  124. {
  125. QString text;
  126. if (active) {
  127. text = QString(obs_module_text("Stop"));
  128. } else {
  129. text = QString(obs_module_text("Start"));
  130. }
  131. ui->previewOutputButton->setChecked(active);
  132. ui->previewOutputButton->setText(text);
  133. }
  134. static obs_properties_t *create_misc_props_ui(void *vp)
  135. {
  136. AJAOutputUI *outputUI = (AJAOutputUI *)vp;
  137. if (!outputUI)
  138. return nullptr;
  139. aja::CardManager *cardManager = outputUI->GetCardManager();
  140. if (!cardManager)
  141. return nullptr;
  142. bool haveMultiView = false;
  143. for (auto &c : *cardManager) {
  144. auto deviceID = c.second->GetDeviceID();
  145. for (const auto &id : aja::MultiViewCards()) {
  146. if (deviceID == id) {
  147. haveMultiView = true;
  148. break;
  149. }
  150. }
  151. }
  152. obs_properties_t *props = obs_properties_create();
  153. obs_property_t *deviceList = obs_properties_add_list(props, kUIPropDevice.id,
  154. obs_module_text(kUIPropDevice.text), OBS_COMBO_TYPE_LIST,
  155. OBS_COMBO_FORMAT_STRING);
  156. obs_property_t *multiViewEnable =
  157. obs_properties_add_bool(props, kUIPropMultiViewEnable.id, obs_module_text(kUIPropMultiViewEnable.text));
  158. obs_property_t *multiViewAudioSources = obs_properties_add_list(
  159. props, kUIPropMultiViewAudioSource.id, obs_module_text(kUIPropMultiViewAudioSource.text),
  160. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  161. obs_property_list_clear(deviceList);
  162. obs_property_list_clear(multiViewAudioSources);
  163. NTV2DeviceID firstDeviceID = DEVICE_ID_NOTFOUND;
  164. populate_misc_device_list(deviceList, cardManager, firstDeviceID);
  165. populate_multi_view_audio_sources(multiViewAudioSources, firstDeviceID);
  166. obs_property_set_modified_callback2(deviceList, on_misc_device_selected, cardManager);
  167. obs_property_set_modified_callback2(multiViewEnable, on_multi_view_toggle, cardManager);
  168. obs_property_set_modified_callback2(multiViewAudioSources, on_multi_view_toggle, cardManager);
  169. outputUI->ui->label_3->setVisible(haveMultiView);
  170. obs_property_set_visible(deviceList, haveMultiView);
  171. obs_property_set_visible(multiViewEnable, haveMultiView);
  172. obs_property_set_visible(multiViewAudioSources, haveMultiView);
  173. return props;
  174. }
  175. void AJAOutputUI::MiscPropertiesChanged()
  176. {
  177. SaveSettings(kMiscPropsFilename, miscPropertiesView->GetSettings());
  178. }
  179. void AJAOutputUI::SetCardManager(aja::CardManager *cm)
  180. {
  181. cardManager = cm;
  182. }
  183. aja::CardManager *AJAOutputUI::GetCardManager()
  184. {
  185. return cardManager;
  186. }
  187. void AJAOutputUI::SetupMiscPropertiesView()
  188. {
  189. if (miscPropertiesView)
  190. delete miscPropertiesView;
  191. obs_data_t *settings = obs_data_create();
  192. OBSData data = load_settings(kMiscPropsFilename);
  193. if (data) {
  194. obs_data_apply(settings, data);
  195. }
  196. miscPropertiesView = new OBSPropertiesView(settings, this, (PropertiesReloadCallback)create_misc_props_ui,
  197. nullptr, nullptr, 170);
  198. ui->miscPropertiesLayout->addWidget(miscPropertiesView);
  199. obs_data_release(settings);
  200. connect(miscPropertiesView, &OBSPropertiesView::Changed, this, &AJAOutputUI::MiscPropertiesChanged);
  201. }