From patchwork Thu Jun 30 06:42:36 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: 36543 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp106834pzh; Wed, 29 Jun 2022 23:43:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uujIwfZLRGu/++/4H+Tybu+czREzcEaa1JnlSbRtLKCsxSGTG83D2AsFc/yJdQ8+aBI1fv X-Received: by 2002:a05:6402:3707:b0:437:61f9:57a9 with SMTP id ek7-20020a056402370700b0043761f957a9mr9200413edb.1.1656571426113; Wed, 29 Jun 2022 23:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656571426; cv=none; d=google.com; s=arc-20160816; b=jewqxEW3ow4msp4/9WBzpVChvV7UaWlsP2isNyiC9KSo0vvYFUEGrGdR7xNrRCq8Ti RBSnwVcLMgldxRaxtBkJBEI464brzi8cydoEf4Qq65J3JaqhqvMb23WfxA9qFg1D3mSV piN/OGcGV1XZ2WMu/QAthuCFEBOodqcrTH8NF3hAsMtUMl5PO8TSxMMcHrYRWJp31i/6 cA9P0wC1V+q49G6fPcXrO3SVDM2TTarH+RVtMGxEJdufC0uy6uFXgO3wcsn5vqps2TAs 7CNyqMYn3BgoBxV5ryMhFUi2jn0OGb4jQ+D+WJJxgwwjEwd/l/Wx5CAASFuiUYiUwH5a cFwg== 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=Ac6mZJrtbUarMhVzUZpb2nlm4VRBfmAymIAX0nnZQdo=; b=a3LKYHK1dIcEbboeqDMAs0NSYoto/k/8FBYqZaBWI9CISYvoT/JKL7gbrzPDPuprba dNJMNM3rgVHPYqhk+DE53e251ClJ7DNYO5nOp0VOYiBOqP2IVyaeuqzKvJeU/0MC8WtF E7iOfBr0/0ReqR3lOq6PwLPFrs2LneXT/xkkBkDABV98t7EasePUiCC7ArTvV/5/2CPm jQQv7orz9QXKWr6EFJ6W4O+jfwN1xwbouKzUGOQu2BeIIhsxu6KzdrKS+B+retBwtwgN OEGUBtXiZJe9Q3OUmj86gTi6Tb+YbImL8K0obD14cAVcXy4Yh4U05rhVS63rzgNOzJ+r dgZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=gGiAZzbp; 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 z7-20020a05640235c700b0042de30cf6e5si27020443edc.365.2022.06.29.23.43.45; Wed, 29 Jun 2022 23:43:46 -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=gGiAZzbp; 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 DA73868B7D8; Thu, 30 Jun 2022 09:42:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D61F468B7B2 for ; Thu, 30 Jun 2022 09:42:50 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id a13so31983266lfr.10 for ; Wed, 29 Jun 2022 23:42:50 -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=3/HYICoP3BHzB8rALuALWgjoEjeOvqSPVxAIkTjb3yc=; b=gGiAZzbpwKUOuybELBIxU/Ac75SeceYg3qxIJ2ozdXdOlotVAGJfx3M4YhF+j2dDus Pm/4gSV/3lVzNJdvFJSuNTrcUKwQi2PGodj3lqAlZ4/fljMR2r6ciw9CjDBZ3sKq1f+b M/hatzg5iPfaqFQlb209nKWVxBqkJvGxWHpRpZntADXq525baIrDlAriprTd+q2d/ZUW mBm60yhwqoaQZv4Pwdb5L5R9Q1Mfk6rzhtMmFQ9ErTgTunDCiaCLd9FP4NXSU4Lhu3+Z rIbB8aEUPLT91UwDOCPuuNpFKsEDvnLmx2WhQ4jCJvPO7h9uBAxIrKpZQZwqnk/kXfpa UXTQ== 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=3/HYICoP3BHzB8rALuALWgjoEjeOvqSPVxAIkTjb3yc=; b=fWUNmf7/NJHSYBYOcaGYb9HIax1e/E1L0YNjCucHj6fP5jBqKuT/SbTOCsl30imR35 beWFp0YMI7vqxI8yCFUVUUsGYS5/+dZ2u0zQ1KM4lCNG+2XSOkCz5i9pI+yyaRo5Qg7T ZSZRdQfNL36nlfS0xFjFFppverNTQ6r2nIkXtHzXI3x4OMSL4OImJgWDsDtmNQaDPD0f OxHL7JrACOt99uRIJMBjE4heQZf9oX4wh5E96ABjo8gNao97I/w1yqCp/pRdsL256gRB FF1j4XaSLhf7s1qrdJl8JX48yBOW55L7WqGF4nXLo+8XywMrAiJ6EamDc1yUD+cO+Z1a uPnQ== X-Gm-Message-State: AJIora8lwaHPPdd3mXT8NRWSKY9u85NicYSb0wpSt++m5oEGQF56TqZk ATdKJ4icLhlMW/UfKHIc0E7eefe/zFk= X-Received: by 2002:a05:6512:118f:b0:47f:6a1a:20d4 with SMTP id g15-20020a056512118f00b0047f6a1a20d4mr4238776lfr.428.1656571370115; Wed, 29 Jun 2022 23:42:50 -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.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 23:42:49 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 Jun 2022 09:42:36 +0300 Message-Id: <20220630064238.45315-6-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 5/7] avformat/movenc: utilize existing AC-3 parsing workflow for AC-3 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: Qmpid2JSlDCd From: Jan Ekström Signed-off-by: Jan Ekström --- libavformat/movenc.c | 46 +++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index b9e3f1a63e..382c2f2e75 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -363,44 +363,34 @@ struct eac3_info { static int mov_write_ac3_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { - GetBitContext gbc; + struct eac3_info *info = track->eac3_priv; PutBitContext pbc; uint8_t buf[3]; - int fscod, bsid, bsmod, acmod, lfeon, frmsizecod; - if (track->vos_len < 7) { + if (!info || !info->ec3_done) { av_log(s, AV_LOG_ERROR, "Cannot write moov atom before AC3 packets." " Set the delay_moov flag to fix this.\n"); return AVERROR(EINVAL); } + if (info->ac3_bit_rate_code < 0) { + av_log(s, AV_LOG_ERROR, + "No valid AC3 bit rate code for data rate of %d!\n", + info->data_rate); + return AVERROR(EINVAL); + } + avio_wb32(pb, 11); ffio_wfourcc(pb, "dac3"); - init_get_bits(&gbc, track->vos_data + 4, (track->vos_len - 4) * 8); - fscod = get_bits(&gbc, 2); - frmsizecod = get_bits(&gbc, 6); - bsid = get_bits(&gbc, 5); - bsmod = get_bits(&gbc, 3); - acmod = get_bits(&gbc, 3); - if (acmod == 2) { - skip_bits(&gbc, 2); // dsurmod - } else { - if ((acmod & 1) && acmod != 1) - skip_bits(&gbc, 2); // cmixlev - if (acmod & 4) - skip_bits(&gbc, 2); // surmixlev - } - lfeon = get_bits1(&gbc); - init_put_bits(&pbc, buf, sizeof(buf)); - put_bits(&pbc, 2, fscod); - put_bits(&pbc, 5, bsid); - put_bits(&pbc, 3, bsmod); - put_bits(&pbc, 3, acmod); - put_bits(&pbc, 1, lfeon); - put_bits(&pbc, 5, frmsizecod >> 1); // bit_rate_code + put_bits(&pbc, 2, info->substream[0].fscod); + put_bits(&pbc, 5, info->substream[0].bsid); + put_bits(&pbc, 3, info->substream[0].bsmod); + put_bits(&pbc, 3, info->substream[0].acmod); + put_bits(&pbc, 1, info->substream[0].lfeon); + put_bits(&pbc, 5, info->ac3_bit_rate_code); // bit_rate_code put_bits(&pbc, 5, 0); // reserved flush_put_bits(&pbc); @@ -6029,8 +6019,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) if ((par->codec_id == AV_CODEC_ID_DNXHD || par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_HEVC || - par->codec_id == AV_CODEC_ID_TRUEHD || - par->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len && + par->codec_id == AV_CODEC_ID_TRUEHD) && !trk->vos_len && !TAG_IS_AVCI(trk->tag)) { /* copy frame to create needed atoms */ trk->vos_len = size; @@ -6107,7 +6096,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) } } - } else if (par->codec_id == AV_CODEC_ID_EAC3) { + } else if (par->codec_id == AV_CODEC_ID_EAC3 || + par->codec_id == AV_CODEC_ID_AC3) { size = handle_eac3(mov, pkt, trk); if (size < 0) return size;