]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/input_manager.cpp
Create a function to free the memory allocated when calling
[vlc] / modules / gui / qt4 / input_manager.cpp
index adb58f13691823bff889d209bc8b6d0e6829d19b..82bdb04729e4d0b6f05979f5ee385b582b1cf51d 100644 (file)
@@ -62,7 +62,7 @@ InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
     artUrl       = "";
     p_input      = NULL;
     i_rate       = 0;
-    i_input_id   = 0;
+    p_item       = NULL;
     b_video      = false;
     timeA        = 0;
     timeB        = 0;
@@ -92,12 +92,12 @@ void InputManager::setInput( input_thread_t *_p_input )
         UpdateNavigation();
         UpdateVout();
         addCallbacks();
-        i_input_id = input_GetItem( p_input )->i_id;
+        p_item = input_GetItem( p_input );
     }
     else
     {
         p_input = NULL;
-        i_input_id = 0;
+        p_item = NULL;
         emit rateChanged( INPUT_RATE_DEFAULT );
     }
 }
@@ -112,7 +112,7 @@ void InputManager::delInput()
 
     delCallbacks();
     i_old_playing_status = END_S;
-    i_input_id           = 0;
+    p_item               = NULL;
     oldName              = "";
     artUrl               = "";
     b_video              = false;
@@ -137,10 +137,10 @@ void InputManager::delInput()
     /* Reset all InfoPanels but stats */
     emit artChanged( NULL );
     emit infoChanged( NULL );
-    emit metaChanged( (input_item_t *)NULL );
-#if 0
+    emit currentMetaChanged( (input_item_t *)NULL );
+
     emit encryptionChanged( false );
-#endif
+    emit recordingStateChanged( false );
 }
 
 /* Convert the event from the callbacks in actions */
@@ -170,14 +170,14 @@ void InputManager::customEvent( QEvent *event )
         break;
     case ItemChanged_Type:
         /* Ignore ItemChanged_Type event that does not apply to our input */
-        if( i_input_id == ple->i_id )
+        if( p_item == ple->p_item )
         {
             UpdateStatus();
             // UpdateName();
             UpdateArt();
             /* Update duration of file */
         }
-        UpdateMeta( ple->i_id );
+        UpdateMeta( ple->p_item->i_id );
         break;
     case ItemStateChanged_Type:
         // TODO: Fusion with above state
@@ -229,6 +229,9 @@ void InputManager::customEvent( QEvent *event )
     case RecordingEvent_Type:
         UpdateRecord();
         break;
+    case ProgramChanged_Type:
+        UpdateProgramEvent();
+        break;
     default:
         msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
         assert(0);
@@ -252,8 +255,9 @@ 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;
+    input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
 
-    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
+    IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
     QApplication::postEvent( im, event );
     return VLC_SUCCESS;
 }
