From patchwork Fri Dec 14 07:04:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Skripka X-Patchwork-Id: 11408 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 88A1744DB90 for ; Fri, 14 Dec 2018 09:04:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 95EF468AAB2; Fri, 14 Dec 2018 09:04:37 +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 74DB068AAAF for ; Fri, 14 Dec 2018 09:04:31 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by mail.undev.ru (Postfix) with ESMTP id 06A3D5F4294C for ; Fri, 14 Dec 2018 10:04:31 +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 AG9jxXCmi3kq for ; Fri, 14 Dec 2018 10:04:30 +0300 (MSK) Received: from localhost (localhost [127.0.0.1]) by mail.undev.ru (Postfix) with ESMTP id 54D865F431F2 for ; Fri, 14 Dec 2018 10:04:30 +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 9Q-9vIX-ozau for ; Fri, 14 Dec 2018 10:04:30 +0300 (MSK) Received: from [10.10.10.51] (unknown [188.244.38.45]) (Authenticated sender: caspy@undev.ru) by mail.undev.ru (Postfix) with ESMTPSA id 379DA5F4294C for ; Fri, 14 Dec 2018 10:04:30 +0300 (MSK) From: Aleksey Skripka Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Message-Id: <6095A590-81BB-4B94-A60F-DBF87B853ECF@undev.ru> Date: Fri, 14 Dec 2018 10:04:29 +0300 To: ffmpeg-devel@ffmpeg.org X-Mailer: Apple Mail (2.3445.102.3) X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [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" greetings! after commit 223d2bde22ce33dcbcb6f17f234b609cb98f1fb6 temp_file functionality totally broken. attached patch prototype will fix: 1) while assigning 'use_temp_file' addressing to '->flags' is done incorrectly in 4 places. 2) before that commit playlist was always created via .tmp for 'file' proto, now not. sure we should keep it in such way, thus not look for this flag in hls_window(). 3) rename logic in hls_write_packet() was accidentally moved to fMP4-only code, thus not renaming files for mpegts. 4) av_free() call, where variable always NULL. please take a look. --- --- --- libavformat/hlsenc.c.orig 2018-12-13 13:27:03.307499151 +0000 +++ libavformat/hlsenc.c 2018-12-13 20:19:59.781833259 +0000 @@ -1348,7 +1348,7 @@ static int hls_window(AVFormatContext *s 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")/* && (hls->flags & HLS_TEMP_FILE)*/; // always use .tmp logic for 'file' proto. static unsigned warned_non_file; char *key_uri = NULL; char *iv_string = NULL; @@ -1463,7 +1463,7 @@ static int hls_start(AVFormatContext *s, 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; @@ -2123,7 +2123,7 @@ static int hls_write_packet(AVFormatCont 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; @@ -2249,7 +2249,8 @@ static int hls_write_packet(AVFormatCont if (hls->flags & HLS_SINGLE_FILE) { ret = flush_dynbuf(vs, &range_length); if (ret < 0) { - av_free(old_filename); +// old_filename not yet defined here +// av_free(old_filename); return ret; } vs->size = range_length; @@ -2268,19 +2269,23 @@ static int hls_write_packet(AVFormatCont } 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); - } - } +// bad place for rename here, it does not rename non-fmp4 files +// // 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); @@ -2346,7 +2351,7 @@ static int hls_write_trailer(struct AVFo 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;