From patchwork Sat Mar 23 02:06:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 47358 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1014:b0:1a3:ac71:9534 with SMTP id nk20csp286127pzb; Fri, 22 Mar 2024 19:08:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXMsWYEUcTIyFEqzBqkZ7ttVuW2MvTsElDqpm/UjhXiwRG5GU1RdNiLoHzvLHB/fZk3ovIJ3qY1E21fSJqIm60a8ixjj36fjudUHQ== X-Google-Smtp-Source: AGHT+IHTiB0DbBBcZA1dgoRDLVpH39mmzBwy0MINALlmmJUMw4KBZAF6um1mEh12aN3uQtLsvozB X-Received: by 2002:a17:906:ae9a:b0:a44:7209:4c93 with SMTP id md26-20020a170906ae9a00b00a4472094c93mr811686ejb.32.1711159681364; Fri, 22 Mar 2024 19:08:01 -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 i13-20020a17090671cd00b00a462fa16055si366952ejk.313.2024.03.22.19.08.01; Fri, 22 Mar 2024 19:08:01 -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=WA1TdGPv; 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 CB31468D601; Sat, 23 Mar 2024 04:06:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04olkn2050.outbound.protection.outlook.com [40.92.74.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CEB968D5DE for ; Sat, 23 Mar 2024 04:06:54 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W9uTja9TGPO32sTeM5iJ5q5v1ZfRLbHv+KgXYlDTS5l/UkOI4LNLyG2w48ad3XWGG4LiTnruftHgxQGL5QlLY4n71wxEFjHeV50BMe7Vqz81EtF2T5mIWvsjYaMtupNN0LvG6Z4BCu/vlPugsF4IrXdzBTpH1sn8m9F6OQ3RfuLegAAfo8IK4UkUYgl/V4MFH5rcOPrvFT2tBlOjQfvIJ+TnfbCSLlTJHOhuBm8o6/u/pr1x4erF9j/nvzTyLJCHNOqTaU67vyWZRg/DpBX+48dgAkq3k2lSCwSAOMRP0Dsktb4GDAWQtLM/avK6LHcUQojLDVKaOqrD4R2r7dtG7A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=b/8Ii/gQD+aeWLHfL9etqXGayqiWX9TB7kLRyOzzsT8=; b=XjKKoStuzjPzGAxiMCY+KjCBU0bWD4EPIsF7vnbUAQJ17P8AcefzQjDI3jLDJBdIOwpeIjEyYpEWkOvHv7A4OK7Mg6D8aA9WCYKaeeGLx+DbXNp0zvCZw3WCnmxGEQCgVCKGWs1GE2p190YQ9N3F48eNe4PmGhm26bGYApeWTz5LKxhI3Ukh1Xn2HBbt6jVO6rzK6wk10KgzhO547NtM37LS1NmqWxyLgtbUQK9+iUyvpfLSxQ5YSNxw5Ht5nE2eiLN9RrznH8vgN/8AoSDinIDLAiYw+HFczUdoKP+xGxVX2nkQI4eQwig23dSnvaP38jlSeq/ZXhBu1/6kcCkcFg== 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=b/8Ii/gQD+aeWLHfL9etqXGayqiWX9TB7kLRyOzzsT8=; b=WA1TdGPvv5LBX6R4EpLHhd8DvVWM2Yn16SQmsS3iQrnn/ys/Jm2J/G527ZlxBYWmYFc32Gor8F4fjEDWgj0kq8TXqE3cRMIxLrq2jlAEc4ulIsALgIInkrkJCZQf0oSeaQrnFkEEZjyVz0jWlNjQZXaQq+7WOglM+ENYtn5vzWQnvinxdF8cxSh97H1aQ5lPsEdd3jgHl/0OSzQEvz4+D3kYGFyjX7+jPo48FKP+RLam5yKWqjklPdyl4OQsDuQxG6fUW1RyyQ8uOgoFcHzLqPZdYomIAVBlLZcCjYbowTMfwm97WBdIJca5liXT8jLj2yXQVaSCaPHn8sLNLv4j7A== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by AM8P250MB0137.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:320::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.24; Sat, 23 Mar 2024 02:06:44 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d%4]) with mapi id 15.20.7386.025; Sat, 23 Mar 2024 02:06:44 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Mar 2024 03:06:20 +0100 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [Nd8TmA0lpK64o4aDKK9Y+aprL+phggt9FsjdvmQBj9Y=] X-ClientProxiedBy: ZR0P278CA0005.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::15) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240323020623.1570961-11-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|AM8P250MB0137:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a17df82-1664-408c-9b71-08dc4adde344 X-MS-Exchange-SLBlob-MailProps: Cq7lScuPrnqkjmXb1vlddM5aSa/Epk3AIxNrDDp5iEsJhW8fX9CWE+q2sQufBCH8WcvMSvWwArVxKBTG7OrTPbvsUoF8jpSkMWuT/6CFigKGj7ZbCKkD7l04x/iHKcNmY7Y27dsA5Dj9JBNqVktyUK8hqcvcn5kkuQEbPZB1M8Rszo7CBmrGGrbKhaK5lR/fB9epq+aTEjyVn4iOaxKf/H9X4G44MLhP8OJESfMCxm4fBV0QSGx5Fbf/PQSGegMh3HyA3dVVo6Wutew0gd4Hu0yVaW4o9tEGMBh3Pi5wf5qkQw3iViNvAKYToeMuNdSY9B3yo94YOBJ7K7+mqYhg+kHN4Ay9ENfK22DNi6Xqzm/uNgGUGXch3k5MDhXPnoSlE8j08SSPADyTMG/vbD5MMHLbq/Wg96Fld7E4RdK2lf89WPe7gvg9SAJnksumxZDgymUMNqs+tOQxIziE0yEZWbMZTW/CkZVahs9RRLZaoCIktM/6F3ZEZpr7CpNCxQ7IE2af+1QgN5tM5OGTl3mypzRZgC4hvYwC0HS1DUptj41MM/SzP5a5mmS0zn5A9B3KRA2UduqdqjQVqVlB6nEyTnUK8+5ypVy7MRLmghAxZCFwRqtG8ToUbwqffBNv/+iM3lEOipV2wIR0klf+3PgMavoMaEtrkInAO2Dioef4EPblFoIKNtuhcQ8wTkCPX8ltqHcvXSgHVLLQVM7NlNyampBnBjGc+1Q6WtzoKjo8gAn685xq357qkcB0738lK/irTWwoo37G3qc= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wb+wNWJJeZODM2hzORTD7dXBvV7GRVHNQBCJ1syP6kzznBiKBChuR1EyCuPIsnUtrH+S90tnPdevlk+lyjgXnIagJ03I1Vgq11fkm2TQkw4LMasU12NXrjhWcH9PzAsZT5F+EXVRDSm5QmNt2yq/bEOXXmQOXXgFFczFiAxsihbED8WjOmY8UVxf7yAWFH13klCy4xHHVfQhV1RW2tqj2+ZqqL5gjsQc2N5l+jUH3OFjYSy5FpMYlKocDxbKJ/shHTRu07TkwI9wH+kr7h4FA47M/HhUTY4VcFIOChL+UhgaWUI8yR/8YqJ+6itbNbuMwOR0NbHrmCFPownZT+N9LyUntpijaJ1sLgfAd1Y2u92M3bRbqQ0ZEP8M1hx727XZcM3tunWjubfp5fOPHa9krY34OXaAUJFGBq+G57vz4OhsB1wS+AlYZ812i3NkZvbcI9+kpJu8wfuBjzsD5YsuAe+C1flmvwULXNXqnvOh7/fSJvouKCDMNXpFMw0hn1BNtOPiaqXWkjprIV2XqQuZHpVX7D0aVJAnitlcxE5w3H2riiOclJDY1B8ePjykpj51VAK4/U6iIBRdM8sLtE0xMGNyNveCI57azBP8SbtvrzoG4Q1bzIGUGzMhTQpiRL+g X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YnGHI+Kwph1UAjPYVyKrUrKzmQ/cq18gSkyyKO2/QdPolAgMSPmmsjONPVdpeaTusz/R7ml6I3c0gn8J/Anj20PxP7OiLcNyF6qMz1TCrT+54NAmDDb1Ynb8FfDP56gYMv3Tz3r60vUa8QceamGytoOfdnCA2ygpNQBd4zXLEuh60OGiZDKKUeMCefjZdLVZKs7vFwf8La8+sSPLC4aIsDaW/P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FKWEviw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a17df82-1664-408c-9b71-08dc4adde344 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2024 02:06:44.2790 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8P250MB0137 Subject: [FFmpeg-devel] [PATCH 12/15] avformat/pcmdec: Avoid av_freep(&(void*){NULL}) 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: xxPoOy6o5ln9 Signed-off-by: Andreas Rheinhardt --- libavformat/pcmdec.c | 61 ++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c index e9c97f7959..03feefb5bb 100644 --- a/libavformat/pcmdec.c +++ b/libavformat/pcmdec.c @@ -37,31 +37,20 @@ typedef struct PCMAudioDemuxerContext { AVChannelLayout ch_layout; } PCMAudioDemuxerContext; -static int pcm_read_header(AVFormatContext *s) +static int pcm_handle_mime_type(AVFormatContext *s, const char *prefix, + AVCodecParameters *par) { - PCMAudioDemuxerContext *s1 = s->priv_data; - AVCodecParameters *par; - AVStream *st; + int rate = 0, channels = 0, little_endian = 0; uint8_t *mime_type = NULL; - int ret; + const char *options; - st = avformat_new_stream(s, NULL); - if (!st) - return AVERROR(ENOMEM); - par = st->codecpar; + av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type); + if (!mime_type) + return 0; - par->codec_type = AVMEDIA_TYPE_AUDIO; - par->codec_id = ffifmt(s->iformat)->raw_codec_id; - par->sample_rate = s1->sample_rate; - ret = av_channel_layout_copy(&par->ch_layout, &s1->ch_layout); - if (ret < 0) - return ret; + if (!av_stristart(mime_type, prefix, &options)) /* audio/L16 */ + goto end; - av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type); - if (mime_type && s->iformat->mime_type) { - int rate = 0, channels = 0, little_endian = 0; - const char *options; - if (av_stristart(mime_type, s->iformat->mime_type, &options)) { /* audio/L16 */ while (options = strchr(options, ';')) { options++; if (!rate) @@ -89,10 +78,38 @@ static int pcm_read_header(AVFormatContext *s) } if (little_endian) par->codec_id = AV_CODEC_ID_PCM_S16LE; - } - } + +end: av_freep(&mime_type); + return 0; +} + +static int pcm_read_header(AVFormatContext *s) +{ + PCMAudioDemuxerContext *s1 = s->priv_data; + AVCodecParameters *par; + AVStream *st; + int ret; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + par = st->codecpar; + + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->codec_id = ffifmt(s->iformat)->raw_codec_id; + par->sample_rate = s1->sample_rate; + ret = av_channel_layout_copy(&par->ch_layout, &s1->ch_layout); + if (ret < 0) + return ret; + + if (s->iformat->mime_type) { + ret = pcm_handle_mime_type(s, s->iformat->mime_type, par); + if (ret < 0) + return ret; + } + par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id); av_assert0(par->bits_per_coded_sample > 0);