]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/input_manager.cpp
Trailing ;
[vlc] / modules / gui / qt4 / input_manager.cpp
index dc3066ec3cc84c2aba6a9790c2a2420d38111877..2dc83e7fc057e506e5b73176a6dcf4834f3b45b5 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
-#include "qt4.hpp"
 #include "input_manager.hpp"
-#include "dialogs_provider.hpp"
+
+#include <QApplication>
+
+#include <assert.h>
 
 static int ItemChanged( vlc_object_t *, const char *,
                         vlc_value_t, vlc_value_t, void * );
@@ -60,7 +63,7 @@ InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
     b_video      = false;
     timeA        = 0;
     timeB        = 0;
-
+    f_cache      = -1.; /* impossible initial value, different from all */
 }
 
 InputManager::~InputManager()
@@ -77,9 +80,10 @@ void InputManager::setInput( input_thread_t *_p_input )
     p_input = _p_input;
     if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
     {
+        msg_Dbg( p_intf, "IM: Setting an input" );
         vlc_object_hold( p_input );
         emit statusChanged( PLAYING_S );
-        UpdateMeta();
+        UpdateName();
         UpdateArt();
         UpdateTeletext();
         UpdateNavigation();
@@ -100,38 +104,37 @@ void InputManager::setInput( input_thread_t *_p_input )
    p_input is released once here */
 void InputManager::delInput()
 {
-    if( p_input )
-    {
-        delCallbacks();
-        i_old_playing_status = END_S;
-        i_input_id = 0;
-        oldName    = "";
-        artUrl     = "";
-        b_video    = false;
-        timeA      = 0;
-        timeB      = 0;
-        emit positionUpdated( -1.0, 0 ,0 );
-        emit statusChanged( END_S );
-        emit nameChanged( "" );
-        emit artChanged( NULL );
-        emit rateChanged( INPUT_RATE_DEFAULT );
-        emit voutChanged( false );
-        vlc_object_release( p_input );
-        p_input = NULL;
-        UpdateTeletext();
-    }
-}
+    if( !p_input ) return;
+    msg_Dbg( p_intf, "IM: Deleting the input" );
 
-/* Add the callbacks on Input. Self explanatory */
-void InputManager::addCallbacks()
-{
-    var_AddCallback( p_input, "intf-event", InputEvent, this );
-}
+    delCallbacks();
+    i_old_playing_status = END_S;
+    i_input_id           = 0;
+    oldName              = "";
+    artUrl               = "";
+    b_video              = false;
+    timeA                = 0;
+    timeB                = 0;
+
+    vlc_object_release( p_input );
+    p_input = NULL;
 
-/* Delete the callbacks on Input. Self explanatory */
-void InputManager::delCallbacks()
-{
-    var_DelCallback( p_input, "intf-event", InputEvent, this );
+    emit positionUpdated( -1.0, 0 ,0 );
+    emit rateChanged( INPUT_RATE_DEFAULT ); /* TODO: Do we want this ? */
+    emit nameChanged( "" );
+    emit chapterChanged( 0 );
+    emit titleChanged( 0 );
+    emit statusChanged( END_S );
+
+    emit teletextPossible( false );
+    emit AtoBchanged( false, false );
+    emit voutChanged( false );
+    emit voutListChanged( NULL, 0 );
+
+    /* Reset all InfoPanels but stats */
+    emit artChanged( NULL );
+    emit infoChanged( NULL );
+    emit metaChanged( NULL );
 }
 
 /* Convert the event from the callbacks in actions */
@@ -140,7 +143,7 @@ void InputManager::customEvent( QEvent *event )
     int i_type = event->type();
     IMEvent *ple = static_cast<IMEvent *>(event);
 
-    if ( i_type != PositionUpdate_Type &&
+    assert( !( i_type != PositionUpdate_Type &&
          i_type != ItemChanged_Type &&
          i_type != ItemRateChanged_Type &&
          i_type != ItemTitleChanged_Type &&
@@ -149,11 +152,20 @@ void InputManager::customEvent( QEvent *event )
          i_type != ItemStateChanged_Type &&
          i_type != StatisticsUpdate_Type &&
          i_type != InterfaceVoutUpdate_Type &&
-         i_type != MetaChanged_Type )
-        return;
+         i_type != MetaChanged_Type &&
+         i_type != NameChanged_Type &&
+         i_type != InfoChanged_Type &&
+         i_type != SynchroChanged_Type &&
+         i_type != CachingEvent_Type &&
+         i_type != BookmarksChanged_Type &&
+         i_type != InterfaceAoutUpdate_Type &&
+         i_type != RecordingEvent_Type ) );
 
     if( !hasInput() ) return;
 
+    if( i_type == CachingEvent_Type )
+        UpdateCaching();
+
     if( ( i_type != PositionUpdate_Type  &&
           i_type != ItemRateChanged_Type &&
           i_type != ItemEsChanged_Type &&
@@ -161,14 +173,22 @@ void InputManager::customEvent( QEvent *event )
           i_type != ItemStateChanged_Type &&
           i_type != StatisticsUpdate_Type &&
           i_type != InterfaceVoutUpdate_Type &&
-          i_type != MetaChanged_Type
+          i_type != MetaChanged_Type &&
+          i_type != NameChanged_Type &&
+          i_type != InfoChanged_Type &&
+          i_type != SynchroChanged_Type &&
+          i_type != BookmarksChanged_Type &&
+          i_type != InterfaceAoutUpdate_Type &&
+          i_type != RecordingEvent_Type
         )
         && ( i_input_id != ple->i_id ) )
         return;
 
+#ifndef NDEBUG
     if( i_type != PositionUpdate_Type &&
         i_type != StatisticsUpdate_Type )
         msg_Dbg( p_intf, "New Event: type %i", i_type );
+#endif
 
     /* Actions */
     switch( i_type )
@@ -180,29 +200,37 @@ void InputManager::customEvent( QEvent *event )
         UpdateStats();
         break;
     case ItemChanged_Type:
-        UpdateMeta();
         UpdateStatus();
-        UpdateArt();
-        break;
-    case MetaChanged_Type:
-        UpdateMeta();
+        // UpdateName();
         UpdateArt();
         break;
     case ItemStateChanged_Type:
+        // TODO: Fusion with above state
         UpdateStatus();
-        UpdateNavigation();
+        // UpdateName();
+        // UpdateNavigation(); This shouldn't be useful now
+        // UpdateTeletext(); Same
+        break;
+    case NameChanged_Type:
+        UpdateName();
+        break;
+    case MetaChanged_Type:
         UpdateMeta();
-        UpdateTeletext();
+        UpdateName(); /* Needed for NowPlaying */
+        UpdateArt(); /* Art is part of meta in the core */
+        break;
+    case InfoChanged_Type:
+        UpdateInfo();
         break;
     case ItemTitleChanged_Type:
         UpdateNavigation();
-        UpdateMeta();
+        UpdateName(); /* Display the name of the Chapter, if exists */
         break;
     case ItemRateChanged_Type:
         UpdateRate();
         break;
     case ItemEsChanged_Type:
-        UpdateSPU();
+        // We don't do anything. Why ?
         break;
     case ItemTeletextChanged_Type:
         UpdateTeletext();
@@ -210,16 +238,134 @@ void InputManager::customEvent( QEvent *event )
     case InterfaceVoutUpdate_Type:
         UpdateVout();
         break;
+    case SynchroChanged_Type:
+        emit synchroChanged();
+        break;
+    case CachingEvent_Type:
+        UpdateCaching();
+        break;
+    case BookmarksChanged_Type:
+        emit bookmarksChanged();
+        break;
+    case InterfaceAoutUpdate_Type:
+        UpdateAout();
+        break;
+    case RecordingEvent_Type:
+        UpdateRecord();
+        break;
     default:
         msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
     }
 }
 
