Beispiel #1
0
Device_thread_state* new_Device_thread_state(
        uint32_t device_id, int32_t audio_buffer_size)
{
    rassert(audio_buffer_size >= 0);

    Device_thread_state* ts = memory_alloc_item(Device_thread_state);
    if (ts == NULL)
        return NULL;

    ts->device_id = device_id;
    ts->audio_buffer_size = audio_buffer_size;
    ts->node_state = DEVICE_NODE_STATE_NEW;
    ts->has_mixed_audio = false;
    ts->in_connected = NULL;

    for (Device_buffer_type buf_type = DEVICE_BUFFER_MIXED;
            buf_type < DEVICE_BUFFER_TYPES; ++buf_type)
    {
        for (Device_port_type port_type = DEVICE_PORT_TYPE_RECV;
                port_type < DEVICE_PORT_TYPES; ++port_type)
            ts->buffers[buf_type][port_type] = NULL;
    }

    ts->in_connected = new_Bit_array(KQT_DEVICE_PORTS_MAX);
    if (ts->in_connected == NULL)
    {
        del_Device_thread_state(ts);
        return NULL;
    }

    for (Device_buffer_type buf_type = DEVICE_BUFFER_MIXED;
            buf_type < DEVICE_BUFFER_TYPES; ++buf_type)
    {
        for (Device_port_type port_type = DEVICE_PORT_TYPE_RECV;
                port_type < DEVICE_PORT_TYPES; ++port_type)
        {
            ts->buffers[buf_type][port_type] =
                new_Etable(KQT_DEVICE_PORTS_MAX, (void (*)(void*))del_Work_buffer);
            if (ts->buffers[buf_type][port_type] == NULL)
            {
                del_Device_thread_state(ts);
                return NULL;
            }
        }
    }

    return ts;
}
Beispiel #2
0
static void del_Entry(Entry* entry)
{
    if (entry == NULL)
        return;

    del_Device_state(entry->state);
    for (int i = 0; i < KQT_THREADS_MAX; ++i)
        del_Device_thread_state(entry->thread_states[i]);

    memory_free(entry);

    return;
}
Beispiel #3
0
bool Device_states_set_thread_count(Device_states* states, int new_count)
{
    rassert(states != NULL);
    rassert(new_count >= 1);
    rassert(new_count <= KQT_THREADS_MAX);

    for (int ei = 0; ei < ENTRY_TABLE_SIZE; ++ei)
    {
        Entry* entry = states->entries[ei];
        while (entry != NULL)
        {
            rassert(entry->state != NULL);
            const Device* device = entry->state->device;
            const int32_t audio_buffer_size = entry->state->audio_buffer_size;

            // Create new thread states
            for (int ti = 0; ti < new_count; ++ti)
            {
                if (entry->thread_states[ti] == NULL)
                {
                    Device_thread_state* ts =
                        new_Device_thread_state(device, audio_buffer_size);
                    if (ts == NULL)
                        return false;

                    entry->thread_states[ti] = ts;
                }
            }

            // Remove excess thread states
            for (int ti = new_count; ti < KQT_THREADS_MAX; ++ti)
            {
                del_Device_thread_state(entry->thread_states[ti]);
                entry->thread_states[ti] = NULL;
            }

            entry = entry->next;
        }
    }

    states->thread_count = new_count;

    return true;
}