FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
frmdec.c
Go to the documentation of this file.
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 /**
23  * @file
24  * Megalux Frame demuxer
25  */
26 
27 #include "libavutil/intreadwrite.h"
28 #include "avformat.h"
29 #include "riff.h"
30 
31 static const AVCodecTag frm_pix_fmt_tags[] = {
32  { PIX_FMT_RGB555, 1 },
33  { PIX_FMT_BGR32, 2 },
34  { PIX_FMT_RGB24, 3 },
35  { PIX_FMT_BGR0, 4 },
36  { PIX_FMT_BGR0, 5 },
37 };
38 
39 typedef struct {
40  int count;
41 } FrmContext;
42 
44 {
45  if (p->buf_size > 8 &&
46  p->buf[0] == 'F' && p->buf[1] == 'R' && p->buf[2] == 'M' &&
47  AV_RL16(&p->buf[4]) && AV_RL16(&p->buf[6]))
48  return AVPROBE_SCORE_MAX / 4;
49  return 0;
50 }
51 
52 static int frm_read_header(AVFormatContext *avctx)
53 {
54  AVIOContext *pb = avctx->pb;
55  AVStream *st = avformat_new_stream(avctx, 0);
56  if (!st)
57  return AVERROR(ENOMEM);
58 
61  avio_skip(pb, 3);
62 
63  st->codec->pix_fmt = ff_codec_get_id(frm_pix_fmt_tags, avio_r8(pb));
64  if (!st->codec->pix_fmt)
65  return AVERROR_INVALIDDATA;
66 
67  st->codec->codec_tag = 0;
68  st->codec->width = avio_rl16(pb);
69  st->codec->height = avio_rl16(pb);
70  return 0;
71 }
72 
74 {
75  FrmContext *s = avctx->priv_data;
76  AVCodecContext *stc = avctx->streams[0]->codec;
77  int packet_size, ret;
78 
79  if (s->count)
80  return AVERROR_EOF;
81 
82  packet_size = avpicture_get_size(stc->pix_fmt, stc->width, stc->height);
83  if (packet_size < 0)
84  return AVERROR_INVALIDDATA;
85 
86  ret = av_get_packet(avctx->pb, pkt, packet_size);
87  if (ret < 0)
88  return ret;
89 
90  pkt->stream_index = 0;
91  s->count++;
92 
93  return 0;
94 }
95 
97  .name = "frm",
98  .priv_data_size = sizeof(FrmContext),
99  .long_name = NULL_IF_CONFIG_SMALL("Megalux Frame"),
100  .read_probe = frm_read_probe,
101  .read_header = frm_read_header,
102  .read_packet = frm_read_packet,
103 };