Exemple #1
0
bool_t read_metadata(FLAC__StreamDecoder *decoder, callback_info *info)
{
    FLAC__StreamDecoderState ret;

    reset_info(info);

    /* Reset the decoder */
    if (FLAC__stream_decoder_reset(decoder) == false)
    {
        FLACNG_ERROR("Could not reset the decoder!\n");
        return FALSE;
    }

    /* Try to decode the metadata */
    if (FLAC__stream_decoder_process_until_end_of_metadata(decoder) == false)
    {
        ret = FLAC__stream_decoder_get_state(decoder);
        AUDDBG("Could not read the metadata: %s(%d)!\n",
            FLAC__StreamDecoderStateString[ret], ret);
        reset_info(info);
        return FALSE;
    }

    return TRUE;
}
Exemple #2
0
callback_info *init_callback_info(void)
{
    callback_info *info;

    if ((info = malloc (sizeof (callback_info))) == NULL)
    {
        FLACNG_ERROR("Could not allocate memory for callback structure!");
        return NULL;
    }

    memset (info, 0, sizeof (callback_info));

    if ((info->output_buffer = malloc (BUFFER_SIZE_BYTE)) == NULL)
    {
        FLACNG_ERROR("Could not allocate memory for output buffer!");
        free (info);
        return NULL;
    }

    reset_info(info);

    AUDDBG("Playback buffer allocated for %d samples, %d bytes\n", BUFFER_SIZE_SAMP, BUFFER_SIZE_BYTE);

    return info;
}
Exemple #3
0
static void
disconnect_hook(void *data)
{
    struct connection_info *info = data;

    reset_info(info);
}
Exemple #4
0
static void
connect_hook(DBusConnection *connection, void *data)
{
    DBusError error;
    DBusObjectPathVTable vtable = { .message_function = message_handler, };
    struct connection_info *info = data;

    info->connection = connection;

    dbus_error_init(&error);

    dbus_bus_request_name(info->connection, info->busname, 0, &error);
    if (dbus_error_is_set(&error)) {
        ErrorF("[config/dbus] couldn't take over org.x.config: %s (%s)\n",
               error.name, error.message);
        goto err_start;
    }

    /* blocks until we get a reply. */
    dbus_bus_add_match(info->connection, MATCH_RULE, &error);
    if (dbus_error_is_set(&error)) {
        ErrorF("[config/dbus] couldn't add match: %s (%s)\n", error.name,
               error.message);
        goto err_name;
    }

    if (!dbus_connection_register_object_path(info->connection,
                                              info->busobject, &vtable,
                                              info)) {
        ErrorF("[config/dbus] couldn't register object path\n");
        goto err_match;
    }

    DebugF("[dbus] registered %s, %s\n", info->busname, info->busobject);

    dbus_error_free(&error);

    return;

err_match:
    dbus_bus_remove_match(info->connection, MATCH_RULE, &error);
err_name:
    dbus_bus_release_name(info->connection, info->busname, &error);
err_start:
    dbus_error_free(&error);

    reset_info(info);
}
Exemple #5
0
void UpvalueMarker::reset_info(Proc *proc)
{
    assert(NULL != proc);

    proc->thisclass_uprefer_pos = -1;
    proc->this_uprefer_pos = -1;

    SymbolTable *st = proc->symbol_table;
    assert(NULL != st);
    st->reset_upvalue_infos();

    // 遍历
    for (size_t i = 0, szi = proc->blocks.size(); i < szi; ++i)
    {
        BasicBlock *block = proc->blocks.at(i);
        assert(NULL != block);

        for (size_t j = 0, szj = block->codes().size(); j < szj; ++j)
        {
            ICode *c = block->codes().at(j);
            assert(NULL != c);

            if (IC_MAKE_LAMBDA == c->op)
            {
                MakeLambdaICode *mlc = SILK_DYNAMIC_CAST<MakeLambdaICode*>(c);
                assert(NULL != mlc);
                reset_info(mlc->proc);
            }
            else if (IC_MAKE_CLASS == c->op)
            {
                MakeClassICode *mcc = SILK_DYNAMIC_CAST<MakeClassICode*>(c);
                assert(NULL != mcc);
                for (size_t i = 0, sz = mcc->static_methods.size(); i < sz; ++i)
                {
                    Proc *sub_proc = mcc->static_methods.at(i).proc;
                    assert(NULL != sub_proc);
                    reset_info(sub_proc);
                }
                reset_info(mcc->static_init_code.proc);
                for (size_t i = 0, sz = mcc->instance_methods.size(); i < sz; ++i)
                {
                    Proc *sub_proc = mcc->instance_methods.at(i).proc;
                    assert(NULL != sub_proc);
                    reset_info(sub_proc);
                }
                reset_info(mcc->instance_init_code.proc);
                reset_info(mcc->constructor.proc);
            }
        }
    }
}
Exemple #6
0
bool UpvalueMarker::run_on_module(ModuleICode *module)
{
    assert(NULL != module);

    // 重置信息
    reset_info(module->proc);

    // 处理模块导出符号
    for (size_t i = 0, sz = module->exports.size(); i < sz; ++i)
    {
        const ModuleICode::Export& ex = module->exports.at(i);
        module->proc->symbol_table->add_upvalue_refer(ex.name);
    }

    // 遍历代码
    run_on_proc(module->proc);

    return false; // 只收集信息,不改变代码
}
Exemple #7
0
static bool_t flac_play (const char * filename, VFSFile * file)
{
    if (!file)
        return FALSE;

    void * play_buffer = NULL;
    bool_t error = FALSE;

    info->fd = file;

    if (read_metadata(decoder, info) == FALSE)
    {
        FLACNG_ERROR("Could not prepare file for playing!\n");
        error = TRUE;
        goto ERR_NO_CLOSE;
    }

    play_buffer = g_malloc (BUFFER_SIZE_BYTE);

    if (! aud_input_open_audio (SAMPLE_FMT (info->bits_per_sample),
        info->sample_rate, info->channels))
    {
        error = TRUE;
        goto ERR_NO_CLOSE;
    }

    aud_input_set_bitrate(info->bitrate);

    while (FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_END_OF_STREAM)
    {
        if (aud_input_check_stop ())
            break;

        int seek_value = aud_input_check_seek ();
        if (seek_value >= 0)
            FLAC__stream_decoder_seek_absolute (decoder, (int64_t)
             seek_value * info->sample_rate / 1000);

        /* Try to decode a single frame of audio */
        if (FLAC__stream_decoder_process_single(decoder) == FALSE)
        {
            FLACNG_ERROR("Error while decoding!\n");
            error = TRUE;
            break;
        }

        squeeze_audio(info->output_buffer, play_buffer, info->buffer_used, info->bits_per_sample);
        aud_input_write_audio(play_buffer, info->buffer_used * SAMPLE_SIZE(info->bits_per_sample));

        reset_info(info);
    }

ERR_NO_CLOSE:
    g_free (play_buffer);
    reset_info(info);

    if (FLAC__stream_decoder_flush(decoder) == FALSE)
        FLACNG_ERROR("Could not flush decoder state!\n");

    return ! error;
}