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 E88D842458 for ; Tue, 18 Apr 2023 21:07:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 50C4968BE5A; Wed, 19 Apr 2023 00:07:14 +0300 (EEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4316868077D for ; Wed, 19 Apr 2023 00:07:07 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 4E41060002 for ; Tue, 18 Apr 2023 21:07:06 +0000 (UTC) Date: Tue, 18 Apr 2023 23:07:05 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20230418210705.GN275832@pb2> References: MIME-Version: 1.0 In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH] PDV format support 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="===============3086505838976655183==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============3086505838976655183== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="TN8pJM9vJMHHFgJc" Content-Disposition: inline --TN8pJM9vJMHHFgJc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Apr 17, 2023 at 08:46:15PM +0200, Paul B Mahol wrote: > Patches attached. > Makefile | 1=20 > allformats.c | 1=20 > pdvdec.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++ > 3 files changed, 174 insertions(+) > c1a534f179e76dfe3731528666d37032b57fb5b0 0002-avformat-add-PDV-demuxer.p= atch > From acf25fc6ca24838196316b81b25b753d01adbfab Mon Sep 17 00:00:00 2001 > From: Paul B Mahol > Date: Mon, 17 Apr 2023 17:45:23 +0200 > Subject: [PATCH 2/2] avformat: add PDV demuxer >=20 > Signed-off-by: Paul B Mahol > --- > libavformat/Makefile | 1 + > libavformat/allformats.c | 1 + > libavformat/pdvdec.c | 172 +++++++++++++++++++++++++++++++++++++++ > 3 files changed, 174 insertions(+) > create mode 100644 libavformat/pdvdec.c >=20 > diff --git a/libavformat/Makefile b/libavformat/Makefile > index 048649689b..f8ad7c6a11 100644 > --- a/libavformat/Makefile > +++ b/libavformat/Makefile > @@ -471,6 +471,7 @@ OBJS-$(CONFIG_PCM_U8_DEMUXER) +=3D pcmdec.= o pcm.o > OBJS-$(CONFIG_PCM_U8_MUXER) +=3D pcmenc.o rawenc.o > OBJS-$(CONFIG_PCM_VIDC_DEMUXER) +=3D pcmdec.o pcm.o > OBJS-$(CONFIG_PCM_VIDC_MUXER) +=3D pcmenc.o rawenc.o > +OBJS-$(CONFIG_PDV_DEMUXER) +=3D pdvdec.o > OBJS-$(CONFIG_PJS_DEMUXER) +=3D pjsdec.o subtitles.o > OBJS-$(CONFIG_PMP_DEMUXER) +=3D pmpdec.o > OBJS-$(CONFIG_PP_BNK_DEMUXER) +=3D pp_bnk.o > diff --git a/libavformat/allformats.c b/libavformat/allformats.c > index cb5b69e9cd..efdb34e29d 100644 > --- a/libavformat/allformats.c > +++ b/libavformat/allformats.c > @@ -369,6 +369,7 @@ extern const AVInputFormat ff_pcm_u16le_demuxer; > extern const FFOutputFormat ff_pcm_u16le_muxer; > extern const AVInputFormat ff_pcm_u8_demuxer; > extern const FFOutputFormat ff_pcm_u8_muxer; > +extern const AVInputFormat ff_pdv_demuxer; > extern const AVInputFormat ff_pjs_demuxer; > extern const AVInputFormat ff_pmp_demuxer; > extern const AVInputFormat ff_pp_bnk_demuxer; > diff --git a/libavformat/pdvdec.c b/libavformat/pdvdec.c > new file mode 100644 > index 0000000000..3dfef819a9 > --- /dev/null > +++ b/libavformat/pdvdec.c > @@ -0,0 +1,172 @@ > +/* > + * PDV demuxer > + * Copyright (c) 2023 Paul B Mahol > + * > + * 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/avstring.h" > +#include "libavutil/imgutils.h" > + > +#include "avformat.h" > +#include "internal.h" > + > +#define PDV_MAGIC "Playdate VID" > + > +typedef struct PDVDemuxContext { > + int current_frame; > + uint8_t *frame_flags; > + uint32_t *frame_offsets; > +} PDVDemuxContext; > + > +static int pdv_probe(const AVProbeData *pd) > +{ > + if (strncmp(pd->buf, PDV_MAGIC, sizeof(PDV_MAGIC) - 1) =3D=3D 0) > + return AVPROBE_SCORE_MAX; > + return 0; > +} > + > +static int pdv_read_header(AVFormatContext *s) > +{ > + PDVDemuxContext *p =3D s->priv_data; > + AVIOContext *pb =3D s->pb; > + AVCodecParameters *par; > + AVStream *st; > + uint64_t start; > + uint32_t fps; > + > + avio_skip(pb, 16); > + > + st =3D avformat_new_stream(s, NULL); > + if (!st) > + return AVERROR(ENOMEM); > + > + par =3D st->codecpar; > + par->codec_type =3D AVMEDIA_TYPE_VIDEO; > + par->codec_id =3D AV_CODEC_ID_PDV; > + st->start_time =3D 0; > + st->duration =3D > + st->nb_frames =3D avio_rl16(pb); > + avio_skip(pb, 2); > + fps =3D avio_rl32(pb); > + st->avg_frame_rate =3D av_d2q(av_int2float(fps), INT_MAX); > + par->width =3D avio_rl16(pb); > + par->height =3D avio_rl16(pb); > + > + avpriv_set_pts_info(st, 64, st->avg_frame_rate.den, st->avg_frame_ra= te.num); > + > + p->current_frame =3D 0; > + p->frame_flags =3D av_calloc(st->nb_frames + 1, sizeof(*p->frame_fla= gs)); > + p->frame_offsets =3D av_calloc(st->nb_frames + 1, sizeof(*p->frame_o= ffsets)); > + > + if (!p->frame_flags || !p->frame_offsets) > + return AVERROR(ENOMEM); > + > + for (int n =3D 0; n <=3D st->nb_frames; n++) { > + const uint32_t entry =3D avio_rl32(pb); > + > + p->frame_flags[n] =3D entry & 3; > + p->frame_offsets[n] =3D entry >> 2; > + } > + > + start =3D avio_tell(pb); > + > + for (int n =3D 0; n < st->nb_frames; n++) { > + const uint64_t pos =3D start + p->frame_offsets[n]; > + const int32_t size =3D p->frame_offsets[n+1] - p->frame_offsets[= n]; > + const int flags =3D p->frame_flags[n] & 1 ? AVINDEX_KEYFRAME : 0; > + > + if (p->frame_flags[n] =3D=3D 0 || size <=3D 0 || pos + size > av= io_size(pb)) > + break; > + av_add_index_entry(st, pos, n, size, 0, flags); > + } > + > + return 0; > +} > + > +static int pdv_read_packet(AVFormatContext *s, AVPacket *pkt) > +{ > + PDVDemuxContext *p =3D s->priv_data; > + AVStream *st =3D s->streams[0]; > + FFStream *const sti =3D ffstream(st); > + AVIOContext *pb =3D s->pb; > + int32_t size, flags, ret; > + int64_t pos; > + > + if (p->current_frame >=3D st->nb_frames) > + return AVERROR_EOF; > + > + pos =3D sti->index_entries[p->current_frame].pos; > + flags =3D sti->index_entries[p->current_frame].flags; > + size =3D sti->index_entries[p->current_frame].size; > + > + avio_seek(pb, pos, SEEK_SET); > + if (avio_feof(pb) || pos + size > avio_size(pb) || size =3D=3D 0) > + return AVERROR_EOF; > + > + ret =3D av_get_packet(pb, pkt, size); > + if (ret < 0) > + return ret; > + > + if (flags & AVINDEX_KEYFRAME) > + pkt->flags |=3D AV_PKT_FLAG_KEY; > + pkt->stream_index =3D 0; > + pkt->pts =3D p->current_frame++; > + pkt->duration =3D 1; > + > + return 0; > +} > + > +static int pdv_read_close(AVFormatContext *s) > +{ > + PDVDemuxContext *p =3D s->priv_data; > + > + av_freep(&p->frame_flags); > + av_freep(&p->frame_offsets); > + > + return 0; > +} > + > +static int pdv_read_seek(AVFormatContext *s, int stream_index, int64_t t= imestamp, int flags) > +{ > + PDVDemuxContext *p =3D s->priv_data; > + AVStream *st =3D s->streams[stream_index]; > + int index =3D av_index_search_timestamp(st, timestamp, flags); > + > + if (index < 0) > + return -1; > + > + if (avio_seek(s->pb, ffstream(st)->index_entries[index].pos, SEEK_SE= T) < 0) > + return -1; > + > + p->current_frame =3D index; > + > + return 0; > +} > + > +const AVInputFormat ff_pdv_demuxer =3D { > + .name =3D "pdv", > + .long_name =3D NULL_IF_CONFIG_SMALL("PlayDate Video"), > + .priv_data_size =3D sizeof(PDVDemuxContext), > + .flags_internal =3D FF_FMT_INIT_CLEANUP, > + .read_probe =3D pdv_probe, > + .read_header =3D pdv_read_header, > + .read_packet =3D pdv_read_packet, > + .read_close =3D pdv_read_close, > + .read_seek =3D pdv_read_seek, > + .extensions =3D "pdv", > +}; > --=20 > 2.39.1 >=20 > Makefile | 1=20 > allcodecs.c | 1=20 > codec_desc.c | 7 +++ > codec_id.h | 1=20 > pdvdec.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++ > 5 files changed, 137 insertions(+) > 8b37d78c146e291e2a693a16ae0b9241699a4a69 0001-avcodec-add-PDV-decoder.pa= tch > From 5a26b13f589c96075fa1dc269cc768163afe1651 Mon Sep 17 00:00:00 2001 > From: Paul B Mahol > Date: Mon, 17 Apr 2023 19:19:42 +0200 > Subject: [PATCH 1/2] avcodec: add PDV decoder >=20 > Signed-off-by: Paul B Mahol > --- > libavcodec/Makefile | 1 + > libavcodec/allcodecs.c | 1 + > libavcodec/codec_desc.c | 7 +++ > libavcodec/codec_id.h | 1 + > libavcodec/pdvdec.c | 127 ++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 137 insertions(+) [...] > diff --git a/libavcodec/pdvdec.c b/libavcodec/pdvdec.c > new file mode 100644 > index 0000000000..8359feac0d > --- /dev/null > +++ b/libavcodec/pdvdec.c > @@ -0,0 +1,127 @@ > +/* > + * PDV video format > + * > + * Copyright (c) 2023 Paul B Mahol > + * > + * 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 "avcodec.h" > +#include "codec_internal.h" > +#include "decode.h" > +#include "zlib_wrapper.h" > + > +#include some zlib depenacy in configure is needed [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Those who are too smart to engage in politics are punished by being governed by those who are dumber. -- Plato=20 --TN8pJM9vJMHHFgJc Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZD8GdQAKCRBhHseHBAsP q8QnAJ9Yu/lzXxAYAxHu2/R1GxZJod4SwACgjbgThXAreg/9yHs+wZbo9+6f21Q= =OnMP -----END PGP SIGNATURE----- --TN8pJM9vJMHHFgJc-- --===============3086505838976655183== 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". --===============3086505838976655183==--