aja-source.cpp 35 KB

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