2010-10-22 17:46:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Gordon Schmidt <gordon.schmidt <at> s2000.tu-chemnitz.de>
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2010-10-22 17:46:12 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2010-10-22 17:46:12 +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,
|
2010-10-22 17:46:12 +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/>.
|
2010-10-22 17:46:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
//==includes==//
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
#include <stdbool.h>
|
2010-10-22 17:46:12 +00:00
|
|
|
|
2014-04-19 15:18:10 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2010-10-22 17:46:12 +00:00
|
|
|
#include "config.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2010-10-22 17:46:12 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
2010-10-22 17:46:12 +00:00
|
|
|
#include "vf.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2010-10-22 17:46:12 +00:00
|
|
|
|
2013-12-03 21:26:24 +00:00
|
|
|
#include "vf_lavfi.h"
|
|
|
|
|
2010-10-22 17:46:12 +00:00
|
|
|
//==types==//
|
|
|
|
typedef enum stereo_code {
|
|
|
|
ANAGLYPH_RC_GRAY, //anaglyph red/cyan gray
|
|
|
|
ANAGLYPH_RC_HALF, //anaglyph red/cyan half colored
|
|
|
|
ANAGLYPH_RC_COLOR, //anaglyph red/cyan colored
|
|
|
|
ANAGLYPH_RC_DUBOIS, //anaglyph red/cyan dubois
|
|
|
|
ANAGLYPH_GM_GRAY, //anaglyph green/magenta gray
|
|
|
|
ANAGLYPH_GM_HALF, //anaglyph green/magenta half colored
|
|
|
|
ANAGLYPH_GM_COLOR, //anaglyph green/magenta colored
|
2013-01-31 12:12:36 +00:00
|
|
|
ANAGLYPH_GM_DUBOIS, //anaglyph green/magenta dubois
|
2010-10-22 17:46:12 +00:00
|
|
|
ANAGLYPH_YB_GRAY, //anaglyph yellow/blue gray
|
|
|
|
ANAGLYPH_YB_HALF, //anaglyph yellow/blue half colored
|
|
|
|
ANAGLYPH_YB_COLOR, //anaglyph yellow/blue colored
|
2012-08-12 17:20:24 +00:00
|
|
|
ANAGLYPH_YB_DUBOIS, //anaglyph yellow/blue dubois
|
2010-10-22 17:46:12 +00:00
|
|
|
MONO_L, //mono output for debugging (left eye only)
|
|
|
|
MONO_R, //mono output for debugging (right eye only)
|
|
|
|
SIDE_BY_SIDE_LR, //side by side parallel (left eye left, right eye right)
|
|
|
|
SIDE_BY_SIDE_RL, //side by side crosseye (right eye left, left eye right)
|
2011-07-11 21:54:53 +00:00
|
|
|
SIDE_BY_SIDE_2_LR, //side by side parallel with half width resolution
|
|
|
|
SIDE_BY_SIDE_2_RL, //side by side crosseye with half width resolution
|
2010-10-22 17:46:12 +00:00
|
|
|
ABOVE_BELOW_LR, //above-below (left eye above, right eye below)
|
|
|
|
ABOVE_BELOW_RL, //above-below (right eye above, left eye below)
|
|
|
|
ABOVE_BELOW_2_LR, //above-below with half height resolution
|
|
|
|
ABOVE_BELOW_2_RL, //above-below with half height resolution
|
2011-06-19 08:33:57 +00:00
|
|
|
INTERLEAVE_ROWS_LR, //row-interleave (left eye has top row)
|
|
|
|
INTERLEAVE_ROWS_RL, //row-interleave (right eye has top row)
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
STEREO_AUTO, //use video metadata info (for input)
|
2010-10-22 17:46:12 +00:00
|
|
|
STEREO_CODE_COUNT //no value set - TODO: needs autodetection
|
|
|
|
} stereo_code;
|
|
|
|
|
|
|
|
typedef struct component {
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
int fmt;
|
2010-10-22 17:46:12 +00:00
|
|
|
unsigned int width;
|
|
|
|
unsigned int height;
|
|
|
|
unsigned int off_left;
|
|
|
|
unsigned int off_right;
|
2010-11-14 15:33:25 +00:00
|
|
|
unsigned int row_left;
|
|
|
|
unsigned int row_right;
|
2010-10-22 17:46:12 +00:00
|
|
|
} component;
|
|
|
|
|
|
|
|
//==global variables==//
|
2012-08-12 17:20:24 +00:00
|
|
|
static const int ana_coeff[][3][6] = {
|
|
|
|
[ANAGLYPH_RC_GRAY] =
|
|
|
|
{{19595, 38470, 7471, 0, 0, 0},
|
2010-10-22 17:46:12 +00:00
|
|
|
{ 0, 0, 0, 19595, 38470, 7471},
|
|
|
|
{ 0, 0, 0, 19595, 38470, 7471}},
|
2012-08-12 17:20:24 +00:00
|
|
|
[ANAGLYPH_RC_HALF] =
|
|
|
|
{{19595, 38470, 7471, 0, 0, 0},
|
2010-10-22 17:46:12 +00:00
|
|
|
{ 0, 0, 0, 0, 65536, 0},
|
|
|
|
{ 0, 0, 0, 0, 0, 65536}},
|
2012-08-12 17:20:24 +00:00
|
|
|
[ANAGLYPH_RC_COLOR] =
|
|
|
|
{{65536, 0, 0, 0, 0, 0},
|
2010-10-22 17:46:12 +00:00
|
|
|
{ 0, 0, 0, 0, 65536, 0},
|
|
|
|
{ 0, 0, 0, 0, 0, 65536}},
|
2012-08-12 17:20:24 +00:00
|
|
|
[ANAGLYPH_RC_DUBOIS] =
|
|
|
|
{{29891, 32800, 11559, -2849, -5763, -102},
|
2010-10-22 17:46:12 +00:00
|
|
|
{-2627, -2479, -1033, 24804, 48080, -1209},
|
|
|
|
{ -997, -1350, -358, -4729, -7403, 80373}},
|
2012-08-12 17:20:24 +00:00
|
|
|
[ANAGLYPH_GM_GRAY] =
|
|
|
|
{{ 0, 0, 0, 19595, 38470, 7471},
|
2010-10-22 17:46:12 +00:00
|
|
|
{19595, 38470, 7471, 0, 0, 0},
|
|
|
|
{ 0, 0, 0, 19595, 38470, 7471}},
|
2012-08-12 17:20:24 +00:00
|
|
|
[ANAGLYPH_GM_HALF] =
|
|
|
|
{{ 0, 0, 0, 65536, 0, 0},
|
2010-10-22 17:46:12 +00:00
|
|
|
{19595, 38470, 7471, 0, 0, 0},
|
|
|
|
{ 0, 0, 0, 0, 0, 65536}},
|
2012-08-12 17:20:24 +00:00
|
|
|
[ANAGLYPH_GM_COLOR] =
|
|
|
|
{{ 0, 0, 0, 65536, 0, 0},
|
2010-10-22 17:46:12 +00:00
|
|
|
{ 0, 65536, 0, 0, 0, 0},
|
|
|
|
{ 0, 0, 0, 0, 0, 65536}},
|
2013-01-31 12:12:36 +00:00
|
|
|
[ANAGLYPH_GM_DUBOIS] =
|
|
|
|
{{-4063,-10354, -2556, 34669, 46203, 1573},
|
|
|
|
{18612, 43778, 9372, -1049, -983, -4260},
|
|
|
|
{ -983, -1769, 1376, 590, 4915, 61407}},
|
2012-08-12 17:20:24 +00:00
|
|
|
[ANAGLYPH_YB_GRAY] =
|
|
|
|
{{ 0, 0, 0, 19595, 38470, 7471},
|
2010-10-22 17:46:12 +00:00
|
|
|
{ 0, 0, 0, 19595, 38470, 7471},
|
|
|
|
{19595, 38470, 7471, 0, 0, 0}},
|
2012-08-12 17:20:24 +00:00
|
|
|
[ANAGLYPH_YB_HALF] =
|
|
|
|
{{ 0, 0, 0, 65536, 0, 0},
|
2010-10-22 17:46:12 +00:00
|
|
|
{ 0, 0, 0, 0, 65536, 0},
|
|
|
|
{19595, 38470, 7471, 0, 0, 0}},
|
2012-08-12 17:20:24 +00:00
|
|
|
[ANAGLYPH_YB_COLOR] =
|
|
|
|
{{ 0, 0, 0, 65536, 0, 0},
|
2010-10-22 17:46:12 +00:00
|
|
|
{ 0, 0, 0, 0, 65536, 0},
|
2012-08-12 17:20:24 +00:00
|
|
|
{ 0, 0, 65536, 0, 0, 0}},
|
|
|
|
[ANAGLYPH_YB_DUBOIS] =
|
|
|
|
{{65535,-12650,18451, -987, -7590, -1049},
|
|
|
|
{-1604, 56032, 4196, 370, 3826, -1049},
|
|
|
|
{-2345,-10676, 1358, 5801, 11416, 56217}},
|
2010-10-22 17:46:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct vf_priv_s {
|
|
|
|
component in;
|
|
|
|
component out;
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
bool auto_in;
|
2010-10-22 17:46:12 +00:00
|
|
|
int ana_matrix[3][6];
|
|
|
|
unsigned int width;
|
|
|
|
unsigned int height;
|
2011-06-19 08:33:57 +00:00
|
|
|
unsigned int row_step;
|
2013-12-03 21:26:24 +00:00
|
|
|
struct vf_lw_opts *lw_opts;
|
2010-10-22 17:46:12 +00:00
|
|
|
} const vf_priv_default = {
|
|
|
|
{SIDE_BY_SIDE_LR},
|
|
|
|
{ANAGLYPH_RC_DUBOIS}
|
|
|
|
};
|
|
|
|
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
static bool handle_auto_in(struct vf_instance *vf);
|
|
|
|
|
2010-10-22 17:46:12 +00:00
|
|
|
//==functions==//
|
|
|
|
static inline uint8_t ana_convert(int coeff[6], uint8_t left[3], uint8_t right[3])
|
|
|
|
{
|
|
|
|
int sum;
|
|
|
|
|
|
|
|
sum = coeff[0] * left[0] + coeff[3] * right[0]; //red in
|
|
|
|
sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in
|
|
|
|
sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in
|
|
|
|
return av_clip_uint8(sum >> 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config(struct vf_instance *vf, int width, int height, int d_width,
|
|
|
|
int d_height, unsigned int flags, unsigned int outfmt)
|
|
|
|
{
|
|
|
|
if ((width & 1) || (height & 1)) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_WARN(vf, "[stereo3d] invalid height or width\n");
|
2010-10-22 17:46:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//default input values
|
|
|
|
vf->priv->width = width;
|
|
|
|
vf->priv->height = height;
|
2011-06-19 08:33:57 +00:00
|
|
|
vf->priv->row_step = 1;
|
2010-10-22 17:46:12 +00:00
|
|
|
vf->priv->in.width = width;
|
|
|
|
vf->priv->in.height = height;
|
|
|
|
vf->priv->in.off_left = 0;
|
|
|
|
vf->priv->in.off_right = 0;
|
2010-11-14 15:33:25 +00:00
|
|
|
vf->priv->in.row_left = 0;
|
|
|
|
vf->priv->in.row_right = 0;
|
2010-10-22 17:46:12 +00:00
|
|
|
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
if (vf->priv->auto_in && !handle_auto_in(vf))
|
|
|
|
return 0;
|
|
|
|
|
2010-10-22 17:46:12 +00:00
|
|
|
//check input format
|
|
|
|
switch (vf->priv->in.fmt) {
|
2011-07-11 21:54:53 +00:00
|
|
|
case SIDE_BY_SIDE_2_LR:
|
|
|
|
d_width *= 2;
|
2010-10-22 17:46:12 +00:00
|
|
|
case SIDE_BY_SIDE_LR:
|
|
|
|
vf->priv->width = width / 2;
|
|
|
|
vf->priv->in.off_right = vf->priv->width * 3;
|
|
|
|
break;
|
2011-07-11 21:54:53 +00:00
|
|
|
case SIDE_BY_SIDE_2_RL:
|
|
|
|
d_width *= 2;
|
2010-10-22 17:46:12 +00:00
|
|
|
case SIDE_BY_SIDE_RL:
|
|
|
|
vf->priv->width = width / 2;
|
|
|
|
vf->priv->in.off_left = vf->priv->width * 3;
|
|
|
|
break;
|
2010-11-14 15:24:12 +00:00
|
|
|
case ABOVE_BELOW_2_LR:
|
|
|
|
d_height *= 2;
|
2010-10-22 17:46:12 +00:00
|
|
|
case ABOVE_BELOW_LR:
|
|
|
|
vf->priv->height = height / 2;
|
2010-11-14 15:33:25 +00:00
|
|
|
vf->priv->in.row_right = vf->priv->height;
|
2010-10-22 17:46:12 +00:00
|
|
|
break;
|
2010-11-14 15:24:12 +00:00
|
|
|
case ABOVE_BELOW_2_RL:
|
|
|
|
d_height *= 2;
|
2010-10-22 17:46:12 +00:00
|
|
|
case ABOVE_BELOW_RL:
|
|
|
|
vf->priv->height = height / 2;
|
2010-11-14 15:33:25 +00:00
|
|
|
vf->priv->in.row_left = vf->priv->height;
|
2010-10-22 17:46:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_WARN(vf, "[stereo3d] stereo format of input is not supported\n");
|
2010-10-22 17:46:12 +00:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//default output values
|
|
|
|
vf->priv->out.width = vf->priv->width;
|
|
|
|
vf->priv->out.height = vf->priv->height;
|
|
|
|
vf->priv->out.off_left = 0;
|
|
|
|
vf->priv->out.off_right = 0;
|
2010-11-14 15:33:25 +00:00
|
|
|
vf->priv->out.row_left = 0;
|
|
|
|
vf->priv->out.row_right = 0;
|
2010-10-22 17:46:12 +00:00
|
|
|
|
|
|
|
//check output format
|
|
|
|
switch (vf->priv->out.fmt) {
|
|
|
|
case ANAGLYPH_RC_GRAY:
|
|
|
|
case ANAGLYPH_RC_HALF:
|
|
|
|
case ANAGLYPH_RC_COLOR:
|
|
|
|
case ANAGLYPH_RC_DUBOIS:
|
|
|
|
case ANAGLYPH_GM_GRAY:
|
|
|
|
case ANAGLYPH_GM_HALF:
|
|
|
|
case ANAGLYPH_GM_COLOR:
|
2013-01-31 12:12:36 +00:00
|
|
|
case ANAGLYPH_GM_DUBOIS:
|
2010-10-22 17:46:12 +00:00
|
|
|
case ANAGLYPH_YB_GRAY:
|
|
|
|
case ANAGLYPH_YB_HALF:
|
|
|
|
case ANAGLYPH_YB_COLOR:
|
2012-08-12 17:20:24 +00:00
|
|
|
case ANAGLYPH_YB_DUBOIS:
|
2010-10-22 17:46:12 +00:00
|
|
|
memcpy(vf->priv->ana_matrix, ana_coeff[vf->priv->out.fmt],
|
|
|
|
sizeof(vf->priv->ana_matrix));
|
|
|
|
break;
|
2011-07-11 21:54:53 +00:00
|
|
|
case SIDE_BY_SIDE_2_LR:
|
|
|
|
d_width /= 2;
|
2010-10-22 17:46:12 +00:00
|
|
|
case SIDE_BY_SIDE_LR:
|
|
|
|
vf->priv->out.width = vf->priv->width * 2;
|
|
|
|
vf->priv->out.off_right = vf->priv->width * 3;
|
|
|
|
break;
|
2011-07-11 21:54:53 +00:00
|
|
|
case SIDE_BY_SIDE_2_RL:
|
|
|
|
d_width /= 2;
|
2010-10-22 17:46:12 +00:00
|
|
|
case SIDE_BY_SIDE_RL:
|
|
|
|
vf->priv->out.width = vf->priv->width * 2;
|
|
|
|
vf->priv->out.off_left = vf->priv->width * 3;
|
|
|
|
break;
|
2010-11-14 15:24:12 +00:00
|
|
|
case ABOVE_BELOW_2_LR:
|
|
|
|
d_height /= 2;
|
2010-10-22 17:46:12 +00:00
|
|
|
case ABOVE_BELOW_LR:
|
|
|
|
vf->priv->out.height = vf->priv->height * 2;
|
2010-11-14 15:33:25 +00:00
|
|
|
vf->priv->out.row_right = vf->priv->height;
|
2010-10-22 17:46:12 +00:00
|
|
|
break;
|
2010-11-14 15:24:12 +00:00
|
|
|
case ABOVE_BELOW_2_RL:
|
|
|
|
d_height /= 2;
|
2010-10-22 17:46:12 +00:00
|
|
|
case ABOVE_BELOW_RL:
|
|
|
|
vf->priv->out.height = vf->priv->height * 2;
|
2010-11-14 15:33:25 +00:00
|
|
|
vf->priv->out.row_left = vf->priv->height;
|
2010-10-22 17:46:12 +00:00
|
|
|
break;
|
2011-06-19 08:33:57 +00:00
|
|
|
case INTERLEAVE_ROWS_LR:
|
|
|
|
vf->priv->row_step = 2;
|
|
|
|
vf->priv->height = vf->priv->height / 2;
|
|
|
|
vf->priv->out.off_right = vf->priv->width * 3;
|
|
|
|
vf->priv->in.off_right += vf->priv->in.width * 3;
|
|
|
|
break;
|
|
|
|
case INTERLEAVE_ROWS_RL:
|
|
|
|
vf->priv->row_step = 2;
|
|
|
|
vf->priv->height = vf->priv->height / 2;
|
|
|
|
vf->priv->out.off_left = vf->priv->width * 3;
|
|
|
|
vf->priv->in.off_left += vf->priv->in.width * 3;
|
|
|
|
break;
|
2010-10-22 17:46:12 +00:00
|
|
|
case MONO_R:
|
|
|
|
//same as MONO_L only needs switching of input offsets
|
|
|
|
vf->priv->in.off_left = vf->priv->in.off_right;
|
2010-11-14 15:33:25 +00:00
|
|
|
vf->priv->in.row_left = vf->priv->in.row_right;
|
2010-10-22 17:46:12 +00:00
|
|
|
//nobreak;
|
|
|
|
case MONO_L:
|
|
|
|
//use default settings
|
|
|
|
break;
|
|
|
|
default:
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_WARN(vf, "[stereo3d] stereo format of output is not supported\n");
|
2010-10-22 17:46:12 +00:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-22 12:28:31 +00:00
|
|
|
vf_rescale_dsize(&d_width, &d_height, width, height,
|
|
|
|
vf->priv->out.width, vf->priv->out.height);
|
2010-10-22 17:46:12 +00:00
|
|
|
return vf_next_config(vf, vf->priv->out.width, vf->priv->out.height,
|
|
|
|
d_width, d_height, flags, outfmt);
|
|
|
|
}
|
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi)
|
2010-10-22 17:46:12 +00:00
|
|
|
{
|
|
|
|
if (vf->priv->in.fmt == vf->priv->out.fmt) { //nothing to do
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
return mpi;
|
2010-10-22 17:46:12 +00:00
|
|
|
} else {
|
2010-11-14 15:33:25 +00:00
|
|
|
int out_off_left, out_off_right;
|
|
|
|
int in_off_left = vf->priv->in.row_left * mpi->stride[0] +
|
|
|
|
vf->priv->in.off_left;
|
|
|
|
int in_off_right = vf->priv->in.row_right * mpi->stride[0] +
|
|
|
|
vf->priv->in.off_right;
|
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
struct mp_image *dmpi = vf_alloc_out_image(vf);
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
if (!dmpi)
|
|
|
|
return NULL;
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
mp_image_copy_attributes(dmpi, mpi);
|
|
|
|
|
2010-11-14 15:33:25 +00:00
|
|
|
out_off_left = vf->priv->out.row_left * dmpi->stride[0] +
|
|
|
|
vf->priv->out.off_left;
|
|
|
|
out_off_right = vf->priv->out.row_right * dmpi->stride[0] +
|
|
|
|
vf->priv->out.off_right;
|
|
|
|
|
2010-10-22 17:46:12 +00:00
|
|
|
switch (vf->priv->out.fmt) {
|
|
|
|
case SIDE_BY_SIDE_LR:
|
|
|
|
case SIDE_BY_SIDE_RL:
|
2011-07-11 21:54:53 +00:00
|
|
|
case SIDE_BY_SIDE_2_LR:
|
|
|
|
case SIDE_BY_SIDE_2_RL:
|
2010-10-22 17:46:12 +00:00
|
|
|
case ABOVE_BELOW_LR:
|
|
|
|
case ABOVE_BELOW_RL:
|
|
|
|
case ABOVE_BELOW_2_LR:
|
|
|
|
case ABOVE_BELOW_2_RL:
|
2011-06-19 08:33:57 +00:00
|
|
|
case INTERLEAVE_ROWS_LR:
|
|
|
|
case INTERLEAVE_ROWS_RL:
|
2015-03-19 23:12:03 +00:00
|
|
|
memcpy_pic(dmpi->planes[0] + out_off_left,
|
2010-11-14 15:33:25 +00:00
|
|
|
mpi->planes[0] + in_off_left,
|
2010-11-14 15:24:12 +00:00
|
|
|
3 * vf->priv->width,
|
|
|
|
vf->priv->height,
|
2011-06-19 08:33:57 +00:00
|
|
|
dmpi->stride[0] * vf->priv->row_step,
|
2015-03-19 23:12:03 +00:00
|
|
|
mpi->stride[0] * vf->priv->row_step);
|
|
|
|
memcpy_pic(dmpi->planes[0] + out_off_right,
|
2010-11-14 15:33:25 +00:00
|
|
|
mpi->planes[0] + in_off_right,
|
2010-11-14 15:24:12 +00:00
|
|
|
3 * vf->priv->width,
|
|
|
|
vf->priv->height,
|
2011-06-19 08:33:57 +00:00
|
|
|
dmpi->stride[0] * vf->priv->row_step,
|
2015-03-19 23:12:03 +00:00
|
|
|
mpi->stride[0] * vf->priv->row_step);
|
2010-10-22 17:46:12 +00:00
|
|
|
break;
|
|
|
|
case MONO_L:
|
|
|
|
case MONO_R:
|
2010-11-14 15:24:12 +00:00
|
|
|
memcpy_pic(dmpi->planes[0],
|
2010-11-14 15:33:25 +00:00
|
|
|
mpi->planes[0] + in_off_left,
|
2010-11-14 15:24:12 +00:00
|
|
|
3 * vf->priv->width,
|
|
|
|
vf->priv->height,
|
2010-11-14 15:33:25 +00:00
|
|
|
dmpi->stride[0],
|
|
|
|
mpi->stride[0]);
|
2010-10-22 17:46:12 +00:00
|
|
|
break;
|
|
|
|
case ANAGLYPH_RC_GRAY:
|
|
|
|
case ANAGLYPH_RC_HALF:
|
|
|
|
case ANAGLYPH_RC_COLOR:
|
|
|
|
case ANAGLYPH_RC_DUBOIS:
|
|
|
|
case ANAGLYPH_GM_GRAY:
|
|
|
|
case ANAGLYPH_GM_HALF:
|
|
|
|
case ANAGLYPH_GM_COLOR:
|
2013-01-31 12:12:36 +00:00
|
|
|
case ANAGLYPH_GM_DUBOIS:
|
2010-10-22 17:46:12 +00:00
|
|
|
case ANAGLYPH_YB_GRAY:
|
|
|
|
case ANAGLYPH_YB_HALF:
|
2013-01-31 12:12:36 +00:00
|
|
|
case ANAGLYPH_YB_COLOR:
|
|
|
|
case ANAGLYPH_YB_DUBOIS: {
|
2010-10-22 17:46:12 +00:00
|
|
|
int x,y,il,ir,o;
|
|
|
|
unsigned char *source = mpi->planes[0];
|
|
|
|
unsigned char *dest = dmpi->planes[0];
|
|
|
|
unsigned int out_width = vf->priv->out.width;
|
|
|
|
int *ana_matrix[3];
|
|
|
|
|
|
|
|
for(int i = 0; i < 3; i++)
|
|
|
|
ana_matrix[i] = vf->priv->ana_matrix[i];
|
|
|
|
|
|
|
|
for (y = 0; y < vf->priv->out.height; y++) {
|
2010-11-14 15:33:25 +00:00
|
|
|
o = dmpi->stride[0] * y;
|
|
|
|
il = in_off_left + y * mpi->stride[0];
|
|
|
|
ir = in_off_right + y * mpi->stride[0];
|
2010-10-22 17:46:12 +00:00
|
|
|
for (x = 0; x < out_width; x++) {
|
|
|
|
dest[o ] = ana_convert(
|
|
|
|
ana_matrix[0], source + il, source + ir); //red out
|
|
|
|
dest[o + 1] = ana_convert(
|
|
|
|
ana_matrix[1], source + il, source + ir); //green out
|
|
|
|
dest[o + 2] = ana_convert(
|
|
|
|
ana_matrix[2], source + il, source + ir); //blue out
|
|
|
|
il += 3;
|
|
|
|
ir += 3;
|
|
|
|
o += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_WARN(vf, "[stereo3d] stereo format of output is not supported\n");
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
return NULL;
|
2010-10-22 17:46:12 +00:00
|
|
|
break;
|
|
|
|
}
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
|
|
|
|
talloc_free(mpi);
|
|
|
|
return dmpi;
|
2010-10-22 17:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
|
|
|
{
|
|
|
|
switch (fmt)
|
|
|
|
case IMGFMT_RGB24:
|
|
|
|
return vf_next_query_format(vf, fmt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-21 21:51:34 +00:00
|
|
|
const struct m_opt_choice_alternatives stereo_code_names[] = {
|
2010-10-22 17:46:12 +00:00
|
|
|
{"arcg", ANAGLYPH_RC_GRAY},
|
|
|
|
{"anaglyph_red_cyan_gray", ANAGLYPH_RC_GRAY},
|
|
|
|
{"arch", ANAGLYPH_RC_HALF},
|
|
|
|
{"anaglyph_red_cyan_half_color", ANAGLYPH_RC_HALF},
|
|
|
|
{"arcc", ANAGLYPH_RC_COLOR},
|
|
|
|
{"anaglyph_red_cyan_color", ANAGLYPH_RC_COLOR},
|
|
|
|
{"arcd", ANAGLYPH_RC_DUBOIS},
|
|
|
|
{"anaglyph_red_cyan_dubios", ANAGLYPH_RC_DUBOIS},
|
|
|
|
{"agmg", ANAGLYPH_GM_GRAY},
|
|
|
|
{"anaglyph_green_magenta_gray", ANAGLYPH_GM_GRAY},
|
|
|
|
{"agmh", ANAGLYPH_GM_HALF},
|
|
|
|
{"anaglyph_green_magenta_half_color",ANAGLYPH_GM_HALF},
|
|
|
|
{"agmc", ANAGLYPH_GM_COLOR},
|
|
|
|
{"anaglyph_green_magenta_color", ANAGLYPH_GM_COLOR},
|
2013-01-31 12:12:36 +00:00
|
|
|
{"agmd", ANAGLYPH_GM_DUBOIS},
|
|
|
|
{"anaglyph_green_magenta_dubois", ANAGLYPH_GM_DUBOIS},
|
2010-10-22 17:46:12 +00:00
|
|
|
{"aybg", ANAGLYPH_YB_GRAY},
|
|
|
|
{"anaglyph_yellow_blue_gray", ANAGLYPH_YB_GRAY},
|
|
|
|
{"aybh", ANAGLYPH_YB_HALF},
|
|
|
|
{"anaglyph_yellow_blue_half_color", ANAGLYPH_YB_HALF},
|
|
|
|
{"aybc", ANAGLYPH_YB_COLOR},
|
|
|
|
{"anaglyph_yellow_blue_color", ANAGLYPH_YB_COLOR},
|
2012-08-12 17:20:24 +00:00
|
|
|
{"aybd", ANAGLYPH_YB_DUBOIS},
|
|
|
|
{"anaglyph_yellow_blue_dubois", ANAGLYPH_YB_DUBOIS},
|
2010-10-22 17:46:12 +00:00
|
|
|
{"ml", MONO_L},
|
|
|
|
{"mono_left", MONO_L},
|
|
|
|
{"mr", MONO_R},
|
|
|
|
{"mono_right", MONO_R},
|
|
|
|
{"sbsl", SIDE_BY_SIDE_LR},
|
|
|
|
{"side_by_side_left_first", SIDE_BY_SIDE_LR},
|
|
|
|
{"sbsr", SIDE_BY_SIDE_RL},
|
|
|
|
{"side_by_side_right_first", SIDE_BY_SIDE_RL},
|
2011-07-11 21:54:53 +00:00
|
|
|
{"sbs2l", SIDE_BY_SIDE_2_LR},
|
|
|
|
{"side_by_side_half_width_left_first", SIDE_BY_SIDE_2_LR},
|
|
|
|
{"sbs2r", SIDE_BY_SIDE_2_RL},
|
|
|
|
{"side_by_side_half_width_right_first",SIDE_BY_SIDE_2_RL},
|
2010-10-22 17:46:12 +00:00
|
|
|
{"abl", ABOVE_BELOW_LR},
|
|
|
|
{"above_below_left_first", ABOVE_BELOW_LR},
|
|
|
|
{"abr", ABOVE_BELOW_RL},
|
|
|
|
{"above_below_right_first", ABOVE_BELOW_RL},
|
|
|
|
{"ab2l", ABOVE_BELOW_2_LR},
|
|
|
|
{"above_below_half_height_left_first", ABOVE_BELOW_2_LR},
|
|
|
|
{"ab2r", ABOVE_BELOW_2_RL},
|
|
|
|
{"above_below_half_height_right_first",ABOVE_BELOW_2_RL},
|
2011-06-19 08:33:57 +00:00
|
|
|
{"irl", INTERLEAVE_ROWS_LR},
|
|
|
|
{"interleave_rows_left_first", INTERLEAVE_ROWS_LR},
|
|
|
|
{"irr", INTERLEAVE_ROWS_RL},
|
|
|
|
{"interleave_rows_right_first", INTERLEAVE_ROWS_RL},
|
2014-08-30 21:24:46 +00:00
|
|
|
// convenience alias for MP_STEREO3D_MONO
|
|
|
|
{"mono", MONO_L},
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
// for filter auto-insertion
|
|
|
|
{"auto", STEREO_AUTO},
|
2010-10-22 17:46:12 +00:00
|
|
|
{ NULL, 0}
|
|
|
|
};
|
|
|
|
|
2013-12-03 21:26:24 +00:00
|
|
|
// Fortunately, the short names are the same as the libavfilter port.
|
|
|
|
// The long names won't work, though.
|
|
|
|
static const char *rev_map_name(int val)
|
|
|
|
{
|
|
|
|
for (int n = 0; stereo_code_names[n].name; n++) {
|
|
|
|
if (stereo_code_names[n].value == val)
|
|
|
|
return stereo_code_names[n].name;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
// Extremely stupid; can be dropped when the internal filter is dropped,
|
2015-04-02 21:54:08 +00:00
|
|
|
// and OPT_CHOICE_C() can be used instead.
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
static int opt_to_stereo3dmode(int val)
|
|
|
|
{
|
|
|
|
// Find x for rev_map_name(val) == MP_STEREO3D_NAME(x)
|
|
|
|
const char *name = rev_map_name(val);
|
|
|
|
for (int n = 0; n < MP_STEREO3D_COUNT; n++) {
|
|
|
|
const char *o = MP_STEREO3D_NAME(val);
|
|
|
|
if (name && o && strcmp(o, name) == 0)
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
return MP_STEREO3D_INVALID;
|
|
|
|
}
|
|
|
|
static int stereo3dmode_to_opt(int val)
|
|
|
|
{
|
|
|
|
// Find x for rev_map_name(x) == MP_STEREO3D_NAME(val)
|
|
|
|
const char *name = MP_STEREO3D_NAME(val);
|
|
|
|
for (int n = 0; stereo_code_names[n].name; n++) {
|
|
|
|
if (name && strcmp(stereo_code_names[n].name, name) == 0)
|
|
|
|
return stereo_code_names[n].value;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool handle_auto_in(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
if (vf->priv->auto_in) {
|
|
|
|
int inv = stereo3dmode_to_opt(vf->fmt_in.stereo_in);
|
|
|
|
if (inv < 0) {
|
|
|
|
MP_ERR(vf, "Unknown/unsupported 3D mode.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
vf->priv->in.fmt = inv;
|
|
|
|
vf->fmt_out.stereo_in = vf->fmt_out.stereo_out =
|
|
|
|
opt_to_stereo3dmode(vf->priv->out.fmt);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-11 16:32:41 +00:00
|
|
|
#if HAVE_LIBAVFILTER
|
|
|
|
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
static int lavfi_reconfig(struct vf_instance *vf,
|
|
|
|
struct mp_image_params *in,
|
|
|
|
struct mp_image_params *out)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf_lw_old_priv(vf);
|
|
|
|
if (p->auto_in) {
|
|
|
|
const char *inf = MP_STEREO3D_NAME(in->stereo_in);
|
|
|
|
if (!inf) {
|
|
|
|
MP_ERR(vf, "Unknown/unsupported 3D mode.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
vf_lw_update_graph(vf, "stereo3d", "%s:%s",
|
|
|
|
inf, rev_map_name(p->out.fmt));
|
|
|
|
out->stereo_in = out->stereo_out = opt_to_stereo3dmode(p->out.fmt);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-11 16:32:41 +00:00
|
|
|
static void lavfi_init(vf_instance_t *vf)
|
|
|
|
{
|
|
|
|
if (vf->priv->in.fmt == STEREO_AUTO &&
|
|
|
|
vf_lw_set_graph(vf, vf->priv->lw_opts, "stereo3d", "null") >= 0)
|
|
|
|
{
|
|
|
|
vf_lw_set_reconfig_cb(vf, lavfi_reconfig);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vf_lw_set_graph(vf, vf->priv->lw_opts, "stereo3d", "%s:%s",
|
|
|
|
rev_map_name(vf->priv->in.fmt),
|
|
|
|
rev_map_name(vf->priv->out.fmt)) >= 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
const struct m_sub_options vf_lw_conf = {0};
|
|
|
|
|
|
|
|
static void lavfi_init(vf_instance_t *vf)
|
|
|
|
{
|
|
|
|
// doing nothing will make it use the internal implementation
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-12-03 23:01:38 +00:00
|
|
|
static int vf_open(vf_instance_t *vf)
|
2013-12-03 21:26:24 +00:00
|
|
|
{
|
|
|
|
vf->config = config;
|
|
|
|
vf->filter = filter;
|
|
|
|
vf->query_format = query_format;
|
|
|
|
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
if (vf->priv->out.fmt == STEREO_AUTO) {
|
|
|
|
MP_FATAL(vf, "No autodetection for stereo output.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (vf->priv->in.fmt == STEREO_AUTO)
|
|
|
|
vf->priv->auto_in = 1;
|
|
|
|
|
2015-02-11 16:32:41 +00:00
|
|
|
lavfi_init(vf);
|
2013-12-03 21:26:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
#define OPT_BASE_STRUCT struct vf_priv_s
|
2010-10-22 17:46:12 +00:00
|
|
|
static const m_option_t vf_opts_fields[] = {
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
OPT_GENERAL(int, "in", in.fmt, 0, .type = CONF_TYPE_CHOICE,
|
|
|
|
.priv = (void *)stereo_code_names),
|
|
|
|
OPT_GENERAL(int, "out", out.fmt, 0, .type = CONF_TYPE_CHOICE,
|
|
|
|
.priv = (void *)stereo_code_names),
|
2013-12-03 21:26:24 +00:00
|
|
|
OPT_SUBSTRUCT("", lw_opts, vf_lw_conf, 0),
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
{0}
|
2010-10-22 17:46:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const vf_info_t vf_info_stereo3d = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "stereoscopic 3d view",
|
|
|
|
.name = "stereo3d",
|
|
|
|
.open = vf_open,
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
.priv_size = sizeof(struct vf_priv_s),
|
|
|
|
.priv_defaults = &vf_priv_default,
|
|
|
|
.options = vf_opts_fields,
|
2010-10-22 17:46:12 +00:00
|
|
|
};
|