Commit fdf11906 authored by Diego Biurrun's avatar Diego Biurrun

Remove deprecated vhook subsystem.

Originally committed as revision 17769 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent f989d397
......@@ -18,15 +18,6 @@ Applications
ffmpeg:
ffmpeg.c Michael Niedermayer
Video Hooks:
vhook
vhook/watermark.c Marcus Engene
vhook/ppm.c
vhook/drawtext.c
vhook/fish.c
vhook/null.c
vhook/imlib2.c
ffplay:
ffplay.c Michael Niedermayer
......
......@@ -32,10 +32,8 @@ FF_LDFLAGS := $(FFLDFLAGS)
FF_EXTRALIBS := $(FFEXTRALIBS)
FF_DEP_LIBS := $(DEP_LIBS)
ALL_TARGETS-$(CONFIG_VHOOK) += videohook
ALL_TARGETS-$(BUILD_DOC) += documentation
INSTALL_TARGETS-$(CONFIG_VHOOK) += install-vhook
ifneq ($(PROGS),)
INSTALL_TARGETS-yes += install-progs install-data
INSTALL_TARGETS-$(BUILD_DOC) += install-man
......@@ -81,41 +79,8 @@ cmdutils.o cmdutils.d: version.h
alltools: $(addsuffix $(EXESUF),$(addprefix tools/, cws2fws pktdumper qt-faststart trasher))
VHOOKCFLAGS += $(filter-out -mdynamic-no-pic,$(CFLAGS))
BASEHOOKS = fish null watermark
ALLHOOKS = $(BASEHOOKS) drawtext imlib2 ppm
ALLHOOKS_SRCS = $(addprefix vhook/, $(addsuffix .c, $(ALLHOOKS)))
HOOKS-$(HAVE_FORK) += ppm
HOOKS-$(HAVE_IMLIB2) += imlib2
HOOKS-$(HAVE_FREETYPE2) += drawtext
HOOKS = $(addprefix vhook/, $(addsuffix $(SLIBSUF), $(BASEHOOKS) $(HOOKS-yes)))
VHOOKCFLAGS-$(HAVE_IMLIB2) += `imlib2-config --cflags`
LIBS_imlib2$(SLIBSUF) = `imlib2-config --libs`
VHOOKCFLAGS-$(HAVE_FREETYPE2) += `freetype-config --cflags`
LIBS_drawtext$(SLIBSUF) = `freetype-config --libs`
VHOOKCFLAGS += $(VHOOKCFLAGS-yes)
vhook/%.o vhook/%.d: CFLAGS:=$(VHOOKCFLAGS)
# vhooks compile fine without libav*, but need them nonetheless.
videohook: $(FF_DEP_LIBS) $(HOOKS)
$(eval VHOOKSHFLAGS=$(VHOOKSHFLAGS))
vhook/%$(SLIBSUF): vhook/%.o
$(CC) $(LDFLAGS) -o $@ $(VHOOKSHFLAGS) $< $(VHOOKLIBS) $(LIBS_$(@F))
VHOOK_DEPS = $(HOOKS:$(SLIBSUF)=.d)
depend dep: $(VHOOK_DEPS)
documentation: $(addprefix doc/, ffmpeg-doc.html faq.html ffserver-doc.html \
ffplay-doc.html general.html hooks.html \
$(ALLMANPAGES))
ffplay-doc.html general.html $(ALLMANPAGES))
doc/%.html: doc/%.texi
texi2html -monolithic -number $<
......@@ -141,11 +106,7 @@ install-man: $(MANPAGES)
install -d "$(MANDIR)/man1"
install -m 644 $(MANPAGES) "$(MANDIR)/man1"
install-vhook: videohook
install -d "$(SHLIBDIR)/vhook"
install -m 755 $(HOOKS) "$(SHLIBDIR)/vhook"
uninstall: uninstall-progs uninstall-data uninstall-man uninstall-vhook
uninstall: uninstall-progs uninstall-data uninstall-man
uninstall-progs:
rm -f $(addprefix "$(BINDIR)/", $(ALLPROGS))
......@@ -156,10 +117,6 @@ uninstall-data:
uninstall-man:
rm -f $(addprefix "$(MANDIR)/man1/",$(ALLMANPAGES))
uninstall-vhook:
rm -f $(addprefix "$(SHLIBDIR)/",$(ALLHOOKS_SRCS:.c=$(SLIBSUF)))
-rmdir "$(SHLIBDIR)/vhook/"
testclean:
rm -rf tests/vsynth1 tests/vsynth2 tests/data tests/asynth1.sw tests/*~
......@@ -168,10 +125,9 @@ clean:: testclean
rm -f doc/*.html doc/*.pod doc/*.1
rm -f $(addprefix tests/,$(addsuffix $(EXESUF),audiogen videogen rotozoom seek_test tiny_psnr))
rm -f $(addprefix tools/,$(addsuffix $(EXESUF),cws2fws pktdumper qt-faststart trasher))
rm -f vhook/*.o vhook/*~ vhook/*.so vhook/*.dylib vhook/*.dll
distclean::
rm -f version.h config.* vhook/*.d
rm -f version.h config.*
# regression tests
......@@ -355,6 +311,4 @@ tests/seek_test$(EXESUF): tests/seek_test.c $(FF_DEP_LIBS)
$(CC) $(FF_LDFLAGS) $(CFLAGS) -o $@ $< $(FF_EXTRALIBS)
.PHONY: lib videohook documentation *test regtest-* swscale-error zlib-error alltools check
-include $(VHOOK_DEPS)
.PHONY: lib documentation *test regtest-* swscale-error zlib-error alltools check
......@@ -82,9 +82,8 @@ show_help(){
echo " --disable-ffserver disable ffserver build"
echo " --enable-postproc enable GPLed postprocessing support [no]"
echo " --enable-swscale enable GPLed software scaler support [no]"
echo " --enable-avfilter video filter support (replaces vhook) [no]"
echo " --enable-avfilter video filter support [no]"
echo " --enable-avfilter-lavf video filters dependent on avformat [no]"
echo " --disable-vhook disable video hooking support"
echo " --enable-beosthreads use BeOS threads [no]"
echo " --enable-os2threads use OS/2 threads [no]"
echo " --enable-pthreads use pthreads [no]"
......@@ -799,7 +798,6 @@ CONFIG_LIST="
static
swscale
vdpau
vhook
x11grab
zlib
"
......@@ -873,11 +871,9 @@ HAVE_LIST="
fast_cmov
fast_unaligned
fork
freetype2
gethrtime
GetProcessTimes
getrusage
imlib2
inet_aton
inline_asm
libdc1394_1
......@@ -1133,7 +1129,6 @@ movie_filter_deps="avfilter_lavf"
ffplay_deps="sdl"
ffserver_deps="ffm_muxer rtp_protocol rtsp_demuxer"
ffserver_extralibs='$ldl'
vhook_extralibs='$ldl'
# default parameters
......@@ -1180,12 +1175,10 @@ enable optimizations
enable protocols
enable static
enable stripping
vhook="default"
# build settings
add_cflags -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112
SHFLAGS='-shared -Wl,-soname,$$(@F)'
VHOOKSHFLAGS='$(SHFLAGS)'
FFSERVERLDFLAGS=-Wl,-E
LIBPREF="lib"
LIBSUF=".a"
......@@ -1560,7 +1553,6 @@ case $target_os in
darwin)
disable need_memalign
SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR) -Wl,-read_only_relocs,suppress'
VHOOKSHFLAGS='-dynamiclib -Wl,-single_module -flat_namespace -undefined suppress -Wl,-install_name,$(SHLIBDIR)/vhook/$$(@F)'
strip="strip -x"
FFLDFLAGS="-Wl,-dynamic,-search_paths_first"
SLIBSUF=".dylib"
......@@ -1578,12 +1570,6 @@ case $target_os in
LIBTARGET=x64
fi
shlibdir_default="$bindir_default"
VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil'
VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)'
if enabled swscale; then
VHOOKSHFLAGS="$VHOOKSHFLAGS -L\$(BUILD_ROOT)/libswscale"
VHOOKLIBS="$VHOOKLIBS -lswscale\$(BUILDSUF)"
fi
disable ffserver
SLIBPREF=""
SLIBSUF=".dll"
......@@ -1607,12 +1593,6 @@ case $target_os in
cygwin*)
target_os=cygwin
shlibdir_default="$bindir_default"
VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil'
VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)'
if enabled swscale; then
VHOOKSHFLAGS="$VHOOKSHFLAGS -L\$(BUILD_ROOT)/libswscale"
VHOOKLIBS="$VHOOKLIBS -lswscale\$(BUILDSUF)"
fi
SLIBPREF="cyg"
SLIBSUF=".dll"
SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
......@@ -1622,7 +1602,7 @@ case $target_os in
enable dos_paths
;;
*-dos|freedos|opendos)
disable ffplay ffserver vhook
disable ffplay ffserver
disable $INDEV_LIST $OUTDEV_LIST
network_extralibs="-lsocket"
objformat="coff"
......@@ -1656,12 +1636,8 @@ case $target_os in
emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib $(SUBDIR)$(NAME).def;'
SLIB_INSTALL_EXTRA_CMD='install -m 644 $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib "$(LIBDIR)"'
SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.a "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.lib'
disable vhook
enable dos_paths
;;
interix)
disable vhook
;;
*)
die "Unknown OS '$target_os'."
......@@ -2040,24 +2016,6 @@ void foo(char * $restrict_keyword p);
EOF
done
test "$vhook" = "default" && vhook="$dlopen"
if test "$target_os" = cygwin -o "$target_os" = mingw32 && enabled_all static vhook ; then
disable vhook
echo
echo "At the moment vhooks don't work on Cygwin or MinGW static builds."
echo "Patches welcome."
echo
fi
if enabled vhook; then
check_ldflags -rdynamic
check_ldflags -export-dynamic
fi
check_foo_config imlib2 imlib2 Imlib2.h imlib_load_font
check_foo_config freetype2 freetype ft2build.h FT_Init_FreeType
##########################################
# SDL check
......@@ -2225,8 +2183,6 @@ if enabled gprof; then
add_ldflags -p
fi
VHOOKCFLAGS="-fPIC"
# Find out if the .align argument is a power of two or not.
check_asm asmalign_pot '".align 3"'
......@@ -2312,11 +2268,6 @@ echo "postprocessing support ${postproc-no}"
echo "software scaler enabled ${swscale-no}"
echo "new filter support ${avfilter-no}"
echo "filters using lavformat ${avfilter_lavf-no}"
echo "video hooking ${vhook-no}"
if enabled vhook; then
echo "Imlib2 support ${imlib2-no}"
echo "FreeType support ${freetype2-no}"
fi
echo "network support ${network-no}"
if enabled network; then
echo "IPv6 support ${ipv6-no}"
......@@ -2395,13 +2346,10 @@ enabled stripping &&
echo "STRIP=echo ignoring strip" >> config.mak
echo "OPTFLAGS=$CFLAGS" >> config.mak
echo "VHOOKCFLAGS=$VHOOKCFLAGS" >> config.mak
echo "LDFLAGS=$LDFLAGS" >> config.mak
echo "FFSERVERLDFLAGS=$FFSERVERLDFLAGS" >> config.mak
echo "SHFLAGS=$SHFLAGS" >> config.mak
echo "YASMFLAGS=$YASMFLAGS" >> config.mak
echo "VHOOKSHFLAGS=$VHOOKSHFLAGS" >> config.mak
echo "VHOOKLIBS=$VHOOKLIBS" >> config.mak
echo "LIBOBJFLAGS=$LIBOBJFLAGS" >> config.mak
echo "BUILD_STATIC=$static" >> config.mak
echo "BUILDSUF=$build_suffix" >> config.mak
......@@ -2529,7 +2477,6 @@ if enabled source_path_used; then
libswscale \
tests \
tools \
vhook \
"
FILES="\
Makefile \
......
......@@ -660,9 +660,6 @@ Calculate PSNR of compressed frames.
Dump video coding statistics to @file{vstats_HHMMSS.log}.
@item -vstats_file @var{file}
Dump video coding statistics to @var{file}.
@item -vhook @var{module}
Insert video processing @var{module}. @var{module} contains the module
name and its parameters separated by spaces.
@item -top @var{n}
top=1/bottom=0/auto=-1 field first
@item -dc @var{precision}
......
......@@ -691,10 +691,6 @@ Notes:
@itemize
@item In order to compile vhooks, you must have a POSIX-compliant libdl in
your MinGW system. Get dlfcn-win32 from
@url{http://code.google.com/p/dlfcn-win32}.
@item In order to compile FFplay, you must have the MinGW development library
of SDL. Get it from @url{http://www.libsdl.org}.
Edit the @file{bin/sdl-config} script so that it points to the correct prefix
......
This diff is collapsed.
......@@ -34,7 +34,6 @@
#include "libavformat/avformat.h"
#include "libavdevice/avdevice.h"
#include "libswscale/swscale.h"
#include "libavformat/framehook.h"
#include "libavcodec/opt.h"
#include "libavcodec/audioconvert.h"
#include "libavutil/fifo.h"
......@@ -203,7 +202,6 @@ static int audio_volume = 256;
static int exit_on_error = 0;
static int using_stdin = 0;
static int using_vhook = 0;
static int verbose = 1;
static int thread_count= 1;
static int q_pressed = 0;
......@@ -736,7 +734,7 @@ static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void
dec = ist->st->codec;
/* deinterlace : must be done before any resize */
if (do_deinterlace || using_vhook) {
if (do_deinterlace) {
int size;
/* create temporary picture */
......@@ -764,10 +762,6 @@ static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void
picture2 = picture;
}
if (CONFIG_VHOOK)
frame_hook_process(picture2, dec->pix_fmt, dec->width, dec->height,
1000000 * ist->pts / AV_TIME_BASE);
if (picture != picture2)
*picture = *picture2;
*bufp = buf;
......@@ -1772,10 +1766,6 @@ static int av_encode(AVFormatContext **output_files,
codec->block_align= 0;
break;
case CODEC_TYPE_VIDEO:
if(using_vhook) {
fprintf(stderr,"-vcodec copy and -vhook are incompatible (frames are not decoded)\n");
av_exit(1);
}
codec->pix_fmt = icodec->pix_fmt;
codec->width = icodec->width;
codec->height = icodec->height;
......@@ -2651,29 +2641,6 @@ static void opt_video_tag(const char *arg)
video_codec_tag= arg[0] + (arg[1]<<8) + (arg[2]<<16) + (arg[3]<<24);
}
#if CONFIG_VHOOK
static void add_frame_hooker(const char *arg)
{
int argc = 0;
char *argv[64];
int i;
char *args = av_strdup(arg);
using_vhook = 1;
argv[0] = strtok(args, " ");
while (argc < 62 && (argv[++argc] = strtok(NULL, " "))) {
}
i = frame_hook_add(argc, argv);
if (i != 0) {
fprintf(stderr, "Failed to add video hook function: %s\n", arg);
av_exit(1);
}
}
#endif
static void opt_video_codec(const char *arg)
{
opt_codec(&video_stream_copy, &video_codec_name, CODEC_TYPE_VIDEO, arg);
......@@ -3840,9 +3807,6 @@ static const OptionDef options[] = {
{ "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
{ "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" },
{ "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" },
#if CONFIG_VHOOK
{ "vhook", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)add_frame_hooker}, "insert video processing module", "module" },
#endif
{ "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
{ "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" },
{ "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" },
......
......@@ -228,8 +228,6 @@ OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER) += yuv4mpeg.o
OBJS-$(CONFIG_LIBNUT_DEMUXER) += libnut.o riff.o
OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o riff.o
OBJS-$(CONFIG_VHOOK) += framehook.o
# protocols I/O
OBJS+= avio.o aviobuf.o
......
/*
* Video processing hooks
* Copyright (c) 2000, 2001 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <errno.h>
#include "config.h"
#include "avformat.h"
#include "framehook.h"
#if HAVE_DLFCN_H
#include <dlfcn.h>
#endif
typedef struct FrameHookEntry {
struct FrameHookEntry *next;
FrameHookConfigureFn Configure;
FrameHookProcessFn Process;
FrameHookReleaseFn Release;
void *ctx;
} FrameHookEntry;
static FrameHookEntry *first_hook;
/* Returns 0 on OK */
int frame_hook_add(int argc, char *argv[])
{
void *loaded;
FrameHookEntry *fhe, **fhep;
if (argc < 1) {
return ENOENT;
}
loaded = dlopen(argv[0], RTLD_NOW);
if (!loaded) {
av_log(NULL, AV_LOG_ERROR, "%s\n", dlerror());
return -1;
}
fhe = av_mallocz(sizeof(*fhe));
if (!fhe) {
return AVERROR(ENOMEM);
}
fhe->Configure = dlsym(loaded, "Configure");
fhe->Process = dlsym(loaded, "Process");
fhe->Release = dlsym(loaded, "Release"); /* Optional */
if (!fhe->Process) {
av_log(NULL, AV_LOG_ERROR, "Failed to find Process entrypoint in %s\n", argv[0]);
return AVERROR(ENOENT);
}
if (!fhe->Configure && argc > 1) {
av_log(NULL, AV_LOG_ERROR, "Failed to find Configure entrypoint in %s\n", argv[0]);
return AVERROR(ENOENT);
}
if (argc > 1 || fhe->Configure) {
if (fhe->Configure(&fhe->ctx, argc, argv)) {
av_log(NULL, AV_LOG_ERROR, "Failed to Configure %s\n", argv[0]);
return AVERROR(EINVAL);
}
}
for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
}
*fhep = fhe;
return 0;
}
void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
{
if (first_hook) {
FrameHookEntry *fhe;
for (fhe = first_hook; fhe; fhe = fhe->next) {
fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
}
}
}
void frame_hook_release(void)
{
FrameHookEntry *fhe;
FrameHookEntry *fhenext;
for (fhe = first_hook; fhe; fhe = fhenext) {
fhenext = fhe->next;
if (fhe->Release)
fhe->Release(fhe->ctx);
av_free(fhe);
}
first_hook = NULL;
}
/*
* video processing hooks
* copyright (c) 2000, 2001 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_FRAMEHOOK_H
#define AVFORMAT_FRAMEHOOK_H
#warning VHOOK is deprecated. Please help finishing libavfilter instead of wasting your time writing new filters for this crappy filter system.
/*
* Prototypes for interface to .so that implement a video processing hook
*/
#include "libavcodec/avcodec.h"
/* Function must be called 'Configure' */
typedef int (FrameHookConfigure)(void **ctxp, int argc, char *argv[]);
typedef FrameHookConfigure *FrameHookConfigureFn;
extern FrameHookConfigure Configure;
/* Function must be called 'Process' */
typedef void (FrameHookProcess)(void *ctx, struct AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts);
typedef FrameHookProcess *FrameHookProcessFn;
extern FrameHookProcess Process;
/* Function must be called 'Release' */
typedef void (FrameHookRelease)(void *ctx);
typedef FrameHookRelease *FrameHookReleaseFn;
extern FrameHookRelease Release;
int frame_hook_add(int argc, char *argv[]);
void frame_hook_process(struct AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts);
void frame_hook_release(void);
#endif /* AVFORMAT_FRAMEHOOK_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* Null Video Hook
* Copyright (c) 2002 Philip Gladstone
*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include "libavformat/framehook.h"
#include "libswscale/swscale.h"
static int sws_flags = SWS_BICUBIC;
typedef struct {
int dummy;
// This vhook first converts frame to RGB ...
struct SwsContext *toRGB_convert_ctx;
// ... and later converts back frame from RGB to initial format
struct SwsContext *fromRGB_convert_ctx;
} ContextInfo;
void Release(void *ctx)
{
ContextInfo *ci;
ci = (ContextInfo *) ctx;
if (ctx) {
sws_freeContext(ci->toRGB_convert_ctx);
sws_freeContext(ci->fromRGB_convert_ctx);
av_free(ctx);
}
}
int Configure(void **ctxp, int argc, char *argv[])
{
av_log(NULL, AV_LOG_DEBUG, "Called with argc=%d\n", argc);
*ctxp = av_mallocz(sizeof(ContextInfo));
return 0;
}
void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
{
ContextInfo *ci = (ContextInfo *) ctx;
char *buf = 0;
AVPicture picture1;
AVPicture *pict = picture;
(void) ci;
if (pix_fmt != PIX_FMT_RGB24) {
int size;
size = avpicture_get_size(PIX_FMT_RGB24, width, height);
buf = av_malloc(size);
avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
// if we already got a SWS context, let's realloc if is not re-useable
ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
width, height, pix_fmt,
width, height, PIX_FMT_RGB24,
sws_flags, NULL, NULL, NULL);
if (ci->toRGB_convert_ctx == NULL) {
av_log(NULL, AV_LOG_ERROR,
"Cannot initialize the toRGB conversion context\n");
return;
}
// img_convert parameters are 2 first destination, then 4 source
// sws_scale parameters are context, 4 first source, then 2 destination
sws_scale(ci->toRGB_convert_ctx,
picture->data, picture->linesize, 0, height,
picture1.data, picture1.linesize);
pict = &picture1;
}
/* Insert filter code here */
if (pix_fmt != PIX_FMT_RGB24) {
ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
width, height, PIX_FMT_RGB24,
width, height, pix_fmt,
sws_flags, NULL, NULL, NULL);
if (ci->fromRGB_convert_ctx == NULL) {
av_log(NULL, AV_LOG_ERROR,
"Cannot initialize the fromRGB conversion context\n");
return;
}
// img_convert parameters are 2 first destination, then 4 source
// sws_scale parameters are context, 4 first source, then 2 destination
sws_scale(ci->fromRGB_convert_ctx,
picture1.data, picture1.linesize, 0, height,
picture->data, picture->linesize);
}
av_free(buf);
}
/*
* PPM Video Hook
* Copyright (c) 2003 Charles Yates
*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <ctype.h>
#include "libavutil/avstring.h"
#include "libavformat/framehook.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#undef fprintf
static int sws_flags = SWS_BICUBIC;
/** Bi-directional pipe structure.
*/
typedef struct rwpipe
{
int pid;
FILE *reader;
FILE *writer;
}
rwpipe;
/** Create a bidirectional pipe for the given command.
*/
static rwpipe *rwpipe_open( int argc, char *argv[] )
{
rwpipe *this = av_mallocz( sizeof( rwpipe ) );
if ( this != NULL )
{
int input[ 2 ];
int output[ 2 ];
if (!pipe( input ))
return NULL;
if (!pipe( output ))
return NULL;
this->pid = fork();
if ( this->pid == 0 )
{
#define COMMAND_SIZE 10240
char *command = av_mallocz( COMMAND_SIZE );
int i;
strcpy( command, "" );
for ( i = 0; i < argc; i ++ )
{
av_strlcat( command, argv[ i ], COMMAND_SIZE );
av_strlcat( command, " ", COMMAND_SIZE );
}
dup2( output[ 0 ], STDIN_FILENO );
dup2( input[ 1 ], STDOUT_FILENO );
close( input[ 0 ] );
close( input[ 1 ] );
close( output[ 0 ] );
close( output[ 1 ] );
execl("/bin/sh", "sh", "-c", command, (char*)NULL );
_exit( 255 );
}
else
{
close( input[ 1 ] );
close( output[ 0 ] );
this->reader = fdopen( input[ 0 ], "r" );
this->writer = fdopen( output[ 1 ], "w" );
}
}
return this;
}
/** Read data from the pipe.
*/
static FILE *rwpipe_reader( rwpipe *this )
{
if ( this != NULL )
return this->reader;
else
return NULL;
}
/** Write data to the pipe.
*/
static FILE *rwpipe_writer( rwpipe *this )
{
if ( this != NULL )
return this->writer;
else
return NULL;
}
/* Read a number from the pipe - assumes PNM style headers.
*/
static int rwpipe_read_number( rwpipe *rw )
{
int value = 0;
int c = 0;
FILE *in = rwpipe_reader( rw );
do
{
c = fgetc( in );
while( c != EOF && !isdigit( c ) && c != '#' )
c = fgetc( in );
if ( c == '#' )
while( c != EOF && c != '\n' )
c = fgetc( in );
}
while ( c != EOF && !isdigit( c ) );
while( c != EOF && isdigit( c ) )
{
value = value * 10 + ( c - '0' );
c = fgetc( in );
}
return value;
}
/** Read a PPM P6 header.
*/
static int rwpipe_read_ppm_header( rwpipe *rw, int *width, int *height )
{
char line[ 3 ];
FILE *in = rwpipe_reader( rw );
int max;
if (!fgets( line, 3, in ))
return -1;
if ( !strncmp( line, "P6", 2 ) )
{
*width = rwpipe_read_number( rw );
*height = rwpipe_read_number( rw );
max = rwpipe_read_number( rw );
return max != 255 || *width <= 0 || *height <= 0;
}
return 1;
}
/** Close the pipe and process.
*/
static void rwpipe_close( rwpipe *this )
{
if ( this != NULL )
{
fclose( this->reader );
fclose( this->writer );
waitpid( this->pid, NULL, 0 );
av_free( this );
}
}
/** Context info for this vhook - stores the pipe and image buffers.
*/
typedef struct
{
rwpipe *rw;
int size1;
char *buf1;
int size2;
char *buf2;
// This vhook first converts frame to RGB ...
struct SwsContext *toRGB_convert_ctx;
// ... then processes it via a PPM command pipe ...
// ... and finally converts back frame from RGB to initial format
struct SwsContext *fromRGB_convert_ctx;
}
ContextInfo;
/** Initialise the context info for this vhook.
*/
int Configure(void **ctxp, int argc, char *argv[])
{
if ( argc > 1 )
{
*ctxp = av_mallocz(sizeof(ContextInfo));
if ( *ctxp != NULL && argc > 1 )
{
ContextInfo *info = (ContextInfo *)*ctxp;
info->rw = rwpipe_open( argc - 1, &argv[ 1 ] );
return 0;
}
}
return 1;
}
/** Process a frame.
*/
void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
{
int err = 0;
ContextInfo *ci = (ContextInfo *) ctx;
AVPicture picture1;
AVPicture picture2;
AVPicture *pict = picture;
int out_width;
int out_height;
int i;
uint8_t *ptr = NULL;
FILE *in = rwpipe_reader( ci->rw );
FILE *out = rwpipe_writer( ci->rw );
/* Check that we have a pipe to talk to. */
if ( in == NULL || out == NULL )
err = 1;
/* Convert to RGB24 if necessary */
if ( !err && pix_fmt != PIX_FMT_RGB24 )
{
int size = avpicture_get_size(PIX_FMT_RGB24, width, height);
if ( size != ci->size1 )
{
av_free( ci->buf1 );
ci->buf1 = av_malloc(size);
ci->size1 = size;
err = ci->buf1 == NULL;
}
if ( !err )
{
avpicture_fill(&picture1, ci->buf1, PIX_FMT_RGB24, width, height);
// if we already got a SWS context, let's realloc if is not re-useable
ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
width, height, pix_fmt,
width, height, PIX_FMT_RGB24,
sws_flags, NULL, NULL, NULL);
if (ci->toRGB_convert_ctx == NULL) {
av_log(NULL, AV_LOG_ERROR,
"Cannot initialize the toRGB conversion context\n");
return;
}
// img_convert parameters are 2 first destination, then 4 source
// sws_scale parameters are context, 4 first source, then 2 destination
sws_scale(ci->toRGB_convert_ctx,
picture->data, picture->linesize, 0, height,
picture1.data, picture1.linesize);
pict = &picture1;
}
}
/* Write out the PPM */
if ( !err )
{
ptr = pict->data[ 0 ];
fprintf( out, "P6\n%d %d\n255\n", width, height );
for ( i = 0; !err && i < height; i ++ )
{
err = !fwrite( ptr, width * 3, 1, out );
ptr += pict->linesize[ 0 ];
}
if ( !err )
err = fflush( out );
}
/* Read the PPM returned. */
if ( !err && !rwpipe_read_ppm_header( ci->rw, &out_width, &out_height ) )
{
int size = avpicture_get_size(PIX_FMT_RGB24, out_width, out_height);
if ( size != ci->size2 )
{
av_free( ci->buf2 );
ci->buf2 = av_malloc(size);
ci->size2 = size;
err = ci->buf2 == NULL;
}
if ( !err )
{
avpicture_fill(&picture2, ci->buf2, PIX_FMT_RGB24, out_width, out_height);
ptr = picture2.data[ 0 ];
for ( i = 0; !err && i < out_height; i ++ )
{
err = !fread( ptr, out_width * 3, 1, in );
ptr += picture2.linesize[ 0 ];
}
}
}
/* Convert the returned PPM back to the input format */
if ( !err )
{
/* The out_width/out_height returned from the PPM
* filter won't necessarily be the same as width and height
* but it will be scaled anyway to width/height.
*/
av_log(NULL, AV_LOG_DEBUG,
"PPM vhook: Input dimensions: %d x %d Output dimensions: %d x %d\n",
width, height, out_width, out_height);
ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
out_width, out_height, PIX_FMT_RGB24,
width, height, pix_fmt,
sws_flags, NULL, NULL, NULL);
if (ci->fromRGB_convert_ctx == NULL) {
av_log(NULL, AV_LOG_ERROR,
"Cannot initialize the fromRGB conversion context\n");
return;
}
// img_convert parameters are 2 first destination, then 4 source
// sws_scale parameters are context, 4 first source, then 2 destination
sws_scale(ci->fromRGB_convert_ctx,
picture2.data, picture2.linesize, 0, out_height,
picture->data, picture->linesize);
}
}
/** Clean up the effect.
*/
void Release(void *ctx)
{
ContextInfo *ci;
ci = (ContextInfo *) ctx;
if (ctx)
{
rwpipe_close( ci->rw );
av_free( ci->buf1 );
av_free( ci->buf2 );
sws_freeContext(ci->toRGB_convert_ctx);
sws_freeContext(ci->fromRGB_convert_ctx);
av_free(ctx);
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment