2011-09-16 05:50:26 +03:00
|
|
|
/*
|
|
|
|
* Binary text demuxer
|
|
|
|
* eXtended BINary text (XBIN) demuxer
|
|
|
|
* Artworx Data Format demuxer
|
|
|
|
* iCEDraw File demuxer
|
|
|
|
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Binary text demuxer
|
|
|
|
* eXtended BINary text (XBIN) demuxer
|
|
|
|
* Artworx Data Format demuxer
|
|
|
|
* iCEDraw File demuxer
|
|
|
|
*/
|
|
|
|
|
2022-02-23 14:56:49 +02:00
|
|
|
#include "config_components.h"
|
|
|
|
|
2011-09-16 05:50:26 +03:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2012-01-29 04:12:57 +03:00
|
|
|
#include "libavutil/opt.h"
|
|
|
|
#include "libavutil/parseutils.h"
|
2011-09-16 05:50:26 +03:00
|
|
|
#include "avformat.h"
|
2024-02-10 16:50:43 +02:00
|
|
|
#include "demux.h"
|
2011-12-03 02:45:46 +03:00
|
|
|
#include "internal.h"
|
2011-09-16 05:50:26 +03:00
|
|
|
#include "sauce.h"
|
|
|
|
#include "libavcodec/bintext.h"
|
|
|
|
|
|
|
|
typedef struct {
|
2012-01-29 04:12:57 +03:00
|
|
|
const AVClass *class;
|
|
|
|
int chars_per_frame; /**< characters to send decoder per frame;
|
|
|
|
set by private options as characters per second, and then
|
|
|
|
converted to characters per frame at runtime */
|
2013-04-05 17:46:28 +03:00
|
|
|
int width, height; /**< video size (WxH pixels) (private option) */
|
2013-04-05 17:39:42 +03:00
|
|
|
AVRational framerate; /**< frames per second (private option) */
|
2011-09-16 05:50:26 +03:00
|
|
|
uint64_t fsize; /**< file size less metadata buffer */
|
|
|
|
} BinDemuxContext;
|
|
|
|
|
2012-06-03 15:47:26 +03:00
|
|
|
static AVStream * init_stream(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
BinDemuxContext *bin = s->priv_data;
|
|
|
|
AVStream *st = avformat_new_stream(s, NULL);
|
|
|
|
if (!st)
|
|
|
|
return NULL;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_tag = 0;
|
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
2012-06-03 15:47:26 +03:00
|
|
|
|
2013-04-05 17:46:28 +03:00
|
|
|
if (!bin->width) {
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->width = (80<<3);
|
|
|
|
st->codecpar->height = (25<<4);
|
2012-06-03 15:47:26 +03:00
|
|
|
}
|
|
|
|
|
2013-04-05 17:39:42 +03:00
|
|
|
avpriv_set_pts_info(st, 60, bin->framerate.den, bin->framerate.num);
|
2012-06-03 15:47:26 +03:00
|
|
|
|
|
|
|
/* simulate tty display speed */
|
2013-10-22 00:19:04 +03:00
|
|
|
bin->chars_per_frame = av_clip(av_q2d(st->time_base) * bin->chars_per_frame, 1, INT_MAX);
|
2012-06-03 15:47:26 +03:00
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2011-09-16 05:50:26 +03:00
|
|
|
#if CONFIG_BINTEXT_DEMUXER | CONFIG_ADF_DEMUXER | CONFIG_IDF_DEMUXER
|
|
|
|
/**
|
|
|
|
* Given filesize and width, calculate height (assume font_height of 16)
|
|
|
|
*/
|
2016-04-10 21:58:15 +02:00
|
|
|
static void calculate_height(AVCodecParameters *par, uint64_t fsize)
|
2011-09-16 05:50:26 +03:00
|
|
|
{
|
2016-04-10 21:58:15 +02:00
|
|
|
par->height = (fsize / ((par->width>>3)*2)) << 4;
|
2011-09-16 05:50:26 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_BINTEXT_DEMUXER
|
|
|
|
static const uint8_t next_magic[]={
|
|
|
|
0x1A, 0x1B, '[', '0', ';', '3', '0', ';', '4', '0', 'm', 'N', 'E', 'X', 'T', 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
static int next_tag_read(AVFormatContext *avctx, uint64_t *fsize)
|
|
|
|
{
|
2011-11-14 02:36:45 +03:00
|
|
|
AVIOContext *pb = avctx->pb;
|
2011-09-16 05:50:26 +03:00
|
|
|
char buf[36];
|
|
|
|
int len;
|
2024-07-11 18:10:00 +02:00
|
|
|
int64_t start_pos = avio_size(pb);
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2024-07-11 18:10:00 +02:00
|
|
|
if (start_pos < 256)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
avio_seek(pb, start_pos - 256, SEEK_SET);
|
2011-11-14 02:53:50 +03:00
|
|
|
if (avio_read(pb, buf, sizeof(next_magic)) != sizeof(next_magic))
|
2011-09-16 05:50:26 +03:00
|
|
|
return -1;
|
|
|
|
if (memcmp(buf, next_magic, sizeof(next_magic)))
|
|
|
|
return -1;
|
2011-11-14 03:19:56 +03:00
|
|
|
if (avio_r8(pb) != 0x01)
|
2011-09-16 05:50:26 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
*fsize -= 256;
|
|
|
|
|
|
|
|
#define GET_EFI2_META(name,size) \
|
2011-11-14 03:19:56 +03:00
|
|
|
len = avio_r8(pb); \
|
2011-09-16 05:50:26 +03:00
|
|
|
if (len < 1 || len > size) \
|
|
|
|
return -1; \
|
2011-11-14 02:53:50 +03:00
|
|
|
if (avio_read(pb, buf, size) == size && *buf) { \
|
2011-09-16 05:50:26 +03:00
|
|
|
buf[len] = 0; \
|
2011-11-14 03:25:52 +03:00
|
|
|
av_dict_set(&avctx->metadata, name, buf, 0); \
|
2011-09-16 05:50:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
GET_EFI2_META("filename", 12)
|
|
|
|
GET_EFI2_META("author", 20)
|
|
|
|
GET_EFI2_META("publisher", 20)
|
|
|
|
GET_EFI2_META("title", 35)
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
static void predict_width(AVCodecParameters *par, uint64_t fsize, int got_width)
|
2011-09-16 05:50:26 +03:00
|
|
|
{
|
|
|
|
/** attempt to guess width */
|
|
|
|
if (!got_width)
|
2016-04-10 21:58:15 +02:00
|
|
|
par->width = fsize > 4000 ? (160<<3) : (80<<3);
|
2011-09-16 05:50:26 +03:00
|
|
|
}
|
|
|
|
|
2019-03-21 02:18:37 +02:00
|
|
|
static int bin_probe(const AVProbeData *p)
|
2018-01-31 16:22:29 +02:00
|
|
|
{
|
|
|
|
const uint8_t *d = p->buf;
|
|
|
|
int magic = 0, sauce = 0;
|
|
|
|
|
|
|
|
if (p->buf_size > 256)
|
|
|
|
magic = !memcmp(d + p->buf_size - 256, next_magic, sizeof(next_magic));
|
|
|
|
if (p->buf_size > 128)
|
|
|
|
sauce = !memcmp(d + p->buf_size - 128, "SAUCE00", 7);
|
|
|
|
|
|
|
|
if (magic)
|
|
|
|
return AVPROBE_SCORE_EXTENSION + 1;
|
|
|
|
|
|
|
|
if (av_match_ext(p->filename, "bin")) {
|
|
|
|
AVCodecParameters par;
|
|
|
|
int got_width = 0;
|
|
|
|
par.width = par.height = 0;
|
|
|
|
if (sauce)
|
|
|
|
return AVPROBE_SCORE_EXTENSION + 1;
|
|
|
|
|
|
|
|
predict_width(&par, p->buf_size, got_width);
|
2019-10-25 12:16:29 +02:00
|
|
|
if (par.width < 8)
|
2018-01-31 16:22:29 +02:00
|
|
|
return 0;
|
|
|
|
calculate_height(&par, p->buf_size);
|
|
|
|
if (par.height <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (par.width * par.height * 2 / (8*16) == p->buf_size)
|
|
|
|
return AVPROBE_SCORE_MAX / 2;
|
2018-05-12 18:33:26 +02:00
|
|
|
return 0;
|
2018-01-31 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sauce)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-28 06:23:26 +03:00
|
|
|
static int bintext_read_header(AVFormatContext *s)
|
2011-09-16 05:50:26 +03:00
|
|
|
{
|
|
|
|
BinDemuxContext *bin = s->priv_data;
|
2011-11-14 02:36:45 +03:00
|
|
|
AVIOContext *pb = s->pb;
|
2019-12-10 23:59:53 +02:00
|
|
|
int ret;
|
2012-01-28 06:23:26 +03:00
|
|
|
AVStream *st = init_stream(s);
|
2011-09-16 05:50:26 +03:00
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_BINTEXT;
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2019-12-10 23:59:53 +02:00
|
|
|
if ((ret = ff_alloc_extradata(st->codecpar, 2)) < 0)
|
|
|
|
return ret;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->extradata[0] = 16;
|
|
|
|
st->codecpar->extradata[1] = 0;
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2017-03-21 22:02:30 +02:00
|
|
|
if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
|
2011-09-16 05:50:26 +03:00
|
|
|
int got_width = 0;
|
2011-11-14 02:54:10 +03:00
|
|
|
bin->fsize = avio_size(pb);
|
2011-09-16 05:50:26 +03:00
|
|
|
if (ff_sauce_read(s, &bin->fsize, &got_width, 0) < 0)
|
|
|
|
next_tag_read(s, &bin->fsize);
|
2013-04-05 17:46:28 +03:00
|
|
|
if (!bin->width) {
|
2016-04-10 21:58:15 +02:00
|
|
|
predict_width(st->codecpar, bin->fsize, got_width);
|
2019-10-25 12:16:29 +02:00
|
|
|
if (st->codecpar->width < 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2016-04-10 21:58:15 +02:00
|
|
|
calculate_height(st->codecpar, bin->fsize);
|
2012-01-29 04:12:57 +03:00
|
|
|
}
|
2011-11-14 02:52:55 +03:00
|
|
|
avio_seek(pb, 0, SEEK_SET);
|
2011-09-16 05:50:26 +03:00
|
|
|
}
|
|
|
|
return 0;
|
2012-08-31 16:20:57 +03:00
|
|
|
}
|
2011-09-16 05:50:26 +03:00
|
|
|
#endif /* CONFIG_BINTEXT_DEMUXER */
|
|
|
|
|
|
|
|
#if CONFIG_XBIN_DEMUXER
|
2019-03-21 02:18:37 +02:00
|
|
|
static int xbin_probe(const AVProbeData *p)
|
2011-09-16 05:50:26 +03:00
|
|
|
{
|
|
|
|
const uint8_t *d = p->buf;
|
|
|
|
|
|
|
|
if (AV_RL32(d) == MKTAG('X','B','I','N') && d[4] == 0x1A &&
|
|
|
|
AV_RL16(d+5) > 0 && AV_RL16(d+5) <= 160 &&
|
|
|
|
d[9] > 0 && d[9] <= 32)
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-28 06:23:26 +03:00
|
|
|
static int xbin_read_header(AVFormatContext *s)
|
2011-09-16 05:50:26 +03:00
|
|
|
{
|
|
|
|
BinDemuxContext *bin = s->priv_data;
|
2011-11-14 02:36:45 +03:00
|
|
|
AVIOContext *pb = s->pb;
|
2011-09-16 05:50:26 +03:00
|
|
|
char fontheight, flags;
|
2019-12-10 23:59:53 +02:00
|
|
|
int ret;
|
2012-01-28 06:23:26 +03:00
|
|
|
AVStream *st = init_stream(s);
|
2011-09-16 05:50:26 +03:00
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2011-11-14 03:28:05 +03:00
|
|
|
avio_skip(pb, 5);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->width = avio_rl16(pb)<<3;
|
|
|
|
st->codecpar->height = avio_rl16(pb);
|
2011-11-14 03:19:56 +03:00
|
|
|
fontheight = avio_r8(pb);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->height *= fontheight;
|
2011-11-14 03:19:56 +03:00
|
|
|
flags = avio_r8(pb);
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->extradata_size = 2;
|
2011-09-16 05:50:26 +03:00
|
|
|
if ((flags & BINTEXT_PALETTE))
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->extradata_size += 48;
|
2011-09-16 05:50:26 +03:00
|
|
|
if ((flags & BINTEXT_FONT))
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->extradata_size += fontheight * (flags & 0x10 ? 512 : 256);
|
|
|
|
st->codecpar->codec_id = flags & 4 ? AV_CODEC_ID_XBIN : AV_CODEC_ID_BINTEXT;
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2019-12-10 23:59:53 +02:00
|
|
|
ret = ff_alloc_extradata(st->codecpar, st->codecpar->extradata_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->extradata[0] = fontheight;
|
|
|
|
st->codecpar->extradata[1] = flags;
|
|
|
|
if (avio_read(pb, st->codecpar->extradata + 2, st->codecpar->extradata_size - 2) < 0)
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVERROR(EIO);
|
|
|
|
|
2017-03-21 22:02:30 +02:00
|
|
|
if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
|
2024-07-11 18:10:00 +02:00
|
|
|
int64_t fsize = avio_size(pb);
|
|
|
|
if (fsize < 9 + st->codecpar->extradata_size)
|
|
|
|
return 0;
|
|
|
|
bin->fsize = fsize - 9 - st->codecpar->extradata_size;
|
2011-09-16 05:50:26 +03:00
|
|
|
ff_sauce_read(s, &bin->fsize, NULL, 0);
|
2016-04-10 21:58:15 +02:00
|
|
|
avio_seek(pb, 9 + st->codecpar->extradata_size, SEEK_SET);
|
2011-09-16 05:50:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_XBIN_DEMUXER */
|
|
|
|
|
|
|
|
#if CONFIG_ADF_DEMUXER
|
2012-01-28 06:23:26 +03:00
|
|
|
static int adf_read_header(AVFormatContext *s)
|
2011-09-16 05:50:26 +03:00
|
|
|
{
|
|
|
|
BinDemuxContext *bin = s->priv_data;
|
2011-11-14 02:36:45 +03:00
|
|
|
AVIOContext *pb = s->pb;
|
2011-09-16 05:50:26 +03:00
|
|
|
AVStream *st;
|
2019-12-10 23:59:53 +02:00
|
|
|
int ret;
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2011-11-14 03:19:56 +03:00
|
|
|
if (avio_r8(pb) != 1)
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2012-01-28 06:23:26 +03:00
|
|
|
st = init_stream(s);
|
2011-09-16 05:50:26 +03:00
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_BINTEXT;
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2019-12-10 23:59:53 +02:00
|
|
|
if ((ret = ff_alloc_extradata(st->codecpar, 2 + 48 + 4096)) < 0)
|
|
|
|
return ret;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->extradata[0] = 16;
|
|
|
|
st->codecpar->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT;
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
if (avio_read(pb, st->codecpar->extradata + 2, 24) < 0)
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVERROR(EIO);
|
2011-11-14 03:28:05 +03:00
|
|
|
avio_skip(pb, 144);
|
2016-04-10 21:58:15 +02:00
|
|
|
if (avio_read(pb, st->codecpar->extradata + 2 + 24, 24) < 0)
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVERROR(EIO);
|
2016-04-10 21:58:15 +02:00
|
|
|
if (avio_read(pb, st->codecpar->extradata + 2 + 48, 4096) < 0)
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVERROR(EIO);
|
|
|
|
|
2017-03-21 22:02:30 +02:00
|
|
|
if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
|
2011-09-16 05:50:26 +03:00
|
|
|
int got_width = 0;
|
2024-07-11 18:10:00 +02:00
|
|
|
int64_t fsize = avio_size(pb);
|
|
|
|
if (fsize < 1 + 192 + 4096)
|
|
|
|
return 0;
|
|
|
|
bin->fsize = fsize - 1 - 192 - 4096;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->width = 80<<3;
|
2011-09-16 05:50:26 +03:00
|
|
|
ff_sauce_read(s, &bin->fsize, &got_width, 0);
|
2020-10-31 14:51:47 +02:00
|
|
|
if (st->codecpar->width < 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2013-04-05 17:46:28 +03:00
|
|
|
if (!bin->width)
|
2016-04-10 21:58:15 +02:00
|
|
|
calculate_height(st->codecpar, bin->fsize);
|
2011-11-14 02:52:55 +03:00
|
|
|
avio_seek(pb, 1 + 192 + 4096, SEEK_SET);
|
2011-09-16 05:50:26 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ADF_DEMUXER */
|
|
|
|
|
|
|
|
#if CONFIG_IDF_DEMUXER
|
|
|
|
static const uint8_t idf_magic[] = {
|
|
|
|
0x04, 0x31, 0x2e, 0x34, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x15, 0x00
|
|
|
|
};
|
|
|
|
|
2019-03-21 02:18:37 +02:00
|
|
|
static int idf_probe(const AVProbeData *p)
|
2011-09-16 05:50:26 +03:00
|
|
|
{
|
2011-10-16 03:38:02 +03:00
|
|
|
if (p->buf_size < sizeof(idf_magic))
|
|
|
|
return 0;
|
|
|
|
if (!memcmp(p->buf, idf_magic, sizeof(idf_magic)))
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-28 06:23:26 +03:00
|
|
|
static int idf_read_header(AVFormatContext *s)
|
2011-09-16 05:50:26 +03:00
|
|
|
{
|
|
|
|
BinDemuxContext *bin = s->priv_data;
|
2011-11-14 02:36:45 +03:00
|
|
|
AVIOContext *pb = s->pb;
|
2011-09-16 05:50:26 +03:00
|
|
|
AVStream *st;
|
2019-12-10 23:59:53 +02:00
|
|
|
int got_width = 0, ret;
|
2024-07-11 18:10:00 +02:00
|
|
|
int64_t fsize;
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2017-03-21 22:02:30 +02:00
|
|
|
if (!(pb->seekable & AVIO_SEEKABLE_NORMAL))
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVERROR(EIO);
|
|
|
|
|
2012-01-28 06:23:26 +03:00
|
|
|
st = init_stream(s);
|
2011-09-16 05:50:26 +03:00
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_IDF;
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2019-12-10 23:59:53 +02:00
|
|
|
if ((ret = ff_alloc_extradata(st->codecpar, 2 + 48 + 4096)) < 0)
|
|
|
|
return ret;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->extradata[0] = 16;
|
|
|
|
st->codecpar->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT;
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2024-07-11 18:10:00 +02:00
|
|
|
fsize = avio_size(pb);
|
|
|
|
if (fsize < 12 + 4096 + 48)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
bin->fsize = fsize - 12 - 4096 - 48;
|
|
|
|
|
|
|
|
avio_seek(pb, bin->fsize + 12, SEEK_SET);
|
2011-09-16 05:50:26 +03:00
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
if (avio_read(pb, st->codecpar->extradata + 2 + 48, 4096) < 0)
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVERROR(EIO);
|
2016-04-10 21:58:15 +02:00
|
|
|
if (avio_read(pb, st->codecpar->extradata + 2, 48) < 0)
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVERROR(EIO);
|
|
|
|
|
|
|
|
ff_sauce_read(s, &bin->fsize, &got_width, 0);
|
2020-10-31 14:51:47 +02:00
|
|
|
if (st->codecpar->width < 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2013-04-05 17:46:28 +03:00
|
|
|
if (!bin->width)
|
2016-04-10 21:58:15 +02:00
|
|
|
calculate_height(st->codecpar, bin->fsize);
|
2011-11-14 02:52:55 +03:00
|
|
|
avio_seek(pb, 12, SEEK_SET);
|
2011-09-16 05:50:26 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IDF_DEMUXER */
|
|
|
|
|
|
|
|
static int read_packet(AVFormatContext *s,
|
|
|
|
AVPacket *pkt)
|
|
|
|
{
|
|
|
|
BinDemuxContext *bin = s->priv_data;
|
|
|
|
|
|
|
|
if (bin->fsize > 0) {
|
|
|
|
if (av_get_packet(s->pb, pkt, bin->fsize) < 0)
|
|
|
|
return AVERROR(EIO);
|
|
|
|
bin->fsize = -1; /* done */
|
|
|
|
} else if (!bin->fsize) {
|
2014-08-07 23:12:41 +03:00
|
|
|
if (avio_feof(s->pb))
|
2011-09-16 05:50:26 +03:00
|
|
|
return AVERROR(EIO);
|
|
|
|
if (av_get_packet(s->pb, pkt, bin->chars_per_frame) < 0)
|
|
|
|
return AVERROR(EIO);
|
|
|
|
} else {
|
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-29 04:12:57 +03:00
|
|
|
#define OFFSET(x) offsetof(BinDemuxContext, x)
|
|
|
|
static const AVOption options[] = {
|
2012-09-05 15:26:01 +03:00
|
|
|
{ "linespeed", "set simulated line speed (bytes per second)", OFFSET(chars_per_frame), AV_OPT_TYPE_INT, {.i64 = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM},
|
2013-04-05 17:46:28 +03:00
|
|
|
{ "video_size", "set video size, such as 640x480 or hd720.", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
|
2016-06-09 05:00:52 +02:00
|
|
|
{ "framerate", "set framerate (frames per second)", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
|
2012-01-29 04:12:57 +03:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CLASS(name) \
|
|
|
|
(const AVClass[1]){{ \
|
|
|
|
.class_name = name, \
|
2024-01-19 14:33:28 +02:00
|
|
|
.item_name = av_default_item_name, \
|
2012-01-29 04:12:57 +03:00
|
|
|
.option = options, \
|
|
|
|
.version = LIBAVUTIL_VERSION_INT, \
|
|
|
|
}}
|
|
|
|
|
2011-09-16 05:50:26 +03:00
|
|
|
#if CONFIG_BINTEXT_DEMUXER
|
2024-02-10 16:50:43 +02:00
|
|
|
const FFInputFormat ff_bintext_demuxer = {
|
|
|
|
.p.name = "bin",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("Binary text"),
|
|
|
|
.p.priv_class = CLASS("Binary text demuxer"),
|
2011-09-26 01:19:56 +03:00
|
|
|
.priv_data_size = sizeof(BinDemuxContext),
|
2018-01-31 16:22:29 +02:00
|
|
|
.read_probe = bin_probe,
|
2011-09-26 01:19:56 +03:00
|
|
|
.read_header = bintext_read_header,
|
|
|
|
.read_packet = read_packet,
|
2011-09-16 05:50:26 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_XBIN_DEMUXER
|
2024-02-10 16:50:43 +02:00
|
|
|
const FFInputFormat ff_xbin_demuxer = {
|
|
|
|
.p.name = "xbin",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("eXtended BINary text (XBIN)"),
|
|
|
|
.p.priv_class = CLASS("eXtended BINary text (XBIN) demuxer"),
|
2011-09-26 01:19:56 +03:00
|
|
|
.priv_data_size = sizeof(BinDemuxContext),
|
|
|
|
.read_probe = xbin_probe,
|
|
|
|
.read_header = xbin_read_header,
|
|
|
|
.read_packet = read_packet,
|
2011-09-16 05:50:26 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_ADF_DEMUXER
|
2024-02-10 16:50:43 +02:00
|
|
|
const FFInputFormat ff_adf_demuxer = {
|
|
|
|
.p.name = "adf",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("Artworx Data Format"),
|
|
|
|
.p.extensions = "adf",
|
|
|
|
.p.priv_class = CLASS("Artworx Data Format demuxer"),
|
2011-09-26 01:19:56 +03:00
|
|
|
.priv_data_size = sizeof(BinDemuxContext),
|
|
|
|
.read_header = adf_read_header,
|
|
|
|
.read_packet = read_packet,
|
2011-09-16 05:50:26 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_IDF_DEMUXER
|
2024-02-10 16:50:43 +02:00
|
|
|
const FFInputFormat ff_idf_demuxer = {
|
|
|
|
.p.name = "idf",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("iCE Draw File"),
|
|
|
|
.p.extensions = "idf",
|
|
|
|
.p.priv_class = CLASS("iCE Draw File demuxer"),
|
2011-09-26 01:19:56 +03:00
|
|
|
.priv_data_size = sizeof(BinDemuxContext),
|
|
|
|
.read_probe = idf_probe,
|
|
|
|
.read_header = idf_read_header,
|
|
|
|
.read_packet = read_packet,
|
2011-09-16 05:50:26 +03:00
|
|
|
};
|
|
|
|
#endif
|