AJAOutputUI.cpp 7.6 KB

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