summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>2016-06-22 13:31:32 +0200
committerPaul B Mahol <onemda@gmail.com>2016-06-23 13:04:11 +0200
commita02766fb4d2dc89d0834bade14242cfa810b4646 (patch)
treeedcad5d20fd6c88a493477a029b3fdbc57464f28
parentdccea0ed0d993792b58dab8f232509c62f0522fd (diff)
downloadffmpeg-a02766fb4d2dc89d0834bade14242cfa810b4646.tar.gz
avcodec: remove libutvideo wrapper support
The 10-bit decoding support is available now in native decoder. Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r--Changelog2
-rw-r--r--LICENSE.md2
-rw-r--r--MAINTAINERS1
-rwxr-xr-xconfigure8
-rw-r--r--libavcodec/Makefile3
-rw-r--r--libavcodec/allcodecs.c1
-rw-r--r--libavcodec/libutvideo.h72
-rw-r--r--libavcodec/libutvideodec.cpp279
-rw-r--r--libavcodec/libutvideoenc.cpp281
9 files changed, 2 insertions, 647 deletions
diff --git a/Changelog b/Changelog
index f6016f40ca..aabdf9050a 100644
--- a/Changelog
+++ b/Changelog
@@ -42,6 +42,8 @@ version <next>:
- OpenExr improvements (tile data and B44/B44A support)
- BitJazz SheerVideo decoder
- CUDA CUVID H264/HEVC decoder
+- 10-bit depth support in native utvideo decoder
+- libutvideo wrapper removed
version 3.0:
diff --git a/LICENSE.md b/LICENSE.md
index a70f48625c..d08c747ae5 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -17,7 +17,6 @@ Specifically, the GPL parts of FFmpeg are:
- `libavcodec/x86/flac_dsp_gpl.asm`
- `libavcodec/x86/idct_mmx.c`
- `libavfilter/x86/vf_removegrain.asm`
-- libutvideo encoding/decoding wrappers in `libavcodec/libutvideo*.cpp`
- the X11 grabber in `libavdevice/x11grab.c`
- the following building and testing tools
- `compat/solaris/make_sunver.pl`
@@ -87,7 +86,6 @@ The following libraries are under GPL:
- frei0r
- libcdio
- librubberband
-- libutvideo
- libvidstab
- libx264
- libx265
diff --git a/MAINTAINERS b/MAINTAINERS
index b9fa0c536d..238baa6444 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -204,7 +204,6 @@ Codecs:
libschroedinger* David Conrad
libspeexdec.c Justin Ruggles
libtheoraenc.c David Conrad
- libutvideo* Carl Eugen Hoyos
libvorbis.c David Conrad
libvpx* James Zern
libx264.c Mans Rullgard, Jason Garrett-Glaser
diff --git a/configure b/configure
index e6ebd3bdb8..94a0a6c7a2 100755
--- a/configure
+++ b/configure
@@ -263,7 +263,6 @@ External library support:
--enable-libtesseract enable Tesseract, needed for ocr filter [no]
--enable-libtheora enable Theora encoding via libtheora [no]
--enable-libtwolame enable MP2 encoding via libtwolame [no]
- --enable-libutvideo enable Ut Video encoding and decoding via libutvideo [no]
--enable-libv4l2 enable libv4l2/v4l-utils [no]
--enable-libvidstab enable video stabilization using vid.stab [no]
--enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no]
@@ -1510,7 +1509,6 @@ EXTERNAL_LIBRARY_LIST="
libtesseract
libtheora
libtwolame
- libutvideo
libv4l2
libvidstab
libvo_amrwbenc
@@ -2773,8 +2771,6 @@ libspeex_encoder_deps="libspeex"
libspeex_encoder_select="audio_frame_queue"
libtheora_encoder_deps="libtheora"
libtwolame_encoder_deps="libtwolame"
-libutvideo_decoder_deps="libutvideo"
-libutvideo_encoder_deps="libutvideo"
libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
libvorbis_decoder_deps="libvorbis"
libvorbis_encoder_deps="libvorbis"
@@ -5013,7 +5009,6 @@ die_license_disabled gpl frei0r
die_license_disabled gpl libcdio
die_license_disabled gpl librubberband
die_license_disabled gpl libsmbclient
-die_license_disabled gpl libutvideo
die_license_disabled gpl libvidstab
die_license_disabled gpl libx264
die_license_disabled gpl libx265
@@ -5685,9 +5680,6 @@ enabled libtheora && require libtheora theora/theoraenc.h th_info_init -
enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame &&
{ check_lib twolame.h twolame_encode_buffer_float32_interleaved -ltwolame ||
die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
-enabled libutvideo && { require_cpp utvideo "stdint.h stdlib.h utvideo/utvideo.h utvideo/Codec.h" 'CCodec*' -lutvideo -lstdc++ &&
- check_cpp_condition utvideo/utvideo.h "!defined(UTVIDEO_VERSION_MAJOR) || UTVIDEO_VERSION_MAJOR < 15 || UTVIDEO_VERSION_MAJOR == 15 && UTVIDEO_VERSION_MINOR < 4" ||
- die "ERROR: libutvideo version must be <= 15.3.0."; }
enabled libv4l2 && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
enabled libvidstab && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 7c3aa69590..6ed45aab31 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -880,8 +880,6 @@ OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o
OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o
OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o
OBJS-$(CONFIG_LIBTWOLAME_ENCODER) += libtwolame.o
-OBJS-$(CONFIG_LIBUTVIDEO_DECODER) += libutvideodec.o
-OBJS-$(CONFIG_LIBUTVIDEO_ENCODER) += libutvideoenc.o
OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o
OBJS-$(CONFIG_LIBVORBIS_DECODER) += libvorbisdec.o
OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbisenc.o \
@@ -993,7 +991,6 @@ SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h
SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h
SKIPHEADERS-$(CONFIG_JNI) += ffjni.h
SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h
-SKIPHEADERS-$(CONFIG_LIBUTVIDEO) += libutvideo.h
SKIPHEADERS-$(CONFIG_LIBVPX) += libvpx.h
SKIPHEADERS-$(CONFIG_LIBWEBP_ENCODER) += libwebpenc_common.h
SKIPHEADERS-$(CONFIG_MEDIACODEC) += mediacodecdec.h mediacodec_wrapper.h mediacodec_sw_buffer.h
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 246f08b593..36a0de0906 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -599,7 +599,6 @@ void avcodec_register_all(void)
REGISTER_ENCDEC (LIBSPEEX, libspeex);
REGISTER_ENCODER(LIBTHEORA, libtheora);
REGISTER_ENCODER(LIBTWOLAME, libtwolame);
- REGISTER_ENCDEC (LIBUTVIDEO, libutvideo);
REGISTER_ENCODER(LIBVO_AMRWBENC, libvo_amrwbenc);
REGISTER_ENCDEC (LIBVORBIS, libvorbis);
REGISTER_ENCDEC (LIBVPX_VP8, libvpx_vp8);
diff --git a/libavcodec/libutvideo.h b/libavcodec/libutvideo.h
deleted file mode 100644
index 0c03097bb7..0000000000
--- a/libavcodec/libutvideo.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2011-2012 Derek Buitenhuis
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation;
- * version 2 of the License.
- *
- * 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
- * General Public License for more details.
- *
- * You should have received a copy of the GNU 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
- */
-
-/**
- * @file
- * Known FOURCCs:
- * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA),
- * 'ULH0' (YCbCr 4:2:0 BT.709), 'ULH2' (YCbCr 4:2:2 BT.709)
- */
-
-#ifndef AVCODEC_LIBUTVIDEO_H
-#define AVCODEC_LIBUTVIDEO_H
-
-#include <stdlib.h>
-#include <utvideo/utvideo.h>
-#include <utvideo/Codec.h>
-
-/*
- * Ut Video version 12.0.0 changed the RGB format names and removed
- * the _WIN names, so if the new names are absent, define them
- * against the old names so compatibility with pre-v12 versions
- * is maintained.
- */
-#if !defined(UTVF_NFCC_BGR_BU)
-#define UTVF_NFCC_BGR_BU UTVF_RGB24_WIN
-#endif
-
-#if !defined(UTVF_NFCC_BGRA_BU)
-#define UTVF_NFCC_BGRA_BU UTVF_RGB32_WIN
-#endif
-
-/*
- * Ut Video version 13.0.1 introduced new BT.709 variants.
- * Special-case these and only use them if v13 is detected.
- */
-#if defined(UTVF_HDYC)
-#define UTV_BT709
-#endif
-
-typedef struct {
- uint32_t version;
- uint32_t original_format;
- uint32_t frameinfo_size;
- uint32_t flags;
-} UtVideoExtra;
-
-typedef struct {
- const AVClass *c;
- CCodec *codec;
- unsigned int buf_size;
- uint8_t *buffer;
- int pred;
-} UtVideoContext;
-
-#endif /* AVCODEC_LIBUTVIDEO_H */
diff --git a/libavcodec/libutvideodec.cpp b/libavcodec/libutvideodec.cpp
deleted file mode 100644
index 29e6db16d0..0000000000
--- a/libavcodec/libutvideodec.cpp
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright (c) 2011 Derek Buitenhuis
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation;
- * version 2 of the License.
- *
- * 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
- * General Public License for more details.
- *
- * You should have received a copy of the GNU 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
- */
-
-/**
- * @file
- * Known FOURCCs:
- * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA),
- * 'ULH0' (YCbCr 4:2:0 BT.709), 'ULH2' (YCbCr 4:2:2 BT.709)
- */
-
-extern "C" {
-#include "avcodec.h"
-#include "libavutil/imgutils.h"
-}
-
-#include "libutvideo.h"
-#include "get_bits.h"
-
-static av_cold int utvideo_decode_init(AVCodecContext *avctx)
-{
- UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
- UtVideoExtra info;
- int format;
- int begin_ret;
-
- if (avctx->extradata_size != 16 && avctx->extradata_size != 8 ) {
- av_log(avctx, AV_LOG_ERROR, "Extradata size (%d) mismatch.\n", avctx->extradata_size);
- return -1;
- }
-
- /* Read extradata */
- info.version = AV_RL32(avctx->extradata);
- info.original_format = AV_RL32(avctx->extradata + 4);
- info.frameinfo_size = AV_RL32(avctx->extradata + 8);
- info.flags = AV_RL32(avctx->extradata + 12);
-
- /* Pick format based on FOURCC */
- switch (avctx->codec_tag) {
-#ifdef UTV_BT709
- case MKTAG('U', 'L', 'H', '0'):
- avctx->pix_fmt = AV_PIX_FMT_YUV420P;
- avctx->colorspace = AVCOL_SPC_BT709;
- format = UTVF_YV12;
- break;
- case MKTAG('U', 'L', 'H', '2'):
- avctx->pix_fmt = AV_PIX_FMT_YUYV422;
- avctx->colorspace = AVCOL_SPC_BT709;
- format = UTVF_YUY2;
- break;
-#endif
- case MKTAG('U', 'L', 'Y', '0'):
- avctx->pix_fmt = AV_PIX_FMT_YUV420P;
- format = UTVF_YV12;
- break;
- case MKTAG('U', 'L', 'Y', '2'):
- avctx->pix_fmt = AV_PIX_FMT_YUYV422;
- format = UTVF_YUY2;
- break;
- case MKTAG('U', 'L', 'R', 'G'):
- avctx->pix_fmt = AV_PIX_FMT_BGR24;
- format = UTVF_NFCC_BGR_BU;
- break;
- case MKTAG('U', 'L', 'R', 'A'):
- avctx->pix_fmt = AV_PIX_FMT_RGB32;
- format = UTVF_NFCC_BGRA_BU;
- break;
-#ifdef UTVF_UQY2
- case MKTAG('U', 'Q', 'Y', '2'):
- avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
- format = UTVF_v210;
- break;
-#endif
- default:
- av_log(avctx, AV_LOG_ERROR,
- "Not a Ut Video FOURCC: %X\n", avctx->codec_tag);
- return -1;
- }
-
- /* Only allocate the buffer once */
- utv->buf_size = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
-#ifdef UTVF_UQY2
- if (format == UTVF_v210)
- utv->buf_size += avctx->height * ((avctx->width + 47) / 48) * 128; // the linesize used by the decoder, this does not seem to be exported
-#endif
- utv->buffer = (uint8_t *)av_malloc(utv->buf_size * sizeof(uint8_t));
-
- if (utv->buffer == NULL) {
- av_log(avctx, AV_LOG_ERROR, "Unable to allocate output buffer.\n");
- return -1;
- }
-
- /* Allocate the output frame */
- avctx->coded_frame = av_frame_alloc();
-
- /* Is it interlaced? */
- avctx->coded_frame->interlaced_frame = info.flags & 0x800 ? 1 : 0;
-
- /* Apparently Ut Video doesn't store this info... */
- avctx->coded_frame->top_field_first = 1;
-
- /*
- * Create a Ut Video instance. Since the function wants
- * an "interface name" string, pass it the name of the lib.
- */
- utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec");
-
- /* Initialize Decoding */
- begin_ret = utv->codec->DecodeBegin(format, avctx->width, avctx->height,
- CBGROSSWIDTH_WINDOWS, &info, sizeof(UtVideoExtra));
-
- /* Check to see if the decoder initlized properly */
- if (begin_ret != 0) {
- av_log(avctx, AV_LOG_ERROR,
- "Could not initialize decoder: %d\n", begin_ret);
- return -1;
- }
-
- return 0;
-}
-
-static int utvideo_decode_frame(AVCodecContext *avctx, void *data,
- int *got_frame, AVPacket *avpkt)
-{
- UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
- AVFrame *pic = avctx->coded_frame;
- int w = avctx->width, h = avctx->height;
-
- /* Set flags */
- pic->pict_type = AV_PICTURE_TYPE_I;
- pic->key_frame = 1;
-
- /* Decode the frame */
- utv->codec->DecodeFrame(utv->buffer, avpkt->data, true);
-
- /* Set the output data depending on the colorspace */
- switch (avctx->pix_fmt) {
- case AV_PIX_FMT_YUV420P:
- pic->linesize[0] = w;
- pic->linesize[1] = pic->linesize[2] = w / 2;
- pic->data[0] = utv->buffer;
- pic->data[2] = utv->buffer + (w * h);
- pic->data[1] = pic->data[2] + (w * h / 4);
- break;
- case AV_PIX_FMT_YUYV422:
- pic->linesize[0] = w * 2;
- pic->data[0] = utv->buffer;
- break;
- case AV_PIX_FMT_YUV422P10: {
- uint16_t *y, *u, *v;
- int i,j;
- int linesize = ((w + 47) / 48) * 128;
-
- pic->linesize[0] = w * 2;
- pic->linesize[1] =
- pic->linesize[2] = w;
- pic->data[0] = utv->buffer + linesize * h;
- pic->data[1] = pic->data[0] + h*pic->linesize[0];
- pic->data[2] = pic->data[1] + h*pic->linesize[1];
- y = (uint16_t*)pic->data[0];
- u = (uint16_t*)pic->data[1];
- v = (uint16_t*)pic->data[2];
- for (j = 0; j < h; j++) {
- const uint8_t *in = utv->buffer + j * linesize;
-
- for (i = 0; i + 1 < w; i += 6, in += 4) {
- unsigned a,b;
- a = AV_RL32(in);
- in += 4;
- b = AV_RL32(in);
- *u++ = (a ) & 0x3FF;
- *y++ = (a>>10) & 0x3FF;
- *v++ = (a>>20) & 0x3FF;
- *y++ = (b ) & 0x3FF;
-
- if (i + 3 >= w)
- break;
-
- in += 4;
- a = AV_RL32(in);
- *u++ = (b>>10) & 0x3FF;
- *y++ = (b>>20) & 0x3FF;
- *v++ = (a ) & 0x3FF;
- *y++ = (a>>10) & 0x3FF;
-
- if (i + 5 >= w)
- break;
-
- in += 4;
- b = AV_RL32(in);
- *u++ = (a>>20) & 0x3FF;
- *y++ = (b ) & 0x3FF;
- *v++ = (b>>10) & 0x3FF;
- *y++ = (b>>20) & 0x3FF;
- }
- }
- break;
- }
- case AV_PIX_FMT_BGR24:
- case AV_PIX_FMT_RGB32:
- /* Make the linesize negative, since Ut Video uses bottom-up BGR */
- pic->linesize[0] = -1 * w * (avctx->pix_fmt == AV_PIX_FMT_BGR24 ? 3 : 4);
- pic->data[0] = utv->buffer + utv->buf_size + pic->linesize[0];
- break;
- }
- pic->width = w;
- pic->height = h;
- pic->format = avctx->pix_fmt;
-
- if (avctx->refcounted_frames) {
- int ret = av_frame_ref((AVFrame*)data, pic);
- if (ret < 0)
- return ret;
- } else {
- av_frame_move_ref((AVFrame*)data, pic);
- }
-
- *got_frame = 1;
-
- return avpkt->size;
-}
-
-static av_cold int utvideo_decode_close(AVCodecContext *avctx)
-{
- UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
-
- /* Free output */
- av_frame_free(&avctx->coded_frame);
- av_freep(&utv->buffer);
-
- /* Finish decoding and clean up the instance */
- utv->codec->DecodeEnd();
- CCodec::DeleteInstance(utv->codec);
-
- return 0;
-}
-
-AVCodec ff_libutvideo_decoder = {
- "libutvideo",
- NULL_IF_CONFIG_SMALL("Ut Video"),
- AVMEDIA_TYPE_VIDEO,
- AV_CODEC_ID_UTVIDEO,
- 0, //capabilities
- NULL, //supported_framerates
- NULL, //pix_fmts
- NULL, //supported_samplerates
- NULL, //sample_fmts
- NULL, //channel_layouts
- 0, //max_lowres
- NULL, //priv_class
- NULL, //profiles
- sizeof(UtVideoContext),
- NULL, //next
- NULL, //init_thread_copy
- NULL, //update_thread_context
- NULL, //defaults
- NULL, //init_static_data
- utvideo_decode_init,
- NULL, //encode
- NULL, //encode2
- utvideo_decode_frame,
- utvideo_decode_close,
-};
diff --git a/libavcodec/libutvideoenc.cpp b/libavcodec/libutvideoenc.cpp
deleted file mode 100644
index d03d5152fc..0000000000
--- a/libavcodec/libutvideoenc.cpp
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Copyright (c) 2012 Derek Buitenhuis
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation;
- * version 2 of the License.
- *
- * 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
- * General Public License for more details.
- *
- * You should have received a copy of the GNU 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
- */
-
-/**
- * @file
- * Known FOURCCs:
- * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA),
- * 'ULH0' (YCbCr 4:2:0 BT.709), 'ULH2' (YCbCr 4:2:2 BT.709)
- */
-
-extern "C" {
-#include "libavutil/opt.h"
-#include "libavutil/avassert.h"
-#include "libavutil/imgutils.h"
-#include "avcodec.h"
-#include "internal.h"
-}
-
-#include "libutvideo.h"
-#include "put_bits.h"
-
-static av_cold int utvideo_encode_init(AVCodecContext *avctx)
-{
- UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
- UtVideoExtra *info;
- uint32_t flags, in_format;
- int ret;
-
- switch (avctx->pix_fmt) {
- case AV_PIX_FMT_YUV420P:
- in_format = UTVF_YV12;
- avctx->bits_per_coded_sample = 12;
- if (avctx->colorspace == AVCOL_SPC_BT709)
- avctx->codec_tag = MKTAG('U', 'L', 'H', '0');
- else
- avctx->codec_tag = MKTAG('U', 'L', 'Y', '0');
- break;
- case AV_PIX_FMT_YUYV422:
- in_format = UTVF_YUYV;
- avctx->bits_per_coded_sample = 16;
- if (avctx->colorspace == AVCOL_SPC_BT709)
- avctx->codec_tag = MKTAG('U', 'L', 'H', '2');
- else
- avctx->codec_tag = MKTAG('U', 'L', 'Y', '2');
- break;
- case AV_PIX_FMT_BGR24:
- in_format = UTVF_NFCC_BGR_BU;
- avctx->bits_per_coded_sample = 24;
- avctx->codec_tag = MKTAG('U', 'L', 'R', 'G');
- break;
- case AV_PIX_FMT_RGB32:
- in_format = UTVF_NFCC_BGRA_BU;
- avctx->bits_per_coded_sample = 32;
- avctx->codec_tag = MKTAG('U', 'L', 'R', 'A');
- break;
- default:
- return AVERROR(EINVAL);
- }
-
-#if FF_API_PRIVATE_OPT
-FF_DISABLE_DEPRECATION_WARNINGS
- if (avctx->prediction_method)
- utv->pred = avctx->prediction_method;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-
- /* Check before we alloc anything */
- if (utv->pred != 0 && utv->pred != 2) {
- av_log(avctx, AV_LOG_ERROR, "Invalid prediction method.\n");
- return AVERROR(EINVAL);
- }
-
- flags = ((utv->pred + 1) << 8) | (avctx->thread_count - 1);
-
- avctx->priv_data = utv;
-
- /* Alloc extradata buffer */
- info = (UtVideoExtra *)av_malloc(sizeof(*info));
-
- if (!info) {
- av_log(avctx, AV_LOG_ERROR, "Could not allocate extradata buffer.\n");
- return AVERROR(ENOMEM);
- }
-
- /*
- * We use this buffer to hold the data that Ut Video returns,
- * since we cannot decode planes separately with it.
- */
- ret = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
- if (ret < 0) {
- av_free(info);
- return ret;
- }
- utv->buf_size = ret;
-
- utv->buffer = (uint8_t *)av_malloc(utv->buf_size);
-
- if (utv->buffer == NULL) {
- av_log(avctx, AV_LOG_ERROR, "Could not allocate output buffer.\n");
- av_free(info);
- return AVERROR(ENOMEM);
- }
-
- /*
- * Create a Ut Video instance. Since the function wants
- * an "interface name" string, pass it the name of the lib.
- */
- utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec");
-
- /* Initialize encoder */
- utv->codec->EncodeBegin(in_format, avctx->width, avctx->height,
- CBGROSSWIDTH_WINDOWS);
-
- /* Get extradata from encoder */
- avctx->extradata_size = utv->codec->EncodeGetExtraDataSize();
- utv->codec->EncodeGetExtraData(info, avctx->extradata_size, in_format,
- avctx->width, avctx->height,
- CBGROSSWIDTH_WINDOWS);
- avctx->extradata = (uint8_t *)info;
-
- /* Set flags */
- utv->codec->SetState(&flags, sizeof(flags));
-
- return 0;
-}
-
-static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
- const AVFrame *pic, int *got_packet)
-{
- UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
- int w = avctx->width, h = avctx->height;
- int ret, rgb_size, i;
- bool keyframe;
- uint8_t *y, *u, *v;
- uint8_t *dst;
-
- /* Alloc buffer */
- if ((ret = ff_alloc_packet2(avctx, pkt, utv->buf_size, 0)) < 0)
- return ret;
-
- dst = pkt->data;
-
- /* Move input if needed data into Ut Video friendly buffer */
- switch (avctx->pix_fmt) {
- case AV_PIX_FMT_YUV420P:
- y = utv->buffer;
- u = y + w * h;
- v = u + w * h / 4;
- for (i = 0; i < h; i++) {
- memcpy(y, pic->data[0] + i * pic->linesize[0], w);
- y += w;
- }
- for (i = 0; i < h / 2; i++) {
- memcpy(u, pic->data[2] + i * pic->linesize[2], w >> 1);
- memcpy(v, pic->data[1] + i * pic->linesize[1], w >> 1);
- u += w >> 1;
- v += w >> 1;
- }
- break;
- case AV_PIX_FMT_YUYV422:
- for (i = 0; i < h; i++)
- memcpy(utv->buffer + i * (w << 1),
- pic->data[0] + i * pic->linesize[0], w << 1);
- break;
- case AV_PIX_FMT_BGR24:
- case AV_PIX_FMT_RGB32:
- /* Ut Video takes bottom-up BGR */
- rgb_size = avctx->pix_fmt == AV_PIX_FMT_BGR24 ? 3 : 4;
- for (i = 0; i < h; i++)
- memcpy(utv->buffer + (h - i - 1) * w * rgb_size,
- pic->data[0] + i * pic->linesize[0],
- w * rgb_size);
- break;
- default:
- return AVERROR(EINVAL);
- }
-
- /* Encode frame */
- pkt->size = utv->codec->EncodeFrame(dst, &keyframe, utv->buffer);
-
- if (!pkt->size) {
- av_log(avctx, AV_LOG_ERROR, "EncodeFrame failed!\n");
- return AVERROR_INVALIDDATA;
- }
-
- /*
- * Ut Video is intra-only and every frame is a keyframe,
- * and the API always returns true. In case something
- * durastic changes in the future, such as inter support,
- * assert that this is true.
- */
- av_assert2(keyframe == true);
-
- pkt->flags |= AV_PKT_FLAG_KEY;
- *got_packet = 1;
- return 0;
-}
-
-static av_cold int utvideo_encode_close(AVCodecContext *avctx)
-{
- UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
-
- av_freep(&avctx->extradata);
- av_freep(&utv->buffer);
-
- utv->codec->EncodeEnd();
- CCodec::DeleteInstance(utv->codec);
-
- return 0;
-}
-
-#define OFFSET(x) offsetof(UtVideoContext, x)
-#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
-static const AVOption options[] = {
- { "pred", "Prediction method", OFFSET(pred), AV_OPT_TYPE_INT, 0, 0, 2, VE, "pred" },
- { "left", NULL, 0, AV_OPT_TYPE_CONST, 0, INT_MIN, INT_MAX, VE, "pred" },
- { "median", NULL, 0, AV_OPT_TYPE_CONST, 2, INT_MIN, INT_MAX, VE, "pred" },
- { NULL },
-};
-
-static const AVClass utvideo_class = {
- "libutvideo",
- av_default_item_name,
- options,
- LIBAVUTIL_VERSION_INT,
- 0,
- 0,
- NULL,
- NULL,
- AV_CLASS_CATEGORY_NA,
- NULL,
- NULL,
-};
-
-AVCodec ff_libutvideo_encoder = {
- "libutvideo",
- NULL_IF_CONFIG_SMALL("Ut Video"),
- AVMEDIA_TYPE_VIDEO,
- AV_CODEC_ID_UTVIDEO,
- AV_CODEC_CAP_AUTO_THREADS | (int)AV_CODEC_CAP_LOSSLESS | AV_CODEC_CAP_INTRA_ONLY,
- NULL, /* supported_framerates */
- (const enum AVPixelFormat[]) {
- AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUYV422, AV_PIX_FMT_BGR24,
- AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE
- },
- NULL, /* supported_samplerates */
- NULL, /* sample_fmts */
- NULL, /* channel_layouts */
- 0, /* max_lowres */
- &utvideo_class, /* priv_class */
- NULL, /* profiles */
- sizeof(UtVideoContext),
- NULL, /* next */
- NULL, /* init_thread_copy */
- NULL, /* update_thread_context */
- NULL, /* defaults */
- NULL, /* init_static_data */
- utvideo_encode_init,
- NULL, /* encode */
- utvideo_encode_frame,
- NULL, /* decode */
- utvideo_encode_close,
- NULL, /* flush */
-};