From patchwork Wed Dec 4 12:37:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16587 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D7776449DB0 for ; Wed, 4 Dec 2019 14:37:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BC46368A3CA; Wed, 4 Dec 2019 14:37:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2315968A3B2 for ; Wed, 4 Dec 2019 14:37:24 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id b6so8465511wrq.0 for ; Wed, 04 Dec 2019 04:37:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=g/dLMpj287Lpd2A7gzXR4eZPPMYFRscP0ftwM3FpRbE=; b=eoxsMRqejrM7zLJ2qAH5AjNsb4SVHIvG8G92tqQ/Q7f+9tqS5NUtj02dl4gY0/X/kJ eF+QxroEb1YG86lAgvyFX/oxYmxjeTdN1rbznbFe51qciSpxD+iWmqdcDClZMSFxmGrA AQhXWAJtA7vVSRlathPbvIZ4g1GaRPRNCEVGy2JwZwkkxMojvWv7++qgcBkdyXidYNuq l4TSVoj/vUUndNEsCacGbmmVIcs54px5+hFemFSlOBzgTFoaGH3oLQTQbEj6rZFjNAWJ UFZlMP/BPywRVyZQXcLJWDqubBttwwjK6r5/ilViRmIPP4JhKf0QtLulV1qqNxkB7lPr SJ8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=g/dLMpj287Lpd2A7gzXR4eZPPMYFRscP0ftwM3FpRbE=; b=OR/gxObsH44tJ2rJVLFFcfDATGnDQn4feL9e8oDeNE1QxIH4EsjVhw1irGdKn709js J8nTpkWhrbn6OzUtMGnCLRuBqeKp2I1A5lWRrgvDU4O9k/+/temzFNP1QqHwAA/XTf0O mOw9VylkIjfZD9tBWu+uYVd2UGxDfWEpxoTuTju2bvfve5sbo7NuewOH0BToH3n9heLK /LoOXVlGqK9gQ1XuM5RTjVrpUrzs6RsCBnmmZZAXcuWMb1nupXlpmWyYBEL0tP9EYlA7 QfVzRq01Bo6wazVmeu5yswCnn99afCvP9MFvIZ3HhE49bLB/1ihBoyKH08R3GgdBJwxc sRNA== X-Gm-Message-State: APjAAAWb6fSUqT5S5JN5ThKkEtbjG8HHOr/Ga7wrEDUdFMPbo2Q0U8YZ p0AfaHUOkHRT7FrguGwZcLjOeTls X-Google-Smtp-Source: APXvYqzYZHRLbBnkWH9Uy/hSF6P2KTpqaBHvmO1yANyYQcpIAZsIjRWsXR+0+v0FlwKdzD6UULm9Fw== X-Received: by 2002:a5d:404b:: with SMTP id w11mr4025468wrp.171.1575463043425; Wed, 04 Dec 2019 04:37:23 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08e23.dynamic.kabel-deutschland.de. [188.192.142.35]) by smtp.gmail.com with ESMTPSA id v15sm6295872wmh.24.2019.12.04.04.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2019 04:37:22 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Dec 2019 13:37:12 +0100 Message-Id: <20191204123714.27765-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/mpeg: Make VobSub demuxer have its own context struct X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" When the VobSub demuxer was added, the fields it required were simply added to the MpegDemuxContext (if the VobSub demuxer was selected at all). The mpeg demuxer of course doesn't use these fields even if they are there; and the VobSub demuxer doesn't use the old ones: It opens an mpeg subdemuxer of its own and uses this where a mpeg demuxer is required. Hence the two contexts can be split, saving memory. Furthermore several headers can now be moved to the section that is guarded by #if CONFIG_VOBSUB_DEMUXER (this even includes avassert.h which was unguarded and has been added in 9cde9f70 despite not being used in that patch). Signed-off-by: Andreas Rheinhardt --- libavformat/mpeg.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index 46c59163fd..80983f8a81 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -24,14 +24,6 @@ #include "internal.h" #include "mpeg.h" -#if CONFIG_VOBSUB_DEMUXER -# include "subtitles.h" -# include "libavutil/bprint.h" -# include "libavutil/opt.h" -#endif - -#include "libavutil/avassert.h" - /*********************************************/ /* demux code */ @@ -123,18 +115,12 @@ static int mpegps_probe(const AVProbeData *p) } typedef struct MpegDemuxContext { - AVClass *class; int32_t header_state; unsigned char psm_es_type[256]; int sofdec; int dvd; int imkh_cctv; int raw_ac3; -#if CONFIG_VOBSUB_DEMUXER - AVFormatContext *sub_ctx; - FFDemuxSubtitlesQueue q[32]; - char *sub_name; -#endif } MpegDemuxContext; static int mpegps_read_header(AVFormatContext *s) @@ -705,9 +691,21 @@ AVInputFormat ff_mpegps_demuxer = { #if CONFIG_VOBSUB_DEMUXER +#include "subtitles.h" +#include "libavutil/avassert.h" +#include "libavutil/bprint.h" +#include "libavutil/opt.h" + #define REF_STRING "# VobSub index file," #define MAX_LINE_SIZE 2048 +typedef struct VobSubDemuxContext { + const AVClass *class; + AVFormatContext *sub_ctx; + FFDemuxSubtitlesQueue q[32]; + char *sub_name; +} VobSubDemuxContext; + static int vobsub_probe(const AVProbeData *p) { if (!strncmp(p->buf, REF_STRING, sizeof(REF_STRING) - 1)) @@ -718,7 +716,7 @@ static int vobsub_probe(const AVProbeData *p) static int vobsub_read_header(AVFormatContext *s) { int i, ret = 0, header_parsed = 0, langidx = 0; - MpegDemuxContext *vobsub = s->priv_data; + VobSubDemuxContext *vobsub = s->priv_data; size_t fname_len; char *header_str = NULL; AVBPrint header; @@ -911,7 +909,7 @@ end: static int vobsub_read_packet(AVFormatContext *s, AVPacket *pkt) { - MpegDemuxContext *vobsub = s->priv_data; + VobSubDemuxContext *vobsub = s->priv_data; FFDemuxSubtitlesQueue *q; AVIOContext *pb = vobsub->sub_ctx->pb; int ret, psize, total_read = 0, i; @@ -999,7 +997,7 @@ fail: static int vobsub_read_seek(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags) { - MpegDemuxContext *vobsub = s->priv_data; + VobSubDemuxContext *vobsub = s->priv_data; /* Rescale requested timestamps based on the first stream (timebase is the * same for all subtitles stream within a .idx/.sub). Rescaling is done just @@ -1031,8 +1029,8 @@ static int vobsub_read_seek(AVFormatContext *s, int stream_index, static int vobsub_read_close(AVFormatContext *s) { + VobSubDemuxContext *vobsub = s->priv_data; int i; - MpegDemuxContext *vobsub = s->priv_data; for (i = 0; i < s->nb_streams; i++) ff_subtitles_queue_clean(&vobsub->q[i]); @@ -1042,7 +1040,7 @@ static int vobsub_read_close(AVFormatContext *s) } static const AVOption options[] = { - { "sub_name", "URI for .sub file", offsetof(MpegDemuxContext, sub_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, + { "sub_name", "URI for .sub file", offsetof(VobSubDemuxContext, sub_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, { NULL } }; @@ -1056,7 +1054,7 @@ static const AVClass vobsub_demuxer_class = { AVInputFormat ff_vobsub_demuxer = { .name = "vobsub", .long_name = NULL_IF_CONFIG_SMALL("VobSub subtitle format"), - .priv_data_size = sizeof(MpegDemuxContext), + .priv_data_size = sizeof(VobSubDemuxContext), .read_probe = vobsub_probe, .read_header = vobsub_read_header, .read_packet = vobsub_read_packet,