From patchwork Fri Dec 14 14:58:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Skripka X-Patchwork-Id: 11414 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 4157744D94D for ; Fri, 14 Dec 2018 16:58:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 658A768AAC4; Fri, 14 Dec 2018 16:58:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.undev.ru (mail.undev.ru [213.232.193.241]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4218F68AAB1 for ; Fri, 14 Dec 2018 16:58:25 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by mail.undev.ru (Postfix) with ESMTP id E068B5F403A2 for ; Fri, 14 Dec 2018 17:58:24 +0300 (MSK) Received: from mail.undev.ru ([127.0.0.1]) by localhost (mail.undev.ru [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id J8mEMGbs1L63 for ; Fri, 14 Dec 2018 17:58:23 +0300 (MSK) Received: from localhost (localhost [127.0.0.1]) by mail.undev.ru (Postfix) with ESMTP id 2B7425F431F2 for ; Fri, 14 Dec 2018 17:58:23 +0300 (MSK) X-Virus-Scanned: amavisd-new at undev.ru Received: from mail.undev.ru ([127.0.0.1]) by localhost (mail.undev.ru [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id slgrZcsiT7kN for ; Fri, 14 Dec 2018 17:58:23 +0300 (MSK) Received: from [10.40.6.129] (unknown [213.232.195.228]) (Authenticated sender: caspy@undev.ru) by mail.undev.ru (Postfix) with ESMTPSA id 0AB605F403A2 for ; Fri, 14 Dec 2018 17:58:23 +0300 (MSK) From: Aleksey Skripka Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Date: Fri, 14 Dec 2018 17:58:22 +0300 References: <6095A590-81BB-4B94-A60F-DBF87B853ECF@undev.ru> <210790C9-C0DD-4CAA-B8BC-92796053D08D@chinaffmpeg.org> <894CB9E4-7AE8-49E9-A78E-79BD68FD5034@undev.ru> <7B6A5A4E-09CA-4A72-8396-E5EAF305F58A@chinaffmpeg.org> To: FFmpeg development discussions and patches In-Reply-To: <7B6A5A4E-09CA-4A72-8396-E5EAF305F58A@chinaffmpeg.org> Message-Id: <42AAD417-F8C1-4ED0-9167-7F02ED2E2929@undev.ru> X-Mailer: Apple Mail (2.3445.102.3) X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [PATCH] libavformat/hlsenc: fix broken -hls_flags +temp_file 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From e85edcc4d8b0312c7871f78ed0859ec7436be460 Mon Sep 17 00:00:00 2001 From: Aleksey Skripka Date: Fri, 14 Dec 2018 14:48:31 +0000 Subject: [PATCH] libavformat/hlsenc: fix broken -hls_flags +temp_file 1. fix addressing '->flags' while assigning 'use_temp_file'. 2. before 223d2bde22ce33dcbcb6f17f234b609cb98f1fb6 playlist file was always created via .tmp for 'file' proto, now not. keep old behavior. 3. rename logic in hls_write_packet() incorrectly placed (in fMP4-only code), thus not renaming files for mpegts. 4. needless av_free() call. --- libavformat/hlsenc.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) -- 1.8.3.1 diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index bdd2a11..70eee19 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1358,7 +1358,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) char temp_filename[1024]; int64_t sequence = FFMAX(hls->start_sequence, vs->sequence - vs->nb_entries); const char *proto = avio_find_protocol_name(s->url); - int use_temp_file = proto && !strcmp(proto, "file") && (s->flags & HLS_TEMP_FILE); + int use_temp_file = proto && !strcmp(proto, "file"); static unsigned warned_non_file; char *key_uri = NULL; char *iv_string = NULL; @@ -1478,7 +1478,7 @@ static int hls_start(AVFormatContext *s, VariantStream *vs) AVFormatContext *vtt_oc = vs->vtt_avf; AVDictionary *options = NULL; const char *proto = avio_find_protocol_name(s->url); - int use_temp_file = proto && !strcmp(proto, "file") && (s->flags & HLS_TEMP_FILE); + int use_temp_file = proto && !strcmp(proto, "file") && (c->flags & HLS_TEMP_FILE); char *filename, iv_string[KEYSIZE*2 + 1]; int err = 0; @@ -2143,7 +2143,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) int stream_index = 0; int range_length = 0; const char *proto = avio_find_protocol_name(s->url); - int use_temp_file = proto && !strcmp(proto, "file") && (s->flags & HLS_TEMP_FILE); + int use_temp_file = proto && !strcmp(proto, "file") && (hls->flags & HLS_TEMP_FILE); uint8_t *buffer = NULL; VariantStream *vs = NULL; AVDictionary *options = NULL; @@ -2266,7 +2266,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) if (hls->flags & HLS_SINGLE_FILE) { ret = flush_dynbuf(vs, &range_length); if (ret < 0) { - av_free(old_filename); return ret; } vs->size = range_length; @@ -2284,20 +2283,12 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) return ret; } ff_format_io_close(s, &vs->out); - - // rename that segment from .tmp to the real one - if (use_temp_file && oc->url[0]) { - hls_rename_temp_file(s, oc); - av_free(old_filename); - old_filename = av_strdup(vs->avf->url); - - if (!old_filename) { - return AVERROR(ENOMEM); - } - } } } + if (use_temp_file && oc->url[0] && !(hls->flags & HLS_SINGLE_FILE)) + hls_rename_temp_file(s, oc); + old_filename = av_strdup(vs->avf->url); if (!old_filename) { return AVERROR(ENOMEM); @@ -2367,7 +2358,7 @@ static int hls_write_trailer(struct AVFormatContext *s) AVFormatContext *vtt_oc = NULL; char *old_filename = NULL; const char *proto = avio_find_protocol_name(s->url); - int use_temp_file = proto && !strcmp(proto, "file") && (s->flags & HLS_TEMP_FILE); + int use_temp_file = proto && !strcmp(proto, "file") && (hls->flags & HLS_TEMP_FILE); int i; int ret = 0; VariantStream *vs = NULL;