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
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  */
22 /**
23  * @file
24  * Megalux Frame demuxer
25  */
27 #include "libavcodec/raw.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/intreadwrite.h"
30 #include "avformat.h"
32 static const enum AVPixelFormat frm_pix_fmt_tags[] = {
38 };
40 typedef struct {
41  int count;
42 } FrmContext;
44 static int frm_read_probe(const AVProbeData *p)
45 {
46  if (p->buf_size > 8 &&
47  p->buf[0] == 'F' && p->buf[1] == 'R' && p->buf[2] == 'M' &&
48  AV_RL16(&p->buf[4]) && AV_RL16(&p->buf[6]))
49  return AVPROBE_SCORE_MAX / 4;
50  return 0;
51 }
53 static int frm_read_header(AVFormatContext *avctx)
54 {
55  AVIOContext *pb = avctx->pb;
56  AVStream *st = avformat_new_stream(avctx, 0);
57  unsigned idx;
59  if (!st)
60  return AVERROR(ENOMEM);
64  avio_skip(pb, 3);
66  idx = avio_r8(pb) - 1;
67  if (idx >= FF_ARRAY_ELEMS(frm_pix_fmt_tags))
69  st->codecpar->format = frm_pix_fmt_tags[idx];
71  st->codecpar->codec_tag = 0;
72  st->codecpar->width = avio_rl16(pb);
73  st->codecpar->height = avio_rl16(pb);
74  return 0;
75 }
78 {
79  FrmContext *s = avctx->priv_data;
80  AVCodecParameters *par = avctx->streams[0]->codecpar;
81  int packet_size, ret;
83  if (s->count)
84  return AVERROR_EOF;
86  packet_size = av_image_get_buffer_size(par->format, par->width, par->height, 1);
87  if (packet_size < 0)
90  ret = av_get_packet(avctx->pb, pkt, packet_size);
91  if (ret < 0)
92  return ret;
94  if (par->format == AV_PIX_FMT_BGRA) {
95  int i;
96  for (i = 3; i + 1 <= pkt->size; i += 4)
97  pkt->data[i] = 0xFF - pkt->data[i];
98  }
100  pkt->stream_index = 0;
101  s->count++;
103  return 0;
104 }
107  .name = "frm",
108  .priv_data_size = sizeof(FrmContext),
109  .long_name = NULL_IF_CONFIG_SMALL("Megalux Frame"),
110  .read_probe = frm_read_probe,
111  .read_header = frm_read_header,
112  .read_packet = frm_read_packet,
113 };
Bytestream IO Context.
Definition: avio.h:161
Invalid data found when processing input.
Definition: error.h:59
static int frm_read_header(AVFormatContext *avctx)
Definition: frmdec.c:53
misc image utilities
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
int size
Definition: packet.h:370
static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition: frmdec.c:77
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:337
#define FF_ARRAY_ELEMS(a)
AVPacket * pkt
Definition: movenc.c:59
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:91
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
Format I/O context.
Definition: avformat.h:1247
int width
Video only.
Definition: codec_par.h:126
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4553
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1315
uint8_t * data
Definition: packet.h:369
End of file.
Definition: error.h:55
static enum AVPixelFormat frm_pix_fmt_tags[]
Definition: frmdec.c:32
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:310
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
Definition: imgutils.c:466
static int frm_read_probe(const AVProbeData *p)
Definition: frmdec.c:44
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:117
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:624
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:444
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:443
Raw Video Codec.
#define s(width, name)
Definition: cbs_vp9.c:257
Stream structure.
Definition: avformat.h:884
AVIOContext * pb
I/O context.
Definition: avformat.h:1289
AVInputFormat ff_frm_demuxer
Definition: frmdec.c:106
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
This structure contains the data a format has to probe a file.
Definition: avformat.h:441
maximum score
Definition: avformat.h:453
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:734
Main libavformat public API header.
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:387
void * priv_data
Format private data.
Definition: avformat.h:1275
int count
Definition: frmdec.c:41
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:654
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1049
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:64
int stream_index
Definition: packet.h:371
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: packet.h:346
int i
Definition: input.c:407