From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id ED3B24265B for ; Fri, 24 Jun 2022 16:45:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A5AA468B6A3; Fri, 24 Jun 2022 19:45:14 +0300 (EEST) Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7554068B3B1 for ; Fri, 24 Jun 2022 19:45:08 +0300 (EEST) Received: by mail-pj1-f41.google.com with SMTP id t3-20020a17090a510300b001ea87ef9a3dso3340733pjh.4 for ; Fri, 24 Jun 2022 09:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DbvekdzaljiyeNd3xL+ayfUkvvIMWSFHJW+PQT747wE=; b=kRQP+Bbupn5q4tY2C/HLnPbmqMult+nKvilH7GXN7x7NYepD+ZkZPBMmgJXOFUh5+w crkN/CUwHGa3QblJkO2uuIp9wjI5dExnywW7ZVA8p/veqTnbpFYX+KGiZIKJv6wslLSS +aCHD2GRlxA49T1H5Xeq72rHXStCIUGA25yqj5DNofWnVC7JhDFZMRxGa/qvy09sElvf Tqcu1BbyxRIt4Is5RXFOxlypOV8L9tugvwVX7yIuyAQXe98CLERDnH8CIdjdngEU+yfC sXWNDH7wHq/9MC44Jo76ZH+s3JeUz36z2D+f+Ooj0O0F/bnqaczA0QlScFe/ZhlI7Cnc MtIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DbvekdzaljiyeNd3xL+ayfUkvvIMWSFHJW+PQT747wE=; b=yDXpY+J/8f7q5JsTtsbA/AoT4KOmKfwgAlzqLtKx9rAklpfsA5hRxQSJIUzvCIGpfL U9RU7WL5J1/47YbrFQE7pK8HcPgqr3mQVnVnU3V8WjnrsaV4bLe/N4SDqXB+GALfew23 DzScLonCOcyZHqCVycUvgoQGNqSnavQ/ukdL8uYsfwrD5QQ7PvfeGjfLAcT5upYiNQAy SK66ZpYypT+om4XzRtP9ICPDE5om/ScsAK0yzB2zWBDXg2djjMLUgrLcKbUqxEzJxH/B E5uUh0DKKHHVKp75fb+XXfydB1PqvQJXpVEaqG4rWagNwEAI+57ohLaqnBU+V5zKbKMX Y7Lw== X-Gm-Message-State: AJIora9uInTtYauPzFUAP50hBDdFwsQ9xvxMIYMfdv2PTUOfsCezzLyO YeQNf/3s4Bu1A58QFwUTgFFsAbe7/lxcvfgf X-Google-Smtp-Source: AGRyM1vasRhMqfGAPUFiVpihFKvD7YNQf+k2M/zJxgDr2HQ9w7kRQcb7vH0JDcU2R/G/3J3wRLUbQg== X-Received: by 2002:a17:903:110c:b0:168:fa61:1440 with SMTP id n12-20020a170903110c00b00168fa611440mr44909865plh.149.1656089105888; Fri, 24 Jun 2022 09:45:05 -0700 (PDT) Received: from localhost.localdomain ([117.143.145.80]) by smtp.gmail.com with ESMTPSA id v11-20020a1709028d8b00b0016a4f3ca2b5sm2023735plo.277.2022.06.24.09.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jun 2022 09:45:05 -0700 (PDT) From: Li Kai X-Google-Original-From: Li Kai To: ffmpeg-devel@ffmpeg.org Date: Sat, 25 Jun 2022 00:44:50 +0800 Message-Id: <20220624164450.2619136-1-wolfleekay@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] avformat/hls:use EXT-X-START instead of live_start_index if it's in playlist X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: lingjiujianke@gmail.com, Li Kai Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Li Kai Signed-off-by: Li Kai --- libavformat/hls.c | 55 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 8204f55df3..bfb20f6492 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -120,6 +120,8 @@ struct playlist { enum PlaylistType type; int64_t target_duration; int64_t start_seq_no; + int time_offset_flag; + int64_t start_time_offset; int n_segments; struct segment **segments; int needed; @@ -741,6 +743,7 @@ static int parse_playlist(HLSContext *c, const char *url, struct segment **prev_segments = NULL; int prev_n_segments = 0; int64_t prev_start_seq_no = -1; + const char *p; if (is_http && !in && c->http_persistent && c->playlist_pb) { in = c->playlist_pb; @@ -889,6 +892,18 @@ static int parse_playlist(HLSContext *c, const char *url, cur_init_section->key = NULL; } + } else if (av_strstart(line, "#EXT-X-START:", &ptr)) { + ret = ensure_playlist(c, &pls, url); + if (ret < 0) { + goto fail; + } + if (av_strstart(ptr, "TIME-OFFSET=", &p)) { + float offset = strtof(p, NULL); + pls->start_time_offset = offset * AV_TIME_BASE; + pls->time_offset_flag = 1; + } else { + goto fail; + } } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) { if (pls) pls->finished = 1; @@ -1722,9 +1737,45 @@ static int64_t select_cur_seq_no(HLSContext *c, struct playlist *pls) /* If this is a live stream, start live_start_index segments from the * start or end */ If EXT-X-START tag in playlist and users set live_start_index, the live_start_index will not work for current codes, which makes users confused. If make live_start_index valid when EXT-X-START tag in playlist, maybe live_start_index needs a flag, or make live_start_index default value is INT_MIN to distinguish. becuase the live_start_index default value is -3, I have no idea to distinguish users action or default value when live_start_index=-3. May I need to set default value=INT_MIN as live_start_index default value? And only when not exist EXT-X-START tag in playlist, make live_start_index = -3 or users's configuration value, it's ok? if (c->live_start_index < 0) - return pls->start_seq_no + FFMAX(pls->n_segments + c->live_start_index, 0); + seq_no = pls->start_seq_no + FFMAX(pls->n_segments + + c->live_start_index, 0); else - return pls->start_seq_no + FFMIN(c->live_start_index, pls->n_segments - 1); + seq_no = pls->start_seq_no + FFMIN(c->live_start_index, + pls->n_segments - 1); + + /* If #EXT-X-START in playlist, need to recalculate */ + if (pls->time_offset_flag) { + int64_t start_timestamp; + int64_t playlist_duration = 0; + int64_t cur_timestamp = c->cur_timestamp == AV_NOPTS_VALUE ? 0 : + c->cur_timestamp; + + for (int i = 0; i < pls->n_segments; i++) + playlist_duration += pls->segments[i]->duration; + + /* If the absolute value of TIME-OFFSET exceeds + * the duration of the playlist, it indicates either the end of the + * playlist (if positive) or the beginning of the playlist (if + * negative). */ + if (pls->start_time_offset >=0 && + pls->start_time_offset > playlist_duration) + start_timestamp = cur_timestamp + playlist_duration; + else if (pls->start_time_offset >= 0 && + pls->start_time_offset <= playlist_duration) + start_timestamp = cur_timestamp + pls->start_time_offset; + else if (pls->start_time_offset < 0 && + pls->start_time_offset < -playlist_duration) + start_timestamp = cur_timestamp; + else if (pls->start_time_offset < 0 && + pls->start_time_offset > -playlist_duration) + start_timestamp = cur_timestamp + playlist_duration + + pls->start_time_offset; + else + start_timestamp = cur_timestamp; + + find_timestamp_in_playlist(c, pls, start_timestamp, &seq_no, NULL); + } + return seq_no; } /* Otherwise just start on the first segment. */ -- 2.25.1 Thanks a lot! _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".