[FFmpeg-devel] [PATCH] avformat: add VPK demuxer

Paul B Mahol onemda at gmail.com
Fri Nov 13 21:07:34 CET 2015


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavformat/Makefile     |  1 +
 libavformat/allformats.c |  1 +
 libavformat/vpk.c        | 79 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+)
 create mode 100644 libavformat/vpk.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 1a03e0c..6704ced 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -459,6 +459,7 @@ OBJS-$(CONFIG_VMD_DEMUXER)               += sierravmd.o
 OBJS-$(CONFIG_VOBSUB_DEMUXER)            += subtitles.o # mpeg demuxer is in the dependencies
 OBJS-$(CONFIG_VOC_DEMUXER)               += vocdec.o voc.o
 OBJS-$(CONFIG_VOC_MUXER)                 += vocenc.o voc.o
+OBJS-$(CONFIG_VPK_DEMUXER)               += vpk.o
 OBJS-$(CONFIG_VPLAYER_DEMUXER)           += vplayerdec.o subtitles.o
 OBJS-$(CONFIG_VQF_DEMUXER)               += vqf.o
 OBJS-$(CONFIG_W64_DEMUXER)               += wavdec.o w64.o pcm.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 8b8d9f2..9f7c0fd 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -323,6 +323,7 @@ void av_register_all(void)
     REGISTER_DEMUXER (VMD,              vmd);
     REGISTER_DEMUXER (VOBSUB,           vobsub);
     REGISTER_MUXDEMUX(VOC,              voc);
+    REGISTER_DEMUXER (VPK,              vpk);
     REGISTER_DEMUXER (VPLAYER,          vplayer);
     REGISTER_DEMUXER (VQF,              vqf);
     REGISTER_MUXDEMUX(W64,              w64);
diff --git a/libavformat/vpk.c b/libavformat/vpk.c
new file mode 100644
index 0000000..daac91f
--- /dev/null
+++ b/libavformat/vpk.c
@@ -0,0 +1,79 @@
+/*
+ * VPK demuxer
+ * Copyright (c) 2015 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-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "internal.h"
+
+static int vpk_probe(AVProbeData *p)
+{
+    if (AV_RL32(p->buf) != MKBETAG('V','P','K',' '))
+        return 0;
+
+    return AVPROBE_SCORE_MAX / 3 * 2;
+}
+
+static int vpk_read_header(AVFormatContext *s)
+{
+    int64_t offset;
+    AVStream *st;
+
+    st = avformat_new_stream(s, NULL);
+    if (!st)
+        return AVERROR(ENOMEM);
+
+    avio_skip(s->pb, 4);
+    st->duration           = avio_rl32(s->pb) / 16 * 28;
+    offset                 = avio_rl32(s->pb);
+    st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
+    st->codec->codec_id    = AV_CODEC_ID_ADPCM_PSX;
+    st->codec->block_align = avio_rl32(s->pb);
+    st->codec->sample_rate = avio_rl32(s->pb);
+    if (st->codec->sample_rate <= 0)
+        return AVERROR_INVALIDDATA;
+    st->codec->channels    = avio_rl32(s->pb);
+    if (st->codec->channels <= 0)
+        return AVERROR_INVALIDDATA;
+    avio_skip(s->pb, offset - avio_tell(s->pb));
+    avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+    return 0;
+}
+
+static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    AVCodecContext *codec = s->streams[0]->codec;
+    int ret;
+
+    ret = av_get_packet(s->pb, pkt, codec->block_align);
+    pkt->stream_index = 0;
+
+    return ret;
+}
+
+AVInputFormat ff_vpk_demuxer = {
+    .name           = "vpk",
+    .long_name      = NULL_IF_CONFIG_SMALL("Sony PS2 VPK"),
+    .read_probe     = vpk_probe,
+    .read_header    = vpk_read_header,
+    .read_packet    = vpk_read_packet,
+    .extensions     = "vpk",
+};
-- 
1.9.1



More information about the ffmpeg-devel mailing list