🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

633 lines
18 KiB

  1. /**
  2. * OpenAL cross platform audio library
  3. * Copyright (C) 1999-2007 by authors.
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. * Or go to http://www.gnu.org/copyleft/lgpl.html
  19. */
  20. #include "config.h"
  21. #include "winmm.h"
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <memory.h>
  25. #include <windows.h>
  26. #include <mmsystem.h>
  27. #include <mmreg.h>
  28. #include <array>
  29. #include <atomic>
  30. #include <thread>
  31. #include <vector>
  32. #include <string>
  33. #include <algorithm>
  34. #include <functional>
  35. #include "alnumeric.h"
  36. #include "core/device.h"
  37. #include "core/helpers.h"
  38. #include "core/logging.h"
  39. #include "ringbuffer.h"
  40. #include "strutils.h"
  41. #include "threads.h"
  42. #ifndef WAVE_FORMAT_IEEE_FLOAT
  43. #define WAVE_FORMAT_IEEE_FLOAT 0x0003
  44. #endif
  45. namespace {
  46. #define DEVNAME_HEAD "OpenAL Soft on "
  47. al::vector<std::string> PlaybackDevices;
  48. al::vector<std::string> CaptureDevices;
  49. bool checkName(const al::vector<std::string> &list, const std::string &name)
  50. { return std::find(list.cbegin(), list.cend(), name) != list.cend(); }
  51. void ProbePlaybackDevices(void)
  52. {
  53. PlaybackDevices.clear();
  54. UINT numdevs{waveOutGetNumDevs()};
  55. PlaybackDevices.reserve(numdevs);
  56. for(UINT i{0};i < numdevs;++i)
  57. {
  58. std::string dname;
  59. WAVEOUTCAPSW WaveCaps{};
  60. if(waveOutGetDevCapsW(i, &WaveCaps, sizeof(WaveCaps)) == MMSYSERR_NOERROR)
  61. {
  62. const std::string basename{DEVNAME_HEAD + wstr_to_utf8(WaveCaps.szPname)};
  63. int count{1};
  64. std::string newname{basename};
  65. while(checkName(PlaybackDevices, newname))
  66. {
  67. newname = basename;
  68. newname += " #";
  69. newname += std::to_string(++count);
  70. }
  71. dname = std::move(newname);
  72. TRACE("Got device \"%s\", ID %u\n", dname.c_str(), i);
  73. }
  74. PlaybackDevices.emplace_back(std::move(dname));
  75. }
  76. }
  77. void ProbeCaptureDevices(void)
  78. {
  79. CaptureDevices.clear();
  80. UINT numdevs{waveInGetNumDevs()};
  81. CaptureDevices.reserve(numdevs);
  82. for(UINT i{0};i < numdevs;++i)
  83. {
  84. std::string dname;
  85. WAVEINCAPSW WaveCaps{};
  86. if(waveInGetDevCapsW(i, &WaveCaps, sizeof(WaveCaps)) == MMSYSERR_NOERROR)
  87. {
  88. const std::string basename{DEVNAME_HEAD + wstr_to_utf8(WaveCaps.szPname)};
  89. int count{1};
  90. std::string newname{basename};
  91. while(checkName(CaptureDevices, newname))
  92. {
  93. newname = basename;
  94. newname += " #";
  95. newname += std::to_string(++count);
  96. }
  97. dname = std::move(newname);
  98. TRACE("Got device \"%s\", ID %u\n", dname.c_str(), i);
  99. }
  100. CaptureDevices.emplace_back(std::move(dname));
  101. }
  102. }
  103. struct WinMMPlayback final : public BackendBase {
  104. WinMMPlayback(DeviceBase *device) noexcept : BackendBase{device} { }
  105. ~WinMMPlayback() override;
  106. void CALLBACK waveOutProc(HWAVEOUT device, UINT msg, DWORD_PTR param1, DWORD_PTR param2) noexcept;
  107. static void CALLBACK waveOutProcC(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2) noexcept
  108. { reinterpret_cast<WinMMPlayback*>(instance)->waveOutProc(device, msg, param1, param2); }
  109. int mixerProc();
  110. void open(const char *name) override;
  111. bool reset() override;
  112. void start() override;
  113. void stop() override;
  114. std::atomic<uint> mWritable{0u};
  115. al::semaphore mSem;
  116. uint mIdx{0u};
  117. std::array<WAVEHDR,4> mWaveBuffer{};
  118. HWAVEOUT mOutHdl{nullptr};
  119. WAVEFORMATEX mFormat{};
  120. std::atomic<bool> mKillNow{true};
  121. std::thread mThread;
  122. DEF_NEWDEL(WinMMPlayback)
  123. };
  124. WinMMPlayback::~WinMMPlayback()
  125. {
  126. if(mOutHdl)
  127. waveOutClose(mOutHdl);
  128. mOutHdl = nullptr;
  129. al_free(mWaveBuffer[0].lpData);
  130. std::fill(mWaveBuffer.begin(), mWaveBuffer.end(), WAVEHDR{});
  131. }
  132. /* WinMMPlayback::waveOutProc
  133. *
  134. * Posts a message to 'WinMMPlayback::mixerProc' everytime a WaveOut Buffer is
  135. * completed and returns to the application (for more data)
  136. */
  137. void CALLBACK WinMMPlayback::waveOutProc(HWAVEOUT, UINT msg, DWORD_PTR, DWORD_PTR) noexcept
  138. {
  139. if(msg != WOM_DONE) return;
  140. mWritable.fetch_add(1, std::memory_order_acq_rel);
  141. mSem.post();
  142. }
  143. FORCE_ALIGN int WinMMPlayback::mixerProc()
  144. {
  145. SetRTPriority();
  146. althrd_setname(MIXER_THREAD_NAME);
  147. while(!mKillNow.load(std::memory_order_acquire)
  148. && mDevice->Connected.load(std::memory_order_acquire))
  149. {
  150. uint todo{mWritable.load(std::memory_order_acquire)};
  151. if(todo < 1)
  152. {
  153. mSem.wait();
  154. continue;
  155. }
  156. size_t widx{mIdx};
  157. do {
  158. WAVEHDR &waveHdr = mWaveBuffer[widx];
  159. if(++widx == mWaveBuffer.size()) widx = 0;
  160. mDevice->renderSamples(waveHdr.lpData, mDevice->UpdateSize, mFormat.nChannels);
  161. mWritable.fetch_sub(1, std::memory_order_acq_rel);
  162. waveOutWrite(mOutHdl, &waveHdr, sizeof(WAVEHDR));
  163. } while(--todo);
  164. mIdx = static_cast<uint>(widx);
  165. }
  166. return 0;
  167. }
  168. void WinMMPlayback::open(const char *name)
  169. {
  170. if(PlaybackDevices.empty())
  171. ProbePlaybackDevices();
  172. // Find the Device ID matching the deviceName if valid
  173. auto iter = name ?
  174. std::find(PlaybackDevices.cbegin(), PlaybackDevices.cend(), name) :
  175. PlaybackDevices.cbegin();
  176. if(iter == PlaybackDevices.cend())
  177. throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found",
  178. name};
  179. auto DeviceID = static_cast<UINT>(std::distance(PlaybackDevices.cbegin(), iter));
  180. DevFmtType fmttype{mDevice->FmtType};
  181. retry_open:
  182. WAVEFORMATEX format{};
  183. if(fmttype == DevFmtFloat)
  184. {
  185. format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
  186. format.wBitsPerSample = 32;
  187. }
  188. else
  189. {
  190. format.wFormatTag = WAVE_FORMAT_PCM;
  191. if(fmttype == DevFmtUByte || fmttype == DevFmtByte)
  192. format.wBitsPerSample = 8;
  193. else
  194. format.wBitsPerSample = 16;
  195. }
  196. format.nChannels = ((mDevice->FmtChans == DevFmtMono) ? 1 : 2);
  197. format.nBlockAlign = static_cast<WORD>(format.wBitsPerSample * format.nChannels / 8);
  198. format.nSamplesPerSec = mDevice->Frequency;
  199. format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
  200. format.cbSize = 0;
  201. HWAVEOUT outHandle{};
  202. MMRESULT res{waveOutOpen(&outHandle, DeviceID, &format,
  203. reinterpret_cast<DWORD_PTR>(&WinMMPlayback::waveOutProcC),
  204. reinterpret_cast<DWORD_PTR>(this), CALLBACK_FUNCTION)};
  205. if(res != MMSYSERR_NOERROR)
  206. {
  207. if(fmttype == DevFmtFloat)
  208. {
  209. fmttype = DevFmtShort;
  210. goto retry_open;
  211. }
  212. throw al::backend_exception{al::backend_error::DeviceError, "waveOutOpen failed: %u", res};
  213. }
  214. if(mOutHdl)
  215. waveOutClose(mOutHdl);
  216. mOutHdl = outHandle;
  217. mFormat = format;
  218. mDevice->DeviceName = PlaybackDevices[DeviceID];
  219. }
  220. bool WinMMPlayback::reset()
  221. {
  222. mDevice->BufferSize = static_cast<uint>(uint64_t{mDevice->BufferSize} *
  223. mFormat.nSamplesPerSec / mDevice->Frequency);
  224. mDevice->BufferSize = (mDevice->BufferSize+3) & ~0x3u;
  225. mDevice->UpdateSize = mDevice->BufferSize / 4;
  226. mDevice->Frequency = mFormat.nSamplesPerSec;
  227. if(mFormat.wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
  228. {
  229. if(mFormat.wBitsPerSample == 32)
  230. mDevice->FmtType = DevFmtFloat;
  231. else
  232. {
  233. ERR("Unhandled IEEE float sample depth: %d\n", mFormat.wBitsPerSample);
  234. return false;
  235. }
  236. }
  237. else if(mFormat.wFormatTag == WAVE_FORMAT_PCM)
  238. {
  239. if(mFormat.wBitsPerSample == 16)
  240. mDevice->FmtType = DevFmtShort;
  241. else if(mFormat.wBitsPerSample == 8)
  242. mDevice->FmtType = DevFmtUByte;
  243. else
  244. {
  245. ERR("Unhandled PCM sample depth: %d\n", mFormat.wBitsPerSample);
  246. return false;
  247. }
  248. }
  249. else
  250. {
  251. ERR("Unhandled format tag: 0x%04x\n", mFormat.wFormatTag);
  252. return false;
  253. }
  254. uint chanmask{};
  255. if(mFormat.nChannels >= 2)
  256. {
  257. mDevice->FmtChans = DevFmtStereo;
  258. chanmask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
  259. }
  260. else if(mFormat.nChannels == 1)
  261. {
  262. mDevice->FmtChans = DevFmtMono;
  263. chanmask = SPEAKER_FRONT_CENTER;
  264. }
  265. else
  266. {
  267. ERR("Unhandled channel count: %d\n", mFormat.nChannels);
  268. return false;
  269. }
  270. setChannelOrderFromWFXMask(chanmask);
  271. uint BufferSize{mDevice->UpdateSize * mFormat.nChannels * mDevice->bytesFromFmt()};
  272. al_free(mWaveBuffer[0].lpData);
  273. mWaveBuffer[0] = WAVEHDR{};
  274. mWaveBuffer[0].lpData = static_cast<char*>(al_calloc(16, BufferSize * mWaveBuffer.size()));
  275. mWaveBuffer[0].dwBufferLength = BufferSize;
  276. for(size_t i{1};i < mWaveBuffer.size();i++)
  277. {
  278. mWaveBuffer[i] = WAVEHDR{};
  279. mWaveBuffer[i].lpData = mWaveBuffer[i-1].lpData + mWaveBuffer[i-1].dwBufferLength;
  280. mWaveBuffer[i].dwBufferLength = BufferSize;
  281. }
  282. mIdx = 0;
  283. return true;
  284. }
  285. void WinMMPlayback::start()
  286. {
  287. try {
  288. for(auto &waveHdr : mWaveBuffer)
  289. waveOutPrepareHeader(mOutHdl, &waveHdr, sizeof(WAVEHDR));
  290. mWritable.store(static_cast<uint>(mWaveBuffer.size()), std::memory_order_release);
  291. mKillNow.store(false, std::memory_order_release);
  292. mThread = std::thread{std::mem_fn(&WinMMPlayback::mixerProc), this};
  293. }
  294. catch(std::exception& e) {
  295. throw al::backend_exception{al::backend_error::DeviceError,
  296. "Failed to start mixing thread: %s", e.what()};
  297. }
  298. }
  299. void WinMMPlayback::stop()
  300. {
  301. if(mKillNow.exchange(true, std::memory_order_acq_rel) || !mThread.joinable())
  302. return;
  303. mThread.join();
  304. while(mWritable.load(std::memory_order_acquire) < mWaveBuffer.size())
  305. mSem.wait();
  306. for(auto &waveHdr : mWaveBuffer)
  307. waveOutUnprepareHeader(mOutHdl, &waveHdr, sizeof(WAVEHDR));
  308. mWritable.store(0, std::memory_order_release);
  309. }
  310. struct WinMMCapture final : public BackendBase {
  311. WinMMCapture(DeviceBase *device) noexcept : BackendBase{device} { }
  312. ~WinMMCapture() override;
  313. void CALLBACK waveInProc(HWAVEIN device, UINT msg, DWORD_PTR param1, DWORD_PTR param2) noexcept;
  314. static void CALLBACK waveInProcC(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2) noexcept
  315. { reinterpret_cast<WinMMCapture*>(instance)->waveInProc(device, msg, param1, param2); }
  316. int captureProc();
  317. void open(const char *name) override;
  318. void start() override;
  319. void stop() override;
  320. void captureSamples(al::byte *buffer, uint samples) override;
  321. uint availableSamples() override;
  322. std::atomic<uint> mReadable{0u};
  323. al::semaphore mSem;
  324. uint mIdx{0};
  325. std::array<WAVEHDR,4> mWaveBuffer{};
  326. HWAVEIN mInHdl{nullptr};
  327. RingBufferPtr mRing{nullptr};
  328. WAVEFORMATEX mFormat{};
  329. std::atomic<bool> mKillNow{true};
  330. std::thread mThread;
  331. DEF_NEWDEL(WinMMCapture)
  332. };
  333. WinMMCapture::~WinMMCapture()
  334. {
  335. // Close the Wave device
  336. if(mInHdl)
  337. waveInClose(mInHdl);
  338. mInHdl = nullptr;
  339. al_free(mWaveBuffer[0].lpData);
  340. std::fill(mWaveBuffer.begin(), mWaveBuffer.end(), WAVEHDR{});
  341. }
  342. /* WinMMCapture::waveInProc
  343. *
  344. * Posts a message to 'WinMMCapture::captureProc' everytime a WaveIn Buffer is
  345. * completed and returns to the application (with more data).
  346. */
  347. void CALLBACK WinMMCapture::waveInProc(HWAVEIN, UINT msg, DWORD_PTR, DWORD_PTR) noexcept
  348. {
  349. if(msg != WIM_DATA) return;
  350. mReadable.fetch_add(1, std::memory_order_acq_rel);
  351. mSem.post();
  352. }
  353. int WinMMCapture::captureProc()
  354. {
  355. althrd_setname(RECORD_THREAD_NAME);
  356. while(!mKillNow.load(std::memory_order_acquire) &&
  357. mDevice->Connected.load(std::memory_order_acquire))
  358. {
  359. uint todo{mReadable.load(std::memory_order_acquire)};
  360. if(todo < 1)
  361. {
  362. mSem.wait();
  363. continue;
  364. }
  365. size_t widx{mIdx};
  366. do {
  367. WAVEHDR &waveHdr = mWaveBuffer[widx];
  368. widx = (widx+1) % mWaveBuffer.size();
  369. mRing->write(waveHdr.lpData, waveHdr.dwBytesRecorded / mFormat.nBlockAlign);
  370. mReadable.fetch_sub(1, std::memory_order_acq_rel);
  371. waveInAddBuffer(mInHdl, &waveHdr, sizeof(WAVEHDR));
  372. } while(--todo);
  373. mIdx = static_cast<uint>(widx);
  374. }
  375. return 0;
  376. }
  377. void WinMMCapture::open(const char *name)
  378. {
  379. if(CaptureDevices.empty())
  380. ProbeCaptureDevices();
  381. // Find the Device ID matching the deviceName if valid
  382. auto iter = name ?
  383. std::find(CaptureDevices.cbegin(), CaptureDevices.cend(), name) :
  384. CaptureDevices.cbegin();
  385. if(iter == CaptureDevices.cend())
  386. throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found",
  387. name};
  388. auto DeviceID = static_cast<UINT>(std::distance(CaptureDevices.cbegin(), iter));
  389. switch(mDevice->FmtChans)
  390. {
  391. case DevFmtMono:
  392. case DevFmtStereo:
  393. break;
  394. case DevFmtQuad:
  395. case DevFmtX51:
  396. case DevFmtX61:
  397. case DevFmtX71:
  398. case DevFmtAmbi3D:
  399. throw al::backend_exception{al::backend_error::DeviceError, "%s capture not supported",
  400. DevFmtChannelsString(mDevice->FmtChans)};
  401. }
  402. switch(mDevice->FmtType)
  403. {
  404. case DevFmtUByte:
  405. case DevFmtShort:
  406. case DevFmtInt:
  407. case DevFmtFloat:
  408. break;
  409. case DevFmtByte:
  410. case DevFmtUShort:
  411. case DevFmtUInt:
  412. throw al::backend_exception{al::backend_error::DeviceError, "%s samples not supported",
  413. DevFmtTypeString(mDevice->FmtType)};
  414. }
  415. mFormat = WAVEFORMATEX{};
  416. mFormat.wFormatTag = (mDevice->FmtType == DevFmtFloat) ?
  417. WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM;
  418. mFormat.nChannels = static_cast<WORD>(mDevice->channelsFromFmt());
  419. mFormat.wBitsPerSample = static_cast<WORD>(mDevice->bytesFromFmt() * 8);
  420. mFormat.nBlockAlign = static_cast<WORD>(mFormat.wBitsPerSample * mFormat.nChannels / 8);
  421. mFormat.nSamplesPerSec = mDevice->Frequency;
  422. mFormat.nAvgBytesPerSec = mFormat.nSamplesPerSec * mFormat.nBlockAlign;
  423. mFormat.cbSize = 0;
  424. MMRESULT res{waveInOpen(&mInHdl, DeviceID, &mFormat,
  425. reinterpret_cast<DWORD_PTR>(&WinMMCapture::waveInProcC),
  426. reinterpret_cast<DWORD_PTR>(this), CALLBACK_FUNCTION)};
  427. if(res != MMSYSERR_NOERROR)
  428. throw al::backend_exception{al::backend_error::DeviceError, "waveInOpen failed: %u", res};
  429. // Ensure each buffer is 50ms each
  430. DWORD BufferSize{mFormat.nAvgBytesPerSec / 20u};
  431. BufferSize -= (BufferSize % mFormat.nBlockAlign);
  432. // Allocate circular memory buffer for the captured audio
  433. // Make sure circular buffer is at least 100ms in size
  434. uint CapturedDataSize{mDevice->BufferSize};
  435. CapturedDataSize = static_cast<uint>(maxz(CapturedDataSize, BufferSize*mWaveBuffer.size()));
  436. mRing = RingBuffer::Create(CapturedDataSize, mFormat.nBlockAlign, false);
  437. al_free(mWaveBuffer[0].lpData);
  438. mWaveBuffer[0] = WAVEHDR{};
  439. mWaveBuffer[0].lpData = static_cast<char*>(al_calloc(16, BufferSize * mWaveBuffer.size()));
  440. mWaveBuffer[0].dwBufferLength = BufferSize;
  441. for(size_t i{1};i < mWaveBuffer.size();++i)
  442. {
  443. mWaveBuffer[i] = WAVEHDR{};
  444. mWaveBuffer[i].lpData = mWaveBuffer[i-1].lpData + mWaveBuffer[i-1].dwBufferLength;
  445. mWaveBuffer[i].dwBufferLength = mWaveBuffer[i-1].dwBufferLength;
  446. }
  447. mDevice->DeviceName = CaptureDevices[DeviceID];
  448. }
  449. void WinMMCapture::start()
  450. {
  451. try {
  452. for(size_t i{0};i < mWaveBuffer.size();++i)
  453. {
  454. waveInPrepareHeader(mInHdl, &mWaveBuffer[i], sizeof(WAVEHDR));
  455. waveInAddBuffer(mInHdl, &mWaveBuffer[i], sizeof(WAVEHDR));
  456. }
  457. mKillNow.store(false, std::memory_order_release);
  458. mThread = std::thread{std::mem_fn(&WinMMCapture::captureProc), this};
  459. waveInStart(mInHdl);
  460. }
  461. catch(std::exception& e) {
  462. throw al::backend_exception{al::backend_error::DeviceError,
  463. "Failed to start recording thread: %s", e.what()};
  464. }
  465. }
  466. void WinMMCapture::stop()
  467. {
  468. waveInStop(mInHdl);
  469. mKillNow.store(true, std::memory_order_release);
  470. if(mThread.joinable())
  471. {
  472. mSem.post();
  473. mThread.join();
  474. }
  475. waveInReset(mInHdl);
  476. for(size_t i{0};i < mWaveBuffer.size();++i)
  477. waveInUnprepareHeader(mInHdl, &mWaveBuffer[i], sizeof(WAVEHDR));
  478. mReadable.store(0, std::memory_order_release);
  479. mIdx = 0;
  480. }
  481. void WinMMCapture::captureSamples(al::byte *buffer, uint samples)
  482. { mRing->read(buffer, samples); }
  483. uint WinMMCapture::availableSamples()
  484. { return static_cast<uint>(mRing->readSpace()); }
  485. } // namespace
  486. bool WinMMBackendFactory::init()
  487. { return true; }
  488. bool WinMMBackendFactory::querySupport(BackendType type)
  489. { return type == BackendType::Playback || type == BackendType::Capture; }
  490. std::string WinMMBackendFactory::probe(BackendType type)
  491. {
  492. std::string outnames;
  493. auto add_device = [&outnames](const std::string &dname) -> void
  494. {
  495. /* +1 to also append the null char (to ensure a null-separated list and
  496. * double-null terminated list).
  497. */
  498. if(!dname.empty())
  499. outnames.append(dname.c_str(), dname.length()+1);
  500. };
  501. switch(type)
  502. {
  503. case BackendType::Playback:
  504. ProbePlaybackDevices();
  505. std::for_each(PlaybackDevices.cbegin(), PlaybackDevices.cend(), add_device);
  506. break;
  507. case BackendType::Capture:
  508. ProbeCaptureDevices();
  509. std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
  510. break;
  511. }
  512. return outnames;
  513. }
  514. BackendPtr WinMMBackendFactory::createBackend(DeviceBase *device, BackendType type)
  515. {
  516. if(type == BackendType::Playback)
  517. return BackendPtr{new WinMMPlayback{device}};
  518. if(type == BackendType::Capture)
  519. return BackendPtr{new WinMMCapture{device}};
  520. return nullptr;
  521. }
  522. BackendFactory &WinMMBackendFactory::getFactory()
  523. {
  524. static WinMMBackendFactory factory{};
  525. return factory;
  526. }