[FFmpeg-cvslog] avformat/hls: split read_from_url() out of read_data()

Anssi Hannula git at videolan.org
Sun Apr 6 16:56:40 CEST 2014


ffmpeg | branch: master | Anssi Hannula <anssi.hannula at iki.fi> | Sat Apr  5 12:16:27 2014 +0300| [1cb8d986b8d4c5c87332514d8ba483108fbbf949] | committer: Anssi Hannula

avformat/hls: split read_from_url() out of read_data()

Useful for ID3 parsing.

Signed-off-by: Anssi Hannula <anssi.hannula at iki.fi>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1cb8d986b8d4c5c87332514d8ba483108fbbf949
---

 libavformat/hls.c |   29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 9af3356..fe14255 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -600,6 +600,24 @@ fail:
     return ret;
 }
 
+/* read from URLContext, limiting read to current segment */
+static int read_from_url(struct playlist *pls, uint8_t *buf, int buf_size)
+{
+    int ret;
+    struct segment *seg = pls->segments[pls->cur_seq_no - pls->start_seq_no];
+
+     /* limit read if the segment was only a part of a file */
+    if (seg->size >= 0)
+        buf_size = FFMIN(buf_size, seg->size - pls->cur_seg_offset);
+
+    ret = ffurl_read(pls->input, buf, buf_size);
+
+    if (ret > 0)
+        pls->cur_seg_offset += ret;
+
+    return ret;
+}
+
 static int open_input(HLSContext *c, struct playlist *pls)
 {
     AVDictionary *opts = NULL;
@@ -702,8 +720,6 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
     struct playlist *v = opaque;
     HLSContext *c = v->parent->priv_data;
     int ret, i;
-    int actual_read_size;
-    struct segment *seg;
 
     if (!v->needed)
         return AVERROR_EOF;
@@ -754,16 +770,9 @@ reload:
             return ret;
         }
     }
-    /* limit read if the segment was only a part of a file */
-    seg = v->segments[v->cur_seq_no - v->start_seq_no];
-    if (seg->size >= 0)
-        actual_read_size = FFMIN(buf_size, seg->size - v->cur_seg_offset);
-    else
-        actual_read_size = buf_size;
 
-    ret = ffurl_read(v->input, buf, actual_read_size);
+    ret = read_from_url(v, buf, buf_size);
     if (ret > 0) {
-        v->cur_seg_offset += ret;
         return ret;
     }
     ffurl_close(v->input);



More information about the ffmpeg-cvslog mailing list