Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 62 additions & 17 deletions src/hostapi/pulseaudio/pa_linux_pulseaudio_cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,20 @@ static int _PaPulseAudio_ProcessAudio(PaPulseAudio_Stream *stream,

if( !stream->isActive && stream->pulseaudioIsActive && stream->outputStream)
{
bufferData = pulseaudioSampleBuffer;
memset( bufferData, 0x00, length);
size_t tmpSize = length;

/* Allocate memory to make it faster to output stuff */
pa_stream_begin_write( stream->outputStream, &bufferData, &tmpSize );

/* If bufferData is NULL then output is not ready
* and we have to wait for it
*/
if(!bufferData)
{
Comment thread
RossBencina marked this conversation as resolved.
return paNotInitialized;
Comment thread
illuusio marked this conversation as resolved.
}

memset( bufferData, 0x00, tmpSize);

pa_stream_write( stream->outputStream,
bufferData,
Expand All @@ -323,8 +335,16 @@ static int _PaPulseAudio_ProcessAudio(PaPulseAudio_Stream *stream,
}


while(1)
do
{
/* Make sure that bufferData is NULL that marks there
* is nothing to output
*/
if( isOutputCb )
{
bufferData = NULL;
}

/*
* If everything fail like stream vanish or mainloop
* is in error state try to handle error
Expand Down Expand Up @@ -396,6 +416,9 @@ static int _PaPulseAudio_ProcessAudio(PaPulseAudio_Stream *stream,
hostFramesPerBuffer );
}

/* Is output is enable and buffer data is not NULL
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code does not check that "buffer data is not null".

* then crap pointer to output ringbuffer
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a "crap pointer"?

*/
if( isOutputCb )
{

Expand All @@ -404,14 +427,6 @@ static int _PaPulseAudio_ProcessAudio(PaPulseAudio_Stream *stream,
/* Allocate memory to make it faster to output stuff */
pa_stream_begin_write( stream->outputStream, &bufferData, &tmpSize );

/* If bufferData is NULL then output is not ready
* and we have to wait for it
*/
if(!bufferData)
{
return paNotInitialized;
}

PaUtil_SetInterleavedOutputChannels( &stream->bufferProcessor,
0,
bufferData,
Expand All @@ -420,6 +435,31 @@ static int _PaPulseAudio_ProcessAudio(PaPulseAudio_Stream *stream,
PaUtil_SetOutputFrameCount( &stream->bufferProcessor,
hostFramesPerBuffer );

}

hostFrameCount =
PaUtil_EndBufferProcessing( &stream->bufferProcessor,
&ret );

PaUtil_EndCpuLoadMeasurement( &stream->cpuLoadMeasurer,
hostFrameCount );

Comment thread
illuusio marked this conversation as resolved.
/*
* pa_stream_begin_write gives pointer to ring
* buffer in Pulseaudio. WhenPaUtil_EndBufferProcessing
* returns paContinue then is ok to write output.
*
* When it's something else than paContinue
* then we have to cancel writing with
* with pa_stream_cancel_write.
*
* If there is no space in output ringbuffer or for
* example USB device has dissapiered and pointer
* is NULL then we just get out of loop as there is not much
* we can't do
*/
if( ret == paContinue && isOutputCb && bufferData )
{
if( pa_stream_write( stream->outputStream,
bufferData,
pulseaudioOutputBytes,
Expand All @@ -433,14 +473,19 @@ static int _PaPulseAudio_ProcessAudio(PaPulseAudio_Stream *stream,

pulseaudioOutputWritten += pulseaudioOutputBytes;
}
else if( ret != paContinue && isOutputCb && bufferData )
{
pa_stream_cancel_write( stream->outputStream );
bufferData = NULL;
}
else if( isOutputCb && !bufferData )
{
ret = -1;
}
}
while( ret == paContinue );

hostFrameCount =
PaUtil_EndBufferProcessing( &stream->bufferProcessor,
&ret );

PaUtil_EndCpuLoadMeasurement( &stream->cpuLoadMeasurer,
hostFrameCount );
}

return ret;
}
Expand Down
Loading