]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/framehook.c
parse pict_type for streams in avi
[ffmpeg] / libavformat / framehook.c
index 03ee32e1885dac99fd62d8e92f376a5ea00fa9e8..18be8a753e68964525b3afad23a326ba37677388 100644 (file)
  */
 #include <errno.h>
 #include "config.h"
-#include "framehook.h"
 #include "avformat.h"
+#include "framehook.h"
 
-#ifdef HAVE_VHOOK
+#ifdef CONFIG_HAVE_DLFCN
 #include <dlfcn.h>
 #endif
 
@@ -30,6 +30,7 @@ typedef struct _FrameHookEntry {
     struct _FrameHookEntry *next;
     FrameHookConfigureFn Configure;
     FrameHookProcessFn Process;
+    FrameHookReleaseFn Release;
     void *ctx;
 } FrameHookEntry;
 
@@ -48,7 +49,7 @@ int frame_hook_add(int argc, char *argv[])
 
     loaded = dlopen(argv[0], RTLD_NOW);
     if (!loaded) {
-        fprintf(stderr, "%s\n", dlerror());
+        av_log(NULL, AV_LOG_ERROR, "%s\n", dlerror());
         return -1;
     }
 
@@ -59,20 +60,21 @@ int frame_hook_add(int argc, char *argv[])
 
     fhe->Configure = dlsym(loaded, "Configure");
     fhe->Process = dlsym(loaded, "Process");
+    fhe->Release = dlsym(loaded, "Release");    /* Optional */
 
     if (!fhe->Process) {
-        fprintf(stderr, "Failed to find Process entrypoint in %s\n", argv[0]);
+        av_log(NULL, AV_LOG_ERROR, "Failed to find Process entrypoint in %s\n", argv[0]);
         return -1;
     }
 
     if (!fhe->Configure && argc > 1) {
-        fprintf(stderr, "Failed to find Configure entrypoint in %s\n", argv[0]);
+        av_log(NULL, AV_LOG_ERROR, "Failed to find Configure entrypoint in %s\n", argv[0]);
         return -1;
     }
 
     if (argc > 1 || fhe->Configure) {
         if (fhe->Configure(&fhe->ctx, argc, argv)) {
-            fprintf(stderr, "Failed to Configure %s\n", argv[0]);
+            av_log(NULL, AV_LOG_ERROR, "Failed to Configure %s\n", argv[0]);
             return -1;
         }
     }
@@ -84,7 +86,7 @@ int frame_hook_add(int argc, char *argv[])
 
     return 0;
 #else
-    fprintf(stderr, "Video hooking not compiled into this version\n");
+    av_log(NULL, AV_LOG_ERROR, "Video hooking not compiled into this version\n");
     return 1;
 #endif
 }
@@ -93,10 +95,25 @@ void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, in
 {
     if (first_hook) {
         FrameHookEntry *fhe;
-        INT64 pts = av_gettime();
+        int64_t pts = av_gettime();
 
         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;
+}