Update of /cvsroot/audacity/lib-src/portaudio-v19/src/hostapi/jack
In directory
sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv27584/portaudio-v19/src/hostapi/jack
Modified Files:
pa_jack.c
Log Message:
Update portaudio to 2007-jun-01 snapshot
Index: pa_jack.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/portaudio-v19/src/hostapi/jack/pa_jack.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pa_jack.c 29 Sep 2006 00:09:54 -0000 1.3
+++ pa_jack.c 3 Jun 2007 08:30:31 -0000 1.4
@@ -44,7 +44,7 @@
/**
@file
- @ingroup hostaip_src
+ @ingroup hostapi_src
*/
#include <string.h>
@@ -68,7 +68,7 @@
#include "pa_process.h"
#include "pa_allocation.h"
#include "pa_cpuload.h"
-#include "../pablio/ringbuffer.c"
+#include "pa_ringbuffer.h"
static int aErr_;
static PaError paErr_; /* For use with ENSURE_PA */
@@ -85,7 +85,7 @@
{ \
if( (paErr_) == paUnanticipatedHostError && pthread_self() ==
mainThread_ ) \
{ \
- assert( jackErr_ ); \
+ if (! jackErr_ ) jackErr_ = "unknown error";\
PaUtil_SetLastHostErrorInfo( paJACK, -1, jackErr_ ); \
} \
PaUtil_DebugPrint(( "Expression '" #expr "' failed in '" __FILE__
"', line: " STRINGIZE( __LINE__ ) "\n" )); \
@@ -100,7 +100,7 @@
{ \
if( (code) == paUnanticipatedHostError && pthread_self() ==
mainThread_ ) \
{ \
- assert( jackErr_ ); \
+ if (!jackErr_) jackErr_ = "unknown error";\
PaUtil_SetLastHostErrorInfo( paJACK, -1, jackErr_ ); \
} \
PaUtil_DebugPrint(( "Expression '" #expr "' failed in '" __FILE__
"', line: " STRINGIZE( __LINE__ ) "\n" )); \
@@ -216,8 +216,8 @@
/* These are useful for the blocking API */
int isBlockingStream;
- RingBuffer inFIFO;
- RingBuffer outFIFO;
+ PaUtilRingBuffer inFIFO;
+ PaUtilRingBuffer outFIFO;
volatile sig_atomic_t data_available;
sem_t data_semaphore;
int bytesPerFrame;
@@ -246,17 +246,17 @@
/* ---- blocking emulation layer ---- */
/* Allocate buffer. */
-static PaError BlockingInitFIFO( RingBuffer *rbuf, long numFrames, long
bytesPerFrame )
+static PaError BlockingInitFIFO( PaUtilRingBuffer *rbuf, long numFrames, long
bytesPerFrame )
{
long numBytes = numFrames * bytesPerFrame;
char *buffer = (char *) malloc( numBytes );
if( buffer == NULL ) return paInsufficientMemory;
memset( buffer, 0, numBytes );
- return (PaError) RingBuffer_Init( rbuf, numBytes, buffer );
+ return (PaError) PaUtil_InitializeRingBuffer( rbuf, numBytes, buffer );
}
/* Free buffer. */
-static PaError BlockingTermFIFO( RingBuffer *rbuf )
+static PaError BlockingTermFIFO( PaUtilRingBuffer *rbuf )
{
if( rbuf->buffer ) free( rbuf->buffer );
rbuf->buffer = NULL;
@@ -277,11 +277,11 @@
/* This may get called with NULL inputBuffer during initial setup. */
if( inputBuffer != NULL )
{
- RingBuffer_Write( &stream->inFIFO, inputBuffer, numBytes );
+ PaUtil_WriteRingBuffer( &stream->inFIFO, inputBuffer, numBytes );
}
if( outputBuffer != NULL )
{
- int numRead = RingBuffer_Read( &stream->outFIFO, outputBuffer,
numBytes );
+ int numRead = PaUtil_ReadRingBuffer( &stream->outFIFO, outputBuffer,
numBytes );
/* Zero out remainder of buffer if we run out of data. */
memset( (char *)outputBuffer + numRead, 0, numBytes - numRead );
}
@@ -323,8 +323,8 @@
ENSURE_PA( BlockingInitFIFO( &stream->outFIFO, numFrames,
stream->bytesPerFrame ) );
/* Make Write FIFO appear full initially. */
- numBytes = RingBuffer_GetWriteAvailable( &stream->outFIFO );
- RingBuffer_AdvanceWriteIndex( &stream->outFIFO, numBytes );
+ numBytes = PaUtil_GetRingBufferWriteAvailable( &stream->outFIFO );
+ PaUtil_AdvanceRingBufferWriteIndex( &stream->outFIFO, numBytes );
}
stream->data_available = 0;
@@ -353,7 +353,7 @@
long numBytes = stream->bytesPerFrame * numFrames;
while( numBytes > 0 )
{
- bytesRead = RingBuffer_Read( &stream->inFIFO, p, numBytes );
+ bytesRead = PaUtil_ReadRingBuffer( &stream->inFIFO, p, numBytes );
numBytes -= bytesRead;
p += bytesRead;
if( numBytes > 0 )
@@ -378,7 +378,7 @@
long numBytes = stream->bytesPerFrame * numFrames;
while( numBytes > 0 )
{
- bytesWritten = RingBuffer_Write( &stream->outFIFO, p, numBytes );
+ bytesWritten = PaUtil_WriteRingBuffer( &stream->outFIFO, p, numBytes );
numBytes -= bytesWritten;
p += bytesWritten;
if( numBytes > 0 )
@@ -412,7 +412,7 @@
{
PaJackStream *stream = (PaJackStream *)s;
- int bytesFull = RingBuffer_GetReadAvailable( &stream->inFIFO );
+ int bytesFull = PaUtil_GetRingBufferReadAvailable( &stream->inFIFO );
return bytesFull / stream->bytesPerFrame;
}
@@ -421,7 +421,7 @@
{
PaJackStream *stream = (PaJackStream *)s;
- int bytesEmpty = RingBuffer_GetWriteAvailable( &stream->outFIFO );
+ int bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &stream->outFIFO );
return bytesEmpty / stream->bytesPerFrame;
}
@@ -430,7 +430,7 @@
{
PaJackStream *stream = (PaJackStream *)s;
- while( RingBuffer_GetReadAvailable( &stream->outFIFO ) > 0 )
+ while( PaUtil_GetRingBufferReadAvailable( &stream->outFIFO ) > 0 )
{
stream->data_available = 0;
sem_wait( &stream->data_semaphore );
@@ -451,11 +451,6 @@
{
/* Utility macros for the repetitive process of allocating memory */
- /* ... MALLOC: allocate memory as part of the device list
- * allocation group */
-#define MALLOC(size) \
- (PaUtil_GroupAllocateMemory( jackApi->deviceInfoMemory, (size) ))
-
/* JACK has no concept of a device. To JACK, there are clients
* which have an arbitrary number of ports. To make this
* intelligible to PortAudio clients, we will group each JACK client
@@ -484,8 +479,8 @@
* associated with the previous list */
PaUtil_FreeAllAllocations( jackApi->deviceInfoMemory );
- regex_pattern = MALLOC( jack_client_name_size() + 3 );
- tmp_client_name = MALLOC( jack_client_name_size() );
+ regex_pattern = PaUtil_GroupAllocateMemory( jackApi->deviceInfoMemory,
jack_client_name_size() + 3 );
+ tmp_client_name = PaUtil_GroupAllocateMemory( jackApi->deviceInfoMemory,
jack_client_name_size() );
/* We can only retrieve the list of clients indirectly, by first
* asking for a list of all ports, then parsing the port names
@@ -497,7 +492,8 @@
while( jack_ports[numPorts] )
++numPorts;
/* At least there will be one port per client :) */
- UNLESS( client_names = MALLOC( numPorts * sizeof (char *) ),
paInsufficientMemory );
+ UNLESS( client_names = PaUtil_GroupAllocateMemory(
jackApi->deviceInfoMemory, numPorts *
+ sizeof (char *) ), paInsufficientMemory );
/* Build a list of clients from the list of ports */
for( numClients = 0, port_index = 0; jack_ports[port_index] != NULL;
port_index++ )
@@ -524,7 +520,8 @@
if (client_seen)
continue; /* A: Nothing to see here, move along */
- UNLESS( client_names[numClients] =
(char*)MALLOC(strlen(tmp_client_name) + 1), paInsufficientMemory );
+ UNLESS( client_names[numClients] = (char*)PaUtil_GroupAllocateMemory(
jackApi->deviceInfoMemory,
+ strlen(tmp_client_name) + 1), paInsufficientMemory );
/* The alsa_pcm client should go in spot 0. If this
* is the alsa_pcm client AND we are NOT about to put
@@ -550,8 +547,8 @@
/* there is one global sample rate all clients must conform to */
globalSampleRate = jack_get_sample_rate( jackApi->jack_client );
- UNLESS( commonApi->deviceInfos = (PaDeviceInfo**)MALLOC(
sizeof(PaDeviceInfo*) *
- numClients ),
paInsufficientMemory );
+ UNLESS( commonApi->deviceInfos =
(PaDeviceInfo**)PaUtil_GroupAllocateMemory( jackApi->deviceInfoMemory,
+ sizeof(PaDeviceInfo*) * numClients ), paInsufficientMemory );
assert( commonApi->info.deviceCount == 0 );
@@ -561,8 +558,10 @@
PaDeviceInfo *curDevInfo;
const char **clientPorts = NULL;
- UNLESS( curDevInfo = (PaDeviceInfo*)MALLOC( sizeof(PaDeviceInfo) ),
paInsufficientMemory );
- UNLESS( curDevInfo->name = (char*)MALLOC(
strlen(client_names[client_index]) + 1 ), paInsufficientMemory );
+ UNLESS( curDevInfo = (PaDeviceInfo*)PaUtil_GroupAllocateMemory(
jackApi->deviceInfoMemory,
+ sizeof(PaDeviceInfo) ), paInsufficientMemory );
+ UNLESS( curDevInfo->name = (char*)PaUtil_GroupAllocateMemory(
jackApi->deviceInfoMemory,
+ strlen(client_names[client_index]) + 1 ),
paInsufficientMemory );
strcpy( (char *)curDevInfo->name, client_names[client_index] );
curDevInfo->structVersion = 2;
@@ -633,7 +632,6 @@
free( jack_ports );
return result;
}
-#undef MALLOC
static void UpdateSampleRate( PaJackStream *stream, double sampleRate )
{
@@ -647,9 +645,8 @@
if( pthread_self() == mainThread_ )
{
assert( msg );
- free( jackErr_ );
- jackErr_ = malloc( strlen( msg ) );
- sprintf( jackErr_, msg );
+ jackErr_ = realloc( jackErr_, strlen( msg ) + 1 );
+ strcpy( jackErr_, msg );
}
}
@@ -1055,7 +1052,7 @@
return result;
}
-/* Add stream to processing queue */
+/* Add stream to JACK callback processing queue */
static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
PaStream** s,
const PaStreamParameters *inputParameters,
@@ -1228,7 +1225,7 @@
{
int err = 0;
- /* ... remote output ports (that we input from) */
+ /* Get output ports of our capture device */
snprintf( regex_pattern, regexSz, "%s:.*", hostApi->deviceInfos[
inputParameters->device ]->name );
UNLESS( jack_ports = jack_get_ports( jackHostApi->jack_client,
regex_pattern,
NULL, JackPortIsOutput ),
paUnanticipatedHostError );
@@ -1252,7 +1249,7 @@
{
int err = 0;
- /* ... remote input ports (that we output to) */
+ /* Get input ports of our playback device */
snprintf( regex_pattern, regexSz, "%s:.*", hostApi->deviceInfos[
outputParameters->device ]->name );
UNLESS( jack_ports = jack_get_ports( jackHostApi->jack_client,
regex_pattern,
NULL, JackPortIsInput ),
paUnanticipatedHostError );
@@ -1301,7 +1298,8 @@
stream->streamRepresentation.streamInfo.sampleRate = jackSr;
stream->t0 = jack_frame_time( jackHostApi->jack_client ); /* A: Time
should run from Pa_OpenStream */
- ENSURE_PA( AddStream( stream ) ); /* Add to queue over opened streams */
+ /* Add to queue of opened streams */
+ ENSURE_PA( AddStream( stream ) );
*s = (PaStream*)stream;
@@ -1410,7 +1408,7 @@
return result;
}
-/* Alter the processing queue if necessary */
+/* Update the JACK callback's stream processing queue. */
static PaError UpdateQueue( PaJackHostApiRepresentation *hostApi )
{
PaError result = paNoError;
@@ -1436,7 +1434,10 @@
node->next = hostApi->toAdd;
}
else
+ {
+ /* The only queue entry. */
hostApi->processQueue = (PaJackStream *)hostApi->toAdd;
+ }
/* If necessary, update stream state */
if( hostApi->toAdd->streamRepresentation.streamInfo.sampleRate !=
jackSr )
@@ -1485,6 +1486,7 @@
return result;
}
+/* Audio processing callback invoked periodically from JACK. */
static int JackCallback( jack_nframes_t frames, void *userData )
{
PaError result = paNoError;
@@ -1586,24 +1588,27 @@
/* Ready the processor */
PaUtil_ResetBufferProcessor( &stream->bufferProcessor );
- /* connect the ports */
+ /* Connect the ports. Note that the ports may already have been connected
by someone else in
+ * the meantime, in which case JACK returns EEXIST. */
- /* NOTE: I would rather use jack_port_connect which uses jack_port_t's
- * instead of port names, but it is not implemented yet. */
if( stream->num_incoming_connections > 0 )
{
for( i = 0; i < stream->num_incoming_connections; i++ )
- UNLESS( jack_connect( stream->jack_client,
- jack_port_name( stream->remote_output_ports[i] ),
- jack_port_name( stream->local_input_ports[i] ) ) == 0,
paUnanticipatedHostError );
+ {
+ int r = jack_connect( stream->jack_client, jack_port_name(
stream->remote_output_ports[i] ),
+ jack_port_name( stream->local_input_ports[i] ) );
+ UNLESS( 0 == r || EEXIST == r, paUnanticipatedHostError );
+ }
}
if( stream->num_outgoing_connections > 0 )
{
for( i = 0; i < stream->num_outgoing_connections; i++ )
- UNLESS( jack_connect( stream->jack_client,
- jack_port_name( stream->local_output_ports[i] ),
- jack_port_name( stream->remote_input_ports[i] ) ) == 0,
paUnanticipatedHostError );
+ {
+ int r = jack_connect( stream->jack_client, jack_port_name(
stream->local_output_ports[i] ),
+ jack_port_name( stream->remote_input_ports[i] ) );
+ UNLESS( 0 == r || EEXIST == r, paUnanticipatedHostError );
+ }
}
stream->xrun = FALSE;
@@ -1669,27 +1674,19 @@
{
for( i = 0; i < stream->num_incoming_connections; i++ )
{
- UNLESS( !jack_port_lock( stream->jack_client,
stream->local_input_ports[i] ),
- paUnanticipatedHostError );
if( jack_port_connected( stream->local_input_ports[i] ) )
{
UNLESS( !jack_port_disconnect( stream->jack_client,
stream->local_input_ports[i] ),
paUnanticipatedHostError );
}
- UNLESS( !jack_port_unlock( stream->jack_client,
stream->local_input_ports[i] ),
- paUnanticipatedHostError );
}
for( i = 0; i < stream->num_outgoing_connections; i++ )
{
- UNLESS( !jack_port_lock( stream->jack_client,
stream->local_output_ports[i] ),
- paUnanticipatedHostError );
if( jack_port_connected( stream->local_output_ports[i] ) )
{
UNLESS( !jack_port_disconnect( stream->jack_client,
stream->local_output_ports[i] ),
paUnanticipatedHostError );
}
- UNLESS( !jack_port_unlock( stream->jack_client,
stream->local_output_ports[i] ),
- paUnanticipatedHostError );
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs