mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
spa examples: Load plugins from SPA_PLUGIN_DIR or installed path
This lets them be used installed or uninstalled, like pipewire itself. Signed-off-by: Simon McVittie <smcv@debian.org>
This commit is contained in:
parent
cecbe8ff17
commit
8b97d2ae74
5 changed files with 99 additions and 32 deletions
|
|
@ -24,6 +24,9 @@
|
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -54,8 +57,6 @@
|
|||
|
||||
static SPA_LOG_IMPL(default_log);
|
||||
|
||||
#define PATH "build/spa/plugins/"
|
||||
|
||||
#define MAX_BUFFERS 8
|
||||
|
||||
#define USE_BUFFER false
|
||||
|
|
@ -70,6 +71,7 @@ struct buffer {
|
|||
};
|
||||
|
||||
struct data {
|
||||
const char *plugin_dir;
|
||||
struct spa_log *log;
|
||||
struct spa_system *system;
|
||||
struct spa_loop *loop;
|
||||
|
|
@ -103,10 +105,17 @@ static int load_handle(struct data *data, struct spa_handle **handle, const char
|
|||
spa_handle_factory_enum_func_t enum_func;
|
||||
uint32_t i;
|
||||
|
||||
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
|
||||
printf("can't load %s: %s\n", lib, dlerror());
|
||||
char *path = NULL;
|
||||
|
||||
if ((path = spa_aprintf("%s/%s", data->plugin_dir, lib)) == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
if ((hnd = dlopen(path, RTLD_NOW)) == NULL) {
|
||||
printf("can't load %s: %s\n", path, dlerror());
|
||||
free(path);
|
||||
return -errno;
|
||||
}
|
||||
free(path);
|
||||
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
|
||||
printf("can't find enum function\n");
|
||||
return -errno;
|
||||
|
|
@ -245,7 +254,7 @@ static int make_nodes(struct data *data, const char *device)
|
|||
|
||||
if ((res =
|
||||
make_node(data, &data->source,
|
||||
PATH "libcamera/libspa-libcamera.so",
|
||||
"libcamera/libspa-libcamera.so",
|
||||
SPA_NAME_API_LIBCAMERA_SOURCE)) < 0) {
|
||||
printf("can't create libcamera-source: %d\n", res);
|
||||
return res;
|
||||
|
|
@ -472,8 +481,12 @@ int main(int argc, char *argv[])
|
|||
struct spa_handle *handle = NULL;
|
||||
void *iface;
|
||||
|
||||
if ((str = getenv("SPA_PLUGIN_DIR")) == NULL)
|
||||
str = PLUGINDIR;
|
||||
data.plugin_dir = str;
|
||||
|
||||
if ((res = load_handle(&data, &handle,
|
||||
PATH "support/libspa-support.so",
|
||||
"support/libspa-support.so",
|
||||
SPA_NAME_SUPPORT_SYSTEM)) < 0)
|
||||
return res;
|
||||
|
||||
|
|
@ -485,7 +498,7 @@ int main(int argc, char *argv[])
|
|||
data.support[data.n_support++] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_System, data.system);
|
||||
|
||||
if ((res = load_handle(&data, &handle,
|
||||
PATH "support/libspa-support.so",
|
||||
"support/libspa-support.so",
|
||||
SPA_NAME_SUPPORT_LOOP)) < 0)
|
||||
return res;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue