2009-02-14 17:57:47 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2009-02-14 17:57:47 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2009-02-14 17:57:47 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2009-02-14 17:57:47 +00:00
|
|
|
* 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
|
2015-04-13 07:36:54 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2009-02-14 17:57:47 +00:00
|
|
|
*/
|
|
|
|
|
2011-06-25 22:04:53 +00:00
|
|
|
#include <libavutil/pixdesc.h>
|
2013-12-18 16:12:21 +00:00
|
|
|
#include <libavutil/avutil.h>
|
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
2009-02-14 17:57:47 +00:00
|
|
|
#include "fmt-conversion.h"
|
2014-03-23 16:56:05 +00:00
|
|
|
#include "config.h"
|
2009-02-14 17:57:47 +00:00
|
|
|
|
|
|
|
static const struct {
|
|
|
|
int fmt;
|
2013-11-29 16:39:57 +00:00
|
|
|
enum AVPixelFormat pix_fmt;
|
2009-02-14 17:57:47 +00:00
|
|
|
} conversion_map[] = {
|
2013-11-29 16:39:57 +00:00
|
|
|
{IMGFMT_ARGB, AV_PIX_FMT_ARGB},
|
|
|
|
{IMGFMT_BGRA, AV_PIX_FMT_BGRA},
|
|
|
|
{IMGFMT_BGR24, AV_PIX_FMT_BGR24},
|
2014-11-05 00:16:57 +00:00
|
|
|
{IMGFMT_RGB565, AV_PIX_FMT_RGB565},
|
|
|
|
{IMGFMT_RGB555, AV_PIX_FMT_RGB555},
|
|
|
|
{IMGFMT_RGB444, AV_PIX_FMT_RGB444},
|
2014-06-14 08:03:04 +00:00
|
|
|
{IMGFMT_RGB8, AV_PIX_FMT_RGB8},
|
|
|
|
{IMGFMT_RGB4, AV_PIX_FMT_RGB4},
|
2013-11-29 16:39:57 +00:00
|
|
|
{IMGFMT_MONO, AV_PIX_FMT_MONOBLACK},
|
|
|
|
{IMGFMT_MONO_W, AV_PIX_FMT_MONOWHITE},
|
2014-06-14 08:03:04 +00:00
|
|
|
{IMGFMT_RGB4_BYTE, AV_PIX_FMT_RGB4_BYTE},
|
|
|
|
{IMGFMT_BGR4_BYTE, AV_PIX_FMT_BGR4_BYTE},
|
2014-11-05 00:16:57 +00:00
|
|
|
{IMGFMT_RGB48, AV_PIX_FMT_RGB48},
|
2013-11-29 16:39:57 +00:00
|
|
|
{IMGFMT_ABGR, AV_PIX_FMT_ABGR},
|
|
|
|
{IMGFMT_RGBA, AV_PIX_FMT_RGBA},
|
|
|
|
{IMGFMT_RGB24, AV_PIX_FMT_RGB24},
|
2014-11-05 00:16:57 +00:00
|
|
|
{IMGFMT_BGR565, AV_PIX_FMT_BGR565},
|
|
|
|
{IMGFMT_BGR555, AV_PIX_FMT_BGR555},
|
|
|
|
{IMGFMT_BGR444, AV_PIX_FMT_BGR444},
|
2014-06-14 08:03:04 +00:00
|
|
|
{IMGFMT_BGR8, AV_PIX_FMT_BGR8},
|
|
|
|
{IMGFMT_BGR4, AV_PIX_FMT_BGR4},
|
2013-11-29 16:39:57 +00:00
|
|
|
{IMGFMT_PAL8, AV_PIX_FMT_PAL8},
|
|
|
|
{IMGFMT_YUYV, AV_PIX_FMT_YUYV422},
|
|
|
|
{IMGFMT_UYVY, AV_PIX_FMT_UYVY422},
|
|
|
|
{IMGFMT_NV12, AV_PIX_FMT_NV12},
|
|
|
|
{IMGFMT_NV21, AV_PIX_FMT_NV21},
|
|
|
|
{IMGFMT_Y8, AV_PIX_FMT_GRAY8},
|
2014-03-16 15:23:12 +00:00
|
|
|
// FFmpeg prefers AV_PIX_FMT_GRAY8A, but Libav has only Y400A
|
|
|
|
{IMGFMT_YA8, AV_PIX_FMT_Y400A},
|
2014-11-05 00:16:57 +00:00
|
|
|
{IMGFMT_Y16, AV_PIX_FMT_GRAY16},
|
2013-11-29 16:39:57 +00:00
|
|
|
{IMGFMT_410P, AV_PIX_FMT_YUV410P},
|
|
|
|
{IMGFMT_420P, AV_PIX_FMT_YUV420P},
|
|
|
|
{IMGFMT_411P, AV_PIX_FMT_YUV411P},
|
|
|
|
{IMGFMT_422P, AV_PIX_FMT_YUV422P},
|
|
|
|
{IMGFMT_444P, AV_PIX_FMT_YUV444P},
|
|
|
|
{IMGFMT_440P, AV_PIX_FMT_YUV440P},
|
|
|
|
|
2014-11-05 00:16:57 +00:00
|
|
|
{IMGFMT_420P16, AV_PIX_FMT_YUV420P16},
|
|
|
|
{IMGFMT_420P9, AV_PIX_FMT_YUV420P9},
|
|
|
|
{IMGFMT_420P10, AV_PIX_FMT_YUV420P10},
|
|
|
|
{IMGFMT_422P10, AV_PIX_FMT_YUV422P10},
|
|
|
|
{IMGFMT_444P9, AV_PIX_FMT_YUV444P9},
|
|
|
|
{IMGFMT_444P10, AV_PIX_FMT_YUV444P10},
|
|
|
|
{IMGFMT_422P16, AV_PIX_FMT_YUV422P16},
|
|
|
|
{IMGFMT_422P9, AV_PIX_FMT_YUV422P9},
|
|
|
|
{IMGFMT_444P16, AV_PIX_FMT_YUV444P16},
|
2009-02-19 12:19:55 +00:00
|
|
|
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
// YUVJ are YUV formats that use the full Y range. Decoder color range
|
|
|
|
// information is used instead. Deprecated in ffmpeg.
|
2013-11-29 16:39:57 +00:00
|
|
|
{IMGFMT_420P, AV_PIX_FMT_YUVJ420P},
|
|
|
|
{IMGFMT_422P, AV_PIX_FMT_YUVJ422P},
|
|
|
|
{IMGFMT_444P, AV_PIX_FMT_YUVJ444P},
|
|
|
|
{IMGFMT_440P, AV_PIX_FMT_YUVJ440P},
|
2009-02-19 12:19:55 +00:00
|
|
|
|
2013-11-29 16:39:57 +00:00
|
|
|
{IMGFMT_420AP, AV_PIX_FMT_YUVA420P},
|
|
|
|
{IMGFMT_422AP, AV_PIX_FMT_YUVA422P},
|
|
|
|
{IMGFMT_444AP, AV_PIX_FMT_YUVA444P},
|
2012-12-26 23:58:45 +00:00
|
|
|
|
2014-11-05 00:16:57 +00:00
|
|
|
{IMGFMT_XYZ12, AV_PIX_FMT_XYZ12},
|
2013-05-01 14:16:03 +00:00
|
|
|
|
2015-02-06 22:20:41 +00:00
|
|
|
#ifdef AV_PIX_FMT_YUV420P12
|
2014-11-05 00:16:57 +00:00
|
|
|
{IMGFMT_420P12, AV_PIX_FMT_YUV420P12},
|
|
|
|
{IMGFMT_420P14, AV_PIX_FMT_YUV420P14},
|
|
|
|
{IMGFMT_422P12, AV_PIX_FMT_YUV422P12},
|
|
|
|
{IMGFMT_422P14, AV_PIX_FMT_YUV422P14},
|
|
|
|
{IMGFMT_444P12, AV_PIX_FMT_YUV444P12},
|
|
|
|
{IMGFMT_444P14, AV_PIX_FMT_YUV444P14},
|
2015-02-06 22:20:41 +00:00
|
|
|
#endif
|
2013-11-29 16:39:57 +00:00
|
|
|
|
2015-02-06 22:20:41 +00:00
|
|
|
#ifdef AV_PIX_FMT_RGBA64
|
2014-11-05 00:16:57 +00:00
|
|
|
{IMGFMT_RGBA64, AV_PIX_FMT_RGBA64},
|
|
|
|
{IMGFMT_BGRA64, AV_PIX_FMT_BGRA64},
|
2015-02-06 22:20:41 +00:00
|
|
|
#endif
|
2013-11-29 16:39:57 +00:00
|
|
|
|
2015-02-06 22:20:41 +00:00
|
|
|
#if LIBAVUTIL_VERSION_MICRO >= 100
|
2013-11-29 16:39:57 +00:00
|
|
|
{IMGFMT_BGR0, AV_PIX_FMT_BGR0},
|
|
|
|
{IMGFMT_0RGB, AV_PIX_FMT_0RGB},
|
|
|
|
{IMGFMT_RGB0, AV_PIX_FMT_RGB0},
|
|
|
|
{IMGFMT_0BGR, AV_PIX_FMT_0BGR},
|
2013-11-05 20:59:26 +00:00
|
|
|
#else
|
2013-11-29 16:39:57 +00:00
|
|
|
{IMGFMT_BGR0, AV_PIX_FMT_BGRA},
|
|
|
|
{IMGFMT_0RGB, AV_PIX_FMT_ARGB},
|
|
|
|
{IMGFMT_RGB0, AV_PIX_FMT_RGBA},
|
|
|
|
{IMGFMT_0BGR, AV_PIX_FMT_ABGR},
|
2012-10-30 18:32:30 +00:00
|
|
|
#endif
|
2012-10-20 23:10:32 +00:00
|
|
|
|
2015-01-21 18:29:18 +00:00
|
|
|
#ifdef AV_PIX_FMT_YA16
|
|
|
|
{IMGFMT_YA16, AV_PIX_FMT_YA16},
|
|
|
|
#endif
|
|
|
|
|
2014-08-01 07:16:42 +00:00
|
|
|
{IMGFMT_VDPAU, AV_PIX_FMT_VDPAU},
|
2015-07-11 15:21:39 +00:00
|
|
|
#if HAVE_VIDEOTOOLBOX_HWACCEL
|
|
|
|
{IMGFMT_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX},
|
2014-03-23 16:56:05 +00:00
|
|
|
#endif
|
2014-08-01 07:16:42 +00:00
|
|
|
{IMGFMT_VAAPI, AV_PIX_FMT_VAAPI_VLD},
|
2014-10-25 17:23:46 +00:00
|
|
|
{IMGFMT_DXVA2, AV_PIX_FMT_DXVA2_VLD},
|
2015-03-29 13:12:11 +00:00
|
|
|
#if HAVE_AV_PIX_FMT_MMAL
|
|
|
|
{IMGFMT_MMAL, AV_PIX_FMT_MMAL},
|
|
|
|
#endif
|
video: add vaapi decode and output support
This is based on the MPlayer VA API patches. To be exact it's based on
a very stripped down version of commit f1ad459a263f8537f6c from
git://gitorious.org/vaapi/mplayer.git.
This doesn't contain useless things like benchmarking hacks and the
demo code for GLX interop. Also, unlike in the original patch, decoding
and video output are split into separate source files (the separation
between decoding and display also makes pixel format hacks unnecessary).
On the other hand, some features not present in the original patch were
added, like screenshot support.
VA API is rather bad for actual video output. Dealing with older libva
versions or the completely broken vdpau backend doesn't help. OSD is
low quality and should be rather slow. In some cases, only either OSD
or subtitles can be shown at the same time (because OSD is drawn first,
OSD is prefered).
Also, libva can't decide whether it accepts straight or premultiplied
alpha for OSD sub-pictures: the vdpau backend seems to assume
premultiplied, while a native vaapi driver uses straight. So I picked
straight alpha. It doesn't matter much, because the blending code for
straight alpha I added to img_convert.c is probably buggy, and ASS
subtitles might be blended incorrectly.
Really good video output with VA API would probably use OpenGL and the
GL interop features, but at this point you might just use vo_opengl.
(Patches for making HW decoding with vo_opengl have a chance of being
accepted.)
Despite these issues, decoding seems to work ok. I still got tearing
on the Intel system I tested (Intel(R) Core(TM) i3-2350M). It was also
tested with the vdpau vaapi wrapper on a nvidia system; however this
was rather broken. (Fortunately, there is no reason to use mpv's VAAPI
support over native VDPAU.)
2013-08-09 12:01:30 +00:00
|
|
|
|
2013-11-29 16:39:57 +00:00
|
|
|
{0, AV_PIX_FMT_NONE}
|
2009-02-14 17:57:47 +00:00
|
|
|
};
|
|
|
|
|
2013-11-29 16:39:57 +00:00
|
|
|
enum AVPixelFormat imgfmt2pixfmt(int fmt)
|
2009-02-14 17:57:47 +00:00
|
|
|
{
|
2013-01-17 15:10:26 +00:00
|
|
|
if (fmt == IMGFMT_NONE)
|
2013-11-29 16:39:57 +00:00
|
|
|
return AV_PIX_FMT_NONE;
|
2013-01-17 15:10:26 +00:00
|
|
|
|
video: passthrough unknown AVPixelFormats
This is a rather radical change: instead of maintaining a whitelist of
FFmpeg formats we support, we automatically support all formats.
In general, a format which doesn't have an explicit IMGFMT_* name will
be converted to a known format through libswscale, or will be handled
by code which can treat pixel formats in a generic way using the pixel
format description, like vo_opengl.
AV_PIX_FMT_UYYVYY411 is a special-case. It's packed YUV with chroma
subsampling by 4 in both directions. Its component order is documented
as "Cb Y0 Y1 Cr Y2 Y3", meaning there's one UV sample for 4 Y samples.
This means each pixel uses 1.5 bytes (4 pixels have 1 UV sample, so
4 bytes + 2 bytes). FFmpeg can actually handle this format with its
generic mechanism in an extremely awkward way, but it doesn't work for
us. Blacklist it, and hope no similar formats will be added in the
future.
Currently, the AV_PIX_FMT_*s allowed are limited to a numeric value of
500. More is not allowed, and there are some fixed size arrays that need
to contain any possible format (look for IMGFMT_END dependencies).
We could have this simpler by replacing IMGFMT_* with AV_PIX_FMT_*
through the whole codebase. But for now, this is better, because we
can compensate for formats missing in Libav or older FFmpeg versions,
like AV_PIX_FMT_RGB0 and others.
2014-11-04 22:32:02 +00:00
|
|
|
if (fmt >= IMGFMT_AVPIXFMT_START && fmt < IMGFMT_AVPIXFMT_END) {
|
|
|
|
enum AVPixelFormat pixfmt = fmt - IMGFMT_AVPIXFMT_START;
|
|
|
|
// Avoid duplicate format - each format must be unique.
|
|
|
|
int mpfmt = pixfmt2imgfmt(pixfmt);
|
|
|
|
if (mpfmt == fmt)
|
|
|
|
return pixfmt;
|
|
|
|
return AV_PIX_FMT_NONE;
|
|
|
|
}
|
|
|
|
|
2013-12-21 17:04:16 +00:00
|
|
|
for (int i = 0; conversion_map[i].fmt; i++) {
|
2009-02-14 17:57:47 +00:00
|
|
|
if (conversion_map[i].fmt == fmt)
|
2013-12-21 17:04:16 +00:00
|
|
|
return conversion_map[i].pix_fmt;
|
|
|
|
}
|
|
|
|
return AV_PIX_FMT_NONE;
|
2009-02-14 17:57:47 +00:00
|
|
|
}
|
|
|
|
|
2013-11-29 16:39:57 +00:00
|
|
|
int pixfmt2imgfmt(enum AVPixelFormat pix_fmt)
|
2009-02-14 17:57:47 +00:00
|
|
|
{
|
2013-11-29 16:39:57 +00:00
|
|
|
if (pix_fmt == AV_PIX_FMT_NONE)
|
2013-01-17 15:10:26 +00:00
|
|
|
return IMGFMT_NONE;
|
|
|
|
|
2013-12-21 17:04:16 +00:00
|
|
|
for (int i = 0; conversion_map[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
|
2009-02-14 17:57:47 +00:00
|
|
|
if (conversion_map[i].pix_fmt == pix_fmt)
|
2013-12-21 17:04:16 +00:00
|
|
|
return conversion_map[i].fmt;
|
2011-06-25 22:04:53 +00:00
|
|
|
}
|
video: passthrough unknown AVPixelFormats
This is a rather radical change: instead of maintaining a whitelist of
FFmpeg formats we support, we automatically support all formats.
In general, a format which doesn't have an explicit IMGFMT_* name will
be converted to a known format through libswscale, or will be handled
by code which can treat pixel formats in a generic way using the pixel
format description, like vo_opengl.
AV_PIX_FMT_UYYVYY411 is a special-case. It's packed YUV with chroma
subsampling by 4 in both directions. Its component order is documented
as "Cb Y0 Y1 Cr Y2 Y3", meaning there's one UV sample for 4 Y samples.
This means each pixel uses 1.5 bytes (4 pixels have 1 UV sample, so
4 bytes + 2 bytes). FFmpeg can actually handle this format with its
generic mechanism in an extremely awkward way, but it doesn't work for
us. Blacklist it, and hope no similar formats will be added in the
future.
Currently, the AV_PIX_FMT_*s allowed are limited to a numeric value of
500. More is not allowed, and there are some fixed size arrays that need
to contain any possible format (look for IMGFMT_END dependencies).
We could have this simpler by replacing IMGFMT_* with AV_PIX_FMT_*
through the whole codebase. But for now, this is better, because we
can compensate for formats missing in Libav or older FFmpeg versions,
like AV_PIX_FMT_RGB0 and others.
2014-11-04 22:32:02 +00:00
|
|
|
|
|
|
|
int generic = IMGFMT_AVPIXFMT_START + pix_fmt;
|
|
|
|
if (generic < IMGFMT_AVPIXFMT_END)
|
|
|
|
return generic;
|
|
|
|
|
2013-12-21 17:04:16 +00:00
|
|
|
return 0;
|
2009-02-14 17:57:47 +00:00
|
|
|
}
|