/** * 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; }
int ca_sound_file_open(ca_sound_file **_f, const char *fn) { FILE *file; ca_sound_file *f; int ret; ca_return_val_if_fail(_f, CA_ERROR_INVALID); ca_return_val_if_fail(fn, CA_ERROR_INVALID); if (!(f = ca_new0(ca_sound_file, 1))) return CA_ERROR_OOM; if (!(f->filename = ca_strdup(fn))) { ret = CA_ERROR_OOM; goto fail; } if (!(file = fopen(fn, "r"))) { ret = errno == ENOENT ? CA_ERROR_NOTFOUND : CA_ERROR_SYSTEM; goto fail; } if ((ret = ca_wav_open(&f->wav, file)) == CA_SUCCESS) { f->nchannels = ca_wav_get_nchannels(f->wav); f->rate = ca_wav_get_rate(f->wav); f->type = ca_wav_get_sample_type(f->wav); *_f = f; return CA_SUCCESS; } if (ret == CA_ERROR_CORRUPT) { if (fseek(file, 0, SEEK_SET) < 0) { ret = CA_ERROR_SYSTEM; goto fail; } if ((ret = ca_vorbis_open(&f->vorbis, file)) == CA_SUCCESS) { f->nchannels = ca_vorbis_get_nchannels(f->vorbis); f->rate = ca_vorbis_get_rate(f->vorbis); f->type = CA_SAMPLE_S16NE; *_f = f; return CA_SUCCESS; } } fail: ca_free(f->filename); ca_free(f); return ret; }