From patchwork Thu Jun 30 06:42:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 36542 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp106805pzh; Wed, 29 Jun 2022 23:43:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uvq9RSzg3XCtFM1WIGxue52WZw8v7HYH8LtngcgleIayP77gmIYtYNqXv5J4pyRqyWvHO6 X-Received: by 2002:a05:6402:3587:b0:435:b9a1:d5c5 with SMTP id y7-20020a056402358700b00435b9a1d5c5mr9458124edc.219.1656571418566; Wed, 29 Jun 2022 23:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656571418; cv=none; d=google.com; s=arc-20160816; b=I/5ijag6vmTBVGaDTqGv54WsDtumWlJHv+V2n7vcwTmLuHS06LkGemvIL5Tb3/WCNE H3KnYxwc5TqKDV0vhFmahaH0lX4F1kYpPSr8IvGQAAftAap/odIc6z3VZboPh8zyvfm2 rRVATb+PRGRYn3iek0Q4jOEawX18tMDJHmDhF45V8TO8LrB0ZZdSbbJVjeyPgzrFmsGS 3uM9ZxB24RDiqZTdp0cFen+niT0VZ2rwAIDvcx9VObei33p9VA0BLZwh+v2ALbm1i1IO cf6bbuwPCZNwcE9U0iNfS7VsyNeQOtWxQlyjNdgIkiKhCrJuZDjU1DAjr433j/r1Y9fy NS2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=TDHfriwAYmMj8fHTLk0IJVAKvt+lrgNzrpuob4nQb28=; b=T6aWESLqJAjwtJTNLoKc+iIImOny9JccWRwuLLH3ni35L/R25KQ7dmb+UPOlLbcf89 /JH8cYJQ9nzfGtA7huYt0UZKNmmOVfe+NP6fdLfrr0QyHKjdX8KMb9OD1RLhdoKCaLHY RO1ymjYKNklE9myp+FAcIgNi30QyBRHHTn3RVDVLEm6zV5oBA90tYjjzg9l9Xf05YNda j9pj7QMyIOwDe7Rd17UobE2P5RLPwqX9sPGoaM0Wc0yxz8VtmfgXzD8ypAkskOX49ZcQ iShVu0lOUz9WvgTwX0z8XOdqrIOeqGzT206PnE6xLaWmUdb9XNs8ttc17JVk6t2ZFUH+ svJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Sl8BnoFF; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hc39-20020a17090716a700b00711da366315si4509974ejc.717.2022.06.29.23.43.26; Wed, 29 Jun 2022 23:43:38 -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=@gmail.com header.s=20210112 header.b=Sl8BnoFF; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CBB6A68B6AC; Thu, 30 Jun 2022 09:42:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D04E568B761 for ; Thu, 30 Jun 2022 09:42:48 +0300 (EEST) Received: by mail-lf1-f43.google.com with SMTP id e12so7706019lfr.6 for ; Wed, 29 Jun 2022 23:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=nZxnpTQNRXnqdoYbb4ISBFYrSW+RnRYA2ZRea53CT3I=; b=Sl8BnoFF2jSFPLcpT/yotE6CDqJPHDr8mZ1CcJOH0WJuLNpce8I3eieKmA9GmBgyzv +F6gti/s+uwcpANH6oAMFDGajp7hsFmPYdGx916hYmUdVGQdi6ounN6jkIBSg0NSoWEI EfsQ7jvq9716EMLWvxH5b5r3NVJAjqLl3+qt9+zcOJUFflhBu6ZlMrOL3M48vbex4rs8 9JTdoefYXTPa4qYlLPh8CP2w3XNNvIknRwyKX9uEA0JO3o7Qj4On3SqPUex5hKzQxXCv Qaq5KO68AUZDlZZtCO62AF1lqeV4GqonBLaeaYv5+lTGpA8tA3iF9Km6F5QHb9OU0sIF BnEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nZxnpTQNRXnqdoYbb4ISBFYrSW+RnRYA2ZRea53CT3I=; b=IsWE+Yi82FkrMqRhLBjSIZr1U+Jqcp8KgGxCvNRjEQDuPwbo9CA3x48qYSHJEAwLzD AVwIFNvQ32mVKWJ8aDmhyLS12ehknxw5qeSh4/JMoL50KSuIRU4B4VYIQbcQ6C1tRIGc oO4/uwdIHixgYimnlb+UstmqV2NZpyrn4RIq3tRv0w5ytMWQPsmfXuJhpwq1yEyhpUtA Ljf59swx2ctuJzU6pq+iDUr/DclXCM9DPspTI9D9tsCj0zJa7qJGF1E76q7ojrPiAH7m qnF+neAPIQZ3zONkaRORZQwhl8t9ur8KYtL+yxI6TJICMW10q16g8hvbG4pzE99Lxee5 Ot5Q== X-Gm-Message-State: AJIora/29tvSHwLqZGW9qHeFfd62zsqGIYLtJgWFT+uYGWRtX2WMJN9V 8dJDU8Y0cMCKWqceMlfH4qiKEwswnRA= X-Received: by 2002:a05:6512:31e:b0:47f:6193:2262 with SMTP id t30-20020a056512031e00b0047f61932262mr4510953lfp.502.1656571368172; Wed, 29 Jun 2022 23:42:48 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id c17-20020a056512075100b00479112bb555sm2948091lfs.60.2022.06.29.23.42.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 23:42:47 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 Jun 2022 09:42:34 +0300 Message-Id: <20220630064238.45315-4-jeebjp@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220630064238.45315-1-jeebjp@gmail.com> References: <20220630064238.45315-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 3/7] avformat/movenc: enable handle_eac3 to handle AC-3 tracks 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: eVySw027t+18 From: Jan Ekström Add the AC-3 frame type, as well as early exit from additional packet parsing in case of AC-3, as only a single packet is required to get the required information. Additionally, expose ac3_bit_rate_code via the eac3_info struct as it is required for AC3SpecificBox. Signed-off-by: Jan Ekström --- libavformat/movenc.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index b799491fd4..8316fd9a45 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -384,6 +384,7 @@ struct eac3_info { /* Layout of the EC3SpecificBox */ /* maximum bitrate */ uint16_t data_rate; + int8_t ac3_bit_rate_code; /* number of independent substreams */ uint8_t num_ind_sub; struct { @@ -414,8 +415,12 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) struct eac3_info *info; int num_blocks, ret; - if (!track->eac3_priv && !(track->eac3_priv = av_mallocz(sizeof(*info)))) - return AVERROR(ENOMEM); + if (!track->eac3_priv) { + if (!(track->eac3_priv = av_mallocz(sizeof(*info)))) + return AVERROR(ENOMEM); + + ((struct eac3_info *)track->eac3_priv)->ac3_bit_rate_code = -1; + } info = track->eac3_priv; if (!info->pkt && !(info->pkt = av_packet_alloc())) @@ -432,6 +437,8 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) } info->data_rate = FFMAX(info->data_rate, hdr->bit_rate / 1000); + info->ac3_bit_rate_code = FFMAX(info->ac3_bit_rate_code, + hdr->ac3_bit_rate_code); num_blocks = hdr->num_blocks; if (!info->ec3_done) { @@ -443,7 +450,8 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) /* this should always be the case, given that our AC-3 parser * concatenates dependent frames to their independent parent */ - if (hdr->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) { + if (hdr->frame_type == EAC3_FRAME_TYPE_INDEPENDENT || + hdr->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) { /* substream ids must be incremental */ if (hdr->substreamid > info->num_ind_sub + 1) { ret = AVERROR(EINVAL); @@ -475,6 +483,14 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) info->substream[hdr->substreamid].acmod = hdr->channel_mode; info->substream[hdr->substreamid].lfeon = hdr->lfe_on; + if (track->par->codec_id == AV_CODEC_ID_AC3) { + // with AC-3 we only require the information of a single packet, + // so we can finish as soon as the basic values of the bit stream + // have been set to the track's informational structure. + info->ec3_done = 1; + goto concatenate; + } + /* Parse dependent substream(s), if any */ if (pkt->size != hdr->frame_size) { int cumul_size = hdr->frame_size;