From patchwork Fri Dec 3 14:57:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31912 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp779192iog; Fri, 3 Dec 2021 06:58:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMOMVZdeo8VTAPVGJFq0hWKK1oNo2aHK0ES9fXjt1RGMBXgRwh04h9P4wYGvuV2qBD+U93 X-Received: by 2002:a17:906:48cd:: with SMTP id d13mr23492601ejt.35.1638543489234; Fri, 03 Dec 2021 06:58:09 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id mq7si3714799ejc.19.2021.12.03.06.58.08; Fri, 03 Dec 2021 06:58:09 -0800 (PST) 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=@hotmail.com header.s=selector1 header.b=srt0FJ2s; 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=NONE dis=NONE) header.from=hotmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9961768AC65; Fri, 3 Dec 2021 16:58:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (unknown [40.92.47.71]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4F0AC6880FA for ; Fri, 3 Dec 2021 16:57:58 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=izTDmnzcdHD0kh9sqgq02uOvoPaHFffQ7tFVwKbmniCMUempaRb3tctcdgUMXdYrSG/ve/M27l8uI2x/pa3rQD1xEOgFHo7rsZSItmEPRn65tE29lJmFMbD/jAWL7KAyVzzZx8pKaC14Di/rYMca0TS8OAiNwb7oIb2BSfUGbXIReXMZrU7GlEP9a/GF4pnXUsI0gsdI+MgNrz1kQFum4ntYZQuonJuM/Gtar6L7gIM8LxrsEss03K5VtJkTPXbhBL23J2h04MSLhPZtSNocF+NJMTysT4tNNV+1HFqldwDFAsICVuUw0P9z8EwMkrXnABjkWFNcv7AccB7d0WP8eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Xjf9RD7GrOPLap8ZvaEeBmnb+T9I/tEEUp2YsTgtxbM=; b=jTvc8N6zmqqRXmkMV2z+1JkG93vzihJN9ScMOx14AxJwBDzQxo1dEL3fn+ZCyuFt3AngQtU9RCvHqa67gJLHCPp4BELY4YsprVvtpS6K6OE5dveECwD/DA6lNWeHmMafrNRnI/j4QI1B8P24mLIyTXopoYMdjDwtSzQ00z1Mg7BduSsn1wVRPioo5XMrscKXzh2sShPvVPxUaK54ysK9Keey3UXcj8gUAGw8q0CZ4DDB3jV1d48Ki3SlSECogYVNS8++OEpCpffCjzdODOEt4LaVMO6V8GPcq5TTGJZYaHo71TUiU46oWhGZvdsCNx4EdWNcZUyDKeXO9yWy6gSVYw== 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=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Xjf9RD7GrOPLap8ZvaEeBmnb+T9I/tEEUp2YsTgtxbM=; b=srt0FJ2semCSJ1/aXioaBvfdUGHl6GDb3WEcw3TqF77wtbF5v0UdwgL/zOhAtFn5J13wqUXjv51yIUQ5ZXwAs9ReGhhC/kRXMclSleq6uYsL1C6R6mPkAjPG/GJ7PIBTXxHXAndj+B4FzrXQYD3JXMB//j34yFANzuQAHG/foYytSbhpgNUiGHtcspXh+muShVV2HOCAp7S4l/KwwfLJrFWRtqU0FtAyspMkXMcAaDPkcoTdlqAJvVBB6pTpOr2Q3Es9U/Au9qcOwa5uNhybvZU8+417y36fNgXa5VRYpgrrUYSuAp6fyi4g25f+8V4o+nsuF9sMwnKwdQ+1oyUVGA== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0173.NAMP223.PROD.OUTLOOK.COM (2603:10b6:5:316::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22; Fri, 3 Dec 2021 14:57:55 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775%8]) with mapi id 15.20.4755.016; Fri, 3 Dec 2021 14:57:55 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v2 1/1] avcodec/dvbsubdec: Fix conditions for fallback to default resolution Thread-Index: AQFpQFvx6eP0sBR9KWgq+dIMmlkhSQG2YfsU Date: Fri, 3 Dec 2021 14:57:55 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [VqYVL/6wFyx/TX9EMnf1lB/SjyWG4wab] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 90b77a41-a944-4fee-d927-08d9b66d49e7 x-ms-traffictypediagnostic: DM8P223MB0173: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /82vl8IiX34J7hIVwR5W/+C2fYY9+42wKKopL1yxw5u1Nt9fjXA7SS8Ixiyrn49TURrPOnQLDBZ1Q968al4yNlyltcrmJZrFvEk5AQPxgyt+puRqYxbJwmoYf2TEeLQ72GxFaI01rHNLLpp44DeuL37SDCpKuSwx72/BrMn63Oph/ifc2x2Ju8Fimu3f2PHd4FFYB4kHg59iZ7BQP13VSQFDzA5OZd8fr7nNfmvXnwd4OdDHVzpRb0SFG+jtKnL5u1NkcwT5Cn7FE3xIZQ73wvhxdhZIO+LEDcRx3y0NRcOepc9zBetrQXU0BPYjy1T600ButQGdnWZ0WzGDo7H3S3L3dl++R0Ql8fdl+HlNtjb/ptbfpaDC2XhicyE+ywwYzw54Q9arJIIyHcQ2fIop30snKTD3ROYISb1wpFjI3UQXJDMX3QCuOKFJcFmV2Fz5TF3R4tsnxHDbQKN4hUw0zkl9PdUmFAYEtNQGeIj6po/TfpsKl8umJ4DMPBdMeoN69X4GF8CiGRX8e9zDNF3Q5q6GHfJpjewBpQb/4VXfAUw1/nptMM+vz37bD68ZTIUX4XLqBoZ35R0r28gH2D44MVbHGoPUt+CXqaomlK+Zl+Cy6O7Kbul5fN5pRbvRzeeZ x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?IRemuPxBLBmik3KGjTcRFHPBoYLr?= =?utf-8?q?wjQK+u73LzCU3pBeEktVT3eXuT8TLGSbkkCWu1YDgTWd6w9FPh4z/7732MAtX2FP9?= =?utf-8?q?UGa4cwVrsARlMg6B5CkCbVLWXqtVNSjvx5cOVyuSY24ccciZlEFzTIEzY+eB9WVg5?= =?utf-8?q?NRVgt/9INNIuiT7pEzuLbBgHe5ch5KEKYffZyl0QHjmSBHfzbtIdL6WYNSOuD3tiH?= =?utf-8?q?JtWA+dkFE++0IiJDNgURrOUcU0XxONpm/gNfaxhrv+3xMPMwJMKy03/yxl7WMetBg?= =?utf-8?q?mk196ANfuyTmiuWuKb9k/WfX4LwQaKv0N9ktn1OWQtg7FpU09z2pXlmGq5sOB9pyK?= =?utf-8?q?BEmpcstprITnb7sy5bs9MnjOGg0L+BYYT67HgfSrrCS60lzX12f12x4BsU5dOGraY?= =?utf-8?q?wIdpePTexBV9xy8BQPQSYBl4UZcM4nwEttEo8Izl5VOoh/21ow3Pq70D6/ObAQlOv?= =?utf-8?q?RmcSxfl1RJKZ40baEbQoXhrs6v37ZyzeGjVBtNYphQL645FmygfkKFcUiY5V6poxH?= =?utf-8?q?MpfHudbbMJHC6H+aHzaahImVWcB8VBUK4IM3bcRi3QkXLmAmIF85dD5lahyBJtEy+?= =?utf-8?q?wea0czP4qETCqhH7w9XTB9d2Hpa8kkFTcoJ7/+YEKWVS+qjeVJYUE2AZbmondeFWs?= =?utf-8?q?PsrTK4PKN7UAstvwKAtAXrTHTsOTM4ZbD6/+WcLcWMFEE+BCA3l5DAVo4qe0uFh4M?= =?utf-8?q?Eyj+Q3EKwjD1JqrRL0NDkDRAr+9VuCJ5YZwRbzms1c6YSfH0Rywby6xKGKwQXcamy?= =?utf-8?q?MBiM79UFpl1r8f6H+LcluWYVZPTDcUBdNNGcax+vSHX+iw3WbJychGADuknuZ3Kom?= =?utf-8?q?k3jKqK2gal/XqfuwCNXaPqz8GZczqQuRov+7+0Yd4pAzidKNnpgDkoq3QbpTgky+M?= =?utf-8?q?mFEu1wpZdR4kr+Wrzl4eiAK1lxu+E6BH53pQvgbX+zuQ=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-1ff67.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 90b77a41-a944-4fee-d927-08d9b66d49e7 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Dec 2021 14:57:55.6650 (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: DM8P223MB0173 Subject: [FFmpeg-devel] [PATCH v2 1/1] avcodec/dvbsubdec: Fix conditions for fallback to default resolution 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: rtrWqLuSjwBi The previous code expected a segment of type CLUT definition to exist in order to accept a set of segments to be complete. This was an incorrect assumption as the presence of a CLUT segment is not mandatory. (version 1.6.1 of the spec is probably a bit more clear about this than earlier versions: https://www.etsi.org/deliver/etsi_en/300700_300799/300743/01.06.01_20/ en_300743v010601a.pdf) The flawed condition prevented proper fallback to using the default resolution for the decoding context. Signed-off-by: softworkz --- v2: Wrapped the commit message. Hmpf. libavcodec/dvbsubdec.c | 50 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index d192f3251d..46cc330a93 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -33,7 +33,7 @@ #define DVBSUB_CLUT_SEGMENT 0x12 #define DVBSUB_OBJECT_SEGMENT 0x13 #define DVBSUB_DISPLAYDEFINITION_SEGMENT 0x14 -#define DVBSUB_DISPLAY_SEGMENT 0x80 +#define DVBSUB_END_DISPLAY_SEGMENT 0x80 #define cm (ff_crop_tab + MAX_NEG_CROP) @@ -1624,8 +1624,11 @@ static int dvbsub_decode(AVCodecContext *avctx, int segment_length; int i; int ret = 0; - int got_segment = 0; - int got_dds = 0; + int got_page = 0; + int got_region = 0; + int got_object = 0; + int got_end_display = 0; + int got_displaydef = 0; ff_dlog(avctx, "DVB sub packet:\n"); @@ -1670,34 +1673,28 @@ static int dvbsub_decode(AVCodecContext *avctx, switch (segment_type) { case DVBSUB_PAGE_SEGMENT: ret = dvbsub_parse_page_segment(avctx, p, segment_length, sub, got_sub_ptr); - got_segment |= 1; + got_page = 1; break; case DVBSUB_REGION_SEGMENT: ret = dvbsub_parse_region_segment(avctx, p, segment_length); - got_segment |= 2; + got_region = 1; break; case DVBSUB_CLUT_SEGMENT: ret = dvbsub_parse_clut_segment(avctx, p, segment_length); if (ret < 0) goto end; - got_segment |= 4; break; case DVBSUB_OBJECT_SEGMENT: ret = dvbsub_parse_object_segment(avctx, p, segment_length); - got_segment |= 8; + got_object = 1; break; case DVBSUB_DISPLAYDEFINITION_SEGMENT: ret = dvbsub_parse_display_definition_segment(avctx, p, segment_length); - got_dds = 1; + got_displaydef = 1; break; - case DVBSUB_DISPLAY_SEGMENT: + case DVBSUB_END_DISPLAY_SEGMENT: ret = dvbsub_display_end_segment(avctx, p, segment_length, sub, got_sub_ptr); - if (got_segment == 15 && !got_dds && !avctx->width && !avctx->height) { - // Default from ETSI EN 300 743 V1.3.1 (7.2.1) - avctx->width = 720; - avctx->height = 576; - } - got_segment |= 16; + got_end_display = 1; break; default: ff_dlog(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n", @@ -1710,13 +1707,24 @@ static int dvbsub_decode(AVCodecContext *avctx, p += segment_length; } - // Some streams do not send a display segment but if we have all the other - // segments then we need no further data. - if (got_segment == 15) { - av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, emulating\n"); - dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr); - } + // Even though not mandated by the spec, we're imposing a minimum requirement + // for a useful packet to have at least one page, region and object segment. + if (got_page && got_region && got_object && got_end_display) { + + if (!got_displaydef && !avctx->width && !avctx->height) { + // Default from ETSI EN 300 743 V1.3.1 (7.2.1) + avctx->width = 720; + avctx->height = 576; + } + + // Some streams do not send an end-of-display segment but if we have all the other + // segments then we need no further data. + if (!got_end_display) { + av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, emulating\n"); + dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr); + } + } end: if (ret < 0) { *got_sub_ptr = 0;