Changeset 1d2aca81f9ce226e86d286d19031b08a16db3c92
- Timestamp:
- 29/08/07 01:25:54
(1 year ago)
- Author:
- Pierre d'Herbemont <pdherbemont@videolan.org>
- git-committer:
- Pierre d'Herbemont <pdherbemont@videolan.org> 1188343554 +0000
- git-parent:
[1f8d74b9502a2f9243ef91e02dd78b7be1ecb667]
- git-author:
- Pierre d'Herbemont <pdherbemont@videolan.org> 1188343554 +0000
- Message:
control/media_list_player.c: Add support for playing a hierarchical media_list.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rf15a567 |
r1d2aca8 |
|
| 23 | 23 | #include "libvlc_internal.h" |
|---|
| 24 | 24 | #include <vlc/libvlc.h> |
|---|
| | 25 | #include "media_list_path.h" |
|---|
| 25 | 26 | |
|---|
| 26 | 27 | /* |
|---|
| … | … | |
| 33 | 34 | * Simple next item fetcher. |
|---|
| 34 | 35 | **************************************************************************/ |
|---|
| 35 | | static int get_next_index( libvlc_media_list_player_t * p_mlp ) |
|---|
| | 36 | static libvlc_media_list_path_t |
|---|
| | 37 | get_next_path( libvlc_media_list_player_t * p_mlp ) |
|---|
| 36 | 38 | { |
|---|
| 37 | 39 | /* We are entered with libvlc_media_list_lock( p_mlp->p_list ) */ |
|---|
| 38 | | |
|---|
| 39 | | int next = p_mlp->i_current_playing_index + 1; |
|---|
| 40 | | |
|---|
| 41 | | if( next >= libvlc_media_list_count( p_mlp->p_mlist, NULL ) ) |
|---|
| 42 | | return -1; /* no more to play */ |
|---|
| 43 | | |
|---|
| 44 | | return next; |
|---|
| | 40 | libvlc_media_list_path_t ret; |
|---|
| | 41 | libvlc_media_list_t * p_parent_of_playing_item; |
|---|
| | 42 | libvlc_media_list_t * p_sublist_of_playing_item; |
|---|
| | 43 | p_sublist_of_playing_item = libvlc_media_list_sublist_at_path( |
|---|
| | 44 | p_mlp->p_mlist, |
|---|
| | 45 | p_mlp->current_playing_item_path ); |
|---|
| | 46 | |
|---|
| | 47 | /* If item just gained a sublist just play it */ |
|---|
| | 48 | if( p_sublist_of_playing_item ) |
|---|
| | 49 | { |
|---|
| | 50 | libvlc_media_list_release( p_sublist_of_playing_item ); |
|---|
| | 51 | return libvlc_media_list_path_copy_by_appending( p_mlp->current_playing_item_path, 0 ); |
|---|
| | 52 | } |
|---|
| | 53 | |
|---|
| | 54 | /* Try to catch next element */ |
|---|
| | 55 | p_parent_of_playing_item = libvlc_media_list_parentlist_at_path( |
|---|
| | 56 | p_mlp->p_mlist, |
|---|
| | 57 | p_mlp->current_playing_item_path ); |
|---|
| | 58 | |
|---|
| | 59 | int deepness = libvlc_media_list_path_deepness( p_mlp->current_playing_item_path ); |
|---|
| | 60 | if( deepness < 1 || !p_parent_of_playing_item ) |
|---|
| | 61 | return NULL; |
|---|
| | 62 | |
|---|
| | 63 | ret = libvlc_media_list_path_copy( p_mlp->current_playing_item_path ); |
|---|
| | 64 | |
|---|
| | 65 | while( ret[deepness-1] >= libvlc_media_list_count( p_parent_of_playing_item, NULL ) ) |
|---|
| | 66 | { |
|---|
| | 67 | deepness--; |
|---|
| | 68 | if( deepness <= 0 ) |
|---|
| | 69 | { |
|---|
| | 70 | free( ret ); |
|---|
| | 71 | libvlc_media_list_release( p_parent_of_playing_item ); |
|---|
| | 72 | return NULL; |
|---|
| | 73 | } |
|---|
| | 74 | ret[deepness] = -1; |
|---|
| | 75 | ret[deepness-1]++; |
|---|
| | 76 | p_parent_of_playing_item = libvlc_media_list_parentlist_at_path( |
|---|
| | 77 | p_mlp->p_mlist, |
|---|
| | 78 | ret ); |
|---|
| | 79 | } |
|---|
| | 80 | libvlc_media_list_release( p_parent_of_playing_item ); |
|---|
| | 81 | return ret; |
|---|
| 45 | 82 | } |
|---|
| 46 | 83 | |
|---|
| … | … | |
| 55 | 92 | libvlc_media_instance_t * p_mi = p_event->p_obj; |
|---|
| 56 | 93 | libvlc_media_descriptor_t *p_md, * p_current_md; |
|---|
| | 94 | |
|---|
| 57 | 95 | p_md = libvlc_media_instance_get_media_descriptor( p_mi, NULL ); |
|---|
| 58 | 96 | /* XXX: need if p_mlp->p_current_playing_index is beyond */ |
|---|
| 59 | | p_current_md = libvlc_media_list_item_at_index( |
|---|
| | 97 | p_current_md = libvlc_media_list_item_at_path( |
|---|
| 60 | 98 | p_mlp->p_mlist, |
|---|
| 61 | | p_mlp->i_current_playing_index, |
|---|
| 62 | | NULL ); |
|---|
| | 99 | p_mlp->current_playing_item_path ); |
|---|
| 63 | 100 | if( p_md != p_current_md ) |
|---|
| 64 | 101 | { |
|---|
| … | … | |
| 84 | 121 | libvlc_media_list_t * p_emitting_mlist = p_event->p_obj; |
|---|
| 85 | 122 | /* XXX: need if p_mlp->p_current_playing_index is beyond */ |
|---|
| 86 | | p_current_md = libvlc_media_list_item_at_index( |
|---|
| | 123 | p_current_md = libvlc_media_list_item_at_path( |
|---|
| 87 | 124 | p_mlp->p_mlist, |
|---|
| 88 | | p_mlp->i_current_playing_index, |
|---|
| 89 | | NULL ); |
|---|
| | 125 | p_mlp->current_playing_item_path ); |
|---|
| 90 | 126 | |
|---|
| 91 | 127 | if( p_event->u.media_list_item_deleted.item == p_current_md && |
|---|
| … | … | |
| 147 | 183 | libvlc_exception_t * p_e ) |
|---|
| 148 | 184 | { |
|---|
| 149 | | libvlc_exception_raise( p_e, "Unimplemented" ); |
|---|
| 150 | | return 0; |
|---|
| 151 | | } |
|---|
| 152 | | |
|---|
| 153 | | /************************************************************************** |
|---|
| 154 | | * Next (private) |
|---|
| | 185 | //libvlc_exception_raise( p_e, "Unimplemented" ); |
|---|
| | 186 | return 1; |
|---|
| | 187 | } |
|---|
| | 188 | |
|---|
| | 189 | /************************************************************************** |
|---|
| | 190 | * set_current_playing_item (private) |
|---|
| 155 | 191 | * |
|---|
| 156 | 192 | * Playlist lock should be held |
|---|
| 157 | 193 | **************************************************************************/ |
|---|
| 158 | 194 | static void |
|---|
| 159 | | media_list_player_set_next( libvlc_media_list_player_t * p_mlp, int index, |
|---|
| 160 | | libvlc_exception_t * p_e ) |
|---|
| | 195 | set_current_playing_item( libvlc_media_list_player_t * p_mlp, |
|---|
| | 196 | libvlc_media_list_path_t path, |
|---|
| | 197 | libvlc_exception_t * p_e ) |
|---|
| 161 | 198 | { |
|---|
| 162 | 199 | libvlc_media_descriptor_t * p_md; |
|---|
| 163 | 200 | |
|---|
| 164 | | p_md = libvlc_media_list_item_at_index( p_mlp->p_mlist, index, p_e ); |
|---|
| | 201 | p_md = libvlc_media_list_item_at_path( p_mlp->p_mlist, path ); |
|---|
| 165 | 202 | if( !p_md ) |
|---|
| 166 | 203 | { |
|---|
| 167 | | libvlc_media_list_unlock( p_mlp->p_mlist ); |
|---|
| 168 | 204 | if( !libvlc_exception_raised( p_e ) ) |
|---|
| 169 | 205 | libvlc_exception_raise( p_e, "Can't obtain a media" ); |
|---|
| 170 | 206 | return; |
|---|
| 171 | 207 | } |
|---|
| 172 | | |
|---|
| | 208 | |
|---|
| 173 | 209 | vlc_mutex_lock( &p_mlp->object_lock ); |
|---|
| 174 | 210 | |
|---|
| 175 | | p_mlp->i_current_playing_index = index; |
|---|
| | 211 | free( p_mlp->current_playing_item_path ); |
|---|
| | 212 | p_mlp->current_playing_item_path = path; |
|---|
| 176 | 213 | |
|---|
| 177 | 214 | /* We are not interested in getting media_descriptor stop event now */ |
|---|
| 178 | 215 | uninstall_media_instance_observer( p_mlp ); |
|---|
| 179 | | libvlc_media_instance_set_media_descriptor( p_mlp->p_mi, p_md, NULL ); |
|---|
| | 216 | if( p_md->p_subitems && libvlc_media_list_count( p_md->p_subitems, NULL ) > 0 ) |
|---|
| | 217 | { |
|---|
| | 218 | libvlc_media_descriptor_t * p_submd; |
|---|
| | 219 | p_submd = libvlc_media_list_item_at_index( p_md->p_subitems, 0, NULL ); |
|---|
| | 220 | libvlc_media_instance_set_media_descriptor( p_mlp->p_mi, p_submd, NULL ); |
|---|
| | 221 | libvlc_media_descriptor_release( p_submd ); |
|---|
| | 222 | } |
|---|
| | 223 | else |
|---|
| | 224 | libvlc_media_instance_set_media_descriptor( p_mlp->p_mi, p_md, NULL ); |
|---|
| 180 | 225 | // wait_playing_state(); /* If we want to be synchronous */ |
|---|
| 181 | 226 | install_media_instance_observer( p_mlp ); |
|---|
| … | … | |
| 202 | 247 | libvlc_media_list_player_t * p_mlp; |
|---|
| 203 | 248 | p_mlp = malloc(sizeof(libvlc_media_list_player_t)); |
|---|
| 204 | | p_mlp->i_current_playing_index = -1; |
|---|
| | 249 | p_mlp->current_playing_item_path = NULL; |
|---|
| 205 | 250 | p_mlp->p_mi = NULL; |
|---|
| 206 | 251 | p_mlp->p_mlist = NULL; |
|---|
| … | … | |
| 222 | 267 | void libvlc_media_list_player_release( libvlc_media_list_player_t * p_mlp ) |
|---|
| 223 | 268 | { |
|---|
| 224 | | libvlc_event_manager_release( p_mlp->p_event_manager ); |
|---|
| 225 | 269 | free(p_mlp); |
|---|
| 226 | 270 | } |
|---|
| … | … | |
| 260 | 304 | |
|---|
| 261 | 305 | if( libvlc_media_list_player_is_playing( p_mlp, p_e ) ) |
|---|
| 262 | | libvlc_media_list_player_stop( p_mlp, p_e ); |
|---|
| | 306 | { |
|---|
| | 307 | libvlc_media_instance_stop( p_mlp->p_mi, p_e ); |
|---|
| | 308 | /* Don't bother if there was an error. */ |
|---|
| | 309 | libvlc_exception_clear( p_e ); |
|---|
| | 310 | } |
|---|
| 263 | 311 | |
|---|
| 264 | 312 | if( p_mlp->p_mlist ) |
|---|
| … | … | |
| 281 | 329 | libvlc_exception_t * p_e ) |
|---|
| 282 | 330 | { |
|---|
| 283 | | if( p_mlp->i_current_playing_index < 0 ) |
|---|
| | 331 | if( !p_mlp->current_playing_item_path ) |
|---|
| 284 | 332 | { |
|---|
| 285 | 333 | libvlc_media_list_player_next( p_mlp, p_e ); |
|---|
| … | … | |
| 292 | 340 | /************************************************************************** |
|---|
| 293 | 341 | * Play item at index (Public) |
|---|
| 294 | | * |
|---|
| 295 | | * Playlist lock should be help |
|---|
| 296 | 342 | **************************************************************************/ |
|---|
| 297 | 343 | void libvlc_media_list_player_play_item_at_index( |
|---|
| … | … | |
| 300 | 346 | libvlc_exception_t * p_e ) |
|---|
| 301 | 347 | { |
|---|
| 302 | | media_list_player_set_next( p_mlp, i_index, p_e ); |
|---|
| | 348 | set_current_playing_item( p_mlp, libvlc_media_list_path_with_root_index(i_index), p_e ); |
|---|
| 303 | 349 | |
|---|
| 304 | 350 | if( libvlc_exception_raised( p_e ) ) |
|---|
| … | … | |
| 313 | 359 | } |
|---|
| 314 | 360 | |
|---|
| | 361 | /************************************************************************** |
|---|
| | 362 | * Play item (Public) |
|---|
| | 363 | **************************************************************************/ |
|---|
| | 364 | void libvlc_media_list_player_play_item( |
|---|
| | 365 | libvlc_media_list_player_t * p_mlp, |
|---|
| | 366 | libvlc_media_descriptor_t * p_md, |
|---|
| | 367 | libvlc_exception_t * p_e ) |
|---|
| | 368 | { |
|---|
| | 369 | libvlc_media_list_path_t path = libvlc_media_list_path_of_item( p_mlp->p_mlist, p_md ); |
|---|
| | 370 | if( !path ) |
|---|
| | 371 | { |
|---|
| | 372 | libvlc_exception_raise( p_e, "No such item in media list" ); |
|---|
| | 373 | return; |
|---|
| | 374 | } |
|---|
| | 375 | set_current_playing_item( p_mlp, path, p_e ); |
|---|
| | 376 | |
|---|
| | 377 | if( libvlc_exception_raised( p_e ) ) |
|---|
| | 378 | return; |
|---|
| | 379 | |
|---|
| | 380 | libvlc_media_instance_play( p_mlp->p_mi, p_e ); |
|---|
| | 381 | } |
|---|
| 315 | 382 | |
|---|
| 316 | 383 | /************************************************************************** |
|---|
| … | … | |
| 323 | 390 | |
|---|
| 324 | 391 | vlc_mutex_lock( &p_mlp->object_lock ); |
|---|
| 325 | | p_mlp->i_current_playing_index = -1; |
|---|
| | 392 | p_mlp->current_playing_item_path = NULL; |
|---|
| 326 | 393 | vlc_mutex_unlock( &p_mlp->object_lock ); |
|---|
| 327 | 394 | } |
|---|
| … | … | |
| 333 | 400 | libvlc_exception_t * p_e ) |
|---|
| 334 | 401 | { |
|---|
| 335 | | int index; |
|---|
| | 402 | libvlc_media_list_path_t path; |
|---|
| 336 | 403 | |
|---|
| 337 | 404 | libvlc_media_list_lock( p_mlp->p_mlist ); |
|---|
| 338 | 405 | |
|---|
| 339 | | index = get_next_index( p_mlp ); |
|---|
| 340 | | |
|---|
| 341 | | if( index < 0 ) |
|---|
| | 406 | path = get_next_path( p_mlp ); |
|---|
| | 407 | |
|---|
| | 408 | if( !path ) |
|---|
| 342 | 409 | { |
|---|
| 343 | 410 | libvlc_media_list_unlock( p_mlp->p_mlist ); |
|---|
| … | … | |
| 347 | 414 | } |
|---|
| 348 | 415 | |
|---|
| 349 | | media_list_player_set_next( p_mlp, index, p_e ); |
|---|
| | 416 | set_current_playing_item( p_mlp, path, p_e ); |
|---|
| 350 | 417 | |
|---|
| 351 | 418 | libvlc_media_instance_play( p_mlp->p_mi, p_e ); |
|---|
| … | … | |
| 358 | 425 | libvlc_event_send( p_mlp->p_event_manager, &event); |
|---|
| 359 | 426 | } |
|---|
| 360 | | |
|---|