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.

106 lines
2.5KB

  1. /*
  2. * messagebuffer.h -- realtime-safe message interface for jackd.
  3. *
  4. * This function is included in libjack so backend drivers can use
  5. * it, *not* for external client processes. The VERBOSE() and
  6. * MESSAGE() macros are realtime-safe.
  7. */
  8. /*
  9. * Copyright (C) 2004 Rui Nuno Capela, Steve Harris
  10. * Copyright (C) 2008 Nedko Arnaudov
  11. * Copyright (C) 2008 Grame
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU Lesser General Public License as published by
  15. * the Free Software Foundation; either version 2.1 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  26. *
  27. */
  28. #ifndef __JackMessageBuffer__
  29. #define __JackMessageBuffer__
  30. #include "JackPlatformPlug.h"
  31. #include "JackMutex.h"
  32. #include "JackAtomic.h"
  33. namespace Jack
  34. {
  35. /* MB_NEXT() relies on the fact that MB_BUFFERS is a power of two */
  36. #define MB_BUFFERS 128
  37. #define MB_NEXT(index) ((index+1) & (MB_BUFFERS-1))
  38. #define MB_BUFFERSIZE 256 /* message length limit */
  39. struct JackMessage
  40. {
  41. int level;
  42. char message[MB_BUFFERSIZE];
  43. };
  44. /*!
  45. \brief Message buffer to be used from RT threads.
  46. */
  47. class JackMessageBuffer : public JackRunnableInterface
  48. {
  49. private:
  50. volatile JackThreadInitCallback fInit;
  51. void* fInitArg;
  52. JackMessage fBuffers[MB_BUFFERS];
  53. JackThread fThread;
  54. JackProcessSync fGuard;
  55. volatile unsigned int fInBuffer;
  56. volatile unsigned int fOutBuffer;
  57. alignas(SInt32) SInt32 fOverruns;
  58. bool fRunning;
  59. void Flush();
  60. bool Start();
  61. bool Stop();
  62. public:
  63. JackMessageBuffer();
  64. ~JackMessageBuffer();
  65. // JackRunnableInterface interface
  66. bool Execute();
  67. bool static Create();
  68. bool static Destroy();
  69. void AddMessage(int level, const char *message);
  70. int SetInitCallback(JackThreadInitCallback callback, void *arg);
  71. static JackMessageBuffer* fInstance;
  72. };
  73. #ifdef __cplusplus
  74. extern "C"
  75. {
  76. #endif
  77. void JackMessageBufferAdd(int level, const char *message);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. };
  82. #endif