Commit Graph

200 Commits

Author SHA1 Message Date
Anton Khirnov 4abf42ab96 lavfi/graphparser: be more verbose when filtergraph parsing fails
When an option could not be found, print its name and value. Note that
this is not done while applying the options in
avfilter_graph_segment_apply_opts() to give the caller the option of
handling the missing options in some other way.
2023-06-16 08:07:02 +02:00
Anton Khirnov fefcba1c1b lavfi/graphparser: use correct logging context 2023-03-10 13:04:25 +01:00
James Almer 2fd86d9afa avfilter/graphparser: fix filter instance name when an id is provided
Restores the behavior of naming the instance filter@id, which was accidentally changed
to simpy id in commit f17051eaae.

Fixes ticket #10226.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-03-06 08:42:18 -03:00
Anton Khirnov f17051eaae lavfi/graphparser: reimplement avfilter_graph_parse* using new API 2023-02-12 10:33:52 +01:00
Anton Khirnov d1b9a3ddb4 lavfi: add a new filtergraph parsing API
Callers currently have two ways of adding filters to a graph - they can
either
- create, initialize, and link them manually
- use one of the avfilter_graph_parse*() functions, which take a
  (typically end-user-written) string, split it into individual filter
  definitions+options, then create filters, apply options, initialize
  filters, and finally link them - all based on information from this
  string.

A major problem with the second approach is that it performs many
actions as a single atomic unit, leaving the caller no space to
intervene in between. Such intervention would be useful e.g. to
- modify filter options;
- supply hardware device contexts;
both of which typically must be done before the filter is initialized.

Callers who need such intervention are then forced to invent their own
filtergraph parsing, which is clearly suboptimal.

This commit aims to address this problem by adding a new modular
filtergraph parsing API. It adds a new  avfilter_graph_segment_parse()
function to parse a string filtergraph description into an intermediate
tree-like representation (AVFilterGraphSegment and its children).

This intermediate form may then be applied step by step using further
new avfilter_graph_segment*() functions, with user intervention possible
between each step.
2023-02-12 10:28:06 +01:00
Anton Khirnov 54c0e72b42 lavfi/graphparser: drop a redundant label 2023-01-10 11:52:02 +01:00
Anton Khirnov ca67a783ab lavfi/graphparser: improve applying graph-level sws options
The current code will apply them if the options string does not contain
a 'flags' substring, and will do so by appending the graph-level option
string to the filter option string (with the standard ':' separator).
This is flawed in at least the following ways:
- naive substring matching without actually parsing the options string
  may lead to false positives (e.g. flags are specified by shorthand)
  and false negatives (e.g. the 'flags' substring is not actually the
  option name)
- graph-level sws options are not limited to flags, but may set
  arbitrary sws options

This commit simply applies the graph-level options with
av_set_options_string() and lets them be overridden as desired by the
user-specified filter options (if any). This is also shorter and avoids
extra string handling.
2023-01-10 11:52:02 +01:00
Andreas Rheinhardt deb6476fd8 avfilter/graphparser: Fix memleak when linking filters fails
Parsing labeled outputs involves a check for an already known match
(a labeled input with the same name) to pair them together. If yes,
it is attempted to create a link between the two filters; in this case
the AVFilterInOuts have fulfilled their purpose and are freed. Yet if
creating the link fails, these AVFilterInOuts have up until now not been
freed, although they had already been removed from their respective lists
(which means that they are not freed automatically). In other words:
They leak. This commit fixes this.

