2013-05-23 13:11:57 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* Filter graph creation code taken from FFmpeg ffplay.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-05-23 13:11:57 +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-05-23 13:11:57 +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-05-23 13:11:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <libavutil/avstring.h>
|
|
|
|
#include <libavutil/mem.h>
|
|
|
|
#include <libavutil/mathematics.h>
|
|
|
|
#include <libavutil/rational.h>
|
|
|
|
#include <libavutil/samplefmt.h>
|
|
|
|
#include <libavutil/time.h>
|
|
|
|
#include <libavutil/opt.h>
|
|
|
|
#include <libavfilter/avfilter.h>
|
|
|
|
#include <libavfilter/avfiltergraph.h>
|
|
|
|
#include <libavfilter/buffersink.h>
|
|
|
|
#include <libavfilter/buffersrc.h>
|
|
|
|
|
2015-09-11 21:04:02 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-05-23 13:11:57 +00:00
|
|
|
#include "audio/format.h"
|
|
|
|
#include "audio/fmt-conversion.h"
|
|
|
|
#include "af.h"
|
|
|
|
|
2014-08-02 01:12:09 +00:00
|
|
|
#include "common/av_common.h"
|
2015-09-11 21:04:02 +00:00
|
|
|
#include "common/tags.h"
|
2014-08-02 01:12:09 +00:00
|
|
|
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2013-07-22 12:47:46 +00:00
|
|
|
|
2013-05-23 13:11:57 +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-05-23 13:11:57 +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-05-23 13:11:57 +00:00
|
|
|
#else
|
|
|
|
#define graph_parse(graph, filters, inputs, outputs, log_ctx) \
|
2014-04-13 00:57:26 +00:00
|
|
|
avfilter_graph_parse_ptr(graph, filters, &(inputs), &(outputs), log_ctx)
|
2013-05-23 13:11:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct priv {
|
|
|
|
AVFilterGraph *graph;
|
|
|
|
AVFilterContext *in;
|
|
|
|
AVFilterContext *out;
|
|
|
|
|
2013-11-10 22:18:31 +00:00
|
|
|
int64_t samples_in;
|
2013-05-23 13:11:57 +00:00
|
|
|
|
|
|
|
AVRational timebase_out;
|
|
|
|
|
2015-03-17 21:31:05 +00:00
|
|
|
bool eof;
|
|
|
|
|
2015-09-11 21:04:02 +00:00
|
|
|
struct mp_tags *metadata;
|
|
|
|
|
2013-05-23 13:11:57 +00:00
|
|
|
// options
|
|
|
|
char *cfg_graph;
|
2014-08-02 01:12:09 +00:00
|
|
|
char **cfg_avopts;
|
2013-05-23 13:11:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void destroy_graph(struct af_instance *af)
|
|
|
|
{
|
2013-07-22 12:47:46 +00:00
|
|
|
struct priv *p = af->priv;
|
2013-05-23 13:11:57 +00:00
|
|
|
avfilter_graph_free(&p->graph);
|
|
|
|
p->in = p->out = NULL;
|
2015-03-17 21:31:05 +00:00
|
|
|
p->samples_in = 0;
|
|
|
|
p->eof = false;
|
2013-05-23 13:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool recreate_graph(struct af_instance *af, struct mp_audio *config)
|
|
|
|
{
|
|
|
|
void *tmp = talloc_new(NULL);
|
2013-07-22 12:47:46 +00:00
|
|
|
struct priv *p = af->priv;
|
2014-03-12 23:29:17 +00:00
|
|
|
AVFilterContext *in = NULL, *out = NULL, *f_format = NULL;
|
2013-05-23 13:11:57 +00:00
|
|
|
|
|
|
|
if (bstr0(p->cfg_graph).len == 0) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_FATAL(af, "lavfi: no filter graph set\n");
|
2013-05-23 13:11:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy_graph(af);
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_VERBOSE(af, "lavfi: create graph: '%s'\n", p->cfg_graph);
|
2013-05-23 13:11:57 +00:00
|
|
|
|
|
|
|
AVFilterGraph *graph = avfilter_graph_alloc();
|
|
|
|
if (!graph)
|
|
|
|
goto error;
|
|
|
|
|
2014-08-02 01:12:09 +00:00
|
|
|
if (mp_set_avopts(af->log, graph, p->cfg_avopts) < 0)
|
2013-07-22 12:47:46 +00:00
|
|
|
goto error;
|
|
|
|
|
2013-05-23 13:11:57 +00:00
|
|
|
AVFilterInOut *outputs = avfilter_inout_alloc();
|
|
|
|
AVFilterInOut *inputs = avfilter_inout_alloc();
|
|
|
|
if (!outputs || !inputs)
|
|
|
|
goto error;
|
|
|
|
|
2014-03-12 23:29:17 +00:00
|
|
|
// Build list of acceptable output sample formats. libavfilter will insert
|
|
|
|
// conversion filters if needed.
|
|
|
|
static const enum AVSampleFormat sample_fmts[] = {
|
|
|
|
AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
|
|
|
|
AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL,
|
|
|
|
AV_SAMPLE_FMT_U8P, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S32P,
|
|
|
|
AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_DBLP,
|
|
|
|
AV_SAMPLE_FMT_NONE
|
|
|
|
};
|
|
|
|
char *fmtstr = talloc_strdup(tmp, "");
|
|
|
|
for (int n = 0; sample_fmts[n] != AV_SAMPLE_FMT_NONE; n++) {
|
|
|
|
const char *name = av_get_sample_fmt_name(sample_fmts[n]);
|
|
|
|
if (name) {
|
2014-03-16 09:04:46 +00:00
|
|
|
const char *s = fmtstr[0] ? "|" : "";
|
2014-03-12 23:29:17 +00:00
|
|
|
fmtstr = talloc_asprintf_append_buffer(fmtstr, "%s%s", s, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-23 13:11:57 +00:00
|
|
|
char *src_args = talloc_asprintf(tmp,
|
2014-03-12 23:29:17 +00:00
|
|
|
"sample_rate=%d:sample_fmt=%s:time_base=%d/%d:"
|
2013-05-23 13:11:57 +00:00
|
|
|
"channel_layout=0x%"PRIx64, config->rate,
|
|
|
|
av_get_sample_fmt_name(af_to_avformat(config->format)),
|
2014-03-12 23:29:17 +00:00
|
|
|
1, config->rate, mp_chmap_to_lavc(&config->channels));
|
2013-05-23 13:11:57 +00:00
|
|
|
|
|
|
|
if (avfilter_graph_create_filter(&in, avfilter_get_by_name("abuffer"),
|
|
|
|
"src", src_args, NULL, graph) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (avfilter_graph_create_filter(&out, avfilter_get_by_name("abuffersink"),
|
|
|
|
"out", NULL, NULL, graph) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2014-03-12 23:29:17 +00:00
|
|
|
if (avfilter_graph_create_filter(&f_format, avfilter_get_by_name("aformat"),
|
|
|
|
"format", fmtstr, NULL, graph) < 0)
|
2013-05-23 13:11:57 +00:00
|
|
|
goto error;
|
|
|
|
|
2014-03-12 23:29:17 +00:00
|
|
|
if (avfilter_link(f_format, 0, out, 0) < 0)
|
2013-05-23 13:11:57 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
outputs->name = av_strdup("in");
|
|
|
|
outputs->filter_ctx = in;
|
|
|
|
|
|
|
|
inputs->name = av_strdup("out");
|
2014-03-12 23:29:17 +00:00
|
|
|
inputs->filter_ctx = f_format;
|
2013-05-23 13:11:57 +00:00
|
|
|
|
|
|
|
if (graph_parse(graph, p->cfg_graph, inputs, outputs, NULL) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
talloc_free(tmp);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_FATAL(af, "Can't configure libavfilter graph.\n");
|
2013-05-23 13:11:57 +00:00
|
|
|
avfilter_graph_free(&graph);
|
|
|
|
talloc_free(tmp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:31:05 +00:00
|
|
|
static void reset(struct af_instance *af)
|
|
|
|
{
|
|
|
|
if (!recreate_graph(af, &af->fmt_in))
|
|
|
|
MP_FATAL(af, "Can't recreate libavfilter filter after a seek reset.\n");
|
|
|
|
}
|
|
|
|
|
2013-05-23 13:11:57 +00:00
|
|
|
static int control(struct af_instance *af, int cmd, void *arg)
|
|
|
|
{
|
2013-07-22 12:47:46 +00:00
|
|
|
struct priv *p = af->priv;
|
2013-05-23 13:11:57 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case AF_CONTROL_REINIT: {
|
|
|
|
struct mp_audio *in = arg;
|
|
|
|
struct mp_audio orig_in = *in;
|
|
|
|
struct mp_audio *out = af->data;
|
|
|
|
|
|
|
|
if (af_to_avformat(in->format) == AV_SAMPLE_FMT_NONE)
|
2013-11-15 20:25:05 +00:00
|
|
|
mp_audio_set_format(in, AF_FORMAT_FLOAT);
|
2013-05-23 13:11:57 +00:00
|
|
|
|
2015-10-26 14:54:00 +00:00
|
|
|
// Removing this requires fixing AVFrame.data vs. AVFrame.extended_data
|
|
|
|
if (in->channels.num > AV_NUM_DATA_POINTERS)
|
|
|
|
return AF_ERROR;
|
|
|
|
|
2013-05-23 13:11:57 +00:00
|
|
|
if (!mp_chmap_is_lavc(&in->channels))
|
|
|
|
mp_chmap_reorder_to_lavc(&in->channels); // will always work
|
|
|
|
|
|
|
|
if (!recreate_graph(af, in))
|
|
|
|
return AF_ERROR;
|
|
|
|
|
|
|
|
AVFilterLink *l_out = p->out->inputs[0];
|
|
|
|
|
|
|
|
out->rate = l_out->sample_rate;
|
|
|
|
|
|
|
|
mp_audio_set_format(out, af_from_avformat(l_out->format));
|
|
|
|
|
|
|
|
struct mp_chmap out_cm;
|
|
|
|
mp_chmap_from_lavc(&out_cm, l_out->channel_layout);
|
|
|
|
mp_audio_set_channels(out, &out_cm);
|
|
|
|
|
2015-10-26 14:54:00 +00:00
|
|
|
if (!mp_audio_config_valid(out) || out->channels.num > AV_NUM_DATA_POINTERS)
|
2013-12-21 17:29:42 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
|
2013-05-23 13:11:57 +00:00
|
|
|
p->timebase_out = l_out->time_base;
|
|
|
|
|
|
|
|
return mp_audio_config_equals(in, &orig_in) ? AF_OK : AF_FALSE;
|
|
|
|
}
|
2016-01-22 19:36:54 +00:00
|
|
|
case AF_CONTROL_COMMAND: {
|
|
|
|
if (!p->graph)
|
|
|
|
break;
|
|
|
|
char **args = arg;
|
|
|
|
return avfilter_graph_send_command(p->graph, "all",
|
|
|
|
args[0], args[1], &(char){0}, 0, 0)
|
|
|
|
>= 0 ? CONTROL_OK : CONTROL_ERROR;
|
|
|
|
}
|
2015-09-11 21:04:02 +00:00
|
|
|
case AF_CONTROL_GET_METADATA:
|
|
|
|
if (p->metadata) {
|
|
|
|
*(struct mp_tags *)arg = *p->metadata;
|
|
|
|
return CONTROL_OK;
|
|
|
|
}
|
|
|
|
return CONTROL_NA;
|
2015-03-17 21:31:05 +00:00
|
|
|
case AF_CONTROL_RESET:
|
|
|
|
reset(af);
|
|
|
|
return AF_OK;
|
2013-05-23 13:11:57 +00:00
|
|
|
}
|
|
|
|
return AF_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2015-09-11 21:04:02 +00:00
|
|
|
static void get_metadata_from_av_frame(struct af_instance *af, AVFrame *frame)
|
|
|
|
{
|
2017-01-24 07:11:42 +00:00
|
|
|
#if LIBAVUTIL_VERSION_MICRO >= 100
|
2015-09-11 21:04:02 +00:00
|
|
|
struct priv *p = af->priv;
|
|
|
|
if (!p->metadata)
|
|
|
|
p->metadata = talloc_zero(p, struct mp_tags);
|
|
|
|
|
|
|
|
mp_tags_copy_from_av_dictionary(p->metadata, av_frame_get_metadata(frame));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-01-14 21:15:56 +00:00
|
|
|
static int filter_frame(struct af_instance *af, struct mp_audio *data)
|
2013-05-23 13:11:57 +00:00
|
|
|
{
|
2013-07-22 12:47:46 +00:00
|
|
|
struct priv *p = af->priv;
|
2015-03-17 21:31:05 +00:00
|
|
|
AVFrame *frame = NULL;
|
|
|
|
|
|
|
|
if (p->eof && data)
|
|
|
|
reset(af);
|
|
|
|
|
|
|
|
if (!p->graph)
|
|
|
|
goto error;
|
|
|
|
|
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 (!data) {
|
|
|
|
if (p->eof)
|
|
|
|
return 0;
|
|
|
|
p->eof = true;
|
|
|
|
}
|
|
|
|
|
2015-01-14 21:15:56 +00:00
|
|
|
if (data) {
|
2016-01-29 21:43:00 +00:00
|
|
|
frame = mp_audio_to_avframe_and_unref(data);
|
|
|
|
data = NULL;
|
2015-01-14 21:15:56 +00:00
|
|
|
if (!frame)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
// Timebase is 1/sample_rate
|
|
|
|
frame->pts = p->samples_in;
|
2016-01-29 21:43:00 +00:00
|
|
|
p->samples_in += frame->nb_samples;
|
2013-05-23 13:11:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-14 21:15:56 +00:00
|
|
|
if (av_buffersrc_add_frame(p->in, frame) < 0)
|
|
|
|
goto error;
|
2013-05-23 13:11:57 +00:00
|
|
|
|
2015-01-14 21:15:56 +00:00
|
|
|
av_frame_free(&frame);
|
|
|
|
talloc_free(data);
|
|
|
|
return 0;
|
|
|
|
error:
|
|
|
|
av_frame_free(&frame);
|
|
|
|
talloc_free(data);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_out(struct af_instance *af)
|
|
|
|
{
|
|
|
|
struct priv *p = af->priv;
|
2013-11-10 22:18:31 +00:00
|
|
|
|
2015-03-17 21:31:05 +00:00
|
|
|
if (!p->graph)
|
|
|
|
goto error;
|
|
|
|
|
2015-01-14 21:15:56 +00:00
|
|
|
AVFrame *frame = av_frame_alloc();
|
|
|
|
if (!frame)
|
|
|
|
goto error;
|
2013-05-23 13:11:57 +00:00
|
|
|
|
2015-01-14 21:15:56 +00:00
|
|
|
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.
|
2015-03-17 21:31:05 +00:00
|
|
|
// AVERROR_EOF means we shouldn't even give the filter more
|
|
|
|
// input, but we don't handle that completely correctly.
|
2013-05-23 13:11:57 +00:00
|
|
|
av_frame_free(&frame);
|
2015-03-17 21:31:05 +00:00
|
|
|
p->eof |= err == AVERROR_EOF;
|
2015-01-14 21:15:56 +00:00
|
|
|
return 0;
|
2013-05-23 13:11:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-14 21:15:56 +00:00
|
|
|
struct mp_audio *out = mp_audio_from_avframe(frame);
|
|
|
|
if (!out)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
mp_audio_copy_config(out, af->data);
|
2013-05-23 13:11:57 +00:00
|
|
|
|
2015-01-14 21:15:56 +00:00
|
|
|
if (frame->pts != AV_NOPTS_VALUE) {
|
|
|
|
double in_time = p->samples_in / (double)af->fmt_in.rate;
|
|
|
|
double out_time = frame->pts * av_q2d(p->timebase_out);
|
2013-05-23 13:11:57 +00:00
|
|
|
// Need pts past the last output sample.
|
2015-01-14 21:15:56 +00:00
|
|
|
out_time += out->samples / (double)out->rate;
|
2013-05-23 13:11:57 +00:00
|
|
|
|
2013-11-10 22:39:29 +00:00
|
|
|
af->delay = in_time - out_time;
|
2013-05-23 13:11:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 21:04:02 +00:00
|
|
|
get_metadata_from_av_frame(af, frame);
|
2015-01-14 21:15:56 +00:00
|
|
|
af_add_output_frame(af, out);
|
|
|
|
av_frame_free(&frame);
|
2013-12-04 23:01:46 +00:00
|
|
|
return 0;
|
2015-01-14 21:15:56 +00:00
|
|
|
error:
|
|
|
|
av_frame_free(&frame);
|
|
|
|
return -1;
|
2013-05-23 13:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit(struct af_instance *af)
|
|
|
|
{
|
2013-11-27 20:12:09 +00:00
|
|
|
destroy_graph(af);
|
2013-05-23 13:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int af_open(struct af_instance *af)
|
|
|
|
{
|
|
|
|
af->control = control;
|
|
|
|
af->uninit = uninit;
|
2015-01-14 21:15:56 +00:00
|
|
|
af->filter_frame = filter_frame;
|
|
|
|
af->filter_out = filter_out;
|
2013-05-23 13:11:57 +00:00
|
|
|
return AF_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-22 12:47:46 +00:00
|
|
|
#define OPT_BASE_STRUCT struct priv
|
|
|
|
|
2014-06-10 21:56:05 +00:00
|
|
|
const struct af_info af_info_lavfi = {
|
2013-10-23 17:05:47 +00:00
|
|
|
.info = "libavfilter bridge",
|
|
|
|
.name = "lavfi",
|
|
|
|
.open = af_open,
|
2013-07-22 12:47:46 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
|
|
|
.options = (const struct m_option[]) {
|
|
|
|
OPT_STRING("graph", cfg_graph, 0),
|
2014-08-02 01:12:09 +00:00
|
|
|
OPT_KEYVALUELIST("o", cfg_avopts, 0),
|
2013-07-22 12:47:46 +00:00
|
|
|
{0}
|
|
|
|
},
|
2013-05-23 13:11:57 +00:00
|
|
|
};
|