From patchwork Sat Feb 26 19:31:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 34530 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1321028nkx; Sat, 26 Feb 2022 11:30:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzv+QAtOlMxHcIl8X43aeh5nt00esVnkEw2jhw4Y8D+HQbjmFUBiwki9vol7BnN65azw+fO X-Received: by 2002:a17:906:27db:b0:6ce:6f8:d0e3 with SMTP id k27-20020a17090627db00b006ce06f8d0e3mr10571873ejc.455.1645903828167; Sat, 26 Feb 2022 11:30:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645903828; cv=none; d=google.com; s=arc-20160816; b=PSRvNE1MjTFch8g2ftd8E8lEcL34v3sbgDO7w6Xw9VmH/c11yPoaKV44nGD5QVqmwu JibWze94DKIDJq2MH6MPmQ57dllr+/y7znmMXUHdNKXlEAksDDn6rfuBp6XDExQozA6d SWtwEqnfTU0QZi7cPNrBWOYnWQozaSQgV/ynLgcOxb1BBfdAL3sZxPRbiJ7njNY7z8xm nnYpRg+7UVDc9+crYy2/uTawgYWCH8eXI5j/HBumjiszaHk19qkDy+zhF13xSzX2B7mp OY82TTFtY263uJTWke4ixWgi62aGhEvpNVt0mZOjMIhExYktdsXAG66+1vwyy6IMdiky 7j4Q== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=BGP1gnMPvWnxl3/yexf0LmKayKWOk26mFNH/9E4ubRc=; b=w23uqQqMcYem3XiZXlTUTDwo1Q+rS2NtSSRu2dcAU9dIP2vQi8GRKGYkPoaFKFx+d1 0A5QEcxUlo3SIYQearoRIBx13vV7KHRH3/y6nHS2Jj+lQm7Pslwm+C/9XTdGJypNEu4J 1cNP3Ky1FxYV0MArBX7764R5pYzfMJGLauMz6OJnrpXSXFcdOhsW4LMGzi9nuJKSXYyr XAGzMH6cKBQlarDH7K7c8EcOFg/JvSaLxv0ga3XhyWFheU9TbXL4IaTYiVJLhd4Snw8R LnjeZot3Q+v1a5NSa1nxw93ICjDZN4soNp0OLnJL4eGfvpVr7koQ/EkEsf8Ha6lNoSV4 oRyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=o60P6wHI; 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 nb7-20020a1709071c8700b006cec3e62ab8si4263440ejc.459.2022.02.26.11.30.27; Sat, 26 Feb 2022 11:30:28 -0800 (PST) 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=o60P6wHI; 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 0EACF68AE86; Sat, 26 Feb 2022 21:30:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1C8B468AB7C for ; Sat, 26 Feb 2022 21:30:17 +0200 (EET) Received: by mail-ed1-f52.google.com with SMTP id z22so11921557edd.1 for ; Sat, 26 Feb 2022 11:30:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=sUh3gzp7RRuNk31inQAYDhKSrPyTrQR6fTVTG1/zSuQ=; b=o60P6wHIxAGV46ADznhucnggbPgrrnmv6dy3+oCcrpnudLYxaQG0rCAwaeNJt9rH1r LxkFqgw9BGHzIEW7txZdEfOCjy7dklPMR+eb/pWnZjzkPslSO4lOOURjUx00FUsV8UDW yzI6jIWDmcIHJunBeloogvNQVssvqTQyIvDcPS8Pg6UvLBAAwhY2gKd3zO9nbABo+N5A KhlVxd3O/oBFKkQesa6i7aoatB5u+ftnZyzdfAfvQBazZO8GzgDd2HkrxoQ6037pJzar ll16dQyvJCPsszjWEau9Zk4/d41QorR8Mr5TfRtbNmV+MEU2vQiMi0aNEmnXx43UZde5 Ohsw== 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:mime-version :content-transfer-encoding; bh=sUh3gzp7RRuNk31inQAYDhKSrPyTrQR6fTVTG1/zSuQ=; b=ww86XMe93fvXpjo96IUB/daS8h6jm5TAMr2Ro1+mRaUeW4v0zp1Ce0S66adRm+yImI egmc2TFttjed4aTp67nrXBmvXQpsn4skD/QZBbNDUY2g/O7VywgLnAfzYIEuoeKyatkc E0DPnn4JF94V/oezMHX2EtZiQRFHY5XrD6xXCsm7HAHZJovDtu6JnUj3w254BTYweHap 38e8V95ce4+H6MLsp8GZErB43rRjjHGxr129thAep2ld1VIcGk2xkGNK4o9vAxkRzcaO KsUSkpkfSUla0qTcKTXg7f7ZjyH/U6T1fFoe9S6He2yjOp7l5PGfH1IVkAO+JaMqqF+r yrvw== X-Gm-Message-State: AOAM5308ZGEC1gWYVM48uMN5F3sqqvdOP2+zkHdwIYRnPLukQT1+PQD2 H+mfGmJ4pRKFouD98Gbl9ij0UCKuiyA= X-Received: by 2002:a05:6402:7cb:b0:410:dde2:5992 with SMTP id u11-20020a05640207cb00b00410dde25992mr12882547edy.323.1645903816579; Sat, 26 Feb 2022 11:30:16 -0800 (PST) Received: from localhost.localdomain ([95.168.121.27]) by smtp.gmail.com with ESMTPSA id g7-20020a50e047000000b00410d26534d3sm3208589edl.101.2022.02.26.11.30.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 11:30:16 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Feb 2022 20:31:42 +0100 Message-Id: <20220226193143.715424-1-onemda@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: fix muxing pcm-bluray 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: kZzCDrhhVtDz Signed-off-by: Paul B Mahol --- libavformat/mpegtsenc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 971b3f55d8..48cd54c770 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -2097,6 +2097,10 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) ts_st->dvb_ac3_desc = dvb_ac3_desc; } av_free(hdr); + } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_BLURAY) { + mpegts_write_pes(s, st, buf, size, pts, dts, + pkt->flags & AV_PKT_FLAG_KEY, stream_id); + return 0; } if (ts_st->payload_size && (ts_st->payload_size + size > ts->pes_payload_size || From patchwork Sat Feb 26 19:31:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 34531 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1321120nkx; Sat, 26 Feb 2022 11:30:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxEChV4v0cWQ4JeyyEbYa1dbunQsEzAqHuzuSjh0Iiw7x+oMB0nHuafFP5FEcfCqWV0ToK9 X-Received: by 2002:a17:906:960c:b0:6ce:f326:f0d with SMTP id s12-20020a170906960c00b006cef3260f0dmr10348543ejx.154.1645903837473; Sat, 26 Feb 2022 11:30:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645903837; cv=none; d=google.com; s=arc-20160816; b=wwPxGiIJe76IW8EZnWfS9WMaqXB25x+mzHv3LcQWhxRMYGlkii4hvds8uLz4D+gLfG Q3TmRpfKzpFNBHaPnNbr9UcuMKVK4Nk/r+b+FNKKcgy3WbyrFVWK7msxmloWuLzXDqaU o2TyvtyL9/J4OhUaLVhKWAGOF/r5zdKUpTA/6YTjbLGCqrhVRs3Au/t4N+Wyx32OxuxB D8HLjOQ7EtpwhIYmwWlBSO8osuPtj3WlgAQKiKzq6o54Mt2/rrwcx1o9ppY6Mxw8o+yR 2nE2qGhnzbXXW7TtwfQCK1jQwRaoYz9LVfAPtVwRFr/UKj/WJQPkEJk6qxonRFc4AduF l0vQ== 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=fCwmdiQcD6ffhwOuoXbIzGi4Ij/4CW3Nbc9vwfNZ1mA=; b=Gb8i+Baru8yWKfkICz7d35IGYt1LMc77+wcpBxc2TIOXbgpfV05TMgFkmJ3lYZ/HTU ROyiFnetR3CZ1OYPP7gRbBLIjXYRpgBGsKcIgRzK2KLobGS54AudI1rCbo/qLLFUxhtC qbKtnIqxcopG/LA75ovWP+EVEH6NuKUZXfOqY4yUksHqXqRtyOlGTpBguF75M3SEF44M itzm17DTcnSRs4wuwYF5N6g7yo/ZY04IB3poaaGztRa8D8ksCFfwvqdNnDyknazvjVKs ZmL+eh9VRmcbfXYq520ml6s+42eOMHeCuOiPCBjjfRxEO0S9zlPDfZ0T8J7Bvf3H3G83 FK4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=K94GRfU3; 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 rs27-20020a170907037b00b006ae158467fdsi3767022ejb.949.2022.02.26.11.30.37; Sat, 26 Feb 2022 11:30:37 -0800 (PST) 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=K94GRfU3; 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 4F30268AEBF; Sat, 26 Feb 2022 21:30:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 055BE68AE64 for ; Sat, 26 Feb 2022 21:30:18 +0200 (EET) Received: by mail-ej1-f52.google.com with SMTP id gb39so17260282ejc.1 for ; Sat, 26 Feb 2022 11:30:17 -0800 (PST) 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=u3J10EH+VC7AwL4/E80QH9Y0/4lAmoFnRsNbARjKi3s=; b=K94GRfU3/V7LNNgznFfcvNIRu4B4j0qPCS5MsoGuWuiGx2g3bbnZ2d25u3+R8pT1C9 KUYqpHOJD1DAaMPKOZQM4aRNlMC56JKAxkXPkSN1t6o0j+h1boTIE84b2/QbEnqEKs4H B8Xh2GncbOMxpAocsrnfjFTuA3kfavJvhNEpo5vV8n8VyS29I3wSLsRqOVZoF56bW1ch gsl0qMRvMHQUWPIMWwpuikRSPiwM1AJHEZSwRxiQRZNFsPEpNLZFHjWLqRjDfb1yK+oz OLZ+QiSeYW45pZDrKvRQZW3d0bUrJMHRTy5GoWdZ4RcUFtZph+nbWGCtBfi83OZ4vMYx 0nVg== 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=u3J10EH+VC7AwL4/E80QH9Y0/4lAmoFnRsNbARjKi3s=; b=ctLDMrYN0wexBpQOQGa89ZzdWGZIOH7ZTC/0w0gsm9dQ3cqWSOSLU8sYeP4KnTgQRf SFCYyeMMHRqaaHXeon+z38phkgSA1dz3awYOE0aMagSFTAmVsgzmcLEi8te5OufbTHOl FPC5BiK+7sTc3qfCdnHvjgMZFroiWTLw0uz/RpJ2m4n0DT6fDzcldyQfaK62vqmOPxxv 6+pVQzmboJmuzCExpltS31Jms0qok1MLHimtSQCBg2ubmcMR/MBliYCsrxrWhFsBrKYm rFu+CFQpxgMdJzGJPmQ1/iXSeu/qAKUu2QP3thKMILKJ2DQalumJ70VSOHiHFpAKMZ3X 5SUw== X-Gm-Message-State: AOAM530cM73TNwM2v2F/+RJb1hCbQlDVyed2Hx0CR5UCdGgUNS6BQLdU xKUblv39xQi9FBH4lH2gI06IF/qjOoE= X-Received: by 2002:a17:907:3c10:b0:6b9:6f01:37b2 with SMTP id gh16-20020a1709073c1000b006b96f0137b2mr10579757ejc.656.1645903817371; Sat, 26 Feb 2022 11:30:17 -0800 (PST) Received: from localhost.localdomain ([95.168.121.27]) by smtp.gmail.com with ESMTPSA id g7-20020a50e047000000b00410d26534d3sm3208589edl.101.2022.02.26.11.30.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 11:30:17 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Feb 2022 20:31:43 +0100 Message-Id: <20220226193143.715424-2-onemda@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220226193143.715424-1-onemda@gmail.com> References: <20220226193143.715424-1-onemda@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec: add pcm-bluray encoder 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: MoHVX66BBb6x Signed-off-by: Paul B Mahol --- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/pcm-blurayenc.c | 291 +++++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+) create mode 100644 libavcodec/pcm-blurayenc.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 6076b4ad80..e34a9ae862 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -800,6 +800,7 @@ OBJS-$(CONFIG_ZMBV_ENCODER) += zmbvenc.o # (AD)PCM decoders/encoders OBJS-$(CONFIG_PCM_ALAW_DECODER) += pcm.o OBJS-$(CONFIG_PCM_ALAW_ENCODER) += pcm.o +OBJS-$(CONFIG_PCM_BLURAY_ENCODER) += pcm-blurayenc.o OBJS-$(CONFIG_PCM_BLURAY_DECODER) += pcm-bluray.o OBJS-$(CONFIG_PCM_DVD_DECODER) += pcm-dvd.o OBJS-$(CONFIG_PCM_DVD_ENCODER) += pcm-dvdenc.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index d1e10197de..1be67e3ec3 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -531,6 +531,7 @@ extern const AVCodec ff_xma2_decoder; /* PCM codecs */ extern const AVCodec ff_pcm_alaw_encoder; extern const AVCodec ff_pcm_alaw_decoder; +extern const AVCodec ff_pcm_bluray_encoder; extern const AVCodec ff_pcm_bluray_decoder; extern const AVCodec ff_pcm_dvd_encoder; extern const AVCodec ff_pcm_dvd_decoder; diff --git a/libavcodec/pcm-blurayenc.c b/libavcodec/pcm-blurayenc.c new file mode 100644 index 0000000000..9201ad9690 --- /dev/null +++ b/libavcodec/pcm-blurayenc.c @@ -0,0 +1,291 @@ +/* + * LPCM codecs for PCM formats found in Blu-ray m2ts streams + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/channel_layout.h" +#include "avcodec.h" +#include "bytestream.h" +#include "encode.h" +#include "internal.h" + +typedef struct BlurayPCMEncContext { + uint16_t header; // Header added to every frame +} BlurayPCMEncContext; + +static av_cold int pcm_bluray_encode_init(AVCodecContext *avctx) +{ + BlurayPCMEncContext *s = avctx->priv_data; + uint8_t ch_layout; + int quant, freq; + + switch (avctx->sample_rate) { + case 48000: + freq = 1; + break; + case 96000: + freq = 4; + break; + case 192000: + freq = 5; + break; + } + + switch (avctx->sample_fmt) { + case AV_SAMPLE_FMT_S16: + avctx->bits_per_coded_sample = 16; + quant = 1; + break; + case AV_SAMPLE_FMT_S32: + avctx->bits_per_coded_sample = 24; + quant = 3; + break; + } + + switch (avctx->channel_layout) { + case AV_CH_LAYOUT_MONO: + ch_layout = 1; + break; + case AV_CH_LAYOUT_STEREO: + ch_layout = 3; + break; + case AV_CH_LAYOUT_SURROUND: + ch_layout = 4; + break; + case AV_CH_LAYOUT_2_1: + ch_layout = 5; + break; + case AV_CH_LAYOUT_4POINT0: + ch_layout = 6; + break; + case AV_CH_LAYOUT_2_2: + ch_layout = 7; + break; + case AV_CH_LAYOUT_5POINT0: + ch_layout = 8; + break; + case AV_CH_LAYOUT_5POINT1: + ch_layout = 9; + break; + case AV_CH_LAYOUT_7POINT0: + ch_layout = 10; + break; + case AV_CH_LAYOUT_7POINT1: + ch_layout = 11; + break; + default: + return AVERROR_BUG; + } + + s->header = (((ch_layout << 4) | freq) << 8) | (quant << 6); + + return 0; +} + +static int pcm_bluray_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, + const AVFrame *frame, int *got_packet_ptr) +{ + BlurayPCMEncContext *s = avctx->priv_data; + int sample_size, samples, channel, num_dest_channels; + const int16_t *src16; + const int32_t *src32; + unsigned pkt_size; + PutByteContext pb; + int ret; + + num_dest_channels = FFALIGN(avctx->channels, 2); + sample_size = (num_dest_channels * + (avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3; + samples = frame->nb_samples; + + pkt_size = sample_size * samples + 4; + + if ((ret = ff_get_encode_buffer(avctx, avpkt, pkt_size, 0)) < 0) + return ret; + + AV_WB16(avpkt->data, pkt_size - 4); + AV_WB16(avpkt->data + 2, s->header); + + src16 = (const int16_t *)frame->data[0]; + src32 = (const int32_t *)frame->data[0]; + + bytestream2_init_writer(&pb, avpkt->data + 4, avpkt->size - 4); + + switch (avctx->channel_layout) { + /* cases with same number of source and coded channels */ + case AV_CH_LAYOUT_STEREO: + case AV_CH_LAYOUT_4POINT0: + case AV_CH_LAYOUT_2_2: + samples *= num_dest_channels; + if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) { +#if HAVE_BIGENDIAN + bytestream2_put_buffer(&pb, src16, buf_size); +#else + do { + bytestream2_put_be16u(&pb, *src16++); + } while (--samples); +#endif + } else { + do { + bytestream2_put_be24u(&pb, (*src32++) >> 8); + } while (--samples); + } + break; + /* cases where number of source channels = coded channels + 1 */ + case AV_CH_LAYOUT_MONO: + case AV_CH_LAYOUT_SURROUND: + case AV_CH_LAYOUT_2_1: + case AV_CH_LAYOUT_5POINT0: + if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) { + do { +#if HAVE_BIGENDIAN + bytestream2_put_bufferu(&pb, src16, avctx->channels * 2); + src16 += avctx->channels; +#else + channel = avctx->channels; + do { + bytestream2_put_be16u(&pb, *src16++); + } while (--channel); +#endif + bytestream2_put_ne16(&pb, 0); + } while (--samples); + } else { + do { + channel = avctx->channels; + do { + bytestream2_put_be24u(&pb, (*src32++) >> 8); + } while (--channel); + bytestream2_put_ne24(&pb, 0); + } while (--samples); + } + break; + /* remapping: L, R, C, LBack, RBack, LF */ + case AV_CH_LAYOUT_5POINT1: + if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) { + do { + bytestream2_put_be16u(&pb, src16[0]); + bytestream2_put_be16u(&pb, src16[1]); + bytestream2_put_be16u(&pb, src16[2]); + bytestream2_put_be16u(&pb, src16[4]); + bytestream2_put_be16u(&pb, src16[5]); + bytestream2_put_be16u(&pb, src16[3]); + src16 += 6; + } while (--samples); + } else { + do { + bytestream2_put_be24u(&pb, src32[0] >> 8); + bytestream2_put_be24u(&pb, src32[1] >> 8); + bytestream2_put_be24u(&pb, src32[2] >> 8); + bytestream2_put_be24u(&pb, src32[4] >> 8); + bytestream2_put_be24u(&pb, src32[5] >> 8); + bytestream2_put_be24u(&pb, src32[3] >> 8); + src32 += 6; + } while (--samples); + } + break; + /* remapping: L, R, C, LSide, LBack, RBack, RSide, */ + case AV_CH_LAYOUT_7POINT0: + if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) { + do { + bytestream2_put_be16u(&pb, src16[0]); + bytestream2_put_be16u(&pb, src16[1]); + bytestream2_put_be16u(&pb, src16[2]); + bytestream2_put_be16u(&pb, src16[5]); + bytestream2_put_be16u(&pb, src16[3]); + bytestream2_put_be16u(&pb, src16[4]); + bytestream2_put_be16u(&pb, src16[6]); + src16 += 7; + bytestream2_put_ne16(&pb, 0); + } while (--samples); + } else { + do { + bytestream2_put_be24u(&pb, src32[0] >> 8); + bytestream2_put_be24u(&pb, src32[1] >> 8); + bytestream2_put_be24u(&pb, src32[2] >> 8); + bytestream2_put_be24u(&pb, src32[5] >> 8); + bytestream2_put_be24u(&pb, src32[3] >> 8); + bytestream2_put_be24u(&pb, src32[4] >> 8); + bytestream2_put_be24u(&pb, src32[6] >> 8); + src32 += 7; + bytestream2_put_ne24(&pb, 0); + } while (--samples); + } + break; + /* remapping: L, R, C, LSide, LBack, RBack, RSide, LF */ + case AV_CH_LAYOUT_7POINT1: + if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) { + do { + bytestream2_put_be16u(&pb, src16[0]); + bytestream2_put_be16u(&pb, src16[1]); + bytestream2_put_be16u(&pb, src16[2]); + bytestream2_put_be16u(&pb, src16[6]); + bytestream2_put_be16u(&pb, src16[4]); + bytestream2_put_be16u(&pb, src16[5]); + bytestream2_put_be16u(&pb, src16[7]); + bytestream2_put_be16u(&pb, src16[3]); + src16 += 8; + } while (--samples); + } else { + do { + bytestream2_put_be24u(&pb, src32[0]); + bytestream2_put_be24u(&pb, src32[1]); + bytestream2_put_be24u(&pb, src32[2]); + bytestream2_put_be24u(&pb, src32[6]); + bytestream2_put_be24u(&pb, src32[4]); + bytestream2_put_be24u(&pb, src32[5]); + bytestream2_put_be24u(&pb, src32[7]); + bytestream2_put_be24u(&pb, src32[3]); + src32 += 8; + } while (--samples); + } + break; + } + + avpkt->pts = frame->pts; + avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); + *got_packet_ptr = 1; + + return 0; +} + +const AVCodec ff_pcm_bluray_encoder = { + .name = "pcm_bluray", + .long_name = NULL_IF_CONFIG_SMALL("PCM signed 16|20|24-bit big-endian for Blu-ray media"), + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_PCM_BLURAY, + .priv_data_size = sizeof(BlurayPCMEncContext), + .init = pcm_bluray_encode_init, + .encode2 = pcm_bluray_encode_frame, + .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME, + .supported_samplerates = (const int[]) { 48000, 96000, 192000, 0 }, + .channel_layouts = (const uint64_t[]) { + AV_CH_LAYOUT_MONO, + AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_SURROUND, + AV_CH_LAYOUT_2_1, + AV_CH_LAYOUT_4POINT0, + AV_CH_LAYOUT_2_2, + AV_CH_LAYOUT_5POINT0, + AV_CH_LAYOUT_5POINT1, + AV_CH_LAYOUT_7POINT0, + AV_CH_LAYOUT_7POINT1, + 0 }, + .sample_fmts = (const enum AVSampleFormat[]) { + AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +};