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