Merge pull request #78 from glyptodon/pulseaudio-silence
GUAC-427: Avoid sending silence received from PulseAudio.
This commit is contained in:
commit
487dc3dc46
@ -29,6 +29,38 @@
|
|||||||
#include <guacamole/client.h>
|
#include <guacamole/client.h>
|
||||||
#include <pulse/pulseaudio.h>
|
#include <pulse/pulseaudio.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the given buffer contains only silence (only null bytes).
|
||||||
|
*
|
||||||
|
* @param buffer
|
||||||
|
* The audio buffer to check.
|
||||||
|
*
|
||||||
|
* @param length
|
||||||
|
* The length of the buffer to check.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* Non-zero if the audio buffer contains silence, zero otherwise.
|
||||||
|
*/
|
||||||
|
static int guac_pa_is_silence(const void* buffer, size_t length) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
const unsigned char* current = (const unsigned char*) buffer;
|
||||||
|
|
||||||
|
/* For each byte in buffer */
|
||||||
|
for (i = 0; i < length; i++) {
|
||||||
|
|
||||||
|
/* If current value non-zero, then not silence */
|
||||||
|
if (*(current++))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, the buffer contains 100% silence */
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void __stream_read_callback(pa_stream* stream, size_t length,
|
static void __stream_read_callback(pa_stream* stream, size_t length,
|
||||||
void* data) {
|
void* data) {
|
||||||
|
|
||||||
@ -41,6 +73,9 @@ static void __stream_read_callback(pa_stream* stream, size_t length,
|
|||||||
/* Read data */
|
/* Read data */
|
||||||
pa_stream_peek(stream, &buffer, &length);
|
pa_stream_peek(stream, &buffer, &length);
|
||||||
|
|
||||||
|
/* Avoid sending silence unless data is waiting to be flushed */
|
||||||
|
if (audio->pcm_bytes_written != 0 || !guac_pa_is_silence(buffer, length)) {
|
||||||
|
|
||||||
/* Write data */
|
/* Write data */
|
||||||
guac_audio_stream_write_pcm(audio, buffer, length);
|
guac_audio_stream_write_pcm(audio, buffer, length);
|
||||||
|
|
||||||
@ -53,6 +88,8 @@ static void __stream_read_callback(pa_stream* stream, size_t length,
|
|||||||
GUAC_VNC_AUDIO_BPS);
|
GUAC_VNC_AUDIO_BPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Advance buffer */
|
/* Advance buffer */
|
||||||
pa_stream_drop(stream);
|
pa_stream_drop(stream);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user