From patchwork Wed Jan 2 08:52:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 11633 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 D2B8644E266 for ; Wed, 2 Jan 2019 10:53:01 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 85F9868A8D8; Wed, 2 Jan 2019 10:52:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A51C868A8CF for ; Wed, 2 Jan 2019 10:52:49 +0200 (EET) X-QQ-mid: bizesmtp17t1546419147txe1xv87 Received: from localhost (unknown [111.204.87.210]) by esmtp6.qq.com (ESMTP) with id ; Wed, 02 Jan 2019 16:52:26 +0800 (CST) X-QQ-SSF: 01100000002000F0FNF0B00A0000000 X-QQ-FEAT: nSUdqPGu3tscXwk53HCXEPDltmbkUFOShRe3/UnMKL9gV0O0ytnW7u2E3sk2k 2UbnEqPP/uk3tR4WBFOVdP0j/w0/6K4+Lracp554BPb5s5oY0APYB3L0aOgiuSRhDylQy1I Mk99wR57Z8Yh6qNCJ1ayRZdYTCuVQHwEyAOWVn1R6rmXSWWje9qwdmY4yu6ZZ7dZb5GURX/ uenx2KamQbDr2AKYNY/oM1vp6qGXHN7J1fGZNZounA1P3Ax+TH8SwtTDTQJ86y/05HgWybP 0g7LO8Vm/2lHiVE1croditbbJgXiTXMSzPTQ== X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Jan 2019 16:52:23 +0800 Message-Id: <20190102085223.14309-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.15.2 (Apple Git-101.1) X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign2 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avformat/dashdec: control download speed when in live stream mode 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: Steven Liu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" fix ticket: 7369 check the duration is less than the fragment duration, retry when the condition is true. Signed-off-by: Steven Liu --- libavformat/dashdec.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index f4f4e935de..11c1307b18 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -108,6 +108,7 @@ struct representation { int64_t cur_seg_offset; int64_t cur_seg_size; struct fragment *cur_seg; + int64_t last_load_time; /* Currently active Media Initialization Section */ struct fragment *init_section; @@ -1084,6 +1085,8 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, } } + if (rep) + rep->last_load_time = get_current_time_in_sec(); video_rep_idx += type == AVMEDIA_TYPE_VIDEO; audio_rep_idx += type == AVMEDIA_TYPE_AUDIO; subtitle_rep_idx += type == AVMEDIA_TYPE_SUBTITLE; @@ -1382,6 +1385,9 @@ static int64_t calc_cur_seg_no(AVFormatContext *s, struct representation *pls) } else { num = pls->first_seq_no; } + + if (pls) + pls->last_load_time = get_current_time_in_sec(); return num; } @@ -1461,6 +1467,7 @@ static int refresh_manifest(AVFormatContext *s) { int ret = 0, i; + int64_t cur_time = get_current_time_in_sec(); DASHContext *c = s->priv_data; // save current context @@ -1505,6 +1512,11 @@ static int refresh_manifest(AVFormatContext *s) for (i = 0; i < n_videos; i++) { struct representation *cur_video = videos[i]; struct representation *ccur_video = c->videos[i]; + if (cur_video) + cur_video->last_load_time = cur_time; + if (ccur_video) + ccur_video->last_load_time = cur_time; + if (cur_video->timelines) { // calc current time int64_t currentTime = get_segment_start_time_based_on_timeline(cur_video, cur_video->cur_seq_no) / cur_video->fragment_timescale; @@ -1521,6 +1533,11 @@ static int refresh_manifest(AVFormatContext *s) for (i = 0; i < n_audios; i++) { struct representation *cur_audio = audios[i]; struct representation *ccur_audio = c->audios[i]; + if (cur_audio) + cur_audio->last_load_time = cur_time; + if (ccur_audio) + ccur_audio->last_load_time = cur_time; + if (cur_audio->timelines) { // calc current time int64_t currentTime = get_segment_start_time_based_on_timeline(cur_audio, cur_audio->cur_seq_no) / cur_audio->fragment_timescale; @@ -1629,6 +1646,8 @@ static struct fragment *get_current_fragment(struct representation *pls) av_free(tmpfilename); seg->size = -1; } + if (pls) + pls->last_load_time = get_current_time_in_sec(); return seg; } @@ -1747,6 +1766,10 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size) DASHContext *c = v->parent->priv_data; restart: + if (c->is_live && v->fragment_duration != 0 && v->fragment_timescale != 0) + if (get_current_time_in_sec() - v->last_load_time < (v->fragment_duration / v->fragment_timescale)) { + goto restart; + } if (!v->input) { free_fragment(&v->cur_seg); v->cur_seg = get_current_fragment(v);