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.

102 lines
2.9KB

  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. #include "internal.h"
  24. #define TXD_FILE 0x16
  25. #define TXD_INFO 0x01
  26. #define TXD_EXTRA 0x03
  27. #define TXD_TEXTURE 0x15
  28. #define TXD_TEXTURE_DATA 0x01
  29. #define TXD_MARKER 0x1803ffff
  30. #define TXD_MARKER2 0x1003ffff
  31. static int txd_probe(AVProbeData * pd) {
  32. if (AV_RL32(pd->buf ) == TXD_FILE &&
  33. (AV_RL32(pd->buf+8) == TXD_MARKER || AV_RL32(pd->buf+8) == TXD_MARKER2))
  34. return AVPROBE_SCORE_MAX;
  35. return 0;
  36. }
  37. static int txd_read_header(AVFormatContext *s) {
  38. AVStream *st;
  39. st = avformat_new_stream(s, NULL);
  40. if (!st)
  41. return AVERROR(ENOMEM);
  42. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  43. st->codec->codec_id = AV_CODEC_ID_TXD;
  44. avpriv_set_pts_info(st, 64, 1, 5);
  45. st->avg_frame_rate = av_inv_q(st->time_base);
  46. /* the parameters will be extracted from the compressed bitstream */
  47. return 0;
  48. }
  49. static int txd_read_packet(AVFormatContext *s, AVPacket *pkt) {
  50. AVIOContext *pb = s->pb;
  51. unsigned int id, chunk_size, marker;
  52. int ret;
  53. next_chunk:
  54. id = avio_rl32(pb);
  55. chunk_size = avio_rl32(pb);
  56. marker = avio_rl32(pb);
  57. if (url_feof(s->pb))
  58. return AVERROR_EOF;
  59. if (marker != TXD_MARKER && marker != TXD_MARKER2) {
  60. av_log(s, AV_LOG_ERROR, "marker does not match\n");
  61. return AVERROR_INVALIDDATA;
  62. }
  63. switch (id) {
  64. case TXD_INFO:
  65. if (chunk_size > 100)
  66. break;
  67. case TXD_EXTRA:
  68. avio_skip(s->pb, chunk_size);
  69. case TXD_FILE:
  70. case TXD_TEXTURE:
  71. goto next_chunk;
  72. default:
  73. av_log(s, AV_LOG_ERROR, "unknown chunk id %i\n", id);
  74. return AVERROR_INVALIDDATA;
  75. }
  76. ret = av_get_packet(s->pb, pkt, chunk_size);
  77. if (ret < 0)
  78. return ret;
  79. pkt->stream_index = 0;
  80. return 0;
  81. }
  82. AVInputFormat ff_txd_demuxer = {
  83. .name = "txd",
  84. .long_name = NULL_IF_CONFIG_SMALL("Renderware TeXture Dictionary"),
  85. .read_probe = txd_probe,
  86. .read_header = txd_read_header,
  87. .read_packet = txd_read_packet,
  88. };