From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id CBB7E40716 for ; Mon, 28 Feb 2022 19:31:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E2080688180; Mon, 28 Feb 2022 21:31:31 +0200 (EET) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D62A9688180 for ; Mon, 28 Feb 2022 21:31:24 +0200 (EET) Received: from localhost (213-47-68-29.cable.dynamic.surfer.at [213.47.68.29]) (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 8BD9A240003 for ; Mon, 28 Feb 2022 19:31:23 +0000 (UTC) Date: Mon, 28 Feb 2022 20:31:22 +0100 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20220228193122.GU2829255@pb2> References: <20220226193143.715424-1-onemda@gmail.com> <20220226193143.715424-2-onemda@gmail.com> MIME-Version: 1.0 In-Reply-To: <20220226193143.715424-2-onemda@gmail.com> Subject: Re: [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 Content-Type: multipart/mixed; boundary="===============2281658042846031917==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============2281658042846031917== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="FXdDSTHoS/Cn7JOX" Content-Disposition: inline --FXdDSTHoS/Cn7JOX Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Feb 26, 2022 at 08:31:43PM +0100, Paul B Mahol wrote: > 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 >=20 > 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) +=3D zmbvenc.o > # (AD)PCM decoders/encoders > OBJS-$(CONFIG_PCM_ALAW_DECODER) +=3D pcm.o > OBJS-$(CONFIG_PCM_ALAW_ENCODER) +=3D pcm.o > +OBJS-$(CONFIG_PCM_BLURAY_ENCODER) +=3D pcm-blurayenc.o > OBJS-$(CONFIG_PCM_BLURAY_DECODER) +=3D pcm-bluray.o > OBJS-$(CONFIG_PCM_DVD_DECODER) +=3D pcm-dvd.o > OBJS-$(CONFIG_PCM_DVD_ENCODER) +=3D 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-1= 301 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 =3D avctx->priv_data; > + uint8_t ch_layout; > + int quant, freq; > + > + switch (avctx->sample_rate) { > + case 48000: > + freq =3D 1; > + break; > + case 96000: > + freq =3D 4; > + break; > + case 192000: > + freq =3D 5; > + break; > + } > + > + switch (avctx->sample_fmt) { > + case AV_SAMPLE_FMT_S16: > + avctx->bits_per_coded_sample =3D 16; > + quant =3D 1; > + break; > + case AV_SAMPLE_FMT_S32: > + avctx->bits_per_coded_sample =3D 24; > + quant =3D 3; > + break; > + } > + > + switch (avctx->channel_layout) { > + case AV_CH_LAYOUT_MONO: > + ch_layout =3D 1; > + break; > + case AV_CH_LAYOUT_STEREO: > + ch_layout =3D 3; > + break; > + case AV_CH_LAYOUT_SURROUND: > + ch_layout =3D 4; > + break; > + case AV_CH_LAYOUT_2_1: > + ch_layout =3D 5; > + break; > + case AV_CH_LAYOUT_4POINT0: > + ch_layout =3D 6; > + break; > + case AV_CH_LAYOUT_2_2: > + ch_layout =3D 7; > + break; > + case AV_CH_LAYOUT_5POINT0: > + ch_layout =3D 8; > + break; > + case AV_CH_LAYOUT_5POINT1: > + ch_layout =3D 9; > + break; > + case AV_CH_LAYOUT_7POINT0: > + ch_layout =3D 10; > + break; > + case AV_CH_LAYOUT_7POINT1: > + ch_layout =3D 11; > + break; > + default: > + return AVERROR_BUG; > + } > + > + s->header =3D (((ch_layout << 4) | freq) << 8) | (quant << 6); > + > + return 0; > +} > + > +static int pcm_bluray_encode_frame(AVCodecContext *avctx, AVPacket *avpk= t, > + const AVFrame *frame, int *got_packet= _ptr) > +{ > + BlurayPCMEncContext *s =3D 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 =3D FFALIGN(avctx->channels, 2); > + sample_size =3D (num_dest_channels * > + (avctx->sample_fmt =3D=3D AV_SAMPLE_FMT_S16 ? 16 : 24= )) >> 3; > + samples =3D frame->nb_samples; > + > + pkt_size =3D sample_size * samples + 4; > + > + if ((ret =3D 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 =3D (const int16_t *)frame->data[0]; > + src32 =3D (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 *=3D num_dest_channels; > + if (AV_SAMPLE_FMT_S16 =3D=3D avctx->sample_fmt) { > +#if HAVE_BIGENDIAN > + bytestream2_put_buffer(&pb, src16, buf_size); > +#else fails to build for mips src/libavcodec/pcm-blurayenc.c: In function =E2=80=98pcm_bluray_encode_fram= e=E2=80=99: src/libavcodec/pcm-blurayenc.c:137:48: error: =E2=80=98buf_size=E2=80=99 un= declared (first use in this function); did you mean =E2=80=98pkt_size=E2=80= =99? bytestream2_put_buffer(&pb, src16, buf_size); ^~~~~~~~ pkt_size src/libavcodec/pcm-blurayenc.c:137:48: note: each undeclared identifier is = reported only once for each function it appears in src/libavcodec/pcm-blurayenc.c:137:41: warning: passing argument 2 of =E2= =80=98bytestream2_put_buffer=E2=80=99 from incompatible pointer type [-Winc= ompatible-pointer-types] bytestream2_put_buffer(&pb, src16, buf_size); ^~~~~ In file included from src/libavcodec/pcm-blurayenc.c:23:0: src/libavcodec/bytestream.h:286:38: note: expected =E2=80=98const uint8_t *= {aka const unsigned char *}=E2=80=99 but argument is of type =E2=80=98cons= t int16_t * {aka const short int *}=E2=80=99 static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext= *p, ^~~~~~~~~~~~~~~~~~~~~~ src/libavcodec/pcm-blurayenc.c:157:46: warning: passing argument 2 of =E2= =80=98bytestream2_put_bufferu=E2=80=99 from incompatible pointer type [-Win= compatible-pointer-types] bytestream2_put_bufferu(&pb, src16, avctx->channels * 2); ^~~~~ In file included from src/libavcodec/pcm-blurayenc.c:23:0: src/libavcodec/bytestream.h:301:38: note: expected =E2=80=98const uint8_t *= {aka const unsigned char *}=E2=80=99 but argument is of type =E2=80=98cons= t int16_t * {aka const short int *}=E2=80=99 static av_always_inline unsigned int bytestream2_put_bufferu(PutByteContex= t *p, ^~~~~~~~~~~~~~~~~~~~~~~ src/ffbuild/common.mak:78: recipe for target 'libavcodec/pcm-blurayenc.o' f= ailed make: *** [libavcodec/pcm-blurayenc.o] Error 1 [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Elect your leaders based on what they did after the last election, not based on what they say before an election. --FXdDSTHoS/Cn7JOX Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCYh0jBwAKCRBhHseHBAsP q06bAJ9yh5EG77+Qtgw029e8jlDdxYW+vQCeJlCzFBFZM8DprXxuSnHiTuGiSjY= =OH24 -----END PGP SIGNATURE----- --FXdDSTHoS/Cn7JOX-- --===============2281658042846031917== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". --===============2281658042846031917==--