[FFmpeg-devel] [PATCH] v210 decoder
Reimar Döffinger
Reimar.Doeffinger
Tue Feb 17 18:26:01 CET 2009
Hello,
this is a decoder for
http://samples.mplayerhq.hu/V-codecs/v210/v210_720p.avi
it is not actually a proper codec, it is just little-endian
UYVY with 10 bits per component and aligned to 32 bit every 3
components.
The last part makes it a bit awkward to deal with, which is also the
reason why a favour a decoder instead of adding a pixfmt, IMHO if
we want to support 10-bit pixfmts the planar or 444 variants would
be enough and less painful to do...
-------------- next part --------------
Index: libavcodec/v210.c
===================================================================
--- libavcodec/v210.c (revision 0)
+++ libavcodec/v210.c (revision 0)
@@ -0,0 +1,109 @@
+/*
+ * v210 (10 bit 4:2:2 YUV) decoder
+ * Copyright (c) 2009 Reimar Doeffinger
+ *
+ * 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"
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+ const uint8_t *buf, int buf_size) {
+ int x, y;
+ AVFrame *picture = data;
+ AVFrame *pic = avctx->priv_data;
+ uint8_t *dst_line = pic->data[0];
+ const uint8_t *src_line = buf;
+ int src_linesize = (avctx->width + 5) / 6 * 16;
+ src_linesize = (src_linesize + 63) & ~63;
+ if (buf_size < src_linesize * avctx->height) {
+ av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
+ return -1;
+ }
+
+ for (y = 0; y < avctx->height; y++) {
+ const uint8_t *src = src_line;
+ uint64_t val;
+ for (x = 0; x < avctx->width - 5; x += 6) {
+ val = bytestream_get_le64(&src);
+ dst_line[2 * x + 0] = val >> 2;
+ dst_line[2 * x + 1] = val >> 12;
+ dst_line[2 * x + 2] = val >> 22;
+ dst_line[2 * x + 3] = val >> 34;
+ dst_line[2 * x + 4] = val >> 44;
+ dst_line[2 * x + 5] = val >> 54;
+ val = bytestream_get_le64(&src);
+ dst_line[2 * x + 6] = val >> 2;
+ dst_line[2 * x + 7] = val >> 12;
+ dst_line[2 * x + 8] = val >> 22;
+ dst_line[2 * x + 9] = val >> 34;
+ dst_line[2 * x + 10] = val >> 44;
+ dst_line[2 * x + 11] = val >> 54;
+ }
+ if (x < avctx->width - 1) {
+ val = bytestream_get_le64(&src);
+ dst_line[2 * x + 0] = val >> 2;
+ dst_line[2 * x + 1] = val >> 12;
+ dst_line[2 * x + 2] = val >> 22;
+ dst_line[2 * x + 3] = val >> 34;
+ }
+ if (x < avctx->width - 3) {
+ dst_line[2 * x + 4] = val >> 44;
+ dst_line[2 * x + 5] = val >> 54;
+ val = bytestream_get_le64(&src);
+ dst_line[2 * x + 6] = val >> 2;
+ dst_line[2 * x + 7] = val >> 12;
+ }
+ src_line += src_linesize;
+ dst_line += pic->linesize[0];
+ }
+
+ *picture = *pic;
+ *data_size = sizeof(AVFrame);
+ return src_line - buf;
+}
+
+static av_cold int decode_init(AVCodecContext *avctx) {
+ AVFrame *pic = avctx->priv_data;
+ if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0)
+ return 1;
+ avctx->pix_fmt = PIX_FMT_UYVY422;
+ if (avctx->get_buffer(avctx, pic) < 0)
+ return 1;
+ pic->pict_type = FF_I_TYPE;
+ pic->key_frame = 1;
+ return 0;
+}
+
+static av_cold int decode_end(AVCodecContext *avctx) {
+ avctx->release_buffer(avctx, avctx->priv_data);
+ return 0;
+}
+
+AVCodec v210_decoder = {
+ "v210",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_V210,
+ sizeof(AVFrame),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("v210 10 bit 4:2:2 YUV"),
+};
+
Index: libavcodec/Makefile
===================================================================
--- libavcodec/Makefile (revision 17393)
+++ libavcodec/Makefile (working copy)
@@ -219,6 +219,7 @@
OBJS-$(CONFIG_TTA_DECODER) += tta.o
OBJS-$(CONFIG_TXD_DECODER) += txd.o s3tc.o
OBJS-$(CONFIG_ULTI_DECODER) += ulti.o
+OBJS-$(CONFIG_V210_DECODER) += v210.o
OBJS-$(CONFIG_VB_DECODER) += vb.o
OBJS-$(CONFIG_VC1_DECODER) += vc1.o vc1data.o vc1dsp.o msmpeg4data.o h263dec.o h263.o intrax8.o intrax8dsp.o error_resilience.o mpegvideo.o
OBJS-$(CONFIG_VC1_VDPAU_DECODER) += vdpau.o vc1.o vc1data.o vc1dsp.o msmpeg4data.o h263dec.o h263.o intrax8.o intrax8dsp.o error_resilience.o mpegvideo.o
Index: libavcodec/allcodecs.c
===================================================================
--- libavcodec/allcodecs.c (revision 17393)
+++ libavcodec/allcodecs.c (working copy)
@@ -156,6 +156,7 @@
REGISTER_DECODER (TSCC, tscc);
REGISTER_DECODER (TXD, txd);
REGISTER_DECODER (ULTI, ulti);
+ REGISTER_DECODER (V210, v210);
REGISTER_DECODER (VB, vb);
REGISTER_DECODER (VC1, vc1);
REGISTER_DECODER (VC1_VDPAU, vc1_vdpau);
Index: libavcodec/avcodec.h
===================================================================
--- libavcodec/avcodec.h (revision 17393)
+++ libavcodec/avcodec.h (working copy)
@@ -191,6 +191,7 @@
CODEC_ID_TGV,
CODEC_ID_TGQ,
CODEC_ID_TQI,
+ CODEC_ID_V210,
/* various PCM "codecs" */
CODEC_ID_PCM_S16LE= 0x10000,
Index: libavformat/riff.c
===================================================================
--- libavformat/riff.c (revision 17393)
+++ libavformat/riff.c (working copy)
@@ -200,6 +200,7 @@
{ CODEC_ID_RPZA, MKTAG('R', 'P', 'Z', 'A') },
{ CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') },
{ CODEC_ID_SP5X, MKTAG('S', 'P', '5', '4') },
+ { CODEC_ID_V210, MKTAG('v', '2', '1', '0') },
{ CODEC_ID_NONE, 0 }
};
More information about the ffmpeg-devel
mailing list