From patchwork Tue Jun 15 23:32:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 28326 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp4311238iol; Tue, 15 Jun 2021 16:34:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwxsQfCNokkyLoBhzFCeUQzr+fbxpDwDZ43f0V9SkRFYSfDVuh2DoJya6+K1+nr9suoTrk X-Received: by 2002:aa7:dc42:: with SMTP id g2mr698291edu.362.1623800090590; Tue, 15 Jun 2021 16:34:50 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s17si457672ejq.18.2021.06.15.16.34.50; Tue, 15 Jun 2021 16:34:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=HF1hyZwG; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0054368998C; Wed, 16 Jun 2021 02:33:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2079.outbound.protection.outlook.com [40.92.91.79]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 470B668980E for ; Wed, 16 Jun 2021 02:33:21 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hGbcLMOnhXSh1kyW/0HyzvCjIDItpO2O24Gvf0/XzeRzHlUp2QDMFA99wYXeQ02ZTTtPjcDSlF1X2nhj2sWc7MVkYR0ws/0e9NlOjEHjozk3lMaFZ7JB+k72zquGMnptnfgtd45sf0sJe1zzNWmRppSCxpR8kBlVF2k13tpZPf7camyupMkN4o7CmX2Zw+AqpiBRk5rogTWAyMHsrMNJGpBkWIoENjGHp0ng9RO/vAV4PXIoshISWujUYAEetBwdGJQ+kjXK3LT4d5DqWSh0QTyHPRcRmS+BbU/uby0jiPMx+9K9gytSLHH9KYBSqflhVI9ekhB4O6LhR51689J3HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KzZjNJCJVVrGBD1oeAdDPZ4yxjVr9TxijRioMXjFmmU=; b=fIaoxEYhss6VuxJ7vawhdrbe7M8XqlBRnfp+dODx7FTDWjBSbe+ZCEljcQ7aLFzs4a8QtzHslFC2Dm+7Tyb2WDUbUU4XSbIKAv2Osy/1S7EMTcRurJocIywEqjIdJr7zYGa/58MlLYuE40HaL90tuwXQywbpPos9u2dGeNS8GjOF3wfIs5ENCFz9k11BPZjCIsx9pNi5XrqmIWcl2PKPGUAeICZS7+s8SaiyrhK9Tv5UxyeiU7Fs2KJNVbrkrro2PO4F+XpjQT5wv15gWpI2fT9ioKz1g3uz/l6BoiAwlE1mNh3lgjXSlUQL4k7Eml7yDfGlHw+mxqQu0+8hNtANLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KzZjNJCJVVrGBD1oeAdDPZ4yxjVr9TxijRioMXjFmmU=; b=HF1hyZwG4NJ5OgU3dFqc1TGpPmP4bJ2zIiyJUXj9VrTWeGBvR09p6CTx2fa2mQkYfwLWHDlJqtCA5YNnErrx4XFTwtFtg+ePCADvi8l/BIWUeoHfHnsoNa5HyMkVqMyL9xGCJ4G8WibcL/WzBv9ej0KM9ZAgOgkSG7Q0PVRW+YbPs7nsysTSnPGdqCNiggUWjj4EvrYkqH0LWKWecBXTF6Xh7dtdRWPUE60eNyDtHBf1oynOnG7smpTZeXeXXIAK0B5spZ73U9qdT53xYV8LqKTAG/FYw5sxs3g4womTtxOXoHN11uE3vl2cbP223GBMfePwpeltlHMepUvdPPPtcQ== Received: from DB8EUR05FT045.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::42) by DB8EUR05HT170.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::343) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21; Tue, 15 Jun 2021 23:33:20 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc0f::46) by DB8EUR05FT045.mail.protection.outlook.com (2a01:111:e400:fc0f::383) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16 via Frontend Transport; Tue, 15 Jun 2021 23:33:20 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:CA07B3D6E808694CFF117D605D2263DEB813996FCD874A26994FA196FC85EC57; UpperCasedChecksum:54D2AADF80F30DF628A283B82E9AF342D4A5E3715C95A4BEC33D23CB9034333E; SizeAsReceived:7590; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::f4cc:63fc:9cef:37fb]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::f4cc:63fc:9cef:37fb%6]) with mapi id 15.20.4219.025; Tue, 15 Jun 2021 23:33:20 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 16 Jun 2021 01:32:03 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [tEC2V1+ZlvP0URYXumQ8OMZAMg2Z29Jm] X-ClientProxiedBy: PR3P189CA0063.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::8) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210615233243.1173928-13-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.97.82) by PR3P189CA0063.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.20 via Frontend Transport; Tue, 15 Jun 2021 23:33:20 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 250cc1e7-4af5-4aae-54ba-08d93055f5e9 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiR9SlwCHtPrt+MV8TUUwp4pWhkGqqrkWQINYQnacuBy6B8ycd1vy7q146KZHJToK0EVwQslUVM/Dm7HMtAfS8GXEQWrRuD3b67UEY8+Rl/CxYvI3PPcUSZGKchIK0VzwHrzeFqogXXDRoPdj3u+l3H1Ra7KRt68C6nMwt1DeVlP2ZAStzgkDOdqEAVML2es1L4U5ewcKmbsKph5c76DpyomzDE2f2v6jvKdhMSuqHwMvwq79HSn5Qn33DdWZa43woSeXmeT4gTF1z46HEj+ui9V6ngT+bG+Qht9L85B4FZ6QSW4UaeRtaBsD3pwMoCDuWCVCHKTMJLMbYHGMd1Hyd4H8/Pxeu66ax4k+DdvTF52zlsyMe8dCoL/enc+nFqC3xMP4T6rSFgaCCknI0MkExEFst1ZtMtB5/6amfywxmpbqUtGfnaj8c3xNGfbzul2b+8gIGpJxB7o1GjnEo7yTtrYPwLW5PsUb4lpviQWarQ9ojYrZ8+4Y38BqAgOQD63guWYig3x2QS8rWRt1kdPRiqjpbzoh538aJnMAJe+IKeiouNHbTb+Z3IZt2qt16LzN0PD70VXYja1ez633sNC65H/PQhm+mj6Ic2bsMYmQtThM+o5TYeg0SYuSD0SX/dC8/g079r6U6Re9PyhYuuzxDCa+LMn8U4RsShDhbVB88QydyXrfaiebQuU1VjPgd/jguoRZmVHWBt6lXSh5csxMgD9IBRoQJCyKW4ZZeDG8rf23hxW01njkE9SNBoIDxJpcXc= X-MS-TrafficTypeDiagnostic: DB8EUR05HT170: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8ErrXXcQDrwQv4MiP5BjBcQbnf8Z72OT3aKxaF97rtHW4ieFIx8NQPAvwi+pgisMOGvD+WhzhrhOKnVRG/j41EkohCNFLaxN4iiW0oR2jGmzUGLtfjSIOgF7TcNKIwHOletDgbiQpoOxLt7n4r5zAE7mRj4vC1Op4krGTX3qNGXNvdJ+fEXL1TEmPXHhtBWfQCEhL7sPmSHiKVhu/TRqQOmVH6q6Gt6anbsWEPq4EMMkdfOz9JDrMmbFbGnJXKIyOWrqjtLjGxm7iXyaTwClII7Z4fCW7T3d3zidZQsLNVFPGNEpw7fUgLzuQA7oHb/KpgCD0Xo9/RWPJ2MJEvMd6rS/n9VZQpjS81B462/I43xdO2V/OqJ/wOPuH3vNY7fhqdLFjBUMaty0evEwBRtB2w== X-MS-Exchange-AntiSpam-MessageData: oz/WX095R7mWpwO8dPLbukB6OndgSjRbjaQ9CUcB/qoBp8SMVz5pzInm/5J3i+rDJN27Gzw4PxZn0QZFqknoSiGOViMA7NuX/nBVtOxfcE9XZLe6TwZVMiAfRXpIb5r1AtRyDD+MfpM8SurgVD70OA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 250cc1e7-4af5-4aae-54ba-08d93055f5e9 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2021 23:33:20.8077 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB8EUR05FT045.eop-eur05.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8EUR05HT170 Subject: [FFmpeg-devel] [PATCH 14/54] avformat/hls: Simplify cleanup after read_header failure 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Aisn+Qqfy5mt by setting the FF_FMT_INIT_CLEANUP flag. Signed-off-by: Andreas Rheinhardt --- libavformat/hls.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index c2ca23e973..3c1b80f60c 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -1874,7 +1874,7 @@ static int hls_read_header(AVFormatContext *s) c->cur_timestamp = AV_NOPTS_VALUE; if ((ret = save_avio_options(s)) < 0) - goto fail; + return ret; /* XXX: Some HLS servers don't like being sent the range header, in this case, need to setting http_seekable = 0 to disable @@ -1882,12 +1882,11 @@ static int hls_read_header(AVFormatContext *s) av_dict_set_int(&c->avio_opts, "seekable", c->http_seekable, 0); if ((ret = parse_playlist(c, s->url, NULL, s->pb)) < 0) - goto fail; + return ret; if (c->n_variants == 0) { av_log(s, AV_LOG_WARNING, "Empty playlist\n"); - ret = AVERROR_EOF; - goto fail; + return AVERROR_EOF; } /* If the playlist only contained playlists (Master Playlist), * parse each individual playlist. */ @@ -1900,7 +1899,7 @@ static int hls_read_header(AVFormatContext *s) pls->broken = 1; if (c->n_playlists > 1) continue; - goto fail; + return ret; } } } @@ -1940,7 +1939,7 @@ static int hls_read_header(AVFormatContext *s) program = av_new_program(s, i); if (!program) - goto fail; + return AVERROR(ENOMEM); av_dict_set_int(&program->metadata, "variant_bitrate", v->bandwidth, 0); } @@ -1962,10 +1961,8 @@ static int hls_read_header(AVFormatContext *s) char *url; AVDictionary *seg_format_opts = NULL; - if (!(pls->ctx = avformat_alloc_context())) { - ret = AVERROR(ENOMEM); - goto fail; - } + if (!(pls->ctx = avformat_alloc_context())) + return AVERROR(ENOMEM); if (pls->n_segments == 0) continue; @@ -1988,10 +1985,9 @@ static int hls_read_header(AVFormatContext *s) pls->read_buffer = av_malloc(INITIAL_BUFFER_SIZE); if (!pls->read_buffer){ - ret = AVERROR(ENOMEM); avformat_free_context(pls->ctx); pls->ctx = NULL; - goto fail; + return AVERROR(ENOMEM); } ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, read_data, NULL, NULL); @@ -2009,7 +2005,7 @@ static int hls_read_header(AVFormatContext *s) avformat_free_context(pls->ctx); pls->ctx = NULL; av_free(url); - goto fail; + return ret; } av_free(url); pls->ctx->pb = &pls->pb; @@ -2017,14 +2013,14 @@ static int hls_read_header(AVFormatContext *s) pls->ctx->flags |= s->flags & ~AVFMT_FLAG_CUSTOM_IO; if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0) - goto fail; + return ret; av_dict_copy(&seg_format_opts, c->seg_format_opts, 0); ret = avformat_open_input(&pls->ctx, pls->segments[0]->url, in_fmt, &seg_format_opts); av_dict_free(&seg_format_opts); if (ret < 0) - goto fail; + return ret; if (pls->id3_deferred_extra && pls->ctx->nb_streams == 1) { ff_id3v2_parse_apic(pls->ctx, pls->id3_deferred_extra); @@ -2045,7 +2041,7 @@ static int hls_read_header(AVFormatContext *s) if (pls->is_id3_timestamped || (pls->n_renditions > 0 && pls->renditions[0]->type == AVMEDIA_TYPE_AUDIO)) { ret = avformat_find_stream_info(pls->ctx, NULL); if (ret < 0) - goto fail; + return ret; } pls->has_noheader_flag = !!(pls->ctx->ctx_flags & AVFMTCTX_NOHEADER); @@ -2053,7 +2049,7 @@ static int hls_read_header(AVFormatContext *s) /* Create new AVStreams for each stream in this playlist */ ret = update_streams_from_subdemuxer(s, pls); if (ret < 0) - goto fail; + return ret; /* * Copy any metadata from playlist to main streams, but do not set @@ -2070,9 +2066,6 @@ static int hls_read_header(AVFormatContext *s) update_noheader_flag(s); return 0; -fail: - hls_close(s); - return ret; } static int recheck_discard_flags(AVFormatContext *s, int first) @@ -2426,6 +2419,7 @@ const AVInputFormat ff_hls_demuxer = { .priv_class = &hls_class, .priv_data_size = sizeof(HLSContext), .flags = AVFMT_NOGENSEARCH | AVFMT_TS_DISCONT, + .flags_internal = FF_FMT_INIT_CLEANUP, .read_probe = hls_probe, .read_header = hls_read_header, .read_packet = hls_read_packet,