]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
* src/input/control.c: added INPUT_ADD_INFO/INPUT_SET_NAME to input_Control().
[vlc] / src / input / input.c
index 2dddeee324f051240ecc5973997936a9798e0c7e..af18fb9c528637f427d8960136f91fac870d91ad 100644 (file)
@@ -37,8 +37,6 @@
 #   include <sys/times.h>
 #endif
 
-#include "vlc_playlist.h"
-
 #include "stream_output.h"
 
 #include "vlc_interface.h"
@@ -77,6 +75,8 @@ static int StateCallback   ( vlc_object_t *p_this, char const *psz_cmd,
                              vlc_value_t oldval, vlc_value_t newval, void *p_data );
 static int RateCallback    ( vlc_object_t *p_this, char const *psz_cmd,
                              vlc_value_t oldval, vlc_value_t newval, void *p_data );
+static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
+                             vlc_value_t oldval, vlc_value_t newval, void *p_data );
 
 /*****************************************************************************
  * input_CreateThread: creates a new input thread
@@ -84,8 +84,8 @@ static int RateCallback    ( vlc_object_t *p_this, char const *psz_cmd,
  * This function creates a new input, and returns a pointer
  * to its description. On error, it returns NULL.
  *****************************************************************************/
-input_thread_t *__input_CreateThread( vlc_object_t *p_parent, char *psz_uri,
-                                      char **ppsz_options, int i_options )
+input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
+                                      input_item_t *p_item )
 
 {
     input_thread_t *p_input;                        /* thread descriptor */
@@ -100,12 +100,17 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, char *psz_uri,
         return NULL;
     }
 
+    /* Store pointer to input item descriptor */
+    p_input->p_item = p_item;
+
     /* Parse input options */
-    for( i = 0; i < i_options; i++ )
+    vlc_mutex_lock( &p_item->lock );
+    for( i = 0; i < p_item->i_options; i++ )
     {
-        msg_Dbg( p_input, "option: %s", ppsz_options[i] );
-        ParseOption( p_input, ppsz_options[i] );
+        msg_Dbg( p_input, "option: %s", p_item->ppsz_options[i] );
+        ParseOption( p_input, p_item->ppsz_options[i] );
     }
+    vlc_mutex_unlock( &p_item->lock );
 
     /* Create a few object variables we'll need later on */
     var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
@@ -113,8 +118,10 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, char *psz_uri,
     var_Create( p_input, "audio-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
     var_Create( p_input, "spu-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
     var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
-    var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
+                VLC_VAR_DOINHERIT );
+    var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
+                VLC_VAR_DOINHERIT );
 
     var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Create( p_input, "sout-all",   VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
@@ -130,7 +137,7 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, char *psz_uri,
     var_Create( p_input, "stop-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
 
     /* decoders */
-    var_Create( p_input, "minimize-threads", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "minimize-threads", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
 
     /* play status */
 
@@ -182,7 +189,9 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, char *psz_uri,
     p_input->p_sys      = NULL;
 
     /* Set target */
-    p_input->psz_source = strdup( psz_uri );
+    vlc_mutex_lock( &p_item->lock );
+    p_input->psz_source = strdup( p_item->psz_uri );
+    vlc_mutex_unlock( &p_item->lock );
 
     /* Stream */
     p_input->s = NULL;
@@ -194,7 +203,7 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, char *psz_uri,
     p_input->p_demux   = NULL;
     p_input->pf_demux  = NULL;
     p_input->pf_rewind = NULL;
-    p_input->pf_demux_control = NULL;
+    p_input->pf_demux_control = demux_vaControlDefault;
     p_input->i_cr_average = config_GetInt( p_input, "cr-average" );
 
     /* Access */
@@ -249,11 +258,64 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, char *psz_uri,
 
     msg_Info( p_input, "playlist item `%s'", p_input->psz_source );
 
-    /* Initialize input info */
-    p_input->stream.p_info = NULL;
-    p_input->stream.p_info = input_InfoCategory( p_input, _("General") );
-    input_AddInfo( p_input->stream.p_info, _("Playlist Item"),
-                   p_input->psz_source );
+    /* Bookmarks */
+    var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "bookmark", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
+                VLC_VAR_ISCOMMAND );
+    val.psz_string = _("Bookmark");
+    var_Change( p_input, "bookmark", VLC_VAR_SETTEXT, &val, NULL );
+    var_AddCallback( p_input, "bookmark", BookmarkCallback, NULL );
+
+    p_input->i_bookmarks = 0;
+    p_input->pp_bookmarks = NULL;
+
+    var_Get( p_input, "bookmarks", &val );
+    if( val.psz_string )
+    {
+        /* FIXME: have a common cfg parsing routine used by sout and others */
+        char *psz_parser, *psz_start, *psz_end;
+        psz_parser = val.psz_string;
+        while( (psz_start = strchr( psz_parser, '{' ) ) )
+        {
+            seekpoint_t seekpoint;
+            char backup;
+            psz_start++;
+            psz_end = strchr( psz_start, '}' );
+            if( !psz_end ) break;
+            psz_parser = psz_end + 1;
+            backup = *psz_parser;
+            *psz_parser = 0;
+            *psz_end = ',';
+
+            seekpoint.psz_name = 0;
+            seekpoint.i_byte_offset = 0;
+            seekpoint.i_time_offset = 0;
+            while( (psz_end = strchr( psz_start, ',' ) ) )
+            {
+                *psz_end = 0;
+                if( !strncmp( psz_start, "name=", 5 ) )
+                {
+                    seekpoint.psz_name = psz_start + 5;
+                }
+                else if( !strncmp( psz_start, "bytes=", 6 ) )
+                {
+                    seekpoint.i_byte_offset = atoll(psz_start + 6);
+                }
+                else if( !strncmp( psz_start, "time=", 5 ) )
+                {
+                    seekpoint.i_time_offset = atoll(psz_start + 5) * 1000000;
+                }
+                psz_start = psz_end + 1;
+            }
+            msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
+                     seekpoint.psz_name, seekpoint.i_byte_offset,
+                     seekpoint.i_time_offset );
+            input_Control( p_input, INPUT_ADD_BOOKMARK, &seekpoint );
+            *psz_parser = backup;
+        }
+        free( val.psz_string );
+    }
+
     vlc_object_attach( p_input, p_parent );
 
     /* Create thread and wait for its readiness. */
@@ -261,7 +323,6 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, char *psz_uri,
                            VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
     {
         msg_Err( p_input, "cannot create input thread" );
-        input_DelInfo( p_input );
         free( p_input );
         return NULL;
     }
@@ -324,8 +385,6 @@ static int RunThread( input_thread_t *p_input )
         /* Tell we're dead */
         p_input->b_dead = 1;
 
-        input_DelInfo( p_input );
-
         return 0;
     }
 
