[FFmpeg-devel] [PATCH] avformat: avisynth demuxer rewrite

Stephen Hutchinson qyot27 at gmail.com
Mon Feb 25 21:20:23 CET 2013


Over the past week, I've been discussing this patch with d
s/avxsynth-testing on Github
(https://github.com/avxsynth/avxsynth/issues/90), and they've given me
permission to resubmit an updated version of the patch on their
behalf.  I have it in two patches on Github, and have kept the
authorship information the same since my contributions to it were
small - just the ifdef for OS X's .dylib, a correction for the
pkt->size math, and the stuff regarding AviSynth 2.6's additional
colorspaces.

AviSynth demuxer rewrite patch:
https://github.com/qyot27/FFmpeg/commit/0403ba7389e3a20df31b94886f4ce3b880d3cfb1.patch

To solve the problem of how to handle the need for AviSynth and
AvxSynth headers to be available, I've adopted the same tactic used by
x264, and included local copies of the necessary headers in
compat/avisynth/.  The versions are the same as those included with
x264.




atexit/exit changes in ffmpeg.c:
https://github.com/qyot27/FFmpeg/commit/d69ebce458ea8dd023f197cf9c89a98d5dc652e8.patch

Their rationale for the second patch is explained in the issues discussion:
"IIRC, the segfault occurs because of an interaction between dlclose,
atexit, and C++ objects. I will look into seeing if it can be
mitigated on the AvxSynth side.

Edit:
More details about the segfault on exit problem:
In ffmpeg.c, exit_program is registered with atexit. C++ static global
objects are also (secretly) registered with a C++ atexit equivalent.
The ScriptEnvironment destructor in Avxsynth has been modified from
the Avisynth version to access some global structures, namely the (now
vector instead of array) list of built-in functions and the log4cpp
service. Normally, this would not be an issue because constructed
static objects are guaranteed by the C++ standard to be destroyed
after user atexit handlers run. However, because Avxsynth is being
dynamically loaded, the global objects are actually constructed upon
calling dlopen through avformat_read_header, which occurs after
exit_program is registered. As a consequence, the Avxsynth global
structures are destroyed before calling exit_program, and
avs_delete_script_environment accesses freed memory when calling the
ScriptEnvironment destructor."

"I have sat down and thought about this for a while. Unfortunately, I
can't think of a way to resolve ffmpeg's atexit usage with AvxSynth's
usage of global objects. Something has to give, and unfortunately, we
are not willing to give up logging to avoid this segfault. This patch
to ffmpeg.c replaces the offending atexit handler and does not appear
to break anything else:

http://pastebin.com/L988RtYz

There is a second atexit handler in libavcodec/bfin/dsputil_bfin.h
which is not affected by this change as it does not touch any
dynamically allocated structures (as far as I can tell)."


More information about the ffmpeg-devel mailing list