0
|
1 /*
|
|
2 * Video processing hooks
|
|
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
|
|
4 *
|
|
5 * This library is free software; you can redistribute it and/or
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
7 * License as published by the Free Software Foundation; either
|
|
8 * version 2 of the License, or (at your option) any later version.
|
|
9 *
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 * Lesser General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
16 * License along with this library; if not, write to the Free Software
|
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 */
|
|
19 #include <errno.h>
|
|
20 #include "config.h"
|
|
21 #include "framehook.h"
|
|
22 #include "avformat.h"
|
|
23
|
|
24 #ifdef HAVE_VHOOK
|
|
25 #include <dlfcn.h>
|
|
26 #endif
|
|
27
|
|
28
|
|
29 typedef struct _FrameHookEntry {
|
|
30 struct _FrameHookEntry *next;
|
|
31 FrameHookConfigureFn Configure;
|
|
32 FrameHookProcessFn Process;
|
|
33 void *ctx;
|
|
34 } FrameHookEntry;
|
|
35
|
|
36 static FrameHookEntry *first_hook;
|
|
37
|
|
38 /* Returns 0 on OK */
|
|
39 int frame_hook_add(int argc, char *argv[])
|
|
40 {
|
|
41 #ifdef HAVE_VHOOK
|
|
42 void *loaded;
|
|
43 FrameHookEntry *fhe, **fhep;
|
|
44
|
|
45 if (argc < 1) {
|
|
46 return ENOENT;
|
|
47 }
|
|
48
|
|
49 loaded = dlopen(argv[0], RTLD_NOW);
|
|
50 if (!loaded) {
|
|
51 fprintf(stderr, "%s\n", dlerror());
|
|
52 return -1;
|
|
53 }
|
|
54
|
|
55 fhe = av_mallocz(sizeof(*fhe));
|
|
56 if (!fhe) {
|
|
57 return errno;
|
|
58 }
|
|
59
|
|
60 fhe->Configure = dlsym(loaded, "Configure");
|
|
61 fhe->Process = dlsym(loaded, "Process");
|
|
62
|
|
63 if (!fhe->Process) {
|
|
64 fprintf(stderr, "Failed to find Process entrypoint in %s\n", argv[0]);
|
|
65 return -1;
|
|
66 }
|
|
67
|
|
68 if (!fhe->Configure && argc > 1) {
|
|
69 fprintf(stderr, "Failed to find Configure entrypoint in %s\n", argv[0]);
|
|
70 return -1;
|
|
71 }
|
|
72
|
|
73 if (argc > 1 || fhe->Configure) {
|
|
74 if (fhe->Configure(&fhe->ctx, argc, argv)) {
|
|
75 fprintf(stderr, "Failed to Configure %s\n", argv[0]);
|
|
76 return -1;
|
|
77 }
|
|
78 }
|
|
79
|
|
80 for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
|
|
81 }
|
|
82
|
|
83 *fhep = fhe;
|
|
84
|
|
85 return 0;
|
|
86 #else
|
|
87 fprintf(stderr, "Video hooking not compiled into this version\n");
|
|
88 return 1;
|
|
89 #endif
|
|
90 }
|
|
91
|
|
92 void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height)
|
|
93 {
|
|
94 if (first_hook) {
|
|
95 FrameHookEntry *fhe;
|
|
96 INT64 pts = av_gettime();
|
|
97
|
|
98 for (fhe = first_hook; fhe; fhe = fhe->next) {
|
|
99 fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
|
|
100 }
|
|
101 }
|
|
102 }
|