jack1 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.

145 lines
4.8KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. $Id$
  15. */
  16. #ifndef __jack_port_h__
  17. #define __jack_port_h__
  18. #include <pthread.h>
  19. #include <jack/types.h>
  20. #include <jack/jslist.h>
  21. #include <jack/shm.h>
  22. #define JACK_PORT_NAME_SIZE 32
  23. #define JACK_PORT_TYPE_SIZE 32
  24. /* The relatively low value of this constant reflects the fact that
  25. * JACK currently only knows about *1* port type. (March 2003)
  26. *
  27. * Further, the 4 covers:
  28. * - a single non-negotiated audio format
  29. * - music data (ie. MIDI)
  30. * - video
  31. * - one other
  32. *
  33. * which is probably enough for more than just the foreseeable future.
  34. */
  35. #define JACK_MAX_PORT_TYPES 4
  36. #define JACK_AUDIO_PORT_TYPE 0
  37. /* these should probably go somewhere else, but not in <jack/types.h> */
  38. #define JACK_CLIENT_NAME_SIZE 32
  39. typedef uint32_t jack_client_id_t;
  40. /* JACK shared memory segments are limited to MAX_INT32, they can be
  41. * shared between 32-bit and 64-bit clients.
  42. */
  43. #define JACK_SHM_MAX (MAX_INT32)
  44. typedef int32_t jack_port_type_id_t;
  45. /* Port type structure.
  46. *
  47. * (1) One for each port type is part of the engine's jack_control_t
  48. * shared memory structure.
  49. *
  50. * (2) One for each port type is appended to the engine's
  51. * jack_client_connect_result_t response. The client reads them into
  52. * its local memory, using them to attach the corresponding shared
  53. * memory segments.
  54. */
  55. typedef struct _jack_port_type_info {
  56. jack_port_type_id_t ptype_id;
  57. const char type_name[JACK_PORT_TYPE_SIZE];
  58. /* If == 1, then a buffer to handle nframes worth of data has
  59. * sizeof(jack_default_audio_sample_t) * nframes bytes.
  60. *
  61. * If > 1, the buffer allocated for input mixing will be
  62. * this value times sizeof(jack_default_audio_sample_t)
  63. * * nframes bytes in size. For non-audio data types,
  64. * it may have a different value.
  65. *
  66. * If < 0, the value should be ignored, and buffer_size
  67. * should be used.
  68. */
  69. int32_t buffer_scale_factor;
  70. /* ignored unless buffer_scale_factor is < 0. see above */
  71. jack_shmsize_t buffer_size;
  72. jack_shm_registry_index_t shm_registry_index;
  73. } jack_port_type_info_t;
  74. /* Allocated by the engine in shared memory. */
  75. typedef struct _jack_port_shared {
  76. jack_port_type_id_t ptype_id; /* index into port type array */
  77. jack_shmsize_t offset; /* buffer offset in shm segment */
  78. jack_port_id_t id; /* index into engine port array */
  79. enum JackPortFlags flags;
  80. char name[JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE+2];
  81. jack_client_id_t client_id; /* who owns me */
  82. volatile jack_nframes_t latency;
  83. volatile jack_nframes_t total_latency;
  84. volatile uint8_t monitor_requests;
  85. char has_mixdown; /* port has a mixdown function */
  86. char in_use;
  87. char locked;
  88. } jack_port_shared_t;
  89. typedef struct _jack_port_functions {
  90. /* Function to mixdown multiple inputs to a buffer. Can be NULL,
  91. * indicating that multiple input connections are not legal for
  92. * this data type.
  93. */
  94. void (*mixdown)(jack_port_t *, jack_nframes_t);
  95. } jack_port_functions_t;
  96. /* Allocated by the client in local memory. */
  97. struct _jack_port {
  98. void **client_segment_base;
  99. void *mix_buffer;
  100. jack_port_type_info_t *type_info; /* shared memory type info */
  101. struct _jack_port_shared *shared; /* corresponding shm struct */
  102. struct _jack_port *tied; /* locally tied source port */
  103. jack_port_functions_t fptr;
  104. pthread_mutex_t connection_lock;
  105. JSList *connections;
  106. };
  107. /* Inline would be cleaner, but it needs to be fast even in
  108. * non-optimized code. jack_output_port_buffer() only handles output
  109. * ports. jack_port_buffer() works for both input and output ports.
  110. */
  111. #define jack_port_buffer(p) \
  112. ((void *) ((p)->mix_buffer? (p)->mix_buffer: \
  113. *(p)->client_segment_base + (p)->shared->offset))
  114. #define jack_output_port_buffer(p) \
  115. ((void *) (*(p)->client_segment_base + (p)->shared->offset))
  116. #endif /* __jack_port_h__ */