2013-03-10 23:16:34 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* Filter graph creation code taken from Libav avplay.c (LGPL 2.1 or later)
|
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* mpv 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.
|
2013-03-10 23:16:34 +00:00
|
|
|
*
|
|
|
|
* mpv 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
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-03-10 23:16:34 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2013-03-10 23:16:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-10-09 16:18:05 +00:00
|
|
|
#include <math.h>
|
2013-03-10 23:16:34 +00:00
|
|
|
#include <inttypes.h>
|
2013-12-03 21:19:27 +00:00
|
|
|
#include <stdarg.h>
|
2013-03-10 23:16:34 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <libavutil/avstring.h>
|
video: support filtering hardware frames via libavfilter
Requires a bunch of hacks:
- we access AVFilterLink.hw_frames_ctx. This is not a public API in
FFmpeg and Libav. Newer FFmpeg provides an accessor
(av_buffersink_get_hw_frames_ctx), but it's not available in Libav or
the current FFmpeg release or Libav. We need this value after filter
graph creation, so We have no choice but to access this.
One alternative is making filter creation and format negotiation
fully lazy (i.e. delay it and do it as filters are output), but this
would be a huge change.
So for now, we knowingly violate FFmpeg's and Libav's ABI and API
constraints because they don't provide anything better.
On newer FFmpeg, we use the (quite ugly) accessor, though.
- mp_image_params doesn't (and can't) have a field for the frames
context AVBufferRef. So we pass it via vf_set_proto_frame(), and even
more hacks.
- if a filter needs a hw context, but we haven't created one yet
(because normally we create them lazily), it will fail at init.
- we allow any hw format now, although this could go horrible wrong.
Why all this effort? We could move hw deinterlacing filters etc. to
FFmpeg, which is a very worthy goal.
2017-01-16 14:52:13 +00:00
|
|
|
#include <libavutil/hwcontext.h>
|
2013-03-10 23:16:34 +00:00
|
|
|
#include <libavutil/mem.h>
|
|
|
|
#include <libavutil/mathematics.h>
|
|
|
|
#include <libavutil/rational.h>
|
|
|
|
#include <libavutil/pixdesc.h>
|
|
|
|
#include <libavutil/time.h>
|
2014-04-28 17:50:32 +00:00
|
|
|
#include <libavutil/error.h>
|
2013-03-10 23:16:34 +00:00
|
|
|
#include <libswscale/swscale.h>
|
|
|
|
#include <libavfilter/avfilter.h>
|
|
|
|
#include <libavfilter/avfiltergraph.h>
|
|
|
|
#include <libavfilter/buffersink.h>
|
|
|
|
#include <libavfilter/buffersrc.h>
|
|
|
|
|
2015-02-11 16:32:41 +00:00
|
|
|
#include "config.h"
|
2014-08-02 01:12:09 +00:00
|
|
|
#include "common/av_common.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2014-04-13 14:04:23 +00:00
|
|
|
#include "common/tags.h"
|
2013-03-10 23:16:34 +00:00
|
|
|
|
video: support filtering hardware frames via libavfilter
Requires a bunch of hacks:
- we access AVFilterLink.hw_frames_ctx. This is not a public API in
FFmpeg and Libav. Newer FFmpeg provides an accessor
(av_buffersink_get_hw_frames_ctx), but it's not available in Libav or
the current FFmpeg release or Libav. We need this value after filter
graph creation, so We have no choice but to access this.
One alternative is making filter creation and format negotiation
fully lazy (i.e. delay it and do it as filters are output), but this
would be a huge change.
So for now, we knowingly violate FFmpeg's and Libav's ABI and API
constraints because they don't provide anything better.
On newer FFmpeg, we use the (quite ugly) accessor, though.
- mp_image_params doesn't (and can't) have a field for the frames
context AVBufferRef. So we pass it via vf_set_proto_frame(), and even
more hacks.
- if a filter needs a hw context, but we haven't created one yet
(because normally we create them lazily), it will fail at init.
- we allow any hw format now, although this could go horrible wrong.
Why all this effort? We could move hw deinterlacing filters etc. to
FFmpeg, which is a very worthy goal.
2017-01-16 14:52:13 +00:00
|
|
|
#include "video/hwdec.h"
|
2013-03-10 23:16:34 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "video/sws_utils.h"
|
|
|
|
#include "video/fmt-conversion.h"
|
|
|
|
#include "vf.h"
|
2013-12-03 21:19:27 +00:00
|
|
|
#include "vf_lavfi.h"
|
2013-03-10 23:16:34 +00:00
|
|
|
|
2013-04-26 10:28:11 +00:00
|
|
|
// FFmpeg and Libav have slightly different APIs, just enough to cause us
|
|
|
|
// unnecessary pain. <Expletive deleted.>
|
2014-03-16 09:04:46 +00:00
|
|
|
#if LIBAVFILTER_VERSION_MICRO < 100
|
2013-04-26 10:28:11 +00:00
|
|
|
#define graph_parse(graph, filters, inputs, outputs, log_ctx) \
|
|
|
|
avfilter_graph_parse(graph, filters, inputs, outputs, log_ctx)
|
2016-01-22 19:53:52 +00:00
|
|
|
#define avfilter_graph_send_command(a, b, c, d, e, f, g) -1
|
2013-04-26 10:28:11 +00:00
|
|
|
#else
|
|
|
|
#define graph_parse(graph, filters, inputs, outputs, log_ctx) \
|
2014-04-11 10:21:14 +00:00
|
|
|
avfilter_graph_parse_ptr(graph, filters, &(inputs), &(outputs), log_ctx)
|
2013-04-26 10:28:11 +00:00
|
|
|
#endif
|
|
|
|
|
2013-03-10 23:16:34 +00:00
|
|
|
struct vf_priv_s {
|
|
|
|
AVFilterGraph *graph;
|
|
|
|
AVFilterContext *in;
|
|
|
|
AVFilterContext *out;
|
2014-05-01 16:42:53 +00:00
|
|
|
bool eof;
|
2013-03-10 23:16:34 +00:00
|
|
|
|
|
|
|
AVRational timebase_in;
|
|
|
|
AVRational timebase_out;
|
|
|
|
AVRational par_in;
|
|
|
|
|
2015-09-11 21:05:14 +00:00
|
|
|
struct mp_tags *metadata;
|
2014-04-13 14:04:23 +00:00
|
|
|
|
2013-12-03 21:19:27 +00:00
|
|
|
// for the lw wrapper
|
|
|
|
void *old_priv;
|
2014-09-27 15:14:23 +00:00
|
|
|
int (*lw_reconfig_cb)(struct vf_instance *vf,
|
|
|
|
struct mp_image_params *in,
|
|
|
|
struct mp_image_params *out);
|
2013-12-03 21:19:27 +00:00
|
|
|
|
2013-03-10 23:16:34 +00:00
|
|
|
// options
|
|
|
|
char *cfg_graph;
|
|
|
|
int64_t cfg_sws_flags;
|
2014-08-02 01:12:09 +00:00
|
|
|
char **cfg_avopts;
|
2013-03-10 23:16:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct vf_priv_s vf_priv_dflt = {
|
|
|
|
.cfg_sws_flags = SWS_BICUBIC,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void destroy_graph(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
avfilter_graph_free(&p->graph);
|
2013-04-25 16:35:32 +00:00
|
|
|
p->in = p->out = NULL;
|
2014-05-01 16:42:53 +00:00
|
|
|
|
|
|
|
if (p->metadata) {
|
|
|
|
talloc_free(p->metadata);
|
|
|
|
p->metadata = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->eof = false;
|
2013-03-10 23:16:34 +00:00
|
|
|
}
|
|
|
|
|
2015-12-19 19:04:31 +00:00
|
|
|
static bool recreate_graph(struct vf_instance *vf, struct mp_image_params *fmt)
|
2013-03-10 23:16:34 +00:00
|
|
|
{
|
|
|
|
void *tmp = talloc_new(NULL);
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
2017-01-13 15:26:31 +00:00
|
|
|
AVFilterContext *in = NULL, *out = NULL;
|
2017-01-16 14:41:50 +00:00
|
|
|
int ret;
|
2013-03-10 23:16:34 +00:00
|
|
|
|
|
|
|
if (bstr0(p->cfg_graph).len == 0) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_FATAL(vf, "lavfi: no filter graph set\n");
|
2013-04-25 16:35:32 +00:00
|
|
|
return false;
|
2013-03-10 23:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
destroy_graph(vf);
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_VERBOSE(vf, "lavfi: create graph: '%s'\n", p->cfg_graph);
|
2013-03-10 23:16:34 +00:00
|
|
|
|
|
|
|
AVFilterGraph *graph = avfilter_graph_alloc();
|
|
|
|
if (!graph)
|
|
|
|
goto error;
|
|
|
|
|
2014-08-02 01:12:09 +00:00
|
|
|
if (mp_set_avopts(vf->log, graph, p->cfg_avopts) < 0)
|
2013-05-25 13:53:55 +00:00
|
|
|
goto error;
|
|
|
|
|
2013-03-10 23:16:34 +00:00
|
|
|
AVFilterInOut *outputs = avfilter_inout_alloc();
|
|
|
|
AVFilterInOut *inputs = avfilter_inout_alloc();
|
|
|
|
if (!outputs || !inputs)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
char *sws_flags = talloc_asprintf(tmp, "flags=%"PRId64, p->cfg_sws_flags);
|
|
|
|
graph->scale_sws_opts = av_strdup(sws_flags);
|
|
|
|
|
2017-01-16 14:41:50 +00:00
|
|
|
in = avfilter_graph_alloc_filter(graph, avfilter_get_by_name("buffer"), "src");
|
|
|
|
if (!in)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
AVBufferSrcParameters *in_params = av_buffersrc_parameters_alloc();
|
|
|
|
if (!in_params)
|
|
|
|
goto error;
|
2013-03-10 23:16:34 +00:00
|
|
|
|
2017-01-16 14:41:50 +00:00
|
|
|
in_params->format = imgfmt2pixfmt(fmt->imgfmt);
|
|
|
|
in_params->time_base = AV_TIME_BASE_Q;
|
|
|
|
in_params->width = fmt->w;
|
|
|
|
in_params->height = fmt->h;
|
|
|
|
in_params->sample_aspect_ratio.num = fmt->p_w;
|
|
|
|
in_params->sample_aspect_ratio.den = fmt->p_h;
|
video: support filtering hardware frames via libavfilter
Requires a bunch of hacks:
- we access AVFilterLink.hw_frames_ctx. This is not a public API in
FFmpeg and Libav. Newer FFmpeg provides an accessor
(av_buffersink_get_hw_frames_ctx), but it's not available in Libav or
the current FFmpeg release or Libav. We need this value after filter
graph creation, so We have no choice but to access this.
One alternative is making filter creation and format negotiation
fully lazy (i.e. delay it and do it as filters are output), but this
would be a huge change.
So for now, we knowingly violate FFmpeg's and Libav's ABI and API
constraints because they don't provide anything better.
On newer FFmpeg, we use the (quite ugly) accessor, though.
- mp_image_params doesn't (and can't) have a field for the frames
context AVBufferRef. So we pass it via vf_set_proto_frame(), and even
more hacks.
- if a filter needs a hw context, but we haven't created one yet
(because normally we create them lazily), it will fail at init.
- we allow any hw format now, although this could go horrible wrong.
Why all this effort? We could move hw deinterlacing filters etc. to
FFmpeg, which is a very worthy goal.
2017-01-16 14:52:13 +00:00
|
|
|
// Assume it's ignored for non-hwaccel formats.
|
|
|
|
in_params->hw_frames_ctx = vf->in_hwframes_ref;
|
2017-01-16 14:41:50 +00:00
|
|
|
|
|
|
|
ret = av_buffersrc_parameters_set(in, in_params);
|
|
|
|
av_free(in_params);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
2013-03-10 23:16:34 +00:00
|
|
|
|
2017-01-16 14:41:50 +00:00
|
|
|
if (avfilter_init_str(in, NULL) < 0)
|
2013-03-10 23:16:34 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (avfilter_graph_create_filter(&out, avfilter_get_by_name("buffersink"),
|
|
|
|
"out", NULL, NULL, graph) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
outputs->name = av_strdup("in");
|
|
|
|
outputs->filter_ctx = in;
|
|
|
|
|
|
|
|
inputs->name = av_strdup("out");
|
2017-01-13 15:26:31 +00:00
|
|
|
inputs->filter_ctx = out;
|
2013-03-10 23:16:34 +00:00
|
|
|
|
|
|
|
if (graph_parse(graph, p->cfg_graph, inputs, outputs, NULL) < 0)
|
|
|
|
goto error;
|
|
|
|
|
video: support filtering hardware frames via libavfilter
Requires a bunch of hacks:
- we access AVFilterLink.hw_frames_ctx. This is not a public API in
FFmpeg and Libav. Newer FFmpeg provides an accessor
(av_buffersink_get_hw_frames_ctx), but it's not available in Libav or
the current FFmpeg release or Libav. We need this value after filter
graph creation, so We have no choice but to access this.
One alternative is making filter creation and format negotiation
fully lazy (i.e. delay it and do it as filters are output), but this
would be a huge change.
So for now, we knowingly violate FFmpeg's and Libav's ABI and API
constraints because they don't provide anything better.
On newer FFmpeg, we use the (quite ugly) accessor, though.
- mp_image_params doesn't (and can't) have a field for the frames
context AVBufferRef. So we pass it via vf_set_proto_frame(), and even
more hacks.
- if a filter needs a hw context, but we haven't created one yet
(because normally we create them lazily), it will fail at init.
- we allow any hw format now, although this could go horrible wrong.
Why all this effort? We could move hw deinterlacing filters etc. to
FFmpeg, which is a very worthy goal.
2017-01-16 14:52:13 +00:00
|
|
|
struct mp_hwdec_ctx *hwdec = hwdec_devices_get_first(vf->hwdec_devs);
|
|
|
|
for (int n = 0; n < graph->nb_filters; n++) {
|
|
|
|
AVFilterContext *filter = graph->filters[n];
|
|
|
|
if (hwdec && hwdec->av_device_ref)
|
|
|
|
filter->hw_device_ctx = av_buffer_ref(hwdec->av_device_ref);
|
|
|
|
}
|
|
|
|
|
2013-03-10 23:16:34 +00:00
|
|
|
if (avfilter_graph_config(graph, NULL) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
p->in = in;
|
|
|
|
p->out = out;
|
|
|
|
p->graph = graph;
|
|
|
|
|
|
|
|
assert(out->nb_inputs == 1);
|
|
|
|
assert(in->nb_outputs == 1);
|
2013-04-25 16:35:32 +00:00
|
|
|
|
|
|
|
talloc_free(tmp);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_FATAL(vf, "Can't configure libavfilter graph.\n");
|
2013-04-25 16:35:32 +00:00
|
|
|
avfilter_graph_free(&graph);
|
|
|
|
talloc_free(tmp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-01 16:42:53 +00:00
|
|
|
static void reset(vf_instance_t *vf)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
struct mp_image_params *f = &vf->fmt_in;
|
|
|
|
if (p->graph && f->imgfmt)
|
2015-12-19 19:04:31 +00:00
|
|
|
recreate_graph(vf, f);
|
2014-05-01 16:42:53 +00:00
|
|
|
}
|
|
|
|
|
2014-09-27 15:14:23 +00:00
|
|
|
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
|
|
|
|
struct mp_image_params *out)
|
2013-04-25 16:35:32 +00:00
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
|
2014-09-27 15:14:23 +00:00
|
|
|
*out = *in; // pass-through untouched flags
|
|
|
|
|
|
|
|
if (vf->priv->lw_reconfig_cb) {
|
|
|
|
if (vf->priv->lw_reconfig_cb(vf, in, out) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-12-19 19:04:31 +00:00
|
|
|
if (!recreate_graph(vf, in))
|
2014-09-27 15:14:23 +00:00
|
|
|
return -1;
|
2013-04-25 16:35:32 +00:00
|
|
|
|
|
|
|
AVFilterLink *l_out = p->out->inputs[0];
|
|
|
|
AVFilterLink *l_in = p->in->outputs[0];
|
2013-03-10 23:16:34 +00:00
|
|
|
|
|
|
|
p->timebase_in = l_in->time_base;
|
|
|
|
p->timebase_out = l_out->time_base;
|
|
|
|
|
|
|
|
p->par_in = l_in->sample_aspect_ratio;
|
|
|
|
|
2014-09-27 15:14:23 +00:00
|
|
|
out->w = l_out->w;
|
|
|
|
out->h = l_out->h;
|
2015-12-19 19:04:31 +00:00
|
|
|
out->p_w = l_out->sample_aspect_ratio.num;
|
|
|
|
out->p_h = l_out->sample_aspect_ratio.den;
|
2014-09-27 15:14:23 +00:00
|
|
|
out->imgfmt = pixfmt2imgfmt(l_out->format);
|
video: support filtering hardware frames via libavfilter
Requires a bunch of hacks:
- we access AVFilterLink.hw_frames_ctx. This is not a public API in
FFmpeg and Libav. Newer FFmpeg provides an accessor
(av_buffersink_get_hw_frames_ctx), but it's not available in Libav or
the current FFmpeg release or Libav. We need this value after filter
graph creation, so We have no choice but to access this.
One alternative is making filter creation and format negotiation
fully lazy (i.e. delay it and do it as filters are output), but this
would be a huge change.
So for now, we knowingly violate FFmpeg's and Libav's ABI and API
constraints because they don't provide anything better.
On newer FFmpeg, we use the (quite ugly) accessor, though.
- mp_image_params doesn't (and can't) have a field for the frames
context AVBufferRef. So we pass it via vf_set_proto_frame(), and even
more hacks.
- if a filter needs a hw context, but we haven't created one yet
(because normally we create them lazily), it will fail at init.
- we allow any hw format now, although this could go horrible wrong.
Why all this effort? We could move hw deinterlacing filters etc. to
FFmpeg, which is a very worthy goal.
2017-01-16 14:52:13 +00:00
|
|
|
av_buffer_unref(&vf->out_hwframes_ref);
|
|
|
|
#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(6, 69, 100) && \
|
|
|
|
LIBAVFILTER_VERSION_MICRO >= 100
|
|
|
|
AVBufferRef *hw_frames_ctx = av_buffersink_get_hw_frames_ctx(p->out);
|
|
|
|
#else
|
|
|
|
AVBufferRef *hw_frames_ctx = l_out->hw_frames_ctx;
|
|
|
|
#endif
|
|
|
|
if (hw_frames_ctx) {
|
|
|
|
AVHWFramesContext *fctx = (void *)hw_frames_ctx->data;
|
|
|
|
out->hw_subfmt = pixfmt2imgfmt(fctx->sw_format);
|
|
|
|
vf->out_hwframes_ref = av_buffer_ref(hw_frames_ctx);
|
|
|
|
}
|
2014-09-27 15:14:23 +00:00
|
|
|
return 0;
|
2013-03-10 23:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
|
|
|
{
|
video: support filtering hardware frames via libavfilter
Requires a bunch of hacks:
- we access AVFilterLink.hw_frames_ctx. This is not a public API in
FFmpeg and Libav. Newer FFmpeg provides an accessor
(av_buffersink_get_hw_frames_ctx), but it's not available in Libav or
the current FFmpeg release or Libav. We need this value after filter
graph creation, so We have no choice but to access this.
One alternative is making filter creation and format negotiation
fully lazy (i.e. delay it and do it as filters are output), but this
would be a huge change.
So for now, we knowingly violate FFmpeg's and Libav's ABI and API
constraints because they don't provide anything better.
On newer FFmpeg, we use the (quite ugly) accessor, though.
- mp_image_params doesn't (and can't) have a field for the frames
context AVBufferRef. So we pass it via vf_set_proto_frame(), and even
more hacks.
- if a filter needs a hw context, but we haven't created one yet
(because normally we create them lazily), it will fail at init.
- we allow any hw format now, although this could go horrible wrong.
Why all this effort? We could move hw deinterlacing filters etc. to
FFmpeg, which is a very worthy goal.
2017-01-16 14:52:13 +00:00
|
|
|
// Format negotiation is not possible with libavfilter.
|
|
|
|
return 1;
|
2013-03-10 23:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static AVFrame *mp_to_av(struct vf_instance *vf, struct mp_image *img)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
video: don't drop last frame when deinterlacing with yadif
Or in other words, add support for properly draining remaining frames
from video filters. vf_yadif is buffering at least one frame, and the
buffered frame was not retrieved on EOF.
For most filters, ignore this for now, and just adjust them to the
changed semantics of filter_ext. But for vf_lavfi (used by vf_yadif),
real support is implemented. libavfilter handles this simply by passing
a NULL frame to av_buffersrc_add_frame(), so we just have to make
mp_to_av() handle NULL arguments.
In load_next_vo_frame(), we first try to output a frame buffered in the
VO, then the filter, and then (if EOF is reached and there's still no
new frame) the VO again, with draining enabled. I guess this was
implemented slightly incorrectly before, because the filter chain still
could have had remaining output frames.
2014-04-28 17:44:35 +00:00
|
|
|
if (!img)
|
|
|
|
return NULL;
|
2013-03-10 23:16:34 +00:00
|
|
|
uint64_t pts = img->pts == MP_NOPTS_VALUE ?
|
|
|
|
AV_NOPTS_VALUE : img->pts * av_q2d(av_inv_q(p->timebase_in));
|
|
|
|
AVFrame *frame = mp_image_to_av_frame_and_unref(img);
|
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 (!frame)
|
|
|
|
return NULL; // OOM is (coincidentally) handled as EOF
|
2013-03-10 23:16:34 +00:00
|
|
|
frame->pts = pts;
|
|
|
|
frame->sample_aspect_ratio = p->par_in;
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mp_image *av_to_mp(struct vf_instance *vf, AVFrame *av_frame)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
struct mp_image *img = mp_image_from_av_frame(av_frame);
|
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 (!img)
|
|
|
|
return NULL; // OOM
|
2013-03-10 23:16:34 +00:00
|
|
|
img->pts = av_frame->pts == AV_NOPTS_VALUE ?
|
|
|
|
MP_NOPTS_VALUE : av_frame->pts * av_q2d(p->timebase_out);
|
|
|
|
av_frame_free(&av_frame);
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
2014-04-13 14:04:23 +00:00
|
|
|
static void get_metadata_from_av_frame(struct vf_instance *vf, AVFrame *frame)
|
|
|
|
{
|
|
|
|
#if HAVE_AVFRAME_METADATA
|
2015-09-11 21:05:14 +00:00
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
if (!p->metadata)
|
|
|
|
p->metadata = talloc_zero(p, struct mp_tags);
|
2014-04-13 14:04:23 +00:00
|
|
|
|
2015-09-11 21:05:14 +00:00
|
|
|
mp_tags_copy_from_av_dictionary(p->metadata, av_frame_get_metadata(frame));
|
2014-04-13 14:04:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-03-10 23:16:34 +00:00
|
|
|
static int filter_ext(struct vf_instance *vf, struct mp_image *mpi)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
|
2014-05-01 16:42:53 +00:00
|
|
|
if (p->eof && mpi) {
|
|
|
|
// Once EOF is reached, libavfilter is "stuck" in the EOF state, and
|
|
|
|
// won't accept new input. Forcefully override it. This helps e.g.
|
|
|
|
// with cover art, where we always want to generate new output.
|
|
|
|
reset(vf);
|
|
|
|
}
|
|
|
|
|
2013-03-10 23:16:34 +00:00
|
|
|
if (!p->graph)
|
|
|
|
return -1;
|
|
|
|
|
af_lavfi, vf_lavfi: work around recent libavfilter EOF bug
Looks quite like a bug. If you have a filter chain with only the
dynaudnorm filter, and send call av_buffersrc_add_frame(s, NULL), then
subsequent av_buffersink_get_frame() calls will return EAGAIN instead of
EOF.
This was apparently caused by a recent change in FFmpeg.
Some other circumstances (which I didn't fully analyze and which is due
to the playloop's absurd temporary-EOF behavior on seeks) then led the
decoder loop to send data again, but since libavfilter was stuck in the
EOF state now, it could never recover. It kept sending new input (due to
missing output), until the demuxer refused to return more audio packets.
Each time a filter error was printed.
Fortunately, it's pretty easy to workaround. We just mark the p->eof
flag as we send an EOF frame to libavfilter. The p->eof flag is used
only to recover from temporary EOF: it resets the filter if new data is
available again. We don't care much about av_buffersink_get_frame()
returning a broken EAGAIN state in this situation and essentially ignore
it, meaning if we get EAGAIN after sending EOF, we assume effectively
that EOF was fully reached.
2017-01-02 17:12:51 +00:00
|
|
|
if (!mpi) {
|
|
|
|
if (p->eof)
|
|
|
|
return 0;
|
|
|
|
p->eof = true;
|
|
|
|
}
|
|
|
|
|
2013-03-10 23:16:34 +00:00
|
|
|
AVFrame *frame = mp_to_av(vf, mpi);
|
2014-09-18 17:26:13 +00:00
|
|
|
int r = av_buffersrc_add_frame(p->in, frame) < 0 ? -1 : 0;
|
2013-03-10 23:16:34 +00:00
|
|
|
av_frame_free(&frame);
|
|
|
|
|
2014-09-18 17:26:13 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_out(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
2014-04-13 14:04:23 +00:00
|
|
|
|
2014-09-18 17:26:13 +00:00
|
|
|
AVFrame *frame = av_frame_alloc();
|
|
|
|
int err = av_buffersink_get_frame(p->out, frame);
|
|
|
|
if (err == AVERROR(EAGAIN) || err == AVERROR_EOF) {
|
|
|
|
// Not an error situation - no more output buffers in queue.
|
|
|
|
// AVERROR_EOF means we shouldn't even give the filter more
|
|
|
|
// input, but we don't handle that completely correctly.
|
|
|
|
av_frame_free(&frame);
|
|
|
|
p->eof |= err == AVERROR_EOF;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (err < 0) {
|
|
|
|
av_frame_free(&frame);
|
|
|
|
MP_ERR(vf, "libavfilter error: %d\n", err);
|
|
|
|
return -1;
|
2013-03-10 23:16:34 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 17:26:13 +00:00
|
|
|
get_metadata_from_av_frame(vf, frame);
|
|
|
|
vf_add_output_frame(vf, av_to_mp(vf, frame));
|
2013-03-10 23:16:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-03 21:19:27 +00:00
|
|
|
static int control(vf_instance_t *vf, int request, void *data)
|
|
|
|
{
|
2013-04-25 16:35:32 +00:00
|
|
|
switch (request) {
|
|
|
|
case VFCTRL_SEEK_RESET:
|
2013-12-03 21:19:27 +00:00
|
|
|
reset(vf);
|
2013-12-07 18:33:38 +00:00
|
|
|
return CONTROL_OK;
|
2016-01-22 15:18:28 +00:00
|
|
|
case VFCTRL_COMMAND: {
|
|
|
|
if (!vf->priv->graph)
|
|
|
|
break;
|
|
|
|
char **args = data;
|
|
|
|
return avfilter_graph_send_command(vf->priv->graph, "all",
|
|
|
|
args[0], args[1], &(char){0}, 0, 0)
|
|
|
|
>= 0 ? CONTROL_OK : CONTROL_ERROR;
|
|
|
|
}
|
2014-04-29 15:00:52 +00:00
|
|
|
case VFCTRL_GET_METADATA:
|
2015-09-11 21:05:14 +00:00
|
|
|
if (vf->priv && vf->priv->metadata) {
|
|
|
|
*(struct mp_tags *)data = *vf->priv->metadata;
|
|
|
|
return CONTROL_OK;
|
|
|
|
} else {
|
|
|
|
return CONTROL_NA;
|
|
|
|
}
|
2013-04-25 16:35:32 +00:00
|
|
|
}
|
2013-12-07 18:33:38 +00:00
|
|
|
return CONTROL_UNKNOWN;
|
2013-04-25 16:35:32 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 23:16:34 +00:00
|
|
|
static void uninit(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
if (!vf->priv)
|
|
|
|
return;
|
|
|
|
destroy_graph(vf);
|
|
|
|
}
|
|
|
|
|
2013-12-03 23:01:38 +00:00
|
|
|
static int vf_open(vf_instance_t *vf)
|
2013-03-10 23:16:34 +00:00
|
|
|
{
|
2014-09-27 15:14:23 +00:00
|
|
|
vf->reconfig = reconfig;
|
2013-03-10 23:16:34 +00:00
|
|
|
vf->filter_ext = filter_ext;
|
2014-09-18 17:26:13 +00:00
|
|
|
vf->filter_out = filter_out;
|
2013-12-03 21:19:27 +00:00
|
|
|
vf->filter = NULL;
|
2013-03-10 23:16:34 +00:00
|
|
|
vf->query_format = query_format;
|
2013-04-25 16:35:32 +00:00
|
|
|
vf->control = control;
|
2013-03-10 23:16:34 +00:00
|
|
|
vf->uninit = uninit;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:35:52 +00:00
|
|
|
static bool is_single_video_only(const AVFilterPad *pads)
|
|
|
|
{
|
2013-12-18 16:13:13 +00:00
|
|
|
int count = avfilter_pad_count(pads);
|
|
|
|
if (count != 1)
|
2013-11-23 20:35:52 +00:00
|
|
|
return false;
|
2013-12-18 16:13:13 +00:00
|
|
|
return avfilter_pad_get_type(pads, 0) == AVMEDIA_TYPE_VIDEO;
|
2013-11-23 20:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Does it have exactly one video input and one video output?
|
|
|
|
static bool is_usable(const AVFilter *filter)
|
|
|
|
{
|
|
|
|
return is_single_video_only(filter->inputs) &&
|
|
|
|
is_single_video_only(filter->outputs);
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:04:49 +00:00
|
|
|
static void print_help(struct mp_log *log)
|
2013-11-23 20:35:52 +00:00
|
|
|
{
|
2013-12-21 19:04:49 +00:00
|
|
|
mp_info(log, "List of libavfilter filters:\n");
|
2013-11-23 20:35:52 +00:00
|
|
|
for (const AVFilter *filter = avfilter_next(NULL); filter;
|
|
|
|
filter = avfilter_next(filter))
|
|
|
|
{
|
2013-12-21 19:04:49 +00:00
|
|
|
if (is_usable(filter))
|
|
|
|
mp_info(log, " %-16s %s\n", filter->name, filter->description);
|
2013-11-23 20:35:52 +00:00
|
|
|
}
|
2013-12-21 19:04:49 +00:00
|
|
|
mp_info(log, "\n"
|
2013-11-23 20:35:52 +00:00
|
|
|
"This lists video->video filters only. Refer to\n"
|
|
|
|
"\n"
|
|
|
|
" https://ffmpeg.org/ffmpeg-filters.html\n"
|
|
|
|
"\n"
|
|
|
|
"to see how to use each filter and what arguments each filter takes.\n"
|
|
|
|
"Also, be sure to quote the FFmpeg filter string properly, e.g.:\n"
|
|
|
|
"\n"
|
|
|
|
" \"--vf=lavfi=[gradfun=20:30]\"\n"
|
|
|
|
"\n"
|
|
|
|
"Otherwise, mpv and libavfilter syntax will conflict.\n"
|
|
|
|
"\n");
|
|
|
|
}
|
|
|
|
|
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
|
2013-03-10 23:16:34 +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_STRING("graph", cfg_graph, M_OPT_MIN, .min = 1),
|
2013-12-03 21:19:27 +00:00
|
|
|
OPT_INT64("sws-flags", cfg_sws_flags, 0),
|
2014-08-02 01:12:09 +00:00
|
|
|
OPT_KEYVALUELIST("o", cfg_avopts, 0),
|
2013-03-10 23:16:34 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
const vf_info_t vf_info_lavfi = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "libavfilter bridge",
|
|
|
|
.name = "lavfi",
|
|
|
|
.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_dflt,
|
|
|
|
.options = vf_opts_fields,
|
2013-11-23 20:35:52 +00:00
|
|
|
.print_help = print_help,
|
2013-03-10 23:16:34 +00:00
|
|
|
};
|
2013-12-03 21:19:27 +00:00
|
|
|
|
|
|
|
// The following code is for the old filters wrapper code.
|
|
|
|
|
|
|
|
struct vf_lw_opts {
|
|
|
|
int64_t sws_flags;
|
2014-08-02 01:12:09 +00:00
|
|
|
char **avopts;
|
2013-12-03 21:19:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#undef OPT_BASE_STRUCT
|
|
|
|
#define OPT_BASE_STRUCT struct vf_lw_opts
|
|
|
|
const struct m_sub_options vf_lw_conf = {
|
|
|
|
.opts = (const m_option_t[]) {
|
|
|
|
OPT_INT64("lavfi-sws-flags", sws_flags, 0),
|
2014-08-02 01:12:09 +00:00
|
|
|
OPT_KEYVALUELIST("lavfi-o", avopts, 0),
|
2013-12-03 21:19:27 +00:00
|
|
|
{0}
|
|
|
|
},
|
|
|
|
.defaults = &(const struct vf_lw_opts){
|
|
|
|
.sws_flags = SWS_BICUBIC,
|
|
|
|
},
|
|
|
|
.size = sizeof(struct vf_lw_opts),
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool have_filter(const char *name)
|
|
|
|
{
|
|
|
|
for (const AVFilter *filter = avfilter_next(NULL); filter;
|
|
|
|
filter = avfilter_next(filter))
|
|
|
|
{
|
|
|
|
if (strcmp(filter->name, name) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is used by "old" filters for wrapping lavfi if possible.
|
|
|
|
// On success, this overwrites all vf callbacks and literally takes over the
|
|
|
|
// old filter and replaces it with vf_lavfi.
|
|
|
|
// On error (<0), nothing is changed.
|
|
|
|
int vf_lw_set_graph(struct vf_instance *vf, struct vf_lw_opts *lavfi_opts,
|
|
|
|
char *filter, char *opts, ...)
|
|
|
|
{
|
|
|
|
if (!lavfi_opts)
|
|
|
|
lavfi_opts = (struct vf_lw_opts *)vf_lw_conf.defaults;
|
2015-02-12 10:53:40 +00:00
|
|
|
if (filter && !have_filter(filter))
|
2013-12-03 21:19:27 +00:00
|
|
|
return -1;
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_VERBOSE(vf, "Using libavfilter for '%s'\n", vf->info->name);
|
2013-12-03 21:19:27 +00:00
|
|
|
void *old_priv = vf->priv;
|
|
|
|
struct vf_priv_s *p = talloc(vf, struct vf_priv_s);
|
|
|
|
vf->priv = p;
|
|
|
|
*p = vf_priv_dflt;
|
|
|
|
p->cfg_sws_flags = lavfi_opts->sws_flags;
|
|
|
|
p->cfg_avopts = lavfi_opts->avopts;
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, opts);
|
|
|
|
char *s = talloc_vasprintf(vf, opts, ap);
|
2014-04-20 19:26:30 +00:00
|
|
|
p->cfg_graph = filter ? talloc_asprintf(vf, "%s=%s", filter, s)
|
|
|
|
: talloc_strdup(vf, s);
|
2013-12-03 21:19:27 +00:00
|
|
|
talloc_free(s);
|
|
|
|
va_end(ap);
|
|
|
|
p->old_priv = old_priv;
|
|
|
|
// Note: we should be sure vf_open really overwrites _all_ vf callbacks.
|
2013-12-03 23:01:38 +00:00
|
|
|
if (vf_open(vf) < 1)
|
2013-12-03 21:19:27 +00:00
|
|
|
abort();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *vf_lw_old_priv(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
return p->old_priv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vf_lw_update_graph(struct vf_instance *vf, char *filter, char *opts, ...)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, opts);
|
|
|
|
char *s = talloc_vasprintf(vf, opts, ap);
|
|
|
|
talloc_free(p->cfg_graph);
|
2014-09-27 15:14:23 +00:00
|
|
|
p->cfg_graph = filter ? talloc_asprintf(vf, "%s=%s", filter, s)
|
|
|
|
: talloc_strdup(vf, s);
|
2013-12-03 21:19:27 +00:00
|
|
|
talloc_free(s);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2014-09-27 15:14:23 +00:00
|
|
|
void vf_lw_set_reconfig_cb(struct vf_instance *vf,
|
|
|
|
int (*reconfig_)(struct vf_instance *vf,
|
|
|
|
struct mp_image_params *in,
|
|
|
|
struct mp_image_params *out))
|
2013-12-03 21:19:27 +00:00
|
|
|
{
|
2014-09-27 15:14:23 +00:00
|
|
|
vf->priv->lw_reconfig_cb = reconfig_;
|
2013-12-03 21:19:27 +00:00
|
|
|
}
|