• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavformat/framehook.c

Go to the documentation of this file.
00001 /*
00002  * Video processing hooks
00003  * Copyright (c) 2000, 2001 Fabrice Bellard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 /* Returns 0 on OK */
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");    /* Optional */
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 }

Generated on Tue Nov 4 2014 12:59:23 for ffmpeg by  doxygen 1.7.1