Skip to content
Open
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
16 changes: 7 additions & 9 deletions src/plugins/pulse/ao_pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <ao/ao.h>
#include <ao/plugin.h>

#define AO_PULSE_BUFFER_TIME 20000
#define AO_PULSE_BUFFER_TIME 20

/* Unfortunately libao doesn't allow "const" for these structures... */
static char * ao_pulse_options[] = {
Expand Down Expand Up @@ -73,7 +73,7 @@ typedef struct ao_pulse_internal {
struct pa_simple *simple;
char *server, *sink, *client_name;
pa_usec_t static_delay;
pa_usec_t buffer_time;
int buffer_time;
Copy link

Choose a reason for hiding this comment

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

Wouldn't this make more sense as unsigned?

Copy link
Author

@tomty89 tomty89 Sep 11, 2025

Choose a reason for hiding this comment

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

@ePirat To be frank, my C is really bad, so I don't exactly know. I don't even remember why I made this change because this was so long ago. I think the reason was that atoi returns int, and/or there was this (int) casting for (internal->buffer_time * format->rate), so to prevent something goes wrong accidentally (like it being an unsigned resulting in other variables getting set to some unexpected value), I went with int.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, actually it might be because atoi(value) * 1000 was apparently due to buffer_time being a "usec", and because there is no "pa_msec_t", I went with what atoi returns when I remove the * 1000 (and didn't care what tlength is)...

Copy link
Author

@tomty89 tomty89 Sep 11, 2025

Choose a reason for hiding this comment

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

Should I maybe just ditch this line of change? Like keeping it as pa_usec_t (uint64_t)? Or should I change it to unsigned int (or uint32_t?) anyway?

(Does using 64-bit for it minimize the chance of overflow as of internal->buffer_time * format->rate (i.e. before / 1000)? Or does the "limit" come from what tlength is instead?)

} ao_pulse_internal;

/* Yes, this is very ugly, but required nonetheless... */
Expand Down Expand Up @@ -174,8 +174,8 @@ int ao_plugin_set_option(ao_device *device, const char *key, const char *value)
} else if (!strcmp(key, "client_name")) {
free(internal->client_name);
internal->client_name = strdup(value);
}else if (!strcmp(key, "buffer_time")){
internal->buffer_time = atoi(value) * 1000;
} else if (!strcmp(key, "buffer_time")) {
internal->buffer_time = atoi(value);
}

return 1;
Expand Down Expand Up @@ -256,12 +256,10 @@ int ao_plugin_open(ao_device *device, ao_sample_format *format) {
}

/* buffering attributes */
battr.prebuf = battr.minreq = battr.fragsize = -1;
battr.prebuf = battr.minreq = battr.fragsize = battr.maxlength = -1;

battr.tlength = (int)(internal->buffer_time * format->rate) / 1000000 *
((format->bits+7)/8) * device->output_channels;
battr.minreq = battr.tlength/4;
battr.maxlength = battr.tlength+battr.minreq;
battr.tlength = internal->buffer_time * format->rate / 1000 *
(format->bits / 8) * device->output_channels;

internal->simple = pa_simple_new(internal->server, t, PA_STREAM_PLAYBACK,
internal->sink, t2, &ss,
Expand Down