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. * Megalux Frame demuxer
  3. * Copyright (c) 2010 Peter Ross <pross@xvid.org>
  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. /**
  22. * @file
  23. * Megalux Frame demuxer
  24. */
  25. #include "libavutil/intreadwrite.h"
  26. #include "avformat.h"
  27. #include "riff.h"
  28. static const AVCodecTag frm_pix_fmt_tags[] = {
  29. { PIX_FMT_RGB555, 1 },
  30. { PIX_FMT_BGR32, 2 },
  31. { PIX_FMT_RGB24, 3 },
  32. { PIX_FMT_BGR0, 4 },
  33. { PIX_FMT_BGR0, 5 },
  34. };
  35. typedef struct {
  36. int count;
  37. } FrmContext;
  38. static int frm_read_probe(AVProbeData *p)
  39. {
  40. if (p->buf_size > 8 &&
  41. p->buf[0] == 'F' && p->buf[1] == 'R' && p->buf[2] == 'M' &&
  42. AV_RL16(&p->buf[4]) && AV_RL16(&p->buf[6]))
  43. return AVPROBE_SCORE_MAX / 4;
  44. return 0;
  45. }
  46. static int frm_read_header(AVFormatContext *avctx)
  47. {
  48. AVIOContext *pb = avctx->pb;
  49. AVStream *st = avformat_new_stream(avctx, 0);
  50. if (!st)
  51. return AVERROR(ENOMEM);
  52. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  53. st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
  54. avio_skip(pb, 3);
  55. st->codec->pix_fmt = ff_codec_get_id(frm_pix_fmt_tags, avio_r8(pb));
  56. if (!st->codec->pix_fmt)
  57. return AVERROR_INVALIDDATA;
  58. st->codec->codec_tag = 0;
  59. st->codec->width = avio_rl16(pb);
  60. st->codec->height = avio_rl16(pb);
  61. return 0;
  62. }
  63. static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt)
  64. {
  65. FrmContext *s = avctx->priv_data;
  66. AVCodecContext *stc = avctx->streams[0]->codec;
  67. int packet_size, ret;
  68. if (s->count)
  69. return AVERROR_EOF;
  70. packet_size = avpicture_get_size(stc->pix_fmt, stc->width, stc->height);
  71. if (packet_size < 0)
  72. return AVERROR_INVALIDDATA;
  73. ret = av_get_packet(avctx->pb, pkt, packet_size);
  74. if (ret < 0)
  75. return ret;
  76. pkt->stream_index = 0;
  77. s->count++;
  78. return 0;
  79. }
  80. AVInputFormat ff_frm_demuxer = {
  81. .name = "frm",
  82. .priv_data_size = sizeof(FrmContext),
  83. .long_name = NULL_IF_CONFIG_SMALL("Megalux Frame"),
  84. .read_probe = frm_read_probe,
  85. .read_header = frm_read_header,
  86. .read_packet = frm_read_packet,
  87. };