aja-source.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. #include "aja-card-manager.hpp"
  2. #include "aja-common.hpp"
  3. #include "aja-ui-props.hpp"
  4. #include "aja-source.hpp"
  5. #include "aja-routing.hpp"
  6. #include <util/threading.h>
  7. #include <util/platform.h>
  8. #include <util/dstr.h>
  9. #include <util/util_uint64.h>
  10. #include <obs-module.h>
  11. #include <ajantv2/includes/ntv2card.h>
  12. #include <ajantv2/includes/ntv2utils.h>
  13. #ifndef NSEC_PER_SEC
  14. #define NSEC_PER_SEC 1000000000LL
  15. #endif
  16. #define NTV2_AUDIOSIZE_MAX (401 * 1024)
  17. AJASource::AJASource(obs_source_t *source)
  18. : mVideoBuffer{},
  19. mAudioBuffer{},
  20. mCard{nullptr},
  21. mSourceName{""},
  22. mCardID{""},
  23. mDeviceIndex{0},
  24. mBuffering{false},
  25. mIsCapturing{false},
  26. mSourceProps{},
  27. mTestPattern{},
  28. mCaptureThread{nullptr},
  29. mMutex{},
  30. mSource{source},
  31. mCrosspoints{}
  32. {
  33. }
  34. AJASource::~AJASource()
  35. {
  36. Deactivate();
  37. mTestPattern.clear();
  38. mVideoBuffer.Deallocate();
  39. mAudioBuffer.Deallocate();
  40. mVideoBuffer = 0;
  41. mAudioBuffer = 0;
  42. }
  43. void AJASource::SetCard(CNTV2Card *card)
  44. {
  45. mCard = card;
  46. }
  47. CNTV2Card *AJASource::GetCard()
  48. {
  49. return mCard;
  50. }
  51. void AJASource::SetOBSSource(obs_source_t *source)
  52. {
  53. mSource = source;
  54. }
  55. obs_source_t *AJASource::GetOBSSource(void) const
  56. {
  57. return mSource;
  58. }
  59. void AJASource::SetName(const std::string &name)
  60. {
  61. mSourceName = name;
  62. }
  63. std::string AJASource::GetName() const
  64. {
  65. return mSourceName;
  66. }
  67. void populate_source_device_list(obs_property_t *list)
  68. {
  69. obs_property_list_clear(list);
  70. auto &cardManager = aja::CardManager::Instance();
  71. cardManager.EnumerateCards();
  72. for (const auto &iter : cardManager.GetCardEntries()) {
  73. if (iter.second) {
  74. CNTV2Card *card = iter.second->GetCard();
  75. if (!card)
  76. continue;
  77. if (aja::IsOutputOnlyDevice(iter.second->GetDeviceID()))
  78. continue;
  79. obs_property_list_add_string(
  80. list, iter.second->GetDisplayName().c_str(),
  81. iter.second->GetCardID().c_str());
  82. }
  83. }
  84. }
  85. //
  86. // Capture Thread stuff
  87. //
  88. struct AudioOffsets {
  89. ULWord currentAddress = 0;
  90. ULWord lastAddress = 0;
  91. ULWord readOffset = 0;
  92. ULWord wrapAddress = 0;
  93. ULWord bytesRead = 0;
  94. };
  95. static void ResetAudioBufferOffsets(CNTV2Card *card,
  96. NTV2AudioSystem audioSystem,
  97. AudioOffsets &offsets)
  98. {
  99. if (!card)
  100. return;
  101. offsets.currentAddress = 0;
  102. offsets.lastAddress = 0;
  103. offsets.readOffset = 0;
  104. offsets.wrapAddress = 0;
  105. offsets.bytesRead = 0;
  106. card->GetAudioReadOffset(offsets.readOffset, audioSystem);
  107. card->GetAudioWrapAddress(offsets.wrapAddress, audioSystem);
  108. offsets.wrapAddress += offsets.readOffset;
  109. offsets.lastAddress = offsets.readOffset;
  110. }
  111. void AJASource::GenerateTestPattern(NTV2VideoFormat vf, NTV2PixelFormat pf,
  112. NTV2TestPatternSelect ps)
  113. {
  114. NTV2VideoFormat vid_fmt = vf;
  115. NTV2PixelFormat pix_fmt = pf;
  116. if (vid_fmt == NTV2_FORMAT_UNKNOWN)
  117. vid_fmt = NTV2_FORMAT_720p_5994;
  118. if (pix_fmt == NTV2_FBF_INVALID)
  119. pix_fmt = kDefaultAJAPixelFormat;
  120. NTV2FormatDesc fd(vid_fmt, pix_fmt, NTV2_VANCMODE_OFF);
  121. auto bufSize = fd.GetTotalRasterBytes();
  122. if (bufSize != mTestPattern.size()) {
  123. mTestPattern.clear();
  124. mTestPattern.resize(bufSize);
  125. NTV2TestPatternGen gen;
  126. gen.DrawTestPattern(ps, fd.GetRasterWidth(),
  127. fd.GetRasterHeight(), pix_fmt,
  128. mTestPattern);
  129. }
  130. if (mTestPattern.size() == 0) {
  131. blog(LOG_DEBUG,
  132. "AJASource::GenerateTestPattern: Error generating test pattern!");
  133. return;
  134. }
  135. const enum video_format obs_vid_fmt =
  136. aja::AJAPixelFormatToOBSVideoFormat(pix_fmt);
  137. struct obs_source_frame2 obsFrame;
  138. obsFrame.flip = false;
  139. obsFrame.timestamp = os_gettime_ns();
  140. obsFrame.width = fd.GetRasterWidth();
  141. obsFrame.height = fd.GetRasterHeight();
  142. obsFrame.format = obs_vid_fmt;
  143. obsFrame.data[0] = mTestPattern.data();
  144. obsFrame.linesize[0] = fd.GetBytesPerRow();
  145. video_colorspace colorspace = VIDEO_CS_709;
  146. if (NTV2_IS_SD_VIDEO_FORMAT(vid_fmt))
  147. colorspace = VIDEO_CS_601;
  148. video_format_get_parameters_for_format(colorspace, VIDEO_RANGE_PARTIAL,
  149. obs_vid_fmt,
  150. obsFrame.color_matrix,
  151. obsFrame.color_range_min,
  152. obsFrame.color_range_max);
  153. obs_source_output_video2(mSource, &obsFrame);
  154. blog(LOG_DEBUG, "AJASource::GenerateTestPattern: Black");
  155. }
  156. static inline uint64_t samples_to_ns(size_t frames, uint_fast32_t rate)
  157. {
  158. return util_mul_div64(frames, NSEC_PER_SEC, rate);
  159. }
  160. static inline uint64_t get_sample_time(size_t frames, uint_fast32_t rate)
  161. {
  162. return os_gettime_ns() - samples_to_ns(frames, rate);
  163. }
  164. static bool CheckTransferAudioDMA(CNTV2Card *card,
  165. const NTV2AudioSystem audioSystem,
  166. void *buffer, ULWord bufferSize,
  167. ULWord dmaOffset, ULWord dmaSize,
  168. const char *log_id)
  169. {
  170. if (dmaSize > bufferSize) {
  171. blog(LOG_DEBUG,
  172. "AJASource::CaptureThread: Audio overrun %s! Buffer Size: %u, Bytes Captured: %u",
  173. log_id, bufferSize, dmaSize);
  174. return false;
  175. }
  176. card->DMAReadAudio(audioSystem, (ULWord *)buffer, dmaOffset, dmaSize);
  177. return true;
  178. }
  179. static inline bool TransferAudio(CNTV2Card *card,
  180. const NTV2AudioSystem audioSystem,
  181. NTV2_POINTER &audioBuffer,
  182. AudioOffsets &offsets)
  183. {
  184. card->ReadAudioLastIn(offsets.currentAddress, audioSystem);
  185. offsets.currentAddress += 1;
  186. offsets.currentAddress += offsets.readOffset;
  187. if (offsets.currentAddress < offsets.lastAddress) {
  188. offsets.bytesRead = offsets.wrapAddress - offsets.lastAddress;
  189. if (!CheckTransferAudioDMA(card, audioSystem, audioBuffer,
  190. audioBuffer.GetByteCount(),
  191. offsets.lastAddress,
  192. offsets.bytesRead, "(1)"))
  193. return false;
  194. if (!CheckTransferAudioDMA(
  195. card, audioSystem,
  196. audioBuffer.GetHostAddress(offsets.bytesRead),
  197. audioBuffer.GetByteCount() - offsets.bytesRead,
  198. offsets.readOffset,
  199. offsets.currentAddress - offsets.readOffset, "(2)"))
  200. return false;
  201. offsets.bytesRead +=
  202. offsets.currentAddress - offsets.readOffset;
  203. } else {
  204. offsets.bytesRead =
  205. offsets.currentAddress - offsets.lastAddress;
  206. if (!CheckTransferAudioDMA(card, audioSystem, audioBuffer,
  207. audioBuffer.GetByteCount(),
  208. offsets.lastAddress,
  209. offsets.bytesRead, "(3)"))
  210. return false;
  211. }
  212. return true;
  213. }
  214. void AJASource::CaptureThread(AJAThread *thread, void *data)
  215. {
  216. UNUSED_PARAMETER(thread);
  217. auto ajaSource = (AJASource *)data;
  218. if (!ajaSource) {
  219. blog(LOG_WARNING,
  220. "AJASource::CaptureThread: Plugin instance is null!");
  221. return;
  222. }
  223. blog(LOG_INFO,
  224. "AJASource::CaptureThread: Starting capture thread for AJA source %s",
  225. ajaSource->GetName().c_str());
  226. auto card = ajaSource->GetCard();
  227. if (!card) {
  228. blog(LOG_ERROR,
  229. "AJASource::CaptureThread: Card instance is null!");
  230. return;
  231. }
  232. auto sourceProps = ajaSource->GetSourceProps();
  233. ajaSource->ResetVideoBuffer(sourceProps.videoFormat,
  234. sourceProps.pixelFormat);
  235. auto inputSource = sourceProps.InitialInputSource();
  236. auto channel = sourceProps.Channel();
  237. auto framestore = sourceProps.Framestore();
  238. auto audioSystem = sourceProps.AudioSystem();
  239. // Current "on-air" frame on the card. The capture thread "Ping-pongs" between
  240. // two frames, starting at an index corresponding to the framestore channel.
  241. // For example:
  242. // Channel 1 (index 0) = frames 0/1
  243. // Channel 2 (index 1) = frames 2/3
  244. // Channel 3 (index 2) = frames 4/5
  245. // Channel 4 (index 3) = frames 6/7
  246. // etc...
  247. ULWord currentCardFrame = GetIndexForNTV2Channel(framestore) * 2;
  248. card->WaitForInputFieldID(NTV2_FIELD0, channel);
  249. currentCardFrame ^= 1;
  250. card->SetInputFrame(framestore, currentCardFrame);
  251. AudioOffsets offsets;
  252. ResetAudioBufferOffsets(card, audioSystem, offsets);
  253. obs_data_t *settings = obs_source_get_settings(ajaSource->mSource);
  254. while (ajaSource->IsCapturing()) {
  255. if (card->GetModelName() == "(Not Found)") {
  256. os_sleep_ms(250);
  257. obs_source_update(ajaSource->mSource, settings);
  258. break;
  259. }
  260. auto videoFormat = sourceProps.videoFormat;
  261. auto pixelFormat = sourceProps.pixelFormat;
  262. auto ioSelection = sourceProps.ioSelect;
  263. card->WaitForInputFieldID(NTV2_FIELD0, channel);
  264. currentCardFrame ^= 1;
  265. // Card format detection -- restarts capture thread via aja_source_update callback
  266. auto newVideoFormat = card->GetInputVideoFormat(
  267. inputSource, aja::Is3GLevelB(card, channel));
  268. if (newVideoFormat == NTV2_FORMAT_UNKNOWN) {
  269. blog(LOG_DEBUG,
  270. "AJASource::CaptureThread: Video format unknown!");
  271. ajaSource->GenerateTestPattern(videoFormat, pixelFormat,
  272. NTV2_TestPatt_Black);
  273. os_sleep_ms(250);
  274. continue;
  275. }
  276. newVideoFormat = aja::HandleSpecialCaseFormats(
  277. ioSelection, newVideoFormat, sourceProps.deviceID);
  278. if (sourceProps.autoDetect && (videoFormat != newVideoFormat)) {
  279. blog(LOG_INFO,
  280. "AJASource::CaptureThread: New Video Format detected! Triggering 'aja_source_update' callback and returning...");
  281. blog(LOG_INFO,
  282. "AJASource::CaptureThread: Current Video Format: %s, | Want Video Format: %s",
  283. NTV2VideoFormatToString(videoFormat, true).c_str(),
  284. NTV2VideoFormatToString(newVideoFormat, true)
  285. .c_str());
  286. os_sleep_ms(250);
  287. obs_source_update(ajaSource->mSource, settings);
  288. break;
  289. }
  290. if (!TransferAudio(card, audioSystem, ajaSource->mAudioBuffer,
  291. offsets)) {
  292. ResetAudioBufferOffsets(card, audioSystem, offsets);
  293. } else {
  294. offsets.lastAddress = offsets.currentAddress;
  295. obs_source_audio audioPacket;
  296. audioPacket.samples_per_sec = 48000;
  297. audioPacket.format = AUDIO_FORMAT_32BIT;
  298. audioPacket.speakers = SPEAKERS_7POINT1;
  299. audioPacket.frames = offsets.bytesRead / 32;
  300. audioPacket.timestamp =
  301. get_sample_time(audioPacket.frames, 48000);
  302. audioPacket.data[0] = (uint8_t *)ajaSource->mAudioBuffer
  303. .GetHostPointer();
  304. obs_source_output_audio(ajaSource->mSource,
  305. &audioPacket);
  306. }
  307. if (ajaSource->mVideoBuffer.GetByteCount() == 0) {
  308. blog(LOG_DEBUG,
  309. "AJASource::CaptureThread: 0 bytes in video buffer! Something went wrong!");
  310. continue;
  311. }
  312. card->DMAReadFrame(currentCardFrame, ajaSource->mVideoBuffer,
  313. ajaSource->mVideoBuffer.GetByteCount());
  314. auto actualVideoFormat = videoFormat;
  315. if (aja::Is3GLevelB(card, channel))
  316. actualVideoFormat = aja::GetLevelAFormatForLevelBFormat(
  317. videoFormat);
  318. const enum video_format obs_vid_fmt =
  319. aja::AJAPixelFormatToOBSVideoFormat(
  320. sourceProps.pixelFormat);
  321. NTV2FormatDesc fd(actualVideoFormat, pixelFormat);
  322. struct obs_source_frame2 obsFrame;
  323. obsFrame.flip = false;
  324. obsFrame.timestamp = os_gettime_ns();
  325. obsFrame.width = fd.GetRasterWidth();
  326. obsFrame.height = fd.GetRasterHeight();
  327. obsFrame.format = obs_vid_fmt;
  328. obsFrame.data[0] = reinterpret_cast<uint8_t *>(
  329. (ULWord *)ajaSource->mVideoBuffer.GetHostPointer());
  330. obsFrame.linesize[0] = fd.GetBytesPerRow();
  331. video_colorspace colorspace = VIDEO_CS_709;
  332. if (NTV2_IS_SD_VIDEO_FORMAT(actualVideoFormat))
  333. colorspace = VIDEO_CS_601;
  334. video_format_get_parameters_for_format(
  335. colorspace, VIDEO_RANGE_PARTIAL, obs_vid_fmt,
  336. obsFrame.color_matrix, obsFrame.color_range_min,
  337. obsFrame.color_range_max);
  338. obs_source_output_video2(ajaSource->mSource, &obsFrame);
  339. card->SetInputFrame(framestore, currentCardFrame);
  340. }
  341. blog(LOG_INFO, "AJASource::Capturethread: Thread loop stopped");
  342. ajaSource->GenerateTestPattern(sourceProps.videoFormat,
  343. sourceProps.pixelFormat,
  344. NTV2_TestPatt_Black);
  345. obs_data_release(settings);
  346. }
  347. void AJASource::Deactivate()
  348. {
  349. SetCapturing(false);
  350. if (mCaptureThread) {
  351. if (mCaptureThread->Active()) {
  352. mCaptureThread->Stop();
  353. blog(LOG_INFO, "AJASource::CaptureThread: Stopped!");
  354. }
  355. delete mCaptureThread;
  356. mCaptureThread = nullptr;
  357. blog(LOG_INFO, "AJASource::CaptureThread: Destroyed!");
  358. }
  359. }
  360. void AJASource::Activate(bool enable)
  361. {
  362. if (mCaptureThread == nullptr) {
  363. mCaptureThread = new AJAThread();
  364. mCaptureThread->Attach(AJASource::CaptureThread, this);
  365. mCaptureThread->SetPriority(AJA_ThreadPriority_High);
  366. blog(LOG_INFO, "AJASource::CaptureThread: Created!");
  367. }
  368. if (enable) {
  369. SetCapturing(true);
  370. if (!mCaptureThread->Active()) {
  371. mCaptureThread->Start();
  372. blog(LOG_INFO, "AJASource::CaptureThread: Started!");
  373. }
  374. }
  375. }
  376. bool AJASource::IsCapturing() const
  377. {
  378. return mIsCapturing;
  379. }
  380. void AJASource::SetCapturing(bool capturing)
  381. {
  382. std::lock_guard<std::mutex> lock(mMutex);
  383. mIsCapturing = capturing;
  384. }
  385. //
  386. // CardEntry/Device stuff
  387. //
  388. std::string AJASource::CardID() const
  389. {
  390. return mCardID;
  391. }
  392. void AJASource::SetCardID(const std::string &cardID)
  393. {
  394. mCardID = cardID;
  395. }
  396. uint32_t AJASource::DeviceIndex() const
  397. {
  398. return static_cast<uint32_t>(mDeviceIndex);
  399. }
  400. void AJASource::SetDeviceIndex(uint32_t index)
  401. {
  402. mDeviceIndex = static_cast<UWord>(index);
  403. }
  404. //
  405. // AJASource Properties stuff
  406. //
  407. void AJASource::SetSourceProps(const SourceProps &props)
  408. {
  409. mSourceProps = props;
  410. }
  411. SourceProps AJASource::GetSourceProps() const
  412. {
  413. return mSourceProps;
  414. }
  415. void AJASource::CacheConnections(const NTV2XptConnections &cnx)
  416. {
  417. mCrosspoints.clear();
  418. mCrosspoints = cnx;
  419. }
  420. void AJASource::ClearConnections()
  421. {
  422. for (auto &&xpt : mCrosspoints) {
  423. mCard->Connect(xpt.first, NTV2_XptBlack);
  424. }
  425. mCrosspoints.clear();
  426. }
  427. bool AJASource::ReadChannelVPIDs(NTV2Channel channel, VPIDData &vpids)
  428. {
  429. ULWord vpid_a = 0;
  430. ULWord vpid_b = 0;
  431. bool read_ok = mCard->ReadSDIInVPID(channel, vpid_a, vpid_b);
  432. vpids.SetA(vpid_a);
  433. vpids.SetB(vpid_b);
  434. vpids.Parse();
  435. return read_ok;
  436. }
  437. bool AJASource::ReadWireFormats(NTV2DeviceID device_id, IOSelection io_select,
  438. NTV2VideoFormat &vf, NTV2PixelFormat &pf,
  439. VPIDDataList &vpids)
  440. {
  441. NTV2InputSourceSet input_srcs;
  442. aja::IOSelectionToInputSources(io_select, input_srcs);
  443. if (input_srcs.empty()) {
  444. blog(LOG_INFO,
  445. "AJASource::ReadWireFormats: No NTV2InputSources found for IOSelection %s",
  446. aja::IOSelectionToString(io_select).c_str());
  447. return false;
  448. }
  449. NTV2InputSource initial_src = *input_srcs.begin();
  450. for (auto &&src : input_srcs) {
  451. auto channel = NTV2InputSourceToChannel(src);
  452. mCard->EnableChannel(channel);
  453. if (NTV2_INPUT_SOURCE_IS_SDI(src)) {
  454. if (NTV2DeviceHasBiDirectionalSDI(device_id)) {
  455. mCard->SetSDITransmitEnable(channel, false);
  456. }
  457. mCard->WaitForInputVerticalInterrupt(channel);
  458. VPIDData vpid_data;
  459. if (ReadChannelVPIDs(channel, vpid_data))
  460. vpids.push_back(vpid_data);
  461. } else if (NTV2_INPUT_SOURCE_IS_HDMI(src)) {
  462. mCard->WaitForInputVerticalInterrupt(channel);
  463. ULWord hdmi_version =
  464. NTV2DeviceGetHDMIVersion(device_id);
  465. // HDMIv1 handles its own RGB->YCbCr color space conversion
  466. if (hdmi_version == 1) {
  467. pf = kDefaultAJAPixelFormat;
  468. } else {
  469. NTV2LHIHDMIColorSpace hdmiInputColor;
  470. mCard->GetHDMIInputColor(hdmiInputColor,
  471. channel);
  472. if (hdmiInputColor ==
  473. NTV2_LHIHDMIColorSpaceYCbCr) {
  474. pf = kDefaultAJAPixelFormat;
  475. } else if (hdmiInputColor ==
  476. NTV2_LHIHDMIColorSpaceRGB) {
  477. pf = NTV2_FBF_24BIT_BGR;
  478. }
  479. }
  480. }
  481. }
  482. NTV2Channel initial_channel = NTV2InputSourceToChannel(initial_src);
  483. mCard->WaitForInputVerticalInterrupt(initial_channel);
  484. vf = mCard->GetInputVideoFormat(
  485. initial_src, aja::Is3GLevelB(mCard, initial_channel));
  486. if (NTV2_INPUT_SOURCE_IS_SDI(initial_src)) {
  487. if (vpids.size() > 0) {
  488. auto vpid = *vpids.begin();
  489. if (vpid.Sampling() == VPIDSampling_YUV_422) {
  490. pf = NTV2_FBF_8BIT_YCBCR;
  491. blog(LOG_INFO,
  492. "AJASource::ReadWireFormats - Detected pixel format %s",
  493. NTV2FrameBufferFormatToString(pf, true)
  494. .c_str());
  495. } else if (vpid.Sampling() == VPIDSampling_GBR_444) {
  496. pf = NTV2_FBF_24BIT_BGR;
  497. blog(LOG_INFO,
  498. "AJASource::ReadWireFormats - Detected pixel format %s",
  499. NTV2FrameBufferFormatToString(pf, true)
  500. .c_str());
  501. }
  502. }
  503. }
  504. vf = aja::HandleSpecialCaseFormats(io_select, vf, device_id);
  505. blog(LOG_INFO, "AJASource::ReadWireFormats - Detected video format %s",
  506. NTV2VideoFormatToString(vf).c_str());
  507. return true;
  508. }
  509. void AJASource::ResetVideoBuffer(NTV2VideoFormat vf, NTV2PixelFormat pf)
  510. {
  511. if (vf != NTV2_FORMAT_UNKNOWN) {
  512. auto videoBufferSize = GetVideoWriteSize(vf, pf);
  513. if (mVideoBuffer)
  514. mVideoBuffer.Deallocate();
  515. mVideoBuffer.Allocate(videoBufferSize, true);
  516. blog(LOG_INFO,
  517. "AJASource::ResetVideoBuffer: Video Format: %s | Pixel Format: %s | Buffer Size: %d",
  518. NTV2VideoFormatToString(vf, false).c_str(),
  519. NTV2FrameBufferFormatToString(pf, true).c_str(),
  520. videoBufferSize);
  521. }
  522. }
  523. void AJASource::ResetAudioBuffer(size_t size)
  524. {
  525. if (mAudioBuffer)
  526. mAudioBuffer.Deallocate();
  527. mAudioBuffer.Allocate(size, true);
  528. }
  529. static const char *aja_source_get_name(void *);
  530. static void *aja_source_create(obs_data_t *, obs_source_t *);
  531. static void aja_source_destroy(void *);
  532. static void aja_source_activate(void *);
  533. static void aja_source_deactivate(void *);
  534. static void aja_source_update(void *, obs_data_t *);
  535. const char *aja_source_get_name(void *unused)
  536. {
  537. UNUSED_PARAMETER(unused);
  538. return obs_module_text(kUIPropCaptureModule.text);
  539. }
  540. bool aja_source_device_changed(void *data, obs_properties_t *props,
  541. obs_property_t *list, obs_data_t *settings)
  542. {
  543. UNUSED_PARAMETER(list);
  544. blog(LOG_DEBUG, "AJA Source Device Changed");
  545. auto *ajaSource = (AJASource *)data;
  546. if (!ajaSource) {
  547. blog(LOG_DEBUG,
  548. "aja_source_device_changed: AJA Source instance is null!");
  549. return false;
  550. }
  551. const char *cardID = obs_data_get_string(settings, kUIPropDevice.id);
  552. if (!cardID || !cardID[0])
  553. return false;
  554. auto &cardManager = aja::CardManager::Instance();
  555. auto cardEntry = cardManager.GetCardEntry(cardID);
  556. if (!cardEntry) {
  557. blog(LOG_DEBUG,
  558. "aja_source_device_changed: Card Entry not found for %s",
  559. cardID);
  560. return false;
  561. }
  562. blog(LOG_DEBUG, "Found CardEntry for %s", cardID);
  563. CNTV2Card *card = cardEntry->GetCard();
  564. if (!card) {
  565. blog(LOG_DEBUG,
  566. "aja_source_device_changed: Card instance is null!");
  567. return false;
  568. }
  569. const NTV2DeviceID deviceID = card->GetDeviceID();
  570. /* If Channel 1 is actively in use, filter the video format list to only
  571. * show video formats within the same framerate family. If Channel 1 is
  572. * not active we just go ahead and try to set all framestores to the same video format.
  573. * This is because Channel 1's clock rate will govern the card's Free Run clock.
  574. */
  575. NTV2VideoFormat videoFormatChannel1 = NTV2_FORMAT_UNKNOWN;
  576. if (!cardEntry->ChannelReady(NTV2_CHANNEL1, ajaSource->GetName())) {
  577. card->GetVideoFormat(videoFormatChannel1, NTV2_CHANNEL1);
  578. }
  579. obs_property_t *devices_list =
  580. obs_properties_get(props, kUIPropDevice.id);
  581. obs_property_t *io_select_list =
  582. obs_properties_get(props, kUIPropInput.id);
  583. obs_property_t *vid_fmt_list =
  584. obs_properties_get(props, kUIPropVideoFormatSelect.id);
  585. obs_property_t *pix_fmt_list =
  586. obs_properties_get(props, kUIPropPixelFormatSelect.id);
  587. obs_property_t *sdi_trx_list =
  588. obs_properties_get(props, kUIPropSDITransport.id);
  589. obs_property_t *sdi_4k_list =
  590. obs_properties_get(props, kUIPropSDITransport4K.id);
  591. obs_property_list_clear(vid_fmt_list);
  592. obs_property_list_add_int(vid_fmt_list, obs_module_text("Auto"),
  593. kAutoDetect);
  594. populate_video_format_list(deviceID, vid_fmt_list, videoFormatChannel1,
  595. true);
  596. obs_property_list_clear(pix_fmt_list);
  597. obs_property_list_add_int(pix_fmt_list, obs_module_text("Auto"),
  598. kAutoDetect);
  599. populate_pixel_format_list(deviceID, pix_fmt_list);
  600. IOSelection io_select = static_cast<IOSelection>(
  601. obs_data_get_int(settings, kUIPropInput.id));
  602. obs_property_list_clear(sdi_trx_list);
  603. populate_sdi_transport_list(sdi_trx_list, deviceID, true);
  604. obs_property_list_clear(sdi_4k_list);
  605. populate_sdi_4k_transport_list(sdi_4k_list);
  606. populate_io_selection_input_list(cardID, ajaSource->GetName(), deviceID,
  607. io_select_list);
  608. auto curr_vf = static_cast<NTV2VideoFormat>(
  609. obs_data_get_int(settings, kUIPropVideoFormatSelect.id));
  610. bool have_cards = cardManager.NumCardEntries() > 0;
  611. obs_property_set_visible(devices_list, have_cards);
  612. obs_property_set_visible(io_select_list, have_cards);
  613. obs_property_set_visible(vid_fmt_list, have_cards);
  614. obs_property_set_visible(pix_fmt_list, have_cards);
  615. obs_property_set_visible(
  616. sdi_trx_list, have_cards && aja::IsIOSelectionSDI(io_select));
  617. obs_property_set_visible(
  618. sdi_4k_list, have_cards && NTV2_IS_4K_VIDEO_FORMAT(curr_vf));
  619. return true;
  620. }
  621. bool aja_io_selection_changed(void *data, obs_properties_t *props,
  622. obs_property_t *list, obs_data_t *settings)
  623. {
  624. UNUSED_PARAMETER(list);
  625. AJASource *ajaSource = (AJASource *)data;
  626. if (!ajaSource) {
  627. blog(LOG_DEBUG,
  628. "aja_io_selection_changed: AJA Source instance is null!");
  629. return false;
  630. }
  631. const char *cardID = obs_data_get_string(settings, kUIPropDevice.id);
  632. if (!cardID || !cardID[0])
  633. return false;
  634. auto &cardManager = aja::CardManager::Instance();
  635. auto cardEntry = cardManager.GetCardEntry(cardID);
  636. if (!cardEntry) {
  637. blog(LOG_DEBUG,
  638. "aja_io_selection_changed: Card Entry not found for %s",
  639. cardID);
  640. return false;
  641. }
  642. filter_io_selection_input_list(cardID, ajaSource->GetName(),
  643. obs_properties_get(props,
  644. kUIPropInput.id));
  645. obs_property_set_visible(
  646. obs_properties_get(props, kUIPropSDITransport.id),
  647. aja::IsIOSelectionSDI(static_cast<IOSelection>(
  648. obs_data_get_int(settings, kUIPropInput.id))));
  649. return true;
  650. }
  651. bool aja_sdi_mode_list_changed(obs_properties_t *props, obs_property_t *list,
  652. obs_data_t *settings)
  653. {
  654. UNUSED_PARAMETER(props);
  655. UNUSED_PARAMETER(list);
  656. UNUSED_PARAMETER(settings);
  657. return true;
  658. }
  659. void *aja_source_create(obs_data_t *settings, obs_source_t *source)
  660. {
  661. blog(LOG_DEBUG, "AJA Source Create");
  662. auto ajaSource = new AJASource(source);
  663. ajaSource->SetName(obs_source_get_name(source));
  664. obs_source_set_async_decoupled(source, true);
  665. ajaSource->SetOBSSource(source);
  666. ajaSource->ResetAudioBuffer(NTV2_AUDIOSIZE_MAX);
  667. ajaSource->Activate(false);
  668. obs_source_update(source, settings);
  669. return ajaSource;
  670. }
  671. void aja_source_destroy(void *data)
  672. {
  673. blog(LOG_DEBUG, "AJA Source Destroy");
  674. auto ajaSource = (AJASource *)data;
  675. if (!ajaSource) {
  676. blog(LOG_ERROR, "aja_source_destroy: Plugin instance is null!");
  677. return;
  678. }
  679. ajaSource->Deactivate();
  680. NTV2DeviceID deviceID = DEVICE_ID_NOTFOUND;
  681. CNTV2Card *card = ajaSource->GetCard();
  682. if (card) {
  683. deviceID = card->GetDeviceID();
  684. aja::Routing::StopSourceAudio(ajaSource->GetSourceProps(),
  685. card);
  686. }
  687. ajaSource->mVideoBuffer.Deallocate();
  688. ajaSource->mAudioBuffer.Deallocate();
  689. ajaSource->mVideoBuffer = 0;
  690. ajaSource->mAudioBuffer = 0;
  691. auto &cardManager = aja::CardManager::Instance();
  692. const auto &cardID = ajaSource->CardID();
  693. auto cardEntry = cardManager.GetCardEntry(cardID);
  694. if (!cardEntry) {
  695. blog(LOG_DEBUG,
  696. "aja_source_destroy: Card Entry not found for %s",
  697. cardID.c_str());
  698. return;
  699. }
  700. auto ioSelect = ajaSource->GetSourceProps().ioSelect;
  701. if (!cardEntry->ReleaseInputSelection(ioSelect, deviceID,
  702. ajaSource->GetName())) {
  703. blog(LOG_WARNING,
  704. "aja_source_destroy: Error releasing Input Selection!");
  705. }
  706. delete ajaSource;
  707. ajaSource = nullptr;
  708. }
  709. static void aja_source_show(void *data)
  710. {
  711. auto ajaSource = (AJASource *)data;
  712. if (!ajaSource) {
  713. blog(LOG_ERROR,
  714. "aja_source_show: AJA Source instance is null!");
  715. return;
  716. }
  717. bool deactivateWhileNotShowing =
  718. ajaSource->GetSourceProps().deactivateWhileNotShowing;
  719. bool showing = obs_source_showing(ajaSource->GetOBSSource());
  720. blog(LOG_DEBUG,
  721. "aja_source_show: deactivateWhileNotShowing = %s, showing = %s",
  722. deactivateWhileNotShowing ? "true" : "false",
  723. showing ? "true" : "false");
  724. if (deactivateWhileNotShowing && showing && !ajaSource->IsCapturing()) {
  725. ajaSource->Activate(true);
  726. blog(LOG_DEBUG, "aja_source_show: activated capture thread!");
  727. }
  728. }
  729. static void aja_source_hide(void *data)
  730. {
  731. auto ajaSource = (AJASource *)data;
  732. if (!ajaSource)
  733. return;
  734. bool deactivateWhileNotShowing =
  735. ajaSource->GetSourceProps().deactivateWhileNotShowing;
  736. bool showing = obs_source_showing(ajaSource->GetOBSSource());
  737. blog(LOG_DEBUG,
  738. "aja_source_hide: deactivateWhileNotShowing = %s, showing = %s",
  739. deactivateWhileNotShowing ? "true" : "false",
  740. showing ? "true" : "false");
  741. if (deactivateWhileNotShowing && !showing && ajaSource->IsCapturing()) {
  742. ajaSource->Deactivate();
  743. blog(LOG_DEBUG, "aja_source_hide: deactivated capture thread!");
  744. }
  745. }
  746. static void aja_source_activate(void *data)
  747. {
  748. UNUSED_PARAMETER(data);
  749. }
  750. static void aja_source_deactivate(void *data)
  751. {
  752. UNUSED_PARAMETER(data);
  753. }
  754. static void aja_source_update(void *data, obs_data_t *settings)
  755. {
  756. static bool initialized = false;
  757. auto ajaSource = (AJASource *)data;
  758. if (!ajaSource) {
  759. blog(LOG_WARNING,
  760. "aja_source_update: Plugin instance is null!");
  761. return;
  762. }
  763. auto io_select = static_cast<IOSelection>(
  764. obs_data_get_int(settings, kUIPropInput.id));
  765. auto vf_select = static_cast<NTV2VideoFormat>(
  766. obs_data_get_int(settings, kUIPropVideoFormatSelect.id));
  767. auto pf_select = static_cast<NTV2PixelFormat>(
  768. obs_data_get_int(settings, kUIPropPixelFormatSelect.id));
  769. auto sdi_trx_select = static_cast<SDITransport>(
  770. obs_data_get_int(settings, kUIPropSDITransport.id));
  771. auto sdi_t4k_select = static_cast<SDITransport4K>(
  772. obs_data_get_int(settings, kUIPropSDITransport4K.id));
  773. bool deactivateWhileNotShowing =
  774. obs_data_get_bool(settings, kUIPropDeactivateWhenNotShowing.id);
  775. const std::string &wantCardID =
  776. obs_data_get_string(settings, kUIPropDevice.id);
  777. obs_source_set_async_unbuffered(
  778. ajaSource->GetOBSSource(),
  779. !obs_data_get_bool(settings, kUIPropBuffering.id));
  780. const std::string &currentCardID = ajaSource->CardID();
  781. if (wantCardID != currentCardID) {
  782. initialized = false;
  783. ajaSource->Deactivate();
  784. }
  785. auto &cardManager = aja::CardManager::Instance();
  786. cardManager.EnumerateCards();
  787. auto cardEntry = cardManager.GetCardEntry(wantCardID);
  788. if (!cardEntry) {
  789. blog(LOG_DEBUG,
  790. "aja_source_update: Card Entry not found for %s",
  791. wantCardID.c_str());
  792. return;
  793. }
  794. CNTV2Card *card = cardEntry->GetCard();
  795. if (!card || !card->IsOpen()) {
  796. blog(LOG_ERROR, "aja_source_update: AJA device %s not open!",
  797. wantCardID.c_str());
  798. return;
  799. }
  800. if (card->GetModelName() == "(Not Found)") {
  801. blog(LOG_ERROR,
  802. "aja_source_update: AJA device %s disconnected?",
  803. wantCardID.c_str());
  804. return;
  805. }
  806. ajaSource->SetCard(cardEntry->GetCard());
  807. SourceProps curr_props = ajaSource->GetSourceProps();
  808. // Release Channels from previous card if card ID changes
  809. if (wantCardID != currentCardID) {
  810. auto prevCardEntry = cardManager.GetCardEntry(currentCardID);
  811. if (prevCardEntry) {
  812. const std::string &ioSelectStr =
  813. aja::IOSelectionToString(curr_props.ioSelect);
  814. if (!prevCardEntry->ReleaseInputSelection(
  815. curr_props.ioSelect, curr_props.deviceID,
  816. ajaSource->GetName())) {
  817. blog(LOG_WARNING,
  818. "aja_source_update: Error releasing IOSelection %s for card ID %s",
  819. ioSelectStr.c_str(),
  820. currentCardID.c_str());
  821. } else {
  822. blog(LOG_INFO,
  823. "aja_source_update: Released IOSelection %s for card ID %s",
  824. ioSelectStr.c_str(),
  825. currentCardID.c_str());
  826. ajaSource->SetCardID(wantCardID);
  827. io_select = IOSelection::Invalid;
  828. }
  829. }
  830. }
  831. if (io_select == IOSelection::Invalid) {
  832. blog(LOG_DEBUG, "aja_source_update: Invalid IOSelection");
  833. return;
  834. }
  835. SourceProps want_props;
  836. want_props.deviceID = card->GetDeviceID();
  837. want_props.ioSelect = io_select;
  838. want_props.videoFormat =
  839. ((int32_t)vf_select == kAutoDetect)
  840. ? NTV2_FORMAT_UNKNOWN
  841. : static_cast<NTV2VideoFormat>(vf_select);
  842. want_props.pixelFormat =
  843. ((int32_t)pf_select == kAutoDetect)
  844. ? NTV2_FBF_INVALID
  845. : static_cast<NTV2PixelFormat>(pf_select);
  846. want_props.sdiTransport =
  847. ((int32_t)sdi_trx_select == kAutoDetect)
  848. ? SDITransport::Unknown
  849. : static_cast<SDITransport>(sdi_trx_select);
  850. want_props.sdi4kTransport = sdi_t4k_select;
  851. want_props.vpids.clear();
  852. want_props.deactivateWhileNotShowing = deactivateWhileNotShowing;
  853. if (aja::IsIOSelectionSDI(io_select)) {
  854. want_props.autoDetect = (int)sdi_trx_select == kAutoDetect;
  855. } else {
  856. want_props.autoDetect = ((int)vf_select == kAutoDetect ||
  857. (int)pf_select == kAutoDetect);
  858. }
  859. ajaSource->SetCardID(wantCardID);
  860. ajaSource->SetDeviceIndex((UWord)cardEntry->GetCardIndex());
  861. // Release Channels if IOSelection changes
  862. if (want_props.ioSelect != curr_props.ioSelect) {
  863. const std::string &ioSelectStr =
  864. aja::IOSelectionToString(curr_props.ioSelect);
  865. if (!cardEntry->ReleaseInputSelection(curr_props.ioSelect,
  866. curr_props.deviceID,
  867. ajaSource->GetName())) {
  868. blog(LOG_WARNING,
  869. "aja_source_update: Error releasing IOSelection %s for card ID %s",
  870. ioSelectStr.c_str(), currentCardID.c_str());
  871. } else {
  872. blog(LOG_INFO,
  873. "aja_source_update: Released IOSelection %s for card ID %s",
  874. ioSelectStr.c_str(), currentCardID.c_str());
  875. }
  876. }
  877. // Acquire Channels for current IOSelection
  878. if (!cardEntry->AcquireInputSelection(want_props.ioSelect,
  879. want_props.deviceID,
  880. ajaSource->GetName())) {
  881. blog(LOG_ERROR,
  882. "aja_source_update: Could not acquire IOSelection %s",
  883. aja::IOSelectionToString(want_props.ioSelect).c_str());
  884. return;
  885. }
  886. // Read SDI video payload IDs (VPID) used for helping to determine the wire format
  887. NTV2VideoFormat new_vf = want_props.videoFormat;
  888. NTV2PixelFormat new_pf = want_props.pixelFormat;
  889. if (!ajaSource->ReadWireFormats(want_props.deviceID,
  890. want_props.ioSelect, new_vf, new_pf,
  891. want_props.vpids)) {
  892. blog(LOG_ERROR, "aja_source_update: ReadWireFormats failed!");
  893. cardEntry->ReleaseInputSelection(want_props.ioSelect,
  894. curr_props.deviceID,
  895. ajaSource->GetName());
  896. return;
  897. }
  898. // Set auto-detected formats
  899. if ((int32_t)vf_select == kAutoDetect)
  900. want_props.videoFormat = new_vf;
  901. if ((int32_t)pf_select == kAutoDetect)
  902. want_props.pixelFormat = new_pf;
  903. if (want_props.videoFormat == NTV2_FORMAT_UNKNOWN ||
  904. want_props.pixelFormat == NTV2_FBF_INVALID) {
  905. blog(LOG_ERROR,
  906. "aja_source_update: Unknown video/pixel format(s): %s / %s",
  907. NTV2VideoFormatToString(want_props.videoFormat).c_str(),
  908. NTV2FrameBufferFormatToString(want_props.pixelFormat)
  909. .c_str());
  910. cardEntry->ReleaseInputSelection(want_props.ioSelect,
  911. curr_props.deviceID,
  912. ajaSource->GetName());
  913. return;
  914. }
  915. // Change capture format and restart capture thread
  916. if (!initialized || want_props != ajaSource->GetSourceProps()) {
  917. ajaSource->ClearConnections();
  918. NTV2XptConnections xpt_cnx;
  919. aja::Routing::ConfigureSourceRoute(
  920. want_props, NTV2_MODE_CAPTURE, card, xpt_cnx);
  921. ajaSource->CacheConnections(xpt_cnx);
  922. ajaSource->Deactivate();
  923. initialized = true;
  924. }
  925. ajaSource->SetSourceProps(want_props);
  926. aja::Routing::StartSourceAudio(want_props, card);
  927. card->SetReference(NTV2_REFERENCE_FREERUN);
  928. ajaSource->Activate(true);
  929. }
  930. static obs_properties_t *aja_source_get_properties(void *data)
  931. {
  932. obs_properties_t *props = obs_properties_create();
  933. obs_property_t *device_list = obs_properties_add_list(
  934. props, kUIPropDevice.id, obs_module_text(kUIPropDevice.text),
  935. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
  936. populate_source_device_list(device_list);
  937. obs_property_t *io_select_list = obs_properties_add_list(
  938. props, kUIPropInput.id, obs_module_text(kUIPropInput.text),
  939. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  940. obs_property_t *vid_fmt_list = obs_properties_add_list(
  941. props, kUIPropVideoFormatSelect.id,
  942. obs_module_text(kUIPropVideoFormatSelect.text),
  943. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  944. obs_properties_add_list(props, kUIPropPixelFormatSelect.id,
  945. obs_module_text(kUIPropPixelFormatSelect.text),
  946. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  947. obs_properties_add_list(props, kUIPropSDITransport.id,
  948. obs_module_text(kUIPropSDITransport.text),
  949. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  950. obs_properties_add_list(props, kUIPropSDITransport4K.id,
  951. obs_module_text(kUIPropSDITransport4K.text),
  952. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  953. obs_properties_add_bool(
  954. props, kUIPropDeactivateWhenNotShowing.id,
  955. obs_module_text(kUIPropDeactivateWhenNotShowing.text));
  956. obs_properties_add_bool(props, kUIPropBuffering.id,
  957. obs_module_text(kUIPropBuffering.text));
  958. obs_property_set_modified_callback(vid_fmt_list,
  959. aja_video_format_changed);
  960. obs_property_set_modified_callback2(device_list,
  961. aja_source_device_changed, data);
  962. obs_property_set_modified_callback2(io_select_list,
  963. aja_io_selection_changed, data);
  964. return props;
  965. }
  966. void aja_source_get_defaults(obs_data_t *settings)
  967. {
  968. obs_data_set_default_int(settings, kUIPropInput.id,
  969. static_cast<long long>(IOSelection::Invalid));
  970. obs_data_set_default_int(settings, kUIPropVideoFormatSelect.id,
  971. static_cast<long long>(kAutoDetect));
  972. obs_data_set_default_int(settings, kUIPropPixelFormatSelect.id,
  973. static_cast<long long>(kAutoDetect));
  974. obs_data_set_default_int(settings, kUIPropSDITransport.id,
  975. static_cast<long long>(kAutoDetect));
  976. obs_data_set_default_int(
  977. settings, kUIPropSDITransport4K.id,
  978. static_cast<long long>(SDITransport4K::TwoSampleInterleave));
  979. obs_data_set_default_bool(settings, kUIPropDeactivateWhenNotShowing.id,
  980. false);
  981. }
  982. static void aja_source_get_defaults_v1(obs_data_t *settings)
  983. {
  984. aja_source_get_defaults(settings);
  985. obs_data_set_default_bool(settings, kUIPropBuffering.id, true);
  986. }
  987. void aja_source_save(void *data, obs_data_t *settings)
  988. {
  989. AJASource *ajaSource = (AJASource *)data;
  990. if (!ajaSource) {
  991. blog(LOG_ERROR,
  992. "aja_source_save: AJA Source instance is null!");
  993. return;
  994. }
  995. const char *cardID = obs_data_get_string(settings, kUIPropDevice.id);
  996. if (!cardID || !cardID[0])
  997. return;
  998. auto &cardManager = aja::CardManager::Instance();
  999. auto cardEntry = cardManager.GetCardEntry(cardID);
  1000. if (!cardEntry) {
  1001. blog(LOG_DEBUG, "aja_source_save: Card Entry not found for %s",
  1002. cardID);
  1003. return;
  1004. }
  1005. auto oldName = ajaSource->GetName();
  1006. auto newName = obs_source_get_name(ajaSource->GetOBSSource());
  1007. if (oldName != newName &&
  1008. cardEntry->UpdateChannelOwnerName(oldName, newName)) {
  1009. ajaSource->SetName(newName);
  1010. blog(LOG_DEBUG, "aja_source_save: Renamed \"%s\" to \"%s\"",
  1011. oldName.c_str(), newName);
  1012. }
  1013. }
  1014. void register_aja_source_info()
  1015. {
  1016. struct obs_source_info aja_source_info = {};
  1017. aja_source_info.id = kUIPropCaptureModule.id;
  1018. aja_source_info.type = OBS_SOURCE_TYPE_INPUT;
  1019. aja_source_info.output_flags =
  1020. OBS_SOURCE_ASYNC_VIDEO | OBS_SOURCE_AUDIO |
  1021. OBS_SOURCE_DO_NOT_DUPLICATE | OBS_SOURCE_CAP_OBSOLETE;
  1022. aja_source_info.get_name = aja_source_get_name;
  1023. aja_source_info.create = aja_source_create;
  1024. aja_source_info.destroy = aja_source_destroy;
  1025. aja_source_info.update = aja_source_update;
  1026. aja_source_info.show = aja_source_show;
  1027. aja_source_info.hide = aja_source_hide;
  1028. aja_source_info.activate = aja_source_activate;
  1029. aja_source_info.deactivate = aja_source_deactivate;
  1030. aja_source_info.get_properties = aja_source_get_properties;
  1031. aja_source_info.get_defaults = aja_source_get_defaults_v1;
  1032. aja_source_info.save = aja_source_save;
  1033. aja_source_info.icon_type = OBS_ICON_TYPE_CAMERA;
  1034. obs_register_source(&aja_source_info);
  1035. aja_source_info.version = 2;
  1036. aja_source_info.output_flags &= ~OBS_SOURCE_CAP_OBSOLETE;
  1037. aja_source_info.get_defaults = aja_source_get_defaults;
  1038. obs_register_source(&aja_source_info);
  1039. }