⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 variables.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 3 页
字号:
            p_var->step = *p_val;            p_var->pf_dup( &p_var->step );            CheckValue( p_var, &p_var->val );            break;        case VLC_VAR_ADDCHOICE:            /* FIXME: the list is sorted, dude. Use something cleverer. */            for( i = p_var->choices.i_count ; i-- ; )            {                if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) < 0 )                {                    break;                }            }            /* The new place is i+1 */            i++;            if( p_var->i_default >= i )            {                p_var->i_default++;            }            INSERT_ELEM( p_var->choices.p_values, p_var->choices.i_count,                         i, *p_val );            INSERT_ELEM( p_var->choices_text.p_values,                         p_var->choices_text.i_count, i, *p_val );            p_var->pf_dup( &p_var->choices.p_values[i] );            p_var->choices_text.p_values[i].psz_string =                ( p_val2 && p_val2->psz_string ) ?                strdup( p_val2->psz_string ) : NULL;            CheckValue( p_var, &p_var->val );            break;        case VLC_VAR_DELCHOICE:            /* FIXME: the list is sorted, dude. Use something cleverer. */            for( i = 0 ; i < p_var->choices.i_count ; i++ )            {                if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) == 0 )                {                    break;                }            }            if( i == p_var->choices.i_count )            {                /* Not found */                vlc_mutex_unlock( &p_this->var_lock );                return VLC_EGENERIC;            }            if( p_var->i_default > i )            {                p_var->i_default--;            }            else if( p_var->i_default == i )            {                p_var->i_default = -1;            }            p_var->pf_free( &p_var->choices.p_values[i] );            if( p_var->choices_text.p_values[i].psz_string )                free( p_var->choices_text.p_values[i].psz_string );            REMOVE_ELEM( p_var->choices.p_values, p_var->choices.i_count, i );            REMOVE_ELEM( p_var->choices_text.p_values,                         p_var->choices_text.i_count, i );            CheckValue( p_var, &p_var->val );            break;        case VLC_VAR_CHOICESCOUNT:            p_val->i_int = p_var->choices.i_count;            break;        case VLC_VAR_CLEARCHOICES:            for( i = 0 ; i < p_var->choices.i_count ; i++ )            {                p_var->pf_free( &p_var->choices.p_values[i] );            }            for( i = 0 ; i < p_var->choices_text.i_count ; i++ )            {                if( p_var->choices_text.p_values[i].psz_string )                    free( p_var->choices_text.p_values[i].psz_string );            }            if( p_var->choices.i_count ) free( p_var->choices.p_values );            if( p_var->choices_text.i_count ) free( p_var->choices_text.p_values );            p_var->choices.i_count = 0;            p_var->choices.p_values = NULL;            p_var->choices_text.i_count = 0;            p_var->choices_text.p_values = NULL;            p_var->i_default = -1;            break;        case VLC_VAR_SETDEFAULT:            /* FIXME: the list is sorted, dude. Use something cleverer. */            for( i = 0 ; i < p_var->choices.i_count ; i++ )            {                if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) == 0 )                {                    break;                }            }            if( i == p_var->choices.i_count )            {                /* Not found */                break;            }            p_var->i_default = i;            CheckValue( p_var, &p_var->val );            break;        case VLC_VAR_SETVALUE:            /* Duplicate data if needed */            p_var->pf_dup( p_val );            /* Backup needed stuff */            oldval = p_var->val;            /* Check boundaries and list */            CheckValue( p_var, p_val );            /* Set the variable */            p_var->val = *p_val;            /* Free data if needed */            p_var->pf_free( &oldval );            break;        case VLC_VAR_GETCHOICES:        case VLC_VAR_GETLIST:            p_val->p_list = malloc( sizeof(vlc_list_t) );            if( p_val2 ) p_val2->p_list = malloc( sizeof(vlc_list_t) );            if( p_var->choices.i_count )            {                p_val->p_list->p_values = malloc( p_var->choices.i_count                                                  * sizeof(vlc_value_t) );                p_val->p_list->pi_types = malloc( p_var->choices.i_count                                                  * sizeof(int) );                if( p_val2 )                {                    p_val2->p_list->p_values =                        malloc( p_var->choices.i_count * sizeof(vlc_value_t) );                    p_val2->p_list->pi_types =                        malloc( p_var->choices.i_count * sizeof(int) );                }            }            p_val->p_list->i_count = p_var->choices.i_count;            if( p_val2 ) p_val2->p_list->i_count = p_var->choices.i_count;            for( i = 0 ; i < p_var->choices.i_count ; i++ )            {                p_val->p_list->p_values[i] = p_var->choices.p_values[i];                p_val->p_list->pi_types[i] = p_var->i_type;                p_var->pf_dup( &p_val->p_list->p_values[i] );                if( p_val2 )                {                    p_val2->p_list->p_values[i].psz_string =                        p_var->choices_text.p_values[i].psz_string ?                    strdup(p_var->choices_text.p_values[i].psz_string) : NULL;                    p_val2->p_list->pi_types[i] = VLC_VAR_STRING;                }            }            break;        case VLC_VAR_FREELIST:            FreeList( p_val );            if( p_val2 && p_val2->p_list )            {                for( i = 0; i < p_val2->p_list->i_count; i++ )                    if( p_val2->p_list->p_values[i].psz_string )                        free( p_val2->p_list->p_values[i].psz_string );                if( p_val2->p_list->i_count )                {                    free( p_val2->p_list->p_values );                    free( p_val2->p_list->pi_types );                }                free( p_val2->p_list );            }            break;        case VLC_VAR_SETTEXT:            if( p_var->psz_text ) free( p_var->psz_text );            if( p_val && p_val->psz_string )                p_var->psz_text = strdup( p_val->psz_string );            break;        case VLC_VAR_GETTEXT:            p_val->psz_string = NULL;            if( p_var->psz_text )            {                p_val->psz_string = strdup( p_var->psz_text );            }            break;        case VLC_VAR_INHERITVALUE:            {                vlc_value_t val;                if( InheritValue( p_this, psz_name, &val, p_var->i_type )                    == VLC_SUCCESS );                {                    /* Duplicate already done */                    /* Backup needed stuff */                    oldval = p_var->val;                    /* Check boundaries and list */                    CheckValue( p_var, &val );                    /* Set the variable */                    p_var->val = val;                    /* Free data if needed */                    p_var->pf_free( &oldval );                }                if( p_val )                {                    *p_val = p_var->val;                    p_var->pf_dup( p_val );                }            }            break;        case VLC_VAR_TRIGGER_CALLBACKS:            {                /* Deal with callbacks. Tell we're in a callback, release the lock,                 * call stored functions, retake the lock. */                if( p_var->i_entries )                {                    int i_var;                    int i_entries = p_var->i_entries;                    callback_entry_t *p_entries = p_var->p_entries;                    p_var->b_incallback = VLC_TRUE;                    vlc_mutex_unlock( &p_this->var_lock );                    /* The real calls */                    for( ; i_entries-- ; )                    {                        p_entries[i_entries].pf_callback( p_this, psz_name, p_var->val, p_var->val,                                                          p_entries[i_entries].p_data );                    }                    vlc_mutex_lock( &p_this->var_lock );                    i_var = Lookup( p_this->p_vars, p_this->i_vars, psz_name );                    if( i_var < 0 )                    {                        msg_Err( p_this, "variable %s has disappeared", psz_name );                        vlc_mutex_unlock( &p_this->var_lock );                        return VLC_ENOVAR;                    }                    p_var = &p_this->p_vars[i_var];                    p_var->b_incallback = VLC_FALSE;                }            }            break;        default:            break;    }    vlc_mutex_unlock( &p_this->var_lock );    return VLC_SUCCESS;}/** * Request a variable's type * * \return The variable type if it exists, or 0 if the * variable could not be found. * \see \ref var_type */int __var_Type( vlc_object_t *p_this, const char *psz_name ){    int i_var, i_type;    vlc_mutex_lock( &p_this->var_lock );    i_var = Lookup( p_this->p_vars, p_this->i_vars, psz_name );    if( i_var < 0 )    {        vlc_mutex_unlock( &p_this->var_lock );        return 0;    }    i_type = p_this->p_vars[i_var].i_type;    vlc_mutex_unlock( &p_this->var_lock );    return i_type;}/** * Set a variable's value * * \param p_this The object that hold the variable * \param psz_name The name of the variable * \param val the value to set */int __var_Set( vlc_object_t *p_this, const char *psz_name, vlc_value_t val ){    int i_var;    variable_t *p_var;    vlc_value_t oldval;    vlc_mutex_lock( &p_this->var_lock );    i_var = GetUnused( p_this, psz_name );    if( i_var < 0 )    {        vlc_mutex_unlock( &p_this->var_lock );        return i_var;    }    p_var = &p_this->p_vars[i_var];    /* Duplicate data if needed */    p_var->pf_dup( &val );    /* Backup needed stuff */    oldval = p_var->val;    /* Check boundaries and list */    CheckValue( p_var, &val );    /* Set the variable */    p_var->val = val;    /* Deal with callbacks. Tell we're in a callback, release the lock,     * call stored functions, retake the lock. */    if( p_var->i_entries )    {        int i_var;        int i_entries = p_var->i_entries;        callback_entry_t *p_entries = p_var->p_entries;        p_var->b_incallback = VLC_TRUE;        vlc_mutex_unlock( &p_this->var_lock );        /* The real calls */        for( ; i_entries-- ; )        {            p_entries[i_entries].pf_callback( p_this, psz_name, oldval, val,                                              p_entries[i_entries].p_data );        }        vlc_mutex_lock( &p_this->var_lock );        i_var = Lookup( p_this->p_vars, p_this->i_vars, psz_name );        if( i_var < 0 )        {            msg_Err( p_this, "variable %s has disappeared", psz_name );            vlc_mutex_unlock( &p_this->var_lock );            return VLC_ENOVAR;        }        p_var = &p_this->p_vars[i_var];        p_var->b_incallback = VLC_FALSE;    }    /* Free data if needed */    p_var->pf_free( &oldval );    vlc_mutex_unlock( &p_this->var_lock );    return VLC_SUCCESS;}/** * Get a variable's value * * \param p_this The object that holds the variable * \param psz_name The name of the variable * \param p_val Pointer to a vlc_value_t that will hold the variable's value *              after the function is finished */int __var_Get( vlc_object_t *p_this, const char *psz_name, vlc_value_t *p_val ){    int i_var;    variable_t *p_var;    vlc_mutex_lock( &p_this->var_lock );    i_var = Lookup( p_this->p_vars, p_this->i_vars, psz_name );    if( i_var < 0 )    {        vlc_mutex_unlock( &p_this->var_lock );        return VLC_ENOVAR;    }    p_var = &p_this->p_vars[i_var];    /* Really get the variable */    *p_val = p_var->val;    /* Duplicate value if needed */    p_var->pf_dup( p_val );    vlc_mutex_unlock( &p_this->var_lock );    return VLC_SUCCESS;}/** * Register a callback in a variable * * We store a function pointer that will be called upon variable * modification. * * \param p_this The object that holds the variable * \param psz_name The name of the variable * \param pf_callback The function pointer * \param p_data A generic pointer that will be passed as the last *               argument to the callback function. * * \warning The callback function is run in the thread that calls var_Set on *          the variable. Use proper locking. This thread may not have much *          time to spare, so keep callback functions short. */int __var_AddCallback( vlc_object_t *p_this, const char *psz_name,                       vlc_callback_t pf_callback, void *p_data ){    int i_var;    variable_t *p_var;    callback_entry_t entry;    entry.pf_callback = pf_callback;    entry.p_data = p_data;    vlc_mutex_lock( &p_this->var_lock );    i_var = GetUnused( p_this, psz_name );    if( i_var < 0 )    {        vlc_mutex_unlock( &p_this->var_lock );        return i_var;    }    p_var = &p_this->p_vars[i_var];    INSERT_ELEM( p_var->p_entries,                 p_var->i_entries,                 p_var->i_entries,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -