forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGStreamerLoader.cpp
116 lines (94 loc) · 2.58 KB
/
GStreamerLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <dlfcn.h>
#include <stdio.h>
#include "GStreamerLoader.h"
#define LIBGSTREAMER 0
#define LIBGSTAPP 1
#define LIBGSTVIDEO 2
namespace mozilla {
/*
* Declare our function pointers using the types from the global gstreamer
* definitions.
*/
#define GST_FUNC(_, func) typeof(::func)* func;
#define REPLACE_FUNC(func) GST_FUNC(-1, func)
#include "GStreamerFunctionList.h"
#undef GST_FUNC
#undef REPLACE_FUNC
/*
* Redefinitions of functions that have been defined in the gstreamer headers to
* stop them calling the gstreamer functions in global scope.
*/
GstBuffer * gst_buffer_ref_impl(GstBuffer *buf);
void gst_buffer_unref_impl(GstBuffer *buf);
void gst_message_unref_impl(GstMessage *msg);
bool
load_gstreamer()
{
#ifdef __APPLE__
return true;
#endif
static bool loaded = false;
if (loaded) {
return true;
}
void *gstreamerLib = NULL;
guint major = 0;
guint minor = 0;
guint micro, nano;
typedef typeof(::gst_version) VersionFuncType;
if (VersionFuncType *versionFunc = (VersionFuncType*)dlsym(RTLD_DEFAULT, "gst_version")) {
versionFunc(&major, &minor, µ, &nano);
}
if (major == GST_VERSION_MAJOR && minor == GST_VERSION_MINOR) {
gstreamerLib = RTLD_DEFAULT;
} else {
gstreamerLib = dlopen("libgstreamer-0.10.so.0", RTLD_NOW | RTLD_LOCAL);
}
void *handles[] = {
gstreamerLib,
dlopen("libgstapp-0.10.so.0", RTLD_NOW | RTLD_LOCAL),
dlopen("libgstvideo-0.10.so.0", RTLD_NOW | RTLD_LOCAL)
};
for (size_t i = 0; i < sizeof(handles) / sizeof(handles[0]); i++) {
if (!handles[i]) {
goto fail;
}
}
#define GST_FUNC(lib, symbol) \
if (!(symbol = (typeof(symbol))dlsym(handles[lib], #symbol))) { \
goto fail; \
}
#define REPLACE_FUNC(symbol) symbol = symbol##_impl;
#include "GStreamerFunctionList.h"
#undef GST_FUNC
#undef REPLACE_FUNC
loaded = true;
return true;
fail:
for (size_t i = 0; i < sizeof(handles) / sizeof(handles[0]); i++) {
if (handles[i] && handles[i] != RTLD_DEFAULT) {
dlclose(handles[i]);
}
}
return false;
}
GstBuffer *
gst_buffer_ref_impl(GstBuffer *buf)
{
return (GstBuffer *)gst_mini_object_ref(GST_MINI_OBJECT_CAST(buf));
}
void
gst_buffer_unref_impl(GstBuffer *buf)
{
gst_mini_object_unref(GST_MINI_OBJECT_CAST(buf));
}
void
gst_message_unref_impl(GstMessage *msg)
{
gst_mini_object_unref(GST_MINI_OBJECT_CAST(msg));
}
}