On Thu, Nov 24, 2011 at 10:01:53PM +0100, Diego Biurrun wrote:
> On Thu, Nov 24, 2011 at 04:05:20PM +0100, =?UTF-8?q?Reimar=20D=C3=B6ffinger?=
> wrote:
> > Not yet complete, for demuxing AAC the AAC header must be generated
> > manually.
> > Possibly the decoder could accept the header as extradata to simplify
> > this.
> > ---
> > Some reformatting and checks added by me.
>
> some nits ..
>
> > --- /dev/null
> > +++ b/libavformat/pmpdec.c
> > @@ -0,0 +1,176 @@
> > +/*
> > + * PMP demuxer.
>
> drop the period
made it aperiodic
> > +static int pmp_probe(AVProbeData *p) {
>
> { on next line please, more below
done for all functions
> > +static int pmp_header(AVFormatContext *s, AVFormatParameters *ap) {
>
> ditto
>
> > +static int pmp_packet(AVFormatContext *s, AVPacket *pkt) {
>
> ditto
>
> > + // FIXME: this is a hack that should be remove once
>
> removeD
fixed
> > + // compute_pkt_fields can handle
>
> Can handle what?
My guess is timestamps, but sometimes I suspect that compute_pkt_fields()
cannot handle anything properly.
> > +static int pmp_seek(AVFormatContext *s, int stream_index,
> > + int64_t ts, int flags) {
>
> ditto and indentation is off
fixed
>From fd8ca17d90621b385eb491ab22630001a6a94f14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= <[email protected]>
Date: Sat, 26 Mar 2011 16:25:10 +0100
Subject: [PATCH] Add PlayStation Portable PMP format demuxer
Not yet complete, for demuxing AAC the AAC header must be generated
manually.
Possibly the decoder could accept the header as extradata to simplify
this.
---
Changelog | 1 +
doc/general.texi | 1 +
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/pmpdec.c | 179 ++++++++++++++++++++++++++++++++++++++++++++++
libavformat/version.h | 2 +-
6 files changed, 184 insertions(+), 1 deletions(-)
create mode 100644 libavformat/pmpdec.c
diff --git a/Changelog b/Changelog
index b9b5f26..ff6b393 100644
--- a/Changelog
+++ b/Changelog
@@ -102,6 +102,7 @@ easier to use. The changes are:
- Discworld II BMV decoding support
- VBLE Decoder
- OS X Video Decoder Acceleration (VDA) support
+- Playstation Portable PMP format demuxer
version 0.7:
diff --git a/doc/general.texi b/doc/general.texi
index d2747c0..be9c9d3 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -165,6 +165,7 @@ library:
@item NUT @tab X @tab X
@tab NUT Open Container Format
@item Ogg @tab X @tab X
+@item Playstation Portable PMP @tab @tab X
@item TechnoTrend PVA @tab @tab X
@tab Used by TechnoTrend DVB PCI boards.
@item QCP @tab @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2b7588f..65de6d0 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -217,6 +217,7 @@ OBJS-$(CONFIG_PCM_U32LE_DEMUXER) += pcmdec.o pcm.o rawdec.o
OBJS-$(CONFIG_PCM_U32LE_MUXER) += pcmenc.o rawenc.o
OBJS-$(CONFIG_PCM_U8_DEMUXER) += pcmdec.o pcm.o rawdec.o
OBJS-$(CONFIG_PCM_U8_MUXER) += pcmenc.o rawenc.o
+OBJS-$(CONFIG_PMP_DEMUXER) += pmpdec.o
OBJS-$(CONFIG_PVA_DEMUXER) += pva.o
OBJS-$(CONFIG_QCP_DEMUXER) += qcp.o
OBJS-$(CONFIG_R3D_DEMUXER) += r3d.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index bee2f5f..a012b10 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -176,6 +176,7 @@ void av_register_all(void)
REGISTER_MUXDEMUX (PCM_U16BE, pcm_u16be);
REGISTER_MUXDEMUX (PCM_U16LE, pcm_u16le);
REGISTER_MUXDEMUX (PCM_U8, pcm_u8);
+ REGISTER_DEMUXER (PMP, pmp);
REGISTER_MUXER (PSP, psp);
REGISTER_DEMUXER (PVA, pva);
REGISTER_DEMUXER (QCP, qcp);
diff --git a/libavformat/pmpdec.c b/libavformat/pmpdec.c
new file mode 100644
index 0000000..e198b5d
--- /dev/null
+++ b/libavformat/pmpdec.c
@@ -0,0 +1,179 @@
+/*
+ * PMP demuxer
+ * Copyright (c) 2011 Reimar Döffinger
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+
+typedef struct PMPContext {
+ int cur_stream;
+ int num_streams;
+ int audio_packets;
+ int current_packet;
+ uint32_t *packet_sizes;
+ int packet_sizes_alloc;
+} PMPContext;
+
+static int pmp_probe(AVProbeData *p)
+{
+ if (!memcmp(p->buf, "pmpm\1\0\0\0", 8))
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+static int pmp_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ PMPContext *pmp = s->priv_data;
+ AVIOContext *pb = s->pb;
+ int tb_num, tb_den;
+ int index_cnt;
+ int audio_codec_id = CODEC_ID_NONE;
+ int srate, channels;
+ int i;
+ uint64_t pos;
+ AVStream *vst = avformat_new_stream(s, NULL);
+ if (!vst)
+ return AVERROR(ENOMEM);
+ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ avio_skip(pb, 8);
+ switch (avio_rl32(pb)) {
+ case 0:
+ vst->codec->codec_id = CODEC_ID_MPEG4;
+ break;
+ case 1:
+ vst->codec->codec_id = CODEC_ID_H264;
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "Unsupported video format\n");
+ break;
+ }
+ index_cnt = avio_rl32(pb);
+ vst->codec->width = avio_rl32(pb);
+ vst->codec->height = avio_rl32(pb);
+
+ tb_num = avio_rl32(pb);
+ tb_den = avio_rl32(pb);
+ av_set_pts_info(vst, 32, tb_num, tb_den);
+ vst->nb_frames = index_cnt;
+ vst->duration = index_cnt;
+
+ switch (avio_rl32(pb)) {
+ case 0:
+ audio_codec_id = CODEC_ID_MP3;
+ break;
+ case 1:
+ av_log(s, AV_LOG_WARNING, "AAC is not yet correctly supported\n");
+ audio_codec_id = CODEC_ID_AAC;
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "Unsupported audio format\n");
+ break;
+ }
+ pmp->num_streams = avio_rl16(pb) + 1;
+ avio_skip(pb, 10);
+ srate = avio_rl32(pb);
+ channels = avio_rl32(pb) + 1;
+ for (i = 1; i < pmp->num_streams; i++) {
+ AVStream *ast = avformat_new_stream(s, NULL);
+ if (!ast)
+ return AVERROR(ENOMEM);
+ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ ast->codec->codec_id = audio_codec_id;
+ ast->codec->channels = channels;
+ ast->codec->sample_rate = srate;
+ av_set_pts_info(ast, 32, 1, srate);
+ }
+ pos = avio_tell(pb) + 4 * index_cnt;
+ for (i = 0; i < index_cnt; i++) {
+ int size = avio_rl32(pb);
+ int flags = size & 1 ? AVINDEX_KEYFRAME : 0;
+ size >>= 1;
+ av_add_index_entry(vst, pos, i, size, 0, flags);
+ pos += size;
+ }
+ return 0;
+}
+
+static int pmp_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ PMPContext *pmp = s->priv_data;
+ AVIOContext *pb = s->pb;
+ int ret = 0;
+ int i;
+
+ if (pb->eof_reached)
+ return AVERROR_EOF;
+ if (pmp->cur_stream == 0) {
+ int num_packets;
+ pmp->audio_packets = avio_r8(pb);
+ num_packets = (pmp->num_streams - 1) * pmp->audio_packets + 1;
+ avio_skip(pb, 8);
+ pmp->current_packet = 0;
+ av_fast_malloc(&pmp->packet_sizes,
+ &pmp->packet_sizes_alloc,
+ num_packets * sizeof(*pmp->packet_sizes));
+ if (!pmp->packet_sizes_alloc) {
+ av_log(s, AV_LOG_ERROR, "Cannot (re)allocate packet buffer\n");
+ return AVERROR(ENOMEM);
+ }
+ for (i = 0; i < num_packets; i++)
+ pmp->packet_sizes[i] = avio_rl32(pb);
+ }
+ ret = av_get_packet(pb, pkt, pmp->packet_sizes[pmp->current_packet]);
+ if (ret > 0) {
+ ret = 0;
+ // FIXME: this is a hack that should be removed once
+ // compute_pkt_fields() can handle timestamps properly
+ if (pmp->cur_stream == 0)
+ pkt->dts = s->streams[0]->cur_dts++;
+ pkt->stream_index = pmp->cur_stream;
+ }
+ pmp->current_packet++;
+ if (pmp->current_packet == 1 || pmp->current_packet > pmp->audio_packets)
+ pmp->cur_stream = (pmp->cur_stream + 1) % pmp->num_streams;
+
+ return ret;
+}
+
+static int pmp_seek(AVFormatContext *s, int stream_idx, int64_t ts, int flags)
+{
+ PMPContext *pmp = s->priv_data;
+ pmp->cur_stream = 0;
+ // fallback to default seek now
+ return -1;
+}
+
+static int pmp_close(AVFormatContext *s)
+{
+ PMPContext *pmp = s->priv_data;
+ av_freep(&pmp->packet_sizes);
+ return 0;
+}
+
+AVInputFormat ff_pmp_demuxer = {
+ .name = "pmp",
+ .long_name = NULL_IF_CONFIG_SMALL("Playstation Portable PMP format"),
+ .priv_data_size = sizeof(PMPContext),
+ .read_probe = pmp_probe,
+ .read_header = pmp_header,
+ .read_packet = pmp_packet,
+ .read_seek = pmp_seek,
+ .read_close = pmp_close,
+};
diff --git a/libavformat/version.h b/libavformat/version.h
index d56bdb7..37c3d5b 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -24,7 +24,7 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 53
-#define LIBAVFORMAT_VERSION_MINOR 15
+#define LIBAVFORMAT_VERSION_MINOR 16
#define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
--
1.7.0.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel