SOUND4 Plugin Host Library [1.0.2]
sound4.plughost.cl_dyn.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <string>
10 #include <exception>
11 #include <thread>
12 #include <functional>
13 #include <memory>
14 #include <array>
15 #include <assert.h>
16 #include <stdexcept>
17 #include <filesystem>
18 #include <string.h>
19 
20 #ifdef __unix__
21  #include <dlfcn.h>
22 #elif defined(_WIN32)
23  #include <libloaderapi.h>
24 #else
25  #error "Unsupported OS"
26 #endif
27 
28 // Needed to have function declarations
29 #include "sound4.plughost.cl.h"
30 
31 
32 #ifdef _WIN32
33  #include <stringapiset.h>
34  #include <wchar.h>
36  #define fs_strdup wcsdup
37 #else // !_WIN32
39  #define fs_strdup strdup
40 #endif // !_WIN32
41 
42 // bridge C callbacks to CPresetLoader
43 extern "C" {
44  static char *plughost_custom_reader(const fs_char *filename, void* userdata);
45  static void plughost_custom_reader_free(char *content, void* userdata);
46  static int plughost_custom_writer(const fs_char *filename, const char *content, void* userdata);
47  static int plughost_custom_exists(const fs_char *filename, void* userdata);
48  static fs_char** plughost_custom_getall(void* userdata);
49  static void plughost_custom_getall_free(fs_char** all, void* userdata);
50  static int plughost_custom_remove(const fs_char *filename, void* userdata);
51  static int plughost_custom_rename(const fs_char *from, const fs_char *to, void* userdata);
52 };
53 
57 namespace sound4 {
61 namespace plughost {
65 namespace dyn {
66 
70  namespace helper {
71  // Storage definition, depending on OS
72  #ifdef __unix__
73  using DynLib_t = void *;
74  using DynFunc_t = void *;
75  #else
76  using DynLib_t = HMODULE;
77  using DynFunc_t = FARPROC;
78  #endif
79 
85  template <typename T>
86  class DynFuncHolder {
87  private:
88  DynFunc_t m_ptr = NULL;
89  public:
90  DynFuncHolder() = default;
91  DynFuncHolder(DynFunc_t a_ptr) : m_ptr(a_ptr) {}
92  bool IsOk() const { return m_ptr!=NULL; }
93  operator T* () const { return reinterpret_cast<T*>(m_ptr); }
94  };
95 
100  class CDynLoader {
101  private:
102  DynLib_t m_lib {};
103  public:
104  CDynLoader() = default;
105  CDynLoader(CDynLoader&&) = default;
106  // No copy allowed
107  CDynLoader(const CDynLoader&) = delete;
108  CDynLoader& operator=(CDynLoader const&) = delete;
109  operator bool() const {
110  return (m_lib!=NULL);
111  }
112  bool IsOk() const {
113  return (m_lib!=NULL);
114  }
115  #ifdef __unix__
116  void Close() {
117  if (IsOk()) {
118  #ifndef __SANITIZE_ADDRESS__ // avoid unloading to keep call stack
119  dlclose(m_lib);
120  #endif // __SANITIZE_ADDRESS__
121  m_lib=NULL;
122  }
123  }
124  bool Load(const std::filesystem::path& dynlib)
125  {
126  Close();
127  m_lib=dlopen(dynlib.c_str(), RTLD_NOW|RTLD_LOCAL);
128  return IsOk();
129  }
130  template <typename T>
131  DynFuncHolder<T> GetSymbol(const std::string& name) {
132  auto ptr=dlsym(m_lib, name.c_str());
133  if (!ptr) {
134  throw std::runtime_error("Missing function in library");
135  }
136  return DynFuncHolder<T>(ptr);
137  }
138  static std::filesystem::path GetThisLibraryPath(void) {
139  static Dl_info info;
140  if (! dladdr((void *) GetThisLibraryPath, & info)) return {};
141  auto rp=realpath(info.dli_fname, NULL);
142  std::filesystem::path p(rp);
143  free(rp);
144  return p;
145  }
146  #else
147  bool Load(const std::filesystem::path& dynlib, uint32_t loadflags = LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|LOAD_LIBRARY_SEARCH_APPLICATION_DIR|LOAD_LIBRARY_SEARCH_USER_DIRS|LOAD_LIBRARY_SEARCH_SYSTEM32)
148  {
149  Close();
150  m_lib=LoadLibraryExW(dynlib.c_str(), NULL, loadflags);
151  return IsOk();
152  }
153  void Close() {
154  if (IsOk()) {
155  // NOTE: On Windows, FreeLibrary may create a lot of troubles, should use FreeLibraryAndExitThread but...
156  // So define SOUND4_CALL_FREELIBRARY before including this file if you really want to unload the library dynamically
157  #if defined(SOUND4_CALL_FREELIBRARYANDEXITTHREAD)
158  FreeLibraryAndExitThread(m_lib, 0);
159  #elif defined(SOUND4_CALL_FREELIBRARY)
160  FreeLibrary(m_lib);
161  #endif // SOUND4_CALL_FREELIBRARY
162  m_lib=NULL;
163  }
164  }
165  template <typename T>
166  DynFuncHolder<T> GetSymbol(const std::string& name) {
167  auto ptr=GetProcAddress(m_lib, name.c_str());
168  if (!ptr) {
169  throw std::runtime_error("Missing function in library");
170  }
171  return DynFuncHolder<T>(ptr);
172  }
173  static std::filesystem::path GetThisLibraryPath(void) {
174  static wchar_t path[MAX_PATH]={};
175  HMODULE hm = NULL;
176  if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
177  GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
178  (LPCWSTR) &GetThisLibraryPath, &hm))
179  {
180  if (GetModuleFileNameW(hm, path, MAX_PATH) > 0) {
181  return std::filesystem::path(path);
182  }
183  }
184  return {};
185  }
186  #endif
187  virtual ~CDynLoader() {
188  Close();
189  }
190  }; // class CDynLoader
191  }; // namespace helper
192 
199  class CDynLib {
200  private:
201  helper::CDynLoader m_lib;
202  bool m_bOK = false;
203  public:
204  CDynLib() = default;
205 
206  // All those wrapped functions have the same signature as there C plughost_XXX
251 #if PLUGHOST_HAS_WEBSERVER
257 #endif // PLUGHOST_HAS_WEBSERVER
258 
259  // added 2023-03-22
262 
263  // added 2023-05-22
267 
268  // added 2023-06-20
271 
272  // added 2023-09-21
276 
277 #if PLUGHOST_HAS_CLOUDBUS
278  // added 2023-06-26
279  helper::DynFuncHolder< decltype(plughost_NewBus ) > NewBus ;
280  helper::DynFuncHolder< decltype(plughost_FreeBus ) > FreeBus ;
281  helper::DynFuncHolder< decltype(plughost_SetInstanceBus ) > SetInstanceBus ;
282 #endif // PLUGHOST_HAS_CLOUDBUS
283 
291  bool Load(const std::filesystem::path& path = std::filesystem::current_path()) {
292  std::string filename;
293  #ifdef __unix__
294  filename="libsound4.plughost.cl.so";
295  #else
296  filename="sound4.plughost.cl.dll";
297  #endif
298  auto p = path;
299  p.append(filename);
300  m_lib.Load(p.native());
301  if (!m_lib.IsOk()) {
302  // Search in the same directory this code is in
304  p.append(filename);
305  m_lib.Load(p.native());
306  if (!m_lib.IsOk()) {
307  return false;
308  }
309  }
310  // Load all C functions
311  try {
312  GetVersion = m_lib.GetSymbol< decltype(plughost_GetVersion ) >("plughost_GetVersion" );
313  GetChunkSizeInFrames = m_lib.GetSymbol< decltype(plughost_GetChunkSizeInFrames ) >("plughost_GetChunkSizeInFrames" );
314  GetChannelCount = m_lib.GetSymbol< decltype(plughost_GetChannelCount ) >("plughost_GetChannelCount" );
315  GetAudioInputCount = m_lib.GetSymbol< decltype(plughost_GetAudioInputCount ) >("plughost_GetAudioInputCount" );
316  GetAudioOutputCount = m_lib.GetSymbol< decltype(plughost_GetAudioOutputCount ) >("plughost_GetAudioOutputCount" );
317  GetSampleRate = m_lib.GetSymbol< decltype(plughost_GetSampleRate ) >("plughost_GetSampleRate" );
318  SetLoggerCallback = m_lib.GetSymbol< decltype(plughost_SetLoggerCallback ) >("plughost_SetLoggerCallback" );
319  SetLogSeverity = m_lib.GetSymbol< decltype(plughost_SetLogSeverity ) >("plughost_SetLogSeverity" );
320  NewParameters = m_lib.GetSymbol< decltype(plughost_NewParameters ) >("plughost_NewParameters" );
321  FreeParameters = m_lib.GetSymbol< decltype(plughost_FreeParameters ) >("plughost_FreeParameters" );
322  SetParameter = m_lib.GetSymbol< decltype(plughost_SetParameter ) >("plughost_SetParameter" );
323  GetParameter = m_lib.GetSymbol< decltype(plughost_GetParameter ) >("plughost_GetParameter" );
324  FreeParameterValue = m_lib.GetSymbol< decltype(plughost_FreeParameterValue ) >("plughost_FreeParameterValue" );
325  InitProcess = m_lib.GetSymbol< decltype(plughost_InitProcess ) >("plughost_InitProcess" );
326  InitProcess2 = m_lib.GetSymbol< decltype(plughost_InitProcess2 ) >("plughost_InitProcess2" );
327  TerminateProcess = m_lib.GetSymbol< decltype(plughost_TerminateProcess ) >("plughost_TerminateProcess" );
328  ExitProcess = m_lib.GetSymbol< decltype(plughost_ExitProcess ) >("plughost_ExitProcess" );
329  StartUpdateThread = m_lib.GetSymbol< decltype(plughost_StartUpdateThread ) >("plughost_StartUpdateThread" );
330  StopUpdateThread = m_lib.GetSymbol< decltype(plughost_StopUpdateThread ) >("plughost_StopUpdateThread" );
331  WaitUpdateThreadReady = m_lib.GetSymbol< decltype(plughost_WaitUpdateThreadReady ) >("plughost_WaitUpdateThreadReady" );
332  ProcessAudio = m_lib.GetSymbol< decltype(plughost_ProcessAudio ) >("plughost_ProcessAudio" );
333  ProcessAudio_Planar = m_lib.GetSymbol< decltype(plughost_ProcessAudio_Planar ) >("plughost_ProcessAudio_Planar" );
334  GetBufferIn = m_lib.GetSymbol< decltype(plughost_GetBufferIn ) >("plughost_GetBufferIn" );
335  GetBufferOut = m_lib.GetSymbol< decltype(plughost_GetBufferOut ) >("plughost_GetBufferOut" );
336  GetEstimatedDelay = m_lib.GetSymbol< decltype(plughost_GetEstimatedDelay ) >("plughost_GetEstimatedDelay" );
337  GetFormatName = m_lib.GetSymbol< decltype(plughost_GetFormatName ) >("plughost_GetFormatName" );
338  GetFormatFromName = m_lib.GetSymbol< decltype(plughost_GetFormatFromName ) >("plughost_GetFormatFromName" );
339  GetBytesFromFormat = m_lib.GetSymbol< decltype(plughost_GetBytesFromFormat ) >("plughost_GetBytesFromFormat" );
340  GetMaxPacketFrame = m_lib.GetSymbol< decltype(plughost_GetMaxPacketFrame ) >("plughost_GetMaxPacketFrame" );
341  AddAudio = m_lib.GetSymbol< decltype(plughost_AddAudio ) >("plughost_AddAudio" );
342  AddPadAudio = m_lib.GetSymbol< decltype(plughost_AddPadAudio ) >("plughost_AddPadAudio" );
343  GetOutputCount = m_lib.GetSymbol< decltype(plughost_GetOutputCount ) >("plughost_GetOutputCount" );
344  GetAudio = m_lib.GetSymbol< decltype(plughost_GetAudio ) >("plughost_GetAudio" );
345  AudioConvertFrom = m_lib.GetSymbol< decltype(plughost_AudioConvertFrom ) >("plughost_AudioConvertFrom" );
346  AudioConvertTo = m_lib.GetSymbol< decltype(plughost_AudioConvertTo ) >("plughost_AudioConvertTo" );
347  StereoToMono = m_lib.GetSymbol< decltype(plughost_StereoToMono ) >("plughost_StereoToMono" );
348  MonoToStereo = m_lib.GetSymbol< decltype(plughost_MonoToStereo ) >("plughost_MonoToStereo" );
349  AudioMonoFromLiveStereo = m_lib.GetSymbol< decltype(plughost_AudioMonoFromLiveStereo) >("plughost_AudioMonoFromLiveStereo");
350  AudioMonoToLiveStereo = m_lib.GetSymbol< decltype(plughost_AudioMonoToLiveStereo ) >("plughost_AudioMonoToLiveStereo" );
351  NewClient = m_lib.GetSymbol< decltype(plughost_NewClient ) >("plughost_NewClient" );
352  DeleteClient = m_lib.GetSymbol< decltype(plughost_DeleteClient ) >("plughost_DeleteClient" );
353  ProcessJson = m_lib.GetSymbol< decltype(plughost_ProcessJson ) >("plughost_ProcessJson" );
354  FreeJsonAnswer = m_lib.GetSymbol< decltype(plughost_FreeJsonAnswer ) >("plughost_FreeJsonAnswer" );
355  SaveState = m_lib.GetSymbol< decltype(plughost_SaveState ) >("plughost_SaveState" );
356 #if PLUGHOST_HAS_WEBSERVER
357  Webserver_tcp = m_lib.GetSymbol< decltype(plughost_Webserver_tcp ) >("plughost_Webserver_tcp" );
358  Webserver_tcp2 = m_lib.GetSymbol< decltype(plughost_Webserver_tcp2 ) >("plughost_Webserver_tcp2" );
359  Webserver = m_lib.GetSymbol< decltype(plughost_Webserver ) >("plughost_Webserver" );
360  Webserver_Stop = m_lib.GetSymbol< decltype(plughost_Webserver_Stop ) >("plughost_Webserver_Stop" );
361  Webserver_Status = m_lib.GetSymbol< decltype(plughost_Webserver_Status ) >("plughost_Webserver_Status" );
362 #endif // PLUGHOST_HAS_WEBSERVER
363 
364  // added 2023-03-22
365  StereoToMono_Planar = m_lib.GetSymbol< decltype(plughost_StereoToMono_Planar ) >("plughost_StereoToMono_Planar" );
366  MonoToStereo_Planar = m_lib.GetSymbol< decltype(plughost_MonoToStereo_Planar ) >("plughost_MonoToStereo_Planar" );
367 
368  } catch (std::runtime_error& ) {
369  return false;
370  }
371  // C functions allowed to be missing
372  try {
373  // added 2023-05-22
374  SetMetadata = m_lib.GetSymbol< decltype(plughost_SetMetadata ) >("plughost_SetMetadata" );
375  GetMetadataInfos = m_lib.GetSymbol< decltype(plughost_GetMetadataInfos ) >("plughost_GetMetadataInfos" );
376  FreeMetadataInfos = m_lib.GetSymbol< decltype(plughost_FreeMetadataInfos ) >("plughost_FreeMetadataInfos" );
377  // added 2023-06-20
378  SetPresetManager = m_lib.GetSymbol< decltype(plughost_SetPresetManager ) >("plughost_SetPresetManager" );
379  PresetManager_InformChange = m_lib.GetSymbol< decltype(plughost_PresetManager_InformChange ) >("plughost_PresetManager_InformChange" );
380 
381  // added 2023-09-21
382  GetPossibleChunkSizeInFrames = m_lib.GetSymbol< decltype(plughost_GetPossibleChunkSizeInFrames ) >("plughost_GetPossibleChunkSizeInFrames" );
383  GetProcessChunkFrames = m_lib.GetSymbol< decltype(plughost_GetProcessChunkFrames ) >("plughost_GetProcessChunkFrames" );
384  InitProcess3 = m_lib.GetSymbol< decltype(plughost_InitProcess3 ) >("plughost_InitProcess3" );
385 
386 #if PLUGHOST_HAS_CLOUDBUS
387  // added 2023-06-26
388  NewBus = m_lib.GetSymbol< decltype(plughost_NewBus ) >("plughost_NewBus" );
389  FreeBus = m_lib.GetSymbol< decltype(plughost_FreeBus ) >("plughost_FreeBus" );
390  SetInstanceBus = m_lib.GetSymbol< decltype(plughost_SetInstanceBus ) >("plughost_SetInstanceBus" );
391 #endif // PLUGHOST_HAS_CLOUDBUS
392  } catch (std::runtime_error& ) {
393  // Ignored, handler will take care
394  }
395 
396  m_bOK=true;
397  return true;
398  }
405  bool IsOk() const {
406  return m_bOK;
407  }
408 
409  };
410 
411 
412 
413  static constexpr const char *process_name = "SOUND4 Plugin Host";
414  static constexpr const char *process_shortname = "plughost";
440 
444  namespace helper {
445  #ifdef _WIN32
451  static inline std::string WStringToUTF8(const std::wstring& wstr) {
452  if (wstr.empty()) return {};
453  int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
454  std::string str(size, 0);
455  WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size, NULL, NULL);
456  return str;
457  }
463  static inline std::wstring UTF8ToWString(const std::string& str) {
464  if (str.empty()) return std::wstring();
465  int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
466  std::wstring wstr(size, 0);
467  MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size);
468  return wstr;
469  }
470  #endif // _WIN32
471 
477  template<typename T>
478  struct SampleFormat {
479  };
480  template<>
481  struct SampleFormat<int16_t> {
483  };
484  template<>
485  struct SampleFormat<int32_t> {
487  };
488  template<>
489  struct SampleFormat<float> {
491  };
492 
493 
498  static inline void AudioConvertFrom(CDynLib& dynlib, const uint8_t *payload, float *output, size_t nSpl, plughost_SampleFormat fmt) {
499  dynlib.AudioConvertFrom(payload, output, nSpl, fmt);
500  }
501  static inline void AudioConvertTo(CDynLib& dynlib, const float *input, uint8_t *payload, size_t nSpl, plughost_SampleFormat fmt) {
502  dynlib.AudioConvertTo(input, payload, nSpl, fmt);
503  }
504  static inline void StereoToMono(CDynLib& dynlib, const float *input, float *output, size_t nSpl) {
505  dynlib.StereoToMono(input, output, nSpl);
506  }
507  static inline void MonoToStereo(CDynLib& dynlib, const float *input, float *output, size_t nSpl) {
508  dynlib.MonoToStereo(input, output, nSpl);
509  }
510  static inline void StereoToMono_Planar(CDynLib& dynlib, const float *inputL, const float *inputR, float *output, size_t nSpl) {
511  dynlib.StereoToMono_Planar(inputL, inputR, output, nSpl);
512  }
513  static inline void MonoToStereo_Planar(CDynLib& dynlib, const float *input, float *outputL, float *outputR, size_t nSpl) {
514  dynlib.MonoToStereo_Planar(input, outputL, outputR, nSpl);
515  }
516  static inline void AudioMonoFromLiveStereo(CDynLib& dynlib, const uint8_t *payload, float *output) {
517  dynlib.AudioMonoFromLiveStereo(payload, output);
518  }
519  static inline void AudioMonoToLiveStereo(CDynLib& dynlib, const float *input, uint8_t *payload) {
520  dynlib.AudioMonoToLiveStereo(input, payload);
521  }
522 
523  }; // namespace helper
524 
530  static inline std::string GetVersion(CDynLib& dynlib)
531  {
532  return std::string(dynlib.GetVersion());
533  }
534 
545  static inline unsigned int GetChunkSizeInFrames(CDynLib& dynlib)
546  {
547  return dynlib.GetChunkSizeInFrames();
548  }
549 
558  static inline std::vector<unsigned int> GetPossibleChunkSizeInFrames(CDynLib& dynlib)
559  {
560  std::vector<unsigned int> list;
561  if (dynlib.GetPossibleChunkSizeInFrames) {
562  for (unsigned int* src=dynlib.GetPossibleChunkSizeInFrames();*src;src++) {
563  list.push_back(*src);
564  }
565  } else {
566  list.push_back(64);
567  }
568  return list;
569  }
570 
578  static inline unsigned int GetChannelCount(CDynLib& dynlib)
579  {
580  return dynlib.GetChannelCount();
581  }
582 
591  static inline unsigned int GetAudioInputCount(CDynLib& dynlib)
592  {
593  return dynlib.GetAudioInputCount();
594  }
595 
604  static inline unsigned int GetAudioOutputCount(CDynLib& dynlib)
605  {
606  return dynlib.GetAudioOutputCount();
607  }
608 
616  static inline unsigned int GetSampleRate(CDynLib& dynlib)
617  {
618  return dynlib.GetSampleRate();
619  }
620 
626  static inline void SanityCheck(CDynLib& dynlib, bool a_bCheckFrames = true)
627  {
628  // Do some sanity checks
629  if (dynlib.GetSampleRate()!=PLUGHOST_SAMPLE_RATE) {
630  throw std::runtime_error("Bad library sampling rate");
631  }
632  if (a_bCheckFrames && dynlib.GetChunkSizeInFrames()!=ChunkFrames) {
633  throw std::runtime_error("Bad library frame size");
634  }
635  if (dynlib.GetChannelCount()!=PLUGHOST_CHANNEL_COUNT) {
636  throw std::runtime_error("Bad library channel count");
637  }
638  if (dynlib.GetAudioInputCount()!=PLUGHOST_AUDIO_INPUT_COUNT) {
639  throw std::runtime_error("Bad library input count");
640  }
641  if (dynlib.GetAudioOutputCount()!=PLUGHOST_AUDIO_OUTPUT_COUNT) {
642  throw std::runtime_error("Bad library output count");
643  }
644  }
645 
652  static inline std::string GetFormatName(CDynLib& dynlib, const SampleFormat fmt)
653  {
654  return std::string(dynlib.GetFormatName(fmt));
655  }
656 
663  static inline SampleFormat GetFormatFromName(CDynLib& dynlib, const std::string& name)
664  {
665  return dynlib.GetFormatFromName(name.c_str());
666  }
667 
674  static inline unsigned int GetBytesFromFormat(CDynLib& dynlib, const SampleFormat fmt)
675  {
676  return dynlib.GetBytesFromFormat(fmt);
677  }
678 
686  using log_cb_t = std::function<void(LogSeverity,const std::string&)>;
687 
691  static log_cb_t _log_cb;
692  extern "C" {
693  static inline void _log_cb_c(plughost_LogSeverity severity, const char *c_msg) {
694  _log_cb(severity, std::string(c_msg));
695  }
696  }
700  static inline void SetLogSeverity(CDynLib& dynlib, LogSeverity severity)
701  {
702  dynlib.SetLogSeverity(severity);
703  }
707  static inline void SetLoggerCallback(CDynLib& dynlib, log_cb_t cb)
708  {
709  _log_cb=cb;
710  dynlib.SetLoggerCallback(&_log_cb_c);
711  }
712 
713 #if PLUGHOST_HAS_CLOUDBUS
714  class CBus {
715  public:
716  CBus(CDynLib& dynlib)
717  : m_dynlib(dynlib)
718  {
719  if (m_dynlib.NewBus) {
720  m_bus=m_dynlib.NewBus();
721  }
722  }
723  ~CBus()
724  {
725  if (m_bus && m_dynlib.FreeBus) {
726  m_dynlib.FreeBus(m_bus);
727  }
728  m_bus = nullptr;
729  }
730  plughost_CBus *Get() const { return m_bus; }
731  private:
732  CDynLib& m_dynlib;
733  plughost_CBus *m_bus;
734  };
735 #endif // PLUGHOST_HAS_CLOUDBUS
736 
742  public:
743  CPresetLoader() = default;
744  virtual ~CPresetLoader() = default;
745 
746  virtual bool IsReadOnly() = 0;
747  virtual bool Exists(const std::filesystem::path &name) = 0;
748  virtual bool Remove(const std::filesystem::path &name) = 0;
749  virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to) = 0;
750  virtual std::vector<std::filesystem::path> GetAll() = 0;
751  virtual std::string Read(const std::filesystem::path &filename) = 0;
752  virtual bool Write(const std::filesystem::path &filename, const std::string &content) =0;
753  };
755 
759  class CInstance {
760  public:
765  : m_dynlib(dynlib)
766  {
767  params = m_dynlib.NewParameters();
768  if (!params) throw std::bad_alloc();
769  }
770  // non-copyable
771  CInstance( const CInstance& ) = delete;
772  CInstance& operator=( const CInstance& ) = delete;
777  {
778  Stop();
779  if (params) m_dynlib.FreeParameters(params);
780  }
784  bool IsOk() const { return instance!=nullptr; }
792  void SetParam(const std::string& name, const std::string& value)
793  {
794  assert(params);
795  m_dynlib.SetParameter(params, name.c_str(), value.c_str());
796  }
802  std::string GetParam(const std::string& name)
803  {
804  assert(params);
805  auto c_value=m_dynlib.GetParameter(params, name.c_str());
806  std::string ret(c_value);
807  m_dynlib.FreeParameterValue(c_value);
808  return ret;
809  }
810 #if PLUGHOST_HAS_CLOUDBUS
814  void SetBus(const CBus& bus) {
815  assert(params);
816  if (m_dynlib.SetInstanceBus) {
817  m_dynlib.SetInstanceBus(params,bus.Get());
818  }
819  }
820 #endif // PLUGHOST_HAS_CLOUDBUS
821 
831  void SetPresetManager(CPresetLoader *preset_manager)
832  {
833  if (!preset_manager) return;
834  if (!m_dynlib.SetPresetManager) return;
835  assert(params);
836  m_dynlib.SetPresetManager(params,
837  plughost_custom_reader,
838  plughost_custom_reader_free,
839  plughost_custom_writer,
840  plughost_custom_exists,
841  plughost_custom_getall,
842  plughost_custom_getall_free,
843  plughost_custom_remove,
844  plughost_custom_rename,
845  preset_manager->IsReadOnly(),
846  preset_manager
847  );
848  }
849 
864  bool Create(const std::string& LoginKey, const std::string& RadioName, const std::string& AWS_Access_ID, const std::string& AWS_Access_Secret, const std::filesystem::path& save_path, int json_port = 0, unsigned int frames_per_chunk=64)
865  {
866  assert(!instance);
867  std::string l_save_path;
868  if (!save_path.empty()) {
869  l_save_path = save_path.u8string();
870  }
871  if (m_dynlib.InitProcess3) {
872  instance = m_dynlib.InitProcess3(LoginKey.c_str(), RadioName.c_str(), AWS_Access_ID.c_str(), AWS_Access_Secret.c_str(), l_save_path.c_str(), params, frames_per_chunk);
873  } else if (frames_per_chunk!=64) {
874  return false;
875  } else {
876  instance = m_dynlib.InitProcess2(LoginKey.c_str(), RadioName.c_str(), AWS_Access_ID.c_str(), AWS_Access_Secret.c_str(), l_save_path.c_str(), params);
877  }
878  if (!instance) return false;
879  if (!init_metadata.empty()) {
880  for (auto&& [key,value]: init_metadata) {
881  m_dynlib.SetMetadata(instance, key.c_str(), value.c_str());
882  }
883  init_metadata.clear();
884  }
885  update_thread = std::thread([this, json_port](){
887  m_dynlib.StartUpdateThread(instance, json_port);
889  });
890  int timeout=5000;
891  #ifdef DEBUG
892  timeout=60*1000; // For debugger pauses
893  #endif
894  if (m_dynlib.WaitUpdateThreadReady(instance, timeout)<0) {
895  return false;
896  }
897  return true;
898  }
899 
907  unsigned int GetChunkFrames() {
908  if (instance && m_dynlib.GetProcessChunkFrames) {
909  return m_dynlib.GetProcessChunkFrames(instance);
910  }
911  return 64;
912  }
913 
921  void PresetManager_InformChange(const std::filesystem::path& relative_path, PresetChange_Kind change_kind)
922  {
923  if (m_dynlib.PresetManager_InformChange) {
924  m_dynlib.PresetManager_InformChange(instance, relative_path.c_str(), (plughost_PresetChange_Kind) change_kind);
925  }
926  }
927 
939  void SetMetadata(const std::string& key, const char* value)
940  {
941  if (m_dynlib.SetMetadata) {
942  if (instance) {
943  m_dynlib.SetMetadata(instance, key.c_str(), value);
944  } else {
945  init_metadata.push_back( {key, value} );
946  }
947  }
948  }
949 
955  std::vector< std::tuple<std::string,std::string> > GetMetadataInfos()
956  {
957  std::vector< std::tuple<std::string,std::string> > values;
958  if (m_dynlib.GetMetadataInfos) {
959  const char** c_values = m_dynlib.GetMetadataInfos(instance);
960  if (c_values) {
961  for (const char** c_value=c_values; *c_value; ) {
962  std::string key(*c_value);
963  c_value++;
964  if (*c_value) {
965  std::string descr(*c_value);
966  c_value++;
967  values.push_back( {key,descr} );
968  }
969  }
970  m_dynlib.FreeMetadataInfos(instance, c_values);
971  }
972  }
973  return values;
974  }
975 
976  // Can be overloaded, called at start of UpdateThread in the thread
977  virtual void OnUpdateThreadStart() {}
978  // Can be overloaded to call at end of UpdateThread in the thread
979  virtual void OnUpdateThreadStop() {}
980 
981 #if PLUGHOST_HAS_WEBSERVER
987  bool StartWebServer(int http_port, int https_port=0)
988  {
989  assert(instance);
990  assert(webserver==SOUND4_INVALID_WEBSERVER_ID);
991  webserver = m_dynlib.Webserver(http_port,https_port,instance);
992  if (webserver==SOUND4_INVALID_WEBSERVER_ID) {
993  return false;
994  }
995  int web_status=m_dynlib.Webserver_Status(webserver);
996  if (http_port && (web_status & SOUND4_WEBSERVER_HTTP_OK) == 0) {
997  return false;
998  }
999  if (https_port && (web_status & SOUND4_WEBSERVER_HTTPS_OK) == 0) {
1000  return false;
1001  }
1002  return true;
1003  }
1010  {
1011  if (webserver != SOUND4_INVALID_WEBSERVER_ID) {
1012  m_dynlib.Webserver_Stop(webserver, 1000);
1013  webserver = SOUND4_INVALID_WEBSERVER_ID;
1014  }
1015  }
1016 #endif // PLUGHOST_HAS_WEBSERVER
1017 
1025  {
1026  if (!instance) return 0;
1027  return m_dynlib.TerminateProcess(instance);
1028  }
1029 
1035  void Stop()
1036  {
1037  if (!instance) return;
1038 #if PLUGHOST_HAS_WEBSERVER
1039  StopWebServer();
1040 #endif // PLUGHOST_HAS_WEBSERVER
1041  if (update_thread.joinable()) {
1042  m_dynlib.StopUpdateThread(instance); // this will exit the update thread
1043  update_thread.join();
1044  }
1045  m_dynlib.ExitProcess(instance);
1046  instance=nullptr;
1047  }
1048 
1054  unsigned int GetEstimatedDelay()
1055  {
1056  assert(instance);
1057  return m_dynlib.GetEstimatedDelay(instance);
1058  }
1059 
1070  std::array<float,InputSampleSize>& GetBufferIn()
1071  {
1072  assert(instance);
1073  float *buf=m_dynlib.GetBufferIn(instance);
1074  return reinterpret_cast< std::array<float,InputSampleSize>& >(*buf);
1075 
1076  }
1087  std::array<float,OutputSampleSize>& GetBufferOut()
1088  {
1089  assert(instance);
1090  float *buf= m_dynlib.GetBufferOut(instance);
1091  return reinterpret_cast< std::array<float,OutputSampleSize>& >(*buf);
1092  }
1099  {
1100  assert(instance);
1101  m_dynlib.ProcessAudio(instance, m_dynlib.GetBufferIn(instance), m_dynlib.GetBufferOut(instance));
1102  }
1116  // void ProcessAudio_Planar(const std::array< const std::array<const float,ChunkFrames>, InputChannels>& input, std::array< std::array<float,ChunkFrames>, OutputChannels>& output)
1117  void ProcessAudio_Planar(float const * const *input, float * const *output)
1118  {
1119  assert(instance);
1120  m_dynlib.ProcessAudio_Planar(instance, input, output);
1121  }
1122 
1134  template<typename T>
1135  std::vector<T> ProcessAnyAudio(const std::vector<T> input)
1136  {
1137  assert(instance);
1138  std::vector<T> output;
1139  unsigned int out_offset=0;
1140  unsigned int in_offset=0;
1141  unsigned int todo = input.size();
1142  while (todo>0) {
1143  unsigned int left = AddAudio(&input[in_offset], todo);
1144  unsigned int out_avail = m_dynlib.GetOutputCount(instance);
1145  output.resize(out_offset + out_avail);
1146  GetAudio(&output[out_offset], out_avail);
1147  out_offset+=out_avail;
1148  in_offset += todo-left;
1149  todo=left;
1150  }
1151  return output;
1152  }
1153 
1159  class CClient {
1160  public:
1161  CClient(plughost_CInstance* instance, CDynLib& dynlib)
1162  : m_dynlib(dynlib)
1163  {
1164  assert(instance);
1165  client=m_dynlib.NewClient(instance);
1166  if (!client) throw std::bad_alloc();
1167  }
1168  // non-copyable
1169  CClient( const CInstance& ) = delete;
1170  CClient& operator=( const CInstance& ) = delete;
1172  {
1173  if (client) {
1174  m_dynlib.DeleteClient(client);
1175  client=nullptr;
1176  }
1177  }
1185  std::string ProcessJson(const std::string &request, bool *NeedSave = nullptr)
1186  {
1187  assert(client);
1188  int need_save=0;
1189  const char *canswer = m_dynlib.ProcessJson(client, request.c_str(), &need_save);
1190  if (!canswer) return {};
1191  std::string answer(canswer);
1192  m_dynlib.FreeJsonAnswer (canswer);
1193  if (NeedSave) {
1194  *NeedSave=(need_save!=0);
1195  }
1196  return answer;
1197  }
1198  private:
1199  CDynLib& m_dynlib;
1200  plughost_CClientInstance *client = nullptr;
1201  };
1209  std::shared_ptr<CClient> NewClient()
1210  {
1211  assert(instance);
1212  return std::make_shared<CClient>(instance, m_dynlib);
1213  }
1214 
1215  protected:
1216  template<typename T>
1217  unsigned int AddAudio(const T* payload, unsigned int nFrame)
1218  {
1219  assert(instance);
1220  return m_dynlib.AddAudio(instance, reinterpret_cast<const T*>(payload), nFrame, helper::SampleFormat<T>::format);
1221  }
1222  template<typename T>
1223  unsigned int GetAudio(T* payload, unsigned int max_nFrame)
1224  {
1225  assert(instance);
1226  return m_dynlib.GetAudio(instance, reinterpret_cast<T*>(payload), max_nFrame, helper::SampleFormat<T>::format);
1227  }
1228 
1229  private:
1230  CDynLib& m_dynlib;
1231  plughost_CParameters* params = nullptr;
1232  plughost_CInstance* instance = nullptr;
1233  std::thread update_thread;
1234  std::vector< std::pair<std::string,std::string> > init_metadata;
1235 #if PLUGHOST_HAS_WEBSERVER
1236  uint64_t webserver = SOUND4_INVALID_WEBSERVER_ID;
1237 #endif // PLUGHOST_HAS_WEBSERVER
1238  };
1239 
1240 }; // namespace dyn
1241 }; // namespace plughost
1242 }; // namespace sound4
1243 
1244 
1245 // bridge C callbacks to CPresetLoader
1246 extern "C" {
1247  static char *plughost_custom_reader(const fs_char *filename, void* userdata) {
1248  sound4::plughost::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::plughost::dyn::CPresetLoader*>(userdata);
1249  std::string content=preset_loader->Read(filename);
1250  return strdup(content.c_str());
1251  }
1252  static void plughost_custom_reader_free(char *content, void* userdata) {
1253  if (!content) return;
1254  free(content);
1255  }
1256  static int plughost_custom_writer(const fs_char *filename, const char *content, void* userdata) {
1257  sound4::plughost::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::plughost::dyn::CPresetLoader*>(userdata);
1258  auto res=preset_loader->Write(filename,content);
1259  return res?0:-1;
1260  }
1261  static int plughost_custom_exists(const fs_char *filename, void* userdata) {
1262  sound4::plughost::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::plughost::dyn::CPresetLoader*>(userdata);
1263  auto res=preset_loader->Exists(filename);
1264  return res?0:-1;
1265  }
1266  static fs_char** plughost_custom_getall(void* userdata) {
1267  sound4::plughost::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::plughost::dyn::CPresetLoader*>(userdata);
1268  auto res=preset_loader->GetAll();
1269  fs_char**all=(fs_char**)malloc((res.size()+1)*sizeof(const fs_char*));
1270  for (size_t n=0;n<res.size();n++) {
1271  all[n]=fs_strdup(res[n].c_str());
1272  }
1273  all[res.size()]=nullptr;
1274  return all;
1275  }
1276  static void plughost_custom_getall_free(fs_char** all, void* userdata) {
1277  if (!all) return;
1278  for (fs_char** one=all;*one;one++) {
1279  free(*one);
1280  }
1281  free(all);
1282  }
1283  static int plughost_custom_remove(const fs_char *filename, void* userdata) {
1284  sound4::plughost::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::plughost::dyn::CPresetLoader*>(userdata);
1285  auto res=preset_loader->Remove(filename);
1286  return res?0:-1;
1287  }
1288  static int plughost_custom_rename(const fs_char *from, const fs_char *to, void* userdata) {
1289  sound4::plughost::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::plughost::dyn::CPresetLoader*>(userdata);
1290  auto res=preset_loader->Rename(from,to);
1291  return res?0:-1;
1292  }
1293 
1294 };
helper::DynFuncHolder< decltype(plughost_StartUpdateThread) > StartUpdateThread
helper::DynFuncHolder< decltype(plughost_ProcessAudio_Planar) > ProcessAudio_Planar
helper::DynFuncHolder< decltype(plughost_ProcessAudio) > ProcessAudio
helper::DynFuncHolder< decltype(plughost_DeleteClient) > DeleteClient
helper::DynFuncHolder< decltype(plughost_AudioConvertFrom) > AudioConvertFrom
helper::DynFuncHolder< decltype(plughost_GetFormatFromName) > GetFormatFromName
helper::DynFuncHolder< decltype(plughost_SetMetadata) > SetMetadata
bool Load(const std::filesystem::path &path=std::filesystem::current_path())
Loads the library.
helper::DynFuncHolder< decltype(plughost_InitProcess) > InitProcess
helper::DynFuncHolder< decltype(plughost_GetBufferOut) > GetBufferOut
helper::DynFuncHolder< decltype(plughost_GetOutputCount) > GetOutputCount
helper::DynFuncHolder< decltype(plughost_GetAudioInputCount) > GetAudioInputCount
helper::DynFuncHolder< decltype(plughost_SetPresetManager) > SetPresetManager
helper::DynFuncHolder< decltype(plughost_TerminateProcess) > TerminateProcess
helper::DynFuncHolder< decltype(plughost_SetLoggerCallback) > SetLoggerCallback
helper::DynFuncHolder< decltype(plughost_GetAudio) > GetAudio
helper::DynFuncHolder< decltype(plughost_FreeMetadataInfos) > FreeMetadataInfos
helper::DynFuncHolder< decltype(plughost_StereoToMono_Planar) > StereoToMono_Planar
helper::DynFuncHolder< decltype(plughost_InitProcess3) > InitProcess3
helper::DynFuncHolder< decltype(plughost_ExitProcess) > ExitProcess
helper::DynFuncHolder< decltype(plughost_GetBufferIn) > GetBufferIn
helper::DynFuncHolder< decltype(plughost_SetLogSeverity) > SetLogSeverity
helper::DynFuncHolder< decltype(plughost_AddPadAudio) > AddPadAudio
helper::DynFuncHolder< decltype(plughost_Webserver) > Webserver
helper::DynFuncHolder< decltype(plughost_StereoToMono) > StereoToMono
helper::DynFuncHolder< decltype(plughost_Webserver_tcp) > Webserver_tcp
helper::DynFuncHolder< decltype(plughost_NewParameters) > NewParameters
helper::DynFuncHolder< decltype(plughost_GetAudioOutputCount) > GetAudioOutputCount
helper::DynFuncHolder< decltype(plughost_GetProcessChunkFrames) > GetProcessChunkFrames
helper::DynFuncHolder< decltype(plughost_GetFormatName) > GetFormatName
helper::DynFuncHolder< decltype(plughost_Webserver_Status) > Webserver_Status
helper::DynFuncHolder< decltype(plughost_GetChunkSizeInFrames) > GetChunkSizeInFrames
helper::DynFuncHolder< decltype(plughost_GetChannelCount) > GetChannelCount
helper::DynFuncHolder< decltype(plughost_GetBytesFromFormat) > GetBytesFromFormat
helper::DynFuncHolder< decltype(plughost_PresetManager_InformChange) > PresetManager_InformChange
helper::DynFuncHolder< decltype(plughost_Webserver_tcp2) > Webserver_tcp2
bool IsOk() const
Check if the library was loaded correctly.
helper::DynFuncHolder< decltype(plughost_GetMetadataInfos) > GetMetadataInfos
helper::DynFuncHolder< decltype(plughost_GetVersion) > GetVersion
helper::DynFuncHolder< decltype(plughost_StopUpdateThread) > StopUpdateThread
helper::DynFuncHolder< decltype(plughost_SetParameter) > SetParameter
helper::DynFuncHolder< decltype(plughost_SaveState) > SaveState
helper::DynFuncHolder< decltype(plughost_AudioMonoToLiveStereo) > AudioMonoToLiveStereo
helper::DynFuncHolder< decltype(plughost_GetEstimatedDelay) > GetEstimatedDelay
helper::DynFuncHolder< decltype(plughost_GetMaxPacketFrame) > GetMaxPacketFrame
helper::DynFuncHolder< decltype(plughost_InitProcess2) > InitProcess2
helper::DynFuncHolder< decltype(plughost_GetPossibleChunkSizeInFrames) > GetPossibleChunkSizeInFrames
helper::DynFuncHolder< decltype(plughost_NewClient) > NewClient
helper::DynFuncHolder< decltype(plughost_GetParameter) > GetParameter
helper::DynFuncHolder< decltype(plughost_FreeParameterValue) > FreeParameterValue
helper::DynFuncHolder< decltype(plughost_AudioMonoFromLiveStereo) > AudioMonoFromLiveStereo
helper::DynFuncHolder< decltype(plughost_FreeParameters) > FreeParameters
helper::DynFuncHolder< decltype(plughost_AddAudio) > AddAudio
helper::DynFuncHolder< decltype(plughost_WaitUpdateThreadReady) > WaitUpdateThreadReady
helper::DynFuncHolder< decltype(plughost_MonoToStereo_Planar) > MonoToStereo_Planar
helper::DynFuncHolder< decltype(plughost_FreeJsonAnswer) > FreeJsonAnswer
helper::DynFuncHolder< decltype(plughost_Webserver_Stop) > Webserver_Stop
helper::DynFuncHolder< decltype(plughost_GetSampleRate) > GetSampleRate
helper::DynFuncHolder< decltype(plughost_MonoToStereo) > MonoToStereo
helper::DynFuncHolder< decltype(plughost_AudioConvertTo) > AudioConvertTo
helper::DynFuncHolder< decltype(plughost_ProcessJson) > ProcessJson
CClient & operator=(const CInstance &)=delete
CClient(plughost_CInstance *instance, CDynLib &dynlib)
std::string ProcessJson(const std::string &request, bool *NeedSave=nullptr)
Process a JSON request and returns the answer.
CInstance & operator=(const CInstance &)=delete
bool Create(const std::string &LoginKey, const std::string &RadioName, const std::string &AWS_Access_ID, const std::string &AWS_Access_Secret, const std::filesystem::path &save_path, int json_port=0, unsigned int frames_per_chunk=64)
std::array< float, InputSampleSize > & GetBufferIn()
unsigned int AddAudio(const T *payload, unsigned int nFrame)
std::vector< T > ProcessAnyAudio(const std::vector< T > input)
void SetPresetManager(CPresetLoader *preset_manager)
std::shared_ptr< CClient > NewClient()
std::vector< std::tuple< std::string, std::string > > GetMetadataInfos()
std::string GetParam(const std::string &name)
bool StartWebServer(int http_port, int https_port=0)
void SetParam(const std::string &name, const std::string &value)
unsigned int GetAudio(T *payload, unsigned int max_nFrame)
void SetMetadata(const std::string &key, const char *value)
CInstance(const CInstance &)=delete
void PresetManager_InformChange(const std::filesystem::path &relative_path, PresetChange_Kind change_kind)
std::array< float, OutputSampleSize > & GetBufferOut()
void ProcessAudio_Planar(float const *const *input, float *const *output)
virtual bool Write(const std::filesystem::path &filename, const std::string &content)=0
virtual bool Exists(const std::filesystem::path &name)=0
virtual std::vector< std::filesystem::path > GetAll()=0
virtual bool Remove(const std::filesystem::path &name)=0
virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to)=0
virtual std::string Read(const std::filesystem::path &filename)=0
CDynLoader & operator=(CDynLoader const &)=delete
DynFuncHolder< T > GetSymbol(const std::string &name)
static std::filesystem::path GetThisLibraryPath(void)
CDynLoader(const CDynLoader &)=delete
bool Load(const std::filesystem::path &dynlib, uint32_t loadflags=LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|LOAD_LIBRARY_SEARCH_APPLICATION_DIR|LOAD_LIBRARY_SEARCH_USER_DIRS|LOAD_LIBRARY_SEARCH_SYSTEM32)
enum plughost_SampleFormat plughost_GetFormatFromName(const char *name)
unsigned int plughost_GetOutputCount(struct plughost_CInstance *instance)
unsigned int plughost_GetBytesFromFormat(const enum plughost_SampleFormat fmt)
unsigned int plughost_AddAudio(struct plughost_CInstance *instance, const uint8_t *payload, unsigned int nFrame, enum plughost_SampleFormat fmt)
unsigned int plughost_GetMaxPacketFrame(struct plughost_CInstance *instance)
unsigned int plughost_AddPadAudio(struct plughost_CInstance *instance)
plughost_SampleFormat
unsigned int plughost_GetAudio(struct plughost_CInstance *instance, uint8_t *payload, unsigned int max_nFrame, enum plughost_SampleFormat fmt)
const char * plughost_GetFormatName(const enum plughost_SampleFormat fmt)
@ F32_NATIVE
32-bit floating-point, native
@ S16_NATIVE
16-bit signed integer, native
@ S32_NATIVE
32-bit signed integer, native
void plughost_DeleteClient(struct plughost_CClientInstance *client)
void plughost_FreeJsonAnswer(const char *json_str)
struct plughost_CClientInstance * plughost_NewClient(struct plughost_CInstance *instance)
int plughost_SaveState(struct plughost_CInstance *instance)
const char * plughost_ProcessJson(struct plughost_CClientInstance *client, const char *json_str, int *need_save)
void plughost_AudioConvertFrom(const uint8_t *payload, float *output, size_t nSpl, enum plughost_SampleFormat fmt)
void plughost_StereoToMono(const float *input, float *output, size_t nFrame)
void plughost_MonoToStereo(const float *input, float *output, size_t nFrame)
void plughost_AudioMonoToLiveStereo(const float *input, uint8_t *payload)
void plughost_StereoToMono_Planar(const float *inputL, const float *inputR, float *output, size_t nFrame)
void plughost_AudioConvertTo(const float *input, uint8_t *payload, size_t nSpl, enum plughost_SampleFormat fmt)
void plughost_MonoToStereo_Planar(const float *input, float *outputL, float *outputR, size_t nFrame)
void plughost_AudioMonoFromLiveStereo(const uint8_t *payload, float *output)
float * plughost_GetBufferIn(struct plughost_CInstance *instance)
void plughost_ProcessAudio_Planar(struct plughost_CInstance *instance, float const *const *input, float *const *output)
void plughost_ProcessAudio(struct plughost_CInstance *instance, const float *input, float *output)
float * plughost_GetBufferOut(struct plughost_CInstance *instance)
unsigned int plughost_GetEstimatedDelay(struct plughost_CInstance *instance)
unsigned int plughost_GetAudioOutputCount()
#define PLUGHOST_CHANNEL_COUNT
plughost_LogSeverity
const char * plughost_GetVersion()
unsigned int plughost_GetSampleRate()
#define PLUGHOST_AUDIO_INPUT_COUNT
unsigned int plughost_GetChannelCount()
unsigned int * plughost_GetPossibleChunkSizeInFrames()
#define PLUGHOST_AUDIOFRAME_COUNT
void plughost_SetLogSeverity(enum plughost_LogSeverity severity)
unsigned int plughost_GetAudioInputCount()
#define PLUGHOST_AUDIO_OUTPUT_COUNT
#define PLUGHOST_SAMPLE_RATE
unsigned int plughost_GetChunkSizeInFrames()
void plughost_SetLoggerCallback(plughost_loggerfn logger)
const char * plughost_GetParameter(struct plughost_CParameters *params, const char *name)
void plughost_FreeParameterValue(const char *value)
int plughost_TerminateProcess(struct plughost_CInstance *instance)
struct plughost_CParameters * plughost_NewParameters()
struct plughost_CInstance * plughost_InitProcess(const char *LoginKey, const char *RadioName, const char *AWS_Access_ID, const char *AWS_Access_Secret, const char *save_path)
struct plughost_CInstance * plughost_InitProcess3(const char *LoginKey, const char *RadioName, const char *AWS_Access_ID, const char *AWS_Access_Secret, const char *save_path, const struct plughost_CParameters *parameters, unsigned int frames_per_chunk)
void plughost_ExitProcess(struct plughost_CInstance *instance)
void plughost_FreeParameters(struct plughost_CParameters *params)
void plughost_SetParameter(struct plughost_CParameters *params, const char *name, const char *value)
struct plughost_CInstance * plughost_InitProcess2(const char *LoginKey, const char *RadioName, const char *AWS_Access_ID, const char *AWS_Access_Secret, const char *save_path, const struct plughost_CParameters *parameters)
unsigned int plughost_GetProcessChunkFrames(struct plughost_CInstance *instance)
void plughost_SetMetadata(struct plughost_CInstance *instance, const char *key, const char *value)
const char ** plughost_GetMetadataInfos(struct plughost_CInstance *instance)
void plughost_FreeMetadataInfos(struct plughost_CInstance *instance, const char **infos)
void plughost_SetPresetManager(struct plughost_CParameters *params, plughost_storage_reader reader, plughost_storage_reader_free, plughost_storage_writer writer, plughost_storage_exists exists, plughost_storage_getall getall, plughost_storage_getall_free getall_free, plughost_storage_remove remove, plughost_storage_rename rename, int IsReadOnly, void *userdata)
plughost_PresetChange_Kind
void plughost_PresetManager_InformChange(struct plughost_CInstance *instance, const fs_char *relative_path, enum plughost_PresetChange_Kind change_kind)
wchar_t fs_char
void plughost_StartUpdateThread(struct plughost_CInstance *instance, unsigned int port)
int plughost_WaitUpdateThreadReady(struct plughost_CInstance *instance, int milliseconds)
void plughost_StopUpdateThread(struct plughost_CInstance *instance)
#define SOUND4_WEBSERVER_HTTPS_OK
int plughost_Webserver_Status(uint64_t id)
int plughost_Webserver_Stop(uint64_t id, int timeout_ms)
uint64_t plughost_Webserver_tcp2(unsigned int listenport, unsigned int listenport_secure, const char *socket_ip, unsigned int socket_port, const struct plughost_CParameters *parameters)
#define SOUND4_WEBSERVER_HTTP_OK
uint64_t plughost_Webserver_tcp(unsigned int listenport, unsigned int listenport_secure, const char *socket_ip, unsigned int socket_port)
#define SOUND4_INVALID_WEBSERVER_ID
uint64_t plughost_Webserver(unsigned int listenport, unsigned int listenport_secure, struct plughost_CInstance *instance)
plughost_SampleFormat SampleFormat
std::function< void(LogSeverity, const std::string &)> log_cb_t
C interface for library.
#define fs_strdup
helper for OS dependant file name copy