From patchwork Fri Aug 27 14:08:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29809 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1494383iov; Fri, 27 Aug 2021 07:09:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwabWpwrHoqFYW6+MRjCxXTyl0AZRmXqAGPKwPiXHx1KANLy1cfGfe1eqoNkhk/TKAxoe8a X-Received: by 2002:a05:651c:113b:: with SMTP id e27mr3432615ljo.6.1630073388788; Fri, 27 Aug 2021 07:09:48 -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 u34si1060339edc.251.2021.08.27.07.09.44; Fri, 27 Aug 2021 07:09:48 -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=Kt11vYy6; 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 4804B6898E6; Fri, 27 Aug 2021 17:09:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (unknown [40.92.90.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 46AC2680544 for ; Fri, 27 Aug 2021 17:09:33 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BWGv4B41Y6OMTXlXZEmAiwye8+zAHdvIAbvnVQpbRYNzis7NotemGQNnj+uuwU+bjsEB7+KgEE5Qhr2dQOfGqXh0AvqvKbjx+MJ6SNkQyv4laO0yXNTm2DsMcCwMJK6KX6c/o8OBoOobnei+w4jSNUJClx73eMzbrg2UhgI4Bbo/vWkHt9DX/9CkkuBbnqnzXqsglBwFagm1QyNZ6Y2Xa1wFEPPazuMlZI4+LwZGH+ri10rB0plTJ/XmUPTSPy82eQWZ29kVt61HqjpmebzQnQ1N0e/ergyOfoBRsjCv7vLdvOQAiWsNCsSsBP07GoB0s6o1D8fWFtxltzFZWRmcAA== 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=NZCL+tV2noyMzJzX5KjB0nbjvdcUP++ymOReqmiXZ94=; b=UbSIHzHhE1qq07CnI64jp9cqBr/QisA8lvjNJb8CBadzxJYfycCQBOCISucCyNGBBkSqRRzlQdH8Lg/9HxtD8SFUcc7JZlM69SeWvaWCPAA8puT0ke5wfwHzh+Ea66M1kfNsd/B0zhsb5n0fAZ4ZgX8SFX4VzYJnDepIHPyif0cHC+Fccq8dWquCeqUblwUR0bmc8wp1y8yyRf6AHNmlA+zGha93SHo6XS8nBdEreuVjbxxP9iQIDzVAnhxfcaDU1urJJlvrTLwobocH9pKs/q+oX1bwsxiLmjRMDoITTltxkTDEvld7EvUoJSHi9ieDfnVFi81WAw/i+TKrH8pM/g== 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=NZCL+tV2noyMzJzX5KjB0nbjvdcUP++ymOReqmiXZ94=; b=Kt11vYy6z9qR6rOfos0W9oLD8q2DwvDs2tQ/s5Kjzt1na8y1TTJVTmIboVpSWKij0c+6FmW2yLX0X8wEz3WLszvoAh6vBUae1JLIgoNn3gN2r979+3LGvE7UCHgTho80pyipKZZ6PKjRM37Po37Pt4qTboCf0XAFp39WTDF673BOgKEqJN3uZGa9gmisnqXMgHkxMoPB11gFiEkTcheyoK8p0QqobEiNn/nmptV/5OzHvQiAFTuYeVcUpVO64t+97dQNzH17BJIrq4hcwEyMWi+RmzUWpQOxCNTK6LVJvtt7ov0ZeQ1Ak3WyJwugZksn2GxFyNZK0G0XxH8MqRJbuw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB5701.eurprd03.prod.outlook.com (2603:10a6:20b:f6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Fri, 27 Aug 2021 14:09:31 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:09:31 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:08:57 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 X-TMN: [WLosU/HJB2y/LCpURh1qmdEmkr1Yzts6] X-ClientProxiedBy: AM8P251CA0023.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:21b::28) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827140921.641126-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM8P251CA0023.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:21b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.21 via Frontend Transport; Fri, 27 Aug 2021 14:09:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 93c400ea-5aff-4c13-df51-08d969644a0d X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXOVIHST31EzKLNwg5cTLbyZb2pMriPNaEZQdgr9pesU6sAppCMvM7AOIIjY+WsAqREQd97XEEg2Dh3zd654Gadq8aatz6KXRr2kGfnyopR1iG0Zb7GR6ibG4+CFvBfHFOJdhHAOeDvP7ZEBhtEFZVPxFu+AWDG1M5yh7o7lAbhf6z4PF+RwmwbQFLkNsm5N0rPqjxY1A+uZduYdplCqHbDRO0fi19UKoVoC4UfatebXpbTsnv9Z22Z1R7pozvqBU/2vCZXyu358Zi4+MmN+88La/tcDvI0kX2BfnWJ1cbuWlaXNbgim6oc6/l3OAfvNQctbQUhy/2x80RZH0rLCrsBpdXcDy4r4V567iyFQNyPu+U78AooETA0fgQXk3J8bJXqj+SrBCRC8r8s8wPeScdswYBFMhU2gClzQ3kEeXTFO5WMCI3CVt5SyZtDbgZjv4N1BWh5VF052jfPNQtdOskH0893LViNw6zzoS8souIjO2CViGLhXJsmf9QGywMi+dnhzN1WBfQB8biK8SVKcPd+evnhYTnZb+cAgvW1tyWrMA0lGNlzeFESHYFGtsf8QcrUCntg1iDtvOWEjGRN/kJ5p3y6rmtgk/3F44X1CYnFj+D8hnC3omokxILM5c43IBt3Uq3anlckEpUEb4sZgR4HUR3ogl5tXMkqPR+pWqd2HVhIekFGaJ5gjOi/96/eBDmLKUJlqOvQ/E9cKd+aFUQDmm4bMUcjuuA= X-MS-TrafficTypeDiagnostic: AM6PR03MB5701: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OsHS1Eugurge1ado60YpsCbl2AW99r1i8ReqikCHbGtFDDLv/r+goy3/58hlVMJ0dnKRaz/dGQkrsKOMyYDyW+G816Qm6uZrguLr9BleZTqtL0DygcB0QV9w1PfC9f+TIw6f0mjPkAZpNtNUE+aublNLbiSQ338/zhrbGHk8pUJ79+SabmJFlHBSZGW77TIzCJG0sZRcuPJTq35kNvlW9n1Xw8FeHb77A23t+uqpYEEZzoFV52Ydlthy19zgAwSt83jN2tDdMjIdNy3oDGaupv2B8RtTx4DOn3REdTbLGtlbkuyk16ONnJT1ZxdIKHHlC6zXqsYMMh4iS13spZO7eeQ1s7voU+xg0dx+mEI5wFk8asYqg7L0JCRembrB8Q9DSABTbZ73B0GYtQ9phsodQK3fOLqNf4+x5RfDA4rThA6nMixWckNtS9C1IcrOuKhC X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: J85p06UwDPoP9VlidQVDidYStbNIzunO6hGiHpZmntn6wHf2jV8zV78QTnWxO5dOtukseOnDko4t8L694NzpGl5urRQ5L15X5m3Q+jXN1FqdmmYE3gNcCXE3XDIGi3Utu5mesUgKLnstBsAoqRj7zQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 93c400ea-5aff-4c13-df51-08d969644a0d X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:09:31.5031 (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: AM6PR03MB5701 Subject: [FFmpeg-devel] [PATCH 01/25] avformat/matroskadec: Fix heap-buffer overflow upon gigantic timestamps 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: bLbEr1jdIxrB The WebM DASH Manifest demuxer creates a comma-delimited list of all the timestamps of index entries. It allocates 20 bytes per timestamp; yet the largest 64bit numbers have 20 decimal digits (for int64_t it can be '-'+ 19 digits), so that one needs 21B per entry because of the comma (resp. the final NUL). The code uses snprintf, but snprintf returns the strlen of the string that would have been written had the supplied buffer been big enough. And if this is 21, then the next entry is written at an offset of 21 from the current position. So if enough such entries exist, the buffer won't suffice. This commit fixes this by replacing the allocation of buffer for the supposedly worst-case with dynamic allocations by using an AVBPrint. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskadec.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 7d79b3d5c4..c67a728737 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -35,6 +35,7 @@ #include "libavutil/avstring.h" #include "libavutil/base64.h" +#include "libavutil/bprint.h" #include "libavutil/dict.h" #include "libavutil/intfloat.h" #include "libavutil/intreadwrite.h" @@ -4146,10 +4147,12 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range) MatroskaDemuxContext *matroska = s->priv_data; EbmlList *seekhead_list = &matroska->seekhead; MatroskaSeekhead *seekhead = seekhead_list->elem; + AVStream *const st = s->streams[0]; + AVBPrint bprint; char *buf; int64_t cues_start = -1, cues_end = -1, before_pos, bandwidth; int i; - int end = 0; + int ret; // determine cues start and end positions for (i = 0; i < seekhead_list->nb_elem; i++) @@ -4180,6 +4183,9 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range) // parse the cues matroska_parse_cues(matroska); + if (!st->internal->nb_index_entries) + return AVERROR_INVALIDDATA; + // cues start av_dict_set_int(&s->streams[0]->metadata, CUES_START, cues_start, 0); @@ -4199,22 +4205,19 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range) // check if all clusters start with key frames av_dict_set_int(&s->streams[0]->metadata, CLUSTER_KEYFRAME, webm_clusters_start_with_keyframe(s), 0); - // store cue point timestamps as a comma separated list for checking subsegment alignment in - // the muxer. assumes that each timestamp cannot be more than 20 characters long. - buf = av_malloc_array(s->streams[0]->internal->nb_index_entries, 20); - if (!buf) return -1; - strcpy(buf, ""); - for (i = 0; i < s->streams[0]->internal->nb_index_entries; i++) { - int ret = snprintf(buf + end, 20, - "%" PRId64"%s", s->streams[0]->internal->index_entries[i].timestamp, - i != s->streams[0]->internal->nb_index_entries - 1 ? "," : ""); - if (ret <= 0 || (ret == 20 && i == s->streams[0]->internal->nb_index_entries - 1)) { - av_log(s, AV_LOG_ERROR, "timestamp too long.\n"); - av_free(buf); - return AVERROR_INVALIDDATA; - } - end += ret; + // Store cue point timestamps as a comma separated list + // for checking subsegment alignment in the muxer. + av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED); + for (int i = 0; i < st->internal->nb_index_entries; i++) + av_bprintf(&bprint, "%" PRId64",", st->internal->index_entries[i].timestamp); + if (!av_bprint_is_complete(&bprint)) { + av_bprint_finalize(&bprint, NULL); + return AVERROR(ENOMEM); } + // Remove the trailing ',' + bprint.str[--bprint.len] = '\0'; + if ((ret = av_bprint_finalize(&bprint, &buf)) < 0) + return ret; av_dict_set(&s->streams[0]->metadata, CUE_TIMESTAMPS, buf, AV_DICT_DONT_STRDUP_VAL); From patchwork Fri Aug 27 14:27:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29816 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1511811iov; Fri, 27 Aug 2021 07:27:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHWVkM+EAtA4Yaf5f6V/DSwxMMzQ+H+beJRilL5AT4Vy8I5Vc8DchTRpNeChRDUcAqPN/k X-Received: by 2002:a50:e789:: with SMTP id b9mr10066540edn.101.1630074467583; Fri, 27 Aug 2021 07:27:47 -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 cy25si6810920edb.240.2021.08.27.07.27.46; Fri, 27 Aug 2021 07:27:47 -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=Gbnd5TjD; 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 DCDAD6898F5; Fri, 27 Aug 2021 17:27:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064019.outbound.protection.outlook.com [40.92.64.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E853D68921B for ; Fri, 27 Aug 2021 17:27:35 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iA54enxAY55A82LkLs9pGRqaZm2DdB4+vNgUrRqmfMQSUPAQCx47BJ2xWFRJlv8ehRnGpU2nM0ySe1kq7aYPbkLn976Y8QwGcTzakhaa7VTpbYT7TIB+4/no6FYvSY0byr3FmA3pYdApfsnfvNuau5fMdTgK2Tt1y5w/UOVf7HwAE4J4ocpO4tu34cHFD542YX9Qgeuq3ULDvG9Z5dUwv/2Q2x2nCFnXiFag5iSEkvgFB7TZMjACnuBal7AelmC56lugZ2q3hmddc5RXi+3sYDEDCWn1Gr37tfJB7FI5L+/qOT0iKo20iisVRQH1bowvvNGeNx11frdup6chG3Gv+A== 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=T2B42vBCgd1bpX8qnRc1mBNurcH++8ZV0MaA98c4nr4=; b=gzSvPgV3rC7NFQB3MmIPxHoozS/rdSLihQ+LR/tvrXoiXbgYpPCnBd61awxWU0yKl3v2wF4VBOEcUSDH4/LuWEyyKekosg82rAtO7k88OgnBSBxM++qUud0/j+1kBKmxpIA9yuagQdc5a1MD7yopykqBO8IeVDyiQ9XmiiXwnUqyBKxkciEXWAYtqKSFxbr0JHsdu9THCANm9wNloK6qgC7nWL5zRS0qAfsbPbLmms363JhsCsrhgQvX2bdAXWZisJp0x1dzmo2sCrm7dUGrizXs+Yo3gvmIaxL4rlZCckm3g65tQFoTXXe1cOehHHsUbT76f/xc7X1/LjmJZI8Oiw== 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=T2B42vBCgd1bpX8qnRc1mBNurcH++8ZV0MaA98c4nr4=; b=Gbnd5TjDZCIropf3/hiuy6SDhosTUkhcfqhuhfwcsmkPMeIBIU6u1qQZa9iwTvVpC/P6XfSNn4EvEZT9YEhMHpMyTZe0669h33HKbkHg08U/s758S3cXpPEgEmj7bMgYM3Hn6jhZUyuxBPKjf7sVCHXmDItgFaWbTNro3UTudseAoIa+wAM6EWqfj+nb7T2/QwQZ8o9KNZbPNqUxKpJBz47237xP+Sj2hZPr5lXjYVK9WvAuC5qgunIXTYwfUCWpfY9TRT22xuNsx4A91LG7HFBPTQiJ5E10dvyHlgLt3hOpYWuMoZTpzjDslCMJlo6Yuo6Q9pAVlpdD2vmZNUIz4w== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4824.eurprd03.prod.outlook.com (2603:10a6:20b:84::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.18; Fri, 27 Aug 2021 14:27:34 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:34 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:02 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [siEbqYuBqVVFNsdQyXEHXaVBTFpUFsDv] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:34 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d561182-6565-47b1-c2d9-08d96966cfbd X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UJFV0D8eNjjrGtWNbxKTG+h8zLHWZP7t6zp9KAnc+cJ5YuxQa/uOAKbNJ/w7DGCga2Yg8sCg2qa+cmPBBaCjlSOHLrNwpIQF8TFYUfPx+MTxuqb7Z4n8/I8Q3uZ5k4je9mwBeiXrRX4CUCzh6/g8x8+HgNDpiof9XG9XkZdZeqahOFQF4tZHZOjM3GLul4MlHEQMP5aVVH5e45XwhnDn5HZi2IkK5Dgslzc8jgsAkhsWfYyCEmBU0RiQDToQ+4LIEFvFs4Vbi1dY+tQD4qHAVgNkWy31kyc5oAJBGElt5Sq/5kt71b5JttBOzoMiTsDqNl1CdZRxtsL2tCyhtaZBYonr44x/g9+g9UxuCvh1o38Vdf9pcg1pjsotkS/5nOYZBXs7QR7AMB6bvy6s/urSpT+2uh3LlV5QL0KoTjEzQtnz6MIknSop6ahvj/zZuR5+BfJd5xK2xTDEfpSSezXFXvekjuFfkovgNW+rALkuSYKMBvcgu0j2FGtteaHMZrKheWysjtcPxOFIxxlf0A3GSjwryOlHV5BuP37zbqunKJLwk7PVlKfEAIpVghT4u04pAtVK2SV3adTSiEL4vLQIS7qqqEgU6EMHlj+VkKkC6ptqBitV/7m6rvfj7Z3CiziG5gm9l4czINCbJGwVqgPUQt7AaUJ57it7BKxPV6IzSGcsWU7x2gYuZdn8L0TTljuCEpB+ELt/E8C+g== X-MS-TrafficTypeDiagnostic: AM6PR03MB4824: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o9To8qyzWvYwryiZxTzWHdLyJpMRGkja/MeRDoYFKqqXa00KmmpmkrF5I5B1OwdaTtgzIzI4k62tKAqAW71Me1jpAmnMkCY0kZpnmZLo6D+Fh1iMLNrrfCNFMn/x7dHCQP+Zq6+CYu/sJeKr0D6crccLtVeO4z0vytv4wH/uXE1sODy0l2BI+Yg9cKnq/laxf3FNY59+Rg1wim+wAyDw/OgMLQ+nWXkA+ioLoc7FpdlT5YKVrPShkT/TCQqU5Ctef0zxNs9RYvlunFHY6ADdoql2hePxKsF/YdgAK6+V73Sc2i7EwrK/QdsobXafqp7FrhrcjsfXWseMYcrA6zgJNcBpwM9GHjxK6tr9/FNG4IhaGb/J7DFogdiOgewqJJzqWKIGvFoYsWuHbmYCDqtkz/hHbTx+DpX/fipz0oTNVHx3Aco4niBv6HkfiwkNNPf2 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: drtdV7YSVAZnQAdtcKTLr8yv68ul23clDlN4QuRlyAnfNrGmAOuCnmBJateGo8OXGrFRZv1QlUAqCHfzb0rr027AsF9dtkO35fgbJydZR3MQbRcD6wuSF8PoZIabDz3RHbb2It6i1da2GvGDAjwGqA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d561182-6565-47b1-c2d9-08d96966cfbd X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:34.5652 (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: AM6PR03MB4824 Subject: [FFmpeg-devel] [PATCH 02/25] avcodec/tiff_common: Fix AVBPrint error checks 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: d+b87Gc6ZFHB Signed-off-by: Andreas Rheinhardt --- libavcodec/tiff_common.c | 76 +++++++++++----------------------------- 1 file changed, 21 insertions(+), 55 deletions(-) diff --git a/libavcodec/tiff_common.c b/libavcodec/tiff_common.c index b3c6b96b57..2b872ea7e2 100644 --- a/libavcodec/tiff_common.c +++ b/libavcodec/tiff_common.c @@ -80,11 +80,26 @@ static const char *auto_sep(int count, const char *sep, int i, int columns) return columns < count ? "\n" : ""; } +static int bprint_to_avdict(AVBPrint *bp, const char *name, + AVDictionary **metadata) +{ + char *ap; + int ret; + + if (!av_bprint_is_complete(bp)) { + av_bprint_finalize(bp, NULL); + return AVERROR(ENOMEM); + } + if ((ret = av_bprint_finalize(bp, &ap)) < 0) + return ret; + + return av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL); +} + int ff_tadd_rational_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, AVDictionary **metadata) { AVBPrint bp; - char *ap; int32_t nom, denom; int i; @@ -101,16 +116,7 @@ int ff_tadd_rational_metadata(int count, const char *name, const char *sep, av_bprintf(&bp, "%s%7"PRId32":%-7"PRId32, auto_sep(count, sep, i, 4), nom, denom); } - if ((i = av_bprint_finalize(&bp, &ap))) { - return i; - } - if (!ap) { - return AVERROR(ENOMEM); - } - - av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL); - - return 0; + return bprint_to_avdict(&bp, name, metadata); } @@ -118,7 +124,6 @@ int ff_tadd_long_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, AVDictionary **metadata) { AVBPrint bp; - char *ap; int i; if (count >= INT_MAX / sizeof(int32_t) || count <= 0) @@ -132,16 +137,7 @@ int ff_tadd_long_metadata(int count, const char *name, const char *sep, av_bprintf(&bp, "%s%7i", auto_sep(count, sep, i, 8), ff_tget_long(gb, le)); } - if ((i = av_bprint_finalize(&bp, &ap))) { - return i; - } - if (!ap) { - return AVERROR(ENOMEM); - } - - av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL); - - return 0; + return bprint_to_avdict(&bp, name, metadata); } @@ -149,7 +145,6 @@ int ff_tadd_doubles_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, AVDictionary **metadata) { AVBPrint bp; - char *ap; int i; if (count >= INT_MAX / sizeof(int64_t) || count <= 0) @@ -163,16 +158,7 @@ int ff_tadd_doubles_metadata(int count, const char *name, const char *sep, av_bprintf(&bp, "%s%.15g", auto_sep(count, sep, i, 4), ff_tget_double(gb, le)); } - if ((i = av_bprint_finalize(&bp, &ap))) { - return i; - } - if (!ap) { - return AVERROR(ENOMEM); - } - - av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL); - - return 0; + return bprint_to_avdict(&bp, name, metadata); } @@ -180,7 +166,6 @@ int ff_tadd_shorts_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, int is_signed, AVDictionary **metadata) { AVBPrint bp; - char *ap; int i; if (count >= INT_MAX / sizeof(int16_t) || count <= 0) @@ -195,16 +180,7 @@ int ff_tadd_shorts_metadata(int count, const char *name, const char *sep, av_bprintf(&bp, "%s%5i", auto_sep(count, sep, i, 8), v); } - if ((i = av_bprint_finalize(&bp, &ap))) { - return i; - } - if (!ap) { - return AVERROR(ENOMEM); - } - - av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL); - - return 0; + return bprint_to_avdict(&bp, name, metadata); } @@ -212,7 +188,6 @@ int ff_tadd_bytes_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, int is_signed, AVDictionary **metadata) { AVBPrint bp; - char *ap; int i; if (count >= INT_MAX / sizeof(int8_t) || count < 0) @@ -227,16 +202,7 @@ int ff_tadd_bytes_metadata(int count, const char *name, const char *sep, av_bprintf(&bp, "%s%3i", auto_sep(count, sep, i, 16), v); } - if ((i = av_bprint_finalize(&bp, &ap))) { - return i; - } - if (!ap) { - return AVERROR(ENOMEM); - } - - av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL); - - return 0; + return bprint_to_avdict(&bp, name, metadata); } int ff_tadd_string_metadata(int count, const char *name, From patchwork Fri Aug 27 14:27: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: 29815 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1511964iov; Fri, 27 Aug 2021 07:27:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5NOLhzhQ+T6HH8wR32qyjTbJQo2PH4K6O5172nQkbg9/1U9QYAWQ+TgYgMMncNJIRPXR7 X-Received: by 2002:a17:906:700f:: with SMTP id n15mr10388402ejj.319.1630074478041; Fri, 27 Aug 2021 07:27:58 -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 h4si7513148edt.426.2021.08.27.07.27.57; Fri, 27 Aug 2021 07:27:58 -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="ryO5i/QX"; 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 E2FDC689EBD; Fri, 27 Aug 2021 17:27:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074075.outbound.protection.outlook.com [40.92.74.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 91BC3680749 for ; Fri, 27 Aug 2021 17:27:38 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T1zws5ITyJ8Od9co8duJiSDVyBfPG5oGNoID9VKtobgM2e7870zhdH4hPN5KWZotuPD1i8JP52o7iNek8f2+EFH/Q/oCVNp++NqNbJLY5J7kPP+G6oXlsrYAtoarIC9eECjQCzHqZVEeHzUJzhWs8ZzMAG+Xyj4HwxbWCEeR2QLmsiSdWCk9BzzatvCi6J0qQqQuOeJ+6+5m+F5YPeHcYQsniw0IHJR8uzkybegKkVVT6M3kfIecQGYAtVGYP0LLfiNQPuMnrq3Djtoi/PuoGOKcarwWuTAswyWGf5QYEQpTYPCmuHzKi7gdjEYBv6stwkSiX9rqXNkTp1AzVd7Etw== 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=S/jXRY2FBkwT4iTbmQTArb409XCnppRnzvfDuwYNATA=; b=B3x6suGG7RdosWfx9QSySdzrcI0EZkSU9GL0eaH6xI0IStnuNmUS0JBBLueklZemVX0QEdahcgstCwZ7EAltmf3l0PZeZZNscX9vjWmcqyYSJ9UARALwT3ER8zPs2wkc2Lk0amGNjjy9vqbHzJDQgw1njbJfmfPx4roFylplIjqJni+Qo0nsSG4wAUDmYPtJ7BE8HcJYr4gP196CpiSi1FdDZFhqcN/wPRFPhZcGDUpfuFT69n8Jtryl18AB3nSTCb9dKDN7gTtt4BVwbiBWn81uDQDtsLOYHLlc8Za6fz6+cp5unouTbSsFZbXhY44tkpkbs2vNIWJCgMR4qH3nUw== 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=S/jXRY2FBkwT4iTbmQTArb409XCnppRnzvfDuwYNATA=; b=ryO5i/QX30gwWmkmGYW+4WSYVNX9WsG9WyA40yuvmOI8RBv0IdQ4fq9k9NR2HUPgd69kDKL68W2qY78hquu+ij1cZ8cxApNvdl5z+zfSlRI1WqDcXliO0zzenVIaS+VfHY+zNYZw1397IAF8/ZUzjm3D8KDvMlgCdflr1S6XaEbCoMBZeijgCb4ifzdAKBh4nrRHNtvAhZw1PsZTNTcwmUjFzut39DfzTzlpbZrWCAGsV4hJSxeM/jbd3pBydGnyh4lncyHEJY3dlw6/tTwDofHlf7mCG5ICCH+5et2j/YYvpdhCkebbWKP0E23b7huJVzW7djy4QJ+KDFnn8M8ZgQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:37 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:37 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:03 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [d13AYz7lNrFoXk0/DSxPt7R7sciJN2RZ] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2ca91fd7-7918-4861-b4f4-08d96966d16b X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7xo2uLN93Y6ByCdpHKAKG1zGYFGP5JiU/ZIulfUYisXRdOjy3jUdYMO1F2NsVPiG7r8Zugz6OyNgb64UqSKVpLREFnQFt1CQhdNKIY55rsNy0Ey0QoHQobHURZDoTbWHYubE8xs1wOmcSZ60/UCiqhlKdSP2JeFmOFw3TiqVZ6nAbOVB483A+YIfHH2PZrGV70M8XIpFC5HibJOH7wlmNr1nyZQoQxJ5t+w8XM14GQ8/K8MOynLE22w2683K5rf8NzXcOVl7INcv+gN423ANgskcmyRmWaUgaR1tWGlRA9KFpnpldfDphDmrsXg/xG15Mvwto3pIymTSINCB0neN0ldrQOnjQPaBxae2EpAlKdS8Oa3aOduEbhSzFzLegg64WBgrdtSvecQQ8BE82fXyMNhcWvoNqu2lzd1ipS4NUzYdaWMqzLy9VA8nSQXYZMLh1Y6SnE0OQoWg784o7MGMaJ0iwvIq5BqAPZjYcPQODa4rReGpUgJCe7bMMYdhhfQOL7sqcAT02RIP1SLlLE1Xh4je5WaflZ+pQJeyG5gelwGRmPFuEM6/gwZnI42qUddbMrEzUcpLcLYeef+m7R3cZ9WF4iwKk6Tb1baJOSVtb85MxZDY60VpwJ6jjwfC+qKrdiy4OPWDtyL4uduI+qrU3Fn6hgfJ0i3KiBLn4Lk05djKeXMAu1//jn1fVTxr/nglZ/xzQh850wvuGhim9QUjGo2hFZTS8EO9tgtpe+6AaxUo= X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EzAR+MzMt812LncMI02/nbEV/YbKuMz29J2r/0IEipKbfVi2hnWeYtir/3+WpOWHdcXMB1MNzwimws8/3Xuw0EVlpKPbS2Ttd6tBK1nNSv7zDw7ggUTgUau92hrPQ2wvNpbrr7Cvvm64f/ql4EQrZhhjlsTXRoQ90JXrp1Z9hl6w3lEro4hH0Ta8PwBzwP0wNXsjV5swsPkOBnDHlxLlgFuHl1icaxu2+0j1h5Uf6f3rhETlTgfjQbO4LmJ0FcYn3/Phcv6c6MS4PA3rr1WL+gYIzH107MJK2OG5kd/JN48WJQn85ylkibqz7Nxa5tKuq+nW3mU28zBkcjgPwfkA8DLzxYRMhS5bzau73g7KQAqzGH38Vk41YEnay9tTbG9N3V740UIM3eYpJJJtjWsEi4eeHXi+UWLQy/8Wt99BHKlV5m+8uQ6eWVhmQqmVuJbI X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qo98e8wFEjfG63FfM4C72o0d3nwYDl3nwV/6He3D5RlVM7WA0n2Mj+F0WxVvoEzkeMOKke8ycXBsUwHWjkZwkpxjB30/Mbk9SubZ7+TDKzvqiKHvNmlD8dGvbVKr22dFFRhzAmUSwpx/1M6GIUEyCg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ca91fd7-7918-4861-b4f4-08d96966d16b X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:37.3321 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 03/25] avformat/yuv4mpegdec: Don't call avio_tell() twice 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: 4R4LASqDvv0t Signed-off-by: Andreas Rheinhardt --- libavformat/yuv4mpegdec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c index c327aa9d3f..69dd8a3165 100644 --- a/libavformat/yuv4mpegdec.c +++ b/libavformat/yuv4mpegdec.c @@ -44,6 +44,7 @@ static int yuv4_read_header(AVFormatContext *s) enum AVFieldOrder field_order = AV_FIELD_UNKNOWN; enum AVColorRange color_range = AVCOL_RANGE_UNSPECIFIED; AVStream *st; + int64_t data_offset; for (i = 0; i < MAX_YUV4_HEADER; i++) { header[i] = avio_r8(pb); @@ -254,9 +255,9 @@ static int yuv4_read_header(AVFormatContext *s) s->packet_size = av_image_get_buffer_size(st->codecpar->format, width, height, 1) + Y4M_FRAME_MAGIC_LEN; if ((int) s->packet_size < 0) return s->packet_size; - s->internal->data_offset = avio_tell(pb); + s->internal->data_offset = data_offset = avio_tell(pb); - st->duration = (avio_size(pb) - avio_tell(pb)) / s->packet_size; + st->duration = (avio_size(pb) - data_offset) / s->packet_size; return 0; } From patchwork Fri Aug 27 14:27:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29810 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1512145iov; Fri, 27 Aug 2021 07:28:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8ccnSKIaSYkdjjdz49a1TE5OfGDXpi7Tvc7UCm3KFcuNysJjVJWpwdWevqEg/7xYvUAB8 X-Received: by 2002:aa7:c70c:: with SMTP id i12mr10196751edq.256.1630074490257; Fri, 27 Aug 2021 07:28:10 -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 f12si5788266ejf.532.2021.08.27.07.28.09; Fri, 27 Aug 2021 07:28:10 -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=oZ74GC3t; 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 0217E68A1CC; Fri, 27 Aug 2021 17:27:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074075.outbound.protection.outlook.com [40.92.74.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B562D68921B for ; Fri, 27 Aug 2021 17:27:43 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OwAmXdEz0R6R2kRMDJoPoRpWT1lghO26SmxprfpJgdL6wsKNCS3qjMxtmyDUr+5ZCw0FU5U+1qH5cfTLdkhMX8beIN1UFUSi3FUB0K+1MZvl/FXc7zsTKsOycPEqx4zTAg66jw3z8oyNg96Q84gHWJzSHQTnW8df1RvtUShDgQXdT6pHmul8l3AmQwJzVkw+6blyTdNnz0fW2KMS0insX9kddVafci0sagpRtMFrhUo0eRb8w0j24dxbetosB2RhYQB2X7OBmOEbiug9dNrextp/TdRQ/ZgV6yP4pkRKxboDZaYQM38KmCkGpQbSKMXL/fh3LAcXuo5zL4+VUzjlUQ== 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=OAF4frFpN5OjEbHJR1CI/vrH1YTdBBCI3Rjdfh0boeE=; b=IEpe5xlcLRq0SrI8o5L3zpUlIzKlF0q8EAYS4ws62JODxahXQWlxZwQldrnf267ewsRkR5IPVSz3wogK5Nkn2VazyhZI5owpcGdoOdpO1JuswG8w4o/cMce1WrvGxom0D14emHGc+HHozxgvAuQ9vPJsl7Uta4DWEqBxMzVfY/zyWOjdBfVCGHKfgkM2Wjqy4ivpA3wk7ISHb+NnWTdY0z+GtGg/6Wnhoz/8HGGS0ipmQ6vGVaS5FW/oQOfcwlNf08n/7N5lqloT4IhLfs6aHFQvfFo0sHCYwG4V37pLIgIS2wQIA3DTqCLRuY4pMg5JpuEq/X/dLgZsFXVevff3yg== 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=OAF4frFpN5OjEbHJR1CI/vrH1YTdBBCI3Rjdfh0boeE=; b=oZ74GC3tk/AXkpVEgbDGN13OphsuzvpwJWzLOb4KQSlbIU9/qCpKdMjWw6Fqw81idw/teosOTotwIrXBnAxd2NbkQyYgzJZqu2snGtOMYq9hHscdWXwHYJbhUnwnr8It0ODHvWqGr+vPIetC2uQrFz7O2J05njCt4J+sHpjG+lCDxM3ts4mPvLQcOqxuePkOw9+ZTZPaUKPeEraFbygYp0mx4hRpjTLUr+XOD1rJokPrq7HBbTq0VuTplebTgN16CoJZkoiCXOcmiGDaqC4mAIyXHQBf7UJNxe6OROodWa1QeutLz7C3zO2VxSbNmQJPH965OBvUyI6wkldhlbIL6w== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:38 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:38 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:04 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [v+a9v4lZtUNhvSD3PAXdDcfkF3lTn7LK] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e4476b01-0166-4ac1-1e3c-08d96966d226 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/73utQ5t/fT2nVSuqhKFpSnLybPDuvQC0ZYEwBpH8YuBuc4sGsS2/1YIK+c1Mq4fW/jc54Q8+62/cXSa/UpBTONwgHNvsvHxauXZglYBOPwinDRTX3XOUUpA3X7gCnQM0vixFipbyEDOo27m3h9GkwzonFqzdRzKM8ZCcM1rfsJXnymn1Nxt7a7YP8jgsrvgoD6PgnwcQAqZk5w6C46WvjZ8WgsNhlK3+B5RygzHa6DOi7ggDqYoW/MRLqcRTHQlw+rXyLJBhcZJPQFlG1us4a6dpLSQJ7TQKUgCv1+wRHvxXPWDASSapyWNDEA/dG41o+ygQLuKWjSdOJJ4NKk0zf5ZNxLZ63R5BNkbgA81EIEHXCEnhpxLzD2lFy/mNwhM/MkVH1X+qlA4LcWPfq2kLnEK/K6nzSrZxpMFAHyXi/41qIoywpDH3sFjGlMdami+lKmAtY1bKH0hmNdE1BSH4Uxh4K3KFv6plWzdajv6EbmljAl1jCKxaS5D4wVQ9Y+5tK3lOLeytkPJ7KCs4ndmnCAbkSRhrG0nuRcg3pVn98PLSr+pHobOJwHWxOWxo9DUKz/spg+gJeUzO/vumg3qbfPl+itsElBRJ55EyH6qwefqLfAFaMsiYl+bsS1uokHBJGXLOjVkhu30aIxxFS/TtcBLlcpNu6MnKFJWxBkL/L9zKiAimknfakTtQuVKwjonbTyLTcmCo1BLq1g1wlZ9DiAmkKqpTNc5hbSYm4Q+oQN4I= X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U2J6D90tap2KnFpai1HHnAen05sebbFOPfMMYfiTVT02S/I4Hx53XfFJM03SXcbUkyQgW4RhLPPzq5JT3X35xB3qjbTrsBnNOkmwWwdluulkg/eCvsrTzymqCKCjkNlUse4+4C02kavgVpqH7qKsbM56Gs083LaEDlN1XS9NGq8YykT5G/AwTx0+PSP0k6SUmCe3keNmoOpthkwdjJWMgD+0WejyizJjhsxLORhgDM/plEeThqBU+X1VG2L6vl7ZkYx0NvHGZJHM6aPTD/MFoiXsraJSlbZHre/WfrjePnAWmHIQpERtfYOK0ZmRbfrqL5jDIl5jmAhfFDqGrrjdzH2p6hm67b58JHQ6j+va3bsbuqWSKl7kF639SkOBpyXVTpU8/8izxE/x8kf1InKhq9kjY8a2e0Nsbp/Ejk9EzXKCTmPJYcrltpZfYItHLY22 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Gw2GitghtskSh3d5C9sbL/ljnHAw62FDtJUhG8WaHsfe5DJkQ4yhx2QPne4kAum9omOaiQyTIJAP2lXHd34y6HpqfhtMHHdc8A3lfhRzLaaNnqgMnkUY5HI1FTJLw88xwWIcYEmmYS38QalbKpuIKQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e4476b01-0166-4ac1-1e3c-08d96966d226 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:38.5458 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 04/25] avfilter/graphdump: Properly initialize AVBPrint 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: 3cc/sBH0/5tI Signed-off-by: Andreas Rheinhardt --- libavfilter/graphdump.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c index 79ef1a733f..22b2e21559 100644 --- a/libavfilter/graphdump.c +++ b/libavfilter/graphdump.c @@ -31,10 +31,12 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link) { char *format; char layout[64]; - AVBPrint dummy_buffer = { 0 }; + AVBPrint dummy_buffer; - if (!buf) + if (!buf) { buf = &dummy_buffer; + av_bprint_init(buf, 0, AV_BPRINT_SIZE_COUNT_ONLY); + } switch (link->type) { case AVMEDIA_TYPE_VIDEO: format = av_x_if_null(av_get_pix_fmt_name(link->format), "?"); From patchwork Fri Aug 27 14:27:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29812 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1512311iov; Fri, 27 Aug 2021 07:28:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwP/ybXvUKcIOXpCMcobN5s0H4V/Aivg3TUR8dKBsXTPqR5hFr9CYtOf79yeL2yurrcQOd8 X-Received: by 2002:aa7:d40b:: with SMTP id z11mr10007429edq.224.1630074503319; Fri, 27 Aug 2021 07:28:23 -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 a1si6554172edr.277.2021.08.27.07.28.22; Fri, 27 Aug 2021 07:28:23 -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="hR2B0Mi/"; 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 1E2B268A214; Fri, 27 Aug 2021 17:27:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074082.outbound.protection.outlook.com [40.92.74.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 332476809E0 for ; Fri, 27 Aug 2021 17:27:47 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nQpcadghvjXAUnKzP3A7hUkJu7SECHYW3psMvUZEO9XvicQrfoEXk8DlzrbxbTlgL5OrnYL72e/kmW/QdGW3u9U0+0wneiKBuEZi9Al1EyYCoyQYtmrXJGa8hJxXzxHGNDDHIFVZmElwnO9zbqceo492Csub7CvSQ5XBz1HilleKWdYjQluqg21gqnrxAT6QpOCUV/r8SXJ3cRtUNQ4G7M0Bfe9QXVISaS7PgEaGjyuXdouKg7xtfIyMeGTh7dP6PWn7yK38a+yQaQ0GkF5hqt0aQ2+meHlcauyuU6SmIEL0XrnkV5IAWkr/OjgJ7OiVLWdkSVABaMV2adBGBvzHvA== 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=bK+7MtGygnQjsX9NIiqfLXEBvy9f7EPi63UM2O+TVEI=; b=cbQJyitOyPvFbPbWgOmO+BNmii1dCyF3oeU61qk9Hnhrifnpr1AXSSmWfLTyeEM8IxlaC434kh4lHDIikxRaSHLWBqUsENsIfR9N4KW3+tBBzhqEgNHdfZI3p0qXlGy3ezOb+Z6KLVj0XT6SbMEGUJA2LJJjVkHs2WOQURw9XpqJs5EvM/Znp+62A2ZziPj5XbWixwGsW3vJClOKawuJCZPQstspGPI/S2X4VD9STxynpDwXSidFvunMBmN/ZHpFp5W1J7kJbnyi6zA23Nk9a3C7/rCqUSETBofYz/tezKHqp0IQfvk7EnjQ7EVtUu3bXNbkd9IIaGJphVoXB2HLnQ== 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=bK+7MtGygnQjsX9NIiqfLXEBvy9f7EPi63UM2O+TVEI=; b=hR2B0Mi/ii3HsmSM0IGARWA6A6seNUFqH5HZcF9LQi9macbx2HHb48NX/4xFAkVHE5O7pgVf2kM5dprgiUZXcaidWKRdsyo8bRmS7KpzQ8SdpiLn1RSGKx8mNDkb5FPMuF2aupyHnuEUujOnOjA9iPwenqg3UtN2nyN4ys27GH1IRdZUC7xwHhEZV2EJqxxZ0GODJusZiHb+15z8fV7bAM1XvH+uewPe2nJe26DUr+/+gOO7EKJa/HXBumKeWVOiDYhtRxxWAP4dLscfjv96mzBuJE1EHS1llK5LFTUoptlRTLvkpeosoKiGTwCbfs6bqopu19k9LipqtBAWS5UdoQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:40 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:40 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:05 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [G/bwsN/R1Ur2pkcBk0u1JKpUMsT+bO9s] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c8001d2-33aa-4cf6-92cb-08d96966d307 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7h4qpQ6owituG0lcXzi5lqtpzuLYE4NzlQyyLfLgJH3pIwOUKPtersGn7mboyF2h535BQ8oMO151OeIlITAFjEKzKytYyXpl65VZ6eaa3CzbF2SdDe8FXpg+88EcH7HNlgQIXC2hjlY3WYLaSsauHxbc8X+iC0JwdcsnoiDivuZbCNKe8OoWn2L8kwwQ1Ubn0aPQfFhGBF4RXLoml37UTKpp1Azm7Dq+u4UvmUrgihq0/7Ibe3PxrcezWGKmRLMHQ96hsNArOhuB+BFO/z9fWaxpD8wM4yziblRMtQ+z6cUCxICqZ3zx7ys3g0tJI4qtPQjQnQ//35MO4ZTAWAD/fc2ZylaLXpxsebtYwA1d7LXO/H9vQdnVctgHmoiNlpa0q4vhonq8a8pq7o08/fRkTqOtqfg+C+iYb9Ame+WUdUhPtp29fODjLn2qrmJ6IiYcdv+Jo5lCPbRE1FpQmXshreH3JKmrCzEq9XFRS3LxBBcQNc40GIM20JNmz3YVQnd60PT3tdDiszBj5+2NeNR1+kT8LneXmyacs6bmWZmw7pRJxRHojatGduwRCNAw0Z9LpfVZsrdRZ6lyg0MNwEy3KMchAQ3ACBi/mVhXRAct4FKntp46AcSZkIG/cTD+qE34MFjrmFXSthwMf9/hH0SSYe6bSYesz6NBgKKGqSdVyfoLEFzkMFrdM2bPhbKZZTIZCwlmPocEjEBjy5i2G7B9cBlG6gn+3B8bH8Ib0gQQa0t0= X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4LAbD6SCE6rJYSxwm7KDjrl7aBVly61LRNTsbF7jRckAigRrosCN4h/2alDQXS9RnixsQ4ppHC0Io8STU9oWJAGtrIGdVNb4k7QqYTxW39rtEm1+TriJlTZAgSS5B+WrAXd3V+4vHrqT5zkeb4IWertFxwK4cjPHAIAfFiQS1KP8TBrmtAoDooSva5dFooh3U4i/44ve1/uYY6ENJ3MTs1a/bacdJRAO+tZfEt+noemLcE4we4VNH2GoEDKWTpzrBbEO+PDs37uJRwjYnlKE8V7YI/y26d63+DxZkRh4/UIYPJWtzhMGoAivjRfAHsqoxRhk1uyzQsDSSj8BNXQeypaPfYAI5s3otwDbvVec+foTiCQY6ySnpbvRjjZuAPzACXOj/rTvLPcal/ascNt1vVLXZRQiuhiHYSc47JhvkkXpDca1YZdpLkS+/8MkRvcp X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: //ty+I6CmxypTv4e8K2mZj8PKhhIuZJ65Mt2XA6w2T+okisa7u2JIIMRvrOzxHS2wS2d1vagGpBzSByNzddGxr6Y7vDAMvzlsaNMHZhPkWNNuz/hCkDpdCKUTAeW0OyXbIkfqum8tyQsfjpr1b5YlQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c8001d2-33aa-4cf6-92cb-08d96966d307 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:40.0204 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 05/25] avfilter/graphdump: Don't silently truncate channel layout string 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: wqdvYCW4U0ZO 64B are not enough any more. Signed-off-by: Andreas Rheinhardt --- libavfilter/graphdump.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c index 22b2e21559..cf3296550c 100644 --- a/libavfilter/graphdump.c +++ b/libavfilter/graphdump.c @@ -30,7 +30,6 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link) { char *format; - char layout[64]; AVBPrint dummy_buffer; if (!buf) { @@ -47,11 +46,11 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link) break; case AVMEDIA_TYPE_AUDIO: - av_get_channel_layout_string(layout, sizeof(layout), - link->channels, link->channel_layout); format = av_x_if_null(av_get_sample_fmt_name(link->format), "?"); - av_bprintf(buf, "[%dHz %s:%s]", - (int)link->sample_rate, format, layout); + av_bprintf(buf, "[%dHz %s:", + (int)link->sample_rate, format); + av_bprint_channel_layout(buf, link->channels, link->channel_layout); + av_bprint_chars(buf, ']', 1); break; default: From patchwork Fri Aug 27 14:27:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29814 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1512468iov; Fri, 27 Aug 2021 07:28:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6MUNP7qpYGpwWbrAh9C5VLyb1MKMWCe6yElZU8eULu5aeuHvZ1mlAA9Ue2oVYpEZjCkxj X-Received: by 2002:a17:907:7817:: with SMTP id la23mr10449446ejc.43.1630074515768; Fri, 27 Aug 2021 07:28:35 -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 z10si6736658edd.2.2021.08.27.07.28.35; Fri, 27 Aug 2021 07:28:35 -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="bCj/+cRp"; 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 2A17E68A306; Fri, 27 Aug 2021 17:27:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074075.outbound.protection.outlook.com [40.92.74.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DA53D68A214 for ; Fri, 27 Aug 2021 17:27:48 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VEYD0MzxufaHxKNMEmbacGjC5DkZXDM1ctdkKj/0V5SmUYV9SLaM+HwlxcPoFLKbWuWUvjskf+Q5+etTSwEHTkTw9aY25detgyaMnzBrFK/xqWqpeE1zfNqkWN3RLabs6WUv/lv4KqvbgBuIwT+hcRdHav5d/NDI3AXT6CcHXwxkD0hI7yG0bY6fQmO3yvWWxTsF4wEc5ZrKn9RF1DgzlprJG2ohL2mIMXeQ7hs1J971y+w2DLIQh7QOusVVtxREIkkbrbmGE0noa3M/T34IHGMOdg3CZytXPN/VV7eoLy/R+GiPw9bOS5yFFGOA9E4hzHiVJLoRTO7OJgoDSvrQUQ== 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=CIPJJNiw6ckmDY87tED9peCXp/xNib/soJKEh88rpzs=; b=gmMT6LWMZTllXHpL3yRVK5WEgjlAnbnGK8ApxYf8Qmt8X9FYAYTb0f1dFq0VYnqSlP2TpPB7UUT/0tp5/6qm/fMoCH6Fdeth3+95O8MbQ8y+LwxIK3SCfahNgyvygzSzXN4IlvnvFFGQqgBqIoXc9L8fDwlA0PBTPrRh3D9dx2pidho/TO2notp53hZnoquZBLJVZwiyTtsqA3agivZLfWofbIy+g4Fbjo+G3kEvu4jJnurQ+/SowRIzZv24L1l/HPGBIA5U+W6zsRTL2OXoMyCjtsbvfEQYmoLfnvjsbStF+bbpWC+hz4S2RzgpCudB7hhlj0ipFY8hKsgHOMzIHw== 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=CIPJJNiw6ckmDY87tED9peCXp/xNib/soJKEh88rpzs=; b=bCj/+cRpqKQylfodB2x/LrJs5BErQaqiRr30aQtVvQyGriungPrQPgjN+j7XderONkJ336IAdc3b4lDzQcwUzzS8CQmNTz9WWH44y3jHAs+t841yhf6snBRjRBrNgZGRNUpD2pubP8Nd1fxy8e/oOV95IgFFyNYN1n9SXMuhOfoQHLvH8plcrF9f5rU5HNga29Ye+RyStWf56UMtocARKBpsJDbXvCppEsKhJ31MoEWNwlF+4ewQFk+voUGhlsmeMtd19f396kT0fj7Ko0xAP37j/6XJCN2qlW6ML6fGryyJng8QOFs0lCNbpTCg+a8sC7Ga9NgVBwg0lCeF5EDdOw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:41 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:41 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:06 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [AoCc/J78F1829iuwAWzUMk6FqXk4AmAn] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3630bd77-58e1-48d3-b9ad-08d96966d3e8 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXOVIHST31EzKLNwg5cTLbykmRyEKg7lkTTVlLW2XdZylbHK2xtcCK0kRA67FWIH3SN9/Kk1kJ3zQgvTh5SC4FgabwIodjkBrDO74mBql/Brx+2N1w/2XR0EST/wcIh6HfC6qWXnIXevb7fMMDjz+eTVHOOLxSOUzk73OB+jQLdcZirtiEn1ixMjd4Rfa6wOlsVNmJegpG4ktBznsStYVaSjTgEI1zBviNeiKS6aHEUS78u2JDvOI4GrW1bquTl4MOvVxAKV2C7wAO6vH6Ux5J/H8KDfS+BNfGFZTKEuqSOw64QWqWgQIkC5xoYvIMELzXn2UT8YMeE3+pDbuDwawES0uLY4aA2lo+EX9Fl/2s4bWVRR5Ya3ZmIpYOtgtgeVW20XBpUFQ0BBQcrJaJn4nYWgq+uBUJOYCJvNFpr7WOSxChCaT4tjhj3mYNy2o+bnx/6NvlP8B8YQ5ZUoRyk9smHOAZ1icKG9BdinLCTHsmPovmQWJ8ax3dWllZTx/+PhKVPpcty/Yg6Amrt5EmD/gQmRaeE+lysAljcoOl5XoIK8xx70bYZxfle9aU24PbloTXNL8uyvRH0k0bJzhbHPE07smil6xqdEnoCqrtV0tDc9nZ1OnI/fNejUQLrcQPxfkIA4APs408W17b2JtH4U3dO04UZ67znCt+0mGoHb4MNvr8yBzd1TdCsFTGko0EgGlGQy45lNkw5zUsDME1OkvCwsFf8PRbmc3c= X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oIRiiF172eKbgKhsWpX2yfy3S9TI4nlMfLSFXVNheJSHOS6xYIrY5yYq8Ymog2PDypU683r+GNffYhAToK16EgnVBMHIZTPedsPUakoNuWTBPWTs6/XJl3RMNn3np3izJ65Wpf0D3RFi70FcoGR7NXNTb/gMApKcO//2aHCffKquia6NTN/3DhQdub/0ArXWH3MMLHMQqlhXRFm+pKn1Qun/0yRDlW7mI0DjAISbjDLE51O8YmDOeesaylJSXuT+brWNkFgpZcbfZVlRrBSlYl5yIKYAFH/7BFlQE/0qY4D5zyHz7VXh8erUJb1xnDQ641PKibV3/QJM872/eFnSwxljWzWSszaE8WNnStWIy/xhx8xsAAWfzlMvmsi5/Set4vQlEmSBf75pSwVtq+H6zwL4tPR4ZmnnYdRrja8f6kQnrEXmCkHFZ8xku4iHqbcm X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: y+mkgUK7qtJxHrNb2VC1A+7ybIwZjY1ahAD/HIgK+64qGCknGCtzybU1IXArlEqwXc856PSzSt5pTX4wr+aof8BZgrw4tgiYpRW/tDKFVhA4sQK71+oTu3md7M3CxFeFK3Ybl9HbQ1EocCstQgIzOQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3630bd77-58e1-48d3-b9ad-08d96966d3e8 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:41.4970 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 06/25] avfilter/graphdump: Don't return truncated string 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: ApiNZLPxXVrV Signed-off-by: Andreas Rheinhardt --- libavfilter/graphdump.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c index cf3296550c..099125bea8 100644 --- a/libavfilter/graphdump.c +++ b/libavfilter/graphdump.c @@ -159,8 +159,10 @@ char *avfilter_graph_dump(AVFilterGraph *graph, const char *options) av_bprint_init(&buf, 0, AV_BPRINT_SIZE_COUNT_ONLY); avfilter_graph_dump_to_buf(&buf, graph); - av_bprint_init(&buf, buf.len + 1, buf.len + 1); + dump = av_malloc(buf.len + 1); + if (!dump) + return NULL; + av_bprint_init_for_buffer(&buf, dump, buf.len + 1); avfilter_graph_dump_to_buf(&buf, graph); - av_bprint_finalize(&buf, &dump); return dump; } From patchwork Fri Aug 27 14:27:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29827 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1512922iov; Fri, 27 Aug 2021 07:29:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+rnQsaOeGEhzC+qIlzoWcQWtYZBaQV3DRGT8WaYpH6I3UIWUGF6YJnSzQnCvRKM2wwIqc X-Received: by 2002:a05:6402:1e8e:: with SMTP id f14mr5145762edf.15.1630074550012; Fri, 27 Aug 2021 07:29:10 -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 nd33si6777084ejc.139.2021.08.27.07.29.09; Fri, 27 Aug 2021 07:29:10 -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=X4pE8g8l; 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 01CDC68A3A8; Fri, 27 Aug 2021 17:28:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074082.outbound.protection.outlook.com [40.92.74.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A61EE6809E0 for ; Fri, 27 Aug 2021 17:27:52 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IcnepAU7A4U5eXvOVKe1fOxxVAojOo8qQMqcP7hnD5xWF6dcG8KjbqMeBsEkbWCegCwLRqZOwK55h3l/xpoPHPjmlUl1VO6LL1ezhthpwcXNNbUgawQYoDgtq+wdieZPTZjPAc8rBZbsVrAk+agWLtZ+nbrwkdvYXkUcdbpDm/pHcEmKYDM+/XzznoGdWGduiEWlr9Sz+h2rz8kLZ0vbKeGPXhAhbmyvf6kITdUBKtThdOZhWwWZjmuWgE8Zy4gRIbNpTsOSNatONWws0Wu5y0YSp+TZLM1I8Ye9Nk6Z/ElyYtHuAnLv3AQk8M8BPI6AOnnOfl6SNZMH2Mi+Fuyh6Q== 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=ZUJgsnuZ0dXQ/4XxbluAUV/DdfrUcbatbFqmb7w24Ug=; b=UDBrtoZmA/f33pgBVLYNSF9LUR7ZN2Y8uX/DZ87suRNNggyjpVcq8Jy58eaZ6wwRTz9Fa0vuCHiMBVF6+vN51ygyCxtVWdBu4yOF1RV4/bZT8mtuIDziPcmGse/p+fwy8O5l/N73PWgcKDFA4I4/EqOVWaO3BjEonfGhDCgVBBhk8TeasnQwcFcu+AmuRrpLnfduDsAPX+o4WeLqidZBiLbGZuAd74pT4+BW7hlTHK1KPGUnuWn7wceGnJS4qkD7YXTxmpFAEIxYZ6T1c8HvwE9Yl8uXb2ScvvZHGgx1tthP98ACWk7zNg98Qzev8B+/cs7tZCwLdaZF8RJcj0Bwrw== 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=ZUJgsnuZ0dXQ/4XxbluAUV/DdfrUcbatbFqmb7w24Ug=; b=X4pE8g8l1bPJ0rHG0cOBayw/QNEGvdTPxtfid6d11oPVxfYrrDErTGLg4L7jpatvWRppfoqsdHJmCJXq4JOZCxIpaHoU7ws9xhkMTOrPLWY028g3D5Uhl7rf0xembKBSAD0sCq46Li7VRIEU0uPRx8fKvPBErPXud8lbj9Y4cQDKsJ5Gh8kAFeotNmDqRbDCQkP9W0i/8Vhpmp27OmRmWFinl6ZyJmkqC2+Ds2VQMeNXCIZOnGIiby+B457op6ZWkfCsD/x0mJNDU2KjVb42QpOvZvTP2zEyfVaqRgaiJaDpZhlJeX8gGwFXA4/Ax5eeuqdDytRbidck8hu2pOrYUw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:43 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:42 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:07 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [vm7jlTaox5sldjr5P1VgT4NzdDdy/gF5] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-6-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c1e53ac8-e86f-4846-0dc6-08d96966d4c8 X-MS-Exchange-SLBlob-MailProps: Eluf6BVNkXkJh7RVaxZPWzX0MjEVHYyw0rs/isx3+aZKbjHFdrUlXQmgAFjBJUc7X4cSkyO8h/ng7MVKW8ge8b8zwuAIuolDDoUmqZe766hEWJ1rQXALOWM+738moYx+JlVQwn23irBoMqPjE2KLw12MRbfLDUtpDNix0evjd/850ePAbOhhlCmlOINIM/Iwy1hT0ml5pMCHyRPHNtOKDTwYl6scfK+wRf6K09VS/cjoOBng7uUdXqhRNtQ1dDgVE87Sd6DLmn3BNLkWkNKX/ydyPi43oZVwJz4r3J7kIwURwkfylmo70Lp1m8PiXDk8/cNBQm0xN2rkIcu2+q964au/RIuDzixe+b7SJ1vNv7aBcZWP1KVBBkl8zAX+HliRR1zSsI2TwJMyiJkQE9FiEm18m1lmYXnNQ6VcXZUUxnUgYN3JeCKWPT0ZzueqNcbBWfgNn4Bq/RDIuSmEuVKpmuVuCYoSFTzmxrDk7V9Rehu6uoUyyztpsNUvw83u6ueDGLEI5jO0+GGu8EDuv5kPdz+P1kNp70d7DwiTOsW04APwtaYmPswpC7RkuPy1Jqq8La6Y4mXKyGJWbYp8vcbP+fnvRXo//NfImdkFb7TRQCSOxdkZ5lHhGIiq6bMccZIniYtNKkzYzwetBkRDTvAlx4cBx34JF5oF X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L8z8OJ8qNDrO6kDDsSE0ZkCPPZMFyPH/h1blG1TdI19qDy57/we00L05MjEEhOqzk2ud4uYfCRMaknVpi1gKz8w2MPJdRFc4kwBb+ASFXgcr6PJ3mYGnhtchJLlvT999k3vjRM1xTTrqvhUigqNzfEcOGz7UUer4/SK2t7mZPtFTxbq7sr1xkCZsymnHAO8QamuXZk02g3XSDer9fCtKwCpkAnDGHv0x8GgyQqu4XrHWQYfKm0ioIyVYSveyzI1O1UW5JJFfMD8dAtfBmwsSbysBYizfyJ6Ljryxo25f8ZNXc/jtJzzafrYlqAkwTkm0eGEmBsOIle9PiXcDbqoTwTOFohrS7+4uGkkUYH4WFKJ0Jq9NojZ1CpaKR7xaw3ZbSzZuJDfM7p0DR/nz9aMHSbcPz7GL4hdptZhbtvN6xxeu1bAf1KkyXS+k6uUiooBy X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8NeetKsTQ1S3beFsxgSc8MRM6me26lb9szA81vMvViRywch5yW0KMucGvTc+NSrPFXMpPolLBDm4hp3UujxhC1DJn5mRER7IQRruavHPmbLHm2cZKGsd3G/Yqx8BStpvCGcmHv4oL4s14IDLdoSf4A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1e53ac8-e86f-4846-0dc6-08d96966d4c8 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:42.9287 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 07/25] avfilter/graphdump: Use pointer to const for pointer to static strings 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: TFuGFgwOOmgL Signed-off-by: Andreas Rheinhardt --- libavfilter/graphdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c index 099125bea8..cf8914b558 100644 --- a/libavfilter/graphdump.c +++ b/libavfilter/graphdump.c @@ -29,7 +29,7 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link) { - char *format; + const char *format; AVBPrint dummy_buffer; if (!buf) { From patchwork Fri Aug 27 14:27:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29811 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1512790iov; Fri, 27 Aug 2021 07:28:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWe8h0HBT7XYeXP+JX/FKKS7XCRd6lebDCmAsOE4HYZ+K13OMu5nqXOwDNgTa4pDerwvvf X-Received: by 2002:aa7:c311:: with SMTP id l17mr10199964edq.320.1630074539641; Fri, 27 Aug 2021 07:28:59 -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 gn9si2196055ejc.550.2021.08.27.07.28.59; Fri, 27 Aug 2021 07:28:59 -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="sW/2UZv5"; 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 198F768A2DE; Fri, 27 Aug 2021 17:28:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074075.outbound.protection.outlook.com [40.92.74.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 079446809A7 for ; Fri, 27 Aug 2021 17:27:54 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffzygpeGeSYDIIi3TX1RPPNH/I5CNkHtx5hW9yQrvysjU1a3vsfTNAHqdofAOz8F+N8HjwiMh6EfVE6aGuweKOhhHVRWhzFk7bMxghUK3iC7x3DVmJkVZ1/jQ0Vr5BnzVAgCl0E2pRMXMWwkEiE4CH774K17nSBtwJI7pLYHNq13eE4k/sxDAJ5xwfPqMmnZeRAFcDRhXAl0BEUPBI3heScdIO+5W+teKjzRC7sS4OkPAFKlS0cKVEA7r/fEcLwdkpvS8Pgsnxp6bUOHM7Q1yOqjMAeD3medg74tH5XDjQV3rU5diHtxfOyuu1E7FntsB/mPjx9i/k6JRA+IPj+hIQ== 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=VeINex0t6dpBRySrzdp+3MSidyKyjSSBZD/nBHFlKK8=; b=X6sWA26q0h/XQ9HqfRk2o8oyYKdTkSQEv2PmG3q0tpeA1JzoJ5CO1iuo0Ovfn0Vp/VhKoT7e4n8HI4kejv4B5jPLfoZOIvapQ+ZT5hQnvhfkR8y1a0kN/a/E4oJQGC0a+7h+DqfJ5k5nsf4U452Q2Z/p5BLSZxMWy+mbrDE4nH4QR9w/U+CJ/mt+MfjTtfQKZQQ7gzmUcwXsdW7etQ474EK8zwqemv2JAAWvnZVfP6VBkI17/C2bycCfH0PUCH154noQBJMXf2yeWo4Rvj2S1bcc89KXC3/9D7YpqD+SSF1c8joQNKGPZItFn8x3iZrULW5UE5mYcQhWOsjkZG26hg== 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=VeINex0t6dpBRySrzdp+3MSidyKyjSSBZD/nBHFlKK8=; b=sW/2UZv5xSIQxw44RCnpg9LkCBP+7RAZW322Wa1SED1BWp5kjGZKUGECsOI7584wklI7CDCT+w9IaBM7ub/SgVmgfFSnGQHMAIy6xkbhWFXj8S3v/zMCH6bJtppjIoM4Od/RGYOw6W+HpvXKlzXJ2PieJ4f/h+wAmF+4DdNJaxM6SQo2fsBITgUeOwsAdH7xG+HSdEKXBSyamFgwSSUNf+Zy2dWMdf41PoSfUESx5v/8rYsVDZr10c4aRptSB+uf10LUKP7/IwoqQaS2pQ/cjxh85FQ4SdyuK1quSslYlPTYLzEdXGf9sTmHl+7vqE3u2E2NSOb4gM12SM3PEOsmfw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:44 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:44 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:08 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [B+4AcitM7lzIladG9ttx6Lg5ZJChPNUH] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-7-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c9dc97ad-5560-43b3-a44e-08d96966d580 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXOVIHST31EzKLNwg5cTLby6aWJZts8XpQXsrgEofaDJPE/1hcylMPsaQ/hCOQckZEUfVhbIP0+bVR+2qVwRe5j5wBtaE8/UegX9T4RPUctzX890DOSWTtymyMV9g1ktoephXbH/iaJIESwl7IcM/3fQGzigUWmVF86Rf+mGbPl7AxiqshTBAbtw6M/F70so7D1IxUtlxatZhL821fwpxQAdjszB1yqVmDJMILa1yYt19AJLh7l8Ra+igL57PH85uGN0mT7+QX5ExUPgwYdJSMCV09M4VsmkKFaIRQ1w5QLBIf83IQDEsyqLiLElnsyCuUlr736aEcWU9tsOeHeW+pE3w3lEVypdogvo5ZMrS5g4pX3ZAR52gfyTsPC1haJaPHAtd3jL/Tfsq5GTwQY8rVUz1N6mIxluRMVsnPpPsG8mT6WUsrBt6fRqKyabq692vfFUMHpaoXzMXhmb0JY5XkhdQTihnT7JFOpwufyJ9arO1oVnqIHD16sFd1NWpWnaqJv7rQpFZ7tDZSIwG7kYHC9dT+25thYhymWHc2CVdV6VKMulmq1TOw6t64lRnhgH3J/Z27UBbs/J+hb52q0rczSqBqtd52ExDAIK1zQcdFZ1hwD8t7NVbQNyc8+sT9jWgqHtUcwf2CJxs6zOaiLLHl6btUpSen2kOEp8GmQwNxo9WPhukzd2ZOPwz+QwxyUF3lpIlxXQI/72ZOf75mUZx530eAeQa6Cf8w= X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EFA49/Yub/DDdweuFgRiR//YG4hk8kbzlh2phGVZ+VYJ7J8BJSx2+8PBB2ITzF5MPL3p6Ve6mxhiYOnQg4Bq0fMekDFZx2wZQkAeerbjK62ZPu1va96Pc+RS8yUi/IwHynGUCgE5RiO4brJ6iSLUSP3jkVfaLPrFN1wrLORXP6vjw2YEhvOzSFKa29kQRz9U3Fz+jPptpOJj40rFp16hla0DLPfy4m48I/+2gZqLAq0DfspWZS4HxXr6YbLKO5Hs4bIsxeXSNEGNEDJmrf6CsPOBhRkQVbp8b712l+/GTlANvgCMLXMogYPIPYcvj6yCHlPOeB0RTrNUXS+SwvmQs75Q6AQV6tcsJ0yEDbDBux2qkBZjWdv4KJdKKDKjW8h5v1hmOE3mRvlxdORdvxtfmRkpcV8D4/fIwAWRHMglU87ieJnfXV+gEXS7lAJjUUHC X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: txy4oktWovxrj1r3N/RWoxiJrbD4QNKVMnWk14+l4lpZdZT2Abnl/tJIuHCVQC3ngYexH2jF7Ba/Iof7XcV9s1il3icDJ7Fd2pGCzLFaPwYEqBET8FgUKFcG7Mvej2BBWIrApsSfaQAZL9tcQfM7kQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9dc97ad-5560-43b3-a44e-08d96966d580 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:44.1543 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 08/25] avformat/utils: Remove always-false check 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: eQCtRo9BrgZI AVFormatContext.internal is already allocated by avformat_alloc_context() on success; and on error, avformat_alloc_context() cleans up manually without avformat_free_context(). Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 4caa3017fb..7d7fd16257 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1742,8 +1742,6 @@ return_packet: /* XXX: suppress the packet queue */ static void flush_packet_queue(AVFormatContext *s) { - if (!s->internal) - return; avpriv_packet_list_free(&s->internal->parse_queue, &s->internal->parse_queue_end); avpriv_packet_list_free(&s->internal->packet_buffer, &s->internal->packet_buffer_end); avpriv_packet_list_free(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end); From patchwork Fri Aug 27 14:27:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29828 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1513201iov; Fri, 27 Aug 2021 07:29:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGRiaSthmcvI1rpyaNnSytVbChuQbi1NR4pQDEFJE4q4MbcTRV7S/dhvILUgV3h4FXvFgj X-Received: by 2002:a05:6402:1702:: with SMTP id y2mr10227154edu.125.1630074572736; Fri, 27 Aug 2021 07:29:32 -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 jg33si2631488ejc.234.2021.08.27.07.29.32; Fri, 27 Aug 2021 07:29:32 -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=AG0qkmd0; 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 E441768A544; Fri, 27 Aug 2021 17:28:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074075.outbound.protection.outlook.com [40.92.74.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6BA106809A7 for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RNSzAEBZOXShekkKsqYMUjqDuOjSTi+1Sk9q7OACJhpGNTjP6/+NdAkuE6hxgrloM2R/Opsei3+2NkiBggXLjLdoSRZzFttXfK00usXXJKNsnXw2+8Gp1pbOxq07BKRJMnb2XtzVIAsVQjFbFJYlPPB9WdvT07K3Q7E1t6nJ6eajPsA6KCB2daH0GQzcVNIHb7Tozc+I0n6fXNbGez95wQSSyrQ9O5GI4r1PpUxZg23e3vr/LgF1+BJ/ioFaQA0KFo+zsY/ZbNbpireiFHSxUZX56UHAkQuEcg853t8yi4CjrZYuONbd/ulcKsuxyqZrHWukY3t1MhRAhHYpj/Dw/g== 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=xi3CL4Jpffus1MvWvlwV242rWoSh5NdBoNucb3QsgT0=; b=VqjH6w4BLnjfNDMVByyxe9Tme8ZhOSTm2HSZVAbYlL42qRhUvwit4JK0+zmmzmUdOwlfkw5bmlUdBxhDoclywgBhReMR2FXwNxyFKKt5nl4R+6EKL4Zhy9DC4e9Yzyyemowfp0zHFJT/7IhfrAjcXPvxPV5XWkCblS4y+5gunJJHpgktUwsn2IJe5+/HtFL1m0sWGE8/sdf9UK2GQHwSd6TaYcUC3s7BmvAvBmXrubBuz3F5IBjUA8WBjXJscee3oEEqBFsfQ415U0D6v/eUMmV2TExFYde2O8yesHNoeC6mXO61cA/xGWVByfPjDyrIz7zFHB5O5YJHPiQxWYbwSw== 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=xi3CL4Jpffus1MvWvlwV242rWoSh5NdBoNucb3QsgT0=; b=AG0qkmd04oITeiQrSJO5l5/NTnbbgGxGszywwLnt+7HQ6qacq+K219HFg4KXUBH+NGyzxPv7hMQv+udTqTSmbFPxmYCVW0cB01axXqk97JUpGpG9bpssP22kwU/YOK/KD/T20185GPKGZ8oFmn7Ha3sy++gDDUoTDyZdKH6Q7yBu69Fhrosv9Try6aT0qavaKRyiyNnVQquBOPJ88jqrgVedPZjpKC2tLHlybm2EZvPr0nztbEvHfeTz588J33i9K0fRYvM/M0MR5VN6r0doEo/1ZPmE51VQUd+BMVGXVZpdC/u0ucZ0+BBu6Sy4kBhAOafLaQkLEhgmfwbK1seTNA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:45 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:45 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:09 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [nFwRmbEFZ4wc2VTQb1y9SLBuwpEvVzVT] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-8-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 00f32d4c-8e39-4a7e-d665-08d96966d639 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXOVIHST31EzKLNwg5cTLby3bfFTwe/vhJ+GJ3JOCEs1EE5VoguAPEM5HNDC2/CSEaebGRwsR78mFJeSMonzGFz8c7LfzUvyUBfiaghYEbYN/2gf9/Z6hCRr4Yl9BufwAIoR17+bF+OPYUuAMtpXwIneoXZXmspFioi95L3ZqyUmx2yXg6TMzmIFpSxVBdLf6cGfFnLJIP98zdt+ZWWOG9IfthvJ0so/qVoFq2FFi40SLdUYhlm74KI0v1ZC5IQUEQP7YD8bFxlULnElMzSZadvQTKa2D84nVVFBfTmhua9tzU4OlJWj7qgE1Fx9bT3ewSTEFX5FgQsuP4fyU137nTxxOR2WkQcmVt6YHcz4ExN76kmiKFIa8/hbDSiOkYILI//CY4GXo61xngAQzhVGgGvglKHhe5IlIF2n3aa4Uvm4OxMKQoo5kzzDCEnCVz7yVmVcgcqFLDnWIPgKoBi85QP/siClrdr/dicFslSExsfqgnOCJHIaYdFwWsK+v0hdYGDbcgj90GVWkDqveSLmm3USoVSgu1jh/FObNyHJpcjwI2Y6LByQ7oGNAw4QmUk3sUANwgM0ILCAeZazU1Y5n2q6cKW8yFUXicYvGI2lKv4yqJzaH8LukmBroJHq+SokLrqZFvk+/sUqqh8wteQ4NH8BRXQRZeYUpenrQ37zeLxPZAO2yEQyl3rwKWqKc7+KfcGv6AkDiJkoUPC0oBmA+GS0WyNyfROmvo= X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FG+971NVGRwzbgFzdrQ80Fe6jIcdsSOreFLGKwcDvGfc8ScGbP4GMhdOhWOTiMwkc1sEWVFdUqLvrRhdg89pLC1+FKY+VnkcgjZga0ivsfM0u+rvyztDyai2OFDnBfq2qV8NkRKHdKn/S2YSDkHUDsOnrDu5hS4Mfp2vTibIOIkKRqFQunIeJKne662Ur7srTjFa3951SiY9wF0tlH66bCHNtCWCkv/2aOuvvS1sEtHDJtYM1wZSP3xb8c90MzQtO8JbJy2+C8MpzV5poX6lE6Gv81fJnRfEdEN/utZE1Y5T7hOCepce8hKEGdBo3KysOpcWPJYrjyPhSPYK34E6yKLH1Hb3ALpc4+58smHR79AdCR3znYnL3i1D7b2slkQu5S6n9gUuVWeII0o/gwdztw8w0mLRyUMYyGxAoLq4QQSARsa/SVUuURr3YvBJwsl7 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VK5CH5uCAkEqQw556QsmFmNmN4HBKhMmVJV0LrhKTaCEH/9qEgZBwyA4/G/j6OCYWEc3EDC+l3mDUu9HOUWtyrBBlKKiSgpwF1B5INqcpFHBcAwqcsTX20NLc/PFkU8eYZ8a9LdgsVpU7NRJhmHUQw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00f32d4c-8e39-4a7e-d665-08d96966d639 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:45.3870 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 09/25] avformat/utils: Remove obsolete todo 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: QOr7Pm7iY1p+ Also initialize the AVCodecContexts directly. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 7d7fd16257..ad8e26d3a3 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -5522,12 +5522,8 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVStream *ost, const AVStream *ist, enum AVTimebaseSource copy_tb) { - //TODO: use [io]st->internal->avctx - const AVCodecContext *dec_ctx; - AVCodecContext *enc_ctx; - - dec_ctx = ist->internal->avctx; - enc_ctx = ost->internal->avctx; + const AVCodecContext *const dec_ctx = ist->internal->avctx; + AVCodecContext *const enc_ctx = ost->internal->avctx; enc_ctx->time_base = ist->time_base; /* From patchwork Fri Aug 27 14:27:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29833 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1513344iov; Fri, 27 Aug 2021 07:29:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhyse31LY8HQNYdala5VItiZapuf7CtpSaAUbF6LmXPc2kbbXqMzVqE2JKKcZCvHBkUKJf X-Received: by 2002:a17:906:2dcf:: with SMTP id h15mr10800574eji.320.1630074584633; Fri, 27 Aug 2021 07:29:44 -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 v3si5907856eji.473.2021.08.27.07.29.43; Fri, 27 Aug 2021 07:29:44 -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="D652/0Xc"; 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 C5FE968A56C; Fri, 27 Aug 2021 17:28:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074082.outbound.protection.outlook.com [40.92.74.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6BBA068A36E for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SNN5SYlQa++ckYxKw2mMz3skmodS03W/ppUV+1NmXO6OTW3ZyI170kTzl0P7F+uG/g3OCyUM5JRc2wTXwqxX4nIoAAN3Zm04SJshc9cyQnFIRcqS1PA5evpFfMpZ9yBCtlNpO0PuwoCLrxYc3504j8ImVIeZ5RKkpkf90Iqigrm5Fkskvzgzh/ScLcKOK4PMmAOSbHnaFwKOEd5Xxa6TRsXBQkMgAhB/x/ykTFHjK9ZP+7ONQOtLu4FK3CthlF0pCrB6W0hCu6wUPl8xbOFcOpIYlKQFlKMvb5s8kUWG17l6xZ8LJMycZIqyzNdVHX00ezKxoTFMZdjwu6VeYZd7Og== 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=E2/T+p255FTwA4nZH5bHUqJoRx/MvM+oabNRpiSUfws=; b=S6XIOIIGxBwJ2p0UdJhkClUo2FVwJSFyzAnAF3t3mfXqhuPoWPnCwozs/Sz4ughrOuh+kwuVYwPvBnhOLiEysPHNn/AH8piMr+arrDBSCutQSCKtx1lwVS5c1TRquOgUlvNOYlyLcgbgqDXmjej1Uj8EM1iVbERkBxWLss6PwbsM0j4VmgwouyMO4tKnmO2BLQgqYjjuiNCcgX5m5niNdIlknKPprL5qvVI6fxkY9BuPQzoLuGEli3uPFmqqWYpWsAzIim3soonxchHxIF+DBobYVWkiZzznKZxDD/5Ro3t2pGlioZBeWV9D34butgPnsyBPd8UESxDxh/sfZgKunQ== 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=E2/T+p255FTwA4nZH5bHUqJoRx/MvM+oabNRpiSUfws=; b=D652/0XcBCvX+O3Z+EXGnqXJvdwqtcfYabLN+ACATteFkhYkmIKIa1K6AZIrlPg55T/W6ovC3EnQQlmam9TQLCxV/R4l1f2BT2ekiUBJsivEFqsFTwV1+LXCRmRcpla2xuLP/nTwnAvMHtmH++Hb9CF6QFvMqhQCrYFo12lqw7C+aqSd5mGL2F1C7POUlkl+nUVuXg+VV27T4NPGNQIKEObCcNnAw2Jwq4Nbdx/pM1tq5eAeGS2AVe/1i+TyUkH/KagweqafE7tkxfkgka3/KBdh9mK403EeOnALdSeDtPuTle+ih8Q0NoCAk6f6TV0F8HfPpPljNA2aJWyVXfB5aw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:46 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:46 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:10 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [kvvW+EAABlEWNuJKXvh/bQ1AqXrVrwU8] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-9-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8b8bfffa-daee-4c35-17ae-08d96966d6dc X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7ZQMwCaRHR1Pio3id876YrSZcorD1CssxZMIrCrJ2Pb8Yub6xfxNXIzMMErZR95SDMtgB5HfpHoOofnmAAi4yoMFrDaRa1UVRHIi9tnW9SJTL+QmJNyCyv7aXIKzHvLw2HCaBLFFOHPZisyMj1Us0z+9Q+5Ph1zc0LWCAVNAu+rHSzFAtuNv12IJHArFfG0BD3G+z9LK1/pRa+ZqinrtFKfLPV/igHam0pcgwFy0lm2MUV+19Iz2BAfjwkKDmIBe1YJujvVogzqGD80kaGCSod2qq9NZSuWcfOQpGmeR3jE5ETG6LGZIMtCKqlV2w6rm+BakPNJ3d+JV4ei7g2oT1ju6Jj6xpyf5ZeT0Gl+TM9bxoJSikjDmgkrWUnGHj+6acFoQ/6MSS+6szgIPCZqMl396WiEWTfRPxEuzhtDo18jQvgY1omwGlsb1DLQoKBJkQWFQsofiql0UYp1rhbOe3jttVfFjP60RRLWRKa6w6a2euu6tKyZMGNtXY5HVaB3Bg2B1fBCD81KOHxKSQ30MbitUwPKmXKzwReqt9dHY+imSdghKB1MHxI7vL87myEb5VuBMAcy7lFGKcBu0+xFYfPnJNPRbNGT78foGzgygQTRFpZW4VpUGqcsEzotwb2b5yuYu3wlGY44TWUTZEKKwI1eojpvCKFUj8rzLEANaM0ZVQ2Xvy5wHnYKergCYzCM/uGBUC0AFOXzHhYIQkVFGFTIW7d1/mNIDkIsr/QFtscKg= X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OKPmVCSj5PFie/cVi8g1G6zqFkEPpD6tH/W51+3DK8HYcj+AIxDQEZGwTEkOPLwjAIXd4c26yxUEeioM3PZLXvUAkVfoIpkDqfAAuaSrQ9vLVQ9DWGvbxv8tS3+0wXgMg/NjgHJOUOSk14KDbWFT8YsVKrQvGBffrJ84VOanepCwz1uNbvvXPj7Aqhq65D6PcrCUuYcSUhMYVzHBBIWYEI0IRn1U/jU7/bz0T9p55tbVOY1KtVlADVCihmRGwo9RRcnqBbOwwamiItI5Pb/OAaFE0i/RI4q0ZaJpltrJkVPqiJrQU0svNfUUOoT/sjez3t5767LzJPCkc00Y60CVpwUzhZW6H3Tvg49UNT5SJ/jQfSEvLBvbnPwxSKj1oE7xkYkzUekMMP1AGYPEgsSF6rBv6cVfgvG7UppAgOwrBP8hW/fahVOmH8M8RGadCE3s X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: y2egscISRWqI5CxkO4FY1cBVRp5tnCWaRcksU8hJ34Uikw/fJHdz0pIScVTwggdLplfx8G8tFRU6oe7X6U5JtMb2Vmk3dNdg4RBVKDC66PVKKTd7JCTbMUWgNxh3+ex+boH0g5FQfCq7k7LcZwJB/w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b8bfffa-daee-4c35-17ae-08d96966d6dc X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:46.4135 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 10/25] avformat/utils: Make ff_compute_frame_duration() static 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: +zgWgCDm6WRQ Since 1c0885334dda9ee8652e60c586fa2e3674056586 ff_compute_frame_duration is only called from within utils.c and only for demuxers. So make it static and remove the code in it that deals with muxers. Signed-off-by: Andreas Rheinhardt --- libavformat/internal.h | 6 ------ libavformat/utils.c | 15 +++++++-------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index 002aeb6601..4fc1154b9d 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -715,12 +715,6 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, void ff_free_stream(AVFormatContext *s, AVStream *st); -/** - * Return the frame duration in seconds. Return 0 if not available. - */ -void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st, - AVCodecParserContext *pc, AVPacket *pkt); - unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id); enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag); diff --git a/libavformat/utils.c b/libavformat/utils.c index ad8e26d3a3..67a1d158b4 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -873,18 +873,18 @@ static int determinable_frame_size(AVCodecContext *avctx) /** * Return the frame duration in seconds. Return 0 if not available. */ -void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st, - AVCodecParserContext *pc, AVPacket *pkt) +static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, + AVStream *st, AVCodecParserContext *pc, + AVPacket *pkt) { - AVRational codec_framerate = s->iformat ? st->internal->avctx->framerate : - av_mul_q(av_inv_q(st->internal->avctx->time_base), (AVRational){1, st->internal->avctx->ticks_per_frame}); + AVRational codec_framerate = st->internal->avctx->framerate; int frame_size, sample_rate; *pnum = 0; *pden = 0; switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: - if (st->r_frame_rate.num && !pc && s->iformat) { + if (st->r_frame_rate.num && !pc) { *pnum = st->r_frame_rate.den; *pden = st->r_frame_rate.num; } else if (st->time_base.num * 1000LL > st->time_base.den) { @@ -898,7 +898,6 @@ void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStrea INT_MAX); if (pc && pc->repeat_pict) { - av_assert0(s->iformat); // this may be wrong for interlaced encoding but its not used for that case av_reduce(pnum, pden, (*pnum) * (1LL + pc->repeat_pict), (*pden), @@ -1225,7 +1224,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, duration = av_mul_q((AVRational) {pkt->duration, 1}, st->time_base); if (pkt->duration <= 0) { - ff_compute_frame_duration(s, &num, &den, st, pc, pkt); + compute_frame_duration(s, &num, &den, st, pc, pkt); if (den && num) { duration = (AVRational) {num, den}; pkt->duration = av_rescale_rnd(1, @@ -2761,7 +2760,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) (st->start_time != AV_NOPTS_VALUE || st->internal->first_dts != AV_NOPTS_VALUE)) { if (pkt->duration == 0) { - ff_compute_frame_duration(ic, &num, &den, st, st->internal->parser, pkt); + compute_frame_duration(ic, &num, &den, st, st->internal->parser, pkt); if (den && num) { pkt->duration = av_rescale_rnd(1, num * (int64_t) st->time_base.den, From patchwork Fri Aug 27 14:27:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29831 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1513479iov; Fri, 27 Aug 2021 07:29:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhU54R6ykHA+XPU/1g89ofYQvp420Oms8hWHOMROLGvh5twQUDJOYpq+DxLH+PvKt56LB0 X-Received: by 2002:aa7:da81:: with SMTP id q1mr10100632eds.29.1630074594293; Fri, 27 Aug 2021 07:29:54 -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 f5si6216643ejj.75.2021.08.27.07.29.53; Fri, 27 Aug 2021 07:29:54 -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=lTzlEiJP; 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 BD534680989; Fri, 27 Aug 2021 17:28:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074075.outbound.protection.outlook.com [40.92.74.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8DA3E680989 for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PpzeV/l68CMX3mv7Zewsz+Fe3vYYiULoTY1yw9qI7mSZ0jIV3dPE/NkAriD6rugw97Ni4sU3wOif55tzA/KvDeq+qA3Pr0Ws10TULgGBmI8jREmGMXgeuUtorUkMytg0nkR5Lraq8JprAGVXzQOxqyXhK54kwWoESCY0P2fVzRyrMuKsnVPYZxHohOvdF93yCdXQKUVc2O/2n8QihJFaiyY+7Z2t6bNJ3ufwqs/oY9G7KT1drvZviLrEeOjsDAEYj5uHrxLjJl+YT3ADW61kH5ee3hVFkK6wdEB5dpOSShSRCLJvW+YVFwZc/XJ4G44b82gPtuEr7y/Aky6wLBn2qA== 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=aDPD7HGHe4hnxeLLe9lGzADJK2SkeQ9z0mDSID/EbHo=; b=gIDgdeagsGJy15kHo/ihXKoSkSb2o4nT/u5UeY4x/rMJSZh7TOPM6ksgQHTleP+gXUvBPYpS7mmRMuiFdm9euoNKTCVg84H87cOwXrXaAIYf9deJX/LTBrElyNmJknJGMSzWdElowJGok+uNIjOE+vPtkEW//ber1/5QWO6N+E2eyPXhIx6d3jkUA2n5Yjj6kuLSKZFmqjDcno71czbY7OY2mZo2lURSDs5L31TM2E0giVeVlASpNeYCnC9IODJCHi1/C5c2U3H96o+sYFWBCHy9krEtadwiZq/Ecc3zqMmEfcKGlmlOrXYNSCuflsTN03XCVXXGzM7nkE1L02pBEA== 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=aDPD7HGHe4hnxeLLe9lGzADJK2SkeQ9z0mDSID/EbHo=; b=lTzlEiJPwUnau8nsXMUem9A6SLN0syvlIJHQwDBwZf55ehHCYUeYEJPPtWLXOdml8SPvgtRozkSA+eupkfwvyDWFTSx/Xqs4xcUA++CW1UGVzCVooFey3MchEo2r+AUtufJ+7R9psBh7PMWw27KLStgEH9c4hrsWxHG7EgKHbjeNvVQcjkEsuFWpIPEedRo+bMRDPk3jWxxkMT/s3CYJ/Mba19K37SER7du9DzmTuexD8T1b/zlEcBAAWLEDAdZDD/aY8UuoHA/4JBwP7kUHR5evmjUxxwPTUNpyWklzFO56D8w++m1qBoRtNaqemjXG8fMu33HXaFLo1ZzldX60qA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:47 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:47 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:11 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [Hx8UCaFKDxayCQQVE6jgZ/ifw/qv8Hgo] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-10-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5e0fa15b-0689-4087-9310-08d96966d778 X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEtNCKoPT6rtVE5PzvjguT+vyuTOS9J2m9anvmyPDbg+7xEAgZZvZ64oJ2t4HSpVpXreQCcQU2VqrimTbDhqIfL8zRpKhHTGEkA/vk1TANJnlMI/vOdJsr3CPqCPMP6gScj2eWSnrgjFj3BaAJSvWfQ+tCQabwUblZnGCaGZMi+tyBXWFdRX6fW/Ng+ZRXEaV56u83X0cHL8EdiEk7/yJqoJ+9WCkogPjHs6sNZGEHnzeOeczlVbQPeuiI6cqf/9rk9gNTAgc9A/pOyMzGByW0Lr6XAc/JolWPdusFbu1wkBPMcn7KpBXk9z6hNWwzQaQ057gw5uh4AjdkUu+aKYYdQv9lDzB0ycYc1WUAVsQ6OTrdqdTc80GxSjr9KijfdjeCP8oj4zElimL9LwKzCMiw1F/7WIWyjxoGCe7EErE3HuL13vuY++mAICDSluY+cWYGP0M3mz9FyW1+3frdOT8UXJ/QIdUM163OlZWX6fV6WTBtftB5gSRSRyq2D6jaJu9Sbnvk1evR/Z+T4sP3LR0zN7CtEiZcVeFMaCWrQThv8a5J9Z3si2JwnbRmHHQ3JWHQEtqZQ8LhP4HyZc008kxgM5adh0dxYvEV27WeFCKpoPFW0DLtbGd0NUdpBJL2ipkBqVl3Vu5a1j71l8C8xSw7V4vZqiH2Ionu/cGr5oMaB1KC/ysQibxJlw7iT471p2Bcif1ZvjomljhhLHbGkOCjS9qKukh9lj1t4kl/Vzvxns2/a+X9qo4Ji/Oik1D1WEJToZXn0Pa/+tKgxP01FQ1ec/ X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ldjK40rM05y2KLXNa8byLp1+opV6LhfZg511W+qEC6GljkiOxnakSshFkmTzY/ItkEBL9+uqWF8MeM2vIAFRo5qAJilGbLn0Wkv9aiPOx4fQ3XRRuAgr2mjK+3aYi63Eh/yBZZ8TQEYX9acAtTJ7iSq/p7m3SpvenAtDpk1qQoB3/S5PNeYKvhR0yAAf1L/CyZT3U4toxNb2FuCPXbDNwfvWKZXmPs6SC1qGZuR5pkaX7232L2YmITY53lq/DBCW0NxUyE99PhV81CBvQQXl7uM/gblnWueW7OAtz3EMAxJU6bDSNv92IvHp6mDRakLuyYAAnzlTob5QvHwBcUtuL1jmpWNRDzhhplSBLOE6zOd1lo0weeb9TiduN5tnlir+GlzV20bsQZuH/1LUbQe8A9+QRgkEiD++T4uhX/3at1bH9m1fQGcDOyIz98Gtt/x3 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zolyvrp1A6xENanEtBjxPx+3iphUnyZL/nkrZqZEvT634oeg73mr35eLXsXk+j/tAnCx5ItXaCxgnyYNTTexDh+6mi/aOi4A93Z9Z+jGfDEkidoiCeeztWkrXQtanBteXWmqmldpbFSwD5jZKZHIOA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e0fa15b-0689-4087-9310-08d96966d778 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:47.4659 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 11/25] avformat/mux: Don't access AVStream's internal AVCodecContext 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: YYVfyogqsINE An AVStream's internal AVCodecContext is pretty much unused for muxing: The only place where any of its fields are set is avformat_transfer_internal_stream_timing_info() where its time base is set based upon the desired output format. The max_b_frames field is never set at all, so don't read it in mux.c. Signed-off-by: Andreas Rheinhardt --- libavformat/mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 6fa1c5495b..b1ad0dd561 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -509,7 +509,7 @@ FF_DISABLE_DEPRECATION_WARNINGS //FIXME merge with compute_pkt_fields static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { - int delay = FFMAX(st->codecpar->video_delay, st->internal->avctx->max_b_frames > 0); + int delay = st->codecpar->video_delay; int i; int frame_size; From patchwork Fri Aug 27 14:27:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29829 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1513801iov; Fri, 27 Aug 2021 07:30:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxN0YO/upaqRLJV6kvUl5fpDvGHQZI8b+FOojxAExJCS+vNuFaCDu/d0ztuLp1zVlFE9COP X-Received: by 2002:a17:906:bfcc:: with SMTP id us12mr10120757ejb.428.1630074614102; Fri, 27 Aug 2021 07:30:14 -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 hc18si5711170ejc.461.2021.08.27.07.30.13; Fri, 27 Aug 2021 07:30:14 -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=Ggiy+qY6; 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 0F23868A5AB; Fri, 27 Aug 2021 17:28:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074082.outbound.protection.outlook.com [40.92.74.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E66868A2DE for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E15uMkD6c8vpBqTGc+KVj4Sr/mBKpiO9URoaQTppLSdco8m3EAcHNDy+5stYgWuxlL9fTEtHgECfQMZfslHlU1Z97zRAwUdHTbEb7jq0a2XeBBk+gKkO2VS6PUhUDr2YumbcNPPriHZH3/NSoUuUFUmd8F8LgVXEJFg3JxwCAlcR/G3QwT5+oYNfBVeDwYANWzY5/YRxazm1mzGduj7bG1n+XD5cZtHuxMyTequg6Pfigj5YBmDBwlTc4nqr2DR7PqqHNPoAsKD0t1TbexoAmWxdycCqCHR4ho+6fIcukrTeMuMvhWelZcmzfxWtKK5zF6u+oKtk/QSoo3P7qtdh/w== 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=8/uyzsu4W8X3l7+BWnCzFCnSpwhLolEJyrBZpvcsaBk=; b=Su3d8yVwtyiHOoiA3PbL5vR3+WvO0gOFWu04Wn4QzShM/84OAwTfMaYxmgMskhaT9bQJUvt6e8K96B7i5E12vW8R+HzMnRbE0rZgBBhyf1SAv+KB7O654Kpv5/MesKnDbkY5EKog8kHkSvm/DxHM3sUNs/H59MqD0tZQWxBtWotFM0rrgxBFiWmF4FBL6aEZEtPpG7uNHG6c7MtiYlgfDfAAebXeBEmFyl698Z/Vw+45/KjjyAPc0nWd0+yLCJA0luNii/jPiYimecHcgIjrbnxSMFTpEKI2oQNd/bAxifmn1RzVyjPnlKDKnc/R/IM1SVipUEkzEKAdrkvtOtRtMg== 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=8/uyzsu4W8X3l7+BWnCzFCnSpwhLolEJyrBZpvcsaBk=; b=Ggiy+qY6PaStQ2W97DfrpDhA9Ma2ock0D/ZpdUZuAf58+QlfaIwX6rMEY032PQbwDjrPHS1DGivIsJdcsubL+kKKyTgMBsMUNlwuHBNITnT8arw2Dfs69qmqscxAodQjy98BRQmb3+dMugXmEE2Q23pzL5SBH4mLZfS+u2a5gCHQtMFup9diwDEnj4j9XhZ2otwyUYHzvOLga7Mtzq2jgZdbIhW1cr7NS7hUogEofB3MSncp5vANkLCa8FjAS+9XFxFERkIUudr6CWUCfrS0JNn4fGlc4njSG5fpx7LWWcW7I4tEJMdjpOw0QyBjaUnq8nGh3djnkIP2k6mcyYXnfA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:48 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:48 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:12 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [A9KArUkkGBugf1uHO1lxBJrulseNRC/5] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-11-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c5dc974-6c6d-4680-b463-08d96966d824 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXOVIHST31EzKLNwg5cTLby/qUG710JpeCm92weNSdZusQCeXo89wKVccsEuY/1sDgjGk2rgX2W1dmorTplMAZ7oXleg2VEwVJkfp5GY3+eFFEp4NpMKPsgVw0lyUFk2sUl/aKDPwyat/PwsqmbLjNoIUtWisca0kiYF6yIqpvNx8TL/tUzo0ugtFa+5zrqAHMwlBUsKOEC4HMWSadQsNvbhb+X1l/ALTuTAZX0zpdqekX2LTWrPGSc7uuKOB//KPKfeRi82xvgEapzL6nA2rijqQLRdzj2HxC2tLz2YXctTmHEIGS4veh7JfZSzBi5FBu00XeDWNMS2ybl4sWgG1aYwJtLyzWP5MqmVzSaWJqdJKdtSJGa5rOhYJxqWf9zm8y/MPkvDpiMidfVoca+0GPpv8QbEvXaMnqQogf+FzmQc3L00j6lr/G3WXBJ1Gn3v1yYCOT02JsRW1RmAxcg+UCuwoXsBFtQ96YdAOC43eeb1HONFmqIvwWQV0hGbui+NXsRP8XPNNoQ1KUEzC7wdMn/lpZOu9xvas/xAFqCXhYE4DV7kWECIVTtkHbNjixS3GnrKw1PLsce6ZTzKlWbgljPIZr8p1odjOAhCzQ07+R0ZoEoeYO8f77CCBXIKzb4cNvUQ5My0M5wyOTh3hOgDIseiTfFvulAr8bHUpp0T0zCLZPo72Dez36qMldpt/BZxUNV+zWIWUcf1XDx2cWtxFVeWXZrw68oOS8= X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MR+i3TLQ9GKmkzfv4x7PPFC7Cvc9WKiwXZjz5oWEncrRuoloccxm6eBxE7y/O+mT2m1yb2yWKtsW0+4zfYOCsYnpYStWiNBYiCW6IICj/Ql438lCX+wakxaaFwILjtZNLmVf4EtAP/NdLQOQwpaGFHMEfddBwkdG+G9pWM7uiKRFhVhIEx+6GiSup0pIo4K+j11AEXJFgr6dC9QEeYirBrpchM5b2NuD/s5DTm96oQam9s6+u/OyOKE2fn2rr+FjQKgIBmifzohZb2WSRUHnYOzGYTKUKnsnHze5iwA5dFj4xH70sIm1QemMyiGSgs1tfqUR7CvQsnJAcU1IGSPnjUKcKN8VxWQvUOqBamaqapPfE06J2LvFJXE1SBqD2UNoGe8D8//f9CsHu3tGf4FIW9jMq8w5vIow+shrE+fK/aZZSWJkTPPkHGHQ/L6ZvB+O X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7MN84XGM7bEVDzVUWvHEVclD+qtVl26Ia33o5Kbvl+C3X6O7D3VCxOaahoQ5d10/9uIXHvc3a9Q1Sci4rk5sRIZTjYYUVLCc30Ac20Y8rKzz5l6r2TmC+1/5etH9OhLhpmGBCWQx0N+Ar4uuh9ZAdA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c5dc974-6c6d-4680-b463-08d96966d824 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:48.5959 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 12/25] avformat/utils: Remove redundant flushing of packet queue 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: Ya/qh6bAF9rg The packet queue is already flushed in avformat_free_context() which is called a few lines below. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 67a1d158b4..79fa9382cf 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4340,8 +4340,6 @@ void avformat_close_input(AVFormatContext **ps) (s->flags & AVFMT_FLAG_CUSTOM_IO)) pb = NULL; - flush_packet_queue(s); - if (s->iformat) if (s->iformat->read_close) s->iformat->read_close(s); From patchwork Fri Aug 27 14:27:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29821 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1514066iov; Fri, 27 Aug 2021 07:30:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwujFOVv3Z6CnWFwD3f59wk9z9ZRS6yQY3i42oV0nz4b5opiPFcwnK5PlZzVNwlzFqLT+CL X-Received: by 2002:a17:906:2441:: with SMTP id a1mr10462424ejb.550.1630074635180; Fri, 27 Aug 2021 07:30:35 -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 s23si7126655eds.407.2021.08.27.07.30.34; Fri, 27 Aug 2021 07:30:35 -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=t11Tzuj0; 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 21B6568A5BE; Fri, 27 Aug 2021 17:28:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074075.outbound.protection.outlook.com [40.92.74.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B42B568A3F4 for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QbohqpNmXAHfKZpwpdWEmv/jVIZwUJQ/SZLkNLGZcLRMnzJWrtUIr4eBSjyBIVkePj802anvYFCbrrLC6KuSw+oqczTal9OGr4Fm9uxvTKl2mAxhxTviZ+Rh8u36lgdy8OE6MxdSiDRtMHiF34B3EcAsbJOEIshljqhkIPkL6lAU3SajCO/PHZWRhzhTPsi10W/Ukjj2UTAtvjMdNDjbKfJWSa1S85BWIBK0dCJB450wT1RI+HozbVexIz86gojhl0Gamja2stbRi8q4mZzzPt246ojbBc3AuxnTQ2/X4/pn41mB+HdUXM7ZIN29J8V6CgBvTIGJ/WYTKDRWkHNqgw== 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=RcMoW9rqdZuVTSUomNGx9Tp/QqmN/AabTqHHpOExMSE=; b=AoYaljM3TeSM3Xi88I4XaM9g9AiP2igFv97WXAQnqB2NO1hoNeyTIUIq/7eYBXufSkl2VHRJwAOHScLlkN3OKMJYXgQXWdfFa8SLeb5bewb0AnyVH6IDph2qvHOP7kx4hpv///4i9nk0J8H5YtnhPeyeVacVAImwlPVkK+fpph8Bg+2ZH63Z73RT/pHxkoEQn4KPPNlwu9sQuIhqIwYvE5nnfDwS2CU6eMiFuTkfEXs4046NI5xuQFYhsvSMRYuIIcZAOhl0YUwSOYHgoC8DR2sX9G6wNXNcB1MJiC/fC0GQsNguQwqKUsd3bXCTPHUOGToB+Eu1mQN/F7ra66wuCg== 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=RcMoW9rqdZuVTSUomNGx9Tp/QqmN/AabTqHHpOExMSE=; b=t11Tzuj07XAyi1iQyNkYN9TGORK6q6EwUSIWRj/P+p361mlhnBGFOPMDPTXVLP9JlU/W6ah/yLOzcpRKNwrTacTwn0cSRspYYvvIzTkG3Qi/vP/M9S7HaU67paHhl8ILTHe5lCIAGxSVq0l2bUO3zyQpb9IPQIgmrxK9e2zGQktt6WiRob/kmfKru6d097t2RxCtrqx76WSq0Cr9Sr4ZqlfZS43qQLTO2eZJcgAMUhcD7ygMSexHClrqpV8tqsuB7AuZSJDpkizFMxrYTJTuCn1yWd8Hp4IMJydUaZeXHK0Tu4XRYhS4mZldmB6McDZGjMj/indpinhz7J0Vs8RRVw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:50 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:50 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:13 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [QRnmMy8mUhHoY2GCyUUTCrZOGAs1lW72] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-12-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 50f6f32f-30ef-42d5-02fc-08d96966d8cf X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEtNCKoPT6rtVE5PzvjguT+vFc6wRHKZk4Shhw2G4KCyyNcii+M08wXIZh0Z8br/EjnIiICSWyfft55fw0NjKH/d+fGeGDL0kiiaxwRt8Gno4aqcSbg+mijeqCGHAGlfhzDlSMUXMicYONMEW1z2ftM9fIlYN1frckCMUahb0lU0YXMVe2MuVex4jvJC6auROzFQ4qNn65qPgV1Ndmga+pqg4y5LNksnGbVK91cHYxJqL70d7TYWceCoDRWa3fb/DzpaS86pQmU9TaBfJBePFZXLWCpaWPgiIDuBxysplFIyQ5v0fzqYk1JTBCnkPGdbZ6bnBpMFeDpx13BrmnHsQbLubPCl84X2JaxwuDKOTkqphAfUTWcbBrdojN02g0MNwyMeyeXBk3tO+rST/GyK1Ur3KvgIpAcNI0ePbflVJ4ZioSPllWXCo0oFr8XZMSzIfsOakwDJcEIIarYRDl/LjdNQdaZbUDTCMYGTfWqXjv/bg9G+hr8E+8UHVLnrLrxRsCJBUrN2DkBeMstLe7gSDjr/Qq6NoKyAIYJtAL15iUrCE2qQcQQZkkVf65wKcKZ4DaZluWUbCzuiMSqMC/lW4iULyXv2MLA8Sy8PZof/0gV1CKP9m8uU4c2kUcoKmQmSjof9LTJLfh5+Zpu0jgVYmvVdusxPONPVla30zefu0MClrgADbXFWfZsKaYMWOtB2DWNexpLCB4DWTZepmtgp/K9fP+vncDKhp9BDXIBza5dv9jVsKc7PqE2d/45C0cRd3gluAkuY+4VI9xmrCA/aCkVi X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1+qFxyA0vt35gDRDMu57Iy1Gs2/vjt47JRfHmFcQvWXPArab81iCy4ffJmK0jmlcLpSas/2qjGSKE5xnmWYEPQnivGVbrcvsu951z/R2BYmHVonpKKuIMCJ/iGDadrY/0cI7eI/bxp7OXfCgW/4P0hY2X4+QOhn1Eyh8SPnQdNaLn9FFYcxifkwC1tLyYlluMyV/e6FyqOVESzAMwMdwGQbw3Hpg/LWN7NDQawcuOifEY5d2s8RErDbchSiaq4SCnOBEPt0ChBaHRuCZOaTXKFahSyrzpn+2o5vhgIkyxfbiVUtVqZjix41+EbNfp9EdGL04zifmu69N8CvIZRimgoyUPZUrqM8j+/MnUp8zbl5+KhgV14BhT/oD2h5aJyR5gfUJufhZ9LfAlQUOajW7IEGVuMhiRd/o6O2soIbXKSYgS1NMDjpF7kFtgX+qbRTM X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mtWaiEQA0EcbZCvR1HpGDurWWQGqp9P/+TMgtdjhyEZWsmp9D5XW+wh6KofqG7bdiJt/+bVyGseaiQ0RXCPZlmhIVxi9Q7uxP4w9FUzAstL1DTX71ozY/7Ya5sOO2HPIhGWH45dMTV5jv5mhrYdWpA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50f6f32f-30ef-42d5-02fc-08d96966d8cf X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:49.9401 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 13/25] avformat/utils: Don't initialize AVStreamInternal.info multiple times 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: INSpl7jMq2oM It has been allocated and initialized in avformat_find_stream_info() until fd0368e7ca35e2feaf7960564e61a76655c4d1f6 when the structure was moved to AVStreamInternal and its allocation to avformat_new_stream. In order to also initialize the struct for new streams that only get created during avformat_find_stream_info() said the initialization has been added to avformat_new_stream() later. Due to the Libav-FFmpeg split this has been done twice: In 4cda8aa1c5bc58f8a7f53a21a19b03e7379bbcdc and in 30c26c2442e4e44ac5a763c23c4b0fdd9921a7f5. The initialization in avformat_find_stream_info() has not been removed at all despite being redundant. This commit removes it and the duplicated initialization in avformat_new_stream(). Signed-off-by: Andreas Rheinhardt --- a) avformat_find_stream_info() frees this info field; this implies that calling it again leads to crashes. Moreover, I am not even certain that the calls to ff_rfps_add_frame() that the mov demuxer performs are safe (i.e. happen before any call to avformat_find_stream_info()). b) That info structure should have a proper type to simplify the many 'st->internal->info'. libavformat/utils.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 79fa9382cf..8cbe2a0278 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3624,14 +3624,6 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) av_dict_free(&thread_opt); } - for (i = 0; i < ic->nb_streams; i++) { -#if FF_API_R_FRAME_RATE - ic->streams[i]->internal->info->last_dts = AV_NOPTS_VALUE; -#endif - ic->streams[i]->internal->info->fps_first_dts = AV_NOPTS_VALUE; - ic->streams[i]->internal->info->fps_last_dts = AV_NOPTS_VALUE; - } - read_size = 0; for (;;) { const AVPacket *pkt; @@ -4379,7 +4371,6 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) st->internal->info = av_mallocz(sizeof(*st->internal->info)); if (!st->internal->info) goto fail; - st->internal->info->last_dts = AV_NOPTS_VALUE; st->codecpar = avcodec_parameters_alloc(); if (!st->codecpar) From patchwork Fri Aug 27 14:27:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29826 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1513922iov; Fri, 27 Aug 2021 07:30:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmUv20DblTyRPsjM9Jd3sbZSlAjITpx2ZIsGDliGrvNogu4cqY7pcbi4T27dGJuNCejXqY X-Received: by 2002:a17:907:1dcf:: with SMTP id og15mr10075261ejc.470.1630074624569; Fri, 27 Aug 2021 07:30:24 -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 g18si6069956eds.512.2021.08.27.07.30.24; Fri, 27 Aug 2021 07:30:24 -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=h6eeouxD; 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 04D8068A569; Fri, 27 Aug 2021 17:28:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074082.outbound.protection.outlook.com [40.92.74.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B4EB568A408 for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AF8093QyX5kfSqi6fT4QL8GSMwiHQ2BIRsP5CD186i7c2szF8/jWHGEkyJPNnUgjD+EnVhNrCEjE8saDA9F9q4wSN4xqChcxPemx5NPH+nE38zmCcc6x3tx5eijUPvPesPFHAkCr93vvLM1dNNRrsgMFXpVt4Y1fUQYkU7o3pRELYmJeDXM1PQQ+L+HYxyIkwHsELrXlRQkhLlcMCCdtyQidJCK0hlVZLhvz/ftK12q+HWehcXX1vJ+uCasi1SLxxilJ8e6UtQxEKDQuWhqHqeLXwZCFYDuk+eVATD5StciyWE6C3pym5HkSI4YrdO5er1KxuGApg03jK651MUR8gw== 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=VGeFSj6pHjYleE6eZG7oHpqPvDLGArlM3/63+lG1iTE=; b=UC4QU+MR58gdkTi/mgGG1XuR1xAK3aZIeKZ3On2h3ThIeDk+hINQ7YFIf18vlwwWQeFx8r227nkNyP7s3TzU8d/wkOBRW1tou3jT4t0Tp0nrH3YTIPu25c2pBV74SfrJKPR4WxqKWEDt+1CSKxw/NaE+GjMqM/zlgNBHQluZPqs09e6kNqST7Q1haE/dgOwtFw1qutjbL7J0eQ3qwc277BtK5crI3RgwOhVBLfwSmArTFbk1y/y6Sl8oRIMgz048jerqdQlAsZGWdTUB2bLClewBIfNHfHFUW32BSBfAXoJI3aomPX3+xHraAke33/AnphPkc38OUiYxnIx5KwfAgg== 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=VGeFSj6pHjYleE6eZG7oHpqPvDLGArlM3/63+lG1iTE=; b=h6eeouxD3es+uO1QVnTxHD0dHh/0InAxMdXlTbDvn+FbzcGgDHPSl12Lzz0yQp54DLXvprYxLZ53Vuxq3ONvpGBiw5I5+5vVXjjdLKa+L32w1kAR+u8gL9mttqOf6O4OjDXO64mqs6S++xaaZUty3KOW7riiYorseJBHVrMShiCUrbcvD1bo0dA+EpZvMVZx+1EjNMpjaJT/seYXtp34u3YXkLDb1TH6mLK/QawOotnFgNDnyoIR06dgmnkgHunyr3sNxQKtBquXiUVkt3xc11GSUpXSzN2fTkZ9gEJjL2tAfYoJexRCfvketAHlBdIayhcOqn+e/jtsdEUm5z0rPQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3687.eurprd03.prod.outlook.com (2603:10a6:209:30::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 27 Aug 2021 14:27:51 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:51 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:14 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [bbGiBhXqS3c/DWhNYkXZm56Al8/QPwCB] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-13-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:51 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3aaf0f2b-eb01-44b8-4b00-08d96966da0d X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7h4qpQ6owituG0lcXzi5lqvZnwPRtP3V3P3B0SClef5WJ3oDFMw4H2WEZUM743lAGDjjtuzZLJFlaj/33k4yFMDngsun7cRYGTgVeN2YfNdLBubTejn6agSKFFGdOL2oBmYShb/yGKVhseLp7oLhaD56fcG57FTQiwie8CgiLm3sgQ3cb81PUOS2ztPT7IPbJSBiAWtl71fwcjp+p2TaH4GTRg9fiptBzn8XU/m7PXWVc/dmaXxK0j69qF1sb7q/6urXyLntmx160SksuhiimFUt+MyomRryXdEfa0tx/An0PdXgKzRtIWJhU/ru/Mi84swjluPdoCByCl/ZsLNX4CIJpqUffH3MZOkBhCEIsGWekzptrGaBO74PKyMqyzowf2y0mfQ6TPx4yZPS5FrcZhCkpiSut8tW5H0VHy+iGRAvV5gJf+pBgwbtfB+DV1e58Wrm++FRuBXaLg0EFPFOBfZvfSVM26BGruiCGHBu8a/a6rkTcLfoIb/2dUbhiFF3vUjHvBnXfIyQD5tZvoWOydMUJQVq3NADNKBxV1cRs42cMK9jP8X0zdy5Eaa5vTmYHUj6rqrFLh9C2V57D9Jog5KGaPh6B2wL1cG0qNM++GparBW6CtPw08O/NZgU+B5lUcK7UKRPsbzp4vYFDUBx1stAb/3YKl2bVkNC7QPGppZyf7b+iOFr/pW7pILAE7USYt4r8sxO7utRBJKvCRyPnrYZeNH3TkxQ8LgEzV26m0o4= X-MS-TrafficTypeDiagnostic: AM6PR03MB3687: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DJA89/na5SNHOjwv+sKG9ljnFebFry6QaumG7npFIZCqsVK7kM1bt0zJ2itT4BSzuLTX0tfCv2QBtUZeWZhA0GFrOodoraaKIlOhaS1gU0YML+hvDBPTHrS6T93FAPnWZiCIjqaqTuzjXbAFKh96joS4JG55mc4vEiW7hmJv9CJE3nfliqgE4b0DldLfYOeZJ/Ak8qP4pfb5JU2bo8nOmAc8cwD/rHMj1IPHQ3gS/VSrhX942B20fYRT8skYRYT84PfEFmikDayyrpNSsV00HKkmUyXTwEYUpm/NmrOkb4jiMP0XUU0GQIlTl8UD3wl1ipKnCWlqu9SUNYNfqQ9B3M+OKIm20X1ECluhTY7kxwIson4YGeWJGNUL5X2Wux39uD8hcdiiNpwpyR1gxQCHBAyJ5y5hMuSsuQYNT3WrbC1ffsVvb1Jak7MwqAebsL2L X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2XSkC7lehm5sQ6vfnRcILoaibIIRduUFzSCk79Wi5yQu59Oalms4PeMt9RIhipMpzavgEWCX5LC+ztq82F478d1qlsWw4HdbxsBA9/VT07RfuNGA5Vusn09SsKCtre5J/CWWwGqjnf/zalcH5fZBEw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3aaf0f2b-eb01-44b8-4b00-08d96966da0d X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:51.7741 (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: AM6PR03MB3687 Subject: [FFmpeg-devel] [PATCH 14/25] avformat/utils: Only allocate FFStream.info for input streams 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: ZjzhCxR+ydh3 This structure is only used for demuxers (mostly in avformat_find_stream_info()), so only allocate it for them. Signed-off-by: Andreas Rheinhardt --- Yes, when demuxing this structure was freed in avformat_find_stream_info(), but for muxers it was always kept. libavformat/utils.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 8cbe2a0278..78bfb36cd0 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4368,10 +4368,6 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) if (!st->internal) goto fail; - st->internal->info = av_mallocz(sizeof(*st->internal->info)); - if (!st->internal->info) - goto fail; - st->codecpar = avcodec_parameters_alloc(); if (!st->codecpar) goto fail; @@ -4381,6 +4377,16 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) goto fail; if (s->iformat) { + st->internal->info = av_mallocz(sizeof(*st->internal->info)); + if (!st->internal->info) + goto fail; + +#if FF_API_R_FRAME_RATE + st->internal->info->last_dts = AV_NOPTS_VALUE; +#endif + st->internal->info->fps_first_dts = AV_NOPTS_VALUE; + st->internal->info->fps_last_dts = AV_NOPTS_VALUE; + /* default pts setting is MPEG-like */ avpriv_set_pts_info(st, 33, 1, 90000); /* we set the current DTS to 0 so that formats without any timestamps @@ -4407,12 +4413,6 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) st->sample_aspect_ratio = (AVRational) { 0, 1 }; -#if FF_API_R_FRAME_RATE - st->internal->info->last_dts = AV_NOPTS_VALUE; -#endif - st->internal->info->fps_first_dts = AV_NOPTS_VALUE; - st->internal->info->fps_last_dts = AV_NOPTS_VALUE; - st->internal->inject_global_side_data = s->internal->inject_global_side_data; st->internal->need_context_update = 1; From patchwork Fri Aug 27 14:27:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29813 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1512641iov; Fri, 27 Aug 2021 07:28:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy//wZeE+tPghbkynrLfxWxfk0d7f5lYLCIen01W+eKSwzVpdsnTIQW/5w6DD8w3L/mq9Pd X-Received: by 2002:a17:906:60c2:: with SMTP id f2mr10285776ejk.531.1630074528478; Fri, 27 Aug 2021 07:28:48 -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 hq41si561243ejc.559.2021.08.27.07.28.47; Fri, 27 Aug 2021 07:28:48 -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=ITPrBME6; 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 2C128689902; Fri, 27 Aug 2021 17:28:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064097.outbound.protection.outlook.com [40.92.64.97]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E51A680A2C for ; Fri, 27 Aug 2021 17:27:54 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EVSs25KGLBRLdvv5JEHXcMN+0kuGJ6/R90BlYQL1NsByn6JbSYY5mZ8qZ/Oq4qYd4xDxqMguXhlkSIqROqHvaR/46pk99W9qIGvvkp2pTQmeVM664Wn/rtZOblKTGc0VX6sOMVzNyDOAszZykjmG99/yWhwdEZv6rt6ZyySDVyXA3FAR33RaXSwugIrl2k0sUEgIlTJmAjxaRaF4IzNCmIwIeEcreXSM9vpNPElA3JDwrkltifLUGMK1+iIuMGU3JieuMHzGH2W4WaxJNWGb6HjQ2vM4wwh+UstFVI3ZBmVp0NzxvGhDdAN7VkDgToqxl6Me4nJSPiNktJpCSv6P4Q== 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=Chw7dNZK8fk7hb3yu4yhznwhOyho+thQ422rhTYj+B4=; b=Wfj5EQOnDMCiW5Paa69xA66Gk8AfSkU+6n1VZ6K711W040XqIYEFXy0V7qEguSOPgeYtnIMbYmTQbyot1bFEKCsyzVyqPUCF07xRbc0KdXK9poCwJzizrHpBYPv2peG9IZRisl+cGU5DtCGARzGE5lAHv843BPJH/N6mqHr+GGyU2CVI4VX7CxnY81n1RlQyUyI4hBhtcrMhJLCjJKQme3Gf51yUdh1NMPvYA+iieUrXUmQlIE2vrCTyU3C6jPUz/stsOLuGP7I4sVNeI1ZhOWT+UO9YwZET/TG5BgO0XbGIg84lH1WYnxS0zlrS+4MvTwCm6C+dNMgtF0Cku4X+aQ== 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=Chw7dNZK8fk7hb3yu4yhznwhOyho+thQ422rhTYj+B4=; b=ITPrBME6e+lWYekbYBK8xdYGyz+l7SXzVe7Y72E5SEwyWOHyUVNS24naA5TxeUMi/TYPYAOwlAEK2Mk+YpuO5lxnHMy84ycw9CMe4foJfMUokyFD7nLaHu6AhVna25A8xiiBt9Y1fJj8InaHLWs9I6qQx3Wps1MWmwHlbsaDhn18VOT6HL4jVuk7JH+YA86cQBNMid5bsYnE4VT1WYK9u0YTzL87hw8sdW8sKXWeLNppQCnuUF3Et4GfBh5Bfn6jiHzuJTDHWEJUy4DgXLOyoHv+iKt25ux/onaLRxae0aZZvv+3n1nBFRGWIaOdwf8/SNaR5yN7e6dVYWZ05mZdCw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4824.eurprd03.prod.outlook.com (2603:10a6:20b:84::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.18; Fri, 27 Aug 2021 14:27:53 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:53 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:15 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [xKrM5uUCbHyy17XhjAql3Dm3xBcDVY6z] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-14-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7dc92044-0e50-4755-28e4-08d96966dac8 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7iZebmMqkgQEARHlsADHjZ7ZrZ/JtFaBqvnksp8FZEXxvQq/EQFjbMBH86ls2lrI+RPrzketv7LKpf0XvyifxQhWkZOWdrbe+NU7Fc3FT6nTazK1Daevl+4Bk/iJ3U+MEk5ZtdBH0cEDTN+eZQmE9ycdnv++HtAOrE8kmJNp2QenMinW5JZrOxUwjLMeB9T1YWVKtlESKhLECP0ep3M6hGJ4DpaP0W21UxbtrsaV5Z/99bcJCjk4SDsR8osB/MwSdP4BHR6Ha6lQDI6PRSlW6PdRWgI1HAZWhInA5upCDhIY/Vc3Coy5X5PDykQbdURvoONOlkh/GcEJkWuyuHSNlMCoPqYx74Q/ytndRmECbYLe8AnmeB2XhxyR2vRM7yLobNIWnqZFu8kf358W+rhUEWAv1CBROs6PcI5jjC4O1dqmW/m7rNpRhwlweMFpzFgYLgoI9vDHBcIubBWg1ZRV5dOzJl9oiNJozRYJfDyClrYnnchVZ4HESe/Xt8jGspvUnhImRz0cHUYLi7JriXmO5dvPRgU5aNKgW+M1FDuJ7ZOyOt24Q29KrPKcJMWMGxpknBRFXR1PDZxCuY8vcuWfSqE454ZzS60u56nKsDfQcEHvFDQYm8CFNgDXaBsWK/mPPdudgwSoh0W2aQ7nFkfxlL0acCeDXWawSvVL+ZJwJ0gg5rXsHY8uEmLnSKfBYM8CTGg2JER/s8hHC4x405nJQbDfEhh3CeI+5odpSkNbDhsU= X-MS-TrafficTypeDiagnostic: AM6PR03MB4824: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nkPQxP+bo1l/4un7ZuBIWx4VAAz1B/1LAyWRRimUiJefLDhYzBDcWATi8RfOU1ujYurK8sqt8qXQuO+zc4RxUeJY7FcdU8MPa2C4SKyAS61G5uY9+3Uev5Oqki12zYICei6jnIaHhxS+t4asNiyAXxddNMeY7xglxZ4vBWaWnqi4yeDNzcMW66AeDEAF/tK5qf9Pm5krAWb4KLZq4SNUmh8dX4nWF/OsLZuItzkZGLZ/8WfsNkI6bdEKmyByQlisqWxd8jS57SAvOQeG83OLyZI4qDz+wytkfXPbN7xvlO52XTQD/ptrFICNmP6yCwyb1MTHssm2K9rVYvv8JiOZCKrTzo1j0j5QqcecdrRRGru+U4YAEJjYx8iJTRbj1wXSkrcQ/2sEuewHvXe+DnQAsI8jIBdAnbhd5Amk7rMUplN9HjJl8WMZyNhlJ6B810q8 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CpUQnJNrVC0oU1GNCLGyqAA+FYB8ABR9p0OTNgPSotO0LwDc4Vzw3R/BwLjJkLJi6JN2E+yz+UiEDzft5VfbM4XYqphFuS0/UG97TrY1sDdUIEAzOWoguGOR75AettzvGYFQ/UWgmpS7roAvsl/cdw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7dc92044-0e50-4755-28e4-08d96966dac8 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:53.0097 (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: AM6PR03MB4824 Subject: [FFmpeg-devel] [PATCH 15/25] avformat/utils: Don't compare pointers when sorting chapters 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: IWfRrXE6UofW The chapters are independently allocated, so that comparing the pointers is undefined behaviour. Furthermore, its result is not platform-independent (and may not even be deterministic on a particular platform). So compare the chapters' ids instead. (avpriv_new_chapter() ensures that there are no duplicate ids.) Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 78bfb36cd0..264b5b1a4b 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3160,7 +3160,7 @@ static int chapter_start_cmp(const void *p1, const void *p2) int delta = av_compare_ts(ch1->start, ch1->time_base, ch2->start, ch2->time_base); if (delta) return delta; - return (ch1 > ch2) - (ch1 < ch2); + return FFDIFFSIGN(ch1->id, ch2->id); } static int compute_chapters_end(AVFormatContext *s) From patchwork Fri Aug 27 14:27:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29832 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1513047iov; Fri, 27 Aug 2021 07:29:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8750VpMvRSwAAaKwY7nujqe1baZ9QxpHJWpoh+2OAqUFEvl7he7fzibLaYsPSoFmcgfSH X-Received: by 2002:a17:906:fc7:: with SMTP id c7mr9554840ejk.333.1630074561051; Fri, 27 Aug 2021 07:29:21 -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 cw19si5613903ejc.744.2021.08.27.07.29.20; Fri, 27 Aug 2021 07:29:21 -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=bhgZ+IJz; 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 C3CF868A543; Fri, 27 Aug 2021 17:28:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064097.outbound.protection.outlook.com [40.92.64.97]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5F9E4680A2C for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E4vVgVMKLLjzxQ6D9cV0L962+hH8cYnSmGOcmRw0tzbVus3Ih/L5UvOR+oetqmVlYuKcIy6HWuqZQ6vAeRUtS9o+6X+z4MnQXVFeXlldFTYCYmYKVUsCVVzbsa/0KP9HFPAYIkxOCkXpR8jyj0Jub4yUPdOT8q/Uc//XMr6a1YQd/n6TL/1132IKv5GqOhiVs/1t0zesZU/3XzczLvZwpSonkBYlnjAcqx8vs+RjC5qECGOgxgU1PpX3qgVeLcb95km3m1M1I6fn9rGxSMaV9SBBhfQrsXHD1dGdtNHe3wuT+aW89vI0mxGtKgCpfdNPKoqdQZ3JQTNPC6sS1PNQyA== 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=4kB2Cecxn6KymE6HUEVhHJiCI/ZG9UVHURAS6eQ/PcM=; b=nGyUxFLb+h5JzXB9x8VAndJgzzgKs2X9hqnhOjaDeJCbwMz6wUMJGSqA5ECDjKoVyK68IN4Wai56NqxVMryNFX45IGmllqgM0+LbrF1+E5WOJ41SrxG2mC0Qlh5i4v1/GzZYXYvClK5QgIg9IhIILsbP5k981M+lhmMDTo4MM5ExJ6mIlehwWqUEAs9ohrUTSi+YS3UfmcU6h0rVBzWGP8gXBkcw5A+m7DGD/WP1tJuDaQL0HwHBJgJEa343akFpXEImHasucf/qfndly4UaivCWlTubbfVQo+NV2F+o1ZgkuriJe8tKGpFlyOfY7rt3wJltAYi81bTPzq5jpbpoQw== 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=4kB2Cecxn6KymE6HUEVhHJiCI/ZG9UVHURAS6eQ/PcM=; b=bhgZ+IJzL8zTUVymxk0FxVXp5b7Hgq2YF8cj9HsDGopc52atEIQmqIFmc1LyJI2Xk6/vOxxIa/rt9a+lxDLHL6/Nd6uldN8KZD4d78HRZbviw+VXiABWmzQpzN1a5WZGJ0QWjJHXHnlQGeCLSag+gttPO3yYVmAV0SF5r481J0g8kK2v9HZvNzoOcjKYe9u0pSxF6EQ+QsyMX/S2NxLm1sGOsWOe74LgGnrWNUoZOLlQLB4BbGC5+vQr2d31GyyI9JcYnajQ/1FgkC6SkVcERRoNDyTDQWmsjvPiihPOsA9h35DJARAxL/Js4EqOzkiElK/mq7w0wgMIlJHT96F5AQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4824.eurprd03.prod.outlook.com (2603:10a6:20b:84::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.18; Fri, 27 Aug 2021 14:27:54 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:54 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:16 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [sWYAqKD/bdESlmY/XBa+70Cd6Q5uIZFT] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-15-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8ba3f6a0-d647-4c0d-c8c6-08d96966db77 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7etJttnuGdjbkUGf+YuOYZpthbYvs/PXyV9izpIB8XVrOyJe1RRXAghNOObQWqrNg/ZnfIt662fkPI320Sn+Y3g5GiUmxVuJAGH91D6aOTGA7W6uLpEklNks3g+vUVjOe23Ia7ej9gwMK5ypyMIK0AhVUD7uFIKT46vI16fS9Y7rqaWo6nfriC6XTA7SRw1h+zLt1JZXQwMlSSMA/8iYAC4nnxJXjeehb9jTWfcS6/hK5lyyBV4pUQgjofF7+VFNMLVLNBuHJn2aZqLKdnqwAI5bW+VFpESePVq8i4PUiTNKNbleJFpuCuLBegDAP/C9Zjyxz0SRh+2DaTg275Q6Ed1if0zMJ1SQ3V7Kf5z4oNiyNUO80i0d428Uht6gj5fdBsENu69/DZZgP4y128sxuLm4K9aYS/ljaNBYLC28LnWfqur1bQaxGvK7g8QUNZI3Bu1t7ApAAEuqw4FVrywyJy9W9m5zEEmPTylJGLo6HBobAASgXC1jSvX4D4R+ID0qCIe1wI6Efk/+R/sTH2dvF3G87d8vLeS86foJIuFb5B5V5+Wd+oV1mcjt91TqrLbl8tE38Pal/MWPe79GPkq1RVaHfcaoCMdRKHexL/PG5A254/oxdHVG/wzjUPW7IjQF1wv9eaNS/Yl/rD5Zt4b/yTRvohBJu/3AijAYino0gOtz5hYOiSboCiKkuhHpx1yFEkDKxpdKqKKdp9RfLhAULNjSSmfYYfdOTRQMMLb8U/B0= X-MS-TrafficTypeDiagnostic: AM6PR03MB4824: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m9n2UmbdX5q59pNP4I93sDuQQHrhinZ8FuzGEXRMLM4SxPKLt2+FFjJ1GOocgIXBCtq2Lnmhg+ebvTc1NiMn+V+lbJp9MsVU/a5iROoJEsiWuZsSZYlmP554oLZ7aRLrFr+UGuuEtCSSnLPfCoZNJWbeb1xrkyv+mK14Xc4SWEUGO0fbepwTH/QzH5BSX41vLejjeCfb6v7dJ/MnICotv9BbeMJu288WzoL+1iLBUD1EZqgLqziP7COj1M+YR/vlsgiuQzH3aO15MuyoDl1KXc63ItJGuCfWphLya0vNdHvA4Xx1X4Uw7LN5ppoAoUmZz+I5NCYacMoHjdXJw3H1Wc8mVlhHam3K5BqHnvtlJ6b29Y8eA8yLqqLtL4jefFZAi2jquMepVUWk/q1m7u27M/81Nb3UC3+eRQ3I1kiAtahswHE4qMhnrJHJgj6IHFgl X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 42VM4OLI2+25Ry0iLANuK4oef+eiwPkojSbfs8oLSlmJte87vUsIzdvmpSccnyLOrYuI/W6Hkf/nz7DgRM+PqwUy+UZFkTgh3Z47zyYZz/d8b0eEDy7WM43qkf1eG0zDgLHza4N4jiAgnfSwHRVHEQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ba3f6a0-d647-4c0d-c8c6-08d96966db77 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:54.1497 (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: AM6PR03MB4824 Subject: [FFmpeg-devel] [PATCH 16/25] avformat/utils: Don't allocate zero-sized array 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: FTalo3f9/IZA It is unnecessary and also ill-defined: av_malloc() returns a 1-byte block of memory in this case, but this is not documented. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 264b5b1a4b..b3ff9e95eb 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3167,15 +3167,19 @@ static int compute_chapters_end(AVFormatContext *s) { unsigned int i; int64_t max_time = 0; - AVChapter **timetable = av_malloc(s->nb_chapters * sizeof(*timetable)); + AVChapter **timetable; - if (!timetable) - return AVERROR(ENOMEM); + if (!s->nb_chapters) + return 0; if (s->duration > 0 && s->start_time < INT64_MAX - s->duration) max_time = s->duration + ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time); + timetable = av_malloc(s->nb_chapters * sizeof(*timetable)); + if (!timetable) + return AVERROR(ENOMEM); + for (i = 0; i < s->nb_chapters; i++) timetable[i] = s->chapters[i]; qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp); From patchwork Fri Aug 27 14:27:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29825 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1513623iov; Fri, 27 Aug 2021 07:30:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu50oeixrXdm+MKlFrfAbj6f1SXnxADQNAoSTYgfMbK/+pK4gkZGG6nyVPwDrcL35gTFlw X-Received: by 2002:aa7:c245:: with SMTP id y5mr4724838edo.20.1630074603926; Fri, 27 Aug 2021 07:30:03 -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 y5si6745955edc.227.2021.08.27.07.30.03; Fri, 27 Aug 2021 07:30:03 -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=vDjQPVnx; 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 CC89E68A36E; Fri, 27 Aug 2021 17:28:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064097.outbound.protection.outlook.com [40.92.64.97]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 82CED6809E0 for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QoluT0QV9ZmHzaV3Y5Kg1uRN6Nf+aOL6U3VvtWAR29AU4BIOa8MIUaD2U+Vjqa3fjk2tiyEXcisDP10fP7f6CS0bRQVZ5Aj7qXWM6z5RFp05yEREDZMserWnZCeWIrBls5BBDot1MRESRAE09ma2QZPyHY/oBGSRydVU0uz+vqp64Fmm3lpp8Dj8Vc7VX83g5+lgZpY/P4jxHUhBl1TLcTKWTk5wM5w2NBOf/lYVHg97LFQo98NsbwcKcKRnT2AoxsXuNv8+VjZcaY/2ZG/bvKs3PuDTtNgDUs2ptG2Aracum0eZaNEAMYW59G+iJ5ASm7AM6v9liOqXGp0Im98L6Q== 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=qHlXVUovbPspIUCDJ17oukDeUtBecOmqhkIB097Cyx8=; b=TFuCMimKaH78o+E03DHE/S1zv41LGFv+X8TXG9BMa7zK66aOeoRIP+vhd6AklPRuxVTc0oWq9LP0ysBl2xrlSytWqgelArnYQMQYVcEgM1wh8JbVz9kL6wf1EZYcZgIh56+lkvwyBZ8GCG9SwPyJ8t67huuHirh8E0fXF9Bj5evQlJUY4/nztjCMT1oAdXJpg1+CIcwl1C39K8nZcUenyakrcnaY1WunHHZmBBvsXdEh4FyeiiYDAGni5WtJudbPfY9EvxnabqHFJndHnk+RusdNcIcWWu4BEbyN30BBPVFZKi/lxP0GiE2h02OlySFSI+h14Qs0vbvWuNv2c98CMQ== 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=qHlXVUovbPspIUCDJ17oukDeUtBecOmqhkIB097Cyx8=; b=vDjQPVnxJhhybJW93v8KJCeuCCCO7UIHicHR82bRMg+3U03mJ+avNxIozOP0VLu8Q1xzQdp/lKWM6k6oYMGyDkA7IT9qQXVMzGxxpu38lQFEYiR58axgT8drJ7uQtQL/wnW81IQrUEpEFdv0A9dGXFw7YmKEcN+ecWpb/yJS2esUuNIHvH3AfWEgBME7ERLnvGODCBbr0p+JAChUDs9YUQj7pmOBOd9hM7XoeohZ1h1cuEnpSgvBl+eIII72oyEYm9/YdgZn+kIT7bH5Fhtz8OqK8abpPwTo+UO24G82NDn2N10sR5F1BL8DGqE7MYNrP2VBFg1NMhYjSPi4z+COeg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4824.eurprd03.prod.outlook.com (2603:10a6:20b:84::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.18; Fri, 27 Aug 2021 14:27:55 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:55 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:17 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [cT4bzdbaQvzGr02zjEOKkTUqifwUYV41] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-16-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 020fdbc2-a9e4-428e-7bc8-08d96966dc21 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7vzheLA1AAf52xcU0SWAMTsZpl2ScDbgAp11I6Ke8eT3dW50Ztab1gf02kRz5Wx7s1QidofBnsWJwX7HbLQ7ult6xR6CDlXTnGxVr0aN0ISzMg8Bae9Sjg8A+tWiUc/q/8bbqQlv/89Qsi5kubUGGuoW8rXGXTkXpQYhcGGcXO6a2MA+pr9erAqQauBnEdnX8Gm4XVQ8q8moRflg7a56frUM5vW4yrpSR2tQ8jT1NWqC0XiT890PmmlCNTJKu3Jz2J7LVVsKYd1yLhCzMRV/9AKcS5X6314F73SpDROw+y5Ug55jeX0pygSf4gkPC1j/fpfwHfV7OiwB6dxiL+7f1sKLsD5tQBYD+TmdlES4mCf/z4vxrIYQ4SKTu/ehmO44H0/f6p00Lm2xlUv6avejM7SSsUl6AHJQ2TPO2SrItr/MMo9o5y+yDQ6zEoEcu/pAKng1B+iqh9dB+Q4Vi+8sWEx/ctfLUd2ICP46o/vcu7oqZ1mCMv2C/sychS0oLsiJoXTmu0JfAptw8q1W6nhxQCdxmuoeJZVb6fUMOl5O/NQY8f1LMNl94KtJdfrRuL/qtJgo/lS6MkKBnrhcrFglJLcF+KKTzZrAbdYr4eaSLaqI1Bvvtsr2OzMzsYoFfTnZlEeVNPIDE5Cs1p5rKK1WXWiStsC0edro5xUQJNaXzZcPyjHtdxxYHwwwfkXmEnOkPUlkHr1nbjzTPnsDBNQGyfXGQrqT0qhqJQ8aXAWZH7X0= X-MS-TrafficTypeDiagnostic: AM6PR03MB4824: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sY2wjnJqit/+7d4IkAAOFLve0o3oqVIcRGQq/YwjEWMlnR5HLjz4iExx63HPgmmcclf0IU4L0oUfBgdtJbhOXjrrxrjiVHwmnOI6XUDr9X/72Z9VN9AHj97n8zMRKXLjCrmHAntlnx0OsTaorcS5UUWJBgAu3mOjJiDBgUtvVXG97JTKrhF/p/XquGIhlqzmmzml7H7sAJfKlGVyKDP9u77M6lLJrSN6QropOeUsSD+j6f137KFUzPWAA5ZXK/gtpJwHYPqKPj5kJUQ4Gn171JCrFuqom/FBS/vLgk7mGjhhPk1/NObKfKyWj7b507hs+YUTCJcrOKRPeWeDiuzrXU+rxG/QmThZ5U8jFWzwaIFXDfDMv+8BIZKMTSPS8N0YJwJ3CmjuquXUErULioUeBWdWwZCvSB/X5zjaVm2hzPw+JbvYk1lgPHP/nStGfOXE X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jZRfsLsSV7DldQxSsQiuzAAJiuELfSX8fkoqXstKh0MpOD8vkUuEJI1Z/N7jzaLdPUheVGUD/MEqsiUpxQtNg5YEiEmfBlRavojFfeM+tWg49FQu4nZzQUznZYmwMZiRohHTO4BXRFtgbavkXo9JgQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 020fdbc2-a9e4-428e-7bc8-08d96966dc21 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:55.3016 (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: AM6PR03MB4824 Subject: [FFmpeg-devel] [PATCH 17/25] avformat/utils: Use av_memdup to duplicate array of AVChapter * 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: BfLsTedSzCzz Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index b3ff9e95eb..b56190d2da 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3176,12 +3176,9 @@ static int compute_chapters_end(AVFormatContext *s) max_time = s->duration + ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time); - timetable = av_malloc(s->nb_chapters * sizeof(*timetable)); + timetable = av_memdup(s->chapters, s->nb_chapters * sizeof(*timetable)); if (!timetable) return AVERROR(ENOMEM); - - for (i = 0; i < s->nb_chapters; i++) - timetable[i] = s->chapters[i]; qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp); for (i = 0; i < s->nb_chapters; i++) From patchwork Fri Aug 27 14:27:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29823 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1514247iov; Fri, 27 Aug 2021 07:30:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxckqZ3DoV/G5oGpC9jrIbB8CVWNy25eFbhUczicJANVxxqzUPNpSzU82CTcXrnWTRwUNYW X-Received: by 2002:aa7:c70c:: with SMTP id i12mr10208459edq.256.1630074647514; Fri, 27 Aug 2021 07:30:47 -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 w11si1386815eds.544.2021.08.27.07.30.47; Fri, 27 Aug 2021 07:30:47 -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=oQ3L5inC; 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 2522068A4DF; Fri, 27 Aug 2021 17:28:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064097.outbound.protection.outlook.com [40.92.64.97]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B3DF268A3E8 for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ER2OGV0ynacSMJWI6Y51SwXXCM4dbFnqCh5wAjlPJ+oBcZiubPOjZ9r9ukmuVyei1XOJf2v+0eZTCNVpA6DfM5v6suoDACofDUNBq6RSNJRtCqL62LFqtzff/9sNW12a6Mhd6OBQTRKualia3hBRXC335x+PhUOq4Y8nRvSh0Pn90j8QiBUTGkfZ7TlNKRJIvdJXLwNZmtB3kJBCx1LjLUsZSuZUT8SrrvAI0tbNWdB0lUyDGOFWfN6P7Ur5337LSTiHKWfSKV7B07dlhoPt5FVQIGrl3Y7p9nH1VRs7nqApj7VKFKn8xzUqkZIGB+X9sw2ubsD+ozx56mS2yhg2kA== 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=E2iwaKKZU8m+89N6Fn2TBp/AOp6TNnl6JY1wkTMMbpY=; b=QxXSC0EHU8Q5/FQzbfoU8x+4QHj2beUqXAeVJd3W2Yj3xnQ0KleOeKEJInMWiCWnXS250srS0eveGkCBXqyxK2MmmJdbU1PBvaMwAR/uCpE8aFiFvC5iSDSYQLlomPmB3WwOSzIF+ZeTPzDSDGWLzDIqzqqEQP0ViMBTe4aWxKCwMlcsXthOZmMq2nbtxExkN73TNfccBPPMuGzGnp5xcLVIwAYsQBx5Jl5e76NHYXv+VJ1YQbwl4xnXScGAFVbfTH8MOJ3jOGVAch7Vs3Ea6OYCX5isKMrCCPSToDVK2THO0DCa4ijFg8fZ4meGKrs2dAyv0N5NJX6j24L0zR/Deg== 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=E2iwaKKZU8m+89N6Fn2TBp/AOp6TNnl6JY1wkTMMbpY=; b=oQ3L5inC2k0XzFf+YZxSGwx78jRqsO0lrQz/3HpVX6lZqcLXgMvyKOI515SJnDC0QX8AH4fVJVtRu6oRiIKEev2N4h2hOULxlgdmIrMm/D108rRyGCHuLODyq55x1jMVUX4SHYZxDPM9a04cl+jQhchxGNOlhgsrTrs7lELkeJfZGqOSlSyqCJML+5PvnGDuiELsLj99oYacJ0Xbp5XYR7x0FZM0lr7w9Vw6rebrOvyU3XYiuramldds4gtvNOj70J8pvPl6JrhUAedyPODLXDRppcl3exG3H2Cd7f5YOyjh//jyInwnYv6Mv26Rz+M00WNhiIN+k0n7XjZ3TGNULg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4824.eurprd03.prod.outlook.com (2603:10a6:20b:84::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.18; Fri, 27 Aug 2021 14:27:57 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:57 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:18 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [Fj6agcyDfj5IyJMIoFXmpj2btrD1wsGt] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-17-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5629b083-39d6-4802-ddce-08d96966dd63 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7dsuKrQuTQ3eW4jPAOn+hpL0i+zXbeGFVAPqC/Y94uVHqPIFN+Ou+yWT1xtCJuAth6fOokVVU/uEFwFfFNG0RHV6mxxuduDDwTzLstG6CYkm+fwwEG7Q2pP7T1L7Q3kQHG3YMZ7lZX8y9iCjoCWaei1hU38CnVcNRVf6lJSEhA0M39VUmH4mu8k0/G8VNbHYg8s2iHrw2LR7T/h1nPuiqFi/mvpEiy67/yYiAr02Xcli125mGBOQUigQuF9i/N5RWTD6Qj/09UYiI10hM00TTnYobS/bf5Kz5iNPwlJyG3jdxifveLWy0yfIt+81EHlE1VJPCjIhu+nloMVpMQdMdcsAaqesF0G7XDWO0qg0sYj72n3lmx5mgo3dWifsQdqpWMJf/qUYhI/6ENlzFVCk3UIXQj2Ti+nNQ5EljbxqhWHQT3qNT/dkHNd4Bbon9T1PwqQNKZIwHAEBJPdZ9Ay5I/sJcfwpt7u3ZT0103cA7tNrqyrq3t5NoqjRblEwdwabBLMe4Tv5SP5qUVmjQhovCDcsVXwMJCzOr1E0c65qR8YNItyTSZaYhH7qEFa7dfaTGRUED+BRQuE1bgD496dzpCZU8jVQ5IiQFPrXZIvkeX8XgLlsFccCer0cRltWsPEA8Ny1/W+bARqZcknRTyoe2fQbytz3RdSn69ImOJw0P7gRIeNpLB7nBqaM0wLtk+9c4i0WOOCPsqUULxtRUTdUwYq+5P/AOTsJCR3cxuraeDHE= X-MS-TrafficTypeDiagnostic: AM6PR03MB4824: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SQxbdnNYP/UqGc49WBjqYjTn6TTKxoxAy4wxbSftp84m9xKkkcUlYuIGRA96dvag8fxrv8ehPTBcVxz/3ZgtUvNSJJZjJkybrxBqZ1ImyLp2MH5HZ1WWz8cLBnkKe9jE7QflXLI9UruQfLaaVt7kOvCTfRsbMkMSuU7jWW99htkDqduGGFxKNE5fRYN+gqxLI8sZ+Rqwfx24XC8t8uz4aNMKm3xHv2tMQ7N/iBMH2RzUK07VYKcn0HyqsjWqzG669/qNOfkJfkfjQQ+375F8H3hn1QZQ1Hs/45zYbOurRQrvW3GrXceqEAtCaXvK8z0WMpkFefJ5dtbaGhoHLz7V2nOwM9TsK6IOsKb1muNkRlWSUYX4J5AvJbqOpUexn3HoHmIdZG3yjpsABWNcN2u55gieL5k1IB9VOaIDoPkc7rRKznjWp5PrYOqWKu7hIPos X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pfM9s5xW+Q6N5m8BDZMrgRD5Y0NaH9+ajFDi9GWG3FJSw2BJffVJpNSvueIHDBLuHAkNYj1j0Ey9HvyIwF48AtfqSWR8Vy1rCqEdr6LKhnvAHNrB98RYQucFavZgzY9FWN+TnRIMquORYuiiWL0QfQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5629b083-39d6-4802-ddce-08d96966dd63 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:57.5319 (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: AM6PR03MB4824 Subject: [FFmpeg-devel] [PATCH 18/25] avformat/mux, utils: Use smaller scope for variables 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: yrFRERSlKO9W Signed-off-by: Andreas Rheinhardt --- libavformat/mux.c | 60 ++++------ libavformat/utils.c | 284 +++++++++++++++++++------------------------- 2 files changed, 148 insertions(+), 196 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index b1ad0dd561..a05deb3f0b 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -91,11 +91,10 @@ static void frac_add(FFFrac *f, int64_t incr) AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precision) { AVRational q; - int j; q = st->time_base; - for (j=2; j<14; j+= 1+(j>2)) + for (int j = 2; j < 14; j += 1 + (j > 2)) while (q.den / q.num < min_precision && q.num % j == 0) q.num /= j; while (q.den / q.num < min_precision && q.den < (1<<24)) @@ -193,7 +192,6 @@ error: static int validate_codec_tag(AVFormatContext *s, AVStream *st) { const AVCodecTag *avctag; - int n; enum AVCodecID id = AV_CODEC_ID_NONE; int64_t tag = -1; @@ -203,7 +201,7 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) * If tag is in the table with another id -> FAIL * If id is in the table with another tag -> FAIL unless strict < normal */ - for (n = 0; s->oformat->codec_tag[n]; n++) { + for (int n = 0; s->oformat->codec_tag[n]; n++) { avctag = s->oformat->codec_tag[n]; while (avctag->id != AV_CODEC_ID_NONE) { if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codecpar->codec_tag)) { @@ -226,13 +224,10 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) static int init_muxer(AVFormatContext *s, AVDictionary **options) { - int ret = 0, i; - AVStream *st; AVDictionary *tmp = NULL; - AVCodecParameters *par = NULL; const AVOutputFormat *of = s->oformat; - const AVCodecDescriptor *desc; AVDictionaryEntry *e; + int ret = 0; if (options) av_dict_copy(&tmp, *options, 0); @@ -255,9 +250,10 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) goto fail; } - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; - par = st->codecpar; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; + AVCodecParameters *const par = st->codecpar; + const AVCodecDescriptor *desc; if (!st->time_base.num) { /* fall back on the default timebase values */ @@ -385,13 +381,10 @@ fail: static int init_pts(AVFormatContext *s) { - int i; - AVStream *st; - /* init PTS generation */ - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; int64_t den = AV_NOPTS_VALUE; - st = s->streams[i]; switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: @@ -510,7 +503,6 @@ FF_DISABLE_DEPRECATION_WARNINGS static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { int delay = st->codecpar->video_delay; - int i; int frame_size; if (!s->internal->missing_ts_warning && @@ -546,9 +538,9 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * //calculate dts from pts if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { st->internal->pts_buffer[0] = pkt->pts; - for (i = 1; i < delay + 1 && st->internal->pts_buffer[i] == AV_NOPTS_VALUE; i++) + for (int i = 1; i < delay + 1 && st->internal->pts_buffer[i] == AV_NOPTS_VALUE; i++) st->internal->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration; - for (i = 0; iinternal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) + for (int i = 0; iinternal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) FFSWAP(int64_t, st->internal->pts_buffer[i], st->internal->pts_buffer[i + 1]); pkt->dts = st->internal->pts_buffer[0]; @@ -895,10 +887,9 @@ static int interleave_compare_dts(AVFormatContext *s, const AVPacket *next, int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - PacketList *pktl; int stream_count = 0; int noninterleaved_count = 0; - int i, ret; + int ret; int eof = flush; if (pkt) { @@ -906,7 +897,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, return ret; } - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { if (s->streams[i]->internal->last_in_packet_buffer) { ++stream_count; } else if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT && @@ -930,7 +921,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, s->streams[top_pkt->stream_index]->time_base, AV_TIME_BASE_Q); - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { int64_t last_dts; const PacketList *last = s->streams[i]->internal->last_in_packet_buffer; @@ -965,18 +956,15 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (s->internal->shortest_end != AV_NOPTS_VALUE) { while (s->internal->packet_buffer) { - AVPacket *top_pkt = &s->internal->packet_buffer->pkt; - AVStream *st; - int64_t top_dts = av_rescale_q(top_pkt->dts, - s->streams[top_pkt->stream_index]->time_base, + PacketList *pktl = s->internal->packet_buffer; + AVPacket *const top_pkt = &pktl->pkt; + AVStream *const st = s->streams[top_pkt->stream_index]; + int64_t top_dts = av_rescale_q(top_pkt->dts, st->time_base, AV_TIME_BASE_Q); if (s->internal->shortest_end + 1 >= top_dts) break; - pktl = s->internal->packet_buffer; - st = s->streams[pktl->pkt.stream_index]; - s->internal->packet_buffer = pktl->next; if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; @@ -991,10 +979,10 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } if (stream_count && flush) { - AVStream *st; - pktl = s->internal->packet_buffer; + PacketList *pktl = s->internal->packet_buffer; + AVStream *const st = s->streams[pktl->pkt.stream_index]; + *out = pktl->pkt; - st = s->streams[out->stream_index]; s->internal->packet_buffer = pktl->next; if (!s->internal->packet_buffer) @@ -1236,11 +1224,11 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) int av_write_trailer(AVFormatContext *s) { - int i, ret1, ret = 0; AVPacket *pkt = s->internal->pkt; + int ret1, ret = 0; av_packet_unref(pkt); - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { if (s->streams[i]->internal->bsfc) { ret1 = write_packets_from_bsfs(s, s->streams[i], pkt, 1/*interleaved*/); if (ret1 < 0) @@ -1269,7 +1257,7 @@ int av_write_trailer(AVFormatContext *s) avio_flush(s->pb); if (ret == 0) ret = s->pb ? s->pb->error : 0; - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { av_freep(&s->streams[i]->priv_data); av_freep(&s->streams[i]->internal->index_entries); } diff --git a/libavformat/utils.c b/libavformat/utils.c index b56190d2da..df11dc2517 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -135,9 +135,8 @@ void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type) void av_format_inject_global_side_data(AVFormatContext *s) { - int i; s->internal->inject_global_side_data = 1; - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; st->internal->inject_global_side_data = 1; } @@ -313,12 +312,11 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); if (fmt) { - int i; av_log(s, AV_LOG_DEBUG, "Probe with size=%d, packets=%d detected %s with score=%d\n", pd->buf_size, s->max_probe_packets - st->internal->probe_packets, fmt->name, score); - for (i = 0; fmt_id_type[i].name; i++) { + for (int i = 0; fmt_id_type[i].name; i++) { if (!strcmp(fmt->name, fmt_id_type[i].name)) { if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) @@ -373,8 +371,8 @@ static int init_input(AVFormatContext *s, const char *filename, int avformat_queue_attached_pictures(AVFormatContext *s) { - int i, ret; - for (i = 0; i < s->nb_streams; i++) + int ret; + for (unsigned i = 0; i < s->nb_streams; i++) if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC && s->streams[i]->discard < AVDISCARD_ALL) { if (s->streams[i]->attached_pic.size <= 0) { @@ -431,8 +429,8 @@ fail: static int update_stream_avctx(AVFormatContext *s) { - int i, ret; - for (i = 0; i < s->nb_streams; i++) { + int ret; + for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (!st->internal->need_context_update) @@ -678,7 +676,7 @@ no_packet: static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) { int64_t ref = pkt->dts; - int i, pts_wrap_behavior; + int pts_wrap_behavior; int64_t pts_wrap_reference; AVProgram *first_program; @@ -700,7 +698,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in if (!first_program) { int default_stream_index = av_find_default_stream_index(s); if (s->streams[default_stream_index]->internal->pts_wrap_reference == AV_NOPTS_VALUE) { - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { if (av_find_program_from_stream(s, NULL, i)) continue; s->streams[i]->internal->pts_wrap_reference = pts_wrap_reference; @@ -727,7 +725,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in program = first_program; while (program) { if (program->pts_wrap_reference != pts_wrap_reference) { - for (i = 0; inb_stream_indexes; i++) { + for (unsigned i = 0; i < program->nb_stream_indexes; i++) { s->streams[program->stream_index[i]]->internal->pts_wrap_reference = pts_wrap_reference; s->streams[program->stream_index[i]]->internal->pts_wrap_behavior = pts_wrap_behavior; } @@ -743,8 +741,8 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in int ff_read_packet(AVFormatContext *s, AVPacket *pkt) { - int err, i; AVStream *st; + int err; #if FF_API_INIT_PACKET FF_DISABLE_DEPRECATION_WARNINGS @@ -784,8 +782,8 @@ FF_ENABLE_DEPRECATION_WARNINGS continue; if (!pktl || err == AVERROR(EAGAIN)) return err; - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; if (st->internal->probe_packets || st->internal->request_probe > 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; @@ -986,7 +984,7 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t } } } else { - for (i = 0; iinternal->pts_reorder_error[i]; @@ -1017,11 +1015,10 @@ static void update_dts_from_pts(AVFormatContext *s, int stream_index, { AVStream *st = s->streams[stream_index]; int delay = st->internal->avctx->has_b_frames; - int i; int64_t pts_buffer[MAX_REORDER_DELAY+1]; - for (i = 0; ipkt.pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { pts_buffer[0] = pkt_buffer->pkt.pts; - for (i = 0; i pts_buffer[i + 1]; i++) + for (int i = 0; i < delay && pts_buffer[i] > pts_buffer[i + 1]; i++) FFSWAP(int64_t, pts_buffer[i], pts_buffer[i + 1]); pkt_buffer->pkt.dts = select_from_pts_buffer(st, pts_buffer, pkt_buffer->pkt.dts); @@ -1455,7 +1452,7 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts) static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { - int ret, i, got_packet = 0; + int ret, got_packet = 0; AVDictionary *metadata = NULL; while (!got_packet && !s->internal->parse_queue) { @@ -1467,8 +1464,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) if (ret == AVERROR(EAGAIN)) return ret; /* flush the parsers */ - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; if (st->internal->parser && st->internal->need_parsing) parse_packet(s, pkt, st->index, 1); } @@ -1596,7 +1593,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } if (st->internal->inject_global_side_data) { - for (i = 0; i < st->nb_side_data; i++) { + for (int i = 0; i < st->nb_side_data; i++) { AVPacketSideData *src_sd = &st->side_data[i]; uint8_t *dst_data; @@ -1753,16 +1750,14 @@ static void flush_packet_queue(AVFormatContext *s) int av_find_default_stream_index(AVFormatContext *s) { - int i; - AVStream *st; int best_stream = 0; int best_score = INT_MIN; if (s->nb_streams <= 0) return -1; - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { + const AVStream *const st = s->streams[i]; int score = 0; - st = s->streams[i]; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) score -= 400; @@ -1791,14 +1786,12 @@ int av_find_default_stream_index(AVFormatContext *s) /** Flush the frame reader. */ void ff_read_frame_flush(AVFormatContext *s) { - AVStream *st; - int i, j; flush_packet_queue(s); /* Reset read state for each stream. */ - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; if (st->internal->parser) { av_parser_close(st->internal->parser); @@ -1814,7 +1807,7 @@ void ff_read_frame_flush(AVFormatContext *s) st->internal->probe_packets = s->max_probe_packets; - for (j = 0; j < MAX_REORDER_DELAY + 1; j++) + for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) st->internal->pts_buffer[j] = AV_NOPTS_VALUE; if (s->internal->inject_global_side_data) @@ -1826,9 +1819,7 @@ void ff_read_frame_flush(AVFormatContext *s) void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp) { - int i; - - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; st->internal->cur_dts = @@ -1964,7 +1955,6 @@ int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) { - int ist1, ist2; int64_t pos_delta = 0; int64_t skip = 0; //We could use URLProtocol flags here but as many user applications do not use URLProtocols this would be unreliable @@ -1983,16 +1973,15 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) if (proto && !(strcmp(proto, "file") && strcmp(proto, "pipe") && strcmp(proto, "cache"))) return; - for (ist1 = 0; ist1 < s->nb_streams; ist1++) { + for (unsigned ist1 = 0; ist1 < s->nb_streams; ist1++) { AVStream *st1 = s->streams[ist1]; - for (ist2 = 0; ist2 < s->nb_streams; ist2++) { + for (unsigned ist2 = 0; ist2 < s->nb_streams; ist2++) { AVStream *st2 = s->streams[ist2]; - int i1, i2; if (ist1 == ist2) continue; - for (i1 = i2 = 0; i1 < st1->internal->nb_index_entries; i1++) { + for (int i1 = 0, i2 = 0; i1 < st1->internal->nb_index_entries; i1++) { AVIndexEntry *e1 = &st1->internal->index_entries[i1]; int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q); @@ -2513,11 +2502,8 @@ int avformat_flush(AVFormatContext *s) */ static int has_duration(AVFormatContext *ic) { - int i; - AVStream *st; - - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; if (st->duration != AV_NOPTS_VALUE) return 1; } @@ -2535,8 +2521,6 @@ static void update_stream_timings(AVFormatContext *ic) { int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text; int64_t duration, duration1, duration_text, filesize; - int i; - AVProgram *p; start_time = INT64_MAX; start_time_text = INT64_MAX; @@ -2545,10 +2529,11 @@ static void update_stream_timings(AVFormatContext *ic) duration = INT64_MIN; duration_text = INT64_MIN; - for (i = 0; i < ic->nb_streams; i++) { + for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *st = ic->streams[i]; int is_text = st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codecpar->codec_type == AVMEDIA_TYPE_DATA; + if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) { start_time1 = av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q); @@ -2566,7 +2551,7 @@ static void update_stream_timings(AVFormatContext *ic) else end_time = FFMAX(end_time, end_time1); } - for (p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) { + for (AVProgram *p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) { if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1) p->start_time = start_time1; if (p->end_time < end_time1) @@ -2601,8 +2586,9 @@ static void update_stream_timings(AVFormatContext *ic) ic->start_time = start_time; if (end_time != INT64_MIN) { if (ic->nb_programs > 1) { - for (i = 0; i < ic->nb_programs; i++) { - p = ic->programs[i]; + for (unsigned i = 0; i < ic->nb_programs; i++) { + AVProgram *const p = ic->programs[i]; + if (p->start_time != AV_NOPTS_VALUE && p->end_time > p->start_time && p->end_time - (uint64_t)p->start_time <= INT64_MAX) @@ -2627,12 +2613,10 @@ static void update_stream_timings(AVFormatContext *ic) static void fill_all_stream_timings(AVFormatContext *ic) { - int i; - AVStream *st; - update_stream_timings(ic); - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + if (st->start_time == AV_NOPTS_VALUE) { if (ic->start_time != AV_NOPTS_VALUE) st->start_time = av_rescale_q(ic->start_time, AV_TIME_BASE_Q, @@ -2646,15 +2630,14 @@ static void fill_all_stream_timings(AVFormatContext *ic) static void estimate_timings_from_bit_rate(AVFormatContext *ic) { - int64_t filesize, duration; - int i, show_warning = 0; - AVStream *st; + int show_warning = 0; /* if bit_rate is already set, we believe it */ if (ic->bit_rate <= 0) { int64_t bit_rate = 0; - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; + if (st->codecpar->bit_rate <= 0 && st->internal->avctx->bit_rate > 0) st->codecpar->bit_rate = st->internal->avctx->bit_rate; if (st->codecpar->bit_rate > 0) { @@ -2676,17 +2659,17 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) /* if duration is already set, we believe it */ if (ic->duration == AV_NOPTS_VALUE && ic->bit_rate != 0) { - filesize = ic->pb ? avio_size(ic->pb) : 0; + int64_t filesize = ic->pb ? avio_size(ic->pb) : 0; if (filesize > ic->internal->data_offset) { filesize -= ic->internal->data_offset; - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + if ( st->time_base.num <= INT64_MAX / ic->bit_rate && st->duration == AV_NOPTS_VALUE) { - duration = av_rescale(filesize, 8LL * st->time_base.den, + st->duration = av_rescale(filesize, 8LL * st->time_base.den, ic->bit_rate * (int64_t) st->time_base.num); - st->duration = duration; show_warning = 1; } } @@ -2704,8 +2687,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) { AVPacket *pkt = ic->internal->pkt; - AVStream *st; - int num, den, read_size, i, ret; + int num, den, read_size, ret; int found_duration = 0; int is_end; int64_t filesize, offset, duration; @@ -2714,8 +2696,9 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) /* flush packet queue */ flush_packet_queue(ic); - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + if (st->start_time == AV_NOPTS_VALUE && st->internal->first_dts == AV_NOPTS_VALUE && st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) @@ -2746,6 +2729,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) avio_seek(ic->pb, offset, SEEK_SET); read_size = 0; for (;;) { + AVStream *st; if (read_size >= DURATION_MAX_READ_SIZE << (FFMAX(retry - 1, 0))) break; @@ -2787,8 +2771,8 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) /* check if all audio/video streams have valid duration */ if (!is_end) { is_end = 1; - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_AUDIO: @@ -2804,8 +2788,9 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) av_opt_set(ic, "skip_changes", "0", AV_OPT_SEARCH_CHILDREN); /* warn about audio/video streams which duration could not be estimated */ - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; + if (st->duration == AV_NOPTS_VALUE) { switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: @@ -2821,14 +2806,13 @@ skip_duration_calc: fill_all_stream_timings(ic); avio_seek(ic->pb, old_offset, SEEK_SET); - for (i = 0; i < ic->nb_streams; i++) { - int j; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; - st = ic->streams[i]; st->internal->cur_dts = st->internal->first_dts; st->internal->last_IP_pts = AV_NOPTS_VALUE; st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; - for (j = 0; j < MAX_REORDER_DELAY + 1; j++) + for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) st->internal->pts_buffer[j] = AV_NOPTS_VALUE; } } @@ -3058,11 +3042,10 @@ unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id) enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag) { - int i; - for (i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) + for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) if (tag == tags[i].tag) return tags[i].id; - for (i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) + for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) if (avpriv_toupper4(tag) == avpriv_toupper4(tags[i].tag)) return tags[i].id; return AV_CODEC_ID_NONE; @@ -3128,8 +3111,7 @@ unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id) int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id, unsigned int *tag) { - int i; - for (i = 0; tags && tags[i]; i++) { + for (int i = 0; tags && tags[i]; i++) { const AVCodecTag *codec_tags = tags[i]; while (codec_tags->id != AV_CODEC_ID_NONE) { if (codec_tags->id == id) { @@ -3144,8 +3126,7 @@ int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id, enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag) { - int i; - for (i = 0; tags && tags[i]; i++) { + for (int i = 0; tags && tags[i]; i++) { enum AVCodecID id = ff_codec_get_id(tags[i], tag); if (id != AV_CODEC_ID_NONE) return id; @@ -3165,7 +3146,6 @@ static int chapter_start_cmp(const void *p1, const void *p2) static int compute_chapters_end(AVFormatContext *s) { - unsigned int i; int64_t max_time = 0; AVChapter **timetable; @@ -3181,7 +3161,7 @@ static int compute_chapters_end(AVFormatContext *s) return AVERROR(ENOMEM); qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp); - for (i = 0; i < s->nb_chapters; i++) + for (unsigned i = 0; i < s->nb_chapters; i++) if (timetable[i]->end == AV_NOPTS_VALUE) { AVChapter *ch = timetable[i]; int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q, @@ -3276,7 +3256,6 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) { - int i, j; int64_t last = st->internal->info->last_dts; if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last @@ -3291,11 +3270,11 @@ int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) // if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) // av_log(NULL, AV_LOG_ERROR, "%f\n", dts); - for (i = 0; iinternal->info->duration_error[0][1][i] < 1e10) { int framerate = get_std_framerate(i); double sdts = dts*framerate/(1001*12); - for (j= 0; j<2; j++) { + for (int j = 0; j < 2; j++) { int64_t ticks = llrint(sdts+j*0.5); double error= sdts - ticks + j*0.5; st->internal->info->duration_error[j][0][i] += error; @@ -3310,7 +3289,7 @@ int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) if (st->internal->info->duration_count % 10 == 0) { int n = st->internal->info->duration_count; - for (i = 0; iinternal->info->duration_error[0][1][i] < 1e10) { double a0 = st->internal->info->duration_error[0][0][i] / n; double error0 = st->internal->info->duration_error[0][1][i] / n - a0*a0; @@ -3336,9 +3315,7 @@ int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) void ff_rfps_calculate(AVFormatContext *ic) { - int i, j; - - for (i = 0; i < ic->nb_streams; i++) { + for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *st = ic->streams[i]; if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) @@ -3355,8 +3332,7 @@ void ff_rfps_calculate(AVFormatContext *ic) double best_error= 0.01; AVRational ref_rate = st->r_frame_rate.num ? st->r_frame_rate : av_inv_q(st->time_base); - for (j= 0; jinternal->info->codec_info_duration && st->internal->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) @@ -3367,7 +3343,7 @@ void ff_rfps_calculate(AVFormatContext *ic) if (av_q2d(st->time_base) * st->internal->info->rfps_duration_sum / st->internal->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) continue; - for (k= 0; k<2; k++) { + for (int k = 0; k < 2; k++) { int n = st->internal->info->duration_count; double a= st->internal->info->duration_error[k][0][j] / n; double error= st->internal->info->duration_error[k][1][j]/n - a*a; @@ -3509,9 +3485,7 @@ static int extract_extradata(AVFormatContext *s, AVStream *st, const AVPacket *p static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) { - int i; - - for (i = 0; i < avctx->nb_coded_side_data; i++) { + for (int i = 0; i < avctx->nb_coded_side_data; i++) { const AVPacketSideData *sd_src = &avctx->coded_side_data[i]; uint8_t *dst_data; dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size); @@ -3524,10 +3498,8 @@ static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { - int i, count = 0, ret = 0, j; + int count = 0, ret = 0; int64_t read_size; - AVStream *st; - AVCodecContext *avctx; AVPacket *pkt1 = ic->internal->pkt; int64_t old_offset = avio_tell(ic->pb); // new streams might appear, no options for those @@ -3562,11 +3534,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, ic->nb_streams); } - for (i = 0; i < ic->nb_streams; i++) { + for (unsigned i = 0; i < ic->nb_streams; i++) { const AVCodec *codec; AVDictionary *thread_opt = NULL; - st = ic->streams[i]; - avctx = st->internal->avctx; + AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; + AVCodecContext *const avctx = sti->avctx; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { @@ -3628,7 +3601,10 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) read_size = 0; for (;;) { const AVPacket *pkt; + AVStream *st; + AVCodecContext *avctx; int analyzed_all_streams; + unsigned i; if (ff_check_interrupt(&ic->interrupt_callback)) { ret = AVERROR_EXIT; av_log(ic, AV_LOG_DEBUG, "interrupted\n"); @@ -3637,10 +3613,10 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* check if one codec still needs to be handled */ for (i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; int fps_analyze_framecount = 20; int count; - st = ic->streams[i]; if (!has_codec_parameters(st, NULL)) break; /* If the timebase is coarse (like the usual millisecond precision @@ -3698,7 +3674,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ret = count; av_log(ic, AV_LOG_DEBUG, "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); - for (i = 0; i < ic->nb_streams; i++) + for (unsigned i = 0; i < ic->nb_streams; i++) if (!ic->streams[i]->r_frame_rate.num && ic->streams[i]->internal->info->duration_count <= 1 && ic->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && @@ -3857,10 +3833,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } if (eof_reached) { - int stream_index; - for (stream_index = 0; stream_index < ic->nb_streams; stream_index++) { - st = ic->streams[stream_index]; - avctx = st->internal->avctx; + for (unsigned stream_index = 0; stream_index < ic->nb_streams; stream_index++) { + AVStream *const st = ic->streams[stream_index]; + AVCodecContext *const avctx = st->internal->avctx; if (!has_codec_parameters(st, NULL)) { const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id); if (codec && !avctx->codec) { @@ -3887,9 +3862,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) int err = 0; av_packet_unref(empty_pkt); - for (i = 0; i < ic->nb_streams; i++) { - - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; /* flush the decoders */ if (st->internal->info->found_decoder == 1) { @@ -3909,9 +3883,11 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ff_rfps_calculate(ic); - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; - avctx = st->internal->avctx; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; + AVCodecContext *const avctx = sti->avctx; + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) { uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); @@ -3937,7 +3913,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* Round guessed framerate to a "standard" framerate if it's * within 1% of the original estimate. */ - for (j = 0; j < MAX_STD_TIMEBASES; j++) { + for (int j = 0; j < MAX_STD_TIMEBASES; j++) { AVRational std_fps = { get_std_framerate(j), 12 * 1001 }; double error = fabs(av_q2d(st->avg_frame_rate) / av_q2d(std_fps) - 1); @@ -4009,9 +3985,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) if (ret >= 0 && ic->nb_streams) /* We could not have all the codec parameters before EOF. */ ret = -1; - for (i = 0; i < ic->nb_streams; i++) { + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; const char *errmsg; - st = ic->streams[i]; /* if no packet was ever seen, update context now for has_codec_parameters */ if (!st->internal->avctx_inited) { @@ -4039,8 +4015,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) goto find_stream_info_err; /* update the stream parameters from the internal codec contexts */ - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; if (st->internal->avctx_inited) { ret = avcodec_parameters_from_context(st->codecpar, st->internal->avctx); @@ -4055,8 +4031,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } find_stream_info_err: - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; if (st->internal->info) av_freep(&st->internal->info->duration_error); avcodec_close(ic->streams[i]->internal->avctx); @@ -4077,14 +4053,12 @@ unref_then_goto_end: AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s) { - int i, j; - - for (i = 0; i < ic->nb_programs; i++) { + for (unsigned i = 0; i < ic->nb_programs; i++) { if (ic->programs[i] == last) { last = NULL; } else { if (!last) - for (j = 0; j < ic->programs[i]->nb_stream_indexes; j++) + for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++) if (ic->programs[i]->stream_index[j] == s) return ic->programs[i]; } @@ -4096,7 +4070,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, const AVCodec **decoder_ret, int flags) { - int i, nb_streams = ic->nb_streams; + int nb_streams = ic->nb_streams; int ret = AVERROR_STREAM_NOT_FOUND; int best_count = -1, best_multiframe = -1, best_disposition = -1; int count, multiframe, disposition; @@ -4112,7 +4086,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, nb_streams = p->nb_stream_indexes; } } - for (i = 0; i < nb_streams; i++) { + for (unsigned i = 0; i < nb_streams; i++) { int real_stream_index = program ? program[i] : i; AVStream *st = ic->streams[real_stream_index]; AVCodecParameters *par = st->codecpar; @@ -4180,7 +4154,7 @@ int av_read_pause(AVFormatContext *s) int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) { - int ret, i; + int ret; dst->id = src->id; dst->time_base = src->time_base; @@ -4200,7 +4174,7 @@ int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) return ret; /* Free existing side data*/ - for (i = 0; i < dst->nb_side_data; i++) + for (int i = 0; i < dst->nb_side_data; i++) av_free(dst->side_data[i].data); av_freep(&dst->side_data); dst->nb_side_data = 0; @@ -4213,7 +4187,7 @@ int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) return AVERROR(ENOMEM); dst->nb_side_data = src->nb_side_data; - for (i = 0; i < src->nb_side_data; i++) { + for (int i = 0; i < src->nb_side_data; i++) { uint8_t *data = av_memdup(src->side_data[i].data, src->side_data[i].size); if (!data) @@ -4230,12 +4204,11 @@ int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) static void free_stream(AVStream **pst) { AVStream *st = *pst; - int i; if (!st) return; - for (i = 0; i < st->nb_side_data; i++) + for (int i = 0; i < st->nb_side_data; i++) av_freep(&st->side_data[i].data); av_freep(&st->side_data); @@ -4275,8 +4248,6 @@ void ff_free_stream(AVFormatContext *s, AVStream *st) void avformat_free_context(AVFormatContext *s) { - int i; - if (!s) return; @@ -4289,11 +4260,11 @@ void avformat_free_context(AVFormatContext *s) if (s->oformat && s->oformat->priv_class && s->priv_data) av_opt_free(s->priv_data); - for (i = 0; i < s->nb_streams; i++) + for (unsigned i = 0; i < s->nb_streams; i++) free_stream(&s->streams[i]); s->nb_streams = 0; - for (i = 0; i < s->nb_programs; i++) { + for (unsigned i = 0; i < s->nb_programs; i++) { av_dict_free(&s->programs[i]->metadata); av_freep(&s->programs[i]->stream_index); av_freep(&s->programs[i]); @@ -4428,11 +4399,11 @@ fail: AVProgram *av_new_program(AVFormatContext *ac, int id) { AVProgram *program = NULL; - int i, ret; + int ret; av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id); - for (i = 0; i < ac->nb_programs; i++) + for (unsigned i = 0; i < ac->nb_programs; i++) if (ac->programs[i]->id == id) program = ac->programs[i]; @@ -4460,7 +4431,7 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba int64_t start, int64_t end, const char *title) { AVChapter *chapter = NULL; - int i, ret; + int ret; if (end != AV_NOPTS_VALUE && start > end) { av_log(s, AV_LOG_ERROR, "Chapter end time %"PRId64" before start %"PRId64"\n", end, start); @@ -4471,7 +4442,7 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba s->internal->chapter_ids_monotonic = 1; } else if (!s->internal->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) { s->internal->chapter_ids_monotonic = 0; - for (i = 0; i < s->nb_chapters; i++) + for (unsigned i = 0; i < s->nb_chapters; i++) if (s->chapters[i]->id == id) chapter = s->chapters[i]; } @@ -4497,7 +4468,6 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx) { - int i, j; AVProgram *program = NULL; void *tmp; @@ -4506,11 +4476,11 @@ void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx) return; } - for (i = 0; i < ac->nb_programs; i++) { + for (unsigned i = 0; i < ac->nb_programs; i++) { if (ac->programs[i]->id != progid) continue; program = ac->programs[i]; - for (j = 0; j < program->nb_stream_indexes; j++) + for (unsigned j = 0; j < program->nb_stream_indexes; j++) if (program->stream_index[j] == idx) return; @@ -4721,7 +4691,6 @@ int ff_mkdir_p(const char *path) char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase) { - int i; static const char hex_table_uc[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', @@ -4732,7 +4701,7 @@ char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase) 'c', 'd', 'e', 'f' }; const char *hex_table = lowercase ? hex_table_lc : hex_table_uc; - for (i = 0; i < s; i++) { + for (int i = 0; i < s; i++) { buff[i * 2] = hex_table[src[i] >> 4]; buff[i * 2 + 1] = hex_table[src[i] & 0xF]; } @@ -4849,8 +4818,7 @@ void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, int ff_find_stream_index(AVFormatContext *s, int id) { - int i; - for (i = 0; i < s->nb_streams; i++) + for (unsigned i = 0; i < s->nb_streams; i++) if (s->streams[i]->id == id) return i; return -1; @@ -5021,7 +4989,7 @@ static int match_stream_specifier(AVFormatContext *s, AVStream *st, if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC)) match = 0; } else if (*spec == 'p' && *(spec + 1) == ':') { - int prog_id, i, j; + int prog_id; int found = 0; char *endptr; spec += 2; @@ -5031,11 +4999,11 @@ static int match_stream_specifier(AVFormatContext *s, AVStream *st, return AVERROR(EINVAL); spec = endptr; if (match) { - for (i = 0; i < s->nb_programs; i++) { + for (unsigned i = 0; i < s->nb_programs; i++) { if (s->programs[i]->id != prog_id) continue; - for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) { + for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) { if (st->index == s->programs[i]->stream_index[j]) { found = 1; if (p) @@ -5295,9 +5263,7 @@ int ff_generate_avci_extradata(AVStream *st) uint8_t *av_stream_get_side_data(const AVStream *st, enum AVPacketSideDataType type, size_t *size) { - int i; - - for (i = 0; i < st->nb_side_data; i++) { + for (int i = 0; i < st->nb_side_data; i++) { if (st->side_data[i].type == type) { if (size) *size = st->side_data[i].size; @@ -5313,9 +5279,8 @@ int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type, uint8_t *data, size_t size) { AVPacketSideData *sd, *tmp; - int i; - for (i = 0; i < st->nb_side_data; i++) { + for (int i = 0; i < st->nb_side_data; i++) { sd = &st->side_data[i]; if (sd->type == type) { @@ -5475,8 +5440,7 @@ int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t * } if (ret == CONTAINS_PAL) { - int i; - for (i = 0; i < AVPALETTE_COUNT; i++) + for (int i = 0; i < AVPALETTE_COUNT; i++) palette[i] = AV_RL32(pkt->data + pkt->size - AVPALETTE_SIZE + i*4); return 1; } From patchwork Fri Aug 27 14:27:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29819 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1514417iov; Fri, 27 Aug 2021 07:31:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbZ2g8RlSA/z1ZnhEuyfTY5DoPnnGUCP9vL93NPEfMwI3x8SPUWsSR2kahC54UfGvBgZuZ X-Received: by 2002:a17:906:d183:: with SMTP id c3mr10248328ejz.283.1630074661187; Fri, 27 Aug 2021 07:31: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 w13si4162171ede.473.2021.08.27.07.31.00; Fri, 27 Aug 2021 07:31: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=mauCNJGX; 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 AB74368A447; Fri, 27 Aug 2021 17:28:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067023.outbound.protection.outlook.com [40.92.67.23]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D503068A2DE for ; Fri, 27 Aug 2021 17:28:00 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U9mZyMF/koWM6xyrvAgzYDJEsVsnnH9BN70X4o145cRhTTq5yGxJnXxkCIFYRX+eCG8qLn0enco41uJMK9IUItbpz+4jaBHvfolvvLNSGWpGtVs30sHj8xUjsHrlwutm6D0jtab53/V3p1MOJ+NxpslgPOx+pbN2+Duwh63FODTp9KOaWaOYR9nSVdFB7OPgXXz5Bg11Cx5XQYNQujjA9Dh3wFxj2dg91M9A5ZGfhFpvz6Vxvc8yahBrJ0lCxx0qnmnlpZMBzrQKK6PSMcECwS5VQxaipwozT2XYPrZ7X0dYGyWBcZM6W2CcLfRSRavZP3a/TN94cLXfes68jfQZvA== 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=0WOPqABQbBq2FePVUAgJ6r7Mx8WQY57uadUP+kQuBhY=; b=LHRcEWkWnFhD3kepgF612+4T5cR6bkHRX67STCZ8adLsRQLd0hkJ5Bqauy4yh19zq8GjO/g6bpwBkYIZcJmMUN1mITfOnzGYSCjQzspG0KcYFoS2FkAV5bLo+BvNiFb+cILpvXR7JR8YIi9n9IlkKzBaUIvlDjxk8gCsL3LOq/DmTJ+SpL9Ntb4aMgQ6RG2MgT2P4KS4TG/qZZR+NbeqmbElJ5KoXGQUICKJFTQgJL55cNMojanrJZguu5HypBSoJcTlvUMkI6pacohLJozBfdh3HAKAwnoZ8up5YRbc9IAHdAD1fWXs6Ytw9LbZ5335lPaNpDP0c3Ib4XNhxUxvIg== 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=0WOPqABQbBq2FePVUAgJ6r7Mx8WQY57uadUP+kQuBhY=; b=mauCNJGX/g/aHfqVLkojBuJBUNbdOID4sji9DXAR+VNwUjKYS3BYLJSkymbQuoik5dq6PJwxi4jtM60nI0csS6lmQ5R9ojvNhDxrCW+JHvdQmq+SckVxwQNbdZTI8zkcCdCMirT2hu8Uzr9feCT4UGNdOF6p2i8FrfdJNb1xaNDehdn7qJzPS0oBoXtVslaI/nQiCXlD58io+qETPTSo2BETWv+lqixLzPjqDkCL4J/+mfcrqOr1gmdjNCswpXg2IMeeZYc8+jkKc4F6/kkp8GDgqDFPbb1Bo1FW6L+M+R0HkgR3D14K2RxBtFoJNSMxOeDPjoXTHizIwpRkK7DwOg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3861.eurprd03.prod.outlook.com (2603:10a6:20b:22::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Fri, 27 Aug 2021 14:27:58 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:58 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:19 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [cxj9rgAe9BJv1g+vojSLGZSjSiTFTbSh] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-18-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0943c129-f42e-4742-e436-08d96966de42 X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEtNCKoPT6rtVE5PzvjguT+vwxgZMDl0eQmh84nWdXI8Z4nf8rddsZuxA5LwMVXiJctLGFtfH9nU/04Qvdk/7YtW0yLA8+YOPnWpvV4K4KRBAEXjza0kK9KKQrCCRD/oInr6pfXHDkgZBgieFSsUg3T4f9GZoN/Nx2aAyrUH2jsw1EuCBX6nalr82ZrRnUDQ8OTbcFg4CuR8eOIOXvqggzEqCDVpARSP0DzQtFpoencHhavVNKgYLIFonKaP/YZ8o+4XMRAp9cY1s/D7HJb+8bAoYN5+VlaUVF9l++qLC63aJH1tMxPpl8ggZ+rl08EiO+n3VfVYZYSbipIk+OAtPfxONjNuZQQK6fzi+9zVPNhCalxpPC/Fr0oMCLJMM366YRzqSSXG5KygMyXCvTDteU9oKTCzCCvcZZwxnxchk+mi6ONAG4A3XLnZ1/6+HnGHh1ckHYw+O3UYvJz/QgoeAHHJz/V1qIWtq/sSTq5lOh7KFT4HHJ8VVilRc6E/FTzQJc5axFPPBOKNMB0ogZaTqdeZnNZhwFLsZGcn92clx2Uxt4iBCt5dhCVSXdzUdpBazOv3msZzFUiafDEKRCkatD1C8hdgCzgbuzMwEciNM//r+CNA3qzDGqcp5+nRiUzeWY9+AqIrGiIlnfB27xLfs6RF2q0Egs8U16+gZ/2H1UDxQeEH2srLadmxviWvs3OUWkuRM/+n9a7wBhizw7cpXaNOtARVNsNDrT+O91CycjA9bw6EjeJF3eS7tQAik1j8z68RvBxIeLSxMUYkOOHVZ+Xg X-MS-TrafficTypeDiagnostic: AM6PR03MB3861: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GES4iTmLXQR1bntl+RMVhTIIj38uhJIMcrGbIcJ4CLpqO4ldmC5eqL7YAJ+hG0lMv7OCksIAlsvN4CQGB9nQEDnTEI34+fdjkppP7MXtu3I1MKRbNU4b2u3OVpXaTHiioqKHMnUlYcj9LrSF6hM8vnGnoRLDJ3MHkfYEKbp9PwET+LIZAiGtJoPhvHtPHcMM787NYQmnpcaXFWYRWgs5/4Qzk6ItiPneUmcnP2xBN72F4YSsPUEeVbvzR2nXDFhu/vvMQREcFmPL3pG1XzSzbP5F5kjbv0tr2jyKK8DL5j/X9Jjxn8UOcvhvcnMwO1C/eHpfbpFChDyu8UksnqJ5nkHg0nWDBb2tXxTRXcF7v8GtEUb4CptIIICkZBExF/Eg733mhKGzWzSdYYYs3J+++ZU8pPRN9+TVQSEtuE4OmfJgfyBJqqPKyiXyuO2qJyXN X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bO3mSqMsW6WJ9/BW88LeNK2M9vxcrCaSLAt/zlUUbjwkNGbfCwozK5MoLInv9ZadNPNLp45f1GSWOmmJCtojkflAD6iwnyvBwQaGb3X4z0/z/7O+SUzJOjCs7xLlhl0JpeJC5pCKB42yx6ZyHwhj3Q== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0943c129-f42e-4742-e436-08d96966de42 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:58.8950 (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: AM6PR03MB3861 Subject: [FFmpeg-devel] [PATCH 19/25] avformat/mux, mxfenc, utils: Use dedicated pointer for AVFormatInternal 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: XoCPQd+Sj7bc This gets rid of ugly "->internal" and is in preparation for removing AVFormatInternal altogether. Signed-off-by: Andreas Rheinhardt --- libavformat/mux.c | 80 +++++++++++++------------- libavformat/mxfenc.c | 15 ++--- libavformat/utils.c | 133 ++++++++++++++++++++++++------------------- 3 files changed, 124 insertions(+), 104 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index a05deb3f0b..036a1956f6 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -433,10 +433,11 @@ static void flush_if_needed(AVFormatContext *s) static void deinit_muxer(AVFormatContext *s) { - if (s->oformat && s->oformat->deinit && s->internal->initialized) + AVFormatInternal *const si = s->internal; + if (s->oformat && s->oformat->deinit && si->initialized) s->oformat->deinit(s); - s->internal->initialized = - s->internal->streams_initialized = 0; + si->initialized = + si->streams_initialized = 0; } int avformat_init_output(AVFormatContext *s, AVDictionary **options) @@ -462,8 +463,9 @@ int avformat_init_output(AVFormatContext *s, AVDictionary **options) int avformat_write_header(AVFormatContext *s, AVDictionary **options) { int ret = 0; - int already_initialized = s->internal->initialized; - int streams_already_initialized = s->internal->streams_initialized; + AVFormatInternal *const si = s->internal; + int already_initialized = si->initialized; + int streams_already_initialized = si->streams_initialized; if (!already_initialized) if ((ret = avformat_init_output(s, options)) < 0) @@ -482,7 +484,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_UNKNOWN); - if (!s->internal->streams_initialized) { + if (!si->streams_initialized) { if ((ret = init_pts(s)) < 0) goto fail; } @@ -650,20 +652,21 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (s->avoid_negative_ts > 0) { + AVFormatInternal *const si = s->internal; AVStream *st = s->streams[pkt->stream_index]; int64_t offset = st->internal->mux_ts_offset; - int64_t ts = s->internal->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; + int64_t ts = si->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; - if (s->internal->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE && + if (si->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE && (ts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) { - s->internal->offset = -ts; - s->internal->offset_timebase = st->time_base; + si->offset = -ts; + si->offset_timebase = st->time_base; } - if (s->internal->offset != AV_NOPTS_VALUE && !offset) { + if (si->offset != AV_NOPTS_VALUE && !offset) { offset = st->internal->mux_ts_offset = - av_rescale_q_rnd(s->internal->offset, - s->internal->offset_timebase, + av_rescale_q_rnd(si->offset, + si->offset_timebase, st->time_base, AV_ROUND_UP); } @@ -673,7 +676,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) if (pkt->pts != AV_NOPTS_VALUE) pkt->pts += offset; - if (s->internal->avoid_negative_ts_use_pts) { + if (si->avoid_negative_ts_use_pts) { if (pkt->pts != AV_NOPTS_VALUE && pkt->pts < 0) { av_log(s, AV_LOG_WARNING, "failed to avoid negative " "pts %s in stream %d.\n" @@ -786,6 +789,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *)) { int ret; + AVFormatInternal *const si = s->internal; PacketList **next_point, *this_pktl; AVStream *st = s->streams[pkt->stream_index]; int chunked = s->max_chunk_size || s->max_chunk_duration; @@ -807,7 +811,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (st->internal->last_in_packet_buffer) { next_point = &(st->internal->last_in_packet_buffer->next); } else { - next_point = &s->internal->packet_buffer; + next_point = &si->packet_buffer; } if (chunked) { @@ -831,7 +835,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (chunked && !(pkt->flags & CHUNK_START)) goto next_non_null; - if (compare(s, &s->internal->packet_buffer_end->pkt, pkt)) { + if (compare(s, &si->packet_buffer_end->pkt, pkt)) { while ( *next_point && ((chunked && !((*next_point)->pkt.flags&CHUNK_START)) || !compare(s, &(*next_point)->pkt, pkt))) @@ -839,12 +843,12 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (*next_point) goto next_non_null; } else { - next_point = &(s->internal->packet_buffer_end->next); + next_point = &(si->packet_buffer_end->next); } } av_assert1(!*next_point); - s->internal->packet_buffer_end = this_pktl; + si->packet_buffer_end = this_pktl; next_non_null: this_pktl->next = *next_point; @@ -887,6 +891,7 @@ static int interleave_compare_dts(AVFormatContext *s, const AVPacket *next, int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { + AVFormatInternal *const si = s->internal; int stream_count = 0; int noninterleaved_count = 0; int ret; @@ -907,15 +912,15 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } } - if (s->internal->nb_interleaved_streams == stream_count) + if (si->nb_interleaved_streams == stream_count) flush = 1; if (s->max_interleave_delta > 0 && - s->internal->packet_buffer && + si->packet_buffer && !flush && - s->internal->nb_interleaved_streams == stream_count+noninterleaved_count + si->nb_interleaved_streams == stream_count+noninterleaved_count ) { - AVPacket *top_pkt = &s->internal->packet_buffer->pkt; + AVPacket *const top_pkt = &si->packet_buffer->pkt; int64_t delta_dts = INT64_MIN; int64_t top_dts = av_rescale_q(top_pkt->dts, s->streams[top_pkt->stream_index]->time_base, @@ -943,31 +948,31 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } } - if (s->internal->packet_buffer && + if (si->packet_buffer && eof && (s->flags & AVFMT_FLAG_SHORTEST) && - s->internal->shortest_end == AV_NOPTS_VALUE) { - AVPacket *top_pkt = &s->internal->packet_buffer->pkt; + si->shortest_end == AV_NOPTS_VALUE) { + AVPacket *const top_pkt = &si->packet_buffer->pkt; - s->internal->shortest_end = av_rescale_q(top_pkt->dts, + si->shortest_end = av_rescale_q(top_pkt->dts, s->streams[top_pkt->stream_index]->time_base, AV_TIME_BASE_Q); } - if (s->internal->shortest_end != AV_NOPTS_VALUE) { - while (s->internal->packet_buffer) { - PacketList *pktl = s->internal->packet_buffer; + if (si->shortest_end != AV_NOPTS_VALUE) { + while (si->packet_buffer) { + PacketList *pktl = si->packet_buffer; AVPacket *const top_pkt = &pktl->pkt; AVStream *const st = s->streams[top_pkt->stream_index]; int64_t top_dts = av_rescale_q(top_pkt->dts, st->time_base, AV_TIME_BASE_Q); - if (s->internal->shortest_end + 1 >= top_dts) + if (si->shortest_end + 1 >= top_dts) break; - s->internal->packet_buffer = pktl->next; - if (!s->internal->packet_buffer) - s->internal->packet_buffer_end = NULL; + si->packet_buffer = pktl->next; + if (!si->packet_buffer) + si->packet_buffer_end = NULL; if (st->internal->last_in_packet_buffer == pktl) st->internal->last_in_packet_buffer = NULL; @@ -979,14 +984,13 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } if (stream_count && flush) { - PacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = si->packet_buffer; AVStream *const st = s->streams[pktl->pkt.stream_index]; - *out = pktl->pkt; - s->internal->packet_buffer = pktl->next; - if (!s->internal->packet_buffer) - s->internal->packet_buffer_end = NULL; + si->packet_buffer = pktl->next; + if (!si->packet_buffer) + si->packet_buffer_end = NULL; if (st->internal->last_in_packet_buffer == pktl) st->internal->last_in_packet_buffer = NULL; diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 229817dba6..36f334adbf 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3100,13 +3100,14 @@ static void mxf_deinit(AVFormatContext *s) static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { + AVFormatInternal *const si = s->internal; int i, stream_count = 0; for (i = 0; i < s->nb_streams; i++) stream_count += !!s->streams[i]->internal->last_in_packet_buffer; if (stream_count && (s->nb_streams == stream_count || flush)) { - PacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = si->packet_buffer; if (s->nb_streams != stream_count) { PacketList *last = NULL; // find last packet in edit unit @@ -3130,20 +3131,20 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket if (last) last->next = NULL; else { - s->internal->packet_buffer = NULL; - s->internal->packet_buffer_end= NULL; + si->packet_buffer = NULL; + si->packet_buffer_end = NULL; goto out; } - pktl = s->internal->packet_buffer; + pktl = si->packet_buffer; } *out = pktl->pkt; av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts); - s->internal->packet_buffer = pktl->next; + si->packet_buffer = pktl->next; if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == pktl) s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer= NULL; - if(!s->internal->packet_buffer) - s->internal->packet_buffer_end= NULL; + if (!si->packet_buffer) + si->packet_buffer_end = NULL; av_freep(&pktl); return 1; } else { diff --git a/libavformat/utils.c b/libavformat/utils.c index df11dc2517..67ec3384d0 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -457,12 +457,14 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options) { AVFormatContext *s = *ps; + AVFormatInternal *si; int ret = 0; AVDictionary *tmp = NULL; ID3v2ExtraMeta *id3v2_extra_meta = NULL; if (!s && !(s = avformat_alloc_context())) return AVERROR(ENOMEM); + si = s->internal; if (!s->av_class) { av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); return AVERROR(EINVAL); @@ -538,7 +540,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */ if (s->pb) - ff_id3v2_read_dict(s->pb, &s->internal->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); + ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); if (s->iformat->read_header) if ((ret = s->iformat->read_header(s)) < 0) { @@ -548,11 +550,11 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, } if (!s->metadata) { - s->metadata = s->internal->id3v2_meta; - s->internal->id3v2_meta = NULL; - } else if (s->internal->id3v2_meta) { + s->metadata = si->id3v2_meta; + si->id3v2_meta = NULL; + } else if (si->id3v2_meta) { av_log(s, AV_LOG_WARNING, "Discarding ID3 tags because more suitable tags were found.\n"); - av_dict_free(&s->internal->id3v2_meta); + av_dict_free(&si->id3v2_meta); } if (id3v2_extra_meta) { @@ -572,10 +574,10 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, if ((ret = avformat_queue_attached_pictures(s)) < 0) goto close; - if (s->pb && !s->internal->data_offset) - s->internal->data_offset = avio_tell(s->pb); + if (s->pb && !si->data_offset) + si->data_offset = avio_tell(s->pb); - s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; + si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; update_stream_avctx(s); @@ -741,6 +743,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in int ff_read_packet(AVFormatContext *s, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; AVStream *st; int err; @@ -755,18 +758,18 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif for (;;) { - PacketList *pktl = s->internal->raw_packet_buffer; + PacketList *pktl = si->raw_packet_buffer; const AVPacket *pkt1; if (pktl) { st = s->streams[pktl->pkt.stream_index]; - if (s->internal->raw_packet_buffer_remaining_size <= 0) + if (si->raw_packet_buffer_remaining_size <= 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; if (st->internal->request_probe <= 0) { - avpriv_packet_list_get(&s->internal->raw_packet_buffer, - &s->internal->raw_packet_buffer_end, pkt); - s->internal->raw_packet_buffer_remaining_size += pkt->size; + avpriv_packet_list_get(&si->raw_packet_buffer, + &si->raw_packet_buffer_end, pkt); + si->raw_packet_buffer_remaining_size += pkt->size; return 0; } } @@ -837,15 +840,15 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!pktl && st->internal->request_probe <= 0) return 0; - err = avpriv_packet_list_put(&s->internal->raw_packet_buffer, - &s->internal->raw_packet_buffer_end, + err = avpriv_packet_list_put(&si->raw_packet_buffer, + &si->raw_packet_buffer_end, pkt, NULL, 0); if (err < 0) { av_packet_unref(pkt); return err; } - pkt1 = &s->internal->raw_packet_buffer_end->pkt; - s->internal->raw_packet_buffer_remaining_size -= pkt1->size; + pkt1 = &si->raw_packet_buffer_end->pkt; + si->raw_packet_buffer_remaining_size -= pkt1->size; if ((err = probe_codec(s, st, pkt1)) < 0) return err; @@ -957,10 +960,11 @@ static int has_decode_delay_been_guessed(AVStream *st) static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pktl) { + AVFormatInternal *const si = s->internal; if (pktl->next) return pktl->next; - if (pktl == s->internal->packet_buffer_end) - return s->internal->parse_queue; + if (pktl == si->packet_buffer_end) + return si->parse_queue; return NULL; } @@ -1038,8 +1042,9 @@ static void update_dts_from_pts(AVFormatContext *s, int stream_index, static void update_initial_timestamps(AVFormatContext *s, int stream_index, int64_t dts, int64_t pts, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; AVStream *st = s->streams[stream_index]; - PacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; PacketList *pktl_it; uint64_t shift; @@ -1091,7 +1096,8 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, static void update_initial_durations(AVFormatContext *s, AVStream *st, int stream_index, int64_t duration) { - PacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + AVFormatInternal *const si = s->internal; + PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; int64_t cur_dts = RELATIVE_TS_BASE; if (st->internal->first_dts != AV_NOPTS_VALUE) { @@ -1117,7 +1123,7 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(st->internal->first_dts)); return; } - pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; st->internal->first_dts = cur_dts; } else if (st->internal->cur_dts != RELATIVE_TS_BASE) return; @@ -1339,7 +1345,8 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index, int flush) { - AVPacket *out_pkt = s->internal->parse_pkt; + AVFormatInternal *const si = s->internal; + AVPacket *out_pkt = si->parse_pkt; AVStream *st = s->streams[stream_index]; uint8_t *data = pkt->data; int size = pkt->size; @@ -1425,8 +1432,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, compute_pkt_fields(s, st, st->internal->parser, out_pkt, next_dts, next_pts); - ret = avpriv_packet_list_put(&s->internal->parse_queue, - &s->internal->parse_queue_end, + ret = avpriv_packet_list_put(&si->parse_queue, + &si->parse_queue_end, out_pkt, NULL, 0); if (ret < 0) goto fail; @@ -1452,10 +1459,11 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts) static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; int ret, got_packet = 0; AVDictionary *metadata = NULL; - while (!got_packet && !s->internal->parse_queue) { + while (!got_packet && !si->parse_queue) { AVStream *st; /* read next packet */ @@ -1565,8 +1573,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } } - if (!got_packet && s->internal->parse_queue) - ret = avpriv_packet_list_get(&s->internal->parse_queue, &s->internal->parse_queue_end, pkt); + if (!got_packet && si->parse_queue) + ret = avpriv_packet_list_get(&si->parse_queue, &si->parse_queue_end, pkt); if (ret >= 0) { AVStream *st = s->streams[pkt->stream_index]; @@ -1639,15 +1647,16 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) int av_read_frame(AVFormatContext *s, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; const int genpts = s->flags & AVFMT_FLAG_GENPTS; int eof = 0; int ret; AVStream *st; if (!genpts) { - ret = s->internal->packet_buffer - ? avpriv_packet_list_get(&s->internal->packet_buffer, - &s->internal->packet_buffer_end, pkt) + ret = si->packet_buffer + ? avpriv_packet_list_get(&si->packet_buffer, + &si->packet_buffer_end, pkt) : read_frame_internal(s, pkt); if (ret < 0) return ret; @@ -1655,7 +1664,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) } for (;;) { - PacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = si->packet_buffer; if (pktl) { AVPacket *next_pkt = &pktl->pkt; @@ -1688,15 +1697,15 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) // 3. the packets for this stream at the end of the files had valid dts. next_pkt->pts = last_dts + next_pkt->duration; } - pktl = s->internal->packet_buffer; + pktl = si->packet_buffer; } /* read packet from packet buffer, if there is data */ st = s->streams[next_pkt->stream_index]; if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL && next_pkt->dts != AV_NOPTS_VALUE && !eof)) { - ret = avpriv_packet_list_get(&s->internal->packet_buffer, - &s->internal->packet_buffer_end, pkt); + ret = avpriv_packet_list_get(&si->packet_buffer, + &si->packet_buffer_end, pkt); goto return_packet; } } @@ -1710,8 +1719,8 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) return ret; } - ret = avpriv_packet_list_put(&s->internal->packet_buffer, - &s->internal->packet_buffer_end, + ret = avpriv_packet_list_put(&si->packet_buffer, + &si->packet_buffer_end, pkt, NULL, 0); if (ret < 0) { av_packet_unref(pkt); @@ -1738,11 +1747,12 @@ return_packet: /* XXX: suppress the packet queue */ static void flush_packet_queue(AVFormatContext *s) { - avpriv_packet_list_free(&s->internal->parse_queue, &s->internal->parse_queue_end); - avpriv_packet_list_free(&s->internal->packet_buffer, &s->internal->packet_buffer_end); - avpriv_packet_list_free(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end); + AVFormatInternal *const si = s->internal; + avpriv_packet_list_free(&si->parse_queue, &si->parse_queue_end); + avpriv_packet_list_free(&si->packet_buffer, &si->packet_buffer_end); + avpriv_packet_list_free(&si->raw_packet_buffer, &si->raw_packet_buffer_end); - s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; + si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; } /*******************************************************/ @@ -3434,10 +3444,10 @@ fail: return ret; } -static int extract_extradata(AVFormatContext *s, AVStream *st, const AVPacket *pkt) +static int extract_extradata(AVFormatInternal *si, AVStream *st, const AVPacket *pkt) { AVStreamInternal *sti = st->internal; - AVPacket *pkt_ref = s->internal->parse_pkt; + AVPacket *pkt_ref = si->parse_pkt; int ret; if (!sti->extract_extradata.inited) { @@ -3498,9 +3508,10 @@ static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { + AVFormatInternal *const si = ic->internal; int count = 0, ret = 0; int64_t read_size; - AVPacket *pkt1 = ic->internal->pkt; + AVPacket *pkt1 = si->pkt; int64_t old_offset = avio_tell(ic->pb); // new streams might appear, no options for those int orig_nb_streams = ic->nb_streams; @@ -3698,13 +3709,13 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { - ret = avpriv_packet_list_put(&ic->internal->packet_buffer, - &ic->internal->packet_buffer_end, + ret = avpriv_packet_list_put(&si->packet_buffer, + &si->packet_buffer_end, pkt1, NULL, 0); if (ret < 0) goto unref_then_goto_end; - pkt = &ic->internal->packet_buffer_end->pkt; + pkt = &si->packet_buffer_end->pkt; } else { pkt = pkt1; } @@ -3808,7 +3819,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) st->internal->info->frame_delay_evidence = 1; } if (!st->internal->avctx->extradata) { - ret = extract_extradata(ic, st, pkt); + ret = extract_extradata(si, st, pkt); if (ret < 0) goto unref_then_goto_end; } @@ -3851,14 +3862,14 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) // EOF already reached while reading the stream above. // So continue with reoordering DTS with whatever delay we have. - if (ic->internal->packet_buffer && !has_decode_delay_been_guessed(st)) { - update_dts_from_pts(ic, stream_index, ic->internal->packet_buffer); + if (si->packet_buffer && !has_decode_delay_been_guessed(st)) { + update_dts_from_pts(ic, stream_index, si->packet_buffer); } } } if (flush_codecs) { - AVPacket *empty_pkt = ic->internal->pkt; + AVPacket *empty_pkt = si->pkt; int err = 0; av_packet_unref(empty_pkt); @@ -3923,7 +3934,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) best_fps = std_fps.num; } - if (ic->internal->prefer_codec_framerate && codec_frame_rate.num > 0 && codec_frame_rate.den > 0) { + if (si->prefer_codec_framerate && codec_frame_rate.num > 0 && codec_frame_rate.den > 0) { error = fabs(av_q2d(codec_frame_rate) / av_q2d(std_fps) - 1); if (error < best_error) { @@ -4248,10 +4259,13 @@ void ff_free_stream(AVFormatContext *s, AVStream *st) void avformat_free_context(AVFormatContext *s) { + AVFormatInternal *si; + if (!s) return; + si = s->internal; - if (s->oformat && s->oformat->deinit && s->internal->initialized) + if (s->oformat && s->oformat->deinit && si->initialized) s->oformat->deinit(s); av_opt_free(s); @@ -4279,9 +4293,9 @@ void avformat_free_context(AVFormatContext *s) } av_freep(&s->chapters); av_dict_free(&s->metadata); - av_dict_free(&s->internal->id3v2_meta); - av_packet_free(&s->internal->pkt); - av_packet_free(&s->internal->parse_pkt); + av_dict_free(&si->id3v2_meta); + av_packet_free(&si->pkt); + av_packet_free(&si->parse_pkt); av_freep(&s->streams); flush_packet_queue(s); av_freep(&s->internal); @@ -4430,6 +4444,7 @@ AVProgram *av_new_program(AVFormatContext *ac, int id) AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title) { + AVFormatInternal *const si = s->internal; AVChapter *chapter = NULL; int ret; @@ -4439,9 +4454,9 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba } if (!s->nb_chapters) { - s->internal->chapter_ids_monotonic = 1; - } else if (!s->internal->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) { - s->internal->chapter_ids_monotonic = 0; + si->chapter_ids_monotonic = 1; + } else if (!si->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) { + si->chapter_ids_monotonic = 0; for (unsigned i = 0; i < s->nb_chapters; i++) if (s->chapters[i]->id == id) chapter = s->chapters[i]; From patchwork Fri Aug 27 14:27:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29830 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1514617iov; Fri, 27 Aug 2021 07:31:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxV8ZDzd4PSKbKDpK02gJu6QeVgqb48yXqAfzBbvlAC3ZdxOqHh2ZmW/nKbh18YAyUkOGVd X-Received: by 2002:a05:600c:154d:: with SMTP id f13mr9112309wmg.153.1630074674342; Fri, 27 Aug 2021 07:31:14 -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 dm13si6553519edb.484.2021.08.27.07.31.13; Fri, 27 Aug 2021 07:31:14 -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=V6u3NuC9; 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 021AF68A5BF; Fri, 27 Aug 2021 17:28:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067010.outbound.protection.outlook.com [40.92.67.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA90368A4FE for ; Fri, 27 Aug 2021 17:28:01 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W8qe1aGjZdIasGq+L9eYJWmpGZjubozq/ZgP9ie77DZ1YtSbe9deRQorCVv2+nD6Jyz7IzgN6iuUffdaFK76OWt+nTFBZ+Gi08fk8WBT88F1BO4nCCWxtNQbygEe2m+MiyiDAHznmpGYRwPfsbHT7fpOe4TX6vk8fQIvsXMrdXG7Xjctvh6KUMQ0baebXcoeOijERjxUJwadgfxQWTB38ZeYzyFa6/t/3UmiLCfV4rRlpOAtN7+8odYljjPcBSR14A5EDKgx58r3nBxWgRdqlRlJO4yINc+w68oabNice3Cf7f5r/HyMuL5O0BmJNYOifEgBcusJJapsM4xVoLErIw== 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=n6JVPT/bgMD8JH0tVOT03xhCTyXFU2jKK3SEW/F1jGU=; b=K8B3D0Leh18KBUW3WhfWT+4b7aenfN6b/34lVU8GaH+FbsQA/RIDbR/OhwS4XYeHnumSQsC6ml4B6btXMUBhiuzI0NO5LJM0e7+AxDqTHuDzVzGEnGa3WhjhoaWlVboFmb3KeI+Rb4iPZxRaxhE+tLYwucBgenSgLBETp0ZGYLj+/LANHt0Csn8uN/4tmpSxrXGSg5XUd2uHT+1arndbEFE+92rSnORIY/aQRG4awcXzbtP3bk/GXiVU+jj8Yd0Xp9aqmQVtS/IGUv9g9dhuTSPJYQLA0rMI+hBVcnQxxoFT9QTA1+602JsIUoxSlLlL5AUhDfqkJabTmOevk3oLhA== 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=n6JVPT/bgMD8JH0tVOT03xhCTyXFU2jKK3SEW/F1jGU=; b=V6u3NuC9KNZTS9T8GihMGXt93a1nGQAuQmy5d1NRK3fO8iaaHnLZhfaGQOTpeLMAddIAgsqgC1OlE85Er9T5zmaQHFKvOooDVqpVzRjEIu3BUWi9sHuPy8qmT3BcUUFhwC1d1qMw5GO7zKaOLQIwlSXqX2XxlB46Y3GS2iBfXL0rUDR1Sp2RuvLtDp7lLbcbWs4St7XPrMliT4K6DJg9/mIWBg96nQuKrppjc96l4jolJCfNR+xXxgmoO+l4UqDAxkXz526IgAR8QoU7a251nKAFPzCLTNcPVm5RtFmTExep+0eVlvKUqQuEqHZQeQh9xgfmS//Mh0+F/yP2hG986Q== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3861.eurprd03.prod.outlook.com (2603:10a6:20b:22::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Fri, 27 Aug 2021 14:28:00 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:28:00 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:20 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [MBmVtnUg1uv6oY3eIbkveR3m3+Neays+] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-19-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c9638303-634e-4abb-52bf-08d96966dee3 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/79Fs68muI3vwQ3lVxV32gsrf+PVIhI5hW45kQ1QTXOiE9H3/obCwKFNp/SImu+sPlNfj5lIWfvZUhIZ7iveaurrFBFV1Jy9a3rIYsMrkqsvFfSOfWLlait609hkE/gTxYY3zh/3twKyjzZEpBvltIWERtudZ6fkQSPCk07mQkxGpq0dsC7M6t5peIlldBydjtNm92MaKwKIShk/pdkW42rDFpyOKAnDm/w0+QZ7H7gh4iOxLLJ1Mrp3J1PRE+bQPgWOHt/TToLALjILJj5SkAYkEm3ecgIwFTBxZtFe3bqHyHqGX1ZXSTC5cVz63vUFrhFTOJwBtFCLfa4t8rO3YUeo8t3lYEeYWjvaIS6koRuop7sPBK6MT9cIuhj6beNJ1dkqdBzAvhK1rtzSnEbvF27P/jiKXHXSvAY32x7JfPNEdwWy5HxmdKvyLUrzrvmQC6miN68QiCQlhkkR5DX5qbim2/Devrhxezacg8+uPEXCpIZrWcg5ib1OKo3SDeJpoJSSJwqh2RFd4PHPaYG3keb+g94hYUfbo8wh8hUjca0esOE0eGwUQxJeE+J8oZYXEuReyr0M8DpVDChsL2ZNT4+g1VDBhhM37BnhyAl3qcfM60rIeAaHtOFLj9AobVHQJXMwWu7LKgeyiKFn+C1PUvELddFVxs5iy93GWMYZyBC+5tmG347KGIhjEpzNZWOJ2vlgBPFwZDPlAl3qRuTWl/CGOk+fafp7HOEZerXlvFCqM= X-MS-TrafficTypeDiagnostic: AM6PR03MB3861: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gS68a/UgbejPdIU2HpxQoC68yCxusAkWPXF5hD+XH5mkVyqRJkwgd7uRfid+Hx57Nl2rD8e564Y45lVjMz3wv/QEdBzpge0v9uv7uf4zDjxZVCQEi3BrEBkGeulcRSkifDouGodVBKV5/vEZlxF96BQb7euGK+OHn0PCthZBsI7PqRHL2biyWDm3bsOJuM7Cyzs6MCB5gY6mbyhweZgY6kZbr82c7mndWg96ZIv0eSKVzVirvi37WO6a7rj459MnAAQwWn0R8VNmzHuGe5EHngNpOrczl8t5w5Vz/N1kS7x399FU/1WouZiWGMeeG8YV/lbezgipBlNLffJsqfE9Qi5bD4YwIOLPD6nrbHdCyRGEWwi72PUNQXbJz5JqcrH1Om044q9nW00XogUI2fDRbUh6KjBoWIuuGA88pcSCLcGVFrYBQGNRrHpJVCEdXO2Z X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 735HdY2vp4JrNF5GlFXkOjv0B6O7SVnWYeZ1GJaoWE4xPzKIlzh8Zg9IGMGTJyN1UdyrxVNfe6igXpB4qRI7tA4A79qEcg435zOcUUMd66cla5pYMAw1Ex+erQsTcDfOyrRW58iGNFzTwvwJTtBNlg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9638303-634e-4abb-52bf-08d96966dee3 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:28:00.0151 (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: AM6PR03MB3861 Subject: [FFmpeg-devel] [PATCH 20/25] avformat: Avoid allocation for AVFormatInternal 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: aHPBDyrb0hmt Do this by allocating AVFormatContext together with the data that is currently in AVFormatInternal; or rather: Put AVFormatContext at the beginning of a new structure called FFFormatContext (which encompasses more than just the internal fields and is a proper context in its own right, hence the name) and remove AVFormatInternal altogether. The biggest simplifications occured in avformat_alloc_context(), where one can now simply call avformat_free_context() in case of errors. Signed-off-by: Andreas Rheinhardt --- libavformat/asfdec_f.c | 12 ++++---- libavformat/avformat.h | 8 ------ libavformat/boadec.c | 4 +-- libavformat/codec2.c | 3 +- libavformat/dsfdec.c | 7 ++--- libavformat/dv.c | 4 +-- libavformat/flacdec.c | 2 +- libavformat/fsb.c | 2 +- libavformat/hca.c | 12 ++++---- libavformat/internal.h | 14 +++++++-- libavformat/ipmovie.c | 2 +- libavformat/matroskadec.c | 6 ++-- libavformat/matroskaenc.c | 4 +-- libavformat/mp3dec.c | 12 ++++---- libavformat/mpegts.c | 2 +- libavformat/mtv.c | 2 +- libavformat/mux.c | 28 +++++++++--------- libavformat/mxfenc.c | 2 +- libavformat/nutdec.c | 2 +- libavformat/oggdec.c | 11 +++---- libavformat/options.c | 45 +++++++++++------------------ libavformat/pcm.c | 2 +- libavformat/r3d.c | 6 ++-- libavformat/serdec.c | 2 +- libavformat/smacker.c | 2 +- libavformat/svs.c | 1 - libavformat/utils.c | 60 +++++++++++++++++++-------------------- libavformat/vqf.c | 2 +- libavformat/wavdec.c | 2 +- libavformat/webm_chunk.c | 4 +-- libavformat/yop.c | 2 +- libavformat/yuv4mpegdec.c | 6 ++-- 32 files changed, 130 insertions(+), 143 deletions(-) diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index ff6ddfb967..eccf21f3b1 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -753,7 +753,7 @@ static int asf_read_header(AVFormatContext *s) } else { if (!s->keylen) { if (!ff_guidcmp(&g, &ff_asf_content_encryption)) { - AVPacket *pkt = s->internal->parse_pkt; + AVPacket *pkt = ffformatcontext(s)->parse_pkt; unsigned int len; av_log(s, AV_LOG_WARNING, "DRM protected stream detected, decoding will likely fail!\n"); @@ -884,7 +884,7 @@ static int asf_get_packet(AVFormatContext *s, AVIOContext *pb) if (asf->no_resync_search) off = 3; // else if (s->packet_size > 0 && !asf->uses_std_ecc) -// off = (avio_tell(pb) - s->internal->data_offset) % s->packet_size + 3; +// off = (avio_tell(pb) - ffformatcontext(s)->data_offset) % s->packet_size + 3; c = d = e = -1; while (off-- > 0) { @@ -1441,9 +1441,9 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, start_pos[i] = pos; if (s->packet_size > 0) - pos = (pos + s->packet_size - 1 - s->internal->data_offset) / + pos = (pos + s->packet_size - 1 - ffformatcontext(s)->data_offset) / s->packet_size * s->packet_size + - s->internal->data_offset; + ffformatcontext(s)->data_offset; *ppos = pos; if (avio_seek(s->pb, pos, SEEK_SET) < 0) return AV_NOPTS_VALUE; @@ -1525,7 +1525,7 @@ static int asf_build_simple_index(AVFormatContext *s, int stream_index) for (i = 0; i < ict; i++) { int pktnum = avio_rl32(s->pb); int pktct = avio_rl16(s->pb); - int64_t pos = s->internal->data_offset + s->packet_size * (int64_t)pktnum; + int64_t pos = ffformatcontext(s)->data_offset + s->packet_size * (int64_t)pktnum; int64_t index_pts = FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0); if (avio_feof(s->pb)) { @@ -1573,7 +1573,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, /* explicitly handle the case of seeking to 0 */ if (!pts) { asf_reset_header(s); - avio_seek(s->pb, s->internal->data_offset, SEEK_SET); + avio_seek(s->pb, ffformatcontext(s)->data_offset, SEEK_SET); return 0; } diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 81d2ac38d0..95746ec46a 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1090,8 +1090,6 @@ enum AVDurationEstimationMethod { AVFMT_DURATION_FROM_BITRATE ///< Duration estimated from bitrate (less accurate) }; -typedef struct AVFormatInternal AVFormatInternal; - /** * Format I/O context. * New fields can be added to the end with minor version bumps. @@ -1560,12 +1558,6 @@ typedef struct AVFormatContext { */ char *format_whitelist; - /** - * An opaque field for libavformat internal usage. - * Must not be accessed in any way by callers. - */ - AVFormatInternal *internal; - /** * IO repositioned flag. * This is set by avformat when the underlaying IO context read pointer diff --git a/libavformat/boadec.c b/libavformat/boadec.c index 69d17763ef..3c335cf410 100644 --- a/libavformat/boadec.c +++ b/libavformat/boadec.c @@ -56,14 +56,14 @@ static int read_header(AVFormatContext *s) st->codecpar->channels = avio_rl32(s->pb); if (st->codecpar->channels > FF_SANE_NB_CHANNELS || st->codecpar->channels <= 0) return AVERROR(ENOSYS); - s->internal->data_offset = avio_rl32(s->pb); + ffformatcontext(s)->data_offset = avio_rl32(s->pb); avio_r8(s->pb); st->codecpar->block_align = avio_rl32(s->pb); if (st->codecpar->block_align > INT_MAX / FF_SANE_NB_CHANNELS || st->codecpar->block_align <= 0) return AVERROR_INVALIDDATA; st->codecpar->block_align *= st->codecpar->channels; - avio_seek(s->pb, s->internal->data_offset, SEEK_SET); + avio_seek(s->pb, ffformatcontext(s)->data_offset, SEEK_SET); return 0; } diff --git a/libavformat/codec2.c b/libavformat/codec2.c index 1ddba808dd..0b992836b3 100644 --- a/libavformat/codec2.c +++ b/libavformat/codec2.c @@ -177,7 +177,7 @@ static int codec2_read_header(AVFormatContext *s) return AVERROR_PATCHWELCOME; } - s->internal->data_offset = CODEC2_HEADER_SIZE; + ffformatcontext(s)->data_offset = CODEC2_HEADER_SIZE; return codec2_read_header_common(s, st); } @@ -255,7 +255,6 @@ static int codec2raw_read_header(AVFormatContext *s) return ret; } - s->internal->data_offset = 0; codec2_make_extradata(st->codecpar->extradata, c2->mode); return codec2_read_header_common(s, st); diff --git a/libavformat/dsfdec.c b/libavformat/dsfdec.c index c872f98cc2..8acf17dd3d 100644 --- a/libavformat/dsfdec.c +++ b/libavformat/dsfdec.c @@ -141,7 +141,6 @@ static int dsf_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; dsf->data_size = avio_rl64(pb) - 12; dsf->data_end += dsf->data_size + 12; - s->internal->data_offset = avio_tell(pb); return 0; } @@ -161,7 +160,7 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt) int last_packet = pos == (dsf->data_end - st->codecpar->block_align); if (last_packet) { - int64_t data_pos = pos - s->internal->data_offset; + int64_t data_pos = pos - ffformatcontext(s)->data_offset; int64_t packet_size = dsf->audio_size - data_pos; int64_t skip_size = dsf->data_size - data_pos - packet_size; uint8_t *dst; @@ -184,7 +183,7 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->pos = pos; pkt->stream_index = 0; - pkt->pts = (pos - s->internal->data_offset) / st->codecpar->channels; + pkt->pts = (pos - ffformatcontext(s)->data_offset) / st->codecpar->channels; pkt->duration = packet_size / st->codecpar->channels; return 0; } @@ -194,7 +193,7 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; pkt->stream_index = 0; - pkt->pts = (pos - s->internal->data_offset) / st->codecpar->channels; + pkt->pts = (pos - ffformatcontext(s)->data_offset) / st->codecpar->channels; pkt->duration = st->codecpar->block_align / st->codecpar->channels; return 0; diff --git a/libavformat/dv.c b/libavformat/dv.c index d7909683c3..3f953be0aa 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -439,7 +439,7 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c, // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk) const int frame_size = c->sys->frame_size; int64_t offset; - int64_t size = avio_size(s->pb) - s->internal->data_offset; + int64_t size = avio_size(s->pb) - ffformatcontext(s)->data_offset; int64_t max_offset = ((size - 1) / frame_size) * frame_size; offset = frame_size * timestamp; @@ -449,7 +449,7 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c, else if (offset < 0) offset = 0; - return offset + s->internal->data_offset; + return offset + ffformatcontext(s)->data_offset; } void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset) diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index bfa464c508..2730e9cc50 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -258,7 +258,7 @@ static int flac_probe(const AVProbeData *p) static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit) { - AVPacket *pkt = s->internal->parse_pkt; + AVPacket *pkt = ffformatcontext(s)->parse_pkt; AVStream *st = s->streams[stream_index]; AVCodecParserContext *parser; int ret; diff --git a/libavformat/fsb.c b/libavformat/fsb.c index f145d10fd3..9e8b9ca6b1 100644 --- a/libavformat/fsb.c +++ b/libavformat/fsb.c @@ -156,7 +156,7 @@ static int fsb_read_header(AVFormatContext *s) } avio_skip(pb, offset - avio_tell(pb)); - s->internal->data_offset = avio_tell(pb); + ffformatcontext(s)->data_offset = avio_tell(pb); avpriv_set_pts_info(st, 64, 1, par->sample_rate); diff --git a/libavformat/hca.c b/libavformat/hca.c index 86be5b1345..eaa96a9b17 100644 --- a/libavformat/hca.c +++ b/libavformat/hca.c @@ -45,14 +45,14 @@ static int hca_read_header(AVFormatContext *s) uint32_t chunk; uint16_t version; uint32_t block_count; - uint16_t block_size; + uint16_t block_size, data_offset; int ret; avio_skip(pb, 4); version = avio_rb16(pb); - s->internal->data_offset = avio_rb16(pb); - if (s->internal->data_offset <= 8) + data_offset = avio_rb16(pb); + if (data_offset <= 8) return AVERROR_INVALIDDATA; st = avformat_new_stream(s, NULL); @@ -60,7 +60,7 @@ static int hca_read_header(AVFormatContext *s) return AVERROR(ENOMEM); par = st->codecpar; - ret = ff_alloc_extradata(par, s->internal->data_offset); + ret = ff_alloc_extradata(par, data_offset); if (ret < 0) return ret; @@ -69,7 +69,7 @@ static int hca_read_header(AVFormatContext *s) return AVERROR(EIO); AV_WL32(par->extradata, MKTAG('H', 'C', 'A', 0)); AV_WB16(par->extradata + 4, version); - AV_WB16(par->extradata + 6, s->internal->data_offset); + AV_WB16(par->extradata + 6, data_offset); bytestream2_init(&gb, par->extradata + 8, par->extradata_size - 8); @@ -97,7 +97,7 @@ static int hca_read_header(AVFormatContext *s) par->block_align = block_size; st->duration = 1024 * block_count; - avio_seek(pb, s->internal->data_offset, SEEK_SET); + avio_seek(pb, data_offset, SEEK_SET); avpriv_set_pts_info(st, 64, 1, par->sample_rate); return 0; diff --git a/libavformat/internal.h b/libavformat/internal.h index 4fc1154b9d..813032870f 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -69,7 +69,12 @@ typedef struct FFFrac { } FFFrac; -struct AVFormatInternal { +typedef struct FFFormatContext { + /** + * The public context. + */ + AVFormatContext pub; + /** * Number of streams relevant for interleaving. * Muxing only. @@ -173,7 +178,12 @@ struct AVFormatInternal { * Set if chapter ids are strictly monotonic. */ int chapter_ids_monotonic; -}; +} FFFormatContext; + +static av_always_inline FFFormatContext *ffformatcontext(AVFormatContext *s) +{ + return (FFFormatContext*)s; +} struct AVStreamInternal { /** diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c index c2505c6faf..9c996d4a98 100644 --- a/libavformat/ipmovie.c +++ b/libavformat/ipmovie.c @@ -644,7 +644,7 @@ static int ipmovie_read_header(AVFormatContext *s) if (chunk_type == CHUNK_VIDEO) ipmovie->audio_type = AV_CODEC_ID_NONE; /* no audio */ - else if (process_ipmovie_chunk(ipmovie, pb, s->internal->parse_pkt) != CHUNK_INIT_AUDIO) { + else if (process_ipmovie_chunk(ipmovie, pb, ffformatcontext(s)->parse_pkt) != CHUNK_INIT_AUDIO) { return AVERROR_INVALIDDATA; } diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index c67a728737..4bc6b40f44 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -382,7 +382,7 @@ typedef struct MatroskaDemuxContext { /* byte position of the segment inside the stream */ int64_t segment_start; - /* This packet coincides with AVFormatInternal.parse_pkt + /* This packet coincides with FFFormatContext.parse_pkt * and is not owned by us. */ AVPacket *pkt; @@ -2944,7 +2944,7 @@ static int matroska_read_header(AVFormatContext *s) } ebml_free(ebml_syntax, &ebml); - matroska->pkt = s->internal->parse_pkt; + matroska->pkt = ffformatcontext(s)->parse_pkt; /* The next thing is a segment. */ pos = avio_tell(matroska->ctx->pb); @@ -2961,7 +2961,7 @@ static int matroska_read_header(AVFormatContext *s) } /* Set data_offset as it might be needed later by seek_frame_generic. */ if (matroska->current_id == MATROSKA_ID_CLUSTER) - s->internal->data_offset = avio_tell(matroska->ctx->pb) - 4; + ffformatcontext(s)->data_offset = avio_tell(matroska->ctx->pb) - 4; matroska_execute_seekhead(matroska); if (!matroska->time_scale) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 6e34243f6b..62be0ac386 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1253,7 +1253,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, // if there is no mkv-specific codec ID, use VFW mode put_ebml_string(pb, MATROSKA_ID_CODECID, "V_MS/VFW/FOURCC"); track->write_dts = 1; - s->internal->avoid_negative_ts_use_pts = 0; + ffformatcontext(s)->avoid_negative_ts_use_pts = 0; } subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0); @@ -2674,7 +2674,7 @@ static int mkv_init(struct AVFormatContext *s) if (s->avoid_negative_ts < 0) { s->avoid_negative_ts = 1; - s->internal->avoid_negative_ts_use_pts = 1; + ffformatcontext(s)->avoid_negative_ts_use_pts = 1; } if (!strcmp(s->oformat->name, "webm")) { diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 195d89814e..622b94e8ff 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -365,8 +365,8 @@ static int mp3_read_header(AVFormatContext *s) int ret; int i; - s->metadata = s->internal->id3v2_meta; - s->internal->id3v2_meta = NULL; + s->metadata = ffformatcontext(s)->id3v2_meta; + ffformatcontext(s)->id3v2_meta = NULL; st = avformat_new_stream(s, NULL); if (!st) @@ -553,8 +553,8 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, if (filesize <= 0) { int64_t size = avio_size(s->pb); - if (size > 0 && size > s->internal->data_offset) - filesize = size - s->internal->data_offset; + if (size > 0 && size > ffformatcontext(s)->data_offset) + filesize = size - ffformatcontext(s)->data_offset; } if (mp3->xing_toc && (mp3->usetoc || (fast_seek && !mp3->is_cbr))) { @@ -575,7 +575,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, ie = &ie1; timestamp = av_clip64(timestamp, 0, st->duration); ie->timestamp = timestamp; - ie->pos = av_rescale(timestamp, filesize, st->duration) + s->internal->data_offset; + ie->pos = av_rescale(timestamp, filesize, st->duration) + ffformatcontext(s)->data_offset; } else { return -1; // generic index code } @@ -586,7 +586,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, if (mp3->is_cbr && ie == &ie1 && mp3->frames) { int frame_duration = av_rescale(st->duration, 1, mp3->frames); - ie1.timestamp = frame_duration * av_rescale(best_pos - s->internal->data_offset, mp3->frames, mp3->header_filesize); + ie1.timestamp = frame_duration * av_rescale(best_pos - ffformatcontext(s)->data_offset, mp3->frames, mp3->header_filesize); } avpriv_update_cur_dts(s, st, ie->timestamp); diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index fe89d4fb9f..9662ef1e61 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -3070,7 +3070,7 @@ static int mpegts_read_header(AVFormatContext *s) int64_t pos, probesize = s->probesize; int64_t seekback = FFMAX(s->probesize, (int64_t)ts->resync_size + PROBE_PACKET_MAX_BUF); - s->internal->prefer_codec_framerate = 1; + ffformatcontext(s)->prefer_codec_framerate = 1; if (ffio_ensure_seekback(pb, seekback) < 0) av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n"); diff --git a/libavformat/mtv.c b/libavformat/mtv.c index d33561b6ec..da02965fd8 100644 --- a/libavformat/mtv.c +++ b/libavformat/mtv.c @@ -202,7 +202,7 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) AVIOContext *pb = s->pb; int ret; - if((avio_tell(pb) - s->internal->data_offset + mtv->img_segment_size) % mtv->full_segment_size) + if((avio_tell(pb) - ffformatcontext(s)->data_offset + mtv->img_segment_size) % mtv->full_segment_size) { avio_skip(pb, MTV_AUDIO_PADDING_SIZE); diff --git a/libavformat/mux.c b/libavformat/mux.c index 036a1956f6..c2a1dc8a28 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -330,7 +330,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) } if (par->codec_type != AVMEDIA_TYPE_ATTACHMENT) - s->internal->nb_interleaved_streams++; + ffformatcontext(s)->nb_interleaved_streams++; } if (!s->priv_data && of->priv_data_size > 0) { @@ -433,7 +433,7 @@ static void flush_if_needed(AVFormatContext *s) static void deinit_muxer(AVFormatContext *s) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); if (s->oformat && s->oformat->deinit && si->initialized) s->oformat->deinit(s); si->initialized = @@ -447,8 +447,8 @@ int avformat_init_output(AVFormatContext *s, AVDictionary **options) if ((ret = init_muxer(s, options)) < 0) return ret; - s->internal->initialized = 1; - s->internal->streams_initialized = ret; + ffformatcontext(s)->initialized = 1; + ffformatcontext(s)->streams_initialized = ret; if (s->oformat->init && ret) { if ((ret = init_pts(s)) < 0) @@ -463,7 +463,7 @@ int avformat_init_output(AVFormatContext *s, AVDictionary **options) int avformat_write_header(AVFormatContext *s, AVDictionary **options) { int ret = 0; - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int already_initialized = si->initialized; int streams_already_initialized = si->streams_initialized; @@ -507,7 +507,7 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * int delay = st->codecpar->video_delay; int frame_size; - if (!s->internal->missing_ts_warning && + if (!ffformatcontext(s)->missing_ts_warning && !(s->oformat->flags & AVFMT_NOTIMESTAMPS) && (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC) || (st->disposition & AV_DISPOSITION_TIMED_THUMBNAILS)) && (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE)) { @@ -515,7 +515,7 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * "Timestamps are unset in a packet for stream %d. " "This is deprecated and will stop working in the future. " "Fix your code to set the timestamps properly\n", st->index); - s->internal->missing_ts_warning = 1; + ffformatcontext(s)->missing_ts_warning = 1; } if (s->debug & FF_FDEBUG_TS) @@ -652,7 +652,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (s->avoid_negative_ts > 0) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVStream *st = s->streams[pkt->stream_index]; int64_t offset = st->internal->mux_ts_offset; int64_t ts = si->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; @@ -789,7 +789,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *)) { int ret; - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); PacketList **next_point, *this_pktl; AVStream *st = s->streams[pkt->stream_index]; int chunked = s->max_chunk_size || s->max_chunk_duration; @@ -891,7 +891,7 @@ static int interleave_compare_dts(AVFormatContext *s, const AVPacket *next, int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int stream_count = 0; int noninterleaved_count = 0; int ret; @@ -1020,7 +1020,7 @@ int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream) { - PacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = ffformatcontext(s)->packet_buffer; while (pktl) { if (pktl->pkt.stream_index == stream) { return &pktl->pkt; @@ -1166,7 +1166,7 @@ static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleav int av_write_frame(AVFormatContext *s, AVPacket *in) { - AVPacket *pkt = s->internal->pkt; + AVPacket *pkt = ffformatcontext(s)->pkt; int ret; if (!in) { @@ -1228,7 +1228,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) int av_write_trailer(AVFormatContext *s) { - AVPacket *pkt = s->internal->pkt; + AVPacket *pkt = ffformatcontext(s)->pkt; int ret1, ret = 0; av_packet_unref(pkt); @@ -1310,7 +1310,7 @@ static void uncoded_frame_free(void *unused, uint8_t *data) static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, AVFrame *frame, int interleaved) { - AVPacket *pkt = s->internal->pkt; + AVPacket *pkt = ffformatcontext(s)->pkt; av_assert0(s->oformat); if (!s->oformat->write_uncoded_frame) { diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 36f334adbf..8e57e10487 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3100,7 +3100,7 @@ static void mxf_deinit(AVFormatContext *s) static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int i, stream_count = 0; for (i = 0; i < s->nb_streams; i++) diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index c6c015f8f0..50f8b64d10 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -845,7 +845,7 @@ static int nut_read_header(AVFormatContext *s) decode_info_header(nut); } - s->internal->data_offset = pos - 8; + ffformatcontext(s)->data_offset = pos - 8; if (bc->seekable & AVIO_SEEKABLE_NORMAL) { int64_t orig_pos = avio_tell(bc); diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index 5afbae2147..c80ea5e216 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -174,7 +174,7 @@ static int ogg_reset(AVFormatContext *s) os->segp = 0; os->incomplete = 0; os->got_data = 0; - if (start_pos <= s->internal->data_offset) { + if (start_pos <= ffformatcontext(s)->data_offset) { os->lastpts = 0; } os->start_trimming = 0; @@ -572,6 +572,7 @@ static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize, } os->header = ret; if (!os->header) { + FFFormatContext *const si = ffformatcontext(s); os->segp = segp; os->psize = psize; @@ -582,8 +583,8 @@ static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize, // Update the header state for all streams and // compute the data_offset. - if (!s->internal->data_offset) - s->internal->data_offset = os->sync_pos; + if (!si->data_offset) + si->data_offset = os->sync_pos; for (i = 0; i < ogg->nstreams; i++) { struct ogg_stream *cur_os = ogg->streams + i; @@ -591,7 +592,7 @@ static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize, // if we have a partial non-header packet, its start is // obviously at or after the data start if (cur_os->incomplete) - s->internal->data_offset = FFMIN(s->internal->data_offset, cur_os->sync_pos); + si->data_offset = FFMIN(si->data_offset, cur_os->sync_pos); } } else { os->nb_header++; @@ -684,7 +685,7 @@ static int ogg_get_length(AVFormatContext *s) if (ret < 0) return ret; - avio_seek (s->pb, s->internal->data_offset, SEEK_SET); + avio_seek (s->pb, ffformatcontext(s)->data_offset, SEEK_SET); ogg_reset(s); while (streams_left > 0 && !ogg_packet(s, &i, NULL, NULL, NULL)) { int64_t pts; diff --git a/libavformat/options.c b/libavformat/options.c index dccb6faa73..753aa9b8dc 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -151,46 +151,33 @@ static void io_close_default(AVFormatContext *s, AVIOContext *pb) avio_close(pb); } -static void avformat_get_context_defaults(AVFormatContext *s) +AVFormatContext *avformat_alloc_context(void) { - memset(s, 0, sizeof(AVFormatContext)); + FFFormatContext *const si = av_mallocz(sizeof(*si)); + AVFormatContext *s; - s->av_class = &av_format_context_class; + if (!si) + return NULL; + s = &si->pub; + s->av_class = &av_format_context_class; s->io_open = io_open_default; s->io_close = io_close_default; av_opt_set_defaults(s); -} -AVFormatContext *avformat_alloc_context(void) -{ - AVFormatContext *ic; - AVFormatInternal *internal; - ic = av_malloc(sizeof(AVFormatContext)); - if (!ic) return ic; - - internal = av_mallocz(sizeof(*internal)); - if (!internal) { - av_free(ic); + si->pkt = av_packet_alloc(); + si->parse_pkt = av_packet_alloc(); + if (!si->pkt || !si->parse_pkt) { + avformat_free_context(s); return NULL; } - internal->pkt = av_packet_alloc(); - internal->parse_pkt = av_packet_alloc(); - if (!internal->pkt || !internal->parse_pkt) { - av_packet_free(&internal->pkt); - av_packet_free(&internal->parse_pkt); - av_free(internal); - av_free(ic); - return NULL; - } - avformat_get_context_defaults(ic); - ic->internal = internal; - ic->internal->offset = AV_NOPTS_VALUE; - ic->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; - ic->internal->shortest_end = AV_NOPTS_VALUE; - return ic; + si->offset = AV_NOPTS_VALUE; + si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; + si->shortest_end = AV_NOPTS_VALUE; + + return s; } enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx) diff --git a/libavformat/pcm.c b/libavformat/pcm.c index 0e5443a826..cfa5b969cb 100644 --- a/libavformat/pcm.c +++ b/libavformat/pcm.c @@ -80,7 +80,7 @@ int ff_pcm_read_seek(AVFormatContext *s, /* recompute exact position */ st->internal->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num); - if ((ret = avio_seek(s->pb, pos + s->internal->data_offset, SEEK_SET)) < 0) + if ((ret = avio_seek(s->pb, pos + ffformatcontext(s)->data_offset, SEEK_SET)) < 0) return ret; return 0; } diff --git a/libavformat/r3d.c b/libavformat/r3d.c index 004efac355..2b1fe3099a 100644 --- a/libavformat/r3d.c +++ b/libavformat/r3d.c @@ -183,8 +183,8 @@ static int r3d_read_header(AVFormatContext *s) if (r3d->audio_channels) s->ctx_flags |= AVFMTCTX_NOHEADER; - s->internal->data_offset = avio_tell(s->pb); - av_log(s, AV_LOG_TRACE, "data offset %#"PRIx64"\n", s->internal->data_offset); + ffformatcontext(s)->data_offset = avio_tell(s->pb); + av_log(s, AV_LOG_TRACE, "data offset %#"PRIx64"\n", ffformatcontext(s)->data_offset); if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) return 0; // find REOB/REOF/REOS to load index @@ -210,7 +210,7 @@ static int r3d_read_header(AVFormatContext *s) } out: - avio_seek(s->pb, s->internal->data_offset, SEEK_SET); + avio_seek(s->pb, ffformatcontext(s)->data_offset, SEEK_SET); return 0; } diff --git a/libavformat/serdec.c b/libavformat/serdec.c index fa2de32fd5..fe185cabd9 100644 --- a/libavformat/serdec.c +++ b/libavformat/serdec.c @@ -110,7 +110,7 @@ static int ser_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_EOF; ret = av_get_packet(s->pb, pkt, s->packet_size); - pkt->pts = pkt->dts = (pkt->pos - s->internal->data_offset) / s->packet_size; + pkt->pts = pkt->dts = (pkt->pos - ffformatcontext(s)->data_offset) / s->packet_size; pkt->stream_index = 0; if (ret < 0) diff --git a/libavformat/smacker.c b/libavformat/smacker.c index a96093b191..98436bd708 100644 --- a/libavformat/smacker.c +++ b/libavformat/smacker.c @@ -374,7 +374,7 @@ static int smacker_read_seek(AVFormatContext *s, int stream_index, return AVERROR(EINVAL); } - if ((ret = avio_seek(s->pb, s->internal->data_offset, SEEK_SET)) < 0) + if ((ret = avio_seek(s->pb, ffformatcontext(s)->data_offset, SEEK_SET)) < 0) return ret; smk->cur_frame = 0; diff --git a/libavformat/svs.c b/libavformat/svs.c index da63c8e370..e5300203f5 100644 --- a/libavformat/svs.c +++ b/libavformat/svs.c @@ -51,7 +51,6 @@ static int svs_read_header(AVFormatContext *s) pitch = avio_rl32(s->pb); avio_skip(s->pb, 12); - s->internal->data_offset = avio_tell(s->pb); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX; st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; diff --git a/libavformat/utils.c b/libavformat/utils.c index 67ec3384d0..58d4f09f35 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -135,7 +135,7 @@ void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type) void av_format_inject_global_side_data(AVFormatContext *s) { - s->internal->inject_global_side_data = 1; + ffformatcontext(s)->inject_global_side_data = 1; for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; st->internal->inject_global_side_data = 1; @@ -371,6 +371,7 @@ static int init_input(AVFormatContext *s, const char *filename, int avformat_queue_attached_pictures(AVFormatContext *s) { + FFFormatContext *const si = ffformatcontext(s); int ret; for (unsigned i = 0; i < s->nb_streams; i++) if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC && @@ -382,8 +383,8 @@ int avformat_queue_attached_pictures(AVFormatContext *s) continue; } - ret = avpriv_packet_list_put(&s->internal->raw_packet_buffer, - &s->internal->raw_packet_buffer_end, + ret = avpriv_packet_list_put(&si->raw_packet_buffer, + &si->raw_packet_buffer_end, &s->streams[i]->attached_pic, av_packet_ref, 0); if (ret < 0) @@ -457,14 +458,14 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options) { AVFormatContext *s = *ps; - AVFormatInternal *si; + FFFormatContext *si; int ret = 0; AVDictionary *tmp = NULL; ID3v2ExtraMeta *id3v2_extra_meta = NULL; if (!s && !(s = avformat_alloc_context())) return AVERROR(ENOMEM); - si = s->internal; + si = ffformatcontext(s); if (!s->av_class) { av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); return AVERROR(EINVAL); @@ -654,7 +655,7 @@ no_packet: } } - end= s->internal->raw_packet_buffer_remaining_size <= 0 + end = ffformatcontext(s)->raw_packet_buffer_remaining_size <= 0 || st->internal->probe_packets<= 0; if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { @@ -743,7 +744,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in int ff_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVStream *st; int err; @@ -960,7 +961,7 @@ static int has_decode_delay_been_guessed(AVStream *st) static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pktl) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); if (pktl->next) return pktl->next; if (pktl == si->packet_buffer_end) @@ -1042,7 +1043,7 @@ static void update_dts_from_pts(AVFormatContext *s, int stream_index, static void update_initial_timestamps(AVFormatContext *s, int stream_index, int64_t dts, int64_t pts, AVPacket *pkt) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVStream *st = s->streams[stream_index]; PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; PacketList *pktl_it; @@ -1096,7 +1097,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, static void update_initial_durations(AVFormatContext *s, AVStream *st, int stream_index, int64_t duration) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; int64_t cur_dts = RELATIVE_TS_BASE; @@ -1237,7 +1238,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, } } - if (pkt->duration > 0 && (s->internal->packet_buffer || s->internal->parse_queue)) + if (pkt->duration > 0 && (ffformatcontext(s)->packet_buffer || ffformatcontext(s)->parse_queue)) update_initial_durations(s, st, pkt->stream_index, pkt->duration); /* Correct timestamps with byte offset if demuxers only have timestamps @@ -1345,7 +1346,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index, int flush) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVPacket *out_pkt = si->parse_pkt; AVStream *st = s->streams[stream_index]; uint8_t *data = pkt->data; @@ -1459,7 +1460,7 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts) static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int ret, got_packet = 0; AVDictionary *metadata = NULL; @@ -1647,7 +1648,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) int av_read_frame(AVFormatContext *s, AVPacket *pkt) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); const int genpts = s->flags & AVFMT_FLAG_GENPTS; int eof = 0; int ret; @@ -1747,7 +1748,7 @@ return_packet: /* XXX: suppress the packet queue */ static void flush_packet_queue(AVFormatContext *s) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); avpriv_packet_list_free(&si->parse_queue, &si->parse_queue_end); avpriv_packet_list_free(&si->packet_buffer, &si->packet_buffer_end); avpriv_packet_list_free(&si->raw_packet_buffer, &si->raw_packet_buffer_end); @@ -1820,7 +1821,7 @@ void ff_read_frame_flush(AVFormatContext *s) for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) st->internal->pts_buffer[j] = AV_NOPTS_VALUE; - if (s->internal->inject_global_side_data) + if (ffformatcontext(s)->inject_global_side_data) st->internal->inject_global_side_data = 1; st->internal->skip_samples = 0; @@ -2191,7 +2192,7 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, av_log(s, AV_LOG_TRACE, "gen_seek: %d %s\n", stream_index, av_ts2str(target_ts)); if (ts_min == AV_NOPTS_VALUE) { - pos_min = s->internal->data_offset; + pos_min = ffformatcontext(s)->data_offset; ts_min = ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp); if (ts_min == AV_NOPTS_VALUE) return -1; @@ -2287,7 +2288,7 @@ static int seek_frame_byte(AVFormatContext *s, int stream_index, { int64_t pos_min, pos_max; - pos_min = s->internal->data_offset; + pos_min = ffformatcontext(s)->data_offset; pos_max = avio_size(s->pb) - 1; if (pos < pos_min) @@ -2319,7 +2320,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, return -1; if (index < 0 || index == st->internal->nb_index_entries - 1) { - AVPacket *pkt = s->internal->pkt; + AVPacket *pkt = ffformatcontext(s)->pkt; int nonkey = 0; if (st->internal->nb_index_entries) { @@ -2330,7 +2331,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, s->io_repositioned = 1; avpriv_update_cur_dts(s, st, ie->timestamp); } else { - if ((ret = avio_seek(s->pb, s->internal->data_offset, SEEK_SET)) < 0) + if ((ret = avio_seek(s->pb, ffformatcontext(s)->data_offset, SEEK_SET)) < 0) return ret; s->io_repositioned = 1; } @@ -2670,8 +2671,8 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) if (ic->duration == AV_NOPTS_VALUE && ic->bit_rate != 0) { int64_t filesize = ic->pb ? avio_size(ic->pb) : 0; - if (filesize > ic->internal->data_offset) { - filesize -= ic->internal->data_offset; + if (filesize > ffformatcontext(ic)->data_offset) { + filesize -= ffformatcontext(ic)->data_offset; for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; @@ -2696,7 +2697,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) /* only usable for MPEG-PS streams */ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) { - AVPacket *pkt = ic->internal->pkt; + AVPacket *pkt = ffformatcontext(ic)->pkt; int num, den, read_size, ret; int found_duration = 0; int is_end; @@ -3444,7 +3445,7 @@ fail: return ret; } -static int extract_extradata(AVFormatInternal *si, AVStream *st, const AVPacket *pkt) +static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt) { AVStreamInternal *sti = st->internal; AVPacket *pkt_ref = si->parse_pkt; @@ -3508,7 +3509,7 @@ static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { - AVFormatInternal *const si = ic->internal; + FFFormatContext *const si = ffformatcontext(ic); int count = 0, ret = 0; int64_t read_size; AVPacket *pkt1 = si->pkt; @@ -4259,11 +4260,11 @@ void ff_free_stream(AVFormatContext *s, AVStream *st) void avformat_free_context(AVFormatContext *s) { - AVFormatInternal *si; + FFFormatContext *si; if (!s) return; - si = s->internal; + si = ffformatcontext(s); if (s->oformat && s->oformat->deinit && si->initialized) s->oformat->deinit(s); @@ -4298,7 +4299,6 @@ void avformat_free_context(AVFormatContext *s) av_packet_free(&si->parse_pkt); av_freep(&s->streams); flush_packet_queue(s); - av_freep(&s->internal); av_freep(&s->url); av_free(s); } @@ -4399,7 +4399,7 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) st->sample_aspect_ratio = (AVRational) { 0, 1 }; - st->internal->inject_global_side_data = s->internal->inject_global_side_data; + st->internal->inject_global_side_data = ffformatcontext(s)->inject_global_side_data; st->internal->need_context_update = 1; @@ -4444,7 +4444,7 @@ AVProgram *av_new_program(AVFormatContext *ac, int id) AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVChapter *chapter = NULL; int ret; diff --git a/libavformat/vqf.c b/libavformat/vqf.c index 08dba858b4..1810fca8b9 100644 --- a/libavformat/vqf.c +++ b/libavformat/vqf.c @@ -280,7 +280,7 @@ static int vqf_read_seek(AVFormatContext *s, st->internal->cur_dts = av_rescale(pos, st->time_base.den, st->codecpar->bit_rate * (int64_t)st->time_base.num); - if ((ret = avio_seek(s->pb, ((pos-7) >> 3) + s->internal->data_offset, SEEK_SET)) < 0) + if ((ret = avio_seek(s->pb, ((pos-7) >> 3) + ffformatcontext(s)->data_offset, SEEK_SET)) < 0) return ret; c->remaining_bits = -7 - ((pos-7)&7); diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 30c9ac37f8..815d189671 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -549,7 +549,7 @@ static int wav_read_header(AVFormatContext *s) case MKTAG('I', 'D', '3', ' '): case MKTAG('i', 'd', '3', ' '): { ID3v2ExtraMeta *id3v2_extra_meta; - ff_id3v2_read_dict(pb, &s->internal->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); + ff_id3v2_read_dict(pb, &ffformatcontext(s)->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); if (id3v2_extra_meta) { ff_id3v2_parse_apic(s, id3v2_extra_meta); ff_id3v2_parse_chapters(s, id3v2_extra_meta); diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index f4d0db83a4..24390e8e74 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -125,8 +125,8 @@ fail: // This ensures that the timestamps will already be properly shifted // when the packets arrive here, so we don't need to shift again. s->avoid_negative_ts = oc->avoid_negative_ts; - s->internal->avoid_negative_ts_use_pts = - oc->internal->avoid_negative_ts_use_pts; + ffformatcontext(s)->avoid_negative_ts_use_pts = + ffformatcontext(oc)->avoid_negative_ts_use_pts; oc->avoid_negative_ts = 0; return 0; diff --git a/libavformat/yop.c b/libavformat/yop.c index 8ecdc654a9..f65e4f8b16 100644 --- a/libavformat/yop.c +++ b/libavformat/yop.c @@ -187,7 +187,7 @@ static int yop_read_seek(AVFormatContext *s, int stream_index, if (!stream_index) return -1; - pos_min = s->internal->data_offset; + pos_min = ffformatcontext(s)->data_offset; pos_max = avio_size(s->pb) - yop->frame_size; frame_count = (pos_max - pos_min) / yop->frame_size; diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c index 69dd8a3165..b24275acc1 100644 --- a/libavformat/yuv4mpegdec.c +++ b/libavformat/yuv4mpegdec.c @@ -255,7 +255,7 @@ static int yuv4_read_header(AVFormatContext *s) s->packet_size = av_image_get_buffer_size(st->codecpar->format, width, height, 1) + Y4M_FRAME_MAGIC_LEN; if ((int) s->packet_size < 0) return s->packet_size; - s->internal->data_offset = data_offset = avio_tell(pb); + ffformatcontext(s)->data_offset = data_offset = avio_tell(pb); st->duration = (avio_size(pb) - data_offset) / s->packet_size; @@ -293,7 +293,7 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO); } pkt->stream_index = 0; - pkt->pts = (off - s->internal->data_offset) / s->packet_size; + pkt->pts = (off - ffformatcontext(s)->data_offset) / s->packet_size; pkt->duration = 1; return 0; } @@ -309,7 +309,7 @@ static int yuv4_read_seek(AVFormatContext *s, int stream_index, return -1; pos = pts * s->packet_size; - if (avio_seek(s->pb, pos + s->internal->data_offset, SEEK_SET) < 0) + if (avio_seek(s->pb, pos + ffformatcontext(s)->data_offset, SEEK_SET) < 0) return -1; return 0; } From patchwork Fri Aug 27 14:27:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29818 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1514840iov; Fri, 27 Aug 2021 07:31:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4VGG7mKgzpsRwXX9imfBJ4pYyhEkX5GNZ/6njWaT+TMWJctmsCLEpGPvz9mUjhYkS+7mN X-Received: by 2002:a05:6402:48e:: with SMTP id k14mr10257514edv.212.1630074689603; Fri, 27 Aug 2021 07:31:29 -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 c11si6538503ejm.510.2021.08.27.07.31.29; Fri, 27 Aug 2021 07:31:29 -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=AOe2ZoE1; 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 4B84368A5F3; Fri, 27 Aug 2021 17:28:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067018.outbound.protection.outlook.com [40.92.67.18]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B8E8268A56A for ; Fri, 27 Aug 2021 17:28:04 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KER96YMxTLhfcX2q+wsnSN6KN+tTuPvl/nbekmWxOr4fmKo296GkLrXkxFFIiX0gPG5qtWJ7OQldaf3YANrpXaIF3eDOmJY+OziZ9b1ZNScwAMSd3uRnkfakVbrhxDzb+CGIpEPRRIMMJNX8NT75DnIpJtrAWVlEmph/wUuA5z+1xUzEiSE8VrGipq2xXG6XCB600IE8vbuEayi1hD6Q9PKXNdfR2vqLWzStEkx+HdUJDP70gvU6N5nzCfPkniJKmCJOnNBkQK0UcYInUzaBe2Va/nhi+Xu65hizm5z3I0wHC+dMm5HdwwCUAhd/XmZ3bNr78mXQmC6FDPZTBTfl5g== 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=IKItTrgU4lGhneQQwJq9pcsW9GRH1Q0oiCHjgQpCqxU=; b=bi9zJxJ+jmZRmlwEU8ljbuJHA2p4p7bLJJTlTpIdvNpTHdmElUWf0Y8mXDe32O/u/sSYVbPPfVaDUQl6/Ek1Dfai4R39cEg9CsV97ds4baxoNkEE2BhGfrFNrh5oGC4uOUvYacgfFp8oWSDULOmzAxrtyTfbgIotIHkGb+A+cbL4rzPPp5LDbTTaERxDRsjLg3iRYPAKLgAx58yJksXBcMXaaKaIeFASbO0SACoxVO10WxMU6yKj2UMtftR70rs9dlbwHrVlRRLvzYr6m/E4+2bnH+LnUwXj3fggG/+xURE9I0V4PD8B++nI//WnTCsp487L+QqwN5An3hzuKlSA3Q== 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=IKItTrgU4lGhneQQwJq9pcsW9GRH1Q0oiCHjgQpCqxU=; b=AOe2ZoE1YOxAnOhLuncMnVJxwlOImc4Pzme5js9ho9lZ1eWjMh/0ar5jXDqXjXBQZ2bf3lS+7F4Oi1ei/iN5qlgoGD5CM/c59GwUXtCo6CztCiA2fcdP26OkoVW7HvYNkipbB2ZFkKHT2iid1Z2UwQ+nYkhlTUl891ewiO1TOCBdsYvza8ebClVEdvoi1wrshNHSEMcFF4neFgPMr52Nex83L1bvrAuF9En23VzUjhexE2FNmc1upJ+owRJefnwfC9JivYnkTpINXRdRMqjwEFj6rnIn9uYRZSLNn0Vi2LH8srXOW/Z2VEJLDPQGXRRsVXQSovmTkiZnbJ91TbXRHw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3861.eurprd03.prod.outlook.com (2603:10a6:20b:22::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Fri, 27 Aug 2021 14:28:01 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:28:01 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:21 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [X+QMifrB7don01CB1PAyPY6dnCHpcei4] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-20-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:28:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f2a09aef-fe7f-4258-e3e5-08d96966dfb5 X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEtNCKoPT6rtVE5PzvjguT+v/RUzqK8pO0Ozox7CNEtzSS9KS+nObw5TaXs9WlYWhoRaz5dIuQIjOZoA4feMwmrR5V9s+8KBhCbVdIwx6o0ySw65IJKtWL5Cfx6/eaHsGygyD9wy8ztSriDMhx60TqUEFGXIoVd2EuKxIp8jwXdz2HeH2yd+F7llspnBHDEJcJgHg1bP6/JDaf9dnW7skNhoftKHc9diL89azP1xCi8WWFJnPs3FpAIdEm4vdkyTtWNMIoQHaqfqSOG/+UKEQ/6wxaqW/+7lckhty62aarc2bhiid/JPFoVzh8KSPl4rLSu9I9e8+dVNdbFoElrxmDei8QqRPSzcDcFo8CwAUja7KeOxtiz8GEunrK6ID8XX80MI7PP/awQheY9dzlI37yZwK56kKws/xySP1+IzJt0cdiN1fYPsyTRueY+ARm7LR4PW6rBdspLKpMReJx/IkuTg4OseD9cCdFYkG0znwZuPazVnDS6eaOJTfAkbd8GIYq2GL8qsTWFsWnKnuZD8/Mu9cx/12oJB/DMPotXxKXBI35styMQkmMNtpDJrG0IH53h+YjrnfN02xHNA8DJdoMog2zEaqX1vV/FGhJxyvbAiMY8MumRdPuKbkqKgwPExJTLWtVV0+jeHJtaQHP1HlmRYDartwfMVIUkQnCZHSiGXZCl04o/E4HCdRXdi7cATq9PSs+uFI5C2Ii3EuejM6fDwf5rC3NKKxdxej0wcSM0ZJKhMxzgFdpyWezVjLuHrHDX30Bi1vLmNzm9fSlzb7Tns X-MS-TrafficTypeDiagnostic: AM6PR03MB3861: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zgf3Ji8KVsw0Dall8CJwyQGxfu9MMTE5H7EOrkgqDanF/ACuglMc5J214Ksj1OaFTDwj7YqCxGj+o1qRk+P6X+hVcG1wNstcZmNDkgGdqYiqcw2jP1oXt5wmhHBlDDvR0RZOGnmWLuOfvMj8bDGLoy7PASwfyamyPTBdW96pK5Rin2mcHjC6lK7Tn0c9MUcb/fqtTJ4E9OKfN6si/h+MrF46EXW0AhdYDx3mI4/A173yKJi1wlaKLIEFqn8nEY024wfaDch/kdCpwC9gR3yBzLe53uqz6C9exdknZEaTVIJqk868sCWtEgCPLRTTNybzZVxlnwP6stoocjD7hUrzl0tg3gNiibap6Wz0IRlczVmVrvhob4hWAHYwcli5xIzywj7cQe1dz/9wnRxbV1vWQgbzN/zbKqd5lCeUUEAn0PSvd0BLsvQySAq9F8UmymJ8 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VfpQJLSNx/C3D9bSq4ge0YOKKFkkuleZoGAK6STyOptG6Fd35yR/svC0OJFIdPxqbuiyvQpErRnyNiWBxOgJaNj3MQR9ykn0buJaeIOTpj9GjPz9A9BaOKC0vmYPa48OrR9Gjzhg7sExUQ2mOH1AtQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2a09aef-fe7f-4258-e3e5-08d96966dfb5 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:28:01.5952 (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: AM6PR03MB3861 Subject: [FFmpeg-devel] [PATCH 21/25] avformat/mux, utils: Use dedicated pointer for AVStreamInternal 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: pxtXfvZhgwcB This gets rid of ugly "->internal" and is in preparation for removing AVStreamInternal altogether. Signed-off-by: Andreas Rheinhardt --- libavformat/mux.c | 94 ++--- libavformat/utils.c | 891 +++++++++++++++++++++++--------------------- 2 files changed, 521 insertions(+), 464 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index c2a1dc8a28..fc3469c287 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -384,6 +384,7 @@ static int init_pts(AVFormatContext *s) /* init PTS generation */ for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *const st = s->streams[i]; + AVStreamInternal *const sti = st->internal; int64_t den = AV_NOPTS_VALUE; switch (st->codecpar->codec_type) { @@ -397,16 +398,16 @@ static int init_pts(AVFormatContext *s) break; } - if (!st->internal->priv_pts) - st->internal->priv_pts = av_mallocz(sizeof(*st->internal->priv_pts)); - if (!st->internal->priv_pts) + if (!sti->priv_pts) + sti->priv_pts = av_mallocz(sizeof(*sti->priv_pts)); + if (!sti->priv_pts) return AVERROR(ENOMEM); if (den != AV_NOPTS_VALUE) { if (den <= 0) return AVERROR_INVALIDDATA; - frac_init(st->internal->priv_pts, 0, 0, den); + frac_init(sti->priv_pts, 0, 0, den); } } @@ -504,6 +505,7 @@ FF_DISABLE_DEPRECATION_WARNINGS //FIXME merge with compute_pkt_fields static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { + AVStreamInternal *const sti = st->internal; int delay = st->codecpar->video_delay; int frame_size; @@ -520,7 +522,7 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * if (s->debug & FF_FDEBUG_TS) av_log(s, AV_LOG_DEBUG, "compute_muxer_pkt_fields: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n", - av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->internal->cur_dts), delay, pkt->size, pkt->stream_index); + av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), delay, pkt->size, pkt->stream_index); if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0) pkt->pts = pkt->dts; @@ -534,28 +536,28 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * } pkt->dts = // pkt->pts= st->cur_dts; - pkt->pts = st->internal->priv_pts->val; + pkt->pts = sti->priv_pts->val; } //calculate dts from pts if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { - st->internal->pts_buffer[0] = pkt->pts; - for (int i = 1; i < delay + 1 && st->internal->pts_buffer[i] == AV_NOPTS_VALUE; i++) - st->internal->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration; - for (int i = 0; iinternal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) - FFSWAP(int64_t, st->internal->pts_buffer[i], st->internal->pts_buffer[i + 1]); + sti->pts_buffer[0] = pkt->pts; + for (int i = 1; i < delay + 1 && sti->pts_buffer[i] == AV_NOPTS_VALUE; i++) + sti->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration; + for (int i = 0; ipts_buffer[i] > sti->pts_buffer[i + 1]; i++) + FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]); - pkt->dts = st->internal->pts_buffer[0]; + pkt->dts = sti->pts_buffer[0]; } - if (st->internal->cur_dts && st->internal->cur_dts != AV_NOPTS_VALUE && + if (sti->cur_dts && sti->cur_dts != AV_NOPTS_VALUE && ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE && st->codecpar->codec_type != AVMEDIA_TYPE_DATA && - st->internal->cur_dts >= pkt->dts) || st->internal->cur_dts > pkt->dts)) { + sti->cur_dts >= pkt->dts) || sti->cur_dts > pkt->dts)) { av_log(s, AV_LOG_ERROR, "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n", - st->index, av_ts2str(st->internal->cur_dts), av_ts2str(pkt->dts)); + st->index, av_ts2str(sti->cur_dts), av_ts2str(pkt->dts)); return AVERROR(EINVAL); } if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) { @@ -570,8 +572,8 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * av_log(s, AV_LOG_DEBUG, "av_write_frame: pts2:%s dts2:%s\n", av_ts2str(pkt->pts), av_ts2str(pkt->dts)); - st->internal->cur_dts = pkt->dts; - st->internal->priv_pts->val = pkt->dts; + sti->cur_dts = pkt->dts; + sti->priv_pts->val = pkt->dts; /* update pts */ switch (st->codecpar->codec_type) { @@ -583,12 +585,12 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * /* HACK/FIXME, we skip the initial 0 size packets as they are most * likely equal to the encoder delay, but it would be better if we * had the real timestamps from the encoder */ - if (frame_size >= 0 && (pkt->size || st->internal->priv_pts->num != st->internal->priv_pts->den >> 1 || st->internal->priv_pts->val)) { - frac_add(st->internal->priv_pts, (int64_t)st->time_base.den * frame_size); + if (frame_size >= 0 && (pkt->size || sti->priv_pts->num != sti->priv_pts->den >> 1 || sti->priv_pts->val)) { + frac_add(sti->priv_pts, (int64_t)st->time_base.den * frame_size); } break; case AVMEDIA_TYPE_VIDEO: - frac_add(st->internal->priv_pts, (int64_t)st->time_base.den * st->time_base.num); + frac_add(sti->priv_pts, (int64_t)st->time_base.den * st->time_base.num); break; } return 0; @@ -654,7 +656,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) if (s->avoid_negative_ts > 0) { FFFormatContext *const si = ffformatcontext(s); AVStream *st = s->streams[pkt->stream_index]; - int64_t offset = st->internal->mux_ts_offset; + AVStreamInternal *const sti = st->internal; + int64_t offset = sti->mux_ts_offset; int64_t ts = si->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; if (si->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE && @@ -664,7 +667,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (si->offset != AV_NOPTS_VALUE && !offset) { - offset = st->internal->mux_ts_offset = + offset = sti->mux_ts_offset = av_rescale_q_rnd(si->offset, si->offset_timebase, st->time_base, @@ -737,13 +740,14 @@ static int check_packet(AVFormatContext *s, AVPacket *pkt) static int prepare_input_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt) { + AVStreamInternal *const sti = st->internal; #if !FF_API_COMPUTE_PKT_FIELDS2 /* sanitize the timestamps */ if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) { /* when there is no reordering (so dts is equal to pts), but * only one of them is set, set the other as well */ - if (!st->internal->reorder) { + if (!sti->reorder) { if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE) pkt->pts = pkt->dts; if (pkt->dts == AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) @@ -759,13 +763,13 @@ static int prepare_input_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt) /* check that the dts are increasing (or at least non-decreasing, * if the format allows it */ - if (st->internal->cur_dts != AV_NOPTS_VALUE && - ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && st->internal->cur_dts >= pkt->dts) || - st->internal->cur_dts > pkt->dts)) { + if (sti->cur_dts != AV_NOPTS_VALUE && + ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && sti->cur_dts >= pkt->dts) || + sti->cur_dts > pkt->dts)) { av_log(s, AV_LOG_ERROR, "Application provided invalid, non monotonically increasing " "dts to muxer in stream %d: %" PRId64 " >= %" PRId64 "\n", - st->index, st->internal->cur_dts, pkt->dts); + st->index, sti->cur_dts, pkt->dts); return AVERROR(EINVAL); } @@ -777,7 +781,7 @@ static int prepare_input_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt) } #endif /* update flags */ - if (st->internal->is_intra_only) + if (sti->is_intra_only) pkt->flags |= AV_PKT_FLAG_KEY; return 0; @@ -792,6 +796,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, FFFormatContext *const si = ffformatcontext(s); PacketList **next_point, *this_pktl; AVStream *st = s->streams[pkt->stream_index]; + AVStreamInternal *const sti = st->internal; int chunked = s->max_chunk_size || s->max_chunk_duration; this_pktl = av_malloc(sizeof(PacketList)); @@ -808,27 +813,27 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, av_packet_move_ref(&this_pktl->pkt, pkt); pkt = &this_pktl->pkt; - if (st->internal->last_in_packet_buffer) { - next_point = &(st->internal->last_in_packet_buffer->next); + if (sti->last_in_packet_buffer) { + next_point = &(sti->last_in_packet_buffer->next); } else { next_point = &si->packet_buffer; } if (chunked) { uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP); - st->internal->interleaver_chunk_size += pkt->size; - st->internal->interleaver_chunk_duration += pkt->duration; - if ( (s->max_chunk_size && st->internal->interleaver_chunk_size > s->max_chunk_size) - || (max && st->internal->interleaver_chunk_duration > max)) { - st->internal->interleaver_chunk_size = 0; + sti->interleaver_chunk_size += pkt->size; + sti->interleaver_chunk_duration += pkt->duration; + if ( (s->max_chunk_size && sti->interleaver_chunk_size > s->max_chunk_size) + || (max && sti->interleaver_chunk_duration > max)) { + sti->interleaver_chunk_size = 0; pkt->flags |= CHUNK_START; - if (max && st->internal->interleaver_chunk_duration > max) { + if (max && sti->interleaver_chunk_duration > max) { int64_t syncoffset = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)*max/2; int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset; - st->internal->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max; + sti->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max; } else - st->internal->interleaver_chunk_duration = 0; + sti->interleaver_chunk_duration = 0; } } if (*next_point) { @@ -853,7 +858,7 @@ next_non_null: this_pktl->next = *next_point; - st->internal->last_in_packet_buffer = *next_point = this_pktl; + sti->last_in_packet_buffer = *next_point = this_pktl; return 0; } @@ -964,6 +969,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, PacketList *pktl = si->packet_buffer; AVPacket *const top_pkt = &pktl->pkt; AVStream *const st = s->streams[top_pkt->stream_index]; + AVStreamInternal *const sti = st->internal; int64_t top_dts = av_rescale_q(top_pkt->dts, st->time_base, AV_TIME_BASE_Q); @@ -974,8 +980,8 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (!si->packet_buffer) si->packet_buffer_end = NULL; - if (st->internal->last_in_packet_buffer == pktl) - st->internal->last_in_packet_buffer = NULL; + if (sti->last_in_packet_buffer == pktl) + sti->last_in_packet_buffer = NULL; av_packet_unref(&pktl->pkt); av_freep(&pktl); @@ -986,14 +992,16 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (stream_count && flush) { PacketList *pktl = si->packet_buffer; AVStream *const st = s->streams[pktl->pkt.stream_index]; + AVStreamInternal *const sti = st->internal; + *out = pktl->pkt; si->packet_buffer = pktl->next; if (!si->packet_buffer) si->packet_buffer_end = NULL; - if (st->internal->last_in_packet_buffer == pktl) - st->internal->last_in_packet_buffer = NULL; + if (sti->last_in_packet_buffer == pktl) + sti->last_in_packet_buffer = NULL; av_freep(&pktl); return 1; diff --git a/libavformat/utils.c b/libavformat/utils.c index 58d4f09f35..ec37a6115e 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -103,13 +103,14 @@ static int is_relative(int64_t ts) { */ static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) { - if (st->internal->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 && - st->internal->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { - if (st->internal->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && - timestamp < st->internal->pts_wrap_reference) + const AVStreamInternal *const sti = st->internal; + if (sti->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 && + sti->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { + if (sti->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && + timestamp < sti->pts_wrap_reference) return timestamp + (1ULL << st->pts_wrap_bits); - else if (st->internal->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && - timestamp >= st->internal->pts_wrap_reference) + else if (sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && + timestamp >= sti->pts_wrap_reference) return timestamp - (1ULL << st->pts_wrap_bits); } return timestamp; @@ -312,21 +313,22 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); if (fmt) { + AVStreamInternal *const sti = st->internal; av_log(s, AV_LOG_DEBUG, "Probe with size=%d, packets=%d detected %s with score=%d\n", - pd->buf_size, s->max_probe_packets - st->internal->probe_packets, + pd->buf_size, s->max_probe_packets - sti->probe_packets, fmt->name, score); for (int i = 0; fmt_id_type[i].name; i++) { if (!strcmp(fmt->name, fmt_id_type[i].name)) { if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) continue; - if (st->internal->request_probe > score && + if (sti->request_probe > score && st->codecpar->codec_id != fmt_id_type[i].id) continue; st->codecpar->codec_id = fmt_id_type[i].id; st->codecpar->codec_type = fmt_id_type[i].type; - st->internal->need_context_update = 1; + sti->need_context_update = 1; return score; } } @@ -433,22 +435,23 @@ static int update_stream_avctx(AVFormatContext *s) int ret; for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; + AVStreamInternal *const sti = st->internal; - if (!st->internal->need_context_update) + if (!sti->need_context_update) continue; /* close parser, because it depends on the codec */ - if (st->internal->parser && st->internal->avctx->codec_id != st->codecpar->codec_id) { - av_parser_close(st->internal->parser); - st->internal->parser = NULL; + if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { + av_parser_close(sti->parser); + sti->parser = NULL; } /* update internal codec context, for the parser */ - ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar); + ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); if (ret < 0) return ret; - st->internal->need_context_update = 0; + sti->need_context_update = 0; } return 0; } @@ -628,11 +631,12 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { - if (st->internal->request_probe>0) { - AVProbeData *pd = &st->internal->probe_data; + AVStreamInternal *const sti = st->internal; + if (sti->request_probe > 0) { + AVProbeData *pd = &sti->probe_data; int end; - av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, st->internal->probe_packets); - --st->internal->probe_packets; + av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, sti->probe_packets); + --sti->probe_packets; if (pkt) { uint8_t *new_buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); @@ -648,7 +652,7 @@ static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) memset(pd->buf + pd->buf_size, 0, AVPROBE_PADDING_SIZE); } else { no_packet: - st->internal->probe_packets = 0; + sti->probe_packets = 0; if (!pd->buf_size) { av_log(s, AV_LOG_WARNING, "nothing to probe for stream %d\n", st->index); @@ -656,7 +660,7 @@ no_packet: } end = ffformatcontext(s)->raw_packet_buffer_remaining_size <= 0 - || st->internal->probe_packets<= 0; + || sti->probe_packets<= 0; if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { int score = set_codec_from_probe_data(s, st, pd); @@ -664,7 +668,7 @@ no_packet: || end) { pd->buf_size = 0; av_freep(&pd->buf); - st->internal->request_probe = -1; + sti->request_probe = -1; if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); } else @@ -678,6 +682,7 @@ no_packet: static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) { + AVStreamInternal *const sti = st->internal; int64_t ref = pkt->dts; int pts_wrap_behavior; int64_t pts_wrap_reference; @@ -685,7 +690,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in if (ref == AV_NOPTS_VALUE) ref = pkt->pts; - if (st->internal->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) + if (sti->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) return 0; ref &= (1LL << st->pts_wrap_bits)-1; @@ -700,17 +705,19 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in if (!first_program) { int default_stream_index = av_find_default_stream_index(s); - if (s->streams[default_stream_index]->internal->pts_wrap_reference == AV_NOPTS_VALUE) { + AVStreamInternal *const default_sti = s->streams[default_stream_index]->internal; + if (default_sti->pts_wrap_reference == AV_NOPTS_VALUE) { for (unsigned i = 0; i < s->nb_streams; i++) { + AVStreamInternal *const sti = s->streams[i]->internal; if (av_find_program_from_stream(s, NULL, i)) continue; - s->streams[i]->internal->pts_wrap_reference = pts_wrap_reference; - s->streams[i]->internal->pts_wrap_behavior = pts_wrap_behavior; + sti->pts_wrap_reference = pts_wrap_reference; + sti->pts_wrap_behavior = pts_wrap_behavior; } } else { - st->internal->pts_wrap_reference = s->streams[default_stream_index]->internal->pts_wrap_reference; - st->internal->pts_wrap_behavior = s->streams[default_stream_index]->internal->pts_wrap_behavior; + sti->pts_wrap_reference = default_sti->pts_wrap_reference; + sti->pts_wrap_behavior = default_sti->pts_wrap_behavior; } } else { @@ -729,8 +736,9 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in while (program) { if (program->pts_wrap_reference != pts_wrap_reference) { for (unsigned i = 0; i < program->nb_stream_indexes; i++) { - s->streams[program->stream_index[i]]->internal->pts_wrap_reference = pts_wrap_reference; - s->streams[program->stream_index[i]]->internal->pts_wrap_behavior = pts_wrap_behavior; + AVStreamInternal *const sti = s->streams[program->stream_index[i]]->internal; + sti->pts_wrap_reference = pts_wrap_reference; + sti->pts_wrap_behavior = pts_wrap_behavior; } program->pts_wrap_reference = pts_wrap_reference; @@ -760,6 +768,7 @@ FF_ENABLE_DEPRECATION_WARNINGS for (;;) { PacketList *pktl = si->raw_packet_buffer; + AVStreamInternal *sti; const AVPacket *pkt1; if (pktl) { @@ -788,10 +797,11 @@ FF_ENABLE_DEPRECATION_WARNINGS return err; for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *const st = s->streams[i]; - if (st->internal->probe_packets || st->internal->request_probe > 0) + AVStreamInternal *const sti = st->internal; + if (sti->probe_packets || sti->request_probe > 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; - av_assert0(st->internal->request_probe <= 0); + av_assert0(sti->request_probe <= 0); } continue; } @@ -818,15 +828,16 @@ FF_ENABLE_DEPRECATION_WARNINGS "Invalid stream index.\n"); st = s->streams[pkt->stream_index]; + sti = st->internal; - if (update_wrap_reference(s, st, pkt->stream_index, pkt) && st->internal->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { + if (update_wrap_reference(s, st, pkt->stream_index, pkt) && sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { // correct first time stamps to negative values - if (!is_relative(st->internal->first_dts)) - st->internal->first_dts = wrap_timestamp(st, st->internal->first_dts); + if (!is_relative(sti->first_dts)) + sti->first_dts = wrap_timestamp(st, sti->first_dts); if (!is_relative(st->start_time)) st->start_time = wrap_timestamp(st, st->start_time); - if (!is_relative(st->internal->cur_dts)) - st->internal->cur_dts = wrap_timestamp(st, st->internal->cur_dts); + if (!is_relative(sti->cur_dts)) + sti->cur_dts = wrap_timestamp(st, sti->cur_dts); } pkt->dts = wrap_timestamp(st, pkt->dts); @@ -838,7 +849,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (s->use_wallclock_as_timestamps) pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base); - if (!pktl && st->internal->request_probe <= 0) + if (!pktl && sti->request_probe <= 0) return 0; err = avpriv_packet_list_put(&si->raw_packet_buffer, @@ -879,7 +890,8 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt) { - AVRational codec_framerate = st->internal->avctx->framerate; + AVStreamInternal *const sti = st->internal; + AVRational codec_framerate = sti->avctx->framerate; int frame_size, sample_rate; *pnum = 0; @@ -893,10 +905,10 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, *pnum = st->time_base.num; *pden = st->time_base.den; } else if (codec_framerate.den * 1000LL > codec_framerate.num) { - av_assert0(st->internal->avctx->ticks_per_frame); + av_assert0(sti->avctx->ticks_per_frame); av_reduce(pnum, pden, codec_framerate.den, - codec_framerate.num * (int64_t)st->internal->avctx->ticks_per_frame, + codec_framerate.num * (int64_t)sti->avctx->ticks_per_frame, INT_MAX); if (pc && pc->repeat_pict) { @@ -908,14 +920,14 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, /* If this codec can be interlaced or progressive then we need * a parser to compute duration of a packet. Thus if we have * no parser in such case leave duration undefined. */ - if (st->internal->avctx->ticks_per_frame > 1 && !pc) + if (sti->avctx->ticks_per_frame > 1 && !pc) *pnum = *pden = 0; } break; case AVMEDIA_TYPE_AUDIO: - if (st->internal->avctx_inited) { - frame_size = av_get_audio_frame_duration(st->internal->avctx, pkt->size); - sample_rate = st->internal->avctx->sample_rate; + if (sti->avctx_inited) { + frame_size = av_get_audio_frame_duration(sti->avctx, pkt->size); + sample_rate = sti->avctx->sample_rate; } else { frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size); sample_rate = st->codecpar->sample_rate; @@ -943,20 +955,21 @@ int ff_is_intra_only(enum AVCodecID id) static int has_decode_delay_been_guessed(AVStream *st) { + AVStreamInternal *const sti = st->internal; if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; - if (!st->internal->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy + if (!sti->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy return 1; #if CONFIG_H264_DECODER - if (st->internal->avctx->has_b_frames && - avpriv_h264_has_num_reorder_frames(st->internal->avctx) == st->internal->avctx->has_b_frames) + if (sti->avctx->has_b_frames && + avpriv_h264_has_num_reorder_frames(sti->avctx) == sti->avctx->has_b_frames) return 1; #endif - if (st->internal->avctx->has_b_frames<3) - return st->internal->nb_decoded_frames >= 7; - else if (st->internal->avctx->has_b_frames<4) - return st->internal->nb_decoded_frames >= 18; + if (sti->avctx->has_b_frames<3) + return sti->nb_decoded_frames >= 7; + else if (sti->avctx->has_b_frames<4) + return sti->nb_decoded_frames >= 18; else - return st->internal->nb_decoded_frames >= 20; + return sti->nb_decoded_frames >= 20; } static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pktl) @@ -970,18 +983,18 @@ static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pk } static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts) { + AVStreamInternal *const sti = st->internal; int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && st->codecpar->codec_id != AV_CODEC_ID_HEVC; if(!onein_oneout) { - int delay = st->internal->avctx->has_b_frames; - int i; + int delay = sti->avctx->has_b_frames; if (dts == AV_NOPTS_VALUE) { int64_t best_score = INT64_MAX; - for (i = 0; iinternal->pts_reorder_error_count[i]) { - int64_t score = st->internal->pts_reorder_error[i] / st->internal->pts_reorder_error_count[i]; + for (int i = 0; i < delay; i++) { + if (sti->pts_reorder_error_count[i]) { + int64_t score = sti->pts_reorder_error[i] / sti->pts_reorder_error_count[i]; if (score < best_score) { best_score = score; dts = pts_buffer[i]; @@ -992,13 +1005,13 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t for (int i = 0; i < delay; i++) { if (pts_buffer[i] != AV_NOPTS_VALUE) { int64_t diff = FFABS(pts_buffer[i] - dts) - + (uint64_t)st->internal->pts_reorder_error[i]; - diff = FFMAX(diff, st->internal->pts_reorder_error[i]); - st->internal->pts_reorder_error[i] = diff; - st->internal->pts_reorder_error_count[i]++; - if (st->internal->pts_reorder_error_count[i] > 250) { - st->internal->pts_reorder_error[i] >>= 1; - st->internal->pts_reorder_error_count[i] >>= 1; + + (uint64_t)sti->pts_reorder_error[i]; + diff = FFMAX(diff, sti->pts_reorder_error[i]); + sti->pts_reorder_error[i] = diff; + sti->pts_reorder_error_count[i]++; + if (sti->pts_reorder_error_count[i] > 250) { + sti->pts_reorder_error[i] >>= 1; + sti->pts_reorder_error_count[i] >>= 1; } } } @@ -1045,22 +1058,23 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, { FFFormatContext *const si = ffformatcontext(s); AVStream *st = s->streams[stream_index]; + AVStreamInternal *const sti = st->internal; PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; PacketList *pktl_it; uint64_t shift; - if (st->internal->first_dts != AV_NOPTS_VALUE || + if (sti->first_dts != AV_NOPTS_VALUE || dts == AV_NOPTS_VALUE || - st->internal->cur_dts == AV_NOPTS_VALUE || - st->internal->cur_dts < INT_MIN + RELATIVE_TS_BASE || - dts < INT_MIN + (st->internal->cur_dts - RELATIVE_TS_BASE) || + sti->cur_dts == AV_NOPTS_VALUE || + sti->cur_dts < INT_MIN + RELATIVE_TS_BASE || + dts < INT_MIN + (sti->cur_dts - RELATIVE_TS_BASE) || is_relative(dts)) return; - st->internal->first_dts = dts - (st->internal->cur_dts - RELATIVE_TS_BASE); - st->internal->cur_dts = dts; - shift = (uint64_t)st->internal->first_dts - RELATIVE_TS_BASE; + sti->first_dts = dts - (sti->cur_dts - RELATIVE_TS_BASE); + sti->cur_dts = dts; + shift = (uint64_t)sti->first_dts - RELATIVE_TS_BASE; if (is_relative(pts)) pts += shift; @@ -1077,7 +1091,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) { st->start_time = pktl_it->pkt.pts; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) - st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->internal->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); + st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); } } @@ -1090,7 +1104,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, st->start_time = pts; } if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) - st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->internal->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); + st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); } } @@ -1098,14 +1112,15 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, int stream_index, int64_t duration) { FFFormatContext *const si = ffformatcontext(s); + AVStreamInternal *const sti = st->internal; PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; int64_t cur_dts = RELATIVE_TS_BASE; - if (st->internal->first_dts != AV_NOPTS_VALUE) { - if (st->internal->update_initial_durations_done) + if (sti->first_dts != AV_NOPTS_VALUE) { + if (sti->update_initial_durations_done) return; - st->internal->update_initial_durations_done = 1; - cur_dts = st->internal->first_dts; + sti->update_initial_durations_done = 1; + cur_dts = sti->first_dts; for (; pktl; pktl = get_next_pkt(s, st, pktl)) { if (pktl->pkt.stream_index == stream_index) { if (pktl->pkt.pts != pktl->pkt.dts || @@ -1115,18 +1130,18 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, cur_dts -= duration; } } - if (pktl && pktl->pkt.dts != st->internal->first_dts) { + if (pktl && pktl->pkt.dts != sti->first_dts) { av_log(s, AV_LOG_DEBUG, "first_dts %s not matching first dts %s (pts %s, duration %"PRId64") in the queue\n", - av_ts2str(st->internal->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration); + av_ts2str(sti->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration); return; } if (!pktl) { - av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(st->internal->first_dts)); + av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(sti->first_dts)); return; } pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; - st->internal->first_dts = cur_dts; - } else if (st->internal->cur_dts != RELATIVE_TS_BASE) + sti->first_dts = cur_dts; + } else if (sti->cur_dts != RELATIVE_TS_BASE) return; for (; pktl; pktl = get_next_pkt(s, st, pktl)) { @@ -1135,13 +1150,13 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, if ((pktl->pkt.pts == pktl->pkt.dts || pktl->pkt.pts == AV_NOPTS_VALUE) && (pktl->pkt.dts == AV_NOPTS_VALUE || - pktl->pkt.dts == st->internal->first_dts || + pktl->pkt.dts == sti->first_dts || pktl->pkt.dts == RELATIVE_TS_BASE) && !pktl->pkt.duration && av_sat_add64(cur_dts, duration) == cur_dts + (uint64_t)duration ) { pktl->pkt.dts = cur_dts; - if (!st->internal->avctx->has_b_frames) + if (!sti->avctx->has_b_frames) pktl->pkt.pts = cur_dts; pktl->pkt.duration = duration; } else @@ -1149,14 +1164,15 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, cur_dts = pktl->pkt.dts + pktl->pkt.duration; } if (!pktl) - st->internal->cur_dts = cur_dts; + sti->cur_dts = cur_dts; } static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt, int64_t next_dts, int64_t next_pts) { - int num, den, presentation_delayed, delay, i; + AVStreamInternal *const sti = st->internal; + int num, den, presentation_delayed, delay; int64_t offset; AVRational duration; int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && @@ -1166,24 +1182,24 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, return; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE) { - if (pkt->dts == pkt->pts && st->internal->last_dts_for_order_check != AV_NOPTS_VALUE) { - if (st->internal->last_dts_for_order_check <= pkt->dts) { - st->internal->dts_ordered++; + if (pkt->dts == pkt->pts && sti->last_dts_for_order_check != AV_NOPTS_VALUE) { + if (sti->last_dts_for_order_check <= pkt->dts) { + sti->dts_ordered++; } else { - av_log(s, st->internal->dts_misordered ? AV_LOG_DEBUG : AV_LOG_WARNING, + av_log(s, sti->dts_misordered ? AV_LOG_DEBUG : AV_LOG_WARNING, "DTS %"PRIi64" < %"PRIi64" out of order\n", pkt->dts, - st->internal->last_dts_for_order_check); - st->internal->dts_misordered++; + sti->last_dts_for_order_check); + sti->dts_misordered++; } - if (st->internal->dts_ordered + st->internal->dts_misordered > 250) { - st->internal->dts_ordered >>= 1; - st->internal->dts_misordered >>= 1; + if (sti->dts_ordered + sti->dts_misordered > 250) { + sti->dts_ordered >>= 1; + sti->dts_misordered >>= 1; } } - st->internal->last_dts_for_order_check = pkt->dts; - if (st->internal->dts_ordered < 8*st->internal->dts_misordered && pkt->dts == pkt->pts) + sti->last_dts_for_order_check = pkt->dts; + if (sti->dts_ordered < 8*sti->dts_misordered && pkt->dts == pkt->pts) pkt->dts = AV_NOPTS_VALUE; } @@ -1191,12 +1207,12 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, pkt->dts = AV_NOPTS_VALUE; if (pc && pc->pict_type == AV_PICTURE_TYPE_B - && !st->internal->avctx->has_b_frames) + && !sti->avctx->has_b_frames) //FIXME Set low_delay = 0 when has_b_frames = 1 - st->internal->avctx->has_b_frames = 1; + sti->avctx->has_b_frames = 1; /* do we have a video B-frame ? */ - delay = st->internal->avctx->has_b_frames; + delay = sti->avctx->has_b_frames; presentation_delayed = 0; /* XXX: need has_b_frame, but cannot get it if the codec is @@ -1208,7 +1224,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, if (pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && st->pts_wrap_bits < 63 && pkt->dts > INT64_MIN + (1LL << st->pts_wrap_bits) && pkt->dts - (1LL << (st->pts_wrap_bits - 1)) > pkt->pts) { - if (is_relative(st->internal->cur_dts) || pkt->dts - (1LL<<(st->pts_wrap_bits - 1)) > st->internal->cur_dts) { + if (is_relative(sti->cur_dts) || pkt->dts - (1LL<<(st->pts_wrap_bits - 1)) > sti->cur_dts) { pkt->dts -= 1LL << st->pts_wrap_bits; } else pkt->pts += 1LL << st->pts_wrap_bits; @@ -1243,7 +1259,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, /* Correct timestamps with byte offset if demuxers only have timestamps * on packet boundaries */ - if (pc && st->internal->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) { + if (pc && sti->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) { /* this will estimate bitrate based on this frame's duration and size */ offset = av_rescale(pc->offset, pkt->duration, pkt->size); if (pkt->pts != AV_NOPTS_VALUE) @@ -1261,7 +1277,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, if (s->debug & FF_FDEBUG_TS) av_log(s, AV_LOG_DEBUG, "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64" delay:%d onein_oneout:%d\n", - presentation_delayed, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->internal->cur_dts), + presentation_delayed, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), pkt->stream_index, pc, pkt->duration, delay, onein_oneout); /* Interpolate PTS and DTS if they are not present. We skip H264 @@ -1272,28 +1288,28 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, /* DTS = decompression timestamp */ /* PTS = presentation timestamp */ if (pkt->dts == AV_NOPTS_VALUE) - pkt->dts = st->internal->last_IP_pts; + pkt->dts = sti->last_IP_pts; update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); if (pkt->dts == AV_NOPTS_VALUE) - pkt->dts = st->internal->cur_dts; + pkt->dts = sti->cur_dts; /* This is tricky: the dts must be incremented by the duration * of the frame we are displaying, i.e. the last I- or P-frame. */ - if (st->internal->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX) - st->internal->last_IP_duration = pkt->duration; + if (sti->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX) + sti->last_IP_duration = pkt->duration; if (pkt->dts != AV_NOPTS_VALUE) - st->internal->cur_dts = av_sat_add64(pkt->dts, st->internal->last_IP_duration); + sti->cur_dts = av_sat_add64(pkt->dts, sti->last_IP_duration); if (pkt->dts != AV_NOPTS_VALUE && pkt->pts == AV_NOPTS_VALUE && - st->internal->last_IP_duration > 0 && - ((uint64_t)st->internal->cur_dts - (uint64_t)next_dts + 1) <= 2 && + sti->last_IP_duration > 0 && + ((uint64_t)sti->cur_dts - (uint64_t)next_dts + 1) <= 2 && next_dts != next_pts && next_pts != AV_NOPTS_VALUE) pkt->pts = next_dts; if ((uint64_t)pkt->duration <= INT32_MAX) - st->internal->last_IP_duration = pkt->duration; - st->internal->last_IP_pts = pkt->pts; + sti->last_IP_duration = pkt->duration; + sti->last_IP_pts = pkt->pts; /* Cannot compute PTS if not present (we can compute it only * by knowing the future. */ } else if (pkt->pts != AV_NOPTS_VALUE || @@ -1306,31 +1322,31 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, update_initial_timestamps(s, pkt->stream_index, pkt->pts, pkt->pts, pkt); if (pkt->pts == AV_NOPTS_VALUE) - pkt->pts = st->internal->cur_dts; + pkt->pts = sti->cur_dts; pkt->dts = pkt->pts; if (pkt->pts != AV_NOPTS_VALUE && duration.num >= 0) - st->internal->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1); + sti->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1); } } if (pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { - st->internal->pts_buffer[0] = pkt->pts; - for (i = 0; iinternal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) - FFSWAP(int64_t, st->internal->pts_buffer[i], st->internal->pts_buffer[i + 1]); + sti->pts_buffer[0] = pkt->pts; + for (int i = 0; i < delay && sti->pts_buffer[i] > sti->pts_buffer[i + 1]; i++) + FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]); if(has_decode_delay_been_guessed(st)) - pkt->dts = select_from_pts_buffer(st, st->internal->pts_buffer, pkt->dts); + pkt->dts = select_from_pts_buffer(st, sti->pts_buffer, pkt->dts); } // We skipped it above so we try here. if (!onein_oneout) // This should happen on the first packet update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); - if (pkt->dts > st->internal->cur_dts) - st->internal->cur_dts = pkt->dts; + if (pkt->dts > sti->cur_dts) + sti->cur_dts = pkt->dts; if (s->debug & FF_FDEBUG_TS) av_log(s, AV_LOG_DEBUG, "OUTdelayed:%d/%d pts:%s, dts:%s cur_dts:%s st:%d (%d)\n", - presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->internal->cur_dts), st->index, st->id); + presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), st->index, st->id); /* update flags */ if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA || ff_is_intra_only(st->codecpar->codec_id)) @@ -1349,13 +1365,14 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, FFFormatContext *const si = ffformatcontext(s); AVPacket *out_pkt = si->parse_pkt; AVStream *st = s->streams[stream_index]; + AVStreamInternal *const sti = st->internal; uint8_t *data = pkt->data; int size = pkt->size; int ret = 0, got_output = flush; - if (!size && !flush && st->internal->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { + if (!size && !flush && sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { // preserve 0-size sync packets - compute_pkt_fields(s, st, st->internal->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); + compute_pkt_fields(s, st, sti->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); } while (size > 0 || (flush && got_output)) { @@ -1363,7 +1380,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int64_t next_pts = pkt->pts; int64_t next_dts = pkt->dts; - len = av_parser_parse2(st->internal->parser, st->internal->avctx, + len = av_parser_parse2(sti->parser, sti->avctx, &out_pkt->data, &out_pkt->size, data, size, pkt->pts, pkt->dts, pkt->pos); @@ -1382,7 +1399,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, if (pkt->buf && out_pkt->data == pkt->data) { /* reference pkt->buf only when out_pkt->data is guaranteed to point * to data in it and not in the parser's internal buffer. */ - /* XXX: Ensure this is the case with all parsers when st->internal->parser->flags + /* XXX: Ensure this is the case with all parsers when sti->parser->flags * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */ out_pkt->buf = av_buffer_ref(pkt->buf); if (!out_pkt->buf) { @@ -1403,35 +1420,35 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, } /* set the duration */ - out_pkt->duration = (st->internal->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; + out_pkt->duration = (sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->internal->avctx->sample_rate > 0) { + if (sti->avctx->sample_rate > 0) { out_pkt->duration = - av_rescale_q_rnd(st->internal->parser->duration, - (AVRational) { 1, st->internal->avctx->sample_rate }, + av_rescale_q_rnd(sti->parser->duration, + (AVRational) { 1, sti->avctx->sample_rate }, st->time_base, AV_ROUND_DOWN); } } out_pkt->stream_index = st->index; - out_pkt->pts = st->internal->parser->pts; - out_pkt->dts = st->internal->parser->dts; - out_pkt->pos = st->internal->parser->pos; + out_pkt->pts = sti->parser->pts; + out_pkt->dts = sti->parser->dts; + out_pkt->pos = sti->parser->pos; out_pkt->flags |= pkt->flags & AV_PKT_FLAG_DISCARD; - if (st->internal->need_parsing == AVSTREAM_PARSE_FULL_RAW) - out_pkt->pos = st->internal->parser->frame_offset; + if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) + out_pkt->pos = sti->parser->frame_offset; - if (st->internal->parser->key_frame == 1 || - (st->internal->parser->key_frame == -1 && - st->internal->parser->pict_type == AV_PICTURE_TYPE_I)) + if (sti->parser->key_frame == 1 || + (sti->parser->key_frame == -1 && + sti->parser->pict_type == AV_PICTURE_TYPE_I)) out_pkt->flags |= AV_PKT_FLAG_KEY; - if (st->internal->parser->key_frame == -1 && st->internal->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) + if (sti->parser->key_frame == -1 && sti->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) out_pkt->flags |= AV_PKT_FLAG_KEY; - compute_pkt_fields(s, st, st->internal->parser, out_pkt, next_dts, next_pts); + compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts); ret = avpriv_packet_list_put(&si->parse_queue, &si->parse_queue_end, @@ -1442,8 +1459,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, /* end of the stream => close and free the parser */ if (flush) { - av_parser_close(st->internal->parser); - st->internal->parser = NULL; + av_parser_close(sti->parser); + sti->parser = NULL; } fail: @@ -1466,6 +1483,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) while (!got_packet && !si->parse_queue) { AVStream *st; + AVStreamInternal *sti; /* read next packet */ ret = ff_read_packet(s, pkt); @@ -1484,30 +1502,31 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } ret = 0; st = s->streams[pkt->stream_index]; + sti = st->internal; st->event_flags |= AVSTREAM_EVENT_FLAG_NEW_PACKETS; /* update context if required */ - if (st->internal->need_context_update) { - if (avcodec_is_open(st->internal->avctx)) { + if (sti->need_context_update) { + if (avcodec_is_open(sti->avctx)) { av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); - avcodec_close(st->internal->avctx); - st->internal->info->found_decoder = 0; + avcodec_close(sti->avctx); + sti->info->found_decoder = 0; } /* close parser, because it depends on the codec */ - if (st->internal->parser && st->internal->avctx->codec_id != st->codecpar->codec_id) { - av_parser_close(st->internal->parser); - st->internal->parser = NULL; + if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { + av_parser_close(sti->parser); + sti->parser = NULL; } - ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar); + ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); if (ret < 0) { av_packet_unref(pkt); return ret; } - st->internal->need_context_update = 0; + sti->need_context_update = 0; } if (pkt->pts != AV_NOPTS_VALUE && @@ -1528,23 +1547,23 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) av_ts2str(pkt->dts), pkt->size, pkt->duration, pkt->flags); - if (st->internal->need_parsing && !st->internal->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { - st->internal->parser = av_parser_init(st->codecpar->codec_id); - if (!st->internal->parser) { + if (sti->need_parsing && !sti->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { + sti->parser = av_parser_init(st->codecpar->codec_id); + if (!sti->parser) { av_log(s, AV_LOG_VERBOSE, "parser not found for codec " "%s, packets or times may be invalid.\n", avcodec_get_name(st->codecpar->codec_id)); /* no parser available: just output the raw packets */ - st->internal->need_parsing = AVSTREAM_PARSE_NONE; - } else if (st->internal->need_parsing == AVSTREAM_PARSE_HEADERS) - st->internal->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; - else if (st->internal->need_parsing == AVSTREAM_PARSE_FULL_ONCE) - st->internal->parser->flags |= PARSER_FLAG_ONCE; - else if (st->internal->need_parsing == AVSTREAM_PARSE_FULL_RAW) - st->internal->parser->flags |= PARSER_FLAG_USE_CODEC_TS; + sti->need_parsing = AVSTREAM_PARSE_NONE; + } else if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) + sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; + else if (sti->need_parsing == AVSTREAM_PARSE_FULL_ONCE) + sti->parser->flags |= PARSER_FLAG_ONCE; + else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) + sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; } - if (!st->internal->need_parsing || !st->internal->parser) { + if (!sti->need_parsing || !sti->parser) { /* no parsing needed: we just output the packet as is */ compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && @@ -1557,18 +1576,18 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } else if (st->discard < AVDISCARD_ALL) { if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0) return ret; - st->codecpar->sample_rate = st->internal->avctx->sample_rate; - st->codecpar->bit_rate = st->internal->avctx->bit_rate; - st->codecpar->channels = st->internal->avctx->channels; - st->codecpar->channel_layout = st->internal->avctx->channel_layout; - st->codecpar->codec_id = st->internal->avctx->codec_id; + st->codecpar->sample_rate = sti->avctx->sample_rate; + st->codecpar->bit_rate = sti->avctx->bit_rate; + st->codecpar->channels = sti->avctx->channels; + st->codecpar->channel_layout = sti->avctx->channel_layout; + st->codecpar->codec_id = sti->avctx->codec_id; } else { /* free packet */ av_packet_unref(pkt); } if (pkt->flags & AV_PKT_FLAG_KEY) - st->internal->skip_to_keyframe = 0; - if (st->internal->skip_to_keyframe) { + sti->skip_to_keyframe = 0; + if (sti->skip_to_keyframe) { av_packet_unref(pkt); got_packet = 0; } @@ -1579,29 +1598,30 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) if (ret >= 0) { AVStream *st = s->streams[pkt->stream_index]; + AVStreamInternal *const sti = st->internal; int discard_padding = 0; - if (st->internal->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { + if (sti->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0); int64_t sample = ts_to_samples(st, pts); int duration = ts_to_samples(st, pkt->duration); int64_t end_sample = sample + duration; - if (duration > 0 && end_sample >= st->internal->first_discard_sample && - sample < st->internal->last_discard_sample) - discard_padding = FFMIN(end_sample - st->internal->first_discard_sample, duration); + if (duration > 0 && end_sample >= sti->first_discard_sample && + sample < sti->last_discard_sample) + discard_padding = FFMIN(end_sample - sti->first_discard_sample, duration); } - if (st->internal->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) - st->internal->skip_samples = st->internal->start_skip_samples; - if (st->internal->skip_samples || discard_padding) { + if (sti->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) + sti->skip_samples = sti->start_skip_samples; + if (sti->skip_samples || discard_padding) { uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); if (p) { - AV_WL32(p, st->internal->skip_samples); + AV_WL32(p, sti->skip_samples); AV_WL32(p + 4, discard_padding); - av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %d / discard %d\n", st->internal->skip_samples, discard_padding); + av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %d / discard %d\n", sti->skip_samples, discard_padding); } - st->internal->skip_samples = 0; + sti->skip_samples = 0; } - if (st->internal->inject_global_side_data) { + if (sti->inject_global_side_data) { for (int i = 0; i < st->nb_side_data; i++) { AVPacketSideData *src_sd = &st->side_data[i]; uint8_t *dst_data; @@ -1617,7 +1637,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) memcpy(dst_data, src_sd->data, src_sd->size); } - st->internal->inject_global_side_data = 0; + sti->inject_global_side_data = 0; } } @@ -1803,28 +1823,29 @@ void ff_read_frame_flush(AVFormatContext *s) /* Reset read state for each stream. */ for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *const st = s->streams[i]; + AVStreamInternal *const sti = st->internal; - if (st->internal->parser) { - av_parser_close(st->internal->parser); - st->internal->parser = NULL; + if (sti->parser) { + av_parser_close(sti->parser); + sti->parser = NULL; } - st->internal->last_IP_pts = AV_NOPTS_VALUE; - st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; - if (st->internal->first_dts == AV_NOPTS_VALUE) - st->internal->cur_dts = RELATIVE_TS_BASE; + sti->last_IP_pts = AV_NOPTS_VALUE; + sti->last_dts_for_order_check = AV_NOPTS_VALUE; + if (sti->first_dts == AV_NOPTS_VALUE) + sti->cur_dts = RELATIVE_TS_BASE; else /* We set the current DTS to an unspecified origin. */ - st->internal->cur_dts = AV_NOPTS_VALUE; + sti->cur_dts = AV_NOPTS_VALUE; - st->internal->probe_packets = s->max_probe_packets; + sti->probe_packets = s->max_probe_packets; for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) - st->internal->pts_buffer[j] = AV_NOPTS_VALUE; + sti->pts_buffer[j] = AV_NOPTS_VALUE; if (ffformatcontext(s)->inject_global_side_data) - st->internal->inject_global_side_data = 1; + sti->inject_global_side_data = 1; - st->internal->skip_samples = 0; + sti->skip_samples = 0; } } @@ -1843,13 +1864,14 @@ void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timesta void ff_reduce_index(AVFormatContext *s, int stream_index) { AVStream *st = s->streams[stream_index]; + AVStreamInternal *const sti = st->internal; unsigned int max_entries = s->max_index_size / sizeof(AVIndexEntry); - if ((unsigned) st->internal->nb_index_entries >= max_entries) { + if ((unsigned) sti->nb_index_entries >= max_entries) { int i; - for (i = 0; 2 * i < st->internal->nb_index_entries; i++) - st->internal->index_entries[i] = st->internal->index_entries[2 * i]; - st->internal->nb_index_entries = i; + for (i = 0; 2 * i < sti->nb_index_entries; i++) + sti->index_entries[i] = sti->index_entries[2 * i]; + sti->nb_index_entries = i; } } @@ -1915,9 +1937,10 @@ int ff_add_index_entry(AVIndexEntry **index_entries, int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags) { + AVStreamInternal *const sti = st->internal; timestamp = wrap_timestamp(st, timestamp); - return ff_add_index_entry(&st->internal->index_entries, &st->internal->nb_index_entries, - &st->internal->index_entries_allocated_size, pos, + return ff_add_index_entry(&sti->index_entries, &sti->nb_index_entries, + &sti->index_entries_allocated_size, pos, timestamp, size, distance, flags); } @@ -1986,19 +2009,21 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) for (unsigned ist1 = 0; ist1 < s->nb_streams; ist1++) { AVStream *st1 = s->streams[ist1]; + AVStreamInternal *const sti1 = st1->internal; for (unsigned ist2 = 0; ist2 < s->nb_streams; ist2++) { AVStream *st2 = s->streams[ist2]; + AVStreamInternal *const sti2 = st2->internal; if (ist1 == ist2) continue; - for (int i1 = 0, i2 = 0; i1 < st1->internal->nb_index_entries; i1++) { - AVIndexEntry *e1 = &st1->internal->index_entries[i1]; + for (int i1 = 0, i2 = 0; i1 < sti1->nb_index_entries; i1++) { + const AVIndexEntry *const e1 = &sti1->index_entries[i1]; int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q); skip = FFMAX(skip, e1->size); - for (; i2 < st2->internal->nb_index_entries; i2++) { - AVIndexEntry *e2 = &st2->internal->index_entries[i2]; + for (; i2 < sti2->nb_index_entries; i2++) { + const AVIndexEntry *const e2 = &sti2->index_entries[i2]; int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q); if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance) continue; @@ -2031,7 +2056,8 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) { - return ff_index_search_timestamp(st->internal->index_entries, st->internal->nb_index_entries, + AVStreamInternal *const sti = st->internal; + return ff_index_search_timestamp(sti->index_entries, sti->nb_index_entries, wanted_timestamp, flags); } @@ -2042,24 +2068,26 @@ int avformat_index_get_entries_count(const AVStream *st) const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx) { - if (idx < 0 || idx >= st->internal->nb_index_entries) + const AVStreamInternal *const sti = st->internal; + if (idx < 0 || idx >= sti->nb_index_entries) return NULL; - return &st->internal->index_entries[idx]; + return &sti->index_entries[idx]; } const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) { - int idx = ff_index_search_timestamp(st->internal->index_entries, - st->internal->nb_index_entries, + const AVStreamInternal *const sti = st->internal; + int idx = ff_index_search_timestamp(sti->index_entries, + sti->nb_index_entries, wanted_timestamp, flags); if (idx < 0) return NULL; - return &st->internal->index_entries[idx]; + return &sti->index_entries[idx]; } static int64_t ff_read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit, @@ -2080,6 +2108,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int index; int64_t ret; AVStream *st; + AVStreamInternal *sti; if (stream_index < 0) return -1; @@ -2091,7 +2120,8 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, pos_limit = -1; // GCC falsely says it may be uninitialized. st = s->streams[stream_index]; - if (st->internal->index_entries) { + sti = st->internal; + if (sti->index_entries) { AVIndexEntry *e; /* FIXME: Whole function must be checked for non-keyframe entries in @@ -2099,7 +2129,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, index = av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD); index = FFMAX(index, 0); - e = &st->internal->index_entries[index]; + e = &sti->index_entries[index]; if (e->timestamp <= target_ts || e->pos == e->min_distance) { pos_min = e->pos; @@ -2112,9 +2142,9 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, index = av_index_search_timestamp(st, target_ts, flags & ~AVSEEK_FLAG_BACKWARD); - av_assert0(index < st->internal->nb_index_entries); + av_assert0(index < sti->nb_index_entries); if (index >= 0) { - e = &st->internal->index_entries[index]; + e = &sti->index_entries[index]; av_assert1(e->timestamp >= target_ts); pos_max = e->pos; ts_max = e->timestamp; @@ -2306,26 +2336,26 @@ static int seek_frame_byte(AVFormatContext *s, int stream_index, static int seek_frame_generic(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { + AVStream *const st = s->streams[stream_index]; + AVStreamInternal *const sti = st->internal; int index; int64_t ret; - AVStream *st; AVIndexEntry *ie; - st = s->streams[stream_index]; index = av_index_search_timestamp(st, timestamp, flags); - if (index < 0 && st->internal->nb_index_entries && - timestamp < st->internal->index_entries[0].timestamp) + if (index < 0 && sti->nb_index_entries && + timestamp < sti->index_entries[0].timestamp) return -1; - if (index < 0 || index == st->internal->nb_index_entries - 1) { + if (index < 0 || index == sti->nb_index_entries - 1) { AVPacket *pkt = ffformatcontext(s)->pkt; int nonkey = 0; - if (st->internal->nb_index_entries) { - av_assert0(st->internal->index_entries); - ie = &st->internal->index_entries[st->internal->nb_index_entries - 1]; + if (sti->nb_index_entries) { + av_assert0(sti->index_entries); + ie = &sti->index_entries[sti->nb_index_entries - 1]; if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) return ret; s->io_repositioned = 1; @@ -2365,7 +2395,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, if (s->iformat->read_seek) if (s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0) return 0; - ie = &st->internal->index_entries[index]; + ie = &sti->index_entries[index]; if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) return ret; s->io_repositioned = 1; @@ -2647,17 +2677,17 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) if (ic->bit_rate <= 0) { int64_t bit_rate = 0; for (unsigned i = 0; i < ic->nb_streams; i++) { - const AVStream *const st = ic->streams[i]; - - if (st->codecpar->bit_rate <= 0 && st->internal->avctx->bit_rate > 0) - st->codecpar->bit_rate = st->internal->avctx->bit_rate; + const AVStream *const st = ic->streams[i]; + const AVStreamInternal *const sti = st->internal; + if (st->codecpar->bit_rate <= 0 && sti->avctx->bit_rate > 0) + st->codecpar->bit_rate = sti->avctx->bit_rate; if (st->codecpar->bit_rate > 0) { if (INT64_MAX - st->codecpar->bit_rate < bit_rate) { bit_rate = 0; break; } bit_rate += st->codecpar->bit_rate; - } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->codec_info_nb_frames > 1) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->codec_info_nb_frames > 1) { // If we have a videostream with packets but without a bitrate // then consider the sum not known bit_rate = 0; @@ -2708,17 +2738,18 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) flush_packet_queue(ic); for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; + AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; if (st->start_time == AV_NOPTS_VALUE && - st->internal->first_dts == AV_NOPTS_VALUE && + sti->first_dts == AV_NOPTS_VALUE && st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) av_log(ic, AV_LOG_WARNING, "start time for stream %d is not set in estimate_timings_from_pts\n", i); - if (st->internal->parser) { - av_parser_close(st->internal->parser); - st->internal->parser = NULL; + if (sti->parser) { + av_parser_close(sti->parser); + sti->parser = NULL; } } @@ -2741,6 +2772,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) read_size = 0; for (;;) { AVStream *st; + AVStreamInternal *sti; if (read_size >= DURATION_MAX_READ_SIZE << (FFMAX(retry - 1, 0))) break; @@ -2751,11 +2783,12 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) break; read_size += pkt->size; st = ic->streams[pkt->stream_index]; + sti = st->internal; if (pkt->pts != AV_NOPTS_VALUE && (st->start_time != AV_NOPTS_VALUE || - st->internal->first_dts != AV_NOPTS_VALUE)) { + sti->first_dts != AV_NOPTS_VALUE)) { if (pkt->duration == 0) { - compute_frame_duration(ic, &num, &den, st, st->internal->parser, pkt); + compute_frame_duration(ic, &num, &den, st, sti->parser, pkt); if (den && num) { pkt->duration = av_rescale_rnd(1, num * (int64_t) st->time_base.den, @@ -2768,12 +2801,12 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) if (st->start_time != AV_NOPTS_VALUE) duration -= st->start_time; else - duration -= st->internal->first_dts; + duration -= sti->first_dts; if (duration > 0) { - if (st->duration == AV_NOPTS_VALUE || st->internal->info->last_duration<= 0 || - (st->duration < duration && FFABS(duration - st->internal->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) + if (st->duration == AV_NOPTS_VALUE || sti->info->last_duration<= 0 || + (st->duration < duration && FFABS(duration - sti->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) st->duration = duration; - st->internal->info->last_duration = duration; + sti->info->last_duration = duration; } } av_packet_unref(pkt); @@ -2819,12 +2852,13 @@ skip_duration_calc: avio_seek(ic->pb, old_offset, SEEK_SET); for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; - st->internal->cur_dts = st->internal->first_dts; - st->internal->last_IP_pts = AV_NOPTS_VALUE; - st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; + sti->cur_dts = sti->first_dts; + sti->last_IP_pts = AV_NOPTS_VALUE; + sti->last_dts_for_order_check = AV_NOPTS_VALUE; for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) - st->internal->pts_buffer[j] = AV_NOPTS_VALUE; + sti->pts_buffer[j] = AV_NOPTS_VALUE; } } @@ -2891,7 +2925,8 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset) static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) { - AVCodecContext *avctx = st->internal->avctx; + AVStreamInternal *const sti = st->internal; + AVCodecContext *avctx = sti->avctx; #define FAIL(errmsg) do { \ if (errmsg_ptr) \ @@ -2906,23 +2941,23 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) case AVMEDIA_TYPE_AUDIO: if (!avctx->frame_size && determinable_frame_size(avctx)) FAIL("unspecified frame size"); - if (st->internal->info->found_decoder >= 0 && + if (sti->info->found_decoder >= 0 && avctx->sample_fmt == AV_SAMPLE_FMT_NONE) FAIL("unspecified sample format"); if (!avctx->sample_rate) FAIL("unspecified sample rate"); if (!avctx->channels) FAIL("unspecified number of channels"); - if (st->internal->info->found_decoder >= 0 && !st->internal->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) + if (sti->info->found_decoder >= 0 && !sti->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) FAIL("no decodable DTS frames"); break; case AVMEDIA_TYPE_VIDEO: if (!avctx->width) FAIL("unspecified size"); - if (st->internal->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) + if (sti->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) FAIL("unspecified pixel format"); if (st->codecpar->codec_id == AV_CODEC_ID_RV30 || st->codecpar->codec_id == AV_CODEC_ID_RV40) - if (!st->sample_aspect_ratio.num && !st->codecpar->sample_aspect_ratio.num && !st->internal->codec_info_nb_frames) + if (!st->sample_aspect_ratio.num && !st->codecpar->sample_aspect_ratio.num && !sti->codec_info_nb_frames) FAIL("no frame in rv30/40 and no sar"); break; case AVMEDIA_TYPE_SUBTITLE: @@ -2940,7 +2975,8 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) static int try_decode_frame(AVFormatContext *s, AVStream *st, const AVPacket *avpkt, AVDictionary **options) { - AVCodecContext *avctx = st->internal->avctx; + AVStreamInternal *const sti = st->internal; + AVCodecContext *avctx = sti->avctx; const AVCodec *codec; int got_picture = 1, ret = 0; AVFrame *frame = av_frame_alloc(); @@ -2953,14 +2989,14 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, return AVERROR(ENOMEM); if (!avcodec_is_open(avctx) && - st->internal->info->found_decoder <= 0 && - (st->codecpar->codec_id != -st->internal->info->found_decoder || !st->codecpar->codec_id)) { + sti->info->found_decoder <= 0 && + (st->codecpar->codec_id != -sti->info->found_decoder || !st->codecpar->codec_id)) { AVDictionary *thread_opt = NULL; codec = find_probe_decoder(s, st, st->codecpar->codec_id); if (!codec) { - st->internal->info->found_decoder = -st->codecpar->codec_id; + sti->info->found_decoder = -st->codecpar->codec_id; ret = -1; goto fail; } @@ -2978,14 +3014,14 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, if (!options) av_dict_free(&thread_opt); if (ret < 0) { - st->internal->info->found_decoder = -avctx->codec_id; + sti->info->found_decoder = -avctx->codec_id; goto fail; } - st->internal->info->found_decoder = 1; - } else if (!st->internal->info->found_decoder) - st->internal->info->found_decoder = 1; + sti->info->found_decoder = 1; + } else if (!sti->info->found_decoder) + sti->info->found_decoder = 1; - if (st->internal->info->found_decoder < 0) { + if (sti->info->found_decoder < 0) { ret = -1; goto fail; } @@ -2999,7 +3035,7 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, while ((pkt.size > 0 || (!pkt.data && got_picture)) && ret >= 0 && (!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) || - (!st->internal->codec_info_nb_frames && + (!sti->codec_info_nb_frames && (avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)))) { got_picture = 0; if (avctx->codec_type == AVMEDIA_TYPE_VIDEO || @@ -3024,7 +3060,7 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, } if (ret >= 0) { if (got_picture) - st->internal->nb_decoded_frames++; + sti->nb_decoded_frames++; ret = got_picture; } } @@ -3267,59 +3303,60 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) { - int64_t last = st->internal->info->last_dts; + AVStreamInternal *const sti = st->internal; + int64_t last = sti->info->last_dts; if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last && ts - (uint64_t)last < INT64_MAX) { double dts = (is_relative(ts) ? ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base); int64_t duration = ts - last; - if (!st->internal->info->duration_error) - st->internal->info->duration_error = av_mallocz(sizeof(st->internal->info->duration_error[0])*2); - if (!st->internal->info->duration_error) + if (!sti->info->duration_error) + sti->info->duration_error = av_mallocz(sizeof(sti->info->duration_error[0])*2); + if (!sti->info->duration_error) return AVERROR(ENOMEM); // if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) // av_log(NULL, AV_LOG_ERROR, "%f\n", dts); for (int i = 0; i < MAX_STD_TIMEBASES; i++) { - if (st->internal->info->duration_error[0][1][i] < 1e10) { + if (sti->info->duration_error[0][1][i] < 1e10) { int framerate = get_std_framerate(i); double sdts = dts*framerate/(1001*12); for (int j = 0; j < 2; j++) { int64_t ticks = llrint(sdts+j*0.5); double error= sdts - ticks + j*0.5; - st->internal->info->duration_error[j][0][i] += error; - st->internal->info->duration_error[j][1][i] += error*error; + sti->info->duration_error[j][0][i] += error; + sti->info->duration_error[j][1][i] += error*error; } } } - if (st->internal->info->rfps_duration_sum <= INT64_MAX - duration) { - st->internal->info->duration_count++; - st->internal->info->rfps_duration_sum += duration; + if (sti->info->rfps_duration_sum <= INT64_MAX - duration) { + sti->info->duration_count++; + sti->info->rfps_duration_sum += duration; } - if (st->internal->info->duration_count % 10 == 0) { - int n = st->internal->info->duration_count; + if (sti->info->duration_count % 10 == 0) { + int n = sti->info->duration_count; for (int i = 0; i < MAX_STD_TIMEBASES; i++) { - if (st->internal->info->duration_error[0][1][i] < 1e10) { - double a0 = st->internal->info->duration_error[0][0][i] / n; - double error0 = st->internal->info->duration_error[0][1][i] / n - a0*a0; - double a1 = st->internal->info->duration_error[1][0][i] / n; - double error1 = st->internal->info->duration_error[1][1][i] / n - a1*a1; + if (sti->info->duration_error[0][1][i] < 1e10) { + double a0 = sti->info->duration_error[0][0][i] / n; + double error0 = sti->info->duration_error[0][1][i] / n - a0*a0; + double a1 = sti->info->duration_error[1][0][i] / n; + double error1 = sti->info->duration_error[1][1][i] / n - a1*a1; if (error0 > 0.04 && error1 > 0.04) { - st->internal->info->duration_error[0][1][i] = 2e10; - st->internal->info->duration_error[1][1][i] = 2e10; + sti->info->duration_error[0][1][i] = 2e10; + sti->info->duration_error[1][1][i] = 2e10; } } } } // ignore the first 4 values, they might have some random jitter - if (st->internal->info->duration_count > 3 && is_relative(ts) == is_relative(last)) - st->internal->info->duration_gcd = av_gcd(st->internal->info->duration_gcd, duration); + if (sti->info->duration_count > 3 && is_relative(ts) == is_relative(last)) + sti->info->duration_gcd = av_gcd(sti->info->duration_gcd, duration); } if (ts != AV_NOPTS_VALUE) - st->internal->info->last_dts = ts; + sti->info->last_dts = ts; return 0; } @@ -3328,36 +3365,36 @@ void ff_rfps_calculate(AVFormatContext *ic) { for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) continue; // the check for tb_unreliable() is not completely correct, since this is not about handling // an unreliable/inexact time base, but a time base that is finer than necessary, as e.g. // ipmovie.c produces. - if (tb_unreliable(st->internal->avctx) && st->internal->info->duration_count > 15 && st->internal->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num && - st->internal->info->duration_gcd < INT64_MAX / st->time_base.num) - av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * st->internal->info->duration_gcd, INT_MAX); - if (st->internal->info->duration_count>1 && !st->r_frame_rate.num - && tb_unreliable(st->internal->avctx)) { + if (tb_unreliable(sti->avctx) && sti->info->duration_count > 15 && sti->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num && + sti->info->duration_gcd < INT64_MAX / st->time_base.num) + av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * sti->info->duration_gcd, INT_MAX); + if (sti->info->duration_count > 1 && !st->r_frame_rate.num + && tb_unreliable(sti->avctx)) { int num = 0; double best_error= 0.01; AVRational ref_rate = st->r_frame_rate.num ? st->r_frame_rate : av_inv_q(st->time_base); for (int j = 0; j < MAX_STD_TIMEBASES; j++) { - - if (st->internal->info->codec_info_duration && - st->internal->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) + if (sti->info->codec_info_duration && + sti->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) continue; - if (!st->internal->info->codec_info_duration && get_std_framerate(j) < 1001*12) + if (!sti->info->codec_info_duration && get_std_framerate(j) < 1001*12) continue; - if (av_q2d(st->time_base) * st->internal->info->rfps_duration_sum / st->internal->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) + if (av_q2d(st->time_base) * sti->info->rfps_duration_sum / sti->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) continue; for (int k = 0; k < 2; k++) { - int n = st->internal->info->duration_count; - double a= st->internal->info->duration_error[k][0][j] / n; - double error= st->internal->info->duration_error[k][1][j]/n - a*a; + int n = sti->info->duration_count; + double a = sti->info->duration_error[k][0][j] / n; + double error = sti->info->duration_error[k][1][j]/n - a*a; if (error < best_error && best_error> 0.000000001) { best_error= error; @@ -3372,19 +3409,19 @@ void ff_rfps_calculate(AVFormatContext *ic) av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX); } if ( !st->avg_frame_rate.num - && st->r_frame_rate.num && st->internal->info->rfps_duration_sum - && st->internal->info->codec_info_duration <= 0 - && st->internal->info->duration_count > 2 - && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - st->internal->info->rfps_duration_sum / (double)st->internal->info->duration_count) <= 1.0 + && st->r_frame_rate.num && sti->info->rfps_duration_sum + && sti->info->codec_info_duration <= 0 + && sti->info->duration_count > 2 + && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - sti->info->rfps_duration_sum / (double)sti->info->duration_count) <= 1.0 ) { av_log(ic, AV_LOG_DEBUG, "Setting avg frame rate based on r frame rate\n"); st->avg_frame_rate = st->r_frame_rate; } - av_freep(&st->internal->info->duration_error); - st->internal->info->last_dts = AV_NOPTS_VALUE; - st->internal->info->duration_count = 0; - st->internal->info->rfps_duration_sum = 0; + av_freep(&sti->info->duration_error); + sti->info->last_dts = AV_NOPTS_VALUE; + sti->info->duration_count = 0; + sti->info->rfps_duration_sum = 0; } } @@ -3563,15 +3600,15 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* check if the caller has overridden the codec id */ // only for the split stuff - if (!st->internal->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && st->internal->request_probe <= 0) { - st->internal->parser = av_parser_init(st->codecpar->codec_id); - if (st->internal->parser) { - if (st->internal->need_parsing == AVSTREAM_PARSE_HEADERS) { - st->internal->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; - } else if (st->internal->need_parsing == AVSTREAM_PARSE_FULL_RAW) { - st->internal->parser->flags |= PARSER_FLAG_USE_CODEC_TS; + if (!sti->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && sti->request_probe <= 0) { + sti->parser = av_parser_init(st->codecpar->codec_id); + if (sti->parser) { + if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) { + sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; + } else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) { + sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; } - } else if (st->internal->need_parsing) { + } else if (sti->need_parsing) { av_log(ic, AV_LOG_VERBOSE, "parser not found for codec " "%s, packets or times may be invalid.\n", avcodec_get_name(st->codecpar->codec_id)); @@ -3581,8 +3618,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ret = avcodec_parameters_to_context(avctx, st->codecpar); if (ret < 0) goto find_stream_info_err; - if (st->internal->request_probe <= 0) - st->internal->avctx_inited = 1; + if (sti->request_probe <= 0) + sti->avctx_inited = 1; codec = find_probe_decoder(ic, st, st->codecpar->codec_id); @@ -3599,7 +3636,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) // Try to just open decoders, in case this is enough to get parameters. // Also ensure that subtitle_header is properly set. - if (!has_codec_parameters(st, NULL) && st->internal->request_probe <= 0 || + if (!has_codec_parameters(st, NULL) && sti->request_probe <= 0 || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (codec && !avctx->codec) if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0) @@ -3614,6 +3651,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) for (;;) { const AVPacket *pkt; AVStream *st; + AVStreamInternal *sti; AVCodecContext *avctx; int analyzed_all_streams; unsigned i; @@ -3626,6 +3664,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* check if one codec still needs to be handled */ for (i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; int fps_analyze_framecount = 20; int count; @@ -3636,7 +3675,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) * the correct fps. */ if (av_q2d(st->time_base) > 0.0005) fps_analyze_framecount *= 2; - if (!tb_unreliable(st->internal->avctx)) + if (!tb_unreliable(sti->avctx)) fps_analyze_framecount = 0; if (ic->fps_probe_size >= 0) fps_analyze_framecount = ic->fps_probe_size; @@ -3644,8 +3683,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) fps_analyze_framecount = 0; /* variable fps and no guess at the real fps */ count = (ic->iformat->flags & AVFMT_NOTIMESTAMPS) ? - st->internal->info->codec_info_duration_fields/2 : - st->internal->info->duration_count; + sti->info->codec_info_duration_fields/2 : + sti->info->duration_count; if (!(st->r_frame_rate.num && st->avg_frame_rate.num) && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (count < fps_analyze_framecount) @@ -3653,16 +3692,15 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } // Look at the first 3 frames if there is evidence of frame delay // but the decoder delay is not set. - if (st->internal->info->frame_delay_evidence && count < 2 && st->internal->avctx->has_b_frames == 0) + if (sti->info->frame_delay_evidence && count < 2 && sti->avctx->has_b_frames == 0) break; - if (!st->internal->avctx->extradata && - (!st->internal->extract_extradata.inited || - st->internal->extract_extradata.bsf) && + if (!sti->avctx->extradata && + (!sti->extract_extradata.inited || sti->extract_extradata.bsf) && extract_extradata_check(st)) break; - if (st->internal->first_dts == AV_NOPTS_VALUE && + if (sti->first_dts == AV_NOPTS_VALUE && !(ic->iformat->flags & AVFMT_NOTIMESTAMPS) && - st->internal->codec_info_nb_frames < ((st->disposition & AV_DISPOSITION_ATTACHED_PIC) ? 1 : ic->max_ts_probe) && + sti->codec_info_nb_frames < ((st->disposition & AV_DISPOSITION_ATTACHED_PIC) ? 1 : ic->max_ts_probe) && (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) break; @@ -3686,14 +3724,16 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ret = count; av_log(ic, AV_LOG_DEBUG, "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); - for (unsigned i = 0; i < ic->nb_streams; i++) - if (!ic->streams[i]->r_frame_rate.num && - ic->streams[i]->internal->info->duration_count <= 1 && - ic->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + if (!st->r_frame_rate.num && + st->internal->info->duration_count <= 1 && + st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && strcmp(ic->iformat->name, "image2")) av_log(ic, AV_LOG_WARNING, "Stream #%d: not enough frames to estimate rate; " "consider increasing probesize\n", i); + } break; } @@ -3722,70 +3762,71 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } st = ic->streams[pkt->stream_index]; + sti = st->internal; if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) read_size += pkt->size; - avctx = st->internal->avctx; - if (!st->internal->avctx_inited) { + avctx = sti->avctx; + if (!sti->avctx_inited) { ret = avcodec_parameters_to_context(avctx, st->codecpar); if (ret < 0) goto unref_then_goto_end; - st->internal->avctx_inited = 1; + sti->avctx_inited = 1; } - if (pkt->dts != AV_NOPTS_VALUE && st->internal->codec_info_nb_frames > 1) { + if (pkt->dts != AV_NOPTS_VALUE && sti->codec_info_nb_frames > 1) { /* check for non-increasing dts */ - if (st->internal->info->fps_last_dts != AV_NOPTS_VALUE && - st->internal->info->fps_last_dts >= pkt->dts) { + if (sti->info->fps_last_dts != AV_NOPTS_VALUE && + sti->info->fps_last_dts >= pkt->dts) { av_log(ic, AV_LOG_DEBUG, "Non-increasing DTS in stream %d: packet %d with DTS " "%"PRId64", packet %d with DTS %"PRId64"\n", - st->index, st->internal->info->fps_last_dts_idx, - st->internal->info->fps_last_dts, st->internal->codec_info_nb_frames, + st->index, sti->info->fps_last_dts_idx, + sti->info->fps_last_dts, sti->codec_info_nb_frames, pkt->dts); - st->internal->info->fps_first_dts = - st->internal->info->fps_last_dts = AV_NOPTS_VALUE; + sti->info->fps_first_dts = + sti->info->fps_last_dts = AV_NOPTS_VALUE; } /* Check for a discontinuity in dts. If the difference in dts * is more than 1000 times the average packet duration in the * sequence, we treat it as a discontinuity. */ - if (st->internal->info->fps_last_dts != AV_NOPTS_VALUE && - st->internal->info->fps_last_dts_idx > st->internal->info->fps_first_dts_idx && - (pkt->dts - (uint64_t)st->internal->info->fps_last_dts) / 1000 > - (st->internal->info->fps_last_dts - (uint64_t)st->internal->info->fps_first_dts) / - (st->internal->info->fps_last_dts_idx - st->internal->info->fps_first_dts_idx)) { + if (sti->info->fps_last_dts != AV_NOPTS_VALUE && + sti->info->fps_last_dts_idx > sti->info->fps_first_dts_idx && + (pkt->dts - (uint64_t)sti->info->fps_last_dts) / 1000 > + (sti->info->fps_last_dts - (uint64_t)sti->info->fps_first_dts) / + (sti->info->fps_last_dts_idx - sti->info->fps_first_dts_idx)) { av_log(ic, AV_LOG_WARNING, "DTS discontinuity in stream %d: packet %d with DTS " "%"PRId64", packet %d with DTS %"PRId64"\n", - st->index, st->internal->info->fps_last_dts_idx, - st->internal->info->fps_last_dts, st->internal->codec_info_nb_frames, + st->index, sti->info->fps_last_dts_idx, + sti->info->fps_last_dts, sti->codec_info_nb_frames, pkt->dts); - st->internal->info->fps_first_dts = - st->internal->info->fps_last_dts = AV_NOPTS_VALUE; + sti->info->fps_first_dts = + sti->info->fps_last_dts = AV_NOPTS_VALUE; } /* update stored dts values */ - if (st->internal->info->fps_first_dts == AV_NOPTS_VALUE) { - st->internal->info->fps_first_dts = pkt->dts; - st->internal->info->fps_first_dts_idx = st->internal->codec_info_nb_frames; + if (sti->info->fps_first_dts == AV_NOPTS_VALUE) { + sti->info->fps_first_dts = pkt->dts; + sti->info->fps_first_dts_idx = sti->codec_info_nb_frames; } - st->internal->info->fps_last_dts = pkt->dts; - st->internal->info->fps_last_dts_idx = st->internal->codec_info_nb_frames; + sti->info->fps_last_dts = pkt->dts; + sti->info->fps_last_dts_idx = sti->codec_info_nb_frames; } - if (st->internal->codec_info_nb_frames>1) { + if (sti->codec_info_nb_frames > 1) { int64_t t = 0; int64_t limit; if (st->time_base.den > 0) - t = av_rescale_q(st->internal->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); + t = av_rescale_q(sti->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); if (st->avg_frame_rate.num > 0) - t = FFMAX(t, av_rescale_q(st->internal->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); + t = FFMAX(t, av_rescale_q(sti->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); if ( t == 0 - && st->internal->codec_info_nb_frames>30 - && st->internal->info->fps_first_dts != AV_NOPTS_VALUE - && st->internal->info->fps_last_dts != AV_NOPTS_VALUE) { - int64_t dur = av_sat_sub64(st->internal->info->fps_last_dts, st->internal->info->fps_first_dts); + && sti->codec_info_nb_frames > 30 + && sti->info->fps_first_dts != AV_NOPTS_VALUE + && sti->info->fps_last_dts != AV_NOPTS_VALUE) { + int64_t dur = av_sat_sub64(sti->info->fps_last_dts, sti->info->fps_first_dts); t = FFMAX(t, av_rescale_q(dur, st->time_base, AV_TIME_BASE_Q)); } @@ -3805,11 +3846,11 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time && (uint64_t)pkt->pts - st->start_time < INT64_MAX ) { - st->internal->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, st->internal->info->codec_info_duration + pkt->duration); + sti->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, sti->info->codec_info_duration + pkt->duration); } else - st->internal->info->codec_info_duration += pkt->duration; - st->internal->info->codec_info_duration_fields += st->internal->parser && st->internal->need_parsing && avctx->ticks_per_frame == 2 - ? st->internal->parser->repeat_pict + 1 : 2; + sti->info->codec_info_duration += pkt->duration; + sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && avctx->ticks_per_frame == 2 + ? sti->parser->repeat_pict + 1 : 2; } } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -3817,9 +3858,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ff_rfps_add_frame(ic, st, pkt->dts); #endif if (pkt->dts != pkt->pts && pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) - st->internal->info->frame_delay_evidence = 1; + sti->info->frame_delay_evidence = 1; } - if (!st->internal->avctx->extradata) { + if (!sti->avctx->extradata) { ret = extract_extradata(si, st, pkt); if (ret < 0) goto unref_then_goto_end; @@ -3840,7 +3881,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) if (ic->flags & AVFMT_FLAG_NOBUFFER) av_packet_unref(pkt1); - st->internal->codec_info_nb_frames++; + sti->codec_info_nb_frames++; count++; } @@ -3908,20 +3949,20 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } /* estimate average framerate if not set by demuxer */ - if (st->internal->info->codec_info_duration_fields && + if (sti->info->codec_info_duration_fields && !st->avg_frame_rate.num && - st->internal->info->codec_info_duration) { + sti->info->codec_info_duration) { int best_fps = 0; double best_error = 0.01; AVRational codec_frame_rate = avctx->framerate; - if (st->internal->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| - st->internal->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || - st->internal->info->codec_info_duration < 0) + if (sti->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| + sti->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || + sti->info->codec_info_duration < 0) continue; av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, - st->internal->info->codec_info_duration_fields * (int64_t) st->time_base.den, - st->internal->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); + sti->info->codec_info_duration_fields * (int64_t) st->time_base.den, + sti->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); /* Round guessed framerate to a "standard" framerate if it's * within 1% of the original estimate. */ @@ -3959,9 +4000,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) st->r_frame_rate.den = st->time_base.num; } } - if (st->internal->display_aspect_ratio.num && st->internal->display_aspect_ratio.den) { + if (sti->display_aspect_ratio.num && sti->display_aspect_ratio.den) { AVRational hw_ratio = { avctx->height, avctx->width }; - st->sample_aspect_ratio = av_mul_q(st->internal->display_aspect_ratio, + st->sample_aspect_ratio = av_mul_q(sti->display_aspect_ratio, hw_ratio); } } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { @@ -3999,20 +4040,21 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ret = -1; for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; const char *errmsg; /* if no packet was ever seen, update context now for has_codec_parameters */ - if (!st->internal->avctx_inited) { + if (!sti->avctx_inited) { if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->format == AV_SAMPLE_FMT_NONE) - st->codecpar->format = st->internal->avctx->sample_fmt; - ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar); + st->codecpar->format = sti->avctx->sample_fmt; + ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); if (ret < 0) goto find_stream_info_err; } if (!has_codec_parameters(st, &errmsg)) { char buf[256]; - avcodec_string(buf, sizeof(buf), st->internal->avctx, 0); + avcodec_string(buf, sizeof(buf), sti->avctx, 0); av_log(ic, AV_LOG_WARNING, "Could not find codec parameters for stream %d (%s): %s\n" "Consider increasing the value for the 'analyzeduration' (%"PRId64") and 'probesize' (%"PRId64") options\n", @@ -4029,27 +4071,30 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* update the stream parameters from the internal codec contexts */ for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; - if (st->internal->avctx_inited) { - ret = avcodec_parameters_from_context(st->codecpar, st->internal->avctx); + if (sti->avctx_inited) { + ret = avcodec_parameters_from_context(st->codecpar, sti->avctx); if (ret < 0) goto find_stream_info_err; - ret = add_coded_side_data(st, st->internal->avctx); + ret = add_coded_side_data(st, sti->avctx); if (ret < 0) goto find_stream_info_err; } - st->internal->avctx_inited = 0; + sti->avctx_inited = 0; } find_stream_info_err: for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - if (st->internal->info) - av_freep(&st->internal->info->duration_error); - avcodec_close(ic->streams[i]->internal->avctx); - av_freep(&ic->streams[i]->internal->info); - av_bsf_free(&ic->streams[i]->internal->extract_extradata.bsf); + AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; + if (sti->info) { + av_freep(&sti->info->duration_error); + av_freep(&sti->info); + } + avcodec_close(sti->avctx); + av_bsf_free(&sti->extract_extradata.bsf); } if (ic->pb) { FFIOContext *const ctx = ffiocontext(ic->pb); @@ -4216,6 +4261,7 @@ int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) static void free_stream(AVStream **pst) { AVStream *st = *pst; + AVStreamInternal *sti; if (!st) return; @@ -4227,19 +4273,21 @@ static void free_stream(AVStream **pst) if (st->attached_pic.data) av_packet_unref(&st->attached_pic); - if (st->internal) { - av_parser_close(st->internal->parser); - avcodec_free_context(&st->internal->avctx); - av_bsf_free(&st->internal->bsfc); - av_freep(&st->internal->priv_pts); - av_freep(&st->internal->index_entries); - av_freep(&st->internal->probe_data.buf); + sti = st->internal; + if (sti) { + av_parser_close(sti->parser); + avcodec_free_context(&sti->avctx); + av_bsf_free(&sti->bsfc); + av_freep(&sti->priv_pts); + av_freep(&sti->index_entries); + av_freep(&sti->probe_data.buf); - av_bsf_free(&st->internal->extract_extradata.bsf); + av_bsf_free(&sti->extract_extradata.bsf); - if (st->internal->info) - av_freep(&st->internal->info->duration_error); - av_freep(&st->internal->info); + if (sti->info) { + av_freep(&sti->info->duration_error); + av_freep(&sti->info); + } } av_freep(&st->internal); @@ -4332,7 +4380,7 @@ void avformat_close_input(AVFormatContext **ps) AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) { AVStream *st; - int i; + AVStreamInternal *sti; AVStream **streams; if (s->nb_streams >= s->max_streams) { @@ -4350,28 +4398,28 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) if (!st) return NULL; - st->internal = av_mallocz(sizeof(*st->internal)); - if (!st->internal) + sti = st->internal = av_mallocz(sizeof(*st->internal)); + if (!sti) goto fail; st->codecpar = avcodec_parameters_alloc(); if (!st->codecpar) goto fail; - st->internal->avctx = avcodec_alloc_context3(NULL); - if (!st->internal->avctx) + sti->avctx = avcodec_alloc_context3(NULL); + if (!sti->avctx) goto fail; if (s->iformat) { - st->internal->info = av_mallocz(sizeof(*st->internal->info)); - if (!st->internal->info) + sti->info = av_mallocz(sizeof(*sti->info)); + if (!sti->info) goto fail; #if FF_API_R_FRAME_RATE - st->internal->info->last_dts = AV_NOPTS_VALUE; + sti->info->last_dts = AV_NOPTS_VALUE; #endif - st->internal->info->fps_first_dts = AV_NOPTS_VALUE; - st->internal->info->fps_last_dts = AV_NOPTS_VALUE; + sti->info->fps_first_dts = AV_NOPTS_VALUE; + sti->info->fps_last_dts = AV_NOPTS_VALUE; /* default pts setting is MPEG-like */ avpriv_set_pts_info(st, 33, 1, 90000); @@ -4379,29 +4427,29 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) * but durations get some timestamps, formats with some unknown * timestamps have their first few packets buffered and the * timestamps corrected before they are returned to the user */ - st->internal->cur_dts = RELATIVE_TS_BASE; + sti->cur_dts = RELATIVE_TS_BASE; } else { - st->internal->cur_dts = AV_NOPTS_VALUE; + sti->cur_dts = AV_NOPTS_VALUE; } st->index = s->nb_streams; st->start_time = AV_NOPTS_VALUE; st->duration = AV_NOPTS_VALUE; - st->internal->first_dts = AV_NOPTS_VALUE; - st->internal->probe_packets = s->max_probe_packets; - st->internal->pts_wrap_reference = AV_NOPTS_VALUE; - st->internal->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; + sti->first_dts = AV_NOPTS_VALUE; + sti->probe_packets = s->max_probe_packets; + sti->pts_wrap_reference = AV_NOPTS_VALUE; + sti->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; - st->internal->last_IP_pts = AV_NOPTS_VALUE; - st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; - for (i = 0; i < MAX_REORDER_DELAY + 1; i++) - st->internal->pts_buffer[i] = AV_NOPTS_VALUE; + sti->last_IP_pts = AV_NOPTS_VALUE; + sti->last_dts_for_order_check = AV_NOPTS_VALUE; + for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) + sti->pts_buffer[i] = AV_NOPTS_VALUE; st->sample_aspect_ratio = (AVRational) { 0, 1 }; - st->internal->inject_global_side_data = ffformatcontext(s)->inject_global_side_data; + sti->inject_global_side_data = ffformatcontext(s)->inject_global_side_data; - st->internal->need_context_update = 1; + sti->need_context_update = 1; s->streams[s->nb_streams++] = st; return st; @@ -4946,7 +4994,8 @@ AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *strea AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame) { AVRational fr = st->r_frame_rate; - AVRational codec_fr = st->internal->avctx->framerate; + AVCodecContext *const avctx = st->internal->avctx; + AVRational codec_fr = avctx->framerate; AVRational avg_fr = st->avg_frame_rate; if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 && @@ -4955,7 +5004,7 @@ AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *f } - if (st->internal->avctx->ticks_per_frame > 1) { + if (avctx->ticks_per_frame > 1) { if ( codec_fr.num > 0 && codec_fr.den > 0 && (fr.num == 0 || av_q2d(codec_fr) < av_q2d(fr)*0.7 && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1)) fr = codec_fr; From patchwork Fri Aug 27 14:27:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29817 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1515248iov; Fri, 27 Aug 2021 07:31:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytHPv5wPAJ6FKCGWDcpjyIKC7/vxnPYysXSXC6t8yITcYuJ09C2WjDY2Qavz2CgHwcVZrk X-Received: by 2002:a50:c31e:: with SMTP id a30mr10145934edb.123.1630074718933; Fri, 27 Aug 2021 07:31:58 -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 t21si6262019ejy.151.2021.08.27.07.31.58; Fri, 27 Aug 2021 07:31:58 -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=uOzl3M9s; 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 7318168A604; Fri, 27 Aug 2021 17:28:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (unknown [40.92.67.59]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F95E68A596 for ; Fri, 27 Aug 2021 17:28:07 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GX2CB3K+KUx7XiABmjFaXyGnNbr0Pp6UsG+LoKEM3YTCdZFJkW4P4QC5DI9MBZC2cLpKv0Kk78JxLEJNQBeWKMZ8/ifkbq4ib3zR87D+7uxRNCDGWAgWXTC6wjQECxs2o5nExTLsMjboty9KQQ1AYh/Ys3Xe0yVdvbq6rdj+NopBz3d71kxtM8Id3edRZa4wgRTarzUxJNRNcHRiFZa9iHuikYABO9LI2EXJZmuXCotQAsz3kKxcR6Hx9k1FCCjLIK3cZpzs7b31autkNHyEzGtffjTzdMlql5MEHHPAtLQ1HOUT4ZvjZSoXsIdJUuVWVlBelKpVpP84eHkuzlwhhw== 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=9UDMslNoi7mgzmZOTYcScV1FxsPzjwyrwRrz/WmVsc0=; b=i4rbhm0VybCfm52EUNINLg/cjJHsrD8w/gI1RGrHhZhq0h2EuTK9I4/wkIhCYxWrpbHqhwBxFLbwzv9f8Sx1Gn06t2M95rb+ILcIxzeICU5LKnGCjWUalNLOX2vYfnBBcPAm22HQpQqgar1pCKhCeipl1AbtPVOpdxN+AlyllpsP7i3kftRNo2f/iZHwfho+nOj9KpkadFiWYBtj3x7MCCGg/y8KrCCLzGIU3fnAIoqlgReW0w+D317bnZnXdPS3ozjdnm62XU6miPHqt0juAk362Y7Hh5RldhyuaApUe9TAzEDIf5AxhwDU7DlUSK7cVY3Fo2fH+oDnNyngMh5MsQ== 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=9UDMslNoi7mgzmZOTYcScV1FxsPzjwyrwRrz/WmVsc0=; b=uOzl3M9sE0OHC/om1RPBqytD3aeedTZ44AFdVjtpuhas+ppI6hmPqWdGS+5gqhs8VEe2h2eWN8NJStFw/o88UyqiM5VrPcOf6xxOQnVK7k5BKkyVEg9FZG+q1TIlDChdne/flhlNqzX4h4zp+daZqFn8zdATnBsxR6Kc1mUvFBifsF/NjTIngRZxquENoDESOtYG6ogMWm9uE0aHTqehAwxZJUqnrTcFc4bPMw/91r7G1tS9kotjBWjl2IDIEcoiy4PR5Q50SvGZRSPoybtRcU4p6bZLWLZWl/w9vIz3AkancY/xsVQTlynsHIRuVjVi9PG4FIvMpLAV9qqmXNaRJA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3861.eurprd03.prod.outlook.com (2603:10a6:20b:22::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Fri, 27 Aug 2021 14:28:04 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:28:04 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:22 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [XXPKAuMJB77YC+91NrBZ4x2ZKSc5rCD1] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-21-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:28:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 34696580-0a1f-4603-0aa3-08d96966e178 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/73NRXBl7CynqqLr7CR5FYKitmst6G5QVM64LnZEtnG5B8RO6SGfTrsstcxVRawncu7FljxzECpNBLA/Wxv4dVPUWxoUU28DI3csq0XeIEPWV4UpxTymDU7RYWF5WsStOwmwGPeDue+H6Q0JWVidcDs7QCjFkNgmBmCLjvVOE/JACrPc1jyXOmESlRTbYBhYr9YmR+S3GnIRmau7qEr3q7LFrheJSaRvmWxwNLuqxOz/dlUl3Iy7K+ZHvPgndo9pTSdjYXYdeRY774KagAKoxNsXWefMojve35o61CWn88XwlX8hnp2N1VUPTTzMKlbRAQ9S+FbEfCnfd+9cpCGG7tw1l/vLyl8urIXk1MCdbq3H1zDd2qsY5h+fTKyd0PHZBRpp3pacjKKg7GUzJd3SSXMGRLXeHYeg8ZYBpI9djaVQ7XkkEUuaWh6qRtrG1OqM+vcoNPE1GBEQRvSjYbOGkIC3GF7kIr0kmImcAp6Dd4Vyevp8pc2Vsp9OXsP2cDThkQayxDQfVN2NkqoHTNH1UQPLKOqW6M7nSmdpZN7MT5ok2dJS+7+4IgaLM4t3n05rPCIzf5rOM7ima4elPMfBml+MXjkqkhoF5hNFImCfH7au6NM1QUnaPznqjea7tc3sYcNe8Ek6duP8xnxX+7GTydwrZhuDXkigluYpBZ/hx6TE26GwJv3O4vaIvShUpP2EDhgZ6HsvLgftAjFIrtCNiDUzO9cKy/e+C4vKhG1CVtlXc= X-MS-TrafficTypeDiagnostic: AM6PR03MB3861: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GP75s9wPUrc+PqtbYshsweZDVkm7zbg5Gz1OMNKnTPpH7t45yzq2XasN7STNso6zWzCmswkvD32FNMGHl3cbf1D3L7b6nAdoDZ55dSWi22AJgqaQsNIStOb8Wm4I7KKYIAEmX1jMEwBMuHc7H9qScavVmhq5g9bO0nj3lxjQhXoLMfLBJ5nsd0wIKNS/C0BGgeOvGKC9eyVsz39m50/HqdA6JXyByOjMwucA/hU0Mp43yxtqlq4SaRjCb/JN3IA0pQCQc9nuv1YjR5I/HlOpsdSuFueE5SE0bqym+8YenaHBk7HrB/G80JK9IFY+wtrn/cLeD4Ncz8ctE4gNufbWx0+LfDAiq0K3HvsB+k2kJgTWKUqzjUV1lYJuM/m8k9xBL7SdtaNGvHIlDvBfKCzS9vBLRE4KXCArkS5/cCF5+c/NWY0+8DYB5CV6uZOGgY1H X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r5OoiViSynziihisAbxy9prSsxx6VpuIbkPFf45oGLvGGANf0MnHn/0MliMKK7NH3eJfLyrLWz4vs0Ypi5hfESwasBYun2ma6lC/MpaiekJbt8efdebLcywd5HBKYBNCYkW39VIapjtOKS7Uhm0zvA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 34696580-0a1f-4603-0aa3-08d96966e178 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:28:04.5771 (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: AM6PR03MB3861 Subject: [FFmpeg-devel] [PATCH 22/25] avformat: Avoid allocation for AVStreamInternal 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: Fz9d0Bd2lzBF Do this by allocating AVStream together with the data that is currently in AVStreamInternal; or rather: Put AVStream at the beginning of a new structure called FFStream (which encompasses more than just the internal fields and is a proper context in its own right, hence the name) and remove AVStreamInternal altogether. Signed-off-by: Andreas Rheinhardt --- libavformat/aacdec.c | 2 +- libavformat/aadec.c | 6 +- libavformat/acm.c | 2 +- libavformat/ape.c | 2 +- libavformat/asfdec_f.c | 16 +-- libavformat/asfdec_o.c | 9 +- libavformat/av1dec.c | 4 +- libavformat/avformat.h | 8 -- libavformat/avidec.c | 130 +++++++++-------- libavformat/bink.c | 10 +- libavformat/cafdec.c | 23 +-- libavformat/cinedec.c | 4 +- libavformat/concatdec.c | 4 +- libavformat/dashenc.c | 4 +- libavformat/dhav.c | 4 +- libavformat/dtshddec.c | 2 +- libavformat/dump.c | 15 +- libavformat/electronicarts.c | 2 +- libavformat/fifo.c | 2 +- libavformat/flacdec.c | 14 +- libavformat/flic.c | 6 +- libavformat/flvdec.c | 25 ++-- libavformat/gxf.c | 12 +- libavformat/hdsenc.c | 6 +- libavformat/hls.c | 2 +- libavformat/ifv.c | 8 +- libavformat/img2dec.c | 6 +- libavformat/internal.h | 19 ++- libavformat/ipudec.c | 2 +- libavformat/iv8.c | 2 +- libavformat/ivfdec.c | 2 +- libavformat/jvdec.c | 27 ++-- libavformat/lmlm4.c | 4 +- libavformat/loasdec.c | 2 +- libavformat/lxfdec.c | 2 +- libavformat/matroskadec.c | 53 +++---- libavformat/mgsts.c | 2 +- libavformat/mlvdec.c | 20 +-- libavformat/mov.c | 238 ++++++++++++++++--------------- libavformat/mp3dec.c | 16 +-- libavformat/mpc.c | 5 +- libavformat/mpc8.c | 4 +- libavformat/mpeg.c | 4 +- libavformat/mpegts.c | 66 ++++----- libavformat/msf.c | 2 +- libavformat/mtv.c | 2 +- libavformat/mux.c | 43 +++--- libavformat/mvdec.c | 4 +- libavformat/mxfdec.c | 12 +- libavformat/mxfenc.c | 10 +- libavformat/ncdec.c | 2 +- libavformat/nsvdec.c | 8 +- libavformat/nutdec.c | 8 +- libavformat/nutenc.c | 13 +- libavformat/nuv.c | 2 +- libavformat/oggparseflac.c | 2 +- libavformat/oggparseogm.c | 6 +- libavformat/oggparsetheora.c | 2 +- libavformat/oggparsevp8.c | 2 +- libavformat/omadec.c | 2 +- libavformat/pcm.c | 2 +- libavformat/pva.c | 4 +- libavformat/rawdec.c | 6 +- libavformat/rdt.c | 4 +- libavformat/rl2.c | 9 +- libavformat/rmdec.c | 8 +- libavformat/rpl.c | 4 +- libavformat/rtpdec_asf.c | 4 +- libavformat/rtsp.c | 2 +- libavformat/s337m.c | 2 +- libavformat/sbgdec.c | 8 +- libavformat/sdr2.c | 2 +- libavformat/segafilm.c | 4 +- libavformat/segment.c | 4 +- libavformat/smoothstreamingenc.c | 6 +- libavformat/swfdec.c | 4 +- libavformat/takdec.c | 2 +- libavformat/tedcaptionsdec.c | 4 +- libavformat/tta.c | 8 +- libavformat/ty.c | 4 +- libavformat/utils.c | 165 +++++++++++---------- libavformat/vocdec.c | 10 +- libavformat/vqf.c | 2 +- libavformat/wavdec.c | 15 +- libavformat/wtvdec.c | 2 +- libavformat/xvag.c | 2 +- libavformat/xwma.c | 2 +- 87 files changed, 614 insertions(+), 591 deletions(-) diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c index 1f68f17bc9..ab97be60b5 100644 --- a/libavformat/aacdec.c +++ b/libavformat/aacdec.c @@ -112,7 +112,7 @@ static int adts_aac_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = s->iformat->raw_codec_id; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; ff_id3v1_read(s); if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && diff --git a/libavformat/aadec.c b/libavformat/aadec.c index 9771a1df81..1bb831b17f 100644 --- a/libavformat/aadec.c +++ b/libavformat/aadec.c @@ -182,7 +182,7 @@ static int aa_read_header(AVFormatContext *s) if (!strcmp(codec_name, "mp332")) { st->codecpar->codec_id = AV_CODEC_ID_MP3; st->codecpar->sample_rate = 22050; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 8, 32000 * TIMEPREC); // encoded audio frame is MP3_FRAME_SIZE bytes (+1 with padding, unlikely) } else if (!strcmp(codec_name, "acelp85")) { @@ -191,7 +191,7 @@ static int aa_read_header(AVFormatContext *s) st->codecpar->channels = 1; st->codecpar->sample_rate = 8500; st->codecpar->bit_rate = 8500; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 8, 8500 * TIMEPREC); } else if (!strcmp(codec_name, "acelp16")) { st->codecpar->codec_id = AV_CODEC_ID_SIPR; @@ -199,7 +199,7 @@ static int aa_read_header(AVFormatContext *s) st->codecpar->channels = 1; st->codecpar->sample_rate = 16000; st->codecpar->bit_rate = 16000; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 8, 16000 * TIMEPREC); } diff --git a/libavformat/acm.c b/libavformat/acm.c index ccd043ee32..0ee9114f70 100644 --- a/libavformat/acm.c +++ b/libavformat/acm.c @@ -54,7 +54,7 @@ static int acm_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; st->start_time = 0; st->duration = AV_RL32(st->codecpar->extradata + 4) / st->codecpar->channels; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; diff --git a/libavformat/ape.c b/libavformat/ape.c index b6f9be4dbc..b1222d9ce0 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -434,7 +434,7 @@ static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp if (index < 0) return -1; - if ((ret = avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET)) < 0) + if ((ret = avio_seek(s->pb, ffstream(st)->index_entries[index].pos, SEEK_SET)) < 0) return ret; ape->currentframe = index; return 0; diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index eccf21f3b1..faba17aa03 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -378,13 +378,13 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) if (is_dvr_ms_audio) { // codec_id and codec_tag are unreliable in dvr_ms // files. Set them later by probing stream. - st->internal->request_probe = 1; + ffstream(st)->request_probe = 1; st->codecpar->codec_tag = 0; } if (st->codecpar->codec_id == AV_CODEC_ID_AAC) - st->internal->need_parsing = AVSTREAM_PARSE_NONE; + ffstream(st)->need_parsing = AVSTREAM_PARSE_NONE; else - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; /* We have to init the frame size at some point .... */ pos2 = avio_tell(pb); if (size >= (pos2 + 8 - pos1 + 24)) { @@ -443,7 +443,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) st->codecpar->codec_tag = tag1; st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); if (tag1 == MKTAG('D', 'V', 'R', ' ')) { - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; /* issue658 contains wrong w/h and MS even puts a fake seq header * with wrong w/h in extradata while a correct one is in the stream. * maximum lameness */ @@ -453,9 +453,9 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) st->codecpar->extradata_size = 0; } if (st->codecpar->codec_id == AV_CODEC_ID_H264) - st->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_ONCE; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) - st->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_ONCE; } pos2 = avio_tell(pb); avio_skip(pb, size - (pos2 - pos1 + 24)); @@ -1583,11 +1583,11 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, asf->index_read = -1; } - if (asf->index_read > 0 && st->internal->index_entries) { + if (asf->index_read > 0 && ffstream(st)->index_entries) { int index = av_index_search_timestamp(st, pts, flags); if (index >= 0) { /* find the position */ - uint64_t pos = st->internal->index_entries[index].pos; + uint64_t pos = ffstream(st)->index_entries[index].pos; /* do the seek */ av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos); diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c index 0a3af53a01..e0663dbb38 100644 --- a/libavformat/asfdec_o.c +++ b/libavformat/asfdec_o.c @@ -1513,13 +1513,14 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { ASFContext *asf = s->priv_data; + AVStream *const st = s->streams[stream_index]; int idx, ret; - if (s->streams[stream_index]->internal->nb_index_entries && asf->is_simple_index) { - idx = av_index_search_timestamp(s->streams[stream_index], timestamp, flags); - if (idx < 0 || idx >= s->streams[stream_index]->internal->nb_index_entries) + if (ffstream(st)->nb_index_entries && asf->is_simple_index) { + idx = av_index_search_timestamp(st, timestamp, flags); + if (idx < 0 || idx >= ffstream(st)->nb_index_entries) return AVERROR_INVALIDDATA; - avio_seek(s->pb, s->streams[stream_index]->internal->index_entries[idx].pos, SEEK_SET); + avio_seek(s->pb, ffstream(st)->index_entries[idx].pos, SEEK_SET); } else { if ((ret = ff_seek_frame_binary(s, stream_index, timestamp, flags)) < 0) return ret; diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c index e994312253..263b2a0532 100644 --- a/libavformat/av1dec.c +++ b/libavformat/av1dec.c @@ -75,9 +75,9 @@ static int av1_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_AV1; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; - st->internal->avctx->framerate = c->framerate; + ffstream(st)->avctx->framerate = c->framerate; // taken from rawvideo demuxers avpriv_set_pts_info(st, 64, 1, 1200000); diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 95746ec46a..3a5bc8a06d 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -821,8 +821,6 @@ typedef struct AVIndexEntry { */ #define AV_DISPOSITION_TIMED_THUMBNAILS 0x0800 -typedef struct AVStreamInternal AVStreamInternal; - /** * To specify text track kind (different from subtitles default). */ @@ -1003,12 +1001,6 @@ typedef struct AVStream { * */ int pts_wrap_bits; - - /** - * An opaque field for libavformat internal usage. - * Must not be accessed in any way by callers. - */ - AVStreamInternal *internal; } AVStream; struct AVCodecParserContext *av_stream_get_parser(const AVStream *s); diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 5d695b9839..661da7046a 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -279,8 +279,9 @@ static void clean_index(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; + FFStream *const sti = ffstream(st); AVIStream *ast = st->priv_data; - int n = st->internal->nb_index_entries; + int n = sti->nb_index_entries; int max = ast->sample_size; int64_t pos, size, ts; @@ -290,9 +291,9 @@ static void clean_index(AVFormatContext *s) while (max < 1024) max += max; - pos = st->internal->index_entries[0].pos; - size = st->internal->index_entries[0].size; - ts = st->internal->index_entries[0].timestamp; + pos = sti->index_entries[0].pos; + size = sti->index_entries[0].size; + ts = sti->index_entries[0].timestamp; for (j = 0; j < size; j += max) av_add_index_entry(st, pos + j, ts + j, FFMIN(max, size - j), 0, @@ -439,14 +440,14 @@ static int calculate_bitrate(AVFormatContext *s) for (i = 0; inb_streams; i++) { int64_t len = 0; - AVStream *st = s->streams[i]; + FFStream *const sti = ffstream(s->streams[i]); - if (!st->internal->nb_index_entries) + if (!sti->nb_index_entries) continue; - for (j = 0; j < st->internal->nb_index_entries; j++) - len += st->internal->index_entries[j].size; - maxpos = FFMAX(maxpos, st->internal->index_entries[j-1].pos); + for (j = 0; j < sti->nb_index_entries; j++) + len += sti->index_entries[j].size; + maxpos = FFMAX(maxpos, sti->index_entries[j-1].pos); lensum += len; } if (maxpos < av_rescale(avi->io_fsize, 9, 10)) // index does not cover the whole file @@ -457,15 +458,16 @@ static int calculate_bitrate(AVFormatContext *s) for (i = 0; inb_streams; i++) { int64_t len = 0; AVStream *st = s->streams[i]; + FFStream *const sti = ffstream(st); int64_t duration; int64_t bitrate; - for (j = 0; j < st->internal->nb_index_entries; j++) - len += st->internal->index_entries[j].size; + for (j = 0; j < sti->nb_index_entries; j++) + len += sti->index_entries[j].size; - if (st->internal->nb_index_entries < 2 || st->codecpar->bit_rate > 0) + if (sti->nb_index_entries < 2 || st->codecpar->bit_rate > 0) continue; - duration = st->internal->index_entries[j-1].timestamp - st->internal->index_entries[0].timestamp; + duration = sti->index_entries[j-1].timestamp - sti->index_entries[0].timestamp; bitrate = av_rescale(8*len, st->time_base.den, duration * st->time_base.num); if (bitrate > 0) { st->codecpar->bit_rate = bitrate; @@ -823,19 +825,19 @@ static int avi_read_header(AVFormatContext *s) /* This is needed to get the pict type which is necessary * for generating correct pts. */ - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 && ast->handler == MKTAG('X', 'V', 'I', 'D')) st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D'); if (st->codecpar->codec_tag == MKTAG('V', 'S', 'S', 'H')) - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; if (st->codecpar->codec_id == AV_CODEC_ID_RV40) - st->internal->need_parsing = AVSTREAM_PARSE_NONE; + ffstream(st)->need_parsing = AVSTREAM_PARSE_NONE; if (st->codecpar->codec_id == AV_CODEC_ID_HEVC && st->codecpar->codec_tag == MKTAG('H', '2', '6', '5')) - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; if (st->codecpar->codec_id == AV_CODEC_ID_AVRN && st->codecpar->codec_tag == MKTAG('A', 'V', 'R', 'n') && @@ -879,16 +881,16 @@ static int avi_read_header(AVFormatContext *s) avio_skip(pb, 1); /* Force parsing as several audio frames can be in * one packet and timestamps refer to packet start. */ - st->internal->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; /* ADTS header is in extradata, AAC without header must be * stored as exact frames. Parser not needed and it will * fail. */ if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size) - st->internal->need_parsing = AVSTREAM_PARSE_NONE; + ffstream(st)->need_parsing = AVSTREAM_PARSE_NONE; // The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) - st->internal->need_parsing = AVSTREAM_PARSE_NONE; + ffstream(st)->need_parsing = AVSTREAM_PARSE_NONE; /* AVI files with Xan DPCM audio (wrongly) declare PCM * audio in the header but have Axan as stream_code_tag. */ if (ast->handler == AV_RL32("Axan")) { @@ -915,7 +917,7 @@ static int avi_read_header(AVFormatContext *s) break; case AVMEDIA_TYPE_SUBTITLE: st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->internal->request_probe= 1; + ffstream(st)->request_probe= 1; avio_skip(pb, size); break; default: @@ -1050,12 +1052,12 @@ end_of_header: AVStream *st = s->streams[i]; if ( st->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO || st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; } for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->internal->nb_index_entries) + if (ffstream(st)->nb_index_entries) break; } // DV-in-AVI cannot be non-interleaved, if set this must be @@ -1341,9 +1343,10 @@ start_sync: ast->remaining = size; if (size) { + FFStream *const sti = ffstream(st); uint64_t pos = avio_tell(pb) - 8; - if (!st->internal->index_entries || !st->internal->nb_index_entries || - st->internal->index_entries[st->internal->nb_index_entries - 1].pos < pos) { + if (!sti->index_entries || !sti->nb_index_entries || + sti->index_entries[sti->nb_index_entries - 1].pos < pos) { av_add_index_entry(st, pos, ast->frame_offset, size, 0, AVINDEX_KEYFRAME); } @@ -1369,14 +1372,15 @@ static int ni_prepare_read(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; + FFStream *const sti = ffstream(st); AVIStream *ast = st->priv_data; int64_t ts = ast->frame_offset; int64_t last_ts; - if (!st->internal->nb_index_entries) + if (!sti->nb_index_entries) continue; - last_ts = st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp; + last_ts = sti->index_entries[sti->nb_index_entries - 1].timestamp; if (!ast->remaining && ts > last_ts) continue; @@ -1405,11 +1409,11 @@ static int ni_prepare_read(AVFormatContext *s) } else { i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY); if (i >= 0) - best_ast->frame_offset = best_st->internal->index_entries[i].timestamp; + best_ast->frame_offset = ffstream(best_st)->index_entries[i].timestamp; } if (i >= 0) { - int64_t pos = best_st->internal->index_entries[i].pos; + int64_t pos = ffstream(best_st)->index_entries[i].pos; pos += best_ast->packet_size - best_ast->remaining; if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0) return AVERROR_EOF; @@ -1419,7 +1423,7 @@ static int ni_prepare_read(AVFormatContext *s) avi->stream_index = best_stream_index; if (!best_ast->remaining) best_ast->packet_size = - best_ast->remaining = best_st->internal->index_entries[i].size; + best_ast->remaining = ffstream(best_st)->index_entries[i].size; } else return AVERROR_EOF; @@ -1508,15 +1512,15 @@ resync: pkt->dts /= ast->sample_size; pkt->stream_index = avi->stream_index; - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->index_entries) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ffstream(st)->index_entries) { AVIndexEntry *e; int index; index = av_index_search_timestamp(st, ast->frame_offset, AVSEEK_FLAG_ANY); - e = &st->internal->index_entries[index]; + e = &ffstream(st)->index_entries[index]; if (index >= 0 && e->timestamp == ast->frame_offset) { - if (index == st->internal->nb_index_entries-1) { + if (index == ffstream(st)->nb_index_entries-1) { int key=1; uint32_t state=-1; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { @@ -1552,7 +1556,7 @@ resync: } ast->seek_pos= 0; - if (!avi->non_interleaved && st->internal->nb_index_entries>1 && avi->index_loaded>1) { + if (!avi->non_interleaved && ffstream(st)->nb_index_entries>1 && avi->index_loaded>1) { int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q); if (avi->dts_max < dts) { @@ -1651,9 +1655,9 @@ static int avi_read_idx1(AVFormatContext *s, int size) } if (!anykey) { for (index = 0; index < s->nb_streams; index++) { - st = s->streams[index]; - if (st->internal->nb_index_entries) - st->internal->index_entries[0].flags |= AVINDEX_KEYFRAME; + FFStream *const sti = ffstream(s->streams[index]); + if (sti->nb_index_entries) + sti->index_entries[0].flags |= AVINDEX_KEYFRAME; } } return 0; @@ -1678,16 +1682,17 @@ static int check_stream_max_drift(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; AVIStream *ast = st->priv_data; - int n = st->internal->nb_index_entries; - while (idx[i] < n && st->internal->index_entries[idx[i]].pos < pos) + FFStream *const sti = ffstream(st); + int n = sti->nb_index_entries; + while (idx[i] < n && sti->index_entries[idx[i]].pos < pos) idx[i]++; if (idx[i] < n) { int64_t dts; - dts = av_rescale_q(st->internal->index_entries[idx[i]].timestamp / + dts = av_rescale_q(sti->index_entries[idx[i]].timestamp / FFMAX(ast->sample_size, 1), st->time_base, AV_TIME_BASE_Q); min_dts = FFMIN(min_dts, dts); - min_pos = FFMIN(min_pos, st->internal->index_entries[idx[i]].pos); + min_pos = FFMIN(min_pos, sti->index_entries[idx[i]].pos); } } for (i = 0; i < s->nb_streams; i++) { @@ -1696,7 +1701,7 @@ static int check_stream_max_drift(AVFormatContext *s) if (idx[i] && min_dts != INT64_MAX / 2) { int64_t dts, delta_dts; - dts = av_rescale_q(st->internal->index_entries[idx[i] - 1].timestamp / + dts = av_rescale_q(ffstream(st)->index_entries[idx[i] - 1].timestamp / FFMAX(ast->sample_size, 1), st->time_base, AV_TIME_BASE_Q); delta_dts = av_sat_sub64(dts, min_dts); @@ -1726,30 +1731,31 @@ static int guess_ni_flag(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - int n = st->internal->nb_index_entries; + FFStream *const sti = ffstream(st); + int n = sti->nb_index_entries; unsigned int size; if (n <= 0) continue; if (n >= 2) { - int64_t pos = st->internal->index_entries[0].pos; + int64_t pos = sti->index_entries[0].pos; unsigned tag[2]; avio_seek(s->pb, pos, SEEK_SET); tag[0] = avio_r8(s->pb); tag[1] = avio_r8(s->pb); avio_rl16(s->pb); size = avio_rl32(s->pb); - if (get_stream_idx(tag) == i && pos + size > st->internal->index_entries[1].pos) + if (get_stream_idx(tag) == i && pos + size > sti->index_entries[1].pos) last_start = INT64_MAX; - if (get_stream_idx(tag) == i && size == st->internal->index_entries[0].size + 8) + if (get_stream_idx(tag) == i && size == sti->index_entries[0].size + 8) last_start = INT64_MAX; } - if (st->internal->index_entries[0].pos > last_start) - last_start = st->internal->index_entries[0].pos; - if (st->internal->index_entries[n - 1].pos < first_end) - first_end = st->internal->index_entries[n - 1].pos; + if (sti->index_entries[0].pos > last_start) + last_start = sti->index_entries[0].pos; + if (sti->index_entries[n - 1].pos < first_end) + first_end = sti->index_entries[n - 1].pos; } avio_seek(s->pb, oldpos, SEEK_SET); @@ -1817,6 +1823,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, { AVIContext *avi = s->priv_data; AVStream *st; + FFStream *sti; int i, index; int64_t pos, pos_min; AVIStream *ast; @@ -1835,25 +1842,26 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, av_assert0(stream_index >= 0); st = s->streams[stream_index]; + sti = ffstream(st); ast = st->priv_data; index = av_index_search_timestamp(st, timestamp * FFMAX(ast->sample_size, 1), flags); if (index < 0) { - if (st->internal->nb_index_entries > 0) + if (sti->nb_index_entries > 0) av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n", timestamp * FFMAX(ast->sample_size, 1), - st->internal->index_entries[0].timestamp, - st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp); + sti->index_entries[0].timestamp, + sti->index_entries[sti->nb_index_entries - 1].timestamp); return AVERROR_INVALIDDATA; } /* find the position */ - pos = st->internal->index_entries[index].pos; - timestamp = st->internal->index_entries[index].timestamp / FFMAX(ast->sample_size, 1); + pos = sti->index_entries[index].pos; + timestamp = sti->index_entries[index].timestamp / FFMAX(ast->sample_size, 1); av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n", - timestamp, index, st->internal->index_entries[index].timestamp); + timestamp, index, sti->index_entries[index].timestamp); if (CONFIG_DV_DEMUXER && avi->dv_demux) { /* One and only one real stream for DV in AVI, and it has video */ @@ -1884,7 +1892,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, continue; } - if (st2->internal->nb_index_entries <= 0) + if (ffstream(st2)->nb_index_entries <= 0) continue; // av_assert1(st2->codecpar->block_align); @@ -1898,14 +1906,14 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); if (index < 0) index = 0; - ast2->seek_pos = st2->internal->index_entries[index].pos; + ast2->seek_pos = ffstream(st2)->index_entries[index].pos; pos_min = FFMIN(pos_min,ast2->seek_pos); } for (i = 0; i < s->nb_streams; i++) { AVStream *st2 = s->streams[i]; AVIStream *ast2 = st2->priv_data; - if (ast2->sub_ctx || st2->internal->nb_index_entries <= 0) + if (ast2->sub_ctx || ffstream(st2)->nb_index_entries <= 0) continue; index = av_index_search_timestamp( @@ -1914,9 +1922,9 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, flags | AVSEEK_FLAG_BACKWARD | (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); if (index < 0) index = 0; - while (!avi->non_interleaved && index>0 && st2->internal->index_entries[index-1].pos >= pos_min) + while (!avi->non_interleaved && index>0 && ffstream(st2)->index_entries[index-1].pos >= pos_min) index--; - ast2->frame_offset = st2->internal->index_entries[index].timestamp; + ast2->frame_offset = ffstream(st2)->index_entries[index].timestamp; } /* do the seek */ diff --git a/libavformat/bink.c b/libavformat/bink.c index 2488aeae2f..8b8841dba9 100644 --- a/libavformat/bink.c +++ b/libavformat/bink.c @@ -225,8 +225,8 @@ static int read_header(AVFormatContext *s) return ret; } - if (vst->internal->index_entries) - avio_seek(pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET); + if (ffstream(vst)->index_entries) + avio_seek(pb, ffstream(vst)->index_entries[0].pos + bink->smush_size, SEEK_SET); else avio_skip(pb, 4); @@ -256,8 +256,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EIO); } - bink->remain_packet_size = st->internal->index_entries[index_entry].size; - bink->flags = st->internal->index_entries[index_entry].flags; + bink->remain_packet_size = ffstream(st)->index_entries[index_entry].size; + bink->flags = ffstream(st)->index_entries[index_entry].flags; bink->current_track = 0; } @@ -313,7 +313,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in return -1; /* seek to the first frame */ - ret = avio_seek(s->pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET); + ret = avio_seek(s->pb, ffstream(vst)->index_entries[0].pos + bink->smush_size, SEEK_SET); if (ret < 0) return ret; diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index e9d171e36b..defa0cda7f 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -342,7 +342,7 @@ found_data: if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) { if (caf->data_size > 0) st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet; - } else if (st->internal->nb_index_entries && st->duration > 0) { + } else if (ffstream(st)->nb_index_entries && st->duration > 0) { if (st->codecpar->sample_rate && caf->data_size / st->duration > INT64_MAX / st->codecpar->sample_rate / 8) { av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %d * 8 * %"PRId64"\n", st->codecpar->sample_rate, caf->data_size / st->duration); @@ -372,6 +372,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; AVStream *st = s->streams[0]; + FFStream *const sti = ffstream(st); CafContext *caf = s->priv_data; int res, pkt_size = 0, pkt_frames = 0; int64_t left = CAF_MAX_PKT_SIZE; @@ -395,13 +396,13 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) pkt_size = (CAF_MAX_PKT_SIZE / pkt_size) * pkt_size; pkt_size = FFMIN(pkt_size, left); pkt_frames = pkt_size / caf->bytes_per_packet; - } else if (st->internal->nb_index_entries) { - if (caf->packet_cnt < st->internal->nb_index_entries - 1) { - pkt_size = st->internal->index_entries[caf->packet_cnt + 1].pos - st->internal->index_entries[caf->packet_cnt].pos; - pkt_frames = st->internal->index_entries[caf->packet_cnt + 1].timestamp - st->internal->index_entries[caf->packet_cnt].timestamp; - } else if (caf->packet_cnt == st->internal->nb_index_entries - 1) { - pkt_size = caf->num_bytes - st->internal->index_entries[caf->packet_cnt].pos; - pkt_frames = st->duration - st->internal->index_entries[caf->packet_cnt].timestamp; + } else if (sti->nb_index_entries) { + if (caf->packet_cnt < sti->nb_index_entries - 1) { + pkt_size = sti->index_entries[caf->packet_cnt + 1].pos - sti->index_entries[caf->packet_cnt].pos; + pkt_frames = sti->index_entries[caf->packet_cnt + 1].timestamp - sti->index_entries[caf->packet_cnt].timestamp; + } else if (caf->packet_cnt == sti->nb_index_entries - 1) { + pkt_size = caf->num_bytes - sti->index_entries[caf->packet_cnt].pos; + pkt_frames = st->duration - sti->index_entries[caf->packet_cnt].timestamp; } else { return AVERROR(EIO); } @@ -440,10 +441,10 @@ static int read_seek(AVFormatContext *s, int stream_index, pos = FFMIN(pos, caf->data_size); packet_cnt = pos / caf->bytes_per_packet; frame_cnt = caf->frames_per_packet * packet_cnt; - } else if (st->internal->nb_index_entries) { + } else if (ffstream(st)->nb_index_entries) { packet_cnt = av_index_search_timestamp(st, timestamp, flags); - frame_cnt = st->internal->index_entries[packet_cnt].timestamp; - pos = st->internal->index_entries[packet_cnt].pos; + frame_cnt = ffstream(st)->index_entries[packet_cnt].timestamp; + pos = ffstream(st)->index_entries[packet_cnt].pos; } else { return -1; } diff --git a/libavformat/cinedec.c b/libavformat/cinedec.c index f1fae6e5db..c53ccb9c91 100644 --- a/libavformat/cinedec.c +++ b/libavformat/cinedec.c @@ -288,10 +288,10 @@ static int cine_read_packet(AVFormatContext *avctx, AVPacket *pkt) AVIOContext *pb = avctx->pb; int n, size, ret; - if (cine->pts >= st->internal->nb_index_entries) + if (cine->pts >= ffstream(st)->nb_index_entries) return AVERROR_EOF; - avio_seek(pb, st->internal->index_entries[cine->pts].pos, SEEK_SET); + avio_seek(pb, ffstream(st)->index_entries[cine->pts].pos, SEEK_SET); n = avio_rl32(pb); if (n < 8) return AVERROR_INVALIDDATA; diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index 30db456b0e..8e3aeafed0 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -667,8 +667,8 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) } } - if (cat->cur_file->duration == AV_NOPTS_VALUE && st->internal->cur_dts != AV_NOPTS_VALUE) { - int64_t next_dts = av_rescale_q(st->internal->cur_dts, st->time_base, AV_TIME_BASE_Q); + if (cat->cur_file->duration == AV_NOPTS_VALUE && ffstream(st)->cur_dts != AV_NOPTS_VALUE) { + int64_t next_dts = av_rescale_q(ffstream(st)->cur_dts, st->time_base, AV_TIME_BASE_Q); if (cat->cur_file->next_dts == AV_NOPTS_VALUE || next_dts > cat->cur_file->next_dts) { cat->cur_file->next_dts = next_dts; } diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 679e30611c..e36a9f6a07 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -2346,8 +2346,8 @@ static int dash_check_bitstream(struct AVFormatContext *s, const AVPacket *avpkt if (ret == 1) { AVStream *st = s->streams[avpkt->stream_index]; AVStream *ost = oc->streams[0]; - st->internal->bsfc = ost->internal->bsfc; - ost->internal->bsfc = NULL; + ffstream(st)->bsfc = ffstream(ost)->bsfc; + ffstream(ost)->bsfc = NULL; } return ret; } diff --git a/libavformat/dhav.c b/libavformat/dhav.c index 92bbfab7c5..0915cd197d 100644 --- a/libavformat/dhav.c +++ b/libavformat/dhav.c @@ -434,10 +434,10 @@ static int dhav_read_seek(AVFormatContext *s, int stream_index, if (index < 0) return -1; - if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, ffstream(st)->index_entries[index].pos, SEEK_SET) < 0) return -1; - pts = st->internal->index_entries[index].timestamp; + pts = ffstream(st)->index_entries[index].timestamp; for (int n = 0; n < s->nb_streams; n++) { AVStream *st = s->streams[n]; diff --git a/libavformat/dtshddec.c b/libavformat/dtshddec.c index 2900623690..b84588af7c 100644 --- a/libavformat/dtshddec.c +++ b/libavformat/dtshddec.c @@ -65,7 +65,7 @@ static int dtshd_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_DTS; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; for (;;) { chunk_type = avio_rb64(pb); diff --git a/libavformat/dump.c b/libavformat/dump.c index cf892de107..4824965ee9 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -508,6 +508,7 @@ static void dump_stream_format(const AVFormatContext *ic, int i, char buf[256]; int flags = (is_output ? ic->oformat->flags : ic->iformat->flags); const AVStream *st = ic->streams[i]; + const FFStream *const sti = cffstream(st); const AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); const char *separator = ic->dump_separator; AVCodecContext *avctx; @@ -524,12 +525,12 @@ static void dump_stream_format(const AVFormatContext *ic, int i, } // Fields which are missing from AVCodecParameters need to be taken from the AVCodecContext - avctx->properties = st->internal->avctx->properties; - avctx->codec = st->internal->avctx->codec; - avctx->qmin = st->internal->avctx->qmin; - avctx->qmax = st->internal->avctx->qmax; - avctx->coded_width = st->internal->avctx->coded_width; - avctx->coded_height = st->internal->avctx->coded_height; + avctx->properties = sti->avctx->properties; + avctx->codec = sti->avctx->codec; + avctx->qmin = sti->avctx->qmin; + avctx->qmax = sti->avctx->qmax; + avctx->coded_width = sti->avctx->coded_width; + avctx->coded_height = sti->avctx->coded_height; if (separator) av_opt_set(avctx, "dump_separator", separator, 0); @@ -544,7 +545,7 @@ static void dump_stream_format(const AVFormatContext *ic, int i, av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id); if (lang) av_log(NULL, AV_LOG_INFO, "(%s)", lang->value); - av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->internal->codec_info_nb_frames, + av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", sti->codec_info_nb_frames, st->time_base.num, st->time_base.den); av_log(NULL, AV_LOG_INFO, ": %s", buf); diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c index 4d0fddab3d..2fb09b34ca 100644 --- a/libavformat/electronicarts.c +++ b/libavformat/electronicarts.c @@ -503,7 +503,7 @@ static int init_video_stream(AVFormatContext *s, VideoProperties *video) st->codecpar->codec_id = video->codec; // parsing is necessary to make FFmpeg generate correct timestamps if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; st->codecpar->codec_tag = 0; /* no fourcc */ st->codecpar->width = video->width; st->codecpar->height = video->height; diff --git a/libavformat/fifo.c b/libavformat/fifo.c index 10511167cd..51d7fa5b94 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -139,7 +139,7 @@ static int fifo_thread_write_header(FifoThreadContext *ctx) } for (i = 0;i < avf2->nb_streams; i++) - avf2->streams[i]->internal->cur_dts = 0; + ffstream(avf2->streams[i])->cur_dts = 0; ret = avformat_write_header(avf2, &format_options); if (!ret) diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 2730e9cc50..6992220d40 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -38,10 +38,8 @@ typedef struct FLACDecContext { static void reset_index_position(int64_t metadata_head_size, AVStream *st) { /* the real seek index offset should be the size of metadata blocks with the offset in the frame blocks */ - int i; - for(i=0; iinternal->nb_index_entries; i++) { - st->internal->index_entries[i].pos += metadata_head_size; - } + for (int i = 0; i < ffstream(st)->nb_index_entries; i++) + ffstream(st)->index_entries[i].pos += metadata_head_size; } static int flac_read_header(AVFormatContext *s) @@ -55,7 +53,7 @@ static int flac_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_FLAC; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; /* the parameters will be extracted from the compressed bitstream */ /* if fLaC marker is not found, assume there is no header */ @@ -286,7 +284,7 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde av_assert1(!pkt->size); } } - av_parser_parse2(parser, st->internal->avctx, + av_parser_parse2(parser, ffstream(st)->avctx, &data, &size, pkt->data, pkt->size, pkt->pts, pkt->dts, *ppos); @@ -317,10 +315,10 @@ static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in } index = av_index_search_timestamp(s->streams[0], timestamp, flags); - if(index<0 || index >= s->streams[0]->internal->nb_index_entries) + if(index<0 || index >= ffstream(s->streams[0])->nb_index_entries) return -1; - e = s->streams[0]->internal->index_entries[index]; + e = ffstream(s->streams[0])->index_entries[index]; pos = avio_seek(s->pb, e.pos, SEEK_SET); if (pos >= 0) { return 0; diff --git a/libavformat/flic.c b/libavformat/flic.c index efd9e54308..14c614d831 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -268,7 +268,7 @@ static int flic_read_seek(AVFormatContext *s, int stream_index, int64_t pos, ts; int index; - if (!st->internal->index_entries || stream_index != flic->video_stream_index) + if (!ffstream(st)->index_entries || stream_index != flic->video_stream_index) return -1; index = av_index_search_timestamp(st, pts, flags); @@ -278,8 +278,8 @@ static int flic_read_seek(AVFormatContext *s, int stream_index, if (index < 0) return -1; - pos = st->internal->index_entries[index].pos; - ts = st->internal->index_entries[index].timestamp; + pos = ffstream(st)->index_entries[index].pos; + ts = ffstream(st)->index_entries[index].timestamp; flic->frame_number = ts; avio_seek(s->pb, pos, SEEK_SET); return 0; diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index b4a419177a..c973de1681 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -143,7 +143,7 @@ static void add_keyframes_index(AVFormatContext *s) av_assert0(flv->last_keyframe_stream_index <= s->nb_streams); stream = s->streams[flv->last_keyframe_stream_index]; - if (stream->internal->nb_index_entries == 0) { + if (ffstream(stream)->nb_index_entries == 0) { for (i = 0; i < flv->keyframe_count; i++) { av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n", flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000); @@ -272,7 +272,7 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, break; case FLV_CODECID_MP3: apar->codec_id = AV_CODEC_ID_MP3; - astream->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(astream)->need_parsing = AVSTREAM_PARSE_FULL; break; case FLV_CODECID_NELLYMOSER_8KHZ_MONO: // in case metadata does not otherwise declare samplerate @@ -363,7 +363,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, break; case FLV_CODECID_H264: par->codec_id = AV_CODEC_ID_H264; - vstream->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(vstream)->need_parsing = AVSTREAM_PARSE_HEADERS; ret = 3; // not 4, reading packet type will consume one byte break; case FLV_CODECID_MPEG4: @@ -375,7 +375,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, par->codec_tag = flv_codecid; } - if (!vstream->internal->need_context_update && par->codec_id != old_codec_id) { + if (!ffstream(vstream)->need_context_update && par->codec_id != old_codec_id) { avpriv_request_sample(s, "Changing the codec id midstream"); return AVERROR_PATCHWELCOME; } @@ -815,7 +815,7 @@ static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0) return ret; - st->internal->need_context_update = 1; + ffstream(st)->need_context_update = 1; return 0; } @@ -837,17 +837,16 @@ static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, static void clear_index_entries(AVFormatContext *s, int64_t pos) { - int i, j, out; av_log(s, AV_LOG_WARNING, "Found invalid index entries, clearing the index.\n"); - for (i = 0; i < s->nb_streams; i++) { - AVStream *st = s->streams[i]; + for (unsigned i = 0; i < s->nb_streams; i++) { + FFStream *const sti = ffstream(s->streams[i]); + int out = 0; /* Remove all index entries that point to >= pos */ - out = 0; - for (j = 0; j < st->internal->nb_index_entries; j++) - if (st->internal->index_entries[j].pos < pos) - st->internal->index_entries[out++] = st->internal->index_entries[j]; - st->internal->nb_index_entries = out; + for (int j = 0; j < sti->nb_index_entries; j++) + if (sti->index_entries[j].pos < pos) + sti->index_entries[out++] = sti->index_entries[j]; + sti->nb_index_entries = out; } } diff --git a/libavformat/gxf.c b/libavformat/gxf.c index 7d23cbd692..ef1a50f5c2 100644 --- a/libavformat/gxf.c +++ b/libavformat/gxf.c @@ -130,13 +130,13 @@ static int get_sindex(AVFormatContext *s, int id, int format) { case 20: st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 22: case 23: st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG1VIDEO; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 9: st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; @@ -169,7 +169,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) { case 29: /* AVCHD */ st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_H264; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; break; // timecode tracks: case 7: @@ -575,9 +575,9 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); if (idx < 0) return -1; - pos = st->internal->index_entries[idx].pos; - if (idx < st->internal->nb_index_entries - 2) - maxlen = st->internal->index_entries[idx + 2].pos - pos; + pos = ffstream(st)->index_entries[idx].pos; + if (idx < ffstream(st)->nb_index_entries - 2) + maxlen = ffstream(st)->index_entries[idx + 2].pos - pos; maxlen = FFMAX(maxlen, 200 * 1024); res = avio_seek(s->pb, pos, SEEK_SET); if (res < 0) diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c index 1793fb69d5..0c3c98fcc0 100644 --- a/libavformat/hdsenc.c +++ b/libavformat/hdsenc.c @@ -504,11 +504,11 @@ static int hds_write_packet(AVFormatContext *s, AVPacket *pkt) int64_t end_dts = os->fragment_index * (int64_t)c->min_frag_duration; int ret; - if (st->internal->first_dts == AV_NOPTS_VALUE) - st->internal->first_dts = pkt->dts; + if (ffstream(st)->first_dts == AV_NOPTS_VALUE) + ffstream(st)->first_dts = pkt->dts; if ((!os->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && - av_compare_ts(pkt->dts - st->internal->first_dts, st->time_base, + av_compare_ts(pkt->dts - ffstream(st)->first_dts, st->time_base, end_dts, AV_TIME_BASE_Q) >= 0 && pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) { diff --git a/libavformat/hls.c b/libavformat/hls.c index 421a60a476..9fd4ad9f32 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -1794,7 +1794,7 @@ static int set_stream_info_from_input_stream(AVStream *st, struct playlist *pls, memcpy(dst_data, sd_src->data, sd_src->size); } - st->internal->need_context_update = 1; + ffstream(st)->need_context_update = 1; return 0; } diff --git a/libavformat/ifv.c b/libavformat/ifv.c index b3b9213aa5..54c8fde1d2 100644 --- a/libavformat/ifv.c +++ b/libavformat/ifv.c @@ -196,15 +196,15 @@ static int ifv_read_packet(AVFormatContext *s, AVPacket *pkt) if (ifv->next_video_index < ifv->total_vframes) { st = s->streams[ifv->video_stream_index]; - if (ifv->next_video_index < st->internal->nb_index_entries) - e_next = ev = &st->internal->index_entries[ifv->next_video_index]; + if (ifv->next_video_index < ffstream(st)->nb_index_entries) + e_next = ev = &ffstream(st)->index_entries[ifv->next_video_index]; } if (ifv->is_audio_present && ifv->next_audio_index < ifv->total_aframes) { st = s->streams[ifv->audio_stream_index]; - if (ifv->next_audio_index < st->internal->nb_index_entries) { - ea = &st->internal->index_entries[ifv->next_audio_index]; + if (ifv->next_audio_index < ffstream(st)->nb_index_entries) { + ea = &ffstream(st)->index_entries[ifv->next_audio_index]; if (!ev || ea->timestamp < ev->timestamp) e_next = ea; } diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index 485444ed31..ad4cc623c8 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -209,7 +209,7 @@ int ff_img_read_header(AVFormatContext *s1) s->is_pipe = 0; else { s->is_pipe = 1; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; } if (s->ts_from_file == 2) { @@ -482,7 +482,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) return AVERROR_EOF; if (s->frame_size > 0) { size[0] = s->frame_size; - } else if (!s1->streams[0]->internal->parser) { + } else if (!ffstream(s1->streams[0])->parser) { size[0] = avio_size(s1->pb); } else { size[0] = 4096; @@ -590,7 +590,7 @@ static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp int index = av_index_search_timestamp(st, timestamp, flags); if(index < 0) return -1; - s1->img_number = st->internal->index_entries[index].pos; + s1->img_number = ffstream(st)->index_entries[index].pos; return 0; } diff --git a/libavformat/internal.h b/libavformat/internal.h index 813032870f..6f53bd44a9 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -185,7 +185,12 @@ static av_always_inline FFFormatContext *ffformatcontext(AVFormatContext *s) return (FFFormatContext*)s; } -struct AVStreamInternal { +typedef struct FFStream { + /** + * The public context. + */ + AVStream pub; + /** * Set to 1 if the codec allows reordering, so pts can be different * from dts. @@ -416,7 +421,17 @@ struct AVStreamInternal { */ int64_t first_dts; int64_t cur_dts; -}; +} FFStream; + +static av_always_inline FFStream *ffstream(AVStream *st) +{ + return (FFStream*)st; +} + +static av_always_inline const FFStream *cffstream(const AVStream *st) +{ + return (FFStream*)st; +} void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type); diff --git a/libavformat/ipudec.c b/libavformat/ipudec.c index 27b6b59356..a314a89001 100644 --- a/libavformat/ipudec.c +++ b/libavformat/ipudec.c @@ -62,7 +62,7 @@ static int ipu_read_header(AVFormatContext *s) st->start_time = 0; st->duration = st->nb_frames = avio_rl32(pb); - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 1, 25); return 0; diff --git a/libavformat/iv8.c b/libavformat/iv8.c index b06797cbf3..a3954ca1ed 100644 --- a/libavformat/iv8.c +++ b/libavformat/iv8.c @@ -47,7 +47,7 @@ static int read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG4; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 90000); return 0; diff --git a/libavformat/ivfdec.c b/libavformat/ivfdec.c index 26717c4999..511f2387ed 100644 --- a/libavformat/ivfdec.c +++ b/libavformat/ivfdec.c @@ -56,7 +56,7 @@ static int read_header(AVFormatContext *s) st->duration = avio_rl32(s->pb); avio_skip(s->pb, 4); // unused - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; if (!time_base.den || !time_base.num) { av_log(s, AV_LOG_ERROR, "Invalid frame rate\n"); diff --git a/libavformat/jvdec.c b/libavformat/jvdec.c index a044f50831..db76fedc4c 100644 --- a/libavformat/jvdec.c +++ b/libavformat/jvdec.c @@ -74,9 +74,9 @@ static int read_header(AVFormatContext *s) JVDemuxContext *jv = s->priv_data; AVIOContext *pb = s->pb; AVStream *vst, *ast; + FFStream *asti; int64_t audio_pts = 0; int64_t offset; - int i; avio_skip(pb, 80); @@ -84,6 +84,7 @@ static int read_header(AVFormatContext *s) vst = avformat_new_stream(s, NULL); if (!ast || !vst) return AVERROR(ENOMEM); + asti = ffstream(ast); vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; vst->codecpar->codec_id = AV_CODEC_ID_JV; @@ -92,7 +93,7 @@ static int read_header(AVFormatContext *s) vst->codecpar->height = avio_rl16(pb); vst->duration = vst->nb_frames = - ast->internal->nb_index_entries = avio_rl16(pb); + asti->nb_index_entries = avio_rl16(pb); avpriv_set_pts_info(vst, 64, avio_rl16(pb), 1000); avio_skip(pb, 4); @@ -107,17 +108,17 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 10); - ast->internal->index_entries = av_malloc(ast->internal->nb_index_entries * - sizeof(*ast->internal->index_entries)); - if (!ast->internal->index_entries) + asti->index_entries = av_malloc(asti->nb_index_entries * + sizeof(*asti->index_entries)); + if (!asti->index_entries) return AVERROR(ENOMEM); - jv->frames = av_malloc(ast->internal->nb_index_entries * sizeof(JVFrame)); + jv->frames = av_malloc(asti->nb_index_entries * sizeof(*jv->frames)); if (!jv->frames) return AVERROR(ENOMEM); - offset = 0x68 + ast->internal->nb_index_entries * 16; - for (i = 0; i < ast->internal->nb_index_entries; i++) { - AVIndexEntry *e = ast->internal->index_entries + i; + offset = 0x68 + asti->nb_index_entries * 16; + for (int i = 0; i < asti->nb_index_entries; i++) { + AVIndexEntry *e = asti->index_entries + i; JVFrame *jvf = jv->frames + i; /* total frame size including audio, video, palette data and padding */ @@ -164,8 +165,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) AVStream *ast = s->streams[0]; int ret; - while (!avio_feof(s->pb) && jv->pts < ast->internal->nb_index_entries) { - const AVIndexEntry *e = ast->internal->index_entries + jv->pts; + while (!avio_feof(s->pb) && jv->pts < ffstream(ast)->nb_index_entries) { + const AVIndexEntry *const e = ffstream(ast)->index_entries + jv->pts; const JVFrame *jvf = jv->frames + jv->pts; switch (jv->state) { @@ -238,9 +239,9 @@ static int read_seek(AVFormatContext *s, int stream_index, return 0; } - if (i < 0 || i >= ast->internal->nb_index_entries) + if (i < 0 || i >= ffstream(ast)->nb_index_entries) return 0; - if (avio_seek(s->pb, ast->internal->index_entries[i].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, ffstream(ast)->index_entries[i].pos, SEEK_SET) < 0) return -1; jv->state = JV_AUDIO; diff --git a/libavformat/lmlm4.c b/libavformat/lmlm4.c index dbeaceab9c..b0bfad001b 100644 --- a/libavformat/lmlm4.c +++ b/libavformat/lmlm4.c @@ -67,14 +67,14 @@ static int lmlm4_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG4; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; avpriv_set_pts_info(st, 64, 1001, 30000); if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_MP2; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; /* the parameters will be extracted from the compressed bitstream */ return 0; diff --git a/libavformat/loasdec.c b/libavformat/loasdec.c index 3c84d9f37e..e739b6c196 100644 --- a/libavformat/loasdec.c +++ b/libavformat/loasdec.c @@ -75,7 +75,7 @@ static int loas_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = s->iformat->raw_codec_id; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; //LCM of all possible AAC sample rates avpriv_set_pts_info(st, 64, 1, 28224000); diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c index 79ccc77747..7889abb2c9 100644 --- a/libavformat/lxfdec.c +++ b/libavformat/lxfdec.c @@ -262,7 +262,7 @@ static int lxf_read_header(AVFormatContext *s) st->codecpar->bit_rate = 1000000 * ((video_params >> 14) & 0xFF); st->codecpar->codec_tag = video_params & 0xF; st->codecpar->codec_id = ff_codec_get_id(lxf_tags, st->codecpar->codec_tag); - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; av_log(s, AV_LOG_DEBUG, "record: %x = %i-%02i-%02i\n", record_date, 1900 + (record_date & 0x7F), (record_date >> 7) & 0xF, diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 4bc6b40f44..17280e233e 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2802,7 +2802,7 @@ static int matroska_parse_tracks(AVFormatContext *s) 255); } if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->default_duration) { int div = track->default_duration <= INT64_MAX ? 1 : 2; @@ -2861,9 +2861,9 @@ static int matroska_parse_tracks(AVFormatContext *s) if (st->codecpar->codec_id == AV_CODEC_ID_MP3 || st->codecpar->codec_id == AV_CODEC_ID_MLP || st->codecpar->codec_id == AV_CODEC_ID_TRUEHD) - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; else if (st->codecpar->codec_id != AV_CODEC_ID_AAC) - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->codec_delay > 0) { st->codecpar->initial_padding = av_rescale_q(track->codec_delay, (AVRational){1, 1000000000}, @@ -3651,7 +3651,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf return res; if (is_keyframe) matroska->skip_to_keyframe = 0; - else if (!st->internal->skip_to_keyframe) { + else if (!ffstream(st)->skip_to_keyframe) { av_log(matroska->ctx, AV_LOG_ERROR, "File is broken, keyframes not correctly marked!\n"); matroska->skip_to_keyframe = 0; } @@ -3813,6 +3813,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, MatroskaDemuxContext *matroska = s->priv_data; MatroskaTrack *tracks = NULL; AVStream *st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); int i, index; /* Parse the CUES now since we need the index data to seek. */ @@ -3821,13 +3822,13 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, matroska_parse_cues(matroska); } - if (!st->internal->nb_index_entries) + if (!sti->nb_index_entries) goto err; - timestamp = FFMAX(timestamp, st->internal->index_entries[0].timestamp); + timestamp = FFMAX(timestamp, sti->index_entries[0].timestamp); - if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) { - matroska_reset_status(matroska, 0, st->internal->index_entries[st->internal->nb_index_entries - 1].pos); - while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) { + if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == sti->nb_index_entries - 1) { + matroska_reset_status(matroska, 0, sti->index_entries[sti->nb_index_entries - 1].pos); + while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == sti->nb_index_entries - 1) { matroska_clear_queue(matroska); if (matroska_parse_cluster(matroska) < 0) break; @@ -3835,7 +3836,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, } matroska_clear_queue(matroska); - if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->internal->nb_index_entries - 1)) + if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == sti->nb_index_entries - 1)) goto err; tracks = matroska->tracks.elem; @@ -3847,17 +3848,17 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, } /* We seek to a level 1 element, so set the appropriate status. */ - matroska_reset_status(matroska, 0, st->internal->index_entries[index].pos); + matroska_reset_status(matroska, 0, sti->index_entries[index].pos); if (flags & AVSEEK_FLAG_ANY) { - st->internal->skip_to_keyframe = 0; + sti->skip_to_keyframe = 0; matroska->skip_to_timecode = timestamp; } else { - st->internal->skip_to_keyframe = 1; - matroska->skip_to_timecode = st->internal->index_entries[index].timestamp; + sti->skip_to_keyframe = 1; + matroska->skip_to_timecode = sti->index_entries[index].timestamp; } matroska->skip_to_keyframe = 1; matroska->done = 0; - avpriv_update_cur_dts(s, st, st->internal->index_entries[index].timestamp); + avpriv_update_cur_dts(s, st, sti->index_entries[index].timestamp); return 0; err: // slightly hackish but allows proper fallback to @@ -3865,7 +3866,7 @@ err: matroska_reset_status(matroska, 0, -1); matroska->resync_pos = -1; matroska_clear_queue(matroska); - st->internal->skip_to_keyframe = + sti->skip_to_keyframe = matroska->skip_to_keyframe = 0; matroska->done = 0; return -1; @@ -3903,8 +3904,8 @@ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start) MatroskaDemuxContext *matroska = s->priv_data; CueDesc cue_desc; int i; - int nb_index_entries = s->streams[0]->internal->nb_index_entries; - AVIndexEntry *index_entries = s->streams[0]->internal->index_entries; + int nb_index_entries = ffstream(s->streams[0])->nb_index_entries; + AVIndexEntry *index_entries = ffstream(s->streams[0])->index_entries; if (ts >= matroska->duration * matroska->time_scale) return (CueDesc) {-1, -1, -1, -1}; for (i = 1; i < nb_index_entries; i++) { if (index_entries[i - 1].timestamp * matroska->time_scale <= ts && @@ -3934,11 +3935,11 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s) uint32_t id = matroska->current_id; int64_t cluster_pos, before_pos; int index, rv = 1; - if (s->streams[0]->internal->nb_index_entries <= 0) return 0; + if (ffstream(s->streams[0])->nb_index_entries <= 0) return 0; // seek to the first cluster using cues. index = av_index_search_timestamp(s->streams[0], 0, 0); if (index < 0) return 0; - cluster_pos = s->streams[0]->internal->index_entries[index].pos; + cluster_pos = ffstream(s->streams[0])->index_entries[index].pos; before_pos = avio_tell(s->pb); while (1) { uint64_t cluster_id, cluster_length; @@ -4060,11 +4061,10 @@ static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t MatroskaDemuxContext *matroska = s->priv_data; AVStream *st = s->streams[0]; double bandwidth = 0.0; - int i; - for (i = 0; i < st->internal->nb_index_entries; i++) { + for (int i = 0; i < ffstream(st)->nb_index_entries; i++) { int64_t prebuffer_ns = 1000000000; - int64_t time_ns = st->internal->index_entries[i].timestamp * matroska->time_scale; + int64_t time_ns = ffstream(st)->index_entries[i].timestamp * matroska->time_scale; double nano_seconds_per_second = 1000000000.0; int64_t prebuffered_ns = time_ns + prebuffer_ns; double prebuffer_bytes = 0.0; @@ -4148,6 +4148,7 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range) EbmlList *seekhead_list = &matroska->seekhead; MatroskaSeekhead *seekhead = seekhead_list->elem; AVStream *const st = s->streams[0]; + FFStream *const sti = ffstream(st); AVBPrint bprint; char *buf; int64_t cues_start = -1, cues_end = -1, before_pos, bandwidth; @@ -4183,7 +4184,7 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range) // parse the cues matroska_parse_cues(matroska); - if (!st->internal->nb_index_entries) + if (!sti->nb_index_entries) return AVERROR_INVALIDDATA; // cues start @@ -4208,8 +4209,8 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range) // Store cue point timestamps as a comma separated list // for checking subsegment alignment in the muxer. av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED); - for (int i = 0; i < st->internal->nb_index_entries; i++) - av_bprintf(&bprint, "%" PRId64",", st->internal->index_entries[i].timestamp); + for (int i = 0; i < sti->nb_index_entries; i++) + av_bprintf(&bprint, "%" PRId64",", sti->index_entries[i].timestamp); if (!av_bprint_is_complete(&bprint)) { av_bprint_finalize(&bprint, NULL); return AVERROR(ENOMEM); diff --git a/libavformat/mgsts.c b/libavformat/mgsts.c index 5886d2475a..b5c704829d 100644 --- a/libavformat/mgsts.c +++ b/libavformat/mgsts.c @@ -50,7 +50,7 @@ static int read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; st->start_time = 0; st->nb_frames = st->duration = avio_rb32(pb); diff --git a/libavformat/mlvdec.c b/libavformat/mlvdec.c index 6a3aa15a4e..19105cfc23 100644 --- a/libavformat/mlvdec.c +++ b/libavformat/mlvdec.c @@ -189,12 +189,12 @@ static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int f } } else if (vst && type == MKTAG('V', 'I', 'D', 'F') && size >= 4) { uint64_t pts = avio_rl32(pb); - ff_add_index_entry(&vst->internal->index_entries, &vst->internal->nb_index_entries, &vst->internal->index_entries_allocated_size, + ff_add_index_entry(&ffstream(vst)->index_entries, &ffstream(vst)->nb_index_entries, &ffstream(vst)->index_entries_allocated_size, avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME); size -= 4; } else if (ast && type == MKTAG('A', 'U', 'D', 'F') && size >= 4) { uint64_t pts = avio_rl32(pb); - ff_add_index_entry(&ast->internal->index_entries, &ast->internal->nb_index_entries, &ast->internal->index_entries_allocated_size, + ff_add_index_entry(&ffstream(ast)->index_entries, &ffstream(ast)->nb_index_entries, &ffstream(ast)->index_entries_allocated_size, avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME); size -= 4; } else if (vst && type == MKTAG('W','B','A','L') && size >= 28) { @@ -372,21 +372,21 @@ static int read_header(AVFormatContext *avctx) } if (vst) - vst->duration = vst->internal->nb_index_entries; + vst->duration = ffstream(vst)->nb_index_entries; if (ast) - ast->duration = ast->internal->nb_index_entries; + ast->duration = ffstream(ast)->nb_index_entries; - if ((vst && !vst->internal->nb_index_entries) || (ast && !ast->internal->nb_index_entries)) { + if ((vst && !ffstream(vst)->nb_index_entries) || (ast && !ffstream(ast)->nb_index_entries)) { av_log(avctx, AV_LOG_ERROR, "no index entries found\n"); return AVERROR_INVALIDDATA; } if (vst && ast) - avio_seek(pb, FFMIN(vst->internal->index_entries[0].pos, ast->internal->index_entries[0].pos), SEEK_SET); + avio_seek(pb, FFMIN(ffstream(vst)->index_entries[0].pos, ffstream(ast)->index_entries[0].pos), SEEK_SET); else if (vst) - avio_seek(pb, vst->internal->index_entries[0].pos, SEEK_SET); + avio_seek(pb, ffstream(vst)->index_entries[0].pos, SEEK_SET); else if (ast) - avio_seek(pb, ast->internal->index_entries[0].pos, SEEK_SET); + avio_seek(pb, ffstream(ast)->index_entries[0].pos, SEEK_SET); return 0; } @@ -412,12 +412,12 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) return AVERROR(EIO); } - pb = mlv->pb[st->internal->index_entries[index].size]; + pb = mlv->pb[ffstream(st)->index_entries[index].size]; if (!pb) { ret = FFERROR_REDO; goto next_packet; } - avio_seek(pb, st->internal->index_entries[index].pos, SEEK_SET); + avio_seek(pb, ffstream(st)->index_entries[index].pos, SEEK_SET); avio_skip(pb, 4); // blockType size = avio_rl32(pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index da4c5d60f8..367c0a1990 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1794,8 +1794,8 @@ static int mov_read_ares(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; den *= 2; case 1: - c->fc->streams[c->fc->nb_streams-1]->internal->display_aspect_ratio.num = num; - c->fc->streams[c->fc->nb_streams-1]->internal->display_aspect_ratio.den = den; + ffstream(c->fc->streams[c->fc->nb_streams-1])->display_aspect_ratio.num = num; + ffstream(c->fc->streams[c->fc->nb_streams-1])->display_aspect_ratio.den = den; default: return 0; } @@ -2198,7 +2198,7 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, switch (st->codecpar->codec_id) { case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; break; } } @@ -2436,10 +2436,10 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, case AV_CODEC_ID_VC1: case AV_CODEC_ID_VP8: case AV_CODEC_ID_VP9: - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; break; case AV_CODEC_ID_AV1: - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; break; default: break; @@ -2785,8 +2785,8 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!entries) { sc->keyframe_absent = 1; - if (!st->internal->need_parsing && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + if (!ffstream(st)->need_parsing && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; return 0; } if (sc->keyframes) @@ -3191,8 +3191,8 @@ static int find_prev_closest_index(AVStream *st, int64_t* ctts_sample) { MOVStreamContext *msc = st->priv_data; - AVIndexEntry *e_keep = st->internal->index_entries; - int nb_keep = st->internal->nb_index_entries; + AVIndexEntry *e_keep = ffstream(st)->index_entries; + int nb_keep = ffstream(st)->nb_index_entries; int64_t i = 0; int64_t index_ctts_count; @@ -3205,8 +3205,8 @@ static int find_prev_closest_index(AVStream *st, timestamp_pts -= msc->dts_shift; } - st->internal->index_entries = e_old; - st->internal->nb_index_entries = nb_old; + ffstream(st)->index_entries = e_old; + ffstream(st)->nb_index_entries = nb_old; *index = av_index_search_timestamp(st, timestamp_pts, flag | AVSEEK_FLAG_BACKWARD); // Keep going backwards in the index entries until the timestamp is the same. @@ -3259,14 +3259,14 @@ static int find_prev_closest_index(AVStream *st, } /* restore AVStream state*/ - st->internal->index_entries = e_keep; - st->internal->nb_index_entries = nb_keep; + ffstream(st)->index_entries = e_keep; + ffstream(st)->nb_index_entries = nb_keep; return *index >= 0 ? 0 : -1; } /** - * Add index entry with the given values, to the end of st->internal->index_entries. - * Returns the new size st->internal->index_entries if successful, else returns -1. + * Add index entry with the given values, to the end of ffstream(st)->index_entries. + * Returns the new size ffstream(st)->index_entries if successful, else returns -1. * * This function is similar to ff_add_index_entry in libavformat/utils.c * except that here we are always unconditionally adding an index entry to @@ -3280,27 +3280,27 @@ static int64_t add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, { AVIndexEntry *entries, *ie; int64_t index = -1; - const size_t min_size_needed = (st->internal->nb_index_entries + 1) * sizeof(AVIndexEntry); + const size_t min_size_needed = (ffstream(st)->nb_index_entries + 1) * sizeof(AVIndexEntry); // Double the allocation each time, to lower memory fragmentation. // Another difference from ff_add_index_entry function. const size_t requested_size = - min_size_needed > st->internal->index_entries_allocated_size ? - FFMAX(min_size_needed, 2 * st->internal->index_entries_allocated_size) : + min_size_needed > ffstream(st)->index_entries_allocated_size ? + FFMAX(min_size_needed, 2 * ffstream(st)->index_entries_allocated_size) : min_size_needed; - if (st->internal->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry)) + if (ffstream(st)->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry)) return -1; - entries = av_fast_realloc(st->internal->index_entries, - &st->internal->index_entries_allocated_size, + entries = av_fast_realloc(ffstream(st)->index_entries, + &ffstream(st)->index_entries_allocated_size, requested_size); if (!entries) return -1; - st->internal->index_entries= entries; + ffstream(st)->index_entries= entries; - index= st->internal->nb_index_entries++; + index= ffstream(st)->nb_index_entries++; ie= &entries[index]; ie->pos = pos; @@ -3319,10 +3319,10 @@ static void fix_index_entry_timestamps(AVStream* st, int end_index, int64_t end_ int64_t* frame_duration_buffer, int frame_duration_buffer_size) { int i = 0; - av_assert0(end_index >= 0 && end_index <= st->internal->nb_index_entries); + av_assert0(end_index >= 0 && end_index <= ffstream(st)->nb_index_entries); for (i = 0; i < frame_duration_buffer_size; i++) { end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 - i]; - st->internal->index_entries[end_index - 1 - i].timestamp = end_ts; + ffstream(st)->index_entries[end_index - 1 - i].timestamp = end_ts; } } @@ -3374,14 +3374,14 @@ static void mov_estimate_video_delay(MOVContext *c, AVStream* st) if (st->codecpar->video_delay <= 0 && msc->ctts_data && st->codecpar->codec_id == AV_CODEC_ID_H264) { st->codecpar->video_delay = 0; - for (ind = 0; ind < st->internal->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) { + for (ind = 0; ind < ffstream(st)->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) { // Point j to the last elem of the buffer and insert the current pts there. j = buf_start; buf_start = (buf_start + 1); if (buf_start == MAX_REORDER_DELAY + 1) buf_start = 0; - pts_buf[j] = st->internal->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration; + pts_buf[j] = ffstream(st)->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration; // The timestamps that are already in the sorted buffer, and are greater than the // current pts, are exactly the timestamps that need to be buffered to output PTS @@ -3461,7 +3461,7 @@ static void mov_current_sample_set(MOVStreamContext *sc, int current_sample) } /** - * Fix st->internal->index_entries, so that it contains only the entries (and the entries + * Fix ffstream(st)->index_entries, so that it contains only the entries (and the entries * which are needed to decode them) that fall in the edit list time ranges. * Also fixes the timestamps of the index entries to match the timeline * specified the edit lists. @@ -3469,8 +3469,8 @@ static void mov_current_sample_set(MOVStreamContext *sc, int current_sample) static void mov_fix_index(MOVContext *mov, AVStream *st) { MOVStreamContext *msc = st->priv_data; - AVIndexEntry *e_old = st->internal->index_entries; - int nb_old = st->internal->nb_index_entries; + AVIndexEntry *e_old = ffstream(st)->index_entries; + int nb_old = ffstream(st)->nb_index_entries; const AVIndexEntry *e_old_end = e_old + nb_old; const AVIndexEntry *current = NULL; MOVStts *ctts_data_old = msc->ctts_data; @@ -3515,9 +3515,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) current_index_range = msc->index_ranges - 1; // Clean AVStream from traces of old index - st->internal->index_entries = NULL; - st->internal->index_entries_allocated_size = 0; - st->internal->nb_index_entries = 0; + ffstream(st)->index_entries = NULL; + ffstream(st)->index_entries_allocated_size = 0; + ffstream(st)->nb_index_entries = 0; // Clean ctts fields of MOVStreamContext msc->ctts_data = NULL; @@ -3562,7 +3562,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) } if (first_non_zero_audio_edit > 0) - st->internal->skip_samples = msc->start_pad = 0; + ffstream(st)->skip_samples = msc->start_pad = 0; } // While reordering frame index according to edit list we must handle properly @@ -3637,7 +3637,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time && first_non_zero_audio_edit > 0) { packet_skip_samples = edit_list_media_time - curr_cts; - st->internal->skip_samples += packet_skip_samples; + ffstream(st)->skip_samples += packet_skip_samples; // Shift the index entry timestamp by packet_skip_samples to be correct. edit_list_dts_counter -= packet_skip_samples; @@ -3646,7 +3646,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Make timestamps strictly monotonically increasing for audio, by rewriting timestamps for // discarded packets. if (frame_duration_buffer) { - fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter, + fix_index_entry_timestamps(st, ffstream(st)->nb_index_entries, edit_list_dts_counter, frame_duration_buffer, num_discarded_begin); av_freep(&frame_duration_buffer); } @@ -3670,7 +3670,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Increment skip_samples for the first non-zero audio edit list if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && first_non_zero_audio_edit > 0 && st->codecpar->codec_id != AV_CODEC_ID_VORBIS) { - st->internal->skip_samples += frame_duration; + ffstream(st)->skip_samples += frame_duration; } } } @@ -3685,7 +3685,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Make timestamps strictly monotonically increasing by rewriting timestamps for // discarded packets. if (frame_duration_buffer) { - fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter, + fix_index_entry_timestamps(st, ffstream(st)->nb_index_entries, edit_list_dts_counter, frame_duration_buffer, num_discarded_begin); av_freep(&frame_duration_buffer); } @@ -3746,8 +3746,8 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (msc->min_corrected_pts > 0) { av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts); - for (i = 0; i < st->internal->nb_index_entries; ++i) { - st->internal->index_entries[i].timestamp -= msc->min_corrected_pts; + for (i = 0; i < ffstream(st)->nb_index_entries; ++i) { + ffstream(st)->index_entries[i].timestamp -= msc->min_corrected_pts; } } } @@ -3756,7 +3756,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Update av stream length, if it ends up shorter than the track's media duration st->duration = FFMIN(st->duration, edit_list_dts_entry_end - start_dts); - msc->start_pad = st->internal->skip_samples; + msc->start_pad = ffstream(st)->skip_samples; // Free the old index and the old CTTS structures av_free(e_old); @@ -3773,6 +3773,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) static void mov_build_index(MOVContext *mov, AVStream *st) { MOVStreamContext *sc = st->priv_data; + FFStream *const sti = ffstream(st); int64_t current_offset; int64_t current_dts = 0; unsigned int stts_index = 0; @@ -3844,17 +3845,17 @@ static void mov_build_index(MOVContext *mov, AVStream *st) current_dts -= sc->dts_shift; last_dts = current_dts; - if (!sc->sample_count || st->internal->nb_index_entries) + if (!sc->sample_count || sti->nb_index_entries) return; - if (sc->sample_count >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries) + if (sc->sample_count >= UINT_MAX / sizeof(*sti->index_entries) - sti->nb_index_entries) return; - if (av_reallocp_array(&st->internal->index_entries, - st->internal->nb_index_entries + sc->sample_count, - sizeof(*st->internal->index_entries)) < 0) { - st->internal->nb_index_entries = 0; + if (av_reallocp_array(&sti->index_entries, + sti->nb_index_entries + sc->sample_count, + sizeof(*sti->index_entries)) < 0) { + sti->nb_index_entries = 0; return; } - st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + sc->sample_count) * sizeof(*st->internal->index_entries); + sti->index_entries_allocated_size = (sti->nb_index_entries + sc->sample_count) * sizeof(*sti->index_entries); if (ctts_data_old) { // Expand ctts entries such that we have a 1-1 mapping with samples @@ -3937,7 +3938,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", sample_size); return; } - e = &st->internal->index_entries[st->internal->nb_index_entries++]; + e = &sti->index_entries[sti->nb_index_entries++]; e->pos = current_offset; e->timestamp = current_dts; e->size = sample_size; @@ -3946,7 +3947,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %u, offset %"PRIx64", dts %"PRId64", " "size %u, distance %u, keyframe %d\n", st->index, current_sample, current_offset, current_dts, sample_size, distance, keyframe); - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries < 100) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->nb_index_entries < 100) ff_rfps_add_frame(mov->fc, st, current_dts); } @@ -4018,15 +4019,15 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } av_log(mov->fc, AV_LOG_TRACE, "chunk count %u\n", total); - if (total >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries) + if (total >= UINT_MAX / sizeof(*sti->index_entries) - sti->nb_index_entries) return; - if (av_reallocp_array(&st->internal->index_entries, - st->internal->nb_index_entries + total, - sizeof(*st->internal->index_entries)) < 0) { - st->internal->nb_index_entries = 0; + if (av_reallocp_array(&sti->index_entries, + sti->nb_index_entries + total, + sizeof(*sti->index_entries)) < 0) { + sti->nb_index_entries = 0; return; } - st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + total) * sizeof(*st->internal->index_entries); + sti->index_entries_allocated_size = (sti->nb_index_entries + total) * sizeof(*sti->index_entries); // populate index for (i = 0; i < sc->chunk_count; i++) { @@ -4061,7 +4062,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } - if (st->internal->nb_index_entries >= total) { + if (sti->nb_index_entries >= total) { av_log(mov->fc, AV_LOG_ERROR, "wrong chunk count %u\n", total); return; } @@ -4069,7 +4070,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", size); return; } - e = &st->internal->index_entries[st->internal->nb_index_entries++]; + e = &sti->index_entries[sti->nb_index_entries++]; e->pos = current_offset; e->timestamp = current_dts; e->size = size; @@ -4092,8 +4093,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } // Update start time of the stream. - if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries > 0) { - st->start_time = st->internal->index_entries[0].timestamp + sc->dts_shift; + if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ffstream(st)->nb_index_entries > 0) { + st->start_time = ffstream(st)->index_entries[0].timestamp + sc->dts_shift; if (sc->ctts_data) { st->start_time += sc->ctts_data[0].duration; } @@ -4328,7 +4329,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) && sc->stts_count > 3 && sc->stts_count*10 > st->nb_frames && sc->time_scale == st->codecpar->sample_rate) { - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; } /* Do not need those anymore. */ av_freep(&sc->chunk_offsets); @@ -4740,6 +4741,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) { MOVFragment *frag = &c->fragment; AVStream *st = NULL; + FFStream *sti; MOVStreamContext *sc; MOVStts *ctts_data; uint64_t offset; @@ -4762,6 +4764,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) for (i = 0; i < c->fc->nb_streams; i++) { if (c->fc->streams[i]->id == frag->track_id) { st = c->fc->streams[i]; + sti = ffstream(st); break; } } @@ -4779,7 +4782,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) // A valid index_entry means the trun for the fragment was read // and it's samples are in index_entries at the given position. // New index entries will be inserted before the index_entry found. - index_entry_pos = st->internal->nb_index_entries; + index_entry_pos = sti->nb_index_entries; for (i = c->frag_index.current + 1; i < c->frag_index.nb_items; i++) { frag_stream_info = get_frag_stream_info(&c->frag_index, i, frag->track_id); if (frag_stream_info && frag_stream_info->index_entry >= 0) { @@ -4788,7 +4791,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) break; } } - av_assert0(index_entry_pos <= st->internal->nb_index_entries); + av_assert0(index_entry_pos <= sti->nb_index_entries); avio_r8(pb); /* version */ flags = avio_rb24(pb); @@ -4839,22 +4842,22 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "first sample flags 0x%x\n", first_sample_flags); // realloc space for new index entries - if((uint64_t)st->internal->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) { - entries = UINT_MAX / sizeof(AVIndexEntry) - st->internal->nb_index_entries; + if ((uint64_t)sti->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) { + entries = UINT_MAX / sizeof(AVIndexEntry) - sti->nb_index_entries; av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n"); } if (entries == 0) return 0; - requested_size = (st->internal->nb_index_entries + entries) * sizeof(AVIndexEntry); - new_entries = av_fast_realloc(st->internal->index_entries, - &st->internal->index_entries_allocated_size, + requested_size = (sti->nb_index_entries + entries) * sizeof(AVIndexEntry); + new_entries = av_fast_realloc(sti->index_entries, + &sti->index_entries_allocated_size, requested_size); if (!new_entries) return AVERROR(ENOMEM); - st->internal->index_entries= new_entries; + sti->index_entries= new_entries; - requested_size = (st->internal->nb_index_entries + entries) * sizeof(*sc->ctts_data); + requested_size = (sti->nb_index_entries + entries) * sizeof(*sc->ctts_data); old_ctts_allocated_size = sc->ctts_allocated_size; ctts_data = av_fast_realloc(sc->ctts_data, &sc->ctts_allocated_size, requested_size); @@ -4868,12 +4871,12 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) memset((uint8_t*)(sc->ctts_data) + old_ctts_allocated_size, 0, sc->ctts_allocated_size - old_ctts_allocated_size); - if (index_entry_pos < st->internal->nb_index_entries) { + if (index_entry_pos < sti->nb_index_entries) { // Make hole in index_entries and ctts_data for new samples - memmove(st->internal->index_entries + index_entry_pos + entries, - st->internal->index_entries + index_entry_pos, - sizeof(*st->internal->index_entries) * - (st->internal->nb_index_entries - index_entry_pos)); + memmove(sti->index_entries + index_entry_pos + entries, + sti->index_entries + index_entry_pos, + sizeof(*sti->index_entries) * + (sti->nb_index_entries - index_entry_pos)); memmove(sc->ctts_data + index_entry_pos + entries, sc->ctts_data + index_entry_pos, sizeof(*sc->ctts_data) * (sc->ctts_count - index_entry_pos)); @@ -4882,15 +4885,15 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) } } - st->internal->nb_index_entries += entries; - sc->ctts_count = st->internal->nb_index_entries; + sti->nb_index_entries += entries; + sc->ctts_count = sti->nb_index_entries; // Record the index_entry position in frag_index of this fragment if (frag_stream_info) frag_stream_info->index_entry = index_entry_pos; if (index_entry_pos > 0) - prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp; + prev_dts = sti->index_entries[index_entry_pos-1].timestamp; for (i = 0; i < entries && !pb->eof_reached; i++) { unsigned sample_size = frag->size; @@ -4939,11 +4942,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (prev_dts >= dts) index_entry_flags |= AVINDEX_DISCARD_FRAME; - st->internal->index_entries[index_entry_pos].pos = offset; - st->internal->index_entries[index_entry_pos].timestamp = dts; - st->internal->index_entries[index_entry_pos].size= sample_size; - st->internal->index_entries[index_entry_pos].min_distance= distance; - st->internal->index_entries[index_entry_pos].flags = index_entry_flags; + sti->index_entries[index_entry_pos].pos = offset; + sti->index_entries[index_entry_pos].timestamp = dts; + sti->index_entries[index_entry_pos].size = sample_size; + sti->index_entries[index_entry_pos].min_distance = distance; + sti->index_entries[index_entry_pos].flags = index_entry_flags; sc->ctts_data[index_entry_pos].count = 1; sc->ctts_data[index_entry_pos].duration = ctts_duration; @@ -4970,16 +4973,16 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) // EOF found before reading all entries. Fix the hole this would // leave in index_entries and ctts_data int gap = entries - i; - memmove(st->internal->index_entries + index_entry_pos, - st->internal->index_entries + index_entry_pos + gap, - sizeof(*st->internal->index_entries) * - (st->internal->nb_index_entries - (index_entry_pos + gap))); + memmove(sti->index_entries + index_entry_pos, + sti->index_entries + index_entry_pos + gap, + sizeof(*sti->index_entries) * + (sti->nb_index_entries - (index_entry_pos + gap))); memmove(sc->ctts_data + index_entry_pos, sc->ctts_data + index_entry_pos + gap, sizeof(*sc->ctts_data) * (sc->ctts_count - (index_entry_pos + gap))); - st->internal->nb_index_entries -= gap; + sti->nb_index_entries -= gap; sc->ctts_count -= gap; if (index_entry_pos < sc->current_sample) { sc->current_sample -= gap; @@ -4992,11 +4995,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) // fragment that overlap with AVINDEX_DISCARD_FRAME prev_dts = AV_NOPTS_VALUE; if (index_entry_pos > 0) - prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp; - for (i = index_entry_pos; i < st->internal->nb_index_entries; i++) { - if (prev_dts < st->internal->index_entries[i].timestamp) + prev_dts = sti->index_entries[index_entry_pos-1].timestamp; + for (int i = index_entry_pos; i < sti->nb_index_entries; i++) { + if (prev_dts < sti->index_entries[i].timestamp) break; - st->internal->index_entries[i].flags |= AVINDEX_DISCARD_FRAME; + sti->index_entries[i].flags |= AVINDEX_DISCARD_FRAME; } // If a hole was created to insert the new index_entries into, @@ -7149,15 +7152,15 @@ static int mov_probe(const AVProbeData *p) static void mov_read_chapters(AVFormatContext *s) { MOVContext *mov = s->priv_data; - AVStream *st; MOVStreamContext *sc; int64_t cur_pos; int i, j; int chapter_track; for (j = 0; j < mov->nb_chapter_tracks; j++) { + AVStream *st = NULL; + FFStream *sti; chapter_track = mov->chapter_tracks[j]; - st = NULL; for (i = 0; i < s->nb_streams; i++) if (s->streams[i]->id == chapter_track) { st = s->streams[i]; @@ -7167,15 +7170,16 @@ static void mov_read_chapters(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "Referenced QT chapter track not found\n"); continue; } + sti = ffstream(st); sc = st->priv_data; cur_pos = avio_tell(sc->pb); if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { st->disposition |= AV_DISPOSITION_ATTACHED_PIC | AV_DISPOSITION_TIMED_THUMBNAILS; - if (st->internal->nb_index_entries) { + if (sti->nb_index_entries) { // Retrieve the first frame, if possible - AVIndexEntry *sample = &st->internal->index_entries[0]; + AVIndexEntry *sample = &sti->index_entries[0]; if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { av_log(s, AV_LOG_ERROR, "Failed to retrieve first frame\n"); goto finish; @@ -7188,9 +7192,9 @@ static void mov_read_chapters(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA; st->discard = AVDISCARD_ALL; - for (i = 0; i < st->internal->nb_index_entries; i++) { - AVIndexEntry *sample = &st->internal->index_entries[i]; - int64_t end = i+1 < st->internal->nb_index_entries ? st->internal->index_entries[i+1].timestamp : st->duration; + for (int i = 0; i < sti->nb_index_entries; i++) { + AVIndexEntry *sample = &sti->index_entries[i]; + int64_t end = i+1 < sti->nb_index_entries ? sti->index_entries[i+1].timestamp : st->duration; uint8_t *title; uint16_t ch; int len, title_len; @@ -7263,10 +7267,10 @@ static int mov_read_rtmd_track(AVFormatContext *s, AVStream *st) int64_t cur_pos = avio_tell(sc->pb); int hh, mm, ss, ff, drop; - if (!st->internal->nb_index_entries) + if (!ffstream(st)->nb_index_entries) return -1; - avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET); + avio_seek(sc->pb, ffstream(st)->index_entries->pos, SEEK_SET); avio_skip(s->pb, 13); hh = avio_r8(s->pb); mm = avio_r8(s->pb); @@ -7288,10 +7292,10 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) int64_t cur_pos = avio_tell(sc->pb); uint32_t value; - if (!st->internal->nb_index_entries) + if (!ffstream(st)->nb_index_entries) return -1; - avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET); + avio_seek(sc->pb, ffstream(st)->index_entries->pos, SEEK_SET); value = avio_rb32(s->pb); if (sc->tmcd_flags & 0x0001) flags |= AV_TIMECODE_FLAG_DROPFRAME; @@ -7613,7 +7617,7 @@ static int mov_read_header(AVFormatContext *s) fix_timescale(mov, sc); if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->codec_id == AV_CODEC_ID_AAC) { - st->internal->skip_samples = sc->start_pad; + ffstream(st)->skip_samples = sc->start_pad; } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sc->nb_frames_for_fps > 0 && sc->duration_for_fps > 0) av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, @@ -7632,7 +7636,7 @@ static int mov_read_header(AVFormatContext *s) mov->handbrake_version <= 1000000*0 + 1000*10 + 2 && // 0.10.2 st->codecpar->codec_id == AV_CODEC_ID_MP3) { av_log(s, AV_LOG_VERBOSE, "Forcing full parsing for mp3 stream\n"); - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; } } @@ -7750,8 +7754,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) for (i = 0; i < s->nb_streams; i++) { AVStream *avst = s->streams[i]; MOVStreamContext *msc = avst->priv_data; - if (msc->pb && msc->current_sample < avst->internal->nb_index_entries) { - AVIndexEntry *current_sample = &avst->internal->index_entries[msc->current_sample]; + if (msc->pb && msc->current_sample < ffstream(avst)->nb_index_entries) { + AVIndexEntry *current_sample = &ffstream(avst)->index_entries[msc->current_sample]; int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale); av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); if (!sample || (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && current_sample->pos < sample->pos) || @@ -7933,9 +7937,9 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) sc->has_palette = 0; } } - if (st->codecpar->codec_id == AV_CODEC_ID_MP3 && !st->internal->need_parsing && pkt->size > 4) { + if (st->codecpar->codec_id == AV_CODEC_ID_MP3 && !ffstream(st)->need_parsing && pkt->size > 4) { if (ff_mpa_check_header(AV_RB32(pkt->data)) < 0) - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; } } @@ -7954,8 +7958,8 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) sc->ctts_sample = 0; } } else { - int64_t next_dts = (sc->current_sample < st->internal->nb_index_entries) ? - st->internal->index_entries[sc->current_sample].timestamp : st->duration; + int64_t next_dts = (sc->current_sample < ffstream(st)->nb_index_entries) ? + ffstream(st)->index_entries[sc->current_sample].timestamp : st->duration; if (next_dts >= pkt->dts) pkt->duration = next_dts - pkt->dts; @@ -8036,7 +8040,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, sample = av_index_search_timestamp(st, timestamp, flags); av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); - if (sample < 0 && st->internal->nb_index_entries && timestamp < st->internal->index_entries[0].timestamp) + if (sample < 0 && ffstream(st)->nb_index_entries && timestamp < ffstream(st)->index_entries[0].timestamp) sample = 0; if (sample < 0) /* not sure what to do */ return AVERROR_INVALIDDATA; @@ -8077,8 +8081,8 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, static int64_t mov_get_skip_samples(AVStream *st, int sample) { MOVStreamContext *sc = st->priv_data; - int64_t first_ts = st->internal->index_entries[0].timestamp; - int64_t ts = st->internal->index_entries[sample].timestamp; + int64_t first_ts = ffstream(st)->index_entries[0].timestamp; + int64_t ts = ffstream(st)->index_entries[sample].timestamp; int64_t off; if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) @@ -8107,8 +8111,8 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti if (mc->seek_individually) { /* adjust seek timestamp to found sample timestamp */ - int64_t seek_timestamp = st->internal->index_entries[sample].timestamp; - st->internal->skip_samples = mov_get_skip_samples(st, sample); + int64_t seek_timestamp = ffstream(st)->index_entries[sample].timestamp; + ffstream(st)->skip_samples = mov_get_skip_samples(st, sample); for (i = 0; i < s->nb_streams; i++) { int64_t timestamp; @@ -8120,7 +8124,7 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti timestamp = av_rescale_q(seek_timestamp, s->streams[stream_index]->time_base, st->time_base); sample = mov_seek_stream(s, st, timestamp, flags); if (sample >= 0) - st->internal->skip_samples = mov_get_skip_samples(st, sample); + ffstream(st)->skip_samples = mov_get_skip_samples(st, sample); } } else { for (i = 0; i < s->nb_streams; i++) { diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 622b94e8ff..d3c6a3bde8 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -255,13 +255,13 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, mp3->start_pad = v>>12; mp3-> end_pad = v&4095; - st->internal->start_skip_samples = mp3->start_pad + 528 + 1; + ffstream(st)->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { - st->internal->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; - st->internal->last_discard_sample = mp3->frames * (int64_t)spf; + ffstream(st)->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; + ffstream(st)->last_discard_sample = mp3->frames * (int64_t)spf; } if (!st->start_time) - st->start_time = av_rescale_q(st->internal->start_skip_samples, + st->start_time = av_rescale_q(ffstream(st)->start_skip_samples, (AVRational){1, c->sample_rate}, st->time_base); av_log(s, AV_LOG_DEBUG, "pad %d %d\n", mp3->start_pad, mp3-> end_pad); @@ -374,7 +374,7 @@ static int mp3_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_MP3; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->start_time = 0; // lcm of all mp3 sample rates @@ -431,8 +431,8 @@ static int mp3_read_header(AVFormatContext *s) } // the seek index is relative to the end of the xing vbr headers - for (i = 0; i < st->internal->nb_index_entries; i++) - st->internal->index_entries[i].pos += avio_tell(s->pb); + for (i = 0; i < ffstream(st)->nb_index_entries; i++) + ffstream(st)->index_entries[i].pos += avio_tell(s->pb); /* the parameters will be extracted from the compressed bitstream */ return 0; @@ -567,7 +567,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, if (ret < 0) return ret; - ie = &st->internal->index_entries[ret]; + ie = &ffstream(st)->index_entries[ret]; } else if (fast_seek && st->duration > 0 && filesize > 0) { if (!mp3->is_cbr) av_log(s, AV_LOG_WARNING, "Using scaling to seek VBR MP3; may be imprecise.\n"); diff --git a/libavformat/mpc.c b/libavformat/mpc.c index 9eaf7de0bc..b5b2bab33c 100644 --- a/libavformat/mpc.c +++ b/libavformat/mpc.c @@ -187,6 +187,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt) static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { AVStream *st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); MPCContext *c = s->priv_data; AVPacket pkt1, *pkt = &pkt1; int ret; @@ -194,8 +195,8 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp uint32_t lastframe; /* if found, seek there */ - if (index >= 0 && st->internal->index_entries[st->internal->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){ - c->curframe = st->internal->index_entries[index].pos; + if (index >= 0 && sti->index_entries[sti->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES) { + c->curframe = sti->index_entries[index].pos; return 0; } /* if timestamp is out of bounds, return error */ diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c index a0e661c2ab..cd0759cbae 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -327,9 +327,9 @@ static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestam int index = av_index_search_timestamp(st, timestamp, flags); if(index < 0) return -1; - if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, ffstream(st)->index_entries[index].pos, SEEK_SET) < 0) return -1; - avpriv_update_cur_dts(s, st, st->internal->index_entries[index].timestamp); + avpriv_update_cur_dts(s, st, ffstream(st)->index_entries[index].timestamp); return 0; } diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index a7874cdae8..2d84fa7de9 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -623,8 +623,8 @@ skip: st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; st->codecpar->sample_rate = 8000; } - st->internal->request_probe = request_probe; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->request_probe = request_probe; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; found: if (st->discard >= AVDISCARD_ALL) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 9662ef1e61..20c8b3d22d 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -881,9 +881,9 @@ static void mpegts_find_stream_type(AVStream *st, st->codecpar->codec_id != types->codec_id) { st->codecpar->codec_type = types->codec_type; st->codecpar->codec_id = types->codec_id; - st->internal->need_context_update = 1; + ffstream(st)->need_context_update = 1; } - st->internal->request_probe = 0; + ffstream(st)->request_probe = 0; return; } } @@ -895,7 +895,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, int old_codec_id = st->codecpar->codec_id; int old_codec_tag = st->codecpar->codec_tag; - if (avcodec_is_open(st->internal->avctx)) { + if (avcodec_is_open(ffstream(st)->avctx)) { av_log(pes->stream, AV_LOG_DEBUG, "cannot set stream info, internal codec is open\n"); return 0; } @@ -904,7 +904,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, st->priv_data = pes; st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_NONE; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; pes->st = st; pes->stream_type = stream_type; @@ -916,7 +916,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, mpegts_find_stream_type(st, pes->stream_type, ISO_types); if (pes->stream_type == 4 || pes->stream_type == 0x0f) - st->internal->request_probe = 50; + ffstream(st)->request_probe = 50; if ((prog_reg_desc == AV_RL32("HDMV") || prog_reg_desc == AV_RL32("HDPR")) && st->codecpar->codec_id == AV_CODEC_ID_NONE) { @@ -942,7 +942,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, sub_st->priv_data = sub_pes; sub_st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; sub_st->codecpar->codec_id = AV_CODEC_ID_AC3; - sub_st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(sub_st)->need_parsing = AVSTREAM_PARSE_FULL; sub_pes->sub_st = pes->sub_st = sub_st; } } @@ -953,19 +953,19 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, st->codecpar->codec_type = old_codec_type; } if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || - (st->internal->request_probe > 0 && st->internal->request_probe < AVPROBE_SCORE_STREAM_RETRY / 5)) && - st->internal->probe_packets > 0 && + (ffstream(st)->request_probe > 0 && ffstream(st)->request_probe < AVPROBE_SCORE_STREAM_RETRY / 5)) && + ffstream(st)->probe_packets > 0 && stream_type == STREAM_TYPE_PRIVATE_DATA) { st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA; - st->internal->request_probe = AVPROBE_SCORE_STREAM_RETRY / 5; + ffstream(st)->request_probe = AVPROBE_SCORE_STREAM_RETRY / 5; } /* queue a context update if properties changed */ if (old_codec_type != st->codecpar->codec_type || old_codec_id != st->codecpar->codec_id || old_codec_tag != st->codecpar->codec_tag) - st->internal->need_context_update = 1; + ffstream(st)->need_context_update = 1; return 0; } @@ -1199,12 +1199,12 @@ static int mpegts_push_data(MpegTSFilter *filter, code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */ code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */ pes->state = MPEGTS_PESHEADER; - if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE && !pes->st->internal->request_probe) { + if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE && !ffstream(pes->st)->request_probe) { av_log(pes->stream, AV_LOG_TRACE, "pid=%x stream_type=%x probing\n", pes->pid, pes->stream_type); - pes->st->internal->request_probe = 1; + ffstream(pes->st)->request_probe = 1; } } else { pes->pes_header_size = 6; @@ -1326,8 +1326,8 @@ skip: int64_t pcr = f->last_pcr / 300; pcr_found = 1; if (st) { - pes->st->internal->pts_wrap_reference = st->internal->pts_wrap_reference; - pes->st->internal->pts_wrap_behavior = st->internal->pts_wrap_behavior; + ffstream(pes->st)->pts_wrap_reference = ffstream(st)->pts_wrap_reference; + ffstream(pes->st)->pts_wrap_behavior = ffstream(st)->pts_wrap_behavior; } if (pes->dts == AV_NOPTS_VALUE || pes->dts < pcr) { pes->pts = pes->dts = pcr; @@ -1719,13 +1719,13 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, ff_mp4_read_dec_config_descr(s, st, &pb.pub); if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) - st->internal->need_parsing = 0; + ffstream(st)->need_parsing = 0; if (st->codecpar->codec_id == AV_CODEC_ID_H264 && st->codecpar->extradata_size > 0) - st->internal->need_parsing = 0; + ffstream(st)->need_parsing = 0; st->codecpar->codec_type = avcodec_get_type(st->codecpar->codec_id); - st->internal->need_context_update = 1; + ffstream(st)->need_context_update = 1; } } for (i = 0; i < mp4_descr_count; i++) @@ -1802,7 +1802,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type av_log(fc, AV_LOG_TRACE, "tag: 0x%02x len=%d\n", desc_tag, desc_len); - if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || st->internal->request_probe > 0) && + if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || ffstream(st)->request_probe > 0) && stream_type == STREAM_TYPE_PRIVATE_DATA) mpegts_find_stream_type(st, desc_tag, DESC_types); @@ -1828,8 +1828,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type ff_mp4_read_dec_config_descr(fc, st, &pb.pub); if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) { - st->internal->need_parsing = 0; - st->internal->need_context_update = 1; + ffstream(st)->need_parsing = 0; + ffstream(st)->need_context_update = 1; } if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4SYSTEMS) mpegts_open_section_filter(ts, pid, m4sl_cb, ts, 1); @@ -1840,8 +1840,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type break; if (mp4_descr_count > 0 && (st->codecpar->codec_id == AV_CODEC_ID_AAC_LATM || - (st->internal->request_probe == 0 && st->codecpar->codec_id == AV_CODEC_ID_NONE) || - st->internal->request_probe > 0) && + (ffstream(st)->request_probe == 0 && st->codecpar->codec_id == AV_CODEC_ID_NONE) || + ffstream(st)->request_probe > 0) && mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) { FFIOContext pb; ffio_init_context(&pb, mp4_descr->dec_config_descr, @@ -1850,9 +1850,9 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type ff_mp4_read_dec_config_descr(fc, st, &pb.pub); if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) { - st->internal->request_probe = st->internal->need_parsing = 0; + ffstream(st)->request_probe = ffstream(st)->need_parsing = 0; st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; - st->internal->need_context_update = 1; + ffstream(st)->need_context_update = 1; } } break; @@ -1893,7 +1893,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type language[i * 4 - 1] = 0; av_dict_set(&st->metadata, "language", language, 0); - st->internal->need_context_update = 1; + ffstream(st)->need_context_update = 1; } } break; @@ -1957,7 +1957,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type language[i * 4 - 1] = 0; av_dict_set(&st->metadata, "language", language, 0); - st->internal->need_context_update = 1; + ffstream(st)->need_context_update = 1; } } break; @@ -1990,14 +1990,14 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type case REGISTRATION_DESCRIPTOR: st->codecpar->codec_tag = bytestream_get_le32(pp); av_log(fc, AV_LOG_TRACE, "reg_desc=%.4s\n", (char *)&st->codecpar->codec_tag); - if (st->codecpar->codec_id == AV_CODEC_ID_NONE || st->internal->request_probe > 0) { + if (st->codecpar->codec_id == AV_CODEC_ID_NONE || ffstream(st)->request_probe > 0) { mpegts_find_stream_type(st, st->codecpar->codec_tag, REGD_types); if (st->codecpar->codec_tag == MKTAG('B', 'S', 'S', 'D')) - st->internal->request_probe = 50; + ffstream(st)->request_probe = 50; } break; case 0x52: /* stream identifier descriptor */ - st->internal->stream_identifier = 1 + get8(pp, desc_end); + ffstream(st)->stream_identifier = 1 + get8(pp, desc_end); break; case METADATA_DESCRIPTOR: if (get16(pp, desc_end) == 0xFFFF) @@ -2037,8 +2037,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type } else { avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code > 0x8"); } - st->internal->need_parsing = AVSTREAM_PARSE_FULL; - st->internal->need_context_update = 1; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_context_update = 1; } } if (ext_desc_tag == 0x06) { /* supplementary audio descriptor */ @@ -2116,7 +2116,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type // Listing of data_component_ids is in STD-B10, part 2, Annex J. // Component tag limits are documented in TR-B14, fascicle 2, // Vol. 3, Section 2, 4.2.8.1 - int actual_component_tag = st->internal->stream_identifier - 1; + int actual_component_tag = ffstream(st)->stream_identifier - 1; int picked_profile = FF_PROFILE_UNKNOWN; int data_component_id = get16(pp, desc_end); if (data_component_id < 0) @@ -2148,7 +2148,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_ARIB_CAPTION; st->codecpar->profile = picked_profile; - st->internal->request_probe = 0; + ffstream(st)->request_probe = 0; } break; case 0xb0: /* DOVI video stream descriptor */ diff --git a/libavformat/msf.c b/libavformat/msf.c index 7d8add387c..98a7ca11c3 100644 --- a/libavformat/msf.c +++ b/libavformat/msf.c @@ -82,7 +82,7 @@ static int msf_read_header(AVFormatContext *s) AV_WL16(st->codecpar->extradata+8, codec == 4 ? 1 : 0); /* joint stereo (repeat?) */ AV_WL16(st->codecpar->extradata+10, 1); st->codecpar->codec_id = AV_CODEC_ID_ATRAC3; break; - case 7: st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + case 7: ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->codecpar->codec_id = AV_CODEC_ID_MP3; break; default: avpriv_request_sample(s, "Codec %d", codec); diff --git a/libavformat/mtv.c b/libavformat/mtv.c index da02965fd8..b6ed43d444 100644 --- a/libavformat/mtv.c +++ b/libavformat/mtv.c @@ -185,7 +185,7 @@ static int mtv_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_MP3; st->codecpar->bit_rate = mtv->audio_br; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; // Jump over header diff --git a/libavformat/mux.c b/libavformat/mux.c index fc3469c287..67c470c5b9 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -302,9 +302,9 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) desc = avcodec_descriptor_get(par->codec_id); if (desc && desc->props & AV_CODEC_PROP_REORDER) - st->internal->reorder = 1; + ffstream(st)->reorder = 1; - st->internal->is_intra_only = ff_is_intra_only(par->codec_id); + ffstream(st)->is_intra_only = ff_is_intra_only(par->codec_id); if (of->codec_tag) { if ( par->codec_tag @@ -384,7 +384,7 @@ static int init_pts(AVFormatContext *s) /* init PTS generation */ for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *const st = s->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int64_t den = AV_NOPTS_VALUE; switch (st->codecpar->codec_type) { @@ -505,7 +505,7 @@ FF_DISABLE_DEPRECATION_WARNINGS //FIXME merge with compute_pkt_fields static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int delay = st->codecpar->video_delay; int frame_size; @@ -656,7 +656,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) if (s->avoid_negative_ts > 0) { FFFormatContext *const si = ffformatcontext(s); AVStream *st = s->streams[pkt->stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int64_t offset = sti->mux_ts_offset; int64_t ts = si->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; @@ -740,7 +740,7 @@ static int check_packet(AVFormatContext *s, AVPacket *pkt) static int prepare_input_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); #if !FF_API_COMPUTE_PKT_FIELDS2 /* sanitize the timestamps */ if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) { @@ -796,7 +796,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, FFFormatContext *const si = ffformatcontext(s); PacketList **next_point, *this_pktl; AVStream *st = s->streams[pkt->stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int chunked = s->max_chunk_size || s->max_chunk_duration; this_pktl = av_malloc(sizeof(PacketList)); @@ -908,11 +908,12 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } for (unsigned i = 0; i < s->nb_streams; i++) { - if (s->streams[i]->internal->last_in_packet_buffer) { + const AVStream *const st = s->streams[i]; + if (cffstream(st)->last_in_packet_buffer) { ++stream_count; - } else if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT && - s->streams[i]->codecpar->codec_id != AV_CODEC_ID_VP8 && - s->streams[i]->codecpar->codec_id != AV_CODEC_ID_VP9) { + } else if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT && + st->codecpar->codec_id != AV_CODEC_ID_VP8 && + st->codecpar->codec_id != AV_CODEC_ID_VP9) { ++noninterleaved_count; } } @@ -933,7 +934,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, for (unsigned i = 0; i < s->nb_streams; i++) { int64_t last_dts; - const PacketList *last = s->streams[i]->internal->last_in_packet_buffer; + const PacketList *last = ffstream(s->streams[i])->last_in_packet_buffer; if (!last) continue; @@ -969,7 +970,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, PacketList *pktl = si->packet_buffer; AVPacket *const top_pkt = &pktl->pkt; AVStream *const st = s->streams[top_pkt->stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int64_t top_dts = av_rescale_q(top_pkt->dts, st->time_base, AV_TIME_BASE_Q); @@ -992,7 +993,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (stream_count && flush) { PacketList *pktl = si->packet_buffer; AVStream *const st = s->streams[pktl->pkt.stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); *out = pktl->pkt; @@ -1018,7 +1019,7 @@ int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset return AVERROR(EINVAL); st = s->streams[stream_index]; - *offset = st->internal->mux_ts_offset; + *offset = ffstream(st)->mux_ts_offset; if (s->output_ts_offset) *offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); @@ -1063,11 +1064,11 @@ static int check_bitstream(AVFormatContext *s, AVStream *st, AVPacket *pkt) return 1; if (s->oformat->check_bitstream) { - if (!st->internal->bitstream_checked) { + if (!ffstream(st)->bitstream_checked) { if ((ret = s->oformat->check_bitstream(s, pkt)) < 0) return ret; else if (ret == 1) - st->internal->bitstream_checked = 1; + ffstream(st)->bitstream_checked = 1; } } @@ -1119,7 +1120,7 @@ static int write_packet_common(AVFormatContext *s, AVStream *st, AVPacket *pkt, static int write_packets_from_bsfs(AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved) { - AVBSFContext *bsfc = st->internal->bsfc; + AVBSFContext *bsfc = ffstream(st)->bsfc; int ret; if ((ret = av_bsf_send_packet(bsfc, pkt)) < 0) { @@ -1165,7 +1166,7 @@ static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleav if (ret < 0) return ret; - if (st->internal->bsfc) { + if (ffstream(st)->bsfc) { return write_packets_from_bsfs(s, st, pkt, interleaved); } else { return write_packet_common(s, st, pkt, interleaved); @@ -1241,7 +1242,7 @@ int av_write_trailer(AVFormatContext *s) av_packet_unref(pkt); for (unsigned i = 0; i < s->nb_streams; i++) { - if (s->streams[i]->internal->bsfc) { + if (ffstream(s->streams[i])->bsfc) { ret1 = write_packets_from_bsfs(s, s->streams[i], pkt, 1/*interleaved*/); if (ret1 < 0) av_packet_unref(pkt); @@ -1271,7 +1272,7 @@ int av_write_trailer(AVFormatContext *s) ret = s->pb ? s->pb->error : 0; for (unsigned i = 0; i < s->nb_streams; i++) { av_freep(&s->streams[i]->priv_data); - av_freep(&s->streams[i]->internal->index_entries); + av_freep(&ffstream(s->streams[i])->index_entries); } if (s->oformat->priv_class) av_opt_free(s->priv_data); diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c index b1450e08da..bec8e7366e 100644 --- a/libavformat/mvdec.c +++ b/libavformat/mvdec.c @@ -440,8 +440,8 @@ static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt) int64_t ret; uint64_t pos; - if (frame < st->internal->nb_index_entries) { - index = &st->internal->index_entries[frame]; + if (frame < ffstream(st)->nb_index_entries) { + index = &ffstream(st)->index_entries[frame]; pos = avio_tell(pb); if (index->pos > pos) avio_skip(pb, index->pos - pos); diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 55f2e5c767..39e9e04094 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1789,7 +1789,7 @@ static int mxf_compute_ptses_fake_index(MXFContext *mxf, MXFIndexTable *index_ta * 6: 5 5 * * We do this by bucket sorting x by x+TemporalOffset[x] into mxf->ptses, - * then settings mxf->internal->first_dts = -max(TemporalOffset[x]). + * then settings ffstream(mxf)->first_dts = -max(TemporalOffset[x]). * The latter makes DTS <= PTS. */ for (i = x = 0; i < index_table->nb_segments; i++) { @@ -2616,7 +2616,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } } } - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; if (material_track->sequence->origin) { av_dict_set_int(&st->metadata, "material_track_origin", material_track->sequence->origin, 0); } @@ -2624,7 +2624,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) av_dict_set_int(&st->metadata, "source_track_origin", source_track->sequence->origin, 0); } if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den) - st->internal->display_aspect_ratio = descriptor->aspect_ratio; + ffstream(st)->display_aspect_ratio = descriptor->aspect_ratio; st->codecpar->color_range = mxf_get_color_range(mxf, descriptor); st->codecpar->color_primaries = mxf_get_codec_ul(ff_mxf_color_primaries_uls, &descriptor->color_primaries_ul)->id; st->codecpar->color_trc = mxf_get_codec_ul(ff_mxf_color_trc_uls, &descriptor->color_trc_ul)->id; @@ -2681,7 +2681,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) else if (descriptor->bits_per_sample == 32) st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE; } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) { - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; } st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id); } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { @@ -2715,7 +2715,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } if (st->codecpar->codec_type != AVMEDIA_TYPE_DATA && source_track->wrapping != FrameWrapped) { /* TODO: decode timestamps */ - st->internal->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; } } @@ -3676,7 +3676,7 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) if (next_ofs <= 0) { // If we have no way to packetize the data, then return it in chunks... if (klv.next_klv - klv.length == pos && max_data_size > MXF_MAX_CHUNK_SIZE) { - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; avpriv_request_sample(s, "Huge KLV without proper index in non-frame wrapped essence"); } size = FFMIN(max_data_size, MXF_MAX_CHUNK_SIZE); diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 8e57e10487..f37606ed89 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3104,7 +3104,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket int i, stream_count = 0; for (i = 0; i < s->nb_streams; i++) - stream_count += !!s->streams[i]->internal->last_in_packet_buffer; + stream_count += !!ffstream(s->streams[i])->last_in_packet_buffer; if (stream_count && (s->nb_streams == stream_count || flush)) { PacketList *pktl = si->packet_buffer; @@ -3115,8 +3115,8 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket if (!stream_count || pktl->pkt.stream_index == 0) break; // update last packet in packet buffer - if (s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer != pktl) - s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer = pktl; + if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer != pktl) + ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer = pktl; last = pktl; pktl = pktl->next; stream_count--; @@ -3141,8 +3141,8 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *out = pktl->pkt; av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts); si->packet_buffer = pktl->next; - if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == pktl) - s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer= NULL; + if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer == pktl) + ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer = NULL; if (!si->packet_buffer) si->packet_buffer_end = NULL; av_freep(&pktl); diff --git a/libavformat/ncdec.c b/libavformat/ncdec.c index 3fe189e729..b2f4dfe282 100644 --- a/libavformat/ncdec.c +++ b/libavformat/ncdec.c @@ -53,7 +53,7 @@ static int nc_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG4; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 100); diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index ec73cb7f48..97c044a5b2 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -461,7 +461,7 @@ static int nsv_parse_NSVs_header(AVFormatContext *s) st->codecpar->codec_tag = atag; st->codecpar->codec_id = ff_codec_get_id(nsv_codec_audio_tags, atag); - st->internal->need_parsing = AVSTREAM_PARSE_FULL; /* for PCM we will read a chunk later and put correct info */ + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; /* for PCM we will read a chunk later and put correct info */ /* set timebase to common denominator of ms and framerate */ avpriv_set_pts_info(st, 64, 1, framerate.num*1000); @@ -609,7 +609,7 @@ null_chunk_retry: asize-=4; av_log(s, AV_LOG_TRACE, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate); if (fill_header) { - st[NSV_ST_AUDIO]->internal->need_parsing = AVSTREAM_PARSE_NONE; /* we know everything */ + ffstream(st[NSV_ST_AUDIO])->need_parsing = AVSTREAM_PARSE_NONE; /* we know everything */ if (bps != 16) { av_log(s, AV_LOG_TRACE, "NSV AUDIO bit/sample != 16 (%d)!!!\n", bps); } @@ -676,10 +676,10 @@ static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp if(index < 0) return -1; - if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, ffstream(st)->index_entries[index].pos, SEEK_SET) < 0) return -1; - nst->frame_offset = st->internal->index_entries[index].timestamp; + nst->frame_offset = ffstream(st)->index_entries[index].timestamp; nsv->state = NSV_UNSYNC; return 0; } diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index 50f8b64d10..1f02d098a1 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -1086,7 +1086,7 @@ static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code) stc->skip_until_key_frame = 0; discard = s->streams[stream_id]->discard; - last_IP_pts = s->streams[stream_id]->internal->last_IP_pts; + last_IP_pts = ffstream(s->streams[stream_id])->last_IP_pts; if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) || (discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts) || @@ -1235,15 +1235,15 @@ static int read_seek(AVFormatContext *s, int stream_index, return AVERROR(ENOSYS); } - if (st->internal->index_entries) { + if (ffstream(st)->index_entries) { int index = av_index_search_timestamp(st, pts, flags); if (index < 0) index = av_index_search_timestamp(st, pts, flags ^ AVSEEK_FLAG_BACKWARD); if (index < 0) return -1; - pos2 = st->internal->index_entries[index].pos; - ts = st->internal->index_entries[index].timestamp; + pos2 = ffstream(st)->index_entries[index].pos; + ts = ffstream(st)->index_entries[index].timestamp; } else { av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp, (void **) next_node); diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 6fb0a810e1..7977980935 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -1006,6 +1006,7 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt) ff_nut_reset_ts(nut, *nus->time_base, pkt->dts); for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; + FFStream *const sti = ffstream(st); int64_t dts_tb = av_rescale_rnd(pkt->dts, nus->time_base->num * (int64_t)nut->stream[i].time_base->den, nus->time_base->den * (int64_t)nut->stream[i].time_base->num, @@ -1013,12 +1014,12 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt) int index = av_index_search_timestamp(st, dts_tb, AVSEEK_FLAG_BACKWARD); if (index >= 0) { - sp_pos = FFMIN(sp_pos, st->internal->index_entries[index].pos); - if (!nut->write_index && 2*index > st->internal->nb_index_entries) { - memmove(st->internal->index_entries, - st->internal->index_entries + index, - sizeof(*st->internal->index_entries) * (st->internal->nb_index_entries - index)); - st->internal->nb_index_entries -= index; + sp_pos = FFMIN(sp_pos, sti->index_entries[index].pos); + if (!nut->write_index && 2*index > sti->nb_index_entries) { + memmove(sti->index_entries, + sti->index_entries + index, + sizeof(*sti->index_entries) * (sti->nb_index_entries - index)); + sti->nb_index_entries -= index; } } } diff --git a/libavformat/nuv.c b/libavformat/nuv.c index 73521ec8e4..5f5cc50302 100644 --- a/libavformat/nuv.c +++ b/libavformat/nuv.c @@ -133,7 +133,7 @@ static int get_codec_data(AVFormatContext *s, AVIOContext *pb, AVStream *vst, } ast->codecpar->codec_id = id; - ast->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(ast)->need_parsing = AVSTREAM_PARSE_FULL; } else avio_skip(pb, 4 * 4); diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c index 15eeca56aa..fa7459c162 100644 --- a/libavformat/oggparseflac.c +++ b/libavformat/oggparseflac.c @@ -59,7 +59,7 @@ flac_header (AVFormatContext * s, int idx) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_FLAC; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; if ((ret = ff_alloc_extradata(st->codecpar, FLAC_STREAMINFO_SIZE)) < 0) return ret; diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c index a8319b9dfa..1cbb6bcddd 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -60,7 +60,7 @@ ogm_header(AVFormatContext *s, int idx) st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); st->codecpar->codec_tag = tag; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; } else if (bytestream2_peek_byte(&p) == 't') { st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_TEXT; @@ -76,7 +76,7 @@ ogm_header(AVFormatContext *s, int idx) st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags, cid); // our parser completely breaks AAC in Ogg if (st->codecpar->codec_id != AV_CODEC_ID_AAC) - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; } size = bytestream2_get_le32(&p); @@ -116,7 +116,7 @@ ogm_header(AVFormatContext *s, int idx) } // Update internal avctx with changes to codecpar above. - st->internal->need_context_update = 1; + ffstream(st)->need_context_update = 1; } else if (bytestream2_peek_byte(&p) == 3) { bytestream2_skip(&p, 7); if (bytestream2_get_bytes_left(&p) > 1) diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c index 28684f6ea9..b9184eff7b 100644 --- a/libavformat/oggparsetheora.c +++ b/libavformat/oggparsetheora.c @@ -112,7 +112,7 @@ static int theora_header(AVFormatContext *s, int idx) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_THEORA; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; } break; case 0x81: diff --git a/libavformat/oggparsevp8.c b/libavformat/oggparsevp8.c index 85b3627c9c..676b3a0f8e 100644 --- a/libavformat/oggparsevp8.c +++ b/libavformat/oggparsevp8.c @@ -61,7 +61,7 @@ static int vp8_header(AVFormatContext *s, int idx) avpriv_set_pts_info(st, 64, framerate.den, framerate.num); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_VP8; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; break; case 0x02: if (p[6] != 0x20) diff --git a/libavformat/omadec.c b/libavformat/omadec.c index d2f7408709..f6b7697a43 100644 --- a/libavformat/omadec.c +++ b/libavformat/omadec.c @@ -515,7 +515,7 @@ static int oma_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 64, 1, samplerate); break; case OMA_CODECID_MP3: - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; framesize = 1024; break; case OMA_CODECID_LPCM: diff --git a/libavformat/pcm.c b/libavformat/pcm.c index cfa5b969cb..e91117ce5a 100644 --- a/libavformat/pcm.c +++ b/libavformat/pcm.c @@ -79,7 +79,7 @@ int ff_pcm_read_seek(AVFormatContext *s, pos *= block_align; /* recompute exact position */ - st->internal->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num); + ffstream(st)->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num); if ((ret = avio_seek(s->pb, pos + ffformatcontext(s)->data_offset, SEEK_SET)) < 0) return ret; return 0; diff --git a/libavformat/pva.c b/libavformat/pva.c index aecd049c03..da54b30bfc 100644 --- a/libavformat/pva.c +++ b/libavformat/pva.c @@ -62,7 +62,7 @@ static int pva_read_header(AVFormatContext *s) { return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 32, 1, 90000); av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); @@ -70,7 +70,7 @@ static int pva_read_header(AVFormatContext *s) { return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_MP2; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 33, 1, 90000); av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 06406424c8..7880f0c8a7 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -59,7 +59,7 @@ int ff_raw_audio_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = s->iformat->raw_codec_id; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->start_time = 0; /* the parameters will be extracted from the compressed bitstream */ @@ -82,9 +82,9 @@ int ff_raw_video_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = s->iformat->raw_codec_id; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; - st->internal->avctx->framerate = s1->framerate; + ffstream(st)->avctx->framerate = s1->framerate; avpriv_set_pts_info(st, 64, 1, 1200000); fail: diff --git a/libavformat/rdt.c b/libavformat/rdt.c index a015acb690..2fa3c2d266 100644 --- a/libavformat/rdt.c +++ b/libavformat/rdt.c @@ -416,7 +416,7 @@ rdt_parse_sdp_line (AVFormatContext *s, int st_index, if (av_strstart(p, "OpaqueData:buffer;", &p)) { rdt->mlti_data = rdt_parse_b64buf(&rdt->mlti_data_size, p); } else if (av_strstart(p, "StartTime:integer;", &p)) - stream->internal->first_dts = atoi(p); + ffstream(stream)->first_dts = atoi(p); else if (av_strstart(p, "ASMRuleBook:string;", &p)) { int n, first = -1; @@ -466,7 +466,7 @@ add_dstream(AVFormatContext *s, AVStream *orig_st) return NULL; st->id = orig_st->id; st->codecpar->codec_type = orig_st->codecpar->codec_type; - st->internal->first_dts = orig_st->internal->first_dts; + ffstream(st)->first_dts = ffstream(orig_st)->first_dts; return st; } diff --git a/libavformat/rl2.c b/libavformat/rl2.c index 8b6a7f1827..6a559c7294 100644 --- a/libavformat/rl2.c +++ b/libavformat/rl2.c @@ -237,9 +237,10 @@ static int rl2_read_packet(AVFormatContext *s, /** check if there is a valid video or audio entry that can be used */ for(i=0; inb_streams; i++){ - if(rl2->index_pos[i] < s->streams[i]->internal->nb_index_entries - && s->streams[i]->internal->index_entries[ rl2->index_pos[i] ].pos < pos){ - sample = &s->streams[i]->internal->index_entries[ rl2->index_pos[i] ]; + const FFStream *const sti = ffstream(s->streams[i]); + if (rl2->index_pos[i] < sti->nb_index_entries + && sti->index_entries[ rl2->index_pos[i] ].pos < pos) { + sample = &sti->index_entries[ rl2->index_pos[i] ]; pos= sample->pos; stream_id= i; } @@ -283,7 +284,7 @@ static int rl2_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp return -1; rl2->index_pos[stream_index] = index; - timestamp = st->internal->index_entries[index].timestamp; + timestamp = ffstream(st)->index_entries[index].timestamp; for(i=0; i < s->nb_streams; i++){ AVStream *st2 = s->streams[i]; diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 2529e8b1a1..29a0ec9bd9 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -202,7 +202,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, switch (st->codecpar->codec_id) { case AV_CODEC_ID_AC3: - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; break; case AV_CODEC_ID_RA_288: st->codecpar->extradata_size= 0; @@ -211,7 +211,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, st->codecpar->block_align = coded_framesize; break; case AV_CODEC_ID_COOK: - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; case AV_CODEC_ID_ATRAC3: case AV_CODEC_ID_SIPR: if (read_all) { @@ -235,7 +235,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, return -1; } st->codecpar->block_align = ff_sipr_subpk_size[flavor]; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; } else { if(sub_packet_size <= 0){ av_log(s, AV_LOG_ERROR, "sub_packet_size is invalid\n"); @@ -388,7 +388,7 @@ int ff_rm_read_mdpr_codecdata(AVFormatContext *s, AVIOContext *pb, avio_skip(pb, 2); // looks like bits per sample avio_skip(pb, 4); // always zero? st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - st->internal->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; fps = avio_rb32(pb); if ((ret = rm_read_extradata(s, pb, st->codecpar, codec_data_size - (avio_tell(pb) - codec_pos))) < 0) diff --git a/libavformat/rpl.c b/libavformat/rpl.c index 296cb2c984..187b03229b 100644 --- a/libavformat/rpl.c +++ b/libavformat/rpl.c @@ -321,10 +321,10 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) stream = s->streams[rpl->chunk_part]; - if (rpl->chunk_number >= stream->internal->nb_index_entries) + if (rpl->chunk_number >= ffstream(stream)->nb_index_entries) return AVERROR_EOF; - index_entry = &stream->internal->index_entries[rpl->chunk_number]; + index_entry = &ffstream(stream)->index_entries[rpl->chunk_number]; if (rpl->frame_in_part == 0) { if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0) diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c index 7812117228..eb19e85351 100644 --- a/libavformat/rtpdec_asf.c +++ b/libavformat/rtpdec_asf.c @@ -166,8 +166,8 @@ static int asfrtp_parse_sdp_line(AVFormatContext *s, int stream_index, if (s->streams[stream_index]->id == rt->asf_ctx->streams[i]->id) { avcodec_parameters_copy(s->streams[stream_index]->codecpar, rt->asf_ctx->streams[i]->codecpar); - s->streams[stream_index]->internal->need_parsing = - rt->asf_ctx->streams[i]->internal->need_parsing; + ffstream(s->streams[stream_index])->need_parsing = + ffstream(rt->asf_ctx->streams[i])->need_parsing; avpriv_set_pts_info(s->streams[stream_index], 32, 1, 1000); } } diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 3772a7f2a9..435b0be0b8 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -218,7 +218,7 @@ static void init_rtp_handler(const RTPDynamicProtocolHandler *handler, par->codec_id = handler->codec_id; rtsp_st->dynamic_handler = handler; if (st) - st->internal->need_parsing = handler->need_parsing; + ffstream(st)->need_parsing = handler->need_parsing; if (handler->priv_data_size) { rtsp_st->dynamic_protocol_context = av_mallocz(handler->priv_data_size); if (!rtsp_st->dynamic_protocol_context) diff --git a/libavformat/s337m.c b/libavformat/s337m.c index e1d921c303..6fecfeffae 100644 --- a/libavformat/s337m.c +++ b/libavformat/s337m.c @@ -181,7 +181,7 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) } st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = codec; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; } return 0; diff --git a/libavformat/sbgdec.c b/libavformat/sbgdec.c index 21a918db44..8f0ecf7889 100644 --- a/libavformat/sbgdec.c +++ b/libavformat/sbgdec.c @@ -1443,13 +1443,13 @@ static av_cold int sbg_read_header(AVFormatContext *avf) st->codecpar->sample_rate = sbg->sample_rate; st->codecpar->frame_size = sbg->frame_size; avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); - st->internal->probe_packets = 0; + ffstream(st)->probe_packets = 0; st->start_time = av_rescale(script.start_ts, sbg->sample_rate, AV_TIME_BASE); st->duration = script.end_ts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE : av_rescale(script.end_ts - script.start_ts, sbg->sample_rate, AV_TIME_BASE); - st->internal->cur_dts = st->start_time; + ffstream(st)->cur_dts = st->start_time; r = encode_intervals(&script, st->codecpar, &inter); if (r < 0) goto fail; @@ -1470,7 +1470,7 @@ static int sbg_read_packet(AVFormatContext *avf, AVPacket *packet) int64_t ts, end_ts; int ret; - ts = avf->streams[0]->internal->cur_dts; + ts = ffstream(avf->streams[0])->cur_dts; end_ts = ts + avf->streams[0]->codecpar->frame_size; if (avf->streams[0]->duration != AV_NOPTS_VALUE) end_ts = FFMIN(avf->streams[0]->start_time + avf->streams[0]->duration, @@ -1493,7 +1493,7 @@ static int sbg_read_seek2(AVFormatContext *avf, int stream_index, return AVERROR(EINVAL); if (stream_index < 0) ts = av_rescale_q(ts, AV_TIME_BASE_Q, avf->streams[0]->time_base); - avf->streams[0]->internal->cur_dts = ts; + ffstream(avf->streams[0])->cur_dts = ts; return 0; } diff --git a/libavformat/sdr2.c b/libavformat/sdr2.c index 0f506fd074..6799339420 100644 --- a/libavformat/sdr2.c +++ b/libavformat/sdr2.c @@ -51,7 +51,7 @@ static int sdr2_read_header(AVFormatContext *s) st->codecpar->width = avio_rl32(s->pb); st->codecpar->height = avio_rl32(s->pb); st->codecpar->codec_id = AV_CODEC_ID_H264; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; ast->codecpar->channels = 1; diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c index ce1166a05b..3af7518d03 100644 --- a/libavformat/segafilm.c +++ b/libavformat/segafilm.c @@ -183,7 +183,7 @@ static int film_read_header(AVFormatContext *s) if (film->audio_type == AV_CODEC_ID_ADPCM_ADX) { st->codecpar->bits_per_coded_sample = 18 * 8 / 32; st->codecpar->block_align = st->codecpar->channels * 18; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; } else { st->codecpar->bits_per_coded_sample = film->audio_bits; st->codecpar->block_align = st->codecpar->channels * @@ -315,7 +315,7 @@ static int film_read_seek(AVFormatContext *s, int stream_index, int64_t timestam if (ret < 0) return ret; - pos = avio_seek(s->pb, st->internal->index_entries[ret].pos, SEEK_SET); + pos = avio_seek(s->pb, ffstream(st)->index_entries[ret].pos, SEEK_SET); if (pos < 0) return pos; diff --git a/libavformat/segment.c b/libavformat/segment.c index ed671353d0..73cb05f783 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -991,8 +991,8 @@ static int seg_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) if (ret == 1) { AVStream *st = s->streams[pkt->stream_index]; AVStream *ost = oc->streams[pkt->stream_index]; - st->internal->bsfc = ost->internal->bsfc; - ost->internal->bsfc = NULL; + ffstream( st)->bsfc = ffstream(ost)->bsfc; + ffstream(ost)->bsfc = NULL; } return ret; } diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c index 65ef942367..6cd98b62c6 100644 --- a/libavformat/smoothstreamingenc.c +++ b/libavformat/smoothstreamingenc.c @@ -586,11 +586,11 @@ static int ism_write_packet(AVFormatContext *s, AVPacket *pkt) int64_t end_dts = (c->nb_fragments + 1) * (int64_t) c->min_frag_duration; int ret; - if (st->internal->first_dts == AV_NOPTS_VALUE) - st->internal->first_dts = pkt->dts; + if (ffstream(st)->first_dts == AV_NOPTS_VALUE) + ffstream(st)->first_dts = pkt->dts; if ((!c->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && - av_compare_ts(pkt->dts - st->internal->first_dts, st->time_base, + av_compare_ts(pkt->dts - ffstream(st)->first_dts, st->time_base, end_dts, AV_TIME_BASE_Q) >= 0 && pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) { diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c index 8eda80b4f6..e549e4f50b 100644 --- a/libavformat/swfdec.c +++ b/libavformat/swfdec.c @@ -204,7 +204,7 @@ static AVStream *create_new_audio_stream(AVFormatContext *s, int id, int info) } ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; ast->codecpar->codec_id = ff_codec_get_id(swf_audio_codec_tags, info>>4 & 15); - ast->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(ast)->need_parsing = AVSTREAM_PARSE_FULL; sample_rate_code = info>>2 & 3; sample_size_code = info>>1 & 1; if (!sample_size_code && ast->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) @@ -293,7 +293,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(ENOMEM); ast->duration = avio_rl32(pb); // number of samples if (((v>>4) & 15) == 2) { // MP3 sound data record - ast->internal->skip_samples = avio_rl16(pb); + ffstream(ast)->skip_samples = avio_rl16(pb); len -= 2; } len -= 7; diff --git a/libavformat/takdec.c b/libavformat/takdec.c index e3f611883b..839e3cc781 100644 --- a/libavformat/takdec.c +++ b/libavformat/takdec.c @@ -64,7 +64,7 @@ static int tak_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_TAK; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; tc->mlast_frame = 0; if (avio_rl32(pb) != MKTAG('t', 'B', 'a', 'K')) { diff --git a/libavformat/tedcaptionsdec.c b/libavformat/tedcaptionsdec.c index 4bf93e26e2..2e039a0dbb 100644 --- a/libavformat/tedcaptionsdec.c +++ b/libavformat/tedcaptionsdec.c @@ -298,10 +298,10 @@ static av_cold int tedcaptions_read_header(AVFormatContext *avf) st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_TEXT; avpriv_set_pts_info(st, 64, 1, 1000); - st->internal->probe_packets = 0; + ffstream(st)->probe_packets = 0; st->start_time = 0; st->duration = last->pts + last->duration; - st->internal->cur_dts = 0; + ffstream(st)->cur_dts = 0; return 0; } diff --git a/libavformat/tta.c b/libavformat/tta.c index e1f9cf27d8..3bdf60dc8d 100644 --- a/libavformat/tta.c +++ b/libavformat/tta.c @@ -157,15 +157,15 @@ static int tta_read_packet(AVFormatContext *s, AVPacket *pkt) if (c->currentframe >= c->totalframes) return AVERROR_EOF; - if (st->internal->nb_index_entries < c->totalframes) { + if (ffstream(st)->nb_index_entries < c->totalframes) { av_log(s, AV_LOG_ERROR, "Index entry disappeared\n"); return AVERROR_INVALIDDATA; } - size = st->internal->index_entries[c->currentframe].size; + size = ffstream(st)->index_entries[c->currentframe].size; ret = av_get_packet(s->pb, pkt, size); - pkt->dts = st->internal->index_entries[c->currentframe++].timestamp; + pkt->dts = ffstream(st)->index_entries[c->currentframe++].timestamp; pkt->duration = c->currentframe == c->totalframes ? c->last_frame_size : c->frame_size; return ret; @@ -178,7 +178,7 @@ static int tta_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp int index = av_index_search_timestamp(st, timestamp, flags); if (index < 0) return -1; - if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, ffstream(st)->index_entries[index].pos, SEEK_SET) < 0) return -1; c->currentframe = index; diff --git a/libavformat/ty.c b/libavformat/ty.c index 5bb5d4267b..760dfda54c 100644 --- a/libavformat/ty.c +++ b/libavformat/ty.c @@ -308,7 +308,7 @@ static int ty_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 1, 90000); ast = avformat_new_stream(s, NULL); @@ -318,7 +318,7 @@ static int ty_read_header(AVFormatContext *s) if (ty->audio_type == TIVO_AUDIO_MPEG) { ast->codecpar->codec_id = AV_CODEC_ID_MP2; - ast->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(ast)->need_parsing = AVSTREAM_PARSE_FULL_RAW; } else { ast->codecpar->codec_id = AV_CODEC_ID_AC3; } diff --git a/libavformat/utils.c b/libavformat/utils.c index ec37a6115e..cedea97593 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -103,7 +103,7 @@ static int is_relative(int64_t ts) { */ static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) { - const AVStreamInternal *const sti = st->internal; + const FFStream *const sti = cffstream(st); if (sti->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 && sti->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { if (sti->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && @@ -118,20 +118,20 @@ static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) int64_t av_stream_get_end_pts(const AVStream *st) { - if (st->internal->priv_pts) { - return st->internal->priv_pts->val; + if (cffstream(st)->priv_pts) { + return cffstream(st)->priv_pts->val; } else return AV_NOPTS_VALUE; } struct AVCodecParserContext *av_stream_get_parser(const AVStream *st) { - return st->internal->parser; + return cffstream(st)->parser; } void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type) { - st->internal->need_parsing = type; + ffstream(st)->need_parsing = type; } void av_format_inject_global_side_data(AVFormatContext *s) @@ -139,7 +139,7 @@ void av_format_inject_global_side_data(AVFormatContext *s) ffformatcontext(s)->inject_global_side_data = 1; for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - st->internal->inject_global_side_data = 1; + ffstream(st)->inject_global_side_data = 1; } } @@ -313,7 +313,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); if (fmt) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); av_log(s, AV_LOG_DEBUG, "Probe with size=%d, packets=%d detected %s with score=%d\n", pd->buf_size, s->max_probe_packets - sti->probe_packets, @@ -435,7 +435,7 @@ static int update_stream_avctx(AVFormatContext *s) int ret; for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (!sti->need_context_update) continue; @@ -631,7 +631,7 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (sti->request_probe > 0) { AVProbeData *pd = &sti->probe_data; int end; @@ -682,7 +682,7 @@ no_packet: static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int64_t ref = pkt->dts; int pts_wrap_behavior; int64_t pts_wrap_reference; @@ -705,10 +705,10 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in if (!first_program) { int default_stream_index = av_find_default_stream_index(s); - AVStreamInternal *const default_sti = s->streams[default_stream_index]->internal; + FFStream *const default_sti = ffstream(s->streams[default_stream_index]); if (default_sti->pts_wrap_reference == AV_NOPTS_VALUE) { for (unsigned i = 0; i < s->nb_streams; i++) { - AVStreamInternal *const sti = s->streams[i]->internal; + FFStream *const sti = ffstream(s->streams[i]); if (av_find_program_from_stream(s, NULL, i)) continue; sti->pts_wrap_reference = pts_wrap_reference; @@ -736,7 +736,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in while (program) { if (program->pts_wrap_reference != pts_wrap_reference) { for (unsigned i = 0; i < program->nb_stream_indexes; i++) { - AVStreamInternal *const sti = s->streams[program->stream_index[i]]->internal; + FFStream *const sti = ffstream(s->streams[program->stream_index[i]]); sti->pts_wrap_reference = pts_wrap_reference; sti->pts_wrap_behavior = pts_wrap_behavior; } @@ -768,7 +768,7 @@ FF_ENABLE_DEPRECATION_WARNINGS for (;;) { PacketList *pktl = si->raw_packet_buffer; - AVStreamInternal *sti; + FFStream *sti; const AVPacket *pkt1; if (pktl) { @@ -776,7 +776,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (si->raw_packet_buffer_remaining_size <= 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; - if (st->internal->request_probe <= 0) { + if (ffstream(st)->request_probe <= 0) { avpriv_packet_list_get(&si->raw_packet_buffer, &si->raw_packet_buffer_end, pkt); si->raw_packet_buffer_remaining_size += pkt->size; @@ -797,7 +797,7 @@ FF_ENABLE_DEPRECATION_WARNINGS return err; for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *const st = s->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (sti->probe_packets || sti->request_probe > 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; @@ -828,7 +828,7 @@ FF_ENABLE_DEPRECATION_WARNINGS "Invalid stream index.\n"); st = s->streams[pkt->stream_index]; - sti = st->internal; + sti = ffstream(st); if (update_wrap_reference(s, st, pkt->stream_index, pkt) && sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { // correct first time stamps to negative values @@ -890,7 +890,7 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); AVRational codec_framerate = sti->avctx->framerate; int frame_size, sample_rate; @@ -955,7 +955,7 @@ int ff_is_intra_only(enum AVCodecID id) static int has_decode_delay_been_guessed(AVStream *st) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; if (!sti->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy return 1; @@ -983,7 +983,7 @@ static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pk } static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && st->codecpar->codec_id != AV_CODEC_ID_HEVC; @@ -1032,7 +1032,7 @@ static void update_dts_from_pts(AVFormatContext *s, int stream_index, PacketList *pkt_buffer) { AVStream *st = s->streams[stream_index]; - int delay = st->internal->avctx->has_b_frames; + int delay = ffstream(st)->avctx->has_b_frames; int64_t pts_buffer[MAX_REORDER_DELAY+1]; @@ -1058,7 +1058,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, { FFFormatContext *const si = ffformatcontext(s); AVStream *st = s->streams[stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; PacketList *pktl_it; @@ -1112,7 +1112,7 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, int stream_index, int64_t duration) { FFFormatContext *const si = ffformatcontext(s); - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; int64_t cur_dts = RELATIVE_TS_BASE; @@ -1171,7 +1171,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt, int64_t next_dts, int64_t next_pts) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int num, den, presentation_delayed, delay; int64_t offset; AVRational duration; @@ -1365,7 +1365,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, FFFormatContext *const si = ffformatcontext(s); AVPacket *out_pkt = si->parse_pkt; AVStream *st = s->streams[stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); uint8_t *data = pkt->data; int size = pkt->size; int ret = 0, got_output = flush; @@ -1483,7 +1483,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) while (!got_packet && !si->parse_queue) { AVStream *st; - AVStreamInternal *sti; + FFStream *sti; /* read next packet */ ret = ff_read_packet(s, pkt); @@ -1493,7 +1493,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) /* flush the parsers */ for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *const st = s->streams[i]; - if (st->internal->parser && st->internal->need_parsing) + FFStream *const sti = ffstream(st); + if (sti->parser && sti->need_parsing) parse_packet(s, pkt, st->index, 1); } /* all remaining packets are now in parse_queue => @@ -1502,7 +1503,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } ret = 0; st = s->streams[pkt->stream_index]; - sti = st->internal; + sti = ffstream(st); st->event_flags |= AVSTREAM_EVENT_FLAG_NEW_PACKETS; @@ -1598,7 +1599,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) if (ret >= 0) { AVStream *st = s->streams[pkt->stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int discard_padding = 0; if (sti->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0); @@ -1800,7 +1801,7 @@ int av_find_default_stream_index(AVFormatContext *s) if (st->codecpar->sample_rate) score += 50; } - if (st->internal->codec_info_nb_frames) + if (cffstream(st)->codec_info_nb_frames) score += 12; if (st->discard != AVDISCARD_ALL) @@ -1823,7 +1824,7 @@ void ff_read_frame_flush(AVFormatContext *s) /* Reset read state for each stream. */ for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *const st = s->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (sti->parser) { av_parser_close(sti->parser); @@ -1854,7 +1855,7 @@ void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timesta for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - st->internal->cur_dts = + ffstream(st)->cur_dts = av_rescale(timestamp, st->time_base.den * (int64_t) ref_st->time_base.num, st->time_base.num * (int64_t) ref_st->time_base.den); @@ -1864,7 +1865,7 @@ void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timesta void ff_reduce_index(AVFormatContext *s, int stream_index) { AVStream *st = s->streams[stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); unsigned int max_entries = s->max_index_size / sizeof(AVIndexEntry); if ((unsigned) sti->nb_index_entries >= max_entries) { @@ -1937,7 +1938,7 @@ int ff_add_index_entry(AVIndexEntry **index_entries, int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); timestamp = wrap_timestamp(st, timestamp); return ff_add_index_entry(&sti->index_entries, &sti->nb_index_entries, &sti->index_entries_allocated_size, pos, @@ -2009,10 +2010,10 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) for (unsigned ist1 = 0; ist1 < s->nb_streams; ist1++) { AVStream *st1 = s->streams[ist1]; - AVStreamInternal *const sti1 = st1->internal; + FFStream *const sti1 = ffstream(st1); for (unsigned ist2 = 0; ist2 < s->nb_streams; ist2++) { AVStream *st2 = s->streams[ist2]; - AVStreamInternal *const sti2 = st2->internal; + FFStream *const sti2 = ffstream(st2); if (ist1 == ist2) continue; @@ -2056,19 +2057,19 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); return ff_index_search_timestamp(sti->index_entries, sti->nb_index_entries, wanted_timestamp, flags); } int avformat_index_get_entries_count(const AVStream *st) { - return st->internal->nb_index_entries; + return cffstream(st)->nb_index_entries; } const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx) { - const AVStreamInternal *const sti = st->internal; + const FFStream *const sti = ffstream(st); if (idx < 0 || idx >= sti->nb_index_entries) return NULL; @@ -2079,7 +2080,7 @@ const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) { - const AVStreamInternal *const sti = st->internal; + const FFStream *const sti = ffstream(st); int idx = ff_index_search_timestamp(sti->index_entries, sti->nb_index_entries, wanted_timestamp, flags); @@ -2108,7 +2109,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int index; int64_t ret; AVStream *st; - AVStreamInternal *sti; + FFStream *sti; if (stream_index < 0) return -1; @@ -2120,7 +2121,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, pos_limit = -1; // GCC falsely says it may be uninitialized. st = s->streams[stream_index]; - sti = st->internal; + sti = ffstream(st); if (sti->index_entries) { AVIndexEntry *e; @@ -2337,7 +2338,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { AVStream *const st = s->streams[stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int index; int64_t ret; AVIndexEntry *ie; @@ -2678,7 +2679,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) int64_t bit_rate = 0; for (unsigned i = 0; i < ic->nb_streams; i++) { const AVStream *const st = ic->streams[i]; - const AVStreamInternal *const sti = st->internal; + const FFStream *const sti = cffstream(st); if (st->codecpar->bit_rate <= 0 && sti->avctx->bit_rate > 0) st->codecpar->bit_rate = sti->avctx->bit_rate; if (st->codecpar->bit_rate > 0) { @@ -2739,7 +2740,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (st->start_time == AV_NOPTS_VALUE && sti->first_dts == AV_NOPTS_VALUE && @@ -2772,7 +2773,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) read_size = 0; for (;;) { AVStream *st; - AVStreamInternal *sti; + FFStream *sti; if (read_size >= DURATION_MAX_READ_SIZE << (FFMAX(retry - 1, 0))) break; @@ -2783,7 +2784,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) break; read_size += pkt->size; st = ic->streams[pkt->stream_index]; - sti = st->internal; + sti = ffstream(st); if (pkt->pts != AV_NOPTS_VALUE && (st->start_time != AV_NOPTS_VALUE || sti->first_dts != AV_NOPTS_VALUE)) { @@ -2839,7 +2840,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_AUDIO: - if (st->start_time != AV_NOPTS_VALUE || st->internal->first_dts != AV_NOPTS_VALUE) { + if (st->start_time != AV_NOPTS_VALUE || cffstream(st)->first_dts != AV_NOPTS_VALUE) { av_log(ic, AV_LOG_WARNING, "stream %d : no PTS found at end of file, duration not set\n", i); } else av_log(ic, AV_LOG_WARNING, "stream %d : no TS found at start of file, duration not set\n", i); @@ -2852,7 +2853,7 @@ skip_duration_calc: avio_seek(ic->pb, old_offset, SEEK_SET); for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); sti->cur_dts = sti->first_dts; sti->last_IP_pts = AV_NOPTS_VALUE; @@ -2925,7 +2926,7 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset) static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); AVCodecContext *avctx = sti->avctx; #define FAIL(errmsg) do { \ @@ -2975,7 +2976,7 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) static int try_decode_frame(AVFormatContext *s, AVStream *st, const AVPacket *avpkt, AVDictionary **options) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); AVCodecContext *avctx = sti->avctx; const AVCodec *codec; int got_picture = 1, ret = 0; @@ -3303,7 +3304,7 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int64_t last = sti->info->last_dts; if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last @@ -3365,7 +3366,7 @@ void ff_rfps_calculate(AVFormatContext *ic) { for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *st = ic->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) continue; @@ -3445,7 +3446,7 @@ static int extract_extradata_check(AVStream *st) static int extract_extradata_init(AVStream *st) { - AVStreamInternal *sti = st->internal; + FFStream *sti = ffstream(st); const AVBitStreamFilter *f; int ret; @@ -3484,7 +3485,7 @@ fail: static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt) { - AVStreamInternal *sti = st->internal; + FFStream *sti = ffstream(st); AVPacket *pkt_ref = si->parse_pkt; int ret; @@ -3587,7 +3588,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) const AVCodec *codec; AVDictionary *thread_opt = NULL; AVStream *const st = ic->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); AVCodecContext *const avctx = sti->avctx; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || @@ -3651,7 +3652,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) for (;;) { const AVPacket *pkt; AVStream *st; - AVStreamInternal *sti; + FFStream *sti; AVCodecContext *avctx; int analyzed_all_streams; unsigned i; @@ -3664,7 +3665,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* check if one codec still needs to be handled */ for (i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int fps_analyze_framecount = 20; int count; @@ -3727,7 +3728,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; if (!st->r_frame_rate.num && - st->internal->info->duration_count <= 1 && + ffstream(st)->info->duration_count <= 1 && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && strcmp(ic->iformat->name, "image2")) av_log(ic, AV_LOG_WARNING, @@ -3762,7 +3763,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } st = ic->streams[pkt->stream_index]; - sti = st->internal; + sti = ffstream(st); if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) read_size += pkt->size; @@ -3888,7 +3889,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) if (eof_reached) { for (unsigned stream_index = 0; stream_index < ic->nb_streams; stream_index++) { AVStream *const st = ic->streams[stream_index]; - AVCodecContext *const avctx = st->internal->avctx; + AVCodecContext *const avctx = ffstream(st)->avctx; if (!has_codec_parameters(st, NULL)) { const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id); if (codec && !avctx->codec) { @@ -3919,7 +3920,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) AVStream *const st = ic->streams[i]; /* flush the decoders */ - if (st->internal->info->found_decoder == 1) { + if (ffstream(st)->info->found_decoder == 1) { do { err = try_decode_frame(ic, st, empty_pkt, (options && i < orig_nb_streams) @@ -3938,7 +3939,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); AVCodecContext *const avctx = sti->avctx; if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -4040,7 +4041,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ret = -1; for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); const char *errmsg; /* if no packet was ever seen, update context now for has_codec_parameters */ @@ -4071,7 +4072,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* update the stream parameters from the internal codec contexts */ for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (sti->avctx_inited) { ret = avcodec_parameters_from_context(st->codecpar, sti->avctx); @@ -4088,7 +4089,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) find_stream_info_err: for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (sti->info) { av_freep(&sti->info->duration_error); av_freep(&sti->info); @@ -4163,7 +4164,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, } disposition = !(st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED | AV_DISPOSITION_VISUAL_IMPAIRED)) + !! (st->disposition & AV_DISPOSITION_DEFAULT); - count = st->internal->codec_info_nb_frames; + count = ffstream(st)->codec_info_nb_frames; bitrate = par->bit_rate; multiframe = FFMIN(5, count); if ((best_disposition > disposition) || @@ -4261,7 +4262,7 @@ int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) static void free_stream(AVStream **pst) { AVStream *st = *pst; - AVStreamInternal *sti; + FFStream *const sti = ffstream(st); if (!st) return; @@ -4273,8 +4274,6 @@ static void free_stream(AVStream **pst) if (st->attached_pic.data) av_packet_unref(&st->attached_pic); - sti = st->internal; - if (sti) { av_parser_close(sti->parser); avcodec_free_context(&sti->avctx); av_bsf_free(&sti->bsfc); @@ -4288,8 +4287,6 @@ static void free_stream(AVStream **pst) av_freep(&sti->info->duration_error); av_freep(&sti->info); } - } - av_freep(&st->internal); av_dict_free(&st->metadata); avcodec_parameters_free(&st->codecpar); @@ -4379,8 +4376,8 @@ void avformat_close_input(AVFormatContext **ps) AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) { + FFStream *sti; AVStream *st; - AVStreamInternal *sti; AVStream **streams; if (s->nb_streams >= s->max_streams) { @@ -4394,13 +4391,11 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) return NULL; s->streams = streams; - st = av_mallocz(sizeof(AVStream)); - if (!st) - return NULL; - sti = st->internal = av_mallocz(sizeof(*st->internal)); + sti = av_mallocz(sizeof(*sti)); if (!sti) - goto fail; + return NULL; + st = &sti->pub; st->codecpar = avcodec_parameters_alloc(); if (!st->codecpar) @@ -4821,7 +4816,7 @@ void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, return; } s->time_base = new_tb; - s->internal->avctx->pkt_timebase = new_tb; + ffstream(s)->avctx->pkt_timebase = new_tb; s->pts_wrap_bits = pts_wrap_bits; } @@ -4994,7 +4989,7 @@ AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *strea AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame) { AVRational fr = st->r_frame_rate; - AVCodecContext *const avctx = st->internal->avctx; + AVCodecContext *const avctx = ffstream(st)->avctx; AVRational codec_fr = avctx->framerate; AVRational avg_fr = st->avg_frame_rate; @@ -5398,7 +5393,7 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a const AVBitStreamFilter *bsf; AVBSFContext *bsfc; - av_assert0(!st->internal->bsfc); + av_assert0(!ffstream(st)->bsfc); if (!(bsf = av_bsf_get_by_name(name))) { av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name); @@ -5432,7 +5427,7 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a return ret; } - st->internal->bsfc = bsfc; + ffstream(st)->bsfc = bsfc; av_log(NULL, AV_LOG_VERBOSE, "Automatically inserted bitstream filter '%s'; args='%s'\n", @@ -5539,8 +5534,8 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVStream *ost, const AVStream *ist, enum AVTimebaseSource copy_tb) { - const AVCodecContext *const dec_ctx = ist->internal->avctx; - AVCodecContext *const enc_ctx = ost->internal->avctx; + const AVCodecContext *const dec_ctx = cffstream(ist)->avctx; + AVCodecContext *const enc_ctx = ffstream(ost)->avctx; enc_ctx->time_base = ist->time_base; /* @@ -5596,7 +5591,7 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVRational av_stream_get_codec_timebase(const AVStream *st) { // See avformat_transfer_internal_stream_timing_info() TODO. - return st->internal->avctx->time_base; + return cffstream(st)->avctx->time_base; } void ff_format_set_url(AVFormatContext *s, char *url) diff --git a/libavformat/vocdec.c b/libavformat/vocdec.c index 0bb2bc4fb1..f235d7635b 100644 --- a/libavformat/vocdec.c +++ b/libavformat/vocdec.c @@ -73,6 +73,7 @@ static int voc_read_seek(AVFormatContext *s, int stream_index, { VocDecContext *voc = s->priv_data; AVStream *st; + FFStream *sti; int index; if (s->nb_streams < 1) { @@ -81,16 +82,17 @@ static int voc_read_seek(AVFormatContext *s, int stream_index, } st = s->streams[stream_index]; + sti = ffstream(st); index = av_index_search_timestamp(st, timestamp, flags); - if (index >= 0 && index < st->internal->nb_index_entries - 1) { - AVIndexEntry *e = &st->internal->index_entries[index]; + if (index >= 0 && index < sti->nb_index_entries - 1) { + const AVIndexEntry *const e = &sti->index_entries[index]; avio_seek(s->pb, e->pos, SEEK_SET); voc->pts = e->timestamp; voc->remaining_size = e->size; return 0; - } else if (st->internal->nb_index_entries && st->internal->index_entries[0].timestamp <= timestamp) { - AVIndexEntry *e = &st->internal->index_entries[st->internal->nb_index_entries - 1]; + } else if (sti->nb_index_entries && sti->index_entries[0].timestamp <= timestamp) { + const AVIndexEntry *const e = &sti->index_entries[sti->nb_index_entries - 1]; // prepare context for seek_frame_generic() voc->pts = e->timestamp; voc->remaining_size = e->size; diff --git a/libavformat/vqf.c b/libavformat/vqf.c index 1810fca8b9..76131cdc55 100644 --- a/libavformat/vqf.c +++ b/libavformat/vqf.c @@ -277,7 +277,7 @@ static int vqf_read_seek(AVFormatContext *s, AV_ROUND_DOWN : AV_ROUND_UP); pos *= c->frame_bit_len; - st->internal->cur_dts = av_rescale(pos, st->time_base.den, + ffstream(st)->cur_dts = av_rescale(pos, st->time_base.den, st->codecpar->bit_rate * (int64_t)st->time_base.num); if ((ret = avio_seek(s->pb, ((pos-7) >> 3) + ffformatcontext(s)->data_offset, SEEK_SET)) < 0) diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 815d189671..7a7e765353 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -166,8 +166,9 @@ static int wav_probe(const AVProbeData *p) static void handle_stream_probing(AVStream *st) { if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) { - st->internal->request_probe = AVPROBE_SCORE_EXTENSION; - st->internal->probe_packets = FFMIN(st->internal->probe_packets, 32); + FFStream *const sti = ffstream(st); + sti->request_probe = AVPROBE_SCORE_EXTENSION; + sti->probe_packets = FFMIN(sti->probe_packets, 32); } } @@ -183,7 +184,7 @@ static int wav_parse_fmt_tag(AVFormatContext *s, int64_t size, AVStream *st) return ret; handle_stream_probing(st); - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); @@ -200,7 +201,7 @@ static int wav_parse_xma2_tag(AVFormatContext *s, int64_t size, AVStream *st) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_XMA2; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; version = avio_r8(pb); if (version != 3 && version != 4) @@ -702,8 +703,8 @@ static int wav_read_packet(AVFormatContext *s, AVPacket *pkt) int64_t audio_dts, video_dts; AVStream *vst = wav->vst; smv_retry: - audio_dts = (int32_t)st->internal->cur_dts; - video_dts = (int32_t)vst->internal->cur_dts; + audio_dts = (int32_t)ffstream( st)->cur_dts; + video_dts = (int32_t)ffstream(vst)->cur_dts; if (audio_dts != AV_NOPTS_VALUE && video_dts != AV_NOPTS_VALUE) { /*We always return a video frame first to get the pixel format first*/ @@ -950,7 +951,7 @@ static int w64_read_header(AVFormatContext *s) ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv); handle_stream_probing(st); - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; avio_seek(pb, data_ofs, SEEK_SET); diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c index 191da2718b..22e4c92565 100644 --- a/libavformat/wtvdec.c +++ b/libavformat/wtvdec.c @@ -618,7 +618,7 @@ static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int code st->priv_data = wst; } st->codecpar->codec_type = codec_type; - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 10000000); return st; } diff --git a/libavformat/xvag.c b/libavformat/xvag.c index 2a85d66ecb..994b710f8d 100644 --- a/libavformat/xvag.c +++ b/libavformat/xvag.c @@ -87,7 +87,7 @@ static int xvag_read_header(AVFormatContext *s) if (avio_rb16(s->pb) == 0xFFFB) { st->codecpar->codec_id = AV_CODEC_ID_MP3; st->codecpar->block_align = 0x1000; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; } avio_skip(s->pb, -2); diff --git a/libavformat/xwma.c b/libavformat/xwma.c index d7fd05504b..37ab3a1ec0 100644 --- a/libavformat/xwma.c +++ b/libavformat/xwma.c @@ -78,7 +78,7 @@ static int xwma_read_header(AVFormatContext *s) ret = ff_get_wav_header(s, pb, st->codecpar, size, 0); if (ret < 0) return ret; - st->internal->need_parsing = AVSTREAM_PARSE_NONE; + ffstream(st)->need_parsing = AVSTREAM_PARSE_NONE; /* XWMA encoder only allows a few channel/sample rate/bitrate combinations, * but some create identical files with fake bitrate (1ch 22050hz at From patchwork Fri Aug 27 14:27:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29820 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1515045iov; Fri, 27 Aug 2021 07:31:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyC1jTf+3d88HxrZHNOOq744BGHIeFssU0zmusA6fupX4uhp6z36ItZ47gWm2EcPe9DrgyA X-Received: by 2002:aa7:c799:: with SMTP id n25mr9858065eds.16.1630074704308; Fri, 27 Aug 2021 07:31:44 -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 10si5731011ejt.595.2021.08.27.07.31.44; Fri, 27 Aug 2021 07:31:44 -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=hFagBTXv; 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 5D1CA68A5FB; Fri, 27 Aug 2021 17:28:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (unknown [40.92.67.59]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 98F8668A588 for ; Fri, 27 Aug 2021 17:28:07 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=To/gkdPEwuV98wSj4gv1GhKDp4sroUWJ2d08GbHxEBexlLvfkV5609sy+3F1UrnkWvN9b/3txSefad8Xtf2XDziqD/QmyuIW0DvGlJHQfgWpwCVjzZeY0Wfb6A5otaQQ5IU3z4exYZOJU46sD0l6KGSLZE9FcIaKq8zTF/lPWYQ7Xs6xxWTRX6cWiJ8yyiNlLxILA2hl767icWyyHqiU4JVzcc7KU7aAe2ROtLScaJl3pHAVLuWtdgGx19bysf2pVX6R2sInZSrsyWRPnnAENPWvMCERBL9Yyw118w3uY51G8jZ6wsiw2jiOg63DlVkmlACM4WZwjlz1ELqxOuv//A== 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=y2MLiK6lOzZpVhDKdwhJKvrAfi+pL7l9+cQg299JuYM=; b=DtcUbmnKMcknS7o9Db81LxAdtLQmmOnRCVpR1SZbZ+G+Y+WFtTgd1kBdALYiRslp2tP2JlmZf8ECtXNmcuQGeYXnegq72PXZRqQpzb6Dg+S0X4hlFGAvyKim3vSTlNmE2lHnoYTPMOfgDoJApsNq0QluAA0Rbv1H+Tf8LzukVM9GZO9bcnFEyBODQZBQZIUXdLA7+xm7urte8QDKod0uyE7oAAj0jRHffzs7w3LMgGRQljBtuxVYWG0j5UVAhWNdo7F4cauln+GeXeCpB+bBHjR65s+GnoTOAIGGG3NwfWyfbShPXtZOhIC6ngom0CD8+6lrOAyZch3terrsZcncPg== 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=y2MLiK6lOzZpVhDKdwhJKvrAfi+pL7l9+cQg299JuYM=; b=hFagBTXve9lLK3u89hEGdbrilCwjrn5Kvf8lCcyAYVSakMU1txQjKhJDUVe4zVEevc2wVTPlKrHPiMhKkPkzxCOZnF9CoU5tIzmcNOvRCe162BmucjpcMIyDQgab3KbwNV3wmBPxUauuUUWXdixOTIJ1/nM/O2e++3N89y0Crzq1QaejJL9l6TEOlDt2axRKeoUBclhxAy8duzlcTaGwZ97thccPPw5eVetKzAarAuKj2eJiBaGm2UY3srrpCEK/3Fr9SxCxqd1DuJ2ovVK3rlgNWcAnBb9Yia0F6bRaEeeYl0I53GBY/8+KgdlAMN6VfY82fCc/BLiXrk16F5s5ag== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3861.eurprd03.prod.outlook.com (2603:10a6:20b:22::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Fri, 27 Aug 2021 14:28:06 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:28:06 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:23 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [r42Jzkts07lD/tjHEo7Q3pVBdfOOiVTE] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-22-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:28:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f51689dd-98c1-476c-9585-08d96966e29b X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXOVIHST31EzKLNwg5cTLbyRqsxVYAXnkeyQKfqqVRh86eDy9ZcAYt8dPPU5Wkg2PxiKXeY/V3YsBECVuWLLBLQAa96zpfKLZ/VHC5pQocZ/lUJbp4bnXWw8poR8SNv2SWzOnqBwbsFExqzJjUwUFFto2hVFu4vEmbdPXmGncJZDA3HHrQHviCP1Fs+8NTi5wJgv5p0jx0UJ42MUrOI+jLDCClSEq/lZq8d7zhGJPl4HWCehaQ/G6fOIfbtD0tIxCrGQPakZcr3vRghxLjfCL5tCVt1L3aj99gwIXbpZFmuyN01eBRQiqKNPZhrNfoWnYQjay39LZsnW9fLTJBBH4w0HdEg/9KLNoqtGybA8LPxKYJRYOucrln//gSoOjums4K6ptiVxqyTe/GDMUx35Ag/O5BklRnU9vp8j0TT4dWqAVYgQNFD3/AvlmI28fTkLQC//qw0vB6B5WIzba8Gjj00abmLAQHMaoBIYDStMuaTx4LmGbXKsxUhquN5x2i1FTV3u0cMjtYAoHcYffCsTRuQE3NwB/Td+fII3ILsgImB2v0FBJ5Z6j8/BK1mCup4CsGFGwVTbVfNQYI6vO7wzw0ttds0zCgSh3kSUwtbZCuhSMvqM69zmYHsfRbpIfgdDlTmSgViARiAurCSCCTqx0Edc/n1L0fhwcqXeJYdetaR+LbDyToHxli4Ofqdfs+LEGkfSq7Jm1w8Vr8lGNeL8/TyNzgf+Mhsrrs= X-MS-TrafficTypeDiagnostic: AM6PR03MB3861: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SZ6DVfSRPtVmomZTxteU/VABtcoMV+9xRufcrl5JJu+8Rigfkj61ZYDJTBnW7CdUimqxdmSjeh8RYydPI0rv5JNPTaEdvYMiYQFfxo2ByJSTZVkBHRUFCm/LQnR2yaCqR1f3mXJ1yEaqCjW4BhI6AbP74HcBweowsY+55JM+K3UlK5PB+soeqRVriHdhaldzqkuoHd/GoCdHSHb1IUTW1S1Q3P2mOKEjHX5F64wR9eOnwkd1FUHws03IYjUkjmOkAgqA2lWNc4nO6u9eotyjpd6TR7vndWj0zH5RiRQeJC1/80apZWxRNDn/vVCtohyigM/Ig0pkIIR/lqqVyXdUUUgLNVA7cDYWp1LKfiCiPZ8PNNUsus2IVUJ7wfBHIy1xS5S0UtDbpa1V5pZPBhiPPbdlrttkAQUVzH3wuErQjZOhKNYULALBa+9mIpcZPcfM X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Uq2bABLPEDAH1O01Q71H5LFZxX4OQz5XrvarVg4MuSU9Bz9W1VyvnkHPx6ThD4uBhyUAYrhaNcCfoNM9kiKdI8bJFPYzq8YDWwGwg5O7LfBsq20RQPYFFPEe7uAAFqFiB/o0jeXSLS/eZP9PH3Xn0A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f51689dd-98c1-476c-9585-08d96966e29b X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:28:06.1522 (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: AM6PR03MB3861 Subject: [FFmpeg-devel] [PATCH 23/25] avformat/utils: Reindentation 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: OfA8M8kKfOWF Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index cedea97593..e86cdaa96f 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4274,19 +4274,19 @@ static void free_stream(AVStream **pst) if (st->attached_pic.data) av_packet_unref(&st->attached_pic); - av_parser_close(sti->parser); - avcodec_free_context(&sti->avctx); - av_bsf_free(&sti->bsfc); - av_freep(&sti->priv_pts); - av_freep(&sti->index_entries); - av_freep(&sti->probe_data.buf); + av_parser_close(sti->parser); + avcodec_free_context(&sti->avctx); + av_bsf_free(&sti->bsfc); + av_freep(&sti->priv_pts); + av_freep(&sti->index_entries); + av_freep(&sti->probe_data.buf); - av_bsf_free(&sti->extract_extradata.bsf); + av_bsf_free(&sti->extract_extradata.bsf); - if (sti->info) { - av_freep(&sti->info->duration_error); + if (sti->info) { + av_freep(&sti->info->duration_error); av_freep(&sti->info); - } + } av_dict_free(&st->metadata); avcodec_parameters_free(&st->codecpar); From patchwork Fri Aug 27 14:27:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29824 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1515426iov; Fri, 27 Aug 2021 07:32:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNZRHcXR/uhleZNGjZgZ2o5P/ugu0+k1NkHXnjnrCj8wu47ccndjDgw1rE82bgJqpYH7ed X-Received: by 2002:adf:a44d:: with SMTP id e13mr10323990wra.177.1630074734807; Fri, 27 Aug 2021 07:32:14 -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 p31si8380206edb.495.2021.08.27.07.32.14; Fri, 27 Aug 2021 07:32:14 -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=kI36OiVg; 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 990B768A3D3; Fri, 27 Aug 2021 17:28:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (unknown [40.92.67.59]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C39B68A596 for ; Fri, 27 Aug 2021 17:28:08 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=budOfZFDoXIb3d9UqqYfTEeXhEdZL7IhRtF1ga7PmsYIKxugXUqU3VsbRMv79W9yhC/kxrblceN5qWDM+ZW1VAkhRsCMxN/M4j9gi0qoVMjUSCbgkMyGsxk6SMsVfVOG1OR+guzXE4F32AMrk8aqi3+5PuAjs2C95ceAGWgNmCgnFms5gGfUoLfMiwrhBOgjTAhea0JwtS500FFlNqWiq+sXxXlVPNOkZiV/lsEosvzKEZUx4qsXytgj+8wRVUpST9dSpP0Yq+Ochvr3R+82RZcRt/tv7a2ijY3ADApkwlYMW3P9qr4ABrERuCFBDxTLMAVPn5Hd9Le3gIh5aJ6OKA== 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=gTo/QDNwsNixcaZF712RqSu1cCNhWtKjLIZs/RU/53s=; b=MMj0QC1ESLWhkJbqcXhVtrkKsS1CwRNw5u9REPPqn7+igfJAYkKg9+hU5qibfQJpycjl2Mxtu0bxijl3SHfp0ePSwwzM1KcrMgeNK3J0wxPseWZCyvlA7UYTNgEtN7prvbPEJ549UPEOuw84Ztb0uvEoq1fLMDGys8O7X7IuGV3G5JxlZm0/cgeORJVegw6fgV+IIBhB1GX847/kVpq+evIyrMA17gCTZwHHIew2juU5K+giFBG5gMUZLVGoFpYkhqb/AX24aTiRjnTup1WGgWnzYtHgjyTsuwAoaFSbCQxCmZa+jyhRy9209/qMRwytKYNQtdZSWmdR+eo+WWZmdQ== 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=gTo/QDNwsNixcaZF712RqSu1cCNhWtKjLIZs/RU/53s=; b=kI36OiVg5NUBGXbKH7ORTV9pFR3NC0T78uuLwP8dZqrFwMcybci9lJWHy/WoDcbM2heKf+oomh1vjCSmU/W3GHwjDC776CIVepbOaD84HX/p/Ja/0/sFyrCKYbtSmSuN+3cG1HApCGE1g/kzi4kZ+LhI1MtdBYdLY8GnUOqWSQ/nX1FtvSKieVXloaSqll/i/Zs8EUpSkJQGljEu1TGupj/DdkSI0E1V6swPHnxpHwFn5P4tktSdi2/qAqXXc/cS31kCJh4sZZIpeL5Cfrb5KbeeOstXCknvcr7iWk6qTPeFOqioHLZr9U1sv9oD8OyWOEDuV9olyzDF/s3lwUSwXw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3861.eurprd03.prod.outlook.com (2603:10a6:20b:22::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Fri, 27 Aug 2021 14:28:07 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:28:07 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:24 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [/vgL7pL21B5sIDL9GHvHHXjZPpBknxRq] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-23-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:28:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 990efd20-d773-49ea-8139-08d96966e36a X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7Jz6zhCU/GQBqy7mZKQAZRxC3PFPbXpIHpCl7BAWGnr2WNd4lMZmuOVC3RY4SlPYdY7XXEEzpTbmyGDgHkFWwME80R3KzbfvlhI70fGxiM5wZNqnIWyTXWG8jyW8p22gCG2pBIP8Gey4nEWAjzu7GxPfzoiH5TWiKNL13fL2OWmG6XaqALWv3o4w1KurA3t3aktTASHYbH3PxEZybZHCDH+QBq1KgmuFWuzW5NBdfteRmb/bC/+4NKrauSYmvZrLjzBejfYIstxBmP9s4+Vvn/qvsGw27ZseCQnVTFmhWYOpfomL/H4qvr+NvS4T7kfyc2+N43acGKuS8cA+XxlxC1gH3Lrakyn1tRGPysb/eqDcFUg++CFC8jgkFpqpSI3FOg5WPNq2hebhPFc1HRVeFMBnvcvWd8muimTr77Y7OCfXIiMUDIU5hEo15b5HsrBAkLlS41Wmy9uAwhLZeYpQXYI4vDUcJIPM09ZAIIuxrwwQPQV/zrKtEuPdkwPEm8hPVvd2Au/RZdZlVmrB2GHFquNzXt+fxWDSvW3zwQwbuC1VwnJ8q0CFp1xv8lKxNPuESe2LXExWO23deLPphLRCFNz32V2bIZO16qiGIHOcSptxTv0S8VImb950MAbbuiojGU195me34+5IJgTalaAPyTe1cP2pWgAu6Oq9x2ha0TkQ/DrhLkwCEkp5K0n84jRAF1g2n45HT5kJj8GDvDzhTtcMsTNvQ49w24KDR9vtw3l0= X-MS-TrafficTypeDiagnostic: AM6PR03MB3861: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AiPeRqkQ4jkuC/Ff9ocmZWL8KzRZRWDh9+tNy0mOI/G/aAmHzXfsx5aOxBoMHjOvYPSARS1bjP6psDL9Mh2Ho/zEg4NFT+ceuDByPE7Bf2srD9i+eS1WLFWiVVXu7vRCHF3d2DgOZZzwye783DMAlH1qf35SkjP8VD8k8htu2jqQ3KseVNqv77b72zCMGSpgYQUYkCMBnjUs7gBtza9r8rb+U/pAsjQYgOtJZtp2Zw5Hdye6XBEWyPfCguaIVlkj3B2+O46TtSM3+p7gefgk0q93Ez1I1c1eAyxi3L4DYZwxP3+sfTn/z2/n0V+HbJJr4RJ7TirFqWnyoBOIWrHrlp049IOCwdi7j2SXzQducb1aYgF2RiQmIlpYuWQvJnFZ0Iu1kvExQrPvDyrrmRD+R1BTLYDvUNQlvHbOSnf7f/UI60VxjlsYLeGC9snucSsZ X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HKqoNq8V0csh6TqO8Aq/0NOb/vqt3o9syuF9vbx9QEaGGR6RpDCNolIGm8LuaK6t7qjP6ieFfeKW8FZQWIXnW9vx/HlUUpic2qdnlfNzpoTXy+DN4z0zW6x1gWT7Rlvbm8FXxHdSvout9OsPVq9lWA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 990efd20-d773-49ea-8139-08d96966e36a X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:28:07.5989 (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: AM6PR03MB3861 Subject: [FFmpeg-devel] [PATCH 24/25] avformat/utils: Move seeking code out into a new file 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: tZN+B/iMH1FU libavformat/utils.c has over 5500 lines and is supposed to contain "various utility functions for use within FFmpeg". In reality it contains all that and the whole demuxing+seeking core of libavformat. This is especially bad, because said file includes the FFMPEG_VERSION (the git commit sha) so that it is rebuilt whenever the commit HEAD points to changes. Therefore this commit starts making it smaller by factoring the seeking code out. Signed-off-by: Andreas Rheinhardt --- libavformat/Makefile | 1 + libavformat/internal.h | 18 + libavformat/seek.c | 748 +++++++++++++++++++++++++++++++++++++++++ libavformat/utils.c | 747 +--------------------------------------- 4 files changed, 775 insertions(+), 739 deletions(-) create mode 100644 libavformat/seek.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 7e0f587b41..52e1dab66d 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -19,6 +19,7 @@ OBJS = allformats.o \ protocols.o \ riff.o \ sdp.o \ + seek.o \ url.o \ utils.o \ diff --git a/libavformat/internal.h b/libavformat/internal.h index 6f53bd44a9..377d980178 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -450,6 +450,24 @@ do {\ } while(0) #endif +#define RELATIVE_TS_BASE (INT64_MAX - (1LL << 48)) + +static av_always_inline int is_relative(int64_t ts) +{ + return ts > (RELATIVE_TS_BASE - (1LL << 48)); +} + +/** + * Wrap a given time stamp, if there is an indication for an overflow + * + * @param st stream + * @param timestamp the time stamp to wrap + * @return resulting time stamp + */ +int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp); + +void ff_flush_packet_queue(AVFormatContext *s); + /** * Automatically create sub-directories * diff --git a/libavformat/seek.c b/libavformat/seek.c new file mode 100644 index 0000000000..b86172dafb --- /dev/null +++ b/libavformat/seek.c @@ -0,0 +1,748 @@ +/* + * Seeking and index-related functions + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/avassert.h" +#include "libavutil/mathematics.h" +#include "libavutil/timestamp.h" + +#include "avformat.h" +#include "avio_internal.h" +#include "internal.h" + +void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp) +{ + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; + + ffstream(st)->cur_dts = + av_rescale(timestamp, + st->time_base.den * (int64_t) ref_st->time_base.num, + st->time_base.num * (int64_t) ref_st->time_base.den); + } +} + +void ff_reduce_index(AVFormatContext *s, int stream_index) +{ + AVStream *const st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); + unsigned int max_entries = s->max_index_size / sizeof(AVIndexEntry); + + if ((unsigned) sti->nb_index_entries >= max_entries) { + int i; + for (i = 0; 2 * i < sti->nb_index_entries; i++) + sti->index_entries[i] = sti->index_entries[2 * i]; + sti->nb_index_entries = i; + } +} + +int ff_add_index_entry(AVIndexEntry **index_entries, + int *nb_index_entries, + unsigned int *index_entries_allocated_size, + int64_t pos, int64_t timestamp, + int size, int distance, int flags) +{ + AVIndexEntry *entries, *ie; + int index; + + if ((unsigned) *nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry)) + return -1; + + if (timestamp == AV_NOPTS_VALUE) + return AVERROR(EINVAL); + + if (size < 0 || size > 0x3FFFFFFF) + return AVERROR(EINVAL); + + if (is_relative(timestamp)) //FIXME this maintains previous behavior but we should shift by the correct offset once known + timestamp -= RELATIVE_TS_BASE; + + entries = av_fast_realloc(*index_entries, + index_entries_allocated_size, + (*nb_index_entries + 1) * + sizeof(AVIndexEntry)); + if (!entries) + return -1; + + *index_entries = entries; + + index = ff_index_search_timestamp(*index_entries, *nb_index_entries, + timestamp, AVSEEK_FLAG_ANY); + + if (index < 0) { + index = (*nb_index_entries)++; + ie = &entries[index]; + av_assert0(index == 0 || ie[-1].timestamp < timestamp); + } else { + ie = &entries[index]; + if (ie->timestamp != timestamp) { + if (ie->timestamp <= timestamp) + return -1; + memmove(entries + index + 1, entries + index, + sizeof(AVIndexEntry) * (*nb_index_entries - index)); + (*nb_index_entries)++; + } else if (ie->pos == pos && distance < ie->min_distance) + // do not reduce the distance + distance = ie->min_distance; + } + + ie->pos = pos; + ie->timestamp = timestamp; + ie->min_distance = distance; + ie->size = size; + ie->flags = flags; + + return index; +} + +int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, + int size, int distance, int flags) +{ + FFStream *const sti = ffstream(st); + timestamp = ff_wrap_timestamp(st, timestamp); + return ff_add_index_entry(&sti->index_entries, &sti->nb_index_entries, + &sti->index_entries_allocated_size, pos, + timestamp, size, distance, flags); +} + +int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, + int64_t wanted_timestamp, int flags) +{ + int a, b, m; + int64_t timestamp; + + a = -1; + b = nb_entries; + + // Optimize appending index entries at the end. + if (b && entries[b - 1].timestamp < wanted_timestamp) + a = b - 1; + + while (b - a > 1) { + m = (a + b) >> 1; + + // Search for the next non-discarded packet. + while ((entries[m].flags & AVINDEX_DISCARD_FRAME) && m < b && m < nb_entries - 1) { + m++; + if (m == b && entries[m].timestamp >= wanted_timestamp) { + m = b - 1; + break; + } + } + + timestamp = entries[m].timestamp; + if (timestamp >= wanted_timestamp) + b = m; + if (timestamp <= wanted_timestamp) + a = m; + } + m = (flags & AVSEEK_FLAG_BACKWARD) ? a : b; + + if (!(flags & AVSEEK_FLAG_ANY)) + while (m >= 0 && m < nb_entries && + !(entries[m].flags & AVINDEX_KEYFRAME)) + m += (flags & AVSEEK_FLAG_BACKWARD) ? -1 : 1; + + if (m == nb_entries) + return -1; + return m; +} + +void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) +{ + int64_t pos_delta = 0; + int64_t skip = 0; + //We could use URLProtocol flags here but as many user applications do not use URLProtocols this would be unreliable + const char *proto = avio_find_protocol_name(s->url); + FFIOContext *ctx; + + av_assert0(time_tolerance >= 0); + + if (!proto) { + av_log(s, AV_LOG_INFO, + "Protocol name not provided, cannot determine if input is local or " + "a network protocol, buffers and access patterns cannot be configured " + "optimally without knowing the protocol\n"); + } + + if (proto && !(strcmp(proto, "file") && strcmp(proto, "pipe") && strcmp(proto, "cache"))) + return; + + for (unsigned ist1 = 0; ist1 < s->nb_streams; ist1++) { + AVStream *const st1 = s->streams[ist1]; + FFStream *const sti1 = ffstream(st1); + for (unsigned ist2 = 0; ist2 < s->nb_streams; ist2++) { + AVStream *const st2 = s->streams[ist2]; + FFStream *const sti2 = ffstream(st2); + + if (ist1 == ist2) + continue; + + for (int i1 = 0, i2 = 0; i1 < sti1->nb_index_entries; i1++) { + const AVIndexEntry *const e1 = &sti1->index_entries[i1]; + int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q); + + skip = FFMAX(skip, e1->size); + for (; i2 < sti2->nb_index_entries; i2++) { + const AVIndexEntry *const e2 = &sti2->index_entries[i2]; + int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q); + if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance) + continue; + pos_delta = FFMAX(pos_delta, e1->pos - e2->pos); + break; + } + } + } + } + + pos_delta *= 2; + ctx = ffiocontext(s->pb); + /* XXX This could be adjusted depending on protocol*/ + if (s->pb->buffer_size < pos_delta && pos_delta < (1<<24)) { + av_log(s, AV_LOG_VERBOSE, "Reconfiguring buffers to size %"PRId64"\n", pos_delta); + + /* realloc the buffer and the original data will be retained */ + if (ffio_realloc_buf(s->pb, pos_delta)) { + av_log(s, AV_LOG_ERROR, "Realloc buffer fail.\n"); + return; + } + + ctx->short_seek_threshold = FFMAX(ctx->short_seek_threshold, pos_delta/2); + } + + if (skip < (1<<23)) { + ctx->short_seek_threshold = FFMAX(ctx->short_seek_threshold, skip); + } +} + +int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) +{ + const FFStream *const sti = ffstream(st); + return ff_index_search_timestamp(sti->index_entries, sti->nb_index_entries, + wanted_timestamp, flags); +} + +int avformat_index_get_entries_count(const AVStream *st) +{ + return cffstream(st)->nb_index_entries; +} + +const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx) +{ + const FFStream *const sti = ffstream(st); + if (idx < 0 || idx >= sti->nb_index_entries) + return NULL; + + return &sti->index_entries[idx]; +} + +const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st, + int64_t wanted_timestamp, + int flags) +{ + const FFStream *const sti = ffstream(st); + int idx = ff_index_search_timestamp(sti->index_entries, + sti->nb_index_entries, + wanted_timestamp, flags); + + if (idx < 0) + return NULL; + + return &sti->index_entries[idx]; +} + +static int64_t read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit, + int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )) +{ + int64_t ts = read_timestamp(s, stream_index, ppos, pos_limit); + if (stream_index >= 0) + ts = ff_wrap_timestamp(s->streams[stream_index], ts); + return ts; +} + +int ff_seek_frame_binary(AVFormatContext *s, int stream_index, + int64_t target_ts, int flags) +{ + const AVInputFormat *const avif = s->iformat; + int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit; + int64_t ts_min, ts_max, ts; + int index; + int64_t ret; + AVStream *st; + FFStream *sti; + + if (stream_index < 0) + return -1; + + av_log(s, AV_LOG_TRACE, "read_seek: %d %s\n", stream_index, av_ts2str(target_ts)); + + ts_max = + ts_min = AV_NOPTS_VALUE; + pos_limit = -1; // GCC falsely says it may be uninitialized. + + st = s->streams[stream_index]; + sti = ffstream(st); + if (sti->index_entries) { + const AVIndexEntry *e; + + /* FIXME: Whole function must be checked for non-keyframe entries in + * index case, especially read_timestamp(). */ + index = av_index_search_timestamp(st, target_ts, + flags | AVSEEK_FLAG_BACKWARD); + index = FFMAX(index, 0); + e = &sti->index_entries[index]; + + if (e->timestamp <= target_ts || e->pos == e->min_distance) { + pos_min = e->pos; + ts_min = e->timestamp; + av_log(s, AV_LOG_TRACE, "using cached pos_min=0x%"PRIx64" dts_min=%s\n", + pos_min, av_ts2str(ts_min)); + } else { + av_assert1(index == 0); + } + + index = av_index_search_timestamp(st, target_ts, + flags & ~AVSEEK_FLAG_BACKWARD); + av_assert0(index < sti->nb_index_entries); + if (index >= 0) { + e = &sti->index_entries[index]; + av_assert1(e->timestamp >= target_ts); + pos_max = e->pos; + ts_max = e->timestamp; + pos_limit = pos_max - e->min_distance; + av_log(s, AV_LOG_TRACE, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64 + " dts_max=%s\n", pos_max, pos_limit, av_ts2str(ts_max)); + } + } + + pos = ff_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, + ts_min, ts_max, flags, &ts, avif->read_timestamp); + if (pos < 0) + return -1; + + /* do the seek */ + if ((ret = avio_seek(s->pb, pos, SEEK_SET)) < 0) + return ret; + + ff_read_frame_flush(s); + avpriv_update_cur_dts(s, st, ts); + + return 0; +} + +int ff_find_last_ts(AVFormatContext *s, int stream_index, int64_t *ts, int64_t *pos, + int64_t (*read_timestamp_func)(struct AVFormatContext *, int , int64_t *, int64_t )) +{ + int64_t step = 1024; + int64_t limit, ts_max; + int64_t filesize = avio_size(s->pb); + int64_t pos_max = filesize - 1; + do { + limit = pos_max; + pos_max = FFMAX(0, (pos_max) - step); + ts_max = read_timestamp(s, stream_index, + &pos_max, limit, read_timestamp_func); + step += step; + } while (ts_max == AV_NOPTS_VALUE && 2*limit > step); + if (ts_max == AV_NOPTS_VALUE) + return -1; + + for (;;) { + int64_t tmp_pos = pos_max + 1; + int64_t tmp_ts = read_timestamp(s, stream_index, + &tmp_pos, INT64_MAX, read_timestamp_func); + if (tmp_ts == AV_NOPTS_VALUE) + break; + av_assert0(tmp_pos > pos_max); + ts_max = tmp_ts; + pos_max = tmp_pos; + if (tmp_pos >= filesize) + break; + } + + if (ts) + *ts = ts_max; + if (pos) + *pos = pos_max; + + return 0; +} + +int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, + int64_t pos_min, int64_t pos_max, int64_t pos_limit, + int64_t ts_min, int64_t ts_max, + int flags, int64_t *ts_ret, + int64_t (*read_timestamp_func)(struct AVFormatContext *, + int, int64_t *, int64_t)) +{ + int64_t pos, ts; + int64_t start_pos; + int no_change; + int ret; + + av_log(s, AV_LOG_TRACE, "gen_seek: %d %s\n", stream_index, av_ts2str(target_ts)); + + if (ts_min == AV_NOPTS_VALUE) { + pos_min = ffformatcontext(s)->data_offset; + ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp_func); + if (ts_min == AV_NOPTS_VALUE) + return -1; + } + + if (ts_min >= target_ts) { + *ts_ret = ts_min; + return pos_min; + } + + if (ts_max == AV_NOPTS_VALUE) { + if ((ret = ff_find_last_ts(s, stream_index, &ts_max, &pos_max, read_timestamp_func)) < 0) + return ret; + pos_limit = pos_max; + } + + if (ts_max <= target_ts) { + *ts_ret = ts_max; + return pos_max; + } + + av_assert0(ts_min < ts_max); + + no_change = 0; + while (pos_min < pos_limit) { + av_log(s, AV_LOG_TRACE, + "pos_min=0x%"PRIx64" pos_max=0x%"PRIx64" dts_min=%s dts_max=%s\n", + pos_min, pos_max, av_ts2str(ts_min), av_ts2str(ts_max)); + av_assert0(pos_limit <= pos_max); + + if (no_change == 0) { + int64_t approximate_keyframe_distance = pos_max - pos_limit; + // interpolate position (better than dichotomy) + pos = av_rescale(target_ts - ts_min, pos_max - pos_min, + ts_max - ts_min) + + pos_min - approximate_keyframe_distance; + } else if (no_change == 1) { + // bisection if interpolation did not change min / max pos last time + pos = (pos_min + pos_limit) >> 1; + } else { + /* linear search if bisection failed, can only happen if there + * are very few or no keyframes between min/max */ + pos = pos_min; + } + if (pos <= pos_min) + pos = pos_min + 1; + else if (pos > pos_limit) + pos = pos_limit; + start_pos = pos; + + // May pass pos_limit instead of -1. + ts = read_timestamp(s, stream_index, &pos, INT64_MAX, read_timestamp_func); + if (pos == pos_max) + no_change++; + else + no_change = 0; + av_log(s, AV_LOG_TRACE, "%"PRId64" %"PRId64" %"PRId64" / %s %s %s" + " target:%s limit:%"PRId64" start:%"PRId64" noc:%d\n", + pos_min, pos, pos_max, + av_ts2str(ts_min), av_ts2str(ts), av_ts2str(ts_max), av_ts2str(target_ts), + pos_limit, start_pos, no_change); + if (ts == AV_NOPTS_VALUE) { + av_log(s, AV_LOG_ERROR, "read_timestamp() failed in the middle\n"); + return -1; + } + if (target_ts <= ts) { + pos_limit = start_pos - 1; + pos_max = pos; + ts_max = ts; + } + if (target_ts >= ts) { + pos_min = pos; + ts_min = ts; + } + } + + pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; + ts = (flags & AVSEEK_FLAG_BACKWARD) ? ts_min : ts_max; +#if 0 + pos_min = pos; + ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp_func); + pos_min++; + ts_max = read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp_func); + av_log(s, AV_LOG_TRACE, "pos=0x%"PRIx64" %s<=%s<=%s\n", + pos, av_ts2str(ts_min), av_ts2str(target_ts), av_ts2str(ts_max)); +#endif + *ts_ret = ts; + return pos; +} + +static int seek_frame_byte(AVFormatContext *s, int stream_index, + int64_t pos, int flags) +{ + int64_t pos_min, pos_max; + + pos_min = ffformatcontext(s)->data_offset; + pos_max = avio_size(s->pb) - 1; + + if (pos < pos_min) + pos = pos_min; + else if (pos > pos_max) + pos = pos_max; + + avio_seek(s->pb, pos, SEEK_SET); + + s->io_repositioned = 1; + + return 0; +} + +static int seek_frame_generic(AVFormatContext *s, int stream_index, + int64_t timestamp, int flags) +{ + AVStream *const st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); + const AVIndexEntry *ie; + int index; + int64_t ret; + + index = av_index_search_timestamp(st, timestamp, flags); + + if (index < 0 && sti->nb_index_entries && + timestamp < sti->index_entries[0].timestamp) + return -1; + + if (index < 0 || index == sti->nb_index_entries - 1) { + AVPacket *const pkt = ffformatcontext(s)->pkt; + int nonkey = 0; + + if (sti->nb_index_entries) { + av_assert0(sti->index_entries); + ie = &sti->index_entries[sti->nb_index_entries - 1]; + if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) + return ret; + s->io_repositioned = 1; + avpriv_update_cur_dts(s, st, ie->timestamp); + } else { + if ((ret = avio_seek(s->pb, ffformatcontext(s)->data_offset, SEEK_SET)) < 0) + return ret; + s->io_repositioned = 1; + } + av_packet_unref(pkt); + for (;;) { + int read_status; + do { + read_status = av_read_frame(s, pkt); + } while (read_status == AVERROR(EAGAIN)); + if (read_status < 0) + break; + if (stream_index == pkt->stream_index && pkt->dts > timestamp) { + if (pkt->flags & AV_PKT_FLAG_KEY) { + av_packet_unref(pkt); + break; + } + if (nonkey++ > 1000 && st->codecpar->codec_id != AV_CODEC_ID_CDGRAPHICS) { + av_log(s, AV_LOG_ERROR,"seek_frame_generic failed as this stream seems to contain no keyframes after the target timestamp, %d non keyframes found\n", nonkey); + av_packet_unref(pkt); + break; + } + } + av_packet_unref(pkt); + } + index = av_index_search_timestamp(st, timestamp, flags); + } + if (index < 0) + return -1; + + ff_read_frame_flush(s); + if (s->iformat->read_seek) + if (s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0) + return 0; + ie = &sti->index_entries[index]; + if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) + return ret; + s->io_repositioned = 1; + avpriv_update_cur_dts(s, st, ie->timestamp); + + return 0; +} + +static int seek_frame_internal(AVFormatContext *s, int stream_index, + int64_t timestamp, int flags) +{ + AVStream *st; + int ret; + + if (flags & AVSEEK_FLAG_BYTE) { + if (s->iformat->flags & AVFMT_NO_BYTE_SEEK) + return -1; + ff_read_frame_flush(s); + return seek_frame_byte(s, stream_index, timestamp, flags); + } + + if (stream_index < 0) { + stream_index = av_find_default_stream_index(s); + if (stream_index < 0) + return -1; + + st = s->streams[stream_index]; + /* timestamp for default must be expressed in AV_TIME_BASE units */ + timestamp = av_rescale(timestamp, st->time_base.den, + AV_TIME_BASE * (int64_t) st->time_base.num); + } + + /* first, we try the format specific seek */ + if (s->iformat->read_seek) { + ff_read_frame_flush(s); + ret = s->iformat->read_seek(s, stream_index, timestamp, flags); + } else + ret = -1; + if (ret >= 0) + return 0; + + if (s->iformat->read_timestamp && + !(s->iformat->flags & AVFMT_NOBINSEARCH)) { + ff_read_frame_flush(s); + return ff_seek_frame_binary(s, stream_index, timestamp, flags); + } else if (!(s->iformat->flags & AVFMT_NOGENSEARCH)) { + ff_read_frame_flush(s); + return seek_frame_generic(s, stream_index, timestamp, flags); + } else + return -1; +} + +int av_seek_frame(AVFormatContext *s, int stream_index, + int64_t timestamp, int flags) +{ + int ret; + + if (s->iformat->read_seek2 && !s->iformat->read_seek) { + int64_t min_ts = INT64_MIN, max_ts = INT64_MAX; + if ((flags & AVSEEK_FLAG_BACKWARD)) + max_ts = timestamp; + else + min_ts = timestamp; + return avformat_seek_file(s, stream_index, min_ts, timestamp, max_ts, + flags & ~AVSEEK_FLAG_BACKWARD); + } + + ret = seek_frame_internal(s, stream_index, timestamp, flags); + + if (ret >= 0) + ret = avformat_queue_attached_pictures(s); + + return ret; +} + +int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, + int64_t ts, int64_t max_ts, int flags) +{ + if (min_ts > ts || max_ts < ts) + return -1; + if (stream_index < -1 || stream_index >= (int)s->nb_streams) + return AVERROR(EINVAL); + + if (s->seek2any > 0) + flags |= AVSEEK_FLAG_ANY; + flags &= ~AVSEEK_FLAG_BACKWARD; + + if (s->iformat->read_seek2) { + int ret; + ff_read_frame_flush(s); + + if (stream_index == -1 && s->nb_streams == 1) { + AVRational time_base = s->streams[0]->time_base; + ts = av_rescale_q(ts, AV_TIME_BASE_Q, time_base); + min_ts = av_rescale_rnd(min_ts, time_base.den, + time_base.num * (int64_t)AV_TIME_BASE, + AV_ROUND_UP | AV_ROUND_PASS_MINMAX); + max_ts = av_rescale_rnd(max_ts, time_base.den, + time_base.num * (int64_t)AV_TIME_BASE, + AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX); + stream_index = 0; + } + + ret = s->iformat->read_seek2(s, stream_index, min_ts, + ts, max_ts, flags); + + if (ret >= 0) + ret = avformat_queue_attached_pictures(s); + return ret; + } + + if (s->iformat->read_timestamp) { + // try to seek via read_timestamp() + } + + // Fall back on old API if new is not implemented but old is. + // Note the old API has somewhat different semantics. + if (s->iformat->read_seek || 1) { + int dir = (ts - (uint64_t)min_ts > (uint64_t)max_ts - ts ? AVSEEK_FLAG_BACKWARD : 0); + int ret = av_seek_frame(s, stream_index, ts, flags | dir); + if (ret < 0 && ts != min_ts && max_ts != ts) { + ret = av_seek_frame(s, stream_index, dir ? max_ts : min_ts, flags | dir); + if (ret >= 0) + ret = av_seek_frame(s, stream_index, ts, flags | (dir^AVSEEK_FLAG_BACKWARD)); + } + return ret; + } + + // try some generic seek like seek_frame_generic() but with new ts semantics + return -1; //unreachable +} + +/** Flush the frame reader. */ +void ff_read_frame_flush(AVFormatContext *s) +{ + ff_flush_packet_queue(s); + + /* Reset read state for each stream. */ + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; + FFStream *const sti = ffstream(st); + + if (sti->parser) { + av_parser_close(sti->parser); + sti->parser = NULL; + } + sti->last_IP_pts = AV_NOPTS_VALUE; + sti->last_dts_for_order_check = AV_NOPTS_VALUE; + if (sti->first_dts == AV_NOPTS_VALUE) + sti->cur_dts = RELATIVE_TS_BASE; + else + /* We set the current DTS to an unspecified origin. */ + sti->cur_dts = AV_NOPTS_VALUE; + + sti->probe_packets = s->max_probe_packets; + + for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) + sti->pts_buffer[j] = AV_NOPTS_VALUE; + + if (ffformatcontext(s)->inject_global_side_data) + sti->inject_global_side_data = 1; + + sti->skip_samples = 0; + } +} + +int avformat_flush(AVFormatContext *s) +{ + ff_read_frame_flush(s); + return 0; +} diff --git a/libavformat/utils.c b/libavformat/utils.c index e86cdaa96f..449c138700 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -88,19 +88,6 @@ int ff_unlock_avformat(void) return ff_mutex_unlock(&avformat_mutex) ? -1 : 0; } -#define RELATIVE_TS_BASE (INT64_MAX - (1LL<<48)) - -static int is_relative(int64_t ts) { - return ts > (RELATIVE_TS_BASE - (1LL<<48)); -} - -/** - * Wrap a given time stamp, if there is an indication for an overflow - * - * @param st stream - * @param timestamp the time stamp to wrap - * @return resulting time stamp - */ static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) { const FFStream *const sti = cffstream(st); @@ -116,6 +103,11 @@ static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) return timestamp; } +int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp) +{ + return wrap_timestamp(st, timestamp); +} + int64_t av_stream_get_end_pts(const AVStream *st) { if (cffstream(st)->priv_pts) { @@ -1767,7 +1759,7 @@ return_packet: } /* XXX: suppress the packet queue */ -static void flush_packet_queue(AVFormatContext *s) +void ff_flush_packet_queue(AVFormatContext *s) { FFFormatContext *const si = ffformatcontext(s); avpriv_packet_list_free(&si->parse_queue, &si->parse_queue_end); @@ -1777,9 +1769,6 @@ static void flush_packet_queue(AVFormatContext *s) si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; } -/*******************************************************/ -/* seek support */ - int av_find_default_stream_index(AVFormatContext *s) { int best_stream = 0; @@ -1815,726 +1804,6 @@ int av_find_default_stream_index(AVFormatContext *s) return best_stream; } -/** Flush the frame reader. */ -void ff_read_frame_flush(AVFormatContext *s) -{ - - flush_packet_queue(s); - - /* Reset read state for each stream. */ - for (unsigned i = 0; i < s->nb_streams; i++) { - AVStream *const st = s->streams[i]; - FFStream *const sti = ffstream(st); - - if (sti->parser) { - av_parser_close(sti->parser); - sti->parser = NULL; - } - sti->last_IP_pts = AV_NOPTS_VALUE; - sti->last_dts_for_order_check = AV_NOPTS_VALUE; - if (sti->first_dts == AV_NOPTS_VALUE) - sti->cur_dts = RELATIVE_TS_BASE; - else - /* We set the current DTS to an unspecified origin. */ - sti->cur_dts = AV_NOPTS_VALUE; - - sti->probe_packets = s->max_probe_packets; - - for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) - sti->pts_buffer[j] = AV_NOPTS_VALUE; - - if (ffformatcontext(s)->inject_global_side_data) - sti->inject_global_side_data = 1; - - sti->skip_samples = 0; - } -} - -void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp) -{ - for (unsigned i = 0; i < s->nb_streams; i++) { - AVStream *st = s->streams[i]; - - ffstream(st)->cur_dts = - av_rescale(timestamp, - st->time_base.den * (int64_t) ref_st->time_base.num, - st->time_base.num * (int64_t) ref_st->time_base.den); - } -} - -void ff_reduce_index(AVFormatContext *s, int stream_index) -{ - AVStream *st = s->streams[stream_index]; - FFStream *const sti = ffstream(st); - unsigned int max_entries = s->max_index_size / sizeof(AVIndexEntry); - - if ((unsigned) sti->nb_index_entries >= max_entries) { - int i; - for (i = 0; 2 * i < sti->nb_index_entries; i++) - sti->index_entries[i] = sti->index_entries[2 * i]; - sti->nb_index_entries = i; - } -} - -int ff_add_index_entry(AVIndexEntry **index_entries, - int *nb_index_entries, - unsigned int *index_entries_allocated_size, - int64_t pos, int64_t timestamp, - int size, int distance, int flags) -{ - AVIndexEntry *entries, *ie; - int index; - - if ((unsigned) *nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry)) - return -1; - - if (timestamp == AV_NOPTS_VALUE) - return AVERROR(EINVAL); - - if (size < 0 || size > 0x3FFFFFFF) - return AVERROR(EINVAL); - - if (is_relative(timestamp)) //FIXME this maintains previous behavior but we should shift by the correct offset once known - timestamp -= RELATIVE_TS_BASE; - - entries = av_fast_realloc(*index_entries, - index_entries_allocated_size, - (*nb_index_entries + 1) * - sizeof(AVIndexEntry)); - if (!entries) - return -1; - - *index_entries = entries; - - index = ff_index_search_timestamp(*index_entries, *nb_index_entries, - timestamp, AVSEEK_FLAG_ANY); - - if (index < 0) { - index = (*nb_index_entries)++; - ie = &entries[index]; - av_assert0(index == 0 || ie[-1].timestamp < timestamp); - } else { - ie = &entries[index]; - if (ie->timestamp != timestamp) { - if (ie->timestamp <= timestamp) - return -1; - memmove(entries + index + 1, entries + index, - sizeof(AVIndexEntry) * (*nb_index_entries - index)); - (*nb_index_entries)++; - } else if (ie->pos == pos && distance < ie->min_distance) - // do not reduce the distance - distance = ie->min_distance; - } - - ie->pos = pos; - ie->timestamp = timestamp; - ie->min_distance = distance; - ie->size = size; - ie->flags = flags; - - return index; -} - -int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, - int size, int distance, int flags) -{ - FFStream *const sti = ffstream(st); - timestamp = wrap_timestamp(st, timestamp); - return ff_add_index_entry(&sti->index_entries, &sti->nb_index_entries, - &sti->index_entries_allocated_size, pos, - timestamp, size, distance, flags); -} - -int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, - int64_t wanted_timestamp, int flags) -{ - int a, b, m; - int64_t timestamp; - - a = -1; - b = nb_entries; - - // Optimize appending index entries at the end. - if (b && entries[b - 1].timestamp < wanted_timestamp) - a = b - 1; - - while (b - a > 1) { - m = (a + b) >> 1; - - // Search for the next non-discarded packet. - while ((entries[m].flags & AVINDEX_DISCARD_FRAME) && m < b && m < nb_entries - 1) { - m++; - if (m == b && entries[m].timestamp >= wanted_timestamp) { - m = b - 1; - break; - } - } - - timestamp = entries[m].timestamp; - if (timestamp >= wanted_timestamp) - b = m; - if (timestamp <= wanted_timestamp) - a = m; - } - m = (flags & AVSEEK_FLAG_BACKWARD) ? a : b; - - if (!(flags & AVSEEK_FLAG_ANY)) - while (m >= 0 && m < nb_entries && - !(entries[m].flags & AVINDEX_KEYFRAME)) - m += (flags & AVSEEK_FLAG_BACKWARD) ? -1 : 1; - - if (m == nb_entries) - return -1; - return m; -} - -void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) -{ - int64_t pos_delta = 0; - int64_t skip = 0; - //We could use URLProtocol flags here but as many user applications do not use URLProtocols this would be unreliable - const char *proto = avio_find_protocol_name(s->url); - FFIOContext *ctx; - - av_assert0(time_tolerance >= 0); - - if (!proto) { - av_log(s, AV_LOG_INFO, - "Protocol name not provided, cannot determine if input is local or " - "a network protocol, buffers and access patterns cannot be configured " - "optimally without knowing the protocol\n"); - } - - if (proto && !(strcmp(proto, "file") && strcmp(proto, "pipe") && strcmp(proto, "cache"))) - return; - - for (unsigned ist1 = 0; ist1 < s->nb_streams; ist1++) { - AVStream *st1 = s->streams[ist1]; - FFStream *const sti1 = ffstream(st1); - for (unsigned ist2 = 0; ist2 < s->nb_streams; ist2++) { - AVStream *st2 = s->streams[ist2]; - FFStream *const sti2 = ffstream(st2); - - if (ist1 == ist2) - continue; - - for (int i1 = 0, i2 = 0; i1 < sti1->nb_index_entries; i1++) { - const AVIndexEntry *const e1 = &sti1->index_entries[i1]; - int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q); - - skip = FFMAX(skip, e1->size); - for (; i2 < sti2->nb_index_entries; i2++) { - const AVIndexEntry *const e2 = &sti2->index_entries[i2]; - int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q); - if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance) - continue; - pos_delta = FFMAX(pos_delta, e1->pos - e2->pos); - break; - } - } - } - } - - pos_delta *= 2; - ctx = ffiocontext(s->pb); - /* XXX This could be adjusted depending on protocol*/ - if (s->pb->buffer_size < pos_delta && pos_delta < (1<<24)) { - av_log(s, AV_LOG_VERBOSE, "Reconfiguring buffers to size %"PRId64"\n", pos_delta); - - /* realloc the buffer and the original data will be retained */ - if (ffio_realloc_buf(s->pb, pos_delta)) { - av_log(s, AV_LOG_ERROR, "Realloc buffer fail.\n"); - return; - } - - ctx->short_seek_threshold = FFMAX(ctx->short_seek_threshold, pos_delta/2); - } - - if (skip < (1<<23)) { - ctx->short_seek_threshold = FFMAX(ctx->short_seek_threshold, skip); - } -} - -int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) -{ - FFStream *const sti = ffstream(st); - return ff_index_search_timestamp(sti->index_entries, sti->nb_index_entries, - wanted_timestamp, flags); -} - -int avformat_index_get_entries_count(const AVStream *st) -{ - return cffstream(st)->nb_index_entries; -} - -const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx) -{ - const FFStream *const sti = ffstream(st); - if (idx < 0 || idx >= sti->nb_index_entries) - return NULL; - - return &sti->index_entries[idx]; -} - -const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st, - int64_t wanted_timestamp, - int flags) -{ - const FFStream *const sti = ffstream(st); - int idx = ff_index_search_timestamp(sti->index_entries, - sti->nb_index_entries, - wanted_timestamp, flags); - - if (idx < 0) - return NULL; - - return &sti->index_entries[idx]; -} - -static int64_t ff_read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit, - int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )) -{ - int64_t ts = read_timestamp(s, stream_index, ppos, pos_limit); - if (stream_index >= 0) - ts = wrap_timestamp(s->streams[stream_index], ts); - return ts; -} - -int ff_seek_frame_binary(AVFormatContext *s, int stream_index, - int64_t target_ts, int flags) -{ - const AVInputFormat *avif = s->iformat; - int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit; - int64_t ts_min, ts_max, ts; - int index; - int64_t ret; - AVStream *st; - FFStream *sti; - - if (stream_index < 0) - return -1; - - av_log(s, AV_LOG_TRACE, "read_seek: %d %s\n", stream_index, av_ts2str(target_ts)); - - ts_max = - ts_min = AV_NOPTS_VALUE; - pos_limit = -1; // GCC falsely says it may be uninitialized. - - st = s->streams[stream_index]; - sti = ffstream(st); - if (sti->index_entries) { - AVIndexEntry *e; - - /* FIXME: Whole function must be checked for non-keyframe entries in - * index case, especially read_timestamp(). */ - index = av_index_search_timestamp(st, target_ts, - flags | AVSEEK_FLAG_BACKWARD); - index = FFMAX(index, 0); - e = &sti->index_entries[index]; - - if (e->timestamp <= target_ts || e->pos == e->min_distance) { - pos_min = e->pos; - ts_min = e->timestamp; - av_log(s, AV_LOG_TRACE, "using cached pos_min=0x%"PRIx64" dts_min=%s\n", - pos_min, av_ts2str(ts_min)); - } else { - av_assert1(index == 0); - } - - index = av_index_search_timestamp(st, target_ts, - flags & ~AVSEEK_FLAG_BACKWARD); - av_assert0(index < sti->nb_index_entries); - if (index >= 0) { - e = &sti->index_entries[index]; - av_assert1(e->timestamp >= target_ts); - pos_max = e->pos; - ts_max = e->timestamp; - pos_limit = pos_max - e->min_distance; - av_log(s, AV_LOG_TRACE, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64 - " dts_max=%s\n", pos_max, pos_limit, av_ts2str(ts_max)); - } - } - - pos = ff_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, - ts_min, ts_max, flags, &ts, avif->read_timestamp); - if (pos < 0) - return -1; - - /* do the seek */ - if ((ret = avio_seek(s->pb, pos, SEEK_SET)) < 0) - return ret; - - ff_read_frame_flush(s); - avpriv_update_cur_dts(s, st, ts); - - return 0; -} - -int ff_find_last_ts(AVFormatContext *s, int stream_index, int64_t *ts, int64_t *pos, - int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )) -{ - int64_t step = 1024; - int64_t limit, ts_max; - int64_t filesize = avio_size(s->pb); - int64_t pos_max = filesize - 1; - do { - limit = pos_max; - pos_max = FFMAX(0, (pos_max) - step); - ts_max = ff_read_timestamp(s, stream_index, - &pos_max, limit, read_timestamp); - step += step; - } while (ts_max == AV_NOPTS_VALUE && 2*limit > step); - if (ts_max == AV_NOPTS_VALUE) - return -1; - - for (;;) { - int64_t tmp_pos = pos_max + 1; - int64_t tmp_ts = ff_read_timestamp(s, stream_index, - &tmp_pos, INT64_MAX, read_timestamp); - if (tmp_ts == AV_NOPTS_VALUE) - break; - av_assert0(tmp_pos > pos_max); - ts_max = tmp_ts; - pos_max = tmp_pos; - if (tmp_pos >= filesize) - break; - } - - if (ts) - *ts = ts_max; - if (pos) - *pos = pos_max; - - return 0; -} - -int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, - int64_t pos_min, int64_t pos_max, int64_t pos_limit, - int64_t ts_min, int64_t ts_max, - int flags, int64_t *ts_ret, - int64_t (*read_timestamp)(struct AVFormatContext *, int, - int64_t *, int64_t)) -{ - int64_t pos, ts; - int64_t start_pos; - int no_change; - int ret; - - av_log(s, AV_LOG_TRACE, "gen_seek: %d %s\n", stream_index, av_ts2str(target_ts)); - - if (ts_min == AV_NOPTS_VALUE) { - pos_min = ffformatcontext(s)->data_offset; - ts_min = ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp); - if (ts_min == AV_NOPTS_VALUE) - return -1; - } - - if (ts_min >= target_ts) { - *ts_ret = ts_min; - return pos_min; - } - - if (ts_max == AV_NOPTS_VALUE) { - if ((ret = ff_find_last_ts(s, stream_index, &ts_max, &pos_max, read_timestamp)) < 0) - return ret; - pos_limit = pos_max; - } - - if (ts_max <= target_ts) { - *ts_ret = ts_max; - return pos_max; - } - - av_assert0(ts_min < ts_max); - - no_change = 0; - while (pos_min < pos_limit) { - av_log(s, AV_LOG_TRACE, - "pos_min=0x%"PRIx64" pos_max=0x%"PRIx64" dts_min=%s dts_max=%s\n", - pos_min, pos_max, av_ts2str(ts_min), av_ts2str(ts_max)); - av_assert0(pos_limit <= pos_max); - - if (no_change == 0) { - int64_t approximate_keyframe_distance = pos_max - pos_limit; - // interpolate position (better than dichotomy) - pos = av_rescale(target_ts - ts_min, pos_max - pos_min, - ts_max - ts_min) + - pos_min - approximate_keyframe_distance; - } else if (no_change == 1) { - // bisection if interpolation did not change min / max pos last time - pos = (pos_min + pos_limit) >> 1; - } else { - /* linear search if bisection failed, can only happen if there - * are very few or no keyframes between min/max */ - pos = pos_min; - } - if (pos <= pos_min) - pos = pos_min + 1; - else if (pos > pos_limit) - pos = pos_limit; - start_pos = pos; - - // May pass pos_limit instead of -1. - ts = ff_read_timestamp(s, stream_index, &pos, INT64_MAX, read_timestamp); - if (pos == pos_max) - no_change++; - else - no_change = 0; - av_log(s, AV_LOG_TRACE, "%"PRId64" %"PRId64" %"PRId64" / %s %s %s" - " target:%s limit:%"PRId64" start:%"PRId64" noc:%d\n", - pos_min, pos, pos_max, - av_ts2str(ts_min), av_ts2str(ts), av_ts2str(ts_max), av_ts2str(target_ts), - pos_limit, start_pos, no_change); - if (ts == AV_NOPTS_VALUE) { - av_log(s, AV_LOG_ERROR, "read_timestamp() failed in the middle\n"); - return -1; - } - if (target_ts <= ts) { - pos_limit = start_pos - 1; - pos_max = pos; - ts_max = ts; - } - if (target_ts >= ts) { - pos_min = pos; - ts_min = ts; - } - } - - pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; - ts = (flags & AVSEEK_FLAG_BACKWARD) ? ts_min : ts_max; -#if 0 - pos_min = pos; - ts_min = ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp); - pos_min++; - ts_max = ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp); - av_log(s, AV_LOG_TRACE, "pos=0x%"PRIx64" %s<=%s<=%s\n", - pos, av_ts2str(ts_min), av_ts2str(target_ts), av_ts2str(ts_max)); -#endif - *ts_ret = ts; - return pos; -} - -static int seek_frame_byte(AVFormatContext *s, int stream_index, - int64_t pos, int flags) -{ - int64_t pos_min, pos_max; - - pos_min = ffformatcontext(s)->data_offset; - pos_max = avio_size(s->pb) - 1; - - if (pos < pos_min) - pos = pos_min; - else if (pos > pos_max) - pos = pos_max; - - avio_seek(s->pb, pos, SEEK_SET); - - s->io_repositioned = 1; - - return 0; -} - -static int seek_frame_generic(AVFormatContext *s, int stream_index, - int64_t timestamp, int flags) -{ - AVStream *const st = s->streams[stream_index]; - FFStream *const sti = ffstream(st); - int index; - int64_t ret; - AVIndexEntry *ie; - - - index = av_index_search_timestamp(st, timestamp, flags); - - if (index < 0 && sti->nb_index_entries && - timestamp < sti->index_entries[0].timestamp) - return -1; - - if (index < 0 || index == sti->nb_index_entries - 1) { - AVPacket *pkt = ffformatcontext(s)->pkt; - int nonkey = 0; - - if (sti->nb_index_entries) { - av_assert0(sti->index_entries); - ie = &sti->index_entries[sti->nb_index_entries - 1]; - if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) - return ret; - s->io_repositioned = 1; - avpriv_update_cur_dts(s, st, ie->timestamp); - } else { - if ((ret = avio_seek(s->pb, ffformatcontext(s)->data_offset, SEEK_SET)) < 0) - return ret; - s->io_repositioned = 1; - } - av_packet_unref(pkt); - for (;;) { - int read_status; - do { - read_status = av_read_frame(s, pkt); - } while (read_status == AVERROR(EAGAIN)); - if (read_status < 0) - break; - if (stream_index == pkt->stream_index && pkt->dts > timestamp) { - if (pkt->flags & AV_PKT_FLAG_KEY) { - av_packet_unref(pkt); - break; - } - if (nonkey++ > 1000 && st->codecpar->codec_id != AV_CODEC_ID_CDGRAPHICS) { - av_log(s, AV_LOG_ERROR,"seek_frame_generic failed as this stream seems to contain no keyframes after the target timestamp, %d non keyframes found\n", nonkey); - av_packet_unref(pkt); - break; - } - } - av_packet_unref(pkt); - } - index = av_index_search_timestamp(st, timestamp, flags); - } - if (index < 0) - return -1; - - ff_read_frame_flush(s); - if (s->iformat->read_seek) - if (s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0) - return 0; - ie = &sti->index_entries[index]; - if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) - return ret; - s->io_repositioned = 1; - avpriv_update_cur_dts(s, st, ie->timestamp); - - return 0; -} - -static int seek_frame_internal(AVFormatContext *s, int stream_index, - int64_t timestamp, int flags) -{ - int ret; - AVStream *st; - - if (flags & AVSEEK_FLAG_BYTE) { - if (s->iformat->flags & AVFMT_NO_BYTE_SEEK) - return -1; - ff_read_frame_flush(s); - return seek_frame_byte(s, stream_index, timestamp, flags); - } - - if (stream_index < 0) { - stream_index = av_find_default_stream_index(s); - if (stream_index < 0) - return -1; - - st = s->streams[stream_index]; - /* timestamp for default must be expressed in AV_TIME_BASE units */ - timestamp = av_rescale(timestamp, st->time_base.den, - AV_TIME_BASE * (int64_t) st->time_base.num); - } - - /* first, we try the format specific seek */ - if (s->iformat->read_seek) { - ff_read_frame_flush(s); - ret = s->iformat->read_seek(s, stream_index, timestamp, flags); - } else - ret = -1; - if (ret >= 0) - return 0; - - if (s->iformat->read_timestamp && - !(s->iformat->flags & AVFMT_NOBINSEARCH)) { - ff_read_frame_flush(s); - return ff_seek_frame_binary(s, stream_index, timestamp, flags); - } else if (!(s->iformat->flags & AVFMT_NOGENSEARCH)) { - ff_read_frame_flush(s); - return seek_frame_generic(s, stream_index, timestamp, flags); - } else - return -1; -} - -int av_seek_frame(AVFormatContext *s, int stream_index, - int64_t timestamp, int flags) -{ - int ret; - - if (s->iformat->read_seek2 && !s->iformat->read_seek) { - int64_t min_ts = INT64_MIN, max_ts = INT64_MAX; - if ((flags & AVSEEK_FLAG_BACKWARD)) - max_ts = timestamp; - else - min_ts = timestamp; - return avformat_seek_file(s, stream_index, min_ts, timestamp, max_ts, - flags & ~AVSEEK_FLAG_BACKWARD); - } - - ret = seek_frame_internal(s, stream_index, timestamp, flags); - - if (ret >= 0) - ret = avformat_queue_attached_pictures(s); - - return ret; -} - -int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, - int64_t ts, int64_t max_ts, int flags) -{ - if (min_ts > ts || max_ts < ts) - return -1; - if (stream_index < -1 || stream_index >= (int)s->nb_streams) - return AVERROR(EINVAL); - - if (s->seek2any>0) - flags |= AVSEEK_FLAG_ANY; - flags &= ~AVSEEK_FLAG_BACKWARD; - - if (s->iformat->read_seek2) { - int ret; - ff_read_frame_flush(s); - - if (stream_index == -1 && s->nb_streams == 1) { - AVRational time_base = s->streams[0]->time_base; - ts = av_rescale_q(ts, AV_TIME_BASE_Q, time_base); - min_ts = av_rescale_rnd(min_ts, time_base.den, - time_base.num * (int64_t)AV_TIME_BASE, - AV_ROUND_UP | AV_ROUND_PASS_MINMAX); - max_ts = av_rescale_rnd(max_ts, time_base.den, - time_base.num * (int64_t)AV_TIME_BASE, - AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX); - stream_index = 0; - } - - ret = s->iformat->read_seek2(s, stream_index, min_ts, - ts, max_ts, flags); - - if (ret >= 0) - ret = avformat_queue_attached_pictures(s); - return ret; - } - - if (s->iformat->read_timestamp) { - // try to seek via read_timestamp() - } - - // Fall back on old API if new is not implemented but old is. - // Note the old API has somewhat different semantics. - if (s->iformat->read_seek || 1) { - int dir = (ts - (uint64_t)min_ts > (uint64_t)max_ts - ts ? AVSEEK_FLAG_BACKWARD : 0); - int ret = av_seek_frame(s, stream_index, ts, flags | dir); - if (ret<0 && ts != min_ts && max_ts != ts) { - ret = av_seek_frame(s, stream_index, dir ? max_ts : min_ts, flags | dir); - if (ret >= 0) - ret = av_seek_frame(s, stream_index, ts, flags | (dir^AVSEEK_FLAG_BACKWARD)); - } - return ret; - } - - // try some generic seek like seek_frame_generic() but with new ts semantics - return -1; //unreachable -} - -int avformat_flush(AVFormatContext *s) -{ - ff_read_frame_flush(s); - return 0; -} - /*******************************************************/ /** @@ -2736,7 +2005,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) int retry = 0; /* flush packet queue */ - flush_packet_queue(ic); + ff_flush_packet_queue(ic); for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; @@ -4343,7 +3612,7 @@ void avformat_free_context(AVFormatContext *s) av_packet_free(&si->pkt); av_packet_free(&si->parse_pkt); av_freep(&s->streams); - flush_packet_queue(s); + ff_flush_packet_queue(s); av_freep(&s->url); av_free(s); } From patchwork Fri Aug 27 14:27:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29822 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1515623iov; Fri, 27 Aug 2021 07:32:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwu7WVE1BsHBN4NVHxIv784qatwjFbcVnzjCqzHRefPtda+m9/b8bdkB7fg1IQoF4YzK/oR X-Received: by 2002:a17:907:75d0:: with SMTP id jl16mr10687211ejc.166.1630074747459; Fri, 27 Aug 2021 07:32:27 -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 a20si8675116edj.204.2021.08.27.07.32.27; Fri, 27 Aug 2021 07:32:27 -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=Cr2aHiER; 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 9D5F568A61E; Fri, 27 Aug 2021 17:28:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (unknown [40.92.67.13]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AF1A968A447 for ; Fri, 27 Aug 2021 17:28:13 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XPG4QcYK91OtnCVsnsyY8AsmMFKXfCQ4YfTjOvlSvc2r0XiWPfgJGZKcRKFEcegW2BEOEm8qBZPTIfUHvXVk/oBanyluIGcGs6t6kE2R9kUyrYzVtcbTjcH48H6RLep7vAzYNlCcc8+2lthpcHJNJPpOf6aRhIX0qsQ5ljfTvCOQ1AnzDFPuT4xaEKG6o4ERmolakDfgvMkn89ANSJ4sxfq78ygi9BNsc3ndKqd9OOHi+ahUjFXDTSxgvUvN6j8+em9BOOmz0lvux7cexO4+J1pzIDAZW2U1OItJ7wP8yDJMShUfdTXxUvLCl6nIqj9KXoo7nPJaIAzmU+wcW5P3Gg== 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=lY7BxHv0BQ18X6Eha8T2VTc0+FWkjKnCbTk41GXBDe0=; b=BSpFwD1BLsp0yNy2jsSWtvYUBG/JG+e3M8WUETCx32yuhRfXMh6HKdd9SSSyqKsgfnxaznTWBdfpuynqxPFF4kYtY8ODJ0oejTNhCYBawV5vX/1wlCmPSTHKymARvXTt/ee1CE81xeOT4Aw0TxMIvS4hT50uuRqNOiuC31ECNeXYgRjYhIUqRQlMBFt/MddYm5k6+Dumfprcbti9rz9tepmlOFmBQQrgc3WvSsxiL2qJAA8/zhm3TEMWhJPCQ6Q4Q45n7sdHSDoOCfra99saA+DCoEUytnjbAyehMQgDQ8YAxdMOwlYcPt/xdYBi0C7RjYLMwJMIUAvFnrlonu3T/w== 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=lY7BxHv0BQ18X6Eha8T2VTc0+FWkjKnCbTk41GXBDe0=; b=Cr2aHiERyZxf8McFgiMzU/NMG+a44ZmR9sHED8nn0qdWd91WqtRIdGkqL4+9YxG3basCN4KWuVU2XB9nRPvWKpiLtXj3wYmpHFl7ff9moKmVAKPVcMvZR4Q/0WNHVcXvHAzBm19n5ueuMGB1ZYn+bZXTGt7Fgv1OzsYgdLsTRJYX7XRBwDRKdNzY2CCE70CrJT3btbnuhWqhkqCXta4ZkpeZA72iswSCu8XytSQxhhaWdthaxHbN5nkUMxGnZ1aPEIb7Fwy1pjdMS93YH2EYoHeaZ+SDy4mzH0EGSVP7oQn3bBautYSjfr2Lvy+bJVt9TOvP55mBCDPKq6HyEFKKwA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3861.eurprd03.prod.outlook.com (2603:10a6:20b:22::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Fri, 27 Aug 2021 14:28:09 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:28:09 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:25 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [NilFkuI0TItBz0W6f7wenkitSzfL4aEM] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-24-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:28:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cca8071b-c3fa-4660-a67d-08d96966e427 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/72eCuh5zF259iqhWU0sX3iUbKGK90PNgFqofOeEQrhlrNxVaETcPv/ay8fKesj1LZSK45D3UQ8RyoszM78js9iESb/L3Xy0axVAxOu7l8TBUptFdBdCq2JbhKoI2IqhCxcQusW9sRdc4EU38jWINnHjuvP5taWfrZMMm5LNls6cCLFcpAn4zauPtYYK2giEAuS7IxMf+2KQhkbJWtTZZsG+BRcQwzxs28ZV5ftqNIV2Vw/jop8TEM8saVC5JxZVKpLMQ2za7YUSrSg7mbpSh1WzGwYco3617krnL69a5IKUSdfr3sqC+EwMTAcNbHTLlU/SLkoSOszcF7enXAcRgWeiaYPfi0aEa+IXmLehqFcmMEENfm4Q0OEFJ3RxKuViAvqzgiQGUCGHjkmQHbm5XHw8cVsC+lK22IGOWWIZB/PPPIf30bNRQ4SjD05jDGCEvaTQQk1OBQRuAfu3ZgYOb831xFtoeqpj6cs54Vh/nOh6/w/erPq98y5sY7WojmqrpuilggLNRU8LkY/x535LVNd8uFJoDlJ55dpmB5EPuuv0Z+djGZPFIe6zq/xBYMu6Hh0/OEKZ7TX3Rg0H2X34536d1Ja6tbHl4X1MyrMqJVhLrTPmccbSZvYpjXuxKLASsQAMpCIpM9m45P32PkShPQ4gRrnsZOpYXJ7OBw5x9MyJ2yywOYtn8C0RtqFL5TstjOnWilRp5dF9deX/J1Hp/J9LTCMgq+mgMbDyhM9I/7a2k= X-MS-TrafficTypeDiagnostic: AM6PR03MB3861: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sjXrUBYGXclIrnjIOwQBvPAGra7v1ttEkeTgY7m5/9fRla6+P6Vhk2lfIVJuFJ+Xi1Hz0v6j0PbK4sfw9ooII4UqApzykfc2yb8j4Kk9C2Bh+hpjh7k5S1zdQf6rx5Fv0XFCcOpKdWktrvWrwHPnq+UmktcFeD8NjHTiWPXeAo0EBFZcyjhEj8RPp8Xwg3hgBgcc09WH3i5Xo66ALSe0sWqR6lPfH4EpHTIpN01HYiijZ0n/nqZiFYLinO/QkTG7uE30m009YbBEFFP8EQXjieAhiS9rORLX4EkvwCVa59KcYM1rY9NrS45rZKMR1pUlqejGsIM9Ym2g8rtMnjl/K7V18JpdgG7Mcfgd65gnXpsPUz75tEs+RqOvpfuhHGy9ruWphmj2ES9GAn5Z4uPGiJ5sZz8JT+eSaQi1lk1cksktbAY3/juWd+cQRrbN7dUA X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U8SAxyRe9b4F89T2lzcrVQNSuYhoIliaH8wh7khjvaCEoBAB7mW88RlnJ/r18wfFSP3npmoRUcSIA8CBjDe71DH/3s8xev2q4b4oaCQv00c/RPvyWFR0yE6QIDRC18u904dmd6we3jNjNtvMyFMlLg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cca8071b-c3fa-4660-a67d-08d96966e427 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:28:09.2786 (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: AM6PR03MB3861 Subject: [FFmpeg-devel] [PATCH 25/25] avformat/utils: Move demuxing code out into a new file 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: Mt03IUKtTSaR libavformat/utils.c has over 4800 lines and is supposed to contain "various utility functions for use within FFmpeg". In reality it contains all that and the whole demuxing core of libavformat. This is especially bad, because said file includes the FFMPEG_VERSION (the git commit sha) so that it is rebuilt whenever the commit HEAD points to changes. Therefore this commit makes it smaller by moving the demuxing code out to a new file, demux.c (in analogy to mux.c for the muxing code). Signed-off-by: Andreas Rheinhardt --- One could also move the avformat_find_stream_info() stuff into a file of their own. IIRC this necessitates making three more functions unstatic. libavformat/Makefile | 1 + libavformat/demux.c | 2953 ++++++++++++++++++++++++++++++++++++ libavformat/internal.h | 2 + libavformat/utils.c | 3238 ++-------------------------------------- 4 files changed, 3113 insertions(+), 3081 deletions(-) create mode 100644 libavformat/demux.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 52e1dab66d..e6c4caf4d0 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -8,6 +8,7 @@ HEADERS = avformat.h \ OBJS = allformats.o \ avio.o \ aviobuf.o \ + demux.o \ dump.o \ format.o \ id3v1.o \ diff --git a/libavformat/demux.c b/libavformat/demux.c new file mode 100644 index 0000000000..559dd10f57 --- /dev/null +++ b/libavformat/demux.c @@ -0,0 +1,2953 @@ +/* + * Core demuxing component + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "config.h" + +#include "libavutil/avassert.h" +#include "libavutil/avstring.h" +#include "libavutil/dict.h" +#include "libavutil/internal.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/mathematics.h" +#include "libavutil/opt.h" +#include "libavutil/pixfmt.h" +#include "libavutil/time.h" +#include "libavutil/timestamp.h" + +#include "libavcodec/bsf.h" +#include "libavcodec/internal.h" +#include "libavcodec/packet_internal.h" +#include "libavcodec/raw.h" + +#include "avformat.h" +#include "avio_internal.h" +#include "id3v2.h" +#include "internal.h" +#include "url.h" + +static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) +{ + const FFStream *const sti = cffstream(st); + if (sti->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 && + sti->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { + if (sti->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && + timestamp < sti->pts_wrap_reference) + return timestamp + (1ULL << st->pts_wrap_bits); + else if (sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && + timestamp >= sti->pts_wrap_reference) + return timestamp - (1ULL << st->pts_wrap_bits); + } + return timestamp; +} + +int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp) +{ + return wrap_timestamp(st, timestamp); +} + +static const AVCodec *find_probe_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id) +{ + const AVCodec *codec; + +#if CONFIG_H264_DECODER + /* Other parts of the code assume this decoder to be used for h264, + * so force it if possible. */ + if (codec_id == AV_CODEC_ID_H264) + return avcodec_find_decoder_by_name("h264"); +#endif + + codec = ff_find_decoder(s, st, codec_id); + if (!codec) + return NULL; + + if (codec->capabilities & AV_CODEC_CAP_AVOID_PROBING) { + const AVCodec *probe_codec = NULL; + void *iter = NULL; + while ((probe_codec = av_codec_iterate(&iter))) { + if (probe_codec->id == codec->id && + av_codec_is_decoder(probe_codec) && + !(probe_codec->capabilities & (AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_EXPERIMENTAL))) { + return probe_codec; + } + } + } + + return codec; +} + +static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, + AVProbeData *pd) +{ + static const struct { + const char *name; + enum AVCodecID id; + enum AVMediaType type; + } fmt_id_type[] = { + { "aac", AV_CODEC_ID_AAC, AVMEDIA_TYPE_AUDIO }, + { "ac3", AV_CODEC_ID_AC3, AVMEDIA_TYPE_AUDIO }, + { "aptx", AV_CODEC_ID_APTX, AVMEDIA_TYPE_AUDIO }, + { "dts", AV_CODEC_ID_DTS, AVMEDIA_TYPE_AUDIO }, + { "dvbsub", AV_CODEC_ID_DVB_SUBTITLE,AVMEDIA_TYPE_SUBTITLE }, + { "dvbtxt", AV_CODEC_ID_DVB_TELETEXT,AVMEDIA_TYPE_SUBTITLE }, + { "eac3", AV_CODEC_ID_EAC3, AVMEDIA_TYPE_AUDIO }, + { "h264", AV_CODEC_ID_H264, AVMEDIA_TYPE_VIDEO }, + { "hevc", AV_CODEC_ID_HEVC, AVMEDIA_TYPE_VIDEO }, + { "loas", AV_CODEC_ID_AAC_LATM, AVMEDIA_TYPE_AUDIO }, + { "m4v", AV_CODEC_ID_MPEG4, AVMEDIA_TYPE_VIDEO }, + { "mjpeg_2000",AV_CODEC_ID_JPEG2000, AVMEDIA_TYPE_VIDEO }, + { "mp3", AV_CODEC_ID_MP3, AVMEDIA_TYPE_AUDIO }, + { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO }, + { "truehd", AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO }, + { 0 } + }; + int score; + const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); + + if (fmt) { + FFStream *const sti = ffstream(st); + av_log(s, AV_LOG_DEBUG, + "Probe with size=%d, packets=%d detected %s with score=%d\n", + pd->buf_size, s->max_probe_packets - sti->probe_packets, + fmt->name, score); + for (int i = 0; fmt_id_type[i].name; i++) { + if (!strcmp(fmt->name, fmt_id_type[i].name)) { + if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO && + st->codecpar->sample_rate) + continue; + if (sti->request_probe > score && + st->codecpar->codec_id != fmt_id_type[i].id) + continue; + st->codecpar->codec_id = fmt_id_type[i].id; + st->codecpar->codec_type = fmt_id_type[i].type; + sti->need_context_update = 1; + return score; + } + } + } + return 0; +} + +static int init_input(AVFormatContext *s, const char *filename, + AVDictionary **options) +{ + int ret; + AVProbeData pd = { filename, NULL, 0 }; + int score = AVPROBE_SCORE_RETRY; + + if (s->pb) { + s->flags |= AVFMT_FLAG_CUSTOM_IO; + if (!s->iformat) + return av_probe_input_buffer2(s->pb, &s->iformat, filename, + s, 0, s->format_probesize); + else if (s->iformat->flags & AVFMT_NOFILE) + av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and " + "will be ignored with AVFMT_NOFILE format.\n"); + return 0; + } + + if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) || + (!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score)))) + return score; + + if ((ret = s->io_open(s, &s->pb, filename, AVIO_FLAG_READ | s->avio_flags, options)) < 0) + return ret; + + if (s->iformat) + return 0; + return av_probe_input_buffer2(s->pb, &s->iformat, filename, + s, 0, s->format_probesize); +} + +static int update_stream_avctx(AVFormatContext *s) +{ + int ret; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; + FFStream *const sti = ffstream(st); + + if (!sti->need_context_update) + continue; + + /* close parser, because it depends on the codec */ + if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { + av_parser_close(sti->parser); + sti->parser = NULL; + } + + /* update internal codec context, for the parser */ + ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); + if (ret < 0) + return ret; + + sti->need_context_update = 0; + } + return 0; +} + +int avformat_open_input(AVFormatContext **ps, const char *filename, + const AVInputFormat *fmt, AVDictionary **options) +{ + AVFormatContext *s = *ps; + FFFormatContext *si; + AVDictionary *tmp = NULL; + ID3v2ExtraMeta *id3v2_extra_meta = NULL; + int ret = 0; + + if (!s && !(s = avformat_alloc_context())) + return AVERROR(ENOMEM); + si = ffformatcontext(s); + if (!s->av_class) { + av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); + return AVERROR(EINVAL); + } + if (fmt) + s->iformat = fmt; + + if (options) + av_dict_copy(&tmp, *options, 0); + + if (s->pb) // must be before any goto fail + s->flags |= AVFMT_FLAG_CUSTOM_IO; + + if ((ret = av_opt_set_dict(s, &tmp)) < 0) + goto fail; + + if (!(s->url = av_strdup(filename ? filename : ""))) { + ret = AVERROR(ENOMEM); + goto fail; + } + + if ((ret = init_input(s, filename, &tmp)) < 0) + goto fail; + s->probe_score = ret; + + if (!s->protocol_whitelist && s->pb && s->pb->protocol_whitelist) { + s->protocol_whitelist = av_strdup(s->pb->protocol_whitelist); + if (!s->protocol_whitelist) { + ret = AVERROR(ENOMEM); + goto fail; + } + } + + if (!s->protocol_blacklist && s->pb && s->pb->protocol_blacklist) { + s->protocol_blacklist = av_strdup(s->pb->protocol_blacklist); + if (!s->protocol_blacklist) { + ret = AVERROR(ENOMEM); + goto fail; + } + } + + if (s->format_whitelist && av_match_list(s->iformat->name, s->format_whitelist, ',') <= 0) { + av_log(s, AV_LOG_ERROR, "Format not on whitelist \'%s\'\n", s->format_whitelist); + ret = AVERROR(EINVAL); + goto fail; + } + + avio_skip(s->pb, s->skip_initial_bytes); + + /* Check filename in case an image number is expected. */ + if (s->iformat->flags & AVFMT_NEEDNUMBER) { + if (!av_filename_number_test(filename)) { + ret = AVERROR(EINVAL); + goto fail; + } + } + + s->duration = s->start_time = AV_NOPTS_VALUE; + + /* Allocate private data. */ + if (s->iformat->priv_data_size > 0) { + if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) { + ret = AVERROR(ENOMEM); + goto fail; + } + if (s->iformat->priv_class) { + *(const AVClass **) s->priv_data = s->iformat->priv_class; + av_opt_set_defaults(s->priv_data); + if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) + goto fail; + } + } + + /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */ + if (s->pb) + ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); + + if (s->iformat->read_header) + if ((ret = s->iformat->read_header(s)) < 0) { + if (s->iformat->flags_internal & FF_FMT_INIT_CLEANUP) + goto close; + goto fail; + } + + if (!s->metadata) { + s->metadata = si->id3v2_meta; + si->id3v2_meta = NULL; + } else if (si->id3v2_meta) { + av_log(s, AV_LOG_WARNING, "Discarding ID3 tags because more suitable tags were found.\n"); + av_dict_free(&si->id3v2_meta); + } + + if (id3v2_extra_meta) { + if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name, "aac") || + !strcmp(s->iformat->name, "tta") || !strcmp(s->iformat->name, "wav")) { + if ((ret = ff_id3v2_parse_apic(s, id3v2_extra_meta)) < 0) + goto close; + if ((ret = ff_id3v2_parse_chapters(s, id3v2_extra_meta)) < 0) + goto close; + if ((ret = ff_id3v2_parse_priv(s, id3v2_extra_meta)) < 0) + goto close; + } else + av_log(s, AV_LOG_DEBUG, "demuxer does not support additional id3 data, skipping\n"); + } + ff_id3v2_free_extra_meta(&id3v2_extra_meta); + + if ((ret = avformat_queue_attached_pictures(s)) < 0) + goto close; + + if (s->pb && !si->data_offset) + si->data_offset = avio_tell(s->pb); + + si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; + + update_stream_avctx(s); + + if (options) { + av_dict_free(options); + *options = tmp; + } + *ps = s; + return 0; + +close: + if (s->iformat->read_close) + s->iformat->read_close(s); +fail: + ff_id3v2_free_extra_meta(&id3v2_extra_meta); + av_dict_free(&tmp); + if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO)) + avio_closep(&s->pb); + avformat_free_context(s); + *ps = NULL; + return ret; +} + +void avformat_close_input(AVFormatContext **ps) +{ + AVFormatContext *s; + AVIOContext *pb; + + if (!ps || !*ps) + return; + + s = *ps; + pb = s->pb; + + if ((s->iformat && strcmp(s->iformat->name, "image2") && s->iformat->flags & AVFMT_NOFILE) || + (s->flags & AVFMT_FLAG_CUSTOM_IO)) + pb = NULL; + + if (s->iformat) + if (s->iformat->read_close) + s->iformat->read_close(s); + + avformat_free_context(s); + + *ps = NULL; + + avio_close(pb); +} + +static void force_codec_ids(AVFormatContext *s, AVStream *st) +{ + switch (st->codecpar->codec_type) { + case AVMEDIA_TYPE_VIDEO: + if (s->video_codec_id) + st->codecpar->codec_id = s->video_codec_id; + break; + case AVMEDIA_TYPE_AUDIO: + if (s->audio_codec_id) + st->codecpar->codec_id = s->audio_codec_id; + break; + case AVMEDIA_TYPE_SUBTITLE: + if (s->subtitle_codec_id) + st->codecpar->codec_id = s->subtitle_codec_id; + break; + case AVMEDIA_TYPE_DATA: + if (s->data_codec_id) + st->codecpar->codec_id = s->data_codec_id; + break; + } +} + +static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) +{ + FFStream *const sti = ffstream(st); + if (sti->request_probe > 0) { + AVProbeData *const pd = &sti->probe_data; + int end; + av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, sti->probe_packets); + --sti->probe_packets; + + if (pkt) { + uint8_t *new_buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); + if (!new_buf) { + av_log(s, AV_LOG_WARNING, + "Failed to reallocate probe buffer for stream %d\n", + st->index); + goto no_packet; + } + pd->buf = new_buf; + memcpy(pd->buf + pd->buf_size, pkt->data, pkt->size); + pd->buf_size += pkt->size; + memset(pd->buf + pd->buf_size, 0, AVPROBE_PADDING_SIZE); + } else { +no_packet: + sti->probe_packets = 0; + if (!pd->buf_size) { + av_log(s, AV_LOG_WARNING, + "nothing to probe for stream %d\n", st->index); + } + } + + end = ffformatcontext(s)->raw_packet_buffer_remaining_size <= 0 + || sti->probe_packets<= 0; + + if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { + int score = set_codec_from_probe_data(s, st, pd); + if ( (st->codecpar->codec_id != AV_CODEC_ID_NONE && score > AVPROBE_SCORE_STREAM_RETRY) + || end) { + pd->buf_size = 0; + av_freep(&pd->buf); + sti->request_probe = -1; + if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { + av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); + } else + av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index); + } + force_codec_ids(s, st); + } + } + return 0; +} + +static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) +{ + FFStream *const sti = ffstream(st); + int64_t ref = pkt->dts; + int pts_wrap_behavior; + int64_t pts_wrap_reference; + AVProgram *first_program; + + if (ref == AV_NOPTS_VALUE) + ref = pkt->pts; + if (sti->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) + return 0; + ref &= (1LL << st->pts_wrap_bits)-1; + + // reference time stamp should be 60 s before first time stamp + pts_wrap_reference = ref - av_rescale(60, st->time_base.den, st->time_base.num); + // if first time stamp is not more than 1/8 and 60s before the wrap point, subtract rather than add wrap offset + pts_wrap_behavior = (ref < (1LL << st->pts_wrap_bits) - (1LL << st->pts_wrap_bits-3)) || + (ref < (1LL << st->pts_wrap_bits) - av_rescale(60, st->time_base.den, st->time_base.num)) ? + AV_PTS_WRAP_ADD_OFFSET : AV_PTS_WRAP_SUB_OFFSET; + + first_program = av_find_program_from_stream(s, NULL, stream_index); + + if (!first_program) { + int default_stream_index = av_find_default_stream_index(s); + FFStream *const default_sti = ffstream(s->streams[default_stream_index]); + if (default_sti->pts_wrap_reference == AV_NOPTS_VALUE) { + for (unsigned i = 0; i < s->nb_streams; i++) { + FFStream *const sti = ffstream(s->streams[i]); + if (av_find_program_from_stream(s, NULL, i)) + continue; + sti->pts_wrap_reference = pts_wrap_reference; + sti->pts_wrap_behavior = pts_wrap_behavior; + } + } else { + sti->pts_wrap_reference = default_sti->pts_wrap_reference; + sti->pts_wrap_behavior = default_sti->pts_wrap_behavior; + } + } else { + AVProgram *program = first_program; + while (program) { + if (program->pts_wrap_reference != AV_NOPTS_VALUE) { + pts_wrap_reference = program->pts_wrap_reference; + pts_wrap_behavior = program->pts_wrap_behavior; + break; + } + program = av_find_program_from_stream(s, program, stream_index); + } + + // update every program with differing pts_wrap_reference + program = first_program; + while (program) { + if (program->pts_wrap_reference != pts_wrap_reference) { + for (unsigned i = 0; i < program->nb_stream_indexes; i++) { + FFStream *const sti = ffstream(s->streams[program->stream_index[i]]); + sti->pts_wrap_reference = pts_wrap_reference; + sti->pts_wrap_behavior = pts_wrap_behavior; + } + + program->pts_wrap_reference = pts_wrap_reference; + program->pts_wrap_behavior = pts_wrap_behavior; + } + program = av_find_program_from_stream(s, program, stream_index); + } + } + return 1; +} + +int ff_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + FFFormatContext *const si = ffformatcontext(s); + int err; + +#if FF_API_INIT_PACKET +FF_DISABLE_DEPRECATION_WARNINGS + pkt->data = NULL; + pkt->size = 0; + av_init_packet(pkt); +FF_ENABLE_DEPRECATION_WARNINGS +#else + av_packet_unref(pkt); +#endif + + for (;;) { + PacketList *pktl = si->raw_packet_buffer; + AVStream *st; + FFStream *sti; + const AVPacket *pkt1; + + if (pktl) { + AVStream *const st = s->streams[pktl->pkt.stream_index]; + if (si->raw_packet_buffer_remaining_size <= 0) + if ((err = probe_codec(s, st, NULL)) < 0) + return err; + if (ffstream(st)->request_probe <= 0) { + avpriv_packet_list_get(&si->raw_packet_buffer, + &si->raw_packet_buffer_end, pkt); + si->raw_packet_buffer_remaining_size += pkt->size; + return 0; + } + } + + err = s->iformat->read_packet(s, pkt); + if (err < 0) { + av_packet_unref(pkt); + + /* Some demuxers return FFERROR_REDO when they consume + data and discard it (ignored streams, junk, extradata). + We must re-call the demuxer to get the real packet. */ + if (err == FFERROR_REDO) + continue; + if (!pktl || err == AVERROR(EAGAIN)) + return err; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; + FFStream *const sti = ffstream(st); + if (sti->probe_packets || sti->request_probe > 0) + if ((err = probe_codec(s, st, NULL)) < 0) + return err; + av_assert0(sti->request_probe <= 0); + } + continue; + } + + err = av_packet_make_refcounted(pkt); + if (err < 0) { + av_packet_unref(pkt); + return err; + } + + if (pkt->flags & AV_PKT_FLAG_CORRUPT) { + av_log(s, AV_LOG_WARNING, + "Packet corrupt (stream = %d, dts = %s)", + pkt->stream_index, av_ts2str(pkt->dts)); + if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) { + av_log(s, AV_LOG_WARNING, ", dropping it.\n"); + av_packet_unref(pkt); + continue; + } + av_log(s, AV_LOG_WARNING, ".\n"); + } + + av_assert0(pkt->stream_index < (unsigned)s->nb_streams && + "Invalid stream index.\n"); + + st = s->streams[pkt->stream_index]; + sti = ffstream(st); + + if (update_wrap_reference(s, st, pkt->stream_index, pkt) && sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { + // correct first time stamps to negative values + if (!is_relative(sti->first_dts)) + sti->first_dts = wrap_timestamp(st, sti->first_dts); + if (!is_relative(st->start_time)) + st->start_time = wrap_timestamp(st, st->start_time); + if (!is_relative(sti->cur_dts)) + sti->cur_dts = wrap_timestamp(st, sti->cur_dts); + } + + pkt->dts = wrap_timestamp(st, pkt->dts); + pkt->pts = wrap_timestamp(st, pkt->pts); + + force_codec_ids(s, st); + + /* TODO: audio: time filter; video: frame reordering (pts != dts) */ + if (s->use_wallclock_as_timestamps) + pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base); + + if (!pktl && sti->request_probe <= 0) + return 0; + + err = avpriv_packet_list_put(&si->raw_packet_buffer, + &si->raw_packet_buffer_end, + pkt, NULL, 0); + if (err < 0) { + av_packet_unref(pkt); + return err; + } + pkt1 = &si->raw_packet_buffer_end->pkt; + si->raw_packet_buffer_remaining_size -= pkt1->size; + + if ((err = probe_codec(s, st, pkt1)) < 0) + return err; + } +} + +/** + * Return the frame duration in seconds. Return 0 if not available. + */ +static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, + AVStream *st, AVCodecParserContext *pc, + AVPacket *pkt) +{ + FFStream *const sti = ffstream(st); + AVRational codec_framerate = sti->avctx->framerate; + int frame_size, sample_rate; + + *pnum = 0; + *pden = 0; + switch (st->codecpar->codec_type) { + case AVMEDIA_TYPE_VIDEO: + if (st->r_frame_rate.num && !pc) { + *pnum = st->r_frame_rate.den; + *pden = st->r_frame_rate.num; + } else if (st->time_base.num * 1000LL > st->time_base.den) { + *pnum = st->time_base.num; + *pden = st->time_base.den; + } else if (codec_framerate.den * 1000LL > codec_framerate.num) { + av_assert0(sti->avctx->ticks_per_frame); + av_reduce(pnum, pden, + codec_framerate.den, + codec_framerate.num * (int64_t)sti->avctx->ticks_per_frame, + INT_MAX); + + if (pc && pc->repeat_pict) { + av_reduce(pnum, pden, + (*pnum) * (1LL + pc->repeat_pict), + (*pden), + INT_MAX); + } + /* If this codec can be interlaced or progressive then we need + * a parser to compute duration of a packet. Thus if we have + * no parser in such case leave duration undefined. */ + if (sti->avctx->ticks_per_frame > 1 && !pc) + *pnum = *pden = 0; + } + break; + case AVMEDIA_TYPE_AUDIO: + if (sti->avctx_inited) { + frame_size = av_get_audio_frame_duration(sti->avctx, pkt->size); + sample_rate = sti->avctx->sample_rate; + } else { + frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size); + sample_rate = st->codecpar->sample_rate; + } + if (frame_size <= 0 || sample_rate <= 0) + break; + *pnum = frame_size; + *pden = sample_rate; + break; + default: + break; + } +} + +static int has_decode_delay_been_guessed(AVStream *st) +{ + FFStream *const sti = ffstream(st); + if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; + if (!sti->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy + return 1; +#if CONFIG_H264_DECODER + if (sti->avctx->has_b_frames && + avpriv_h264_has_num_reorder_frames(sti->avctx) == sti->avctx->has_b_frames) + return 1; +#endif + if (sti->avctx->has_b_frames<3) + return sti->nb_decoded_frames >= 7; + else if (sti->avctx->has_b_frames<4) + return sti->nb_decoded_frames >= 18; + else + return sti->nb_decoded_frames >= 20; +} + +static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pktl) +{ + FFFormatContext *const si = ffformatcontext(s); + if (pktl->next) + return pktl->next; + if (pktl == si->packet_buffer_end) + return si->parse_queue; + return NULL; +} + +static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts) +{ + FFStream *const sti = ffstream(st); + int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && + st->codecpar->codec_id != AV_CODEC_ID_HEVC; + + if (!onein_oneout) { + int delay = sti->avctx->has_b_frames; + + if (dts == AV_NOPTS_VALUE) { + int64_t best_score = INT64_MAX; + for (int i = 0; i < delay; i++) { + if (sti->pts_reorder_error_count[i]) { + int64_t score = sti->pts_reorder_error[i] / sti->pts_reorder_error_count[i]; + if (score < best_score) { + best_score = score; + dts = pts_buffer[i]; + } + } + } + } else { + for (int i = 0; i < delay; i++) { + if (pts_buffer[i] != AV_NOPTS_VALUE) { + int64_t diff = FFABS(pts_buffer[i] - dts) + + (uint64_t)sti->pts_reorder_error[i]; + diff = FFMAX(diff, sti->pts_reorder_error[i]); + sti->pts_reorder_error[i] = diff; + sti->pts_reorder_error_count[i]++; + if (sti->pts_reorder_error_count[i] > 250) { + sti->pts_reorder_error[i] >>= 1; + sti->pts_reorder_error_count[i] >>= 1; + } + } + } + } + } + + if (dts == AV_NOPTS_VALUE) + dts = pts_buffer[0]; + + return dts; +} + +/** + * Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts + * of the packets in a window. + */ +static void update_dts_from_pts(AVFormatContext *s, int stream_index, + PacketList *pkt_buffer) +{ + AVStream *const st = s->streams[stream_index]; + int delay = ffstream(st)->avctx->has_b_frames; + + int64_t pts_buffer[MAX_REORDER_DELAY+1]; + + for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) + pts_buffer[i] = AV_NOPTS_VALUE; + + for (; pkt_buffer; pkt_buffer = get_next_pkt(s, st, pkt_buffer)) { + if (pkt_buffer->pkt.stream_index != stream_index) + continue; + + if (pkt_buffer->pkt.pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { + pts_buffer[0] = pkt_buffer->pkt.pts; + for (int i = 0; i < delay && pts_buffer[i] > pts_buffer[i + 1]; i++) + FFSWAP(int64_t, pts_buffer[i], pts_buffer[i + 1]); + + pkt_buffer->pkt.dts = select_from_pts_buffer(st, pts_buffer, pkt_buffer->pkt.dts); + } + } +} + +static void update_initial_timestamps(AVFormatContext *s, int stream_index, + int64_t dts, int64_t pts, AVPacket *pkt) +{ + FFFormatContext *const si = ffformatcontext(s); + AVStream *const st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); + PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; + + uint64_t shift; + + if (sti->first_dts != AV_NOPTS_VALUE || + dts == AV_NOPTS_VALUE || + sti->cur_dts == AV_NOPTS_VALUE || + sti->cur_dts < INT_MIN + RELATIVE_TS_BASE || + dts < INT_MIN + (sti->cur_dts - RELATIVE_TS_BASE) || + is_relative(dts)) + return; + + sti->first_dts = dts - (sti->cur_dts - RELATIVE_TS_BASE); + sti->cur_dts = dts; + shift = (uint64_t)sti->first_dts - RELATIVE_TS_BASE; + + if (is_relative(pts)) + pts += shift; + + for (PacketList *pktl_it = pktl; pktl_it; pktl_it = get_next_pkt(s, st, pktl_it)) { + if (pktl_it->pkt.stream_index != stream_index) + continue; + if (is_relative(pktl_it->pkt.pts)) + pktl_it->pkt.pts += shift; + + if (is_relative(pktl_it->pkt.dts)) + pktl_it->pkt.dts += shift; + + if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) { + st->start_time = pktl_it->pkt.pts; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) + st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); + } + } + + if (has_decode_delay_been_guessed(st)) { + update_dts_from_pts(s, stream_index, pktl); + } + + if (st->start_time == AV_NOPTS_VALUE) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || !(pkt->flags & AV_PKT_FLAG_DISCARD)) { + st->start_time = pts; + } + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) + st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); + } +} + +static void update_initial_durations(AVFormatContext *s, AVStream *st, + int stream_index, int64_t duration) +{ + FFFormatContext *const si = ffformatcontext(s); + FFStream *const sti = ffstream(st); + PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; + int64_t cur_dts = RELATIVE_TS_BASE; + + if (sti->first_dts != AV_NOPTS_VALUE) { + if (sti->update_initial_durations_done) + return; + sti->update_initial_durations_done = 1; + cur_dts = sti->first_dts; + for (; pktl; pktl = get_next_pkt(s, st, pktl)) { + if (pktl->pkt.stream_index == stream_index) { + if (pktl->pkt.pts != pktl->pkt.dts || + pktl->pkt.dts != AV_NOPTS_VALUE || + pktl->pkt.duration) + break; + cur_dts -= duration; + } + } + if (pktl && pktl->pkt.dts != sti->first_dts) { + av_log(s, AV_LOG_DEBUG, "first_dts %s not matching first dts %s (pts %s, duration %"PRId64") in the queue\n", + av_ts2str(sti->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration); + return; + } + if (!pktl) { + av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(sti->first_dts)); + return; + } + pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; + sti->first_dts = cur_dts; + } else if (sti->cur_dts != RELATIVE_TS_BASE) + return; + + for (; pktl; pktl = get_next_pkt(s, st, pktl)) { + if (pktl->pkt.stream_index != stream_index) + continue; + if ((pktl->pkt.pts == pktl->pkt.dts || + pktl->pkt.pts == AV_NOPTS_VALUE) && + (pktl->pkt.dts == AV_NOPTS_VALUE || + pktl->pkt.dts == sti->first_dts || + pktl->pkt.dts == RELATIVE_TS_BASE) && + !pktl->pkt.duration && + av_sat_add64(cur_dts, duration) == cur_dts + (uint64_t)duration + ) { + pktl->pkt.dts = cur_dts; + if (!sti->avctx->has_b_frames) + pktl->pkt.pts = cur_dts; + pktl->pkt.duration = duration; + } else + break; + cur_dts = pktl->pkt.dts + pktl->pkt.duration; + } + if (!pktl) + sti->cur_dts = cur_dts; +} + +static void compute_pkt_fields(AVFormatContext *s, AVStream *st, + AVCodecParserContext *pc, AVPacket *pkt, + int64_t next_dts, int64_t next_pts) +{ + FFStream *const sti = ffstream(st); + int num, den, presentation_delayed, delay; + int64_t offset; + AVRational duration; + int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && + st->codecpar->codec_id != AV_CODEC_ID_HEVC; + + if (s->flags & AVFMT_FLAG_NOFILLIN) + return; + + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE) { + if (pkt->dts == pkt->pts && sti->last_dts_for_order_check != AV_NOPTS_VALUE) { + if (sti->last_dts_for_order_check <= pkt->dts) { + sti->dts_ordered++; + } else { + av_log(s, sti->dts_misordered ? AV_LOG_DEBUG : AV_LOG_WARNING, + "DTS %"PRIi64" < %"PRIi64" out of order\n", + pkt->dts, + sti->last_dts_for_order_check); + sti->dts_misordered++; + } + if (sti->dts_ordered + sti->dts_misordered > 250) { + sti->dts_ordered >>= 1; + sti->dts_misordered >>= 1; + } + } + + sti->last_dts_for_order_check = pkt->dts; + if (sti->dts_ordered < 8*sti->dts_misordered && pkt->dts == pkt->pts) + pkt->dts = AV_NOPTS_VALUE; + } + + if ((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) + pkt->dts = AV_NOPTS_VALUE; + + if (pc && pc->pict_type == AV_PICTURE_TYPE_B + && !sti->avctx->has_b_frames) + //FIXME Set low_delay = 0 when has_b_frames = 1 + sti->avctx->has_b_frames = 1; + + /* do we have a video B-frame ? */ + delay = sti->avctx->has_b_frames; + presentation_delayed = 0; + + /* XXX: need has_b_frame, but cannot get it if the codec is + * not initialized */ + if (delay && + pc && pc->pict_type != AV_PICTURE_TYPE_B) + presentation_delayed = 1; + + if (pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && + st->pts_wrap_bits < 63 && pkt->dts > INT64_MIN + (1LL << st->pts_wrap_bits) && + pkt->dts - (1LL << (st->pts_wrap_bits - 1)) > pkt->pts) { + if (is_relative(sti->cur_dts) || pkt->dts - (1LL<<(st->pts_wrap_bits - 1)) > sti->cur_dts) { + pkt->dts -= 1LL << st->pts_wrap_bits; + } else + pkt->pts += 1LL << st->pts_wrap_bits; + } + + /* Some MPEG-2 in MPEG-PS lack dts (issue #171 / input_file.mpg). + * We take the conservative approach and discard both. + * Note: If this is misbehaving for an H.264 file, then possibly + * presentation_delayed is not set correctly. */ + if (delay == 1 && pkt->dts == pkt->pts && + pkt->dts != AV_NOPTS_VALUE && presentation_delayed) { + av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination %"PRIi64"\n", pkt->dts); + if ( strcmp(s->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") + && strcmp(s->iformat->name, "flv")) // otherwise we discard correct timestamps for vc1-wmapro.ism + pkt->dts = AV_NOPTS_VALUE; + } + + duration = av_mul_q((AVRational) {pkt->duration, 1}, st->time_base); + if (pkt->duration <= 0) { + compute_frame_duration(s, &num, &den, st, pc, pkt); + if (den && num) { + duration = (AVRational) {num, den}; + pkt->duration = av_rescale_rnd(1, + num * (int64_t) st->time_base.den, + den * (int64_t) st->time_base.num, + AV_ROUND_DOWN); + } + } + + if (pkt->duration > 0 && (ffformatcontext(s)->packet_buffer || ffformatcontext(s)->parse_queue)) + update_initial_durations(s, st, pkt->stream_index, pkt->duration); + + /* Correct timestamps with byte offset if demuxers only have timestamps + * on packet boundaries */ + if (pc && sti->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) { + /* this will estimate bitrate based on this frame's duration and size */ + offset = av_rescale(pc->offset, pkt->duration, pkt->size); + if (pkt->pts != AV_NOPTS_VALUE) + pkt->pts += offset; + if (pkt->dts != AV_NOPTS_VALUE) + pkt->dts += offset; + } + + /* This may be redundant, but it should not hurt. */ + if (pkt->dts != AV_NOPTS_VALUE && + pkt->pts != AV_NOPTS_VALUE && + pkt->pts > pkt->dts) + presentation_delayed = 1; + + if (s->debug & FF_FDEBUG_TS) + av_log(s, AV_LOG_DEBUG, + "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64" delay:%d onein_oneout:%d\n", + presentation_delayed, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), + pkt->stream_index, pc, pkt->duration, delay, onein_oneout); + + /* Interpolate PTS and DTS if they are not present. We skip H264 + * currently because delay and has_b_frames are not reliably set. */ + if ((delay == 0 || (delay == 1 && pc)) && + onein_oneout) { + if (presentation_delayed) { + /* DTS = decompression timestamp */ + /* PTS = presentation timestamp */ + if (pkt->dts == AV_NOPTS_VALUE) + pkt->dts = sti->last_IP_pts; + update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); + if (pkt->dts == AV_NOPTS_VALUE) + pkt->dts = sti->cur_dts; + + /* This is tricky: the dts must be incremented by the duration + * of the frame we are displaying, i.e. the last I- or P-frame. */ + if (sti->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX) + sti->last_IP_duration = pkt->duration; + if (pkt->dts != AV_NOPTS_VALUE) + sti->cur_dts = av_sat_add64(pkt->dts, sti->last_IP_duration); + if (pkt->dts != AV_NOPTS_VALUE && + pkt->pts == AV_NOPTS_VALUE && + sti->last_IP_duration > 0 && + ((uint64_t)sti->cur_dts - (uint64_t)next_dts + 1) <= 2 && + next_dts != next_pts && + next_pts != AV_NOPTS_VALUE) + pkt->pts = next_dts; + + if ((uint64_t)pkt->duration <= INT32_MAX) + sti->last_IP_duration = pkt->duration; + sti->last_IP_pts = pkt->pts; + /* Cannot compute PTS if not present (we can compute it only + * by knowing the future. */ + } else if (pkt->pts != AV_NOPTS_VALUE || + pkt->dts != AV_NOPTS_VALUE || + pkt->duration > 0 ) { + + /* presentation is not delayed : PTS and DTS are the same */ + if (pkt->pts == AV_NOPTS_VALUE) + pkt->pts = pkt->dts; + update_initial_timestamps(s, pkt->stream_index, pkt->pts, + pkt->pts, pkt); + if (pkt->pts == AV_NOPTS_VALUE) + pkt->pts = sti->cur_dts; + pkt->dts = pkt->pts; + if (pkt->pts != AV_NOPTS_VALUE && duration.num >= 0) + sti->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1); + } + } + + if (pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { + sti->pts_buffer[0] = pkt->pts; + for (int i = 0; i < delay && sti->pts_buffer[i] > sti->pts_buffer[i + 1]; i++) + FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]); + + if (has_decode_delay_been_guessed(st)) + pkt->dts = select_from_pts_buffer(st, sti->pts_buffer, pkt->dts); + } + // We skipped it above so we try here. + if (!onein_oneout) + // This should happen on the first packet + update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); + if (pkt->dts > sti->cur_dts) + sti->cur_dts = pkt->dts; + + if (s->debug & FF_FDEBUG_TS) + av_log(s, AV_LOG_DEBUG, "OUTdelayed:%d/%d pts:%s, dts:%s cur_dts:%s st:%d (%d)\n", + presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), st->index, st->id); + + /* update flags */ + if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA || ff_is_intra_only(st->codecpar->codec_id)) + pkt->flags |= AV_PKT_FLAG_KEY; +} + +/** + * Parse a packet, add all split parts to parse_queue. + * + * @param pkt Packet to parse; must not be NULL. + * @param flush Indicates whether to flush. If set, pkt must be blank. + */ +static int parse_packet(AVFormatContext *s, AVPacket *pkt, + int stream_index, int flush) +{ + FFFormatContext *const si = ffformatcontext(s); + AVPacket *out_pkt = si->parse_pkt; + AVStream *st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); + const uint8_t *data = pkt->data; + int size = pkt->size; + int ret = 0, got_output = flush; + + if (!size && !flush && sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { + // preserve 0-size sync packets + compute_pkt_fields(s, st, sti->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); + } + + while (size > 0 || (flush && got_output)) { + int64_t next_pts = pkt->pts; + int64_t next_dts = pkt->dts; + int len; + + len = av_parser_parse2(sti->parser, sti->avctx, + &out_pkt->data, &out_pkt->size, data, size, + pkt->pts, pkt->dts, pkt->pos); + + pkt->pts = pkt->dts = AV_NOPTS_VALUE; + pkt->pos = -1; + /* increment read pointer */ + av_assert1(data || !len); + data = len ? data + len : data; + size -= len; + + got_output = !!out_pkt->size; + + if (!out_pkt->size) + continue; + + if (pkt->buf && out_pkt->data == pkt->data) { + /* reference pkt->buf only when out_pkt->data is guaranteed to point + * to data in it and not in the parser's internal buffer. */ + /* XXX: Ensure this is the case with all parsers when sti->parser->flags + * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */ + out_pkt->buf = av_buffer_ref(pkt->buf); + if (!out_pkt->buf) { + ret = AVERROR(ENOMEM); + goto fail; + } + } else { + ret = av_packet_make_refcounted(out_pkt); + if (ret < 0) + goto fail; + } + + if (pkt->side_data) { + out_pkt->side_data = pkt->side_data; + out_pkt->side_data_elems = pkt->side_data_elems; + pkt->side_data = NULL; + pkt->side_data_elems = 0; + } + + /* set the duration */ + out_pkt->duration = (sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (sti->avctx->sample_rate > 0) { + out_pkt->duration = + av_rescale_q_rnd(sti->parser->duration, + (AVRational) { 1, sti->avctx->sample_rate }, + st->time_base, + AV_ROUND_DOWN); + } + } + + out_pkt->stream_index = st->index; + out_pkt->pts = sti->parser->pts; + out_pkt->dts = sti->parser->dts; + out_pkt->pos = sti->parser->pos; + out_pkt->flags |= pkt->flags & AV_PKT_FLAG_DISCARD; + + if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) + out_pkt->pos = sti->parser->frame_offset; + + if (sti->parser->key_frame == 1 || + (sti->parser->key_frame == -1 && + sti->parser->pict_type == AV_PICTURE_TYPE_I)) + out_pkt->flags |= AV_PKT_FLAG_KEY; + + if (sti->parser->key_frame == -1 && sti->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) + out_pkt->flags |= AV_PKT_FLAG_KEY; + + compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts); + + ret = avpriv_packet_list_put(&si->parse_queue, + &si->parse_queue_end, + out_pkt, NULL, 0); + if (ret < 0) + goto fail; + } + + /* end of the stream => close and free the parser */ + if (flush) { + av_parser_close(sti->parser); + sti->parser = NULL; + } + +fail: + if (ret < 0) + av_packet_unref(out_pkt); + av_packet_unref(pkt); + return ret; +} + +static int64_t ts_to_samples(AVStream *st, int64_t ts) +{ + return av_rescale(ts, st->time_base.num * st->codecpar->sample_rate, st->time_base.den); +} + +static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) +{ + FFFormatContext *const si = ffformatcontext(s); + int ret, got_packet = 0; + AVDictionary *metadata = NULL; + + while (!got_packet && !si->parse_queue) { + AVStream *st; + FFStream *sti; + + /* read next packet */ + ret = ff_read_packet(s, pkt); + if (ret < 0) { + if (ret == AVERROR(EAGAIN)) + return ret; + /* flush the parsers */ + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; + FFStream *const sti = ffstream(st); + if (sti->parser && sti->need_parsing) + parse_packet(s, pkt, st->index, 1); + } + /* all remaining packets are now in parse_queue => + * really terminate parsing */ + break; + } + ret = 0; + st = s->streams[pkt->stream_index]; + sti = ffstream(st); + + st->event_flags |= AVSTREAM_EVENT_FLAG_NEW_PACKETS; + + /* update context if required */ + if (sti->need_context_update) { + if (avcodec_is_open(sti->avctx)) { + av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); + avcodec_close(sti->avctx); + sti->info->found_decoder = 0; + } + + /* close parser, because it depends on the codec */ + if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { + av_parser_close(sti->parser); + sti->parser = NULL; + } + + ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); + if (ret < 0) { + av_packet_unref(pkt); + return ret; + } + + sti->need_context_update = 0; + } + + if (pkt->pts != AV_NOPTS_VALUE && + pkt->dts != AV_NOPTS_VALUE && + pkt->pts < pkt->dts) { + av_log(s, AV_LOG_WARNING, + "Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n", + pkt->stream_index, + av_ts2str(pkt->pts), + av_ts2str(pkt->dts), + pkt->size); + } + if (s->debug & FF_FDEBUG_TS) + av_log(s, AV_LOG_DEBUG, + "ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64", flags=%d\n", + pkt->stream_index, + av_ts2str(pkt->pts), + av_ts2str(pkt->dts), + pkt->size, pkt->duration, pkt->flags); + + if (sti->need_parsing && !sti->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { + sti->parser = av_parser_init(st->codecpar->codec_id); + if (!sti->parser) { + av_log(s, AV_LOG_VERBOSE, "parser not found for codec " + "%s, packets or times may be invalid.\n", + avcodec_get_name(st->codecpar->codec_id)); + /* no parser available: just output the raw packets */ + sti->need_parsing = AVSTREAM_PARSE_NONE; + } else if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) + sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; + else if (sti->need_parsing == AVSTREAM_PARSE_FULL_ONCE) + sti->parser->flags |= PARSER_FLAG_ONCE; + else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) + sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; + } + + if (!sti->need_parsing || !sti->parser) { + /* no parsing needed: we just output the packet as is */ + compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); + if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && + (pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) { + ff_reduce_index(s, st->index); + av_add_index_entry(st, pkt->pos, pkt->dts, + 0, 0, AVINDEX_KEYFRAME); + } + got_packet = 1; + } else if (st->discard < AVDISCARD_ALL) { + if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0) + return ret; + st->codecpar->sample_rate = sti->avctx->sample_rate; + st->codecpar->bit_rate = sti->avctx->bit_rate; + st->codecpar->channels = sti->avctx->channels; + st->codecpar->channel_layout = sti->avctx->channel_layout; + st->codecpar->codec_id = sti->avctx->codec_id; + } else { + /* free packet */ + av_packet_unref(pkt); + } + if (pkt->flags & AV_PKT_FLAG_KEY) + sti->skip_to_keyframe = 0; + if (sti->skip_to_keyframe) { + av_packet_unref(pkt); + got_packet = 0; + } + } + + if (!got_packet && si->parse_queue) + ret = avpriv_packet_list_get(&si->parse_queue, &si->parse_queue_end, pkt); + + if (ret >= 0) { + AVStream *const st = s->streams[pkt->stream_index]; + FFStream *const sti = ffstream(st); + int discard_padding = 0; + if (sti->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { + int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0); + int64_t sample = ts_to_samples(st, pts); + int duration = ts_to_samples(st, pkt->duration); + int64_t end_sample = sample + duration; + if (duration > 0 && end_sample >= sti->first_discard_sample && + sample < sti->last_discard_sample) + discard_padding = FFMIN(end_sample - sti->first_discard_sample, duration); + } + if (sti->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) + sti->skip_samples = sti->start_skip_samples; + if (sti->skip_samples || discard_padding) { + uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); + if (p) { + AV_WL32(p, sti->skip_samples); + AV_WL32(p + 4, discard_padding); + av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %d / discard %d\n", sti->skip_samples, discard_padding); + } + sti->skip_samples = 0; + } + + if (sti->inject_global_side_data) { + for (int i = 0; i < st->nb_side_data; i++) { + const AVPacketSideData *const src_sd = &st->side_data[i]; + uint8_t *dst_data; + + if (av_packet_get_side_data(pkt, src_sd->type, NULL)) + continue; + + dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size); + if (!dst_data) { + av_log(s, AV_LOG_WARNING, "Could not inject global side data\n"); + continue; + } + + memcpy(dst_data, src_sd->data, src_sd->size); + } + sti->inject_global_side_data = 0; + } + } + + av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata); + if (metadata) { + s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED; + av_dict_copy(&s->metadata, metadata, 0); + av_dict_free(&metadata); + av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN); + } + + if (s->debug & FF_FDEBUG_TS) + av_log(s, AV_LOG_DEBUG, + "read_frame_internal stream=%d, pts=%s, dts=%s, " + "size=%d, duration=%"PRId64", flags=%d\n", + pkt->stream_index, + av_ts2str(pkt->pts), + av_ts2str(pkt->dts), + pkt->size, pkt->duration, pkt->flags); + + /* A demuxer might have returned EOF because of an IO error, let's + * propagate this back to the user. */ + if (ret == AVERROR_EOF && s->pb && s->pb->error < 0 && s->pb->error != AVERROR(EAGAIN)) + ret = s->pb->error; + + return ret; +} + +int av_read_frame(AVFormatContext *s, AVPacket *pkt) +{ + FFFormatContext *const si = ffformatcontext(s); + const int genpts = s->flags & AVFMT_FLAG_GENPTS; + int eof = 0; + int ret; + AVStream *st; + + if (!genpts) { + ret = si->packet_buffer + ? avpriv_packet_list_get(&si->packet_buffer, + &si->packet_buffer_end, pkt) + : read_frame_internal(s, pkt); + if (ret < 0) + return ret; + goto return_packet; + } + + for (;;) { + PacketList *pktl = si->packet_buffer; + + if (pktl) { + AVPacket *next_pkt = &pktl->pkt; + + if (next_pkt->dts != AV_NOPTS_VALUE) { + int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits; + // last dts seen for this stream. if any of packets following + // current one had no dts, we will set this to AV_NOPTS_VALUE. + int64_t last_dts = next_pkt->dts; + av_assert2(wrap_bits <= 64); + while (pktl && next_pkt->pts == AV_NOPTS_VALUE) { + if (pktl->pkt.stream_index == next_pkt->stream_index && + av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2ULL << (wrap_bits - 1)) < 0) { + if (av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2ULL << (wrap_bits - 1))) { + // not B-frame + next_pkt->pts = pktl->pkt.dts; + } + if (last_dts != AV_NOPTS_VALUE) { + // Once last dts was set to AV_NOPTS_VALUE, we don't change it. + last_dts = pktl->pkt.dts; + } + } + pktl = pktl->next; + } + if (eof && next_pkt->pts == AV_NOPTS_VALUE && last_dts != AV_NOPTS_VALUE) { + // Fixing the last reference frame had none pts issue (For MXF etc). + // We only do this when + // 1. eof. + // 2. we are not able to resolve a pts value for current packet. + // 3. the packets for this stream at the end of the files had valid dts. + next_pkt->pts = last_dts + next_pkt->duration; + } + pktl = si->packet_buffer; + } + + /* read packet from packet buffer, if there is data */ + st = s->streams[next_pkt->stream_index]; + if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL && + next_pkt->dts != AV_NOPTS_VALUE && !eof)) { + ret = avpriv_packet_list_get(&si->packet_buffer, + &si->packet_buffer_end, pkt); + goto return_packet; + } + } + + ret = read_frame_internal(s, pkt); + if (ret < 0) { + if (pktl && ret != AVERROR(EAGAIN)) { + eof = 1; + continue; + } else + return ret; + } + + ret = avpriv_packet_list_put(&si->packet_buffer, + &si->packet_buffer_end, + pkt, NULL, 0); + if (ret < 0) { + av_packet_unref(pkt); + return ret; + } + } + +return_packet: + st = s->streams[pkt->stream_index]; + if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY) { + ff_reduce_index(s, st->index); + av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME); + } + + if (is_relative(pkt->dts)) + pkt->dts -= RELATIVE_TS_BASE; + if (is_relative(pkt->pts)) + pkt->pts -= RELATIVE_TS_BASE; + + return ret; +} + +/** + * Return TRUE if the stream has accurate duration in any stream. + * + * @return TRUE if the stream has accurate duration for at least one component. + */ +static int has_duration(AVFormatContext *ic) +{ + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; + if (st->duration != AV_NOPTS_VALUE) + return 1; + } + if (ic->duration != AV_NOPTS_VALUE) + return 1; + return 0; +} + +/** + * Estimate the stream timings from the one of each components. + * + * Also computes the global bitrate if possible. + */ +static void update_stream_timings(AVFormatContext *ic) +{ + int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text; + int64_t duration, duration1, duration_text, filesize; + + start_time = INT64_MAX; + start_time_text = INT64_MAX; + end_time = INT64_MIN; + end_time_text = INT64_MIN; + duration = INT64_MIN; + duration_text = INT64_MIN; + + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + int is_text = st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || + st->codecpar->codec_type == AVMEDIA_TYPE_DATA; + + if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) { + start_time1 = av_rescale_q(st->start_time, st->time_base, + AV_TIME_BASE_Q); + if (is_text) + start_time_text = FFMIN(start_time_text, start_time1); + else + start_time = FFMIN(start_time, start_time1); + end_time1 = av_rescale_q_rnd(st->duration, st->time_base, + AV_TIME_BASE_Q, + AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); + if (end_time1 != AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) { + end_time1 += start_time1; + if (is_text) + end_time_text = FFMAX(end_time_text, end_time1); + else + end_time = FFMAX(end_time, end_time1); + } + for (AVProgram *p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) { + if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1) + p->start_time = start_time1; + if (p->end_time < end_time1) + p->end_time = end_time1; + } + } + if (st->duration != AV_NOPTS_VALUE) { + duration1 = av_rescale_q(st->duration, st->time_base, + AV_TIME_BASE_Q); + if (is_text) + duration_text = FFMAX(duration_text, duration1); + else + duration = FFMAX(duration, duration1); + } + } + if (start_time == INT64_MAX || (start_time > start_time_text && start_time - (uint64_t)start_time_text < AV_TIME_BASE)) + start_time = start_time_text; + else if (start_time > start_time_text) + av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream starttime %f\n", start_time_text / (float)AV_TIME_BASE); + + if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - (uint64_t)end_time < AV_TIME_BASE)) + end_time = end_time_text; + else if (end_time < end_time_text) + av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream endtime %f\n", end_time_text / (float)AV_TIME_BASE); + + if (duration == INT64_MIN || (duration < duration_text && duration_text - duration < AV_TIME_BASE)) + duration = duration_text; + else if (duration < duration_text) + av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream duration %f\n", duration_text / (float)AV_TIME_BASE); + + if (start_time != INT64_MAX) { + ic->start_time = start_time; + if (end_time != INT64_MIN) { + if (ic->nb_programs > 1) { + for (unsigned i = 0; i < ic->nb_programs; i++) { + AVProgram *const p = ic->programs[i]; + + if (p->start_time != AV_NOPTS_VALUE && + p->end_time > p->start_time && + p->end_time - (uint64_t)p->start_time <= INT64_MAX) + duration = FFMAX(duration, p->end_time - p->start_time); + } + } else if (end_time >= start_time && end_time - (uint64_t)start_time <= INT64_MAX) { + duration = FFMAX(duration, end_time - start_time); + } + } + } + if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) { + ic->duration = duration; + } + if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0) { + /* compute the bitrate */ + double bitrate = (double) filesize * 8.0 * AV_TIME_BASE / + (double) ic->duration; + if (bitrate >= 0 && bitrate <= INT64_MAX) + ic->bit_rate = bitrate; + } +} + +static void fill_all_stream_timings(AVFormatContext *ic) +{ + update_stream_timings(ic); + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + + if (st->start_time == AV_NOPTS_VALUE) { + if (ic->start_time != AV_NOPTS_VALUE) + st->start_time = av_rescale_q(ic->start_time, AV_TIME_BASE_Q, + st->time_base); + if (ic->duration != AV_NOPTS_VALUE) + st->duration = av_rescale_q(ic->duration, AV_TIME_BASE_Q, + st->time_base); + } + } +} + +static void estimate_timings_from_bit_rate(AVFormatContext *ic) +{ + int show_warning = 0; + + /* if bit_rate is already set, we believe it */ + if (ic->bit_rate <= 0) { + int64_t bit_rate = 0; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; + const FFStream *const sti = cffstream(st); + if (st->codecpar->bit_rate <= 0 && sti->avctx->bit_rate > 0) + st->codecpar->bit_rate = sti->avctx->bit_rate; + if (st->codecpar->bit_rate > 0) { + if (INT64_MAX - st->codecpar->bit_rate < bit_rate) { + bit_rate = 0; + break; + } + bit_rate += st->codecpar->bit_rate; + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->codec_info_nb_frames > 1) { + // If we have a videostream with packets but without a bitrate + // then consider the sum not known + bit_rate = 0; + break; + } + } + ic->bit_rate = bit_rate; + } + + /* if duration is already set, we believe it */ + if (ic->duration == AV_NOPTS_VALUE && + ic->bit_rate != 0) { + int64_t filesize = ic->pb ? avio_size(ic->pb) : 0; + if (filesize > ffformatcontext(ic)->data_offset) { + filesize -= ffformatcontext(ic)->data_offset; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + + if ( st->time_base.num <= INT64_MAX / ic->bit_rate + && st->duration == AV_NOPTS_VALUE) { + st->duration = av_rescale(filesize, 8LL * st->time_base.den, + ic->bit_rate * + (int64_t) st->time_base.num); + show_warning = 1; + } + } + } + } + if (show_warning) + av_log(ic, AV_LOG_WARNING, + "Estimating duration from bitrate, this may be inaccurate\n"); +} + +#define DURATION_MAX_READ_SIZE 250000LL +#define DURATION_MAX_RETRY 6 + +/* only usable for MPEG-PS streams */ +static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) +{ + AVPacket *pkt = ffformatcontext(ic)->pkt; + int num, den, read_size, ret; + int found_duration = 0; + int is_end; + int64_t filesize, offset, duration; + int retry = 0; + + /* flush packet queue */ + ff_flush_packet_queue(ic); + + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); + + if (st->start_time == AV_NOPTS_VALUE && + sti->first_dts == AV_NOPTS_VALUE && + st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) + av_log(ic, AV_LOG_WARNING, + "start time for stream %d is not set in estimate_timings_from_pts\n", i); + + if (sti->parser) { + av_parser_close(sti->parser); + sti->parser = NULL; + } + } + + if (ic->skip_estimate_duration_from_pts) { + av_log(ic, AV_LOG_INFO, "Skipping duration calculation in estimate_timings_from_pts\n"); + goto skip_duration_calc; + } + + av_opt_set(ic, "skip_changes", "1", AV_OPT_SEARCH_CHILDREN); + /* estimate the end time (duration) */ + /* XXX: may need to support wrapping */ + filesize = ic->pb ? avio_size(ic->pb) : 0; + do { + is_end = found_duration; + offset = filesize - (DURATION_MAX_READ_SIZE << retry); + if (offset < 0) + offset = 0; + + avio_seek(ic->pb, offset, SEEK_SET); + read_size = 0; + for (;;) { + AVStream *st; + FFStream *sti; + if (read_size >= DURATION_MAX_READ_SIZE << (FFMAX(retry - 1, 0))) + break; + + do { + ret = ff_read_packet(ic, pkt); + } while (ret == AVERROR(EAGAIN)); + if (ret != 0) + break; + read_size += pkt->size; + st = ic->streams[pkt->stream_index]; + sti = ffstream(st); + if (pkt->pts != AV_NOPTS_VALUE && + (st->start_time != AV_NOPTS_VALUE || + sti->first_dts != AV_NOPTS_VALUE)) { + if (pkt->duration == 0) { + compute_frame_duration(ic, &num, &den, st, sti->parser, pkt); + if (den && num) { + pkt->duration = av_rescale_rnd(1, + num * (int64_t) st->time_base.den, + den * (int64_t) st->time_base.num, + AV_ROUND_DOWN); + } + } + duration = pkt->pts + pkt->duration; + found_duration = 1; + if (st->start_time != AV_NOPTS_VALUE) + duration -= st->start_time; + else + duration -= sti->first_dts; + if (duration > 0) { + if (st->duration == AV_NOPTS_VALUE || sti->info->last_duration<= 0 || + (st->duration < duration && FFABS(duration - sti->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) + st->duration = duration; + sti->info->last_duration = duration; + } + } + av_packet_unref(pkt); + } + + /* check if all audio/video streams have valid duration */ + if (!is_end) { + is_end = 1; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; + switch (st->codecpar->codec_type) { + case AVMEDIA_TYPE_VIDEO: + case AVMEDIA_TYPE_AUDIO: + if (st->duration == AV_NOPTS_VALUE) + is_end = 0; + } + } + } + } while (!is_end && + offset && + ++retry <= DURATION_MAX_RETRY); + + av_opt_set(ic, "skip_changes", "0", AV_OPT_SEARCH_CHILDREN); + + /* warn about audio/video streams which duration could not be estimated */ + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; + + if (st->duration == AV_NOPTS_VALUE) { + switch (st->codecpar->codec_type) { + case AVMEDIA_TYPE_VIDEO: + case AVMEDIA_TYPE_AUDIO: + if (st->start_time != AV_NOPTS_VALUE || cffstream(st)->first_dts != AV_NOPTS_VALUE) { + av_log(ic, AV_LOG_WARNING, "stream %d : no PTS found at end of file, duration not set\n", i); + } else + av_log(ic, AV_LOG_WARNING, "stream %d : no TS found at start of file, duration not set\n", i); + } + } + } +skip_duration_calc: + fill_all_stream_timings(ic); + + avio_seek(ic->pb, old_offset, SEEK_SET); + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); + + sti->cur_dts = sti->first_dts; + sti->last_IP_pts = AV_NOPTS_VALUE; + sti->last_dts_for_order_check = AV_NOPTS_VALUE; + for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) + sti->pts_buffer[j] = AV_NOPTS_VALUE; + } +} + +/* 1:1 map to AVDurationEstimationMethod */ +static const char *const duration_name[] = { + [AVFMT_DURATION_FROM_PTS] = "pts", + [AVFMT_DURATION_FROM_STREAM] = "stream", + [AVFMT_DURATION_FROM_BITRATE] = "bit rate", +}; + +static const char *duration_estimate_name(enum AVDurationEstimationMethod method) +{ + return duration_name[method]; +} + +static void estimate_timings(AVFormatContext *ic, int64_t old_offset) +{ + int64_t file_size; + + /* get the file size, if possible */ + if (ic->iformat->flags & AVFMT_NOFILE) { + file_size = 0; + } else { + file_size = avio_size(ic->pb); + file_size = FFMAX(0, file_size); + } + + if ((!strcmp(ic->iformat->name, "mpeg") || + !strcmp(ic->iformat->name, "mpegts")) && + file_size && (ic->pb->seekable & AVIO_SEEKABLE_NORMAL)) { + /* get accurate estimate from the PTSes */ + estimate_timings_from_pts(ic, old_offset); + ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; + } else if (has_duration(ic)) { + /* at least one component has timings - we use them for all + * the components */ + fill_all_stream_timings(ic); + /* nut demuxer estimate the duration from PTS */ + if (!strcmp(ic->iformat->name, "nut")) + ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; + else + ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM; + } else { + /* less precise: use bitrate info */ + estimate_timings_from_bit_rate(ic); + ic->duration_estimation_method = AVFMT_DURATION_FROM_BITRATE; + } + update_stream_timings(ic); + + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + if (st->time_base.den) + av_log(ic, AV_LOG_TRACE, "stream %u: start_time: %s duration: %s\n", i, + av_ts2timestr(st->start_time, &st->time_base), + av_ts2timestr(st->duration, &st->time_base)); + } + av_log(ic, AV_LOG_TRACE, + "format: start_time: %s duration: %s (estimate from %s) bitrate=%"PRId64" kb/s\n", + av_ts2timestr(ic->start_time, &AV_TIME_BASE_Q), + av_ts2timestr(ic->duration, &AV_TIME_BASE_Q), + duration_estimate_name(ic->duration_estimation_method), + (int64_t)ic->bit_rate / 1000); +} + +static int determinable_frame_size(const AVCodecContext *avctx) +{ + switch(avctx->codec_id) { + case AV_CODEC_ID_MP1: + case AV_CODEC_ID_MP2: + case AV_CODEC_ID_MP3: + case AV_CODEC_ID_CODEC2: + return 1; + } + + return 0; +} + +static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr) +{ + const FFStream *const sti = cffstream(st); + const AVCodecContext *const avctx = sti->avctx; + +#define FAIL(errmsg) do { \ + if (errmsg_ptr) \ + *errmsg_ptr = errmsg; \ + return 0; \ + } while (0) + + if ( avctx->codec_id == AV_CODEC_ID_NONE + && avctx->codec_type != AVMEDIA_TYPE_DATA) + FAIL("unknown codec"); + switch (avctx->codec_type) { + case AVMEDIA_TYPE_AUDIO: + if (!avctx->frame_size && determinable_frame_size(avctx)) + FAIL("unspecified frame size"); + if (sti->info->found_decoder >= 0 && + avctx->sample_fmt == AV_SAMPLE_FMT_NONE) + FAIL("unspecified sample format"); + if (!avctx->sample_rate) + FAIL("unspecified sample rate"); + if (!avctx->channels) + FAIL("unspecified number of channels"); + if (sti->info->found_decoder >= 0 && !sti->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) + FAIL("no decodable DTS frames"); + break; + case AVMEDIA_TYPE_VIDEO: + if (!avctx->width) + FAIL("unspecified size"); + if (sti->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) + FAIL("unspecified pixel format"); + if (st->codecpar->codec_id == AV_CODEC_ID_RV30 || st->codecpar->codec_id == AV_CODEC_ID_RV40) + if (!st->sample_aspect_ratio.num && !st->codecpar->sample_aspect_ratio.num && !sti->codec_info_nb_frames) + FAIL("no frame in rv30/40 and no sar"); + break; + case AVMEDIA_TYPE_SUBTITLE: + if (avctx->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE && !avctx->width) + FAIL("unspecified size"); + break; + case AVMEDIA_TYPE_DATA: + if (avctx->codec_id == AV_CODEC_ID_NONE) return 1; + } + + return 1; +} + +/* returns 1 or 0 if or if not decoded data was returned, or a negative error */ +static int try_decode_frame(AVFormatContext *s, AVStream *st, + const AVPacket *avpkt, AVDictionary **options) +{ + FFStream *const sti = ffstream(st); + AVCodecContext *const avctx = sti->avctx; + const AVCodec *codec; + int got_picture = 1, ret = 0; + AVFrame *frame = av_frame_alloc(); + AVSubtitle subtitle; + AVPacket pkt = *avpkt; + int do_skip_frame = 0; + enum AVDiscard skip_frame; + + if (!frame) + return AVERROR(ENOMEM); + + if (!avcodec_is_open(avctx) && + sti->info->found_decoder <= 0 && + (st->codecpar->codec_id != -sti->info->found_decoder || !st->codecpar->codec_id)) { + AVDictionary *thread_opt = NULL; + + codec = find_probe_decoder(s, st, st->codecpar->codec_id); + + if (!codec) { + sti->info->found_decoder = -st->codecpar->codec_id; + ret = -1; + goto fail; + } + + /* Force thread count to 1 since the H.264 decoder will not extract + * SPS and PPS to extradata during multi-threaded decoding. */ + av_dict_set(options ? options : &thread_opt, "threads", "1", 0); + /* Force lowres to 0. The decoder might reduce the video size by the + * lowres factor, and we don't want that propagated to the stream's + * codecpar */ + av_dict_set(options ? options : &thread_opt, "lowres", "0", 0); + if (s->codec_whitelist) + av_dict_set(options ? options : &thread_opt, "codec_whitelist", s->codec_whitelist, 0); + ret = avcodec_open2(avctx, codec, options ? options : &thread_opt); + if (!options) + av_dict_free(&thread_opt); + if (ret < 0) { + sti->info->found_decoder = -avctx->codec_id; + goto fail; + } + sti->info->found_decoder = 1; + } else if (!sti->info->found_decoder) + sti->info->found_decoder = 1; + + if (sti->info->found_decoder < 0) { + ret = -1; + goto fail; + } + + if (avpriv_codec_get_cap_skip_frame_fill_param(avctx->codec)) { + do_skip_frame = 1; + skip_frame = avctx->skip_frame; + avctx->skip_frame = AVDISCARD_ALL; + } + + while ((pkt.size > 0 || (!pkt.data && got_picture)) && + ret >= 0 && + (!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) || + (!sti->codec_info_nb_frames && + (avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)))) { + got_picture = 0; + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO || + avctx->codec_type == AVMEDIA_TYPE_AUDIO) { + ret = avcodec_send_packet(avctx, &pkt); + if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) + break; + if (ret >= 0) + pkt.size = 0; + ret = avcodec_receive_frame(avctx, frame); + if (ret >= 0) + got_picture = 1; + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) + ret = 0; + } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { + ret = avcodec_decode_subtitle2(avctx, &subtitle, + &got_picture, &pkt); + if (got_picture) + avsubtitle_free(&subtitle); + if (ret >= 0) + pkt.size = 0; + } + if (ret >= 0) { + if (got_picture) + sti->nb_decoded_frames++; + ret = got_picture; + } + } + + if (!pkt.data && !got_picture) + ret = -1; + +fail: + if (do_skip_frame) { + avctx->skip_frame = skip_frame; + } + + av_frame_free(&frame); + return ret; +} + +static int chapter_start_cmp(const void *p1, const void *p2) +{ + const AVChapter *const ch1 = *(AVChapter**)p1; + const AVChapter *const ch2 = *(AVChapter**)p2; + int delta = av_compare_ts(ch1->start, ch1->time_base, ch2->start, ch2->time_base); + if (delta) + return delta; + return FFDIFFSIGN(ch1->id, ch2->id); +} + +static int compute_chapters_end(AVFormatContext *s) +{ + int64_t max_time = 0; + AVChapter **timetable; + + if (!s->nb_chapters) + return 0; + + if (s->duration > 0 && s->start_time < INT64_MAX - s->duration) + max_time = s->duration + + ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time); + + timetable = av_memdup(s->chapters, s->nb_chapters * sizeof(*timetable)); + if (!timetable) + return AVERROR(ENOMEM); + qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp); + + for (unsigned i = 0; i < s->nb_chapters; i++) + if (timetable[i]->end == AV_NOPTS_VALUE) { + AVChapter *const ch = timetable[i]; + int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q, + ch->time_base) + : INT64_MAX; + + if (i + 1 < s->nb_chapters) { + const AVChapter *const ch1 = timetable[i + 1]; + int64_t next_start = av_rescale_q(ch1->start, ch1->time_base, + ch->time_base); + if (next_start > ch->start && next_start < end) + end = next_start; + } + ch->end = (end == INT64_MAX || end < ch->start) ? ch->start : end; + } + av_free(timetable); + return 0; +} + +static int get_std_framerate(int i) +{ + if (i < 30*12) + return (i + 1) * 1001; + i -= 30*12; + + if (i < 30) + return (i + 31) * 1001 * 12; + i -= 30; + + if (i < 3) + return ((const int[]) { 80, 120, 240})[i] * 1001 * 12; + + i -= 3; + + return ((const int[]) { 24, 30, 60, 12, 15, 48 })[i] * 1000 * 12; +} + +/* Is the time base unreliable? + * This is a heuristic to balance between quick acceptance of the values in + * the headers vs. some extra checks. + * Old DivX and Xvid often have nonsense timebases like 1fps or 2fps. + * MPEG-2 commonly misuses field repeat flags to store different framerates. + * And there are "variable" fps files this needs to detect as well. */ +static int tb_unreliable(AVCodecContext *c) +{ + if (c->time_base.den >= 101LL * c->time_base.num || + c->time_base.den < 5LL * c->time_base.num || + // c->codec_tag == AV_RL32("DIVX") || + // c->codec_tag == AV_RL32("XVID") || + c->codec_tag == AV_RL32("mp4v") || + c->codec_id == AV_CODEC_ID_MPEG2VIDEO || + c->codec_id == AV_CODEC_ID_GIF || + c->codec_id == AV_CODEC_ID_HEVC || + c->codec_id == AV_CODEC_ID_H264) + return 1; + return 0; +} + +int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) +{ + FFStream *const sti = ffstream(st); + int64_t last = sti->info->last_dts; + + if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last + && ts - (uint64_t)last < INT64_MAX) { + double dts = (is_relative(ts) ? ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base); + int64_t duration = ts - last; + + if (!sti->info->duration_error) + sti->info->duration_error = av_mallocz(sizeof(sti->info->duration_error[0])*2); + if (!sti->info->duration_error) + return AVERROR(ENOMEM); + +// if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) +// av_log(NULL, AV_LOG_ERROR, "%f\n", dts); + for (int i = 0; i < MAX_STD_TIMEBASES; i++) { + if (sti->info->duration_error[0][1][i] < 1e10) { + int framerate = get_std_framerate(i); + double sdts = dts*framerate/(1001*12); + for (int j = 0; j < 2; j++) { + int64_t ticks = llrint(sdts+j*0.5); + double error = sdts - ticks + j*0.5; + sti->info->duration_error[j][0][i] += error; + sti->info->duration_error[j][1][i] += error*error; + } + } + } + if (sti->info->rfps_duration_sum <= INT64_MAX - duration) { + sti->info->duration_count++; + sti->info->rfps_duration_sum += duration; + } + + if (sti->info->duration_count % 10 == 0) { + int n = sti->info->duration_count; + for (int i = 0; i < MAX_STD_TIMEBASES; i++) { + if (sti->info->duration_error[0][1][i] < 1e10) { + double a0 = sti->info->duration_error[0][0][i] / n; + double error0 = sti->info->duration_error[0][1][i] / n - a0*a0; + double a1 = sti->info->duration_error[1][0][i] / n; + double error1 = sti->info->duration_error[1][1][i] / n - a1*a1; + if (error0 > 0.04 && error1 > 0.04) { + sti->info->duration_error[0][1][i] = 2e10; + sti->info->duration_error[1][1][i] = 2e10; + } + } + } + } + + // ignore the first 4 values, they might have some random jitter + if (sti->info->duration_count > 3 && is_relative(ts) == is_relative(last)) + sti->info->duration_gcd = av_gcd(sti->info->duration_gcd, duration); + } + if (ts != AV_NOPTS_VALUE) + sti->info->last_dts = ts; + + return 0; +} + +void ff_rfps_calculate(AVFormatContext *ic) +{ + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); + + if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) + continue; + // the check for tb_unreliable() is not completely correct, since this is not about handling + // an unreliable/inexact time base, but a time base that is finer than necessary, as e.g. + // ipmovie.c produces. + if (tb_unreliable(sti->avctx) && sti->info->duration_count > 15 && sti->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num && + sti->info->duration_gcd < INT64_MAX / st->time_base.num) + av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * sti->info->duration_gcd, INT_MAX); + if (sti->info->duration_count > 1 && !st->r_frame_rate.num + && tb_unreliable(sti->avctx)) { + int num = 0; + double best_error = 0.01; + AVRational ref_rate = st->r_frame_rate.num ? st->r_frame_rate : av_inv_q(st->time_base); + + for (int j = 0; j < MAX_STD_TIMEBASES; j++) { + if (sti->info->codec_info_duration && + sti->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) + continue; + if (!sti->info->codec_info_duration && get_std_framerate(j) < 1001*12) + continue; + + if (av_q2d(st->time_base) * sti->info->rfps_duration_sum / sti->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) + continue; + + for (int k = 0; k < 2; k++) { + int n = sti->info->duration_count; + double a = sti->info->duration_error[k][0][j] / n; + double error = sti->info->duration_error[k][1][j]/n - a*a; + + if (error < best_error && best_error> 0.000000001) { + best_error= error; + num = get_std_framerate(j); + } + if (error < 0.02) + av_log(ic, AV_LOG_DEBUG, "rfps: %f %f\n", get_std_framerate(j) / 12.0/1001, error); + } + } + // do not increase frame rate by more than 1 % in order to match a standard rate. + if (num && (!ref_rate.num || (double)num/(12*1001) < 1.01 * av_q2d(ref_rate))) + av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX); + } + if ( !st->avg_frame_rate.num + && st->r_frame_rate.num && sti->info->rfps_duration_sum + && sti->info->codec_info_duration <= 0 + && sti->info->duration_count > 2 + && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - sti->info->rfps_duration_sum / (double)sti->info->duration_count) <= 1.0 + ) { + av_log(ic, AV_LOG_DEBUG, "Setting avg frame rate based on r frame rate\n"); + st->avg_frame_rate = st->r_frame_rate; + } + + av_freep(&sti->info->duration_error); + sti->info->last_dts = AV_NOPTS_VALUE; + sti->info->duration_count = 0; + sti->info->rfps_duration_sum = 0; + } +} + +static int extract_extradata_check(AVStream *st) +{ + const AVBitStreamFilter *f = av_bsf_get_by_name("extract_extradata"); + if (!f) + return 0; + + if (f->codec_ids) { + const enum AVCodecID *ids; + for (ids = f->codec_ids; *ids != AV_CODEC_ID_NONE; ids++) + if (*ids == st->codecpar->codec_id) + return 1; + } + + return 0; +} + +static int extract_extradata_init(AVStream *st) +{ + FFStream *const sti = ffstream(st); + const AVBitStreamFilter *f; + int ret; + + f = av_bsf_get_by_name("extract_extradata"); + if (!f) + goto finish; + + /* check that the codec id is supported */ + ret = extract_extradata_check(st); + if (!ret) + goto finish; + + ret = av_bsf_alloc(f, &sti->extract_extradata.bsf); + if (ret < 0) + return ret; + + ret = avcodec_parameters_copy(sti->extract_extradata.bsf->par_in, + st->codecpar); + if (ret < 0) + goto fail; + + sti->extract_extradata.bsf->time_base_in = st->time_base; + + ret = av_bsf_init(sti->extract_extradata.bsf); + if (ret < 0) + goto fail; + +finish: + sti->extract_extradata.inited = 1; + + return 0; +fail: + av_bsf_free(&sti->extract_extradata.bsf); + return ret; +} + +static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt) +{ + FFStream *const sti = ffstream(st); + AVPacket *const pkt_ref = si->parse_pkt; + int ret; + + if (!sti->extract_extradata.inited) { + ret = extract_extradata_init(st); + if (ret < 0) + return ret; + } + + if (sti->extract_extradata.inited && !sti->extract_extradata.bsf) + return 0; + + ret = av_packet_ref(pkt_ref, pkt); + if (ret < 0) + return ret; + + ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref); + if (ret < 0) { + av_packet_unref(pkt_ref); + return ret; + } + + while (ret >= 0 && !sti->avctx->extradata) { + ret = av_bsf_receive_packet(sti->extract_extradata.bsf, pkt_ref); + if (ret < 0) { + if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) + return ret; + continue; + } + + for (int i = 0; i < pkt_ref->side_data_elems; i++) { + AVPacketSideData *const side_data = &pkt_ref->side_data[i]; + if (side_data->type == AV_PKT_DATA_NEW_EXTRADATA) { + sti->avctx->extradata = side_data->data; + sti->avctx->extradata_size = side_data->size; + side_data->data = NULL; + side_data->size = 0; + break; + } + } + av_packet_unref(pkt_ref); + } + + return 0; +} + +static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) +{ + for (int i = 0; i < avctx->nb_coded_side_data; i++) { + const AVPacketSideData *const sd_src = &avctx->coded_side_data[i]; + uint8_t *dst_data; + dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size); + if (!dst_data) + return AVERROR(ENOMEM); + memcpy(dst_data, sd_src->data, sd_src->size); + } + return 0; +} + +int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) +{ + FFFormatContext *const si = ffformatcontext(ic); + int count = 0, ret = 0; + int64_t read_size; + AVPacket *pkt1 = si->pkt; + int64_t old_offset = avio_tell(ic->pb); + // new streams might appear, no options for those + int orig_nb_streams = ic->nb_streams; + int flush_codecs; + int64_t max_analyze_duration = ic->max_analyze_duration; + int64_t max_stream_analyze_duration; + int64_t max_subtitle_analyze_duration; + int64_t probesize = ic->probesize; + int eof_reached = 0; + int *missing_streams = av_opt_ptr(ic->iformat->priv_class, ic->priv_data, "missing_streams"); + + flush_codecs = probesize > 0; + + av_opt_set(ic, "skip_clear", "1", AV_OPT_SEARCH_CHILDREN); + + max_stream_analyze_duration = max_analyze_duration; + max_subtitle_analyze_duration = max_analyze_duration; + if (!max_analyze_duration) { + max_stream_analyze_duration = + max_analyze_duration = 5*AV_TIME_BASE; + max_subtitle_analyze_duration = 30*AV_TIME_BASE; + if (!strcmp(ic->iformat->name, "flv")) + max_stream_analyze_duration = 90*AV_TIME_BASE; + if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts")) + max_stream_analyze_duration = 7*AV_TIME_BASE; + } + + if (ic->pb) { + FFIOContext *const ctx = ffiocontext(ic->pb); + av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d nb_streams:%d\n", + avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, ic->nb_streams); + } + + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVCodec *codec; + AVDictionary *thread_opt = NULL; + AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); + AVCodecContext *const avctx = sti->avctx; + + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { +/* if (!st->time_base.num) + st->time_base = */ + if (!avctx->time_base.num) + avctx->time_base = st->time_base; + } + + /* check if the caller has overridden the codec id */ + // only for the split stuff + if (!sti->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && sti->request_probe <= 0) { + sti->parser = av_parser_init(st->codecpar->codec_id); + if (sti->parser) { + if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) { + sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; + } else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) { + sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; + } + } else if (sti->need_parsing) { + av_log(ic, AV_LOG_VERBOSE, "parser not found for codec " + "%s, packets or times may be invalid.\n", + avcodec_get_name(st->codecpar->codec_id)); + } + } + + ret = avcodec_parameters_to_context(avctx, st->codecpar); + if (ret < 0) + goto find_stream_info_err; + if (sti->request_probe <= 0) + sti->avctx_inited = 1; + + codec = find_probe_decoder(ic, st, st->codecpar->codec_id); + + /* Force thread count to 1 since the H.264 decoder will not extract + * SPS and PPS to extradata during multi-threaded decoding. */ + av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0); + /* Force lowres to 0. The decoder might reduce the video size by the + * lowres factor, and we don't want that propagated to the stream's + * codecpar */ + av_dict_set(options ? &options[i] : &thread_opt, "lowres", "0", 0); + + if (ic->codec_whitelist) + av_dict_set(options ? &options[i] : &thread_opt, "codec_whitelist", ic->codec_whitelist, 0); + + // Try to just open decoders, in case this is enough to get parameters. + // Also ensure that subtitle_header is properly set. + if (!has_codec_parameters(st, NULL) && sti->request_probe <= 0 || + st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { + if (codec && !avctx->codec) + if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0) + av_log(ic, AV_LOG_WARNING, + "Failed to open codec in %s\n",__FUNCTION__); + } + if (!options) + av_dict_free(&thread_opt); + } + + read_size = 0; + for (;;) { + const AVPacket *pkt; + AVStream *st; + FFStream *sti; + AVCodecContext *avctx; + int analyzed_all_streams; + unsigned i; + if (ff_check_interrupt(&ic->interrupt_callback)) { + ret = AVERROR_EXIT; + av_log(ic, AV_LOG_DEBUG, "interrupted\n"); + break; + } + + /* check if one codec still needs to be handled */ + for (i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); + int fps_analyze_framecount = 20; + int count; + + if (!has_codec_parameters(st, NULL)) + break; + /* If the timebase is coarse (like the usual millisecond precision + * of mkv), we need to analyze more frames to reliably arrive at + * the correct fps. */ + if (av_q2d(st->time_base) > 0.0005) + fps_analyze_framecount *= 2; + if (!tb_unreliable(sti->avctx)) + fps_analyze_framecount = 0; + if (ic->fps_probe_size >= 0) + fps_analyze_framecount = ic->fps_probe_size; + if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) + fps_analyze_framecount = 0; + /* variable fps and no guess at the real fps */ + count = (ic->iformat->flags & AVFMT_NOTIMESTAMPS) ? + sti->info->codec_info_duration_fields/2 : + sti->info->duration_count; + if (!(st->r_frame_rate.num && st->avg_frame_rate.num) && + st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (count < fps_analyze_framecount) + break; + } + // Look at the first 3 frames if there is evidence of frame delay + // but the decoder delay is not set. + if (sti->info->frame_delay_evidence && count < 2 && sti->avctx->has_b_frames == 0) + break; + if (!sti->avctx->extradata && + (!sti->extract_extradata.inited || sti->extract_extradata.bsf) && + extract_extradata_check(st)) + break; + if (sti->first_dts == AV_NOPTS_VALUE && + !(ic->iformat->flags & AVFMT_NOTIMESTAMPS) && + sti->codec_info_nb_frames < ((st->disposition & AV_DISPOSITION_ATTACHED_PIC) ? 1 : ic->max_ts_probe) && + (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) + break; + } + analyzed_all_streams = 0; + if (!missing_streams || !*missing_streams) + if (i == ic->nb_streams) { + analyzed_all_streams = 1; + /* NOTE: If the format has no header, then we need to read some + * packets to get most of the streams, so we cannot stop here. */ + if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) { + /* If we found the info for all the codecs, we can stop. */ + ret = count; + av_log(ic, AV_LOG_DEBUG, "All info found\n"); + flush_codecs = 0; + break; + } + } + /* We did not get all the codec info, but we read too much data. */ + if (read_size >= probesize) { + ret = count; + av_log(ic, AV_LOG_DEBUG, + "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + if (!st->r_frame_rate.num && + ffstream(st)->info->duration_count <= 1 && + st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + strcmp(ic->iformat->name, "image2")) + av_log(ic, AV_LOG_WARNING, + "Stream #%d: not enough frames to estimate rate; " + "consider increasing probesize\n", i); + } + break; + } + + /* NOTE: A new stream can be added there if no header in file + * (AVFMTCTX_NOHEADER). */ + ret = read_frame_internal(ic, pkt1); + if (ret == AVERROR(EAGAIN)) + continue; + + if (ret < 0) { + /* EOF or error*/ + eof_reached = 1; + break; + } + + if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { + ret = avpriv_packet_list_put(&si->packet_buffer, + &si->packet_buffer_end, + pkt1, NULL, 0); + if (ret < 0) + goto unref_then_goto_end; + + pkt = &si->packet_buffer_end->pkt; + } else { + pkt = pkt1; + } + + st = ic->streams[pkt->stream_index]; + sti = ffstream(st); + if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) + read_size += pkt->size; + + avctx = sti->avctx; + if (!sti->avctx_inited) { + ret = avcodec_parameters_to_context(avctx, st->codecpar); + if (ret < 0) + goto unref_then_goto_end; + sti->avctx_inited = 1; + } + + if (pkt->dts != AV_NOPTS_VALUE && sti->codec_info_nb_frames > 1) { + /* check for non-increasing dts */ + if (sti->info->fps_last_dts != AV_NOPTS_VALUE && + sti->info->fps_last_dts >= pkt->dts) { + av_log(ic, AV_LOG_DEBUG, + "Non-increasing DTS in stream %d: packet %d with DTS " + "%"PRId64", packet %d with DTS %"PRId64"\n", + st->index, sti->info->fps_last_dts_idx, + sti->info->fps_last_dts, sti->codec_info_nb_frames, + pkt->dts); + sti->info->fps_first_dts = + sti->info->fps_last_dts = AV_NOPTS_VALUE; + } + /* Check for a discontinuity in dts. If the difference in dts + * is more than 1000 times the average packet duration in the + * sequence, we treat it as a discontinuity. */ + if (sti->info->fps_last_dts != AV_NOPTS_VALUE && + sti->info->fps_last_dts_idx > sti->info->fps_first_dts_idx && + (pkt->dts - (uint64_t)sti->info->fps_last_dts) / 1000 > + (sti->info->fps_last_dts - (uint64_t)sti->info->fps_first_dts) / + (sti->info->fps_last_dts_idx - sti->info->fps_first_dts_idx)) { + av_log(ic, AV_LOG_WARNING, + "DTS discontinuity in stream %d: packet %d with DTS " + "%"PRId64", packet %d with DTS %"PRId64"\n", + st->index, sti->info->fps_last_dts_idx, + sti->info->fps_last_dts, sti->codec_info_nb_frames, + pkt->dts); + sti->info->fps_first_dts = + sti->info->fps_last_dts = AV_NOPTS_VALUE; + } + + /* update stored dts values */ + if (sti->info->fps_first_dts == AV_NOPTS_VALUE) { + sti->info->fps_first_dts = pkt->dts; + sti->info->fps_first_dts_idx = sti->codec_info_nb_frames; + } + sti->info->fps_last_dts = pkt->dts; + sti->info->fps_last_dts_idx = sti->codec_info_nb_frames; + } + if (sti->codec_info_nb_frames > 1) { + int64_t t = 0; + int64_t limit; + + if (st->time_base.den > 0) + t = av_rescale_q(sti->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); + if (st->avg_frame_rate.num > 0) + t = FFMAX(t, av_rescale_q(sti->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); + + if ( t == 0 + && sti->codec_info_nb_frames > 30 + && sti->info->fps_first_dts != AV_NOPTS_VALUE + && sti->info->fps_last_dts != AV_NOPTS_VALUE) { + int64_t dur = av_sat_sub64(sti->info->fps_last_dts, sti->info->fps_first_dts); + t = FFMAX(t, av_rescale_q(dur, st->time_base, AV_TIME_BASE_Q)); + } + + if (analyzed_all_streams) limit = max_analyze_duration; + else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) limit = max_subtitle_analyze_duration; + else limit = max_stream_analyze_duration; + + if (t >= limit) { + av_log(ic, AV_LOG_VERBOSE, "max_analyze_duration %"PRId64" reached at %"PRId64" microseconds st:%d\n", + limit, + t, pkt->stream_index); + if (ic->flags & AVFMT_FLAG_NOBUFFER) + av_packet_unref(pkt1); + break; + } + if (pkt->duration) { + if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time + && (uint64_t)pkt->pts - st->start_time < INT64_MAX + ) { + sti->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, sti->info->codec_info_duration + pkt->duration); + } else + sti->info->codec_info_duration += pkt->duration; + sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && avctx->ticks_per_frame == 2 + ? sti->parser->repeat_pict + 1 : 2; + } + } + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { +#if FF_API_R_FRAME_RATE + ff_rfps_add_frame(ic, st, pkt->dts); +#endif + if (pkt->dts != pkt->pts && pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) + sti->info->frame_delay_evidence = 1; + } + if (!sti->avctx->extradata) { + ret = extract_extradata(si, st, pkt); + if (ret < 0) + goto unref_then_goto_end; + } + + /* If still no information, we try to open the codec and to + * decompress the frame. We try to avoid that in most cases as + * it takes longer and uses more memory. For MPEG-4, we need to + * decompress for QuickTime. + * + * If AV_CODEC_CAP_CHANNEL_CONF is set this will force decoding of at + * least one frame of codec data, this makes sure the codec initializes + * the channel configuration and does not only trust the values from + * the container. */ + try_decode_frame(ic, st, pkt, + (options && i < orig_nb_streams) ? &options[i] : NULL); + + if (ic->flags & AVFMT_FLAG_NOBUFFER) + av_packet_unref(pkt1); + + sti->codec_info_nb_frames++; + count++; + } + + if (eof_reached) { + for (unsigned stream_index = 0; stream_index < ic->nb_streams; stream_index++) { + AVStream *const st = ic->streams[stream_index]; + AVCodecContext *const avctx = ffstream(st)->avctx; + if (!has_codec_parameters(st, NULL)) { + const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id); + if (codec && !avctx->codec) { + AVDictionary *opts = NULL; + if (ic->codec_whitelist) + av_dict_set(&opts, "codec_whitelist", ic->codec_whitelist, 0); + if (avcodec_open2(avctx, codec, (options && stream_index < orig_nb_streams) ? &options[stream_index] : &opts) < 0) + av_log(ic, AV_LOG_WARNING, + "Failed to open codec in %s\n",__FUNCTION__); + av_dict_free(&opts); + } + } + + // EOF already reached while reading the stream above. + // So continue with reoordering DTS with whatever delay we have. + if (si->packet_buffer && !has_decode_delay_been_guessed(st)) { + update_dts_from_pts(ic, stream_index, si->packet_buffer); + } + } + } + + if (flush_codecs) { + AVPacket *empty_pkt = si->pkt; + int err = 0; + av_packet_unref(empty_pkt); + + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + + /* flush the decoders */ + if (ffstream(st)->info->found_decoder == 1) { + do { + err = try_decode_frame(ic, st, empty_pkt, + (options && i < orig_nb_streams) + ? &options[i] : NULL); + } while (err > 0 && !has_codec_parameters(st, NULL)); + + if (err < 0) { + av_log(ic, AV_LOG_INFO, + "decoding for stream %d failed\n", st->index); + } + } + } + } + + ff_rfps_calculate(ic); + + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); + AVCodecContext *const avctx = sti->avctx; + + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { + if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) { + uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); + if (avpriv_find_pix_fmt(avpriv_get_raw_pix_fmt_tags(), tag) == avctx->pix_fmt) + avctx->codec_tag= tag; + } + + /* estimate average framerate if not set by demuxer */ + if (sti->info->codec_info_duration_fields && + !st->avg_frame_rate.num && + sti->info->codec_info_duration) { + int best_fps = 0; + double best_error = 0.01; + AVRational codec_frame_rate = avctx->framerate; + + if (sti->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| + sti->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || + sti->info->codec_info_duration < 0) + continue; + av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, + sti->info->codec_info_duration_fields * (int64_t) st->time_base.den, + sti->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); + + /* Round guessed framerate to a "standard" framerate if it's + * within 1% of the original estimate. */ + for (int j = 0; j < MAX_STD_TIMEBASES; j++) { + AVRational std_fps = { get_std_framerate(j), 12 * 1001 }; + double error = fabs(av_q2d(st->avg_frame_rate) / + av_q2d(std_fps) - 1); + + if (error < best_error) { + best_error = error; + best_fps = std_fps.num; + } + + if (si->prefer_codec_framerate && codec_frame_rate.num > 0 && codec_frame_rate.den > 0) { + error = fabs(av_q2d(codec_frame_rate) / + av_q2d(std_fps) - 1); + if (error < best_error) { + best_error = error; + best_fps = std_fps.num; + } + } + } + if (best_fps) + av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, + best_fps, 12 * 1001, INT_MAX); + } + + if (!st->r_frame_rate.num) { + if ( avctx->time_base.den * (int64_t) st->time_base.num + <= avctx->time_base.num * (uint64_t)avctx->ticks_per_frame * st->time_base.den) { + av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, + avctx->time_base.den, (int64_t)avctx->time_base.num * avctx->ticks_per_frame, INT_MAX); + } else { + st->r_frame_rate.num = st->time_base.den; + st->r_frame_rate.den = st->time_base.num; + } + } + if (sti->display_aspect_ratio.num && sti->display_aspect_ratio.den) { + AVRational hw_ratio = { avctx->height, avctx->width }; + st->sample_aspect_ratio = av_mul_q(sti->display_aspect_ratio, + hw_ratio); + } + } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { + if (!avctx->bits_per_coded_sample) + avctx->bits_per_coded_sample = + av_get_bits_per_sample(avctx->codec_id); + // set stream disposition based on audio service type + switch (avctx->audio_service_type) { + case AV_AUDIO_SERVICE_TYPE_EFFECTS: + st->disposition = AV_DISPOSITION_CLEAN_EFFECTS; + break; + case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: + st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED; + break; + case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: + st->disposition = AV_DISPOSITION_HEARING_IMPAIRED; + break; + case AV_AUDIO_SERVICE_TYPE_COMMENTARY: + st->disposition = AV_DISPOSITION_COMMENT; + break; + case AV_AUDIO_SERVICE_TYPE_KARAOKE: + st->disposition = AV_DISPOSITION_KARAOKE; + break; + } + } + } + + if (probesize) + estimate_timings(ic, old_offset); + + av_opt_set(ic, "skip_clear", "0", AV_OPT_SEARCH_CHILDREN); + + if (ret >= 0 && ic->nb_streams) + /* We could not have all the codec parameters before EOF. */ + ret = -1; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); + const char *errmsg; + + /* if no packet was ever seen, update context now for has_codec_parameters */ + if (!sti->avctx_inited) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + st->codecpar->format == AV_SAMPLE_FMT_NONE) + st->codecpar->format = sti->avctx->sample_fmt; + ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); + if (ret < 0) + goto find_stream_info_err; + } + if (!has_codec_parameters(st, &errmsg)) { + char buf[256]; + avcodec_string(buf, sizeof(buf), sti->avctx, 0); + av_log(ic, AV_LOG_WARNING, + "Could not find codec parameters for stream %d (%s): %s\n" + "Consider increasing the value for the 'analyzeduration' (%"PRId64") and 'probesize' (%"PRId64") options\n", + i, buf, errmsg, ic->max_analyze_duration, ic->probesize); + } else { + ret = 0; + } + } + + ret = compute_chapters_end(ic); + if (ret < 0) + goto find_stream_info_err; + + /* update the stream parameters from the internal codec contexts */ + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); + + if (sti->avctx_inited) { + ret = avcodec_parameters_from_context(st->codecpar, sti->avctx); + if (ret < 0) + goto find_stream_info_err; + ret = add_coded_side_data(st, sti->avctx); + if (ret < 0) + goto find_stream_info_err; + } + + sti->avctx_inited = 0; + } + +find_stream_info_err: + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); + if (sti->info) { + av_freep(&sti->info->duration_error); + av_freep(&sti->info); + } + avcodec_close(sti->avctx); + av_bsf_free(&sti->extract_extradata.bsf); + } + if (ic->pb) { + FFIOContext *const ctx = ffiocontext(ic->pb); + av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n", + avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, count); + } + return ret; + +unref_then_goto_end: + av_packet_unref(pkt1); + goto find_stream_info_err; +} diff --git a/libavformat/internal.h b/libavformat/internal.h index 377d980178..2428085019 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -651,6 +651,8 @@ void ff_reduce_index(AVFormatContext *s, int stream_index); enum AVCodecID ff_guess_image2_codec(const char *filename); +const AVCodec *ff_find_decoder(AVFormatContext *s, const AVStream *st, + enum AVCodecID codec_id); /** * Perform a binary search using av_index_search_timestamp() and * AVInputFormat.read_timestamp(). diff --git a/libavformat/utils.c b/libavformat/utils.c index 449c138700..788e12912b 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -28,28 +28,23 @@ #include "libavutil/bprint.h" #include "libavutil/dict.h" #include "libavutil/internal.h" -#include "libavutil/mathematics.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "libavutil/pixfmt.h" #include "libavutil/thread.h" #include "libavutil/time.h" -#include "libavutil/timestamp.h" #include "libavcodec/bsf.h" #include "libavcodec/bytestream.h" #include "libavcodec/internal.h" #include "libavcodec/packet_internal.h" -#include "libavcodec/raw.h" #include "avformat.h" #include "avio_internal.h" -#include "id3v2.h" #include "internal.h" #if CONFIG_NETWORK #include "network.h" #endif -#include "url.h" #include "libavutil/ffversion.h" const char av_format_ffversion[] = "FFmpeg version " FFMPEG_VERSION; @@ -88,26 +83,6 @@ int ff_unlock_avformat(void) return ff_mutex_unlock(&avformat_mutex) ? -1 : 0; } -static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) -{ - const FFStream *const sti = cffstream(st); - if (sti->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 && - sti->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { - if (sti->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && - timestamp < sti->pts_wrap_reference) - return timestamp + (1ULL << st->pts_wrap_bits); - else if (sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && - timestamp >= sti->pts_wrap_reference) - return timestamp - (1ULL << st->pts_wrap_bits); - } - return timestamp; -} - -int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp) -{ - return wrap_timestamp(st, timestamp); -} - int64_t av_stream_get_end_pts(const AVStream *st) { if (cffstream(st)->priv_pts) { @@ -155,7 +130,8 @@ int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src) return 0; } -static const AVCodec *find_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id) +const AVCodec *ff_find_decoder(AVFormatContext *s, const AVStream *st, + enum AVCodecID codec_id) { switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: @@ -172,36 +148,6 @@ static const AVCodec *find_decoder(AVFormatContext *s, const AVStream *st, enum return avcodec_find_decoder(codec_id); } -static const AVCodec *find_probe_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id) -{ - const AVCodec *codec; - -#if CONFIG_H264_DECODER - /* Other parts of the code assume this decoder to be used for h264, - * so force it if possible. */ - if (codec_id == AV_CODEC_ID_H264) - return avcodec_find_decoder_by_name("h264"); -#endif - - codec = find_decoder(s, st, codec_id); - if (!codec) - return NULL; - - if (codec->capabilities & AV_CODEC_CAP_AVOID_PROBING) { - const AVCodec *probe_codec = NULL; - void *iter = NULL; - while ((probe_codec = av_codec_iterate(&iter))) { - if (probe_codec->id == codec->id && - av_codec_is_decoder(probe_codec) && - !(probe_codec->capabilities & (AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_EXPERIMENTAL))) { - return probe_codec; - } - } - } - - return codec; -} - /* an arbitrarily chosen "sane" max packet size -- 50M */ #define SANE_CHUNK_SIZE (50000000) @@ -276,93 +222,6 @@ int av_filename_number_test(const char *filename) (av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 0); } -static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, - AVProbeData *pd) -{ - static const struct { - const char *name; - enum AVCodecID id; - enum AVMediaType type; - } fmt_id_type[] = { - { "aac", AV_CODEC_ID_AAC, AVMEDIA_TYPE_AUDIO }, - { "ac3", AV_CODEC_ID_AC3, AVMEDIA_TYPE_AUDIO }, - { "aptx", AV_CODEC_ID_APTX, AVMEDIA_TYPE_AUDIO }, - { "dts", AV_CODEC_ID_DTS, AVMEDIA_TYPE_AUDIO }, - { "dvbsub", AV_CODEC_ID_DVB_SUBTITLE,AVMEDIA_TYPE_SUBTITLE }, - { "dvbtxt", AV_CODEC_ID_DVB_TELETEXT,AVMEDIA_TYPE_SUBTITLE }, - { "eac3", AV_CODEC_ID_EAC3, AVMEDIA_TYPE_AUDIO }, - { "h264", AV_CODEC_ID_H264, AVMEDIA_TYPE_VIDEO }, - { "hevc", AV_CODEC_ID_HEVC, AVMEDIA_TYPE_VIDEO }, - { "loas", AV_CODEC_ID_AAC_LATM, AVMEDIA_TYPE_AUDIO }, - { "m4v", AV_CODEC_ID_MPEG4, AVMEDIA_TYPE_VIDEO }, - { "mjpeg_2000",AV_CODEC_ID_JPEG2000, AVMEDIA_TYPE_VIDEO }, - { "mp3", AV_CODEC_ID_MP3, AVMEDIA_TYPE_AUDIO }, - { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO }, - { "truehd", AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO }, - { 0 } - }; - int score; - const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); - - if (fmt) { - FFStream *const sti = ffstream(st); - av_log(s, AV_LOG_DEBUG, - "Probe with size=%d, packets=%d detected %s with score=%d\n", - pd->buf_size, s->max_probe_packets - sti->probe_packets, - fmt->name, score); - for (int i = 0; fmt_id_type[i].name; i++) { - if (!strcmp(fmt->name, fmt_id_type[i].name)) { - if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO && - st->codecpar->sample_rate) - continue; - if (sti->request_probe > score && - st->codecpar->codec_id != fmt_id_type[i].id) - continue; - st->codecpar->codec_id = fmt_id_type[i].id; - st->codecpar->codec_type = fmt_id_type[i].type; - sti->need_context_update = 1; - return score; - } - } - } - return 0; -} - -/************************************************************/ -/* input media file */ - -/* Open input file and probe the format if necessary. */ -static int init_input(AVFormatContext *s, const char *filename, - AVDictionary **options) -{ - int ret; - AVProbeData pd = { filename, NULL, 0 }; - int score = AVPROBE_SCORE_RETRY; - - if (s->pb) { - s->flags |= AVFMT_FLAG_CUSTOM_IO; - if (!s->iformat) - return av_probe_input_buffer2(s->pb, &s->iformat, filename, - s, 0, s->format_probesize); - else if (s->iformat->flags & AVFMT_NOFILE) - av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and " - "will be ignored with AVFMT_NOFILE format.\n"); - return 0; - } - - if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) || - (!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score)))) - return score; - - if ((ret = s->io_open(s, &s->pb, filename, AVIO_FLAG_READ | s->avio_flags, options)) < 0) - return ret; - - if (s->iformat) - return 0; - return av_probe_input_buffer2(s->pb, &s->iformat, filename, - s, 0, s->format_probesize); -} - int avformat_queue_attached_pictures(AVFormatContext *s) { FFFormatContext *const si = ffformatcontext(s); @@ -422,2960 +281,203 @@ fail: return ret; } -static int update_stream_avctx(AVFormatContext *s) -{ - int ret; - for (unsigned i = 0; i < s->nb_streams; i++) { - AVStream *st = s->streams[i]; - FFStream *const sti = ffstream(st); - - if (!sti->need_context_update) - continue; - - /* close parser, because it depends on the codec */ - if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { - av_parser_close(sti->parser); - sti->parser = NULL; - } - - /* update internal codec context, for the parser */ - ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); - if (ret < 0) - return ret; - - sti->need_context_update = 0; - } - return 0; -} - - -int avformat_open_input(AVFormatContext **ps, const char *filename, - const AVInputFormat *fmt, AVDictionary **options) -{ - AVFormatContext *s = *ps; - FFFormatContext *si; - int ret = 0; - AVDictionary *tmp = NULL; - ID3v2ExtraMeta *id3v2_extra_meta = NULL; - - if (!s && !(s = avformat_alloc_context())) - return AVERROR(ENOMEM); - si = ffformatcontext(s); - if (!s->av_class) { - av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); - return AVERROR(EINVAL); - } - if (fmt) - s->iformat = fmt; - - if (options) - av_dict_copy(&tmp, *options, 0); - - if (s->pb) // must be before any goto fail - s->flags |= AVFMT_FLAG_CUSTOM_IO; - - if ((ret = av_opt_set_dict(s, &tmp)) < 0) - goto fail; - - if (!(s->url = av_strdup(filename ? filename : ""))) { - ret = AVERROR(ENOMEM); - goto fail; - } - - if ((ret = init_input(s, filename, &tmp)) < 0) - goto fail; - s->probe_score = ret; - - if (!s->protocol_whitelist && s->pb && s->pb->protocol_whitelist) { - s->protocol_whitelist = av_strdup(s->pb->protocol_whitelist); - if (!s->protocol_whitelist) { - ret = AVERROR(ENOMEM); - goto fail; - } - } - - if (!s->protocol_blacklist && s->pb && s->pb->protocol_blacklist) { - s->protocol_blacklist = av_strdup(s->pb->protocol_blacklist); - if (!s->protocol_blacklist) { - ret = AVERROR(ENOMEM); - goto fail; - } - } - - if (s->format_whitelist && av_match_list(s->iformat->name, s->format_whitelist, ',') <= 0) { - av_log(s, AV_LOG_ERROR, "Format not on whitelist \'%s\'\n", s->format_whitelist); - ret = AVERROR(EINVAL); - goto fail; - } - - avio_skip(s->pb, s->skip_initial_bytes); - - /* Check filename in case an image number is expected. */ - if (s->iformat->flags & AVFMT_NEEDNUMBER) { - if (!av_filename_number_test(filename)) { - ret = AVERROR(EINVAL); - goto fail; - } - } - - s->duration = s->start_time = AV_NOPTS_VALUE; - - /* Allocate private data. */ - if (s->iformat->priv_data_size > 0) { - if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) { - ret = AVERROR(ENOMEM); - goto fail; - } - if (s->iformat->priv_class) { - *(const AVClass **) s->priv_data = s->iformat->priv_class; - av_opt_set_defaults(s->priv_data); - if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) - goto fail; - } - } - - /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */ - if (s->pb) - ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); - - if (s->iformat->read_header) - if ((ret = s->iformat->read_header(s)) < 0) { - if (s->iformat->flags_internal & FF_FMT_INIT_CLEANUP) - goto close; - goto fail; - } - - if (!s->metadata) { - s->metadata = si->id3v2_meta; - si->id3v2_meta = NULL; - } else if (si->id3v2_meta) { - av_log(s, AV_LOG_WARNING, "Discarding ID3 tags because more suitable tags were found.\n"); - av_dict_free(&si->id3v2_meta); - } - - if (id3v2_extra_meta) { - if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name, "aac") || - !strcmp(s->iformat->name, "tta") || !strcmp(s->iformat->name, "wav")) { - if ((ret = ff_id3v2_parse_apic(s, id3v2_extra_meta)) < 0) - goto close; - if ((ret = ff_id3v2_parse_chapters(s, id3v2_extra_meta)) < 0) - goto close; - if ((ret = ff_id3v2_parse_priv(s, id3v2_extra_meta)) < 0) - goto close; - } else - av_log(s, AV_LOG_DEBUG, "demuxer does not support additional id3 data, skipping\n"); - } - ff_id3v2_free_extra_meta(&id3v2_extra_meta); - - if ((ret = avformat_queue_attached_pictures(s)) < 0) - goto close; - - if (s->pb && !si->data_offset) - si->data_offset = avio_tell(s->pb); - - si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; - - update_stream_avctx(s); - - if (options) { - av_dict_free(options); - *options = tmp; - } - *ps = s; - return 0; - -close: - if (s->iformat->read_close) - s->iformat->read_close(s); -fail: - ff_id3v2_free_extra_meta(&id3v2_extra_meta); - av_dict_free(&tmp); - if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO)) - avio_closep(&s->pb); - avformat_free_context(s); - *ps = NULL; - return ret; -} - -/*******************************************************/ - -static void force_codec_ids(AVFormatContext *s, AVStream *st) -{ - switch (st->codecpar->codec_type) { - case AVMEDIA_TYPE_VIDEO: - if (s->video_codec_id) - st->codecpar->codec_id = s->video_codec_id; - break; - case AVMEDIA_TYPE_AUDIO: - if (s->audio_codec_id) - st->codecpar->codec_id = s->audio_codec_id; - break; - case AVMEDIA_TYPE_SUBTITLE: - if (s->subtitle_codec_id) - st->codecpar->codec_id = s->subtitle_codec_id; - break; - case AVMEDIA_TYPE_DATA: - if (s->data_codec_id) - st->codecpar->codec_id = s->data_codec_id; - break; - } -} - -static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) -{ - FFStream *const sti = ffstream(st); - if (sti->request_probe > 0) { - AVProbeData *pd = &sti->probe_data; - int end; - av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, sti->probe_packets); - --sti->probe_packets; - - if (pkt) { - uint8_t *new_buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); - if (!new_buf) { - av_log(s, AV_LOG_WARNING, - "Failed to reallocate probe buffer for stream %d\n", - st->index); - goto no_packet; - } - pd->buf = new_buf; - memcpy(pd->buf + pd->buf_size, pkt->data, pkt->size); - pd->buf_size += pkt->size; - memset(pd->buf + pd->buf_size, 0, AVPROBE_PADDING_SIZE); - } else { -no_packet: - sti->probe_packets = 0; - if (!pd->buf_size) { - av_log(s, AV_LOG_WARNING, - "nothing to probe for stream %d\n", st->index); - } - } - - end = ffformatcontext(s)->raw_packet_buffer_remaining_size <= 0 - || sti->probe_packets<= 0; - - if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { - int score = set_codec_from_probe_data(s, st, pd); - if ( (st->codecpar->codec_id != AV_CODEC_ID_NONE && score > AVPROBE_SCORE_STREAM_RETRY) - || end) { - pd->buf_size = 0; - av_freep(&pd->buf); - sti->request_probe = -1; - if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { - av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); - } else - av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index); - } - force_codec_ids(s, st); - } - } - return 0; -} - -static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) -{ - FFStream *const sti = ffstream(st); - int64_t ref = pkt->dts; - int pts_wrap_behavior; - int64_t pts_wrap_reference; - AVProgram *first_program; - - if (ref == AV_NOPTS_VALUE) - ref = pkt->pts; - if (sti->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) - return 0; - ref &= (1LL << st->pts_wrap_bits)-1; - - // reference time stamp should be 60 s before first time stamp - pts_wrap_reference = ref - av_rescale(60, st->time_base.den, st->time_base.num); - // if first time stamp is not more than 1/8 and 60s before the wrap point, subtract rather than add wrap offset - pts_wrap_behavior = (ref < (1LL << st->pts_wrap_bits) - (1LL << st->pts_wrap_bits-3)) || - (ref < (1LL << st->pts_wrap_bits) - av_rescale(60, st->time_base.den, st->time_base.num)) ? - AV_PTS_WRAP_ADD_OFFSET : AV_PTS_WRAP_SUB_OFFSET; - - first_program = av_find_program_from_stream(s, NULL, stream_index); - - if (!first_program) { - int default_stream_index = av_find_default_stream_index(s); - FFStream *const default_sti = ffstream(s->streams[default_stream_index]); - if (default_sti->pts_wrap_reference == AV_NOPTS_VALUE) { - for (unsigned i = 0; i < s->nb_streams; i++) { - FFStream *const sti = ffstream(s->streams[i]); - if (av_find_program_from_stream(s, NULL, i)) - continue; - sti->pts_wrap_reference = pts_wrap_reference; - sti->pts_wrap_behavior = pts_wrap_behavior; - } - } - else { - sti->pts_wrap_reference = default_sti->pts_wrap_reference; - sti->pts_wrap_behavior = default_sti->pts_wrap_behavior; - } - } - else { - AVProgram *program = first_program; - while (program) { - if (program->pts_wrap_reference != AV_NOPTS_VALUE) { - pts_wrap_reference = program->pts_wrap_reference; - pts_wrap_behavior = program->pts_wrap_behavior; - break; - } - program = av_find_program_from_stream(s, program, stream_index); - } - - // update every program with differing pts_wrap_reference - program = first_program; - while (program) { - if (program->pts_wrap_reference != pts_wrap_reference) { - for (unsigned i = 0; i < program->nb_stream_indexes; i++) { - FFStream *const sti = ffstream(s->streams[program->stream_index[i]]); - sti->pts_wrap_reference = pts_wrap_reference; - sti->pts_wrap_behavior = pts_wrap_behavior; - } - - program->pts_wrap_reference = pts_wrap_reference; - program->pts_wrap_behavior = pts_wrap_behavior; - } - program = av_find_program_from_stream(s, program, stream_index); - } - } - return 1; -} - -int ff_read_packet(AVFormatContext *s, AVPacket *pkt) -{ - FFFormatContext *const si = ffformatcontext(s); - AVStream *st; - int err; - -#if FF_API_INIT_PACKET -FF_DISABLE_DEPRECATION_WARNINGS - pkt->data = NULL; - pkt->size = 0; - av_init_packet(pkt); -FF_ENABLE_DEPRECATION_WARNINGS -#else - av_packet_unref(pkt); -#endif - - for (;;) { - PacketList *pktl = si->raw_packet_buffer; - FFStream *sti; - const AVPacket *pkt1; - - if (pktl) { - st = s->streams[pktl->pkt.stream_index]; - if (si->raw_packet_buffer_remaining_size <= 0) - if ((err = probe_codec(s, st, NULL)) < 0) - return err; - if (ffstream(st)->request_probe <= 0) { - avpriv_packet_list_get(&si->raw_packet_buffer, - &si->raw_packet_buffer_end, pkt); - si->raw_packet_buffer_remaining_size += pkt->size; - return 0; - } - } - - err = s->iformat->read_packet(s, pkt); - if (err < 0) { - av_packet_unref(pkt); - - /* Some demuxers return FFERROR_REDO when they consume - data and discard it (ignored streams, junk, extradata). - We must re-call the demuxer to get the real packet. */ - if (err == FFERROR_REDO) - continue; - if (!pktl || err == AVERROR(EAGAIN)) - return err; - for (unsigned i = 0; i < s->nb_streams; i++) { - AVStream *const st = s->streams[i]; - FFStream *const sti = ffstream(st); - if (sti->probe_packets || sti->request_probe > 0) - if ((err = probe_codec(s, st, NULL)) < 0) - return err; - av_assert0(sti->request_probe <= 0); - } - continue; - } - - err = av_packet_make_refcounted(pkt); - if (err < 0) { - av_packet_unref(pkt); - return err; - } - - if (pkt->flags & AV_PKT_FLAG_CORRUPT) { - av_log(s, AV_LOG_WARNING, - "Packet corrupt (stream = %d, dts = %s)", - pkt->stream_index, av_ts2str(pkt->dts)); - if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) { - av_log(s, AV_LOG_WARNING, ", dropping it.\n"); - av_packet_unref(pkt); - continue; - } - av_log(s, AV_LOG_WARNING, ".\n"); - } - - av_assert0(pkt->stream_index < (unsigned)s->nb_streams && - "Invalid stream index.\n"); - - st = s->streams[pkt->stream_index]; - sti = ffstream(st); - - if (update_wrap_reference(s, st, pkt->stream_index, pkt) && sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { - // correct first time stamps to negative values - if (!is_relative(sti->first_dts)) - sti->first_dts = wrap_timestamp(st, sti->first_dts); - if (!is_relative(st->start_time)) - st->start_time = wrap_timestamp(st, st->start_time); - if (!is_relative(sti->cur_dts)) - sti->cur_dts = wrap_timestamp(st, sti->cur_dts); - } - - pkt->dts = wrap_timestamp(st, pkt->dts); - pkt->pts = wrap_timestamp(st, pkt->pts); - - force_codec_ids(s, st); - - /* TODO: audio: time filter; video: frame reordering (pts != dts) */ - if (s->use_wallclock_as_timestamps) - pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base); - - if (!pktl && sti->request_probe <= 0) - return 0; - - err = avpriv_packet_list_put(&si->raw_packet_buffer, - &si->raw_packet_buffer_end, - pkt, NULL, 0); - if (err < 0) { - av_packet_unref(pkt); - return err; - } - pkt1 = &si->raw_packet_buffer_end->pkt; - si->raw_packet_buffer_remaining_size -= pkt1->size; - - if ((err = probe_codec(s, st, pkt1)) < 0) - return err; - } -} - - /**********************************************************/ -static int determinable_frame_size(AVCodecContext *avctx) -{ - switch(avctx->codec_id) { - case AV_CODEC_ID_MP1: - case AV_CODEC_ID_MP2: - case AV_CODEC_ID_MP3: - case AV_CODEC_ID_CODEC2: - return 1; - } - - return 0; -} - -/** - * Return the frame duration in seconds. Return 0 if not available. - */ -static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, - AVStream *st, AVCodecParserContext *pc, - AVPacket *pkt) -{ - FFStream *const sti = ffstream(st); - AVRational codec_framerate = sti->avctx->framerate; - int frame_size, sample_rate; - - *pnum = 0; - *pden = 0; - switch (st->codecpar->codec_type) { - case AVMEDIA_TYPE_VIDEO: - if (st->r_frame_rate.num && !pc) { - *pnum = st->r_frame_rate.den; - *pden = st->r_frame_rate.num; - } else if (st->time_base.num * 1000LL > st->time_base.den) { - *pnum = st->time_base.num; - *pden = st->time_base.den; - } else if (codec_framerate.den * 1000LL > codec_framerate.num) { - av_assert0(sti->avctx->ticks_per_frame); - av_reduce(pnum, pden, - codec_framerate.den, - codec_framerate.num * (int64_t)sti->avctx->ticks_per_frame, - INT_MAX); - - if (pc && pc->repeat_pict) { - av_reduce(pnum, pden, - (*pnum) * (1LL + pc->repeat_pict), - (*pden), - INT_MAX); - } - /* If this codec can be interlaced or progressive then we need - * a parser to compute duration of a packet. Thus if we have - * no parser in such case leave duration undefined. */ - if (sti->avctx->ticks_per_frame > 1 && !pc) - *pnum = *pden = 0; - } - break; - case AVMEDIA_TYPE_AUDIO: - if (sti->avctx_inited) { - frame_size = av_get_audio_frame_duration(sti->avctx, pkt->size); - sample_rate = sti->avctx->sample_rate; - } else { - frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size); - sample_rate = st->codecpar->sample_rate; - } - if (frame_size <= 0 || sample_rate <= 0) - break; - *pnum = frame_size; - *pden = sample_rate; - break; - default: - break; - } -} - int ff_is_intra_only(enum AVCodecID id) { - const AVCodecDescriptor *d = avcodec_descriptor_get(id); - if (!d) - return 0; - if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) && - !(d->props & AV_CODEC_PROP_INTRA_ONLY)) - return 0; - return 1; -} - -static int has_decode_delay_been_guessed(AVStream *st) -{ - FFStream *const sti = ffstream(st); - if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; - if (!sti->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy - return 1; -#if CONFIG_H264_DECODER - if (sti->avctx->has_b_frames && - avpriv_h264_has_num_reorder_frames(sti->avctx) == sti->avctx->has_b_frames) - return 1; -#endif - if (sti->avctx->has_b_frames<3) - return sti->nb_decoded_frames >= 7; - else if (sti->avctx->has_b_frames<4) - return sti->nb_decoded_frames >= 18; - else - return sti->nb_decoded_frames >= 20; -} - -static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pktl) -{ - FFFormatContext *const si = ffformatcontext(s); - if (pktl->next) - return pktl->next; - if (pktl == si->packet_buffer_end) - return si->parse_queue; - return NULL; -} - -static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts) { - FFStream *const sti = ffstream(st); - int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && - st->codecpar->codec_id != AV_CODEC_ID_HEVC; - - if(!onein_oneout) { - int delay = sti->avctx->has_b_frames; - - if (dts == AV_NOPTS_VALUE) { - int64_t best_score = INT64_MAX; - for (int i = 0; i < delay; i++) { - if (sti->pts_reorder_error_count[i]) { - int64_t score = sti->pts_reorder_error[i] / sti->pts_reorder_error_count[i]; - if (score < best_score) { - best_score = score; - dts = pts_buffer[i]; - } - } - } - } else { - for (int i = 0; i < delay; i++) { - if (pts_buffer[i] != AV_NOPTS_VALUE) { - int64_t diff = FFABS(pts_buffer[i] - dts) - + (uint64_t)sti->pts_reorder_error[i]; - diff = FFMAX(diff, sti->pts_reorder_error[i]); - sti->pts_reorder_error[i] = diff; - sti->pts_reorder_error_count[i]++; - if (sti->pts_reorder_error_count[i] > 250) { - sti->pts_reorder_error[i] >>= 1; - sti->pts_reorder_error_count[i] >>= 1; - } - } - } - } - } - - if (dts == AV_NOPTS_VALUE) - dts = pts_buffer[0]; - - return dts; -} - -/** - * Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts - * of the packets in a window. - */ -static void update_dts_from_pts(AVFormatContext *s, int stream_index, - PacketList *pkt_buffer) -{ - AVStream *st = s->streams[stream_index]; - int delay = ffstream(st)->avctx->has_b_frames; - - int64_t pts_buffer[MAX_REORDER_DELAY+1]; - - for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) - pts_buffer[i] = AV_NOPTS_VALUE; - - for (; pkt_buffer; pkt_buffer = get_next_pkt(s, st, pkt_buffer)) { - if (pkt_buffer->pkt.stream_index != stream_index) - continue; - - if (pkt_buffer->pkt.pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { - pts_buffer[0] = pkt_buffer->pkt.pts; - for (int i = 0; i < delay && pts_buffer[i] > pts_buffer[i + 1]; i++) - FFSWAP(int64_t, pts_buffer[i], pts_buffer[i + 1]); - - pkt_buffer->pkt.dts = select_from_pts_buffer(st, pts_buffer, pkt_buffer->pkt.dts); - } - } -} - -static void update_initial_timestamps(AVFormatContext *s, int stream_index, - int64_t dts, int64_t pts, AVPacket *pkt) -{ - FFFormatContext *const si = ffformatcontext(s); - AVStream *st = s->streams[stream_index]; - FFStream *const sti = ffstream(st); - PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; - PacketList *pktl_it; - - uint64_t shift; - - if (sti->first_dts != AV_NOPTS_VALUE || - dts == AV_NOPTS_VALUE || - sti->cur_dts == AV_NOPTS_VALUE || - sti->cur_dts < INT_MIN + RELATIVE_TS_BASE || - dts < INT_MIN + (sti->cur_dts - RELATIVE_TS_BASE) || - is_relative(dts)) - return; - - sti->first_dts = dts - (sti->cur_dts - RELATIVE_TS_BASE); - sti->cur_dts = dts; - shift = (uint64_t)sti->first_dts - RELATIVE_TS_BASE; - - if (is_relative(pts)) - pts += shift; - - for (pktl_it = pktl; pktl_it; pktl_it = get_next_pkt(s, st, pktl_it)) { - if (pktl_it->pkt.stream_index != stream_index) - continue; - if (is_relative(pktl_it->pkt.pts)) - pktl_it->pkt.pts += shift; - - if (is_relative(pktl_it->pkt.dts)) - pktl_it->pkt.dts += shift; - - if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) { - st->start_time = pktl_it->pkt.pts; - if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) - st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); - } - } - - if (has_decode_delay_been_guessed(st)) { - update_dts_from_pts(s, stream_index, pktl); - } - - if (st->start_time == AV_NOPTS_VALUE) { - if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || !(pkt->flags & AV_PKT_FLAG_DISCARD)) { - st->start_time = pts; - } - if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) - st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); - } -} - -static void update_initial_durations(AVFormatContext *s, AVStream *st, - int stream_index, int64_t duration) -{ - FFFormatContext *const si = ffformatcontext(s); - FFStream *const sti = ffstream(st); - PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; - int64_t cur_dts = RELATIVE_TS_BASE; - - if (sti->first_dts != AV_NOPTS_VALUE) { - if (sti->update_initial_durations_done) - return; - sti->update_initial_durations_done = 1; - cur_dts = sti->first_dts; - for (; pktl; pktl = get_next_pkt(s, st, pktl)) { - if (pktl->pkt.stream_index == stream_index) { - if (pktl->pkt.pts != pktl->pkt.dts || - pktl->pkt.dts != AV_NOPTS_VALUE || - pktl->pkt.duration) - break; - cur_dts -= duration; - } - } - if (pktl && pktl->pkt.dts != sti->first_dts) { - av_log(s, AV_LOG_DEBUG, "first_dts %s not matching first dts %s (pts %s, duration %"PRId64") in the queue\n", - av_ts2str(sti->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration); - return; - } - if (!pktl) { - av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(sti->first_dts)); - return; - } - pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; - sti->first_dts = cur_dts; - } else if (sti->cur_dts != RELATIVE_TS_BASE) - return; - - for (; pktl; pktl = get_next_pkt(s, st, pktl)) { - if (pktl->pkt.stream_index != stream_index) - continue; - if ((pktl->pkt.pts == pktl->pkt.dts || - pktl->pkt.pts == AV_NOPTS_VALUE) && - (pktl->pkt.dts == AV_NOPTS_VALUE || - pktl->pkt.dts == sti->first_dts || - pktl->pkt.dts == RELATIVE_TS_BASE) && - !pktl->pkt.duration && - av_sat_add64(cur_dts, duration) == cur_dts + (uint64_t)duration - ) { - pktl->pkt.dts = cur_dts; - if (!sti->avctx->has_b_frames) - pktl->pkt.pts = cur_dts; - pktl->pkt.duration = duration; - } else - break; - cur_dts = pktl->pkt.dts + pktl->pkt.duration; - } - if (!pktl) - sti->cur_dts = cur_dts; -} - -static void compute_pkt_fields(AVFormatContext *s, AVStream *st, - AVCodecParserContext *pc, AVPacket *pkt, - int64_t next_dts, int64_t next_pts) -{ - FFStream *const sti = ffstream(st); - int num, den, presentation_delayed, delay; - int64_t offset; - AVRational duration; - int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && - st->codecpar->codec_id != AV_CODEC_ID_HEVC; - - if (s->flags & AVFMT_FLAG_NOFILLIN) - return; - - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE) { - if (pkt->dts == pkt->pts && sti->last_dts_for_order_check != AV_NOPTS_VALUE) { - if (sti->last_dts_for_order_check <= pkt->dts) { - sti->dts_ordered++; - } else { - av_log(s, sti->dts_misordered ? AV_LOG_DEBUG : AV_LOG_WARNING, - "DTS %"PRIi64" < %"PRIi64" out of order\n", - pkt->dts, - sti->last_dts_for_order_check); - sti->dts_misordered++; - } - if (sti->dts_ordered + sti->dts_misordered > 250) { - sti->dts_ordered >>= 1; - sti->dts_misordered >>= 1; - } - } - - sti->last_dts_for_order_check = pkt->dts; - if (sti->dts_ordered < 8*sti->dts_misordered && pkt->dts == pkt->pts) - pkt->dts = AV_NOPTS_VALUE; - } - - if ((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) - pkt->dts = AV_NOPTS_VALUE; - - if (pc && pc->pict_type == AV_PICTURE_TYPE_B - && !sti->avctx->has_b_frames) - //FIXME Set low_delay = 0 when has_b_frames = 1 - sti->avctx->has_b_frames = 1; - - /* do we have a video B-frame ? */ - delay = sti->avctx->has_b_frames; - presentation_delayed = 0; - - /* XXX: need has_b_frame, but cannot get it if the codec is - * not initialized */ - if (delay && - pc && pc->pict_type != AV_PICTURE_TYPE_B) - presentation_delayed = 1; - - if (pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && - st->pts_wrap_bits < 63 && pkt->dts > INT64_MIN + (1LL << st->pts_wrap_bits) && - pkt->dts - (1LL << (st->pts_wrap_bits - 1)) > pkt->pts) { - if (is_relative(sti->cur_dts) || pkt->dts - (1LL<<(st->pts_wrap_bits - 1)) > sti->cur_dts) { - pkt->dts -= 1LL << st->pts_wrap_bits; - } else - pkt->pts += 1LL << st->pts_wrap_bits; - } - - /* Some MPEG-2 in MPEG-PS lack dts (issue #171 / input_file.mpg). - * We take the conservative approach and discard both. - * Note: If this is misbehaving for an H.264 file, then possibly - * presentation_delayed is not set correctly. */ - if (delay == 1 && pkt->dts == pkt->pts && - pkt->dts != AV_NOPTS_VALUE && presentation_delayed) { - av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination %"PRIi64"\n", pkt->dts); - if ( strcmp(s->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") - && strcmp(s->iformat->name, "flv")) // otherwise we discard correct timestamps for vc1-wmapro.ism - pkt->dts = AV_NOPTS_VALUE; - } - - duration = av_mul_q((AVRational) {pkt->duration, 1}, st->time_base); - if (pkt->duration <= 0) { - compute_frame_duration(s, &num, &den, st, pc, pkt); - if (den && num) { - duration = (AVRational) {num, den}; - pkt->duration = av_rescale_rnd(1, - num * (int64_t) st->time_base.den, - den * (int64_t) st->time_base.num, - AV_ROUND_DOWN); - } - } - - if (pkt->duration > 0 && (ffformatcontext(s)->packet_buffer || ffformatcontext(s)->parse_queue)) - update_initial_durations(s, st, pkt->stream_index, pkt->duration); - - /* Correct timestamps with byte offset if demuxers only have timestamps - * on packet boundaries */ - if (pc && sti->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) { - /* this will estimate bitrate based on this frame's duration and size */ - offset = av_rescale(pc->offset, pkt->duration, pkt->size); - if (pkt->pts != AV_NOPTS_VALUE) - pkt->pts += offset; - if (pkt->dts != AV_NOPTS_VALUE) - pkt->dts += offset; - } - - /* This may be redundant, but it should not hurt. */ - if (pkt->dts != AV_NOPTS_VALUE && - pkt->pts != AV_NOPTS_VALUE && - pkt->pts > pkt->dts) - presentation_delayed = 1; - - if (s->debug & FF_FDEBUG_TS) - av_log(s, AV_LOG_DEBUG, - "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64" delay:%d onein_oneout:%d\n", - presentation_delayed, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), - pkt->stream_index, pc, pkt->duration, delay, onein_oneout); - - /* Interpolate PTS and DTS if they are not present. We skip H264 - * currently because delay and has_b_frames are not reliably set. */ - if ((delay == 0 || (delay == 1 && pc)) && - onein_oneout) { - if (presentation_delayed) { - /* DTS = decompression timestamp */ - /* PTS = presentation timestamp */ - if (pkt->dts == AV_NOPTS_VALUE) - pkt->dts = sti->last_IP_pts; - update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); - if (pkt->dts == AV_NOPTS_VALUE) - pkt->dts = sti->cur_dts; - - /* This is tricky: the dts must be incremented by the duration - * of the frame we are displaying, i.e. the last I- or P-frame. */ - if (sti->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX) - sti->last_IP_duration = pkt->duration; - if (pkt->dts != AV_NOPTS_VALUE) - sti->cur_dts = av_sat_add64(pkt->dts, sti->last_IP_duration); - if (pkt->dts != AV_NOPTS_VALUE && - pkt->pts == AV_NOPTS_VALUE && - sti->last_IP_duration > 0 && - ((uint64_t)sti->cur_dts - (uint64_t)next_dts + 1) <= 2 && - next_dts != next_pts && - next_pts != AV_NOPTS_VALUE) - pkt->pts = next_dts; - - if ((uint64_t)pkt->duration <= INT32_MAX) - sti->last_IP_duration = pkt->duration; - sti->last_IP_pts = pkt->pts; - /* Cannot compute PTS if not present (we can compute it only - * by knowing the future. */ - } else if (pkt->pts != AV_NOPTS_VALUE || - pkt->dts != AV_NOPTS_VALUE || - pkt->duration > 0 ) { - - /* presentation is not delayed : PTS and DTS are the same */ - if (pkt->pts == AV_NOPTS_VALUE) - pkt->pts = pkt->dts; - update_initial_timestamps(s, pkt->stream_index, pkt->pts, - pkt->pts, pkt); - if (pkt->pts == AV_NOPTS_VALUE) - pkt->pts = sti->cur_dts; - pkt->dts = pkt->pts; - if (pkt->pts != AV_NOPTS_VALUE && duration.num >= 0) - sti->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1); - } - } - - if (pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { - sti->pts_buffer[0] = pkt->pts; - for (int i = 0; i < delay && sti->pts_buffer[i] > sti->pts_buffer[i + 1]; i++) - FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]); - - if(has_decode_delay_been_guessed(st)) - pkt->dts = select_from_pts_buffer(st, sti->pts_buffer, pkt->dts); - } - // We skipped it above so we try here. - if (!onein_oneout) - // This should happen on the first packet - update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); - if (pkt->dts > sti->cur_dts) - sti->cur_dts = pkt->dts; - - if (s->debug & FF_FDEBUG_TS) - av_log(s, AV_LOG_DEBUG, "OUTdelayed:%d/%d pts:%s, dts:%s cur_dts:%s st:%d (%d)\n", - presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), st->index, st->id); - - /* update flags */ - if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA || ff_is_intra_only(st->codecpar->codec_id)) - pkt->flags |= AV_PKT_FLAG_KEY; -} - -/** - * Parse a packet, add all split parts to parse_queue. - * - * @param pkt Packet to parse; must not be NULL. - * @param flush Indicates whether to flush. If set, pkt must be blank. - */ -static int parse_packet(AVFormatContext *s, AVPacket *pkt, - int stream_index, int flush) -{ - FFFormatContext *const si = ffformatcontext(s); - AVPacket *out_pkt = si->parse_pkt; - AVStream *st = s->streams[stream_index]; - FFStream *const sti = ffstream(st); - uint8_t *data = pkt->data; - int size = pkt->size; - int ret = 0, got_output = flush; - - if (!size && !flush && sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { - // preserve 0-size sync packets - compute_pkt_fields(s, st, sti->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); - } - - while (size > 0 || (flush && got_output)) { - int len; - int64_t next_pts = pkt->pts; - int64_t next_dts = pkt->dts; - - len = av_parser_parse2(sti->parser, sti->avctx, - &out_pkt->data, &out_pkt->size, data, size, - pkt->pts, pkt->dts, pkt->pos); - - pkt->pts = pkt->dts = AV_NOPTS_VALUE; - pkt->pos = -1; - /* increment read pointer */ - av_assert1(data || !len); - data = len ? data + len : data; - size -= len; - - got_output = !!out_pkt->size; - - if (!out_pkt->size) - continue; - - if (pkt->buf && out_pkt->data == pkt->data) { - /* reference pkt->buf only when out_pkt->data is guaranteed to point - * to data in it and not in the parser's internal buffer. */ - /* XXX: Ensure this is the case with all parsers when sti->parser->flags - * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */ - out_pkt->buf = av_buffer_ref(pkt->buf); - if (!out_pkt->buf) { - ret = AVERROR(ENOMEM); - goto fail; - } - } else { - ret = av_packet_make_refcounted(out_pkt); - if (ret < 0) - goto fail; - } - - if (pkt->side_data) { - out_pkt->side_data = pkt->side_data; - out_pkt->side_data_elems = pkt->side_data_elems; - pkt->side_data = NULL; - pkt->side_data_elems = 0; - } - - /* set the duration */ - out_pkt->duration = (sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; - if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - if (sti->avctx->sample_rate > 0) { - out_pkt->duration = - av_rescale_q_rnd(sti->parser->duration, - (AVRational) { 1, sti->avctx->sample_rate }, - st->time_base, - AV_ROUND_DOWN); - } - } - - out_pkt->stream_index = st->index; - out_pkt->pts = sti->parser->pts; - out_pkt->dts = sti->parser->dts; - out_pkt->pos = sti->parser->pos; - out_pkt->flags |= pkt->flags & AV_PKT_FLAG_DISCARD; - - if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) - out_pkt->pos = sti->parser->frame_offset; - - if (sti->parser->key_frame == 1 || - (sti->parser->key_frame == -1 && - sti->parser->pict_type == AV_PICTURE_TYPE_I)) - out_pkt->flags |= AV_PKT_FLAG_KEY; - - if (sti->parser->key_frame == -1 && sti->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) - out_pkt->flags |= AV_PKT_FLAG_KEY; - - compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts); - - ret = avpriv_packet_list_put(&si->parse_queue, - &si->parse_queue_end, - out_pkt, NULL, 0); - if (ret < 0) - goto fail; - } - - /* end of the stream => close and free the parser */ - if (flush) { - av_parser_close(sti->parser); - sti->parser = NULL; - } - -fail: - if (ret < 0) - av_packet_unref(out_pkt); - av_packet_unref(pkt); - return ret; -} - -static int64_t ts_to_samples(AVStream *st, int64_t ts) -{ - return av_rescale(ts, st->time_base.num * st->codecpar->sample_rate, st->time_base.den); -} - -static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) -{ - FFFormatContext *const si = ffformatcontext(s); - int ret, got_packet = 0; - AVDictionary *metadata = NULL; - - while (!got_packet && !si->parse_queue) { - AVStream *st; - FFStream *sti; - - /* read next packet */ - ret = ff_read_packet(s, pkt); - if (ret < 0) { - if (ret == AVERROR(EAGAIN)) - return ret; - /* flush the parsers */ - for (unsigned i = 0; i < s->nb_streams; i++) { - AVStream *const st = s->streams[i]; - FFStream *const sti = ffstream(st); - if (sti->parser && sti->need_parsing) - parse_packet(s, pkt, st->index, 1); - } - /* all remaining packets are now in parse_queue => - * really terminate parsing */ - break; - } - ret = 0; - st = s->streams[pkt->stream_index]; - sti = ffstream(st); - - st->event_flags |= AVSTREAM_EVENT_FLAG_NEW_PACKETS; - - /* update context if required */ - if (sti->need_context_update) { - if (avcodec_is_open(sti->avctx)) { - av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); - avcodec_close(sti->avctx); - sti->info->found_decoder = 0; - } - - /* close parser, because it depends on the codec */ - if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { - av_parser_close(sti->parser); - sti->parser = NULL; - } - - ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); - if (ret < 0) { - av_packet_unref(pkt); - return ret; - } - - sti->need_context_update = 0; - } - - if (pkt->pts != AV_NOPTS_VALUE && - pkt->dts != AV_NOPTS_VALUE && - pkt->pts < pkt->dts) { - av_log(s, AV_LOG_WARNING, - "Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n", - pkt->stream_index, - av_ts2str(pkt->pts), - av_ts2str(pkt->dts), - pkt->size); - } - if (s->debug & FF_FDEBUG_TS) - av_log(s, AV_LOG_DEBUG, - "ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64", flags=%d\n", - pkt->stream_index, - av_ts2str(pkt->pts), - av_ts2str(pkt->dts), - pkt->size, pkt->duration, pkt->flags); - - if (sti->need_parsing && !sti->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { - sti->parser = av_parser_init(st->codecpar->codec_id); - if (!sti->parser) { - av_log(s, AV_LOG_VERBOSE, "parser not found for codec " - "%s, packets or times may be invalid.\n", - avcodec_get_name(st->codecpar->codec_id)); - /* no parser available: just output the raw packets */ - sti->need_parsing = AVSTREAM_PARSE_NONE; - } else if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) - sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; - else if (sti->need_parsing == AVSTREAM_PARSE_FULL_ONCE) - sti->parser->flags |= PARSER_FLAG_ONCE; - else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) - sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; - } - - if (!sti->need_parsing || !sti->parser) { - /* no parsing needed: we just output the packet as is */ - compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); - if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && - (pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) { - ff_reduce_index(s, st->index); - av_add_index_entry(st, pkt->pos, pkt->dts, - 0, 0, AVINDEX_KEYFRAME); - } - got_packet = 1; - } else if (st->discard < AVDISCARD_ALL) { - if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0) - return ret; - st->codecpar->sample_rate = sti->avctx->sample_rate; - st->codecpar->bit_rate = sti->avctx->bit_rate; - st->codecpar->channels = sti->avctx->channels; - st->codecpar->channel_layout = sti->avctx->channel_layout; - st->codecpar->codec_id = sti->avctx->codec_id; - } else { - /* free packet */ - av_packet_unref(pkt); - } - if (pkt->flags & AV_PKT_FLAG_KEY) - sti->skip_to_keyframe = 0; - if (sti->skip_to_keyframe) { - av_packet_unref(pkt); - got_packet = 0; - } - } - - if (!got_packet && si->parse_queue) - ret = avpriv_packet_list_get(&si->parse_queue, &si->parse_queue_end, pkt); - - if (ret >= 0) { - AVStream *st = s->streams[pkt->stream_index]; - FFStream *const sti = ffstream(st); - int discard_padding = 0; - if (sti->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { - int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0); - int64_t sample = ts_to_samples(st, pts); - int duration = ts_to_samples(st, pkt->duration); - int64_t end_sample = sample + duration; - if (duration > 0 && end_sample >= sti->first_discard_sample && - sample < sti->last_discard_sample) - discard_padding = FFMIN(end_sample - sti->first_discard_sample, duration); - } - if (sti->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) - sti->skip_samples = sti->start_skip_samples; - if (sti->skip_samples || discard_padding) { - uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); - if (p) { - AV_WL32(p, sti->skip_samples); - AV_WL32(p + 4, discard_padding); - av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %d / discard %d\n", sti->skip_samples, discard_padding); - } - sti->skip_samples = 0; - } - - if (sti->inject_global_side_data) { - for (int i = 0; i < st->nb_side_data; i++) { - AVPacketSideData *src_sd = &st->side_data[i]; - uint8_t *dst_data; - - if (av_packet_get_side_data(pkt, src_sd->type, NULL)) - continue; - - dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size); - if (!dst_data) { - av_log(s, AV_LOG_WARNING, "Could not inject global side data\n"); - continue; - } - - memcpy(dst_data, src_sd->data, src_sd->size); - } - sti->inject_global_side_data = 0; - } - } - - av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata); - if (metadata) { - s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED; - av_dict_copy(&s->metadata, metadata, 0); - av_dict_free(&metadata); - av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN); - } - - if (s->debug & FF_FDEBUG_TS) - av_log(s, AV_LOG_DEBUG, - "read_frame_internal stream=%d, pts=%s, dts=%s, " - "size=%d, duration=%"PRId64", flags=%d\n", - pkt->stream_index, - av_ts2str(pkt->pts), - av_ts2str(pkt->dts), - pkt->size, pkt->duration, pkt->flags); - - /* A demuxer might have returned EOF because of an IO error, let's - * propagate this back to the user. */ - if (ret == AVERROR_EOF && s->pb && s->pb->error < 0 && s->pb->error != AVERROR(EAGAIN)) - ret = s->pb->error; - - return ret; -} - -int av_read_frame(AVFormatContext *s, AVPacket *pkt) -{ - FFFormatContext *const si = ffformatcontext(s); - const int genpts = s->flags & AVFMT_FLAG_GENPTS; - int eof = 0; - int ret; - AVStream *st; - - if (!genpts) { - ret = si->packet_buffer - ? avpriv_packet_list_get(&si->packet_buffer, - &si->packet_buffer_end, pkt) - : read_frame_internal(s, pkt); - if (ret < 0) - return ret; - goto return_packet; - } - - for (;;) { - PacketList *pktl = si->packet_buffer; - - if (pktl) { - AVPacket *next_pkt = &pktl->pkt; - - if (next_pkt->dts != AV_NOPTS_VALUE) { - int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits; - // last dts seen for this stream. if any of packets following - // current one had no dts, we will set this to AV_NOPTS_VALUE. - int64_t last_dts = next_pkt->dts; - av_assert2(wrap_bits <= 64); - while (pktl && next_pkt->pts == AV_NOPTS_VALUE) { - if (pktl->pkt.stream_index == next_pkt->stream_index && - av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2ULL << (wrap_bits - 1)) < 0) { - if (av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2ULL << (wrap_bits - 1))) { - // not B-frame - next_pkt->pts = pktl->pkt.dts; - } - if (last_dts != AV_NOPTS_VALUE) { - // Once last dts was set to AV_NOPTS_VALUE, we don't change it. - last_dts = pktl->pkt.dts; - } - } - pktl = pktl->next; - } - if (eof && next_pkt->pts == AV_NOPTS_VALUE && last_dts != AV_NOPTS_VALUE) { - // Fixing the last reference frame had none pts issue (For MXF etc). - // We only do this when - // 1. eof. - // 2. we are not able to resolve a pts value for current packet. - // 3. the packets for this stream at the end of the files had valid dts. - next_pkt->pts = last_dts + next_pkt->duration; - } - pktl = si->packet_buffer; - } - - /* read packet from packet buffer, if there is data */ - st = s->streams[next_pkt->stream_index]; - if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL && - next_pkt->dts != AV_NOPTS_VALUE && !eof)) { - ret = avpriv_packet_list_get(&si->packet_buffer, - &si->packet_buffer_end, pkt); - goto return_packet; - } - } - - ret = read_frame_internal(s, pkt); - if (ret < 0) { - if (pktl && ret != AVERROR(EAGAIN)) { - eof = 1; - continue; - } else - return ret; - } - - ret = avpriv_packet_list_put(&si->packet_buffer, - &si->packet_buffer_end, - pkt, NULL, 0); - if (ret < 0) { - av_packet_unref(pkt); - return ret; - } - } - -return_packet: - - st = s->streams[pkt->stream_index]; - if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY) { - ff_reduce_index(s, st->index); - av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME); - } - - if (is_relative(pkt->dts)) - pkt->dts -= RELATIVE_TS_BASE; - if (is_relative(pkt->pts)) - pkt->pts -= RELATIVE_TS_BASE; - - return ret; -} - -/* XXX: suppress the packet queue */ -void ff_flush_packet_queue(AVFormatContext *s) -{ - FFFormatContext *const si = ffformatcontext(s); - avpriv_packet_list_free(&si->parse_queue, &si->parse_queue_end); - avpriv_packet_list_free(&si->packet_buffer, &si->packet_buffer_end); - avpriv_packet_list_free(&si->raw_packet_buffer, &si->raw_packet_buffer_end); - - si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; -} - -int av_find_default_stream_index(AVFormatContext *s) -{ - int best_stream = 0; - int best_score = INT_MIN; - - if (s->nb_streams <= 0) - return -1; - for (unsigned i = 0; i < s->nb_streams; i++) { - const AVStream *const st = s->streams[i]; - int score = 0; - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) - score -= 400; - if (st->codecpar->width && st->codecpar->height) - score += 50; - score+= 25; - } - if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->codecpar->sample_rate) - score += 50; - } - if (cffstream(st)->codec_info_nb_frames) - score += 12; - - if (st->discard != AVDISCARD_ALL) - score += 200; - - if (score > best_score) { - best_score = score; - best_stream = i; - } - } - return best_stream; -} - -/*******************************************************/ - -/** - * Return TRUE if the stream has accurate duration in any stream. - * - * @return TRUE if the stream has accurate duration for at least one component. - */ -static int has_duration(AVFormatContext *ic) -{ - for (unsigned i = 0; i < ic->nb_streams; i++) { - const AVStream *const st = ic->streams[i]; - if (st->duration != AV_NOPTS_VALUE) - return 1; - } - if (ic->duration != AV_NOPTS_VALUE) - return 1; - return 0; -} - -/** - * Estimate the stream timings from the one of each components. - * - * Also computes the global bitrate if possible. - */ -static void update_stream_timings(AVFormatContext *ic) -{ - int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text; - int64_t duration, duration1, duration_text, filesize; - - start_time = INT64_MAX; - start_time_text = INT64_MAX; - end_time = INT64_MIN; - end_time_text = INT64_MIN; - duration = INT64_MIN; - duration_text = INT64_MIN; - - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *st = ic->streams[i]; - int is_text = st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || - st->codecpar->codec_type == AVMEDIA_TYPE_DATA; - - if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) { - start_time1 = av_rescale_q(st->start_time, st->time_base, - AV_TIME_BASE_Q); - if (is_text) - start_time_text = FFMIN(start_time_text, start_time1); - else - start_time = FFMIN(start_time, start_time1); - end_time1 = av_rescale_q_rnd(st->duration, st->time_base, - AV_TIME_BASE_Q, - AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); - if (end_time1 != AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) { - end_time1 += start_time1; - if (is_text) - end_time_text = FFMAX(end_time_text, end_time1); - else - end_time = FFMAX(end_time, end_time1); - } - for (AVProgram *p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) { - if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1) - p->start_time = start_time1; - if (p->end_time < end_time1) - p->end_time = end_time1; - } - } - if (st->duration != AV_NOPTS_VALUE) { - duration1 = av_rescale_q(st->duration, st->time_base, - AV_TIME_BASE_Q); - if (is_text) - duration_text = FFMAX(duration_text, duration1); - else - duration = FFMAX(duration, duration1); - } - } - if (start_time == INT64_MAX || (start_time > start_time_text && start_time - (uint64_t)start_time_text < AV_TIME_BASE)) - start_time = start_time_text; - else if (start_time > start_time_text) - av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream starttime %f\n", start_time_text / (float)AV_TIME_BASE); - - if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - (uint64_t)end_time < AV_TIME_BASE)) - end_time = end_time_text; - else if (end_time < end_time_text) - av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream endtime %f\n", end_time_text / (float)AV_TIME_BASE); - - if (duration == INT64_MIN || (duration < duration_text && duration_text - duration < AV_TIME_BASE)) - duration = duration_text; - else if (duration < duration_text) - av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream duration %f\n", duration_text / (float)AV_TIME_BASE); - - if (start_time != INT64_MAX) { - ic->start_time = start_time; - if (end_time != INT64_MIN) { - if (ic->nb_programs > 1) { - for (unsigned i = 0; i < ic->nb_programs; i++) { - AVProgram *const p = ic->programs[i]; - - if (p->start_time != AV_NOPTS_VALUE && - p->end_time > p->start_time && - p->end_time - (uint64_t)p->start_time <= INT64_MAX) - duration = FFMAX(duration, p->end_time - p->start_time); - } - } else if (end_time >= start_time && end_time - (uint64_t)start_time <= INT64_MAX) { - duration = FFMAX(duration, end_time - start_time); - } - } - } - if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) { - ic->duration = duration; - } - if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0) { - /* compute the bitrate */ - double bitrate = (double) filesize * 8.0 * AV_TIME_BASE / - (double) ic->duration; - if (bitrate >= 0 && bitrate <= INT64_MAX) - ic->bit_rate = bitrate; - } -} - -static void fill_all_stream_timings(AVFormatContext *ic) -{ - update_stream_timings(ic); - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - - if (st->start_time == AV_NOPTS_VALUE) { - if (ic->start_time != AV_NOPTS_VALUE) - st->start_time = av_rescale_q(ic->start_time, AV_TIME_BASE_Q, - st->time_base); - if (ic->duration != AV_NOPTS_VALUE) - st->duration = av_rescale_q(ic->duration, AV_TIME_BASE_Q, - st->time_base); - } - } -} - -static void estimate_timings_from_bit_rate(AVFormatContext *ic) -{ - int show_warning = 0; - - /* if bit_rate is already set, we believe it */ - if (ic->bit_rate <= 0) { - int64_t bit_rate = 0; - for (unsigned i = 0; i < ic->nb_streams; i++) { - const AVStream *const st = ic->streams[i]; - const FFStream *const sti = cffstream(st); - if (st->codecpar->bit_rate <= 0 && sti->avctx->bit_rate > 0) - st->codecpar->bit_rate = sti->avctx->bit_rate; - if (st->codecpar->bit_rate > 0) { - if (INT64_MAX - st->codecpar->bit_rate < bit_rate) { - bit_rate = 0; - break; - } - bit_rate += st->codecpar->bit_rate; - } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->codec_info_nb_frames > 1) { - // If we have a videostream with packets but without a bitrate - // then consider the sum not known - bit_rate = 0; - break; - } - } - ic->bit_rate = bit_rate; - } - - /* if duration is already set, we believe it */ - if (ic->duration == AV_NOPTS_VALUE && - ic->bit_rate != 0) { - int64_t filesize = ic->pb ? avio_size(ic->pb) : 0; - if (filesize > ffformatcontext(ic)->data_offset) { - filesize -= ffformatcontext(ic)->data_offset; - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - - if ( st->time_base.num <= INT64_MAX / ic->bit_rate - && st->duration == AV_NOPTS_VALUE) { - st->duration = av_rescale(filesize, 8LL * st->time_base.den, - ic->bit_rate * - (int64_t) st->time_base.num); - show_warning = 1; - } - } - } - } - if (show_warning) - av_log(ic, AV_LOG_WARNING, - "Estimating duration from bitrate, this may be inaccurate\n"); -} - -#define DURATION_MAX_READ_SIZE 250000LL -#define DURATION_MAX_RETRY 6 - -/* only usable for MPEG-PS streams */ -static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) -{ - AVPacket *pkt = ffformatcontext(ic)->pkt; - int num, den, read_size, ret; - int found_duration = 0; - int is_end; - int64_t filesize, offset, duration; - int retry = 0; - - /* flush packet queue */ - ff_flush_packet_queue(ic); - - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - FFStream *const sti = ffstream(st); - - if (st->start_time == AV_NOPTS_VALUE && - sti->first_dts == AV_NOPTS_VALUE && - st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) - av_log(ic, AV_LOG_WARNING, - "start time for stream %d is not set in estimate_timings_from_pts\n", i); - - if (sti->parser) { - av_parser_close(sti->parser); - sti->parser = NULL; - } - } - - if (ic->skip_estimate_duration_from_pts) { - av_log(ic, AV_LOG_INFO, "Skipping duration calculation in estimate_timings_from_pts\n"); - goto skip_duration_calc; - } - - av_opt_set(ic, "skip_changes", "1", AV_OPT_SEARCH_CHILDREN); - /* estimate the end time (duration) */ - /* XXX: may need to support wrapping */ - filesize = ic->pb ? avio_size(ic->pb) : 0; - do { - is_end = found_duration; - offset = filesize - (DURATION_MAX_READ_SIZE << retry); - if (offset < 0) - offset = 0; - - avio_seek(ic->pb, offset, SEEK_SET); - read_size = 0; - for (;;) { - AVStream *st; - FFStream *sti; - if (read_size >= DURATION_MAX_READ_SIZE << (FFMAX(retry - 1, 0))) - break; - - do { - ret = ff_read_packet(ic, pkt); - } while (ret == AVERROR(EAGAIN)); - if (ret != 0) - break; - read_size += pkt->size; - st = ic->streams[pkt->stream_index]; - sti = ffstream(st); - if (pkt->pts != AV_NOPTS_VALUE && - (st->start_time != AV_NOPTS_VALUE || - sti->first_dts != AV_NOPTS_VALUE)) { - if (pkt->duration == 0) { - compute_frame_duration(ic, &num, &den, st, sti->parser, pkt); - if (den && num) { - pkt->duration = av_rescale_rnd(1, - num * (int64_t) st->time_base.den, - den * (int64_t) st->time_base.num, - AV_ROUND_DOWN); - } - } - duration = pkt->pts + pkt->duration; - found_duration = 1; - if (st->start_time != AV_NOPTS_VALUE) - duration -= st->start_time; - else - duration -= sti->first_dts; - if (duration > 0) { - if (st->duration == AV_NOPTS_VALUE || sti->info->last_duration<= 0 || - (st->duration < duration && FFABS(duration - sti->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) - st->duration = duration; - sti->info->last_duration = duration; - } - } - av_packet_unref(pkt); - } - - /* check if all audio/video streams have valid duration */ - if (!is_end) { - is_end = 1; - for (unsigned i = 0; i < ic->nb_streams; i++) { - const AVStream *const st = ic->streams[i]; - switch (st->codecpar->codec_type) { - case AVMEDIA_TYPE_VIDEO: - case AVMEDIA_TYPE_AUDIO: - if (st->duration == AV_NOPTS_VALUE) - is_end = 0; - } - } - } - } while (!is_end && - offset && - ++retry <= DURATION_MAX_RETRY); - - av_opt_set(ic, "skip_changes", "0", AV_OPT_SEARCH_CHILDREN); - - /* warn about audio/video streams which duration could not be estimated */ - for (unsigned i = 0; i < ic->nb_streams; i++) { - const AVStream *const st = ic->streams[i]; - - if (st->duration == AV_NOPTS_VALUE) { - switch (st->codecpar->codec_type) { - case AVMEDIA_TYPE_VIDEO: - case AVMEDIA_TYPE_AUDIO: - if (st->start_time != AV_NOPTS_VALUE || cffstream(st)->first_dts != AV_NOPTS_VALUE) { - av_log(ic, AV_LOG_WARNING, "stream %d : no PTS found at end of file, duration not set\n", i); - } else - av_log(ic, AV_LOG_WARNING, "stream %d : no TS found at start of file, duration not set\n", i); - } - } - } -skip_duration_calc: - fill_all_stream_timings(ic); - - avio_seek(ic->pb, old_offset, SEEK_SET); - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - FFStream *const sti = ffstream(st); - - sti->cur_dts = sti->first_dts; - sti->last_IP_pts = AV_NOPTS_VALUE; - sti->last_dts_for_order_check = AV_NOPTS_VALUE; - for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) - sti->pts_buffer[j] = AV_NOPTS_VALUE; - } -} - -/* 1:1 map to AVDurationEstimationMethod */ -static const char *const duration_name[] = { - [AVFMT_DURATION_FROM_PTS] = "pts", - [AVFMT_DURATION_FROM_STREAM] = "stream", - [AVFMT_DURATION_FROM_BITRATE] = "bit rate", -}; - -static const char *duration_estimate_name(enum AVDurationEstimationMethod method) -{ - return duration_name[method]; -} - -static void estimate_timings(AVFormatContext *ic, int64_t old_offset) -{ - int64_t file_size; - - /* get the file size, if possible */ - if (ic->iformat->flags & AVFMT_NOFILE) { - file_size = 0; - } else { - file_size = avio_size(ic->pb); - file_size = FFMAX(0, file_size); - } - - if ((!strcmp(ic->iformat->name, "mpeg") || - !strcmp(ic->iformat->name, "mpegts")) && - file_size && (ic->pb->seekable & AVIO_SEEKABLE_NORMAL)) { - /* get accurate estimate from the PTSes */ - estimate_timings_from_pts(ic, old_offset); - ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; - } else if (has_duration(ic)) { - /* at least one component has timings - we use them for all - * the components */ - fill_all_stream_timings(ic); - /* nut demuxer estimate the duration from PTS */ - if(!strcmp(ic->iformat->name, "nut")) - ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; - else - ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM; - } else { - /* less precise: use bitrate info */ - estimate_timings_from_bit_rate(ic); - ic->duration_estimation_method = AVFMT_DURATION_FROM_BITRATE; - } - update_stream_timings(ic); - - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *st = ic->streams[i]; - if (st->time_base.den) - av_log(ic, AV_LOG_TRACE, "stream %u: start_time: %s duration: %s\n", i, - av_ts2timestr(st->start_time, &st->time_base), - av_ts2timestr(st->duration, &st->time_base)); - } - av_log(ic, AV_LOG_TRACE, - "format: start_time: %s duration: %s (estimate from %s) bitrate=%"PRId64" kb/s\n", - av_ts2timestr(ic->start_time, &AV_TIME_BASE_Q), - av_ts2timestr(ic->duration, &AV_TIME_BASE_Q), - duration_estimate_name(ic->duration_estimation_method), - (int64_t)ic->bit_rate / 1000); -} - -static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) -{ - FFStream *const sti = ffstream(st); - AVCodecContext *avctx = sti->avctx; - -#define FAIL(errmsg) do { \ - if (errmsg_ptr) \ - *errmsg_ptr = errmsg; \ - return 0; \ - } while (0) - - if ( avctx->codec_id == AV_CODEC_ID_NONE - && avctx->codec_type != AVMEDIA_TYPE_DATA) - FAIL("unknown codec"); - switch (avctx->codec_type) { - case AVMEDIA_TYPE_AUDIO: - if (!avctx->frame_size && determinable_frame_size(avctx)) - FAIL("unspecified frame size"); - if (sti->info->found_decoder >= 0 && - avctx->sample_fmt == AV_SAMPLE_FMT_NONE) - FAIL("unspecified sample format"); - if (!avctx->sample_rate) - FAIL("unspecified sample rate"); - if (!avctx->channels) - FAIL("unspecified number of channels"); - if (sti->info->found_decoder >= 0 && !sti->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) - FAIL("no decodable DTS frames"); - break; - case AVMEDIA_TYPE_VIDEO: - if (!avctx->width) - FAIL("unspecified size"); - if (sti->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) - FAIL("unspecified pixel format"); - if (st->codecpar->codec_id == AV_CODEC_ID_RV30 || st->codecpar->codec_id == AV_CODEC_ID_RV40) - if (!st->sample_aspect_ratio.num && !st->codecpar->sample_aspect_ratio.num && !sti->codec_info_nb_frames) - FAIL("no frame in rv30/40 and no sar"); - break; - case AVMEDIA_TYPE_SUBTITLE: - if (avctx->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE && !avctx->width) - FAIL("unspecified size"); - break; - case AVMEDIA_TYPE_DATA: - if (avctx->codec_id == AV_CODEC_ID_NONE) return 1; - } - - return 1; -} - -/* returns 1 or 0 if or if not decoded data was returned, or a negative error */ -static int try_decode_frame(AVFormatContext *s, AVStream *st, - const AVPacket *avpkt, AVDictionary **options) -{ - FFStream *const sti = ffstream(st); - AVCodecContext *avctx = sti->avctx; - const AVCodec *codec; - int got_picture = 1, ret = 0; - AVFrame *frame = av_frame_alloc(); - AVSubtitle subtitle; - AVPacket pkt = *avpkt; - int do_skip_frame = 0; - enum AVDiscard skip_frame; - - if (!frame) - return AVERROR(ENOMEM); - - if (!avcodec_is_open(avctx) && - sti->info->found_decoder <= 0 && - (st->codecpar->codec_id != -sti->info->found_decoder || !st->codecpar->codec_id)) { - AVDictionary *thread_opt = NULL; - - codec = find_probe_decoder(s, st, st->codecpar->codec_id); - - if (!codec) { - sti->info->found_decoder = -st->codecpar->codec_id; - ret = -1; - goto fail; - } - - /* Force thread count to 1 since the H.264 decoder will not extract - * SPS and PPS to extradata during multi-threaded decoding. */ - av_dict_set(options ? options : &thread_opt, "threads", "1", 0); - /* Force lowres to 0. The decoder might reduce the video size by the - * lowres factor, and we don't want that propagated to the stream's - * codecpar */ - av_dict_set(options ? options : &thread_opt, "lowres", "0", 0); - if (s->codec_whitelist) - av_dict_set(options ? options : &thread_opt, "codec_whitelist", s->codec_whitelist, 0); - ret = avcodec_open2(avctx, codec, options ? options : &thread_opt); - if (!options) - av_dict_free(&thread_opt); - if (ret < 0) { - sti->info->found_decoder = -avctx->codec_id; - goto fail; - } - sti->info->found_decoder = 1; - } else if (!sti->info->found_decoder) - sti->info->found_decoder = 1; - - if (sti->info->found_decoder < 0) { - ret = -1; - goto fail; - } - - if (avpriv_codec_get_cap_skip_frame_fill_param(avctx->codec)) { - do_skip_frame = 1; - skip_frame = avctx->skip_frame; - avctx->skip_frame = AVDISCARD_ALL; - } - - while ((pkt.size > 0 || (!pkt.data && got_picture)) && - ret >= 0 && - (!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) || - (!sti->codec_info_nb_frames && - (avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)))) { - got_picture = 0; - if (avctx->codec_type == AVMEDIA_TYPE_VIDEO || - avctx->codec_type == AVMEDIA_TYPE_AUDIO) { - ret = avcodec_send_packet(avctx, &pkt); - if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) - break; - if (ret >= 0) - pkt.size = 0; - ret = avcodec_receive_frame(avctx, frame); - if (ret >= 0) - got_picture = 1; - if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) - ret = 0; - } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { - ret = avcodec_decode_subtitle2(avctx, &subtitle, - &got_picture, &pkt); - if (got_picture) - avsubtitle_free(&subtitle); - if (ret >= 0) - pkt.size = 0; - } - if (ret >= 0) { - if (got_picture) - sti->nb_decoded_frames++; - ret = got_picture; - } - } - - if (!pkt.data && !got_picture) - ret = -1; - -fail: - if (do_skip_frame) { - avctx->skip_frame = skip_frame; - } - - av_frame_free(&frame); - return ret; -} - -unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id) -{ - while (tags->id != AV_CODEC_ID_NONE) { - if (tags->id == id) - return tags->tag; - tags++; - } - return 0; -} - -enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag) -{ - for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) - if (tag == tags[i].tag) - return tags[i].id; - for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) - if (avpriv_toupper4(tag) == avpriv_toupper4(tags[i].tag)) - return tags[i].id; - return AV_CODEC_ID_NONE; -} - -enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags) -{ - if (bps <= 0 || bps > 64) - return AV_CODEC_ID_NONE; - - if (flt) { - switch (bps) { - case 32: - return be ? AV_CODEC_ID_PCM_F32BE : AV_CODEC_ID_PCM_F32LE; - case 64: - return be ? AV_CODEC_ID_PCM_F64BE : AV_CODEC_ID_PCM_F64LE; - default: - return AV_CODEC_ID_NONE; - } - } else { - bps += 7; - bps >>= 3; - if (sflags & (1 << (bps - 1))) { - switch (bps) { - case 1: - return AV_CODEC_ID_PCM_S8; - case 2: - return be ? AV_CODEC_ID_PCM_S16BE : AV_CODEC_ID_PCM_S16LE; - case 3: - return be ? AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE; - case 4: - return be ? AV_CODEC_ID_PCM_S32BE : AV_CODEC_ID_PCM_S32LE; - case 8: - return be ? AV_CODEC_ID_PCM_S64BE : AV_CODEC_ID_PCM_S64LE; - default: - return AV_CODEC_ID_NONE; - } - } else { - switch (bps) { - case 1: - return AV_CODEC_ID_PCM_U8; - case 2: - return be ? AV_CODEC_ID_PCM_U16BE : AV_CODEC_ID_PCM_U16LE; - case 3: - return be ? AV_CODEC_ID_PCM_U24BE : AV_CODEC_ID_PCM_U24LE; - case 4: - return be ? AV_CODEC_ID_PCM_U32BE : AV_CODEC_ID_PCM_U32LE; - default: - return AV_CODEC_ID_NONE; - } - } - } -} - -unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id) -{ - unsigned int tag; - if (!av_codec_get_tag2(tags, id, &tag)) - return 0; - return tag; -} - -int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id, - unsigned int *tag) -{ - for (int i = 0; tags && tags[i]; i++) { - const AVCodecTag *codec_tags = tags[i]; - while (codec_tags->id != AV_CODEC_ID_NONE) { - if (codec_tags->id == id) { - *tag = codec_tags->tag; - return 1; - } - codec_tags++; - } - } - return 0; -} - -enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag) -{ - for (int i = 0; tags && tags[i]; i++) { - enum AVCodecID id = ff_codec_get_id(tags[i], tag); - if (id != AV_CODEC_ID_NONE) - return id; - } - return AV_CODEC_ID_NONE; -} - -static int chapter_start_cmp(const void *p1, const void *p2) -{ - AVChapter *ch1 = *(AVChapter**)p1; - AVChapter *ch2 = *(AVChapter**)p2; - int delta = av_compare_ts(ch1->start, ch1->time_base, ch2->start, ch2->time_base); - if (delta) - return delta; - return FFDIFFSIGN(ch1->id, ch2->id); -} - -static int compute_chapters_end(AVFormatContext *s) -{ - int64_t max_time = 0; - AVChapter **timetable; - - if (!s->nb_chapters) - return 0; - - if (s->duration > 0 && s->start_time < INT64_MAX - s->duration) - max_time = s->duration + - ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time); - - timetable = av_memdup(s->chapters, s->nb_chapters * sizeof(*timetable)); - if (!timetable) - return AVERROR(ENOMEM); - qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp); - - for (unsigned i = 0; i < s->nb_chapters; i++) - if (timetable[i]->end == AV_NOPTS_VALUE) { - AVChapter *ch = timetable[i]; - int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q, - ch->time_base) - : INT64_MAX; - - if (i + 1 < s->nb_chapters) { - AVChapter *ch1 = timetable[i + 1]; - int64_t next_start = av_rescale_q(ch1->start, ch1->time_base, - ch->time_base); - if (next_start > ch->start && next_start < end) - end = next_start; - } - ch->end = (end == INT64_MAX || end < ch->start) ? ch->start : end; - } - av_free(timetable); - return 0; -} - -static int get_std_framerate(int i) -{ - if (i < 30*12) - return (i + 1) * 1001; - i -= 30*12; - - if (i < 30) - return (i + 31) * 1001 * 12; - i -= 30; - - if (i < 3) - return ((const int[]) { 80, 120, 240})[i] * 1001 * 12; - - i -= 3; - - return ((const int[]) { 24, 30, 60, 12, 15, 48 })[i] * 1000 * 12; -} - -/* Is the time base unreliable? - * This is a heuristic to balance between quick acceptance of the values in - * the headers vs. some extra checks. - * Old DivX and Xvid often have nonsense timebases like 1fps or 2fps. - * MPEG-2 commonly misuses field repeat flags to store different framerates. - * And there are "variable" fps files this needs to detect as well. */ -static int tb_unreliable(AVCodecContext *c) -{ - if (c->time_base.den >= 101LL * c->time_base.num || - c->time_base.den < 5LL * c->time_base.num || - // c->codec_tag == AV_RL32("DIVX") || - // c->codec_tag == AV_RL32("XVID") || - c->codec_tag == AV_RL32("mp4v") || - c->codec_id == AV_CODEC_ID_MPEG2VIDEO || - c->codec_id == AV_CODEC_ID_GIF || - c->codec_id == AV_CODEC_ID_HEVC || - c->codec_id == AV_CODEC_ID_H264) - return 1; - return 0; -} - -int ff_alloc_extradata(AVCodecParameters *par, int size) -{ - av_freep(&par->extradata); - par->extradata_size = 0; - - if (size < 0 || size >= INT32_MAX - AV_INPUT_BUFFER_PADDING_SIZE) - return AVERROR(EINVAL); - - par->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!par->extradata) - return AVERROR(ENOMEM); - - memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); - par->extradata_size = size; - - return 0; -} - -int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb, int size) -{ - int ret = ff_alloc_extradata(par, size); - if (ret < 0) - return ret; - ret = ffio_read_size(pb, par->extradata, size); - if (ret < 0) { - av_freep(&par->extradata); - par->extradata_size = 0; - av_log(s, AV_LOG_ERROR, "Failed to read extradata of size %d\n", size); - return ret; - } - - return ret; -} - -int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) -{ - FFStream *const sti = ffstream(st); - int64_t last = sti->info->last_dts; - - if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last - && ts - (uint64_t)last < INT64_MAX) { - double dts = (is_relative(ts) ? ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base); - int64_t duration = ts - last; - - if (!sti->info->duration_error) - sti->info->duration_error = av_mallocz(sizeof(sti->info->duration_error[0])*2); - if (!sti->info->duration_error) - return AVERROR(ENOMEM); - -// if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) -// av_log(NULL, AV_LOG_ERROR, "%f\n", dts); - for (int i = 0; i < MAX_STD_TIMEBASES; i++) { - if (sti->info->duration_error[0][1][i] < 1e10) { - int framerate = get_std_framerate(i); - double sdts = dts*framerate/(1001*12); - for (int j = 0; j < 2; j++) { - int64_t ticks = llrint(sdts+j*0.5); - double error= sdts - ticks + j*0.5; - sti->info->duration_error[j][0][i] += error; - sti->info->duration_error[j][1][i] += error*error; - } - } - } - if (sti->info->rfps_duration_sum <= INT64_MAX - duration) { - sti->info->duration_count++; - sti->info->rfps_duration_sum += duration; - } - - if (sti->info->duration_count % 10 == 0) { - int n = sti->info->duration_count; - for (int i = 0; i < MAX_STD_TIMEBASES; i++) { - if (sti->info->duration_error[0][1][i] < 1e10) { - double a0 = sti->info->duration_error[0][0][i] / n; - double error0 = sti->info->duration_error[0][1][i] / n - a0*a0; - double a1 = sti->info->duration_error[1][0][i] / n; - double error1 = sti->info->duration_error[1][1][i] / n - a1*a1; - if (error0 > 0.04 && error1 > 0.04) { - sti->info->duration_error[0][1][i] = 2e10; - sti->info->duration_error[1][1][i] = 2e10; - } - } - } - } - - // ignore the first 4 values, they might have some random jitter - if (sti->info->duration_count > 3 && is_relative(ts) == is_relative(last)) - sti->info->duration_gcd = av_gcd(sti->info->duration_gcd, duration); - } - if (ts != AV_NOPTS_VALUE) - sti->info->last_dts = ts; - - return 0; -} - -void ff_rfps_calculate(AVFormatContext *ic) -{ - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *st = ic->streams[i]; - FFStream *const sti = ffstream(st); - - if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) - continue; - // the check for tb_unreliable() is not completely correct, since this is not about handling - // an unreliable/inexact time base, but a time base that is finer than necessary, as e.g. - // ipmovie.c produces. - if (tb_unreliable(sti->avctx) && sti->info->duration_count > 15 && sti->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num && - sti->info->duration_gcd < INT64_MAX / st->time_base.num) - av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * sti->info->duration_gcd, INT_MAX); - if (sti->info->duration_count > 1 && !st->r_frame_rate.num - && tb_unreliable(sti->avctx)) { - int num = 0; - double best_error= 0.01; - AVRational ref_rate = st->r_frame_rate.num ? st->r_frame_rate : av_inv_q(st->time_base); - - for (int j = 0; j < MAX_STD_TIMEBASES; j++) { - if (sti->info->codec_info_duration && - sti->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) - continue; - if (!sti->info->codec_info_duration && get_std_framerate(j) < 1001*12) - continue; - - if (av_q2d(st->time_base) * sti->info->rfps_duration_sum / sti->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) - continue; - - for (int k = 0; k < 2; k++) { - int n = sti->info->duration_count; - double a = sti->info->duration_error[k][0][j] / n; - double error = sti->info->duration_error[k][1][j]/n - a*a; - - if (error < best_error && best_error> 0.000000001) { - best_error= error; - num = get_std_framerate(j); - } - if (error < 0.02) - av_log(ic, AV_LOG_DEBUG, "rfps: %f %f\n", get_std_framerate(j) / 12.0/1001, error); - } - } - // do not increase frame rate by more than 1 % in order to match a standard rate. - if (num && (!ref_rate.num || (double)num/(12*1001) < 1.01 * av_q2d(ref_rate))) - av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX); - } - if ( !st->avg_frame_rate.num - && st->r_frame_rate.num && sti->info->rfps_duration_sum - && sti->info->codec_info_duration <= 0 - && sti->info->duration_count > 2 - && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - sti->info->rfps_duration_sum / (double)sti->info->duration_count) <= 1.0 - ) { - av_log(ic, AV_LOG_DEBUG, "Setting avg frame rate based on r frame rate\n"); - st->avg_frame_rate = st->r_frame_rate; - } - - av_freep(&sti->info->duration_error); - sti->info->last_dts = AV_NOPTS_VALUE; - sti->info->duration_count = 0; - sti->info->rfps_duration_sum = 0; - } -} - -static int extract_extradata_check(AVStream *st) -{ - const AVBitStreamFilter *f; - - f = av_bsf_get_by_name("extract_extradata"); - if (!f) - return 0; - - if (f->codec_ids) { - const enum AVCodecID *ids; - for (ids = f->codec_ids; *ids != AV_CODEC_ID_NONE; ids++) - if (*ids == st->codecpar->codec_id) - return 1; - } - - return 0; -} - -static int extract_extradata_init(AVStream *st) -{ - FFStream *sti = ffstream(st); - const AVBitStreamFilter *f; - int ret; - - f = av_bsf_get_by_name("extract_extradata"); - if (!f) - goto finish; - - /* check that the codec id is supported */ - ret = extract_extradata_check(st); - if (!ret) - goto finish; - - ret = av_bsf_alloc(f, &sti->extract_extradata.bsf); - if (ret < 0) - return ret; - - ret = avcodec_parameters_copy(sti->extract_extradata.bsf->par_in, - st->codecpar); - if (ret < 0) - goto fail; - - sti->extract_extradata.bsf->time_base_in = st->time_base; - - ret = av_bsf_init(sti->extract_extradata.bsf); - if (ret < 0) - goto fail; - -finish: - sti->extract_extradata.inited = 1; - - return 0; -fail: - av_bsf_free(&sti->extract_extradata.bsf); - return ret; -} - -static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt) -{ - FFStream *sti = ffstream(st); - AVPacket *pkt_ref = si->parse_pkt; - int ret; - - if (!sti->extract_extradata.inited) { - ret = extract_extradata_init(st); - if (ret < 0) - return ret; - } - - if (sti->extract_extradata.inited && !sti->extract_extradata.bsf) - return 0; - - ret = av_packet_ref(pkt_ref, pkt); - if (ret < 0) - return ret; - - ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref); - if (ret < 0) { - av_packet_unref(pkt_ref); - return ret; - } - - while (ret >= 0 && !sti->avctx->extradata) { - ret = av_bsf_receive_packet(sti->extract_extradata.bsf, pkt_ref); - if (ret < 0) { - if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) - return ret; - continue; - } - - for (int i = 0; i < pkt_ref->side_data_elems; i++) { - AVPacketSideData *side_data = &pkt_ref->side_data[i]; - if (side_data->type == AV_PKT_DATA_NEW_EXTRADATA) { - sti->avctx->extradata = side_data->data; - sti->avctx->extradata_size = side_data->size; - side_data->data = NULL; - side_data->size = 0; - break; - } - } - av_packet_unref(pkt_ref); - } - - return 0; -} - -static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) -{ - for (int i = 0; i < avctx->nb_coded_side_data; i++) { - const AVPacketSideData *sd_src = &avctx->coded_side_data[i]; - uint8_t *dst_data; - dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size); - if (!dst_data) - return AVERROR(ENOMEM); - memcpy(dst_data, sd_src->data, sd_src->size); - } - return 0; + const AVCodecDescriptor *d = avcodec_descriptor_get(id); + if (!d) + return 0; + if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) && + !(d->props & AV_CODEC_PROP_INTRA_ONLY)) + return 0; + return 1; } -int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) +/* XXX: suppress the packet queue */ +void ff_flush_packet_queue(AVFormatContext *s) { - FFFormatContext *const si = ffformatcontext(ic); - int count = 0, ret = 0; - int64_t read_size; - AVPacket *pkt1 = si->pkt; - int64_t old_offset = avio_tell(ic->pb); - // new streams might appear, no options for those - int orig_nb_streams = ic->nb_streams; - int flush_codecs; - int64_t max_analyze_duration = ic->max_analyze_duration; - int64_t max_stream_analyze_duration; - int64_t max_subtitle_analyze_duration; - int64_t probesize = ic->probesize; - int eof_reached = 0; - int *missing_streams = av_opt_ptr(ic->iformat->priv_class, ic->priv_data, "missing_streams"); - - flush_codecs = probesize > 0; - - av_opt_set(ic, "skip_clear", "1", AV_OPT_SEARCH_CHILDREN); - - max_stream_analyze_duration = max_analyze_duration; - max_subtitle_analyze_duration = max_analyze_duration; - if (!max_analyze_duration) { - max_stream_analyze_duration = - max_analyze_duration = 5*AV_TIME_BASE; - max_subtitle_analyze_duration = 30*AV_TIME_BASE; - if (!strcmp(ic->iformat->name, "flv")) - max_stream_analyze_duration = 90*AV_TIME_BASE; - if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts")) - max_stream_analyze_duration = 7*AV_TIME_BASE; - } - - if (ic->pb) { - FFIOContext *const ctx = ffiocontext(ic->pb); - av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d nb_streams:%d\n", - avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, ic->nb_streams); - } - - for (unsigned i = 0; i < ic->nb_streams; i++) { - const AVCodec *codec; - AVDictionary *thread_opt = NULL; - AVStream *const st = ic->streams[i]; - FFStream *const sti = ffstream(st); - AVCodecContext *const avctx = sti->avctx; - - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || - st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { -/* if (!st->time_base.num) - st->time_base = */ - if (!avctx->time_base.num) - avctx->time_base = st->time_base; - } - - /* check if the caller has overridden the codec id */ - // only for the split stuff - if (!sti->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && sti->request_probe <= 0) { - sti->parser = av_parser_init(st->codecpar->codec_id); - if (sti->parser) { - if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) { - sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; - } else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) { - sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; - } - } else if (sti->need_parsing) { - av_log(ic, AV_LOG_VERBOSE, "parser not found for codec " - "%s, packets or times may be invalid.\n", - avcodec_get_name(st->codecpar->codec_id)); - } - } - - ret = avcodec_parameters_to_context(avctx, st->codecpar); - if (ret < 0) - goto find_stream_info_err; - if (sti->request_probe <= 0) - sti->avctx_inited = 1; - - codec = find_probe_decoder(ic, st, st->codecpar->codec_id); - - /* Force thread count to 1 since the H.264 decoder will not extract - * SPS and PPS to extradata during multi-threaded decoding. */ - av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0); - /* Force lowres to 0. The decoder might reduce the video size by the - * lowres factor, and we don't want that propagated to the stream's - * codecpar */ - av_dict_set(options ? &options[i] : &thread_opt, "lowres", "0", 0); - - if (ic->codec_whitelist) - av_dict_set(options ? &options[i] : &thread_opt, "codec_whitelist", ic->codec_whitelist, 0); - - // Try to just open decoders, in case this is enough to get parameters. - // Also ensure that subtitle_header is properly set. - if (!has_codec_parameters(st, NULL) && sti->request_probe <= 0 || - st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { - if (codec && !avctx->codec) - if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0) - av_log(ic, AV_LOG_WARNING, - "Failed to open codec in %s\n",__FUNCTION__); - } - if (!options) - av_dict_free(&thread_opt); - } + FFFormatContext *const si = ffformatcontext(s); + avpriv_packet_list_free(&si->parse_queue, &si->parse_queue_end); + avpriv_packet_list_free(&si->packet_buffer, &si->packet_buffer_end); + avpriv_packet_list_free(&si->raw_packet_buffer, &si->raw_packet_buffer_end); - read_size = 0; - for (;;) { - const AVPacket *pkt; - AVStream *st; - FFStream *sti; - AVCodecContext *avctx; - int analyzed_all_streams; - unsigned i; - if (ff_check_interrupt(&ic->interrupt_callback)) { - ret = AVERROR_EXIT; - av_log(ic, AV_LOG_DEBUG, "interrupted\n"); - break; - } + si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; +} - /* check if one codec still needs to be handled */ - for (i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - FFStream *const sti = ffstream(st); - int fps_analyze_framecount = 20; - int count; +int av_find_default_stream_index(AVFormatContext *s) +{ + int best_stream = 0; + int best_score = INT_MIN; - if (!has_codec_parameters(st, NULL)) - break; - /* If the timebase is coarse (like the usual millisecond precision - * of mkv), we need to analyze more frames to reliably arrive at - * the correct fps. */ - if (av_q2d(st->time_base) > 0.0005) - fps_analyze_framecount *= 2; - if (!tb_unreliable(sti->avctx)) - fps_analyze_framecount = 0; - if (ic->fps_probe_size >= 0) - fps_analyze_framecount = ic->fps_probe_size; + if (s->nb_streams <= 0) + return -1; + for (unsigned i = 0; i < s->nb_streams; i++) { + const AVStream *const st = s->streams[i]; + int score = 0; + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) - fps_analyze_framecount = 0; - /* variable fps and no guess at the real fps */ - count = (ic->iformat->flags & AVFMT_NOTIMESTAMPS) ? - sti->info->codec_info_duration_fields/2 : - sti->info->duration_count; - if (!(st->r_frame_rate.num && st->avg_frame_rate.num) && - st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - if (count < fps_analyze_framecount) - break; - } - // Look at the first 3 frames if there is evidence of frame delay - // but the decoder delay is not set. - if (sti->info->frame_delay_evidence && count < 2 && sti->avctx->has_b_frames == 0) - break; - if (!sti->avctx->extradata && - (!sti->extract_extradata.inited || sti->extract_extradata.bsf) && - extract_extradata_check(st)) - break; - if (sti->first_dts == AV_NOPTS_VALUE && - !(ic->iformat->flags & AVFMT_NOTIMESTAMPS) && - sti->codec_info_nb_frames < ((st->disposition & AV_DISPOSITION_ATTACHED_PIC) ? 1 : ic->max_ts_probe) && - (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || - st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) - break; + score -= 400; + if (st->codecpar->width && st->codecpar->height) + score += 50; + score+= 25; } - analyzed_all_streams = 0; - if (!missing_streams || !*missing_streams) - if (i == ic->nb_streams) { - analyzed_all_streams = 1; - /* NOTE: If the format has no header, then we need to read some - * packets to get most of the streams, so we cannot stop here. */ - if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) { - /* If we found the info for all the codecs, we can stop. */ - ret = count; - av_log(ic, AV_LOG_DEBUG, "All info found\n"); - flush_codecs = 0; - break; - } - } - /* We did not get all the codec info, but we read too much data. */ - if (read_size >= probesize) { - ret = count; - av_log(ic, AV_LOG_DEBUG, - "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - if (!st->r_frame_rate.num && - ffstream(st)->info->duration_count <= 1 && - st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && - strcmp(ic->iformat->name, "image2")) - av_log(ic, AV_LOG_WARNING, - "Stream #%d: not enough frames to estimate rate; " - "consider increasing probesize\n", i); - } - break; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->sample_rate) + score += 50; } + if (cffstream(st)->codec_info_nb_frames) + score += 12; - /* NOTE: A new stream can be added there if no header in file - * (AVFMTCTX_NOHEADER). */ - ret = read_frame_internal(ic, pkt1); - if (ret == AVERROR(EAGAIN)) - continue; + if (st->discard != AVDISCARD_ALL) + score += 200; - if (ret < 0) { - /* EOF or error*/ - eof_reached = 1; - break; + if (score > best_score) { + best_score = score; + best_stream = i; } + } + return best_stream; +} - if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { - ret = avpriv_packet_list_put(&si->packet_buffer, - &si->packet_buffer_end, - pkt1, NULL, 0); - if (ret < 0) - goto unref_then_goto_end; - - pkt = &si->packet_buffer_end->pkt; - } else { - pkt = pkt1; - } +/*******************************************************/ - st = ic->streams[pkt->stream_index]; - sti = ffstream(st); - if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) - read_size += pkt->size; +unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id) +{ + while (tags->id != AV_CODEC_ID_NONE) { + if (tags->id == id) + return tags->tag; + tags++; + } + return 0; +} - avctx = sti->avctx; - if (!sti->avctx_inited) { - ret = avcodec_parameters_to_context(avctx, st->codecpar); - if (ret < 0) - goto unref_then_goto_end; - sti->avctx_inited = 1; - } +enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag) +{ + for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) + if (tag == tags[i].tag) + return tags[i].id; + for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) + if (avpriv_toupper4(tag) == avpriv_toupper4(tags[i].tag)) + return tags[i].id; + return AV_CODEC_ID_NONE; +} - if (pkt->dts != AV_NOPTS_VALUE && sti->codec_info_nb_frames > 1) { - /* check for non-increasing dts */ - if (sti->info->fps_last_dts != AV_NOPTS_VALUE && - sti->info->fps_last_dts >= pkt->dts) { - av_log(ic, AV_LOG_DEBUG, - "Non-increasing DTS in stream %d: packet %d with DTS " - "%"PRId64", packet %d with DTS %"PRId64"\n", - st->index, sti->info->fps_last_dts_idx, - sti->info->fps_last_dts, sti->codec_info_nb_frames, - pkt->dts); - sti->info->fps_first_dts = - sti->info->fps_last_dts = AV_NOPTS_VALUE; - } - /* Check for a discontinuity in dts. If the difference in dts - * is more than 1000 times the average packet duration in the - * sequence, we treat it as a discontinuity. */ - if (sti->info->fps_last_dts != AV_NOPTS_VALUE && - sti->info->fps_last_dts_idx > sti->info->fps_first_dts_idx && - (pkt->dts - (uint64_t)sti->info->fps_last_dts) / 1000 > - (sti->info->fps_last_dts - (uint64_t)sti->info->fps_first_dts) / - (sti->info->fps_last_dts_idx - sti->info->fps_first_dts_idx)) { - av_log(ic, AV_LOG_WARNING, - "DTS discontinuity in stream %d: packet %d with DTS " - "%"PRId64", packet %d with DTS %"PRId64"\n", - st->index, sti->info->fps_last_dts_idx, - sti->info->fps_last_dts, sti->codec_info_nb_frames, - pkt->dts); - sti->info->fps_first_dts = - sti->info->fps_last_dts = AV_NOPTS_VALUE; - } +enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags) +{ + if (bps <= 0 || bps > 64) + return AV_CODEC_ID_NONE; - /* update stored dts values */ - if (sti->info->fps_first_dts == AV_NOPTS_VALUE) { - sti->info->fps_first_dts = pkt->dts; - sti->info->fps_first_dts_idx = sti->codec_info_nb_frames; - } - sti->info->fps_last_dts = pkt->dts; - sti->info->fps_last_dts_idx = sti->codec_info_nb_frames; + if (flt) { + switch (bps) { + case 32: + return be ? AV_CODEC_ID_PCM_F32BE : AV_CODEC_ID_PCM_F32LE; + case 64: + return be ? AV_CODEC_ID_PCM_F64BE : AV_CODEC_ID_PCM_F64LE; + default: + return AV_CODEC_ID_NONE; } - if (sti->codec_info_nb_frames > 1) { - int64_t t = 0; - int64_t limit; - - if (st->time_base.den > 0) - t = av_rescale_q(sti->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); - if (st->avg_frame_rate.num > 0) - t = FFMAX(t, av_rescale_q(sti->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); - - if ( t == 0 - && sti->codec_info_nb_frames > 30 - && sti->info->fps_first_dts != AV_NOPTS_VALUE - && sti->info->fps_last_dts != AV_NOPTS_VALUE) { - int64_t dur = av_sat_sub64(sti->info->fps_last_dts, sti->info->fps_first_dts); - t = FFMAX(t, av_rescale_q(dur, st->time_base, AV_TIME_BASE_Q)); - } - - if (analyzed_all_streams) limit = max_analyze_duration; - else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) limit = max_subtitle_analyze_duration; - else limit = max_stream_analyze_duration; - - if (t >= limit) { - av_log(ic, AV_LOG_VERBOSE, "max_analyze_duration %"PRId64" reached at %"PRId64" microseconds st:%d\n", - limit, - t, pkt->stream_index); - if (ic->flags & AVFMT_FLAG_NOBUFFER) - av_packet_unref(pkt1); - break; + } else { + bps += 7; + bps >>= 3; + if (sflags & (1 << (bps - 1))) { + switch (bps) { + case 1: + return AV_CODEC_ID_PCM_S8; + case 2: + return be ? AV_CODEC_ID_PCM_S16BE : AV_CODEC_ID_PCM_S16LE; + case 3: + return be ? AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE; + case 4: + return be ? AV_CODEC_ID_PCM_S32BE : AV_CODEC_ID_PCM_S32LE; + case 8: + return be ? AV_CODEC_ID_PCM_S64BE : AV_CODEC_ID_PCM_S64LE; + default: + return AV_CODEC_ID_NONE; } - if (pkt->duration) { - if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time - && (uint64_t)pkt->pts - st->start_time < INT64_MAX - ) { - sti->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, sti->info->codec_info_duration + pkt->duration); - } else - sti->info->codec_info_duration += pkt->duration; - sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && avctx->ticks_per_frame == 2 - ? sti->parser->repeat_pict + 1 : 2; + } else { + switch (bps) { + case 1: + return AV_CODEC_ID_PCM_U8; + case 2: + return be ? AV_CODEC_ID_PCM_U16BE : AV_CODEC_ID_PCM_U16LE; + case 3: + return be ? AV_CODEC_ID_PCM_U24BE : AV_CODEC_ID_PCM_U24LE; + case 4: + return be ? AV_CODEC_ID_PCM_U32BE : AV_CODEC_ID_PCM_U32LE; + default: + return AV_CODEC_ID_NONE; } } - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { -#if FF_API_R_FRAME_RATE - ff_rfps_add_frame(ic, st, pkt->dts); -#endif - if (pkt->dts != pkt->pts && pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) - sti->info->frame_delay_evidence = 1; - } - if (!sti->avctx->extradata) { - ret = extract_extradata(si, st, pkt); - if (ret < 0) - goto unref_then_goto_end; - } - - /* If still no information, we try to open the codec and to - * decompress the frame. We try to avoid that in most cases as - * it takes longer and uses more memory. For MPEG-4, we need to - * decompress for QuickTime. - * - * If AV_CODEC_CAP_CHANNEL_CONF is set this will force decoding of at - * least one frame of codec data, this makes sure the codec initializes - * the channel configuration and does not only trust the values from - * the container. */ - try_decode_frame(ic, st, pkt, - (options && i < orig_nb_streams) ? &options[i] : NULL); - - if (ic->flags & AVFMT_FLAG_NOBUFFER) - av_packet_unref(pkt1); - - sti->codec_info_nb_frames++; - count++; } +} - if (eof_reached) { - for (unsigned stream_index = 0; stream_index < ic->nb_streams; stream_index++) { - AVStream *const st = ic->streams[stream_index]; - AVCodecContext *const avctx = ffstream(st)->avctx; - if (!has_codec_parameters(st, NULL)) { - const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id); - if (codec && !avctx->codec) { - AVDictionary *opts = NULL; - if (ic->codec_whitelist) - av_dict_set(&opts, "codec_whitelist", ic->codec_whitelist, 0); - if (avcodec_open2(avctx, codec, (options && stream_index < orig_nb_streams) ? &options[stream_index] : &opts) < 0) - av_log(ic, AV_LOG_WARNING, - "Failed to open codec in %s\n",__FUNCTION__); - av_dict_free(&opts); - } - } +unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id) +{ + unsigned int tag; + if (!av_codec_get_tag2(tags, id, &tag)) + return 0; + return tag; +} - // EOF already reached while reading the stream above. - // So continue with reoordering DTS with whatever delay we have. - if (si->packet_buffer && !has_decode_delay_been_guessed(st)) { - update_dts_from_pts(ic, stream_index, si->packet_buffer); +int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id, + unsigned int *tag) +{ + for (int i = 0; tags && tags[i]; i++) { + const AVCodecTag *codec_tags = tags[i]; + while (codec_tags->id != AV_CODEC_ID_NONE) { + if (codec_tags->id == id) { + *tag = codec_tags->tag; + return 1; } + codec_tags++; } } + return 0; +} - if (flush_codecs) { - AVPacket *empty_pkt = si->pkt; - int err = 0; - av_packet_unref(empty_pkt); - - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - - /* flush the decoders */ - if (ffstream(st)->info->found_decoder == 1) { - do { - err = try_decode_frame(ic, st, empty_pkt, - (options && i < orig_nb_streams) - ? &options[i] : NULL); - } while (err > 0 && !has_codec_parameters(st, NULL)); - - if (err < 0) { - av_log(ic, AV_LOG_INFO, - "decoding for stream %d failed\n", st->index); - } - } - } +enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag) +{ + for (int i = 0; tags && tags[i]; i++) { + enum AVCodecID id = ff_codec_get_id(tags[i], tag); + if (id != AV_CODEC_ID_NONE) + return id; } + return AV_CODEC_ID_NONE; +} - ff_rfps_calculate(ic); - - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - FFStream *const sti = ffstream(st); - AVCodecContext *const avctx = sti->avctx; - - if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { - if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) { - uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); - if (avpriv_find_pix_fmt(avpriv_get_raw_pix_fmt_tags(), tag) == avctx->pix_fmt) - avctx->codec_tag= tag; - } +int ff_alloc_extradata(AVCodecParameters *par, int size) +{ + av_freep(&par->extradata); + par->extradata_size = 0; - /* estimate average framerate if not set by demuxer */ - if (sti->info->codec_info_duration_fields && - !st->avg_frame_rate.num && - sti->info->codec_info_duration) { - int best_fps = 0; - double best_error = 0.01; - AVRational codec_frame_rate = avctx->framerate; - - if (sti->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| - sti->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || - sti->info->codec_info_duration < 0) - continue; - av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, - sti->info->codec_info_duration_fields * (int64_t) st->time_base.den, - sti->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); - - /* Round guessed framerate to a "standard" framerate if it's - * within 1% of the original estimate. */ - for (int j = 0; j < MAX_STD_TIMEBASES; j++) { - AVRational std_fps = { get_std_framerate(j), 12 * 1001 }; - double error = fabs(av_q2d(st->avg_frame_rate) / - av_q2d(std_fps) - 1); - - if (error < best_error) { - best_error = error; - best_fps = std_fps.num; - } + if (size < 0 || size >= INT32_MAX - AV_INPUT_BUFFER_PADDING_SIZE) + return AVERROR(EINVAL); - if (si->prefer_codec_framerate && codec_frame_rate.num > 0 && codec_frame_rate.den > 0) { - error = fabs(av_q2d(codec_frame_rate) / - av_q2d(std_fps) - 1); - if (error < best_error) { - best_error = error; - best_fps = std_fps.num; - } - } - } - if (best_fps) - av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, - best_fps, 12 * 1001, INT_MAX); - } + par->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!par->extradata) + return AVERROR(ENOMEM); - if (!st->r_frame_rate.num) { - if ( avctx->time_base.den * (int64_t) st->time_base.num - <= avctx->time_base.num * (uint64_t)avctx->ticks_per_frame * st->time_base.den) { - av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, - avctx->time_base.den, (int64_t)avctx->time_base.num * avctx->ticks_per_frame, INT_MAX); - } else { - st->r_frame_rate.num = st->time_base.den; - st->r_frame_rate.den = st->time_base.num; - } - } - if (sti->display_aspect_ratio.num && sti->display_aspect_ratio.den) { - AVRational hw_ratio = { avctx->height, avctx->width }; - st->sample_aspect_ratio = av_mul_q(sti->display_aspect_ratio, - hw_ratio); - } - } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { - if (!avctx->bits_per_coded_sample) - avctx->bits_per_coded_sample = - av_get_bits_per_sample(avctx->codec_id); - // set stream disposition based on audio service type - switch (avctx->audio_service_type) { - case AV_AUDIO_SERVICE_TYPE_EFFECTS: - st->disposition = AV_DISPOSITION_CLEAN_EFFECTS; - break; - case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: - st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED; - break; - case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: - st->disposition = AV_DISPOSITION_HEARING_IMPAIRED; - break; - case AV_AUDIO_SERVICE_TYPE_COMMENTARY: - st->disposition = AV_DISPOSITION_COMMENT; - break; - case AV_AUDIO_SERVICE_TYPE_KARAOKE: - st->disposition = AV_DISPOSITION_KARAOKE; - break; - } - } - } + memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); + par->extradata_size = size; - if (probesize) - estimate_timings(ic, old_offset); - - av_opt_set(ic, "skip_clear", "0", AV_OPT_SEARCH_CHILDREN); - - if (ret >= 0 && ic->nb_streams) - /* We could not have all the codec parameters before EOF. */ - ret = -1; - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - FFStream *const sti = ffstream(st); - const char *errmsg; - - /* if no packet was ever seen, update context now for has_codec_parameters */ - if (!sti->avctx_inited) { - if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && - st->codecpar->format == AV_SAMPLE_FMT_NONE) - st->codecpar->format = sti->avctx->sample_fmt; - ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); - if (ret < 0) - goto find_stream_info_err; - } - if (!has_codec_parameters(st, &errmsg)) { - char buf[256]; - avcodec_string(buf, sizeof(buf), sti->avctx, 0); - av_log(ic, AV_LOG_WARNING, - "Could not find codec parameters for stream %d (%s): %s\n" - "Consider increasing the value for the 'analyzeduration' (%"PRId64") and 'probesize' (%"PRId64") options\n", - i, buf, errmsg, ic->max_analyze_duration, ic->probesize); - } else { - ret = 0; - } - } + return 0; +} - ret = compute_chapters_end(ic); +int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb, int size) +{ + int ret = ff_alloc_extradata(par, size); if (ret < 0) - goto find_stream_info_err; - - /* update the stream parameters from the internal codec contexts */ - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - FFStream *const sti = ffstream(st); - - if (sti->avctx_inited) { - ret = avcodec_parameters_from_context(st->codecpar, sti->avctx); - if (ret < 0) - goto find_stream_info_err; - ret = add_coded_side_data(st, sti->avctx); - if (ret < 0) - goto find_stream_info_err; - } - - sti->avctx_inited = 0; + return ret; + ret = ffio_read_size(pb, par->extradata, size); + if (ret < 0) { + av_freep(&par->extradata); + par->extradata_size = 0; + av_log(s, AV_LOG_ERROR, "Failed to read extradata of size %d\n", size); + return ret; } -find_stream_info_err: - for (unsigned i = 0; i < ic->nb_streams; i++) { - AVStream *const st = ic->streams[i]; - FFStream *const sti = ffstream(st); - if (sti->info) { - av_freep(&sti->info->duration_error); - av_freep(&sti->info); - } - avcodec_close(sti->avctx); - av_bsf_free(&sti->extract_extradata.bsf); - } - if (ic->pb) { - FFIOContext *const ctx = ffiocontext(ic->pb); - av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n", - avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, count); - } return ret; - -unref_then_goto_end: - av_packet_unref(pkt1); - goto find_stream_info_err; } AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s) @@ -3424,7 +526,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, if (type == AVMEDIA_TYPE_AUDIO && !(par->channels && par->sample_rate)) continue; if (decoder_ret) { - decoder = find_decoder(ic, st, par->codec_id); + decoder = ff_find_decoder(ic, st, par->codec_id); if (!decoder) { if (ret < 0) ret = AVERROR_DECODER_NOT_FOUND; @@ -3617,32 +719,6 @@ void avformat_free_context(AVFormatContext *s) av_free(s); } -void avformat_close_input(AVFormatContext **ps) -{ - AVFormatContext *s; - AVIOContext *pb; - - if (!ps || !*ps) - return; - - s = *ps; - pb = s->pb; - - if ((s->iformat && strcmp(s->iformat->name, "image2") && s->iformat->flags & AVFMT_NOFILE) || - (s->flags & AVFMT_FLAG_CUSTOM_IO)) - pb = NULL; - - if (s->iformat) - if (s->iformat->read_close) - s->iformat->read_close(s); - - avformat_free_context(s); - - *ps = NULL; - - avio_close(pb); -} - AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) { FFStream *sti;