jack2 codebase
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.

768 lines
22KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2006 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include "JackClient.h"
  17. #include "JackGraphManager.h"
  18. #include "JackClientControl.h"
  19. #include "JackEngineControl.h"
  20. #include "JackGlobals.h"
  21. #include "JackChannel.h"
  22. #include "JackTransportEngine.h"
  23. #include <math.h>
  24. #include <string>
  25. int verbose = 0;
  26. using namespace std;
  27. namespace Jack
  28. {
  29. JackClient::JackClient()
  30. {}
  31. JackClient::JackClient(JackSynchro** table)
  32. {
  33. fThread = JackGlobals::MakeThread(this);
  34. fSynchroTable = table;
  35. fProcess = NULL;
  36. fGraphOrder = NULL;
  37. fXrun = NULL;
  38. fShutdown = NULL;
  39. fInit = NULL;
  40. fBufferSize = NULL;
  41. fFreewheel = NULL;
  42. fPortRegistration = NULL;
  43. fSync = NULL;
  44. fProcessArg = NULL;
  45. fGraphOrderArg = NULL;
  46. fXrunArg = NULL;
  47. fShutdownArg = NULL;
  48. fInitArg = NULL;
  49. fBufferSizeArg = NULL;
  50. fFreewheelArg = NULL;
  51. fPortRegistrationArg = NULL;
  52. fSyncArg = NULL;
  53. fConditionnal = 0; // Temporary??
  54. }
  55. JackClient::~JackClient()
  56. {
  57. delete fThread;
  58. }
  59. int JackClient::Close()
  60. {
  61. JackLog("JackClient::Close ref = %ld\n", GetClientControl()->fRefNum);
  62. Deactivate();
  63. int result = -1;
  64. fChannel->ClientClose(GetClientControl()->fRefNum, &result);
  65. fChannel->Stop();
  66. fChannel->Close();
  67. fSynchroTable[GetClientControl()->fRefNum]->Disconnect();
  68. return result;
  69. }
  70. bool JackClient::IsActive()
  71. {
  72. return (GetClientControl()) ? GetClientControl()->fActive : false;
  73. }
  74. pthread_t JackClient::GetThreadID()
  75. {
  76. return fThread->GetThreadID();
  77. }
  78. /*!
  79. \brief
  80. In ASYNC mode, the server does not synchronize itself on the output drivers, thus it would never "consume" the activations.
  81. The synchronization primitives for drivers are setup in "flush" mode that to not keep unneeded activations.
  82. Drivers synchro are setup in "flush" mode if server is ASYNC and NOT freewheel.
  83. */
  84. void JackClient::SetupDriverSync(bool freewheel)
  85. {
  86. if (!freewheel && !GetEngineControl()->fSyncMode) {
  87. JackLog("JackClient::SetupDriverSync driver sem in flush mode\n");
  88. fSynchroTable[AUDIO_DRIVER_REFNUM]->SetFlush(true);
  89. fSynchroTable[FREEWHEEL_DRIVER_REFNUM]->SetFlush(true);
  90. fSynchroTable[LOOPBACK_DRIVER_REFNUM]->SetFlush(true);
  91. } else {
  92. JackLog("JackClient::SetupDriverSync driver sem in normal mode\n");
  93. fSynchroTable[AUDIO_DRIVER_REFNUM]->SetFlush(false);
  94. fSynchroTable[FREEWHEEL_DRIVER_REFNUM]->SetFlush(false);
  95. fSynchroTable[LOOPBACK_DRIVER_REFNUM]->SetFlush(false);
  96. }
  97. }
  98. /*!
  99. \brief Notification received from the server.
  100. */
  101. int JackClient::ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value)
  102. {
  103. return 0;
  104. }
  105. int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, int value)
  106. {
  107. int res = 0;
  108. // Done all time: redirected on subclass implementation JackLibClient and JackInternalClient
  109. switch (notify) {
  110. case JackNotifyChannelInterface::kAddClient:
  111. case JackNotifyChannelInterface::kRemoveClient:
  112. res = ClientNotifyImp(refnum, name, notify, sync, value);
  113. break;
  114. }
  115. /*
  116. The current semantic is that notifications can only be received when the client has been activated,
  117. although is this implementation, one could imagine calling notifications as soon as the client has be opened.
  118. */
  119. if (IsActive()) {
  120. switch (notify) {
  121. case JackNotifyChannelInterface::kBufferSizeCallback:
  122. JackLog("JackClient::kBufferSizeCallback buffer_size = %ld\n", value);
  123. if (fBufferSize)
  124. res = fBufferSize(value, fBufferSizeArg);
  125. break;
  126. case JackNotifyChannelInterface::kGraphOrderCallback:
  127. JackLog("JackClient::kGraphOrderCallback\n");
  128. if (fGraphOrder)
  129. res = fGraphOrder(fGraphOrderArg);
  130. break;
  131. case JackNotifyChannelInterface::kStartFreewheel:
  132. JackLog("JackClient::kStartFreewheel\n");
  133. SetupDriverSync(true);
  134. fThread->DropRealTime();
  135. if (fFreewheel)
  136. fFreewheel(1, fFreewheelArg);
  137. break;
  138. case JackNotifyChannelInterface::kStopFreewheel:
  139. JackLog("JackClient::kStopFreewheel\n");
  140. SetupDriverSync(false);
  141. if (fFreewheel)
  142. fFreewheel(0, fFreewheelArg);
  143. fThread->AcquireRealTime();
  144. break;
  145. case JackNotifyChannelInterface::kPortRegistrationOn:
  146. JackLog("JackClient::kPortRegistrationOn port_index = %ld\n", value);
  147. if (fPortRegistration)
  148. fPortRegistration(value, 1, fPortRegistrationArg);
  149. break;
  150. case JackNotifyChannelInterface::kPortRegistrationOff:
  151. JackLog("JackClient::kPortRegistrationOff port_index = %ld \n", value);
  152. if (fPortRegistration)
  153. fPortRegistration(value, 0, fPortRegistrationArg);
  154. break;
  155. case JackNotifyChannelInterface::kXRunCallback:
  156. JackLog("JackClient::kXRunCallback\n");
  157. if (fXrun)
  158. res = fXrun(fXrunArg);
  159. break;
  160. case JackNotifyChannelInterface::kZombifyClient:
  161. res = fThread->Kill();
  162. JackLog("JackClient::kZombifyClient name = %s ref = %ld \n", name, refnum);
  163. ShutDown();
  164. break;
  165. }
  166. }
  167. return res;
  168. }
  169. /*!
  170. \brief We need to start thread before activating in the server, otherwise the FW driver
  171. connected to the client may not be activated.
  172. */
  173. int JackClient::Activate()
  174. {
  175. JackLog("JackClient::Activate \n");
  176. if (IsActive())
  177. return 0;
  178. if (StartThread() < 0)
  179. return -1;
  180. int result = -1;
  181. fChannel->ClientActivate(GetClientControl()->fRefNum, &result);
  182. if (result < 0)
  183. return result;
  184. if (fSync != NULL) /* If a SyncCallback is pending... */
  185. SetSyncCallback(fSync, fSyncArg);
  186. if (fTimebase != NULL) /* If a TimebaseCallback is pending... */
  187. SetTimebaseCallback(fConditionnal, fTimebase, fTimebaseArg);
  188. GetClientControl()->fActive = true;
  189. return 0;
  190. }
  191. /*!
  192. \brief Need to stop thread after deactivating in the server.
  193. */
  194. int JackClient::Deactivate()
  195. {
  196. JackLog("JackClient::Deactivate \n");
  197. if (!IsActive())
  198. return 0;
  199. GetClientControl()->fActive = false;
  200. int result = -1;
  201. fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result);
  202. JackLog("JackClient::Deactivate res = %ld \n", result);
  203. // We need to wait for the new engine cycle before stopping the RT thread, but this is done by ClientDeactivate
  204. fThread->Kill();
  205. return result;
  206. }
  207. //----------------------
  208. // RT thread management
  209. //----------------------
  210. bool JackClient::CallProcessCallback()
  211. {
  212. return (fProcess == NULL) ? true : (fProcess(GetEngineControl()->fBufferSize, fProcessArg) == 0);
  213. }
  214. /*!
  215. \brief Called once when the thread starts.
  216. */
  217. bool JackClient::Init()
  218. {
  219. if (fInit) {
  220. JackLog("JackClient::Init calling client thread init callback\n");
  221. fInit(fInitArg);
  222. }
  223. return true;
  224. }
  225. int JackClient::StartThread()
  226. {
  227. JackLog("JackClient::StartThread : period = %ld computation = %ld constraint = %ld\n",
  228. long(int64_t(GetEngineControl()->fPeriod) / 1000.0f),
  229. long(int64_t(GetEngineControl()->fComputation) / 1000.0f),
  230. long(int64_t(GetEngineControl()->fConstraint) / 1000.0f));
  231. // Will do "something" on OSX only...
  232. fThread->SetParams(GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint);
  233. if (fThread->Start() < 0) {
  234. jack_error("Start thread error");
  235. return -1;
  236. }
  237. if (GetEngineControl()->fRealTime) {
  238. if (fThread->AcquireRealTime(GetEngineControl()->fPriority - 1) < 0) {
  239. jack_error("AcquireRealTime error");
  240. }
  241. }
  242. return 0;
  243. }
  244. /*!
  245. \brief RT thread.
  246. */
  247. bool JackClient::Execute()
  248. {
  249. // Suspend itself: wait on the input synchro
  250. if (GetGraphManager()->SuspendRefNum(GetClientControl(), fSynchroTable, 0x7FFFFFFF) < 0) {
  251. jack_error("SuspendRefNum error");
  252. goto error;
  253. }
  254. // Process call
  255. if (IsActive()) {
  256. CallSyncCallback();
  257. bool res = CallProcessCallback();
  258. CallTimebaseCallback();
  259. if (!res)
  260. goto end;
  261. } else {
  262. JackLog("Process called for an inactive client\n");
  263. // Happens if client is still not activated (connected to the FW)
  264. // or still runs while being desactivated by the server
  265. }
  266. // Resume: signal output clients connected to the running client
  267. if (GetGraphManager()->ResumeRefNum(GetClientControl(), fSynchroTable) < 0) {
  268. jack_error("ResumeRefNum error");
  269. }
  270. return true;
  271. end:
  272. JackLog("JackClient::Execute end name = %s\n", GetClientControl()->fName);
  273. // Continue graph execution for this cycle
  274. if (GetGraphManager()->ResumeRefNum(GetClientControl(), fSynchroTable) < 0) {
  275. jack_error("ResumeRefNum error");
  276. }
  277. // Hum... not sure about this, the following "close" code is called in the RT thread...
  278. int result;
  279. fThread->DropRealTime();
  280. fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result);
  281. Close(); // Not sure...
  282. return false;
  283. error:
  284. jack_error("JackClient::Execute error name = %s", GetClientControl()->fName);
  285. // Hum... not sure about this, the following "close" code is called in the RT thread...
  286. fThread->DropRealTime();
  287. ShutDown();
  288. return false;
  289. }
  290. //-----------------
  291. // Port management
  292. //-----------------
  293. int JackClient::PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
  294. {
  295. // Check port name length
  296. string port_name_str = string(port_name);
  297. if (port_name_str.size() == 0) {
  298. jack_error("port_name is empty.");
  299. return 0; // Means failure here...
  300. }
  301. string name = string(GetClientControl()->fName) + string(":") + port_name_str;
  302. if (name.size() >= JACK_PORT_NAME_SIZE) {
  303. jack_error("\"%s:%s\" is too long to be used as a JACK port name.\n"
  304. "Please use %lu characters or less.",
  305. GetClientControl()->fName,
  306. port_name,
  307. JACK_PORT_NAME_SIZE - 1);
  308. return 0; // Means failure here...
  309. }
  310. // Check if port name already exists
  311. if (GetGraphManager()->GetPort(name.c_str()) != NO_PORT) {
  312. jack_error("port_name \"%s\" already exists.", port_name);
  313. return 0; // Means failure here...
  314. }
  315. JackLog("JackClient::PortRegister ref = %ld name = %s \n", GetClientControl()->fRefNum, name.c_str());
  316. int result = -1;
  317. jack_port_id_t port_index = NO_PORT;
  318. fChannel->PortRegister(GetClientControl()->fRefNum, name.c_str(), flags, buffer_size, &port_index, &result);
  319. JackLog("JackClient::PortRegister port_index = %ld \n", port_index);
  320. if (result == 0) {
  321. fPortList.push_back(port_index);
  322. return port_index;
  323. } else {
  324. return 0;
  325. }
  326. }
  327. int JackClient::PortUnRegister(jack_port_id_t port_index)
  328. {
  329. JackLog("JackClient::PortUnRegister port_index = %ld\n", port_index);
  330. list<jack_port_id_t>::iterator it;
  331. for (it = fPortList.begin(); it != fPortList.end() && *it != port_index; it++)
  332. ;
  333. if (it != fPortList.end()) {
  334. fPortList.erase(it);
  335. int result = -1;
  336. fChannel->PortUnRegister(GetClientControl()->fRefNum, port_index, &result);
  337. return result;
  338. } else {
  339. jack_error("unregistering a port %ld that is not own by the client", port_index);
  340. return -1;
  341. }
  342. }
  343. int JackClient::PortConnect(const char* src, const char* dst)
  344. {
  345. JackLog("JackClient::Connect src = %s dst = %s\n", src, dst);
  346. int result = -1;
  347. fChannel->PortConnect(GetClientControl()->fRefNum, src, dst, &result);
  348. return result;
  349. }
  350. int JackClient::PortDisconnect(const char* src, const char* dst)
  351. {
  352. JackLog("JackClient::Disconnect src = %s dst = %s\n", src, dst);
  353. int result = -1;
  354. fChannel->PortDisconnect(GetClientControl()->fRefNum, src, dst, &result);
  355. return result;
  356. }
  357. int JackClient::PortConnect(jack_port_id_t src, jack_port_id_t dst)
  358. {
  359. JackLog("JackClient::PortConnect src = %ld dst = %ld\n", src, dst);
  360. int result = -1;
  361. fChannel->PortConnect(GetClientControl()->fRefNum, src, dst, &result);
  362. return result;
  363. }
  364. int JackClient::PortDisconnect(jack_port_id_t src)
  365. {
  366. JackLog("JackClient::PortDisconnect src = %ld\n", src);
  367. int result = -1;
  368. fChannel->PortDisconnect(GetClientControl()->fRefNum, src, ALL_PORTS, &result);
  369. return result;
  370. }
  371. int JackClient::PortIsMine(jack_port_id_t port_index)
  372. {
  373. JackPort* port = GetGraphManager()->GetPort(port_index);
  374. return GetClientControl()->fRefNum == port->GetRefNum();
  375. }
  376. //--------------------
  377. // Context management
  378. //--------------------
  379. int JackClient::SetBufferSize(jack_nframes_t nframes)
  380. {
  381. int result = -1;
  382. fChannel->SetBufferSize(nframes, &result);
  383. return result;
  384. }
  385. int JackClient::SetFreeWheel(int onoff)
  386. {
  387. int result = -1;
  388. fChannel->SetFreewheel(onoff, &result);
  389. return result;
  390. }
  391. /*
  392. ShutDown is called:
  393. - from the RT thread when Execute method fails
  394. - possibly from a "closed" notification channel
  395. (Not needed since the synch object used (Sema of Fifo will fails when server quits... see ShutDown))
  396. */
  397. void JackClient::ShutDown()
  398. {
  399. JackLog("ShutDown\n");
  400. if (fShutdown) {
  401. GetClientControl()->fActive = false;
  402. fShutdown(fShutdownArg);
  403. fShutdown = NULL;
  404. }
  405. }
  406. //----------------------
  407. // Transport management
  408. //----------------------
  409. int JackClient::ReleaseTimebase()
  410. {
  411. int result = -1;
  412. fChannel->ReleaseTimebase(GetClientControl()->fRefNum, &result);
  413. if (result == 0) {
  414. fTimebase = NULL;
  415. fTimebaseArg = NULL;
  416. }
  417. return result;
  418. }
  419. /* Call the server if the client is active, otherwise keeps the arguments */
  420. int JackClient::SetSyncCallback(JackSyncCallback sync_callback, void* arg)
  421. {
  422. if (IsActive())
  423. GetClientControl()->fTransportState = (sync_callback == NULL) ? JackTransportStopped : JackTransportSynching;
  424. fSync = sync_callback;
  425. fSyncArg = arg;
  426. return 0;
  427. }
  428. int JackClient::SetSyncTimeout(jack_time_t timeout)
  429. {
  430. GetEngineControl()->fTransport.SetSyncTimeout(timeout);
  431. return 0;
  432. }
  433. /* Call the server if the client is active, otherwise keeps the arguments */
  434. int JackClient::SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg)
  435. {
  436. if (IsActive()) {
  437. int result = -1;
  438. fChannel->SetTimebaseCallback(GetClientControl()->fRefNum, conditional, &result);
  439. JackLog("SetTimebaseCallback result = %ld\n", result);
  440. if (result == 0) {
  441. fTimebase = timebase_callback;
  442. fTimebaseArg = arg;
  443. } else {
  444. fTimebase = NULL;
  445. fTimebaseArg = NULL;
  446. }
  447. JackLog("SetTimebaseCallback OK result = %ld\n", result);
  448. return result;
  449. } else {
  450. fTimebase = timebase_callback;
  451. fTimebaseArg = arg;
  452. fConditionnal = conditional;
  453. return 0;
  454. }
  455. }
  456. // Must be RT safe
  457. int JackClient::RequestNewPos(jack_position_t* pos)
  458. {
  459. JackTransportEngine& transport = GetEngineControl()->fTransport;
  460. jack_position_t* request = transport.WriteNextStateStart(2);
  461. pos->unique_1 = pos->unique_2 = transport.GenerateUniqueID();
  462. JackTransportEngine::TransportCopyPosition(pos, request);
  463. JackLog("RequestNewPos pos = %ld\n", pos->frame);
  464. transport.WriteNextStateStop(2);
  465. return 0;
  466. }
  467. int JackClient::TransportLocate(jack_nframes_t frame)
  468. {
  469. jack_position_t pos;
  470. pos.frame = frame;
  471. pos.valid = (jack_position_bits_t)0;
  472. JackLog("TransportLocate pos = %ld\n", pos.frame);
  473. return RequestNewPos(&pos);
  474. }
  475. int JackClient::TransportReposition(jack_position_t* pos)
  476. {
  477. jack_position_t tmp = *pos;
  478. JackLog("TransportReposition pos = %ld\n", pos->frame);
  479. return (tmp.valid & ~JACK_POSITION_MASK) ? EINVAL : RequestNewPos(&tmp);
  480. }
  481. jack_transport_state_t JackClient::TransportQuery(jack_position_t* pos)
  482. {
  483. if (pos)
  484. GetEngineControl()->fTransport.ReadCurrentPos(pos);
  485. return GetEngineControl()->fTransport.GetState();
  486. }
  487. jack_nframes_t JackClient::GetCurrentTransportFrame()
  488. {
  489. jack_position_t pos;
  490. jack_transport_state_t state = TransportQuery(&pos);
  491. if (state == JackTransportRolling) {
  492. float usecs = GetMicroSeconds() - pos.usecs;
  493. jack_nframes_t elapsed = (jack_nframes_t)floor((((float) pos.frame_rate) / 1000000.0f) * usecs);
  494. return pos.frame + elapsed;
  495. } else {
  496. return pos.frame;
  497. }
  498. }
  499. // Must be RT safe: directly write in the transport shared mem
  500. void JackClient::TransportStart()
  501. {
  502. GetEngineControl()->fTransport.SetCommand(TransportCommandStart);
  503. }
  504. // Must be RT safe: directly write in the transport shared mem
  505. void JackClient::TransportStop()
  506. {
  507. GetEngineControl()->fTransport.SetCommand(TransportCommandStop);
  508. }
  509. // Never called concurently with the server
  510. // TODO check concurency with SetSyncCallback
  511. void JackClient::CallSyncCallback()
  512. {
  513. JackTransportEngine& transport = GetEngineControl()->fTransport;
  514. jack_position_t* cur_pos = transport.ReadCurrentState();
  515. jack_transport_state_t transport_state = transport.GetState();
  516. switch (transport_state) {
  517. case JackTransportStarting: // Starting...
  518. if (fSync == NULL) {
  519. GetClientControl()->fTransportState = JackTransportRolling;
  520. } else if (GetClientControl()->fTransportState == JackTransportStarting) {
  521. if (fSync(transport_state, cur_pos, fSyncArg))
  522. GetClientControl()->fTransportState = JackTransportRolling;
  523. }
  524. break;
  525. case JackTransportRolling:
  526. if (fSync != NULL && GetClientControl()->fTransportState == JackTransportStarting) { // Client still not ready
  527. if (fSync(transport_state, cur_pos, fSyncArg))
  528. GetClientControl()->fTransportState = JackTransportRolling;
  529. }
  530. break;
  531. case JackTransportSynching:
  532. // New pos when transport engine is stopped...
  533. if (fSync != NULL) {
  534. fSync(JackTransportStopped, cur_pos, fSyncArg);
  535. GetClientControl()->fTransportState = JackTransportStopped;
  536. }
  537. break;
  538. default:
  539. break;
  540. }
  541. }
  542. void JackClient::CallTimebaseCallback()
  543. {
  544. JackTransportEngine& transport = GetEngineControl()->fTransport;
  545. if (fTimebase != NULL && fTimebaseArg != NULL && GetClientControl()->fRefNum == transport.GetTimebaseMaster()) {
  546. jack_transport_state_t transport_state = transport.GetState();
  547. jack_position_t* cur_pos = transport.WriteNextStateStart(1);
  548. switch (transport_state) {
  549. case JackTransportRolling:
  550. fTimebase(transport_state, GetEngineControl()->fBufferSize, cur_pos, false, fTimebaseArg);
  551. break;
  552. case JackTransportSynching:
  553. fTimebase(JackTransportStopped, GetEngineControl()->fBufferSize, cur_pos, true, fTimebaseArg);
  554. break;
  555. default:
  556. break;
  557. }
  558. transport.WriteNextStateStop(1);
  559. }
  560. }
  561. //---------------------
  562. // Callback management
  563. //---------------------
  564. void JackClient::OnShutdown(JackShutdownCallback callback, void *arg)
  565. {
  566. if (IsActive()) {
  567. jack_error("You cannot set callbacks on an active client");
  568. } else {
  569. fShutdownArg = arg;
  570. fShutdown = callback;
  571. }
  572. }
  573. int JackClient::SetProcessCallback(JackProcessCallback callback, void *arg)
  574. {
  575. if (IsActive()) {
  576. jack_error("You cannot set callbacks on an active client");
  577. return -1;
  578. } else {
  579. fProcessArg = arg;
  580. fProcess = callback;
  581. return 0;
  582. }
  583. }
  584. int JackClient::SetXRunCallback(JackXRunCallback callback, void *arg)
  585. {
  586. if (IsActive()) {
  587. jack_error("You cannot set callbacks on an active client");
  588. return -1;
  589. } else {
  590. fXrunArg = arg;
  591. fXrun = callback;
  592. return 0;
  593. }
  594. }
  595. int JackClient::SetInitCallback(JackThreadInitCallback callback, void *arg)
  596. {
  597. if (IsActive()) {
  598. jack_error("You cannot set callbacks on an active client");
  599. return -1;
  600. } else {
  601. fInitArg = arg;
  602. fInit = callback;
  603. return 0;
  604. }
  605. }
  606. int JackClient::SetGraphOrderCallback(JackGraphOrderCallback callback, void *arg)
  607. {
  608. JackLog("SetGraphOrderCallback \n");
  609. if (IsActive()) {
  610. jack_error("You cannot set callbacks on an active client");
  611. return -1;
  612. } else {
  613. fGraphOrder = callback;
  614. fGraphOrderArg = arg;
  615. return 0;
  616. }
  617. }
  618. int JackClient::SetBufferSizeCallback(JackBufferSizeCallback callback, void *arg)
  619. {
  620. if (IsActive()) {
  621. jack_error("You cannot set callbacks on an active client");
  622. return -1;
  623. } else {
  624. fBufferSizeArg = arg;
  625. fBufferSize = callback;
  626. return 0;
  627. }
  628. }
  629. int JackClient::SetFreewheelCallback(JackFreewheelCallback callback, void *arg)
  630. {
  631. if (IsActive()) {
  632. jack_error("You cannot set callbacks on an active client");
  633. return -1;
  634. } else {
  635. fFreewheelArg = arg;
  636. fFreewheel = callback;
  637. return 0;
  638. }
  639. }
  640. int JackClient::SetPortRegistrationCallback(JackPortRegistrationCallback callback, void *arg)
  641. {
  642. if (IsActive()) {
  643. jack_error("You cannot set callbacks on an active client");
  644. return -1;
  645. } else {
  646. fPortRegistrationArg = arg;
  647. fPortRegistration = callback;
  648. return 0;
  649. }
  650. }
  651. } // end of namespace