From 89c3c79d5e25f92fe7882e268b62b79288867f63 Mon Sep 17 00:00:00 2001 From: Edward Hervey <bilboed@bilboed.com> Date: Tue, 27 Jan 2009 15:59:25 +0100 Subject: [PATCH] Differentiate between "no more data" from "IO failure" when reading. Where no more data is available, av_read_frame just returns an error code instead of making the difference between "I am not returning anything because we finished reading" and "I am not returning anything because the underlying read failed". We differentiate between the two by looking at whether we outputted any data previously or not. --- ext/ffmpeg/gstffmpegdemux.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ext/ffmpeg/gstffmpegdemux.c b/ext/ffmpeg/gstffmpegdemux.c index 7556e492e8..725a5df58b 100644 --- a/ext/ffmpeg/gstffmpegdemux.c +++ b/ext/ffmpeg/gstffmpegdemux.c @@ -387,6 +387,7 @@ gst_ffmpegdemux_is_eos (GstFFMpegDemux * demux) for (n = 0; n < MAX_STREAMS; n++) { if ((s = demux->streams[n])) { + GST_DEBUG ("stream %d %p eos:%d", n, s, s->eos); if (!s->eos) return FALSE; } @@ -394,6 +395,22 @@ gst_ffmpegdemux_is_eos (GstFFMpegDemux * demux) return TRUE; } +/* Returns True if we at least outputted one buffer */ +static gboolean +gst_ffmpegdemux_has_outputted (GstFFMpegDemux * demux) +{ + GstFFStream *s; + gint n; + + for (n = 0; n < MAX_STREAMS; n++) { + if ((s = demux->streams[n])) { + if (GST_CLOCK_TIME_IS_VALID (s->last_ts)) + return TRUE; + } + } + return FALSE; +} + static gboolean gst_ffmpegdemux_do_seek (GstFFMpegDemux * demux, GstSegment * segment) { @@ -1446,7 +1463,11 @@ read_failed: /* pause appropriatly based on if we are flushing or not */ if (demux->flushing) ret = GST_FLOW_WRONG_STATE; - else + else if (gst_ffmpegdemux_has_outputted (demux) + || gst_ffmpegdemux_is_eos (demux)) { + GST_DEBUG_OBJECT (demux, "We are EOS"); + ret = GST_FLOW_UNEXPECTED; + } else ret = GST_FLOW_ERROR; GST_OBJECT_UNLOCK (demux);