aboutsummaryrefslogtreecommitdiffstats
path: root/libavdevice/pulse_audio_enc.c
diff options
context:
space:
mode:
authorLukasz Marek <lukasz.m.luki2@gmail.com>2014-04-06 23:12:44 +0200
committerLukasz Marek <lukasz.m.luki2@gmail.com>2014-04-18 01:42:18 +0200
commitbc31a57902b83ae09221d53861c35dcb0109c4f7 (patch)
treed7763007cfb2c670fadf2e4e0c86b14e12bf8c37 /libavdevice/pulse_audio_enc.c
parenteb9dee2d0d2d9fafb769c44b8d851fbd98263c34 (diff)
downloadffmpeg-bc31a57902b83ae09221d53861c35dcb0109c4f7.tar.gz
lavd/pulse_audio_enc: add nonblocking mode
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
Diffstat (limited to 'libavdevice/pulse_audio_enc.c')
-rw-r--r--libavdevice/pulse_audio_enc.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/libavdevice/pulse_audio_enc.c b/libavdevice/pulse_audio_enc.c
index 779766e963..6c02399e84 100644
--- a/libavdevice/pulse_audio_enc.c
+++ b/libavdevice/pulse_audio_enc.c
@@ -41,6 +41,7 @@ typedef struct PulseData {
pa_threaded_mainloop *mainloop;
pa_context *ctx;
pa_stream *stream;
+ int nonblocking;
} PulseData;
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)
else
stream_name = "Playback";
}
+ s->nonblocking = (h->flags & AVFMT_FLAG_NONBLOCK);
if (s->buffer_duration) {
int64_t bytes = s->buffer_duration;
@@ -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");
goto fail;
}
- while (!pa_stream_writable_size(s->stream))
- pa_threaded_mainloop_wait(s->mainloop);
+ while (!pa_stream_writable_size(s->stream)) {
+ 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) {
av_log(s, AV_LOG_ERROR, "pa_stream_write failed: %s\n", pa_strerror(ret));