@@ -267,72 +271,74 @@ static int InputEvent( vlc_object_t *p_this, const char *,
     switch( newval.i_int )
     {
     case INPUT_EVENT_STATE:
-        event = new IMEvent( ItemStateChanged_Type, 0 );
+        event = new IMEvent( ItemStateChanged_Type );
         break;
     case INPUT_EVENT_RATE:
-        event = new IMEvent( ItemRateChanged_Type, 0 );
+        event = new IMEvent( ItemRateChanged_Type );
         break;
-    case INPUT_EVENT_TIMES:
-        event = new IMEvent( PositionUpdate_Type, 0 );
+    case INPUT_EVENT_POSITION:
+    //case INPUT_EVENT_LENGTH:
+        event = new IMEvent( PositionUpdate_Type );
         break;
 
     case INPUT_EVENT_TITLE:
     case INPUT_EVENT_CHAPTER:
-        event = new IMEvent( ItemTitleChanged_Type, 0 );
+        event = new IMEvent( ItemTitleChanged_Type );
         break;
 
     case INPUT_EVENT_ES:
-        event = new IMEvent( ItemEsChanged_Type, 0 );
+        event = new IMEvent( ItemEsChanged_Type );
         break;
     case INPUT_EVENT_TELETEXT:
-        event = new IMEvent( ItemTeletextChanged_Type, 0 );
+        event = new IMEvent( ItemTeletextChanged_Type );
         break;
 
     case INPUT_EVENT_STATISTICS:
-        event = new IMEvent( StatisticsUpdate_Type, 0 );
+        event = new IMEvent( StatisticsUpdate_Type );
         break;
 
     case INPUT_EVENT_VOUT:
-        event = new IMEvent( InterfaceVoutUpdate_Type, 0 );
+        event = new IMEvent( InterfaceVoutUpdate_Type );
         break;
     case INPUT_EVENT_AOUT:
-        event = new IMEvent( InterfaceAoutUpdate_Type, 0 );
+        event = new IMEvent( InterfaceAoutUpdate_Type );
         break;
 
     case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
-        event = new IMEvent( MetaChanged_Type, 0 );
+        event = new IMEvent( MetaChanged_Type );
         break;
     case INPUT_EVENT_ITEM_INFO: /* Codec Info */
-        event = new IMEvent( InfoChanged_Type, 0 );
+        event = new IMEvent( InfoChanged_Type );
         break;
     case INPUT_EVENT_ITEM_NAME:
-        event = new IMEvent( NameChanged_Type, 0 );
+        event = new IMEvent( NameChanged_Type );
         break;
 
     case INPUT_EVENT_AUDIO_DELAY:
     case INPUT_EVENT_SUBTITLE_DELAY:
-        event = new IMEvent( SynchroChanged_Type, 0 );
+        event = new IMEvent( SynchroChanged_Type );
         break;
 
     case INPUT_EVENT_CACHE:
-        event = new IMEvent( CachingEvent_Type, 0 );
+        event = new IMEvent( CachingEvent_Type );
         break;
 
     case INPUT_EVENT_BOOKMARK:
-        event = new IMEvent( BookmarksChanged_Type, 0 );
+        event = new IMEvent( BookmarksChanged_Type );
         break;
 
     case INPUT_EVENT_RECORD:
-        event = new IMEvent( RecordingEvent_Type, 0 );
+        event = new IMEvent( RecordingEvent_Type );
         break;
 
     case INPUT_EVENT_PROGRAM:
         /* This is for PID changes */
-        /* event = new IMEvent( ProgramChanged_Type, 0 );
-        break; */
+        event = new IMEvent( ProgramChanged_Type );
+        break;
+
     case INPUT_EVENT_SIGNAL:
         /* This is for capture-card signals */
-        /* event = new IMEvent( SignalChanged_Type, 0 );
+        /* event = new IMEvent( SignalChanged_Type );
         break; */
     default:
         event = NULL;
@@ -343,14 +349,14 @@ static int InputEvent( vlc_object_t *p_this, const char *,
         QApplication::postEvent( im, event );
     return VLC_SUCCESS;
 }
+
 static int VbiEvent( vlc_object_t *, const char *,
                      vlc_value_t, vlc_value_t, void *param )
 {
     InputManager *im = (InputManager*)param;
-    IMEvent *event = new IMEvent( ItemTeletextChanged_Type, 0 );
+    IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
 
-    if( event )
-        QApplication::postEvent( im, event );
+    QApplication::postEvent( im, event );
     return VLC_SUCCESS;
 }
 
@@ -390,12 +396,11 @@ void InputManager::UpdateNavigation()
 void InputManager::UpdateStatus()
 {
     /* Update playing status */
-    vlc_value_t val; val.i_int = 0;
-    var_Get( p_input, "state", &val );
-    if( i_old_playing_status != val.i_int )
+    int state = var_GetInteger( p_input, "state" );
+    if( i_old_playing_status != state )
     {
-        i_old_playing_status = val.i_int;
-        emit statusChanged( val.i_int );
+        i_old_playing_status = state;
+        emit statusChanged( state );
     }
 }
 
@@ -417,12 +422,7 @@ void InputManager::UpdateName()
     QString text;
 
     /* Try to get the Title, then the Name */
-    char *psz_name = input_item_GetTitle( input_GetItem( p_input ) );
-    if( EMPTY_STR( psz_name ) )
-    {
-        free( psz_name );
-        psz_name = input_item_GetName( input_GetItem( p_input ) );
-    }
+    char *psz_name = input_item_GetTitleFbName( input_GetItem( p_input ) );
 
     /* Try to get the nowplaying */
     char *psz_nowplaying =
@@ -590,7 +590,7 @@ void InputManager::UpdateArt()
     if( hasInput() )
     {
         char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) );
-        url = psz_art;
+        url = qfu( psz_art );
         free( psz_art );
     }
     url = url.replace( "file://", QString("" ) );
@@ -612,7 +612,7 @@ inline void InputManager::UpdateMeta( int id )
 
 inline void InputManager::UpdateMeta()
 {
-    emit metaChanged( input_GetItem( p_input ) );
+    emit currentMetaChanged( input_GetItem( p_input ) );
 }
 
 inline void InputManager::UpdateInfo()
@@ -628,6 +628,15 @@ void InputManager::UpdateRecord()
     }
 }
 
+void InputManager::UpdateProgramEvent()
+{
+    if( hasInput() )
+    {
+        bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
+        emit encryptionChanged( b_scrambled );
+    }
+}
+
 /* User update of the slider */
 void InputManager::sliderUpdate( float new_pos )
 {
@@ -638,13 +647,12 @@ void InputManager::sliderUpdate( float new_pos )
 /* User togglePlayPause */
 void InputManager::togglePlayPause()
 {
-    vlc_value_t state;
     if( hasInput() )
     {
-        var_Get( p_input, "state", &state );
-        state.i_int = ( state.i_int != PLAYING_S ) ? PLAYING_S : PAUSE_S;
-        var_Set( p_input, "state", state );
-        emit statusChanged( state.i_int );
+        int state = var_GetInteger( p_input, "state" );
+        state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
+        var_SetInteger( p_input, "state", state );
+        emit statusChanged( state );
     }
 }
 
@@ -653,9 +661,8 @@ void InputManager::sectionPrev()
     if( hasInput() )
     {
         int i_type = var_Type( p_input, "next-chapter" );
-        vlc_value_t val; val.b_bool = true;
-        var_Set( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
-                            "prev-chapter":"prev-title", val );
+        var_SetVoid( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
+                            "prev-chapter":"prev-title" );
     }
 }
 
