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 ESMTP id 4DF2740C1C for ; Sun, 8 May 2022 04:30:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E94EC68B3BB; Sun, 8 May 2022 07:30:51 +0300 (EEST) 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 CAB2868B196 for ; Sun, 8 May 2022 07:30:45 +0300 (EEST) Received: by mail-pl1-f180.google.com with SMTP id k1so11058377pll.4 for ; Sat, 07 May 2022 21:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=PVUb/9lMJHEjwEZwq5hdBLr3Pc07Avct0pVOYEv9/LE=; b=fJqJ6W73sjsnHLWIlGTVUD+lW9oyCQRgcP8pQ8diLz29VWFULcXnqY01JkddgYvleo xaFAkeiwcmuRO0pynnohFb6/qD8Il3xBUjHc8CdSIvavJfqLlNmYNkDHglxc2oHqDN7k Knqp5QUQ+dbuUPkwgvl9qado52N66JAIbmw2TL3MXbIGCms5tagumwYbg9+fvYZHHUw+ LofDwnaHLSsIrekj0LbfU6aAZDvRsUe1YgZvBoLNik3CcQvoHBT2Qmr7Jdmo1ctk17oB J/gk7jx246okp/E34D0sR5sLTl5HwBdZPMVwT519H5xc/cZavcKgVuPsazWBiWde/xij ur+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to; bh=PVUb/9lMJHEjwEZwq5hdBLr3Pc07Avct0pVOYEv9/LE=; b=jKEhPgdgo7u8n6ahnMGRXbsPoeALNiVgkYZMaS2/SWMvjN8JhwFVBw1x7lkzcJJ/na b0GtNTQHridn1cIgFBqAEdVLCDX6J1RsgoaDkf1Z2jXB/LYkZabuLfH8AH2nL9T79oTN Pum7pDiuzTjDj3mbgXtM66xZ/nv7hb7jMlc9YMi9Jgk+wbT0GvA23gUWPTFI2kbnt0sD 37vgfmltMy4qE7/hri78AgKTbAXQYyGdl8eA6Iw1pAO23Pv7z8i7vm6OmtRF7kk0/wiO DGpcb1C508K7yFA+NLh8y8fSG0BX3NlxV26s1E/1RqeImm3Ys3DsXTjyo0acEMmBUtTt qCEw== X-Gm-Message-State: AOAM532Xu6kwdzQK7r45zPY0FDO+nTxHP7IcaXGA5Rq1D/LwgCqgrmU1 Mg9Jh3OlAunmVFKrZQJ9X6hkAb9PiPY= X-Google-Smtp-Source: ABdhPJyOKHSlyFfjoWPGHgi/j4X+uj1pHUio8T2XYSBwBcvlHzTDZGG0tYvoqcqBd4C+9auFiXiUUA== X-Received: by 2002:a17:902:d50a:b0:15e:9528:72ad with SMTP id b10-20020a170902d50a00b0015e952872admr10637628plg.83.1651984243756; Sat, 07 May 2022 21:30:43 -0700 (PDT) Received: from gmail.com ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id a7-20020a1709027e4700b0015e8d4eb222sm3540712pln.108.2022.05.07.21.30.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 May 2022 21:30:43 -0700 (PDT) Date: Sun, 8 May 2022 12:30:40 +0800 From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Message-ID: <20220508043040.GA15024@gmail.com> Mail-Followup-To: ffmpeg-devel@ffmpeg.org References: <20220427084949.73931-1-4rusxg@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220427084949.73931-1-4rusxg@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH] libavcodec/mpeg12dec: extract embedded CC of particular type only 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 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: On Wed, Apr 27, 2022 at 03:49:49PM +0700, Ivan Baykalov wrote: > Some streams contain closed caption data embedded using several wrapping > types. For example stream can contain CC wrapped as ATSC A53 packets + > the same data wrapped as SCTE-20 packets. Prior to the patch CC data was > extracted from both types of packets, so it gave duplicated character > pairs on the output. > > Now we calculate some statistics which CC types appear more often in the > stream and extract the data from a single type only. If at some point > the other CC type becomes more active, we switch to this new type. It's better to export them on demand instead of autodetect. I'll post the patchset which fixed my local branch for review. > > Fixes ticket #9724. > --- > libavcodec/mpeg12dec.c | 44 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 44 insertions(+) > > diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c > index e9bde48f7a..f7e54ef0a9 100644 > --- a/libavcodec/mpeg12dec.c > +++ b/libavcodec/mpeg12dec.c > @@ -58,6 +58,14 @@ > > #define A53_MAX_CC_COUNT 2000 > > +typedef enum CcType { > + CC_TYPE_UNKNOWN = -1, > + CC_TYPE_A53 = 0, > + CC_TYPE_SCTE20, > + CC_TYPE_DVD, > + CC_TYPE_COUNT > +} CcType; > + > typedef struct Mpeg1Context { > MpegEncContext mpeg_enc_ctx; > int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ > @@ -81,6 +89,7 @@ typedef struct Mpeg1Context { > int first_slice; > int extradata_decoded; > int64_t timecode_frame_start; /*< GOP timecode frame start number, in non drop frame format */ > + int cc_packet_count[CC_TYPE_COUNT]; > } Mpeg1Context; > > #define MB_TYPE_ZERO_MV 0x20000000 > @@ -2198,6 +2207,32 @@ static int vcr2_init_sequence(AVCodecContext *avctx) > return 0; > } > > +static int cc_type_is_selected(Mpeg1Context *s1, CcType type) > +{ > + int max = 0; > + int max_index = -1; > + int sum = 0; > + av_assert0(type >= 0 && type < CC_TYPE_COUNT); > + s1->cc_packet_count[type]++; > + > + for (int i = 0; i < CC_TYPE_COUNT; i++) { > + if (s1->cc_packet_count[i] > max) { > + max = s1->cc_packet_count[i]; > + max_index = i; > + } > + sum += s1->cc_packet_count[i]; > + } > + > + if (sum < 2 || sum > 20) { > + // reset statistics, but give some advantage to the current selection > + // to avoid frequent switching between the types > + memset(s1->cc_packet_count, 0, sizeof(s1->cc_packet_count)); > + s1->cc_packet_count[max_index] = 2; > + } > + > + return type == max_index; > +} > + > static int mpeg_decode_a53_cc(AVCodecContext *avctx, > const uint8_t *p, int buf_size) > { > @@ -2217,6 +2252,9 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, > if (new_size > 3*A53_MAX_CC_COUNT) > return AVERROR(EINVAL); > > + if (!cc_type_is_selected(s1, CC_TYPE_A53)) > + return 0; > + > ret = av_buffer_realloc(&s1->a53_buf_ref, new_size); > if (ret >= 0) > memcpy(s1->a53_buf_ref->data + old_size, p + 7, cc_count * UINT64_C(3)); > @@ -2240,6 +2278,9 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, > if (new_size > 3*A53_MAX_CC_COUNT) > return AVERROR(EINVAL); > > + if (!cc_type_is_selected(s1, CC_TYPE_SCTE20)) > + return 0; > + > ret = av_buffer_realloc(&s1->a53_buf_ref, new_size); > if (ret >= 0) { > uint8_t field, cc1, cc2; > @@ -2310,6 +2351,9 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, > if (new_size > 3*A53_MAX_CC_COUNT) > return AVERROR(EINVAL); > > + if (!cc_type_is_selected(s1, CC_TYPE_DVD)) > + return 0; > + > ret = av_buffer_realloc(&s1->a53_buf_ref, new_size); > if (ret >= 0) { > uint8_t field1 = !!(p[4] & 0x80); > -- > 2.35.1 > > _______________________________________________ > 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". -- Thanks, Limin Wang _______________________________________________ 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".