@@ -560,9 +619,9 @@ static int RunThread( input_thread_t *p_input )
  *****************************************************************************/
 static int InitThread( input_thread_t * p_input )
 {
-    vlc_meta_t *meta;
-    float f_fps;
-    playlist_t *p_playlist;
+    vlc_meta_t *p_meta = NULL, *p_meta_user = NULL;
+//    float f_fps;
+    double f_fps;
     mtime_t i_length;
 
     /* Parse source string. Syntax : [[<access>][/<demux>]:][<source>] */
@@ -824,53 +883,85 @@ static int InitThread( input_thread_t * p_input )
 
     p_input->p_sys->i_stop_time = 0;
 
-    /* get meta informations */
-    if( !demux_Control( p_input, DEMUX_GET_META, &meta ) )
+    /* Get meta information from user */
+    var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
+    var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
+    var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    if( (p_meta_user = vlc_meta_New()) )
+    {
+        vlc_value_t val;
+
+        var_Get( p_input, "meta-title", &val );
+        if( val.psz_string && *val.psz_string )
+            vlc_meta_Add( p_meta_user, VLC_META_TITLE, val.psz_string );
+        if( val.psz_string ) free( val.psz_string );
+        var_Get( p_input, "meta-author", &val );
+        if( val.psz_string && *val.psz_string )
+            vlc_meta_Add( p_meta_user, VLC_META_AUTHOR, val.psz_string );
+        if( val.psz_string ) free( val.psz_string );
+        var_Get( p_input, "meta-artist", &val );
+        if( val.psz_string && *val.psz_string )
+            vlc_meta_Add( p_meta_user, VLC_META_ARTIST, val.psz_string );
+        if( val.psz_string ) free( val.psz_string );
+        var_Get( p_input, "meta-genre", &val );
+        if( val.psz_string && *val.psz_string )
+            vlc_meta_Add( p_meta_user, VLC_META_GENRE, val.psz_string );
+        if( val.psz_string ) free( val.psz_string );
+        var_Get( p_input, "meta-copyright", &val );
+        if( val.psz_string && *val.psz_string )
+            vlc_meta_Add( p_meta_user, VLC_META_COPYRIGHT, val.psz_string );
+        if( val.psz_string ) free( val.psz_string );
+        var_Get( p_input, "meta-description", &val );
+        if( val.psz_string && *val.psz_string )
+            vlc_meta_Add( p_meta_user, VLC_META_DESCRIPTION, val.psz_string );
+        if( val.psz_string ) free( val.psz_string );
+        var_Get( p_input, "meta-date", &val );
+        if( val.psz_string && *val.psz_string )
+            vlc_meta_Add( p_meta_user, VLC_META_DATE, val.psz_string );
+        if( val.psz_string ) free( val.psz_string );
+        var_Get( p_input, "meta-url", &val );
+        if( val.psz_string && *val.psz_string )
+            vlc_meta_Add( p_meta_user, VLC_META_URL, val.psz_string );
+        if( val.psz_string ) free( val.psz_string );
+    }
+
+    /* Get meta informations from demuxer */
+    if( !demux_Control( p_input, DEMUX_GET_META, &p_meta ) ||
+        ( p_meta_user && p_meta_user->i_meta ) )
     {
-        playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_input,
-                                         VLC_OBJECT_PLAYLIST,  FIND_PARENT);
-        playlist_item_t *p_item = NULL;
-        input_info_category_t *p_cat;
         int i;
 
-        if( p_playlist )
-        {
-            vlc_mutex_lock( &p_playlist->object_lock );
-            p_item = playlist_ItemGetByPos( p_playlist, -1 );
-            if( p_item )
-            {
-                vlc_mutex_lock( &p_item->lock );
-            }
-            vlc_mutex_unlock( &p_playlist->object_lock );
-        }
+        /* Merge demux and user metadata */
+        if( !p_meta ){ p_meta = p_meta_user; p_meta_user = NULL; }
+        else if( p_meta && p_meta_user ) vlc_meta_Merge( p_meta, p_meta_user );
 
         msg_Dbg( p_input, "meta informations:" );
-        if( meta->i_meta > 0 )
+        if( p_meta->i_meta > 0 )
         {
-            p_cat = input_InfoCategory( p_input, _("File") );
-            for( i = 0; i < meta->i_meta; i++ )
+            for( i = 0; i < p_meta->i_meta; i++ )
             {
-                msg_Dbg( p_input, "  - '%s' = '%s'", _(meta->name[i]), meta->value[i] );
-                if( !strcmp( meta->name[i], VLC_META_TITLE ) )
-                {
-                    playlist_ItemSetName( p_item, meta->value[i] );
-                }
-                if( !strcmp( meta->name[i], VLC_META_AUTHOR ) )
-                {
-                    playlist_ItemAddInfo( p_item, _("General"), _("Author"),
-                                            meta->value[i] );
-                }
-                input_AddInfo( p_cat, _(meta->name[i]), "%s", meta->value[i] );
-                if( p_item )
-                {
-                    playlist_ItemAddInfo( p_item, _("File"),
-                                          _(meta->name[i]), "%s", meta->value[i] );
-                }
+                msg_Dbg( p_input, "  - '%s' = '%s'", _(p_meta->name[i]),
+                         p_meta->value[i] );
+                if( !strcmp( p_meta->name[i], VLC_META_TITLE ) &&
+                    p_meta->value[i] )
+                    input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
+
+                if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
+                    input_Control( p_input, INPUT_ADD_INFO, _("General"),
+                                   _("Author"), p_meta->value[i] );
+
+                input_Control( p_input, INPUT_ADD_INFO, _("File"),
+                              _(p_meta->name[i]), "%s", p_meta->value[i] );
             }
         }
-        for( i = 0; i < meta->i_track; i++ )
+        for( i = 0; i < p_meta->i_track; i++ )
         {
-            vlc_meta_t *tk = meta->track[i];
+            vlc_meta_t *tk = p_meta->track[i];
             int j;
 
             msg_Dbg( p_input, "  - track[%d]:", i );
@@ -878,67 +969,52 @@ static int InitThread( input_thread_t * p_input )
             {
                 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
                 sprintf( psz_cat, "%s %d", _("Stream"), i );
-                p_cat = input_InfoCategory( p_input, psz_cat );
 
                 for( j = 0; j < tk->i_meta; j++ )
                 {
-                    msg_Dbg( p_input, "     - '%s' = '%s'", _(tk->name[j]), tk->value[j] );
-                    input_AddInfo( p_cat, _(tk->name[j]), "%s", tk->value[j] );
-                    if( p_item )
-                    {
-                        playlist_ItemAddInfo( p_item, psz_cat,
-                                              _(tk->name[j]), "%s", tk->value[j] );
-                    }
+                    msg_Dbg( p_input, "     - '%s' = '%s'", _(tk->name[j]),
+                             tk->value[j] );
+
+                    input_Control( p_input, INPUT_ADD_INFO, psz_cat,
+                                   _(tk->name[j]), "%s", tk->value[j] );
                 }
             }
         }
 
-        if( p_item )
-        {
-            vlc_mutex_unlock( &p_item->lock );
-        }
-        if( p_playlist ) vlc_object_release( p_playlist );
-
         if( p_input->stream.p_sout && p_input->stream.p_sout->p_meta == NULL )
         {
-            p_input->stream.p_sout->p_meta = meta;
+            p_input->stream.p_sout->p_meta = p_meta;
         }
         else
         {
-            vlc_meta_Delete( meta );
+            vlc_meta_Delete( p_meta );
         }
     }
