Skip to content

Commit

Permalink
Pulseaudio: Another manual intetantion round
Browse files Browse the repository at this point in the history
Manual intetation is fun and now it should be
correct (tm)
  • Loading branch information
illuusio committed Sep 4, 2023
1 parent f580a6c commit b13c5a5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 56 deletions.
81 changes: 41 additions & 40 deletions src/hostapi/pulseaudio/pa_linux_pulseaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ int PaPulseAudio_CheckConnection( PaPulseAudio_HostApiRepresentation * ptr )
*/
if( !ptr )
{
PA_PULSEAUDIO_SET_LAST_HOST_ERROR(0,
"PaPulseAudio_CheckConnection: Host API is NULL! Can't do anything about it");
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_CheckConnection: Host API is NULL! Can't do anything about it" );
return -1;
}

if( !ptr->context || !ptr->mainloop )
{
PA_PULSEAUDIO_SET_LAST_HOST_ERROR(0,
"PaPulseAudio_CheckConnection: PulseAudio context or mainloop are NULL");
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_CheckConnection: PulseAudio context or mainloop are NULL" );
return -1;
}

Expand All @@ -98,13 +98,14 @@ int PaPulseAudio_CheckConnection( PaPulseAudio_HostApiRepresentation * ptr )
*/

case PA_CONTEXT_UNCONNECTED:
PA_PULSEAUDIO_SET_LAST_HOST_ERROR(0, "PaPulseAudio_CheckConnection: The context hasn't been connected yet (PA_CONTEXT_UNCONNECTED)");
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_CheckConnection: The context hasn't been connected yet (PA_CONTEXT_UNCONNECTED)" );
break;

case PA_CONTEXT_FAILED:
PA_PULSEAUDIO_SET_LAST_HOST_ERROR(0, "PaPulseAudio_CheckConnection: The connection failed or was disconnected. (PA_CONTEXT_FAILED)");
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_CheckConnection: The connection failed or was disconnected. (PA_CONTEXT_FAILED)" );
break;

}

return -1;
Expand All @@ -125,8 +126,8 @@ PaPulseAudio_HostApiRepresentation *PaPulseAudio_New( void )
/* ptr is NULL if runs out of memory or pointer to allocated memory */
if( !ptr )
{
PA_PULSEAUDIO_SET_LAST_HOST_ERROR(0,
"PaPulseAudio_HostApiRepresentation: Can't allocate memory required for using PulseAudio");
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_HostApiRepresentation: Can't allocate memory required for using PulseAudio" );
return NULL;
}

Expand All @@ -137,8 +138,8 @@ PaPulseAudio_HostApiRepresentation *PaPulseAudio_New( void )

if( !ptr->mainloop )
{
PA_PULSEAUDIO_SET_LAST_HOST_ERROR(0,
"PaPulseAudio_HostApiRepresentation: Can't allocate PulseAudio mainloop");
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_HostApiRepresentation: Can't allocate PulseAudio mainloop" );
goto fail;
}

Expand Down Expand Up @@ -186,8 +187,8 @@ void PaPulseAudio_Free( PaPulseAudio_HostApiRepresentation * ptr )
*/
if( !ptr )
{
PA_PULSEAUDIO_SET_LAST_HOST_ERROR(0,
"PaPulseAudio_Free: Host API is NULL! Can't do anything about it");
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_Free: Host API is NULL! Can't do anything about it" );
return;
}

Expand Down Expand Up @@ -233,7 +234,7 @@ void PaPulseAudio_CheckContextStateCb( pa_context * c,
{
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_CheckContextStateCb: Invalid context " );
pa_threaded_mainloop_signal(ptr->mainloop, 0);
pa_threaded_mainloop_signal( ptr->mainloop, 0 );
return;
}

Expand Down Expand Up @@ -281,8 +282,8 @@ int _PaPulseAudio_AddAudioDevice( PaPulseAudio_HostApiRepresentation *hostapi,
* which should be mostly suffient even pulseaudio device
* names can be very long
*/
int pulseaudioRealNameSize = strnlen(PaPulseAudio_SinkSourceNameDesc, PAPULSEAUDIO_MAX_DEVICENAME - 1) + 1;
int pulseaudioDeviceNameSize = strnlen(PaPulseAudio_SinkSourceName, PAPULSEAUDIO_MAX_DEVICENAME - 1) + 1;
int pulseaudioRealNameSize = strnlen( PaPulseAudio_SinkSourceNameDesc, (PAPULSEAUDIO_MAX_DEVICENAME - 1) ) + 1;
int pulseaudioDeviceNameSize = strnlen( PaPulseAudio_SinkSourceName, (PAPULSEAUDIO_MAX_DEVICENAME - 1) ) + 1;
char *pulseaudioLocalDeviceName = NULL;

hostapi->deviceInfoArray[hostapi->deviceCount].structVersion = 2;
Expand Down Expand Up @@ -467,7 +468,7 @@ void PaPulseAudio_StreamStateCb( pa_stream * s,
{
PA_DEBUG( ("Portaudio %s: Can get buffer attr: '%s'\n",
__FUNCTION__,
pa_strerror(pa_context_errno(pa_stream_get_context(s) ) ) ) );
pa_strerror(pa_context_errno(pa_stream_get_context(s) ) )) );
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_StreamStateCb: Can't get Stream pa_buffer_attr" );
}
Expand All @@ -484,7 +485,7 @@ void PaPulseAudio_StreamStateCb( pa_stream * s,
default:
PA_DEBUG( ("Portaudio %s: FAILED '%s'\n",
__FUNCTION__,
pa_strerror( pa_context_errno( pa_stream_get_context( s ) ) ) ) );
pa_strerror( pa_context_errno( pa_stream_get_context( s ) ) )) );

