From patchwork Thu Jan 20 03:25:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 33719 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5434305iog; Wed, 19 Jan 2022 19:30:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzyXypiO572W2yA6UzUCFRsPk3ebNYCE6Nw0M1fpb3neJFyWF9WrGOpH8pc0KSiqlomybv X-Received: by 2002:a05:6402:1692:: with SMTP id a18mr9142067edv.40.1642649432089; Wed, 19 Jan 2022 19:30:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642649432; cv=none; d=google.com; s=arc-20160816; b=YVaK7cHvqvuTgOGpZyqV4LMoqIKZy2lRkmVs8XMHhLDcPu8qXvQyzQTDzl35vmSqGq 64Sl6PoBmEzdBeH96CExR2bpdV4htj9vavrU4zizyvNflX/a9bXxO6fX6obu1BTxJvPI mu/ECEOAab0bCVUqlPH4Xj56PPe2HloDasiFFVwvuHuPL21YCmAOr++cW+QxTAstOx0e DBRpLGVSK8psIryJNWgEd3b30K7bsBqYaxm4+Gj1Lgf/B5OMI0rcTegYl2VRg5+MEoco H99Gf378SnWJNTRxQrkQ03KgGEcyeHtf6MoAeR1v+nigml3wqNjqITHdEelc86blQ2cs DPrA== 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:from:references :in-reply-to:message-id:dkim-signature:delivered-to; bh=TLxTlDyiyoKHVDXw8hos0tqxUd05RXDYZZ4nSSTcfqU=; b=qikE4X12532Wg5KM9kJVhw1GHETnEEfoJTmQ/wNWb24lQZBaQPk0PyM1SBcDYQlQjS r6oSbR84XVw9bfwnRJBstnAjGQWEzHk86UTTIEyUHEt0106H3hbGgBhOJl+lK6bacscC aM4V9N/bOJbNAFPPHphSWL/EL0LcCtFOjtCCJ9SsBfKuJCq6B2BRivuP4SrE6v5BOPcP JFb0Rro1Er216GSdSn0YzlLLwTWzDS1uZ12r7MzNQg1V9BlgUKnzrwjNWvQpNyWC1VoE QGiGqOGeFtvRkCPmeOHDCN35Gpe3j8j1sfxz3/vGR276Pl9MC1oeeWhu0TCjRyFAumKy 6ypw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=fYfG9zXx; 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 v7si1112990edj.356.2022.01.19.19.30.31; Wed, 19 Jan 2022 19:30:32 -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=@gmail.com header.s=20210112 header.b=fYfG9zXx; 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 7EE3768B346; Thu, 20 Jan 2022 05:26:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 75A3068B309 for ; Thu, 20 Jan 2022 05:26:04 +0200 (EET) Received: by mail-pg1-f173.google.com with SMTP id e9so910597pgn.4 for ; Wed, 19 Jan 2022 19:26:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=DGjY2UfwVDogFgZo29av9KeU5AuKhN9QE8fHp3Wbnfk=; b=fYfG9zXxxf6gt7pwbXcRrztWKbCEnKuEcRbJZpHVgg4ISZag8IH5FGZGOyiHtWEVz1 OHQCh2tKV6bX8AbbIgDtRigrfY0EHOzM4di+0Gymu66/84zBPAXJe3ibEcXu0wl2o75I UWiQeadmqV6F2l8K80f6a4hOcPVSp9rWrhP8XhRyUgPv6AHa+KZ7cJ7ucPHf6JBJG+7v /7YoMcPjV2Yu8+8keUDcplFL/FVAVKxgpFmBR9Av0ManO7iyKRZv8ZNj2hdLPkvZy/TY wf63odCZKarGlkNvAJhnyNhjcXrzGX3iApgPuSEn8vVi1QGjgASq9zVGQ3JgNMmgnGd7 uhvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=DGjY2UfwVDogFgZo29av9KeU5AuKhN9QE8fHp3Wbnfk=; b=xsOnhd9cdL3vv1qXBvAgQiEGrlqQSEVuA8e/ihAyRb091uODmlM05VlqUpVNT3vrAR B6y9pSj8NnFIoNrBev7YGox8K1qVH7N0JheXj20GkJPzaY/FCI0dGgUdvA1AhN0xEjfT lY9ba7e1SWZhGXpJgHveKwpAHbheDEHhAIQy7amA2k1sdYwvySrbHg5QDI7fcKseEpyG Uwj02bYiKyCNkCgy3X3NFkdHNWDzyrAJxU27HUKLotpT0hMqarhpypYjuSjX6r0fpncX FMVSNeT8WZn+6gdE01n+kWBCnUQ/s+6XTvbGwlnlIvos+rZL0xmMQ4olYJSGQIGW1MSX FWVA== X-Gm-Message-State: AOAM532/4TlfqmlzMKUFGLpQZm7g8GxNY5EKdHbpjs0zwrusGKLQxa3H 4pAMjfHjVAj1Xv5mXKPOIFtmI/lcsIU= X-Received: by 2002:a63:9d46:: with SMTP id i67mr29551312pgd.441.1642649162713; Wed, 19 Jan 2022 19:26:02 -0800 (PST) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id d1sm951921pfu.206.2022.01.19.19.26.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jan 2022 19:26:02 -0800 (PST) Message-Id: <03e1a98e080047da886afeb942ca1d0c6dac1330.1642649134.git.ffmpegagent@gmail.com> In-Reply-To: References: From: ffmpegagent Date: Thu, 20 Jan 2022 03:25:34 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3 26/26] 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: Michael Niedermayer , softworkz , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bInSKdKU+lPp 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 0d64c6e71c..3a6259101c 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) @@ -1620,8 +1620,12 @@ static int dvbsub_decode(AVCodecContext *avctx, 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"); @@ -1666,34 +1670,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", @@ -1706,13 +1704,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) { return ret;