You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.8KB

  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 "avformat.h"
  22. #define TXD_FILE 0x16
  23. #define TXD_INFO 0x01
  24. #define TXD_EXTRA 0x03
  25. #define TXD_TEXTURE 0x15
  26. #define TXD_TEXTURE_DATA 0x01
  27. #define TXD_MARKER 0x1803ffff
  28. #define TXD_MARKER2 0x1003ffff
  29. static int txd_probe(AVProbeData * pd) {
  30. if (AV_RL32(pd->buf ) == TXD_FILE &&
  31. (AV_RL32(pd->buf+8) == TXD_MARKER || AV_RL32(pd->buf+8) == TXD_MARKER2))
  32. return AVPROBE_SCORE_MAX;
  33. return 0;
  34. }
  35. static int txd_read_header(AVFormatContext *s, AVFormatParameters *ap) {
  36. AVStream *st;
  37. st = av_new_stream(s, 0);
  38. if (!st)
  39. return AVERROR(ENOMEM);
  40. st->codec->codec_type = CODEC_TYPE_VIDEO;
  41. st->codec->codec_id = CODEC_ID_TXD;
  42. st->codec->time_base.den = 5;
  43. st->codec->time_base.num = 1;
  44. /* the parameters will be extracted from the compressed bitstream */
  45. return 0;
  46. }
  47. static int txd_read_packet(AVFormatContext *s, AVPacket *pkt) {
  48. ByteIOContext *pb = &s->pb;
  49. unsigned int id, chunk_size, marker;
  50. int ret;
  51. next_chunk:
  52. id = get_le32(pb);
  53. chunk_size = get_le32(pb);
  54. marker = get_le32(pb);
  55. if (url_feof(&s->pb))
  56. return AVERROR(EIO);
  57. if (marker != TXD_MARKER && marker != TXD_MARKER2) {
  58. av_log(NULL, AV_LOG_ERROR, "marker does not match\n");
  59. return AVERROR(EIO);
  60. }
  61. switch (id) {
  62. case TXD_INFO:
  63. if (chunk_size > 100)
  64. break;
  65. case TXD_EXTRA:
  66. url_fskip(&s->pb, chunk_size);
  67. case TXD_FILE:
  68. case TXD_TEXTURE:
  69. goto next_chunk;
  70. default:
  71. av_log(NULL, AV_LOG_ERROR, "unknown chunk id %i\n", id);
  72. return AVERROR(EIO);
  73. }
  74. ret = av_get_packet(&s->pb, pkt, chunk_size);
  75. pkt->stream_index = 0;
  76. return ret <= 0 ? AVERROR(EIO) : ret;
  77. }
  78. static int txd_read_close(AVFormatContext *s) {
  79. return 0;
  80. }
  81. AVInputFormat txd_demuxer =
  82. {
  83. "txd",
  84. "txd format",
  85. 0,
  86. txd_probe,
  87. txd_read_header,
  88. txd_read_packet,
  89. txd_read_close,
  90. };