+    if( p_meta_user ) vlc_meta_Delete( p_meta_user );
 
-    /* get length */
-    if( !demux_Control( p_input, DEMUX_GET_LENGTH, &i_length ) && i_length > 0 )
+    /* Get length */
+    if( !demux_Control( p_input, DEMUX_GET_LENGTH, &i_length ) &&
+        i_length > 0 )
     {
-        input_info_category_t *p_cat = input_InfoCategory( p_input, _("File") );
-        p_playlist = (playlist_t*)vlc_object_find( p_input,
-                                                   VLC_OBJECT_PLAYLIST,
-                                                   FIND_PARENT );
-        if( p_playlist )
-        {
-            playlist_SetDuration( p_playlist, -1 , i_length );
-            val.b_bool = p_playlist->i_index;
-            var_Set( p_playlist, "item-change", val );
-            vlc_object_release( p_playlist );
-        }
-        if( p_cat )
-        {
-            char psz_buffer[MSTRTIME_MAX_SIZE];
-            input_AddInfo( p_cat, _("Duration"),
-                           msecstotimestr( psz_buffer, i_length / 1000 ) );
-        }
+        char psz_buffer[MSTRTIME_MAX_SIZE];
+
+        vlc_mutex_lock( &p_input->p_item->lock );
+        p_input->p_item->i_duration = i_length;
+        vlc_mutex_unlock( &p_input->p_item->lock );
+
+        input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
+                       msecstotimestr( psz_buffer, i_length / 1000 ) );
 
         /* Set start time */
         var_Get( p_input, "start-time", &val );
         if(  val.i_int > 0 )
         {
-            double f_pos = (double)( (int64_t)val.i_int * I64C(1000000) ) / (double)i_length;
+            double f_pos = val.i_int * I64C(1000000) / (double)i_length;
 
             if( f_pos >= 1.0 )
             {
-                msg_Warn( p_input, "invalid start-time, ignored (start-time >= media length)" );
+                msg_Warn( p_input, "invalid start-time, ignored (start-time "
+                          ">= media length)" );
             }
             else
             {
@@ -949,6 +1025,7 @@ static int InitThread( input_thread_t * p_input )
             }
         }
     }
