FFmpeg
Loading...
Searching...
No Matches
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 "codec_internal.h"
26#include "decode.h"
27#include "libavutil/opt.h"
28
33
35{
36 if (avctx->width & 1) {
37 av_log(avctx, AV_LOG_ERROR, "frwu needs even width\n");
38 return AVERROR(EINVAL);
39 }
41
42 return 0;
43}
44
45static int decode_frame(AVCodecContext *avctx, AVFrame *pic,
46 int *got_frame, AVPacket *avpkt)
47{
48 FRWUContext *s = avctx->priv_data;
49 int field, ret;
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");
56 }
57 if (bytestream_get_le32(&buf) != MKTAG('F', 'R', 'W', '1')) {
58 av_log(avctx, AV_LOG_ERROR, "incorrect marker\n");
60 }
61
62 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
63 return ret;
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)
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);
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));
81 }
82 if (field ^ s->change_field_order) {
83 dst += pic->linesize[0];
84 } else if (s->change_field_order) {
85 dst += 2 * pic->linesize[0];
86 }
87 for (i = 0; i < field_h; i++) {
88 if (s->change_field_order && field && i == field_h - 1)
89 dst = pic->data[0];
90 memcpy(dst, buf, avctx->width * 2);
91 buf += avctx->width * 2;
92 dst += pic->linesize[0] << 1;
93 }
94 buf += field_size - min_field_size;
95 }
96
97 *got_frame = 1;
98
99 return avpkt->size;
100}
101
102static const AVOption frwu_options[] = {
103 {"change_field_order", "Change field order", offsetof(FRWUContext, change_field_order), AV_OPT_TYPE_BOOL,
105 {NULL}
106};
107
108static const AVClass frwu_class = {
109 .class_name = "frwu Decoder",
110 .item_name = av_default_item_name,
111 .option = frwu_options,
112 .version = LIBAVUTIL_VERSION_INT,
113};
114
116 .p.name = "frwu",
117 CODEC_LONG_NAME("Forward Uncompressed"),
118 .p.type = AVMEDIA_TYPE_VIDEO,
119 .p.id = AV_CODEC_ID_FRWU,
120 .priv_data_size = sizeof(FRWUContext),
121 .init = decode_init,
123 .p.capabilities = AV_CODEC_CAP_DR1,
124 .p.priv_class = &frwu_class,
125};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
const FFCodec ff_frwu_decoder
Definition frwu.c:115
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define NULL
Definition coverity.c:32
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1777
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static av_cold int decode_init(AVCodecContext *avctx)
Definition frwu.c:34
static int decode_frame(AVCodecContext *avctx, AVFrame *pic, int *got_frame, AVPacket *avpkt)
Definition frwu.c:45
static const AVClass frwu_class
Definition frwu.c:108
static const AVOption frwu_options[]
Definition frwu.c:102
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
#define AV_OPT_FLAG_VIDEO_PARAM
Definition opt.h:357
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_FRWU
Definition codec_id.h:180
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static av_cold int decode_init(AVCodecContext *avctx)
Definition 4xm.c:998
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition 4xm.c:837
#define av_cold
Definition attributes.h:117
#define MKTAG(a, b, c, d)
Definition macros.h:55
AVOptions.
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition pixfmt.h:88
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int width
picture width / height.
Definition avcodec.h:604
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
AVClass * av_class
Definition frwu.c:30
int change_field_order
Definition frwu.c:31
#define av_log(a,...)