📄 objects.c
字号:
(*pp_current)->psz_object_type ); } } vlc_mutex_unlock( &structure_lock ); } return VLC_SUCCESS;}/***************************************************************************** * vlc_list_release: free a list previously allocated by vlc_list_find ***************************************************************************** * This function decreases the refcount of all objects in the list and * frees the list. *****************************************************************************/void vlc_list_release( vlc_list_t *p_list ){ int i_index; for( i_index = 0; i_index < p_list->i_count; i_index++ ) { vlc_mutex_lock( &structure_lock ); p_list->p_values[i_index].p_object->i_refcount--; vlc_mutex_unlock( &structure_lock ); } free( p_list->p_values ); free( p_list );}/* Following functions are local *//***************************************************************************** * FindIndex: find the index of an object in an array of objects ***************************************************************************** * This function assumes that p_this can be found in pp_objects. It will not * crash if p_this cannot be found, but will return a wrong value. It is your * duty to check the return value if you are not certain that the object could * be found for sure. *****************************************************************************/static int FindIndex( vlc_object_t *p_this, vlc_object_t **pp_objects, int i_count ){ int i_middle = i_count / 2; if( i_count == 0 ) { return 0; } if( pp_objects[i_middle] == p_this ) { return i_middle; } if( i_count == 1 ) { return 0; } /* We take advantage of the sorted array */ if( pp_objects[i_middle]->i_object_id < p_this->i_object_id ) { return i_middle + FindIndex( p_this, pp_objects + i_middle, i_count - i_middle ); } else { return FindIndex( p_this, pp_objects, i_middle ); }}static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode ){ int i; vlc_object_t *p_tmp; switch( i_mode & 0x000f ) { case FIND_PARENT: p_tmp = p_this->p_parent; if( p_tmp ) { if( p_tmp->i_object_type == i_type ) { p_tmp->i_refcount++; return p_tmp; } else { return FindObject( p_tmp, i_type, i_mode ); } } break; case FIND_CHILD: for( i = p_this->i_children; i--; ) { p_tmp = p_this->pp_children[i]; if( p_tmp->i_object_type == i_type ) { p_tmp->i_refcount++; return p_tmp; } else if( p_tmp->i_children ) { p_tmp = FindObject( p_tmp, i_type, i_mode ); if( p_tmp ) { return p_tmp; } } } break; case FIND_ANYWHERE: /* Handled in vlc_object_find */ break; } return NULL;}static void DetachObject( vlc_object_t *p_this ){ vlc_object_t *p_parent = p_this->p_parent; int i_index, i; /* Remove p_this's parent */ p_this->p_parent = NULL; /* Remove all of p_parent's children which are p_this */ for( i_index = p_parent->i_children ; i_index-- ; ) { if( p_parent->pp_children[i_index] == p_this ) { p_parent->i_children--; for( i = i_index ; i < p_parent->i_children ; i++ ) { p_parent->pp_children[i] = p_parent->pp_children[i+1]; } } } if( p_parent->i_children ) { p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children, p_parent->i_children * sizeof(vlc_object_t *) ); } else { free( p_parent->pp_children ); p_parent->pp_children = NULL; }}/***************************************************************************** * SetAttachment: recursively set the b_attached flag of a subtree. ***************************************************************************** * This function is used by the attach and detach functions to propagate * the b_attached flag in a subtree. *****************************************************************************/static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached ){ int i_index; for( i_index = p_this->i_children ; i_index-- ; ) { SetAttachment( p_this->pp_children[i_index], b_attached ); } p_this->b_attached = b_attached;}static void PrintObject( vlc_object_t *p_this, const char *psz_prefix ){ char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50]; psz_name[0] = '\0'; if( p_this->psz_object_name ) { snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name ); psz_name[48] = '\"'; psz_name[49] = '\0'; } psz_children[0] = '\0'; switch( p_this->i_children ) { case 0: break; case 1: strcpy( psz_children, ", 1 child" ); break; default: snprintf( psz_children, 20, ", %i children", p_this->i_children ); psz_children[19] = '\0'; break; } psz_refcount[0] = '\0'; if( p_this->i_refcount ) { snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount ); psz_refcount[19] = '\0'; } psz_thread[0] = '\0'; if( p_this->b_thread ) { snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id ); psz_thread[19] = '\0'; } printf( " %so %.8i %s%s%s%s%s\n", psz_prefix, p_this->i_object_id, p_this->psz_object_type, psz_name, psz_thread, psz_refcount, psz_children );}static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo ){ int i; char i_back = psz_foo[i_level]; psz_foo[i_level] = '\0'; PrintObject( p_this, psz_foo ); psz_foo[i_level] = i_back; if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH ) { msg_Warn( p_this, "structure tree is too deep" ); return; } for( i = 0 ; i < p_this->i_children ; i++ ) { if( i_level ) { psz_foo[i_level-1] = ' '; if( psz_foo[i_level-2] == '`' ) { psz_foo[i_level-2] = ' '; } } if( i == p_this->i_children - 1 ) { psz_foo[i_level] = '`'; } else { psz_foo[i_level] = '|'; } psz_foo[i_level+1] = '-'; psz_foo[i_level+2] = '\0'; DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo ); }}static vlc_list_t * NewList( int i_count ){ vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) ); if( p_list == NULL ) { return NULL; } p_list->i_count = i_count; if( i_count == 0 ) { p_list->p_values = NULL; return p_list; } p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) ); if( p_list->p_values == NULL ) { p_list->i_count = 0; return p_list; } return p_list;}static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object, int i_index ){ if( p_list == NULL || i_index >= p_list->i_count ) { return; } p_object->i_refcount++; p_list->p_values[i_index].p_object = p_object; return;}/*static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object ){ if( p_list == NULL ) { return; } p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1) * sizeof( vlc_value_t ) ); if( p_list->p_values == NULL ) { p_list->i_count = 0; return; } p_object->i_refcount++; p_list->p_values[p_list->i_count].p_object = p_object; p_list->i_count++; return;}*/static int CountChildren( vlc_object_t *p_this, int i_type ){ vlc_object_t *p_tmp; int i, i_count = 0; for( i = 0; i < p_this->i_children; i++ ) { p_tmp = p_this->pp_children[i]; if( p_tmp->i_object_type == i_type ) { i_count++; } if( p_tmp->i_children ) { i_count += CountChildren( p_tmp, i_type ); } } return i_count;}static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type ){ vlc_object_t *p_tmp; int i; for( i = 0; i < p_this->i_children; i++ ) { p_tmp = p_this->pp_children[i]; if( p_tmp->i_object_type == i_type ) { ListReplace( p_list, p_tmp, p_list->i_count++ ); } if( p_tmp->i_children ) { ListChildren( p_list, p_tmp, i_type ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -