From patchwork Sun May 6 21:05:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 8815 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp2227076jad; Sun, 6 May 2018 14:05:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrc9hMf5mDo0t0NuaIme9xEIxRhZqCuipe2ihA2z/cCyW57cGlgrZr79aUlTdrBZFwXQ8NA X-Received: by 2002:adf:ab0a:: with SMTP id q10-v6mr26604142wrc.239.1525640723972; Sun, 06 May 2018 14:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525640723; cv=none; d=google.com; s=arc-20160816; b=Zzf+rzmBK32p76XtNu6wdA+U5+6G+Qgo40nAIr3uJCDjWBHix2MuAV4oGyfw02eM5w A2ueaqAEGIXzcY31kCJIrjhiSeo3lmF3VMt5NLQyZ675GTHlMPrEuuSWa5mDh1l7s8zt SPW7sGvUgSyevktm4LMV3Z7ElpWcngMH9IqCLbo53bv8MukbX4fT/DFAOhN0PlSPulS/ XypjkLblLhyMNQS+AaE+Pfw/W6QBrQ9pw3xbRrfo+J30m20VOiEsRYDKSnSomvkrjUck fW3m4wrazo+ly67c3jjNJNgT16CA0C9i7gmqJEc2pq1h0ttzBZk3VCecAnvk3q1fyDZl bA0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=toDBZg5DJygGsyYGBSkk3DLYxzaQZhtnKmu97ld+o9M=; b=LspgDk/Jf7+m7FnKRml/19o/0s2MJAZ7aCdJKHU5wghFeevTBegcBdgV/MxnKVXbf0 qgPpnFRJbE1KGBAh9CJ9a/gXgukhTvPYmUJDN+zmMEsS2/hu5TfvF7MHVOjONh0UfLD3 QX/20D2JlGgjbO7jWqhTHD+q4q/UnUAtybWVjMTD59XOnRU453DnmakT7AlRhue0eZsO XaQv55Gh7cF4G+GWS5UT2pz6i/bwaH1+M19bt1JX2KuHNNt59+zhQEaIadtDgw4k4CVy EivgRg5VEd8tryUlRaqr+VNSbxSxVeWuQblMv5thhRQYUOkNMU5oUWoNX4wlglj/bunK GHjQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k10-v6si17968459wrh.432.2018.05.06.14.05.23; Sun, 06 May 2018 14:05:23 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EA08368A4D6; Mon, 7 May 2018 00:04:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0064B689EFE for ; Mon, 7 May 2018 00:04:44 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 92ADEE0F8F; Sun, 6 May 2018 23:05:19 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ejCIgdvnF4ym; Sun, 6 May 2018 23:05:18 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D8A7CE0E4F; Sun, 6 May 2018 23:05:17 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 6 May 2018 23:05:13 +0200 Message-Id: <20180506210514.7390-1-cus@passwd.hu> X-Mailer: git-send-email 2.13.6 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/libzvbi-teletextdec: add support for selecting subtitle pages only X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- doc/decoders.texi | 5 +++-- libavcodec/libzvbi-teletextdec.c | 31 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/doc/decoders.texi b/doc/decoders.texi index a551d5d0fd..8f07bc1afb 100644 --- a/doc/decoders.texi +++ b/doc/decoders.texi @@ -248,8 +248,9 @@ configuration. You need to explicitly configure the build with @table @option @item txt_page -List of teletext page numbers to decode. You may use the special * string to -match all pages. Pages that do not match the specified list are dropped. +List of teletext page numbers to decode. Pages that do not match the specified +list are dropped. You may use the special @code{*} string to match all pages, +or @code{subtitle} to match all subtitle pages. Default value is *. @item txt_chop_top Discards the top teletext line. Default value is 1. diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c index a800ad34ae..56a7182882 100644 --- a/libavcodec/libzvbi-teletextdec.c +++ b/libavcodec/libzvbi-teletextdec.c @@ -73,6 +73,7 @@ typedef struct TeletextContext vbi_sliced sliced[MAX_SLICES]; int readorder; + uint8_t subtitle_map[2048]; } TeletextContext; static int chop_spaces_utf8(const unsigned char* t, int len) @@ -281,16 +282,14 @@ static void handler(vbi_event *ev, void *user_data) vbi_page page; int res; char pgno_str[12]; - vbi_subno subno; - vbi_page_type vpt; int chop_top; - char *lang; + int is_subtitle_page = ctx->subtitle_map[ev->ev.ttx_page.pgno & 0x7ff]; snprintf(pgno_str, sizeof pgno_str, "%03x", ev->ev.ttx_page.pgno); av_log(ctx, AV_LOG_DEBUG, "decoded page %s.%02x\n", pgno_str, ev->ev.ttx_page.subno & 0xFF); - if (strcmp(ctx->pgno, "*") && !strstr(ctx->pgno, pgno_str)) + if (strcmp(ctx->pgno, "*") && (strcmp(ctx->pgno, "subtitle") || !is_subtitle_page) && !strstr(ctx->pgno, pgno_str)) return; if (ctx->handler_ret < 0) return; @@ -303,9 +302,7 @@ static void handler(vbi_event *ev, void *user_data) if (!res) return; - vpt = vbi_classify_page(ctx->vbi, ev->ev.ttx_page.pgno, &subno, &lang); - chop_top = ctx->chop_top || - ((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE)); + chop_top = ctx->chop_top || ((page.rows > 1) && is_subtitle_page); av_log(ctx, AV_LOG_DEBUG, "%d x %d page chop:%d\n", page.columns, page.rows, chop_top); @@ -357,11 +354,26 @@ static int slice_to_vbi_lines(TeletextContext *ctx, uint8_t* buf, int size) else { int line_offset = buf[2] & 0x1f; int field_parity = buf[2] & 0x20; - int i; + uint8_t *p = ctx->sliced[lines].data; + int i, pmag; ctx->sliced[lines].id = VBI_SLICED_TELETEXT_B; ctx->sliced[lines].line = (line_offset > 0 ? (line_offset + (field_parity ? 0 : 313)) : 0); for (i = 0; i < 42; i++) - ctx->sliced[lines].data[i] = vbi_rev8(buf[4 + i]); + p[i] = vbi_rev8(buf[4 + i]); + /* Unfortunately libzvbi does not expose page flags, and + * vbi_classify_page only checks MIP, so we have to manually + * decode the page flags and store the results. */ + pmag = vbi_unham16p(p); + if (pmag >= 0 && pmag >> 3 == 0) { // We found a row 0 header + int page = vbi_unham16p(p + 2); + int flags1 = vbi_unham16p(p + 6); + int flags2 = vbi_unham16p(p + 8); + if (page >= 0 && flags1 >= 0 && flags2 >= 0) { + int pgno = ((pmag & 7) << 8) + page; + // Check for disabled NEWSFLASH flag and enabled SUBTITLE and SUPRESS_HEADER flags + ctx->subtitle_map[pgno] = (!(flags1 & 0x40) && flags1 & 0x80 && flags2 & 0x01); + } + } lines++; } } @@ -502,6 +514,7 @@ static int teletext_close_decoder(AVCodecContext *avctx) vbi_decoder_delete(ctx->vbi); ctx->vbi = NULL; ctx->pts = AV_NOPTS_VALUE; + memset(ctx->subtitle_map, 0, sizeof(ctx->subtitle_map)); if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP)) ctx->readorder = 0; return 0;