Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2017-06-02 12:28:35 +0300
committerPaul B Mahol <onemda@gmail.com>2017-06-11 11:00:39 +0300
commitc94841487622e52f95e6c703514d604b6ae8e47d (patch)
tree30629c865d76608bde115d60ddc2e7e8d6994d85 /libavformat
parentd1c08027d8e4eb77467926588f437dd946e8fb65 (diff)
avformat: add Gremlin Digital Video demuxer
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/Makefile1
-rw-r--r--libavformat/allformats.c1
-rw-r--r--libavformat/gdv.c161
-rw-r--r--libavformat/version.h4
4 files changed, 165 insertions, 2 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 00cba52a43..80aeed22c0 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -192,6 +192,7 @@ OBJS-$(CONFIG_G722_MUXER) += rawenc.o
OBJS-$(CONFIG_G723_1_DEMUXER) += g723_1.o
OBJS-$(CONFIG_G723_1_MUXER) += rawenc.o
OBJS-$(CONFIG_G729_DEMUXER) += g729dec.o
+OBJS-$(CONFIG_GDV_DEMUXER) += gdv.o
OBJS-$(CONFIG_GENH_DEMUXER) += genh.o
OBJS-$(CONFIG_H261_DEMUXER) += h261dec.o rawdec.o
OBJS-$(CONFIG_H261_MUXER) += rawenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index ad516eba06..a0e2fb8c85 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -134,6 +134,7 @@ static void register_all(void)
REGISTER_MUXDEMUX(G722, g722);
REGISTER_MUXDEMUX(G723_1, g723_1);
REGISTER_DEMUXER (G729, g729);
+ REGISTER_DEMUXER (GDV, gdv);
REGISTER_DEMUXER (GENH, genh);
REGISTER_MUXDEMUX(GIF, gif);
REGISTER_MUXDEMUX(GSM, gsm);
diff --git a/libavformat/gdv.c b/libavformat/gdv.c
new file mode 100644
index 0000000000..87bba2fdbd
--- /dev/null
+++ b/libavformat/gdv.c
@@ -0,0 +1,161 @@
+/*
+ * Gremlin Digital Video demuxer
+ * Copyright (c) 2017 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 "avio.h"
+#include "internal.h"
+
+typedef struct GDVContext {
+ int is_first_video;
+ int is_audio;
+ int audio_size;
+ int audio_stream_index;
+ int video_stream_index;
+ unsigned pal[256];
+} GDVContext;
+
+static int gdv_read_probe(AVProbeData *p)
+{
+ if (AV_RL32(p->buf) == 0x29111994)
+ return AVPROBE_SCORE_MAX;
+
+ return 0;
+}
+
+static int gdv_read_header(AVFormatContext *ctx)
+{
+ GDVContext *gdv = ctx->priv_data;
+ AVIOContext *pb = ctx->pb;
+ AVStream *vst, *ast;
+ unsigned fps, snd_flags, vid_depth;
+
+ avio_skip(pb, 6);
+
+ vst = avformat_new_stream(ctx, 0);
+ if (!vst)
+ return AVERROR(ENOMEM);
+
+ vst->start_time = 0;
+ vst->duration =
+ vst->nb_frames = avio_rl16(pb);
+
+ fps = avio_rl16(pb);
+ snd_flags = avio_rl16(pb);
+ if (snd_flags & 1) {
+ ast = avformat_new_stream(ctx, 0);
+ if (!ast)
+ return AVERROR(ENOMEM);
+
+ ast->start_time = 0;
+ ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+ ast->codecpar->codec_tag = 0;
+ ast->codecpar->sample_rate = avio_rl16(pb);
+ ast->codecpar->channels = 1 + !!(snd_flags & 2);
+ if (snd_flags & 8) {
+ ast->codecpar->codec_id = AV_CODEC_ID_GREMLIN_DPCM;
+ } else {
+ ast->codecpar->codec_id = (snd_flags & 4) ? AV_CODEC_ID_PCM_S16LE : AV_CODEC_ID_PCM_U8;
+ }
+
+ avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate);
+ gdv->audio_size = (ast->codecpar->sample_rate / fps) *
+ ast->codecpar->channels * (1 + !!(snd_flags & 4)) / (1 + !!(snd_flags & 8));
+ gdv->is_audio = 1;
+ }
+ vid_depth = avio_rl16(pb);
+ avio_skip(pb, 4);
+
+ vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+ vst->codecpar->codec_id = AV_CODEC_ID_GDV;
+ vst->codecpar->codec_tag = 0;
+ vst->codecpar->width = avio_rl16(pb);
+ vst->codecpar->height = avio_rl16(pb);
+
+ avpriv_set_pts_info(vst, 64, 1, fps);
+
+ if (vid_depth & 1) {
+ int i;
+
+ for (i = 0; i < 256; i++) {
+ unsigned r = avio_r8(pb);
+ unsigned g = avio_r8(pb);
+ unsigned b = avio_r8(pb);
+ gdv->pal[i] = 0xFF << 24 | r << 18 | g << 10 | b << 2;
+ }
+ }
+
+ gdv->is_first_video = 1;
+
+ return 0;
+}
+
+static int gdv_read_packet(AVFormatContext *ctx, AVPacket *pkt)
+{
+ GDVContext *gdv = ctx->priv_data;
+ AVIOContext *pb = ctx->pb;
+ int ret;
+
+ if (avio_feof(pb))
+ return pb->error ? pb->error : AVERROR_EOF;
+
+ if (gdv->audio_size && gdv->is_audio) {
+ ret = av_get_packet(pb, pkt, gdv->audio_size);
+ if (ret < 0)
+ return ret;
+ pkt->stream_index = 1;
+ gdv->is_audio = 0;
+ } else {
+ uint8_t *pal;
+
+ if (avio_rl16(pb) != 0x1305)
+ return AVERROR_INVALIDDATA;
+ ret = av_get_packet(pb, pkt, 4 + avio_rl16(pb));
+ if (ret < 0)
+ return ret;
+ pkt->stream_index = 0;
+ gdv->is_audio = 1;
+
+ if (gdv->is_first_video) {
+ pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,
+ AVPALETTE_SIZE);
+ if (!pal) {
+ av_packet_unref(pkt);
+ return AVERROR(ENOMEM);
+ }
+ memcpy(pal, gdv->pal, AVPALETTE_SIZE);
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ gdv->is_first_video = 0;
+ }
+ }
+
+ return 0;
+}
+
+AVInputFormat ff_gdv_demuxer = {
+ .name = "gdv",
+ .long_name = NULL_IF_CONFIG_SMALL("Gremlin Digital Video"),
+ .priv_data_size = sizeof(GDVContext),
+ .read_probe = gdv_read_probe,
+ .read_header = gdv_read_header,
+ .read_packet = gdv_read_packet,
+};
diff --git a/libavformat/version.h b/libavformat/version.h
index 411fd6613d..b00a8b0333 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,8 +32,8 @@
// Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
// Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 57
-#define LIBAVFORMAT_VERSION_MINOR 72
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MINOR 73
+#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \