00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/intreadwrite.h"
00023 #include "avformat.h"
00024
00025 #define TXD_FILE 0x16
00026 #define TXD_INFO 0x01
00027 #define TXD_EXTRA 0x03
00028 #define TXD_TEXTURE 0x15
00029 #define TXD_TEXTURE_DATA 0x01
00030 #define TXD_MARKER 0x1803ffff
00031 #define TXD_MARKER2 0x1003ffff
00032
00033 static int txd_probe(AVProbeData * pd) {
00034 if (AV_RL32(pd->buf ) == TXD_FILE &&
00035 (AV_RL32(pd->buf+8) == TXD_MARKER || AV_RL32(pd->buf+8) == TXD_MARKER2))
00036 return AVPROBE_SCORE_MAX;
00037 return 0;
00038 }
00039
00040 static int txd_read_header(AVFormatContext *s, AVFormatParameters *ap) {
00041 AVStream *st;
00042
00043 st = av_new_stream(s, 0);
00044 if (!st)
00045 return AVERROR(ENOMEM);
00046 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00047 st->codec->codec_id = CODEC_ID_TXD;
00048 st->codec->time_base.den = 5;
00049 st->codec->time_base.num = 1;
00050
00051 return 0;
00052 }
00053
00054 static int txd_read_packet(AVFormatContext *s, AVPacket *pkt) {
00055 ByteIOContext *pb = s->pb;
00056 unsigned int id, chunk_size, marker;
00057 int ret;
00058
00059 next_chunk:
00060 id = get_le32(pb);
00061 chunk_size = get_le32(pb);
00062 marker = get_le32(pb);
00063
00064 if (url_feof(s->pb))
00065 return AVERROR_EOF;
00066 if (marker != TXD_MARKER && marker != TXD_MARKER2) {
00067 av_log(s, AV_LOG_ERROR, "marker does not match\n");
00068 return AVERROR_INVALIDDATA;
00069 }
00070
00071 switch (id) {
00072 case TXD_INFO:
00073 if (chunk_size > 100)
00074 break;
00075 case TXD_EXTRA:
00076 url_fskip(s->pb, chunk_size);
00077 case TXD_FILE:
00078 case TXD_TEXTURE:
00079 goto next_chunk;
00080 default:
00081 av_log(s, AV_LOG_ERROR, "unknown chunk id %i\n", id);
00082 return AVERROR_INVALIDDATA;
00083 }
00084
00085 ret = av_get_packet(s->pb, pkt, chunk_size);
00086 if (ret < 0)
00087 return ret;
00088 pkt->stream_index = 0;
00089
00090 return 0;
00091 }
00092
00093 AVInputFormat txd_demuxer =
00094 {
00095 "txd",
00096 NULL_IF_CONFIG_SMALL("Renderware TeXture Dictionary"),
00097 0,
00098 txd_probe,
00099 txd_read_header,
00100 txd_read_packet,
00101 };