-void InputManager::UpdateStats()
+/* Add the callbacks on Input. Self explanatory */
+inline void InputManager::addCallbacks()
 {
-    emit statisticsUpdated( input_GetItem( p_input ) );
+    var_AddCallback( p_input, "intf-event", InputEvent, this );
+}
+
+/* Delete the callbacks on Input. Self explanatory */
+inline void InputManager::delCallbacks()
+{
+    var_DelCallback( p_input, "intf-event", InputEvent, this );
+}
+
+/* Static callbacks for IM */
+static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
+                        vlc_value_t oldval, vlc_value_t newval, void *param )
+{
+    InputManager *im = (InputManager*)param;
+
+    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
+    QApplication::postEvent( im, event );
+    return VLC_SUCCESS;
 }
 
+static int InputEvent( vlc_object_t *p_this, const char *,
+                       vlc_value_t, vlc_value_t newval, void *param )
+{
+    InputManager *im = (InputManager*)param;
+    IMEvent *event;
+
+    switch( newval.i_int )
+    {
+    case INPUT_EVENT_STATE:
+        event = new IMEvent( ItemStateChanged_Type, 0 );
+        break;
+    case INPUT_EVENT_RATE:
+        event = new IMEvent( ItemRateChanged_Type, 0 );
+        break;
+    case INPUT_EVENT_TIMES:
+        event = new IMEvent( PositionUpdate_Type, 0 );
+        break;
+
+    case INPUT_EVENT_TITLE:
+    case INPUT_EVENT_CHAPTER:
+        event = new IMEvent( ItemTitleChanged_Type, 0 );
+        break;
+
+    case INPUT_EVENT_ES:
+        event = new IMEvent( ItemEsChanged_Type, 0 );
+        break;
+    case INPUT_EVENT_TELETEXT:
+        event = new IMEvent( ItemTeletextChanged_Type, 0 );
+        break;
+
+    case INPUT_EVENT_STATISTICS:
+        event = new IMEvent( StatisticsUpdate_Type, 0 );
+        break;
+
+    case INPUT_EVENT_VOUT:
+        event = new IMEvent( InterfaceVoutUpdate_Type, 0 );
+        break;
+    case INPUT_EVENT_AOUT:
+        event = new IMEvent( InterfaceAoutUpdate_Type, 0 );
+        break;
+
+    case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
+        event = new IMEvent( MetaChanged_Type, 0 );
+        break;
+    case INPUT_EVENT_ITEM_INFO: /* Codec Info */
+        event = new IMEvent( InfoChanged_Type, 0 );
+        break;
+    case INPUT_EVENT_ITEM_NAME:
+        event = new IMEvent( NameChanged_Type, 0 );
+        break;
+
+    case INPUT_EVENT_AUDIO_DELAY:
+    case INPUT_EVENT_SUBTITLE_DELAY:
+        event = new IMEvent( SynchroChanged_Type, 0 );
+        break;
+
+    case INPUT_EVENT_CACHE:
+        event = new IMEvent( CachingEvent_Type, 0 );
+        break;
+
+    case INPUT_EVENT_BOOKMARK:
+        event = new IMEvent( BookmarksChanged_Type, 0 );
+        break;
+
+    case INPUT_EVENT_RECORD:
+        event = new IMEvent( RecordingEvent_Type, 0 );
+        break;
+
+    case INPUT_EVENT_PROGRAM:
+        /* This is for PID changes */
+        /* event = new IMEvent( ProgramChanged_Type, 0 );
+        break; */
+    case INPUT_EVENT_SIGNAL:
+        /* This is for capture-card signals */
+        /* event = new IMEvent( SignalChanged_Type, 0 );
+        break; */
+    default:
+        event = NULL;
+        break;
+    }
+
+    if( event )
+        QApplication::postEvent( im, event );
+    return VLC_SUCCESS;
+}
 void InputManager::UpdatePosition()
 {
     /* Update position */
@@ -242,10 +388,12 @@ void InputManager::UpdateNavigation()
     if( val.i_int > 0 )
     {
         emit titleChanged( true );
+        msg_Dbg( p_intf, "Title %i", val.i_int );
         /* p_input != NULL since val.i_int != 0 */
         val.i_int = 0;
         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
         emit chapterChanged( (val.i_int > 0) );
+        msg_Dbg( p_intf, "Chapter: %i", val.i_int );
     }
     else
         emit titleChanged( false );
@@ -275,7 +423,7 @@ void InputManager::UpdateRate()
     }
 }
 
