Skip to content

Commit

Permalink
Set unbuffered mode for PCM controller IO channel
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Oct 30, 2023
1 parent 72bada7 commit b65a40f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/bluealsa-dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "ba-adapter.h"
#include "ba-device.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-config.h"
#include "bluealsa-iface.h"
#include "bluez.h"
Expand Down Expand Up @@ -389,12 +390,16 @@ static gboolean bluealsa_pcm_controller(GIOChannel *ch, GIOCondition condition,
(void)condition;

struct ba_transport_pcm *pcm = userdata;
GError *err = NULL;
char command[32];
size_t len;

switch (g_io_channel_read_chars(ch, command, sizeof(command), &len, NULL)) {
switch (g_io_channel_read_chars(ch, command, sizeof(command), &len, &err)) {
case G_IO_STATUS_AGAIN:
return TRUE;
case G_IO_STATUS_ERROR:
error("Couldn't read controller channel");
error("PCM controller read error: %s", err->message);
g_error_free(err);
return TRUE;
case G_IO_STATUS_NORMAL:
if (strncmp(command, BLUEALSA_PCM_CTRL_DRAIN, len) == 0) {
Expand All @@ -421,8 +426,6 @@ static gboolean bluealsa_pcm_controller(GIOChannel *ch, GIOCondition condition,
}
g_io_channel_flush(ch, NULL);
return TRUE;
case G_IO_STATUS_AGAIN:
return TRUE;
case G_IO_STATUS_EOF:
pthread_mutex_lock(&pcm->mutex);
ba_transport_pcm_release(pcm);
Expand Down Expand Up @@ -517,6 +520,7 @@ static void bluealsa_pcm_open(GDBusMethodInvocation *inv, void *userdata) {
GIOChannel *ch = g_io_channel_unix_new(pcm_fds[2]);
g_io_channel_set_close_on_unref(ch, TRUE);
g_io_channel_set_encoding(ch, NULL, NULL);
g_io_channel_set_buffered(ch, FALSE);

g_io_add_watch_full(ch, G_PRIORITY_DEFAULT, G_IO_IN,
bluealsa_pcm_controller, ba_transport_pcm_ref(pcm),
Expand Down

0 comments on commit b65a40f

Please sign in to comment.