txd.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Renderware TeXture Dictionary (.txd) demuxer
  3. * Copyright (c) 2007 Ivo van Poorten
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/intreadwrite.h"
  22. #include "avformat.h"
  23. #define TXD_FILE 0x16
  24. #define TXD_INFO 0x01
  25. #define TXD_EXTRA 0x03
  26. #define TXD_TEXTURE 0x15
  27. #define TXD_TEXTURE_DATA 0x01
  28. #define TXD_MARKER 0x1803ffff
  29. #define TXD_MARKER2 0x1003ffff
  30. static int txd_probe(AVProbeData * pd) {
  31. if (AV_RL32(pd->buf ) == TXD_FILE &&
  32. (AV_RL32(pd->buf+8) == TXD_MARKER || AV_RL32(pd->buf+8) == TXD_MARKER2))
  33. return AVPROBE_SCORE_MAX;
  34. return 0;
  35. }
  36. static int txd_read_header(AVFormatContext *s) {
  37. AVStream *st;
  38. st = avformat_new_stream(s, NULL);
  39. if (!st)
  40. return AVERROR(ENOMEM);
  41. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  42. st->codec->codec_id = AV_CODEC_ID_TXD;
  43. st->codec->time_base.den = 5;
  44. st->codec->time_base.num = 1;
  45. /* the parameters will be extracted from the compressed bitstream */
  46. return 0;
  47. }
  48. static int txd_read_packet(AVFormatContext *s, AVPacket *pkt) {
  49. AVIOContext *pb = s->pb;
  50. unsigned int id, chunk_size, marker;
  51. int ret;
  52. next_chunk:
  53. id = avio_rl32(pb);
  54. chunk_size = avio_rl32(pb);
  55. marker = avio_rl32(pb);
  56. if (url_feof(s->pb))
  57. return AVERROR_EOF;
  58. if (marker != TXD_MARKER && marker != TXD_MARKER2) {
  59. av_log(s, AV_LOG_ERROR, "marker does not match\n");
  60. return AVERROR_INVALIDDATA;
  61. }
  62. switch (id) {
  63. case TXD_INFO:
  64. if (chunk_size > 100)
  65. break;
  66. case TXD_EXTRA:
  67. avio_skip(s->pb, chunk_size);
  68. case TXD_FILE:
  69. case TXD_TEXTURE:
  70. goto next_chunk;
  71. default:
  72. av_log(s, AV_LOG_ERROR, "unknown chunk id %i\n", id);
  73. return AVERROR_INVALIDDATA;
  74. }
  75. ret = av_get_packet(s->pb, pkt, chunk_size);
  76. if (ret < 0)
  77. return ret;
  78. pkt->stream_index = 0;
  79. return 0;
  80. }
  81. AVInputFormat ff_txd_demuxer = {
  82. .name = "txd",
  83. .long_name = NULL_IF_CONFIG_SMALL("Renderware TeXture Dictionary"),
  84. .read_probe = txd_probe,
  85. .read_header = txd_read_header,
  86. .read_packet = txd_read_packet,
  87. };