Libav 0.7.1
|
00001 /* 00002 * Renderware TeXture Dictionary (.txd) demuxer 00003 * Copyright (c) 2007 Ivo van Poorten 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 /* the parameters will be extracted from the compressed bitstream */ 00051 return 0; 00052 } 00053 00054 static int txd_read_packet(AVFormatContext *s, AVPacket *pkt) { 00055 AVIOContext *pb = s->pb; 00056 unsigned int id, chunk_size, marker; 00057 int ret; 00058 00059 next_chunk: 00060 id = avio_rl32(pb); 00061 chunk_size = avio_rl32(pb); 00062 marker = avio_rl32(pb); 00063 00064 if (s->pb->eof_reached) 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 avio_skip(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 ff_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 };