Ejemplo n.º 1
0
/**
 * gsound_context_cachev:
 * @context: A #GSoundContext
 * @attrs: (element-type utf8 utf8): Hash table of attrerties
 * @error: Return location for error, or %NULL
 * 
 * Returns: %TRUE on success
 * 
 * Rename to: gsound_context_cache
 */
gboolean
gsound_context_cachev(GSoundContext *self,
                      GHashTable *attrs,
                      GError **error)
{
    ca_proplist *proplist;
    int res = ca_proplist_create(&proplist);
    if (!test_return (res, error))
        return FALSE;
    
    hash_table_to_prop_list (attrs, proplist);

    res = ca_context_cache_full(self->priv->ca, proplist);

    ca_proplist_destroy(proplist);

    return test_return(res, error);
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
static PyObject*
osk_audio_cache_sample(PyObject* self, PyObject* args)
{
    OskAudio* audio = (OskAudio*) self;
    ca_proplist* props;
    const char* event_id;
    int ret;

    if (!PyArg_ParseTuple(args, "s", &event_id))
        return NULL;

    ca_proplist_create(&props);
    ca_proplist_sets(props, CA_PROP_EVENT_ID, event_id);
    ret = ca_context_cache_full(audio->ca, props);
    ca_proplist_destroy(props);

    if (ret < 0)
    {
        PyErr_SetString(OSK_EXCEPTION, ca_strerror(ret));
        return NULL;
    }
    Py_RETURN_NONE;
}
Ejemplo n.º 4
0
/**
 * gsound_context_cache: (skip)
 * @context: A #GSoundContext
 * @error: Return location for error, or %NULL
 * @...: attributes
 * 
 * Returns: %TRUE on success, %FALSE otherwise
 */
gboolean
gsound_context_cache(GSoundContext *self,
                     GError **error,
                     ...)
{
    ca_proplist *pl;
    va_list args;
    int res;
    
    g_return_val_if_fail(GSOUND_IS_CONTEXT(self), FALSE);

    if ((res = ca_proplist_create(&pl)) != CA_SUCCESS)
        return test_return(res, error);

    va_start(args, error);
    var_args_to_prop_list (args, pl);
    va_end(args);

    res = ca_context_cache_full(self->priv->ca, pl);

    ca_proplist_destroy(pl);

    return test_return(res, error);
}
Ejemplo n.º 5
0
Archivo: plugin.c Proyecto: jusa/ngfd
static int
canberra_sink_play (NSinkInterface *iface, NRequest *request)
{
    CanberraData *data = (CanberraData*) n_request_get_data (request, CANBERRA_KEY);
    (void) iface;

    N_DEBUG (LOG_CAT "sink play");

    g_assert (data != NULL);

    if (!data->sound_enabled)
        goto complete;

    if (canberra_connect () == FALSE)
        return FALSE;

    static GHashTable *cached_samples = NULL;
    if (!cached_samples) {
        cached_samples = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
    }

    NProplist *props = props = (NProplist*) n_request_get_properties (request);
    ca_proplist *ca_props = 0;
    int error;
    ca_proplist_create (&ca_props);

    /* TODO: don't hardcode */
    ca_proplist_sets (ca_props, CA_PROP_CANBERRA_XDG_THEME_NAME, "jolla-ambient");
    ca_proplist_sets (ca_props, CA_PROP_EVENT_ID, data->filename);

    /* convert all properties within the request that begin with
       "sound.stream." prefix. */
    n_proplist_foreach (props, proplist_to_structure_cb, ca_props);

    if (g_hash_table_lookup_extended (cached_samples, data->filename, NULL, NULL) == FALSE) {
        N_DEBUG (LOG_CAT "caching sample %s", data->filename);
        error = ca_context_cache_full (c_context, ca_props);
        if (error) {
            N_WARNING (LOG_CAT "canberra couldn't cache sample %s", data->filename);
            return FALSE;
        }

        g_hash_table_add (cached_samples, strdup(data->filename));
    } else {
        N_DEBUG (LOG_CAT "sample %s is cached", data->filename);
    }

    error = ca_context_play_full (c_context, 0, ca_props, NULL, NULL);
    ca_proplist_destroy (ca_props);

    if (error) {
        N_WARNING (LOG_CAT "sink play had a warning: %s", ca_strerror (error));

        if (error == CA_ERROR_NOTAVAILABLE ||
                error == CA_ERROR_DISCONNECTED ||
                error == CA_ERROR_STATE ||
                error == CA_ERROR_DESTROYED) {
            ca_context_destroy (c_context);
            c_context = 0;
        }

        return FALSE;
    }

complete:
    /* We do not know how long our samples play, but let's guess we
     * are done in 200ms. */
    data->complete_cb_id = g_timeout_add (200, canberra_complete_cb, data);

    return TRUE;
}