Libav
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 Libav.
7  *
8  * Libav 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  * Libav 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 Libav; 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 
28 {
29  if (avctx->width & 1) {
30  av_log(avctx, AV_LOG_ERROR, "frwu needs even width\n");
31  return AVERROR(EINVAL);
32  }
33  avctx->pix_fmt = AV_PIX_FMT_UYVY422;
34 
35  return 0;
36 }
37 
38 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
39  AVPacket *avpkt)
40 {
41  int field, ret;
42  AVFrame *pic = data;
43  const uint8_t *buf = avpkt->data;
44  const uint8_t *buf_end = buf + avpkt->size;
45 
46  if (avpkt->size < avctx->width * 2 * avctx->height + 4 + 2*8) {
47  av_log(avctx, AV_LOG_ERROR, "Packet is too small.\n");
48  return AVERROR_INVALIDDATA;
49  }
50  if (bytestream_get_le32(&buf) != MKTAG('F', 'R', 'W', '1')) {
51  av_log(avctx, AV_LOG_ERROR, "incorrect marker\n");
52  return AVERROR_INVALIDDATA;
53  }
54 
55  if ((ret = ff_get_buffer(avctx, pic, 0)) < 0) {
56  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
57  return ret;
58  }
59 
61  pic->key_frame = 1;
62  pic->interlaced_frame = 1;
63  pic->top_field_first = 1;
64 
65  for (field = 0; field < 2; field++) {
66  int i;
67  int field_h = (avctx->height + !field) >> 1;
68  int field_size, min_field_size = avctx->width * 2 * field_h;
69  uint8_t *dst = pic->data[0];
70  if (buf_end - buf < 8)
71  return AVERROR_INVALIDDATA;
72  buf += 4; // flags? 0x80 == bottom field maybe?
73  field_size = bytestream_get_le32(&buf);
74  if (field_size < min_field_size) {
75  av_log(avctx, AV_LOG_ERROR, "Field size %i is too small (required %i)\n", field_size, min_field_size);
76  return AVERROR_INVALIDDATA;
77  }
78  if (buf_end - buf < field_size) {
79  av_log(avctx, AV_LOG_ERROR, "Packet is too small, need %i, have %i\n", field_size, (int)(buf_end - buf));
80  return AVERROR_INVALIDDATA;
81  }
82  if (field)
83  dst += pic->linesize[0];
84  for (i = 0; i < field_h; i++) {
85  memcpy(dst, buf, avctx->width * 2);
86  buf += avctx->width * 2;
87  dst += pic->linesize[0] << 1;
88  }
89  buf += field_size - min_field_size;
90  }
91 
92  *got_frame = 1;
93 
94  return avpkt->size;
95 }
96 
98  .name = "frwu",
99  .long_name = NULL_IF_CONFIG_SMALL("Forward Uncompressed"),
100  .type = AVMEDIA_TYPE_VIDEO,
101  .id = AV_CODEC_ID_FRWU,
102  .init = decode_init,
103  .decode = decode_frame,
104  .capabilities = CODEC_CAP_DR1,
105 };
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:84
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
This structure describes decoded (raw) audio or video data.
Definition: frame.h:107
int size
Definition: avcodec.h:974
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1247
AVCodec.
Definition: avcodec.h:2755
AVCodec ff_frwu_decoder
Definition: frwu.c:97
uint8_t
#define av_cold
Definition: attributes.h:66
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:711
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:973
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:292
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
const char * name
Name of the codec implementation.
Definition: avcodec.h:2762
static av_cold int decode_init(AVCodecContext *avctx)
Definition: frwu.c:27
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:168
int width
picture width / height.
Definition: avcodec.h:1217
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:125
main external API structure.
Definition: avcodec.h:1054
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:575
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: frwu.c:38
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:113
common internal api header.
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:297
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:163
#define MKTAG(a, b, c, d)
Definition: common.h:238
This structure stores compressed data.
Definition: avcodec.h:950