@@ -664,9 +671,8 @@ void InputManager::sectionNext()
     if( hasInput() )
     {
         int i_type = var_Type( p_input, "next-chapter" );
-        vlc_value_t val; val.b_bool = true;
-        var_Set( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
-                            "next-chapter":"next-title", val );
+        var_SetVoid( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
+                            "next-chapter":"next-title" );
     }
 }
 
@@ -675,21 +681,20 @@ void InputManager::sectionMenu()
     if( hasInput() )
     {
         vlc_value_t val, text;
-        vlc_value_t root;
 
         if( var_Change( p_input, "title  0", VLC_VAR_GETLIST, &val, &text ) < 0 )
             return;
 
         /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
-        root.i_int = 0;
+        int root = 0;
         for( int i = 0; i < val.p_list->i_count; i++ )
         {
             if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
-                root.i_int = i;
+                root = i;
         }
-        var_Change( p_input, "title  0", VLC_VAR_FREELIST, &val, &text );
+        var_FreeList( &val, &text );
 
-        var_Set( p_input, "title  0", root );
+        var_SetInteger( p_input, "title  0", root );
     }
 }
 
@@ -755,7 +760,7 @@ void InputManager::activateTeletext( bool b_enable )
                 i = 0;
             var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
         }
-        var_Change( p_input, "teletext-es", VLC_VAR_FREELIST, &list, &text );
+        var_FreeList( &list, &text );
     }
 }
 
@@ -807,9 +812,8 @@ void InputManager::jumpFwd()
     int i_interval = config_GetInt( p_input, "short-jump-size" );
     if( i_interval > 0 )
     {
-        vlc_value_t val;
-        val.i_time = (mtime_t)(i_interval) * 1000000L;
-        var_Set( p_input, "time-offset", val );
+        mtime_t val = (mtime_t)(i_interval) * 1000000L;
+        var_SetTime( p_input, "time-offset", val );
     }
 }
 
@@ -818,9 +822,8 @@ void InputManager::jumpBwd()
     int i_interval = config_GetInt( p_input, "short-jump-size" );
     if( i_interval > 0 )
     {
-        vlc_value_t val;
-        val.i_time = -1 *(mtime_t)(i_interval) * 1000000L;
-        var_Set( p_input, "time-offset", val );
+        mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
+        var_SetTime( p_input, "time-offset", val );
     }
 }
 
@@ -881,13 +884,19 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
     CONNECT( this, inputChanged( input_thread_t * ),
              im, setInput( input_thread_t * ) );
 
-    /* emit check if playlist has allready started playing */
-    vlc_value_t val;
-    var_Change( THEPL, "item-current", VLC_VAR_CHOICESCOUNT, &val, NULL );
-
-    IMEvent *event = new IMEvent( ItemChanged_Type, val.i_int);
-    customEvent( event );
-    delete event;
+    /* emit check if playlist has already started playing */
+    input_thread_t *p_input = playlist_CurrentInput( THEPL );
+    if( p_input )
+    {
+        input_item_t *p_item = input_GetItem( p_input );
+        if( p_item )
+        {
+            IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
+            customEvent( event );
+            delete event;
+        }
+        vlc_object_release( p_input );
+    }
 }
 
 MainInputManager::~MainInputManager()
@@ -933,14 +942,12 @@ void MainInputManager::customEvent( QEvent *event )
     /* Should be PLItemChanged Event */
     if( !p_intf->p_sys->b_isDialogProvider )
     {
-        vlc_mutex_lock( &p_intf->change_lock );
         if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
         {
             emit inputChanged( p_input );
             var_DelCallback( p_input, "state", PLItemChanged, this );
             vlc_object_release( p_input );
             p_input = NULL;
-            vlc_mutex_unlock( &p_intf->change_lock );
             return;
         }
 
@@ -953,17 +960,21 @@ void MainInputManager::customEvent( QEvent *event )
                 emit inputChanged( p_input );
             }
         }
-        vlc_mutex_unlock( &p_intf->change_lock );
     }
     else
     {
+        /* remove previous stored p_input */
+        if( p_input )
+        {
+            vlc_object_release( p_input );
+            p_input = NULL;
+        }
         /* we are working as a dialogs provider */
         playlist_t *p_playlist = pl_Hold( p_intf );
         p_input = playlist_CurrentInput( p_playlist );
         if( p_input )
         {
             emit inputChanged( p_input );
-            vlc_object_release( p_input );
         }
         pl_Release( p_intf );
     }
@@ -1001,11 +1012,11 @@ void MainInputManager::activatePlayQuit( bool b_exit )
 
 /* 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 )
+                        vlc_value_t oldval, vlc_value_t, void *param )
 {
     MainInputManager *mim = (MainInputManager*)param;
 
-    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
+    IMEvent *event = new IMEvent( ItemChanged_Type );
     QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
@@ -1015,7 +1026,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 );
+    IMEvent *event = new IMEvent( VolumeChanged_Type );
     QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }