FFmpeg
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/imgutils.h"
28 #include "libavutil/intreadwrite.h"
29 #include "avformat.h"
30 
31 static const enum AVPixelFormat frm_pix_fmt_tags[] = {
37 };
38 
39 typedef struct {
40  int count;
41 } FrmContext;
42 
43 static int frm_read_probe(const AVProbeData *p)
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  unsigned idx;
57 
58  if (!st)
59  return AVERROR(ENOMEM);
60 
63  avio_skip(pb, 3);
64 
65  idx = avio_r8(pb) - 1;
66  if (idx >= FF_ARRAY_ELEMS(frm_pix_fmt_tags))
67  return AVERROR_INVALIDDATA;
68  st->codecpar->format = frm_pix_fmt_tags[idx];
69 
70  st->codecpar->codec_tag = 0;
71  st->codecpar->width = avio_rl16(pb);
72  st->codecpar->height = avio_rl16(pb);
73  return 0;
74 }
75 
77 {
78  FrmContext *s = avctx->priv_data;
79  AVCodecParameters *par = avctx->streams[0]->codecpar;
80  int packet_size, ret;
81 
82  if (s->count)
83  return AVERROR_EOF;
84 
85  packet_size = av_image_get_buffer_size(par->format, par->width, par->height, 1);
86  if (packet_size < 0)
87  return AVERROR_INVALIDDATA;
88 
89  ret = av_get_packet(avctx->pb, pkt, packet_size);
90  if (ret < 0)
91  return ret;
92 
93  if (par->format == AV_PIX_FMT_BGRA) {
94  int i;
95  for (i = 3; i + 1 <= pkt->size; i += 4)
96  pkt->data[i] = 0xFF - pkt->data[i];
97  }
98 
99  pkt->stream_index = 0;
100  s->count++;
101 
102  return 0;
103 }
104 
106  .name = "frm",
107  .priv_data_size = sizeof(FrmContext),
108  .long_name = NULL_IF_CONFIG_SMALL("Megalux Frame"),
109  .read_probe = frm_read_probe,
110  .read_header = frm_read_header,
111  .read_packet = frm_read_packet,
112 };
FrmContext
Definition: frmdec.c:39
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVERROR
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
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: options.c:237
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:57
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:53
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:63
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1281
AVPacket::data
uint8_t * data
Definition: packet.h:374
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:65
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:456
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:465
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:743
pkt
AVPacket * pkt
Definition: movenc.c:59
AVInputFormat
Definition: avformat.h:656
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
frm_read_probe
static int frm_read_probe(const AVProbeData *p)
Definition: frmdec.c:43
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:661
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:455
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:127
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
ff_frm_demuxer
const AVInputFormat ff_frm_demuxer
Definition: frmdec.c:105
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1108
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1255
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:453
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:230
AVIOContext
Bytestream IO Context.
Definition: avio.h:162
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
AVPacket::size
int size
Definition: packet.h:375
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:632
av_image_get_buffer_size
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
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:228
frm_pix_fmt_tags
static enum AVPixelFormat frm_pix_fmt_tags[]
Definition: frmdec.c:31
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AVCodecParameters::height
int height
Definition: codec_par.h:128
AV_PIX_FMT_RGB555
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:394
av_get_packet
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:102
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:948
avformat.h
frm_read_header
static int frm_read_header(AVFormatContext *avctx)
Definition: frmdec.c:52
frm_read_packet
static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition: frmdec.c:76
AVPacket::stream_index
int stream_index
Definition: packet.h:376
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:347
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FrmContext::count
int count
Definition: frmdec.c:40
AVCodecParameters::format
int format
Definition: codec_par.h:85
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:61
AVPacket
This structure stores compressed data.
Definition: packet.h:351
imgutils.h
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1241