-void InputManager::UpdateMeta()
+void InputManager::UpdateName()
 {
     /* Update text, name and nowplaying */
     QString text;
@@ -322,7 +470,7 @@ void InputManager::UpdateMeta()
     if( oldName != text )
     {
         emit nameChanged( text );
-        oldName=text;
+        oldName = text;
     }
 }
 
@@ -337,11 +485,6 @@ bool InputManager::hasAudio()
     return false;
 }
 
-void InputManager::UpdateSPU()
-{
-    UpdateTeletext();
-}
-
 void InputManager::UpdateTeletext()
 {
     if( hasInput() )
@@ -354,22 +497,104 @@ void InputManager::UpdateVout()
 {
     if( hasInput() )
     {
-        bool b_old_video = b_video;
+        /* Get current vout lists from input */
+        int i_vout;
+        vout_thread_t **pp_vout;
+        if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
+        {
+            i_vout = 0;
+            pp_vout = NULL;
+        }
+
+        /* */
+        emit voutListChanged( pp_vout, i_vout );
 
-        vlc_object_t *p_vout = (vlc_object_t*)vlc_object_find( p_input,
-                                         VLC_OBJECT_VOUT, FIND_CHILD );
-        b_video = p_vout != NULL;
-        if( p_vout )
-            vlc_object_release( p_vout );
+        /* */
+        bool b_old_video = b_video;
+        b_video = i_vout > 0;
         if( !!b_old_video != !!b_video )
             emit voutChanged( b_video );
+
+        /* Release the vout list */
+        for( int i = 0; i < i_vout; i++ )
+            vlc_object_release( (vlc_object_t*)pp_vout[i] );
+        free( pp_vout );
+    }
+}
+void InputManager::UpdateAout()
+{
+    if( hasInput() )
+    {
+        /* TODO */
+    }
+}
+void InputManager::UpdateCaching()
+{
+    if(!hasInput()) return;
+
+    float f_newCache = var_GetFloat ( p_input, "cache" );
+    if( f_newCache != f_cache )
+    {
+        f_cache = f_newCache;
+        /* Update rate */
+        emit cachingChanged( f_cache );
+    }
+}
+
+void InputManager::requestArtUpdate()
+{
+    if( hasInput() )
+    {
+        playlist_t *p_playlist = pl_Hold( p_intf );
+        playlist_AskForArtEnqueue( p_playlist, input_GetItem( p_input ), pl_Unlocked );
+        pl_Release( p_intf );
+    }
+    else
+    {
+        /* No input will signal the cover art to update,
+         * let's do it ourself */
+        UpdateArt();
     }
 }
 
 void InputManager::UpdateArt()
 {
+    QString url;
+
+    if( hasInput() )
+    {
+        char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) );
+        url = psz_art;
+        free( psz_art );
+    }
+    url = url.replace( "file://", QString("" ) );
+    /* Taglib seems to define a attachment://, It won't work yet */
+    url = url.replace( "attachment://", QString("" ) );
     /* Update Art meta */
