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. * Metar Gear Solid: The Twin Snakes demuxer
  3. * Copyright (c) 2012 Paul B Mahol
  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 "libavutil/intfloat.h"
  23. #include "avformat.h"
  24. #include "riff.h"
  25. static int read_probe(AVProbeData *p)
  26. {
  27. if (AV_RB32(p->buf ) != 0x000E ||
  28. AV_RB32(p->buf + 4) != 0x0050 ||
  29. AV_RB32(p->buf + 12) != 0x0034)
  30. return 0;
  31. return AVPROBE_SCORE_MAX;
  32. }
  33. static int read_header(AVFormatContext *s)
  34. {
  35. AVIOContext *pb = s->pb;
  36. AVStream *st;
  37. AVRational fps;
  38. uint32_t chunk_size;
  39. avio_skip(pb, 4);
  40. chunk_size = avio_rb32(pb);
  41. if (chunk_size != 80)
  42. return AVERROR(EIO);
  43. avio_skip(pb, 20);
  44. st = avformat_new_stream(s, 0);
  45. if (!st)
  46. return AVERROR(ENOMEM);
  47. st->start_time = 0;
  48. st->nb_frames =
  49. st->duration = avio_rb32(pb);
  50. fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX);
  51. st->codec->width = avio_rb32(pb);
  52. st->codec->height = avio_rb32(pb);
  53. avio_skip(pb, 12);
  54. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  55. st->codec->codec_tag = avio_rb32(pb);
  56. st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
  57. st->codec->codec_tag);
  58. avpriv_set_pts_info(st, 64, fps.den, fps.num);
  59. avio_skip(pb, 20);
  60. return 0;
  61. }
  62. static int read_packet(AVFormatContext *s, AVPacket *pkt)
  63. {
  64. AVIOContext *pb = s->pb;
  65. uint32_t chunk_size, payload_size;
  66. int ret;
  67. if (url_feof(pb))
  68. return AVERROR_EOF;
  69. avio_skip(pb, 4);
  70. chunk_size = avio_rb32(pb);
  71. avio_skip(pb, 4);
  72. payload_size = avio_rb32(pb);
  73. if (chunk_size < payload_size + 16)
  74. return AVERROR(EIO);
  75. ret = av_get_packet(pb, pkt, payload_size);
  76. if (ret < 0)
  77. return ret;
  78. pkt->duration = 1;
  79. avio_skip(pb, chunk_size - (ret + 16));
  80. return ret;
  81. }
  82. AVInputFormat ff_mgsts_demuxer = {
  83. .name = "mgsts",
  84. .long_name = NULL_IF_CONFIG_SMALL("Metal Gear Solid: The Twin Snakes"),
  85. .read_probe = read_probe,
  86. .read_header = read_header,
  87. .read_packet = read_packet,
  88. };