Skip to content
Snippets Groups Projects
Commit bc31a579 authored by Lukasz Marek's avatar Lukasz Marek
Browse files

lavd/pulse_audio_enc: add nonblocking mode

parent eb9dee2d
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ typedef struct PulseData { ...@@ -41,6 +41,7 @@ typedef struct PulseData {
pa_threaded_mainloop *mainloop; pa_threaded_mainloop *mainloop;
pa_context *ctx; pa_context *ctx;
pa_stream *stream; pa_stream *stream;
int nonblocking;
} PulseData; } PulseData;
static void pulse_stream_writable(pa_stream *stream, size_t nbytes, void *userdata) static void pulse_stream_writable(pa_stream *stream, size_t nbytes, void *userdata)
...@@ -257,6 +258,7 @@ static av_cold int pulse_write_header(AVFormatContext *h) ...@@ -257,6 +258,7 @@ static av_cold int pulse_write_header(AVFormatContext *h)
else else
stream_name = "Playback"; stream_name = "Playback";
} }
s->nonblocking = (h->flags & AVFMT_FLAG_NONBLOCK);
if (s->buffer_duration) { if (s->buffer_duration) {
int64_t bytes = s->buffer_duration; int64_t bytes = s->buffer_duration;
...@@ -401,8 +403,13 @@ static int pulse_write_packet(AVFormatContext *h, AVPacket *pkt) ...@@ -401,8 +403,13 @@ static int pulse_write_packet(AVFormatContext *h, AVPacket *pkt)
av_log(s, AV_LOG_ERROR, "PulseAudio stream is in invalid state.\n"); av_log(s, AV_LOG_ERROR, "PulseAudio stream is in invalid state.\n");
goto fail; goto fail;
} }
while (!pa_stream_writable_size(s->stream)) while (!pa_stream_writable_size(s->stream)) {
pa_threaded_mainloop_wait(s->mainloop); if (s->nonblocking) {
pa_threaded_mainloop_unlock(s->mainloop);
return AVERROR(EAGAIN);
} else
pa_threaded_mainloop_wait(s->mainloop);
}
if ((ret = pa_stream_write(s->stream, pkt->data, pkt->size, NULL, 0, PA_SEEK_RELATIVE)) < 0) { if ((ret = pa_stream_write(s->stream, pkt->data, pkt->size, NULL, 0, PA_SEEK_RELATIVE)) < 0) {
av_log(s, AV_LOG_ERROR, "pa_stream_write failed: %s\n", pa_strerror(ret)); av_log(s, AV_LOG_ERROR, "pa_stream_write failed: %s\n", pa_strerror(ret));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment