| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
#ifdef HAVE_CONFIG_H |
|---|
| 25 |
# include "config.h" |
|---|
| 26 |
#endif |
|---|
| 27 |
|
|---|
| 28 |
#include <vlc_common.h> |
|---|
| 29 |
#include <assert.h> |
|---|
| 30 |
#include <vlc_playlist.h> |
|---|
| 31 |
#include "playlist_internal.h" |
|---|
| 32 |
|
|---|
| 33 |
static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item, |
|---|
| 34 |
playlist_item_t *p_node, int i_mode, int i_pos ); |
|---|
| 35 |
static void GoAndPreparse( playlist_t *p_playlist, int i_mode, |
|---|
| 36 |
playlist_item_t *, playlist_item_t * ); |
|---|
| 37 |
static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item ); |
|---|
| 38 |
static int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item, |
|---|
| 39 |
bool b_stop ); |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
static void input_item_subitem_added( const vlc_event_t * p_event, |
|---|
| 45 |
void * user_data ) |
|---|
| 46 |
{ |
|---|
| 47 |
playlist_item_t *p_parent_playlist_item = user_data; |
|---|
| 48 |
playlist_t * p_playlist = p_parent_playlist_item->p_playlist; |
|---|
| 49 |
input_item_t * p_parent, * p_child; |
|---|
| 50 |
playlist_item_t * p_child_in_category; |
|---|
| 51 |
playlist_item_t * p_item_in_category; |
|---|
| 52 |
bool b_play; |
|---|
| 53 |
|
|---|
| 54 |
p_parent = p_event->p_obj; |
|---|
| 55 |
p_child = p_event->u.input_item_subitem_added.p_new_child; |
|---|
| 56 |
|
|---|
| 57 |
PL_LOCK; |
|---|
| 58 |
b_play = var_CreateGetBool( p_playlist, "playlist-autostart" ); |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
p_child_in_category = playlist_ItemFindFromInputAndRoot( |
|---|
| 65 |
p_playlist, p_child->i_id, |
|---|
| 66 |
p_playlist->p_root_category, |
|---|
| 67 |
false ); |
|---|
| 68 |
|
|---|
| 69 |
if( !p_child_in_category ) |
|---|
| 70 |
{ |
|---|
| 71 |
|
|---|
| 72 |
p_item_in_category = playlist_ItemFindFromInputAndRoot( |
|---|
| 73 |
p_playlist, p_parent->i_id, |
|---|
| 74 |
p_playlist->p_root_category, |
|---|
| 75 |
false ); |
|---|
| 76 |
if( !p_item_in_category ) |
|---|
| 77 |
{ |
|---|
| 78 |
|
|---|
| 79 |
PL_UNLOCK; |
|---|
| 80 |
return; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
b_play = b_play && |
|---|
| 84 |
p_item_in_category == get_current_status_item( p_playlist ); |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
if( p_item_in_category->i_children == -1 ) |
|---|
| 88 |
{ |
|---|
| 89 |
p_item_in_category = playlist_ItemToNode( p_playlist, |
|---|
| 90 |
p_item_in_category, pl_Locked ); |
|---|
| 91 |
p_item_in_category->p_input->i_type = ITEM_TYPE_PLAYLIST; |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
int i_ret = playlist_BothAddInput( p_playlist, p_child, |
|---|
| 95 |
p_item_in_category, |
|---|
| 96 |
PLAYLIST_APPEND | PLAYLIST_SPREPARSE , PLAYLIST_END, |
|---|
| 97 |
NULL, NULL, pl_Locked ); |
|---|
| 98 |
|
|---|
| 99 |
if( i_ret == VLC_SUCCESS && b_play ) |
|---|
| 100 |
{ |
|---|
| 101 |
playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, |
|---|
| 102 |
pl_Locked, p_item_in_category, NULL ); |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
PL_UNLOCK; |
|---|
| 107 |
|
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
static void input_item_changed( const vlc_event_t * p_event, |
|---|
| 114 |
void * user_data ) |
|---|
| 115 |
{ |
|---|
| 116 |
(void)p_event; |
|---|
| 117 |
playlist_item_t * p_item = user_data; |
|---|
| 118 |
var_SetInteger( p_item->p_playlist, "item-change", p_item->i_id ); |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
static void install_input_item_observer( playlist_item_t * p_item ) |
|---|
| 125 |
{ |
|---|
| 126 |
vlc_event_manager_t * p_em = &p_item->p_input->event_manager; |
|---|
| 127 |
vlc_event_attach( p_em, vlc_InputItemSubItemAdded, |
|---|
| 128 |
input_item_subitem_added, p_item ); |
|---|
| 129 |
vlc_event_attach( p_em, vlc_InputItemDurationChanged, |
|---|
| 130 |
input_item_changed, p_item ); |
|---|
| 131 |
vlc_event_attach( p_em, vlc_InputItemMetaChanged, |
|---|
| 132 |
input_item_changed, p_item ); |
|---|
| 133 |
vlc_event_attach( p_em, vlc_InputItemNameChanged, |
|---|
| 134 |
input_item_changed, p_item ); |
|---|
| 135 |
vlc_event_attach( p_em, vlc_InputItemInfoChanged, |
|---|
| 136 |
input_item_changed, p_item ); |
|---|
| 137 |
vlc_event_attach( p_em, vlc_InputItemErrorWhenReadingChanged, |
|---|
| 138 |
input_item_changed, p_item ); |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
static void uninstall_input_item_observer( playlist_item_t * p_item ) |
|---|
| 142 |
{ |
|---|
| 143 |
vlc_event_manager_t * p_em = &p_item->p_input->event_manager; |
|---|
| 144 |
vlc_event_detach( p_em, vlc_InputItemSubItemAdded, |
|---|
| 145 |
input_item_subitem_added, p_item ); |
|---|
| 146 |
vlc_event_detach( p_em, vlc_InputItemMetaChanged, |
|---|
| 147 |
input_item_changed, p_item ); |
|---|
| 148 |
vlc_event_detach( p_em, vlc_InputItemDurationChanged, |
|---|
| 149 |
input_item_changed, p_item ); |
|---|
| 150 |
vlc_event_detach( p_em, vlc_InputItemNameChanged, |
|---|
| 151 |
input_item_changed, p_item ); |
|---|
| 152 |
vlc_event_detach( p_em, vlc_InputItemInfoChanged, |
|---|
| 153 |
input_item_changed, p_item ); |
|---|
| 154 |
vlc_event_detach( p_em, vlc_InputItemErrorWhenReadingChanged, |
|---|
| 155 |
input_item_changed, p_item ); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
playlist_item_t *playlist_ItemNewFromInput( playlist_t *p_playlist, |
|---|
| 162 |
input_item_t *p_input ) |
|---|
| 163 |
{ |
|---|
| 164 |
DECMALLOC_NULL( p_item, playlist_item_t ); |
|---|
| 165 |
|
|---|
| 166 |
assert( p_input ); |
|---|
| 167 |
|
|---|
| 168 |
p_item->p_input = p_input; |
|---|
| 169 |
vlc_gc_incref( p_item->p_input ); |
|---|
| 170 |
|
|---|
| 171 |
p_item->i_id = ++p_playlist->i_last_playlist_id; |
|---|
| 172 |
|
|---|
| 173 |
p_item->p_parent = NULL; |
|---|
| 174 |
p_item->i_children = -1; |
|---|
| 175 |
p_item->pp_children = NULL; |
|---|
| 176 |
p_item->i_flags = 0; |
|---|
| 177 |
p_item->p_playlist = p_playlist; |
|---|
| 178 |
|
|---|
| 179 |
install_input_item_observer( p_item ); |
|---|
| 180 |
|
|---|
| 181 |
return p_item; |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
playlist_item_t * playlist_ItemNewWithType( playlist_t *p_playlist, |
|---|
| 185 |
const char *psz_uri, |
|---|
| 186 |
const char *psz_name, |
|---|
| 187 |
int i_options, |
|---|
| 188 |
const char *const *ppsz_options, |
|---|
| 189 |
int i_duration, int i_type ) |
|---|
| 190 |
{ |
|---|
| 191 |
input_item_t *p_input; |
|---|
| 192 |
if( psz_uri == NULL ) return NULL; |
|---|
| 193 |
p_input = input_item_NewWithType( VLC_OBJECT(p_playlist), psz_uri, |
|---|
| 194 |
psz_name, i_options, ppsz_options, |
|---|
| 195 |
i_duration, i_type ); |
|---|
| 196 |
return playlist_ItemNewFromInput( p_playlist, p_input ); |
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
int playlist_ItemRelease( playlist_item_t *p_item ) |
|---|
| 210 |
{ |
|---|
| 211 |
|
|---|
| 212 |
playlist_t *p_playlist = p_item->p_playlist; |
|---|
| 213 |
PL_ASSERT_LOCKED; |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
uninstall_input_item_observer( p_item ); |
|---|
| 223 |
ARRAY_APPEND( p_item->p_playlist->items_to_delete, p_item); |
|---|
| 224 |
return VLC_SUCCESS; |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
static int DeleteFromInput( playlist_t *p_playlist, int i_input_id, |
|---|
| 238 |
playlist_item_t *p_root, bool b_do_stop ) |
|---|
| 239 |
{ |
|---|
| 240 |
int i; |
|---|
| 241 |
PL_ASSERT_LOCKED; |
|---|
| 242 |
for( i = 0 ; i< p_root->i_children ; i++ ) |
|---|
| 243 |
{ |
|---|
| 244 |
if( p_root->pp_children[i]->i_children == -1 && |
|---|
| 245 |
p_root->pp_children[i]->p_input->i_id == i_input_id ) |
|---|
| 246 |
{ |
|---|
| 247 |
DeleteInner( p_playlist, p_root->pp_children[i], b_do_stop ); |
|---|
| 248 |
return VLC_SUCCESS; |
|---|
| 249 |
} |
|---|
| 250 |
else if( p_root->pp_children[i]->i_children >= 0 ) |
|---|
| 251 |
{ |
|---|
| 252 |
int i_ret = DeleteFromInput( p_playlist, i_input_id, |
|---|
| 253 |
p_root->pp_children[i], b_do_stop ); |
|---|
| 254 |
if( i_ret == VLC_SUCCESS ) return VLC_SUCCESS; |
|---|
| 255 |
} |
|---|
| 256 |
} |
|---|
| 257 |
return VLC_EGENERIC; |
|---|
| 258 |
} |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
int playlist_DeleteFromInputInParent( playlist_t *p_playlist, int i_input_id, |
|---|
| 271 |
playlist_item_t *p_root, bool b_locked ) |
|---|
| 272 |
{ |
|---|
| 273 |
int i_ret; |
|---|
| 274 |
PL_LOCK_IF( !b_locked ); |
|---|
| 275 |
i_ret = DeleteFromInput( p_playlist, i_input_id, |
|---|
| 276 |
p_root, true ); |
|---|
| 277 |
PL_UNLOCK_IF( !b_locked ); |
|---|
| 278 |
return i_ret; |
|---|
| 279 |
} |
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
int playlist_DeleteFromInput( playlist_t *p_playlist, int i_input_id, |
|---|
| 291 |
bool b_locked ) |
|---|
| 292 |
{ |
|---|
| 293 |
int i_ret1, i_ret2; |
|---|
| 294 |
PL_LOCK_IF( !b_locked ); |
|---|
| 295 |
i_ret1 = DeleteFromInput( p_playlist, i_input_id, |
|---|
| 296 |
p_playlist->p_root_category, true ); |
|---|
| 297 |
i_ret2 = DeleteFromInput( p_playlist, i_input_id, |
|---|
| 298 |
p_playlist->p_root_onelevel, true ); |
|---|
| 299 |
PL_UNLOCK_IF( !b_locked ); |
|---|
| 300 |
return ( i_ret1 == VLC_SUCCESS || i_ret2 == VLC_SUCCESS ) ? |
|---|
| 301 |
VLC_SUCCESS : VLC_ENOITEM; |
|---|
| 302 |
} |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
void playlist_Clear( playlist_t * p_playlist, bool b_locked ) |
|---|
| 312 |
{ |
|---|
| 313 |
PL_LOCK_IF( !b_locked ); |
|---|
| 314 |
playlist_NodeEmpty( p_playlist, p_playlist->p_local_category, true ); |
|---|
| 315 |
playlist_NodeEmpty( p_playlist, p_playlist->p_local_onelevel, true ); |
|---|
| 316 |
PL_UNLOCK_IF( !b_locked ); |
|---|
| 317 |
} |
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id ) |
|---|
| 329 |
{ |
|---|
| 330 |
PL_ASSERT_LOCKED; |
|---|
| 331 |
playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id, |
|---|
| 332 |
pl_Locked ); |
|---|
| 333 |
if( !p_item ) return VLC_EGENERIC; |
|---|
| 334 |
return DeleteInner( p_playlist, p_item, true ); |
|---|
| 335 |
} |
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
int playlist_Add( playlist_t *p_playlist, const char *psz_uri, |
|---|
| 356 |
const char *psz_name, int i_mode, int i_pos, |
|---|
| 357 |
bool b_playlist, bool b_locked ) |
|---|
| 358 |
{ |
|---|
| 359 |
return playlist_AddExt( p_playlist, psz_uri, psz_name, |
|---|
| 360 |
i_mode, i_pos, -1, NULL, 0, b_playlist, b_locked ); |
|---|
| 361 |
} |
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri, |
|---|
| 381 |
const char *psz_name, int i_mode, int i_pos, |
|---|
| 382 |
mtime_t i_duration, const char *const *ppsz_options, |
|---|
| 383 |
int i_options, bool b_playlist, bool b_locked ) |
|---|
| 384 |
{ |
|---|
| 385 |
int i_ret; |
|---|
| 386 |
input_item_t *p_input = input_item_NewExt( p_playlist, psz_uri, psz_name, |
|---|
| 387 |
i_options, ppsz_options, |
|---|
| 388 |
i_duration ); |
|---|
| 389 |
|
|---|
| 390 |
i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist, |
|---|
| 391 |
b_locked ); |
|---|
| 392 |
int i_id = (i_ret == VLC_SUCCESS) ? p_input->i_id : -1; |
|---|
| 393 |
|
|---|
| 394 |
vlc_gc_decref( p_input ); |
|---|
| 395 |
|
|---|
| 396 |
return i_id; |
|---|
| 397 |
} |
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 |
int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input, |
|---|
| 413 |
int i_mode, int i_pos, bool b_playlist, |
|---|
| 414 |
bool b_locked ) |
|---|
| 415 |
{ |
|---|
| 416 |
playlist_item_t *p_item_cat, *p_item_one; |
|---|
| 417 |
if( p_playlist->b_die ) return VLC_EGENERIC; |
|---|
| 418 |
if( !p_playlist->b_doing_ml ) |
|---|
| 419 |
PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name, |
|---|
| 420 |
p_input->psz_uri ); |
|---|
| 421 |
|
|---|
| 422 |
PL_LOCK_IF( !b_locked ); |
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
p_item_one = playlist_ItemNewFromInput( p_playlist, p_input ); |
|---|
| 426 |
if( p_item_one == NULL ) return VLC_ENOMEM; |
|---|
| 427 |
AddItem( p_playlist, p_item_one, |
|---|
| 428 |
b_playlist ? p_playlist->p_local_onelevel : |
|---|
| 429 |
p_playlist->p_ml_onelevel , i_mode, i_pos ); |
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input ); |
|---|
| 433 |
if( p_item_cat == NULL ) return VLC_ENOMEM; |
|---|
| 434 |
AddItem( p_playlist, p_item_cat, |
|---|
| 435 |
b_playlist ? p_playlist->p_local_category : |
|---|
| 436 |
p_playlist->p_ml_category , i_mode, i_pos ); |
|---|
| 437 |
|
|---|
| 438 |
GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one ); |
|---|
| 439 |
|
|---|
| 440 |
PL_UNLOCK_IF( !b_locked ); |
|---|
| 441 |
return VLC_SUCCESS; |
|---|
| 442 |
} |
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
int playlist_BothAddInput( playlist_t *p_playlist, |
|---|
| 462 |
input_item_t *p_input, |
|---|
| 463 |
playlist_item_t *p_direct_parent, |
|---|
| 464 |
int i_mode, int i_pos, |
|---|
| 465 |
int *i_cat, int *i_one, bool b_locked ) |
|---|
| 466 |
{ |
|---|
| 467 |
playlist_item_t *p_item_cat, *p_item_one, *p_up; |
|---|
| 468 |
int i_top; |
|---|
| 469 |
assert( p_input ); |
|---|
| 470 |
|
|---|
| 471 |
if( !vlc_object_alive( p_playlist ) ) |
|---|
| 472 |
return VLC_EGENERIC; |
|---|
| 473 |
|
|---|
| 474 |
PL_LOCK_IF( !b_locked ); |
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input ); |
|---|
| 478 |
if( p_item_cat == NULL ) return VLC_ENOMEM; |
|---|
| 479 |
AddItem( p_playlist, p_item_cat, p_direct_parent, i_mode, i_pos ); |
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
p_item_one = playlist_ItemNewFromInput( p_playlist, p_input ); |
|---|
| 484 |
if( p_item_one == NULL ) return VLC_ENOMEM; |
|---|
| 485 |
|
|---|
| 486 |
p_up = p_direct_parent; |
|---|
| 487 |
while( p_up->p_parent != p_playlist->p_root_category ) |
|---|
| 488 |
{ |
|---|
| 489 |
p_up = p_up->p_parent; |
|---|
| 490 |
} |
|---|
| 491 |
for( i_top = 0 ; i_top < p_playlist->p_root_onelevel->i_children; i_top++ ) |
|---|
| 492 |
{ |
|---|
| 493 |
if( p_playlist->p_root_onelevel->pp_children[i_top]->p_input->i_id == |
|---|
| 494 |
p_up->p_input->i_id ) |
|---|
| 495 |
{ |
|---|
| 496 |
AddItem( p_playlist, p_item_one, |
|---|
| 497 |
p_playlist->p_root_onelevel->pp_children[i_top], |
|---|
| 498 |
i_mode, i_pos ); |
|---|
| 499 |
break; |
|---|
| 500 |
} |
|---|
| 501 |
} |
|---|
| 502 |
GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one ); |
|---|
| 503 |
|
|---|
| 504 |
if( i_cat ) *i_cat = p_item_cat->i_id; |
|---|
| 505 |
if( i_one ) *i_one = p_item_one->i_id; |
|---|
| 506 |
|
|---|
| 507 |
PL_UNLOCK_IF( !b_locked ); |
|---|
| 508 |
return VLC_SUCCESS; |
|---|
| 509 |
} |
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist, |
|---|
| 525 |
input_item_t *p_input, |
|---|
| 526 |
playlist_item_t *p_parent, |
|---|
| 527 |
int i_mode, int i_pos, |
|---|
| 528 |
bool b_locked ) |
|---|
| 529 |
{ |
|---|
| 530 |
playlist_item_t *p_item; |
|---|
| 531 |
assert( p_input ); |
|---|
| 532 |
assert( p_parent && p_parent->i_children != -1 ); |
|---|
| 533 |
|
|---|
| 534 |
if( p_playlist->b_die ) |
|---|
| 535 |
return NULL; |
|---|
| 536 |
PL_LOCK_IF( !b_locked ); |
|---|
| 537 |
|
|---|
| 538 |
p_item = playlist_ItemNewFromInput( p_playlist, p_input ); |
|---|
| 539 |
if( p_item == NULL ) return NULL; |
|---|
| 540 |
AddItem( p_playlist, p_item, p_parent, i_mode, i_pos ); |
|---|
| 541 |
|
|---|
| 542 |
PL_UNLOCK_IF( !b_locked ); |
|---|
| 543 |
|
|---|
| 544 |
return p_item; |
|---|
| 545 |
} |
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist, |
|---|
| 563 |
playlist_item_t *p_item, |
|---|
| 564 |
bool b_locked ) |
|---|
| 565 |
{ |
|---|
| 566 |
|
|---|
| 567 |
playlist_item_t *p_item_in_category; |
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
|
|---|
| 582 |
PL_LOCK_IF( !b_locked ); |
|---|
| 583 |
|
|---|
| 584 |
|
|---|
| 585 |
if( p_item == p_playlist->p_ml_category ) { |
|---|
| 586 |
PL_UNLOCK_IF( !b_locked ); |
|---|
| 587 |
return p_item; |
|---|
| 588 |
} |
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
p_item_in_category = playlist_ItemFindFromInputAndRoot( |
|---|
| 592 |
p_playlist, p_item->p_input->i_id, |
|---|
| 593 |
p_playlist->p_root_category, |
|---|
| 594 |
true ); |
|---|
| 595 |
|
|---|
| 596 |
if( p_item_in_category ) |
|---|
| 597 |
{ |
|---|
| 598 |
playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot( |
|---|
| 599 |
p_playlist, p_item->p_input->i_id, |
|---|
| 600 |
p_playlist->p_root_onelevel, |
|---|
| 601 |
true ); |
|---|
| 602 |
assert( p_item_in_one ); |
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
ChangeToNode( p_playlist, p_item_in_category ); |
|---|
| 606 |
|
|---|
| 607 |
|
|---|
| 608 |
if( p_item_in_one->p_parent == p_playlist->p_root_onelevel ) |
|---|
| 609 |
ChangeToNode( p_playlist, p_item_in_one ); |
|---|
| 610 |
else |
|---|
| 611 |
{ |
|---|
| 612 |
playlist_item_t *p_status_item = get_current_status_item( p_playlist ); |
|---|
| 613 |
playlist_item_t *p_status_node = get_current_status_node( p_playlist ); |
|---|
| 614 |
if( p_item_in_one == p_status_item ) |
|---|
| 615 |
{ |
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
|
|---|
| 619 |
playlist_item_t *p_prev_status_item = NULL; |
|---|
| 620 |
int i = 0; |
|---|
| 621 |
while( i < p_status_node->i_children && |
|---|
| 622 |
p_status_node->pp_children[i] != p_status_item ) |
|---|
| 623 |
{ |
|---|
| 624 |
p_prev_status_item = p_status_node->pp_children[i]; |
|---|
| 625 |
i++; |
|---|
| 626 |
} |
|---|
| 627 |
if( i == p_status_node->i_children ) |
|---|
| 628 |
p_prev_status_item = NULL; |
|---|
| 629 |
if( p_prev_status_item ) |
|---|
| 630 |
set_current_status_item( p_playlist, p_prev_status_item ); |
|---|
| 631 |
} |
|---|
| 632 |
DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id, |
|---|
| 633 |
p_playlist->p_root_onelevel, false ); |
|---|
| 634 |
} |
|---|
| 635 |
p_playlist->b_reset_currently_playing = true; |
|---|
| 636 |
vlc_object_signal_unlocked( p_playlist ); |
|---|
| 637 |
var_SetInteger( p_playlist, "item-change", p_item_in_category-> |
|---|
| 638 |
p_input->i_id ); |
|---|
| 639 |
PL_UNLOCK_IF( !b_locked ); |
|---|
| 640 |
return p_item_in_category; |
|---|
| 641 |
} |
|---|
| 642 |
else |
|---|
| 643 |
{ |
|---|
| 644 |
ChangeToNode( p_playlist, p_item ); |
|---|
| 645 |
PL_UNLOCK_IF( !b_locked ); |
|---|
| 646 |
return p_item; |
|---|
| 647 |
} |
|---|
| 648 |
} |
|---|
| 649 |
|
|---|
| 650 |
|
|---|
| 651 |
|
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 |
playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist, |
|---|
| 660 |
int i_input_id, |
|---|
| 661 |
playlist_item_t *p_root, |
|---|
| 662 |
bool b_items_only ) |
|---|
| 663 |
{ |
|---|
| 664 |
int i; |
|---|
| 665 |
for( i = 0 ; i< p_root->i_children ; i++ ) |
|---|
| 666 |
{ |
|---|
| 667 |
if( ( b_items_only ? p_root->pp_children[i]->i_children == -1 : 1 ) && |
|---|
| 668 |
p_root->pp_children[i]->p_input->i_id == i_input_id ) |
|---|
| 669 |
{ |
|---|
| 670 |
return p_root->pp_children[i]; |
|---|
| 671 |
} |
|---|
| 672 |
else if( p_root->pp_children[i]->i_children >= 0 ) |
|---|
| 673 |
{ |
|---|
| 674 |
playlist_item_t *p_search = |
|---|
| 675 |
playlist_ItemFindFromInputAndRoot( p_playlist, i_input_id, |
|---|
| 676 |
p_root->pp_children[i], |
|---|
| 677 |
b_items_only ); |
|---|
| 678 |
if( p_search ) return p_search; |
|---|
| 679 |
} |
|---|
| 680 |
} |
|---|
| 681 |
return NULL; |
|---|
| 682 |
} |
|---|
| 683 |
|
|---|
| 684 |
|
|---|
| 685 |
static int TreeMove( playlist_t *p_playlist, playlist_item_t *p_item, |
|---|
| 686 |
playlist_item_t *p_node, int i_newpos ) |
|---|
| 687 |
{ |
|---|
| 688 |
int j; |
|---|
| 689 |
playlist_item_t *p_detach = p_item->p_parent; |
|---|
| 690 |
(void)p_playlist; |
|---|
| 691 |
|
|---|
| 692 |
if( p_node->i_children == -1 ) return VLC_EGENERIC; |
|---|
| 693 |
|
|---|
| 694 |
for( j = 0; j < p_detach->i_children; j++ ) |
|---|
| 695 |
{ |
|---|
| 696 |
if( p_detach->pp_children[j] == p_item ) break; |
|---|
| 697 |
} |
|---|
| 698 |
REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j ); |
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 |
INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item ); |
|---|
| 702 |
p_item->p_parent = p_node; |
|---|
| 703 |
|
|---|
| 704 |
return VLC_SUCCESS; |
|---|
| 705 |
} |
|---|
| 706 |
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 |
|
|---|
| 710 |
|
|---|
| 711 |
|
|---|
| 712 |
|
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
|
|---|
| 716 |
|
|---|
| 717 |
|
|---|
| 718 |
int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item, |
|---|
| 719 |
playlist_item_t *p_node, int i_newpos ) |
|---|
| 720 |
{ |
|---|
| 721 |
int i_ret; |
|---|
| 722 |
PL_ASSERT_LOCKED; |
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
if( p_node->p_parent == p_playlist->p_root_category || |
|---|
| 726 |
p_node->p_parent == p_playlist->p_root_onelevel ) |
|---|
| 727 |
{ |
|---|
| 728 |
|
|---|
| 729 |
{ |
|---|
| 730 |
|
|---|
| 731 |
|
|---|
| 732 |
|
|---|
| 733 |
|
|---|
| 734 |
playlist_item_t *p_node_onelevel; |
|---|
| 735 |
playlist_item_t *p_item_onelevel; |
|---|
| 736 |
p_node_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist, |
|---|
| 737 |
p_node->p_input->i_id, |
|---|
| 738 |
p_playlist->p_root_onelevel, |
|---|
| 739 |
false ); |
|---|
| 740 |
p_item_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist, |
|---|
| 741 |
p_item->p_input->i_id, |
|---|
| 742 |
p_playlist->p_root_onelevel, |
|---|
| 743 |
false ); |
|---|
| 744 |
if( p_node_onelevel && p_item_onelevel ) |
|---|
| 745 |
TreeMove( p_playlist, p_item_onelevel, p_node_onelevel, 0 ); |
|---|
| 746 |
} |
|---|
| 747 |
{ |
|---|
| 748 |
playlist_item_t *p_node_category; |
|---|
| 749 |
playlist_item_t *p_item_category; |
|---|
| 750 |
p_node_category = playlist_ItemFindFromInputAndRoot( p_playlist, |
|---|
| 751 |
p_node->p_input->i_id, |
|---|
| 752 |
p_playlist->p_root_category, |
|---|
| 753 |
false ); |
|---|
| 754 |
p_item_category = playlist_ItemFindFromInputAndRoot( p_playlist, |
|---|
| 755 |
p_item->p_input->i_id, |
|---|
| 756 |
p_playlist->p_root_category, |
|---|
| 757 |
false ); |
|---|
| 758 |
if( p_node_category && p_item_category ) |
|---|
| 759 |
TreeMove( p_playlist, p_item_category, p_node_category, 0 ); |
|---|
| 760 |
} |
|---|
| 761 |
i_ret = VLC_SUCCESS; |
|---|
| 762 |
} |
|---|
| 763 |
else |
|---|
| 764 |
i_ret = TreeMove( p_playlist, p_item, p_node, i_newpos ); |
|---|
| 765 |
p_playlist->b_reset_currently_playing = true; |
|---|
| 766 |
vlc_object_signal_unlocked( p_playlist ); |
|---|
| 767 |
return i_ret; |
|---|
| 768 |
} |
|---|
| 769 |
|
|---|
| 770 |
|
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 |
|
|---|
| 777 |
|
|---|
| 778 |
|
|---|
| 779 |
void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id, |
|---|
| 780 |
int i_node_id, bool b_signal ) |
|---|
| 781 |
{ |
|---|
| 782 |
vlc_value_t val; |
|---|
| 783 |
PL_ASSERT_LOCKED; |
|---|
| 784 |
|
|---|
| 785 |
playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t) ); |
|---|
| 786 |
if( !p_add ) |
|---|
| 787 |
return; |
|---|
| 788 |
|
|---|
| 789 |
p_add->i_item = i_item_id; |
|---|
| 790 |
p_add->i_node = i_node_id; |
|---|
| 791 |
val.p_address = p_add; |
|---|
| 792 |
p_playlist->b_reset_currently_playing = true; |
|---|
| 793 |
if( b_signal ) |
|---|
| 794 |
vlc_object_signal_unlocked( p_playlist ); |
|---|
| 795 |
|
|---|
| 796 |
var_Set( p_playlist, "item-append", val ); |
|---|
| 797 |
free( p_add ); |
|---|
| 798 |
} |
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 |
|
|---|
| 803 |
|
|---|
| 804 |
|
|---|
| 805 |
|
|---|
| 806 |
|
|---|
| 807 |
|
|---|
| 808 |
|
|---|
| 809 |
|
|---|
| 810 |
|
|---|
| 811 |
int playlist_ItemSetName( playlist_item_t *p_item, const char *psz_name ) |
|---|
| 812 |
{ |
|---|
| 813 |
if( psz_name && p_item ) |
|---|
| 814 |
{ |
|---|
| 815 |
input_item_SetName( p_item->p_input, psz_name ); |
|---|
| 816 |
return VLC_SUCCESS; |
|---|
| 817 |
} |
|---|
| 818 |
return VLC_EGENERIC; |
|---|
| 819 |
} |
|---|
| 820 |
|
|---|
| 821 |
|
|---|
| 822 |
|
|---|
| 823 |
|
|---|
| 824 |
|
|---|
| 825 |
|
|---|
| 826 |
static void GoAndPreparse( playlist_t *p_playlist, int i_mode, |
|---|
| 827 |
playlist_item_t *p_item_cat, |
|---|
| 828 |
playlist_item_t *p_item_one ) |
|---|
| 829 |
{ |
|---|
| 830 |
PL_ASSERT_LOCKED; |
|---|
| 831 |
if( (i_mode & PLAYLIST_GO ) ) |
|---|
| 832 |
{ |
|---|
| 833 |
playlist_item_t *p_parent = p_item_one; |
|---|
| 834 |
playlist_item_t *p_toplay = NULL; |
|---|
| 835 |
while( p_parent ) |
|---|
| 836 |
{ |
|---|
| 837 |
if( p_parent == p_playlist->p_root_category ) |
|---|
| 838 |
{ |
|---|
| 839 |
p_toplay = p_item_cat; break; |
|---|
| 840 |
} |
|---|
| 841 |
else if( p_parent == p_playlist->p_root_onelevel ) |
|---|
| 842 |
{ |
|---|
| 843 |
p_toplay = p_item_one; break; |
|---|
| 844 |
} |
|---|
| 845 |
p_parent = p_parent->p_parent; |
|---|
| 846 |
} |
|---|
| 847 |
assert( p_toplay ); |
|---|
| 848 |
p_playlist->request.b_request = true; |
|---|
| 849 |
p_playlist->request.i_skip = 0; |
|---|
| 850 |
p_playlist->request.p_item = p_toplay; |
|---|
| 851 |
if( p_playlist->p_input ) |
|---|
| 852 |
input_StopThread( p_playlist->p_input ); |
|---|
| 853 |
p_playlist->request.i_status = PLAYLIST_RUNNING; |
|---|
| 854 |
vlc_object_signal_unlocked( p_playlist ); |
|---|
| 855 |
} |
|---|
| 856 |
|
|---|
| 857 |
char *psz_artist = input_item_GetArtist( p_item_cat->p_input ); |
|---|
| 858 |
char *psz_album = input_item_GetAlbum( p_item_cat->p_input ); |
|---|
| 859 |
if( p_playlist->b_auto_preparse && |
|---|
| 860 |
(i_mode & PLAYLIST_PREPARSE || |
|---|
| 861 |
( i_mode & PLAYLIST_SPREPARSE && |
|---|
| 862 |
( EMPTY_STR( psz_artist ) || ( EMPTY_STR( psz_album ) ) ) |
|---|
| 863 |
) ) ) |
|---|
| 864 |
playlist_PreparseEnqueue( p_playlist, p_item_cat->p_input ); |
|---|
| 865 |
|
|---|
| 866 |
else if( !EMPTY_STR( psz_artist ) && !EMPTY_STR( psz_album ) ) |
|---|
| 867 |
input_item_SetPreparsed( p_item_cat->p_input, true ); |
|---|
| 868 |
free( psz_artist ); |
|---|
| 869 |
free( psz_album ); |
|---|
| 870 |
} |
|---|
| 871 |
|
|---|
| 872 |
|
|---|
| 873 |
static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item, |
|---|
| 874 |
playlist_item_t *p_node, int i_mode, int i_pos ) |
|---|
| 875 |
{ |
|---|
| 876 |
PL_ASSERT_LOCKED;< |
|---|