log: don't crash when failed to load

Improve docs for node
This commit is contained in:
Wim Taymans 2017-06-14 10:16:24 +02:00
parent 9257e3b8f3
commit b9c719ac7e
2 changed files with 28 additions and 29 deletions

View file

@ -52,25 +52,25 @@ struct spa_log *pw_spa_log_load(const char *lib,
map = support[index].data; map = support[index].data;
} }
if (map == NULL) { if (map == NULL) {
fprintf(stderr, "no type map"); fprintf(stderr, "no type map\n");
return NULL; return NULL;
} }
type_log = spa_type_map_get_id(map, SPA_TYPE__Log); type_log = spa_type_map_get_id(map, SPA_TYPE__Log);
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) { if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
fprintf(stderr, "can't load %s: %s", lib, dlerror()); fprintf(stderr, "can't load %s: %s\n", lib, dlerror());
return NULL; return NULL;
} }
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) { if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
fprintf(stderr, "can't find enum function"); fprintf(stderr, "can't find enum function\n");
goto no_symbol; goto no_symbol;
} }
for (index = 0;; index++) { for (index = 0;; index++) {
if ((res = enum_func(&factory, index)) < 0) { if ((res = enum_func(&factory, index)) < 0) {
if (res != SPA_RESULT_ENUM_END) if (res != SPA_RESULT_ENUM_END)
fprintf(stderr, "can't enumerate factories: %d", res); fprintf(stderr, "can't enumerate factories: %d\n", res);
goto enum_failed; goto enum_failed;
} }
if (strcmp(factory->name, factory_name) == 0) if (strcmp(factory->name, factory_name) == 0)
@ -80,11 +80,11 @@ struct spa_log *pw_spa_log_load(const char *lib,
handle = calloc(1, factory->size); handle = calloc(1, factory->size);
if ((res = spa_handle_factory_init(factory, if ((res = spa_handle_factory_init(factory,
handle, NULL, support, n_support)) < 0) { handle, NULL, support, n_support)) < 0) {
fprintf(stderr, "can't make factory instance: %d", res); fprintf(stderr, "can't make factory instance: %d\n", res);
goto init_failed; goto init_failed;
} }
if ((res = spa_handle_get_interface(handle, type_log, &iface)) < 0) { if ((res = spa_handle_get_interface(handle, type_log, &iface)) < 0) {
fprintf(stderr, "can't get log interface %d", res); fprintf(stderr, "can't get log interface %d\n", res);
goto interface_failed; goto interface_failed;
} }
return iface; return iface;
@ -111,7 +111,8 @@ struct spa_log *pw_log_get(struct spa_support *support,
"logger", "logger",
support, support,
n_support); n_support);
global_log->level = pw_log_level; if (global_log)
global_log->level = pw_log_level;
} }
return global_log; return global_log;
} }

View file

@ -38,25 +38,22 @@ struct spa_node;
#include <spa/buffer.h> #include <spa/buffer.h>
#include <spa/format.h> #include <spa/format.h>
/** A range */
struct spa_range { struct spa_range {
uint64_t offset; uint64_t offset; /**< offset in range */
uint32_t min_size; uint32_t min_size; /**< minimum size of data */
uint32_t max_size; uint32_t max_size; /**< maximum size of data */
}; };
/** /** Port IO area
* struct spa_port_io:
* @status: the status
* @buffer_id: a buffer id
* @range: requested range
* *
* IO information for a port on a node. This is allocated * IO information for a port on a node. This is allocated
* by the host and configured on all ports for which IO is requested. * by the host and configured on all ports for which IO is requested.
*/ */
struct spa_port_io { struct spa_port_io {
uint32_t status; uint32_t status; /**< the status code */
uint32_t buffer_id; uint32_t buffer_id; /**< a buffer id */
struct spa_range range; struct spa_range range; /**< the requested range */
}; };
#define SPA_PORT_IO_INIT (struct spa_port_io) { SPA_RESULT_NEED_BUFFER, SPA_ID_INVALID, } #define SPA_PORT_IO_INIT (struct spa_port_io) { SPA_RESULT_NEED_BUFFER, SPA_ID_INVALID, }
@ -67,17 +64,18 @@ struct spa_port_io {
* @rate: rate of sequence number increment per second of media data * @rate: rate of sequence number increment per second of media data
*/ */
struct spa_port_info { struct spa_port_info {
#define SPA_PORT_INFO_FLAG_REMOVABLE (1<<0) /* port can be removed */ #define SPA_PORT_INFO_FLAG_REMOVABLE (1<<0) /**< port can be removed */
#define SPA_PORT_INFO_FLAG_OPTIONAL (1<<1) /* processing on port is optional */ #define SPA_PORT_INFO_FLAG_OPTIONAL (1<<1) /**< processing on port is optional */
#define SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS (1<<2) /* the port can allocate buffer data */ #define SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS (1<<2) /**< the port can allocate buffer data */
#define SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS (1<<3) /* the port can use a provided buffer */ #define SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS (1<<3) /**< the port can use a provided buffer */
#define SPA_PORT_INFO_FLAG_IN_PLACE (1<<4) /* the port can process data in-place and will need #define SPA_PORT_INFO_FLAG_IN_PLACE (1<<4) /**< the port can process data in-place and will need
* a writable input buffer */ * a writable input buffer */
#define SPA_PORT_INFO_FLAG_NO_REF (1<<5) /* the port does not keep a ref on the buffer */ #define SPA_PORT_INFO_FLAG_NO_REF (1<<5) /**< the port does not keep a ref on the buffer */
#define SPA_PORT_INFO_FLAG_LIVE (1<<6) /* output buffers from this port are timestamped against #define SPA_PORT_INFO_FLAG_LIVE (1<<6) /**< output buffers from this port are timestamped against
* a live clock. */ * a live clock. */
uint32_t flags; uint32_t flags; /**< port flags */
uint32_t rate; uint32_t rate; /**< rate of sequence numbers on port */
const struct spa_dict *props; /**< extra port properties */
}; };