2009-10-13 20:15:57 +02:00
|
|
|
/*
|
|
|
|
* Forward Uncompressed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
|
|
|
#include "bytestream.h"
|
2012-11-10 13:22:56 +01:00
|
|
|
#include "internal.h"
|
2012-11-25 22:27:32 +01:00
|
|
|
#include "libavutil/opt.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
AVClass *av_class;
|
|
|
|
int change_field_order;
|
|
|
|
} FRWUContext;
|
2009-10-13 20:15:57 +02:00
|
|
|
|
|
|
|
static av_cold int decode_init(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
if (avctx->width & 1) {
|
2011-05-01 00:38:25 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "frwu needs even width\n");
|
2012-02-01 22:05:16 +01:00
|
|
|
return AVERROR(EINVAL);
|
2009-10-13 20:15:57 +02:00
|
|
|
}
|
2012-10-06 12:10:34 +02:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_UYVY422;
|
2009-10-13 20:15:57 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-13 19:35:22 +01:00
|
|
|
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
2009-10-13 20:15:57 +02:00
|
|
|
AVPacket *avpkt)
|
|
|
|
{
|
2012-11-25 22:27:32 +01:00
|
|
|
FRWUContext *s = avctx->priv_data;
|
2012-02-01 22:05:16 +01:00
|
|
|
int field, ret;
|
2012-11-21 21:34:46 +01:00
|
|
|
AVFrame *pic = data;
|
2009-10-13 20:15:57 +02:00
|
|
|
const uint8_t *buf = avpkt->data;
|
|
|
|
const uint8_t *buf_end = buf + avpkt->size;
|
|
|
|
|
|
|
|
if (avpkt->size < avctx->width * 2 * avctx->height + 4 + 2*8) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Packet is too small.\n");
|
2012-02-01 22:05:16 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-10-13 20:15:57 +02:00
|
|
|
}
|
2012-03-12 19:11:32 +01:00
|
|
|
if (bytestream_get_le32(&buf) != MKTAG('F', 'R', 'W', '1')) {
|
2009-10-13 20:15:57 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "incorrect marker\n");
|
2012-02-01 22:05:16 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-10-13 20:15:57 +02:00
|
|
|
}
|
|
|
|
|
lavc: factorize ff_{thread_,re,}get_buffer error messages.
Coccinelle profile used:
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_get_buffer(ctx, f, flags)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str;
@@
-if ((r = ff_reget_buffer(ctx, f)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_reget_buffer(ctx, f)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0)
+ return r;
...along with some manual patches for the remaining ones.
2013-03-12 08:41:53 +01:00
|
|
|
if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
|
2012-02-01 22:05:16 +01:00
|
|
|
return ret;
|
2009-10-13 20:15:57 +02:00
|
|
|
|
2011-04-28 01:40:44 +02:00
|
|
|
pic->pict_type = AV_PICTURE_TYPE_I;
|
2009-10-13 20:15:57 +02:00
|
|
|
pic->key_frame = 1;
|
|
|
|
|
|
|
|
for (field = 0; field < 2; field++) {
|
|
|
|
int i;
|
|
|
|
int field_h = (avctx->height + !field) >> 1;
|
|
|
|
int field_size, min_field_size = avctx->width * 2 * field_h;
|
|
|
|
uint8_t *dst = pic->data[0];
|
|
|
|
if (buf_end - buf < 8)
|
2012-02-01 22:05:16 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-10-13 20:15:57 +02:00
|
|
|
buf += 4; // flags? 0x80 == bottom field maybe?
|
|
|
|
field_size = bytestream_get_le32(&buf);
|
|
|
|
if (field_size < min_field_size) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Field size %i is too small (required %i)\n", field_size, min_field_size);
|
2012-02-01 22:05:16 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-10-13 20:15:57 +02:00
|
|
|
}
|
|
|
|
if (buf_end - buf < field_size) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Packet is too small, need %i, have %i\n", field_size, (int)(buf_end - buf));
|
2012-02-01 22:05:16 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-10-13 20:15:57 +02:00
|
|
|
}
|
2012-11-25 22:27:32 +01:00
|
|
|
if (field ^ s->change_field_order) {
|
2009-10-13 20:15:57 +02:00
|
|
|
dst += pic->linesize[0];
|
2012-11-25 22:27:32 +01:00
|
|
|
} else if (s->change_field_order) {
|
|
|
|
dst += 2 * pic->linesize[0];
|
|
|
|
}
|
2009-10-13 20:15:57 +02:00
|
|
|
for (i = 0; i < field_h; i++) {
|
2012-11-25 22:27:32 +01:00
|
|
|
if (s->change_field_order && field && i == field_h - 1)
|
|
|
|
dst = pic->data[0];
|
2009-10-13 20:15:57 +02:00
|
|
|
memcpy(dst, buf, avctx->width * 2);
|
|
|
|
buf += avctx->width * 2;
|
|
|
|
dst += pic->linesize[0] << 1;
|
|
|
|
}
|
|
|
|
buf += field_size - min_field_size;
|
|
|
|
}
|
|
|
|
|
2012-11-13 19:35:22 +01:00
|
|
|
*got_frame = 1;
|
2009-10-13 20:15:57 +02:00
|
|
|
|
|
|
|
return avpkt->size;
|
|
|
|
}
|
|
|
|
|
2012-11-25 22:27:32 +01:00
|
|
|
static const AVOption frwu_options[] = {
|
2015-11-21 22:04:39 +01:00
|
|
|
{"change_field_order", "Change field order", offsetof(FRWUContext, change_field_order), AV_OPT_TYPE_BOOL,
|
2012-11-25 22:27:32 +01:00
|
|
|
{.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM},
|
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass frwu_class = {
|
|
|
|
.class_name = "frwu Decoder",
|
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = frwu_options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
2011-01-25 22:40:11 +01:00
|
|
|
AVCodec ff_frwu_decoder = {
|
2011-11-09 23:04:22 +01:00
|
|
|
.name = "frwu",
|
2013-10-03 22:57:53 +02:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Forward Uncompressed"),
|
2011-07-17 12:54:31 +02:00
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 11:11:04 +02:00
|
|
|
.id = AV_CODEC_ID_FRWU,
|
2012-11-25 22:27:32 +01:00
|
|
|
.priv_data_size = sizeof(FRWUContext),
|
2011-07-17 12:54:31 +02:00
|
|
|
.init = decode_init,
|
|
|
|
.decode = decode_frame,
|
2015-07-07 02:41:27 +02:00
|
|
|
.capabilities = AV_CODEC_CAP_DR1,
|
2012-11-25 22:27:32 +01:00
|
|
|
.priv_class = &frwu_class,
|
2009-10-13 20:15:57 +02:00
|
|
|
};
|