summaryrefslogtreecommitdiff
path: root/libavformat/hls.c
diff options
context:
space:
mode:
authorAnssi Hannula <anssi.hannula@iki.fi>2014-04-05 12:16:27 +0300
committerAnssi Hannula <anssi.hannula@iki.fi>2014-04-06 17:55:03 +0300
commit1cb8d986b8d4c5c87332514d8ba483108fbbf949 (patch)
treeaff53bc9514173998ad009503ac122c0e68eb559 /libavformat/hls.c
parentf7c7fc13698abcdd35a919024cf9129e67fbcff0 (diff)
avformat/hls: split read_from_url() out of read_data()
Useful for ID3 parsing. Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Diffstat (limited to 'libavformat/hls.c')
-rw-r--r--libavformat/hls.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/libavformat/hls.c b/libavformat/hls.c
index 9af3356a38..fe142557d0 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);