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.

163 lines
5.5KB

  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. #ifndef __JackClient__
  17. #define __JackClient__
  18. #include "JackClientInterface.h"
  19. #include "JackThread.h"
  20. #include "JackConstants.h"
  21. #include "JackSynchro.h"
  22. #include "types.h"
  23. #include "transport_types.h"
  24. #include <list>
  25. namespace Jack
  26. {
  27. class JackClientChannelInterface;
  28. class JackGraphManager;
  29. class JackServer;
  30. class JackEngine;
  31. class JackSynchro;
  32. struct JackClientControl;
  33. struct JackEngineControl;
  34. class JackSyncInterface;
  35. typedef void (*JackShutdownCallback)(void *arg);
  36. /*!
  37. \brief The base class for clients: share part of the implementation for JackInternalClient and JackLibClient.
  38. */
  39. class JackClient : public JackClientInterface, public JackRunnableInterface
  40. {
  41. protected:
  42. JackProcessCallback fProcess;
  43. JackGraphOrderCallback fGraphOrder;
  44. JackXRunCallback fXrun;
  45. JackShutdownCallback fShutdown;
  46. JackThreadInitCallback fInit;
  47. JackBufferSizeCallback fBufferSize;
  48. JackFreewheelCallback fFreewheel;
  49. JackPortRegistrationCallback fPortRegistration;
  50. JackTimebaseCallback fTimebase;
  51. JackSyncCallback fSync;
  52. void* fProcessArg;
  53. void* fGraphOrderArg;
  54. void* fXrunArg;
  55. void* fShutdownArg;
  56. void* fInitArg;
  57. void* fBufferSizeArg;
  58. void* fFreewheelArg;
  59. void* fPortRegistrationArg;
  60. void* fTimebaseArg;
  61. void* fSyncArg;
  62. int fConditionnal;
  63. JackThread* fThread; /*! Thread to execute the Process function */
  64. JackClientChannelInterface* fChannel;
  65. JackSynchro** fSynchroTable;
  66. std::list<jack_port_id_t> fPortList;
  67. int StartThread();
  68. void SetupDriverSync(bool freewheel);
  69. bool IsActive();
  70. bool CallProcessCallback();
  71. void CallSyncCallback();
  72. void CallTimebaseCallback();
  73. int RequestNewPos(jack_position_t* pos);
  74. virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value);
  75. public:
  76. JackClient();
  77. JackClient(JackSynchro** table);
  78. virtual ~JackClient();
  79. virtual int Open(const char* name) = 0;
  80. virtual int Close();
  81. virtual JackGraphManager* GetGraphManager() const = 0;
  82. virtual JackEngineControl* GetEngineControl() const = 0;
  83. // Notifications
  84. virtual int ClientNotify(int refnum, const char* name, int notify, int sync, int value);
  85. virtual int Activate();
  86. virtual int Deactivate();
  87. // Context
  88. virtual int SetBufferSize(jack_nframes_t nframes);
  89. virtual int SetFreeWheel(int onoff);
  90. virtual void ShutDown();
  91. virtual pthread_t GetThreadID();
  92. // Port management
  93. virtual int PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
  94. virtual int PortUnRegister(jack_port_id_t port);
  95. virtual int PortConnect(const char* src, const char* dst);
  96. virtual int PortDisconnect(const char* src, const char* dst);
  97. virtual int PortConnect(jack_port_id_t src, jack_port_id_t dst);
  98. virtual int PortDisconnect(jack_port_id_t src);
  99. int PortIsMine(jack_port_id_t port_index);
  100. // Transport
  101. virtual int ReleaseTimebase();
  102. virtual int SetSyncCallback(JackSyncCallback sync_callback, void* arg);
  103. virtual int SetSyncTimeout(jack_time_t timeout);
  104. virtual int SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg);
  105. virtual int TransportLocate(jack_nframes_t frame);
  106. virtual jack_transport_state_t TransportQuery(jack_position_t* pos);
  107. virtual jack_nframes_t GetCurrentTransportFrame();
  108. virtual int TransportReposition(jack_position_t* pos);
  109. virtual void TransportStart();
  110. virtual void TransportStop();
  111. // Callbacks
  112. virtual void OnShutdown(JackShutdownCallback callback, void *arg);
  113. virtual int SetProcessCallback(JackProcessCallback callback, void* arg);
  114. virtual int SetXRunCallback(JackXRunCallback callback, void* arg);
  115. virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
  116. virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg);
  117. virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg);
  118. virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
  119. virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
  120. // JackRunnableInterface interface
  121. bool Init();
  122. bool Execute();
  123. };
  124. // Each "side" server and client will implement this to get the shared graph manager, engine control and inter-process synchro table.
  125. extern JackGraphManager* GetGraphManager();
  126. extern JackEngineControl* GetEngineControl();
  127. extern JackSynchro** GetSynchroTable();
  128. } // end of namespace
  129. #endif