From 53e2f9caf80ed385a3d4cfb9200d8827b65580ef Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michaelni@gmx.at>
Date: Sun, 25 Jul 2004 11:59:34 +0000
Subject: [PATCH] ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot
 nl>)

Originally committed as revision 3340 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 ffserver.c            | 4 +++-
 libavformat/aviobuf.c | 7 ++++---
 libavformat/ffm.c     | 1 +
 libavformat/utils.c   | 8 +++++++-
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index 7423abc07b4..cb195ef88e6 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -600,7 +600,9 @@ static int http_server(void)
            second to handle timeouts */
         do {
             ret = poll(poll_table, poll_entry - poll_table, delay);
-        } while (ret == -1);
+            if (ret < 0 && errno != EAGAIN && errno != EINTR)
+                return -1;
+        } while (ret <= 0);
         
         cur_time = gettime_ms();
 
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 3838e46669a..0ad63299a4f 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -148,7 +148,8 @@ offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
                 return -EPIPE;
             s->buf_ptr = s->buffer;
             s->buf_end = s->buffer;
-            s->seek(s->opaque, offset, SEEK_SET);
+            if (s->seek(s->opaque, offset, SEEK_SET) == (offset_t)-EPIPE)
+                return -EPIPE;
             s->pos = offset;
         }
         s->eof_reached = 0;
@@ -449,8 +450,8 @@ static int url_read_packet(void *opaque, uint8_t *buf, int buf_size)
 static int url_seek_packet(void *opaque, int64_t offset, int whence)
 {
     URLContext *h = opaque;
-    url_seek(h, offset, whence);
-    return 0;
+    return url_seek(h, offset, whence);
+    //return 0;
 }
 
 int url_fdopen(ByteIOContext *s, URLContext *h)
diff --git a/libavformat/ffm.c b/libavformat/ffm.c
index fca46b170f2..22a2a812ff9 100644
--- a/libavformat/ffm.c
+++ b/libavformat/ffm.c
@@ -150,6 +150,7 @@ static int ffm_write_header(AVFormatContext *s)
         fst = av_mallocz(sizeof(FFMStream));
         if (!fst)
             goto fail;
+        av_set_pts_info(st, 64, 1, 1000000);
         st->priv_data = fst;
 
         codec = &st->codec;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 04e11e20702..be3df4a6e74 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -428,7 +428,13 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
         if (!fmt) {
             /* read probe data */
             pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
-            url_fseek(pb, 0, SEEK_SET);
+            if (url_fseek(pb, 0, SEEK_SET) == (offset_t)-EPIPE) {
+                url_fclose(pb);
+                if (url_fopen(pb, filename, URL_RDONLY) < 0) {
+                    err = AVERROR_IO;
+                    goto fail;
+                }
+            }
         }
     }
     
-- 
GitLab