This fixes ticket #7084. Said ticket contains an example program to
reproduce a leak. It can also be reproduced with ffmpeg alone, e.g. with
the complex filters "[0]null[1],[2]anull[0]" or with "[0]abitscope[0]".
All of these three examples involve media type mismatches which make it
impossible to create the links. The bug could also be triggered by other
means, e.g. failure to allocate the necessary AVFilterLink.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-23 19:57:42 +02:00
Andreas Rheinhardt 95b8df687c avfilter/graphparser: Check allocations for success
parse_filter() did not check the return value of av_get_token() for
success; in case name (the name of a filter) was NULL, one got a
segfault in av_strlcpy() (called from create_filter()).

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-23 19:57:42 +02:00
Andreas Rheinhardt f33faa5b9b avfilter/graphparser: Don't set pointer to one beyond '\0' of string
This happened in parse_link_name() if there was a '[' without matching
']'. While this is not undefined behaviour (pointer arithmetic one
beyond the end of an array works fine as long as there are no accesses),
it is potentially dangerous. It currently isn't (all callers of
parse_link_name() treat this as an error and don't access the string any
more), but making sure that this will never cause trouble in the future
seems nevertheless worthwhile.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-23 19:57:42 +02:00
Andreas Rheinhardt b3f6dee728 avfilter/graphparser: Fix leaks when parsing inputs fails
parse_inputs() uses a temporary linked list to parse the labeled inputs
of a filter; said linked list owns its elements (and their names). On
success, the list of unlabeled inputs is appened to the end of the list
of labeled inputs and the new list is returned; yet on failures, nothing
frees the already existing elements of the temporary linked list, leading
to a leak.

This can be triggered by e.g. using '-vf [v][' in the FFmpeg
command-line tool.

This leak seems to exist since 4e781c25b7.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-23 19:57:42 +02:00
Carl Eugen Hoyos ea049ad862 lavfi/graphparser: Constify a variable.
Fixes the following warning:
libavfilter/graphparser.c:122:10: warning: assignment discards 'const' qualifier from pointer target type
2017-10-21 20:24:49 +02:00
Muhammad Faiz 162414cefe avfilter/graphparser: allow specifying filter@id as filter instance
See http://lists.ffmpeg.org/pipermail/ffmpeg-user/2017-April/035975.html
Parsed_filter_X could remain and user can override it with custom one.

Example:
ffplay -f lavfi "nullsrc=s=640x360,
sendcmd='1 drawtext@top reinit text=Hello; 2 drawtext@bottom reinit text=World',
drawtext@top=x=16:y=16:fontsize=20:fontcolor=Red:text='',
drawtext@bottom=x=16:y=340:fontsize=16:fontcolor=Blue:text=''"

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
2017-05-19 20:21:47 +07:00
Muhammad Faiz 6602361295 avfilter/graphparser: remove '\n' from parse_filter
this allow a filter to be written like this:
aformat =
    sample_fmts  = fltp|flt:
    sample_rates = 44100|44800

Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
2016-06-13 16:17:53 +07:00
Muhammad Faiz 1d4400ac7f avfilter/graphparser: add '\r' as whitespace
for compatibility with platforms that treat it
as newline

Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
2016-05-06 07:37:12 +07:00
Lou Logan 06eef96b69 fix some a/an typos
Signed-off-by: Lou Logan <lou@lrcd.com>
2016-03-28 14:13:17 -08:00
Hendrik Leppkes 3433228795 lavfi: remove old graph parser API with different semantics
This API hasn't been active since the last bump already.
2015-09-05 18:35:09 +02:00
Michael Niedermayer 41e733c1ef avfilter/graphparser: Do not ignore scale_sws_opts if args == NULL
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-08-08 13:24:52 +02:00
Michael Niedermayer 9d5017a20c Merge commit '9d3b752fceb0f2a42cac7c2a1109b0629823c99f'
* commit '9d3b752fceb0f2a42cac7c2a1109b0629823c99f':
  graphparser: Check av_get_token() memory error

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-17 20:48:22 +01:00
Vittorio Giovara 9d3b752fce graphparser: Check av_get_token() memory error
CC: libav-stable@libav.org
Bug-Id: CID 1267891
2015-02-17 11:27:41 -05:00
Michael Niedermayer 9146a47600 avfilter/graphparser: Use av_freep(), avoid leaving stale pointers in memory
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-11-22 18:56:37 +01:00
Michael Niedermayer 175e689cc5 avfilter/graphparser: zero filter_ctx in case of deallocation in create_filter()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-11-07 23:38:44 +01:00
Michael Niedermayer ec8e68c763 Merge commit 'cffecc0e7ebd642afaa1fb9f56fab1fcc283293c'
* commit 'cffecc0e7ebd642afaa1fb9f56fab1fcc283293c':
  avfilter/graphparser: Directly free filter memory if initialization fails