-    emit artChanged( input_GetItem( p_input ) );
+    emit artChanged( url );
+}
+
+inline void InputManager::UpdateStats()
+{
+    emit statisticsUpdated( input_GetItem( p_input ) );
+}
+
+inline void InputManager::UpdateMeta()
+{
+    emit metaChanged( input_GetItem( p_input ) );
+}
+
+inline void InputManager::UpdateInfo()
+{
+    emit infoChanged( input_GetItem( p_input ) );
+}
+
+void InputManager::UpdateRecord()
+{
+    if( hasInput() )
+    {
+        emit recordingStateChanged( var_GetBool( p_input, "record" ) );
+    }
 }
 
 /* User update of the slider */
@@ -614,18 +839,19 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
     /* emit check if playlist has allready started playing */
     vlc_value_t val;
     var_Change( THEPL, "playlist-current", VLC_VAR_CHOICESCOUNT, &val, NULL );
-    IMEvent *event = new IMEvent( ItemChanged_Type, val.i_int);
-    QApplication::postEvent( this, static_cast<QEvent*>(event) );
 
+    IMEvent *event = new IMEvent( ItemChanged_Type, val.i_int);
+    customEvent( event );
+    delete event;
 }
 
 MainInputManager::~MainInputManager()
 {
     if( p_input )
     {
+       emit inputChanged( NULL );
        var_DelCallback( p_input, "state", PLItemChanged, this );
        vlc_object_release( p_input );
-       emit inputChanged( NULL );
     }
 
     var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
@@ -636,6 +862,16 @@ MainInputManager::~MainInputManager()
     var_DelCallback( THEPL, "playlist-current", PLItemChanged, this );
 }
 
