Skip to content

Instantly share code, notes, and snippets.

@tinyzimmer
Created January 4, 2021 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinyzimmer/2fb84f8816063e6e709f3290b255a841 to your computer and use it in GitHub Desktop.
Save tinyzimmer/2fb84f8816063e6e709f3290b255a841 to your computer and use it in GitHub Desktop.
$ ./test.o
name: test-plugin
Hello world
Plugin loaded successfully
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() {}
#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