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 
36  if (!avctx->coded_frame)
37  return AVERROR(ENOMEM);
38 
39  return 0;
40 }
41 
42 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
43  AVPacket *avpkt)
44 {
45  int field, ret;
46  AVFrame *pic = avctx->coded_frame;
47  const uint8_t *buf = avpkt->data;
48  const uint8_t *buf_end = buf + avpkt->size;
49 
50  if (pic->data[0])
51  avctx->release_buffer(avctx, pic);
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  pic->reference = 0;
63  if ((ret = ff_get_buffer(avctx, pic)) < 0) {
64  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
65  return ret;
66  }
67 
69  pic->key_frame = 1;
70  pic->interlaced_frame = 1;
71  pic->top_field_first = 1;
72 
73  for (field = 0; field < 2; field++) {
74  int i;
75  int field_h = (avctx->height + !field) >> 1;
76  int field_size, min_field_size = avctx->width * 2 * field_h;
77  uint8_t *dst = pic->data[0];
78  if (buf_end - buf < 8)
79  return AVERROR_INVALIDDATA;
80  buf += 4; // flags? 0x80 == bottom field maybe?
81  field_size = bytestream_get_le32(&buf);
82  if (field_size < min_field_size) {
83  av_log(avctx, AV_LOG_ERROR, "Field size %i is too small (required %i)\n", field_size, min_field_size);
84  return AVERROR_INVALIDDATA;
85  }
86  if (buf_end - buf < field_size) {
87  av_log(avctx, AV_LOG_ERROR, "Packet is too small, need %i, have %i\n", field_size, (int)(buf_end - buf));
88  return AVERROR_INVALIDDATA;
89  }
90  if (field)
91  dst += pic->linesize[0];
92  for (i = 0; i < field_h; i++) {
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  *(AVFrame*)data = *pic;
102 
103  return avpkt->size;
104 }
105 
107 {
108  AVFrame *pic = avctx->coded_frame;
109  if (pic->data[0])
110  avctx->release_buffer(avctx, pic);
111  av_freep(&avctx->coded_frame);
112 
113  return 0;
114 }
115 
117  .name = "frwu",
118  .type = AVMEDIA_TYPE_VIDEO,
119  .id = AV_CODEC_ID_FRWU,
120  .init = decode_init,
121  .close = decode_close,
122  .decode = decode_frame,
123  .capabilities = CODEC_CAP_DR1,
124  .long_name = NULL_IF_CONFIG_SMALL("Forward Uncompressed"),
125 };
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:82
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:2259
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
static av_cold int decode_close(AVCodecContext *avctx)
Definition: frwu.c:106
int size
Definition: avcodec.h:916
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
AVCodec.
Definition: avcodec.h:2960
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:151
AVCodec ff_frwu_decoder
Definition: frwu.c:116
uint8_t
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:915
int interlaced_frame
The content of the picture is interlaced.
Definition: avcodec.h:1232
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
Definition: avcodec.h:1132
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
static av_cold int decode_init(AVCodecContext *avctx)
Definition: frwu.c:27
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
Definition: utils.c:616
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
Definition: avcodec.h:1065
int width
picture width / height.
Definition: avcodec.h:1508
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
external API header
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
main external API structure.
Definition: avcodec.h:1339
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: frwu.c:42
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
common internal api header.
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: avcodec.h:1239
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1058
This structure stores compressed data.
Definition: avcodec.h:898