+vout_thread_t* MainInputManager::getVout()
+{
+    return p_input ? input_GetVout( p_input ) : NULL;
+}
+
+aout_instance_t * MainInputManager::getAout()
+{
+    return p_input ? input_GetAout( p_input ) : NULL;
+}
+
 void MainInputManager::customEvent( QEvent *event )
 {
     int type = event->type();
@@ -655,9 +891,9 @@ void MainInputManager::customEvent( QEvent *event )
         vlc_mutex_lock( &p_intf->change_lock );
         if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
         {
+            emit inputChanged( NULL );
             var_DelCallback( p_input, "state", PLItemChanged, this );
             vlc_object_release( p_input );
-            emit inputChanged( NULL );
             p_input = NULL;
             vlc_mutex_unlock( &p_intf->change_lock );
             return;
@@ -713,88 +949,14 @@ void MainInputManager::togglePlayPause()
         getIM()->togglePlayPause();
 }
 
-/* Static callbacks */
-
-/* IM */
-static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
-                        vlc_value_t oldval, vlc_value_t newval, void *param )
-{
-    InputManager *im = (InputManager*)param;
-
-    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
-    QApplication::postEvent( im, static_cast<QEvent*>(event) );
-    return VLC_SUCCESS;
-}
-
-static int InputEvent( vlc_object_t *p_this, const char *,
-                       vlc_value_t, vlc_value_t newval, void *param )
-{
-    InputManager *im = (InputManager*)param;
-    IMEvent *event;
-
-    switch( newval.i_int )
-    {
-    case INPUT_EVENT_STATE:
-        event = new IMEvent( ItemStateChanged_Type, 0 );
-        break;
-    case INPUT_EVENT_RATE:
-        event = new IMEvent( ItemRateChanged_Type, 0 );
-        break;
-    case INPUT_EVENT_TIMES:
-        event = new IMEvent( PositionUpdate_Type, 0 );
-        break;
-
-    case INPUT_EVENT_TITLE:
-    case INPUT_EVENT_CHAPTER: /* TODO is that correct ? */
-        event = new IMEvent( ItemTitleChanged_Type, 0 );
-        break;
-
-    case INPUT_EVENT_ES:
-        event = new IMEvent( ItemEsChanged_Type, 0 );
-        break;
-    case INPUT_EVENT_TELETEXT:
-        event = new IMEvent( ItemTeletextChanged_Type, 0 );
-        break;
-
-    case INPUT_EVENT_VOUT:
-        event = new IMEvent( InterfaceVoutUpdate_Type, 0 );
-        break;
-
-    case INPUT_EVENT_STATISTICS:
-        event = new IMEvent( StatisticsUpdate_Type, 0 );
-        break;
-
-    case INPUT_EVENT_ITEM_META:
-    case INPUT_EVENT_ITEM_INFO:
-    case INPUT_EVENT_ITEM_NAME:
-        event = new IMEvent( MetaChanged_Type, 0 );
-        break;
-
-    case INPUT_EVENT_PROGRAM:
-    case INPUT_EVENT_RECORD:
-    case INPUT_EVENT_SIGNAL:
-    case INPUT_EVENT_AUDIO_DELAY:
-    case INPUT_EVENT_SUBTITLE_DELAY:
-    case INPUT_EVENT_BOOKMARK:
-    case INPUT_EVENT_CACHE:
-    default:
-        event = NULL;
-        break;
-    }
-
-    if( event )
-        QApplication::postEvent( im, static_cast<QEvent*>(event) );
-    return VLC_SUCCESS;
-}
-
-/* MIM */
+/* Static callbacks for MIM */
 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *param )
 {
     MainInputManager *mim = (MainInputManager*)param;
 
     IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
-    QApplication::postEvent( mim, static_cast<QEvent*>(event) );
+    QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
 
@@ -804,8 +966,7 @@ static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
     MainInputManager *mim = (MainInputManager*)param;
 
     IMEvent *event = new IMEvent( VolumeChanged_Type, newval.i_int );
-    QApplication::postEvent( mim, static_cast<QEvent*>(event) );
+    QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
 
-