From patchwork Thu Sep 9 15:50:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30086 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp642628iov; Thu, 9 Sep 2021 08:51:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZti9WVoEHnPk9ZK73gZOyQ2yUhr33sjLqqmA5PKG6eHwBkLMaQskgEAjadKVM1/jcXOka X-Received: by 2002:a17:906:abd7:: with SMTP id kq23mr4070858ejb.542.1631202671404; Thu, 09 Sep 2021 08:51:11 -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 x17si2093183edr.232.2021.09.09.08.51.10; Thu, 09 Sep 2021 08:51:11 -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=vKQ96JDp; 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 92CE168A126; Thu, 9 Sep 2021 18:51:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2025.outbound.protection.outlook.com [40.92.89.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3096968A126 for ; Thu, 9 Sep 2021 18:51:00 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=erG4iaxEOSJ7PHCtk7MWGzETh97XYYaQ6f4h4gXjgOMrQsGQMXPa90hqAzAmuTKzUYwC0lNZwj1Yq2tgcQHKEUYsz0nDAwFDOvzXDdYFxOh5DQ0TqoyKAs7dEKZrwCbgtnsJGoEZI1D8GLaK6Ikl3QTKkYNMv+vdOG+CmXMjMv+k3ai2//mupo1MTvNcHcgRgMryrZxRw+Q3MXyapKUCy4/InFyomqfmO+s3ax2JvWjihmB0oNPMUQJcUhsxsuzQE9e+xhgNhaRpe2jvduBQeh92hYF4QwOR9Q8aHsxtr2S048tpxwmOnCu5MmwRvlwvqSpItqjbF6JSA+aKLOQKQg== 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; bh=aC1vRRl+O9LxIttxzkk4Ly//L4AbgosCrc22+n2gakg=; b=AzhOBaEwI5Kb6AH1xB2bYdf7guRyCb/9SlwiNRk4GePOx5aqWPnofEgdjZdxlyDhRPk3WnxSyFAL8f26DHQu0khmzbfQYiWo7wx8K7R/UxOvljud/M0N5CZLqY0PpxdkVhxOHFlCKmJ7aKg++WuUj3ToRu6K3yBx9FGWiQbDpwqIbagLKuyPEl4oOyXAXAMrbzAGzvVWvHNC9FdcYwF2MaBz6uhTzANTQQW8WuVv7DZ/a4VbcCRGmxLI7U08UEHkZKAfDRVHSSnyS+nu4TRe22h8C4t7M6YwVj9a8Iw8lwu0hkwMb3sFkvcxxy6J5siThcqpCnaZ8TKiR9JVboBeUA== 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=aC1vRRl+O9LxIttxzkk4Ly//L4AbgosCrc22+n2gakg=; b=vKQ96JDpckTY4lqQ8vEiliUSbCBKJ7OlzyJ9IO77l8FTuULwmWVYjrwtU+a4lQUvLxLQqJYCJflMTkeWQC8gIRafq5oVErT1AXSAs9MawmvBWGu4vyPedhhfqzEB/WAE7QmBcrQgSh+eJLUaOKLHqMkRaaI8YIxnd/+5jgkY6KzIo5rFkuRR1+vpUd3n4Gy2NAlLItWHprm7YMg/SivsfbJ15Fm6hczgTc0hpt06iGgF78zeMACc26sbkTUWCjkjtneTiIsXUcV5PgEXUQ6GinSfW+P+ccLf6P7+ik5ICO7KN8h9foEYhQcdQXbA1O7kDlixeScxgTforiAd8KehiA== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6880.eurprd03.prod.outlook.com (2603:10a6:102:e4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.16; Thu, 9 Sep 2021 15:50:58 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:50:58 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:50:38 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 X-TMN: [yU8THfRgswa9HvrY6cN6Kq6tJ3RIBTUJ] X-ClientProxiedBy: AM0PR01CA0169.eurprd01.prod.exchangelabs.com (2603:10a6:208:aa::38) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155051.1841354-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR01CA0169.eurprd01.prod.exchangelabs.com (2603:10a6:208:aa::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:50:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dec46e63-a8bd-4626-66f5-08d973a99dd7 X-MS-Exchange-SLBlob-MailProps: 6qklvm/at0p/2h/IwjM+J4vA3FxDmJV+YQgnFaxRKaXkVwsNkBLrLv3CfC0KTjyyf+Ne57LK8b6OCfQcdBDZkTmX3hcL4fy6/DJKAx2BNvOHBlD1gTbUT9mX1P6RHId49SmO0SIb1mKY68O4AK0OQKX1+KnRMLn30WFjju83JodlK0Lb8hRs0nrzCVnTisQrERyZwcjtiBqmAZOJYvGp32hFue8C1dnbUq9OXUKLNPyks5+lwSCv6sX9M3KevczptJsXTWZiGPp0CDfoWxE8pvc2V06zTpSm0088aPBTOOheQmXfBEdTi1S5aLtuoAfQ4SJdSvWHom2SMMCdKMtTfusYYGgD34Trawmx9ydj4XcCZ8R3mI0YhpL3hwHfgBuLA2xwHvQ0bKTRuW65GtZEayqwkkWfxdyJr06LiStVa9y1riJAGreQ67kiRqcIxMXddptAdAwLU39iEH5i6cL961egf+jZNeP/Bcj4MOzffZ4m142yfaxgwIKKkhXa2wewQfZyVs2+1OBf4kz+BoCq+T3W9W6A3QIjXsupiOIkW9j5LyenlyrArev8JXmY46bpLAuee488OYdVEvtpPLNh5OfUtuEx+xq3gsmvCk/Ih4heGqiPipwy/7g85qt3k1Wo0FVta5Q7Ph+RBiBMSdwbr7CubL6DuxX/RNmIafh4jrFBAA8b5wIa4/0AZJ1oq9hVedwQ9yZ1PuxLxs1LqzQAOr+WIYpYEh/W6e3iaYFHpr4KHCtGzFfCnquvAh7aFw/qd4CjoEDBX/5Mnovx38du8ahLpqrQC/fpNWbpRX8HFblA7Pyxc8CMiQmTti5XTY2a X-MS-TrafficTypeDiagnostic: PA4PR03MB6880: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /2SlkBD3SvlqwWFuZnXeY0qhnuBETKDhKl9wtseizoPVPRSisaJVzvUIxbUMJkKejwQ9VpG3pYh+LgWOdvMJi2EYWBhcUePdWe1HJ6P8kNk1Mmru7c0tHqbkK82tLT/h0wnlK6g4XhF1O5+g7UDkLiy5xRYG5CTaUWLQyBI7Jwko+FiCqwxdHSOfC8TOCR/KSenRmGbVqvCCJPGRcfYD3tb3WsjQHYsE0lwaMKVGoKy64ohvRX6EfMN1EhnHEqEcdgG+8M8ETwQEWpcPhxomx5ZZc1Yc4jw+Ta/crSV2PcCM7RDb856kq5Ja/fTZZq+bcINaAPTfKqEXLdodbOqunk6+/QQyNytRDVrCmYjFXNjaaZexToUBiJNyKzRz4T6Jwq1NHAl1BkU5OZfwGNW/AuJdGAsTLSnUM54iLbbloINCIvVXpD4zAn6CzFKf9dsnPtb11ezNbGJMB0hAWfYTOovyqe2YOahrOzuKlN2uxTE= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dSNBlUDkhK2TPb0ML5A3HNGxkxD5bKcmtywBKM8qY5YLzK3yxJu+B6zilTPuyqiM/ggjgMx/BRmKfJ1scSUyoTuFlQfQWYAPNY8hvOhOKG05nTT2h/6EH58Zdb2KzIixdRQhE+FGVlU/AowsGHDItQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: dec46e63-a8bd-4626-66f5-08d973a99dd7 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:50:58.7967 (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: PA4PR03MB6880 Subject: [FFmpeg-devel] [PATCH 01/14] Revert "avfilter/af_silenceremove: fix processing of periods > 1" 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: kVATX1XAkSNK This reverts commits 3b331468dae2e88ee6c87c257ac159ad662efcac and 8a42ee6697317d0a30438df5905dfc0247cd28e7. They broke the filter-silenceremove FATE-test, as they were pushed without updating the reference file. Worse, the new output is not bitexact across all arches, as the diff on aarch64 is different; see e.g. http://fate.ffmpeg.org/report.cgi?slot=aarch64-linux-clang-10&time=20210909013452 and http://fate.ffmpeg.org/report.cgi?time=20210909095918&slot=x86_64-archlinux-gcc-threads-16 So revert the commits for now until this can be properly addressed. Signed-off-by: Andreas Rheinhardt --- I hope that this patch needn't be applied and include it here mainly so that patchwork won't be red for the other patches of this patchset. libavfilter/af_silenceremove.c | 79 ++++++++++------------------------ 1 file changed, 23 insertions(+), 56 deletions(-) diff --git a/libavfilter/af_silenceremove.c b/libavfilter/af_silenceremove.c index 6f3250bbb1..2f376eb1ca 100644 --- a/libavfilter/af_silenceremove.c +++ b/libavfilter/af_silenceremove.c @@ -23,7 +23,6 @@ #include /* DBL_MAX */ -#include "libavutil/audio_fifo.h" #include "libavutil/avassert.h" #include "libavutil/opt.h" #include "libavutil/timestamp.h" @@ -94,8 +93,6 @@ typedef struct SilenceRemoveContext { int64_t window_duration; double sum; - int threshold; - int one_period; int restart; int64_t next_pts; @@ -104,22 +101,20 @@ typedef struct SilenceRemoveContext { double (*compute)(struct SilenceRemoveContext *s, AVFrame *frame, int ch, int offset); void (*copy)(struct SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset); - - AVAudioFifo *fifo; } SilenceRemoveContext; #define OFFSET(x) offsetof(SilenceRemoveContext, x) #define AF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM static const AVOption silenceremove_options[] = { - { "start_periods", "set periods of silence parts to skip from start", OFFSET(start_periods), AV_OPT_TYPE_INT, {.i64=0}, 0, 9000, AF }, + { "start_periods", NULL, OFFSET(start_periods), AV_OPT_TYPE_INT, {.i64=0}, 0, 9000, AF }, { "start_duration", "set start duration of non-silence part", OFFSET(start_duration_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF }, { "start_threshold", "set threshold for start silence detection", OFFSET(start_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, AF }, { "start_silence", "set start duration of silence part to keep", OFFSET(start_silence_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF }, { "start_mode", "set which channel will trigger trimming from start", OFFSET(start_mode), AV_OPT_TYPE_INT, {.i64=T_ANY}, T_ANY, T_ALL, AF, "mode" }, { "any", 0, 0, AV_OPT_TYPE_CONST, {.i64=T_ANY}, 0, 0, AF, "mode" }, { "all", 0, 0, AV_OPT_TYPE_CONST, {.i64=T_ALL}, 0, 0, AF, "mode" }, - { "stop_periods", "set periods of silence parts to skip from end", OFFSET(stop_periods), AV_OPT_TYPE_INT, {.i64=0}, -9000, 9000, AF }, + { "stop_periods", NULL, OFFSET(stop_periods), AV_OPT_TYPE_INT, {.i64=0}, -9000, 9000, AF }, { "stop_duration", "set stop duration of non-silence part", OFFSET(stop_duration_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF }, { "stop_threshold", "set threshold for stop silence detection", OFFSET(stop_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, AF }, { "stop_silence", "set stop duration of silence part to keep", OFFSET(stop_silence_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF }, @@ -435,7 +430,6 @@ static int config_input(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; SilenceRemoveContext *s = ctx->priv; - s->threshold = -1; s->next_pts = AV_NOPTS_VALUE; s->window_duration = av_rescale(s->window_duration_opt, inlink->sample_rate, AV_TIME_BASE); @@ -545,16 +539,12 @@ static int config_input(AVFilterLink *inlink) return AVERROR_BUG; } - s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, 1024); - if (!s->fifo) - return AVERROR(ENOMEM); - return 0; } static void flush(SilenceRemoveContext *s, AVFrame *out, AVFilterLink *outlink, - int *nb_samples_written, int flush_silence) + int *nb_samples_written, int *ret, int flush_silence) { AVFrame *silence; @@ -566,18 +556,22 @@ static void flush(SilenceRemoveContext *s, (AVRational){1, outlink->sample_rate}, outlink->time_base); - av_audio_fifo_write(s->fifo, (void **)out->extended_data, out->nb_samples); + *ret = ff_filter_frame(outlink, out); + if (*ret < 0) + return; *nb_samples_written = 0; + } else { + av_frame_free(&out); } - av_frame_free(&out); - if (s->stop_silence_end <= 0 || !flush_silence) return; silence = ff_get_audio_buffer(outlink, s->stop_silence_end); - if (!silence) + if (!silence) { + *ret = AVERROR(ENOMEM); return; + } if (s->stop_silence_offset < s->stop_silence_end) { av_samples_copy(silence->extended_data, s->stop_silence_hold->extended_data, 0, @@ -601,8 +595,7 @@ static void flush(SilenceRemoveContext *s, (AVRational){1, outlink->sample_rate}, outlink->time_base); - av_audio_fifo_write(s->fifo, (void **)silence->extended_data, silence->nb_samples); - av_frame_free(&silence); + *ret = ff_filter_frame(outlink, silence); } static int filter_frame(AVFilterLink *inlink, AVFrame *in) @@ -610,8 +603,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; SilenceRemoveContext *s = ctx->priv; - int nbs, nb_samples_read, nb_samples_written; int i, j, threshold, ret = 0; + int nbs, nb_samples_read, nb_samples_written; AVFrame *out; nb_samples_read = nb_samples_written = 0; @@ -639,10 +632,6 @@ silence_trim: } } - if (s->threshold >= 0) - s->one_period = s->threshold != threshold; - s->threshold = threshold; - if (threshold) { for (j = 0; j < outlink->channels; j++) { s->update(s, in, j, nb_samples_read); @@ -656,8 +645,7 @@ silence_trim: nb_samples_read++; if (s->start_holdoff_end >= s->start_duration) { - s->start_found_periods += s->one_period; - if (s->start_found_periods >= s->start_periods) { + if (++s->start_found_periods >= s->start_periods) { s->mode = SILENCE_TRIM_FLUSH; goto silence_trim_flush; } @@ -731,8 +719,7 @@ silence_trim_flush: s->start_holdoff_offset += nbs; - av_audio_fifo_write(s->fifo, (void **)out->extended_data, out->nb_samples); - av_frame_free(&out); + ret = ff_filter_frame(outlink, out); if (s->start_holdoff_offset == s->start_holdoff_end) { s->start_holdoff_offset = 0; @@ -770,13 +757,9 @@ silence_copy: } } - if (s->threshold >= 0) - s->one_period = s->threshold != threshold; - s->threshold = threshold; - if (threshold && s->stop_holdoff_end && !s->stop_silence) { s->mode = SILENCE_COPY_FLUSH; - flush(s, out, outlink, &nb_samples_written, 0); + flush(s, out, outlink, &nb_samples_written, &ret, 0); goto silence_copy_flush; } else if (threshold) { for (j = 0; j < outlink->channels; j++) { @@ -813,14 +796,13 @@ silence_copy: s->stop_holdoff_end++; if (s->stop_holdoff_end >= s->stop_duration) { - s->stop_found_periods += s->one_period; - if (s->stop_found_periods >= s->stop_periods) { + if (++s->stop_found_periods >= s->stop_periods) { s->stop_holdoff_offset = 0; s->stop_holdoff_end = 0; if (!s->restart) { s->mode = SILENCE_STOP; - flush(s, out, outlink, &nb_samples_written, 1); + flush(s, out, outlink, &nb_samples_written, &ret, 1); goto silence_stop; } else { s->stop_found_periods = 0; @@ -831,17 +813,17 @@ silence_copy: s->start_silence_end = 0; clear_window(s); s->mode = SILENCE_TRIM; - flush(s, out, outlink, &nb_samples_written, 1); + flush(s, out, outlink, &nb_samples_written, &ret, 1); goto silence_trim; } } s->mode = SILENCE_COPY_FLUSH; - flush(s, out, outlink, &nb_samples_written, 0); + flush(s, out, outlink, &nb_samples_written, &ret, 0); goto silence_copy_flush; } } } - flush(s, out, outlink, &nb_samples_written, 0); + flush(s, out, outlink, &nb_samples_written, &ret, 0); } else { av_samples_copy(out->extended_data, in->extended_data, nb_samples_written, @@ -853,8 +835,7 @@ silence_copy: (AVRational){1, outlink->sample_rate}, outlink->time_base); - av_audio_fifo_write(s->fifo, (void **)out->extended_data, out->nb_samples); - av_frame_free(&out); + ret = ff_filter_frame(outlink, out); } break; @@ -881,8 +862,7 @@ silence_copy_flush: (AVRational){1, outlink->sample_rate}, outlink->time_base); - av_audio_fifo_write(s->fifo, (void **)out->extended_data, out->nb_samples); - av_frame_free(&out); + ret = ff_filter_frame(outlink, out); if (s->stop_holdoff_offset == s->stop_holdoff_end) { s->stop_holdoff_offset = 0; @@ -902,16 +882,6 @@ silence_stop: av_frame_free(&in); - if (av_audio_fifo_size(s->fifo) > 0) { - out = ff_get_audio_buffer(outlink, av_audio_fifo_size(s->fifo)); - if (!out) - return AVERROR(ENOMEM); - - av_audio_fifo_read(s->fifo, (void **)out->extended_data, out->nb_samples); - out->pts = s->next_pts; - ret = ff_filter_frame(outlink, out); - } - return ret; } @@ -975,9 +945,6 @@ static av_cold void uninit(AVFilterContext *ctx) av_frame_free(&s->stop_holdoff); av_frame_free(&s->stop_silence_hold); av_frame_free(&s->window); - - av_audio_fifo_free(s->fifo); - s->fifo = NULL; } static const AVFilterPad silenceremove_inputs[] = { From patchwork Thu Sep 9 15:57:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30088 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp648364iov; Thu, 9 Sep 2021 08:58:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbenxHCzUbd0Sev/QsOV/H3pbEEP1K3uSB4S6FW1qeRpsly0J8GGqsXnptr5MJz6AcCzDK X-Received: by 2002:a17:906:4fd6:: with SMTP id i22mr4204337ejw.92.1631203087824; Thu, 09 Sep 2021 08:58:07 -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 l14si2276601edr.27.2021.09.09.08.58.07; Thu, 09 Sep 2021 08:58:07 -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=HoSYc1Vd; 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 692F168A98D; Thu, 9 Sep 2021 18:58:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-oln040092065087.outbound.protection.outlook.com [40.92.65.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E1A7A687EBB for ; Thu, 9 Sep 2021 18:57:57 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j0kVtmDMz0nc3qGbu2zqJKXUEJjd5JgfdjeT3/hoaqv6hShFKspRGqDyVbalNPrpBdeqdwndMVyvIIcejX7OIxGMXJ1oJUtctMbBHgdaZo9+9r1Q+1ZkbJtJ5R/E8MPSWwDjMV6oWj2bbkziv3m2ny3y1I/rJjcrkJsw0OIJtX81OiqP39o7d7sJShSoxYPr8rIlQvJ3CsfEW3dKch2yvb/b2F9ovkD43K+FDayV8rdyHcPynyF6rcAb7nGwKsf5eCQH8egTVr2Et/OKIAYju8CWXUkinGt1zyOHTnQtjlmoJ4GYv/4GW4j1ypjQrHQfQlCKjZHQ5nrCPAS0INuB8w== 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; bh=j3RdeHHqNG3NWZ9PeI2McX8ep28t4QvioyvpjwYmgr0=; b=DpY5w8VaxSCIYKUoEhUNLiLtNBWCSkckquApxb64mD+o9nAqUMsN15HqOe22lj5h6ngCERrqGnHpv30y8YiS5maBEQteinM2jGmjdNEpRi2/n2DE2tLfBA3+VmQz9qqz9Q5lCEgJHy9qnHW961bBsB4lyqfr6p3IKuyv7FJC+QvNozPxHBFv5VSciMLEcxyIxaId0YP8+1zfmKHw2pRW8argeZWQ5LJHYbiDoFkFIulWBkIrBI4v/dTfVScqxqY5Zarjo/gK02SxZRf3aN2hdUWZ1YaNT5locDmSHJVPsZ0s9qEhVteBc6aw8Cp3j+bxlhNwlsgjQsHS2WJ+eRzmtQ== 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=j3RdeHHqNG3NWZ9PeI2McX8ep28t4QvioyvpjwYmgr0=; b=HoSYc1VdGm036f0+r/6vgx3lUwrlcSpk0hD2qg14zKEJg5zKLm6pvIQpSKJ6v6d5uAzbWoFoUwbM3iB+SfZMaHgLh4k5BzZReLNTWvlU14zCfmpKfi+C5EgDsrQlZ5WwGcLvfvNMgeqqMUyWdoPE0qJ3dj5Rzzr8D1LauHkEBgZBVhMsG++uYU5ju4VtJkD81kOvRvAP9bt88AGEGs5ko2BnreQFysK8za0zLELkE2+tHr8mFtZtfG11ORHNo5TrpWR8vXdOQIk+3R1x6je8rI9uU3j/UQr/lBfGmO+iTOORedibt7DmCG4K+moEvXoPl7E03201al+407So5KtRBg== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB7039.eurprd03.prod.outlook.com (2603:10a6:102:ef::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.16; Thu, 9 Sep 2021 15:57:56 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:57:56 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:35 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [1ygMiQuIeHGTsNORb8i0g539t2IbOvvN] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:57:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: adfa10b5-2e3f-49aa-5362-08d973aa96ac X-MS-Exchange-SLBlob-MailProps: EpEO96k6Wok19LiHRQJwUjXseAn0bFx1v+YUssy3vwcQRgJ/7DRXGaWd8wpOH+4nwzI7SwuP+HWbv9AW+fHTZF2iGgld/Z+olQndfmfzV/FIwDwF/xesTgP01TGMM58lVHgDsZ5WKylJs973hGGjAmJQEP7sqc1519eTBssDzTjoyz2tDpRVq0fopWgDvbWUw6SQie+LFEMAkRRQuVdWyWH9qrZXKCHR+QH+sm9wZtYf7hCAxAi53p1SFavJAOuPTekdcd8M8RXPQQ2+7St9IOb8q3GXtTVZq/BVDZmBLHBTMDMqFk1WYdEgYAfX6vaE8LLz5Z//Uxp019k0ijOJxfGoMJ/xYxdPJzHip4Zdnp9xa6hLqjDcL6GLqgO9zrQwZaxrFVIcKbatZknocxp4tKRK/mds4tbUO8kva4DaTmgX5uVKIUL06YBIEx7Ys+16C/0VbcbCBf321AJnELDtVev8f8CAWUNAk4ia29uj5RiRQzu/GuxyrGj9QBEU5wnhjdvcQH9jKImpsAmP6DVeLUB9hBapGkZq8CDXfYcA8/uNIbNsTi6g8jVX788ACJUjHWMIKUa+FfS4dHXx5dx+Eeh6O8ktYROgdBC3VxeVUVy1+H+45rllvGej/J/oB0TGdseud5XpRYDtbS/DveWRVZZYisjgJmKpLYfXIdmELxlHen1NKrHDRbKwq3yPyKxq7XynF0jNAvBIH0EL+uLOmFLTQHAV3ZVkUPbW6VPKBJq+6WAeEy1Df3pLRjZTy8NJ7ACsCidh+Oo= X-MS-TrafficTypeDiagnostic: PA4PR03MB7039: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qS+WLLFGEBfOY5fuk9NBOuxwPycXvUNyqJWsvjNffyzalow4bPtoJ8gOjE7ab76+e4jsJgZudFg+1yr2aJ5TUW3Tm/8/FfOGbZ9HVgczoZ42wX5YunNpwEKOO/DcAgF7IYqCymNO5hauLoqiDeGAVbTOgsC33S5YWcrHRmW22t4reh0/Az9C0OQTFvaotqtcdVe9vlhcyIu9YRmvVMYdCvC/JDjCB4AHSh5Wqnk+Pwjo2ME0TFzTdR265wojpQUt7rS/LuYcQLuFYe/hgymJeV24Bk5NMP4TXKfuhaGI3MoqjR+NL4rzhrITtrD+vgNw8kpI7rRXe6hQCDUzRz5UQTXFvY6gsYYwUE+IYGYtt8yvC0xc9KbXuexZZ8mECCnoHdITYCyIdFX3Zd6wm8eCCCoF4ShP2mxtEnxkFWr9zlJslBsBLeNyR6r99ul2UMzl X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3eLu49kihsVLiSfUPgvPWqrKKkpGa81nOp564tuRhPlKQejYkpQy4YL6K5i4eoXXl2P1IH9psgznnRrw6QXDv9hQ/XrTHp6eus8VXFJcVyEvzd5vTqmx6xDwh/I+07/Ovp36DAKGqpE+MxhZo1ABRQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: adfa10b5-2e3f-49aa-5362-08d973aa96ac X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:57:56.1436 (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: PA4PR03MB7039 Subject: [FFmpeg-devel] [PATCH 02/14] avformat/mp3dec: Avoid calling avio_tell() 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: V6XQiKligMXW Signed-off-by: Andreas Rheinhardt --- libavformat/mp3dec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 195d89814e..9205abebc4 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -171,7 +171,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, MP3DecContext *mp3 = s->priv_data; static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; uint64_t fsize = avio_size(s->pb); - fsize = fsize >= avio_tell(s->pb) ? fsize - avio_tell(s->pb) : 0; + int64_t pos = avio_tell(s->pb); + fsize = fsize >= pos ? fsize - pos : 0; /* Check for Xing / Info tag */ avio_skip(s->pb, xing_offtbl[c->lsf == 1][c->nb_channels == 1]); @@ -430,9 +431,10 @@ static int mp3_read_header(AVFormatContext *s) return ret; } + off = avio_tell(s->pb); // 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); + st->internal->index_entries[i].pos += off; /* the parameters will be extracted from the compressed bitstream */ return 0; From patchwork Thu Sep 9 15:57:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30090 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp648554iov; Thu, 9 Sep 2021 08:58:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyONalYD6WCRkzyhWKBqFHezXZRFjJZ9gHu2ofNIFRJHIUo6gtwOKjqwnVNrqhuKOZLlvJ7 X-Received: by 2002:a05:6402:4247:: with SMTP id g7mr3888661edb.245.1631203099941; Thu, 09 Sep 2021 08:58:19 -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 b1si2433765edr.458.2021.09.09.08.58.19; Thu, 09 Sep 2021 08:58:19 -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=ljjML4aJ; 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 7EFE768A996; Thu, 9 Sep 2021 18:58:16 +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 7664A68A996 for ; Thu, 9 Sep 2021 18:58:09 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ieqRRhOwsRnPkAruJkJiQ5RXPejQVox5DSO0dHDJnAIvaF50/FOVp1QlMEcD+PqHr6v5ReAqnGZWmgQeizPef8Jiq+vwIUo57WXXUBGUlQK313TeerDyel5nplPHRyR0LTS655TqVAk3W7VqQqsKX5sf9v5Wuomj24KxL+AsWwSs42SJr2E2OxhTy4erMl9Q5IEnnfXax8YEv+ghA71GazPlvwgg9Uou7a346OWySGvQlOzHe3guaqakXYAo8ZVz7My8WWXe5NLmHqqVN0qB6GIxXBUd0b8ExS6mIIpuXKV+6/YBME6Ip8Sd54QntV53UNHR5/MzE6K6IW0ZcxAAvQ== 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; bh=iFfgvoW+SuZWvuiOezPQAImCtxWoYO/FCVnzk8Xd7e4=; b=S3WIUmiftU/yRbPNQXlNVdAZGKpZ3kZF17v8Hq79wsXXeKqlUWTBRRrpW2VGiMW5cmq+qO97aNLoCBGocG/xSnajBrU9x5nFBtaPAQGGCVPe5OcVPfHyCm3wKVnCOJAnYX2nFnh9RPc59rRAo2z7lrYhBFodys0PfpPt+c3P+dg053cQ7gPSVY2gtcimSyEO93DNgz5TIakB2QhfgGlZcnATRXPtbqC+8UwfGUb2muz+bPPkQpOUuwUUTPCuGrB5+rAgfC1g5JhaW1anV5xVp8IBtAjpKUNgLS3flCzyE/Ls51ADaUlf5UY93Pwm3MrU7U6hHzwhA7hX/unn8v3D7g== 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=iFfgvoW+SuZWvuiOezPQAImCtxWoYO/FCVnzk8Xd7e4=; b=ljjML4aJJzfR47qtW+b49ng2YZf3DaZr/bnE+C2qknMGiUazbTtxmbYsBfQ2v2aTYlRlapxYhBhSuUEmVL4W/PAe678ZLtqKQ63dO7LZW80uaobUxPjdedE4MmJcJ7+9kDt4WGUdJM5sOgkUbmXAxhkO+PbKzaPwoUUWGjvlTANChiMaSePHO8vPSCSwScvvH4gfr392XP7luDjCTmMWNvIzBqCrgHt2pWBIMm7tt5/RojHfz5Ddtlxq6Dyb7YYKZaLr/sQuHMoCMADTMYpPa1lwsVdaNDAvBSypLEIZqoPhpGxXwXsyIZLfpMxNgNMEt4jRL08HiI7Lmwh6LJRniQ== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:08 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:08 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:36 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [g8pe1QAIOKLc1hD+gbxjyUhnLjItpXy8] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 73c28769-7f44-4bb0-6e60-08d973aa9de4 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXImq1sWRAABPXhZ8q25ZjYdgCAY6eAxKwuvX/7vMmFcWnp7g5AglVVxD9dpnNqiR/0Fm7HgqdTICT+ezCpmLTyAqQFIBwHmpbwxQ0ZFXrPfVH7TljS0D9DOupBIEaNAca8O45s9+tJX0UD1OIvglIRwr7Njm3yOXY2p6siIRhVhtttCwSC+mMrFJf3ZP1iqL/jpU5Xf3rUXa70YKkrW/YFAqKt4hd0imloCXmlvwQIGSFK1OxMpNe2HaiWfQdoI3EB9J8pSkYdNDwr3Sr/a8AE/27SqVKpeh64/V7HqbEXCaR46LMRBAFCcf41SNtzgU+nLwohG4/nnAWZ4ryiw8MFjI0dg5IY2RI06Hq9xemrEA5jdRdyO/t4t5ZdGRzo/CNhBFQ7IAp4Xg0J0i10jH83lubTVJmnhLjO4kCiNt5jadFUN6RaEIqaa0hg/XN7tFZmYs6v75n0ybqUawipwqBElmWjtLGft6dOUvGNlMRIgTYF+o1cQAdULEfCJBEcIqknkPA2jq/PAb1wMF6t5lkQJFNmZycZ3Rl5S8471mJLJbxZ5WryDZjyYG6jYk9EJbOjdVMRnhzcm7DDBACK5XPzSfGPuuli9hl+kWBomnkbnEhYNk5b+W4TPdD3Z5R6lzRPDLFkCeGl8Z+BaC1PtD+8djQ8+ceDhe5MhY1+5bDu6bu7WsyGwBFBm3ebkx2UuoiVPZIM0AT2S0xqgi1/QTPKKTcEB7VSKUw= X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VJeJ6OkEcWYjI/PNVwxznAi83xpNPcjwvA2kqQieB6mJXPb2MwZ5TL+aVTrnjxIn6IgGVN/UBoQlgCGPX9a2dG/KSfG3RGhwxbFz8P50440ZnVn0ye1KAvRL1ILFz99bOLKyi3u70LzIw+J1TftxyU8Yx0MMWWYoZ5tCIJoTxxy5k1ApPDEP/D2wLhvokDz7nhIdKTmDXGnPofCNfQNem6Hy0E9Tn+Ki5aqMWcYfG3oX0uMx3yc1OxEFvZmvavo5LXaUzWGo+QR2atzzrsYPyXDm3jHI4Ukq5K+gDgxr6jTMXQYUaub0n1jiMRSXAtlOtgGTPfIcwhh0VLpgvHqoO+YbnFzsCalaWvN6Bd379slEalTUdCweAv/METl5H77fxSOp+BONwrFTGwXf1pVKY1sQIqqqpoecqYaV8jmmsbamIFIpixcOjQ0WVpd6W0vE X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Tr8V2P4PLhR4ch31fJ++5yAnr4g+ewGSKbrrybumuF/9so12x324EbyTpfHcWQfzQs7eoyjkb8fEsKipYri3P95AHKTurmMdbQXUeUHd5aJ36fay+xRsl+pUIuIRT5/hffe3J9dZUKiQJmEUB8ImfA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73c28769-7f44-4bb0-6e60-08d973aa9de4 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:08.2493 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 03/14] avformat/mp3dec: Simplify checking for no-metadata 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: U7p0WbUidIMf Signed-off-by: Andreas Rheinhardt --- If it were documented that a non-NULL AVDictionary is always nonempty this could be simplified. But I don't know whether we want to document that. libavformat/mp3dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 9205abebc4..72c049edaf 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -384,7 +384,7 @@ static int mp3_read_header(AVFormatContext *s) ffiocontext(s->pb)->maxsize = -1; off = avio_tell(s->pb); - if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) + if (!av_dict_count(s->metadata)) ff_id3v1_read(s); if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) From patchwork Thu Sep 9 15:57:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30098 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp648733iov; Thu, 9 Sep 2021 08:58:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxizoAuW6ZfR2J//aMHfD8apMwH+xd8yIX9pJVCuGhLaJhU3Lkx28UgX1Q874GkFxEuCRM9 X-Received: by 2002:a17:907:7755:: with SMTP id kx21mr4233287ejc.463.1631203112292; Thu, 09 Sep 2021 08:58: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 du4si2485326ejc.696.2021.09.09.08.58.31; Thu, 09 Sep 2021 08:58: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=G48cGWM0; 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 A3AF768A98A; Thu, 9 Sep 2021 18:58:21 +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 A8F18689D1F for ; Thu, 9 Sep 2021 18:58:14 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c3QMcTyuPanAW8gNWVMJxgSTBV+t4AKay26wj4qlXfgtZ/XlY9AKk/eXAW5qfStba2FmSupK88TNxcHOI2YaX45NqSgIngr+IWRR1ryOtJU7NtLGlO6tIKumjZmnA08lTe9Fyp8cva0KqJ9h74bTZh7wLxbxTSeGypOplKEF2ylSokBrrRdFSuwMAZQAV5BOPVlsxwiARZ7JBO7NUkyXZIlLgoDC9PjGbW7XoxRfS1WEiWh0o746wi/Kkb/WkFRSEs+L5qXd23xlNvUSPCQCs6W+0SdaNA94H+NXsBsQvdoKOu3mF7hA/EzrVCV1jLoNNwm2RN3V1agNkawVyBnX9w== 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; bh=1bicEWDRunpD5kgwXTR3aJEkAU9EJt/xCMYJxhT2hzk=; b=jsRPq8Woy8g/v0Ki4OJApedZGwilxKJlAsdDC2POWxRrH5cwk1p+F4/EmTg5cpGG1UNPj1s70KLUXbKUz8Be+Rb2X1rtczN5fHd4cf6H8XkQ3ylxXpVadqqpgDvwf2X/z8xcAOch+J4CztgyuWd57nPkPtV5/VuAVJHcKCfUZx7KFqgPVvkh8JjaOH/PLhw1CAvBv2kd6+rF0Ic0S+ah9uUfUjnjjwfVMICMTZGkgRKczxMC4MTs8AJ/dyonxv5fT6bCNUMjDvb6LnGCCODWDZlT+LY1pnLAuPh+2u5daaMwIfqEFDs5//Gv2AWwSkDonYT3rqivm0EQD6fj3643Yg== 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=1bicEWDRunpD5kgwXTR3aJEkAU9EJt/xCMYJxhT2hzk=; b=G48cGWM0RVJNJRiBl38PGKyxVyP77tUVyBJJnQ6Lmk2IxwKW4KSgonOeNDfmYtmxaL3AwunIZu1ks/suJkc20uWFHK7VW6iTwN8I4isyVvmvrB7Vi1COzvUq4L5zdSpTpSO11i1MXs7FPxig/7lo99w+Spm0B5SpsrFAafuVr375EPxv6wa/ErsCV2MnOK/rNJUJ2A78vIkSbWTvqlJnrHtv3aOQK6l/Wqy4GEvtUtvk3lBEYtyXeIAYgwwwuGRiIFk4sk502pH8cO+HfyNc5e5WJUihmhFOcbDBD0r0Ua28YVPQY5LRlef4Tir6MP6TevOFAXvqdeV9KEa/KfilyQ== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:10 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:10 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:37 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [XJJW+tfgZSUIGgBxdAu2cKsX6jSqkoi5] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 183ff599-b21f-4417-13c1-08d973aa9f54 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQjHo/KsCc3LoxlbG+9PiyI2N6bxK7u/BetRSOqbh/MVpNTcRA1evcfivCEt7bJtbNUQ6vEPVerUNa23LFVu65sj2myQPPP/6TSXm+1soN8Y/2jb0Egt8DpfLQnwQMBwRyp/iPWilwRFNbGx2khw5/XCD8woCMOIKY8/s1RZyI2ILgBsX8G1wFXhZAA/GQ7gA+36ZKx+X0HprvMvcxHYvaPAzEWErI4EUT5o4GthDyPC9j4A5G2yWC2TU3v9XlmSC+9MWwg8LzQik4AdyJ91V4tduSoWPzX/5ljghxA+Bl98ZxDGuHmA/BShFsHioXA6mOFpv1lnmQXaCX5qx+YZPBjyyTrlpmzo0Ittj+wSeXvSL7towo71egDgBE7fST9fH9PM33JAmVgX/yCwzsyaX1s5wfQ8uq6Y7NElWrW4mWY4d7barenYhHVjvRWnsb89Z7jIyIQ87305iBqVCTRtoSTsyygGunMrXgAZADOCzGCfNaeC1WL7oEHFH2/9JBaf2WO2zly0C+nhGPJ0JFGmyDHWep51tkw35952iHOMMOhF3EtsGgrtDbTbM/UUwoV1E9xXncAXBORqKg4lE+XLA0F/ee1gV5225Q5Ww0/cH9ULCWDvRdI8SuxVMwCSDRguzwl7+bkFw72klspMSbTMIohpZYm7fhnHSu3tLw/fBDHBdKcjCnQtRsryu+5di8BvDTlyDq354AwnT4fzPqgj3O7crRPY0oXFS7ZoyBhAEZaQBN5A4GDEEPPiz4uRl3EUZI= X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yRMZnecobjWuzUHxy7+c2TpKRulm5gPLTSg671Sjqe1g09ajgPgFpvZfzJbox8fLSnnTp/pP+DOQdLdQGOwnnD0L0MQEeWxheRLW4vT5lsvhJftaY6SJDUWc2fG8t0BLrq0h6h9KMgN7/mULumlZqtDMNVx+yiRpeLfliAgct6wd1R/Ber0nHbyv7D8XXKWW7d8cTBEUaysG7jAAaPSRE8JCbC8Mav9L419tGUgQjgFlnbGvxst1YsizucudEsxx6je+YECFePaju04GulNjKDtFSnYdJqqPBvC11EkqlUcNrGErdWk2DtMgupVBBKuehE1VWMhpT80bUdAsb9mt5KilLUAUsjRwjyez5gt1AUzgdKbUz7iNYFjXEFF/l2Z6SU9dtEkzBUNV0PLfmTRcu40w2TzaFW/PS/DWeZg2WTBGr3xAwED5UsiJJWggl9ls X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YkLF+1pB0dVEQBq77VWgADfsW8irPuxfJV0U2uPmi9o7wFNoakWizpgKPlghuy+p9/gQ8M3Dc6JiBhC3Ef+ovE5CdhJvBFA6HETAPWhGvJdrhEUOOHW29byTtN+Ugv7qFkcZuc5oBJn+lpoCz6bebw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 183ff599-b21f-4417-13c1-08d973aa9f54 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:10.8390 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 04/14] avformat/asfenc, 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: a99N5m5/BWr/ Signed-off-by: Andreas Rheinhardt --- Now also including asfenc because I don't like that there is an AVCodecParameters in asf_write_header1 in the outer function block although all AVCodecParameters in said function have smaller scope. libavformat/asfenc.c | 54 ++++---- libavformat/mux.c | 60 ++++----- libavformat/utils.c | 294 +++++++++++++++++++------------------------ 3 files changed, 175 insertions(+), 233 deletions(-) diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c index b294431aec..07588772c6 100644 --- a/libavformat/asfenc.c +++ b/libavformat/asfenc.c @@ -329,10 +329,9 @@ static int64_t unix_to_file_time(int64_t ti) static int32_t get_send_time(ASFContext *asf, int64_t pres_time, uint64_t *offset) { - int i; int32_t send_time = 0; *offset = asf->data_offset + DATA_HEADER_SIZE; - for (i = 0; i < asf->next_start_sec; i++) { + for (int i = 0; i < asf->next_start_sec; i++) { if (pres_time <= asf->index_ptr[i].send_time) break; send_time = asf->index_ptr[i].send_time; @@ -346,7 +345,6 @@ static int asf_write_markers(AVFormatContext *s) { ASFContext *asf = s->priv_data; AVIOContext *pb = s->pb; - int i; AVRational scale = {1, 10000000}; int64_t hpos = put_header(pb, &ff_asf_marker_header); @@ -355,7 +353,7 @@ static int asf_write_markers(AVFormatContext *s) avio_wl16(pb, 0); // ASF spec mandates 0 for this avio_wl16(pb, 0); // name length 0, no name given - for (i = 0; i < s->nb_chapters; i++) { + for (unsigned i = 0; i < s->nb_chapters; i++) { AVChapter *c = s->chapters[i]; AVDictionaryEntry *t = av_dict_get(c->metadata, "title", NULL, 0); int64_t pres_time = av_rescale_q(c->start, c->time_base, scale); @@ -392,10 +390,9 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, ASFContext *asf = s->priv_data; AVIOContext *pb = s->pb; AVDictionaryEntry *tags[5]; - int header_size, n, extra_size, extra_size2, wav_extra_size; + int header_size, extra_size, extra_size2, wav_extra_size; int has_title, has_aspect_ratio = 0; int metadata_count; - AVCodecParameters *par; int64_t header_offset, cur_pos, hpos; int bit_rate; int64_t duration; @@ -420,9 +417,10 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, metadata_count = av_dict_count(s->metadata); bit_rate = 0; - for (n = 0; n < s->nb_streams; n++) { + for (unsigned n = 0; n < s->nb_streams; n++) { + AVStream *const st = s->streams[n]; + AVCodecParameters *const par = st->codecpar; AVDictionaryEntry *entry; - par = s->streams[n]->codecpar; avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */ @@ -489,18 +487,17 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, avio_wl32(pb, 0); /* length, to be filled later */ if (asf->nb_languages) { int64_t hpos2; - int i; int nb_audio_languages = 0; hpos2 = put_header(pb, &ff_asf_language_guid); avio_wl16(pb, asf->nb_languages); - for (i = 0; i < asf->nb_languages; i++) { + for (int i = 0; i < asf->nb_languages; i++) { avio_w8(pb, 6); avio_put_str16le(pb, asf->languages[i]); } end_header(pb, hpos2); - for (i = 0; i < asf->nb_languages; i++) + for (int i = 0; i < asf->nb_languages; i++) if (audio_language_counts[i]) nb_audio_languages++; @@ -508,10 +505,10 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, hpos2 = put_header(pb, &ff_asf_group_mutual_exclusion_object); ff_put_guid(pb, &ff_asf_mutex_language); avio_wl16(pb, nb_audio_languages); - for (i = 0; i < asf->nb_languages; i++) { + for (int i = 0; i < asf->nb_languages; i++) { if (audio_language_counts[i]) { avio_wl16(pb, audio_language_counts[i]); - for (n = 0; n < s->nb_streams; n++) + for (unsigned n = 0; n < s->nb_streams; n++) if (asf->streams[n].stream_language_index == i && s->streams[n]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl16(pb, n + 1); } @@ -519,7 +516,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, end_header(pb, hpos2); } - for (n = 0; n < s->nb_streams; n++) { + for (unsigned n = 0; n < s->nb_streams; n++) { int64_t es_pos; if (asf->streams[n].stream_language_index > 127) continue; @@ -546,8 +543,8 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t hpos2; hpos2 = put_header(pb, &ff_asf_metadata_header); avio_wl16(pb, 2 * has_aspect_ratio); - for (n = 0; n < s->nb_streams; n++) { - par = s->streams[n]->codecpar; + for (unsigned n = 0; n < s->nb_streams; n++) { + AVCodecParameters *const par = s->streams[n]->codecpar; if ( par->codec_type == AVMEDIA_TYPE_VIDEO && par->sample_aspect_ratio.num > 0 && par->sample_aspect_ratio.den > 0) { @@ -592,7 +589,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, hpos = put_header(pb, &ff_asf_comment_header); - for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) { + for (size_t n = 0; n < FF_ARRAY_ELEMS(tags); n++) { len = tags[n] ? avio_put_str16le(dyn_buf, tags[n]->value) : 0; avio_wl16(pb, len); } @@ -619,11 +616,11 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, return ret; } /* stream headers */ - for (n = 0; n < s->nb_streams; n++) { + for (unsigned n = 0; n < s->nb_streams; n++) { + AVCodecParameters *const par = s->streams[n]->codecpar; int64_t es_pos; // ASFStream *stream = &asf->streams[n]; - par = s->streams[n]->codecpar; asf->streams[n].num = n + 1; asf->streams[n].seq = 1; @@ -696,13 +693,11 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, hpos = put_header(pb, &ff_asf_codec_comment_header); ff_put_guid(pb, &ff_asf_codec_comment1_header); avio_wl32(pb, s->nb_streams); - for (n = 0; n < s->nb_streams; n++) { - const AVCodecDescriptor *codec_desc; + for (unsigned n = 0; n < s->nb_streams; n++) { + AVCodecParameters *const par = s->streams[n]->codecpar; + const AVCodecDescriptor *const codec_desc = avcodec_descriptor_get(par->codec_id); const char *desc; - par = s->streams[n]->codecpar; - codec_desc = avcodec_descriptor_get(par->codec_id); - if (par->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl16(pb, 2); else if (par->codec_type == AVMEDIA_TYPE_VIDEO) @@ -832,7 +827,7 @@ static int put_payload_parsing_info(AVFormatContext *s, { ASFContext *asf = s->priv_data; AVIOContext *pb = s->pb; - int ppi_size, i; + int ppi_size; int64_t start = avio_tell(pb); int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS; @@ -843,7 +838,7 @@ static int put_payload_parsing_info(AVFormatContext *s, av_assert0(padsize >= 0); avio_w8(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS); - for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++) + for (int i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++) avio_w8(pb, 0x0); if (asf->multi_payloads_present) @@ -1015,8 +1010,6 @@ static int update_index(AVFormatContext *s, int start_sec, ASFContext *asf = s->priv_data; if (start_sec > asf->next_start_sec) { - int i; - if (!asf->next_start_sec) { asf->next_packet_number = packet_number; asf->next_packet_count = packet_count; @@ -1033,7 +1026,7 @@ static int update_index(AVFormatContext *s, int start_sec, return err; } } - for (i = asf->next_start_sec; i < start_sec; i++) { + for (int i = asf->next_start_sec; i < start_sec; i++) { asf->index_ptr[i].packet_number = asf->next_packet_number; asf->index_ptr[i].packet_count = asf->next_packet_count; asf->index_ptr[i].send_time = asf->next_start_sec * INT64_C(10000000); @@ -1102,7 +1095,6 @@ static int asf_write_index(AVFormatContext *s, const ASFIndex *index, uint16_t max, uint32_t count) { AVIOContext *pb = s->pb; - int i; ff_put_guid(pb, &ff_asf_simple_index_header); avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2) * count); @@ -1110,7 +1102,7 @@ static int asf_write_index(AVFormatContext *s, const ASFIndex *index, avio_wl64(pb, ASF_INDEXED_INTERVAL); avio_wl32(pb, max); avio_wl32(pb, count); - for (i = 0; i < count; i++) { + for (uint32_t i = 0; i < count; i++) { avio_wl32(pb, index[i].packet_number); avio_wl16(pb, index[i].packet_count); } diff --git a/libavformat/mux.c b/libavformat/mux.c index 6ba1306f2b..84dfdb9170 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]; @@ -894,10 +886,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) { @@ -905,7 +896,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 && @@ -929,7 +920,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; @@ -964,18 +955,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; @@ -990,10 +978,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..2b12904d61 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; @@ -972,11 +970,10 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t if(!onein_oneout) { int delay = st->internal->avctx->has_b_frames; - int i; 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]; if (score < best_score) { @@ -986,7 +983,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 +1014,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); @@ -1152,7 +1148,7 @@ 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; + int num, den, presentation_delayed, delay; int64_t offset; AVRational duration; int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && @@ -1311,7 +1307,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, 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++) + for (int i = 0; i < delay && st->internal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) FFSWAP(int64_t, st->internal->pts_buffer[i], st->internal->pts_buffer[i + 1]); if(has_decode_delay_been_guessed(st)) @@ -1455,7 +1451,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 +1463,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 +1592,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 +1749,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 +1785,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 +1806,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 +1818,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 +1954,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 +1972,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 +2501,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 +2520,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 +2528,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 +2550,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 +2585,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 +2612,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 +2629,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 +2658,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 +2686,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 +2695,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 +2728,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 +2770,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 +2787,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 +2805,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 +3041,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 +3110,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 +3125,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 +3145,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 +3160,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 +3255,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 +3269,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 +3288,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 +3314,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 +3331,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 +3342,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 +3484,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 +3497,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 +3533,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 +3600,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 +3612,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 +3673,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 +3832,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 +3861,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 +3882,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 +3912,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 +3984,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 +4014,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 +4030,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 +4052,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 +4069,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 +4085,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 +4153,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 +4173,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 +4186,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 +4203,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 +4247,6 @@ void ff_free_stream(AVFormatContext *s, AVStream *st) void avformat_free_context(AVFormatContext *s) { - int i; - if (!s) return; @@ -4289,11 +4259,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]); @@ -4347,7 +4317,6 @@ void avformat_close_input(AVFormatContext **ps) AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) { AVStream *st; - int i; AVStream **streams; if (s->nb_streams >= s->max_streams) { @@ -4409,7 +4378,7 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) 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++) + for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) st->internal->pts_buffer[i] = AV_NOPTS_VALUE; st->sample_aspect_ratio = (AVRational) { 0, 1 }; @@ -4428,11 +4397,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 +4429,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 +4440,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 +4466,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 +4474,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 +4689,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 +4699,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 +4816,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 +4987,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 +4997,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 +5261,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 +5277,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 +5438,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 Thu Sep 9 15:57:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30099 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp648932iov; Thu, 9 Sep 2021 08:58:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVdJsrIWN0AWHf4m4Ut3rk+kHdUy0CI9M8GrihJqvE1JXZ5X7T4ZanP2AQ+VnzJzDinfhk X-Received: by 2002:a05:6402:4404:: with SMTP id y4mr3945589eda.52.1631203128288; Thu, 09 Sep 2021 08:58: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 l20si2159080ejn.131.2021.09.09.08.58.47; Thu, 09 Sep 2021 08:58: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=t8WeADLb; 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 CC27768A9AA; Thu, 9 Sep 2021 18:58:26 +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 E3D1A68A9AA for ; Thu, 9 Sep 2021 18:58:19 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VU0xD6Efev1qvoW+s7MKiYPIjCay63kigU848C2R93eiGZUvvA2bFvo5+XlEZ6LBKm/062T8+JAJumiTKsozRXFSEJYv19uSszNBkqADTiYGNL4ZtsWStpLG65wdC0v/oekjgzRp76ys+vwUdOIJkw6ehGIAK+wek5olyChQRwEI5MP15jgazXPY5f3IaFBreXwQwZFmVPHPPTgNOmASoE9jFvwjyG0PrUfynGoWZ8hS4lpaOvVFMQwHefucKTumyNUrWtQGbY9W4qupE5rxGDlwf++8ysMAOJM6Y6bPX4s+0//nA4GGUnDPBalwek5wJhEdIiAelERnI7cLrGMeGA== 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; bh=Z3NdTI0iT+9nN9a37mV7k6/oj/igDHEB/sRJlk+EtOM=; b=ZNMRzA51ro13AuTq5V0JHgGoW4D4caY+IdbiPALQXs/O840Wzt/59h/5j3GuCID844vjf2wjUfG+jc8rj64vu6X5+IcJqpAc6P+kSxEhU+rW6t4+3yhIc6ey6SnI/yxFrHHG7mfX+LqItuR/mdmBDVpba1lTjwB1dSKt01OvCppdlb+v0w2lTyEGNV08XLXqlA4rKFJLaNfod79jlWbhACZlf1TQ4fr+j2E/GC03WQrgj+SsJ7aGmijLocpDVeJ4CRUUC5Kw0eGJlHmHTNAeKjyLhKux0QiB6L0atbY/6oASBH+yjKNZcrJnGelpAXbgK0XsSaz1PS/9gQ9Y553uDg== 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=Z3NdTI0iT+9nN9a37mV7k6/oj/igDHEB/sRJlk+EtOM=; b=t8WeADLb5cE2xvvWcKqwGNMIHO6tRGPuDStt/0PaFSxcPNm6++gKcCs/zZAqM1pFpWoD965QQe5TzWR+ZR8ZyTck37leqOkz7WKOLbrmQT9uATQtLTYPItKwLb+2cBblRN0Zrsb+SrbZL//3ueFZssZeBYM+T6dYQ3AWyLcrvQdzUSXp+vvyDU1MMvkO0KaNL8SHHYWN7cKwL4irrv6Mw6sUpkuorZ1lXuZi8dI2eG/Egs5C1VGdIQBze1ZP0GtIYw5mT2A5aactG62S3WwSVsEz2HaIBAWkTdCdg0mmv2/ltz/KY2yvdloKaxFktic1YAbncNTJTJSDdIystzeUmw== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:13 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:13 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:38 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [7rxd/J1poVtaMAFbvWXfCXCF3ySxSPWW] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2f8e3aa9-8585-480e-bf53-08d973aaa0f8 X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEsS78EXmycSIjNILG4ckU6Sf+ddb+SWOQ4rr/HZY0r0ZrD3I1RkmypV1IQJML1NO7eFB4WHC5/HGZBakVOSfTGGfbCAfF47fbYa1ZGkMjwNVQQw6CrQKoaYhzWXgjkXWPg2MH2C3ru3yq7NZDfomUTt9PN454P8a5Yzc47gw43A95Jb4ZPVnk1TA497JafVTHs+2ocoFpkEA6ARmATQxdkwwzN4m/r3+4Eh9L/B9I+uhN7cG3+GmcItko0NWvoK59SPQ7NpVEB+NS27B/YrAOl33MDQ5XnI/zaIU/vu/Dh3XCjOsrdya4V6ZNqmK29Fc3DOm5s1YDWT+aab+kzZC7I3fXrJt9JDGLGET9qz+70sRgDzdTJ2iT1qRgELb/OLEWiWsEJjFxfRC9Ur7eQbk5dpo1faRM6SRtx7dFHZ/t+bQjQasoyc2hhLsFtbL8EowASLpmqhswHr50Hz8cXInW9bPSWJ/Nh7dzi8NTUEM6OErst8HLmeIKfTbWfnW0ZUu8a0gV8QbM3wU5kp549H0OMrFCpax+brWHNz7tUHFx1UlAIQmBlI01iaLa33uQ0G5/W4HzpDtSRKR8ia1JymmGrDrUHU1j28FoqZ9G+agq1AL2rS6q8k8CJL21p2fuO3Hwqut0SZuzJ6ioF1bmZQa4owQObSP5Eieoijr7Qtkt2e1a1jBiJZQ3783ze6RCbSEG4EIgA5/uwYta+Y3HC2P3/8x6Nk4IihfIEplQsO7LsDpy/NP9K9cQg0d/hoHWo+Pd8ceVW8WS5CKhaZm4GT3UPn X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yMkRxYhoDeFSujaFFvvP+J77gXQxAAFVnCHzy06EFclXHmc7ewOTZKFuXId1VJx6pLKK/pZcVZ0qno09aYqI0n/AUoq/SjDRoXGsqWZvDtUpfX0a6dAC6z4rIgtxwahZuyjE8aiqylv6MXK8JxyAGg0TjTWgEdgQofU4nBtp75nqJqI2PwPS+zDEynVc7mRd4BPr9sP3x0vhmQ4cyjROob8NRNf5cMa9OVFBFrsRMcU/KEzEx67nJkTGSpGr5hW9X+Vylerecgy3fH4wbCAqGZ2OO25KwC1MpVCGrExoo5VVwvWqo0N+MSp7uF0wornqfzyasEZSrlFydscclQbc1HI0Mo+/vz99JTBOw1wPBYsSnxQZ6W70x1MP8KIjiTnYzu4gqSLEooKnIAX/OaoyLljnieSozZb6OW6no9NJHSi7cQiAA3xrzZzZDy1u6JjD X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UeNV2Z1uE87aFptfaFphT6KyeO3x6UryR6DbIo74r2cCWGpMy3Fa1EyVlI2CfxetHD4qIDUnTV/hlgk0Jiz5ejbm/OCqpcK97tqxuhjaiBgCU4/CxPy0x6L7wRv6QiaRJEdqFoxxi0HxV5xChTMroA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f8e3aa9-8585-480e-bf53-08d973aaa0f8 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:13.4963 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 05/14] 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: /dHLbUK2E8vH This gets rid of ugly "->internal" and is in preparation for removing AVFormatInternal altogether. Signed-off-by: Andreas Rheinhardt --- libavformat/mux.c | 105 ++++++++++++++------------ libavformat/mxfenc.c | 15 ++-- libavformat/utils.c | 173 +++++++++++++++++++++++++------------------ 3 files changed, 166 insertions(+), 127 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 84dfdb9170..95a56f0545 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -224,6 +224,7 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) static int init_muxer(AVFormatContext *s, AVDictionary **options) { + AVFormatInternal *const si = s->internal; AVDictionary *tmp = NULL; const AVOutputFormat *of = s->oformat; AVDictionaryEntry *e; @@ -330,7 +331,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) } if (par->codec_type != AVMEDIA_TYPE_ATTACHMENT) - s->internal->nb_interleaved_streams++; + si->nb_interleaved_streams++; } if (!s->priv_data && of->priv_data_size > 0) { @@ -433,21 +434,23 @@ 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) { + AVFormatInternal *const si = s->internal; int ret = 0; if ((ret = init_muxer(s, options)) < 0) return ret; - s->internal->initialized = 1; - s->internal->streams_initialized = ret; + si->initialized = 1; + si->streams_initialized = ret; if (s->oformat->init && ret) { if ((ret = init_pts(s)) < 0) @@ -461,9 +464,10 @@ int avformat_init_output(AVFormatContext *s, AVDictionary **options) int avformat_write_header(AVFormatContext *s, AVDictionary **options) { + AVFormatInternal *const si = s->internal; + int already_initialized = si->initialized; + int streams_already_initialized = si->streams_initialized; int ret = 0; - int already_initialized = s->internal->initialized; - int streams_already_initialized = s->internal->streams_initialized; if (!already_initialized) if ((ret = avformat_init_output(s, options)) < 0) @@ -482,7 +486,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; } @@ -502,10 +506,11 @@ FF_DISABLE_DEPRECATION_WARNINGS //FIXME merge with compute_pkt_fields static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; int delay = st->codecpar->video_delay; int frame_size; - if (!s->internal->missing_ts_warning && + if (!si->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)) { @@ -513,7 +518,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; + si->missing_ts_warning = 1; } if (s->debug & FF_FDEBUG_TS) @@ -635,6 +640,7 @@ static void guess_pkt_duration(AVFormatContext *s, AVStream *st, AVPacket *pkt) */ static int write_packet(AVFormatContext *s, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; AVStream *const st = s->streams[pkt->stream_index]; int ret; @@ -651,18 +657,18 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) if (s->avoid_negative_ts > 0) { 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); } @@ -672,7 +678,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" @@ -785,6 +791,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; @@ -806,7 +813,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) { @@ -830,7 +837,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))) @@ -838,12 +845,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; @@ -886,6 +893,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; @@ -906,15 +914,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, @@ -942,31 +950,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; @@ -978,14 +986,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; @@ -1015,7 +1022,8 @@ 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; + AVFormatInternal *const si = s->internal; + PacketList *pktl = si->packet_buffer; while (pktl) { if (pktl->pkt.stream_index == stream) { return &pktl->pkt; @@ -1161,7 +1169,8 @@ static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleav int av_write_frame(AVFormatContext *s, AVPacket *in) { - AVPacket *pkt = s->internal->pkt; + AVFormatInternal *const si = s->internal; + AVPacket *pkt = si->pkt; int ret; if (!in) { @@ -1224,7 +1233,8 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) int av_write_trailer(AVFormatContext *s) { - AVPacket *pkt = s->internal->pkt; + AVFormatInternal *const si = s->internal; + AVPacket *const pkt = si->pkt; int ret1, ret = 0; av_packet_unref(pkt); @@ -1315,7 +1325,8 @@ 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; + AVFormatInternal *const si = s->internal; + AVPacket *pkt = si->pkt; av_assert0(s->oformat); if (!s->oformat->write_uncoded_frame) { 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 2b12904d61..2102b6aeac 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -135,7 +135,8 @@ 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; + AVFormatInternal *const si = s->internal; + si->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 +372,7 @@ static int init_input(AVFormatContext *s, const char *filename, int avformat_queue_attached_pictures(AVFormatContext *s) { + AVFormatInternal *const si = s->internal; int ret; for (unsigned i = 0; i < s->nb_streams; i++) if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC && @@ -382,8 +384,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,12 +459,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 +542,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 +552,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 +576,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); @@ -625,6 +629,8 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { + AVFormatInternal *const si = s->internal; + if (st->internal->request_probe>0) { AVProbeData *pd = &st->internal->probe_data; int end; @@ -652,7 +658,7 @@ no_packet: } } - end= s->internal->raw_packet_buffer_remaining_size <= 0 + end = si->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)) { @@ -741,6 +747,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 +762,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 +844,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 +964,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; } @@ -1037,8 +1045,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; @@ -1090,7 +1099,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) { @@ -1116,7 +1126,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; @@ -1148,6 +1158,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt, int64_t next_dts, int64_t next_pts) { + AVFormatInternal *const si = s->internal; int num, den, presentation_delayed, delay; int64_t offset; AVRational duration; @@ -1230,7 +1241,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 && (si->packet_buffer || si->parse_queue)) update_initial_durations(s, st, pkt->stream_index, pkt->duration); /* Correct timestamps with byte offset if demuxers only have timestamps @@ -1338,7 +1349,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; @@ -1424,8 +1436,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; @@ -1451,10 +1463,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 */ @@ -1564,8 +1577,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]; @@ -1638,15 +1651,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; @@ -1654,7 +1668,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; @@ -1687,15 +1701,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; } } @@ -1709,8 +1723,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); @@ -1737,11 +1751,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; } /*******************************************************/ @@ -1785,6 +1800,7 @@ int av_find_default_stream_index(AVFormatContext *s) /** Flush the frame reader. */ void ff_read_frame_flush(AVFormatContext *s) { + AVFormatInternal *const si = s->internal; flush_packet_queue(s); @@ -1809,7 +1825,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 (si->inject_global_side_data) st->internal->inject_global_side_data = 1; st->internal->skip_samples = 0; @@ -2172,6 +2188,7 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t (*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t)) { + AVFormatInternal *const si = s->internal; int64_t pos, ts; int64_t start_pos; int no_change; @@ -2180,7 +2197,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 = si->data_offset; ts_min = ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp); if (ts_min == AV_NOPTS_VALUE) return -1; @@ -2274,9 +2291,10 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, static int seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags) { + AVFormatInternal *const si = s->internal; int64_t pos_min, pos_max; - pos_min = s->internal->data_offset; + pos_min = si->data_offset; pos_max = avio_size(s->pb) - 1; if (pos < pos_min) @@ -2294,6 +2312,7 @@ 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) { + AVFormatInternal *const si = s->internal; int index; int64_t ret; AVStream *st; @@ -2308,7 +2327,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 *const pkt = si->pkt; int nonkey = 0; if (st->internal->nb_index_entries) { @@ -2319,7 +2338,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, si->data_offset, SEEK_SET)) < 0) return ret; s->io_repositioned = 1; } @@ -2629,6 +2648,7 @@ static void fill_all_stream_timings(AVFormatContext *ic) static void estimate_timings_from_bit_rate(AVFormatContext *ic) { + AVFormatInternal *const si = ic->internal; int show_warning = 0; /* if bit_rate is already set, we believe it */ @@ -2659,8 +2679,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 > si->data_offset) { + filesize -= si->data_offset; for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; @@ -2685,7 +2705,8 @@ 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; + AVFormatInternal *const si = ic->internal; + AVPacket *const pkt = si->pkt; int num, den, read_size, ret; int found_duration = 0; int is_end; @@ -3433,10 +3454,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) { @@ -3497,9 +3518,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; @@ -3697,13 +3719,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; } @@ -3807,7 +3829,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; } @@ -3850,14 +3872,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); @@ -3922,7 +3944,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) { @@ -4247,10 +4269,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); @@ -4278,9 +4303,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); @@ -4316,6 +4341,7 @@ void avformat_close_input(AVFormatContext **ps) AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) { + AVFormatInternal *const si = s->internal; AVStream *st; AVStream **streams; @@ -4383,7 +4409,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 = si->inject_global_side_data; st->internal->need_context_update = 1; @@ -4428,6 +4454,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; @@ -4437,9 +4464,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 Thu Sep 9 15:57:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30101 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp663515iov; Thu, 9 Sep 2021 09:13:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkb+G4D6sQSGqqWn5S/xIILS//tOjaq1xeKRWWvTUY0gH/N2LWy9OyH4tMDsjvxtbcnsWO X-Received: by 2002:a05:651c:385:: with SMTP id e5mr516405ljp.35.1631204026789; Thu, 09 Sep 2021 09:13:46 -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 p10si2411811ejn.780.2021.09.09.09.13.46; Thu, 09 Sep 2021 09:13:46 -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=n93X3MT2; 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 560F268AA36; Thu, 9 Sep 2021 19:13:42 +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-oln040092064025.outbound.protection.outlook.com [40.92.64.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BBC6568A498 for ; Thu, 9 Sep 2021 19:13:35 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EWTfQPVhW1NTab1fNjZOro2LFiZQrz/XKv6Uo0szz69sgoWR//h/0p5NJQ5PEX3s7WxHdWzudYvr7b3ZyftJiOGxbWnD0QowBRBNG2n2meVujHmUDqZFUB9fpXXMuJICAttDysXgTnrON3C8z5lDZee+ZY7SWcvGFH7gW4pf2FJ9eUY4v5TyBEoYZfN/H7iUgSrjkwWczGTi/b9X+lzTwtniT5OHTi/JmVYWMS2U6FRNwAyP/W/f7nQf+pl+UT0khI7fvFUeAD5pcxwj4J79JYXTuTzPqO9Kps8WQORkcHXGBXhx3YxIWgrJFA71FMBF0FWlnRyavfCbCMzPqiBuJw== 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; bh=PURMu2L4GQiLW6eVVYrxUpw8eAWd6jtWq5CTe8gXFhw=; b=NY+fwkkT3Y26h7+bf3MuTmHLWEr5Imzf0XtCHc+6t8ZeEyRDLw12ipX53L9W7ucmzeS21gtFoDWT9xhXvbS3S6LoRhgKnJ7PcDvC0KCCAIl+CKULtyzs3G8zMw0pBDFeu0M1W4rh2AyV23+AprGD1McpQv6ahKqwB+c8Sm4Mh6IdFis89VA4LywZlP9cZ6ICF8TmAMoA3Uba1u9scMsdKKdl+9Wy0qRgLS18FtLmq98l6kpgfVkUdHjgN59fPlD1ys9CFU0zdNHGoYCDiw4vAWwOMqudFmgxfwY0fSZ8qJZP918i0Yj17UQ4LvBdyFFbyKBnPRtNx+zGUigum/bQwQ== 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=PURMu2L4GQiLW6eVVYrxUpw8eAWd6jtWq5CTe8gXFhw=; b=n93X3MT2LPpW5RibOkTN/OwKKzjuXKB442pHitBQ6o8g3LaQGVgFnYC7nhnYQHWh9D1DQtEg/qE94GY8aEQa2198xJ35DpWzkqVyZzdk3E3kfXFEg18PgYL9p5R4ug85p+r1JX5cVwGBA2qjqTeqOHo3Ec+GDhesSQffihikQAzdXfRjvOSJwn2SF/8r+O5Aq/AiVbzi6hepVoZyzc+T0wu3rK6xiHBG69ebmf5oby2/8Zmxjlr3IoWuvNqPJFcGRKBTOEEbFz2z8z5cEiCJuBCYnudDHyziYtNZmX/BSzohJ1X4DEfnUa6M1CmU/0b2wxA+tXJm7BK51M0NHOtY4Q== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:14 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:14 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:39 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [fstGK4UmuW4e0WydNTFvly3LTbOxOw8W] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4160865d-224d-4297-673f-08d973aaa19f X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQjHo/KsCc3LoxlbG+9PiyI2V4vxFpXfrchDEIX32sNuB38vdunG5qePvZjq/th71tRhhxKkmDR0bVkWBIeyKRnzfrQn7B44yyX2PLLkvmsvrZO+cQrDC6S1kxq7dGwUbN9heAgiWYPXF5WM9JBnAW+VMqcCfWxjIySQLG5G9vVq8mfTrylYsg/Ha4k5LX95iTcCw4wSZFEyA0D8COMxz8LnXk6dTlVQ9qrx8An8wDDZ8y/8PKX+OSdM1ihM/dfcG/KttG409iHzcV8n3vp0b1y5qPCeQwbaJ6uyqaKi+vU3yzD8eGZ9nu/3wFIjwYG/eyjkZlhywKj9GSBKSLQvDsr3uj9m1dtZGucXqXYPYPpQjyTwrX9YIa/55o814M+Xzlf102WWcpLg0bS47iXgDel9wJPlS+CiHc9JikKpH+OnMCKsQHzCjcttV4pbylqFvrRsHzF61Fix662eVYSNdAC9lSz3hDT5tr70eU2tcWrArnG9Fui5u/xvP8c3yUgwGu9z3caJ4TYCOyusHuqU1oXVDEnTe6DqhDvHqEhWzeVMsUZ/A5P55hl66HhifhBNlTPmGNqSvT7AbhRZyGXKbOjYLjKsLFNV0u+yqk35oSgj7YbsTX5d4IZI+co59U4jKghIczimujR8RFOIC8cdt/E7HlyP1J73QFx4iNjkyazbzhckZ9x7Ajk5M6LnbbSpRIIpgk3No2UOTR7tBRyY37cu5ZXkyVWmTehyNMCUP5Ih6bJUmQF3H/j53iXuEQistU= X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6hZFVdglhmkdSa7Yfa9v4qC18kbVbkPseyODP3paSoDvM/EaHY4PYCKRTGaGwVcT3CTjgXAWiY4SNslorDPbxUazTf7BZ0Nt6ul/UWg92XrLECikkfK3YBU504xP6hH7F0vV7EJnZUQSXMis/E12guzEtnW1SrlsT0oK9aSrSqJVA6Cl84yJ00dhah9OLTIhu/o0ZrK9FKnGq+KITav8eZSGx9rWOUxUA+SEarGVl5D/M8Ptf/XzUc3NSTDrb7jCKhre/XFeejKM1x2E2cDItkgZBitwLI8KDrA5HxGGGwBDtQJ6nipVS93ECd+eNMCrQlvFz9PgQtZycz9Xi/lc4nn3TrkSy4/6VzMmWDbHKIUpGjleVzy2dt7MMhRtUk8kkDgfjQBD767W2yCwiy9nhsPybdPW+KYY+NeEphrw0ZuWq7TykO2FIEB+FaWIfx25 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /CEBDlqOv7bi9aNC9E2zVvHUfCpNPzPFK/SNGPLL6RXOCdcE8z/QGWn5mPCrO8eUmQhA5gsavp78YKxoRYLR27l1CWxX0XwYs7UQCY3+hhywNXng1EJ1RM1CwW9DNGpTKy8KFGaB0EwBAYxKHFPcMg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4160865d-224d-4297-673f-08d973aaa19f X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:14.5985 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 06/14] 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: nGQ7Fhpt2wzA 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 | 13 +++++----- libavformat/avformat.h | 8 ------ libavformat/boadec.c | 6 +++-- libavformat/codec2.c | 3 +-- libavformat/dsfdec.c | 8 +++--- libavformat/dv.c | 5 ++-- libavformat/flacdec.c | 3 ++- libavformat/fsb.c | 2 +- libavformat/hca.c | 12 ++++----- libavformat/internal.h | 14 +++++++++-- libavformat/ipmovie.c | 2 +- libavformat/matroskadec.c | 7 +++--- libavformat/matroskaenc.c | 5 ++-- libavformat/mp3dec.c | 14 ++++++----- libavformat/mpegts.c | 2 +- libavformat/mtv.c | 2 +- libavformat/mux.c | 24 +++++++++--------- libavformat/mxfenc.c | 2 +- libavformat/nutdec.c | 2 +- libavformat/oggdec.c | 11 ++++---- libavformat/options.c | 45 ++++++++++++--------------------- libavformat/pcm.c | 2 +- libavformat/r3d.c | 7 +++--- libavformat/serdec.c | 2 +- libavformat/smacker.c | 2 +- libavformat/svs.c | 1 - libavformat/utils.c | 53 +++++++++++++++++++-------------------- libavformat/vqf.c | 2 +- libavformat/wavdec.c | 2 +- libavformat/webm_chunk.c | 4 +-- libavformat/yop.c | 2 +- libavformat/yuv4mpegdec.c | 6 ++--- 32 files changed, 135 insertions(+), 138 deletions(-) diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index ff6ddfb967..7bdaeda583 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 *const 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) { @@ -1429,6 +1429,7 @@ static int asf_read_close(AVFormatContext *s) static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit) { + FFFormatContext *const si = ffformatcontext(s); ASFContext *asf = s->priv_data; AVPacket pkt1, *pkt = &pkt1; ASFStream *asf_st; @@ -1441,9 +1442,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 - si->data_offset) / s->packet_size * s->packet_size + - s->internal->data_offset; + si->data_offset; *ppos = pos; if (avio_seek(s->pb, pos, SEEK_SET) < 0) return AV_NOPTS_VALUE; @@ -1525,7 +1526,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 +1574,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..536300a895 100644 --- a/libavformat/boadec.c +++ b/libavformat/boadec.c @@ -44,6 +44,8 @@ static int probe(const AVProbeData *p) static int read_header(AVFormatContext *s) { AVStream *st = avformat_new_stream(s, NULL); + uint32_t data_offset; + if (!st) return AVERROR(ENOMEM); @@ -56,14 +58,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 = 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, 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..40c8210a0f 100644 --- a/libavformat/dsfdec.c +++ b/libavformat/dsfdec.c @@ -141,13 +141,13 @@ 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; } static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt) { + FFFormatContext *const si = ffformatcontext(s); DSFContext *dsf = s->priv_data; AVIOContext *pb = s->pb; AVStream *st = s->streams[0]; @@ -161,7 +161,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 - si->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 +184,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 - si->data_offset) / st->codecpar->channels; pkt->duration = packet_size / st->codecpar->channels; return 0; } @@ -194,7 +194,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 - si->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..b96e039f71 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -437,9 +437,10 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c, int64_t timestamp, int flags) { // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk) + FFFormatContext *const si = ffformatcontext(s); 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) - si->data_offset; int64_t max_offset = ((size - 1) / frame_size) * frame_size; offset = frame_size * timestamp; @@ -449,7 +450,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 + si->data_offset; } void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset) diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 2060b48c69..ffa7e38561 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -258,7 +258,8 @@ 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; + FFFormatContext *const si = ffformatcontext(s); + AVPacket *const pkt = si->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 9d7312c0e2..8625ab8258 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..b38b1b418b 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; @@ -2898,6 +2898,7 @@ static int matroska_parse_tracks(AVFormatContext *s) static int matroska_read_header(AVFormatContext *s) { + FFFormatContext *const si = ffformatcontext(s); MatroskaDemuxContext *matroska = s->priv_data; EbmlList *attachments_list = &matroska->attachments; EbmlList *chapters_list = &matroska->chapters; @@ -2944,7 +2945,7 @@ static int matroska_read_header(AVFormatContext *s) } ebml_free(ebml_syntax, &ebml); - matroska->pkt = s->internal->parse_pkt; + matroska->pkt = si->parse_pkt; /* The next thing is a segment. */ pos = avio_tell(matroska->ctx->pb); @@ -2961,7 +2962,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; + si->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..b900937e82 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); @@ -2653,6 +2653,7 @@ static uint64_t mkv_get_uid(const mkv_track *tracks, int i, AVLFG *c) static int mkv_init(struct AVFormatContext *s) { + FFFormatContext *const si = ffformatcontext(s); MatroskaMuxContext *mkv = s->priv_data; AVLFG c; unsigned nb_tracks = 0; @@ -2674,7 +2675,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; + si->avoid_negative_ts_use_pts = 1; } if (!strcmp(s->oformat->name, "webm")) { diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 72c049edaf..cc97131227 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -360,14 +360,15 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base) static int mp3_read_header(AVFormatContext *s) { + FFFormatContext *const si = ffformatcontext(s); MP3DecContext *mp3 = s->priv_data; AVStream *st; int64_t off; int ret; int i; - s->metadata = s->internal->id3v2_meta; - s->internal->id3v2_meta = NULL; + s->metadata = si->id3v2_meta; + si->id3v2_meta = NULL; st = avformat_new_stream(s, NULL); if (!st) @@ -546,6 +547,7 @@ static int64_t mp3_sync(AVFormatContext *s, int64_t target_pos, int flags) static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { + FFFormatContext *const si = ffformatcontext(s); MP3DecContext *mp3 = s->priv_data; AVIndexEntry *ie, ie1; AVStream *st = s->streams[0]; @@ -555,8 +557,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 > si->data_offset) + filesize = size - si->data_offset; } if (mp3->xing_toc && (mp3->usetoc || (fast_seek && !mp3->is_cbr))) { @@ -577,7 +579,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) + si->data_offset; } else { return -1; // generic index code } @@ -588,7 +590,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 - si->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 95a56f0545..ce56595f29 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -224,7 +224,7 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) static int init_muxer(AVFormatContext *s, AVDictionary **options) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVDictionary *tmp = NULL; const AVOutputFormat *of = s->oformat; AVDictionaryEntry *e; @@ -434,7 +434,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 = @@ -443,7 +443,7 @@ static void deinit_muxer(AVFormatContext *s) int avformat_init_output(AVFormatContext *s, AVDictionary **options) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int ret = 0; if ((ret = init_muxer(s, options)) < 0) @@ -464,7 +464,7 @@ int avformat_init_output(AVFormatContext *s, AVDictionary **options) int avformat_write_header(AVFormatContext *s, AVDictionary **options) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int already_initialized = si->initialized; int streams_already_initialized = si->streams_initialized; int ret = 0; @@ -506,7 +506,7 @@ FF_DISABLE_DEPRECATION_WARNINGS //FIXME merge with compute_pkt_fields static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int delay = st->codecpar->video_delay; int frame_size; @@ -640,7 +640,7 @@ static void guess_pkt_duration(AVFormatContext *s, AVStream *st, AVPacket *pkt) */ static int write_packet(AVFormatContext *s, AVPacket *pkt) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVStream *const st = s->streams[pkt->stream_index]; int ret; @@ -791,7 +791,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; @@ -893,7 +893,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; @@ -1022,7 +1022,7 @@ int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); PacketList *pktl = si->packet_buffer; while (pktl) { if (pktl->pkt.stream_index == stream) { @@ -1169,7 +1169,7 @@ static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleav int av_write_frame(AVFormatContext *s, AVPacket *in) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVPacket *pkt = si->pkt; int ret; @@ -1233,7 +1233,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) int av_write_trailer(AVFormatContext *s) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVPacket *const pkt = si->pkt; int ret1, ret = 0; @@ -1325,7 +1325,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) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVPacket *pkt = si->pkt; av_assert0(s->oformat); 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..87f178bb7b 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; @@ -497,6 +497,7 @@ static int ogg_read_page(AVFormatContext *s, int *sid, int probing) static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize, int64_t *fpos) { + FFFormatContext *const si = ffformatcontext(s); struct ogg *ogg = s->priv_data; int idx, i, ret; struct ogg_stream *os; @@ -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..c98e3dbc66 100644 --- a/libavformat/r3d.c +++ b/libavformat/r3d.c @@ -160,6 +160,7 @@ static void r3d_read_reos(AVFormatContext *s) static int r3d_read_header(AVFormatContext *s) { + FFFormatContext *const si = ffformatcontext(s); R3DContext *r3d = s->priv_data; Atom atom; int ret; @@ -183,8 +184,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); + si->data_offset = avio_tell(s->pb); + av_log(s, AV_LOG_TRACE, "data offset %#"PRIx64"\n", si->data_offset); if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) return 0; // find REOB/REOF/REOS to load index @@ -210,7 +211,7 @@ static int r3d_read_header(AVFormatContext *s) } out: - avio_seek(s->pb, s->internal->data_offset, SEEK_SET); + avio_seek(s->pb, si->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 2102b6aeac..6ae6952733 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) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); si->inject_global_side_data = 1; for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; @@ -372,7 +372,7 @@ static int init_input(AVFormatContext *s, const char *filename, int avformat_queue_attached_pictures(AVFormatContext *s) { - AVFormatInternal *const si = s->internal; + 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 && @@ -459,14 +459,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); @@ -629,7 +629,7 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); if (st->internal->request_probe>0) { AVProbeData *pd = &st->internal->probe_data; @@ -747,7 +747,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; @@ -964,7 +964,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) @@ -1045,7 +1045,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; @@ -1099,7 +1099,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; @@ -1158,7 +1158,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt, int64_t next_dts, int64_t next_pts) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int num, den, presentation_delayed, delay; int64_t offset; AVRational duration; @@ -1349,7 +1349,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; @@ -1463,7 +1463,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; @@ -1651,7 +1651,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; @@ -1751,7 +1751,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); @@ -1800,7 +1800,7 @@ int av_find_default_stream_index(AVFormatContext *s) /** Flush the frame reader. */ void ff_read_frame_flush(AVFormatContext *s) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); flush_packet_queue(s); @@ -2188,7 +2188,7 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t (*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t)) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int64_t pos, ts; int64_t start_pos; int no_change; @@ -2291,7 +2291,7 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, static int seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int64_t pos_min, pos_max; pos_min = si->data_offset; @@ -2312,7 +2312,7 @@ 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) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); int index; int64_t ret; AVStream *st; @@ -2648,7 +2648,7 @@ static void fill_all_stream_timings(AVFormatContext *ic) static void estimate_timings_from_bit_rate(AVFormatContext *ic) { - AVFormatInternal *const si = ic->internal; + FFFormatContext *const si = ffformatcontext(ic); int show_warning = 0; /* if bit_rate is already set, we believe it */ @@ -2705,7 +2705,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) { - AVFormatInternal *const si = ic->internal; + FFFormatContext *const si = ffformatcontext(ic); AVPacket *const pkt = si->pkt; int num, den, read_size, ret; int found_duration = 0; @@ -3454,7 +3454,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; @@ -3518,7 +3518,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; @@ -4269,11 +4269,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); @@ -4308,7 +4308,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); } @@ -4341,7 +4340,7 @@ void avformat_close_input(AVFormatContext **ps) AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) { - AVFormatInternal *const si = s->internal; + FFFormatContext *const si = ffformatcontext(s); AVStream *st; AVStream **streams; @@ -4454,7 +4453,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 Thu Sep 9 15:57:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30091 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp649140iov; Thu, 9 Sep 2021 08:59:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUA6h0bgCxFzTOnl7jKtzM/T0WhG3TiUutowLclnmENGw43fWN+nY/MyGVilTTukOUVRrs X-Received: by 2002:a17:906:3e1b:: with SMTP id k27mr4294912eji.284.1631203143250; Thu, 09 Sep 2021 08:59: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 e16si368249edz.49.2021.09.09.08.59.01; Thu, 09 Sep 2021 08:59: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=P4+ySgng; 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 E2ACB68A9C1; Thu, 9 Sep 2021 18:58:27 +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 22E2868A9AA for ; Thu, 9 Sep 2021 18:58:25 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V746bRw5srSIownzkAfxAhAfFHo/AncmApXDKzs3xprs0qbImvH+8hQf5R4PZyHRnvdA1Z1ZLEU0jk163IFVBJWE+MVbqE7B62N6ML5ebu/lsutdiW9wt1EdE5Z7LAZkVm6Pvr1B+LMC839RiCljwtFk3IYl4kBKnacJ/Nz8x9iTcw0o7XQ7j5IHnQRUb9OUPa0ImQUhUvw9ftK1xeASXjyjED0EjVRbEI5mIoDHmCNYTHu26zNaOH3a1dcvUwjdQqPuCNt/l98KinJkLXMPRGqF3m8crLb+v+DwGhkGRFWHCzdZts8ScwRvKO2h+ZxNcq4Uyen3U8Ag14AQi5ZRMw== 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; bh=i6UoiLv+gm9lRcvZPv6dWFrqTOrxnwmwxolNoV3zsmg=; b=dRG4QlFa+khq8A7OCRaIUla1C5SB+Tx5cklnRHqb0oZSQCSA99f/NM7jg775R70CrbYPKhSaeNqG7K65FS1OJfXH7iOdm8TXU+MC1mrs1Vr5mRE7tB2Tzdde2Nzn98Ml6J6srnN1FGq+82O256iT4XfjZHFuuScwsxX31v+tIbRNpjevetkP+gJn9VgVMQGKD8gPceafmd68sP7lieaAM4pl4EsjUH1COWaX5/USWmbaTRii7pLRCFkUEm2eVGlubaXySP2imk1RAPs2ZbiPTozy6XKuWjKASD6Ph7fjDyUvU/nof3YJKrUtCYbnat+Z0aNXNB6RGnABgHwWI2pd4w== 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=i6UoiLv+gm9lRcvZPv6dWFrqTOrxnwmwxolNoV3zsmg=; b=P4+ySgngMcFVDxR/EFK+7a/jg8aqZHpbeIRRkEnCIu7mKJXEeQ1FE1+N5Z2bbXUDIdRda5CjSI+01JPQ+miB+9x9DnIsAq5KS39WOyUt6W50XPqrTWyT1d6EphSUD2qm+ZHFDgKEqnwsKRELTJUbcN4AroXgQg8KQWGhxWECH80jE/EmRvEz/2XuIzYuJT2XeW44/q/kqbWTRTOXDHBNSHiLbqbrqCOBuR0S3tCLL5JFJQDXvtGi6c4x2kRIb81WLwRo0sSMpkkTd7bFdqnamKVqaFM2aOseZ4VoYxx4EGXwCeYUI1J8XS/W6mW6H0MJn2S5mse0BGvcwk7jHfc7dQ== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:15 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:15 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:40 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [fSQT5vSr8ArzI0SlVrNgMpxZWYTPpIgp] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-6-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 059e89fa-2330-4f6d-7786-08d973aaa1fb X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEsS78EXmycSIjNILG4ckU6S1VGn1vaXuIGC4nTS1ElTJtOEM7gA7DmaF4TsIlaVDHTriHKLCr11EBOxx5vM1RbPlciPo5S5+GF6kLABaw0kncMNhO7KDlXoKj7dpYlC1HoSnmm35yK1cpaynn4CO6XaADwlpCZ7SzLaTPp72Pm1tsZynhuQ3fS08PU/eWCgrgT26HRTah7pLbnPpxix5DZbBOmoKwITMgnRx81S32zGzzs08LvLCRh6Vn06Jv5bu96IcO3xeSvm+APZ+9pdKktG9bk+7onAOV1EeX+TwhkBi6+Vs86zUcnLEhXg6G1hvMFTzZTsBzIfTQvQnh1MXjPAnhgOcQ/M/HbesajobjXvleuDvHVAafFSMgkceTB1mek6aB2Qxr1NBNDO0zoP6LB8X2XDAz9KtJIiGgx/gdaH3w8kA2PLnuwIhxNcV1FGpyh2FmzsaUQ+lAFKdvjXPazdEmiBNa4o6VF8ti23teQCsg+vGrtFRW/UPu0q/cRCUgw9dLtK+kqa4WWKUh3J6hZKTBpuLMVx68moRKxD03MOjkG7tPRkih2xtvdHkIqNDaxV7fG+xLmy6LPeoA9NbEMHyijRhQDAgHG5H+nnd0p566esWVQqWajdmaq+w1Fd5gSxXAdwyF7Xx7g6R82pa13IMPhWVH9W0kcFnZFD5Z4G3jF2w9MPkIkA5gZkYtioSDD1tHwOcoNJ3+PI+4e0ZreWYMF8utiE3m06CVTNYGIl3YQI/+cz/nIM+3ghjXLQEhFqGHti+u6ugNAT6YxBDmGZ X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W6Bzg93tVXzzrYmF1F8porzTOqWNBwBm0DOAZzGEKYsRq9nAXWfJDjRMTLMwBqjjNfR2FzdKEhJVSxnXOfuzVyV29RFkL2/wCOADoJZV2vAeCz4vnCx7MveZortN0ESwzUhu3qSSF5DHZkrc0ykVb5GBXQobDbW7WUwPGY01L7+tPjiuSWtUGQfsZmyTyAuGl7bY/TYsEUyQyjKChDXPk7thdPS1OtZZM7LIsBN7yonkgwxLajx/pcgvTVmy96JIfQfsaX8rYwlcEu/5VpTvcVx+hikFGTDv+B9TLMWlTZTLMNdNPHK8APTH9qk6uA1rokT0/6PLS+gB/TPyLbmXQWURFwFc+c3XWCVtuKuO73q/x8uafyf59rRLIlW1CjoZDNlKDOMDdE5FPIKNtPp2kj/pSodSyETjH5WtUnHR6CmuQnbTEOcRC8K4KAY0OGYy X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hcII4SSwUhHMTJQUoUoRnQCyk0T9+qLN6qUQzv809093ExKe5PnZnp8ot7Qc47TxxEu2lo5/WydD5himCGZaoQyVW+QJHXg3aEssRB4ziNsSCfxDSYxEXijbFU02tvis6xSS30TDDWhqCJ/hugM0xQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 059e89fa-2330-4f6d-7786-08d973aaa1fb X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:15.6538 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 07/14] 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: P+YaF2S1UFbt This gets rid of ugly "->internal" and is in preparation for removing AVStreamInternal altogether. Signed-off-by: Andreas Rheinhardt --- libavformat/mux.c | 131 ++++--- libavformat/utils.c | 885 +++++++++++++++++++++++--------------------- 2 files changed, 542 insertions(+), 474 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index ce56595f29..c9a1aadbc8 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -253,6 +253,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *const st = s->streams[i]; + AVStreamInternal *const sti = st->internal; AVCodecParameters *const par = st->codecpar; const AVCodecDescriptor *desc; @@ -303,9 +304,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; + sti->reorder = 1; - st->internal->is_intra_only = ff_is_intra_only(par->codec_id); + sti->is_intra_only = ff_is_intra_only(par->codec_id); if (of->codec_tag) { if ( par->codec_tag @@ -385,6 +386,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) { @@ -398,16 +400,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); } } @@ -507,6 +509,7 @@ FF_DISABLE_DEPRECATION_WARNINGS static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { FFFormatContext *const si = ffformatcontext(s); + AVStreamInternal *const sti = st->internal; int delay = st->codecpar->video_delay; int frame_size; @@ -523,7 +526,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; @@ -537,28 +540,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) { @@ -573,8 +576,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) { @@ -586,12 +589,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; @@ -642,6 +645,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) { FFFormatContext *const si = ffformatcontext(s); AVStream *const st = s->streams[pkt->stream_index]; + AVStreamInternal *const sti = st->internal; int ret; // If the timestamp offsetting below is adjusted, adjust @@ -656,7 +660,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (s->avoid_negative_ts > 0) { - int64_t offset = st->internal->mux_ts_offset; + 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 && @@ -666,7 +670,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, @@ -739,13 +743,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) @@ -761,13 +766,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); } @@ -779,7 +784,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; @@ -794,6 +799,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)); @@ -810,27 +816,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) { @@ -855,7 +861,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; } @@ -905,11 +911,14 @@ 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]; + const AVStreamInternal *const sti = st->internal; + const AVCodecParameters *const par = st->codecpar; + if (sti->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 (par->codec_type != AVMEDIA_TYPE_ATTACHMENT && + par->codec_id != AV_CODEC_ID_VP8 && + par->codec_id != AV_CODEC_ID_VP9) { ++noninterleaved_count; } } @@ -929,14 +938,16 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AV_TIME_BASE_Q); for (unsigned i = 0; i < s->nb_streams; i++) { + const AVStream *const st = s->streams[i]; + const AVStreamInternal *const sti = st->internal; + const PacketList *last = sti->last_in_packet_buffer; int64_t last_dts; - const PacketList *last = s->streams[i]->internal->last_in_packet_buffer; if (!last) continue; last_dts = av_rescale_q(last->pkt.dts, - s->streams[i]->time_base, + st->time_base, AV_TIME_BASE_Q); delta_dts = FFMAX(delta_dts, last_dts - top_dts); } @@ -966,6 +977,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); @@ -976,8 +988,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); @@ -988,14 +1000,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; @@ -1050,7 +1064,7 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in return ff_interleave_packet_per_dts(s, out, in, flush); } -static int check_bitstream(AVFormatContext *s, AVStream *st, AVPacket *pkt) +static int check_bitstream(AVFormatContext *s, AVStreamInternal *sti, AVPacket *pkt) { int ret; @@ -1058,11 +1072,11 @@ static int check_bitstream(AVFormatContext *s, AVStream *st, AVPacket *pkt) return 1; if (s->oformat->check_bitstream) { - if (!st->internal->bitstream_checked) { + if (!sti->bitstream_checked) { if ((ret = s->oformat->check_bitstream(s, pkt)) < 0) return ret; else if (ret == 1) - st->internal->bitstream_checked = 1; + sti->bitstream_checked = 1; } } @@ -1114,7 +1128,8 @@ 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; + AVStreamInternal *const sti = st->internal; + AVBSFContext *const bsfc = sti->bsfc; int ret; if ((ret = av_bsf_send_packet(bsfc, pkt)) < 0) { @@ -1147,20 +1162,22 @@ static int write_packets_from_bsfs(AVFormatContext *s, AVStream *st, AVPacket *p static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleaved) { AVStream *st; + AVStreamInternal *sti; int ret = check_packet(s, pkt); if (ret < 0) return ret; st = s->streams[pkt->stream_index]; + sti = st->internal; ret = prepare_input_packet(s, st, pkt); if (ret < 0) return ret; - ret = check_bitstream(s, st, pkt); + ret = check_bitstream(s, sti, pkt); if (ret < 0) return ret; - if (st->internal->bsfc) { + if (sti->bsfc) { return write_packets_from_bsfs(s, st, pkt, interleaved); } else { return write_packet_common(s, st, pkt, interleaved); diff --git a/libavformat/utils.c b/libavformat/utils.c index 6ae6952733..90c15b01f2 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; @@ -313,21 +314,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; } } @@ -434,22 +436,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; } @@ -630,12 +633,13 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { FFFormatContext *const si = ffformatcontext(s); + AVStreamInternal *const sti = st->internal; - if (st->internal->request_probe>0) { - AVProbeData *pd = &st->internal->probe_data; + 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); @@ -651,7 +655,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); @@ -659,7 +663,7 @@ no_packet: } end = si->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); @@ -667,7 +671,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 @@ -681,6 +685,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; @@ -688,7 +693,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; @@ -703,17 +708,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 { @@ -732,8 +739,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; @@ -763,6 +771,7 @@ FF_ENABLE_DEPRECATION_WARNINGS for (;;) { PacketList *pktl = si->raw_packet_buffer; + AVStreamInternal *sti; const AVPacket *pkt1; if (pktl) { @@ -791,10 +800,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; } @@ -821,15 +831,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); @@ -841,7 +852,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, @@ -882,7 +893,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; @@ -896,10 +908,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) { @@ -911,14 +923,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; @@ -946,20 +958,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) @@ -973,17 +986,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 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 (st->internal->pts_reorder_error_count[i]) { - int64_t score = st->internal->pts_reorder_error[i] / st->internal->pts_reorder_error_count[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]; @@ -994,13 +1008,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; } } } @@ -1047,22 +1061,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; @@ -1079,7 +1094,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)); } } @@ -1092,7 +1107,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)); } } @@ -1100,14 +1115,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 || @@ -1117,18 +1133,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)) { @@ -1137,13 +1153,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 @@ -1151,7 +1167,7 @@ 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, @@ -1159,6 +1175,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, int64_t next_dts, int64_t next_pts) { FFFormatContext *const si = ffformatcontext(s); + AVStreamInternal *const sti = st->internal; int num, den, presentation_delayed, delay; int64_t offset; AVRational duration; @@ -1169,24 +1186,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; } @@ -1194,12 +1211,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 @@ -1211,7 +1228,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; @@ -1246,7 +1263,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) @@ -1264,7 +1281,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 @@ -1275,28 +1292,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 || @@ -1309,31 +1326,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 (int i = 0; i < delay && st->internal->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)) @@ -1352,13 +1369,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)) { @@ -1366,7 +1384,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); @@ -1385,7 +1403,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) { @@ -1406,35 +1424,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, @@ -1445,8 +1463,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: @@ -1469,6 +1487,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); @@ -1487,30 +1506,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 && @@ -1531,23 +1551,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) && @@ -1560,18 +1580,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; } @@ -1582,29 +1602,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; @@ -1620,7 +1641,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; } } @@ -1807,28 +1828,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 (si->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; } } @@ -1847,13 +1869,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; } } @@ -1919,9 +1942,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); } @@ -1990,19 +2014,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; @@ -2035,7 +2061,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); } @@ -2046,24 +2073,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, @@ -2084,6 +2113,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; @@ -2095,7 +2125,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 @@ -2103,7 +2134,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; @@ -2116,9 +2147,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; @@ -2313,26 +2344,26 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { FFFormatContext *const si = ffformatcontext(s); + 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) { - AVPacket *const pkt = si->pkt; + 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; @@ -2372,7 +2403,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; @@ -2655,17 +2686,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; @@ -2717,17 +2748,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; } } @@ -2750,6 +2782,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; @@ -2760,11 +2793,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, @@ -2777,12 +2811,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); @@ -2828,12 +2862,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; } } @@ -2900,7 +2935,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) \ @@ -2915,23 +2951,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: @@ -2949,7 +2985,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(); @@ -2962,14 +2999,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; } @@ -2987,14 +3024,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; } @@ -3008,7 +3045,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 || @@ -3033,7 +3070,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; } } @@ -3276,59 +3313,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; } @@ -3337,36 +3375,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; @@ -3381,19 +3419,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; } } @@ -3572,15 +3610,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)); @@ -3590,8 +3628,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); @@ -3608,7 +3646,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) @@ -3623,6 +3661,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; @@ -3635,6 +3674,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; @@ -3645,7 +3685,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; @@ -3653,8 +3693,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) @@ -3662,16 +3702,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; @@ -3695,14 +3734,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; } @@ -3731,70 +3772,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)); } @@ -3814,11 +3856,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) { @@ -3826,9 +3868,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; @@ -3849,7 +3891,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++; } @@ -3917,20 +3959,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. */ @@ -3968,9 +4010,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) { @@ -4008,20 +4050,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", @@ -4038,27 +4081,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); @@ -4225,6 +4271,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; @@ -4236,19 +4283,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); @@ -4342,6 +4391,7 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) { FFFormatContext *const si = ffformatcontext(s); AVStream *st; + AVStreamInternal *sti; AVStream **streams; if (s->nb_streams >= s->max_streams) { @@ -4359,28 +4409,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); @@ -4388,29 +4438,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; + 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++) - st->internal->pts_buffer[i] = AV_NOPTS_VALUE; + sti->pts_buffer[i] = AV_NOPTS_VALUE; st->sample_aspect_ratio = (AVRational) { 0, 1 }; - st->internal->inject_global_side_data = si->inject_global_side_data; + sti->inject_global_side_data = si->inject_global_side_data; - st->internal->need_context_update = 1; + sti->need_context_update = 1; s->streams[s->nb_streams++] = st; return st; @@ -4955,7 +5005,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 && @@ -4964,7 +5015,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 Thu Sep 9 15:57:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30093 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp649825iov; Thu, 9 Sep 2021 08:59:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMgfgQ/vpBloDJnfAkPrT0XjF3B+AKYJUA6NEdo94DaA099PRNf44K6PkUJuDF8EfsyyYW X-Received: by 2002:a7b:cb44:: with SMTP id v4mr3756674wmj.169.1631203192744; Thu, 09 Sep 2021 08:59:52 -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 y13si2737893edm.398.2021.09.09.08.59.52; Thu, 09 Sep 2021 08:59:52 -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=RlPCbjD2; 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 47B2A68AA3D; Thu, 9 Sep 2021 18:58:32 +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 C000968A9AD for ; Thu, 9 Sep 2021 18:58:25 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sr7ztzE42JYKcyQ35aGahKV+YVxDXg3ajGlc2g1fMbW+i1zh4gSsGAURTUuqRMuKT7WsLgwz0OVxygUveZm3iZORlb++7naIShYzveFqFt8avB680BVeM5Sm39/zE6J9JVnGF2SBO2iL/xYAbtpzJ2tJZMd9mNfaiBKLpwnI+KDRiq/rHaL6q9Os09MvnVYBiPFiTMD8u1UMc4tJgP0dOX9bY2QsIAFOLVcGN5vOshr9znNYSnGfaCAeOQAioyI+pPNDZxTXl+sZ3WwpUYm2FJTJirOzRnhj4W9Br4f55UP3Z1yNqIsC7fQ0Lz0abF+v3XYSkBK3tC90KvhfxT/BHQ== 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; bh=MpaSc6hDUtjAEUfnKVPfHuJSVklC9BYQLDyit9Mfdp0=; b=j70tgE66W+vBKP8JRBSjtowkcmPnxEGl0WkFbYWIPNr2hM63YS9eBpdq5OaPB2qQVKqrjzaMrPh0jnaVvRBh8C2R7pk3R2uvYb6XKundtH4jxWkCaHpSjK/IycyWHDcW6lBrH71eMiRTYHa5CHUsAJGp9Q7Lt6rCEybFmhlxFyJiWE4bKvBNCLRYCEf+OtbnPa7eiBRFyVmSm2Bklc6V3Ie/LqvIJ2OhAFCChYiJl6v1lFbr0sv819AJ25JreKww0qzlr70K+Bs8Q/wUJwp/WXNvgeEUsNn0z0r1XUbcDoG1/Os/N/0mI4IOH2f3qSQOv7YFZGlhM28Xjxzv7/Saiw== 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=MpaSc6hDUtjAEUfnKVPfHuJSVklC9BYQLDyit9Mfdp0=; b=RlPCbjD2EBkzjhB9lQcLjuOQIG7DLnbTh1VnGpmSV9GyA+Ivm+bvsBjr3luPIt8XE3UWttPY4F2U1pCGW19EEBc6HBLj/NU49DouAJm3RaRLML1boPhXMTw9Y0lQ6/KqSAt1L9uMqQp6Ypliw3KaqS1n9f1C8VC/mnIOU0gCgJzKh7Ku+64EncIXoPodphC1wMh/2tUErxJmjRs2gxBGB7JHwK/mH8WZkAC1mbtpdXZe0pNIQMUNbUBuMQwnq7S2DvKm6MaAXVk4epZ6ZmBaKPIn0buTQrQ3fBmbzFrPS9S/ldByor6KUjQwTD4fsEc10BFfX2nbS6B2GHfbSd5Xuw== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:17 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:17 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:41 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [Zq3yX7Xkocu+VNtSJufmxQAxmUE5RLVg] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-7-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3045a104-18ed-4e31-d819-08d973aaa29f X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQjHo/KsCc3LoxlbG+9PiyI+mxnW3Z1ir9iAhj93/XQ3pc3aiPD8jL10cjvAcT8uFEbEYNtS0aAR9yEXcoMQKD8VCdgPD5H8gHJnOAZ5TefXaE09WxImhcRQJjk/E7vsy/cMuJec8M0YKo8hbzBMl884dUSdifIRiXD4vn86RCoaJZVefwQ2/77eOD5wCVXgUAzI2OfM7Emhp3WU9KZuH/6YFzxIqxKsWcx0lOfDU0tTiCgZK28c3Kcqd7VvwYfbPFx2jeFbGZHupBjbUbEws/tlL2a+Y1i5AH9gMLJBKdn1IThxEMhTPPjkx/+d0uaHtPlQ6SVEdptAcTON0iAVqVis7z5v/QUkqFi2lukdX4AUqWewkdk73IFRgw2HFzi/Hdz8t7C4l9IZrB3dAgoYX6Hk1m71ilc4RhKH/NdSr384QjvayauQoiJKKruFObo43f9PDY5jh1KO4vac+11EhomYiledgO+MeVBtk+VFgiZoJ9XJsLZQoVKUg+LAtLdOJtHeEhI4muBVUD9yfoYfhxkjdl3QfAWUvpG3XOPFDPHjf0sS8gThjtT6opLkn2woVqK3JkG596JbBJtuN4EiYhhu90C7aEKNS74ZK2YXype99bYtpILHXoglYG4K+DKM884IkkizcbEPp98qf90HmyZa9ZBx6g2kdyQH1j+BQdUTify+a+v9jCU8P4dYm6AkmbRwafddiod23OrrI3uNUwNE5NsPRiloLj2euBvq7rMIxb6fHghMqjCFxTzRnJ2kb0= X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TmGDrFfxxi8549tCqD1RT4IgPcdqx6VUdUQXFEHU9R46Q/aEPGoogyfzoY5NdkxS2vuzIsCsn0QWK03Z6Wl1UYTtftthVj/EcQ6bdmRuOBpaR5veRXDcgRJMdvsm55emh2FxbSxVtAcWJJtIGIS5otYaVajY9XgAZt0bc1syQsChN3X7zXWNRY0wwF3PJEbXXFcxECzZx7EjUtcptlBP7ZcCyq1S3qpV064P8QFWWW8Ax0WbW9LuI0n2ztnqPylo/oxIn2OKcqr7vohgKS/R/HzTAoFgrvtDUvLVu3/Vd1RxGvjxZ1263gx04wt82xLbd/D2+APupxjL6P1KqtMNk98e5pTEFWhwEOTgt2zMSu3DWTavcJjS/jkOxYvbbmlOvgE1wJHckBL19bOz9yspOBsgctD/yHorfj9JBhH/UK3Aymsj+664vDs5GEFohqEM X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cBjtOEMMdpqmsywf+Nqa3CY+ifcra09u+I0sPECshKOTKjCDHDpOIQ7dBBCFr28DQ0ckxzT1oJGXn/XjKD8LpxPlLIqZnBzQe4JzC88nZjYkDSedmDM/OfRVs8PhGi8Jz/6JQXfdCooReH+eCo/QnA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3045a104-18ed-4e31-d819-08d973aaa29f X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:17.2249 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 08/14] 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: 9+Ovc2qFRlOr 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 | 8 +- libavformat/acm.c | 2 +- libavformat/ape.c | 2 +- libavformat/asfdec_f.c | 19 ++- libavformat/asfdec_o.c | 10 +- libavformat/av1dec.c | 6 +- libavformat/avformat.h | 8 - libavformat/avidec.c | 138 +++++++++------- libavformat/bink.c | 18 ++- libavformat/cafdec.c | 24 +-- libavformat/cinedec.c | 5 +- libavformat/concatdec.c | 6 +- libavformat/dashenc.c | 8 +- libavformat/dhav.c | 5 +- libavformat/dtshddec.c | 2 +- libavformat/dump.c | 15 +- libavformat/electronicarts.c | 2 +- libavformat/fifo.c | 2 +- libavformat/flacdec.c | 19 +-- libavformat/flic.c | 7 +- libavformat/flvdec.c | 26 +-- libavformat/gxf.c | 15 +- libavformat/hdsenc.c | 7 +- libavformat/hls.c | 2 +- libavformat/ifv.c | 17 +- libavformat/img2dec.c | 6 +- libavformat/internal.h | 19 ++- libavformat/ipudec.c | 2 +- libavformat/iv8.c | 2 +- libavformat/ivfdec.c | 2 +- libavformat/jvdec.c | 29 ++-- libavformat/lmlm4.c | 4 +- libavformat/loasdec.c | 2 +- libavformat/lxfdec.c | 2 +- libavformat/matroskadec.c | 73 +++++---- libavformat/mgsts.c | 2 +- libavformat/mlvdec.c | 29 ++-- libavformat/mov.c | 265 +++++++++++++++++-------------- libavformat/mp3dec.c | 20 ++- libavformat/mpc.c | 5 +- libavformat/mpc8.c | 5 +- libavformat/mpeg.c | 6 +- libavformat/mpegts.c | 75 +++++---- libavformat/msf.c | 2 +- libavformat/mtv.c | 2 +- libavformat/mux.c | 34 ++-- libavformat/mvdec.c | 5 +- libavformat/mxfdec.c | 14 +- libavformat/mxfenc.c | 10 +- libavformat/ncdec.c | 2 +- libavformat/nsvdec.c | 9 +- libavformat/nutdec.c | 9 +- libavformat/nutenc.c | 13 +- libavformat/nuv.c | 2 +- libavformat/oggparseflac.c | 2 +- libavformat/oggparseogm.c | 7 +- libavformat/oggparsetheora.c | 2 +- libavformat/oggparsevp8.c | 2 +- libavformat/omadec.c | 2 +- libavformat/pcm.c | 2 +- libavformat/pva.c | 4 +- libavformat/rawdec.c | 8 +- libavformat/rdt.c | 4 +- libavformat/rl2.c | 9 +- libavformat/rmdec.c | 9 +- libavformat/rpl.c | 6 +- libavformat/rtpdec_asf.c | 4 +- libavformat/rtsp.c | 2 +- libavformat/s337m.c | 2 +- libavformat/sbgdec.c | 10 +- libavformat/sdr2.c | 2 +- libavformat/segafilm.c | 4 +- libavformat/segment.c | 8 +- libavformat/smoothstreamingenc.c | 7 +- libavformat/swfdec.c | 4 +- libavformat/takdec.c | 2 +- libavformat/tedcaptionsdec.c | 6 +- libavformat/tta.c | 9 +- libavformat/ty.c | 4 +- libavformat/utils.c | 172 ++++++++++---------- 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, 745 insertions(+), 606 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..72f4b6f7cc 100644 --- a/libavformat/aadec.c +++ b/libavformat/aadec.c @@ -86,6 +86,7 @@ static int aa_read_header(AVFormatContext *s) AADemuxContext *c = s->priv_data; AVIOContext *pb = s->pb; AVStream *st; + FFStream *sti; int ret; /* parse .aa header */ @@ -178,11 +179,12 @@ static int aa_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); + sti = ffstream(st); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; 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; + sti->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 +193,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; + sti->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 +201,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; + sti->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 7bdaeda583..72ba8b32a0 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -299,6 +299,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) ASFContext *asf = s->priv_data; AVIOContext *pb = s->pb; AVStream *st; + FFStream *sti; ASFStream *asf_st; ff_asf_guid g; enum AVMediaType type; @@ -317,6 +318,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); + sti = ffstream(st); avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ start_time = asf->hdr.preroll; @@ -378,13 +380,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; + sti->request_probe = 1; st->codecpar->codec_tag = 0; } if (st->codecpar->codec_id == AV_CODEC_ID_AAC) - st->internal->need_parsing = AVSTREAM_PARSE_NONE; + sti->need_parsing = AVSTREAM_PARSE_NONE; else - st->internal->need_parsing = AVSTREAM_PARSE_FULL; + sti->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 +445,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; + sti->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 +455,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; + sti->need_parsing = AVSTREAM_PARSE_FULL_ONCE; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) - st->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE; + sti->need_parsing = AVSTREAM_PARSE_FULL_ONCE; } pos2 = avio_tell(pb); avio_skip(pb, size - (pos2 - pos1 + 24)); @@ -1557,6 +1559,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, { ASFContext *asf = s->priv_data; AVStream *st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); int ret = 0; if (s->packet_size <= 0) @@ -1584,11 +1587,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 && sti->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 = sti->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..fb614d42de 100644 --- a/libavformat/asfdec_o.c +++ b/libavformat/asfdec_o.c @@ -1513,13 +1513,15 @@ 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]; + FFStream *const sti = ffstream(st); 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 (sti->nb_index_entries && asf->is_simple_index) { + idx = av_index_search_timestamp(st, timestamp, flags); + if (idx < 0 || idx >= sti->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, sti->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..6e1c2a45ff 100644 --- a/libavformat/av1dec.c +++ b/libavformat/av1dec.c @@ -61,6 +61,7 @@ static int av1_read_header(AVFormatContext *s) AV1DemuxContext *const c = s->priv_data; const AVBitStreamFilter *filter = av_bsf_get_by_name("av1_frame_merge"); AVStream *st; + FFStream *sti; int ret; if (!filter) { @@ -72,12 +73,13 @@ static int av1_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); + sti = ffstream(st); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_AV1; - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + sti->need_parsing = AVSTREAM_PARSE_HEADERS; - st->internal->avctx->framerate = c->framerate; + sti->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 b1dea1362e..3eb5d4dff5 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; @@ -736,10 +738,12 @@ static int avi_read_header(AVFormatContext *s) avio_skip(pb, size); } else { uint64_t cur_pos = avio_tell(pb); + FFStream *sti; unsigned esize; if (cur_pos < list_end) size = FFMIN(size, list_end - cur_pos); st = s->streams[stream_index]; + sti = ffstream(st); if (st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) { avio_skip(pb, size); break; @@ -823,19 +827,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; + sti->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; + sti->need_parsing = AVSTREAM_PARSE_FULL; if (st->codecpar->codec_id == AV_CODEC_ID_RV40) - st->internal->need_parsing = AVSTREAM_PARSE_NONE; + sti->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; + sti->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 +883,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; + sti->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; + sti->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; + sti->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 +919,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; + sti->request_probe = 1; avio_skip(pb, size); break; default: @@ -1050,12 +1054,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 +1345,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); } @@ -1363,20 +1368,22 @@ static int ni_prepare_read(AVFormatContext *s) AVIContext *avi = s->priv_data; int best_stream_index = 0; AVStream *best_st = NULL; + FFStream *best_sti; AVIStream *best_ast; int64_t best_ts = INT64_MAX; int i; 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; @@ -1395,6 +1402,7 @@ static int ni_prepare_read(AVFormatContext *s) if (!best_st) return AVERROR_EOF; + best_sti = ffstream(best_st); best_ast = best_st->priv_data; best_ts = best_ast->frame_offset; if (best_ast->remaining) { @@ -1405,11 +1413,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 = best_sti->index_entries[i].timestamp; } if (i >= 0) { - int64_t pos = best_st->internal->index_entries[i].pos; + int64_t pos = best_sti->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 +1427,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 = best_sti->index_entries[i].size; } else return AVERROR_EOF; @@ -1450,6 +1458,7 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) resync: if (avi->stream_index >= 0) { AVStream *st = s->streams[avi->stream_index]; + FFStream *const sti = ffstream(st); AVIStream *ast = st->priv_data; int dv_demux = CONFIG_DV_DEMUXER && avi->dv_demux; int size, err; @@ -1508,15 +1517,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 && sti->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 = &sti->index_entries[index]; if (index >= 0 && e->timestamp == ast->frame_offset) { - if (index == st->internal->nb_index_entries-1) { + if (index == sti->nb_index_entries-1) { int key=1; uint32_t state=-1; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { @@ -1552,7 +1561,7 @@ resync: } ast->seek_pos= 0; - if (!avi->non_interleaved && st->internal->nb_index_entries>1 && avi->index_loaded>1) { + if (!avi->non_interleaved && sti->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 +1660,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,25 +1687,27 @@ 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++) { AVStream *st = s->streams[i]; + FFStream *const sti = ffstream(st); AVIStream *ast = st->priv_data; 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(sti->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 +1737,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 +1829,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 +1848,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 */ @@ -1874,6 +1888,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, pos_min = pos; for (i = 0; i < s->nb_streams; i++) { AVStream *st2 = s->streams[i]; + FFStream *const sti2 = ffstream(st2); AVIStream *ast2 = st2->priv_data; ast2->packet_size = @@ -1884,7 +1899,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, continue; } - if (st2->internal->nb_index_entries <= 0) + if (sti2->nb_index_entries <= 0) continue; // av_assert1(st2->codecpar->block_align); @@ -1898,14 +1913,15 @@ 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 = sti2->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]; + FFStream *const sti2 = ffstream(st2); AVIStream *ast2 = st2->priv_data; - if (ast2->sub_ctx || st2->internal->nb_index_entries <= 0) + if (ast2->sub_ctx || sti2->nb_index_entries <= 0) continue; index = av_index_search_timestamp( @@ -1914,9 +1930,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 && sti2->index_entries[index-1].pos >= pos_min) index--; - ast2->frame_offset = st2->internal->index_entries[index].timestamp; + ast2->frame_offset = sti2->index_entries[index].timestamp; } /* do the seek */ diff --git a/libavformat/bink.c b/libavformat/bink.c index 2488aeae2f..6627a17e71 100644 --- a/libavformat/bink.c +++ b/libavformat/bink.c @@ -87,7 +87,8 @@ static int read_header(AVFormatContext *s) BinkDemuxContext *bink = s->priv_data; AVIOContext *pb = s->pb; uint32_t fps_num, fps_den; - AVStream *vst, *ast; + AVStream *const vst = avformat_new_stream(s, NULL); + FFStream *const vsti = ffstream(vst); unsigned int i; uint32_t pos, next_pos; uint16_t flags; @@ -97,7 +98,6 @@ static int read_header(AVFormatContext *s) uint32_t signature; uint8_t revision; - vst = avformat_new_stream(s, NULL); if (!vst) return AVERROR(ENOMEM); @@ -175,7 +175,7 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 4 * bink->num_audio_tracks); /* max decoded size */ for (i = 0; i < bink->num_audio_tracks; i++) { - ast = avformat_new_stream(s, NULL); + AVStream *const ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; @@ -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 (vsti->index_entries) + avio_seek(pb, vsti->index_entries[0].pos + bink->smush_size, SEEK_SET); else avio_skip(pb, 4); @@ -243,6 +243,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) if (bink->current_track < 0) { int index_entry; AVStream *st = s->streams[0]; // stream 0 is video stream with index + FFStream *const sti = ffstream(st); if (bink->video_pts >= st->duration) return AVERROR_EOF; @@ -256,8 +257,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 = sti->index_entries[index_entry].size; + bink->flags = sti->index_entries[index_entry].flags; bink->current_track = 0; } @@ -307,13 +308,14 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in { BinkDemuxContext *bink = s->priv_data; AVStream *vst = s->streams[0]; + FFStream *const vsti = ffstream(vst); int64_t ret; if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) 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, vsti->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 4df8744b79..3ff0558afe 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); } @@ -428,6 +429,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { AVStream *st = s->streams[0]; + FFStream *const sti = ffstream(st); CafContext *caf = s->priv_data; int64_t pos, packet_cnt, frame_cnt; @@ -440,10 +442,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 (sti->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 = sti->index_entries[packet_cnt].timestamp; + pos = sti->index_entries[packet_cnt].pos; } else { return -1; } diff --git a/libavformat/cinedec.c b/libavformat/cinedec.c index f1fae6e5db..c83a4c1471 100644 --- a/libavformat/cinedec.c +++ b/libavformat/cinedec.c @@ -285,13 +285,14 @@ static int cine_read_packet(AVFormatContext *avctx, AVPacket *pkt) { CineDemuxContext *cine = avctx->priv_data; AVStream *st = avctx->streams[0]; + FFStream *const sti = ffstream(st); AVIOContext *pb = avctx->pb; int n, size, ret; - if (cine->pts >= st->internal->nb_index_entries) + if (cine->pts >= sti->nb_index_entries) return AVERROR_EOF; - avio_seek(pb, st->internal->index_entries[cine->pts].pos, SEEK_SET); + avio_seek(pb, sti->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..95d1bed28c 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -603,6 +603,7 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) int64_t delta; ConcatStream *cs; AVStream *st; + FFStream *sti; if (cat->eof) return AVERROR_EOF; @@ -639,6 +640,7 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) return ret; st = cat->avf->streams[pkt->stream_index]; + sti = ffstream(st); av_log(avf, AV_LOG_DEBUG, "file:%d stream:%d pts:%s pts_time:%s dts:%s dts_time:%s", (unsigned)(cat->cur_file - cat->files), pkt->stream_index, av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base), @@ -667,8 +669,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 && sti->cur_dts != AV_NOPTS_VALUE) { + int64_t next_dts = av_rescale_q(sti->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..06bbf36c95 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -2344,10 +2344,10 @@ static int dash_check_bitstream(struct AVFormatContext *s, const AVPacket *avpkt pkt.stream_index = 0; ret = oc->oformat->check_bitstream(oc, &pkt); 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 *const sti = ffstream(s->streams[avpkt->stream_index]); + FFStream *const osti = ffstream(oc->streams[0]); + sti->bsfc = osti->bsfc; + osti->bsfc = NULL; } return ret; } diff --git a/libavformat/dhav.c b/libavformat/dhav.c index 28c476d9c1..5ae39a2a64 100644 --- a/libavformat/dhav.c +++ b/libavformat/dhav.c @@ -433,15 +433,16 @@ static int dhav_read_seek(AVFormatContext *s, int stream_index, { DHAVContext *dhav = s->priv_data; AVStream *st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); int index = av_index_search_timestamp(st, timestamp, flags); int64_t pts; if (index < 0) return -1; - if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, sti->index_entries[index].pos, SEEK_SET) < 0) return -1; - pts = st->internal->index_entries[index].timestamp; + pts = sti->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 ffa7e38561..04d3cadf1c 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -37,11 +37,10 @@ typedef struct FLACDecContext { static void reset_index_position(int64_t metadata_head_size, AVStream *st) { + FFStream *const sti = ffstream(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 < sti->nb_index_entries; i++) + sti->index_entries[i].pos += metadata_head_size; } static int flac_read_header(AVFormatContext *s) @@ -55,7 +54,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 */ @@ -287,7 +286,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); @@ -308,6 +307,8 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde } static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { + AVStream *const st = s->streams[0]; + FFStream *const sti = ffstream(st); int index; int64_t pos; AVIndexEntry e; @@ -317,11 +318,11 @@ static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in return -1; } - index = av_index_search_timestamp(s->streams[0], timestamp, flags); - if(index<0 || index >= s->streams[0]->internal->nb_index_entries) + index = av_index_search_timestamp(st, timestamp, flags); + if (index < 0 || index >= sti->nb_index_entries) return -1; - e = s->streams[0]->internal->index_entries[index]; + e = sti->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..44ed696421 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -265,10 +265,11 @@ static int flic_read_seek(AVFormatContext *s, int stream_index, { FlicDemuxContext *flic = s->priv_data; AVStream *st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); int64_t pos, ts; int index; - if (!st->internal->index_entries || stream_index != flic->video_stream_index) + if (!sti->index_entries || stream_index != flic->video_stream_index) return -1; index = av_index_search_timestamp(st, pts, flags); @@ -278,8 +279,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 = sti->index_entries[index].pos; + ts = sti->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..44a7e5f93c 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 @@ -329,6 +329,7 @@ static int flv_same_video_codec(AVCodecParameters *vpar, int flags) static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid, int read) { + FFStream *const vstreami = ffstream(vstream); int ret = 0; AVCodecParameters *par = vstream->codecpar; enum AVCodecID old_codec_id = vstream->codecpar->codec_id; @@ -363,7 +364,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; + vstreami->need_parsing = AVSTREAM_PARSE_HEADERS; ret = 3; // not 4, reading packet type will consume one byte break; case FLV_CODECID_MPEG4: @@ -375,7 +376,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 (!vstreami->need_context_update && par->codec_id != old_codec_id) { avpriv_request_sample(s, "Changing the codec id midstream"); return AVERROR_PATCHWELCOME; } @@ -815,7 +816,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 +838,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..6f370c1b57 100644 --- a/libavformat/gxf.c +++ b/libavformat/gxf.c @@ -104,12 +104,14 @@ static int gxf_probe(const AVProbeData *p) { static int get_sindex(AVFormatContext *s, int id, int format) { int i; AVStream *st = NULL; + FFStream *sti; i = ff_find_stream_index(s, id); if (i >= 0) return i; st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); + sti = ffstream(st); st->id = id; switch (format) { case 3: @@ -130,13 +132,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. + sti->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. + sti->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 9: st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; @@ -169,7 +171,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; + sti->need_parsing = AVSTREAM_PARSE_HEADERS; break; // timecode tracks: case 7: @@ -567,6 +569,7 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int uint64_t pos; uint64_t maxlen = 100 * 1024 * 1024; AVStream *st = s->streams[0]; + FFStream *const sti = ffstream(st); int64_t start_time = s->streams[stream_index]->start_time; int64_t found; int idx; @@ -575,9 +578,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 = sti->index_entries[idx].pos; + if (idx < sti->nb_index_entries - 2) + maxlen = sti->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..a603d5067e 100644 --- a/libavformat/hdsenc.c +++ b/libavformat/hdsenc.c @@ -500,15 +500,16 @@ static int hds_write_packet(AVFormatContext *s, AVPacket *pkt) { HDSContext *c = s->priv_data; AVStream *st = s->streams[pkt->stream_index]; + FFStream *const sti = ffstream(st); OutputStream *os = &c->streams[s->streams[pkt->stream_index]->id]; 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 (sti->first_dts == AV_NOPTS_VALUE) + sti->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 - sti->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..d38c3ef5a2 100644 --- a/libavformat/ifv.c +++ b/libavformat/ifv.c @@ -188,23 +188,26 @@ static int ifv_read_header(AVFormatContext *s) static int ifv_read_packet(AVFormatContext *s, AVPacket *pkt) { IFVContext *ifv = s->priv_data; - AVStream *st; AVIndexEntry *ev, *ea, *e_next; int ret; ev = ea = e_next = NULL; 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]; + AVStream *const st = s->streams[ifv->video_stream_index]; + FFStream *const sti = ffstream(st); + + if (ifv->next_video_index < sti->nb_index_entries) + e_next = ev = &sti->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]; + AVStream *const st = s->streams[ifv->audio_stream_index]; + FFStream *const sti = ffstream(st); + + if (ifv->next_audio_index < sti->nb_index_entries) { + ea = &sti->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 8625ab8258..13e0a3df30 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..8f21ea1893 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 */ @@ -162,10 +163,11 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) JVDemuxContext *jv = s->priv_data; AVIOContext *pb = s->pb; AVStream *ast = s->streams[0]; + FFStream *const asti = ffstream(ast); 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 < asti->nb_index_entries) { + const AVIndexEntry *const e = asti->index_entries + jv->pts; const JVFrame *jvf = jv->frames + jv->pts; switch (jv->state) { @@ -222,6 +224,7 @@ static int read_seek(AVFormatContext *s, int stream_index, { JVDemuxContext *jv = s->priv_data; AVStream *ast = s->streams[0]; + FFStream *const asti = ffstream(ast); int i; if (flags & (AVSEEK_FLAG_BYTE | AVSEEK_FLAG_FRAME)) @@ -238,9 +241,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 >= asti->nb_index_entries) return 0; - if (avio_seek(s->pb, ast->internal->index_entries[i].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, asti->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 b38b1b418b..500c83ac3a 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2338,7 +2338,6 @@ static int matroska_parse_tracks(AVFormatContext *s) { MatroskaDemuxContext *matroska = s->priv_data; MatroskaTrack *tracks = matroska->tracks.elem; - AVStream *st; int i, j, ret; int k; @@ -2352,6 +2351,8 @@ static int matroska_parse_tracks(AVFormatContext *s) int extradata_offset = 0; uint32_t fourcc = 0; FFIOContext b; + AVStream *st; + FFStream *sti; char* key_id_base64 = NULL; int bit_depth = -1; @@ -2486,6 +2487,7 @@ static int matroska_parse_tracks(AVFormatContext *s) av_free(key_id_base64); return AVERROR(ENOMEM); } + sti = ffstream(st); if (key_id_base64) { /* export encryption key id as base64 metadata tag */ @@ -2802,7 +2804,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; + sti->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->default_duration) { int div = track->default_duration <= INT64_MAX ? 1 : 2; @@ -2861,9 +2863,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; + sti->need_parsing = AVSTREAM_PARSE_FULL; else if (st->codecpar->codec_id != AV_CODEC_ID_AAC) - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + sti->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->codec_delay > 0) { st->codecpar->initial_padding = av_rescale_q(track->codec_delay, (AVRational){1, 1000000000}, @@ -3652,7 +3654,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; } @@ -3814,6 +3816,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. */ @@ -3822,13 +3825,15 @@ 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; @@ -3836,7 +3841,8 @@ 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; @@ -3848,17 +3854,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 @@ -3866,7 +3872,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; @@ -3902,10 +3908,12 @@ typedef struct { */ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start) { MatroskaDemuxContext *matroska = s->priv_data; + FFStream *const sti = ffstream(s->streams[0]); + AVIndexEntry *const index_entries = sti->index_entries; + int nb_index_entries = sti->nb_index_entries; 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; + 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 && @@ -3932,14 +3940,20 @@ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start) static int webm_clusters_start_with_keyframe(AVFormatContext *s) { MatroskaDemuxContext *matroska = s->priv_data; + AVStream *const st = s->streams[0]; + FFStream *const sti = ffstream(st); 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 (sti->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; + index = av_index_search_timestamp(st, 0, 0); + if (index < 0) + return 0; + cluster_pos = sti->index_entries[index].pos; before_pos = avio_tell(s->pb); while (1) { uint64_t cluster_id, cluster_length; @@ -4060,12 +4074,12 @@ static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t { MatroskaDemuxContext *matroska = s->priv_data; AVStream *st = s->streams[0]; + FFStream *const sti = ffstream(st); double bandwidth = 0.0; - int i; - for (i = 0; i < st->internal->nb_index_entries; i++) { + for (int i = 0; i < sti->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 = sti->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; @@ -4149,6 +4163,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; @@ -4184,7 +4199,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 @@ -4209,8 +4224,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..a02b190620 100644 --- a/libavformat/mlvdec.c +++ b/libavformat/mlvdec.c @@ -117,6 +117,7 @@ static void read_uint64(AVFormatContext *avctx, AVIOContext *pb, const char *tag static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int file) { + FFStream *const vsti = ffstream(vst), *const asti = ffstream(ast); MlvContext *mlv = avctx->priv_data; AVIOContext *pb = mlv->pb[file]; int ret; @@ -189,12 +190,14 @@ 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(&vsti->index_entries, &vsti->nb_index_entries, + &vsti->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(&asti->index_entries, &asti->nb_index_entries, + &asti->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) { @@ -257,6 +260,7 @@ static int read_header(AVFormatContext *avctx) MlvContext *mlv = avctx->priv_data; AVIOContext *pb = avctx->pb; AVStream *vst = NULL, *ast = NULL; + FFStream *vsti = NULL, *asti = NULL; int size, ret; unsigned nb_video_frames, nb_audio_frames; uint64_t guid; @@ -285,6 +289,8 @@ static int read_header(AVFormatContext *avctx) vst = avformat_new_stream(avctx, NULL); if (!vst) return AVERROR(ENOMEM); + vsti = ffstream(vst); + vst->id = 0; vst->nb_frames = nb_video_frames; if ((mlv->class[0] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA))) @@ -316,6 +322,7 @@ static int read_header(AVFormatContext *avctx) ast = avformat_new_stream(avctx, NULL); if (!ast) return AVERROR(ENOMEM); + asti = ffstream(ast); ast->id = 1; ast->nb_frames = nb_audio_frames; if ((mlv->class[1] & MLV_CLASS_FLAG_LZMA)) @@ -372,21 +379,21 @@ static int read_header(AVFormatContext *avctx) } if (vst) - vst->duration = vst->internal->nb_index_entries; + vst->duration = vsti->nb_index_entries; if (ast) - ast->duration = ast->internal->nb_index_entries; + ast->duration = asti->nb_index_entries; - if ((vst && !vst->internal->nb_index_entries) || (ast && !ast->internal->nb_index_entries)) { + if ((vst && !vsti->nb_index_entries) || (ast && !asti->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(vsti->index_entries[0].pos, asti->index_entries[0].pos), SEEK_SET); else if (vst) - avio_seek(pb, vst->internal->index_entries[0].pos, SEEK_SET); + avio_seek(pb, vsti->index_entries[0].pos, SEEK_SET); else if (ast) - avio_seek(pb, ast->internal->index_entries[0].pos, SEEK_SET); + avio_seek(pb, asti->index_entries[0].pos, SEEK_SET); return 0; } @@ -396,6 +403,7 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) MlvContext *mlv = avctx->priv_data; AVIOContext *pb; AVStream *st; + FFStream *sti; int index, ret; unsigned int size, space; @@ -403,6 +411,7 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) return AVERROR_EOF; st = avctx->streams[mlv->stream_index]; + sti = ffstream(st); if (mlv->pts >= st->duration) return AVERROR_EOF; @@ -412,12 +421,12 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) return AVERROR(EIO); } - pb = mlv->pb[st->internal->index_entries[index].size]; + pb = mlv->pb[sti->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, sti->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 c5583e07c7..5e1ae049cb 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1767,7 +1767,10 @@ static int mov_read_targa_y216(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_ares(MOVContext *c, AVIOContext *pb, MOVAtom atom) { if (c->fc->nb_streams >= 1) { - AVCodecParameters *par = c->fc->streams[c->fc->nb_streams-1]->codecpar; + AVStream *const st = c->fc->streams[c->fc->nb_streams - 1]; + FFStream *const sti = ffstream(st); + AVCodecParameters *par = st->codecpar; + if (par->codec_tag == MKTAG('A', 'V', 'i', 'n') && par->codec_id == AV_CODEC_ID_H264 && atom.size > 11) { @@ -1794,8 +1797,7 @@ 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; + sti->display_aspect_ratio = (AVRational){ num, den }; default: return 0; } @@ -2198,7 +2200,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; } } @@ -2368,6 +2370,8 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb, static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, AVStream *st, MOVStreamContext *sc) { + FFStream *const sti = ffstream(st); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && !st->codecpar->sample_rate && sc->time_scale > 1) st->codecpar->sample_rate = sc->time_scale; @@ -2436,10 +2440,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; + sti->need_parsing = AVSTREAM_PARSE_FULL; break; case AV_CODEC_ID_AV1: - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + sti->need_parsing = AVSTREAM_PARSE_HEADERS; break; default: break; @@ -2768,12 +2772,14 @@ static int mov_read_stps(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; + FFStream *sti; MOVStreamContext *sc; unsigned int i, entries; if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; + sti = ffstream(st); sc = st->priv_data; avio_r8(pb); /* version */ @@ -2785,8 +2791,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 (!sti->need_parsing && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + sti->need_parsing = AVSTREAM_PARSE_HEADERS; return 0; } if (sc->keyframes) @@ -3191,8 +3197,9 @@ 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; + FFStream *const sti = ffstream(st); + AVIndexEntry *e_keep = sti->index_entries; + int nb_keep = sti->nb_index_entries; int64_t i = 0; int64_t index_ctts_count; @@ -3205,8 +3212,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; + sti->index_entries = e_old; + sti->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 +3266,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; + sti->index_entries = e_keep; + sti->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 @@ -3278,29 +3285,30 @@ static int find_prev_closest_index(AVStream *st, static int64_t add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags) { + FFStream *const sti = ffstream(st); 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 = (sti->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 > sti->index_entries_allocated_size ? + FFMAX(min_size_needed, 2 * sti->index_entries_allocated_size) : min_size_needed; - if (st->internal->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry)) + if (sti->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(sti->index_entries, + &sti->index_entries_allocated_size, requested_size); if (!entries) return -1; - st->internal->index_entries= entries; + sti->index_entries = entries; - index= st->internal->nb_index_entries++; + index = sti->nb_index_entries++; ie= &entries[index]; ie->pos = pos; @@ -3318,11 +3326,12 @@ static int64_t add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, static void fix_index_entry_timestamps(AVStream* st, int end_index, int64_t end_ts, int64_t* frame_duration_buffer, int frame_duration_buffer_size) { + FFStream *const sti = ffstream(st); int i = 0; - av_assert0(end_index >= 0 && end_index <= st->internal->nb_index_entries); + av_assert0(end_index >= 0 && end_index <= sti->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; + sti->index_entries[end_index - 1 - i].timestamp = end_ts; } } @@ -3361,7 +3370,7 @@ static int64_t add_ctts_entry(MOVStts** ctts_data, unsigned int* ctts_count, uns static void mov_estimate_video_delay(MOVContext *c, AVStream* st) { MOVStreamContext *msc = st->priv_data; - int ind; + FFStream *const sti = ffstream(st); int ctts_ind = 0; int ctts_sample = 0; int64_t pts_buf[MAX_REORDER_DELAY + 1]; // Circular buffer to sort pts. @@ -3374,14 +3383,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 (int ind = 0; ind < sti->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] = sti->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 +3470,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 +3478,9 @@ 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; + FFStream *const sti = ffstream(st); + AVIndexEntry *e_old = sti->index_entries; + int nb_old = sti->nb_index_entries; const AVIndexEntry *e_old_end = e_old + nb_old; const AVIndexEntry *current = NULL; MOVStts *ctts_data_old = msc->ctts_data; @@ -3497,7 +3507,6 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) int first_non_zero_audio_edit = -1; int packet_skip_samples = 0; MOVIndexRange *current_index_range; - int i; int found_keyframe_after_edit = 0; int found_non_empty_edit = 0; @@ -3515,9 +3524,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; + sti->index_entries = NULL; + sti->index_entries_allocated_size = 0; + sti->nb_index_entries = 0; // Clean ctts fields of MOVStreamContext msc->ctts_data = NULL; @@ -3562,7 +3571,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; + sti->skip_samples = msc->start_pad = 0; } // While reordering frame index according to edit list we must handle properly @@ -3637,7 +3646,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; + sti->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 +3655,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, sti->nb_index_entries, edit_list_dts_counter, frame_duration_buffer, num_discarded_begin); av_freep(&frame_duration_buffer); } @@ -3670,7 +3679,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; + sti->skip_samples += frame_duration; } } } @@ -3685,7 +3694,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, sti->nb_index_entries, edit_list_dts_counter, frame_duration_buffer, num_discarded_begin); av_freep(&frame_duration_buffer); } @@ -3746,9 +3755,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 (int i = 0; i < sti->nb_index_entries; ++i) + sti->index_entries[i].timestamp -= msc->min_corrected_pts; } } // Start time should be equal to zero or the duration of any empty edits. @@ -3756,7 +3764,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 = sti->skip_samples; // Free the old index and the old CTTS structures av_free(e_old); @@ -3773,6 +3781,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 +3853,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 +3946,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 +3955,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 +4027,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 +4070,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 +4078,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 +4101,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 && sti->nb_index_entries > 0) { + st->start_time = sti->index_entries[0].timestamp + sc->dts_shift; if (sc->ctts_data) { st->start_time += sc->ctts_data[0].duration; } @@ -4328,7 +4337,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 +4749,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) { MOVFragment *frag = &c->fragment; AVStream *st = NULL; + FFStream *sti = NULL; MOVStreamContext *sc; MOVStts *ctts_data; uint64_t offset; @@ -4762,6 +4772,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 +4790,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 +4799,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 +4850,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 +4879,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 +4893,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 +4950,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; @@ -4972,16 +4983,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; @@ -4994,11 +5005,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, @@ -7151,15 +7162,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 = NULL; 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]; @@ -7169,15 +7180,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; @@ -7190,9 +7202,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; @@ -7261,14 +7273,15 @@ static int parse_timecode_in_framenum_format(AVFormatContext *s, AVStream *st, static int mov_read_rtmd_track(AVFormatContext *s, AVStream *st) { MOVStreamContext *sc = st->priv_data; + FFStream *const sti = ffstream(st); char buf[AV_TIMECODE_STR_SIZE]; int64_t cur_pos = avio_tell(sc->pb); int hh, mm, ss, ff, drop; - if (!st->internal->nb_index_entries) + if (!sti->nb_index_entries) return -1; - avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET); + avio_seek(sc->pb, sti->index_entries->pos, SEEK_SET); avio_skip(s->pb, 13); hh = avio_r8(s->pb); mm = avio_r8(s->pb); @@ -7286,14 +7299,15 @@ static int mov_read_rtmd_track(AVFormatContext *s, AVStream *st) static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) { MOVStreamContext *sc = st->priv_data; + FFStream *const sti = ffstream(st); int flags = 0; int64_t cur_pos = avio_tell(sc->pb); uint32_t value; - if (!st->internal->nb_index_entries) + if (!sti->nb_index_entries) return -1; - avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET); + avio_seek(sc->pb, sti->index_entries->pos, SEEK_SET); value = avio_rb32(s->pb); if (sc->tmcd_flags & 0x0001) flags |= AV_TIMECODE_FLAG_DROPFRAME; @@ -7611,11 +7625,12 @@ static int mov_read_header(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; + FFStream *const sti = ffstream(st); MOVStreamContext *sc = st->priv_data; 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; + sti->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, @@ -7634,7 +7649,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; + sti->need_parsing = AVSTREAM_PARSE_FULL; } } @@ -7751,9 +7766,10 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) int i; for (i = 0; i < s->nb_streams; i++) { AVStream *avst = s->streams[i]; + FFStream *const avsti = ffstream(avst); 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 < avsti->nb_index_entries) { + AVIndexEntry *current_sample = &avsti->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) || @@ -7935,9 +7951,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; } } @@ -7956,8 +7972,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; @@ -8025,6 +8041,7 @@ static int mov_seek_fragment(AVFormatContext *s, AVStream *st, int64_t timestamp static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, int flags) { MOVStreamContext *sc = st->priv_data; + FFStream *const sti = ffstream(st); int sample, time_sample, ret; unsigned int i; @@ -8038,7 +8055,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 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) sample = 0; if (sample < 0) /* not sure what to do */ return AVERROR_INVALIDDATA; @@ -8079,8 +8096,9 @@ 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; + FFStream *const sti = ffstream(st); + int64_t first_ts = sti->index_entries[0].timestamp; + int64_t ts = sti->index_entries[sample].timestamp; int64_t off; if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) @@ -8096,6 +8114,7 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti { MOVContext *mc = s->priv_data; AVStream *st; + FFStream *sti; int sample; int i; @@ -8103,18 +8122,20 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti return AVERROR_INVALIDDATA; st = s->streams[stream_index]; + sti = ffstream(st); sample = mov_seek_stream(s, st, sample_time, flags); if (sample < 0) return sample; 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 = sti->index_entries[sample].timestamp; + sti->skip_samples = mov_get_skip_samples(st, sample); for (i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; + FFStream *const sti = ffstream(st); int64_t timestamp; - st = s->streams[i]; if (stream_index == i) continue; @@ -8122,7 +8143,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); + sti->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 cc97131227..f617348b2e 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -160,6 +160,7 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, #define LAST_BITS(k, n) ((k) & ((1 << (n)) - 1)) #define MIDDLE_BITS(k, m, n) LAST_BITS((k) >> (m), ((n) - (m) + 1)) + FFStream *const sti = ffstream(st); uint16_t crc; uint32_t v; @@ -256,13 +257,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; + sti->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; + sti->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; + sti->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(sti->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); @@ -363,6 +364,7 @@ static int mp3_read_header(AVFormatContext *s) FFFormatContext *const si = ffformatcontext(s); MP3DecContext *mp3 = s->priv_data; AVStream *st; + FFStream *sti; int64_t off; int ret; int i; @@ -373,10 +375,11 @@ static int mp3_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); + sti = ffstream(st); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_MP3; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + sti->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->start_time = 0; // lcm of all mp3 sample rates @@ -434,8 +437,8 @@ static int mp3_read_header(AVFormatContext *s) off = avio_tell(s->pb); // 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 += off; + for (int i = 0; i < sti->nb_index_entries; i++) + sti->index_entries[i].pos += off; /* the parameters will be extracted from the compressed bitstream */ return 0; @@ -551,6 +554,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, MP3DecContext *mp3 = s->priv_data; AVIndexEntry *ie, ie1; AVStream *st = s->streams[0]; + FFStream *const sti = ffstream(st); int64_t best_pos; int fast_seek = s->flags & AVFMT_FLAG_FAST_SEEK; int64_t filesize = mp3->header_filesize; @@ -571,7 +575,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 = &sti->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..0cf46b36a0 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -324,12 +324,13 @@ static int mpc8_read_packet(AVFormatContext *s, AVPacket *pkt) static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { AVStream *st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); 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, sti->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, sti->index_entries[index].timestamp); return 0; } diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index a7874cdae8..ca15d9f241 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -478,6 +478,7 @@ static int mpegps_read_packet(AVFormatContext *s, { MpegDemuxContext *m = s->priv_data; AVStream *st; + FFStream *sti; int len, startcode, i, es_type, ret; int pcm_dvd = 0; int request_probe= 0; @@ -614,6 +615,7 @@ skip: st = avformat_new_stream(s, NULL); if (!st) goto skip; + sti = ffstream(st); st->id = startcode; st->codecpar->codec_type = type; st->codecpar->codec_id = codec_id; @@ -623,8 +625,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; + sti->request_probe = request_probe; + sti->need_parsing = AVSTREAM_PARSE_FULL; found: if (st->discard >= AVDISCARD_ALL) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 9662ef1e61..ed918cb356 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -875,15 +875,16 @@ static void mpegts_find_stream_type(AVStream *st, uint32_t stream_type, const StreamType *types) { + FFStream *const sti = ffstream(st); for (; types->stream_type; types++) if (stream_type == types->stream_type) { if (st->codecpar->codec_type != types->codec_type || 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; + sti->need_context_update = 1; } - st->internal->request_probe = 0; + sti->request_probe = 0; return; } } @@ -891,11 +892,12 @@ static void mpegts_find_stream_type(AVStream *st, static int mpegts_set_stream_info(AVStream *st, PESContext *pes, uint32_t stream_type, uint32_t prog_reg_desc) { + FFStream *const sti = ffstream(st); int old_codec_type = st->codecpar->codec_type; 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(sti->avctx)) { av_log(pes->stream, AV_LOG_DEBUG, "cannot set stream info, internal codec is open\n"); return 0; } @@ -904,7 +906,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; + sti->need_parsing = AVSTREAM_PARSE_FULL; pes->st = st; pes->stream_type = stream_type; @@ -916,7 +918,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; + sti->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 +944,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 +955,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 && + (sti->request_probe > 0 && sti->request_probe < AVPROBE_SCORE_STREAM_RETRY / 5)) && + sti->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; + sti->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; + sti->need_context_update = 1; return 0; } @@ -1198,13 +1200,14 @@ static int mpegts_push_data(MpegTSFilter *filter, code != 0x1f0 && code != 0x1f1 && /* ECM, EMM */ code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */ code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */ + FFStream *const pes_sti = ffstream(pes->st); 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 && !pes_sti->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; + pes_sti->request_probe = 1; } } else { pes->pes_header_size = 6; @@ -1326,8 +1329,11 @@ 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; + const FFStream *const sti = ffstream(st); + FFStream *const pes_sti = ffstream(pes->st); + + pes_sti->pts_wrap_reference = sti->pts_wrap_reference; + pes_sti->pts_wrap_behavior = sti->pts_wrap_behavior; } if (pes->dts == AV_NOPTS_VALUE || pes->dts < pcr) { pes->pts = pes->dts = pcr; @@ -1699,6 +1705,7 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, for (i = 0; i < mp4_descr_count; i++) { PESContext *pes; AVStream *st; + FFStream *sti; FFIOContext pb; if (ts->pids[pid]->es_id != mp4_descr[i].es_id) continue; @@ -1710,6 +1717,7 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, st = pes->st; if (!st) continue; + sti = ffstream(st); pes->sl = mp4_descr[i].sl; @@ -1719,13 +1727,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; + sti->need_parsing = 0; if (st->codecpar->codec_id == AV_CODEC_ID_H264 && st->codecpar->extradata_size > 0) - st->internal->need_parsing = 0; + sti->need_parsing = 0; st->codecpar->codec_type = avcodec_get_type(st->codecpar->codec_id); - st->internal->need_context_update = 1; + sti->need_context_update = 1; } } for (i = 0; i < mp4_descr_count; i++) @@ -1785,6 +1793,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type Mp4Descr *mp4_descr, int mp4_descr_count, int pid, MpegTSContext *ts) { + FFStream *const sti = ffstream(st); const uint8_t *desc_end; int desc_len, desc_tag, desc_es_id, ext_desc_tag, channels, channel_config_code; char language[252]; @@ -1802,7 +1811,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 || sti->request_probe > 0) && stream_type == STREAM_TYPE_PRIVATE_DATA) mpegts_find_stream_type(st, desc_tag, DESC_types); @@ -1828,8 +1837,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; + sti->need_parsing = 0; + sti->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 +1849,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) && + (sti->request_probe == 0 && st->codecpar->codec_id == AV_CODEC_ID_NONE) || + sti->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 +1859,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; + sti->request_probe = sti->need_parsing = 0; st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; - st->internal->need_context_update = 1; + sti->need_context_update = 1; } } break; @@ -1893,7 +1902,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; + sti->need_context_update = 1; } } break; @@ -1957,7 +1966,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; + sti->need_context_update = 1; } } break; @@ -1990,14 +1999,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 || sti->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; + sti->request_probe = 50; } break; case 0x52: /* stream identifier descriptor */ - st->internal->stream_identifier = 1 + get8(pp, desc_end); + sti->stream_identifier = 1 + get8(pp, desc_end); break; case METADATA_DESCRIPTOR: if (get16(pp, desc_end) == 0xFFFF) @@ -2037,8 +2046,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; + sti->need_parsing = AVSTREAM_PARSE_FULL; + sti->need_context_update = 1; } } if (ext_desc_tag == 0x06) { /* supplementary audio descriptor */ @@ -2116,7 +2125,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 = sti->stream_identifier - 1; int picked_profile = FF_PROFILE_UNKNOWN; int data_component_id = get16(pp, desc_end); if (data_component_id < 0) @@ -2148,7 +2157,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; + sti->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 c9a1aadbc8..82cd634b7e 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -253,7 +253,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) 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); AVCodecParameters *const par = st->codecpar; const AVCodecDescriptor *desc; @@ -386,7 +386,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) { @@ -509,7 +509,7 @@ FF_DISABLE_DEPRECATION_WARNINGS static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { FFFormatContext *const si = ffformatcontext(s); - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int delay = st->codecpar->video_delay; int frame_size; @@ -645,7 +645,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) { FFFormatContext *const si = ffformatcontext(s); AVStream *const st = s->streams[pkt->stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int ret; // If the timestamp offsetting below is adjusted, adjust @@ -743,7 +743,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)) { @@ -799,7 +799,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)); @@ -912,7 +912,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, for (unsigned i = 0; i < s->nb_streams; i++) { const AVStream *const st = s->streams[i]; - const AVStreamInternal *const sti = st->internal; + const FFStream *const sti = cffstream(st); const AVCodecParameters *const par = st->codecpar; if (sti->last_in_packet_buffer) { ++stream_count; @@ -939,7 +939,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, for (unsigned i = 0; i < s->nb_streams; i++) { const AVStream *const st = s->streams[i]; - const AVStreamInternal *const sti = st->internal; + const FFStream *const sti = cffstream(st); const PacketList *last = sti->last_in_packet_buffer; int64_t last_dts; @@ -977,7 +977,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); @@ -1000,7 +1000,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; @@ -1026,7 +1026,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); @@ -1064,7 +1064,7 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in return ff_interleave_packet_per_dts(s, out, in, flush); } -static int check_bitstream(AVFormatContext *s, AVStreamInternal *sti, AVPacket *pkt) +static int check_bitstream(AVFormatContext *s, FFStream *sti, AVPacket *pkt) { int ret; @@ -1128,7 +1128,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) { - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); AVBSFContext *const bsfc = sti->bsfc; int ret; @@ -1162,12 +1162,12 @@ static int write_packets_from_bsfs(AVFormatContext *s, AVStream *st, AVPacket *p static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleaved) { AVStream *st; - AVStreamInternal *sti; + FFStream *sti; int ret = check_packet(s, pkt); if (ret < 0) return ret; st = s->streams[pkt->stream_index]; - sti = st->internal; + sti = ffstream(st); ret = prepare_input_packet(s, st, pkt); if (ret < 0) @@ -1256,7 +1256,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); @@ -1286,7 +1286,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..2aaa4e4575 100644 --- a/libavformat/mvdec.c +++ b/libavformat/mvdec.c @@ -435,13 +435,14 @@ static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt) MvContext *mv = avctx->priv_data; AVIOContext *pb = avctx->pb; AVStream *st = avctx->streams[mv->stream_index]; + FFStream *const sti = ffstream(st); const AVIndexEntry *index; int frame = mv->frame[mv->stream_index]; int64_t ret; uint64_t pos; - if (frame < st->internal->nb_index_entries) { - index = &st->internal->index_entries[frame]; + if (frame < sti->nb_index_entries) { + index = &sti->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..469ddf4f47 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++) { @@ -2324,6 +2324,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) const MXFCodecUL *container_ul = NULL; const MXFCodecUL *pix_fmt_ul = NULL; AVStream *st; + FFStream *sti; AVTimecode tc; int flags; @@ -2431,6 +2432,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) ret = AVERROR(ENOMEM); goto fail_and_free; } + sti = ffstream(st); st->id = material_track->track_id; st->priv_data = source_track; @@ -2616,7 +2618,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } } } - st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; + sti->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 +2626,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; + sti->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 +2683,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; + sti->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 +2717,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; + sti->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; } } @@ -3676,7 +3678,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..27471125ff 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); } @@ -669,6 +669,7 @@ static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp { NSVContext *nsv = s->priv_data; AVStream *st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); NSVStream *nst = st->priv_data; int index; @@ -676,10 +677,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, sti->index_entries[index].pos, SEEK_SET) < 0) return -1; - nst->frame_offset = st->internal->index_entries[index].timestamp; + nst->frame_offset = sti->index_entries[index].timestamp; nsv->state = NSV_UNSYNC; return 0; } diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index 50f8b64d10..0a8a700acf 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) || @@ -1225,6 +1225,7 @@ static int read_seek(AVFormatContext *s, int stream_index, { NUTContext *nut = s->priv_data; AVStream *st = s->streams[stream_index]; + FFStream *const sti = ffstream(st); Syncpoint dummy = { .ts = pts * av_q2d(st->time_base) * AV_TIME_BASE }; Syncpoint nopts_sp = { .ts = AV_NOPTS_VALUE, .back_ptr = AV_NOPTS_VALUE }; Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp }; @@ -1235,15 +1236,15 @@ static int read_seek(AVFormatContext *s, int stream_index, return AVERROR(ENOSYS); } - if (st->internal->index_entries) { + if (sti->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 = sti->index_entries[index].pos; + ts = sti->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..f777790523 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -39,6 +39,7 @@ ogm_header(AVFormatContext *s, int idx) struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; AVStream *st = s->streams[idx]; + FFStream *const sti = ffstream(st); GetByteContext p; uint64_t time_unit; uint64_t spu; @@ -60,7 +61,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; + sti->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 +77,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; + sti->need_parsing = AVSTREAM_PARSE_FULL; } size = bytestream2_get_le32(&p); @@ -116,7 +117,7 @@ ogm_header(AVFormatContext *s, int idx) } // Update internal avctx with changes to codecpar above. - st->internal->need_context_update = 1; + sti->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 b7e5a2d966..15e26c03bd 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 */ @@ -70,6 +70,7 @@ int ff_raw_audio_read_header(AVFormatContext *s) int ff_raw_video_read_header(AVFormatContext *s) { AVStream *st; + FFStream *sti; FFRawVideoDemuxerContext *s1 = s->priv_data; int ret = 0; @@ -79,12 +80,13 @@ int ff_raw_video_read_header(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } + sti = ffstream(st); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = s->iformat->raw_codec_id; - st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; + sti->need_parsing = AVSTREAM_PARSE_FULL_RAW; - st->internal->avctx->framerate = s1->framerate; + sti->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..93899a2139 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -122,6 +122,7 @@ void ff_rm_free_rmstream (RMStream *rms) static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, AVStream *st, RMStream *ast, int read_all) { + FFStream *const sti = ffstream(st); char buf[256]; uint32_t version; int ret; @@ -202,7 +203,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; + sti->need_parsing = AVSTREAM_PARSE_FULL; break; case AV_CODEC_ID_RA_288: st->codecpar->extradata_size= 0; @@ -211,7 +212,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; + sti->need_parsing = AVSTREAM_PARSE_HEADERS; case AV_CODEC_ID_ATRAC3: case AV_CODEC_ID_SIPR: if (read_all) { @@ -235,7 +236,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; + sti->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 +389,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..459791ffd3 100644 --- a/libavformat/rpl.c +++ b/libavformat/rpl.c @@ -311,6 +311,7 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) RPLContext *rpl = s->priv_data; AVIOContext *pb = s->pb; AVStream* stream; + FFStream *sti; AVIndexEntry* index_entry; int ret; @@ -320,11 +321,12 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) } stream = s->streams[rpl->chunk_part]; + sti = ffstream(stream); - if (rpl->chunk_number >= stream->internal->nb_index_entries) + if (rpl->chunk_number >= sti->nb_index_entries) return AVERROR_EOF; - index_entry = &stream->internal->index_entries[rpl->chunk_number]; + index_entry = &sti->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..f6e9968ef1 100644 --- a/libavformat/sbgdec.c +++ b/libavformat/sbgdec.c @@ -1403,6 +1403,7 @@ static av_cold int sbg_read_header(AVFormatContext *avf) char *buf = NULL; struct sbg_script script = { 0 }; AVStream *st; + FFStream *sti; struct ws_intervals inter = { 0 }; r = read_whole_file(avf->pb, sbg->max_file_size, &buf); @@ -1436,6 +1437,7 @@ static av_cold int sbg_read_header(AVFormatContext *avf) st = avformat_new_stream(avf, NULL); if (!st) return AVERROR(ENOMEM); + sti = ffstream(st); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_FFWAVESYNTH; st->codecpar->channels = 2; @@ -1443,13 +1445,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; + sti->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; + sti->cur_dts = st->start_time; r = encode_intervals(&script, st->codecpar, &inter); if (r < 0) goto fail; @@ -1470,7 +1472,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 +1495,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 7c171b6fa4..2b024fd373 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -991,10 +991,10 @@ static int seg_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) if (oc->oformat->check_bitstream) { int ret = oc->oformat->check_bitstream(oc, 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 *const sti = ffstream( s->streams[pkt->stream_index]); + FFStream *const osti = ffstream(oc->streams[pkt->stream_index]); + sti->bsfc = osti->bsfc; + osti->bsfc = NULL; } return ret; } diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c index 65ef942367..36330b17b6 100644 --- a/libavformat/smoothstreamingenc.c +++ b/libavformat/smoothstreamingenc.c @@ -582,15 +582,16 @@ static int ism_write_packet(AVFormatContext *s, AVPacket *pkt) { SmoothStreamingContext *c = s->priv_data; AVStream *st = s->streams[pkt->stream_index]; + FFStream *const sti = ffstream(st); OutputStream *os = &c->streams[pkt->stream_index]; 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 (sti->first_dts == AV_NOPTS_VALUE) + sti->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 - sti->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..31197349b0 100644 --- a/libavformat/tedcaptionsdec.c +++ b/libavformat/tedcaptionsdec.c @@ -277,12 +277,14 @@ static av_cold int tedcaptions_read_header(AVFormatContext *avf) { TEDCaptionsDemuxer *tc = avf->priv_data; AVStream *st = avformat_new_stream(avf, NULL); + FFStream *sti; int ret, i; AVPacket *last; if (!st) return AVERROR(ENOMEM); + sti = ffstream(st); ret = parse_file(avf->pb, &tc->subs); if (ret < 0) { if (ret == AVERROR_INVALIDDATA) @@ -298,10 +300,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; + sti->probe_packets = 0; st->start_time = 0; st->duration = last->pts + last->duration; - st->internal->cur_dts = 0; + sti->cur_dts = 0; return 0; } diff --git a/libavformat/tta.c b/libavformat/tta.c index e1f9cf27d8..6de8c620a6 100644 --- a/libavformat/tta.c +++ b/libavformat/tta.c @@ -151,21 +151,22 @@ static int tta_read_packet(AVFormatContext *s, AVPacket *pkt) { TTAContext *c = s->priv_data; AVStream *st = s->streams[0]; + FFStream *const sti = ffstream(st); int size, ret; // FIXME! if (c->currentframe >= c->totalframes) return AVERROR_EOF; - if (st->internal->nb_index_entries < c->totalframes) { + if (sti->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 = sti->index_entries[c->currentframe].size; ret = av_get_packet(s->pb, pkt, size); - pkt->dts = st->internal->index_entries[c->currentframe++].timestamp; + pkt->dts = sti->index_entries[c->currentframe++].timestamp; pkt->duration = c->currentframe == c->totalframes ? c->last_frame_size : c->frame_size; return ret; @@ -178,7 +179,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 90c15b01f2..9c174425d3 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) @@ -140,7 +140,7 @@ void av_format_inject_global_side_data(AVFormatContext *s) si->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; } } @@ -312,9 +312,9 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, }; int score; const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); + FFStream *const sti = ffstream(st); 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 - sti->probe_packets, @@ -436,7 +436,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; @@ -633,7 +633,7 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { FFFormatContext *const si = ffformatcontext(s); - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); if (sti->request_probe > 0) { AVProbeData *pd = &sti->probe_data; @@ -685,7 +685,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; @@ -708,10 +708,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; @@ -739,7 +739,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; } @@ -771,7 +771,7 @@ FF_ENABLE_DEPRECATION_WARNINGS for (;;) { PacketList *pktl = si->raw_packet_buffer; - AVStreamInternal *sti; + FFStream *sti; const AVPacket *pkt1; if (pktl) { @@ -779,7 +779,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; @@ -800,7 +800,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; @@ -831,7 +831,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 @@ -893,7 +893,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; @@ -958,7 +958,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; @@ -986,7 +986,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; @@ -1035,7 +1035,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]; @@ -1061,7 +1061,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; @@ -1115,7 +1115,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; @@ -1175,7 +1175,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, int64_t next_dts, int64_t next_pts) { FFFormatContext *const si = ffformatcontext(s); - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int num, den, presentation_delayed, delay; int64_t offset; AVRational duration; @@ -1369,7 +1369,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; @@ -1487,7 +1487,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); @@ -1497,7 +1497,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 => @@ -1506,7 +1507,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; @@ -1602,7 +1603,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); @@ -1792,6 +1793,7 @@ int av_find_default_stream_index(AVFormatContext *s) return -1; for (unsigned i = 0; i < s->nb_streams; i++) { const AVStream *const st = s->streams[i]; + const FFStream *const sti = cffstream(st); int score = 0; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) @@ -1804,7 +1806,7 @@ int av_find_default_stream_index(AVFormatContext *s) if (st->codecpar->sample_rate) score += 50; } - if (st->internal->codec_info_nb_frames) + if (sti->codec_info_nb_frames) score += 12; if (st->discard != AVDISCARD_ALL) @@ -1828,7 +1830,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); @@ -1858,8 +1860,9 @@ 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]; + FFStream *const sti = ffstream(st); - st->internal->cur_dts = + sti->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); @@ -1869,7 +1872,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) { @@ -1942,7 +1945,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, @@ -2014,10 +2017,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; @@ -2061,19 +2064,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; @@ -2084,7 +2087,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); @@ -2113,7 +2116,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; @@ -2125,7 +2128,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; @@ -2345,7 +2348,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, { FFFormatContext *const si = ffformatcontext(s); AVStream *const st = s->streams[stream_index]; - AVStreamInternal *const sti = st->internal; + FFStream *const sti = ffstream(st); int index; int64_t ret; AVIndexEntry *ie; @@ -2687,7 +2690,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) { @@ -2749,7 +2752,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 && @@ -2782,7 +2785,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; @@ -2793,7 +2796,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)) { @@ -2844,12 +2847,13 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) /* 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]; + const FFStream *const sti = cffstream(st); 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 || st->internal->first_dts != AV_NOPTS_VALUE) { + if (st->start_time != AV_NOPTS_VALUE || sti->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); @@ -2862,7 +2866,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; @@ -2935,7 +2939,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 { \ @@ -2985,7 +2989,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; @@ -3313,7 +3317,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 @@ -3375,7 +3379,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; @@ -3455,7 +3459,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; @@ -3494,7 +3498,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; @@ -3597,7 +3601,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 || @@ -3661,7 +3665,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; @@ -3674,7 +3678,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; @@ -3736,8 +3740,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) "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]; + FFStream *const sti = ffstream(st); if (!st->r_frame_rate.num && - st->internal->info->duration_count <= 1 && + sti->info->duration_count <= 1 && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && strcmp(ic->iformat->name, "image2")) av_log(ic, AV_LOG_WARNING, @@ -3772,7 +3777,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; @@ -3898,7 +3903,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) { @@ -3927,9 +3932,10 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *const st = ic->streams[i]; + FFStream *const sti = ffstream(st); /* flush the decoders */ - if (st->internal->info->found_decoder == 1) { + if (sti->info->found_decoder == 1) { do { err = try_decode_frame(ic, st, empty_pkt, (options && i < orig_nb_streams) @@ -3948,7 +3954,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) { @@ -4050,7 +4056,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 */ @@ -4081,7 +4087,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); @@ -4098,7 +4104,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); @@ -4173,7 +4179,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) || @@ -4271,7 +4277,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; @@ -4283,8 +4289,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); @@ -4298,8 +4302,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); @@ -4390,8 +4392,8 @@ void avformat_close_input(AVFormatContext **ps) AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) { FFFormatContext *const si = ffformatcontext(s); + FFStream *sti; AVStream *st; - AVStreamInternal *sti; AVStream **streams; if (s->nb_streams >= s->max_streams) { @@ -4405,13 +4407,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) @@ -4814,6 +4814,7 @@ int ff_hex_to_data(uint8_t *data, const char *p) void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den) { + FFStream *const sti = ffstream(s); AVRational new_tb; if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) { if (new_tb.num != pts_num) @@ -4832,7 +4833,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; + sti->avctx->pkt_timebase = new_tb; s->pts_wrap_bits = pts_wrap_bits; } @@ -5005,7 +5006,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; @@ -5407,9 +5408,10 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a { int ret; const AVBitStreamFilter *bsf; + FFStream *const sti = ffstream(st); AVBSFContext *bsfc; - av_assert0(!st->internal->bsfc); + av_assert0(!sti->bsfc); if (!(bsf = av_bsf_get_by_name(name))) { av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name); @@ -5443,7 +5445,7 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a return ret; } - st->internal->bsfc = bsfc; + sti->bsfc = bsfc; av_log(NULL, AV_LOG_VERBOSE, "Automatically inserted bitstream filter '%s'; args='%s'\n", @@ -5550,8 +5552,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; /* @@ -5607,7 +5609,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 Thu Sep 9 15:57:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30097 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp649337iov; Thu, 9 Sep 2021 08:59:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdke368BZW5oOFJ6ZdVcFpieA95dOKITCHoO7EU7j8FmrwBmr4EEAp5fMFk0t+ADHggMaE X-Received: by 2002:a1c:1b48:: with SMTP id b69mr3748683wmb.14.1631203155883; Thu, 09 Sep 2021 08:59:15 -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 ec31si2227249edb.235.2021.09.09.08.59.15; Thu, 09 Sep 2021 08:59:15 -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="PBxZv/rz"; 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 05C6A68AA09; Thu, 9 Sep 2021 18:58:29 +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 52B4D68A998 for ; Thu, 9 Sep 2021 18:58:25 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BQo/FwckiqlRUSNALuTF55Pmd4LzoC49VZk5cHztu90kuMqC0WjMnPnrMDKquo1TvIBCUCzhlmKCOgYp39lhOXPZcuuWVfjGsOGFOFcZXHM2o3BVD/W5rwa7oGI2VWOt8eCvKf92gqIj8knQaMiTayhOXz2ps42VQ+cpHHQBAZvThLhWcRwI9m4vi2uA+6wJ68kE10a8FZwyUYIkimD2v1UR4fZ/ix3A+uJzVqOGXFbSmvX8wP5jxwIHh6Fpgo0vsA8ZAkuJu8baMJZOqca73TB/KKaRcgdi1Jj+9ZPVyK1svJmjcj6fW90pPz/2uIf8Xqv9vK7Fa7hD6SlpGZyuXw== 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; bh=jJvZE0Haf3avty22Md1AIKgwNdvQt6yLjIIn0xfBdtc=; b=nvLxIehBS4u+BDuziDDgIuvMwxmQIfFmug4UlyLQiHLGnE96gEMzIcC/4WxXbfzokNbJTmCAgJ3n7QL9zgDT8Ka3PPhs5BXkRcTH5fn5hLZZ/LlNUxNc4Mx0439M9SH5iZ2Eowqh/sABV4r3rGH3UKxLjH530/NqpteGC+cMqLxYhIM9AIzWbDFT5tRWvrJLNYX9pqGbP93zzzCVYL97z1IAPMJNovJo0jLtJhgBn92oNPr3Ie0lqAuWXeLvjhqbutLDQbX4XERRyd+IsaswKD4nrRM5pqi9hDrg4eAwM9m1d8glSveZSWySAL2rd0WCidGov7Y2BWH46Df8turrFg== 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=jJvZE0Haf3avty22Md1AIKgwNdvQt6yLjIIn0xfBdtc=; b=PBxZv/rz4n2WBJ0lXrqsEiGzF2R0Zkn4SwraaBHgGmxkSbUddLxsIkv/kkSwie6yVzO7sbDUSZJ26+6+BU/VUYc6yROv18QawKNlyObXom0eltd8y+IJoFHZWRaZ/CviH5BrnMq8fNY85AJNXPsdHMK/lyjQfOU53XyzYFnfFN9Zey2F6DPkdjcj5jXt1EVuDSnpS4c95TYBuFjR3RKjVXVHEXj5WID6w0iEEohLD07vUXPfSRiwepiLACbwhz9/PPkvn1zWOdrbaLrDTFkBOstpxqHVPmB3R1VwuI0HSmlRRNFSsRYZeKTI/xGKtHbpZjJHYmXRz47hnPjEeyPATA== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:17 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:17 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:42 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [nMDkSBAk/b4WHG56T3aZ4wWX7gQfjNP2] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-8-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 736cd8bc-bf4d-40e1-7c43-08d973aaa390 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXImq1sWRAABPXhZ8q25ZjYGYhBLHVx78Lt4u6XkPLuDlvru0zHeDKkmT/RBnw0essZvkjWoGktVKeGp4nwG9efibDS4gp6KIQeV/7p1yVoHrkvdzJomp9i7bfFxBOHGOM6/vJwK00l+Vof50VYOMKLiuTJXxSYuwYMVR1y9Vn7fA1dARQMkRZ5yukcz3Lsw9FdKF5lSulGL+uI95DgeJu97ULS/1TbXkO7tEjUikodIcyxNWz/G6t1VIn4DP9S+naoc2mtBlsTfnZfHS3bL/LXitBVjDZpFz9B6yo8e8WD4q2Pah03h1Stng+U6qrUAsBcFIav1Juu8lWIaPeD7YRXjhKmaVwq1MGXNyW45JQrU6bozfRtxGk0w5kgtzekOmha8iOoS1BDwOrCK0z8lDEV6y9QE2W8PpMD1dCsSXSTShAf/iwurDm4VbQx2JFrFvaEQI3G2dbJQPoklVJEAO97fW/1cA39sMpSOj5ypjk2yRhs4HjLknKsi+qhqrfu9RevrpQTFJjBQUZvUkRk1m26yyqmbadaxMpdVgXvPEIqf7UOjXPj/2p/WRKcYMzfvyPuV/2LOOhdSaMrDCpBTfyR8GmuKRYT4rJD9t7IDlpk4AkslbIdXdyZFx8WQq3HO4ESTgzKt/qIGpaX4lv3C/OlYW1V6HztNzMZq9Rm43x9/9dqh5OZahmbWeLjW1Skec2g2JlKrkivIUbWiToz74bU16owlWxN5jY= X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6IRuRVoYXwaGqZzZMpG/UQh5jd76e5GiY0NYFZTBtPS+8QJIgjlXlQmRfeof9mwIMlfzMJBYnT9yc0pP6R/LwHfliJK6lOP+RJO7s2barGDn2CkpsZ6mpKxL0/zxpakw5qmUhVYIfixFrLMO739HBKLn1L7+KpuQv10JaY3bEwj67zyVpeD0EGg7AAwE5czscFiMxL7ByY9/kRIDvORBHPXt6O11OGAmdQ+ZwdXcYxIvRhUFaTuQ0uZoGNKPhJ7nPqEArCbzGYEMKiWPZXtbZ3oGtTiYuRNh2AcXNk5LODzuYbpF+0zQm4xZ1tor/tdey+xHKxnR4OqRT9ln9+joyiy+lhZcqU3feUwj+hWklFCV3HjGjQVNECJsEuKSEfBPS6UytY6/JcXIX79HNhVjPID+G9zZUAfz9plcaqqjiHT5xau+55QyVqEsZM/3ayNd X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: beBSP4z6+HWJDzw97te6niK4s8IfOxI1teIT8891G8+vsPyj7oZ9Z1bjrb3Iit9T4r0YjiVnpuBj9uJw9gKVe9z5O9bEz93TgrCsJLQ4kEOyNHVTzmbST9sy24a6rQPw8pLdaV5+FYvqkyGrb3Ei6w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 736cd8bc-bf4d-40e1-7c43-08d973aaa390 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:17.7546 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 09/14] 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: m0xhh2tlZ0YH 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 9c174425d3..25285f62ab 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4289,19 +4289,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 Thu Sep 9 15:57:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30100 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp649526iov; Thu, 9 Sep 2021 08:59:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmpWF2gsxg57ykM2U7c6xSxeYPXbkNKNCh+NayxNC2evsB3RK55pS3+M8qj5kmwgo3HgcT X-Received: by 2002:aa7:db10:: with SMTP id t16mr3848004eds.357.1631203167970; Thu, 09 Sep 2021 08:59: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 d23si905188eds.175.2021.09.09.08.59.27; Thu, 09 Sep 2021 08:59: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=HhVOyLhL; 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 1C5F468A9AD; Thu, 9 Sep 2021 18:58:30 +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 7713B68A9AD for ; Thu, 9 Sep 2021 18:58:25 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XSNq+38uwSjcHtG2mCjhs/WMF5DFA9YsHWLACdbWnRQvf1z1yc06NwITE8el6B0EYz5GSwcxUnK2PqIr1igNuDwFXm2dDiqqNha+U5x5tHSJkR2k54j51jWRhFa7USNlNx1te6Ehi6TWHGLFEGVbF07eHzN6jFME1XzHY0s45h8bVc2KTmAueVday6OndD3XLIsSf4y9Z8GZmGIOWPqQsLGhlh01DXa8wWcjZLCgKd76SxlV6KRE+Ul+KlKG7WvV8JtmGC8J5f8G75k29QnNTDZWmAKc1gbuqwQKZTmUXH3sr8GhUY9vkN/tqBqdI7GbdkGTy3JHF9T1/u/9ctlOjA== 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; bh=zh6vTsjor8AMzaPFNrV5QsU2OBakNDBRFIi3u6qmO3g=; b=nwl4vX8x9qsVye6ezaT2iJVpkNtL3XfZm1KW6ERRMKlD6Tm4qc/v0ICpFFg2CKswH90Y+WnOL25PmyH4ftZVX4FkRfWqDFG1Ru0AcTRZYcE7xhAa5VDs9lvFW7rtuoeTULV9ng5X4329rA6GKu/76vVi/GskuUV+Sygxp0Zka1eu6f6AGJ6fC/e7zxcPMuO4IqB1vT/q//EXxlAZJ63T4iVW8TxP+PsHz6gqD1CvcXb7QjgnUFa1rD2agR+Lg59sMddPnPC/B/Htn7JZgnF2W42/SJ6v2QqkPZKwvhPL3RGt6q6s4CgLYcH5ytH9CmaehOlW0g8Jxa0nXl6GueNTxA== 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=zh6vTsjor8AMzaPFNrV5QsU2OBakNDBRFIi3u6qmO3g=; b=HhVOyLhLtyEkkwKno5MY8KoCuOzeSbQ1ddppLRL5w0m2fZjFahBZGjc8QszIyP7+ZjWHGVCxPbuD3f4/O/QcU/3NSqwEIsj7UQ3b4Hecf6/bN44TXiwoA34Pkk5gbQndiCUbaFK+ms+G+dWOzdlTc+5znf9j0h9SKzDYrPrrogltlZNJQYzrwHXCzFUqKDtj8q7BwZpFCoa42y83HnaF0aG7sepKUOOrtO7f467cY27blLEdh5kCzEyGqotIkfc5hf0D9AjdQCNRfErmlnwZuohNqGFb8R0tGwUQBkiebCAfhfkRekGUFcxz83J9QkGINsu4wgnq9YL7cuVOJsfOgg== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:18 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:18 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:43 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [HITmtyanXhAWxa4zSaLbOQqXRKkDpluF] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-9-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d925d563-36f4-4c50-4142-08d973aaa3d9 X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UI4W5gxJ7aMBRY067gw8CzBesLKswGHgoJxSBOa5kpK7hAA55EYyimsz3YcT4Fp+6HtuNCDd3ojhhX3BhomfJwkIh8H+FD4dlSfSf+eQAIXQcubOxTWjwO8Xnzn0zxr6QFq5pjDyGcuorNOLBN4+pKu/x5BfYWDDGGU5zowUTXUjMf4SzFROsS7uE+T6Zc/LVmPTiGMPF5T3DhX4tNi0CMwKzUM7NpzC9QBlDuxaVmgKJf8WdfgKEv935wROEPkjO5guW4dGF7oCJKtJbCdFYLVpLLtdgZsuAPRj3iCVZlgaOsG4nNz2fYP/stnX/whUioNahduWbuT1YYPvfnQJW/dUW88nlCNMzizgaULjmLvVKjcSSVWB15wLPM8NaXAGgxXNBKIPsge+0x/D/yLirqbiiUqUrTYu4Dnjv6fUjMXUjCpTQZmyolkn9cvz/dJlC3RO0GQ46ebh38YikU6ghI3/4hmDNXZhRT2zkOSb6bhYal8v3S/YO6plbV4gvPLn1bfO9HKSJm1+DS2+W/0gBndc7VW7gNaqMLVF0QS4PN20tZQcZ2sfr7lwGyAoWMJbB/CjKizX7NXaFgiL8SfB1+cWw0ZHau76czOlheYag1jryTlEJ97aDwFvKTKVbdBcCcs2G2//gjNGJhOwjOuFvoCChCT4CCGW2xo3NBFXcsn0UlhewQt2oFMSjCH9wLlIDHgJoP4JQmELw== X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9PzQRjTRoAHlEb05cx9mGfEMulpuC5dToYyDkmOY/PI5SDuf6WYZmS2fhUp2J3/DP2pZd9G2cCzrUcqi234fXEvvGhDXh31OeD6eZmi8naGpKJl1S3qt6N9Slh0LNFUlCN57jDWvfMLrjPFVvKesrdYxLccsTtY75Ne1HA3nNUOs1dtWqzdMSBXH2DZ+lnQZjkS2d/t8JVfQgMY2Q9mB7ipbK52pLbOOKjAHcaluzowFI0WBuY6eTKX1m1peb23cSQ90/rQj1QhXWl2butf56JNUZer7rIW70Nr23v2hVP0DsYrd/Ox3GWeUrbCdaISrMFHiBcRNdbjdkGOw6cEIpVgz+qQNZjBdFeUhbgOnd8Ecom4YQgV2SHzcuvuOmZwwmFzZ91TR4zHZATc2nqRsDttLBT2dGj+mewtjAORO70RR7Xl/se+2dJ/q/BNYMjr1 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9tniYKJHfCNnzzQpET1r6sKxTvZLXa6QYYOMSxVuKPY+tVd+6HKdMo59VcFx8Tt50fDLf50vkSs5huoNbZLzctvMxpsB+43DGx+khEzvnIGzt/CqWF0ozHKMmgSUV3p1VL8KZHcMkcFE5s0ZL2ECJw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d925d563-36f4-4c50-4142-08d973aaa3d9 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:18.7303 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 10/14] 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: PTKCjINRuQ1q 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 | 754 +++++++++++++++++++++++++++++++++++++++++ libavformat/utils.c | 752 +--------------------------------------- 4 files changed, 781 insertions(+), 744 deletions(-) create mode 100644 libavformat/seek.c diff --git a/libavformat/Makefile b/libavformat/Makefile index f7e47563da..f67d261402 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 13e0a3df30..d0b9d6200a 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..a9262cfa0a --- /dev/null +++ b/libavformat/seek.c @@ -0,0 +1,754 @@ +/* + * 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 *const sti = ffstream(st); + + sti->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)) +{ + FFFormatContext *const si = ffformatcontext(s); + 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 = si->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) +{ + FFFormatContext *const si = ffformatcontext(s); + int64_t pos_min, pos_max; + + pos_min = si->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) +{ + FFFormatContext *const si = ffformatcontext(s); + 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 = si->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, si->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) +{ + FFFormatContext *const si = ffformatcontext(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 (si->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 25285f62ab..61acaf16a2 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) { @@ -1771,7 +1763,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); @@ -1781,9 +1773,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; @@ -1820,731 +1809,6 @@ int av_find_default_stream_index(AVFormatContext *s) return best_stream; } -/** Flush the frame reader. */ -void ff_read_frame_flush(AVFormatContext *s) -{ - FFFormatContext *const si = ffformatcontext(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 (si->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 *const sti = ffstream(st); - - sti->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)) -{ - FFFormatContext *const si = ffformatcontext(s); - 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 = si->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) -{ - FFFormatContext *const si = ffformatcontext(s); - int64_t pos_min, pos_max; - - pos_min = si->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) -{ - FFFormatContext *const si = ffformatcontext(s); - 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, si->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; -} - /*******************************************************/ /** @@ -2748,7 +2012,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]; @@ -4358,7 +3622,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 Thu Sep 9 15:57:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30092 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp650446iov; Thu, 9 Sep 2021 09:00:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv82H12gybvMzK8ikyEA5SmYpJkGrqaO3Yz+kRzchaic4hAwuC0Wx6GtPa/YDpXQorpAZC X-Received: by 2002:a50:cd9d:: with SMTP id p29mr3933734edi.30.1631203234917; Thu, 09 Sep 2021 09:00:34 -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 hd17si2039710ejc.727.2021.09.09.09.00.34; Thu, 09 Sep 2021 09:00:34 -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=OzoNWoPw; 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 E110168AA67; Thu, 9 Sep 2021 18:58:35 +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 50F0A68A9D3 for ; Thu, 9 Sep 2021 18:58:26 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ctJAIRo6YSCT5npf87fG1/vIIW7R8aeIXgcxDpb2u/FvLt5dOBntoOvcbNQa9QTM/Ny4u0s1fZ/yDiY4EpW6SVztbXIFOIYT2JjlA6AXszmBNW8EhTdnJ19nvNUHMh5XiNcydrX9eqiteCuRIoNm5RynbpMCVI6ucRqnnVPC/KTuS4vVnr9ulUZmjbU7aR7UCAeXtSGenCWK69r3RDXOXozo7x3SCvXY8LOoz6cnUc0O+N+R7upRuAvAOQUZ+KfR+5VaSgghJVgvzWB8jGOU8iOo0wj+amvKRzQkmN1L5nu1cc47OYu/sefG6V0Z4GvIEwh2aDfrBy3S01zqajP5Bw== 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; bh=5T7uBq2nh/otYwYLZEwjQ5ZYiZOoSzenzjVdXO9UR9A=; b=HHGWzldcn9AWTGfJ0fbJrwros6zHeuckLRN/DL2pYsYAZBDinnEYcR7DHRjM4mv5G1rCpvdsyHt66vH8QYAtKgi1aV7JOR5qAhK6LxkyJeBCs+0Aq19jQbp/yh6R9+fQQpyXw++16I8afijjVKcwIwd81hhifoAamay6VWFKl+kZwE83H5VyAogoqXqiG5L8hEbvnLM2TM6EhRsintVdPGfyvcgK/WlSoFtpTBN2oohViX7Dq7PXfpJ8PkAvJ2LywJBi8GTJ+aV9SdFVJp1+0NtMSGZfcBQm4PZyimKCJ+8zFSlB6xvbVxIRd4hvirk4EbFkfE8i1HhZjMQztzU1rg== 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=5T7uBq2nh/otYwYLZEwjQ5ZYiZOoSzenzjVdXO9UR9A=; b=OzoNWoPw+fKSy1c6iGzbXEhlt3QTke72sy4mkFpvxLVu/kP/Hq8t+YMuIao1OTPz97Ptkw3j86bvK3Dg8+npWZ+MtpvbYz0UvpncDMKaCjEOGBnzHS5rHcpFflYNUnaS7Iia53OkYAowxi7/BTeNGN2wLxWwgSs/dWPlqEkAG8ePGX5MniegdHmzwwZvbRadXkTLA9s5k30GWZDMv2zsUveUi4xDyXiKculg1DdbSsF4GMBp2ocdszfjCyd9WT/QmEHs/c01sc/MtBP1m/Fk8ptHIQn7pZOPMY7rCzXjEJkgts6ekKCgT0Yc+b+lzJwWn2WTm/sPcbxhXprwzVdnTw== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:20 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:20 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:44 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [98BqW4Ys6tMkEtkwopBgW1XkB/CVceiV] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-10-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c6e93b66-0b75-445c-c1e3-08d973aaa473 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXImq1sWRAABPXhZ8q25ZjY5uU2q58aHcvAZQnuBjMAJjLiyZmZUWkRytufBQ4INoNHHYXqv9TD984xLTQpUVf08kjOf6r/NO9BHRbVfVHW8V973yhwN0sbomTX0YUHzLRTU1S++w691MH0AeXWWLP7n1nm3ob1vfT/E4xudg2xCiKLA0bqHoKFA2jDm3ZWy1frl3Pu/64t3tS+LyksrPYNvS4pci48zZs8lv1fg+ZPeVZrNbxFn4rxYby4PbVUiEsvx2XxqW6UCAU2BshfOdaK4g8RiquK4D3fzalBxNgeBw+oa3WwRhsjkMxVV7BleSFLQfpvreeSdUCMvfRSgZ1xvmvsUwVgGu41wEI9UCeq91WUPzngWSGLorKGrBfFTlOWr5hS81819Rv/cJcgMFcMUOF0MTYgdpwB2a2uQt6Y4380q8+toGp/t1quw4Xr4GhQPj5EoULMiziB/U6z2TtFcalHgJRh6HuwSyQqd4ue3eKTuW0RbGYHfuKxeA8wEGYHHPnQZmUzl02Ata3IkznHex0sY5E4LV/hvqubqcdNmxwRcHpm0LpBygGVwz/wJRRu3pNY2MzuVpqbwK2dltsSThIvk7E1u7BUgl1+Tg8KmAf9I3fBRVRXyHY3HQY1PEGcd7PBV+T3d6/rtoeiwKXfI42oYW6kZD6r/hkuJUKG9qQhurLF4Se2f1WewmgLfGwL3URVDOyl7Tcko147UDEybLbL/TNJ1gI= X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ixi2yXnpfYDW8fyqjE4NQQqBXFdGzMziax9b1hStcONyd2DtvukLMpXfDiqPtTwmgfSpvbnq4ZftcKqlei4iyT1KMyPQEllf1TpU/fnYdkxT4HxwnzZNB0vYpWRw1EljQonlWTK5pDA/8zeQ3UjpqOooYF8ZK8ZKT4BAGDUzVFrEYJXNQbDzNRZvJuA486GCB08MUy5kak8T8rluGvqJE9JTkV80clsSD6kEnpeBCVgZGKx9VKsXptRSSchNl10iGCfMA8HRz2rGxp8hFcmGypusfdurSFz3bntaMdaanfaCCKCnCHQQz2MPnTK1FWLs2i5yjuCCJqeJ2TDwvwbdEiClTUf/A3jM3iq8hA6oviSbjs7ni+uwd4zQEdzMT9DHf7GDDlWJkiJyn1hOO7e7qGvxpEIcAOVNV3OvCTMAfHyTr75g7pNtQlemCngewe/P X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PFjfPGs8pJuM2HXHmvg4GHEVMgcTHBo14BB/hG37vUytSB1UKjyyFUgg02g3A8BTv0xdxiIRQDKqvkigvuXHv/wpaGLQGuC2ZJyyZw4w7Q5WcW5/yS38BqmZs21JaAishcyG8xgLoSDFCAccpVa8jw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c6e93b66-0b75-445c-c1e3-08d973aaa473 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:20.1242 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 11/14] 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: +z1wVAHPojxi 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 --- libavformat/Makefile | 1 + libavformat/demux.c | 2961 ++++++++++++++++++++++++++++++++++++++++ libavformat/internal.h | 2 + libavformat/utils.c | 2938 +-------------------------------------- 4 files changed, 2967 insertions(+), 2935 deletions(-) create mode 100644 libavformat/demux.c diff --git a/libavformat/Makefile b/libavformat/Makefile index f67d261402..c45caa3eed 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..267ebce07f --- /dev/null +++ b/libavformat/demux.c @@ -0,0 +1,2961 @@ +/* + * 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); + FFStream *const sti = ffstream(st); + + if (fmt) { + 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 an 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) +{ + FFFormatContext *const si = ffformatcontext(s); + 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 = si->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) +{ + FFFormatContext *const si = ffformatcontext(s); + 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 && (si->packet_buffer || si->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) +{ + FFFormatContext *const si = ffformatcontext(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 > si->data_offset) { + filesize -= si->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) +{ + FFFormatContext *const si = ffformatcontext(ic); + AVPacket *const pkt = si->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]; + const FFStream *const sti = cffstream(st); + + 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 || sti->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 *const 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]; + FFStream *const sti = ffstream(st); + if (!st->r_frame_rate.num && + sti->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]; + FFStream *const sti = ffstream(st); + + /* flush the decoders */ + if (sti->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 d0b9d6200a..d14dee5422 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -652,6 +652,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 61acaf16a2..b0814d7bc2 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) { @@ -156,7 +131,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: @@ -173,36 +149,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) @@ -277,93 +223,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); - FFStream *const sti = ffstream(st); - - if (fmt) { - 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); @@ -423,520 +282,8 @@ 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) -{ - FFFormatContext *const si = ffformatcontext(s); - 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 = si->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); @@ -948,820 +295,6 @@ int ff_is_intra_only(enum AVCodecID id) 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) -{ - FFFormatContext *const si = ffformatcontext(s); - 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 && (si->packet_buffer || si->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) { @@ -1811,550 +344,6 @@ int av_find_default_stream_index(AVFormatContext *s) /*******************************************************/ -/** - * 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) -{ - FFFormatContext *const si = ffformatcontext(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 > si->data_offset) { - filesize -= si->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) -{ - FFFormatContext *const si = ffformatcontext(ic); - AVPacket *const pkt = si->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]; - const FFStream *const sti = cffstream(st); - - 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 || sti->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) { @@ -2459,92 +448,6 @@ enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag) 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); @@ -2579,815 +482,6 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb 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; -} - -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]; - FFStream *const sti = ffstream(st); - if (!st->r_frame_rate.num && - sti->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]; - FFStream *const sti = ffstream(st); - - /* flush the decoders */ - if (sti->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; -} - AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s) { for (unsigned i = 0; i < ic->nb_programs; i++) { @@ -3434,7 +528,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; @@ -3627,32 +721,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) { FFFormatContext *const si = ffformatcontext(s); From patchwork Thu Sep 9 15:57:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30089 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp649647iov; Thu, 9 Sep 2021 08:59:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrqR73ChCUlkadKrJn0tOEgT5/s3Mg5hTcFNde5nXmtRnrmZrwO1W42wzXBcjCZVlH687v X-Received: by 2002:a17:906:a399:: with SMTP id k25mr4120686ejz.514.1631203180307; Thu, 09 Sep 2021 08:59:40 -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 t1si2340378edw.582.2021.09.09.08.59.39; Thu, 09 Sep 2021 08:59:40 -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=l1Oe3E+M; 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 1A84268AA2B; Thu, 9 Sep 2021 18:58:31 +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 9B96868A9C4 for ; Thu, 9 Sep 2021 18:58:25 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kmz/eAtWN1qrfpjC97xv7a0EyLXmR0Y+JP98yykFVSRpLzqOY06uP4t5kRHdSrDvxves7HwSERSFnWh/zn6SUgOWnyHQsr0f03IAbgMGJELdbjkb19RpY7o5RSQ8T//FCkg92/u7rDUlj29HOm1nIGqSatxWtgSqcgrDvrmXifaFuADvmojmPAsFKpqcaTAdqgJ/bFS8rtodUUQPmIgg++imOl+h5/7WYdRSgAlctMUVFwNHF1KeKUtgEV0EjSDpFD6nykCtfALL7/uRuzkqgsCCNnLAVvPgFuyI6lcQLFcKbTRuRQlT8UC9vFarQszYQuOEfmyHSeSVNzVmP5xkeg== 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; bh=STCJ3oNZ+WpQfB4726a0mPQNHuCMn6uYIxPamZpC8iA=; b=NGRDTj5ElfILKoPuW8utePpyH8KTF2wIQEkutnmlQoGYdE3XXQU4UhK0CphfRrh5hWZgseLK4tOnaJqM3zn0UWnaXLjXb/h/kE+hFz6LZioR1g6slIbLPKqrUMIm37tTNHow39rkOatFQ5Zq73GcOQWDLu82y6SCOPQ6tBBSxQbZjiakrBIocrgMeaZijhHnP8fL90AoeOtAmLtJB8iiG0WU/Hn4VhQ5yXXrZLk3WXpuiPSCMsuSAQnpNfbFZWkq8BZI/KvV8VnOB2NUtKf9nKj1R4T5kxhwt22+VZuaRiCfUidhnQnyReQeWZAhHdvGzJn2GaTu99mnT4ARfAhKmQ== 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=STCJ3oNZ+WpQfB4726a0mPQNHuCMn6uYIxPamZpC8iA=; b=l1Oe3E+Ma7N08iDt13MuStcB/cHx5ZAeMpCRio7m7RHYG3jlJZUWmBgWdogzc/S2U0MxUffNFlj9AKVECr5VZbXT7nJBnYXcxJxt9+JPjZAolQvVBo4jaPmOX4qY1KNzP4ltJXqUhBlC28/nw69om8Y6YBnElxtCOHRbQVncYH1qgI6nqHWBcwj3EDIFfIaRcp8Zf2zZ7h0BKyfrSTA9ZfF9YJjfcZIcIq7+NtN1kpOmhOkc29jWnc7G/S4pzsvmM/q+5GaU/i5/Ma4mo0HfLD6z7zYo2M6jlC4D9fEF6r1+XqKv+sER042EXm/UbyUDqWz3Pi5pjki/24zqdpaqHA== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:20 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:20 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:45 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [Bx3w8EQvGEziFeg6S5MUIYE8fhNQnAe5] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-11-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c5bcbe4b-5073-4dd1-64bf-08d973aaa540 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQjHo/KsCc3LoxlbG+9PiyINimxZ/kQua79NS5nW6fNQVWhyKIT9y9IGxXol21HSCw5PBEULalt10aHVy7wm4XhH8ZnY+4h/MbhUI2rpVBSwHHFz89bBckGLHtBvoRlDCRyPR6m+G55w9wJVwL1qqoNrW1Ko4TD+WiFmr9rAPQKqo20lRr1iQknREFQfd3guZ71gaqMp61ggfTmBMtZ4uDWXkoDLAn0XofTjuYKNuTS7l/XTWlvqra2ljRsn70u7/yfJIx+VQQ8J7tvt1YFSfE+YMzQyaUFswtKYn/Liu6GCPtobBFW5LkcU78WfZwPLjMJrI8FBZq6A99ZWsdetoQuSHqMVTfbYRzfeooiFNEWlz/k84YWpOFA6yzWEIdromew3PvavNgIuMeX9wTv/4QIAp/1+EZIPq60Qq1awBJvB2KLHmZ5mj7K3Cq32iSJ43U4zatZBoOFodbjyNAEaWTl7OuVg+aFLERxrrYmH7LVHVqP8MPVrqO4QF90spcljXE1rIAG1eOvLrEq7fi4NJEu7FbhWuJu81Os++rEOhjmIVxpyZxISjVJ9tsMxe5xKzCAV5XuJ4tuM38rjcBgZJQ4u5KryZwZ8z0QjVxnr2jRaG2dB07FHbUEBXXRrweJBL5YILlCtOI1S6SuEcWBvbcSdEgM7EVcHxiVddTiEnchRc9hq6cEPP8cgXxrRzwOWOQBKakK2EBdltOnLQVqlQ/v2IaiZIhZWT2uagDheCGaORLlWJgRLIDkv6acC352Pso= X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0t4S8OZJSNhxlbUikbF6ITNyh1dydMxj2NJlwaDJ55n28EFZ8riPZ5RW6R/+wb+6NV+Pi+NTB051RkFblyUpZPyI6MAspmdPDjp3SONh2nRsuWw7YjtU64+MJpzPtVNkIHnMadWfvISjJOvOpxnhCL++wItq41znPsX1dd6STUPmW+uI7NWMky+xKBOjnKKs/fhstK5IyPH9viqiJWlaW9/K7Afq8nHHUldRHzjPYg9UnI1hWOjpqnh390PCIcinGDWxInRfUpfpLcqrUrk5l20iYcW6T9u6l5vD5dC7A5yhAl0kRE0pWVyf33WltyQEtgqDWpflaSJYojkxvM2ehr/YVZsq3e384tEdJNKFER2AZ4DQMYueh9mXwjiylAahVkkVh9HNDNbVyPVspRIgM84QqZQS5/d4RmBgdStMiZizkypugJpYgOa1l+sUsJKZ X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d3vmoKgQv8408CGwBIMA+/AFxOcZbURNCuSbJsN7TpwvNRlM1LBJbJ2EHqafm4reAjp8Lzrem/bh3g2H27MDS4KKlV0h8lU3zXxpf5gJ5FABQEHTHZZ+gfdMu+AgmNXZgJMPLu6qmPtmF3KLthtEnw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c5bcbe4b-5073-4dd1-64bf-08d973aaa540 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:20.6090 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 12/14] avformat/demux: Don't free inexistent ID3v2 metadata 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: 5SZCbIiU3uR1 Signed-off-by: Andreas Rheinhardt --- libavformat/demux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index 267ebce07f..7bcd23ed62 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -319,8 +319,8 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, 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); } - ff_id3v2_free_extra_meta(&id3v2_extra_meta); if ((ret = avformat_queue_attached_pictures(s)) < 0) goto close; From patchwork Thu Sep 9 15:57:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30096 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp650045iov; Thu, 9 Sep 2021 09:00:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr3JKhVNYLD5bq/M8S5O5fDqW595wgNrPtuRsNcyNa9mnix3I3YBgQHx+b2ZxZLYR2SR+S X-Received: by 2002:a17:906:f15:: with SMTP id z21mr4079608eji.177.1631203206955; Thu, 09 Sep 2021 09:00:06 -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 k1si2112067edr.250.2021.09.09.09.00.05; Thu, 09 Sep 2021 09:00:06 -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=jO2eWWra; 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 D5F5868AA47; Thu, 9 Sep 2021 18:58:33 +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 F09C868A9C4 for ; Thu, 9 Sep 2021 18:58:25 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NFvt26Hu2+geS2rxb3sfsVChUF3h5ZpQu69b+hJ+35qXH3QVKaVbvlsE4jnAyftK9ZBjdxs8PQRUJjAayVKTCa2635VdII0RvuHb+n1aiBCtGS9wpfM45piuj7pB7q7Kd2HWJ0MxoTwNNlW5/CtuX3Yl/puDz5pOoLElqgnCdSE9Iu5bcviiEQeF0WoX3EMlrBfzEMIcdu1biuvOX7Wc3RkUryiUn/f5GYkl8u7EoiAktCdLOxSEn7eDcIKbGyhZ3H1h0R2eTR8/Ax8Jx8cRzVb7GqNRlmAmjnHbrdAr8w/hHpPo4lLn02jObnxsQInItfqs1mEy7JbES/w8RhPbGg== 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; bh=c/8LgLzgJZ0AP2A8BOTrm8l363p5y5QijYOTfHzT7YM=; b=Dmdvy+MsNpSldfAuHn5ERkdl6He31u/sTC53V9WmbhtbuOP3dER8w2jPq9bV0twM4qoFH58q5EJaAkdTyk/qlin+aFbRoNG33JpC+bYCnbv9/KAjTHIxzDQnCu51ivHVz5OW638dIsSIJ8J16Iylcwx1MSSOn7oen1vRSUn8f6NPzg7dEqAGtakzTEh0vbJduchT855UyhJKdpiom28+If86CJJInuL9qFtRTyNhwW2NcXDd8CvE2B+djXyh9Tdii8QbC2zkIHxxdFCQ3WiUpoBClnAY2jpWHgmgdhvV//ht19tgoaTkCdNmh4xaJ4jN5zGAHBHvhJ7/UdRtX61srQ== 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=c/8LgLzgJZ0AP2A8BOTrm8l363p5y5QijYOTfHzT7YM=; b=jO2eWWra238o0Z2zEp0oxE9EjMNn6pDSQec4Hgoz1f495pxpHB8DLCO0rrPMyJYN0lPJcUXewY3f2kLKwTpAMlF9hh92zT4eFCJSuMOZOg9JvaabuMOb8WATdMQRZyKRb7suZ/5EEBZWN7tkhN+/QkLoB0xF7B+WnnnZPeEOGWLmc6Ca9W0zwuNkD2DjLs6m9zbMrv+S7ovTYTKPOrlTh9lTmL6iHtQwADI+GOs8rUnIIlz5TuVnuTEki11PQjJsHw4gKcprPbqaNUkriHP/RR/oR7dYxgKQ5DuuYyLNJOG527l5A5Qgnzkv8RkgOVVDrnoXMlVOepiYwvbLZ6+PYQ== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:21 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:21 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:46 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [zNmG0KFSpCMWwmPEeysMvieQs8VsPvRU] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-12-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 57a27288-4c42-42c0-1cf5-08d973aaa58d X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQjHo/KsCc3LoxlbG+9PiyIN7rYFo3v+th9Gx0dfEDl3xkIdGO2T16Kw/P8+Ytpp8/EYPB8CYxgc1gtfkruL7N94F3ymuB/li54nxEEhK77m9PrAEIHrZFTkJ7tTpNs3p+e4rmHf9lgvNI8nX0PUFHuUdk9AgRG55/HEnj+Abwg3wrQ9FoSIZSrXclFT8SOoymRLLpNcQwTNIBBUUsk5sveKKIirU2TP/SM4tglx+cmyC+mkzAXFyXtg2I+5hd7gXwY8QP9C5QjESnkGSXl4R/JYLTj/leGA7neCHjGx0HFUvxtYbV7YbZzyXJ4zJXgTB6r3bfBov2TvhBTBHtHkefaXX2veXPK7UPuCSrjNhIcvuhyIFnTxGIN6SJkHgISky9I8U5U4mIXHhQkG1mjbH58aLtvsVcSmMNG3K52GxlDwDlw24ESNN/CuHvirvW2g4tS/SaEKB4+b8xd+PoiKYOz2DM9xO83URccSVvQVt1bYG1UxT07AhJGe6gQwI6Xz3QDhurAZo9loT5spG7xsUNxgAFXIyuPnn1tnfxpLMQZqYwwT/865dkrCKiRRKtLwooYCOeGFfWf/VgB8FMnXWaAKChIGJZzlP6pkdCykFh4bCi9qM00RS/AKyJb45N6MZhdVfwOgqdBlqDQVAs9LS41lmrKmSnaJPadbmSHzG7fgdUeN/AhHqyItLd5Q+FqzvCq7R8mQAgkUA5moVt8+yZgYtOfKwhSPjiGcpEnKTrSc5tQArWGSd2VQwpobf5Y0xY= X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l/2gub3Fc99hr3q0GL/wqInO+aHrv6gwS5V55H7Al6pxVXVaqZPnG+ZjUr0TNroUFMi6eIsvdMQCA7dkvenUdGcTnkgLKKtgpfyXg8kWXIWo+xxkc0l3hFKCJCZGT6c6PdXK1xSu3RMOyhHhzMJQRzHI4ZNi6+d0tqaE4qCTOSi/BxpWMGK5oiiM9ZO3i8B1IZKD2LQh2L7Xhsy45n+0zv8OkwTw30MDwUH9IZoFByrh9Udn6yWT4GDHu4D21RpgBlHyBhMYFJrWG9TrkJ/tIFFwYGcBzafH8z2v3R6YYbxX292Y5fQpq2adbt9wFYYLa6jP2V+0BcThF5FgF+WNkum9yCP5u3v/wQQ+pWtBnm0++TYtF86/NCjaX1/hMF/AbaUPHoN59FGasu574ul7XmxWDIGZkYVOSK6I35unyYXj+3ffrzi9mrnFv7kfMPVr X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rTrCXhdkt9yo34TZs65QHVZBpIgIUJ9LtGnbwF3KgIG+C8+5YfC7n9GNVmlJ/fBg5aO7crsM8vh7VZ4NK4uLIyKGh2T2sY6GIXCoLKFsdPPxpbgxpfWdDYVNH7jIyh5Kefni9Y4OqiBVb39VF0igLw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57a27288-4c42-42c0-1cf5-08d973aaa58d X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:21.1138 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 13/14] avformat/utils: Use st for AVStream variable in avpriv_set_pts_info 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: MR1Ud/PqjuZf Signed-off-by: Andreas Rheinhardt --- libavformat/internal.h | 4 ++-- libavformat/utils.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index d14dee5422..cc8c8f4b43 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -696,13 +696,13 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, * (numerator or denominator are non-positive), it leaves the stream * unchanged. * - * @param s stream + * @param st stream * @param pts_wrap_bits number of bits effectively used by the pts * (used for wrap control) * @param pts_num time base numerator * @param pts_den time base denominator */ -void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, +void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den); /** diff --git a/libavformat/utils.c b/libavformat/utils.c index b0814d7bc2..3e6b6a1e23 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1143,30 +1143,30 @@ int ff_hex_to_data(uint8_t *data, const char *p) return len; } -void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, +void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den) { - FFStream *const sti = ffstream(s); + FFStream *const sti = ffstream(st); AVRational new_tb; if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) { if (new_tb.num != pts_num) av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from timebase\n", - s->index, pts_num / new_tb.num); + st->index, pts_num / new_tb.num); } else av_log(NULL, AV_LOG_WARNING, - "st:%d has too large timebase, reducing\n", s->index); + "st:%d has too large timebase, reducing\n", st->index); if (new_tb.num <= 0 || new_tb.den <= 0) { av_log(NULL, AV_LOG_ERROR, "Ignoring attempt to set invalid timebase %d/%d for st:%d\n", new_tb.num, new_tb.den, - s->index); + st->index); return; } - s->time_base = new_tb; + st->time_base = new_tb; sti->avctx->pkt_timebase = new_tb; - s->pts_wrap_bits = pts_wrap_bits; + st->pts_wrap_bits = pts_wrap_bits; } void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, From patchwork Thu Sep 9 15:57:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30095 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp650237iov; Thu, 9 Sep 2021 09:00:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziL8Ib+SyFeya+3gQeEMAeRpUYFCXpo3T/EkWf4ZYRiVwOtzfBEkhMOL8ISmYlzePnirIB X-Received: by 2002:a05:6402:719:: with SMTP id w25mr2357827edx.94.1631203219468; Thu, 09 Sep 2021 09:00:19 -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 l7si3131190edk.342.2021.09.09.09.00.18; Thu, 09 Sep 2021 09:00:19 -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=MlGz9E2x; 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 DE8E468A9B3; Thu, 9 Sep 2021 18:58:34 +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 2CC7668A9C4 for ; Thu, 9 Sep 2021 18:58:26 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J16uEwF6w8zgQgD6LdcQnChPYoK1r22fVfXScrKBPaZh+96FGt5KqUiExSHg1WtqenikJ6tJKN7mwk+A1AfxHti/8jSFJ1qMK8huNINldj73hP7rawSEpAMuH2mb7TvabWJNxN8CmdhPMdmgnu5ilZWqAErEoQroxP0gmy6Sp9d33Id7rh8MSB+nZY861NtpmOovsZLPhES4C5xrMVcjUgJnV2c1uUmPo6/0IMMFICA2tM2AxLSq3dNdVDJ41jqq4Z3QTlfr+9YuXjAlgz6o+U6zDreImaulyeJapATe7y6+rpoN+yqgDNz02VEwAIsvHcJ6lBGWwoZSwKjhAXNtKA== 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; bh=YkrTSOJnbSGqNCQr085ZGmka5lDrGpoZuhw+4L9QPHA=; b=JUruEh2Jo8RkqYqPWziDuEJlMRLNbyEkqFLaeNn7WFoV8Iba2AzfiwSUm1bwgBjjFwkdknjfo3NPZR1fpuHLqhUpLdxiLLBgeM/1lAQjI30gR6QSnxUDUTKGFk+rO932CxaJKRaW4Dc2f4Bn3qGDGZlCCIXOxod1A42yq4SnXEiDimoaXa78McgmgW/IZrqlPxLK64TQ8HHaJlrXpx8/0XcRLFKd+FSsuqA2z1JpEZgDkxhTZDlKxZCDrRwy1oyew8wZRZfSgSHg5zDjTR+Ru8zmLh4hxTZf3vzRfzJcTy8xixP9nAieu7toLGeiDdwJCjYioYQl37hM1q0jjFcO/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=YkrTSOJnbSGqNCQr085ZGmka5lDrGpoZuhw+4L9QPHA=; b=MlGz9E2xulu7VFv3m2ep+0OjP7VnDGaInukDZyAdrvwyrdU1hRxpag6terw57+w/58wkKCr+NkqFdx+dkQxMN0C4Vdsvi1yN72l6TBptciwwwhLLpf3Tf8vG3XOJyB9PJvlpbvwHG1YUi/bLZd82sqc+0D0Y4oQdMT9LGek4PAPbX8DIY6tr4UxfW+/KgRzxjY0gu3ugPB+x2Uyyi2osZjROFbrVJ/L68d2VADJr9BciUR4BZTWyJUGvgR7S5yJC2OY7JhgcS/7Hgk1IH6mfRuVWtHDhkoG59UqhYM6PDSm0F7Czp2G2allYtxRqqL08LBi0tD687cK292M/K24dbg== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PA4PR03MB6863.eurprd03.prod.outlook.com (2603:10a6:102:e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 9 Sep 2021 15:58:21 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 15:58:21 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 17:57:47 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [eWV4ET9ZGjCC2254ZEFih9rAGWMUOJTP] X-ClientProxiedBy: AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909155747.1841422-13-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR10CA0036.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 15:58:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d470f1c9-2a47-4ddb-7721-08d973aaa5d8 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQjHo/KsCc3LoxlbG+9PiyI3igFqrKf8wY8sTFRBzYyrNBD1b2pqeKVpoMhBC7ZfPUqHeBuU8K7pJn+jgvMFMymqS2TtXJerVaGJLmy8dZBOk4a1e9+3O5KqQz4gyJjT0KpGxHs7W4K0X2hABgCplom5t0+QPYHLHm1xTKidB3SbmFtb6n963lCjJUiJGOhcsHtY6DbNx0ULx9sok22rBTNgok8Yj5kD4A45JsovYR9SlH8uiHHwTbufGICNdc4WnxPvdNXz0fniYqns6KpsLY6cQ2iR0U7VSUWK0eT+DR7A3w/cgY2l6r6Y62697X7O2Bd2beFe2NL2h1006idU7uTUOc3Sn1bnJz68oIPNCbKV4PaDvHFYvsQaouvPJ8X7/Hz6+vM4NYnMqcEItJw3+93jFlwCnUOns0FkVb/U16E+yRs7iQDwWD2RhevKSi9olRva7qGgCii1N9EW2Xgnwglx82R7aqQcqH0aIhon9FNAxv2V1geCaigJ6kfuZhFQKJZn5wLgy7jpkTELrU7c4EDLayVQVmGL7TrbOfqz9FLZpvg/Ve2fpRCTLhzU5iA/iSWDsilDqv2y4MiUrC3zrU5t8w+9Dv53peaf6m8whaUa6IyUzjbYSvfAoU3EzvUGxRjYmSR5IJNULg3mBLU4mr51lciZOaUg9+LDwMRisLjoZe+VXBcLKKMCIAyIfGfHW9xRQR5MwEy4FJbsLkIgB+QgeLlNgfCoXl/iCmtsS7oyVf0btEFR6TximkM/XwLF8k= X-MS-TrafficTypeDiagnostic: PA4PR03MB6863: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WO6cFgbslAKb8MwzbySaM6akR9j211V/rnrYnC2f+jGcYfxJ+0NBFnc4MLfvWgmp4sH5QnrrviEVknTj63y+JNU0oPQT2vrVW2A6eZeVzAnpS/gdsqfEelfIkm5lyk3d9ZAEfcPjA8nzkaz1NqfaibW6piyGYQ7Sc1NXF6wzSHEGHhWcLMXH4/SjhWGcNCXLsFik5mL8koecwIZPNBshBKFaaQJ4QBJnNwUKl0uKWe0qoobvKP7s6H/Xyp8rhacGCidbgyMfmZs8LIjJaRoJ95Dn+7lVa/Jar5OqNqOY57XZzLvDu0c+0p9JMfXmOwbMIEQ7kfnZCBMSPJsq9q6f4z8cjUDeyDrdroB9yP3uwLp3EvVYiK8yh7JGAbZl9YoSw4tN8Dlqkuwz1L2i0ThPhlKRcOXtyhpap4ISPW3b4bLxQbYuq4HrnPuPX9bzTwV0 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mWjeHzdNbubIoSlUqx98mTfghEvfjRNkvtBPIodv4ZuXVp3rttOOAsW4VAaKpH4lrPXKqrjSFnh7zvpRCHU7HjBBq8MSRUR46ERC9eVzcwI9kohBSVPSGyDoGIvHJ+beaytm2szNHYzPngHd/3VExQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d470f1c9-2a47-4ddb-7721-08d973aaa5d8 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 15:58:21.5887 (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: PA4PR03MB6863 Subject: [FFmpeg-devel] [PATCH 14/14] fftools/ffprobe: Don't access AVProgram.(start|end)_time 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: sZfawQMdyXFd These are internal fields. Signed-off-by: Andreas Rheinhardt --- show_program() is only entered by three tests: mpegts-probe-pmt-merge, mpegts-probe-program and mpegts-probe-latm. Even mpegts-probe-latm does not print detailed information about programs, hence the lack of FATE-updates. fftools/ffprobe.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index acfec09656..d8e968321e 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -2844,10 +2844,6 @@ static int show_program(WriterContext *w, InputFile *ifile, AVProgram *program) print_int("nb_streams", program->nb_stream_indexes); print_int("pmt_pid", program->pmt_pid); print_int("pcr_pid", program->pcr_pid); - print_ts("start_pts", program->start_time); - print_time("start_time", program->start_time, &AV_TIME_BASE_Q); - print_ts("end_pts", program->end_time); - print_time("end_time", program->end_time, &AV_TIME_BASE_Q); if (do_show_program_tags) ret = show_tags(w, program->metadata, SECTION_ID_PROGRAM_TAGS); if (ret < 0) From patchwork Thu Sep 9 16:07:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30087 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp658122iov; Thu, 9 Sep 2021 09:08:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNltB+pkufCVEb1LH6u7lqGTI9aFYZdZX/7tA0GRdrLFMRz1P/3fj66P9FtFB2vN4Pi8C+ X-Received: by 2002:aa7:dc19:: with SMTP id b25mr4093016edu.23.1631203688374; Thu, 09 Sep 2021 09:08:08 -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 i2si2826383ejp.581.2021.09.09.09.08.07; Thu, 09 Sep 2021 09:08:08 -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=rIyKU6mv; 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 B3CD868A9BE; Thu, 9 Sep 2021 19:08:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2046.outbound.protection.outlook.com [40.92.89.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4A84A68A7FD for ; Thu, 9 Sep 2021 19:07:57 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XfZyChm1G07JXgIohq03+xSpB1MZ6VbqU87gktxxXrK7/FuE2zsp6Zg6lLY5P/KinRdrFrLblt256WxIk8Jo6k0UX0FWNkjcbDXOsld+XlXHCer5s5Nn4YHvOwZBDigCfwbVI1NkH1NC17yu5xtUYGQHyG5jBV6/tjfgmZcIFhJLP6XUfC6HSL1GKc0NsBbXVXdKXlQnx7PYPEiAdkdqGiBJpqaYo7HkNRfMpDRdJu2TTsh0+rLyH7dRyP2hPYOawbYkDMbfW7ByAFAsxQWbeLgOsvdFnaLGjzKb+RNdQPVzPF18juZm8jh09VbY8ybxW/jqbF6azmM0pHmR/MNrIw== 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; bh=4sr4BI0XJzWkfKoMc80aK/kFRrjk5ufp6ekTlPhbMIc=; b=J3bYJyC7qFGtiT8+KWbY12vyolDjSuZOOxLaA7HHhHOSAos7RbFXkd5xs1Mbai7KsGZ2wulUoAkH64FX4m6S09fY3+i65x85aGhRyxPo5wmXJHIp9s5hgOn7zlNveGZUF5LzBfCVU8Ce3rJggzJRHuWNsRBBuwWxPeY2XFSDUz0vOXlzB+JV3yZgd4qtanNMaHDFR4GRw9NiyFtEgxKD9+H/XbvNd9LO3PIeGgbT07mrs1sxQggZv818bAVe9B8QGTI511VWJir5MMZf7IGFzfjMj0P0nc7mBcSsxcOPkKds6vdmnBRhf1s9KRltRXXM1XY2cWMXzcjzxUQ0wU6LOQ== 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=4sr4BI0XJzWkfKoMc80aK/kFRrjk5ufp6ekTlPhbMIc=; b=rIyKU6mv3pJK2japVVgMugst4l2WBnr+2vBh3+aYgO/eJbnMSdBpWpKGnD1PbsiAed8giIczGlV8R0cgJ2USPGS8rOe/HeU9GNQ3atQJdeVw85hz40fjytR+DZCmiwLBeo+8t2kFn1MOIyzTksV4Vhk+hTWhrIohPY6ZTjAWSfHGwv2z9Nqvvy6Y6+UUrgnqnP0m/qKBsygskvbKsO9mA0x/m6Bbp7/EJwWTpjR08R7qfG4y+Ku+sMvwqzvNXIOnnT6f4GmLsC8hIhhHBD1N8oZdHU9QlmvNLRzgUxpqr5ZmFtACgICY5EBRskxXPBzg/E7xIu6WSHC7l1fGDG90mA== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PR3PR03MB6556.eurprd03.prod.outlook.com (2603:10a6:102:70::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.21; Thu, 9 Sep 2021 16:07:55 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 16:07:55 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 18:07:46 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [czGm2eLQHPSwWPoWot/gV3TAOojtcwLC] X-ClientProxiedBy: PR0P264CA0283.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1::31) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909160747.1841811-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by PR0P264CA0283.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 16:07:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eb0c0a0a-a24a-4600-631d-08d973abfbeb X-MS-Exchange-SLBlob-MailProps: f36zkjAOy3XPOJFAXlWDV2wrQ9tjfmBZ7QIQozD/Xr9xtDymICrE2/a+CETH6h0xJGix1e4NvRVjfDIf2rhnUvLB0M+oJYQPDFXqHljRqSRtSO4W4GNurIMCKgb1R3gwH89ad4MvYV3kcx/4Bd6gm+u27FpdNeVgFNeERt2Q4RtV5CVU2e+OW10uEtruQ2XQE4NPMaqyfo/l0liS1dpqkCqZKWN8Zd2WvAXZys/cxZkyTe00WxKaUImmR9xoZiHkeMvsk4sWGk1+d5pNQUbmauSf9JXrriTIRGNv2kh5v2GxqU0V/bUH9rPO5OxXAin84hENpcxLREceVVVjW/DmZIOemUOMAdLeDqPWm37ff2Izry+P9220SJ6752jXldvatfpPwMyxsCBQ0BSddUio+9E85FmtWSjcAKjoIaDz8Q9H6y6tkcUvr+jLkuYO0HTHPzPKAnoc9bp5pAna4+g36YLfJxUyO1TGCL0KKbbx4pP4tE4omrnUyLxk0+cUj/eAtgJWehb04ZykMfOAcrNwlmGJboq+9sSDwwgPtpfgO4hS3zGcv6nNaqqU4trE1DpakEqMfVD88duB66Vp49gyLwX63EFbAsp3RkWTiW6G5WKwHaidhuuVywaX1WVszBpJoFlhACBMCVAwuwxopp9D13S4XWhUz8j4qq5eiOM9ge65eEDhwLxXbnMXHJSWopN6u0EkLH3MR+pJ+6UXiBlybKeA1/m4TwZ5IsWaHlQvJoI= X-MS-TrafficTypeDiagnostic: PR3PR03MB6556: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KwwqnjHdI2eACy+lv4+Plazep78V94OIyBppjb6Pw5YjhqTQT9lF5oyTxXaDIPS7CnJMqpkHeQu15OyVA11QwNEo66wKCurpjqbYdx3lT34tZnSheSX1I4VLDCBgTuriS+VwRxRrsHBhTqoya5fjONHQQonES0VCMtvIcc/O9dbZu2QTmNiZvPjaBYwf0SJ08rniL1NYLYZeodwcvMYmxvxDby83TKTwR5hwgNQDQLH1I0W66sgItvSWLtBc8i1CfOMGKtUQmJ+4YKB/XbIlQtYgbpgFmPDNyY0I11LCvkRmeJfe+L3SWal2+2Jpi91Gf296UHjvxYZgDdHJgc/UO6rPJ4tKCgGrlU+AlV4AiUNOeZ2+X71tPheTjE4UQxal+v1U2Ant1NuZEBsGeBbvjt9SoZHDATeSPEMEZjlPeJzD1rpFNEyc6j0k1zB1mCn8 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8zi93VImolcHbeoISkoNK/FleYOxqPEYswZt4a4jcUN2TGPL3HsHcYp+UImo8TnVWmmPAy+0cyskhO5r6TytRjmpah53eEp5TzVmXAKc+0rvbr4bStWSk1wLxsYknj6LItMBSYuAm8XnQxDARlCQRg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb0c0a0a-a24a-4600-631d-08d973abfbeb X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 16:07:55.5562 (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: PR3PR03MB6556 Subject: [FFmpeg-devel] [PATCH 15/16] avcodec/qsvenc: Fix memleaks upon allocation errors 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: dvnlJhZnEIx3 Fixes leaks in case the allocation of the H.264-specific stuff fails. Fixes Coverity issues #1442911 and #1442914. Signed-off-by: Andreas Rheinhardt --- Sending this as part of the other patchset so that fate doesn't fail. It is of course completely separate. libavcodec/qsvenc.c | 49 +++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 090fdbe75e..bd4e8fd8cd 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1417,10 +1417,10 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, const AVFrame *frame) { AVPacket new_pkt = { 0 }; - mfxBitstream *bs; + mfxBitstream *bs = NULL; #if QSV_VERSION_ATLEAST(1, 26) - mfxExtAVCEncodedFrameInfo *enc_info; - mfxExtBuffer **enc_buf; + mfxExtAVCEncodedFrameInfo *enc_info = NULL; + mfxExtBuffer **enc_buf = NULL; #endif mfxFrameSurface1 *surf = NULL; @@ -1454,10 +1454,8 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, } bs = av_mallocz(sizeof(*bs)); - if (!bs) { - av_packet_unref(&new_pkt); - return AVERROR(ENOMEM); - } + if (!bs) + goto nomem; bs->Data = new_pkt.data; bs->MaxLength = new_pkt.size; @@ -1465,14 +1463,14 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, if (avctx->codec_id == AV_CODEC_ID_H264) { enc_info = av_mallocz(sizeof(*enc_info)); if (!enc_info) - return AVERROR(ENOMEM); + goto nomem; enc_info->Header.BufferId = MFX_EXTBUFF_ENCODED_FRAME_INFO; enc_info->Header.BufferSz = sizeof (*enc_info); bs->NumExtParam = 1; enc_buf = av_mallocz(sizeof(mfxExtBuffer *)); if (!enc_buf) - return AVERROR(ENOMEM); + goto nomem; enc_buf[0] = (mfxExtBuffer *)enc_info; bs->ExtParam = enc_buf; @@ -1484,17 +1482,8 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, } sync = av_mallocz(sizeof(*sync)); - if (!sync) { - av_freep(&bs); - #if QSV_VERSION_ATLEAST(1, 26) - if (avctx->codec_id == AV_CODEC_ID_H264) { - av_freep(&enc_info); - av_freep(&enc_buf); - } - #endif - av_packet_unref(&new_pkt); - return AVERROR(ENOMEM); - } + if (!sync) + goto nomem; do { ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf, bs, sync); @@ -1506,27 +1495,22 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, ff_qsv_print_warning(avctx, ret, "Warning during encoding"); if (ret < 0) { - av_packet_unref(&new_pkt); - av_freep(&bs); -#if QSV_VERSION_ATLEAST(1, 26) - if (avctx->codec_id == AV_CODEC_ID_H264) { - av_freep(&enc_info); - av_freep(&enc_buf); - } -#endif - av_freep(&sync); - return (ret == MFX_ERR_MORE_DATA) ? + ret = (ret == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_print_error(avctx, ret, "Error during encoding"); + goto free; } if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame) print_interlace_msg(avctx, q); + ret = 0; + if (*sync) { av_fifo_generic_write(q->async_fifo, &new_pkt, sizeof(new_pkt), NULL); av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL); av_fifo_generic_write(q->async_fifo, &bs, sizeof(bs), NULL); } else { +free: av_freep(&sync); av_packet_unref(&new_pkt); av_freep(&bs); @@ -1538,7 +1522,10 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, #endif } - return 0; + return ret; +nomem: + ret = AVERROR(ENOMEM); + goto free; } int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, From patchwork Thu Sep 9 16:07:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30094 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp658291iov; Thu, 9 Sep 2021 09:08:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9PmRVXR/ghif+02ND0NeySuNiVn1pHlMgHGn/iLOqCdKMUHJsu0br40qVb+qrmx6fygTT X-Received: by 2002:a17:906:843:: with SMTP id f3mr3359394ejd.468.1631203699383; Thu, 09 Sep 2021 09:08:19 -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 n6si718764edx.253.2021.09.09.09.08.17; Thu, 09 Sep 2021 09:08:19 -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=crp2ZP4A; 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 DEEA368A9BC; Thu, 9 Sep 2021 19:08:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2079.outbound.protection.outlook.com [40.92.91.79]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9657B68A9BD for ; Thu, 9 Sep 2021 19:07:58 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EOUW004q4nCNcuknX04fXQISyNwdGNtgb6UgAKQwsBkVcBct0U+RmpQObe/DCiezFOnnbuWDro9WYUaPzs7r+CLjCxyL47UF6QK6yHz409nmPQxW+9ncChVvZtB2uEqmpr4Vv88vNpbRtNI7qX0/w48thJonRRnRspG+5ImKP3FY5zfrW5nUwrZ8dZQSEvO8xXjrXOFvfiMJO4KwRITF6kXkm7Hq/Z8m3Y3qLi6I8f5hcA3NPCnDQFke3wKnH/BSUwSEbNE4JYr+OgIEK2IpVr9bAxgI29+FUsCVB+hvXs1EKOVgNbsiqiKeHTFC7DIHIfkXmqj8sYo09gy1luea+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; bh=w1HWuHLXSyLd66vNmHXydlaRbjbunRETNm7cWFsezFM=; b=hfAP/6zX5C2zDafiSUphluwWfgvS+N40auy8IunTo/g6F8fZ3KIY4FYeG1fwPWnmH6lYaQbppNZGx2sMQZxXOtJGYBsNPit1uOS+CC4DgIwlDKsujGGKi7Uj1+H/nx5RJxH7O5SCx/jtJCZCkVt60PWGM4NKfhQwlKp6XGGGxBEczkllIk5a2GZUdzla8xCuROBrxq/HKSd6o0fYjSA5fiZhFJhO5aHaleMfFhx5TvqO3ggsF4pbZtyM+Pj90igKQXxoR4KownD8T/meDj7VXF97CLD5U8oHh/t7lnsV0yICqU2tqEMkIioC4zeOuoYosJCAfBhez86VYXOSgkIE9A== 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=w1HWuHLXSyLd66vNmHXydlaRbjbunRETNm7cWFsezFM=; b=crp2ZP4A0dQS9kZ2V2dacUCUsGqXPYhoKcKMtvUCEH4oZjKCS2P1jcyiArp5MqrSArbW51Scr2/z2OZihQUw4iMSqmc278XvTi6ORq743BWGepR410Nrn1enRmjxl1CqtHSX3YIB9gLhisM1NK4gbf+/gpx6EyRSuHCITxe3ZLViMCRpf+apwcR4IDKAeU5CrzDzNckz6/7Ki+QN/dNhltkYJPYktJkMdB5izULDHwQTYCietteVpNbIcEk8fBNvJpT48y0AIjhw6AaDg/a0oXSaH7NjBstwlhBMzuc2mH7FUTPJnImh5CA5JV1PsTna7l+PA46IXbvQTYGnprs91Q== Received: from PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) by PR3PR03MB6379.eurprd03.prod.outlook.com (2603:10a6:102:71::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.22; Thu, 9 Sep 2021 16:07:57 +0000 Received: from PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0]) by PR3PR03MB6665.eurprd03.prod.outlook.com ([fe80::2924:e83a:49ed:92f0%5]) with mapi id 15.20.4478.025; Thu, 9 Sep 2021 16:07:57 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 18:07:47 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [Ap8tP8VGqKWPGBskQu+6A6qJAizxii2n] X-ClientProxiedBy: PR0P264CA0283.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1::31) To PR3PR03MB6665.eurprd03.prod.outlook.com (2603:10a6:102:7d::6) X-Microsoft-Original-Message-ID: <20210909160747.1841811-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by PR0P264CA0283.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 16:07:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0f293699-9075-4bb2-32df-08d973abfd05 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXImq1sWRAABPXhZ8q25ZjY4gJdSlowUYb5b3hrWoHJbgr0ZhpSS4yDTsBN9vhp2TVYfEp5LE7BR5yiMkap/o1yRboUIiIDELJc6Z3Jocv7gdYVOZFxRZlxF3ulwrOVoZf9E+lSD5mwSNHgFDYDvFaMUfH2Lu+ZrEdCY1lmXp4OJ4YGiPKy5qmrnyhNybIweOy/2DJi4YW5U8vIK4DStRCriPZ5xvifxf3RrYUwAQ1b9COvSvC+0fptTJEx8w0de27CCDDXnRYxp+PsHfWkf5Yla/H6Vz9IHrg79FkE3HogJaH3GcIR+Zr++OG7p4oEQ2KvQnKptAZQsNYaSvT5Q/uByqAeHzZsVgUu0wOlA3aUPI3677sgG1rqaksNrpRCqI277XgJEVlVCuLJEd82SUVwkjWx9m9syW82P16dkncrdBcE5aFP2TwxZdAqF4nwihcr2BixDRv29mT2vSYOFnvThbSt5LOWB/OroYYKTOvEroL0IgJzT+XTewdjaKq8jqOkrMHKGqbH5czWuHUd7/9hyAALcE2hCu41/Cp8Mq9S/s20/yiON2EAao6xbiUJ7mzTFr72CcnrIZPl45Wc42/CFDavKOZAiVaFSUHJK5FIiHzL0cANovEsABAQEZ5HfuUQ68tMYAr5ynPj9mJAccjX2sPqW+FP2Sxbx4dKQILZHr0erRn17yQX/ccw63FMQIVu7fda1KCiDOzK/RhPiSffgCM2SevGsww= X-MS-TrafficTypeDiagnostic: PR3PR03MB6379: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qKYkKgteMWb+5zpO7XMazN4UMTUs+icHZ7FxDmsDdS88n6244T8q/TWBJ+BGIyNK0fkMLNdEBxrbwTjizEMdX3NBX69T1YpSZo6Wo+rGHUSt8WBjVKee6idcQYFczikSqE0Y3CQar5OVWD+nQd2vg/H4+rYJ6TORPL9d8HhVhBU9tz2Oak39usJuyfqx+WzMQGickx+vE32N8L7w6D5YzxfuLAW347G9WLRbtAq11FDewL7GTT5HHaU5YuqzqG+u3VXmAjNMLodDtVGR3asprlpfOXWO/bse3sx0RM6wmuRu5nEz1IBwa2EDAjE+lE0WAwHTut8aYGJ3uyatYuPm//iFCmQAhv59DqFJK8TJorXL22wZ9/8Jle1lPojJxY0Z3z9JzxLrgoVbxaDyNAVFMgcyEjlhrd/vJF6Fh3Z+dVLG1Y5zrv+P6SHiVEJOB4m/ X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rs2I0cvn8LNvxN+Smwsx5a0dlZtLtCNDTNKTZUu1NWelfYUxiVGKDzPIs20gyk6IER+Mh4PPwFrUE+R9c9cFvzBrmzal90vtoHvWa0AzwW77xh4DyfD8F2JuovWWNs3QvOKa25e8uXM9MBDpYRbrAA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f293699-9075-4bb2-32df-08d973abfd05 X-MS-Exchange-CrossTenant-AuthSource: PR3PR03MB6665.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 16:07:57.3503 (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: PR3PR03MB6379 Subject: [FFmpeg-devel] [PATCH 16/16] avcodec/qsvenc: Remove dead code for user-provided buffers 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: 3UWgLhE6VEEk Dead since commit 93016f5d1d280f9cb7856883af287fa66affc04c which ensured that the packets received by encoders are always blank. Signed-off-by: Andreas Rheinhardt --- libavcodec/qsvenc.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index bd4e8fd8cd..3ae496bc56 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1590,23 +1590,7 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, av_freep(&bs); av_freep(&sync); - if (pkt->data) { - if (pkt->size < new_pkt.size) { - av_log(avctx, AV_LOG_ERROR, "Submitted buffer not large enough: %d < %d\n", - pkt->size, new_pkt.size); - av_packet_unref(&new_pkt); - return AVERROR(EINVAL); - } - - memcpy(pkt->data, new_pkt.data, new_pkt.size); - pkt->size = new_pkt.size; - - ret = av_packet_copy_props(pkt, &new_pkt); - av_packet_unref(&new_pkt); - if (ret < 0) - return ret; - } else - *pkt = new_pkt; + av_packet_move_ref(pkt, &new_pkt); *got_packet = 1; }