From patchwork Fri Aug 27 14:27:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29819 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1514417iov; Fri, 27 Aug 2021 07:31:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbZ2g8RlSA/z1ZnhEuyfTY5DoPnnGUCP9vL93NPEfMwI3x8SPUWsSR2kahC54UfGvBgZuZ X-Received: by 2002:a17:906:d183:: with SMTP id c3mr10248328ejz.283.1630074661187; Fri, 27 Aug 2021 07:31:01 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w13si4162171ede.473.2021.08.27.07.31.00; Fri, 27 Aug 2021 07:31:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=mauCNJGX; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AB74368A447; Fri, 27 Aug 2021 17:28:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067023.outbound.protection.outlook.com [40.92.67.23]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D503068A2DE for ; Fri, 27 Aug 2021 17:28:00 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U9mZyMF/koWM6xyrvAgzYDJEsVsnnH9BN70X4o145cRhTTq5yGxJnXxkCIFYRX+eCG8qLn0enco41uJMK9IUItbpz+4jaBHvfolvvLNSGWpGtVs30sHj8xUjsHrlwutm6D0jtab53/V3p1MOJ+NxpslgPOx+pbN2+Duwh63FODTp9KOaWaOYR9nSVdFB7OPgXXz5Bg11Cx5XQYNQujjA9Dh3wFxj2dg91M9A5ZGfhFpvz6Vxvc8yahBrJ0lCxx0qnmnlpZMBzrQKK6PSMcECwS5VQxaipwozT2XYPrZ7X0dYGyWBcZM6W2CcLfRSRavZP3a/TN94cLXfes68jfQZvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0WOPqABQbBq2FePVUAgJ6r7Mx8WQY57uadUP+kQuBhY=; b=LHRcEWkWnFhD3kepgF612+4T5cR6bkHRX67STCZ8adLsRQLd0hkJ5Bqauy4yh19zq8GjO/g6bpwBkYIZcJmMUN1mITfOnzGYSCjQzspG0KcYFoS2FkAV5bLo+BvNiFb+cILpvXR7JR8YIi9n9IlkKzBaUIvlDjxk8gCsL3LOq/DmTJ+SpL9Ntb4aMgQ6RG2MgT2P4KS4TG/qZZR+NbeqmbElJ5KoXGQUICKJFTQgJL55cNMojanrJZguu5HypBSoJcTlvUMkI6pacohLJozBfdh3HAKAwnoZ8up5YRbc9IAHdAD1fWXs6Ytw9LbZ5335lPaNpDP0c3Ib4XNhxUxvIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0WOPqABQbBq2FePVUAgJ6r7Mx8WQY57uadUP+kQuBhY=; b=mauCNJGX/g/aHfqVLkojBuJBUNbdOID4sji9DXAR+VNwUjKYS3BYLJSkymbQuoik5dq6PJwxi4jtM60nI0csS6lmQ5R9ojvNhDxrCW+JHvdQmq+SckVxwQNbdZTI8zkcCdCMirT2hu8Uzr9feCT4UGNdOF6p2i8FrfdJNb1xaNDehdn7qJzPS0oBoXtVslaI/nQiCXlD58io+qETPTSo2BETWv+lqixLzPjqDkCL4J/+mfcrqOr1gmdjNCswpXg2IMeeZYc8+jkKc4F6/kkp8GDgqDFPbb1Bo1FW6L+M+R0HkgR3D14K2RxBtFoJNSMxOeDPjoXTHizIwpRkK7DwOg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3861.eurprd03.prod.outlook.com (2603:10a6:20b:22::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Fri, 27 Aug 2021 14:27:58 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:58 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:19 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [cxj9rgAe9BJv1g+vojSLGZSjSiTFTbSh] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-18-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0943c129-f42e-4742-e436-08d96966de42 X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEtNCKoPT6rtVE5PzvjguT+vwxgZMDl0eQmh84nWdXI8Z4nf8rddsZuxA5LwMVXiJctLGFtfH9nU/04Qvdk/7YtW0yLA8+YOPnWpvV4K4KRBAEXjza0kK9KKQrCCRD/oInr6pfXHDkgZBgieFSsUg3T4f9GZoN/Nx2aAyrUH2jsw1EuCBX6nalr82ZrRnUDQ8OTbcFg4CuR8eOIOXvqggzEqCDVpARSP0DzQtFpoencHhavVNKgYLIFonKaP/YZ8o+4XMRAp9cY1s/D7HJb+8bAoYN5+VlaUVF9l++qLC63aJH1tMxPpl8ggZ+rl08EiO+n3VfVYZYSbipIk+OAtPfxONjNuZQQK6fzi+9zVPNhCalxpPC/Fr0oMCLJMM366YRzqSSXG5KygMyXCvTDteU9oKTCzCCvcZZwxnxchk+mi6ONAG4A3XLnZ1/6+HnGHh1ckHYw+O3UYvJz/QgoeAHHJz/V1qIWtq/sSTq5lOh7KFT4HHJ8VVilRc6E/FTzQJc5axFPPBOKNMB0ogZaTqdeZnNZhwFLsZGcn92clx2Uxt4iBCt5dhCVSXdzUdpBazOv3msZzFUiafDEKRCkatD1C8hdgCzgbuzMwEciNM//r+CNA3qzDGqcp5+nRiUzeWY9+AqIrGiIlnfB27xLfs6RF2q0Egs8U16+gZ/2H1UDxQeEH2srLadmxviWvs3OUWkuRM/+n9a7wBhizw7cpXaNOtARVNsNDrT+O91CycjA9bw6EjeJF3eS7tQAik1j8z68RvBxIeLSxMUYkOOHVZ+Xg X-MS-TrafficTypeDiagnostic: AM6PR03MB3861: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GES4iTmLXQR1bntl+RMVhTIIj38uhJIMcrGbIcJ4CLpqO4ldmC5eqL7YAJ+hG0lMv7OCksIAlsvN4CQGB9nQEDnTEI34+fdjkppP7MXtu3I1MKRbNU4b2u3OVpXaTHiioqKHMnUlYcj9LrSF6hM8vnGnoRLDJ3MHkfYEKbp9PwET+LIZAiGtJoPhvHtPHcMM787NYQmnpcaXFWYRWgs5/4Qzk6ItiPneUmcnP2xBN72F4YSsPUEeVbvzR2nXDFhu/vvMQREcFmPL3pG1XzSzbP5F5kjbv0tr2jyKK8DL5j/X9Jjxn8UOcvhvcnMwO1C/eHpfbpFChDyu8UksnqJ5nkHg0nWDBb2tXxTRXcF7v8GtEUb4CptIIICkZBExF/Eg733mhKGzWzSdYYYs3J+++ZU8pPRN9+TVQSEtuE4OmfJgfyBJqqPKyiXyuO2qJyXN X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bO3mSqMsW6WJ9/BW88LeNK2M9vxcrCaSLAt/zlUUbjwkNGbfCwozK5MoLInv9ZadNPNLp45f1GSWOmmJCtojkflAD6iwnyvBwQaGb3X4z0/z/7O+SUzJOjCs7xLlhl0JpeJC5pCKB42yx6ZyHwhj3Q== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0943c129-f42e-4742-e436-08d96966de42 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:58.8950 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR03MB3861 Subject: [FFmpeg-devel] [PATCH 19/25] avformat/mux, mxfenc, utils: Use dedicated pointer for AVFormatInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: XoCPQd+Sj7bc This gets rid of ugly "->internal" and is in preparation for removing AVFormatInternal altogether. Signed-off-by: Andreas Rheinhardt --- libavformat/mux.c | 80 +++++++++++++------------- libavformat/mxfenc.c | 15 ++--- libavformat/utils.c | 133 ++++++++++++++++++++++++------------------- 3 files changed, 124 insertions(+), 104 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index a05deb3f0b..036a1956f6 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -433,10 +433,11 @@ static void flush_if_needed(AVFormatContext *s) static void deinit_muxer(AVFormatContext *s) { - if (s->oformat && s->oformat->deinit && s->internal->initialized) + AVFormatInternal *const si = s->internal; + if (s->oformat && s->oformat->deinit && si->initialized) s->oformat->deinit(s); - s->internal->initialized = - s->internal->streams_initialized = 0; + si->initialized = + si->streams_initialized = 0; } int avformat_init_output(AVFormatContext *s, AVDictionary **options) @@ -462,8 +463,9 @@ int avformat_init_output(AVFormatContext *s, AVDictionary **options) int avformat_write_header(AVFormatContext *s, AVDictionary **options) { int ret = 0; - int already_initialized = s->internal->initialized; - int streams_already_initialized = s->internal->streams_initialized; + AVFormatInternal *const si = s->internal; + int already_initialized = si->initialized; + int streams_already_initialized = si->streams_initialized; if (!already_initialized) if ((ret = avformat_init_output(s, options)) < 0) @@ -482,7 +484,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_UNKNOWN); - if (!s->internal->streams_initialized) { + if (!si->streams_initialized) { if ((ret = init_pts(s)) < 0) goto fail; } @@ -650,20 +652,21 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (s->avoid_negative_ts > 0) { + AVFormatInternal *const si = s->internal; AVStream *st = s->streams[pkt->stream_index]; int64_t offset = st->internal->mux_ts_offset; - int64_t ts = s->internal->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; + int64_t ts = si->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; - if (s->internal->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE && + if (si->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE && (ts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) { - s->internal->offset = -ts; - s->internal->offset_timebase = st->time_base; + si->offset = -ts; + si->offset_timebase = st->time_base; } - if (s->internal->offset != AV_NOPTS_VALUE && !offset) { + if (si->offset != AV_NOPTS_VALUE && !offset) { offset = st->internal->mux_ts_offset = - av_rescale_q_rnd(s->internal->offset, - s->internal->offset_timebase, + av_rescale_q_rnd(si->offset, + si->offset_timebase, st->time_base, AV_ROUND_UP); } @@ -673,7 +676,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) if (pkt->pts != AV_NOPTS_VALUE) pkt->pts += offset; - if (s->internal->avoid_negative_ts_use_pts) { + if (si->avoid_negative_ts_use_pts) { if (pkt->pts != AV_NOPTS_VALUE && pkt->pts < 0) { av_log(s, AV_LOG_WARNING, "failed to avoid negative " "pts %s in stream %d.\n" @@ -786,6 +789,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *)) { int ret; + AVFormatInternal *const si = s->internal; PacketList **next_point, *this_pktl; AVStream *st = s->streams[pkt->stream_index]; int chunked = s->max_chunk_size || s->max_chunk_duration; @@ -807,7 +811,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (st->internal->last_in_packet_buffer) { next_point = &(st->internal->last_in_packet_buffer->next); } else { - next_point = &s->internal->packet_buffer; + next_point = &si->packet_buffer; } if (chunked) { @@ -831,7 +835,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (chunked && !(pkt->flags & CHUNK_START)) goto next_non_null; - if (compare(s, &s->internal->packet_buffer_end->pkt, pkt)) { + if (compare(s, &si->packet_buffer_end->pkt, pkt)) { while ( *next_point && ((chunked && !((*next_point)->pkt.flags&CHUNK_START)) || !compare(s, &(*next_point)->pkt, pkt))) @@ -839,12 +843,12 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (*next_point) goto next_non_null; } else { - next_point = &(s->internal->packet_buffer_end->next); + next_point = &(si->packet_buffer_end->next); } } av_assert1(!*next_point); - s->internal->packet_buffer_end = this_pktl; + si->packet_buffer_end = this_pktl; next_non_null: this_pktl->next = *next_point; @@ -887,6 +891,7 @@ static int interleave_compare_dts(AVFormatContext *s, const AVPacket *next, int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { + AVFormatInternal *const si = s->internal; int stream_count = 0; int noninterleaved_count = 0; int ret; @@ -907,15 +912,15 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } } - if (s->internal->nb_interleaved_streams == stream_count) + if (si->nb_interleaved_streams == stream_count) flush = 1; if (s->max_interleave_delta > 0 && - s->internal->packet_buffer && + si->packet_buffer && !flush && - s->internal->nb_interleaved_streams == stream_count+noninterleaved_count + si->nb_interleaved_streams == stream_count+noninterleaved_count ) { - AVPacket *top_pkt = &s->internal->packet_buffer->pkt; + AVPacket *const top_pkt = &si->packet_buffer->pkt; int64_t delta_dts = INT64_MIN; int64_t top_dts = av_rescale_q(top_pkt->dts, s->streams[top_pkt->stream_index]->time_base, @@ -943,31 +948,31 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } } - if (s->internal->packet_buffer && + if (si->packet_buffer && eof && (s->flags & AVFMT_FLAG_SHORTEST) && - s->internal->shortest_end == AV_NOPTS_VALUE) { - AVPacket *top_pkt = &s->internal->packet_buffer->pkt; + si->shortest_end == AV_NOPTS_VALUE) { + AVPacket *const top_pkt = &si->packet_buffer->pkt; - s->internal->shortest_end = av_rescale_q(top_pkt->dts, + si->shortest_end = av_rescale_q(top_pkt->dts, s->streams[top_pkt->stream_index]->time_base, AV_TIME_BASE_Q); } - if (s->internal->shortest_end != AV_NOPTS_VALUE) { - while (s->internal->packet_buffer) { - PacketList *pktl = s->internal->packet_buffer; + if (si->shortest_end != AV_NOPTS_VALUE) { + while (si->packet_buffer) { + PacketList *pktl = si->packet_buffer; AVPacket *const top_pkt = &pktl->pkt; AVStream *const st = s->streams[top_pkt->stream_index]; int64_t top_dts = av_rescale_q(top_pkt->dts, st->time_base, AV_TIME_BASE_Q); - if (s->internal->shortest_end + 1 >= top_dts) + if (si->shortest_end + 1 >= top_dts) break; - s->internal->packet_buffer = pktl->next; - if (!s->internal->packet_buffer) - s->internal->packet_buffer_end = NULL; + si->packet_buffer = pktl->next; + if (!si->packet_buffer) + si->packet_buffer_end = NULL; if (st->internal->last_in_packet_buffer == pktl) st->internal->last_in_packet_buffer = NULL; @@ -979,14 +984,13 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } if (stream_count && flush) { - PacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = si->packet_buffer; AVStream *const st = s->streams[pktl->pkt.stream_index]; - *out = pktl->pkt; - s->internal->packet_buffer = pktl->next; - if (!s->internal->packet_buffer) - s->internal->packet_buffer_end = NULL; + si->packet_buffer = pktl->next; + if (!si->packet_buffer) + si->packet_buffer_end = NULL; if (st->internal->last_in_packet_buffer == pktl) st->internal->last_in_packet_buffer = NULL; diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 229817dba6..36f334adbf 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3100,13 +3100,14 @@ static void mxf_deinit(AVFormatContext *s) static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { + AVFormatInternal *const si = s->internal; int i, stream_count = 0; for (i = 0; i < s->nb_streams; i++) stream_count += !!s->streams[i]->internal->last_in_packet_buffer; if (stream_count && (s->nb_streams == stream_count || flush)) { - PacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = si->packet_buffer; if (s->nb_streams != stream_count) { PacketList *last = NULL; // find last packet in edit unit @@ -3130,20 +3131,20 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket if (last) last->next = NULL; else { - s->internal->packet_buffer = NULL; - s->internal->packet_buffer_end= NULL; + si->packet_buffer = NULL; + si->packet_buffer_end = NULL; goto out; } - pktl = s->internal->packet_buffer; + pktl = si->packet_buffer; } *out = pktl->pkt; av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts); - s->internal->packet_buffer = pktl->next; + si->packet_buffer = pktl->next; if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == pktl) s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer= NULL; - if(!s->internal->packet_buffer) - s->internal->packet_buffer_end= NULL; + if (!si->packet_buffer) + si->packet_buffer_end = NULL; av_freep(&pktl); return 1; } else { diff --git a/libavformat/utils.c b/libavformat/utils.c index df11dc2517..67ec3384d0 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -457,12 +457,14 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options) { AVFormatContext *s = *ps; + AVFormatInternal *si; int ret = 0; AVDictionary *tmp = NULL; ID3v2ExtraMeta *id3v2_extra_meta = NULL; if (!s && !(s = avformat_alloc_context())) return AVERROR(ENOMEM); + si = s->internal; if (!s->av_class) { av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); return AVERROR(EINVAL); @@ -538,7 +540,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */ if (s->pb) - ff_id3v2_read_dict(s->pb, &s->internal->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); + ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); if (s->iformat->read_header) if ((ret = s->iformat->read_header(s)) < 0) { @@ -548,11 +550,11 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, } if (!s->metadata) { - s->metadata = s->internal->id3v2_meta; - s->internal->id3v2_meta = NULL; - } else if (s->internal->id3v2_meta) { + s->metadata = si->id3v2_meta; + si->id3v2_meta = NULL; + } else if (si->id3v2_meta) { av_log(s, AV_LOG_WARNING, "Discarding ID3 tags because more suitable tags were found.\n"); - av_dict_free(&s->internal->id3v2_meta); + av_dict_free(&si->id3v2_meta); } if (id3v2_extra_meta) { @@ -572,10 +574,10 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, if ((ret = avformat_queue_attached_pictures(s)) < 0) goto close; - if (s->pb && !s->internal->data_offset) - s->internal->data_offset = avio_tell(s->pb); + if (s->pb && !si->data_offset) + si->data_offset = avio_tell(s->pb); - s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; + si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; update_stream_avctx(s); @@ -741,6 +743,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in int ff_read_packet(AVFormatContext *s, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; AVStream *st; int err; @@ -755,18 +758,18 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif for (;;) { - PacketList *pktl = s->internal->raw_packet_buffer; + PacketList *pktl = si->raw_packet_buffer; const AVPacket *pkt1; if (pktl) { st = s->streams[pktl->pkt.stream_index]; - if (s->internal->raw_packet_buffer_remaining_size <= 0) + if (si->raw_packet_buffer_remaining_size <= 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; if (st->internal->request_probe <= 0) { - avpriv_packet_list_get(&s->internal->raw_packet_buffer, - &s->internal->raw_packet_buffer_end, pkt); - s->internal->raw_packet_buffer_remaining_size += pkt->size; + avpriv_packet_list_get(&si->raw_packet_buffer, + &si->raw_packet_buffer_end, pkt); + si->raw_packet_buffer_remaining_size += pkt->size; return 0; } } @@ -837,15 +840,15 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!pktl && st->internal->request_probe <= 0) return 0; - err = avpriv_packet_list_put(&s->internal->raw_packet_buffer, - &s->internal->raw_packet_buffer_end, + err = avpriv_packet_list_put(&si->raw_packet_buffer, + &si->raw_packet_buffer_end, pkt, NULL, 0); if (err < 0) { av_packet_unref(pkt); return err; } - pkt1 = &s->internal->raw_packet_buffer_end->pkt; - s->internal->raw_packet_buffer_remaining_size -= pkt1->size; + pkt1 = &si->raw_packet_buffer_end->pkt; + si->raw_packet_buffer_remaining_size -= pkt1->size; if ((err = probe_codec(s, st, pkt1)) < 0) return err; @@ -957,10 +960,11 @@ static int has_decode_delay_been_guessed(AVStream *st) static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pktl) { + AVFormatInternal *const si = s->internal; if (pktl->next) return pktl->next; - if (pktl == s->internal->packet_buffer_end) - return s->internal->parse_queue; + if (pktl == si->packet_buffer_end) + return si->parse_queue; return NULL; } @@ -1038,8 +1042,9 @@ static void update_dts_from_pts(AVFormatContext *s, int stream_index, static void update_initial_timestamps(AVFormatContext *s, int stream_index, int64_t dts, int64_t pts, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; AVStream *st = s->streams[stream_index]; - PacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; PacketList *pktl_it; uint64_t shift; @@ -1091,7 +1096,8 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, static void update_initial_durations(AVFormatContext *s, AVStream *st, int stream_index, int64_t duration) { - PacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + AVFormatInternal *const si = s->internal; + PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; int64_t cur_dts = RELATIVE_TS_BASE; if (st->internal->first_dts != AV_NOPTS_VALUE) { @@ -1117,7 +1123,7 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(st->internal->first_dts)); return; } - pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; st->internal->first_dts = cur_dts; } else if (st->internal->cur_dts != RELATIVE_TS_BASE) return; @@ -1339,7 +1345,8 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index, int flush) { - AVPacket *out_pkt = s->internal->parse_pkt; + AVFormatInternal *const si = s->internal; + AVPacket *out_pkt = si->parse_pkt; AVStream *st = s->streams[stream_index]; uint8_t *data = pkt->data; int size = pkt->size; @@ -1425,8 +1432,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, compute_pkt_fields(s, st, st->internal->parser, out_pkt, next_dts, next_pts); - ret = avpriv_packet_list_put(&s->internal->parse_queue, - &s->internal->parse_queue_end, + ret = avpriv_packet_list_put(&si->parse_queue, + &si->parse_queue_end, out_pkt, NULL, 0); if (ret < 0) goto fail; @@ -1452,10 +1459,11 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts) static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; int ret, got_packet = 0; AVDictionary *metadata = NULL; - while (!got_packet && !s->internal->parse_queue) { + while (!got_packet && !si->parse_queue) { AVStream *st; /* read next packet */ @@ -1565,8 +1573,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } } - if (!got_packet && s->internal->parse_queue) - ret = avpriv_packet_list_get(&s->internal->parse_queue, &s->internal->parse_queue_end, pkt); + if (!got_packet && si->parse_queue) + ret = avpriv_packet_list_get(&si->parse_queue, &si->parse_queue_end, pkt); if (ret >= 0) { AVStream *st = s->streams[pkt->stream_index]; @@ -1639,15 +1647,16 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) int av_read_frame(AVFormatContext *s, AVPacket *pkt) { + AVFormatInternal *const si = s->internal; const int genpts = s->flags & AVFMT_FLAG_GENPTS; int eof = 0; int ret; AVStream *st; if (!genpts) { - ret = s->internal->packet_buffer - ? avpriv_packet_list_get(&s->internal->packet_buffer, - &s->internal->packet_buffer_end, pkt) + ret = si->packet_buffer + ? avpriv_packet_list_get(&si->packet_buffer, + &si->packet_buffer_end, pkt) : read_frame_internal(s, pkt); if (ret < 0) return ret; @@ -1655,7 +1664,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) } for (;;) { - PacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = si->packet_buffer; if (pktl) { AVPacket *next_pkt = &pktl->pkt; @@ -1688,15 +1697,15 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) // 3. the packets for this stream at the end of the files had valid dts. next_pkt->pts = last_dts + next_pkt->duration; } - pktl = s->internal->packet_buffer; + pktl = si->packet_buffer; } /* read packet from packet buffer, if there is data */ st = s->streams[next_pkt->stream_index]; if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL && next_pkt->dts != AV_NOPTS_VALUE && !eof)) { - ret = avpriv_packet_list_get(&s->internal->packet_buffer, - &s->internal->packet_buffer_end, pkt); + ret = avpriv_packet_list_get(&si->packet_buffer, + &si->packet_buffer_end, pkt); goto return_packet; } } @@ -1710,8 +1719,8 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) return ret; } - ret = avpriv_packet_list_put(&s->internal->packet_buffer, - &s->internal->packet_buffer_end, + ret = avpriv_packet_list_put(&si->packet_buffer, + &si->packet_buffer_end, pkt, NULL, 0); if (ret < 0) { av_packet_unref(pkt); @@ -1738,11 +1747,12 @@ return_packet: /* XXX: suppress the packet queue */ static void flush_packet_queue(AVFormatContext *s) { - avpriv_packet_list_free(&s->internal->parse_queue, &s->internal->parse_queue_end); - avpriv_packet_list_free(&s->internal->packet_buffer, &s->internal->packet_buffer_end); - avpriv_packet_list_free(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end); + AVFormatInternal *const si = s->internal; + avpriv_packet_list_free(&si->parse_queue, &si->parse_queue_end); + avpriv_packet_list_free(&si->packet_buffer, &si->packet_buffer_end); + avpriv_packet_list_free(&si->raw_packet_buffer, &si->raw_packet_buffer_end); - s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; + si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; } /*******************************************************/ @@ -3434,10 +3444,10 @@ fail: return ret; } -static int extract_extradata(AVFormatContext *s, AVStream *st, const AVPacket *pkt) +static int extract_extradata(AVFormatInternal *si, AVStream *st, const AVPacket *pkt) { AVStreamInternal *sti = st->internal; - AVPacket *pkt_ref = s->internal->parse_pkt; + AVPacket *pkt_ref = si->parse_pkt; int ret; if (!sti->extract_extradata.inited) { @@ -3498,9 +3508,10 @@ static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { + AVFormatInternal *const si = ic->internal; int count = 0, ret = 0; int64_t read_size; - AVPacket *pkt1 = ic->internal->pkt; + AVPacket *pkt1 = si->pkt; int64_t old_offset = avio_tell(ic->pb); // new streams might appear, no options for those int orig_nb_streams = ic->nb_streams; @@ -3698,13 +3709,13 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { - ret = avpriv_packet_list_put(&ic->internal->packet_buffer, - &ic->internal->packet_buffer_end, + ret = avpriv_packet_list_put(&si->packet_buffer, + &si->packet_buffer_end, pkt1, NULL, 0); if (ret < 0) goto unref_then_goto_end; - pkt = &ic->internal->packet_buffer_end->pkt; + pkt = &si->packet_buffer_end->pkt; } else { pkt = pkt1; } @@ -3808,7 +3819,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) st->internal->info->frame_delay_evidence = 1; } if (!st->internal->avctx->extradata) { - ret = extract_extradata(ic, st, pkt); + ret = extract_extradata(si, st, pkt); if (ret < 0) goto unref_then_goto_end; } @@ -3851,14 +3862,14 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) // EOF already reached while reading the stream above. // So continue with reoordering DTS with whatever delay we have. - if (ic->internal->packet_buffer && !has_decode_delay_been_guessed(st)) { - update_dts_from_pts(ic, stream_index, ic->internal->packet_buffer); + if (si->packet_buffer && !has_decode_delay_been_guessed(st)) { + update_dts_from_pts(ic, stream_index, si->packet_buffer); } } } if (flush_codecs) { - AVPacket *empty_pkt = ic->internal->pkt; + AVPacket *empty_pkt = si->pkt; int err = 0; av_packet_unref(empty_pkt); @@ -3923,7 +3934,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) best_fps = std_fps.num; } - if (ic->internal->prefer_codec_framerate && codec_frame_rate.num > 0 && codec_frame_rate.den > 0) { + if (si->prefer_codec_framerate && codec_frame_rate.num > 0 && codec_frame_rate.den > 0) { error = fabs(av_q2d(codec_frame_rate) / av_q2d(std_fps) - 1); if (error < best_error) { @@ -4248,10 +4259,13 @@ void ff_free_stream(AVFormatContext *s, AVStream *st) void avformat_free_context(AVFormatContext *s) { + AVFormatInternal *si; + if (!s) return; + si = s->internal; - if (s->oformat && s->oformat->deinit && s->internal->initialized) + if (s->oformat && s->oformat->deinit && si->initialized) s->oformat->deinit(s); av_opt_free(s); @@ -4279,9 +4293,9 @@ void avformat_free_context(AVFormatContext *s) } av_freep(&s->chapters); av_dict_free(&s->metadata); - av_dict_free(&s->internal->id3v2_meta); - av_packet_free(&s->internal->pkt); - av_packet_free(&s->internal->parse_pkt); + av_dict_free(&si->id3v2_meta); + av_packet_free(&si->pkt); + av_packet_free(&si->parse_pkt); av_freep(&s->streams); flush_packet_queue(s); av_freep(&s->internal); @@ -4430,6 +4444,7 @@ AVProgram *av_new_program(AVFormatContext *ac, int id) AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title) { + AVFormatInternal *const si = s->internal; AVChapter *chapter = NULL; int ret; @@ -4439,9 +4454,9 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba } if (!s->nb_chapters) { - s->internal->chapter_ids_monotonic = 1; - } else if (!s->internal->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) { - s->internal->chapter_ids_monotonic = 0; + si->chapter_ids_monotonic = 1; + } else if (!si->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) { + si->chapter_ids_monotonic = 0; for (unsigned i = 0; i < s->nb_chapters; i++) if (s->chapters[i]->id == id) chapter = s->chapters[i];