From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id A6A114DBE0 for ; Sat, 1 Mar 2025 17:40:36 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C3EC268E11B; Sat, 1 Mar 2025 19:40:31 +0200 (EET) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D2D368E0E6 for ; Sat, 1 Mar 2025 19:40:25 +0200 (EET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2237cf6a45dso17068515ad.2 for ; Sat, 01 Mar 2025 09:40:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740850823; x=1741455623; darn=ffmpeg.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :message-id:from:from:to:cc:subject:date:message-id:reply-to; bh=oe5jSSufZQt+vwAWdsmpVTtQng4HX9SB1t2pgNpbea8=; b=DtjIgmb+5S3L0oN74iG/da4drXWUF973OwvLR0+2pAylL+9ciooOk7YUA8ODqAS4Af BeuVSu/nurzUhc3aJu03cWk4/KUHicYlSxAwlatATFa5sacdQ1m4tMjUY7E9l7s6uI03 kM/HvomNxQ2HS3o0b1SBYMoId+SMXbg7Jkka/fhkVA75XzIraD8tej8Y1iwXyJGjZX3w ZL0ch6JwqGAFwM1L8kzfBoPv944H2ilSQvYbPzT9PMFk/cMP3ybAOBn7TR6O0jD/Ld2q QEWz57ucq+jcX3tUN2N2BbDY9OKK/mqSxIZhaBfhOtbSnUDSu/h7vrQp5ZEr06UWOcKj /XJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740850823; x=1741455623; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :message-id:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=oe5jSSufZQt+vwAWdsmpVTtQng4HX9SB1t2pgNpbea8=; b=GtaXpVUJW6zc9HDojJ+JCLxZIrhhhc+jBAjbMauOAqDPZRT8wJ8nUowE75dzDBuTW0 0gtPpT4nXSAknS8s8EhvOqsm9KY7kEohKucilwM3LaYy4NCvmzomiF26kMnuFXQvkRhB j0ADtNuiG4l5FlWaEWQNsRmvXGH4u3wBYUj8swhea2+fH0ZhnnxC8TjnUp3irg6+SI9S hz5OYhCbdsKx0YzyLNIYPuIC82zfJQlQSaAnZ5N6lrhay2xms5qITLAtZE2clm4Mh8qV /1IwvLjbObbWFiFEAttec2oX54k8VP7NL0NSxSPJK1hErvD0MoQy/Zy0/Stcr9TdpqcF TjVA== X-Gm-Message-State: AOJu0Yzb/zTEYrF0H7qKqKjDLRQFxUpkOFnercOGVGJnOUeJVLoHH2Sf WfMiDYBP8S10BF/nlOybvYRXtgOw6uQXBUbLk/HdHMrz0qXje72y8E8vvA== X-Gm-Gg: ASbGncvCAd4zimZ5toqZetq8ijVZuy7dJP0F7fi8DbrsCuoTSqmlvEW6qkZzYXlGbAO uek8ApVEJOWFBuR5WCLdQysYlpy4aSCIAK6dgpXocySEWu+zGaDjIKmP793OOLU3WJ5c2aZ2AIf Xuf8uQrwgTmxk8/W3qcPxb1SmAE1OXnK1w0hAU5MhT+dp9OnGQeuEHGkNz0IvGgfmWsi4iFXj4H XbwXrsVxbd7WrA+aTD51gsKgCHXkRRb/1IX0Rd5OTgQ1mW2rbHGL2vela4brl+5lBeR2IyciaKG q3T5CqJ8b6s5zpo2qHpwVxT685I2Kjl5LmKeFYXGymONXrnRJfAi24a374XqQx0= X-Google-Smtp-Source: AGHT+IFM4x9wPQyAGIHpD5t85s8rHDMVcqnVcBT7ROIK90bBBZra2vBHKr5/Fao2yDE7eSXVeiMqbQ== X-Received: by 2002:a05:6a00:1490:b0:736:34ff:be7 with SMTP id d2e1a72fcca58-73634ff0cf5mr3633696b3a.15.1740850822936; Sat, 01 Mar 2025 09:40:22 -0800 (PST) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-734a0024d35sm5829286b3a.87.2025.03.01.09.40.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Mar 2025 09:40:22 -0800 (PST) From: softworkz X-Google-Original-From: softworkz Message-Id: Date: Sat, 01 Mar 2025 17:40:16 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 incorrect condition prevented proper fallback to using the default resolution for the decoding context. This also adds variables and moves the fallback check to the outside for better clarity. Signed-off-by: softworkz --- avcodec/dvbsubdec: Fix conditions for fallback to default resolution 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 incorrect condition prevented proper fallback to using the default resolution for the decoding context. This also adds variables and moves the fallback check to the outside for better clarity. Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-57%2Fsoftworkz%2Fsubmit_dvbsubdec-v1 Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-57/softworkz/submit_dvbsubdec-v1 Pull-Request: https://github.com/ffstaging/FFmpeg/pull/57 libavcodec/dvbsubdec.c | 50 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index 4553c45b3d..cbb16e501a 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -35,7 +35,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) @@ -1451,8 +1451,11 @@ 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_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"); @@ -1497,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", @@ -1537,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) { + + 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; base-commit: 79c47dfd25f101b6842bbec8c6ffef8d5077c3ae -- ffmpeg-codebot _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".