[FFmpeg-devel] [PATCH 3/3] lavf/dashdec: avoid reading the first data segment in read_header
rcombs
rcombs at rcombs.me
Fri May 22 08:42:00 EEST 2020
This reduces the number of requests that have to be made during startup.
---
libavformat/dashdec.c | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index ec2aadcee3..1bd070c7cb 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -1798,6 +1798,19 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
DASHContext *c = v->parent->priv_data;
restart:
+ /* load/update Media Initialization Section, if any */
+ if ((ret = update_init_section(v)) < 0)
+ goto end;
+
+ if (v->init_sec_buf_read_offset < v->init_sec_data_len) {
+ /* Push init section out first before first actual fragment */
+ int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size);
+ memcpy(buf, v->init_sec_buf, copy_size);
+ v->init_sec_buf_read_offset += copy_size;
+ ret = copy_size;
+ goto end;
+ }
+
if (!v->input) {
free_fragment(&v->cur_seg);
v->cur_seg = get_current_fragment(v);
@@ -1806,11 +1819,6 @@ restart:
goto end;
}
- /* load/update Media Initialization Section, if any */
- ret = update_init_section(v);
- if (ret)
- goto end;
-
ret = open_input(c, v, v->cur_seg);
if (ret < 0) {
if (ff_check_interrupt(c->interrupt_callback)) {
@@ -1823,15 +1831,6 @@ restart:
}
}
- if (v->init_sec_buf_read_offset < v->init_sec_data_len) {
- /* Push init section out first before first actual fragment */
- int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size);
- memcpy(buf, v->init_sec_buf, copy_size);
- v->init_sec_buf_read_offset += copy_size;
- ret = copy_size;
- goto end;
- }
-
/* check the v->cur_seg, if it is null, get current and double check if the new v->cur_seg*/
if (!v->cur_seg) {
v->cur_seg = get_current_fragment(v);
@@ -1940,10 +1939,19 @@ static int reopen_demux_for_component(AVFormatContext *s, struct representation
if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0)
goto fail;
+
+ if (pls->init_sec_data_len <= 0) {
+ /* load/update Media Initialization Section, if any */
+ if ((ret = update_init_section(pls)) < 0)
+ goto fail;
+ }
+
pls->ctx->flags = AVFMT_FLAG_CUSTOM_IO;
pls->ctx->probesize = s->probesize > 0 ? s->probesize : 1024 * 4;
+ if (pls->init_sec_data_len > 0)
+ pls->ctx->probesize = FFMIN(pls->ctx->probesize, pls->init_sec_data_len);
pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? s->max_analyze_duration : 4 * AV_TIME_BASE;
- ret = av_probe_input_buffer(&pls->pb, &in_fmt, "", NULL, 0, 0);
+ ret = av_probe_input_buffer(&pls->pb, &in_fmt, "", NULL, 0, pls->ctx->probesize);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Error when loading first fragment, playlist %d\n", (int)pls->rep_idx);
avformat_free_context(pls->ctx);
@@ -1954,6 +1962,9 @@ static int reopen_demux_for_component(AVFormatContext *s, struct representation
pls->ctx->pb = &pls->pb;
pls->ctx->io_open = nested_io_open;
+ if (pls->init_sec_data_len > 0)
+ av_dict_set_int(&in_fmt_opts, "header_size", pls->init_sec_data_len, 0);
+
// provide additional information from mpd if available
ret = avformat_open_input(&pls->ctx, "", in_fmt, &in_fmt_opts); //pls->init_section->url
av_dict_free(&in_fmt_opts);
--
2.26.2
More information about the ffmpeg-devel
mailing list