+
     /* Set stop-time and check validity */
     var_Get( p_input, "stop-time", &val );
     if( val.i_int > 0 )
@@ -958,7 +1035,8 @@ static int InitThread( input_thread_t * p_input )
         var_Get( p_input, "start-time", &start );
         if( start.i_int >= val.i_int )
         {
-            msg_Warn( p_input, "invalid stop-time, ignored (stop-time < start-time)" );
+            msg_Warn( p_input, "invalid stop-time, ignored (stop-time < "
+                      "start-time)" );
         }
         else
         {
@@ -967,7 +1045,7 @@ static int InitThread( input_thread_t * p_input )
         }
     }
 
-    /* get fps */
+    /* Get fps */
     if( demux_Control( p_input, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
     {
         i_microsecondperframe = 0;
@@ -1007,7 +1085,8 @@ static int InitThread( input_thread_t * p_input )
                 if( ( p_sub = subtitle_New( p_input, *tmp2,
                                             i_microsecondperframe ) ) )
                 {
-                    TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub, p_sub );
+                    TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub,
+                                p_sub );
                 }
             }
             free( *tmp2++ );
@@ -1140,7 +1219,6 @@ static void EndThread( input_thread_t * p_input )
 
     /* Free info structures XXX destroy es before 'cause vorbis */
     msg_Dbg( p_input, "freeing info structures...");
-    input_DelInfo( p_input );
 
     free( p_input->psz_source );
     if( p_input->psz_dupsource != NULL ) free( p_input->psz_dupsource );
@@ -1357,3 +1435,10 @@ static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
     }
     return VLC_SUCCESS;
 }
+
+static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
+                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    input_thread_t *p_input = (input_thread_t *)p_this;
+    return input_Control( p_input, INPUT_SET_BOOKMARK, newval );
+}