break;
}
Expand Down Expand Up @@ -831,7 +832,7 @@ PaError IsFormatSupported( struct PaUtilHostApiRepresentation *hostApi,
inputChannelCount = 0;
}

if( outputParameters)
if( outputParameters )
{
outputChannelCount = outputParameters->channelCount;
outputSampleFormat = outputParameters->sampleFormat;
Expand Down Expand Up @@ -926,13 +927,13 @@ PaError PaPulseAudio_ConvertPortaudioFormatToPaPulseAudio_( PaSampleFormat porta
PaError PaPulseAudio_BlockingInitRingBuffer( PaUtilRingBuffer * rbuf,
int size )
{
char *ringbufferBuffer = (char *) malloc(size);
char *ringbufferBuffer = (char *) malloc( size );
PaError ret = paNoError;

if( ringbufferBuffer == NULL )
{
PA_PULSEAUDIO_SET_LAST_HOST_ERROR(0,
"PaPulseAudio_BlockingInitRingBuffer: Not enough memory to handle request");
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_BlockingInitRingBuffer: Not enough memory to handle request" );
return paInsufficientMemory;
}

Expand All @@ -950,8 +951,8 @@ PaError PaPulseAudio_BlockingInitRingBuffer( PaUtilRingBuffer * rbuf,
free( ringbufferBuffer );
PA_DEBUG( ("Portaudio %s: Can't initialize input ringbuffer with size: %ld!\n",
__FUNCTION__, size) );
PA_PULSEAUDIO_SET_LAST_HOST_ERROR(0,
"PaPulseAudio_BlockingInitRingBuffer: Can't initialize input ringbuffer");
PA_PULSEAUDIO_SET_LAST_HOST_ERROR( 0,
"PaPulseAudio_BlockingInitRingBuffer: Can't initialize input ringbuffer" );

return paNotInitialized;
}
Expand Down Expand Up @@ -986,7 +987,7 @@ PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
/* validate platform specific flags */
if( (streamFlags & paPlatformSpecificFlags) != 0 )
{
return paInvalidFlag; /* unexpected platform specific flag */
return paInvalidFlag;
}

/* This is something that Pulseaudio can handle
Expand All @@ -1012,17 +1013,17 @@ PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
const char defaultSinkStreamName[] = "Portaudio sink";

stream->framesPerHostCallback = framesPerBuffer;
stream->inputStreamName = (char*)PaUtil_AllocateZeroInitializedMemory(sizeof(defaultSourceStreamName));
stream->outputStreamName = (char*)PaUtil_AllocateZeroInitializedMemory(sizeof(defaultSinkStreamName));
stream->inputStreamName = (char*)PaUtil_AllocateZeroInitializedMemory( sizeof( defaultSourceStreamName ) );
stream->outputStreamName = (char*)PaUtil_AllocateZeroInitializedMemory( sizeof( defaultSinkStreamName ) );
if ( !stream->inputStreamName || !stream->outputStreamName )
{
result = paInsufficientMemory;
goto openstream_error;
}

/* Copy initial stream names to memory. */
memcpy( stream->inputStreamName, defaultSourceStreamName, sizeof(defaultSourceStreamName) );
memcpy( stream->outputStreamName, defaultSinkStreamName, sizeof(defaultSinkStreamName) );
memcpy( stream->inputStreamName, defaultSourceStreamName, sizeof( defaultSourceStreamName ) );
memcpy( stream->outputStreamName, defaultSinkStreamName, sizeof( defaultSinkStreamName ) );

stream->isActive = 0;
stream->isStopped = 1;
Expand All @@ -1033,7 +1034,7 @@ PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
stream->outputStream = NULL;
memset( &stream->inputRing,
0x00,
sizeof(PaUtilRingBuffer) );
sizeof( PaUtilRingBuffer ) );

if( inputParameters )
{
Expand Down Expand Up @@ -1084,7 +1085,7 @@ PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
stream->inputSampleSpec.channels = inputChannelCount;
stream->inputChannelCount = inputChannelCount;

if( !pa_sample_spec_valid(&stream->inputSampleSpec) )
if( !pa_sample_spec_valid( &stream->inputSampleSpec ) )
{
PA_DEBUG( ("Portaudio %s: Invalid input audio spec!\n",
__FUNCTION__) );
Expand Down Expand Up @@ -1310,7 +1311,7 @@ PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
{
PaUtil_FreeMemory( stream->inputStreamName );
PaUtil_FreeMemory( stream->outputStreamName );
PaUtil_FreeMemory(stream);
PaUtil_FreeMemory( stream );
}

goto openstream_end;
Expand Down Expand Up @@ -1341,8 +1342,8 @@ PaTime GetStreamTime( PaStream * s )
if( stream->outputStream )
{
if( PaPulseAudio_updateTimeInfo( stream->outputStream,
&timeInfo,
0 ) == -PA_ERR_NODATA )
&timeInfo,
0 ) == -PA_ERR_NODATA )
{
return 0;
}
Expand All @@ -1351,8 +1352,8 @@ PaTime GetStreamTime( PaStream * s )
if( stream->inputStream )
{
if( PaPulseAudio_updateTimeInfo( stream->inputStream,
&timeInfo,
1 ) == -PA_ERR_NODATA )
&timeInfo,
1 ) == -PA_ERR_NODATA )
{
return 0;
}
Expand Down Expand Up @@ -1392,13 +1393,13 @@ PaError PaPulseAudio_RenameSource( PaStream *s, const char *streamName )

/* Reallocate stream name in memory. */
PaPulseAudio_Lock( stream->mainloop );
char *newStreamName = (char*)PaUtil_AllocateZeroInitializedMemory(strnlen(streamName, PAPULSEAUDIO_MAX_DEVICENAME) + 1);
char *newStreamName = (char*)PaUtil_AllocateZeroInitializedMemory( strnlen( streamName, PAPULSEAUDIO_MAX_DEVICENAME ) + 1 );
if ( !newStreamName )
{
PaPulseAudio_UnLock( stream->mainloop );
return paInsufficientMemory;
}
snprintf(newStreamName, strnlen(streamName, PAPULSEAUDIO_MAX_DEVICENAME) + 1, "%s", streamName);
snprintf( newStreamName, strnlen( streamName, PAPULSEAUDIO_MAX_DEVICENAME ) + 1, "%s", streamName );

PaUtil_FreeMemory( stream->inputStreamName );
stream->inputStreamName = newStreamName;
Expand Down Expand Up @@ -1428,13 +1429,13 @@ PaError PaPulseAudio_RenameSink( PaStream *s, const char *streamName )

/* Reallocate stream name in memory. */
PaPulseAudio_Lock( stream->mainloop );
char *newStreamName = (char*)PaUtil_AllocateZeroInitializedMemory(strnlen(streamName, PAPULSEAUDIO_MAX_DEVICENAME) + 1);
char *newStreamName = (char*)PaUtil_AllocateZeroInitializedMemory( strnlen( streamName, PAPULSEAUDIO_MAX_DEVICENAME ) + 1 );
if ( !newStreamName )
{
PaPulseAudio_UnLock( stream->mainloop );
return paInsufficientMemory;
}
snprintf(newStreamName, strnlen(streamName, PAPULSEAUDIO_MAX_DEVICENAME) + 1, "%s", streamName);
snprintf( newStreamName, strnlen( streamName, PAPULSEAUDIO_MAX_DEVICENAME ) + 1, "%s", streamName );

PaUtil_FreeMemory( stream->outputStreamName );
stream->outputStreamName = newStreamName;
Expand Down
12 changes: 6 additions & 6 deletions src/hostapi/pulseaudio/pa_linux_pulseaudio_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ PaError PaPulseAudio_ReadStreamBlock( PaStream * s,

while( bufferLeftToRead > 0 )
{
PA_PULSEAUDIO_IS_ERROR(pulseaudioStream, paStreamIsStopped)
PA_PULSEAUDIO_IS_ERROR( pulseaudioStream, paStreamIsStopped )

PaPulseAudio_Lock( pulseaudioStream->mainloop );
long l_read = PaUtil_ReadRingBuffer( &pulseaudioStream->inputRing, readableBuffer,
Expand Down Expand Up @@ -110,7 +110,7 @@ PaError PaPulseAudio_WriteStreamBlock( PaStream * s,

while( bufferLeftToWrite > 0)
{
PA_PULSEAUDIO_IS_ERROR(pulseaudioStream, paStreamIsStopped)
PA_PULSEAUDIO_IS_ERROR( pulseaudioStream, paStreamIsStopped )

PaPulseAudio_Lock( pulseaudioStream->mainloop );
pulseaudioWritable = pa_stream_writable_size( pulseaudioStream->outputStream );
Expand All @@ -131,8 +131,8 @@ PaError PaPulseAudio_WriteStreamBlock( PaStream * s,
PA_SEEK_RELATIVE );

pulseaudioOperation = pa_stream_update_timing_info( pulseaudioStream->outputStream,
NULL,
NULL );
NULL,
NULL );
PaPulseAudio_UnLock( pulseaudioStream->mainloop );

ret = 0;
Expand Down Expand Up @@ -192,6 +192,6 @@ signed long PaPulseAudio_GetStreamReadAvailableBlock( PaStream * s )
return 0;
}

return (PaUtil_GetRingBufferReadAvailable(&pulseaudioStream->inputRing) /
pulseaudioStream->inputFrameSize);
return ( PaUtil_GetRingBufferReadAvailable( &pulseaudioStream->inputRing ) /
pulseaudioStream->inputFrameSize );
}
19 changes: 9 additions & 10 deletions src/hostapi/pulseaudio/pa_linux_pulseaudio_cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int PaPulseAudio_updateTimeInfo( pa_stream * s,
pa_usec_t pulseaudioStreamLatency = 0;

if( pa_stream_get_time( s,
&pulseaudioStreamTime ) == -PA_ERR_NODATA )
&pulseaudioStreamTime ) == -PA_ERR_NODATA )
{
return -PA_ERR_NODATA;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ void _PaPulseAudio_WriteRingBuffer( PaUtilRingBuffer *ringbuffer,
* If you try to read too much and there is no room then this
* will fail. But I don't know how to get into that?
*/
if( PaUtil_GetRingBufferWriteAvailable(ringbuffer) < length )
if( PaUtil_GetRingBufferWriteAvailable( ringbuffer ) < length )
{
uint8_t tmpBuffer[ PULSEAUDIO_BUFFER_SIZE ];
PaUtil_ReadRingBuffer( ringbuffer,
Expand Down Expand Up @@ -666,7 +666,7 @@ PaError PaPulseAudio_StartStreamCb( PaStream * s )
if( ! pa_stream_connect_record( stream->inputStream,
pulseaudioName,
&stream->inputBufferAttr,
pulseaudioStreamFlags) )
pulseaudioStreamFlags ) )
{
pa_stream_set_started_callback( stream->inputStream,
PaPulseAudio_StreamStartedCb,
Expand Down Expand Up @@ -749,11 +749,11 @@ PaError PaPulseAudio_StartStreamCb( PaStream * s )
__FUNCTION__,
stream->outputDevice,
pulseaudioHostApi->pulseaudioDeviceNames[stream->
outputDevice]) );
outputDevice]) );
}

PaDeviceIndex defaultOutputDevice;
PaError result = PaUtil_DeviceIndexToHostApiDeviceIndex(&defaultOutputDevice,
PaError result = PaUtil_DeviceIndexToHostApiDeviceIndex( &defaultOutputDevice,
pulseaudioHostApi->inheritedHostApiRep.info.defaultOutputDevice,
&(pulseaudioHostApi->inheritedHostApiRep) );

Expand All @@ -764,7 +764,7 @@ PaError PaPulseAudio_StartStreamCb( PaStream * s )
if( result == paNoError && stream->outputDevice != defaultOutputDevice )
{
pulseaudioName = pulseaudioHostApi->
pulseaudioDeviceNames[stream->outputDevice];
pulseaudioDeviceNames[stream->outputDevice];
}

if(result == paNoError)
Expand Down Expand Up @@ -880,9 +880,9 @@ static PaError RequestStop( PaPulseAudio_Stream * stream,
&& !abort )
{
pulseaudioOperation = pa_stream_cork( stream->outputStream,
1,
PaPulseAudio_CorkSuccessCb,
stream );
1,
PaPulseAudio_CorkSuccessCb,
stream );

while( pa_operation_get_state( pulseaudioOperation ) == PA_OPERATION_RUNNING )
{
Expand Down Expand Up @@ -910,7 +910,6 @@ PaError PaPulseAudio_StopStreamCb( PaStream * s )
0 );
}


PaError PaPulseAudio_AbortStreamCb( PaStream * s )
{
return RequestStop( (PaPulseAudio_Stream *) s,
Expand Down

0 comments on commit b13c5a5

Please sign in to comment.