Conflicts:
	libavfilter/graphparser.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-11-07 23:05:26 +01:00
Diego Biurrun cffecc0e7e avfilter/graphparser: Directly free filter memory if initialization fails 2013-11-06 22:06:15 +01:00
Michael Niedermayer d5ec8ba7f2 Do not leave positive values undefined when negative are defined as error
Define positive return values as non errors and leave further meaning undefined
This allows future extensions to use these values

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-10-19 16:42:57 +02:00
Michael Niedermayer 1350a5c4d5 avfilter/graphparser: fix use of deprecated symbols
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-08-25 19:36:58 +02:00
Michael Niedermayer 61af627d56 avfilter/graphparser: remove 256 char limit from create_filter()
Fixes Ticket2803

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-08-04 00:56:55 +02:00
Michael Niedermayer d5de123195 avfilter/graphparse: Fix build with --enable-incompatible-fork-abi
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-07-09 19:06:32 +02:00
Stefano Sabatini 838bd73139 lavfi: create Libav-API compatibility layer for avfilter_graph_parse() at the next bump
Add function avfilter_graph_parse_ptr() and favor it in place of
avfilter_graph_parse(), which will be restored with the old/Libav
signature at the next bump.

If HAVE_INCOMPATIBLE_LIBAV_API is enabled it will use the
Libav-compatible signature for avfilter_graph_parse().

At the next major bump the current implementation of
avfilter_graph_parse() should be dropped in favor of the Libav/old
implementation.

Should address trac ticket #2672.
2013-07-03 13:21:42 +02:00
Michael Niedermayer e41d3aba01 Merge commit 'c22263d3e813d442df8fa5f5ba8993573fe775d8'
* commit 'c22263d3e813d442df8fa5f5ba8993573fe775d8':
  graphparser: only print filter arguments if they are non-NULL
  af_channelmap: ensure the output channel layout is valid.

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-01 10:16:31 +02:00
Anton Khirnov c22263d3e8 graphparser: only print filter arguments if they are non-NULL 2013-04-30 11:16:57 +02:00
Clément Bœsch 6b5ec76283 lavfi: fix forgotten chunk in eb0f774d. 2013-04-12 14:08:04 +02:00
Michael Niedermayer 710b0aa801 Merge commit '48a5adab62bd2a553f5069d41fa632a0701835e5'
* commit '48a5adab62bd2a553f5069d41fa632a0701835e5':
  lavfi: add avfilter_init_str() to replace avfilter_init_filter().

avfilter_graph_create_filter() opaque is still passed to avfilter_init_filter()
which continues to pass it to init_opaque as its still used in the buffer sinks
the sinks should be changed and the opaque passing removed

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-12 01:31:55 +02:00
Michael Niedermayer eb0f774d4b Merge commit '1565cbc65cbb9f95c11367314a080068895e0cf0'
* commit '1565cbc65cbb9f95c11367314a080068895e0cf0':
  lavfi: make avfilter_free() remove the filter from its graph.

Conflicts:
	libavfilter/avfilter.c
	libavfilter/avfiltergraph.c
	libavfilter/graphparser.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-12 00:54:05 +02:00
Michael Niedermayer 86070b8e5a Merge commit 'bc1a985ba030e9861d24965d42792850b43a43ea'
* commit 'bc1a985ba030e9861d24965d42792850b43a43ea':
  lavfi: replace avfilter_open() with avfilter_graph_alloc_filter().

Conflicts:
	libavfilter/avfiltergraph.c
	libavfilter/internal.h
	libavfilter/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-12 00:31:44 +02:00
Michael Niedermayer 231fd4411f Merge commit '38f0c0781a6e099f11c0acec07f9b8be742190c4'
* commit '38f0c0781a6e099f11c0acec07f9b8be742190c4':
  lavfi: merge avfiltergraph.h into avfilter.h

