aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2012-10-02 13:43:19 +0000
committerPaul B Mahol <onemda@gmail.com>2012-10-08 09:06:25 +0000
commitd7a473926504e2acfa6ae3bead0938e1f4e03441 (patch)
treef4eae034819efb112671ec93273fc1653b64b9eb /libavformat
parent208a5d13228208caea10d96353693c39d08a1211 (diff)
downloadffmpeg-d7a473926504e2acfa6ae3bead0938e1f4e03441.tar.gz
TAK demuxer, decoder and parser
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/takdec.c184
-rw-r--r--libavformat/version.h4
4 files changed, 188 insertions, 2 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 9481d2bd12..1fd616bebb 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -333,6 +333,7 @@ OBJS-$(CONFIG_STR_DEMUXER) += psxstr.o
OBJS-$(CONFIG_SUBVIEWER_DEMUXER) += subviewerdec.o
OBJS-$(CONFIG_SWF_DEMUXER) += swfdec.o swf.o
OBJS-$(CONFIG_SWF_MUXER) += swfenc.o swf.o
+OBJS-$(CONFIG_TAK_DEMUXER) += takdec.o apetag.o img2.o rawdec.o
OBJS-$(CONFIG_THP_DEMUXER) += thp.o
OBJS-$(CONFIG_TIERTEXSEQ_DEMUXER) += tiertexseq.o
OBJS-$(CONFIG_MKVTIMESTAMP_V2_MUXER) += mkvtimestamp_v2.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 36b6988f11..f1e8edcd65 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -233,6 +233,7 @@ void av_register_all(void)
REGISTER_DEMUXER (STR, str);
REGISTER_DEMUXER (SUBVIEWER, subviewer);
REGISTER_MUXDEMUX (SWF, swf);
+ REGISTER_DEMUXER (TAK, tak);
REGISTER_MUXER (TG2, tg2);
REGISTER_MUXER (TGP, tgp);
REGISTER_DEMUXER (THP, thp);
diff --git a/libavformat/takdec.c b/libavformat/takdec.c
new file mode 100644
index 0000000000..6fd3d93cbd
--- /dev/null
+++ b/libavformat/takdec.c
@@ -0,0 +1,184 @@
+/*
+ * Raw TAK demuxer
+ * Copyright (c) 2012 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 "libavcodec/tak.h"
+#include "avformat.h"
+#include "internal.h"
+#include "rawdec.h"
+#include "apetag.h"
+
+typedef struct TAKDemuxContext {
+ int mlast_frame;
+ int64_t left;
+} TAKDemuxContext;
+
+static int tak_probe(AVProbeData *p)
+{
+ if (!memcmp(p->buf, "tBaK", 4))
+ return AVPROBE_SCORE_MAX / 2;
+ return 0;
+}
+
+static int tak_read_header(AVFormatContext *s)
+{
+ TAKDemuxContext *tc = s->priv_data;
+ AVIOContext *pb = s->pb;
+ GetBitContext gb;
+ AVStream *st;
+ uint8_t *buffer = NULL;
+ int ret;
+
+ st = avformat_new_stream(s, 0);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codec->codec_id = AV_CODEC_ID_TAK;
+ st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
+
+ tc->mlast_frame = 0;
+ if (avio_rl32(pb) != MKTAG('t', 'B', 'a', 'K')) {
+ avio_seek(pb, -4, SEEK_CUR);
+ return 0;
+ }
+
+ while (!url_feof(pb)) {
+ enum TAKMetaDataType type;
+ int size;
+
+ type = avio_r8(pb) & 0x7f;
+ size = avio_rl24(pb);
+
+ switch (type) {
+ case TAK_METADATA_STREAMINFO:
+ case TAK_METADATA_LAST_FRAME:
+ case TAK_METADATA_ENCODER:
+ buffer = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!buffer)
+ return AVERROR(ENOMEM);
+
+ if (avio_read(pb, buffer, size) != size) {
+ av_freep(&buffer);
+ return AVERROR(EIO);
+ }
+
+ init_get_bits(&gb, buffer, size * 8);
+ break;
+ case TAK_METADATA_MD5: {
+ uint8_t md5[16];
+ int i;
+
+ if (size != 19)
+ return AVERROR_INVALIDDATA;
+ avio_read(pb, md5, 16);
+ avio_skip(pb, 3);
+ av_log(s, AV_LOG_VERBOSE, "MD5=");
+ for (i = 0; i < 16; i++)
+ av_log(s, AV_LOG_VERBOSE, "%02x", md5[i]);
+ av_log(s, AV_LOG_VERBOSE, "\n");
+ break;
+ }
+ case TAK_METADATA_END:
+ if (pb->seekable) {
+ int64_t curpos = avio_tell(pb);
+
+ ff_ape_parse_tag(s);
+ avio_seek(pb, curpos, SEEK_SET);
+ }
+ return 0;
+ break;
+ default:
+ ret = avio_skip(pb, size);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (type == TAK_METADATA_STREAMINFO) {
+ TAKStreamInfo ti;
+
+ avpriv_tak_parse_streaminfo(&gb, &ti);
+ if (ti.samples > 0)
+ st->duration = ti.samples;
+ st->codec->bits_per_coded_sample = ti.bps;
+ if (ti.ch_layout)
+ st->codec->channel_layout = ti.ch_layout;
+ st->codec->sample_rate = ti.sample_rate;
+ st->codec->channels = ti.channels;
+ st->start_time = 0;
+ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ st->codec->extradata = buffer;
+ st->codec->extradata_size = size;
+ buffer = NULL;
+ } else if (type == TAK_METADATA_LAST_FRAME) {
+ if (size != 11)
+ return AVERROR_INVALIDDATA;
+ tc->mlast_frame = 1;
+ tc->left = get_bits_longlong(&gb, TAK_LAST_FRAME_POS_BITS) +
+ get_bits(&gb, TAK_LAST_FRAME_SIZE_BITS);
+ av_freep(&buffer);
+ } else if (type == TAK_METADATA_ENCODER) {
+ av_log(s, AV_LOG_VERBOSE, "encoder version: %0X\n",
+ get_bits_long(&gb, TAK_ENCODER_VERSION_BITS));
+ av_freep(&buffer);
+ }
+ }
+
+ return AVERROR_EOF;
+}
+
+static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ TAKDemuxContext *tc = s->priv_data;
+ int ret;
+
+ if (tc->mlast_frame) {
+ AVIOContext *pb = s->pb;
+ int64_t size;
+
+ size = FFMIN(tc->left, 1024);
+ if (!size)
+ return AVERROR_EOF;
+
+ ret = av_get_packet(pb, pkt, size);
+ if (ret < 0)
+ return ret;
+
+ pkt->stream_index = 0;
+ pkt->pos = avio_tell(pb);
+ tc->left -= ret;
+ } else {
+ ret = ff_raw_read_partial_packet(s, pkt);
+ }
+
+ return ret;
+}
+
+AVInputFormat ff_tak_demuxer = {
+ .name = "tak",
+ .long_name = NULL_IF_CONFIG_SMALL("raw TAK"),
+ .priv_data_size = sizeof(TAKDemuxContext),
+ .read_probe = tak_probe,
+ .read_header = tak_read_header,
+ .read_packet = raw_read_packet,
+ .flags = AVFMT_GENERIC_INDEX,
+ .extensions = "tak",
+ .raw_codec_id = AV_CODEC_ID_TAK,
+};
diff --git a/libavformat/version.h b/libavformat/version.h
index 32a70d2792..b733ef6c3c 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,8 +30,8 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 54
-#define LIBAVFORMAT_VERSION_MINOR 29
-#define LIBAVFORMAT_VERSION_MICRO 105
+#define LIBAVFORMAT_VERSION_MINOR 30
+#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \