diff --git a/spa/examples/adapter-control.c b/spa/examples/adapter-control.c index c80c8601c..8a3daf590 100644 --- a/spa/examples/adapter-control.c +++ b/spa/examples/adapter-control.c @@ -22,6 +22,9 @@ * DEALINGS IN THE SOFTWARE. */ + +#include "config.h" + #include #include #include @@ -59,6 +62,7 @@ struct buffer { }; struct data { + const char *plugin_dir; struct spa_log *log; struct spa_system *system; struct spa_loop *loop; @@ -95,11 +99,17 @@ static int load_handle(struct data *data, struct spa_handle **handle, const char void *hnd; spa_handle_factory_enum_func_t enum_func; uint32_t i; + char *path; - if ((hnd = dlopen(lib, RTLD_NOW)) == 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", lib, dlerror()); + free(path); return -ENOENT; } + free(path); if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) { printf("can't find enum function\n"); return -ENOENT; @@ -137,6 +147,10 @@ int init_data(struct data *data) struct spa_handle *handle = NULL; void *iface; + if ((str = getenv("SPA_PLUGIN_DIR")) == NULL) + str = PLUGINDIR; + data->plugin_dir = str; + /* init the graph */ spa_graph_init(&data->graph, &data->graph_state); @@ -146,7 +160,7 @@ int init_data(struct data *data) /* load and set support system */ if ((res = load_handle(data, &handle, - "build/spa/plugins/support/libspa-support.so", + "support/libspa-support.so", SPA_NAME_SUPPORT_SYSTEM)) < 0) return res; if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_System, &iface)) < 0) { @@ -159,7 +173,7 @@ int init_data(struct data *data) /* load and set support loop and loop control */ if ((res = load_handle(data, &handle, - "build/spa/plugins/support/libspa-support.so", + "support/libspa-support.so", SPA_NAME_SUPPORT_LOOP)) < 0) return res; @@ -190,11 +204,17 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, void *hnd; spa_handle_factory_enum_func_t enum_func; uint32_t i; + char *path; - if ((hnd = dlopen(lib, RTLD_NOW)) == 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", lib, dlerror()); + free(path); return -ENOENT; } + free(path); if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) { printf("can't find enum function\n"); return -ENOENT; @@ -269,7 +289,7 @@ static int make_nodes(struct data *data, const char *device) /* make the source node (audiotestsrc) */ if ((res = make_node(data, &data->source_follower_node, - "build/spa/plugins/audiotestsrc/libspa-audiotestsrc.so", + "audiotestsrc/libspa-audiotestsrc.so", "audiotestsrc", NULL)) < 0) { printf("can't create source follower node (audiotestsrc): %d\n", res); @@ -294,7 +314,7 @@ static int make_nodes(struct data *data, const char *device) snprintf(value, sizeof(value), "pointer:%p", data->source_follower_node); items[0] = SPA_DICT_ITEM_INIT("audio.adapt.follower", value); if ((res = make_node(data, &data->source_node, - "build/spa/plugins/audioconvert/libspa-audioconvert.so", + "audioconvert/libspa-audioconvert.so", SPA_NAME_AUDIO_ADAPT, &SPA_DICT_INIT(items, 1))) < 0) { printf("can't create source adapter node: %d\n", res); @@ -333,7 +353,7 @@ static int make_nodes(struct data *data, const char *device) /* make the sink follower node (alsa-pcm-sink) */ if ((res = make_node(data, &data->sink_follower_node, - "build/spa/plugins/alsa/libspa-alsa.so", + "alsa/libspa-alsa.so", SPA_NAME_API_ALSA_PCM_SINK, NULL)) < 0) { printf("can't create sink follower node (alsa-pcm-sink): %d\n", res); @@ -344,7 +364,7 @@ static int make_nodes(struct data *data, const char *device) snprintf(value, sizeof(value), "pointer:%p", data->sink_follower_node); items[0] = SPA_DICT_ITEM_INIT("audio.adapt.follower", value); if ((res = make_node(data, &data->sink_node, - "build/spa/plugins/audioconvert/libspa-audioconvert.so", + "audioconvert/libspa-audioconvert.so", SPA_NAME_AUDIO_ADAPT, &SPA_DICT_INIT(items, 1))) < 0) { printf("can't create sink adapter node: %d\n", res); diff --git a/spa/examples/example-control.c b/spa/examples/example-control.c index 6f54db524..29052f520 100644 --- a/spa/examples/example-control.c +++ b/spa/examples/example-control.c @@ -22,6 +22,8 @@ * DEALINGS IN THE SOFTWARE. */ +#include "config.h" + #include #include #include @@ -63,6 +65,7 @@ struct buffer { }; struct data { + const char *plugin_dir; struct spa_log *log; struct spa_system *system; struct spa_loop *loop; @@ -141,11 +144,17 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, void *hnd; spa_handle_factory_enum_func_t enum_func; uint32_t i; + char *path; - if ((hnd = dlopen(lib, RTLD_NOW)) == 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", lib, dlerror()); + free(path); return -ENOENT; } + free(path); if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) { printf("can't find enum function\n"); return -ENOENT; @@ -256,7 +265,7 @@ static int make_nodes(struct data *data, const char *device) //uint32_t idx; if ((res = make_node(data, &data->sink, - "build/spa/plugins/alsa/libspa-alsa.so", + "alsa/libspa-alsa.so", SPA_NAME_API_ALSA_PCM_SINK)) < 0) { printf("can't create alsa-sink: %d\n", res); return res; @@ -275,7 +284,7 @@ static int make_nodes(struct data *data, const char *device) printf("got set_props error %d\n", res); if ((res = make_node(data, &data->source, - "build/spa/plugins/audiotestsrc/libspa-audiotestsrc.so", + "audiotestsrc/libspa-audiotestsrc.so", "audiotestsrc")) < 0) { printf("can't create audiotestsrc: %d\n", res); return res; @@ -421,11 +430,17 @@ static int load_handle(struct data *data, struct spa_handle **handle, const char void *hnd; spa_handle_factory_enum_func_t enum_func; uint32_t i; + char *path; - if ((hnd = dlopen(lib, RTLD_NOW)) == 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", lib, dlerror()); + free(path); return -ENOENT; } + free(path); if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) { printf("can't find enum function\n"); return -ENOENT; @@ -463,6 +478,10 @@ int init_data(struct data *data) struct spa_handle *handle = NULL; void *iface; + if ((str = getenv("SPA_PLUGIN_DIR")) == NULL) + str = PLUGINDIR; + data->plugin_dir = str; + /* init the graph */ spa_graph_init(&data->graph, &data->graph_state); @@ -472,7 +491,7 @@ int init_data(struct data *data) /* load and set support system */ if ((res = load_handle(data, &handle, - "build/spa/plugins/support/libspa-support.so", + "support/libspa-support.so", SPA_NAME_SUPPORT_SYSTEM)) < 0) return res; if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_System, &iface)) < 0) { @@ -485,7 +504,7 @@ int init_data(struct data *data) /* load and set support loop and loop control */ if ((res = load_handle(data, &handle, - "build/spa/plugins/support/libspa-support.so", + "support/libspa-support.so", SPA_NAME_SUPPORT_LOOP)) < 0) return res; diff --git a/spa/examples/local-libcamera.c b/spa/examples/local-libcamera.c index cd08a5b37..bd9ff62be 100644 --- a/spa/examples/local-libcamera.c +++ b/spa/examples/local-libcamera.c @@ -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 #include #include @@ -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; diff --git a/spa/examples/local-v4l2.c b/spa/examples/local-v4l2.c index a8466c2b6..7bb8b61d1 100644 --- a/spa/examples/local-v4l2.c +++ b/spa/examples/local-v4l2.c @@ -22,6 +22,8 @@ * DEALINGS IN THE SOFTWARE. */ +#include "config.h" + #include #include #include @@ -49,8 +51,6 @@ static SPA_LOG_IMPL(default_log); -#define PATH "build/spa/plugins/" - #define MAX_BUFFERS 8 struct buffer { @@ -63,6 +63,7 @@ struct buffer { }; struct data { + const char *plugin_dir; struct spa_log *log; struct spa_system *system; struct spa_loop *loop; @@ -95,11 +96,17 @@ static int load_handle(struct data *data, struct spa_handle **handle, const char void *hnd; spa_handle_factory_enum_func_t enum_func; uint32_t i; + char *path = NULL; - if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) { - printf("can't load %s: %s\n", lib, dlerror()); + 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 -ENOENT; } + free(path); if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) { printf("can't find enum function\n"); return -ENOENT; @@ -240,7 +247,7 @@ static int make_nodes(struct data *data, const char *device) if ((res = make_node(data, &data->source, - PATH "v4l2/libspa-v4l2.so", + "v4l2/libspa-v4l2.so", SPA_NAME_API_V4L2_SOURCE)) < 0) { printf("can't create v4l2-source: %d\n", res); return res; @@ -465,8 +472,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; @@ -478,7 +489,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; diff --git a/spa/examples/meson.build b/spa/examples/meson.build index ba5615b3b..e00440e28 100644 --- a/spa/examples/meson.build +++ b/spa/examples/meson.build @@ -1,23 +1,27 @@ if sdl_dep.found() executable('local-v4l2', 'local-v4l2.c', - include_directories : [spa_inc ], + include_directories : [configinc, spa_inc], + c_args : ['-D_GNU_SOURCE'], dependencies : [dl_lib, sdl_dep, pthread_lib], install : false) if get_option('libcamera') and libcamera_dep.found() executable('local-libcamera', 'local-libcamera.c', - include_directories : [spa_inc ], + include_directories : [configinc, spa_inc], + c_args : ['-D_GNU_SOURCE'], dependencies : [dl_lib, sdl_dep, pthread_lib, libcamera_dep], install : false) endif endif executable('example-control', 'example-control.c', - include_directories : [spa_inc ], + include_directories : [configinc, spa_inc], + c_args : ['-D_GNU_SOURCE'], dependencies : [dl_lib, pthread_lib, mathlib], install : false) executable('adapter-control', 'adapter-control.c', - include_directories : [spa_inc ], + include_directories : [configinc, spa_inc], + c_args : ['-D_GNU_SOURCE'], dependencies : [dl_lib, pthread_lib, mathlib], install : false)