Conflicts:
	doc/APIchanges
	ffmpeg_filter.c
	libavfilter/avfilter.h
	libavfilter/avfiltergraph.h
	libavfilter/version.h
	tools/graph2dot.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-11 23:50:39 +02:00
Anton Khirnov 48a5adab62 lavfi: add avfilter_init_str() to replace avfilter_init_filter().
Drop the unused opaque parameter from its signature.
2013-04-11 20:39:13 +02:00
Anton Khirnov 1565cbc65c lavfi: make avfilter_free() remove the filter from its graph. 2013-04-11 20:38:48 +02:00
Anton Khirnov bc1a985ba0 lavfi: replace avfilter_open() with avfilter_graph_alloc_filter().
Since we do not support "standalone" filters not attached to an
AVFilterGraph, we should not have a public function to create such
filters. In addition that function is horribly named, the action it does
cannot be possibly described as "opening" a filter.
2013-04-11 20:34:14 +02:00
Anton Khirnov 38f0c0781a lavfi: merge avfiltergraph.h into avfilter.h
We do not support using filters without AVFilterGraph in practice
anyway, so there is no point in pretending we do.
2013-04-11 20:33:33 +02:00
Michael Niedermayer d3fc2db47e Merge remote-tracking branch 'qatar/master'
* qatar/master:
  avfiltergraph: check for sws opts being non-NULL before using them.

Conflicts:
	libavfilter/avfiltergraph.c
	libavfilter/graphparser.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-03 15:20:05 +02:00
Anton Khirnov 6e3c13a559 avfiltergraph: check for sws opts being non-NULL before using them.
Avoid snprintfing a NULL pointer.

CC: libav-stable@libav.org
2013-04-03 09:29:55 +02:00
Michael Niedermayer ecade984ac Merge commit '42c7c61ab25809620b8c8809b3da73e25f5bbaaf'
* commit '42c7c61ab25809620b8c8809b3da73e25f5bbaaf':
  avfiltergraph: replace AVFilterGraph.filter_count with nb_filters

Conflicts:
	doc/APIchanges
	libavfilter/avfiltergraph.c
	libavfilter/avfiltergraph.h
	libavfilter/graphparser.c
	libavfilter/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-16 16:09:37 +01:00
Anton Khirnov 42c7c61ab2 avfiltergraph: replace AVFilterGraph.filter_count with nb_filters
This is more consistent with the naming in the rest of Libav.
2013-03-16 05:33:23 +01:00
Reimar Döffinger efa7f42020 Use the avstring.h locale-independent character type functions
Make sure the behavior does not change with the locale.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-03-07 15:16:36 +02:00
Reimar Döffinger 88d55b827d Remove incorrect use of ctype.h functions.
As far as I can tell the code should not change behaviour
depending on locale in any of these places.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2013-03-03 21:44:10 +01:00
Michael Niedermayer 507f2940cc Merge commit '1b891d17c531e8a63c2974aab4bf997ce70746f3'
* commit '1b891d17c531e8a63c2974aab4bf997ce70746f3':
  avconv: fix bitrate report when writing to /dev/null
  avfilter: fix graphparser memleaks on error paths
  rawdec: remove ff_raw_read_header
  pcmdec: remove dependency from rawdec
  g722: refactor out of rawdec.c
  rawvideo: use a specific read_header

Conflicts:
	ffmpeg.c
	libavformat/Makefile
	libavformat/rawdec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-10-26 14:24:57 +02:00
Janne Grunau 285b706b55 avfilter: fix graphparser memleaks on error paths
Fixes CID700635, CID700636 and CID732274.
2012-10-25 15:00:15 +02:00
Michael Niedermayer 39747d87d0 avfilter_graph_parse: add support for parsing sws_flags
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2012-10-22 00:07:35 +02:00
Stefano Sabatini 2969abd908 lavfi/graphparser: fix parsing error in case of NULL sws_opts addition
If sws_opts was NULL it was resulting in the args being set to
"W:H:(null)", which with the new parsing code was generating a syntax
failure.
2012-10-21 21:44:45 +02:00