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.

174 lines
5.6KB

  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. */
  15. #ifndef __jack_port_h__
  16. #define __jack_port_h__
  17. #include <pthread.h>
  18. #include <jack/types.h>
  19. #include <jack/jslist.h>
  20. #include "shm.h"
  21. #define JACK_PORT_NAME_SIZE 256
  22. #define JACK_PORT_TYPE_SIZE 32
  23. /* The relatively low value of this constant reflects the fact that
  24. * JACK currently only knows about *2* port types. (May 2006)
  25. *
  26. * Further, the 4 covers:
  27. * - a single non-negotiated audio format
  28. * - music data (ie. MIDI)
  29. * - video
  30. * - one other
  31. *
  32. * which is probably enough for more than just the foreseeable future.
  33. */
  34. #define JACK_MAX_PORT_TYPES 4
  35. #define JACK_AUDIO_PORT_TYPE 0
  36. #define JACK_MIDI_PORT_TYPE 1
  37. /* these should probably go somewhere else, but not in <jack/types.h> */
  38. #define JACK_CLIENT_NAME_SIZE 33
  39. /* JACK shared memory segments are limited to MAX_INT32, they can be
  40. * shared between 32-bit and 64-bit clients.
  41. */
  42. #define JACK_SHM_MAX (MAX_INT32)
  43. typedef int32_t jack_port_type_id_t;
  44. #define JACK_BACKEND_ALIAS "system"
  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_shmsize_t zero_buffer_offset;
  74. } POST_PACKED_STRUCTURE jack_port_type_info_t;
  75. /* Allocated by the engine in shared memory. */
  76. typedef struct _jack_port_shared {
  77. jack_port_type_id_t ptype_id; /* index into port type array */
  78. jack_shmsize_t offset; /* buffer offset in shm segment */
  79. jack_port_id_t id; /* index into engine port array */
  80. jack_uuid_t uuid;
  81. uint32_t flags;
  82. char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
  83. char alias1[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
  84. char alias2[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
  85. jack_uuid_t client_id; /* who owns me */
  86. volatile jack_nframes_t latency;
  87. volatile jack_nframes_t total_latency;
  88. volatile jack_latency_range_t playback_latency;
  89. volatile jack_latency_range_t capture_latency;
  90. volatile uint8_t monitor_requests;
  91. char has_mixdown; /* port has a mixdown function */
  92. char in_use;
  93. char unused; /* legacy locked field */
  94. } POST_PACKED_STRUCTURE jack_port_shared_t;
  95. typedef struct _jack_port_functions {
  96. /* Function to initialize port buffer. Cannot be NULL.
  97. * NOTE: This must take a buffer rather than jack_port_t as it is called
  98. * in jack_engine_place_buffers() before any port creation.
  99. * A better solution is to make jack_engine_place_buffers to be type-specific,
  100. * but this works.
  101. */
  102. void (*buffer_init)(void *buffer, size_t size, jack_nframes_t);
  103. /* Function to mixdown multiple inputs to a buffer. Can be NULL,
  104. * indicating that multiple input connections are not legal for
  105. * this data type.
  106. */
  107. void (*mixdown)(jack_port_t *, jack_nframes_t);
  108. } jack_port_functions_t;
  109. /**
  110. * Get port functions.
  111. * @param ptid port type id.
  112. *
  113. * @return pointer to port type functions or NULL if port type is unknown.
  114. */
  115. /*const*/ jack_port_functions_t *
  116. jack_get_port_functions(jack_port_type_id_t ptid);
  117. /* Allocated by the client in local memory. */
  118. struct _jack_port {
  119. void **client_segment_base;
  120. void *mix_buffer;
  121. jack_port_type_info_t *type_info; /* shared memory type info */
  122. struct _jack_port_shared *shared; /* corresponding shm struct */
  123. struct _jack_port *tied; /* locally tied source port */
  124. jack_port_functions_t fptr;
  125. pthread_mutex_t connection_lock;
  126. JSList *connections;
  127. };
  128. /* Inline would be cleaner, but it needs to be fast even in
  129. * non-optimized code. jack_output_port_buffer() only handles output
  130. * ports. jack_port_buffer() works for both input and output ports.
  131. */
  132. #define jack_port_buffer(p) \
  133. ((void*)((p)->mix_buffer ? (p)->mix_buffer : \
  134. *(p)->client_segment_base + (p)->shared->offset))
  135. #define jack_output_port_buffer(p) \
  136. ((void*)(*(p)->client_segment_base + (p)->shared->offset))
  137. /* not for use by JACK applications */
  138. size_t jack_port_type_buffer_size(jack_port_type_info_t* port_type_info, jack_nframes_t nframes);
  139. #endif /* __jack_port_h__ */