| 1 | #ifndef PA_STREAM_H |
| 2 | #define PA_STREAM_H |
| 3 | /* |
| 4 | * $Id: pa_stream.h,v 1.1 2006/06/10 21:30:55 dmazzoni Exp $ |
| 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-2002 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 | * Any person wishing to distribute modifications to the Software is |
| 23 | * requested to send the modifications to the original developer so that |
| 24 | * they can be incorporated into the canonical version. |
| 25 | * |
| 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 27 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 29 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
| 30 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 31 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 32 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 33 | */ |
| 34 | |
| 35 | /** @file |
| 36 | @brief Interface used by pa_front to virtualize functions which operate on |
| 37 | streams. |
| 38 | */ |
| 39 | |
| 40 | |
| 41 | #include "portaudio.h" |
| 42 | |
| 43 | #ifdef __cplusplus |
| 44 | extern "C" |
| 45 | { |
| 46 | #endif /* __cplusplus */ |
| 47 | |
| 48 | |
| 49 | #define PA_STREAM_MAGIC (0x18273645) |
| 50 | |
| 51 | |
| 52 | /** A structure representing an (abstract) interface to a host API. Contains |
| 53 | pointers to functions which implement the interface. |
| 54 | |
| 55 | All PaStreamInterface functions are guaranteed to be called with a non-null, |
| 56 | valid stream parameter. |
| 57 | */ |
| 58 | typedef struct { |
| 59 | PaError (*Close)( PaStream* stream ); |
| 60 | PaError (*Start)( PaStream *stream ); |
| 61 | PaError (*Stop)( PaStream *stream ); |
| 62 | PaError (*Abort)( PaStream *stream ); |
| 63 | PaError (*IsStopped)( PaStream *stream ); |
| 64 | PaError (*IsActive)( PaStream *stream ); |
| 65 | PaTime (*GetTime)( PaStream *stream ); |
| 66 | double (*GetCpuLoad)( PaStream* stream ); |
| 67 | PaError (*Read)( PaStream* stream, void *buffer, unsigned long frames ); |
| 68 | PaError (*Write)( PaStream* stream, const void *buffer, unsigned long frames ); |
| 69 | signed long (*GetReadAvailable)( PaStream* stream ); |
| 70 | signed long (*GetWriteAvailable)( PaStream* stream ); |
| 71 | } PaUtilStreamInterface; |
| 72 | |
| 73 | |
| 74 | /** Initialize the fields of a PaUtilStreamInterface structure. |
| 75 | */ |
| 76 | void PaUtil_InitializeStreamInterface( PaUtilStreamInterface *streamInterface, |
| 77 | PaError (*Close)( PaStream* ), |
| 78 | PaError (*Start)( PaStream* ), |
| 79 | PaError (*Stop)( PaStream* ), |
| 80 | PaError (*Abort)( PaStream* ), |
| 81 | PaError (*IsStopped)( PaStream* ), |
| 82 | PaError (*IsActive)( PaStream* ), |
| 83 | PaTime (*GetTime)( PaStream* ), |
| 84 | double (*GetCpuLoad)( PaStream* ), |
| 85 | PaError (*Read)( PaStream* stream, void *buffer, unsigned long frames ), |
| 86 | PaError (*Write)( PaStream* stream, const void *buffer, unsigned long frames ), |
| 87 | signed long (*GetReadAvailable)( PaStream* stream ), |
| 88 | signed long (*GetWriteAvailable)( PaStream* stream ) ); |
| 89 | |
| 90 | |
| 91 | /** Dummy Read function for use in interfaces to a callback based streams. |
| 92 | Pass to the Read parameter of PaUtil_InitializeStreamInterface. |
| 93 | @return An error code indicating that the function has no effect |
| 94 | because the stream is a callback stream. |
| 95 | */ |
| 96 | PaError PaUtil_DummyRead( PaStream* stream, |
| 97 | void *buffer, |
| 98 | unsigned long frames ); |
| 99 | |
| 100 | |
| 101 | /** Dummy Write function for use in an interfaces to callback based streams. |
| 102 | Pass to the Write 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 | PaError PaUtil_DummyWrite( PaStream* stream, |
| 107 | const void *buffer, |
| 108 | unsigned long frames ); |
| 109 | |
| 110 | |
| 111 | /** Dummy GetReadAvailable function for use in interfaces to callback based |
| 112 | streams. Pass to the GetReadAvailable parameter of PaUtil_InitializeStreamInterface. |
| 113 | @return An error code indicating that the function has no effect |
| 114 | because the stream is a callback stream. |
| 115 | */ |
| 116 | signed long PaUtil_DummyGetReadAvailable( PaStream* stream ); |
| 117 | |
| 118 | |
| 119 | /** Dummy GetWriteAvailable function for use in interfaces to callback based |
| 120 | streams. Pass to the GetWriteAvailable parameter of PaUtil_InitializeStreamInterface. |
| 121 | @return An error code indicating that the function has no effect |
| 122 | because the stream is a callback stream. |
| 123 | */ |
| 124 | signed long PaUtil_DummyGetWriteAvailable( PaStream* stream ); |
| 125 | |
| 126 | |
| 127 | |
| 128 | /** Dummy GetCpuLoad function for use in an interface to a read/write stream. |
| 129 | Pass to the GetCpuLoad parameter of PaUtil_InitializeStreamInterface. |
| 130 | @return Returns 0. |
| 131 | */ |
| 132 | double PaUtil_DummyGetCpuLoad( PaStream* stream ); |
| 133 | |
| 134 | |
| 135 | /** Non host specific data for a stream. This data is used by pa_front to |
| 136 | forward to the appropriate functions in the streamInterface structure. |
| 137 | */ |
| 138 | typedef struct PaUtilStreamRepresentation { |
| 139 | unsigned long magic; /**< set to PA_STREAM_MAGIC */ |
| 140 | struct PaUtilStreamRepresentation *nextOpenStream; /**< field used by multi-api code */ |
| 141 | PaUtilStreamInterface *streamInterface; |
| 142 | PaStreamCallback *streamCallback; |
| 143 | PaStreamFinishedCallback *streamFinishedCallback; |
| 144 | void *userData; |
| 145 | PaStreamInfo streamInfo; |
| 146 | } PaUtilStreamRepresentation; |
| 147 | |
| 148 | |
| 149 | /** Initialize a PaUtilStreamRepresentation structure. |
| 150 | |
| 151 | @see PaUtil_InitializeStreamRepresentation |
| 152 | */ |
| 153 | void PaUtil_InitializeStreamRepresentation( |
| 154 | PaUtilStreamRepresentation *streamRepresentation, |
| 155 | PaUtilStreamInterface *streamInterface, |
| 156 | PaStreamCallback *streamCallback, |
| 157 | void *userData ); |
| 158 | |
| 159 | |
| 160 | /** Clean up a PaUtilStreamRepresentation structure previously initialized |
| 161 | by a call to PaUtil_InitializeStreamRepresentation. |
| 162 | |
| 163 | @see PaUtil_InitializeStreamRepresentation |
| 164 | */ |
| 165 | void PaUtil_TerminateStreamRepresentation( PaUtilStreamRepresentation *streamRepresentation ); |
| 166 | |
| 167 | |
| 168 | /** Check that the stream pointer is valid. |
| 169 | |
| 170 | @return Returns paNoError if the stream pointer appears to be OK, otherwise |
| 171 | returns an error indicating the cause of failure. |
| 172 | */ |
| 173 | PaError PaUtil_ValidateStreamPointer( PaStream *stream ); |
| 174 | |
| 175 | |
| 176 | /** Cast an opaque stream pointer into a pointer to a PaUtilStreamRepresentation. |
| 177 | |
| 178 | @see PaUtilStreamRepresentation |
| 179 | */ |
| 180 | #define PA_STREAM_REP( stream )\ |
| 181 | ((PaUtilStreamRepresentation*) (stream) ) |
| 182 | |
| 183 | |
| 184 | /** Cast an opaque stream pointer into a pointer to a PaUtilStreamInterface. |
| 185 | |
| 186 | @see PaUtilStreamRepresentation, PaUtilStreamInterface |
| 187 | */ |
| 188 | #define PA_STREAM_INTERFACE( stream )\ |
| 189 | PA_STREAM_REP( (stream) )->streamInterface |
| 190 | |
| 191 | |
| 192 | |
| 193 | #ifdef __cplusplus |
| 194 | } |
| 195 | #endif /* __cplusplus */ |
| 196 | #endif /* PA_STREAM_H */ |