📄 objects.c
字号:
switch( i_mode & 0x000f ) { case FIND_PARENT: p_tmp = p_this->p_parent; if( p_tmp ) { if( p_tmp->i_object_type == i_type ) { vlc_object_yield( p_tmp ); return p_tmp; } else { return FindObject( p_tmp, i_type, i_mode ); } } break; case FIND_CHILD: for( i = vlc_internals( p_this )->i_children; i--; ) { p_tmp = vlc_internals( p_this )->pp_children[i]; if( p_tmp->i_object_type == i_type ) { vlc_object_yield( p_tmp ); return p_tmp; } else if( vlc_internals( 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 vlc_object_t * FindObjectName( vlc_object_t *p_this, const char *psz_name, 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->psz_object_name && !strcmp( p_tmp->psz_object_name, psz_name ) ) { vlc_object_yield( p_tmp ); return p_tmp; } else { return FindObjectName( p_tmp, psz_name, i_mode ); } } break; case FIND_CHILD: for( i = vlc_internals( p_this )->i_children; i--; ) { p_tmp = vlc_internals( p_this )->pp_children[i]; if( p_tmp->psz_object_name && !strcmp( p_tmp->psz_object_name, psz_name ) ) { vlc_object_yield( p_tmp ); return p_tmp; } else if( vlc_internals( p_tmp )->i_children ) { p_tmp = FindObjectName( p_tmp, psz_name, i_mode ); if( p_tmp ) { return p_tmp; } } } break; case FIND_ANYWHERE: /* Handled in vlc_object_find */ break; } return NULL;}static void PrintObject( vlc_object_t *p_this, const char *psz_prefix ){ char psz_children[20], psz_refcount[20], psz_thread[30], psz_name[50], psz_parent[20]; memset( &psz_name, 0, sizeof(psz_name) ); if( p_this->psz_object_name ) { snprintf( psz_name, 49, " \"%s\"", p_this->psz_object_name ); if( psz_name[48] ) psz_name[48] = '\"'; } psz_children[0] = '\0'; switch( vlc_internals( p_this )->i_children ) { case 0: break; case 1: strcpy( psz_children, ", 1 child" ); break; default: snprintf( psz_children, 19, ", %i children", vlc_internals( p_this )->i_children ); break; } psz_refcount[0] = '\0'; if( vlc_internals( p_this )->i_refcount > 0 ) snprintf( psz_refcount, 19, ", refcount %u", vlc_internals( p_this )->i_refcount ); psz_thread[0] = '\0'; if( vlc_internals( p_this )->b_thread ) snprintf( psz_thread, 29, " (thread %lu)", (unsigned long)vlc_internals( p_this )->thread_id ); psz_parent[0] = '\0'; if( p_this->p_parent ) snprintf( psz_parent, 19, ", parent %i", p_this->p_parent->i_object_id ); printf( " %so %.8i %s%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, psz_parent );}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 < vlc_internals( 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 == vlc_internals( 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( vlc_internals( 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; } vlc_object_yield( p_object ); 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; } vlc_object_yield( p_object ); 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 < vlc_internals( p_this )->i_children; i++ ) { p_tmp = vlc_internals( p_this )->pp_children[i]; if( p_tmp->i_object_type == i_type ) { i_count++; } 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 < vlc_internals( p_this )->i_children; i++ ) { p_tmp = vlc_internals( p_this )->pp_children[i]; if( p_tmp->i_object_type == i_type ) ListReplace( p_list, p_tmp, p_list->i_count++ ); ListChildren( p_list, p_tmp, i_type ); }}#ifdef LIBVLC_REFCHECK# if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE)# include <execinfo.h># endifvoid vlc_refcheck (vlc_object_t *obj){ static unsigned errors = 0; if (errors > 100) return; /* Anyone can use the root object (though it should not exist) */ if (obj == VLC_OBJECT (vlc_global ())) return; /* Anyone can use its libvlc instance object */ if (obj == VLC_OBJECT (obj->p_libvlc)) return; /* The thread that created the object holds the initial reference */ vlc_object_internals_t *priv = vlc_internals (obj);#if defined (LIBVLC_USE_PTHREAD) if (pthread_equal (priv->creator_id, pthread_self ()))#elif defined WIN32 if (priv->creator_id == GetCurrentThreadId ())#else if (0)#endif return; /* A thread can use its own object without references! */ vlc_object_t *caller = vlc_threadobj (); if (caller == obj) return;#if 0 /* The calling thread is younger than the object. * Access could be valid through cross-thread synchronization; * we would need better accounting. */ if (caller && (caller->i_object_id > obj->i_object_id)) return;#endif int refs; vlc_spin_lock (&priv->ref_spin); refs = priv->i_refcount; vlc_spin_unlock (&priv->ref_spin); for (held_list_t *hlcur = vlc_threadvar_get (&held_objects); hlcur != NULL; hlcur = hlcur->next) if (hlcur->obj == obj) return; fprintf (stderr, "The %s %s thread object is accessing...\n" "the %s %s object without references.\n", caller && caller->psz_object_name ? caller->psz_object_name : "unnamed", caller ? caller->psz_object_type : "main", obj->psz_object_name ? obj->psz_object_name : "unnamed", obj->psz_object_type); fflush (stderr);#ifdef HAVE_BACKTRACE void *stack[20]; int stackdepth = backtrace (stack, sizeof (stack) / sizeof (stack[0])); backtrace_symbols_fd (stack, stackdepth, 2);#endif if (++errors == 100) fprintf (stderr, "Too many reference errors!\n");}static void held_objects_destroy (void *data){ VLC_UNUSED( data ); held_list_t *hl = vlc_threadvar_get (&held_objects); vlc_object_t *caller = vlc_threadobj (); while (hl != NULL) { held_list_t *buf = hl->next; vlc_object_t *obj = hl->obj; fprintf (stderr, "The %s %s thread object leaked a reference to...\n" "the %s %s object.\n", caller && caller->psz_object_name ? caller->psz_object_name : "unnamed", caller ? caller->psz_object_type : "main", obj->psz_object_name ? obj->psz_object_name : "unnamed", obj->psz_object_type); free (hl); hl = buf; }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -