From patchwork Sat Jul 17 02:38:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zheng qian X-Patchwork-Id: 28950 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp2351939ios; Fri, 16 Jul 2021 19:45:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8ZCSTb7NWLdtMaNRJi+HCNA6+gSazntseeIFBI6KprKMJ/w8X0rMVI0NLHhxH59FHt6R7 X-Received: by 2002:a05:6402:2206:: with SMTP id cq6mr18875647edb.209.1626489915973; Fri, 16 Jul 2021 19:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626489915; cv=none; d=google.com; s=arc-20160816; b=cFk8hRNtmXIaQwUW+2oLCvtT0/xDKBMCYMjYzGt5yHxxj52rsTJJqkbM5CaOpvVJ6i DGYU/ayoRnRbOOUh4lB0RyEAJFe0oXSJ5PCLeg8YDGb6iHdXiq9bdgomjfldJe9+HYKT o2iwkkGAb+Gc/3LzHNUF2FsZtZ4Zh+xnSDElJ1tzSp2IpeZDHnCA/HY3SSXwKT458HG6 modRLmMsHcdUZIcThdH7DJ0TtUniukV2F0+O1AIgDKn6RfOsgcDAKK2Aeh9Dqbax7OR1 PYah0DrMreIh/zH/Wk7OdD8kI2IFW3gDyXd0R+umRKL/L6BIA+rnbjR6ZLMTZVdXfssC RxwA== 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:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=TFw7pAL4Gfh1qjhkiQ81jgchHMjcXCEOhB2eKjCPWUQ=; b=JoxcrMVtpWk7dOgTnDPRgBhi3AUBRvGzJX1H+Zz3zcvmHvNTRzJus3MCXY3uo1c6hc aVpNr9YV6dSYQxFMMbVXXocnWzY7DQEu1egPLA9ZR2v40n8Nu5SC2hJ3qCXKeIb3yVWJ s4H8R0lzOXCZ2348eo8XJFUYYeuMdlRvE28RiPgzl4bsYH2vLtBywGu4vYZ6MybwVWVk b5XrgN7nyEnWvuBgafTqT/gXUhqEz1DcdnN/oR8HUnKlX0wGNhmDChbwnyGg0As4CSoQ WVvvYjM/iXz5wc1LOE/DR5FbeS1pw8FVS6oLiJWtJMFNWmPhMhM7QNVklTdO6//XZGDo 9IfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@xqq-im.20150623.gappssmtp.com header.s=20150623 header.b="oLkLKBO/"; 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 c16si14020251edw.522.2021.07.16.19.45.15; Fri, 16 Jul 2021 19:45:15 -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=@xqq-im.20150623.gappssmtp.com header.s=20150623 header.b="oLkLKBO/"; 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 CF3B268A834; Sat, 17 Jul 2021 05:45:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 640E068A35C for ; Sat, 17 Jul 2021 05:45:06 +0300 (EEST) Received: by mail-pl1-f169.google.com with SMTP id b2so1664839plx.1 for ; Fri, 16 Jul 2021 19:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xqq-im.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tgpfjvaVpLYLixZdOS7JyVSuckFhfT6/7PGsxmTRjYU=; b=oLkLKBO/AjvssPMxhu3BD7XX5bKuK0ABbWKzZbmw+2LkI5UWcR+8YTveCxjnlqX6aJ 46ouWIylNtTJ6G1yY6PeEd4+0x7v1K2wWbixTPIL7InOpaos70OdA+8yphpuy2bVX7kO Zf1Qfj7+VAkVZFYjIkRBzvBgZYVkqWJsQJpIVLnBU/75Byzg8W2080ntveIPV9ZxpZzY VMxko4+QNF4S08CXud++L5gItg/qy3DwyAp5IMvy+bPTrFxA2WIkSfp+625ExMZVOyuW Y8/gxzZ4WwbdT2+4/PIz1XVRpnuNwCkh7QnxsHQ43EIXe3TUjGxhBtck7TIq83FCwja9 oGmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tgpfjvaVpLYLixZdOS7JyVSuckFhfT6/7PGsxmTRjYU=; b=a/uPys6iHU5IbUiNhLyfrpXv+lQsNyYfGeb1anV1Q3pX/9/Uq38LPSvcHRCZQTEAXb svJ62DFYnG+6RO6UE66DZlcDdeqM0cloBjH5osnuiVo+uLS1qSFov8GI7h1BhJS1RRzH /YXcNCKhohQz0PDDWvtihm0JB5jMk4VDR3aAsqaP21s7oGZczG0284SekGb5F4WupNyi O+WxOuxD+vTNGPQNSJEPrgCHFQC/njXJp4J5WZM9iy+8HvQMjpKoL3jvTe3jBlqj4IpF o0wm4tyNbQmGF8OWHAfV/tAXpidqdJxssoCcBXiAZH2eotEuePZp2xAe96yFNoFx8gW2 Xrhg== X-Gm-Message-State: AOAM532vWPtGkClgH5gbgfSpQEUlAC5vBtiXRKX8XKYbE9LtchjTlQig YWsSA5xaRz6P/toGsmdcl3OD9i0LvN/hGQ== X-Received: by 2002:a62:8283:0:b029:336:6e7a:9c73 with SMTP id w125-20020a6282830000b02903366e7a9c73mr5186329pfd.45.1626489534013; Fri, 16 Jul 2021 19:38:54 -0700 (PDT) Received: from zhengqian-xps.lan (ngn-nat1.v4.open.ad.jp. [202.222.12.138]) by smtp.gmail.com with ESMTPSA id q18sm12909263pgj.8.2021.07.16.19.38.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jul 2021 19:38:53 -0700 (PDT) From: zheng qian To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Jul 2021 11:38:28 +0900 Message-Id: <20210717023829.84846-3-xqq@xqq.im> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210717023829.84846-1-xqq@xqq.im> References: <20210717023829.84846-1-xqq@xqq.im> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/4] avformat/mpegtsenc: Add muxing support for ARIB superimpose stream 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: zheng qian Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vK0Ff8eatDrW Signed-off-by: zheng qian --- libavformat/mpegtsenc.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 98dac17994..b5d2938c4a 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -287,26 +287,37 @@ static void putbuf(uint8_t **q_ptr, const uint8_t *buf, size_t len) *q_ptr += len; } -static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr, - AVCodecParameters *codecpar) +static int put_arib_descriptor(AVFormatContext *s, AVStream* st, uint8_t **q_ptr) { uint8_t stream_identifier; uint16_t data_component_id; uint8_t *q = *q_ptr; - switch (codecpar->profile) { + switch (st->codecpar->profile) { case FF_PROFILE_ARIB_PROFILE_A: - stream_identifier = 0x30; + if (st->disposition & AV_DISPOSITION_URGENT) { + // ARIB superimpose, with AV_DISPOSITION_URGENT flag + stream_identifier = 0x38; + } else { + // ARIB caption + stream_identifier = 0x30; + } data_component_id = 0x0008; break; case FF_PROFILE_ARIB_PROFILE_C: - stream_identifier = 0x87; + if (st->disposition & AV_DISPOSITION_URGENT) { + // ARIB superimpose + stream_identifier = 0x88; + } else { + // ARIB caption + stream_identifier = 0x87; + } data_component_id = 0x0012; break; default: av_log(s, AV_LOG_ERROR, "Unset/unknown ARIB caption profile %d utilized!\n", - codecpar->profile); + st->codecpar->profile); return AVERROR_INVALIDDATA; } @@ -320,11 +331,17 @@ static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr, *q++ = 3; // descriptor_length put16(&q, data_component_id); // data_component_id // additional_arib_caption_info: defined in ARIB STD-B24, fascicle 1, Part 3, 9.6.1 - // Here we utilize a pre-defined set of values defined in ARIB TR-B14, + // Here we utilize pre-defined sets of values defined in ARIB TR-B14, // Fascicle 2, 4.2.8.5 for PMT usage, with the reserved bits in the middle // set to 1 (as that is what every broadcaster seems to be doing in // production). - *q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01') + if (st->disposition & AV_DISPOSITION_URGENT) { + // ARIB superimpose + *q++ = 0x3C; // DMF('0011'), Reserved('11'), Timing('00') + } else { + // ARIB caption + *q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01') + } *q_ptr = q; @@ -772,7 +789,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *len_ptr = q - len_ptr - 1; } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) { - if (put_arib_caption_descriptor(s, &q, st->codecpar) < 0) + if (put_arib_descriptor(s, st, &q) < 0) break; } break; @@ -1444,6 +1461,11 @@ static int get_pes_stream_id(AVFormatContext *s, AVStream *st, int stream_id, in if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous KLV */ *async = 1; return stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM; + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE && + st->codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION && + st->disposition & AV_DISPOSITION_URGENT) { // ARIB superimpose + // ARIB TR-B14, Fascicle 1 (2/2), Vol.3, 4.2.3 + return STREAM_ID_PRIVATE_STREAM_2; } else { return STREAM_ID_PRIVATE_STREAM_1; }