From patchwork Thu Jul 30 14:58:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 21384 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C423C44AB77 for ; Thu, 30 Jul 2020 18:07:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 971E568B310; Thu, 30 Jul 2020 18:07:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 174BA68B29C for ; Thu, 30 Jul 2020 18:07:19 +0300 (EEST) Received: by mail-pj1-f68.google.com with SMTP id mt12so4444764pjb.4 for ; Thu, 30 Jul 2020 08:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vGQuUmm4CH7LuDNP9VhL4c5ThM2yayq5zHfQMoqboSE=; b=NTmg4Lf+RINMANDk8eUFc5YarTy3eOReSgK6qgoewQzM9G3RkHUPMfVuScR487HRbH hcCFioQLc51I7unSGr+qF9qUZpDV67Hbn9OcO0YXFAwKyh6vFuuvWZiZrCjsxhW3nhbj EgPXSvcJRS2732kpkZGZ07LAFlAB9I1lUYCFasLiwXgCsUzJIBSI9kMW/E2I4xlFYFxn 8pw3Bqi6pzZkZb7vO4Sy7ET0uQAmFb4+QT3qRhOw4wiJXrP7jieANMgPvYTa/c6aFZs1 V+dwA9okOgpsfyxfNOwoS+RaPGJnANbgAku5dfLotanvvfAobhdHoiMwp6hsgjWAWf/R thHA== 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; bh=vGQuUmm4CH7LuDNP9VhL4c5ThM2yayq5zHfQMoqboSE=; b=chzM8z0XVWAG/BJfvedLGbyATQg2F7BwwH5PgXkYMYgBbXUxx2VAJUiPPIPAmEuCg4 2ccKpn1btGtzw8jWIlPqSWd/Za71VWUV+BG55i+uEwTo6d+eJJcDNTykkiGK4gGR7dxV T09KOb+z5DKtgoHr2j/nm1puFytaOItNYy8OyBHCNEe/oOIfBUIyuC8J0Dqgf8UNo8Ir hLs3mjsM64BAUsZbNHFEp2bSEo2TzIHUcHucdcz6C+QIvcLRbDNoAPDKcXNY0kufwURp jDGGVUV1NT5bjDRgYjYBdEiapaa2rUYQ4aA3CNNkPQfY7qkenGqh1W6vagjM4X3HIB+i rs7g== X-Gm-Message-State: AOAM530Ep6whZlBQc6GKQJOlMg7Je76i7SbMR9jZauO4PQIV2jqWOty8 r6TC40pFO+5OUvYiqVLochwc46LH X-Google-Smtp-Source: ABdhPJzk2iCtLiJpmwXyOp0IdEzsWGIoAwaYjfa4oyOHmu7R2F+Wa9nAo0EBnF4Eca/fk5Qj0xzfBA== X-Received: by 2002:a62:9254:: with SMTP id o81mr3615286pfd.73.1596121149963; Thu, 30 Jul 2020 07:59:09 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id d5sm5620864pju.15.2020.07.30.07.59.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jul 2020 07:59:09 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 Jul 2020 22:58:58 +0800 Message-Id: <1596121138-20997-5-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596121138-20997-1-git-send-email-lance.lmwang@gmail.com> References: <1595948614-10861-1-git-send-email-lance.lmwang@gmail.com> <1596121138-20997-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 5/5] avformat/mpegtsenc: support 0x6a descriptor for AC-3 by side data if have 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavformat/mpegtsenc.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 718ddab..f4f4e3d 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -26,6 +26,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/mathematics.h" #include "libavutil/opt.h" +#include "libavutil//mpegts_audio_desc_metadata.h" #include "libavcodec/internal.h" @@ -244,6 +245,8 @@ typedef struct MpegTSWriteStream { /* For Opus */ int opus_queued_samples; int opus_pending_trim_start; + + AVDescriptor6A desc6a; } MpegTSWriteStream; static void mpegts_write_pat(AVFormatContext *s) @@ -486,9 +489,22 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) case AVMEDIA_TYPE_AUDIO: if (ts->flags & MPEGTS_FLAG_SYSTEM_B) { if (codec_id == AV_CODEC_ID_AC3) { + int len = 1; + + if (ts_st->desc6a.component_type_flag) len++; + if (ts_st->desc6a.bsid_flag) len++; + if (ts_st->desc6a.mainid_flag) len++; + if (ts_st->desc6a.asvc_flag) len++; + *q++=0x6a; // AC3 descriptor see A038 DVB SI - *q++=1; // 1 byte, all flags sets to 0 - *q++=0; // omit all fields... + *q++ = len; + *q++ = ts_st->desc6a.component_type_flag << 7 | ts_st->desc6a.bsid_flag << 6 | + ts_st->desc6a.mainid_flag << 5 | ts_st->desc6a.asvc_flag << 4; + + if (ts_st->desc6a.component_type_flag) *q++ = ts_st->desc6a.component_type; + if (ts_st->desc6a.bsid_flag) *q++ = ts_st->desc6a.bsid; + if (ts_st->desc6a.mainid_flag) *q++ = ts_st->desc6a.mainid; + if (ts_st->desc6a.asvc_flag) *q++ = ts_st->desc6a.asvc; } else if (codec_id == AV_CODEC_ID_EAC3) { *q++=0x7a; // EAC3 descriptor see A038 DVB SI *q++=1; // 1 byte, all flags sets to 0 @@ -1075,6 +1091,7 @@ static int mpegts_init(AVFormatContext *s) ts_st->first_pts_check = 1; ts_st->cc = 15; ts_st->discontinuity = ts->flags & MPEGTS_FLAG_DISCONT; + memset(&ts_st->desc6a, 0, sizeof(ts_st->desc6a)); if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) { AVStream *ast; @@ -1843,6 +1860,13 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) * need to count the samples of that too! */ av_log(s, AV_LOG_WARNING, "Got MPEG-TS formatted Opus data, unhandled"); } + } else if (st->codecpar->codec_id == AV_CODEC_ID_AC3) { + AVDescriptor6A *side_data; + int sd_size; + side_data = (AVDescriptor6A *) av_packet_get_side_data(pkt, + AV_PKT_DATA_MPEGTS_DESC_6A, &sd_size); + if (side_data && sd_size == sizeof(*side_data)) + memcpy(&ts_st->desc6a, side_data, sizeof(*side_data)); } if (ts_st->payload_size && (ts_st->payload_size + size > ts->pes_payload_size ||