From patchwork Sun Aug 23 12:23:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongcheng Zhong X-Patchwork-Id: 21843 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 285E8449B15 for ; Sun, 23 Aug 2020 15:24:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C12B689EA6; Sun, 23 Aug 2020 15:24:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp181.sjtu.edu.cn (smtp181.sjtu.edu.cn [202.120.2.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 94D2968827C for ; Sun, 23 Aug 2020 15:24:21 +0300 (EEST) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp181.sjtu.edu.cn (Postfix) with ESMTPS id EB1BB1008CBC4; Sun, 23 Aug 2020 20:24:18 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id E71B8200B449C; Sun, 23 Aug 2020 20:24:18 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tQB8_ayXvIIB; Sun, 23 Aug 2020 20:24:18 +0800 (CST) Received: from localhost.localdomain (unknown [10.162.157.92]) (Authenticated sender: sj.hc_Zhong@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 472C0200B4496; Sun, 23 Aug 2020 20:24:16 +0800 (CST) From: Hongcheng Zhong To: ffmpeg-devel@ffmpeg.org Date: Sun, 23 Aug 2020 20:23:54 +0800 Message-Id: <20200823122355.188611-6-sj.hc_Zhong@sjtu.edu.cn> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200823122355.188611-1-sj.hc_Zhong@sjtu.edu.cn> References: <20200823122355.188611-1-sj.hc_Zhong@sjtu.edu.cn> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] [GSoC v3 6/7] avformat/hls add metadata "abr_initial" for ffplay X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: spartazhc Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: spartazhc Add an AVDictionary option "abr_initial", which could be used to send message to ffplay. Currently, the first entry "abr_init_duration" is added. Signed-off-by: spartazhc --- doc/demuxers.texi | 3 +++ libavformat/hls.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/doc/demuxers.texi b/doc/demuxers.texi index 4cdbd95962..761a372b86 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -324,6 +324,9 @@ It accepts the following options: @item abr enable abr to switch streams. +@item abr_initial +metadata used by abr for ffplay. + @item live_start_index segment index to start live streams at (negative values are from the end). diff --git a/libavformat/hls.c b/libavformat/hls.c index 37a5a017b1..5c251cd002 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -243,6 +243,7 @@ typedef struct HLSContext { AVIOContext *playlist_pb; int abr; + AVDictionary *abr_initial; struct throughput *throughputs; struct switch_task *switch_tasks; struct switch_info *switch_info; @@ -2308,6 +2309,7 @@ static int hls_read_header(AVFormatContext *s) } if (c->abr) { + int64_t abr_init_duration = AV_NOPTS_VALUE; c->switch_tasks = av_malloc(c->n_playlists * sizeof(struct switch_task)); if (!c->switch_tasks) { ret = AVERROR(ENOMEM); @@ -2326,6 +2328,15 @@ static int hls_read_header(AVFormatContext *s) for (i = 0; i < c->n_playlists; i++) { struct playlist *pls = c->playlists[i]; int type; + int64_t start = 0; + for (int i = 0; i < c->cur_seq_no + 1; i++) { + start += pls->segments[i]->duration; + } + start = av_rescale_q(start, + AV_TIME_BASE_Q, + get_timebase(pls)); + if (abr_init_duration == AV_NOPTS_VALUE || abr_init_duration > start) + abr_init_duration = start; c->switch_tasks[i].switch_timestamp = AV_NOPTS_VALUE; type = playlist_type_simple(pls); @@ -2337,6 +2348,7 @@ static int hls_read_header(AVFormatContext *s) c->switch_info[SWITCH_VIDEO].pls_index = pls->index; } } + av_dict_set_int(&c->abr_initial, "abr_init_duration", abr_init_duration, 0); } update_noheader_flag(s); @@ -2768,6 +2780,8 @@ static int hls_probe(const AVProbeData *p) static const AVOption hls_options[] = { {"abr", "enable abr to switch streams", OFFSET(abr), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, + {"abr_initial", "metadata used by abr for ffplay", + OFFSET(abr_initial), AV_OPT_TYPE_DICT, { 0 }, 0, 0, FLAGS }, {"live_start_index", "segment index to start live streams at (negative values are from the end)", OFFSET(live_start_index), AV_OPT_TYPE_INT, {.i64 = -3}, INT_MIN, INT_MAX, FLAGS}, {"allowed_extensions", "List of file extensions that hls is allowed to access",