Skip to content

Bug fixes #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
33 changes: 20 additions & 13 deletions pipewire/qubes-pw-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,26 @@ static const struct spa_dict_item module_props[] = {
struct impl;

struct qubes_stream {
// Stream properties. Immutable after init.
struct pw_properties *stream_props;
// Pointer to stream. Immutable after init.
struct pw_stream *stream;
// Stream event listener. Accessed on main thread only.
struct spa_hook stream_listener;
// Audio format info. Accessed only on main thread.
struct spa_audio_info_raw info;
// Vchans, explicitly synchronized using message passing.
struct libvchan *vchan, *closed_vchan;
// Pointer to the implementation.
struct impl *impl;
atomic_size_t current_state, last_state;
struct spa_source source;
// Set at creation, immutable afterwards
size_t buffer_size;
bool is_open, direction;
// Whether the stream is open. Only accessed on RT thread.
bool is_open;
// Set at creation, immutable afterwards
bool direction;
atomic_bool dead, in_use;
};

Expand Down Expand Up @@ -376,6 +386,7 @@ static int main_thread_connect(struct spa_loop *loop,
stream->direction,
PW_ID_ANY,
PW_STREAM_FLAG_AUTOCONNECT |
PW_STREAM_FLAG_MAP_BUFFERS |
PW_STREAM_FLAG_RT_PROCESS |
0,
params, n_params) < 0)
Expand Down Expand Up @@ -473,7 +484,7 @@ static void discard_unwanted_recorded_data(struct qubes_stream *stream)
return;

size_t to_read = (size_t)ready;
pw_log_debug("Discarding %d bytes of unwanted data", ready);
pw_log_trace("Discarding %d bytes of unwanted data", ready);
while (to_read > 0) {
int res = libvchan_read(stream->vchan, buf, to_read > sizeof buf ? sizeof buf : to_read);
if (res <= 0)
Expand Down Expand Up @@ -616,20 +627,16 @@ static void capture_stream_process(void *d)

spa_assert(buf->n_datas == 1 && "wrong number of datas");

size = buf->datas[0].maxsize;
// TODO: handle more data
#if PW_CHECK_VERSION(0, 3, 49)
if (SPA_UNLIKELY(b->requested > size))
pw_log_warn("Can only record %" PRIu32 " bytes of %" PRIu64, size,
b->requested);
else if (b->requested)
size = b->requested;
#endif

if (__builtin_mul_overflow(size, impl->frame_size, &size)) {
if (__builtin_mul_overflow(b->requested ? b->requested : 4096, impl->frame_size, &size)) {
pw_log_error("Overflow calculating amount of data there is room for????");
goto done;
}
size = SPA_MIN(size, buf->datas[0].maxsize);
#else
size = buf->datas[0].maxsize;
#endif
buf->datas[0].chunk->size = size;

if (size > bytes_ready) {
Expand All @@ -638,7 +645,7 @@ static void capture_stream_process(void *d)
size = bytes_ready;
}

pw_log_debug("reading %" PRIu32 " bytes from vchan", size);
pw_log_trace("reading %" PRIu32 " bytes from vchan", size);
if (size && libvchan_read(stream->vchan, dst, size) != (int)size) {
pw_log_error("vchan error: %m");
// avoid recording uninitialized memory
Expand Down Expand Up @@ -691,7 +698,7 @@ static void playback_stream_process(void *d)
size = ready;
}

pw_log_debug("writing %" PRIu32 " bytes to vchan", size);
pw_log_trace("writing %" PRIu32 " bytes to vchan", size);
if (size > 0 && libvchan_write(stream->vchan, data, size) != (int)size) {
pw_log_error("vchan error: %m");
return;
Expand Down