control.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:7k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * control.c : Handle control of the playlist & running through it
  3.  *****************************************************************************
  4.  * Copyright (C) 1999-2004 the VideoLAN team
  5.  * $Id: 4aed8889a5f90ca2f4cf4374e73a0cb462eab6c0 $
  6.  *
  7.  * Authors: Samuel Hocevar <sam@zoy.org>
  8.  *          Clément Stenac <zorglub@videolan.org>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23.  *****************************************************************************/
  24. #ifdef HAVE_CONFIG_H
  25. # include "config.h"
  26. #endif
  27. #include <vlc_common.h>
  28. #include "vlc_playlist.h"
  29. #include "playlist_internal.h"
  30. #include <assert.h>
  31. /*****************************************************************************
  32.  * Local prototypes
  33.  *****************************************************************************/
  34. static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args );
  35. /*****************************************************************************
  36.  * Playlist control
  37.  *****************************************************************************/
  38. playlist_t *__pl_Hold( vlc_object_t *p_this )
  39. {
  40.     playlist_t *pl;
  41.     barrier();
  42.     pl = libvlc_priv (p_this->p_libvlc)->p_playlist;
  43.     assert( VLC_OBJECT(pl) != p_this /* This does not make sense to hold the playlist
  44.     using pl_Hold. use vlc_object_hold in this case */ );
  45.     if (pl)
  46.         vlc_object_hold (pl);
  47.     return pl;
  48. }
  49. void __pl_Release( vlc_object_t *p_this )
  50. {
  51.     playlist_t *pl = libvlc_priv (p_this->p_libvlc)->p_playlist;
  52.     assert( pl != NULL );
  53.     /* The rule is that pl_Release() should act on
  54.        the same object than pl_Hold() */
  55.     assert( VLC_OBJECT(pl) != p_this);
  56.     vlc_object_release( pl );
  57. }
  58. void playlist_Lock( playlist_t *pl )
  59. {
  60.     vlc_mutex_lock( &pl_priv(pl)->lock );
  61. }
  62. void playlist_Unlock( playlist_t *pl )
  63. {
  64.     vlc_mutex_unlock( &pl_priv(pl)->lock );
  65. }
  66. void playlist_AssertLocked( playlist_t *pl )
  67. {
  68.     vlc_assert_locked( &pl_priv(pl)->lock );
  69. }
  70. int playlist_Control( playlist_t * p_playlist, int i_query,
  71.                       bool b_locked, ... )
  72. {
  73.     va_list args;
  74.     int i_result;
  75.     PL_LOCK_IF( !b_locked );
  76.     va_start( args, b_locked );
  77.     i_result = PlaylistVAControl( p_playlist, i_query, args );
  78.     va_end( args );
  79.     PL_UNLOCK_IF( !b_locked );
  80.     return i_result;
  81. }
  82. static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args )
  83. {
  84.     playlist_item_t *p_item, *p_node;
  85.     PL_ASSERT_LOCKED;
  86.     if( !vlc_object_alive( p_playlist ) )
  87.         return VLC_EGENERIC;
  88.     if( playlist_IsEmpty( p_playlist ) && i_query != PLAYLIST_STOP )
  89.         return VLC_EGENERIC;
  90.     switch( i_query )
  91.     {
  92.     case PLAYLIST_STOP:
  93.         pl_priv(p_playlist)->request.i_status = PLAYLIST_STOPPED;
  94.         pl_priv(p_playlist)->request.b_request = true;
  95.         pl_priv(p_playlist)->request.p_item = NULL;
  96.         break;
  97.     // Node can be null, it will keep the same. Use with care ...
  98.     // Item null = take the first child of node
  99.     case PLAYLIST_VIEWPLAY:
  100.         p_node = (playlist_item_t *)va_arg( args, playlist_item_t * );
  101.         p_item = (playlist_item_t *)va_arg( args, playlist_item_t * );
  102.         if ( p_node == NULL )
  103.         {
  104.             p_node = get_current_status_node( p_playlist );
  105.             assert( p_node );
  106.         }
  107.         pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
  108.         pl_priv(p_playlist)->request.i_skip = 0;
  109.         pl_priv(p_playlist)->request.b_request = true;
  110.         pl_priv(p_playlist)->request.p_node = p_node;
  111.         pl_priv(p_playlist)->request.p_item = p_item;
  112.         if( p_item && var_GetBool( p_playlist, "random" ) )
  113.             pl_priv(p_playlist)->b_reset_currently_playing = true;
  114.         break;
  115.     case PLAYLIST_PLAY:
  116.         if( pl_priv(p_playlist)->p_input )
  117.         {
  118.             var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
  119.             break;
  120.         }
  121.         else
  122.         {
  123.             pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
  124.             pl_priv(p_playlist)->request.b_request = true;
  125.             pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
  126.             pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
  127.             pl_priv(p_playlist)->request.i_skip = 0;
  128.         }
  129.         break;
  130.     case PLAYLIST_PAUSE:
  131.         if( pl_priv(p_playlist)->p_input &&
  132.             var_GetInteger( pl_priv(p_playlist)->p_input, "state" ) == PAUSE_S )
  133.         {
  134.             pl_priv(p_playlist)->status.i_status = PLAYLIST_RUNNING;
  135.             if( pl_priv(p_playlist)->p_input )
  136.             {
  137.                 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
  138.             }
  139.         }
  140.         else
  141.         {
  142.             pl_priv(p_playlist)->status.i_status = PLAYLIST_PAUSED;
  143.             if( pl_priv(p_playlist)->p_input )
  144.             {
  145.                 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
  146.             }
  147.         }
  148.         break;
  149.     case PLAYLIST_SKIP:
  150.         pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
  151.         pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
  152.         pl_priv(p_playlist)->request.i_skip = (int) va_arg( args, int );
  153.         /* if already running, keep running */
  154.         if( pl_priv(p_playlist)->status.i_status != PLAYLIST_STOPPED )
  155.             pl_priv(p_playlist)->request.i_status = pl_priv(p_playlist)->status.i_status;
  156.         pl_priv(p_playlist)->request.b_request = true;
  157.         break;
  158.     default:
  159.         msg_Err( p_playlist, "unknown playlist query" );
  160.         return VLC_EBADVAR;
  161.     }
  162.     vlc_cond_signal( &pl_priv(p_playlist)->signal );
  163.     return VLC_SUCCESS;
  164. }
  165. /*****************************************************************************
  166.  * Preparse control
  167.  *****************************************************************************/
  168. /** Enqueue an item for preparsing */
  169. int playlist_PreparseEnqueue( playlist_t *p_playlist,
  170.                               input_item_t *p_item, bool b_locked )
  171. {
  172.     playlist_private_t *p_sys = pl_priv(p_playlist);
  173.     PL_LOCK_IF( !b_locked );
  174.     if( p_sys->p_preparser )
  175.         playlist_preparser_Push( p_sys->p_preparser, p_item );
  176.     PL_UNLOCK_IF( !b_locked );
  177.     return VLC_SUCCESS;
  178. }
  179. int playlist_AskForArtEnqueue( playlist_t *p_playlist,
  180.                                input_item_t *p_item, bool b_locked )
  181. {
  182.     playlist_private_t *p_sys = pl_priv(p_playlist);
  183.     PL_LOCK_IF( !b_locked );
  184.     if( p_sys->p_fetcher )
  185.         playlist_fetcher_Push( p_sys->p_fetcher, p_item );
  186.     PL_UNLOCK_IF( !b_locked );
  187.     return VLC_SUCCESS;
  188. }