CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
"pa_threaded_mainloop_lock failed\n");
+ if (pa_stream_get_state(p->stream) != PA_STREAM_READY) {
+ /* wait for stream to become ready */
+ l = 0;
+ ret = NULL;
+ goto unlock;
+ }
l = pa_stream_writable_size(p->stream);
CHECK_SUCCESS_GOTO(c, l != (size_t) -1, unlock_and_fail,
CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail,
"pa_stream_begin_write failed\n");
+unlock:
pa_threaded_mainloop_unlock(c->mainloop);
if (*size > l) {
*size = l;
CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
"pa_threaded_mainloop_lock failed\n");
+ if (pa_stream_get_state(p->stream) != PA_STREAM_READY) {
+ /* wait for stream to become ready */
+ l = 0;
+ goto unlock;
+ }
l = pa_stream_writable_size(p->stream);
r = pa_stream_write(p->stream, data, l, NULL, 0LL, PA_SEEK_RELATIVE);
CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed\n");
+unlock:
pa_threaded_mainloop_unlock(c->mainloop);
return l;
}
if (r < 0) {
- goto fail;
+ goto fail;
}
pa_threaded_mainloop_unlock(c->mainloop);
ss.rate = as->freq;
ba.tlength = pa_usec_to_bytes(ppdo->latency, &ss);
- ba.minreq = -1;
+ ba.minreq = pa_usec_to_bytes(MIN(ppdo->latency >> 2,
+ (g->dev->timer_period >> 2) * 3), &ss);
ba.maxlength = -1;
ba.prebuf = -1;
}
audio_pcm_init_info (&hw->info, &obt_as);
+ /*
+ * This is wrong. hw->samples counts in frames. hw->samples will be
+ * number of channels times larger than expected.
+ */
hw->samples = audio_buffer_samples(
- qapi_AudiodevPaPerDirectionOptions_base(ppdo),
- &obt_as, ppdo->buffer_length);
+ qapi_AudiodevPaPerDirectionOptions_base(ppdo), &obt_as, 46440);
return 0;
ss.channels = as->nchannels;
ss.rate = as->freq;
- ba.fragsize = pa_usec_to_bytes(ppdo->latency, &ss);
- ba.maxlength = pa_usec_to_bytes(ppdo->latency * 2, &ss);
+ ba.fragsize = pa_usec_to_bytes((g->dev->timer_period >> 1) * 3, &ss);
+ ba.maxlength = pa_usec_to_bytes(
+ MAX(ppdo->latency, g->dev->timer_period * 3), &ss);
ba.minreq = -1;
ba.prebuf = -1;
}
audio_pcm_init_info (&hw->info, &obt_as);
+ /*
+ * This is wrong. hw->samples counts in frames. hw->samples will be
+ * number of channels times larger than expected.
+ */
hw->samples = audio_buffer_samples(
- qapi_AudiodevPaPerDirectionOptions_base(ppdo),
- &obt_as, ppdo->buffer_length);
+ qapi_AudiodevPaPerDirectionOptions_base(ppdo), &obt_as, 46440);
return 0;
static int qpa_validate_per_direction_opts(Audiodev *dev,
AudiodevPaPerDirectionOptions *pdo)
{
- if (!pdo->has_buffer_length) {
- pdo->has_buffer_length = true;
- pdo->buffer_length = 46440;
- }
if (!pdo->has_latency) {
pdo->has_latency = true;
pdo->latency = 15000;