[FFmpeg-devel] [PATCH] 8088flex TMV demuxer and decoder

Daniel Verkamp daniel
Wed Apr 22 21:33:42 CEST 2009


On Wed, Apr 22, 2009 at 2:17 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Wed, Apr 22, 2009 at 09:42:29AM -0500, Daniel Verkamp wrote:
> [...]
>
>> + ? ?for (y = 0; y < char_rows; y++) {
>> + ? ? ? ?for (x = 0; x < char_cols; x++) {
>> + ? ? ? ? ? ?c ?= *src++ * 8;
>> + ? ? ? ? ? ?bg = *src ?>> 4;
>> + ? ? ? ? ? ?fg = *src++ & 0xF;
>> +
>> + ? ? ? ? ? ?dst_char = dst + x * 8;
>> + ? ? ? ? ? ?for (char_y = 0; char_y < 8; char_y++) {
>> + ? ? ? ? ? ? ? ?for (mask = 0x80; mask; mask >>= 1) {
>> + ? ? ? ? ? ? ? ? ? ?*dst_char++ = ff_cga_font[c + char_y] & mask ? fg : bg;
>> + ? ? ? ? ? ? ? ?}
>> + ? ? ? ? ? ? ? ?dst_char += tmv->pic.linesize[0] - 8;
>> + ? ? ? ? ? ?}
>> + ? ? ? ?}
>
> compression wise this is not wise ...
> you could store a bit for each of the 80x25 chars and only if its
> 1 store color+char oterwise copy from the same location of the previous frame
> similarly the color could be reused from the last frame and just the char
> updated
>
> also if you sort the 256 chars based on their amount of foreground/background
> pixels then chars might be nummerically correlated and compression of changed
> chars might be possible by huffman coded differences.
>
> speedwise it can of course be done faster by building more than 1 pixel at a
> time but i guess theres no point, its better if it stays simple.
>

If this is a critique of the format itself, I didn't design it. :)
Or do you mean I should change the decoder somehow?

>
> [...]
>> +static int tmv_read_header(AVFormatContext *s, AVFormatParameters *ap)
>> +{
>> + ? ?TMVContext *tmv ? = s->priv_data;
>> + ? ?ByteIOContext *pb = s->pb;
>> + ? ?AVStream *vst, *ast;
>> +
>> + ? ?if (get_le32(pb) != TMV_TAG)
>> + ? ? ? ?return -1;
>> +
>> + ? ?if (!(vst = av_new_stream(s, 0)))
>> + ? ? ? ?return AVERROR(ENOMEM);
>> +
>> + ? ?if (!(ast = av_new_stream(s, 0)))
>> + ? ? ? ?return AVERROR(ENOMEM);
>> +
>> + ? ?ast->codec->sample_rate = get_le16(pb);
>> + ? ?tmv->audio_chunk_size ? = get_le16(pb);
>> + ? ?tmv->comp_method ? ? ? ?= get_byte(pb);
>> + ? ?if (tmv->comp_method) {
>> + ? ? ? ?av_log(s, AV_LOG_ERROR, "unsupported compression method %d\n",
>> + ? ? ? ? ? ? ? tmv->comp_method);
>> + ? ? ? ?return -1;
>> + ? ?}
>> +
>> + ? ?tmv->char_cols = get_byte(pb);
>> + ? ?tmv->char_rows = get_byte(pb);
>> +
>> + ? ?tmv->features ?= get_byte(pb);
>> + ? ?if (tmv->features & ~(TMV_PADDING | TMV_STEREO)) {
>> + ? ? ? ?av_log(s, AV_LOG_ERROR, "unsupported features 0x%02x\n",
>> + ? ? ? ? ? ? ? tmv->features & ~(TMV_PADDING | TMV_STEREO));
>> + ? ? ? ?return -1;
>> + ? ?}
>> +
>> + ? ?ast->codec->codec_type ? ? ? ? ? ?= CODEC_TYPE_AUDIO;
>> + ? ?ast->codec->codec_id ? ? ? ? ? ? ?= CODEC_ID_PCM_U8;
>> + ? ?ast->codec->sample_fmt ? ? ? ? ? ?= SAMPLE_FMT_U8;
>> + ? ?ast->codec->channels ? ? ? ? ? ? ?= tmv->features & TMV_STEREO ? 2 : 1;
>> + ? ?ast->codec->bits_per_coded_sample = 8;
>> + ? ?ast->codec->bit_rate ? ? ? ? ? ? ?= ast->codec->sample_rate *
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ast->codec->bits_per_coded_sample;
>> + ? ?tmv->pts_inc[1] ? ? ? ? ? ? ? ? ? = tmv->audio_chunk_size;
>> + ? ?av_set_pts_info(ast, 32, 1, ast->codec->sample_rate);
>> +
>> + ? ?vst->codec->codec_type = CODEC_TYPE_VIDEO;
>> + ? ?vst->codec->codec_id ? = CODEC_ID_TMV;
>> + ? ?vst->codec->pix_fmt ? ?= PIX_FMT_PAL8;
>> + ? ?vst->codec->width ? ? ?= tmv->char_cols * 8;
>> + ? ?vst->codec->height ? ? = tmv->char_rows * 8;
>> + ? ?tmv->pts_inc[0] ? ? ? ?= 1;
>> + ? ?av_set_pts_info(vst, 32, tmv->audio_chunk_size,
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ast->codec->sample_rate * ast->codec->channels);
>
> if you set av_set_pts_info() so each contain 1 frame then you should not
> need to set pts of packets, lavf can add 1 as well
>

Ok, removed this.  It seems I don't need to set pts for PCM audio
either, correct?

> [...]
> --
> Michael ? ? GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Also added #endif comment on the include guard in cga_data.h.

Thanks,
-- Daniel Verkamp
-------------- next part --------------
>From b23603a97b7d1f5cb422f85757532e1157d3bb9d Mon Sep 17 00:00:00 2001
From: Daniel Verkamp <daniel at drv.nu>
Date: Wed, 22 Apr 2009 14:33:49 -0500
Subject: [PATCH 1/3] CGA ROM font and palette

---
 libavcodec/cga_data.c |  157 +++++++++++++++++++++++++++++++++++++++++++++++++
 libavcodec/cga_data.h |   27 +++++++++
 2 files changed, 184 insertions(+), 0 deletions(-)
 create mode 100644 libavcodec/cga_data.c
 create mode 100644 libavcodec/cga_data.h

diff --git a/libavcodec/cga_data.c b/libavcodec/cga_data.c
new file mode 100644
index 0000000..2d1f89c
--- /dev/null
+++ b/libavcodec/cga_data.c
@@ -0,0 +1,157 @@
+/*
+ * CGA ROM data
+ *
+ * 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 <stdint.h>
+
+const uint8_t ff_cga_font[2048] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e,
+ 0x7e, 0xff, 0xdb, 0xff, 0xc3, 0xe7, 0xff, 0x7e, 0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00,
+ 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x38, 0x7c, 0x38, 0xfe, 0xfe, 0x7c, 0x38, 0x7c,
+ 0x10, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x7c, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00,
+ 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00,
+ 0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0x0f, 0x07, 0x0f, 0x7d, 0xcc, 0xcc, 0xcc, 0x78,
+ 0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x70, 0xf0, 0xe0,
+ 0x7f, 0x63, 0x7f, 0x63, 0x63, 0x67, 0xe6, 0xc0, 0x99, 0x5a, 0x3c, 0xe7, 0xe7, 0x3c, 0x5a, 0x99,
+ 0x80, 0xe0, 0xf8, 0xfe, 0xf8, 0xe0, 0x80, 0x00, 0x02, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x02, 0x00,
+ 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00,
+ 0x7f, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x00, 0x3e, 0x63, 0x38, 0x6c, 0x6c, 0x38, 0xcc, 0x78,
+ 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x7e, 0x3c, 0x18, 0xff,
+ 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00,
+ 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00,
+ 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00,
+ 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7e, 0x3c, 0x18, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78, 0x78, 0x30, 0x30, 0x00, 0x30, 0x00,
+ 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x00,
+ 0x30, 0x7c, 0xc0, 0x78, 0x0c, 0xf8, 0x30, 0x00, 0x00, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xc6, 0x00,
+ 0x38, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0x76, 0x00, 0x60, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00,
+ 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00,
+ 0x7c, 0xc6, 0xce, 0xde, 0xf6, 0xe6, 0x7c, 0x00, 0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x00,
+ 0x78, 0xcc, 0x0c, 0x38, 0x60, 0xcc, 0xfc, 0x00, 0x78, 0xcc, 0x0c, 0x38, 0x0c, 0xcc, 0x78, 0x00,
+ 0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x1e, 0x00, 0xfc, 0xc0, 0xf8, 0x0c, 0x0c, 0xcc, 0x78, 0x00,
+ 0x38, 0x60, 0xc0, 0xf8, 0xcc, 0xcc, 0x78, 0x00, 0xfc, 0xcc, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x00,
+ 0x78, 0xcc, 0xcc, 0x78, 0xcc, 0xcc, 0x78, 0x00, 0x78, 0xcc, 0xcc, 0x7c, 0x0c, 0x18, 0x70, 0x00,
+ 0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x60,
+ 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0xfc, 0x00, 0x00,
+ 0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x78, 0xcc, 0x0c, 0x18, 0x30, 0x00, 0x30, 0x00,
+ 0x7c, 0xc6, 0xde, 0xde, 0xde, 0xc0, 0x78, 0x00, 0x30, 0x78, 0xcc, 0xcc, 0xfc, 0xcc, 0xcc, 0x00,
+ 0xfc, 0x66, 0x66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0xc6, 0x00, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x30, 0x78, 0x00,
+ 0xfe, 0xc6, 0x8c, 0x18, 0x32, 0x66, 0xfe, 0x00, 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00,
+ 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x02, 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00,
+ 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
+ 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
+ 0xe0, 0x60, 0x60, 0x7c, 0x66, 0x66, 0xdc, 0x00, 0x00, 0x00, 0x78, 0xcc, 0xc0, 0xcc, 0x78, 0x00,
+ 0x1c, 0x0c, 0x0c, 0x7c, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00,
+ 0x38, 0x6c, 0x60, 0xf0, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8,
+ 0xe0, 0x60, 0x6c, 0x76, 0x66, 0x66, 0xe6, 0x00, 0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00,
+ 0x0c, 0x00, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0xe0, 0x60, 0x66, 0x6c, 0x78, 0x6c, 0xe6, 0x00,
+ 0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, 0xcc, 0xfe, 0xfe, 0xd6, 0xc6, 0x00,
+ 0x00, 0x00, 0xf8, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x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0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18,
+ 0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36,
+ 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00,
+ 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18,
+ 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18,
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18,
+ 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
+ 0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
+ 0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18,
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00,
+ 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18,
+ 0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36,
+ 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
+ 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x76, 0xdc, 0xc8, 0xdc, 0x76, 0x00, 0x00, 0x78, 0xcc, 0xf8, 0xcc, 0xf8, 0xc0, 0xc0,
+ 0x00, 0xfc, 0xcc, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00,
+ 0xfc, 0xcc, 0x60, 0x30, 0x60, 0xcc, 0xfc, 0x00, 0x00, 0x00, 0x7e, 0xd8, 0xd8, 0xd8, 0x70, 0x00,
+ 0x00, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0xc0, 0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x00,
+ 0xfc, 0x30, 0x78, 0xcc, 0xcc, 0x78, 0x30, 0xfc, 0x38, 0x6c, 0xc6, 0xfe, 0xc6, 0x6c, 0x38, 0x00,
+ 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x6c, 0xee, 0x00, 0x1c, 0x30, 0x18, 0x7c, 0xcc, 0xcc, 0x78, 0x00,
+ 0x00, 0x00, 0x7e, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x06, 0x0c, 0x7e, 0xdb, 0xdb, 0x7e, 0x60, 0xc0,
+ 0x38, 0x60, 0xc0, 0xf8, 0xc0, 0x60, 0x38, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00,
+ 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0x00, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x00, 0xfc, 0x00,
+ 0x60, 0x30, 0x18, 0x30, 0x60, 0x00, 0xfc, 0x00, 0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0xfc, 0x00,
+ 0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70,
+ 0x30, 0x30, 0x00, 0xfc, 0x00, 0x30, 0x30, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00,
+ 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x3c, 0x1c,
+ 0x78, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x70, 0x18, 0x30, 0x60, 0x78, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+const uint32_t ff_cga_palette[16] = {
+    0x000000, 0x0000AA, 0x00AA00, 0x00AAAA, 0xAA0000, 0xAA00AA, 0xAA5500, 0xAAAAAA,
+    0x555555, 0x5555FF, 0x55FF55, 0x55FFFF, 0xFF5555, 0xFF55FF, 0xFFFF55, 0xFFFFFF,
+};
diff --git a/libavcodec/cga_data.h b/libavcodec/cga_data.h
new file mode 100644
index 0000000..c2c96bf
--- /dev/null
+++ b/libavcodec/cga_data.h
@@ -0,0 +1,27 @@
+/*
+ * CGA ROM data
+ *
+ * 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
+ */
+
+#ifndef AVCODEC_CGA_DATA_H
+#define AVCODEC_CGA_DATA_H
+
+extern const uint8_t ff_cga_font[2048];
+extern const uint32_t ff_cga_palette[16];
+
+#endif /* AVCODEC_CGA_DATA_H */
-- 
1.6.2.3
-------------- next part --------------
>From 20ca281b4da3ecb080995b9da0fdae174db5b035 Mon Sep 17 00:00:00 2001
From: Daniel Verkamp <daniel at drv.nu>
Date: Wed, 22 Apr 2009 14:34:28 -0500
Subject: [PATCH 2/3] 8088flex TMV video decoder

---
 libavcodec/Makefile    |    1 +
 libavcodec/allcodecs.c |    1 +
 libavcodec/avcodec.h   |    1 +
 libavcodec/tmv.c       |  116 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 119 insertions(+), 0 deletions(-)
 create mode 100644 libavcodec/tmv.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b02b44e..e2f0b2c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -221,6 +221,7 @@ OBJS-$(CONFIG_THP_DECODER)             += mjpegdec.o mjpeg.o
 OBJS-$(CONFIG_TIERTEXSEQVIDEO_DECODER) += tiertexseqv.o
 OBJS-$(CONFIG_TIFF_DECODER)            += tiff.o lzw.o faxcompr.o
 OBJS-$(CONFIG_TIFF_ENCODER)            += tiffenc.o rle.o lzwenc.o
+OBJS-$(CONFIG_TMV_DECODER)             += tmv.o cga_data.o
 OBJS-$(CONFIG_TRUEHD_DECODER)          += mlpdec.o mlp_parser.o mlp.o
 OBJS-$(CONFIG_TRUEMOTION1_DECODER)     += truemotion1.o
 OBJS-$(CONFIG_TRUEMOTION2_DECODER)     += truemotion2.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index bcc11d0..41cf661 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -162,6 +162,7 @@ void avcodec_register_all(void)
     REGISTER_DECODER (THP, thp);
     REGISTER_DECODER (TIERTEXSEQVIDEO, tiertexseqvideo);
     REGISTER_ENCDEC  (TIFF, tiff);
+    REGISTER_DECODER (TMV, tmv);
     REGISTER_DECODER (TRUEMOTION1, truemotion1);
     REGISTER_DECODER (TRUEMOTION2, truemotion2);
     REGISTER_DECODER (TSCC, tscc);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 8016d82..7bea9ca 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -194,6 +194,7 @@ enum CodecID {
     CODEC_ID_AURA,
     CODEC_ID_AURA2,
     CODEC_ID_V210X,
+    CODEC_ID_TMV,
 
     /* various PCM "codecs" */
     CODEC_ID_PCM_S16LE= 0x10000,
diff --git a/libavcodec/tmv.c b/libavcodec/tmv.c
new file mode 100644
index 0000000..70b8cf1
--- /dev/null
+++ b/libavcodec/tmv.c
@@ -0,0 +1,116 @@
+/*
+ * 8088flex TMV video decoder
+ * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
+ *
+ * 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
+ */
+
+/**
+ * 8088flex TMV video decoder
+ * @file libavcodec/tmv.c
+ * @author Daniel Verkamp
+ * @sa http://www.oldskool.org/pc/8088_Corruption
+ */
+
+#include "avcodec.h"
+
+#include "cga_data.h"
+
+typedef struct TMVContext {
+    AVFrame pic;
+    int pal_set;
+} TMVContext;
+
+static av_cold int tmv_decode_init(AVCodecContext *avctx)
+{
+    TMVContext *tmv = avctx->priv_data;
+
+    tmv->pic.data[0] = NULL;
+
+    return 0;
+}
+
+static int tmv_decode_frame(AVCodecContext *avctx, void *data,
+                            int *data_size, AVPacket *avpkt)
+{
+    TMVContext *tmv    = avctx->priv_data;
+    const uint8_t *src = avpkt->data;
+    uint8_t *dst, *dst_char;
+    unsigned char_cols = avctx->width >> 3;
+    unsigned char_rows = avctx->height >> 3;
+    unsigned x, y, mask, char_y, fg, bg, c;
+
+    if (tmv->pic.data[0])
+        avctx->release_buffer(avctx, &tmv->pic);
+
+    if (avctx->get_buffer(avctx, &tmv->pic) < 0) {
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+        return -1;
+    }
+
+    tmv->pic.pict_type = FF_I_TYPE;
+    tmv->pic.key_frame = 1;
+    dst                = tmv->pic.data[0];
+
+    if (!tmv->pal_set) {
+        tmv->pal_set                 = 1;
+        tmv->pic.palette_has_changed = 1;
+        memcpy(tmv->pic.data[1], ff_cga_palette, 16 * 4);
+    }
+
+    for (y = 0; y < char_rows; y++) {
+        for (x = 0; x < char_cols; x++) {
+            c  = *src++ * 8;
+            bg = *src  >> 4;
+            fg = *src++ & 0xF;
+
+            dst_char = dst + x * 8;
+            for (char_y = 0; char_y < 8; char_y++) {
+                for (mask = 0x80; mask; mask >>= 1) {
+                    *dst_char++ = ff_cga_font[c + char_y] & mask ? fg : bg;
+                }
+                dst_char += tmv->pic.linesize[0] - 8;
+            }
+        }
+        dst += tmv->pic.linesize[0] * 8;
+    }
+
+    *data_size = sizeof(AVFrame);
+    *(AVFrame *)data = tmv->pic;
+    return avpkt->size;
+}
+
+static av_cold int tmv_decode_close(AVCodecContext *avctx)
+{
+    TMVContext *tmv = avctx->priv_data;
+
+    if (tmv->pic.data[0])
+        avctx->release_buffer(avctx, &tmv->pic);
+
+    return 0;
+}
+
+AVCodec tmv_decoder = {
+    .name           = "tmv",
+    .type           = CODEC_TYPE_VIDEO,
+    .id             = CODEC_ID_TMV,
+    .priv_data_size = sizeof(TMVContext),
+    .init           = tmv_decode_init,
+    .close          = tmv_decode_close,
+    .decode         = tmv_decode_frame,
+    .long_name      = NULL_IF_CONFIG_SMALL("8088flex TMV"),
+};
-- 
1.6.2.3
-------------- next part --------------
>From ca787e669a1caf42f827e1ce5e38c4d44a996c83 Mon Sep 17 00:00:00 2001
From: Daniel Verkamp <daniel at drv.nu>
Date: Wed, 22 Apr 2009 14:35:04 -0500
Subject: [PATCH 3/3] 8088flex TMV demuxer

---
 libavformat/Makefile     |    1 +
 libavformat/allformats.c |    1 +
 libavformat/tmv.c        |  143 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 145 insertions(+), 0 deletions(-)
 create mode 100644 libavformat/tmv.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 55717e6..b9e5eb7 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -210,6 +210,7 @@ OBJS-$(CONFIG_TG2_MUXER)                 += movenc.o riff.o isom.o avc.o
 OBJS-$(CONFIG_TGP_MUXER)                 += movenc.o riff.o isom.o avc.o
 OBJS-$(CONFIG_THP_DEMUXER)               += thp.o
 OBJS-$(CONFIG_TIERTEXSEQ_DEMUXER)        += tiertexseq.o
+OBJS-$(CONFIG_TMV_DEMUXER)               += tmv.o
 OBJS-$(CONFIG_TRUEHD_DEMUXER)            += raw.o id3v2.o
 OBJS-$(CONFIG_TRUEHD_MUXER)              += raw.o
 OBJS-$(CONFIG_TTA_DEMUXER)               += tta.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index e193af7..626b66c 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -182,6 +182,7 @@ void av_register_all(void)
     REGISTER_MUXER    (TGP, tgp);
     REGISTER_DEMUXER  (THP, thp);
     REGISTER_DEMUXER  (TIERTEXSEQ, tiertexseq);
+    REGISTER_DEMUXER  (TMV, tmv);
     REGISTER_MUXDEMUX (TRUEHD, truehd);
     REGISTER_DEMUXER  (TTA, tta);
     REGISTER_DEMUXER  (TXD, txd);
diff --git a/libavformat/tmv.c b/libavformat/tmv.c
new file mode 100644
index 0000000..2c16493
--- /dev/null
+++ b/libavformat/tmv.c
@@ -0,0 +1,143 @@
+/*
+ * 8088flex TMV file demuxer
+ * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
+ *
+ * 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
+ */
+
+/**
+ * 8088flex TMV file demuxer
+ * @file libavformat/tmv.c
+ * @author Daniel Verkamp
+ * @sa http://www.oldskool.org/pc/8088_Corruption
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+
+enum {
+    TMV_PADDING = 0x01,
+    TMV_STEREO  = 0x02,
+};
+
+#define TMV_TAG MKTAG('T', 'M', 'A', 'V')
+
+typedef struct TMVContext {
+    unsigned audio_chunk_size;
+    unsigned comp_method;
+    unsigned char_cols;
+    unsigned char_rows;
+    unsigned features;
+
+    unsigned padding;
+
+    unsigned stream_index;
+} TMVContext;
+
+static int tmv_probe(AVProbeData *p)
+{
+    if (AV_RL32(p->buf) == TMV_TAG)
+        return AVPROBE_SCORE_MAX;
+    return 0;
+}
+
+static int tmv_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+    TMVContext *tmv   = s->priv_data;
+    ByteIOContext *pb = s->pb;
+    AVStream *vst, *ast;
+
+    if (get_le32(pb) != TMV_TAG)
+        return -1;
+
+    if (!(vst = av_new_stream(s, 0)))
+        return AVERROR(ENOMEM);
+
+    if (!(ast = av_new_stream(s, 0)))
+        return AVERROR(ENOMEM);
+
+    ast->codec->sample_rate = get_le16(pb);
+    tmv->audio_chunk_size   = get_le16(pb);
+    tmv->comp_method        = get_byte(pb);
+    if (tmv->comp_method) {
+        av_log(s, AV_LOG_ERROR, "unsupported compression method %d\n",
+               tmv->comp_method);
+        return -1;
+    }
+
+    tmv->char_cols = get_byte(pb);
+    tmv->char_rows = get_byte(pb);
+
+    tmv->features  = get_byte(pb);
+    if (tmv->features & ~(TMV_PADDING | TMV_STEREO)) {
+        av_log(s, AV_LOG_ERROR, "unsupported features 0x%02x\n",
+               tmv->features & ~(TMV_PADDING | TMV_STEREO));
+        return -1;
+    }
+
+    ast->codec->codec_type            = CODEC_TYPE_AUDIO;
+    ast->codec->codec_id              = CODEC_ID_PCM_U8;
+    ast->codec->sample_fmt            = SAMPLE_FMT_U8;
+    ast->codec->channels              = tmv->features & TMV_STEREO ? 2 : 1;
+    ast->codec->bits_per_coded_sample = 8;
+    ast->codec->bit_rate              = ast->codec->sample_rate *
+                                        ast->codec->bits_per_coded_sample;
+    av_set_pts_info(ast, 32, 1, ast->codec->sample_rate);
+
+    vst->codec->codec_type = CODEC_TYPE_VIDEO;
+    vst->codec->codec_id   = CODEC_ID_TMV;
+    vst->codec->pix_fmt    = PIX_FMT_PAL8;
+    vst->codec->width      = tmv->char_cols * 8;
+    vst->codec->height     = tmv->char_rows * 8;
+    av_set_pts_info(vst, 32, tmv->audio_chunk_size,
+                             ast->codec->sample_rate * ast->codec->channels);
+
+    if (tmv->features & TMV_PADDING)
+        tmv->padding = ((2000 + tmv->audio_chunk_size + 511) & ~511) -
+                        (2000 + tmv->audio_chunk_size);
+
+    return 0;
+}
+
+static int tmv_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    TMVContext *tmv   = s->priv_data;
+    ByteIOContext *pb = s->pb;
+    int ret, pkt_size = tmv->stream_index ? tmv->audio_chunk_size : 2000;
+
+    if (url_feof(pb))
+        return AVERROR_EOF;
+
+    ret = av_get_packet(pb, pkt, pkt_size);
+
+    if (tmv->features & TMV_PADDING && tmv->stream_index)
+        url_fskip(pb, tmv->padding);
+
+    pkt->stream_index            = tmv->stream_index;
+    tmv->stream_index ^= 1;
+
+    return ret;
+}
+
+AVInputFormat tmv_demuxer = {
+    "tmv",
+    NULL_IF_CONFIG_SMALL("8088flex TMV"),
+    sizeof(TMVContext),
+    tmv_probe,
+    tmv_read_header,
+    tmv_read_packet,
+};
-- 
1.6.2.3



More information about the ffmpeg-devel mailing list