00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <errno.h>
00022 #include "config.h"
00023 #include "avformat.h"
00024 #include "framehook.h"
00025
00026 #if HAVE_DLFCN_H
00027 #include <dlfcn.h>
00028 #endif
00029
00030
00031 typedef struct FrameHookEntry {
00032 struct FrameHookEntry *next;
00033 FrameHookConfigureFn Configure;
00034 FrameHookProcessFn Process;
00035 FrameHookReleaseFn Release;
00036 void *ctx;
00037 } FrameHookEntry;
00038
00039 static FrameHookEntry *first_hook;
00040
00041
00042 int frame_hook_add(int argc, char *argv[])
00043 {
00044 void *loaded;
00045 FrameHookEntry *fhe, **fhep;
00046
00047 if (argc < 1) {
00048 return ENOENT;
00049 }
00050
00051 loaded = dlopen(argv[0], RTLD_NOW);
00052 if (!loaded) {
00053 av_log(NULL, AV_LOG_ERROR, "%s\n", dlerror());
00054 return -1;
00055 }
00056
00057 fhe = av_mallocz(sizeof(*fhe));
00058 if (!fhe) {
00059 return AVERROR(ENOMEM);
00060 }
00061
00062 fhe->Configure = dlsym(loaded, "Configure");
00063 fhe->Process = dlsym(loaded, "Process");
00064 fhe->Release = dlsym(loaded, "Release");
00065
00066 if (!fhe->Process) {
00067 av_log(NULL, AV_LOG_ERROR, "Failed to find Process entrypoint in %s\n", argv[0]);
00068 return AVERROR(ENOENT);
00069 }
00070
00071 if (!fhe->Configure && argc > 1) {
00072 av_log(NULL, AV_LOG_ERROR, "Failed to find Configure entrypoint in %s\n", argv[0]);
00073 return AVERROR(ENOENT);
00074 }
00075
00076 if (argc > 1 || fhe->Configure) {
00077 if (fhe->Configure(&fhe->ctx, argc, argv)) {
00078 av_log(NULL, AV_LOG_ERROR, "Failed to Configure %s\n", argv[0]);
00079 return AVERROR(EINVAL);
00080 }
00081 }
00082
00083 for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
00084 }
00085
00086 *fhep = fhe;
00087
00088 return 0;
00089 }
00090
00091 void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
00092 {
00093 if (first_hook) {
00094 FrameHookEntry *fhe;
00095
00096 for (fhe = first_hook; fhe; fhe = fhe->next) {
00097 fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
00098 }
00099 }
00100 }
00101
00102 void frame_hook_release(void)
00103 {
00104 FrameHookEntry *fhe;
00105 FrameHookEntry *fhenext;
00106
00107 for (fhe = first_hook; fhe; fhe = fhenext) {
00108 fhenext = fhe->next;
00109 if (fhe->Release)
00110 fhe->Release(fhe->ctx);
00111 av_free(fhe);
00112 }
00113
00114 first_hook = NULL;
00115 }