2002-11-20 05:00:27 +02:00
|
|
|
/*
|
|
|
|
* Video processing hooks
|
|
|
|
* Copyright (c) 2000, 2001 Fabrice Bellard.
|
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-11-20 05:00:27 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2002-11-20 05:00:27 +02:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2002-11-20 05:00:27 +02:00
|
|
|
* 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
|
2006-10-07 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-13 00:43:26 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-11-20 05:00:27 +02:00
|
|
|
*/
|
|
|
|
#include <errno.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "avformat.h"
|
2004-02-22 02:31:19 +02:00
|
|
|
#include "framehook.h"
|
2002-11-20 05:00:27 +02:00
|
|
|
|
2006-11-15 01:53:37 +02:00
|
|
|
#ifdef HAVE_DLFCN_H
|
2002-11-20 05:00:27 +02:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _FrameHookEntry {
|
|
|
|
struct _FrameHookEntry *next;
|
|
|
|
FrameHookConfigureFn Configure;
|
|
|
|
FrameHookProcessFn Process;
|
2002-11-30 19:16:32 +02:00
|
|
|
FrameHookReleaseFn Release;
|
2002-11-20 05:00:27 +02:00
|
|
|
void *ctx;
|
|
|
|
} FrameHookEntry;
|
|
|
|
|
|
|
|
static FrameHookEntry *first_hook;
|
|
|
|
|
|
|
|
/* Returns 0 on OK */
|
|
|
|
int frame_hook_add(int argc, char *argv[])
|
|
|
|
{
|
2006-11-09 01:18:18 +02:00
|
|
|
#ifdef CONFIG_VHOOK
|
2002-11-20 05:00:27 +02:00
|
|
|
void *loaded;
|
|
|
|
FrameHookEntry *fhe, **fhep;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
loaded = dlopen(argv[0], RTLD_NOW);
|
|
|
|
if (!loaded) {
|
2005-07-13 13:18:35 +03:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "%s\n", dlerror());
|
2002-11-20 05:00:27 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fhe = av_mallocz(sizeof(*fhe));
|
|
|
|
if (!fhe) {
|
2007-01-28 11:07:49 +02:00
|
|
|
return -ENOMEM;
|
2002-11-20 05:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fhe->Configure = dlsym(loaded, "Configure");
|
|
|
|
fhe->Process = dlsym(loaded, "Process");
|
2002-11-30 19:16:32 +02:00
|
|
|
fhe->Release = dlsym(loaded, "Release"); /* Optional */
|
2002-11-20 05:00:27 +02:00
|
|
|
|
|
|
|
if (!fhe->Process) {
|
2005-07-13 13:18:35 +03:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "Failed to find Process entrypoint in %s\n", argv[0]);
|
2002-11-20 05:00:27 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fhe->Configure && argc > 1) {
|
2005-07-13 13:18:35 +03:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "Failed to find Configure entrypoint in %s\n", argv[0]);
|
2002-11-20 05:00:27 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1 || fhe->Configure) {
|
|
|
|
if (fhe->Configure(&fhe->ctx, argc, argv)) {
|
2005-07-13 13:18:35 +03:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "Failed to Configure %s\n", argv[0]);
|
2002-11-20 05:00:27 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
*fhep = fhe;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
#else
|
2005-07-13 13:18:35 +03:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "Video hooking not compiled into this version\n");
|
2002-11-20 05:00:27 +02:00
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height)
|
|
|
|
{
|
|
|
|
if (first_hook) {
|
|
|
|
FrameHookEntry *fhe;
|
2003-02-11 18:35:48 +02:00
|
|
|
int64_t pts = av_gettime();
|
2002-11-20 05:00:27 +02:00
|
|
|
|
|
|
|
for (fhe = first_hook; fhe; fhe = fhe->next) {
|
|
|
|
fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-11-30 19:16:32 +02:00
|
|
|
|
2003-02-10 11:35:32 +02:00
|
|
|
void frame_hook_release(void)
|
2002-11-30 19:16:32 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|