pa_stream.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #ifndef PA_STREAM_H
  2. #define PA_STREAM_H
  3. /*
  4. * $Id: pa_stream.h 1339 2008-02-15 07:50:33Z rossb $
  5. * Portable Audio I/O Library
  6. * stream interface
  7. *
  8. * Based on the Open Source API proposed by Ross Bencina
  9. * Copyright (c) 1999-2008 Ross Bencina, Phil Burk
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining
  12. * a copy of this software and associated documentation files
  13. * (the "Software"), to deal in the Software without restriction,
  14. * including without limitation the rights to use, copy, modify, merge,
  15. * publish, distribute, sublicense, and/or sell copies of the Software,
  16. * and to permit persons to whom the Software is furnished to do so,
  17. * subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be
  20. * included in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  25. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  26. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  27. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. /*
  31. * The text above constitutes the entire PortAudio license; however,
  32. * the PortAudio community also makes the following non-binding requests:
  33. *
  34. * Any person wishing to distribute modifications to the Software is
  35. * requested to send the modifications to the original developer so that
  36. * they can be incorporated into the canonical version. It is also
  37. * requested that these non-binding requests be included along with the
  38. * license above.
  39. */
  40. /** @file
  41. @ingroup common_src
  42. @brief Stream interfaces, representation structures and helper functions
  43. used to interface between pa_front.c host API implementations.
  44. */
  45. #include "portaudio.h"
  46. #ifdef __cplusplus
  47. extern "C"
  48. {
  49. #endif /* __cplusplus */
  50. #define PA_STREAM_MAGIC (0x18273645)
  51. /** A structure representing an (abstract) interface to a host API. Contains
  52. pointers to functions which implement the interface.
  53. All PaStreamInterface functions are guaranteed to be called with a non-null,
  54. valid stream parameter.
  55. */
  56. typedef struct {
  57. PaError (*Close)( PaStream* stream );
  58. PaError (*Start)( PaStream *stream );
  59. PaError (*Stop)( PaStream *stream );
  60. PaError (*Abort)( PaStream *stream );
  61. PaError (*IsStopped)( PaStream *stream );
  62. PaError (*IsActive)( PaStream *stream );
  63. PaTime (*GetTime)( PaStream *stream );
  64. double (*GetCpuLoad)( PaStream* stream );
  65. PaError (*Read)( PaStream* stream, void *buffer, unsigned long frames );
  66. PaError (*Write)( PaStream* stream, const void *buffer, unsigned long frames );
  67. signed long (*GetReadAvailable)( PaStream* stream );
  68. signed long (*GetWriteAvailable)( PaStream* stream );
  69. } PaUtilStreamInterface;
  70. /** Initialize the fields of a PaUtilStreamInterface structure.
  71. */
  72. void PaUtil_InitializeStreamInterface( PaUtilStreamInterface *streamInterface,
  73. PaError (*Close)( PaStream* ),
  74. PaError (*Start)( PaStream* ),
  75. PaError (*Stop)( PaStream* ),
  76. PaError (*Abort)( PaStream* ),
  77. PaError (*IsStopped)( PaStream* ),
  78. PaError (*IsActive)( PaStream* ),
  79. PaTime (*GetTime)( PaStream* ),
  80. double (*GetCpuLoad)( PaStream* ),
  81. PaError (*Read)( PaStream* stream, void *buffer, unsigned long frames ),
  82. PaError (*Write)( PaStream* stream, const void *buffer, unsigned long frames ),
  83. signed long (*GetReadAvailable)( PaStream* stream ),
  84. signed long (*GetWriteAvailable)( PaStream* stream ) );
  85. /** Dummy Read function for use in interfaces to a callback based streams.
  86. Pass to the Read parameter of PaUtil_InitializeStreamInterface.
  87. @return An error code indicating that the function has no effect
  88. because the stream is a callback stream.
  89. */
  90. PaError PaUtil_DummyRead( PaStream* stream,
  91. void *buffer,
  92. unsigned long frames );
  93. /** Dummy Write function for use in an interfaces to callback based streams.
  94. Pass to the Write parameter of PaUtil_InitializeStreamInterface.
  95. @return An error code indicating that the function has no effect
  96. because the stream is a callback stream.
  97. */
  98. PaError PaUtil_DummyWrite( PaStream* stream,
  99. const void *buffer,
  100. unsigned long frames );
  101. /** Dummy GetReadAvailable function for use in interfaces to callback based
  102. streams. Pass to the GetReadAvailable parameter of PaUtil_InitializeStreamInterface.
  103. @return An error code indicating that the function has no effect
  104. because the stream is a callback stream.
  105. */
  106. signed long PaUtil_DummyGetReadAvailable( PaStream* stream );
  107. /** Dummy GetWriteAvailable function for use in interfaces to callback based
  108. streams. Pass to the GetWriteAvailable parameter of PaUtil_InitializeStreamInterface.
  109. @return An error code indicating that the function has no effect
  110. because the stream is a callback stream.
  111. */
  112. signed long PaUtil_DummyGetWriteAvailable( PaStream* stream );
  113. /** Dummy GetCpuLoad function for use in an interface to a read/write stream.
  114. Pass to the GetCpuLoad parameter of PaUtil_InitializeStreamInterface.
  115. @return Returns 0.
  116. */
  117. double PaUtil_DummyGetCpuLoad( PaStream* stream );
  118. /** Non host specific data for a stream. This data is used by pa_front to
  119. forward to the appropriate functions in the streamInterface structure.
  120. */
  121. typedef struct PaUtilStreamRepresentation {
  122. unsigned long magic; /**< set to PA_STREAM_MAGIC */
  123. struct PaUtilStreamRepresentation *nextOpenStream; /**< field used by multi-api code */
  124. PaUtilStreamInterface *streamInterface;
  125. PaStreamCallback *streamCallback;
  126. PaStreamFinishedCallback *streamFinishedCallback;
  127. void *userData;
  128. PaStreamInfo streamInfo;
  129. } PaUtilStreamRepresentation;
  130. /** Initialize a PaUtilStreamRepresentation structure.
  131. @see PaUtil_InitializeStreamRepresentation
  132. */
  133. void PaUtil_InitializeStreamRepresentation(
  134. PaUtilStreamRepresentation *streamRepresentation,
  135. PaUtilStreamInterface *streamInterface,
  136. PaStreamCallback *streamCallback,
  137. void *userData );
  138. /** Clean up a PaUtilStreamRepresentation structure previously initialized
  139. by a call to PaUtil_InitializeStreamRepresentation.
  140. @see PaUtil_InitializeStreamRepresentation
  141. */
  142. void PaUtil_TerminateStreamRepresentation( PaUtilStreamRepresentation *streamRepresentation );
  143. /** Check that the stream pointer is valid.
  144. @return Returns paNoError if the stream pointer appears to be OK, otherwise
  145. returns an error indicating the cause of failure.
  146. */
  147. PaError PaUtil_ValidateStreamPointer( PaStream *stream );
  148. /** Cast an opaque stream pointer into a pointer to a PaUtilStreamRepresentation.
  149. @see PaUtilStreamRepresentation
  150. */
  151. #define PA_STREAM_REP( stream )\
  152. ((PaUtilStreamRepresentation*) (stream) )
  153. /** Cast an opaque stream pointer into a pointer to a PaUtilStreamInterface.
  154. @see PaUtilStreamRepresentation, PaUtilStreamInterface
  155. */
  156. #define PA_STREAM_INTERFACE( stream )\
  157. PA_STREAM_REP( (stream) )->streamInterface
  158. #ifdef __cplusplus
  159. }
  160. #endif /* __cplusplus */
  161. #endif /* PA_STREAM_H */