Created
January 4, 2021 12:30
-
-
Save tinyzimmer/2fb84f8816063e6e709f3290b255a841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./test.o | |
name: test-plugin | |
Hello world | |
Plugin loaded successfully |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "C" | |
import ( | |
"fmt" | |
"unsafe" | |
"github.com/tinyzimmer/go-gst/gst" | |
) | |
var pluginMeta = &gst.PluginMetadata{ | |
MajorVersion: gst.VersionMajor, | |
MinorVersion: gst.VersionMinor, | |
Name: "test-plugin", | |
Description: "Test plugin plugin", | |
Init: initPlugin, | |
Version: "v0.0.1", | |
License: gst.LicenseLGPL, | |
Source: "go-gst", | |
Package: "examples", | |
Origin: "https://github.com/tinyzimmer/go-gst", | |
} | |
//export gst_plugin_test_plugin_get_desc | |
func gst_plugin_test_plugin_get_desc() unsafe.Pointer { return pluginMeta.Export() } | |
func initPlugin(plugin *gst.Plugin) bool { | |
fmt.Println("Hello world") | |
return true | |
} | |
func main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dlfcn.h> | |
#include <stdio.h> | |
#include "gst/gst.h" | |
typedef GstPluginDesc * (*get_desc)(); | |
int main () { | |
void *plugin = dlopen("./test-plugin.so", RTLD_NOW); | |
get_desc func = dlsym(plugin, "gst_plugin_test_plugin_get_desc"); | |
GstPluginDesc *desc = func(); | |
printf("name: %s\n", desc->name); | |
gboolean res = desc->plugin_init(NULL); | |
if (res == TRUE) | |
printf("Plugin loaded successfully\n"); | |
else | |
printf("Plugin did not load successfully\n"); | |
dlclose(plugin); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment