txd.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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, AVFormatParameters *ap) {
  37. AVStream *st;
  38. st = av_new_stream(s, 0);
  39. if (!st)
  40. return AVERROR(ENOMEM);
  41. st->codec->codec_type = CODEC_TYPE_VIDEO;
  42. st->codec->codec_id = 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. ByteIOContext *pb = s->pb;
  50. unsigned int id, chunk_size, marker;
  51. int ret;
  52. next_chunk:
  53. id = get_le32(pb);
  54. chunk_size = get_le32(pb);
  55. marker = get_le32(pb);
  56. if (url_feof(s->pb))
  57. return AVERROR(EIO);
  58. if (marker != TXD_MARKER && marker != TXD_MARKER2) {
  59. av_log(NULL, AV_LOG_ERROR, "marker does not match\n");
  60. return AVERROR(EIO);
  61. }
  62. switch (id) {
  63. case TXD_INFO:
  64. if (chunk_size > 100)
  65. break;
  66. case TXD_EXTRA:
  67. url_fskip(s->pb, chunk_size);
  68. case TXD_FILE:
  69. case TXD_TEXTURE:
  70. goto next_chunk;
  71. default:
  72. av_log(NULL, AV_LOG_ERROR, "unknown chunk id %i\n", id);
  73. return AVERROR(EIO);
  74. }
  75. ret = av_get_packet(s->pb, pkt, chunk_size);
  76. pkt->stream_index = 0;
  77. return ret <= 0 ? AVERROR(EIO) : ret;
  78. }
  79. AVInputFormat txd_demuxer =
  80. {
  81. "txd",
  82. NULL_IF_CONFIG_SMALL("Renderware TeXture Dictionary"),
  83. 0,
  84. txd_probe,
  85. txd_read_header,
  86. txd_read_packet,
  87. };