Exemple #1
0
/* decoder_init
 *
 * Initialize a pipeline to handle decoding.
 * If multiple disjoint threads want to handle decoding
 * of separate audio files, then this must be called on
 * each of them.
 *
 * handle	out	decoder handle to be used with each
 * 			transaction with the decoder.
 *
 * Return: 0 on success, negative error code on failure.
 */
int decoder_init(decoder_handle *_handle)
{
	struct decoder_handle_struct *handle;

	*_handle = NULL;
	handle = (struct decoder_handle_struct *)
	    		malloc(sizeof(struct decoder_handle_struct));
	if(!handle)
	      goto handle_malloc_failed;
	handle->queue = (q_type *)malloc(sizeof(q_type));
	if(!handle->queue)
	      goto queue_malloc_failed;

	if(q_init(handle->queue))
	      goto queue_init_failed;
	handle->active = 1;
	SIGNAL_INIT(&handle->start_signal);
	SIGNAL_INIT(&handle->finished_signal);

	if(pthread_create(&handle->thread, 0, decoder_thread, handle))
	      goto thread_creation_failed;

	*_handle = handle;
	return 0;
thread_creation_failed:
	SIGNAL_DEINIT(&handle->start_signal);
	SIGNAL_DEINIT(&handle->finished_signal);
queue_init_failed:
	free(handle->queue);
queue_malloc_failed:
	free(handle);
handle_malloc_failed:
	return -1;
}
int ratchet_chain_key_create(ratchet_chain_key **chain_key, hkdf_context *kdf, const uint8_t *key, size_t key_len, uint32_t index, signal_context *global_context)
{
    ratchet_chain_key *result = 0;

    if(!kdf || !key) {
        return SG_ERR_INVAL;
    }

    result = malloc(sizeof(ratchet_chain_key));
    if(!result) {
        return SG_ERR_NOMEM;
    }

    SIGNAL_INIT(result, ratchet_chain_key_destroy);
    result->global_context = global_context;
    result->kdf = kdf;

    result->key = malloc(key_len);
    if(!result->key) {
        free(result);
        return SG_ERR_NOMEM;
    }
    memcpy(result->key, key, key_len);
    result->key_len = key_len;

    result->index = index;
    SIGNAL_REF(result->kdf);
    *chain_key = result;

    return 0;
}
Exemple #3
0
/**
 * PropertiesChangedSignal() synthetizes and sends the
 * org.freedesktop.DBus.Properties.PropertiesChanged signal
 */
