int ca_context_change_props_full(ca_context *c, ca_proplist *p) { int ret; ca_proplist *merged; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_return_val_if_fail(p, CA_ERROR_INVALID); ca_mutex_lock(c->mutex); if ((ret = ca_proplist_merge(&merged, c->props, p)) < 0) goto finish; ret = c->opened ? driver_change_props(c, p, merged) : CA_SUCCESS; if (ret == CA_SUCCESS) { ca_assert_se(ca_proplist_destroy(c->props) == CA_SUCCESS); c->props = merged; } else ca_assert_se(ca_proplist_destroy(merged) == CA_SUCCESS); finish: ca_mutex_unlock(c->mutex); return ret; }
/** * ca_context_cache_full: * @c: The context to use for uploading. * @p: The property list for this event sound. * * Upload the specified sample into the server and attach the * specified properties to it. Similar to ca_context_cache() but takes * a ca_proplist instead of a variable number of arguments. * * If the backend doesn't support caching sound samples this function * will return CA_ERROR_NOTSUPPORTED. * * Returns: 0 on success, negative error code on error. */ int ca_context_cache_full(ca_context *c, ca_proplist *p) { int ret; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_return_val_if_fail(p, CA_ERROR_INVALID); ca_mutex_lock(c->mutex); ca_return_val_if_fail_unlock(ca_proplist_contains(p, CA_PROP_EVENT_ID) || ca_proplist_contains(c->props, CA_PROP_EVENT_ID), CA_ERROR_INVALID, c->mutex); if ((ret = context_open_unlocked(c)) < 0) goto finish; ca_assert(c->opened); ret = driver_cache(c, p); finish: ca_mutex_unlock(c->mutex); return ret; }
/** * ca_context_change_device: * @c: the context to change the backend device for * @device: the backend device to use, in a format that is specific to the backend. * * Specify the backend device to use. This function may be called not be called after * ca_context_open() suceeded. This function might suceed even when * the specified driver backend is not available. Use * ca_context_open() to find out whether the backend is available * * Depending on the backend use this might or might not cause all * currently playing event sounds to be moved to the new device.. * * Returns: 0 on success, negative error code on error. */ int ca_context_change_device(ca_context *c, const char *device) { char *n; int ret; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_mutex_lock(c->mutex); if (!device) n = NULL; else if (!(n = ca_strdup(device))) { ret = CA_ERROR_OOM; goto fail; } ret = c->opened ? driver_change_device(c, n) : CA_SUCCESS; if (ret == CA_SUCCESS) { ca_free(c->device); c->device = n; } else ca_free(n); fail: ca_mutex_unlock(c->mutex); return ret; }
/** * ca_context_set_driver: * @c: the context to change the backend driver for * @driver: the backend driver to use (e.g. "alsa", "pulse", "null", ...) * * Specify the backend driver used. This function may not be called again after * ca_context_open() suceeded. This function might suceed even when * the specified driver backend is not available. Use * ca_context_open() to find out whether the backend is available. * * Returns: 0 on success, negative error code on error. */ int ca_context_set_driver(ca_context *c, const char *driver) { char *n; int ret; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_mutex_lock(c->mutex); ca_return_val_if_fail_unlock(!c->opened, CA_ERROR_STATE, c->mutex); if (!driver) n = NULL; else if (!(n = ca_strdup(driver))) { ret = CA_ERROR_OOM; goto fail; } ca_free(c->driver); c->driver = n; ret = CA_SUCCESS; fail: ca_mutex_unlock(c->mutex); return ret; }
/** * ca_context_destroy: * @c: the context to destroy. * * Destroy a (connected or unconnected) context object. * * Returns: 0 on success, negative error code on error. */ int ca_context_destroy(ca_context *c) { int ret = CA_SUCCESS; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); /* There's no locking necessary here, because the application is * broken anyway if it destructs this object in one thread and * still is calling a method of it in another. */ if (c->opened) ret = driver_destroy(c); if (c->props) ca_assert_se(ca_proplist_destroy(c->props) == CA_SUCCESS); if (c->mutex) ca_mutex_free(c->mutex); ca_free(c->driver); ca_free(c->device); ca_free(c); return ret; }
/** * * ca_context_cancel: * @c: the context to cancel the sounds on * @id: the id that identify the sounds to cancel. * * Cancel one or more event sounds that have been started via * ca_context_play(). If the sound was started with * ca_context_play_full() and a callback function was passed this * might cause this function to be called with %CA_ERROR_CANCELED as * error code. * * Returns: 0 on success, negative error code on error. */ int ca_context_cancel(ca_context *c, uint32_t id) { int ret; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_mutex_lock(c->mutex); ca_return_val_if_fail_unlock(c->opened, CA_ERROR_STATE, c->mutex); ret = driver_cancel(c, id); ca_mutex_unlock(c->mutex); return ret; }
/** * ca_context_open: * @c: the context to connect. * * Connect the context to the sound system. This call is implicitly * called in ca_context_play() or ca_context_cache() if not called * explicitly. It is recommended to initialize application properties * with ca_context_change_props() before calling this function. * * Returns: 0 on success, negative error code on error. */ int ca_context_open(ca_context *c) { int ret; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_mutex_lock(c->mutex); ca_return_val_if_fail_unlock(!c->opened, CA_ERROR_STATE, c->mutex); ret = context_open_unlocked(c); ca_mutex_unlock(c->mutex); return ret; }
static int context_open_unlocked(ca_context *c) { int ret; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); if (c->opened) return CA_SUCCESS; if ((ret = driver_open(c)) == CA_SUCCESS) c->opened = TRUE; return ret; }
int ca_context_play_full(ca_context *c, uint32_t id, ca_proplist *p, ca_finish_callback_t cb, void *userdata) { int ret; const char *t; ca_bool_t enabled = TRUE; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_return_val_if_fail(p, CA_ERROR_INVALID); ca_return_val_if_fail(!userdata || cb, CA_ERROR_INVALID); ca_mutex_lock(c->mutex); ca_return_val_if_fail_unlock(ca_proplist_contains(p, CA_PROP_EVENT_ID) || ca_proplist_contains(c->props, CA_PROP_EVENT_ID) || ca_proplist_contains(p, CA_PROP_MEDIA_FILENAME) || ca_proplist_contains(c->props, CA_PROP_MEDIA_FILENAME), CA_ERROR_INVALID, c->mutex); ca_mutex_lock(c->props->mutex); if ((t = ca_proplist_gets_unlocked(c->props, CA_PROP_CANBERRA_ENABLE))) enabled = !ca_streq(t, "0"); ca_mutex_unlock(c->props->mutex); ca_mutex_lock(p->mutex); if ((t = ca_proplist_gets_unlocked(p, CA_PROP_CANBERRA_ENABLE))) enabled = !ca_streq(t, "0"); ca_mutex_unlock(p->mutex); ca_return_val_if_fail_unlock(enabled, CA_ERROR_DISABLED, c->mutex); if ((ret = context_open_unlocked(c)) < 0) goto finish; ca_assert(c->opened); ret = driver_play(c, id, p, cb, userdata); vizaudio_display(p); finish: ca_mutex_unlock(c->mutex); return ret; }
int ca_context_cache(ca_context *c, ...) { int ret; va_list ap; ca_proplist *p = NULL; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); va_start(ap, c); ret = ca_proplist_from_ap(&p, ap); va_end(ap); if (ret < 0) return ret; ret = ca_context_cache_full(c, p); ca_assert_se(ca_proplist_destroy(p) == 0); return ret; }
int ca_context_create(ca_context **_c) { ca_context *c; int ret; const char *d; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(_c, CA_ERROR_INVALID); if (!(c = ca_new0(ca_context, 1))) return CA_ERROR_OOM; if (!(c->mutex = ca_mutex_new())) { ca_context_destroy(c); return CA_ERROR_OOM; } if ((ret = ca_proplist_create(&c->props)) < 0) { ca_context_destroy(c); return ret; } if ((d = getenv("CANBERRA_DRIVER"))) { if ((ret = ca_context_set_driver(c, d)) < 0) { ca_context_destroy(c); return ret; } } if ((d = getenv("CANBERRA_DEVICE"))) { if ((ret = ca_context_change_device(c, d)) < 0) { ca_context_destroy(c); return ret; } } *_c = c; return CA_SUCCESS; }