From 94d9ad5f80e85af0cead5b6c6b2efdb7d947ca4f Mon Sep 17 00:00:00 2001
From: Giancarlo Formicuccia <ilsensine@inwind.it>
Date: Sun, 29 Jun 2003 01:25:41 +0000
Subject: [PATCH] *** fix for read() Reading 1-char per read() is the less
 intrusive way to fix the behaviour I observed. Not a nice fix, but the client
 requests shouldn't steal so much bandwidth *** fix for
 find_rtp_session_with_url. Note that mplayer send one PLAY request per
 stream, I don't know if this should be handled more gracefully patch by
 (Giancarlo Formicuccia <ilsensine at inwind dot it>)

Originally committed as revision 1998 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 ffserver.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index 265e3ac579f..d8cbef53311 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -786,14 +786,14 @@ static int handle_connection(HTTPContext *c)
         if (!(c->poll_entry->revents & POLLIN))
             return 0;
         /* read the data */
-        len = read(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr);
+        len = read(c->fd, c->buffer_ptr, 1);
         if (len < 0) {
             if (errno != EAGAIN && errno != EINTR)
                 return -1;
         } else if (len == 0) {
             return -1;
         } else {
-            /* search for end of request. XXX: not fully correct since garbage could come after the end */
+            /* search for end of request. */
             uint8_t *ptr;
             c->buffer_ptr += len;
             ptr = c->buffer_ptr;
@@ -2973,6 +2973,8 @@ static HTTPContext *find_rtp_session_with_url(const char *url,
     HTTPContext *rtp_c;
     char path1[1024];
     const char *path;
+    char buf[1024];
+    int s;
 
     rtp_c = find_rtp_session(session_id);
     if (!rtp_c)
@@ -2983,9 +2985,16 @@ static HTTPContext *find_rtp_session_with_url(const char *url,
     path = path1;
     if (*path == '/')
         path++;
-    if (strcmp(path, rtp_c->stream->filename) != 0)
-        return NULL;
-    return rtp_c;
+    if(!strcmp(path, rtp_c->stream->filename)) return rtp_c;
+    for(s=0; s<rtp_c->stream->nb_streams; ++s) {
+      snprintf(buf, sizeof(buf), "%s/streamid=%d",
+        rtp_c->stream->filename, s);
+      if(!strncmp(path, buf, sizeof(buf))) {
+    // XXX: Should we reply with RTSP_STATUS_ONLY_AGGREGATE if nb_streams>1?
+        return rtp_c;
+      }
+    }
+    return NULL;
 }
 
 static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPHeader *h)
-- 
GitLab