| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
#ifndef _LIBVLC_MEDIA_LIST_PATH_H |
|---|
| 26 |
#define _LIBVLC_MEDIA_LIST_PATH_H 1 |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
static inline libvlc_media_list_path_t libvlc_media_list_path_empty( void ) |
|---|
| 32 |
{ |
|---|
| 33 |
libvlc_media_list_path_t ret = malloc(sizeof(int)); |
|---|
| 34 |
ret[0] = -1; |
|---|
| 35 |
return ret; |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
static inline libvlc_media_list_path_t libvlc_media_list_path_with_root_index( int index ) |
|---|
| 42 |
{ |
|---|
| 43 |
libvlc_media_list_path_t ret = malloc(sizeof(int)*2); |
|---|
| 44 |
ret[0] = index; |
|---|
| 45 |
ret[1] = -1; |
|---|
| 46 |
return ret; |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
static inline int libvlc_media_list_path_deepness( libvlc_media_list_path_t path ) |
|---|
| 53 |
{ |
|---|
| 54 |
int i; |
|---|
| 55 |
for( i = 0; path[i] != -1; i++ ); |
|---|
| 56 |
return i; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
static inline void libvlc_media_list_path_append( libvlc_media_list_path_t * p_path, int index ) |
|---|
| 63 |
{ |
|---|
| 64 |
int old_deepness = libvlc_media_list_path_deepness( *p_path ); |
|---|
| 65 |
*p_path = realloc( *p_path, sizeof(int)*(old_deepness+2)); |
|---|
| 66 |
*p_path[old_deepness] = index; |
|---|
| 67 |
*p_path[old_deepness+1] = -1; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
static inline libvlc_media_list_path_t libvlc_media_list_path_copy_by_appending( libvlc_media_list_path_t path, int index ) |
|---|
| 74 |
{ |
|---|
| 75 |
libvlc_media_list_path_t ret; |
|---|
| 76 |
int old_deepness = libvlc_media_list_path_deepness( path ); |
|---|
| 77 |
ret = malloc( sizeof(int)*(old_deepness+2) ); |
|---|
| 78 |
memcpy( ret, path, sizeof(int)*(old_deepness+2) ); |
|---|
| 79 |
ret[old_deepness] = index; |
|---|
| 80 |
ret[old_deepness+1] = -1; |
|---|
| 81 |
return ret; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
static inline libvlc_media_list_path_t libvlc_media_list_path_copy( libvlc_media_list_path_t path ) |
|---|
| 88 |
{ |
|---|
| 89 |
libvlc_media_list_path_t ret; |
|---|
| 90 |
int deepness = libvlc_media_list_path_deepness( path ); |
|---|
| 91 |
ret = malloc( sizeof(int)*(deepness+1) ); |
|---|
| 92 |
memcpy( ret, path, sizeof(int)*(deepness+1) ); |
|---|
| 93 |
return ret; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
static libvlc_media_list_path_t |
|---|
| 100 |
get_path_rec( libvlc_media_list_path_t path, libvlc_media_list_t * p_current_mlist, libvlc_media_t * p_searched_md ) |
|---|
| 101 |
{ |
|---|
| 102 |
int i, count; |
|---|
| 103 |
count = libvlc_media_list_count( p_current_mlist, NULL ); |
|---|
| 104 |
for( i = 0; i < count; i++ ) |
|---|
| 105 |
{ |
|---|
| 106 |
libvlc_media_t * p_md = libvlc_media_list_item_at_index( p_current_mlist, i, NULL ); |
|---|
| 107 |
|
|---|
| 108 |
if( p_md == p_searched_md ) |
|---|
| 109 |
return libvlc_media_list_path_copy_by_appending( path, i ); |
|---|
| 110 |
|
|---|
| 111 |
libvlc_media_list_t * p_subitems = libvlc_media_subitems( p_md, NULL ); |
|---|
| 112 |
libvlc_media_release( p_md ); |
|---|
| 113 |
if( p_subitems ) |
|---|
| 114 |
{ |
|---|
| 115 |
libvlc_media_list_path_t new_path = libvlc_media_list_path_copy_by_appending( path, i ); |
|---|
| 116 |
libvlc_media_list_lock( p_subitems ); |
|---|
| 117 |
libvlc_media_list_path_t ret = get_path_rec( new_path, p_subitems, p_searched_md ); |
|---|
| 118 |
libvlc_media_list_unlock( p_subitems ); |
|---|
| 119 |
free( new_path ); |
|---|
| 120 |
libvlc_media_list_release( p_subitems ); |
|---|
| 121 |
if( ret ) |
|---|
| 122 |
return ret; |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
return NULL; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
static inline libvlc_media_list_path_t libvlc_media_list_path_of_item( libvlc_media_list_t * p_mlist, libvlc_media_t * p_md ) |
|---|
| 132 |
{ |
|---|
| 133 |
libvlc_media_list_path_t path = libvlc_media_list_path_empty(); |
|---|
| 134 |
libvlc_media_list_path_t ret; |
|---|
| 135 |
ret = get_path_rec( path, p_mlist, p_md ); |
|---|
| 136 |
free( path ); |
|---|
| 137 |
return ret; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
static libvlc_media_t * |
|---|
| 144 |
libvlc_media_list_item_at_path( libvlc_media_list_t * p_mlist, libvlc_media_list_path_t path ) |
|---|
| 145 |
{ |
|---|
| 146 |
libvlc_media_list_t * p_current_mlist = p_mlist; |
|---|
| 147 |
libvlc_media_t * p_md = NULL; |
|---|
| 148 |
int i; |
|---|
| 149 |
for( i = 0; path[i] != -1; i++ ) |
|---|
| 150 |
{ |
|---|
| 151 |
p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i], NULL ); |
|---|
| 152 |
|
|---|
| 153 |
if( p_current_mlist != p_mlist ) |
|---|
| 154 |
libvlc_media_list_release( p_current_mlist ); |
|---|
| 155 |
|
|---|
| 156 |
if( path[i+1] == -1 ) |
|---|
| 157 |
return p_md; |
|---|
| 158 |
|
|---|
| 159 |
p_current_mlist = libvlc_media_subitems( p_md, NULL ); |
|---|
| 160 |
libvlc_media_release( p_md ); |
|---|
| 161 |
|
|---|
| 162 |
if( !p_current_mlist ) |
|---|
| 163 |
return NULL; |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
if( p_current_mlist != p_mlist ) |
|---|
| 169 |
libvlc_media_list_release( p_current_mlist ); |
|---|
| 170 |
return NULL; |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
static libvlc_media_list_t * |
|---|
| 177 |
libvlc_media_list_parentlist_at_path( libvlc_media_list_t * p_mlist, libvlc_media_list_path_t path ) |
|---|
| 178 |
{ |
|---|
| 179 |
libvlc_media_list_t * p_current_mlist = p_mlist; |
|---|
| 180 |
libvlc_media_t * p_md = NULL; |
|---|
| 181 |
int i; |
|---|
| 182 |
for( i = 0; path[i] != -1; i++ ) |
|---|
| 183 |
{ |
|---|
| 184 |
if( p_current_mlist != p_mlist ) |
|---|
| 185 |
libvlc_media_list_release( p_current_mlist ); |
|---|
| 186 |
|
|---|
| 187 |
if( path[i+1] == -1 ) |
|---|
| 188 |
return p_current_mlist; |
|---|
| 189 |
|
|---|
| 190 |
p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i], NULL ); |
|---|
| 191 |
|
|---|
| 192 |
p_current_mlist = libvlc_media_subitems( p_md, NULL ); |
|---|
| 193 |
libvlc_media_release( p_md ); |
|---|
| 194 |
|
|---|
| 195 |
if( !p_current_mlist ) |
|---|
| 196 |
return NULL; |
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
if( p_current_mlist != p_mlist ) |
|---|
| 202 |
libvlc_media_list_release( p_current_mlist ); |
|---|
| 203 |
return NULL; |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
static libvlc_media_list_t * |
|---|
| 210 |
libvlc_media_list_sublist_at_path( libvlc_media_list_t * p_mlist, libvlc_media_list_path_t path ) |
|---|
| 211 |
{ |
|---|
| 212 |
libvlc_media_list_t * ret; |
|---|
| 213 |
libvlc_media_t * p_md = libvlc_media_list_item_at_path( p_mlist, path ); |
|---|
| 214 |
if( !p_md ) |
|---|
| 215 |
return NULL; |
|---|
| 216 |
|
|---|
| 217 |
ret = libvlc_media_subitems( p_md, NULL ); |
|---|
| 218 |
libvlc_media_release( p_md ); |
|---|
| 219 |
|
|---|
| 220 |
return ret; |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
#endif |
|---|