From patchwork Tue Oct 25 09:13:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 38980 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2686430pzb; Tue, 25 Oct 2022 02:17:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4s6qkGcrUsBC+RHfLdm142K0cP9mLXIyHKYLf6H8seX8Q8HQnvGU5nIs3S8skXADx24I3W X-Received: by 2002:a17:907:3ea9:b0:78d:fdf0:88fe with SMTP id hs41-20020a1709073ea900b0078dfdf088femr32742539ejc.667.1666689468903; Tue, 25 Oct 2022 02:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666689468; cv=none; d=google.com; s=arc-20160816; b=pGH6lyFkvOWeWxuahc5fJ7R91iCml704I0275RSoXXUafFgdKFStuj6Eu2SC2+XyZi KkwkLvawSy2I1gdToLNKstWwKPTM4xn+3lbNcDcsEUMxEU87DeZZPp90R/WhaOf4lpIX jr9wsYzzg1sRPtWdHGoh1wl1HA+gMUsHg/lwyBaHd+BkphkAEvDPyYJEDjfExw9mB3H8 hOXh7EmFR6j+v/a18CfgdZTZnheAWegbFj4iHTbtxL3u7TzlFTVL6c55CSMH2L13NZmB lR10b0/MU5pKUgIXlAAnKXPUCXtYnpdnbmtg7nGpVhruCyjD5BTTs4HHsYAycYyD8B3z KtFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=qQAb1yx8ZGCgmBkmTUZlZL/f8QYRB0RqnQsPHzFsQyM=; b=THXC+saABgABfOoarpP6IyQw8p7r7dpteow/3dSgTeZ9rJGgc4qpH/68qTPHNcWjdg lCJO01HdCE9Ok9j3f0VMKZ33ipEmVDWnsx5EJaGGAJHSYaRdi7c/nqf3h/CaX4rdCSjP eFxrV49vwyWFIOkJx+jLiTxV3Jkbi+PkHQdBVm0QOe/4hbg8xC1bg/ot1EkZ1Ek3tIV1 0YV6503TOAmRlTq+nFxgAfMBv3BxzALWU2CfkufS0RjknzRnEAeIHTBXNm42NeZbo+oI 11u/ghDxmYExSILxN8OQ+tukkZMdTI6FFkqx1JCTGlD384WdYrro/zMZJaddAh0Jcx8l 8vxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=dmF6VOmH; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gt12-20020a1709072d8c00b0078d1faeb619si2883517ejc.777.2022.10.25.02.17.48; Tue, 25 Oct 2022 02:17: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=@gmail.com header.s=20210112 header.b=dmF6VOmH; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 47EBB68BD9F; Tue, 25 Oct 2022 12:14:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B208C68BD84 for ; Tue, 25 Oct 2022 12:14:20 +0300 (EEST) Received: by mail-pf1-f171.google.com with SMTP id g62so7227587pfb.10 for ; Tue, 25 Oct 2022 02:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=d0XqOcvlQCaW2AQnlWuouX8iEt5sctwyaH4eLUsrptw=; b=dmF6VOmH6XKaucGaiLX+MTMSRM9JDQ6NE9CuNDd0NhGUGwXKFbbYsozapr7etDbb1r yENcSxklG4KY9HdV3MK+mxWvZIGYrk2oe8V1XojHD5HlvTI5t6LAjQtmr3SWvYy2yuP9 OdR9wJpt8sLnU6aLI7I9vLhMkflN4lLDYfYfRQjtuZ0dqwnMgZMwC84G0e3xaqzra0t0 EDi8b7C3QQhSaApNx5/sX2Vtj9RxCBKfEHfRkToQDapXk6s5e3688htdLzSM8YLLcpLb UGLpKjobRqFJMxnUbbNpGXA6WwsRYXkbFExc1Mic7c5rHe/UNAJfMO2kn06cRE1NDGXQ 0tSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=d0XqOcvlQCaW2AQnlWuouX8iEt5sctwyaH4eLUsrptw=; b=IkJcGCKMOVtyvOEMXlMo3eRkd/jOpONu5hH4KSi/GOzdk7X8ypQZ5Uus/MIRLZ+QRX FcOJ42Wqj1X6YTChiEsAzZpbZWaZ9GmlvRNw3AeoT8MiYYHrC8pxro3UkQPJFGw/jm33 F6lgnd9J9pE3DQL3cg+GykwuVgKxK7dl7HeTT0Z/AFT8rpiz8z4IxJgZVK9cQ+KBcJCw blcGfHrEDxJr0ArXyn+0DjKWV5e1N321WfBeXOdBN4D0f+S4EavsVroVfo1SYDfhjNIK YZ+WN/ZE1rRjVl0w6EgbgR3y49TJTfRB+c0yIZWdU7X1GHG9R3jduhOUYbWYMKmBbahK eRyw== X-Gm-Message-State: ACrzQf0AXPj2yPhaiLw8vsbtG8r229QkE13rgJtPIdVD1nN79gf8b4se QYHtDUV3sAUV1BtANADTbXKeTft80kk= X-Received: by 2002:a05:6a02:47:b0:46e:ea48:9543 with SMTP id az7-20020a056a02004700b0046eea489543mr12345033pgb.6.1666689258746; Tue, 25 Oct 2022 02:14:18 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id oc12-20020a17090b1c0c00b00212735c8898sm5118299pjb.30.2022.10.25.02.14.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Oct 2022 02:14:18 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Tue, 25 Oct 2022 09:13:46 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v9 25/25] 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 Cc: softworkz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Rg2FnurnyPD7 From: softworkz 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 --- libavcodec/dvbsubdec.c | 51 +++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index c864ba3fb6..4df350574d 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -34,7 +34,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) @@ -1450,8 +1450,12 @@ static int dvbsub_decode(AVCodecContext *avctx, AVSubtitle *sub, int segment_length; int i; int ret = 0; - int got_segment = 0; - int got_dds = 0; + //int got_segment = 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"); @@ -1496,34 +1500,28 @@ static int dvbsub_decode(AVCodecContext *avctx, AVSubtitle *sub, 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", @@ -1536,13 +1534,24 @@ static int dvbsub_decode(AVCodecContext *avctx, AVSubtitle *sub, 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) { return ret;