Statistics
| Branch: | Revision:

ffmpeg / libavformat / framehook.c @ d2062ff6

History | View | Annotate | Download (3.05 KB)

1 3b2cbbed Philip Gladstone
/*
2
 * Video processing hooks
3
 * Copyright (c) 2000, 2001 Fabrice Bellard.
4
 *
5 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8 3b2cbbed Philip Gladstone
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
11 3b2cbbed Philip Gladstone
 *
12 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
13 3b2cbbed Philip Gladstone
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
19 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 3b2cbbed Philip Gladstone
 */
21
#include <errno.h>
22
#include "config.h"
23
#include "avformat.h"
24 d705e4a6 Michael Niedermayer
#include "framehook.h"
25 3b2cbbed Philip Gladstone
26 18b67ae5 Måns Rullgård
#ifdef HAVE_DLFCN_H
27 3b2cbbed Philip Gladstone
#include <dlfcn.h>
28
#endif
29
30
31
typedef struct _FrameHookEntry {
32
    struct _FrameHookEntry *next;
33
    FrameHookConfigureFn Configure;
34
    FrameHookProcessFn Process;
35 042f2465 Philip Gladstone
    FrameHookReleaseFn Release;
36 3b2cbbed Philip Gladstone
    void *ctx;
37
} FrameHookEntry;
38
39
static FrameHookEntry *first_hook;
40
41
/* Returns 0 on OK */
42
int frame_hook_add(int argc, char *argv[])
43
{
44 d226c750 Måns Rullgård
#ifdef CONFIG_VHOOK
45 3b2cbbed Philip Gladstone
    void *loaded;
46
    FrameHookEntry *fhe, **fhep;
47
48
    if (argc < 1) {
49
        return ENOENT;
50
    }
51
52
    loaded = dlopen(argv[0], RTLD_NOW);
53
    if (!loaded) {
54 58379c06 Benjamin Larsson
        av_log(NULL, AV_LOG_ERROR, "%s\n", dlerror());
55 3b2cbbed Philip Gladstone
        return -1;
56
    }
57
58
    fhe = av_mallocz(sizeof(*fhe));
59
    if (!fhe) {
60 8fa36ae0 François Revol
        return AVERROR(ENOMEM);
61 3b2cbbed Philip Gladstone
    }
62
63
    fhe->Configure = dlsym(loaded, "Configure");
64
    fhe->Process = dlsym(loaded, "Process");
65 042f2465 Philip Gladstone
    fhe->Release = dlsym(loaded, "Release");    /* Optional */
66 3b2cbbed Philip Gladstone
67
    if (!fhe->Process) {
68 58379c06 Benjamin Larsson
        av_log(NULL, AV_LOG_ERROR, "Failed to find Process entrypoint in %s\n", argv[0]);
69 8fa36ae0 François Revol
        return AVERROR(ENOENT);
70 3b2cbbed Philip Gladstone
    }
71
72
    if (!fhe->Configure && argc > 1) {
73 58379c06 Benjamin Larsson
        av_log(NULL, AV_LOG_ERROR, "Failed to find Configure entrypoint in %s\n", argv[0]);
74 8fa36ae0 François Revol
        return AVERROR(ENOENT);
75 3b2cbbed Philip Gladstone
    }
76
77
    if (argc > 1 || fhe->Configure) {
78
        if (fhe->Configure(&fhe->ctx, argc, argv)) {
79 58379c06 Benjamin Larsson
            av_log(NULL, AV_LOG_ERROR, "Failed to Configure %s\n", argv[0]);
80 8fa36ae0 François Revol
            return AVERROR(EINVAL);
81 3b2cbbed Philip Gladstone
        }
82
    }
83
84
    for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
85
    }
86
87
    *fhep = fhe;
88
89
    return 0;
90
#else
91 58379c06 Benjamin Larsson
    av_log(NULL, AV_LOG_ERROR, "Video hooking not compiled into this version\n");
92 3b2cbbed Philip Gladstone
    return 1;
93
#endif
94
}
95
96 4992d8bf Bobby Bingham
void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
97 3b2cbbed Philip Gladstone
{
98
    if (first_hook) {
99
        FrameHookEntry *fhe;
100
101
        for (fhe = first_hook; fhe; fhe = fhe->next) {
102
            fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
103
        }
104
    }
105
}
106 042f2465 Philip Gladstone
107 5c91a675 Zdenek Kabelac
void frame_hook_release(void)
108 042f2465 Philip Gladstone
{
109
    FrameHookEntry *fhe;
110
    FrameHookEntry *fhenext;
111
112
    for (fhe = first_hook; fhe; fhe = fhenext) {
113
        fhenext = fhe->next;
114
        if (fhe->Release)
115
            fhe->Release(fhe->ctx);
116
        av_free(fhe);
117
    }
118
119
    first_hook = NULL;
120
}