2011-03-15 10:37:48 +02:00
|
|
|
/*
|
|
|
|
* Chronomaster DFA Format Demuxer
|
|
|
|
* Copyright (c) 2011 Konstantin Shishkov
|
|
|
|
*
|
2011-03-29 03:46:11 +03:00
|
|
|
* This file is part of FFmpeg.
|
2011-03-15 10:37:48 +02:00
|
|
|
*
|
2011-03-29 03:46:11 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2011-03-15 10:37:48 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2011-03-29 03:46:11 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2011-03-15 10:37:48 +02:00
|
|
|
* 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
|
2011-03-29 03:46:11 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2011-03-15 10:37:48 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2014-03-10 17:35:59 +03:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2011-03-15 10:37:48 +02:00
|
|
|
#include "libavutil/intreadwrite.h"
|
|
|
|
#include "avformat.h"
|
2011-11-29 21:28:15 +03:00
|
|
|
#include "internal.h"
|
2011-03-15 10:37:48 +02:00
|
|
|
|
|
|
|
static int dfa_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
if (p->buf_size < 4 || AV_RL32(p->buf) != MKTAG('D', 'F', 'I', 'A'))
|
|
|
|
return 0;
|
|
|
|
|
2013-11-11 20:11:43 +03:00
|
|
|
if (AV_RL32(p->buf + 16) != 0x80)
|
|
|
|
return AVPROBE_SCORE_MAX / 4;
|
|
|
|
|
2011-03-15 10:37:48 +02:00
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
}
|
|
|
|
|
2012-01-12 15:20:36 +03:00
|
|
|
static int dfa_read_header(AVFormatContext *s)
|
2011-03-15 10:37:48 +02:00
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
AVStream *st;
|
|
|
|
int frames;
|
2013-04-15 13:07:12 +03:00
|
|
|
int version;
|
2011-03-15 10:37:48 +02:00
|
|
|
uint32_t mspf;
|
|
|
|
|
|
|
|
if (avio_rl32(pb) != MKTAG('D', 'F', 'I', 'A')) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Invalid magic for DFA\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2013-04-15 13:07:12 +03:00
|
|
|
|
|
|
|
version = avio_rl16(pb);
|
2011-03-15 10:37:48 +02:00
|
|
|
frames = avio_rl16(pb);
|
|
|
|
|
2011-06-18 12:43:24 +03:00
|
|
|
st = avformat_new_stream(s, NULL);
|
2011-03-15 10:37:48 +02:00
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
2012-08-05 12:11:04 +03:00
|
|
|
st->codec->codec_id = AV_CODEC_ID_DFA;
|
2011-03-15 10:37:48 +02:00
|
|
|
st->codec->width = avio_rl16(pb);
|
|
|
|
st->codec->height = avio_rl16(pb);
|
|
|
|
mspf = avio_rl32(pb);
|
|
|
|
if (!mspf) {
|
|
|
|
av_log(s, AV_LOG_WARNING, "Zero FPS reported, defaulting to 10\n");
|
|
|
|
mspf = 100;
|
|
|
|
}
|
2011-11-29 21:28:15 +03:00
|
|
|
avpriv_set_pts_info(st, 24, mspf, 1000);
|
2011-03-15 10:37:48 +02:00
|
|
|
avio_skip(pb, 128 - 16); // padding
|
|
|
|
st->duration = frames;
|
|
|
|
|
2013-10-13 13:30:59 +03:00
|
|
|
if (ff_alloc_extradata(st->codec, 2))
|
|
|
|
return AVERROR(ENOMEM);
|
2013-04-15 13:07:12 +03:00
|
|
|
AV_WL16(st->codec->extradata, version);
|
|
|
|
if (version == 0x100)
|
|
|
|
st->sample_aspect_ratio = (AVRational){2, 1};
|
|
|
|
|
2011-03-15 10:37:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
uint32_t frame_size;
|
|
|
|
int ret, first = 1;
|
|
|
|
|
2014-08-24 17:28:02 +03:00
|
|
|
if (avio_feof(pb))
|
2011-03-15 10:37:48 +02:00
|
|
|
return AVERROR_EOF;
|
|
|
|
|
|
|
|
if (av_get_packet(pb, pkt, 12) != 12)
|
|
|
|
return AVERROR(EIO);
|
2014-08-24 17:28:02 +03:00
|
|
|
while (!avio_feof(pb)) {
|
2011-03-15 10:37:48 +02:00
|
|
|
if (!first) {
|
|
|
|
ret = av_append_packet(pb, pkt, 12);
|
|
|
|
if (ret < 0) {
|
|
|
|
av_free_packet(pkt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
first = 0;
|
|
|
|
frame_size = AV_RL32(pkt->data + pkt->size - 8);
|
|
|
|
if (frame_size > INT_MAX - 4) {
|
2014-03-10 17:35:59 +03:00
|
|
|
av_log(s, AV_LOG_ERROR, "Too large chunk size: %"PRIu32"\n", frame_size);
|
2011-03-15 10:37:48 +02:00
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) {
|
|
|
|
if (frame_size) {
|
2014-03-10 17:35:59 +03:00
|
|
|
av_log(s, AV_LOG_WARNING,
|
|
|
|
"skipping %"PRIu32" bytes of end-of-frame marker chunk\n",
|
2011-03-15 10:37:48 +02:00
|
|
|
frame_size);
|
|
|
|
avio_skip(pb, frame_size);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = av_append_packet(pb, pkt, frame_size);
|
|
|
|
if (ret < 0) {
|
|
|
|
av_free_packet(pkt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AVInputFormat ff_dfa_demuxer = {
|
2011-07-16 23:18:12 +03:00
|
|
|
.name = "dfa",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
|
|
|
|
.read_probe = dfa_probe,
|
|
|
|
.read_header = dfa_read_header,
|
|
|
|
.read_packet = dfa_read_packet,
|
2012-04-06 17:50:48 +03:00
|
|
|
.flags = AVFMT_GENERIC_INDEX,
|
2011-03-15 10:37:48 +02:00
|
|
|
};
|