changeset 5544:fc48f8bfbf2e libavformat

restore old buffer content when seek failed in http protocol, fix issue #1631
author bcoudurier
date Wed, 13 Jan 2010 23:27:52 +0000
parents fbedfacb36ed
children 3a5082b94ab3
files http.c
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/http.c	Wed Jan 13 22:57:37 2010 +0000
+++ b/http.c	Wed Jan 13 23:27:52 2010 +0000
@@ -394,6 +394,8 @@
     HTTPContext *s = h->priv_data;
     URLContext *old_hd = s->hd;
     int64_t old_off = s->off;
+    uint8_t old_buf[BUFFER_SIZE];
+    int old_buf_size;
 
     if (whence == AVSEEK_SIZE)
         return s->filesize;
@@ -401,6 +403,8 @@
         return -1;
 
     /* we save the old context in case the seek fails */
+    old_buf_size = s->buf_end - s->buf_ptr;
+    memcpy(old_buf, s->buf_ptr, old_buf_size);
     s->hd = NULL;
     if (whence == SEEK_CUR)
         off += s->off;
@@ -410,6 +414,9 @@
 
     /* if it fails, continue on old connection */
     if (http_open_cnx(h) < 0) {
+        memcpy(s->buffer, old_buf, old_buf_size);
+        s->buf_ptr = s->buffer;
+        s->buf_end = s->buffer + old_buf_size;
         s->hd = old_hd;
         s->off = old_off;
         return -1;