static DBusHandlerResult
PropertiesChangedSignal( intf_thread_t    *p_intf,
                         vlc_dictionary_t *p_changed_properties )
{
    DBusConnection  *p_conn = p_intf->p_sys->p_conn;
    DBusMessageIter changed_properties, invalidated_properties;
    const char *psz_interface_name = DBUS_MPRIS_PLAYER_INTERFACE;
    char **ppsz_properties = NULL;

    SIGNAL_INIT( DBUS_INTERFACE_PROPERTIES,
                 DBUS_MPRIS_OBJECT_PATH,
                 "PropertiesChanged" );

    OUT_ARGUMENTS;
    ADD_STRING( &psz_interface_name );

    if( !dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "{sv}",
                                           &changed_properties ) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    ppsz_properties = vlc_dictionary_all_keys( p_changed_properties );

    if( unlikely(!ppsz_properties) )
    {
        dbus_message_iter_abandon_container( &args, &changed_properties );
        return DBUS_HANDLER_RESULT_NEED_MEMORY;
    }

    for( int i = 0; ppsz_properties[i]; i++ )
    {
        PROPERTY_MAPPING_BEGIN
        PROPERTY_ENTRY( Metadata,       "a{sv}" )
        PROPERTY_ENTRY( PlaybackStatus, "s"     )
        PROPERTY_ENTRY( LoopStatus,     "s"     )
        PROPERTY_ENTRY( Rate,           "d"     )
        PROPERTY_ENTRY( Shuffle,        "b"     )
        PROPERTY_ENTRY( Volume,         "d"     )
        PROPERTY_ENTRY( CanSeek,        "b"     )
        PROPERTY_ENTRY( CanPlay,        "b"     )
        PROPERTY_ENTRY( CanPause,       "b"     )
        PROPERTY_MAPPING_END

        free( ppsz_properties[i] );
    }

    free( ppsz_properties );

    if( !dbus_message_iter_close_container( &args, &changed_properties ) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    if( !dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "s",
                                           &invalidated_properties ) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    if( !dbus_message_iter_close_container( &args, &invalidated_properties ) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    SIGNAL_SEND;
}
Exemple #4
0
/**
 * PropertiesChangedSignal: synthetizes and sends the
 * org.freedesktop.DBus.Properties.PropertiesChanged signal
 */
static DBusHandlerResult
PropertiesChangedSignal( intf_thread_t    *p_intf,
                         vlc_dictionary_t *p_changed_properties )
{
    DBusConnection  *p_conn = p_intf->p_sys->p_conn;
    DBusMessageIter changed_properties, invalidated_properties;
    const char *psz_interface_name = DBUS_MPRIS_TRACKLIST_INTERFACE;
    char **ppsz_properties = NULL;
    int i_properties = 0;

    SIGNAL_INIT( DBUS_INTERFACE_PROPERTIES,
                 DBUS_MPRIS_OBJECT_PATH,
                 "PropertiesChanged" );

    OUT_ARGUMENTS;
    ADD_STRING( &psz_interface_name );

    if( unlikely(!dbus_message_iter_open_container( &args,
                                                    DBUS_TYPE_ARRAY, "{sv}",
                                                    &changed_properties )) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    if( unlikely(!dbus_message_iter_close_container( &args,
                                                     &changed_properties )) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    if( unlikely(!dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "s",
                                                    &invalidated_properties )) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    i_properties    = vlc_dictionary_keys_count( p_changed_properties );
    ppsz_properties = vlc_dictionary_all_keys( p_changed_properties );

    if( unlikely(!ppsz_properties) )
    {
        dbus_message_iter_abandon_container( &args, &invalidated_properties );
        return DBUS_HANDLER_RESULT_NEED_MEMORY;
    }

    for( int i = 0; i < i_properties; i++ )
    {
        if( !strcmp( ppsz_properties[i], "Tracks" ) )
            dbus_message_iter_append_basic( &invalidated_properties,
                                            DBUS_TYPE_STRING,
                                            &ppsz_properties[i] );

        free( ppsz_properties[i] );
    }

    free( ppsz_properties );

    if( unlikely(!dbus_message_iter_close_container( &args,
                    &invalidated_properties )) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    SIGNAL_SEND;
}
Exemple #5
0
static DBusHandlerResult
PropertiesChangedSignal( intf_thread_t    *p_intf,
                         vlc_dictionary_t *p_changed_properties )
{
    DBusConnection  *p_conn = p_intf->p_sys->p_conn;
    DBusMessageIter changed_properties, invalidated_properties, entry, variant;
    const char *psz_interface_name = DBUS_MPRIS_ROOT_INTERFACE;
    char **ppsz_properties = NULL;
    int i_properties = 0;

    SIGNAL_INIT( DBUS_INTERFACE_PROPERTIES,
                 DBUS_MPRIS_OBJECT_PATH,
                 "PropertiesChanged" );

    OUT_ARGUMENTS;
    ADD_STRING( &psz_interface_name );
    dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "{sv}",
                                      &changed_properties );

    i_properties = vlc_dictionary_keys_count( p_changed_properties );
    ppsz_properties = vlc_dictionary_all_keys( p_changed_properties );

    for( int i = 0; i < i_properties; i++ )
    {
        dbus_message_iter_open_container( &changed_properties,
                                          DBUS_TYPE_DICT_ENTRY, NULL,
                                          &entry );

        dbus_message_iter_append_basic( &entry, DBUS_TYPE_STRING,
                                        &ppsz_properties[i] );

        if( !strcmp( ppsz_properties[i], "Fullscreen" ) )
        {
            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "b",
                                              &variant );
            MarshalFullscreen( p_intf, &variant );
            dbus_message_iter_close_container( &entry, &variant );
        }

        dbus_message_iter_close_container( &changed_properties, &entry );
        free( ppsz_properties[i] );
    }

    dbus_message_iter_close_container( &args, &changed_properties );

    dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "s",
                                      &invalidated_properties );

    dbus_message_iter_close_container( &args, &invalidated_properties );
    free( ppsz_properties );

    SIGNAL_SEND;
}
int scannable_fingerprint_create(scannable_fingerprint **scannable,
        uint32_t version,
        const char *local_stable_identifier, ec_public_key *local_identity_key,
        const char *remote_stable_identifier, ec_public_key *remote_identity_key)
{
    int result = 0;
    scannable_fingerprint *result_scannable = 0;

    if(!local_stable_identifier || !local_identity_key ||
            !remote_stable_identifier || !remote_identity_key) {
        return SG_ERR_INVAL;
    }

    result_scannable = malloc(sizeof(scannable_fingerprint));
    if(!result_scannable) {
        return SG_ERR_NOMEM;
    }

    memset(result_scannable, 0, sizeof(scannable_fingerprint));
    SIGNAL_INIT(result_scannable, scannable_fingerprint_destroy);

    result_scannable->version = version;

    result_scannable->local_stable_identifier = strdup(local_stable_identifier);
    if(!result_scannable->local_stable_identifier) {
        result = SG_ERR_NOMEM;
        goto complete;
    }

    result_scannable->local_identity_key = local_identity_key;
    SIGNAL_REF(local_identity_key);

    result_scannable->remote_stable_identifier = strdup(remote_stable_identifier);
    if(!result_scannable->remote_stable_identifier) {
        result = SG_ERR_NOMEM;
        goto complete;
    }

    result_scannable->remote_identity_key = remote_identity_key;
    SIGNAL_REF(remote_identity_key);

complete:
    if(result < 0) {
        SIGNAL_UNREF(result_scannable);
    }
    else {
        *scannable = result_scannable;
    }

    return result;
}
int bob_signal_protocol_parameters_create(
        bob_signal_protocol_parameters **parameters,
        ratchet_identity_key_pair *our_identity_key,
        ec_key_pair *our_signed_pre_key,
        ec_key_pair *our_one_time_pre_key,
        ec_key_pair *our_ratchet_key,
        ec_public_key *their_identity_key,
        ec_public_key *their_base_key)
{
    bob_signal_protocol_parameters *result = 0;

    /* Only "our_one_time_pre_key" is allowed to be null */
    if(!our_identity_key || !our_signed_pre_key || !our_ratchet_key
            || !their_identity_key || !their_base_key) {
        return SG_ERR_INVAL;
    }

    result = malloc(sizeof(bob_signal_protocol_parameters));
    if(!result) {
        return SG_ERR_NOMEM;
    }

    memset(result, 0, sizeof(bob_signal_protocol_parameters));

    SIGNAL_INIT(result, bob_signal_protocol_parameters_destroy);
    SIGNAL_REF(our_identity_key);
    SIGNAL_REF(our_signed_pre_key);
    SIGNAL_REF(our_ratchet_key);
    SIGNAL_REF(their_identity_key);
    SIGNAL_REF(their_base_key);
    result->our_identity_key = our_identity_key;
    result->our_signed_pre_key = our_signed_pre_key;
    result->our_ratchet_key = our_ratchet_key;
    result->their_identity_key = their_identity_key;
    result->their_base_key = their_base_key;

    if(our_one_time_pre_key) {
        SIGNAL_REF(our_one_time_pre_key);
        result->our_one_time_pre_key = our_one_time_pre_key;
    }

    *parameters = result;
    return 0;
}
int device_consistency_message_create(device_consistency_message **message)
{
    int result = 0;
    device_consistency_message *result_message = 0;

    result_message = malloc(sizeof(device_consistency_message));
    if(!result_message) {
        result = SG_ERR_NOMEM;
        goto complete;
    }
    memset(result_message, 0, sizeof(device_consistency_message));
    SIGNAL_INIT(result_message, device_consistency_message_destroy);

complete:
    if(result >= 0) {
        *message = result_message;
    }
    return result;
}
int ratchet_identity_key_pair_create(
        ratchet_identity_key_pair **key_pair,
        ec_public_key *public_key,
        ec_private_key *private_key)
{
    ratchet_identity_key_pair *result = malloc(sizeof(ratchet_identity_key_pair));
    if(!result) {
        return SG_ERR_NOMEM;
    }

    SIGNAL_INIT(result, ratchet_identity_key_pair_destroy);
    SIGNAL_REF(public_key);
    SIGNAL_REF(private_key);
    result->public_key = public_key;
    result->private_key = private_key;

    *key_pair = result;

    return 0;
}
Exemple #10
0
/**
 * PropertiesChangedSignal() synthetizes and sends the
 * org.freedesktop.DBus.Properties.PropertiesChanged signal
 */
static DBusHandlerResult
PropertiesChangedSignal( intf_thread_t    *p_intf,
                         vlc_dictionary_t *p_changed_properties )
{
    DBusConnection  *p_conn = p_intf->p_sys->p_conn;
    DBusMessageIter changed_properties, invalidated_properties;
    const char *psz_interface_name = DBUS_MPRIS_ROOT_INTERFACE;

    SIGNAL_INIT( DBUS_INTERFACE_PROPERTIES,
                 DBUS_MPRIS_OBJECT_PATH,
                 "PropertiesChanged" );

    OUT_ARGUMENTS;
    ADD_STRING( &psz_interface_name );

    if( !dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "{sv}",
                                           &changed_properties ) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    if( vlc_dictionary_has_key( p_changed_properties, "Fullscreen" ) )
    {
        if( AddProperty( p_intf, &changed_properties, "Fullscreen", "b",
                     MarshalFullscreen ) != VLC_SUCCESS )
        {
            dbus_message_iter_abandon_container( &args, &changed_properties );
            return DBUS_HANDLER_RESULT_NEED_MEMORY;
        }
    }

    if( !dbus_message_iter_close_container( &args, &changed_properties ) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    if( !dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "s",
                                           &invalidated_properties ) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    if( !dbus_message_iter_close_container( &args, &invalidated_properties ) )
        return DBUS_HANDLER_RESULT_NEED_MEMORY;

    SIGNAL_SEND;
}
int symmetric_signal_protocol_parameters_create(
        symmetric_signal_protocol_parameters **parameters,
        ratchet_identity_key_pair *our_identity_key,
        ec_key_pair *our_base_key,
        ec_key_pair *our_ratchet_key,
        ec_public_key *their_base_key,
        ec_public_key *their_ratchet_key,
        ec_public_key *their_identity_key)
{
    symmetric_signal_protocol_parameters *result = 0;
    
    if(!our_identity_key || !our_base_key || !our_ratchet_key
            || !their_base_key || !their_ratchet_key || !their_identity_key) {
        return SG_ERR_INVAL;
    }

    result = malloc(sizeof(symmetric_signal_protocol_parameters));
    if(!result) {
        return SG_ERR_NOMEM;
    }

    memset(result, 0, sizeof(symmetric_signal_protocol_parameters));

    SIGNAL_INIT(result, symmetric_signal_protocol_parameters_destroy);
    SIGNAL_REF(our_identity_key);
    SIGNAL_REF(our_base_key);
    SIGNAL_REF(our_ratchet_key);
    SIGNAL_REF(their_base_key);
    SIGNAL_REF(their_ratchet_key);
    SIGNAL_REF(their_identity_key);
    result->our_identity_key = our_identity_key;
    result->our_base_key = our_base_key;
    result->our_ratchet_key = our_ratchet_key;
    result->their_base_key = their_base_key;
    result->their_ratchet_key = their_ratchet_key;
    result->their_identity_key = their_identity_key;

    *parameters = result;
    return 0;
}
int fingerprint_create(fingerprint **fingerprint_val, displayable_fingerprint *displayable, scannable_fingerprint *scannable)
{
    fingerprint *result = malloc(sizeof(fingerprint));
    if(!result) {
        return SG_ERR_NOMEM;
    }

    memset(result, 0, sizeof(fingerprint));
    SIGNAL_INIT(result, fingerprint_destroy);
    if(displayable) {
        result->displayable = displayable;
        SIGNAL_REF(displayable);
    }
    if(scannable) {
        result->scannable = scannable;
        SIGNAL_REF(scannable);
    }

    *fingerprint_val = result;

    return 0;
}
int device_consistency_signature_create(device_consistency_signature **signature,
        const uint8_t *signature_data, size_t signature_len,
        const uint8_t *vrf_output_data, size_t vrf_output_len)
{
    int result = 0;
    device_consistency_signature *result_signature = 0;

    result_signature = malloc(sizeof(device_consistency_signature));
    if(!result_signature) {
        result = SG_ERR_NOMEM;
        goto complete;
    }
    memset(result_signature, 0, sizeof(device_consistency_signature));
    SIGNAL_INIT(result_signature, device_consistency_signature_destroy);

    result_signature->signature = signal_buffer_create(signature_data, signature_len);
    if(!result_signature->signature) {
        result = SG_ERR_NOMEM;
        goto complete;
    }

    result_signature->vrf_output = signal_buffer_create(vrf_output_data, vrf_output_len);
    if(!result_signature->vrf_output) {
        result = SG_ERR_NOMEM;
        goto complete;
    }

complete:
    if(result >= 0) {
        *signature = result_signature;
    }
    else {
        SIGNAL_UNREF(result_signature);
    }
    return result;
}
Exemple #14
0
static succeed_type flash_init(FLASH_PRIVATE_HANDLE *phandle)
{
	SIGNAL_STRUCT_T signal;
	if ( NULL == phandle )
	{
		SYS_ERROR("in flash_init phandle is NULL.\r\n");
		return succeed_type_failed;
	}

	phandle->gbshm_handle = GBSHM_INIT();
	if (NULL == phandle->gbshm_handle)
	{
		SYS_ERROR("GBSHM_INIT failed.\r\n");
		return succeed_type_failed;
	}

	if (UNIX_CREATE(UNIXFILE_SOCKET_FLASH, &(phandle->unix_fd), 0) == succeed_type_failed)
	{
		SYS_ERROR("UNIX_CREATE %s failed.\r\n", UNIXFILE_SOCKET_FLASH);
		return succeed_type_failed;
	}

	flash_poll_init(phandle);
	//以下添加各自的处理
	//对操作互斥量的初始化
	pthread_mutex_init(&phandle->mutex,NULL);
	//将para的最大偏移记录,方便信息的读取
	phandle->savesize = PARA_CMD_SYSTEM_END_PARAM_OFFSET;

	memset(&signal, 0x00, sizeof(signal));
	signal.signo[0] = SIGINT;
	signal.sig_phandle[0] = sig_handle_proc;
	SIGNAL_INIT(&signal, 1);

	return succeed_type_succeed;
}
Exemple #15
0
/**
 * PropertiesChangedSignal() synthetizes and sends the
 * org.freedesktop.DBus.Properties.PropertiesChanged signal
 */
static DBusHandlerResult
PropertiesChangedSignal( intf_thread_t    *p_intf,
                         vlc_dictionary_t *p_changed_properties )
{
    DBusConnection  *p_conn = p_intf->p_sys->p_conn;
    DBusMessageIter changed_properties, invalidated_properties, entry, variant;
    const char *psz_interface_name = DBUS_MPRIS_PLAYER_INTERFACE;
    char **ppsz_properties = NULL;
    int i_properties = 0;

    SIGNAL_INIT( DBUS_INTERFACE_PROPERTIES,
                 DBUS_MPRIS_OBJECT_PATH,
                 "PropertiesChanged" );

    OUT_ARGUMENTS;
    ADD_STRING( &psz_interface_name );
    dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "{sv}",
                                      &changed_properties );

    i_properties = vlc_dictionary_keys_count( p_changed_properties );
    ppsz_properties = vlc_dictionary_all_keys( p_changed_properties );

    for( int i = 0; i < i_properties; i++ )
    {
        dbus_message_iter_open_container( &changed_properties,
                                          DBUS_TYPE_DICT_ENTRY, NULL,
                                          &entry );

        dbus_message_iter_append_basic( &entry, DBUS_TYPE_STRING,
                                        &ppsz_properties[i] );

        if( !strcmp( ppsz_properties[i], "Metadata" ) )
        {
            input_thread_t *p_input;
            p_input = playlist_CurrentInput( p_intf->p_sys->p_playlist );

            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "a{sv}",
                                              &variant );

            if( p_input )
            {
                input_item_t *p_item = input_GetItem( p_input );
                GetInputMeta( p_item, &variant );
                vlc_object_release( p_input );
            }

            dbus_message_iter_close_container( &entry, &variant );
        }
        else if( !strcmp( ppsz_properties[i], "PlaybackStatus" ) )
        {
            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "s",
                                              &variant );
            MarshalPlaybackStatus( p_intf, &variant );
            dbus_message_iter_close_container( &entry, &variant );
        }
        else if( !strcmp( ppsz_properties[i], "LoopStatus" ) )
        {
            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "s",
                                              &variant );
            MarshalLoopStatus( p_intf, &variant );
            dbus_message_iter_close_container( &entry, &variant );
        }
        else if( !strcmp( ppsz_properties[i], "Rate" ) )
        {
            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "d",
                                              &variant );
            MarshalRate( p_intf, &variant );
            dbus_message_iter_close_container( &entry, &variant );
        }
        else if( !strcmp( ppsz_properties[i], "Shuffle" ) )
        {
            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "b",
                                              &variant );
            MarshalShuffle( p_intf, &variant );
            dbus_message_iter_close_container( &entry, &variant );
        }
        else if( !strcmp( ppsz_properties[i], "Volume" ) )
        {
            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "d",
                                              &variant );
            MarshalVolume( p_intf, &variant );
            dbus_message_iter_close_container( &entry, &variant );
        }
        else if( !strcmp( ppsz_properties[i], "CanSeek" ) )
        {
            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "b",
                                              &variant );
            MarshalCanSeek( p_intf, &variant );
            dbus_message_iter_close_container( &entry, &variant );
        }
        else if( !strcmp( ppsz_properties[i], "CanPlay" ) )
        {
            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "b",
                                              &variant );
            MarshalCanPlay( p_intf, &variant );
            dbus_message_iter_close_container( &entry, &variant );
        }
        else if( !strcmp( ppsz_properties[i], "CanPause" ) )
        {
            dbus_message_iter_open_container( &entry,
                                              DBUS_TYPE_VARIANT, "b",
                                              &variant );
            MarshalCanPause( p_intf, &variant );
            dbus_message_iter_close_container( &entry, &variant );
        }
        dbus_message_iter_close_container( &changed_properties, &entry );
        free( ppsz_properties[i] );
    }

    dbus_message_iter_close_container( &args, &changed_properties );
    dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "s",
                                      &invalidated_properties );
    dbus_message_iter_close_container( &args, &invalidated_properties );
    free( ppsz_properties );

    SIGNAL_SEND;
}
Exemple #16
0
static inline spectgen_session_t *spectgen_session_create(unsigned int window_size,
							 scale_t scale,
							 spect_method_t method,
							 unsigned int nbands)
{
	spectgen_session_t *session;
	int i;
	unsigned int num_bands = nbands;

	if(method == CEPSTOGRAM)
		num_bands = (nbands - 1) * 2;

	if(num_bands > (1 + (window_size / 2)))
	      return NULL;

	session = (spectgen_session_t *)malloc(sizeof(spectgen_session_t));
	if(!session)
	      return NULL;

	session->window_size = window_size;
	session->numfreqs = (window_size / 2) + 1;
	session->nbands = nbands;
	session->scale = scale;
	session->method = method;

	session->window = (float *)malloc(sizeof(float) * window_size);
	if(!session->window)
	      goto window_creation_failed;
	for(i = 0; i < window_size; i++) {
		session->window[i] = 0.5 * (1 - cos(2 * M_PI * (float)i / (float)(window_size - 1)));
	}


	session->scale_table = generate_scale_table(num_bands, scale);
	if(!session->scale_table)
	      goto scale_generation_failed;

	session->norm_table = generate_scale_norm_table(session->scale_table, num_bands);
	if(!session->norm_table)
	      goto norm_generation_failed;

	session->fft_in_pre = (float *)fftwf_malloc(sizeof(float) * window_size);
	if(!session->fft_in_pre)
	      goto fft_in_pre_failed;

	session->fft_out_pre = (fftwf_complex *)
	    fftwf_malloc(sizeof(fftwf_complex) * session->numfreqs);
	if(!session->fft_out_pre)
	      goto fft_out_pre_failed;

	/* Even though we are thread safe, the planner is not. so 
	 * serialize the calls to fftwf plan create */
	pthread_mutex_lock(&planner_lock);
	session->plan_pre  = fftwf_plan_dft_r2c_1d(window_size, session->fft_in_pre,
				session->fft_out_pre, FFTW_MEASURE | FFTW_DESTROY_INPUT);
	pthread_mutex_unlock(&planner_lock);
	if(!session->plan_pre)
	      goto plan_pre_creation_failed;

	session->fft_in_post = NULL;
	session->fft_out_post = NULL;
	session->plan_post = 0;

	if(method == CEPSTOGRAM) {
		unsigned int len_out_post = nbands;
		unsigned int len_in_post = num_bands;
		session->fft_in_post = (float *)fftwf_malloc(sizeof(float) * len_in_post);
		if(!session->fft_in_post)
			goto fft_in_post_failed;

		session->fft_out_post = (fftwf_complex *)
		    fftwf_malloc(sizeof(fftwf_complex) * len_out_post);
		if(!session->fft_out_post)
			goto fft_out_post_failed;

		pthread_mutex_lock(&planner_lock);
		session->plan_post = fftwf_plan_dft_r2c_1d(len_in_post, session->fft_in_post,
				session->fft_out_post, FFTW_MEASURE | FFTW_DESTROY_INPUT);
		pthread_mutex_unlock(&planner_lock);
		if(!session->plan_post)
			goto plan_post_creation_failed;
	}

	/* The reason we create is for it to be taken! */
	session->busy = 1;
	session->next = NULL;
	pthread_mutex_init(&session->lock, NULL);
	SIGNAL_INIT(&session->start_signal);
	SIGNAL_INIT(&session->finished_signal);
	session->active = 1;

	if(decoder_init(&session->d_handle))
	      goto decoder_init_failed;

	/* The thread will wait on the start signal */
	pthread_create(&session->thread, 0, spectgen_session_thread, session);
	if(!session->thread)
	      goto thread_creation_failed;

	return session;

thread_creation_failed:
	decoder_exit(session->d_handle);
decoder_init_failed:
	pthread_mutex_destroy(&session->lock);
	SIGNAL_DEINIT(&session->start_signal);
	SIGNAL_DEINIT(&session->finished_signal);
	if(session->plan_post)
		fftwf_destroy_plan(session->plan_post);
plan_post_creation_failed:
	if(session->fft_out_post)
	      fftwf_free(session->fft_out_post);
fft_out_post_failed:
	if(session->fft_in_post)
	      fftwf_free(session->fft_in_post);
fft_in_post_failed:
	fftwf_destroy_plan(session->plan_pre);
plan_pre_creation_failed:
	fftwf_free(session->fft_out_pre);
fft_out_pre_failed:
	fftwf_free(session->fft_in_pre);
fft_in_pre_failed:
	free(session->norm_table);
norm_generation_failed:
	free(session->scale_table);
scale_generation_failed:
	free(session->window);
window_creation_failed:
	free(session);
	return NULL;
}
int device_consistency_commitment_create(device_consistency_commitment **commitment,
        uint32_t generation, ec_public_key_list *identity_key_list,
        signal_context *global_context)
{
    static const char version[] = "DeviceConsistencyCommitment_V0";
    int result = 0;
    void *digest_context = 0;
    device_consistency_commitment *result_commitment = 0;
    ec_public_key_list *sorted_list = 0;
    uint8_t gen_data[4];
    unsigned int list_size;
    unsigned int i;

    result_commitment = malloc(sizeof(device_consistency_commitment));
    if(!result_commitment) {
        result = SG_ERR_NOMEM;
        goto complete;
    }
    memset(result_commitment, 0, sizeof(device_consistency_commitment));
    SIGNAL_INIT(result_commitment, device_consistency_commitment_destroy);

    sorted_list = ec_public_key_list_copy(identity_key_list);
    if(!sorted_list) {
        result = SG_ERR_NOMEM;
        goto complete;
    }

    ec_public_key_list_sort(sorted_list);

    result = signal_sha512_digest_init(global_context, &digest_context);
    if(result < 0) {
        goto complete;
    }

    result = signal_sha512_digest_update(global_context, digest_context,
            (uint8_t *)version, sizeof(version) - 1);
    if(result < 0) {
        goto complete;
    }

    gen_data[3] = (uint8_t)(generation);
    gen_data[2] = (uint8_t)(generation >> 8);
    gen_data[1] = (uint8_t)(generation >> 16);
    gen_data[0] = (uint8_t)(generation >> 24);

    result = signal_sha512_digest_update(global_context, digest_context,
            gen_data, sizeof(gen_data));
    if(result < 0) {
        goto complete;
    }

    list_size = ec_public_key_list_size(sorted_list);
    for(i = 0; i < list_size; i++) {
        signal_buffer *key_buffer = 0;
        ec_public_key *key = ec_public_key_list_at(sorted_list, i);

        result = ec_public_key_serialize(&key_buffer, key);
        if(result < 0) {
            goto complete;
        }

        result = signal_sha512_digest_update(global_context, digest_context,
                signal_buffer_data(key_buffer), signal_buffer_len(key_buffer));
        signal_buffer_free(key_buffer);
        if(result < 0) {
            goto complete;
        }
    }

    result_commitment->generation = generation;
    result = signal_sha512_digest_final(global_context, digest_context, &result_commitment->serialized);

complete:
    if(sorted_list) {
        ec_public_key_list_free(sorted_list);
    }
    if(digest_context) {
        signal_sha512_digest_cleanup(global_context, digest_context);
    }
    if(result >= 0) {
        *commitment = result_commitment;
    }
    else {
        SIGNAL_UNREF(result_commitment);
    }
    return result;
}
int displayable_fingerprint_create(displayable_fingerprint **displayable, const char *local_fingerprint, const char *remote_fingerprint)
{
    int result = 0;
    size_t local_len = 0;
    size_t remote_len = 0;
    displayable_fingerprint *result_displayable = 0;
    char *display_text = 0;

    if(!local_fingerprint || !remote_fingerprint) {
        return SG_ERR_INVAL;
    }

    result_displayable = malloc(sizeof(displayable_fingerprint));
    if(!result_displayable) {
        return SG_ERR_NOMEM;
    }

    memset(result_displayable, 0, sizeof(displayable_fingerprint));
    SIGNAL_INIT(result_displayable, displayable_fingerprint_destroy);

    result_displayable->local_fingerprint = strdup(local_fingerprint);
    if(!result_displayable->local_fingerprint) {
        result = SG_ERR_NOMEM;
        goto complete;
    }

    result_displayable->remote_fingerprint = strdup(remote_fingerprint);
    if(!result_displayable->remote_fingerprint) {
        result = SG_ERR_NOMEM;
        goto complete;
    }

    local_len = strlen(local_fingerprint);
    remote_len = strlen(remote_fingerprint);

    display_text = malloc(local_len + remote_len + 1);
    if(!display_text) {
        result = SG_ERR_NOMEM;
        goto complete;
    }

    if(strcmp(local_fingerprint, remote_fingerprint) <= 0) {
        memcpy(display_text, local_fingerprint, local_len);
        memcpy(display_text + local_len, remote_fingerprint, remote_len + 1);
    }
    else {
        memcpy(display_text, remote_fingerprint, remote_len);
        memcpy(display_text + remote_len, local_fingerprint, local_len + 1);
    }

    result_displayable->display_text = display_text;

complete:
    if(result < 0) {
        SIGNAL_UNREF(result_displayable);
    }
    else {
        *displayable = result_displayable;
    }

    return result;
}