Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _LIBVLC_MEDIA_LIST_PATH_H
00026 #define _LIBVLC_MEDIA_LIST_PATH_H 1
00027
00028 typedef int * libvlc_media_list_path_t;
00029
00030
00031
00032
00033 static inline void libvlc_media_list_path_dump( const libvlc_media_list_path_t path )
00034 {
00035 if(!path)
00036 {
00037 printf("NULL path\n");
00038 return;
00039 }
00040
00041 int i;
00042 for(i = 0; path[i] != -1; i++)
00043 printf("%s%d", i > 0 ? "/" : "", path[i]);
00044 printf("\n");
00045 }
00046
00047
00048
00049
00050 static inline libvlc_media_list_path_t libvlc_media_list_path_empty( void )
00051 {
00052 libvlc_media_list_path_t ret = xmalloc(sizeof(int));
00053 ret[0] = -1;
00054 return ret;
00055 }
00056
00057
00058
00059
00060 static inline libvlc_media_list_path_t libvlc_media_list_path_with_root_index( int index )
00061 {
00062 libvlc_media_list_path_t ret = xmalloc(sizeof(int)*2);
00063 ret[0] = index;
00064 ret[1] = -1;
00065 return ret;
00066 }
00067
00068
00069
00070
00071 static inline int libvlc_media_list_path_depth( const libvlc_media_list_path_t path )
00072 {
00073 int i;
00074 for( i = 0; path[i] != -1; i++ );
00075 return i;
00076 }
00077
00078
00079
00080
00081 static inline void libvlc_media_list_path_append( libvlc_media_list_path_t * p_path, int index )
00082 {
00083 int old_depth = libvlc_media_list_path_depth( *p_path );
00084 *p_path = xrealloc( *p_path, sizeof(int)*(old_depth+2));
00085 *p_path[old_depth] = index;
00086 *p_path[old_depth+1] = -1;
00087 }
00088
00089
00090
00091
00092 static inline libvlc_media_list_path_t libvlc_media_list_path_copy_by_appending( const libvlc_media_list_path_t path, int index )
00093 {
00094 libvlc_media_list_path_t ret;
00095 int old_depth = libvlc_media_list_path_depth( path );
00096 ret = xmalloc( sizeof(int) * (old_depth + 2) );
00097 memcpy( ret, path, sizeof(int) * old_depth );
00098 ret[old_depth] = index;
00099 ret[old_depth+1] = -1;
00100 return ret;
00101 }
00102
00103
00104
00105
00106 static inline libvlc_media_list_path_t libvlc_media_list_path_copy( const libvlc_media_list_path_t path )
00107 {
00108 libvlc_media_list_path_t ret;
00109 int depth = libvlc_media_list_path_depth( path );
00110 ret = xmalloc( sizeof(int)*(depth+1) );
00111 memcpy( ret, path, sizeof(int)*(depth+1) );
00112 return ret;
00113 }
00114
00115
00116
00117
00118 static libvlc_media_list_path_t
00119 get_path_rec( const libvlc_media_list_path_t path, libvlc_media_list_t * p_current_mlist, libvlc_media_t * p_searched_md )
00120 {
00121 int i, count;
00122 count = libvlc_media_list_count( p_current_mlist );
00123 for( i = 0; i < count; i++ )
00124 {
00125 libvlc_media_t * p_md = libvlc_media_list_item_at_index( p_current_mlist, i );
00126
00127 if( p_md == p_searched_md )
00128 return libvlc_media_list_path_copy_by_appending( path, i );
00129
00130 libvlc_media_list_t * p_subitems = libvlc_media_subitems( p_md );
00131 libvlc_media_release( p_md );
00132 if( p_subitems )
00133 {
00134 libvlc_media_list_path_t new_path = libvlc_media_list_path_copy_by_appending( path, i );
00135 libvlc_media_list_lock( p_subitems );
00136 libvlc_media_list_path_t ret = get_path_rec( new_path, p_subitems, p_searched_md );
00137 libvlc_media_list_unlock( p_subitems );
00138 free( new_path );
00139 libvlc_media_list_release( p_subitems );
00140 if( ret )
00141 return ret;
00142 }
00143 }
00144 return NULL;
00145 }
00146
00147
00148
00149
00150 static inline libvlc_media_list_path_t libvlc_media_list_path_of_item( libvlc_media_list_t * p_mlist, libvlc_media_t * p_md )
00151 {
00152 libvlc_media_list_path_t path = libvlc_media_list_path_empty();
00153 libvlc_media_list_path_t ret;
00154 ret = get_path_rec( path, p_mlist, p_md );
00155 free( path );
00156 return ret;
00157 }
00158
00159
00160
00161
00162 static libvlc_media_t *
00163 libvlc_media_list_item_at_path( libvlc_media_list_t * p_mlist, const libvlc_media_list_path_t path )
00164 {
00165 libvlc_media_list_t * p_current_mlist = p_mlist;
00166 libvlc_media_t * p_md = NULL;
00167 int i;
00168 for( i = 0; path[i] != -1; i++ )
00169 {
00170 p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i] );
00171
00172 if( p_current_mlist != p_mlist )
00173 libvlc_media_list_release( p_current_mlist );
00174
00175 if( path[i+1] == -1 )
00176 return p_md;
00177
00178 p_current_mlist = libvlc_media_subitems( p_md );
00179 libvlc_media_release( p_md );
00180
00181 if( !p_current_mlist )
00182 return NULL;
00183
00184
00185 }
00186
00187 if( p_current_mlist != p_mlist )
00188 libvlc_media_list_release( p_current_mlist );
00189 return NULL;
00190 }
00191
00192
00193
00194
00195 static libvlc_media_list_t *
00196 libvlc_media_list_parentlist_at_path( libvlc_media_list_t * p_mlist, const libvlc_media_list_path_t path )
00197 {
00198 libvlc_media_list_t * p_current_mlist = p_mlist;
00199 libvlc_media_t * p_md = NULL;
00200 int i;
00201 for( i = 0; path[i] != -1; i++ )
00202 {
00203 if( p_current_mlist != p_mlist )
00204 libvlc_media_list_release( p_current_mlist );
00205
00206 if( path[i+1] == -1 )
00207 {
00208 libvlc_media_list_retain(p_current_mlist);
00209 return p_current_mlist;
00210 }
00211
00212 p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i] );
00213
00214 p_current_mlist = libvlc_media_subitems( p_md );
00215 libvlc_media_release( p_md );
00216
00217 if( !p_current_mlist )
00218 return NULL;
00219
00220
00221 }
00222
00223 if( p_current_mlist != p_mlist )
00224 libvlc_media_list_release( p_current_mlist );
00225 return NULL;
00226 }
00227
00228
00229
00230
00231 static libvlc_media_list_t *
00232 libvlc_media_list_sublist_at_path( libvlc_media_list_t * p_mlist, const libvlc_media_list_path_t path )
00233 {
00234 libvlc_media_list_t * ret;
00235 libvlc_media_t * p_md = libvlc_media_list_item_at_path( p_mlist, path );
00236 if( !p_md )
00237 return NULL;
00238
00239 ret = libvlc_media_subitems( p_md );
00240 libvlc_media_release( p_md );
00241
00242 return ret;
00243 }
00244
00245 #endif