frwu.c
Go to the documentation of this file.
1 /*
2  * Forward Uncompressed
3  *
4  * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "avcodec.h"
24 #include "bytestream.h"
25 #include "internal.h"
26 #include "libavutil/opt.h"
27 
28 typedef struct {
31 } FRWUContext;
32 
34 {
35  if (avctx->width & 1) {
36  av_log(avctx, AV_LOG_ERROR, "frwu needs even width\n");
37  return AVERROR(EINVAL);
38  }
39  avctx->pix_fmt = AV_PIX_FMT_UYVY422;
40 
41  return 0;
42 }
43 
44 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
45  AVPacket *avpkt)
46 {
47  FRWUContext *s = avctx->priv_data;
48  int field, ret;
49  AVFrame *pic = data;
50  const uint8_t *buf = avpkt->data;
51  const uint8_t *buf_end = buf + avpkt->size;
52 
53  if (avpkt->size < avctx->width * 2 * avctx->height + 4 + 2*8) {
54  av_log(avctx, AV_LOG_ERROR, "Packet is too small.\n");
55  return AVERROR_INVALIDDATA;
56  }
57  if (bytestream_get_le32(&buf) != MKTAG('F', 'R', 'W', '1')) {
58  av_log(avctx, AV_LOG_ERROR, "incorrect marker\n");
59  return AVERROR_INVALIDDATA;
60  }
61 
62  if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
63  return ret;
64 
66  pic->key_frame = 1;
67 
68  for (field = 0; field < 2; field++) {
69  int i;
70  int field_h = (avctx->height + !field) >> 1;
71  int field_size, min_field_size = avctx->width * 2 * field_h;
72  uint8_t *dst = pic->data[0];
73  if (buf_end - buf < 8)
74  return AVERROR_INVALIDDATA;
75  buf += 4; // flags? 0x80 == bottom field maybe?
76  field_size = bytestream_get_le32(&buf);
77  if (field_size < min_field_size) {
78  av_log(avctx, AV_LOG_ERROR, "Field size %i is too small (required %i)\n", field_size, min_field_size);
79  return AVERROR_INVALIDDATA;
80  }
81  if (buf_end - buf < field_size) {
82  av_log(avctx, AV_LOG_ERROR, "Packet is too small, need %i, have %i\n", field_size, (int)(buf_end - buf));
83  return AVERROR_INVALIDDATA;
84  }
85  if (field ^ s->change_field_order) {
86  dst += pic->linesize[0];
87  } else if (s->change_field_order) {
88  dst += 2 * pic->linesize[0];
89  }
90  for (i = 0; i < field_h; i++) {
91  if (s->change_field_order && field && i == field_h - 1)
92  dst = pic->data[0];
93  memcpy(dst, buf, avctx->width * 2);
94  buf += avctx->width * 2;
95  dst += pic->linesize[0] << 1;
96  }
97  buf += field_size - min_field_size;
98  }
99 
100  *got_frame = 1;
101 
102  return avpkt->size;
103 }
104 
105 static const AVOption frwu_options[] = {
106  {"change_field_order", "Change field order", offsetof(FRWUContext, change_field_order), FF_OPT_TYPE_INT,
108  {NULL}
109 };
110 
111 static const AVClass frwu_class = {
112  .class_name = "frwu Decoder",
113  .item_name = av_default_item_name,
114  .option = frwu_options,
115  .version = LIBAVUTIL_VERSION_INT,
116 };
117 
119  .name = "frwu",
120  .type = AVMEDIA_TYPE_VIDEO,
121  .id = AV_CODEC_ID_FRWU,
122  .priv_data_size = sizeof(FRWUContext),
123  .init = decode_init,
124  .decode = decode_frame,
125  .capabilities = CODEC_CAP_DR1,
126  .long_name = NULL_IF_CONFIG_SMALL("Forward Uncompressed"),
127  .priv_class = &frwu_class,
128 };
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:85
const char * s
Definition: avisynth_c.h:668
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
AVClass * av_class
Definition: frwu.c:29
AVOption.
Definition: opt.h:251
av_default_item_name
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
AVCodec ff_frwu_decoder
Definition: frwu.c:118
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:55
uint8_t
#define av_cold
Definition: attributes.h:78
AVOptions.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
uint8_t * data
static const AVClass frwu_class
Definition: frwu.c:111
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Spectrum Plot time data
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
static av_cold int decode_init(AVCodecContext *avctx)
Definition: frwu.c:33
external API header
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:144
ret
Definition: avfilter.c:821
int width
picture width / height.
static const AVOption frwu_options[]
Definition: frwu.c:105
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
NULL
Definition: eval.c:55
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:285
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
void * buf
Definition: avisynth_c.h:594
Describe the class of an AVClass context structure.
Definition: log.h:50
synthesis window for stochastic i
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:282
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: frwu.c:44
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
common internal api header.
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
int change_field_order
Definition: frwu.c:30
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
#define MKTAG(a, b, c, d)
Definition: common.h:282
This structure stores compressed data.