]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
* English grammar fixes and beautifications for the intf_UserFatal messages
[vlc] / src / input / input.c
index 55fe92c6820dfbc2876679df8510790c4f498c86..fdfda62b60eaad4cd9ba9fda79304ca4b9033fdd 100644 (file)
@@ -28,6 +28,7 @@
 #include <vlc/vlc.h>
 
 #include <ctype.h>
+#include <limits.h>
 
 #include "input_internal.h"
 
@@ -75,7 +76,6 @@ static int  InputSourceInit( input_thread_t *, input_source_t *,
 static void InputSourceClean( input_source_t * );
 /* TODO */
 //static void InputGetAttachments( input_thread_t *, input_source_t * );
-
 static void SlaveDemux( input_thread_t *p_input );
 static void SlaveSeek( input_thread_t *p_input );
 
@@ -85,6 +85,10 @@ static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta );
 static sout_instance_t *SoutFind( vlc_object_t *p_parent, input_item_t *p_item, vlc_bool_t * );
 static void SoutKeep( sout_instance_t * );
 
+static void DemuxMeta( input_thread_t *p_input, vlc_meta_t *p_meta, demux_t *p_demux );
+static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
+                              int i_new, input_attachment_t **pp_new );
+
 /*****************************************************************************
  * This function creates a new input, and returns a pointer
  * to its description. On error, it returns NULL.
@@ -1157,7 +1161,7 @@ static int Init( input_thread_t * p_input )
     InputMetaUser( p_input, p_meta );
 
     /* Get meta data from master input */
-    demux2_Control( p_input->p->input.p_demux, DEMUX_GET_META, p_meta );
+    DemuxMeta( p_input, p_meta, p_input->p->input.p_demux );
 
     /* Access_file does not give any meta, and there are no slave */
     if( !p_input->b_preparsing )
@@ -1169,8 +1173,7 @@ static int Init( input_thread_t * p_input )
         /* Get meta data from slave input */
         for( i = 0; i < p_input->p->i_slave; i++ )
         {
-            demux2_Control( p_input->p->slave[i]->p_demux,
-                            DEMUX_GET_META, p_meta );
+            DemuxMeta( p_input, p_meta, p_input->p->slave[i]->p_demux );
             if( p_input->p->slave[i]->p_access )
             {
                 access2_Control( p_input->p->slave[i]->p_access,
@@ -1519,8 +1522,7 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
             if( f_pos < 0.0 ) f_pos = 0.0;
             if( f_pos > 1.0 ) f_pos = 1.0;
             /* Reset the decoders states and clock sync (before calling the demuxer */
-            es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
-            input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_TRUE, VLC_FALSE );
+            input_EsOutChangePosition( p_input->p->p_es_out );
             if( demux2_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
                                 f_pos ) )
             {
@@ -1557,8 +1559,7 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
             if( i_time < 0 ) i_time = 0;
 
             /* Reset the decoders states and clock sync (before calling the demuxer */
-            es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
-            input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_TRUE, VLC_FALSE );
+            input_EsOutChangePosition( p_input->p->p_es_out );
 
             i_ret = demux2_Control( p_input->p->input.p_demux,
                                     DEMUX_SET_TIME, i_time );
@@ -1674,12 +1675,52 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
         {
             int i_rate;
 
-            if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
-                i_rate = p_input->p->i_rate * 2;
-            else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
-                i_rate = p_input->p->i_rate / 2;
-            else
+            if( i_type == INPUT_CONTROL_SET_RATE )
+            {
                 i_rate = val.i_int;
+            }
+            else
+            {
+                static const int ppi_factor[][2] = {
+                    {1,64}, {1,32}, {1,16}, {1,8}, {1,4}, {1,3}, {1,2}, {2,3},
+                    {1,1},
+                    {3,2}, {2,1}, {3,1}, {4,1}, {8,1}, {16,1}, {32,1}, {64,1},
+                    {0,0}
+                };
+                int i_error;
+                int i_idx;
+                int i;
+
+                i_error = INT_MAX;
+                i_idx = -1;
+                for( i = 0; ppi_factor[i][0] != 0; i++ )
+                {
+                    const int i_test_r = INPUT_RATE_DEFAULT * ppi_factor[i][0] / ppi_factor[i][1];
+                    const int i_test_e = abs(p_input->p->i_rate - i_test_r);
+                    if( i_test_e < i_error )
+                    {
+                        i_idx = i;
+                        i_error = i_test_e;
+                    }
+                }
+                assert( i_idx >= 0 && ppi_factor[i_idx][0] != 0 );
+
+                if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
+                {
+                    if( ppi_factor[i_idx+1][0] > 0 )
+                        i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx+1][0] / ppi_factor[i_idx+1][1];
+                    else
+                        i_rate = INPUT_RATE_MAX+1;
+                }
+                else
+                {
+                    assert( i_type == INPUT_CONTROL_SET_RATE_FASTER );
+                    if( i_idx > 0 )
+                        i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx-1][0] / ppi_factor[i_idx-1][1];
+                    else
+                        i_rate = INPUT_RATE_MIN-1;
+                }
+            }
 
             if( i_rate < INPUT_RATE_MIN )
             {
@@ -1760,8 +1801,7 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
 
                 if( i_title >= 0 && i_title < p_input->p->input.i_title )
                 {
-                    es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
-                    input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_TRUE, VLC_FALSE );
+                    input_EsOutChangePosition( p_input->p->p_es_out );
 
                     demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
                     input_ControlVarTitle( p_input, i_title );
@@ -1781,8 +1821,7 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
 
                 if( i_title >= 0 && i_title < p_input->p->input.i_title )
                 {
-                    es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
-                    input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_TRUE, VLC_FALSE );
+                    input_EsOutChangePosition( p_input->p->p_es_out );
 
                     access2_Control( p_access, ACCESS_SET_TITLE, i_title );
                     stream_AccessReset( p_input->p->input.p_stream );
@@ -1822,8 +1861,8 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
                 if( i_seekpoint >= 0 && i_seekpoint <
                     p_input->p->input.title[p_demux->info.i_title]->i_seekpoint )
                 {
-                    es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
-                    input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_TRUE, VLC_FALSE );
+
+                    input_EsOutChangePosition( p_input->p->p_es_out );
 
                     demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
                 }
@@ -1858,8 +1897,7 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
                 if( i_seekpoint >= 0 && i_seekpoint <
                     p_input->p->input.title[p_access->info.i_title]->i_seekpoint )
                 {
-                    es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
-                    input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_TRUE, VLC_FALSE );
+                    input_EsOutChangePosition( p_input->p->p_es_out );
 
                     access2_Control( p_access, ACCESS_SET_SEEKPOINT,
                                     i_seekpoint );
@@ -2013,7 +2051,7 @@ static int UpdateFromAccess( input_thread_t *p_input )
         vlc_meta_t *p_meta = vlc_meta_New();
         access2_Control( p_input->p->input.p_access,ACCESS_GET_META, p_meta );
         InputUpdateMeta( p_input, p_meta );
-        var_SetBool( p_input, "item-change", p_input->p->input.p_item->i_id );
+        var_SetInteger( pl_Get( p_input ), "item-change", p_input->p->input.p_item->i_id );
         p_access->info.i_update &= ~INPUT_UPDATE_META;
     }
 
@@ -2325,8 +2363,8 @@ static int InputSourceInit( input_thread_t *p_input,
             msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
                      psz_access, psz_demux, psz_path );
             intf_UserFatal( VLC_OBJECT( p_input ), VLC_FALSE,
-                            _("Can't recognize the input's format"),
-                            _("The format of '%s' can't be detected. "
+                            _("VLC can't recognize the input's format"),
+                            _("The format of '%s' cannot be detected. "
                             "Have a look the log for details."), psz_mrl );
             goto error;
         }
@@ -2356,14 +2394,9 @@ static int InputSourceInit( input_thread_t *p_input,
         if( !demux2_Control( in->p_demux, DEMUX_GET_ATTACHMENTS,
                              &attachment, &i_attachment ) )
         {
-            int i;
             vlc_mutex_lock( &p_input->p->input.p_item->lock );
-            p_input->p->attachment = realloc( p_input->p->attachment,
-                    sizeof(input_attachment_t**) * ( p_input->p->i_attachment + i_attachment ) );
-            for( i = 0; i < i_attachment; i++ )
-                p_input->p->attachment[p_input->p->i_attachment++] = attachment[i];
-            if( attachment )
-                free( attachment );
+            AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
+                              i_attachment, attachment );
             vlc_mutex_unlock( &p_input->p->input.p_item->lock );
         }
     }
@@ -2566,8 +2599,6 @@ static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
             input_ExtractAttachmentAndCacheArt( p_input );
     }
     free( psz_arturl );
-    input_item_SetPreparsed( p_item, VLC_TRUE );
 
     /* A bit ugly */
     p_meta = NULL;
@@ -2578,6 +2609,8 @@ static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
     }
     vlc_mutex_unlock( &p_item->lock );
 
+    input_item_SetPreparsed( p_item, VLC_TRUE );
+
     if( i_arturl_event == VLC_TRUE )
     {
         vlc_event_t event;
@@ -2628,6 +2661,76 @@ static inline vlc_bool_t IsValidAccess( const char *psz )
     return VLC_FALSE;
 }
 
+static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
+                              int i_new, input_attachment_t **pp_new )
+{
+    int i_attachment = *pi_attachment;
+    input_attachment_t **attachment = *ppp_attachment;
+    int i;
+
+    attachment = realloc( attachment,
+                          sizeof(input_attachment_t**) * ( i_attachment + i_new ) );
+    for( i = 0; i < i_new; i++ )
+        attachment[i_attachment++] = pp_new[i];
+    if( pp_new )
+        free( pp_new );
+
+    /* */
+    *pi_attachment = i_attachment;
+    *ppp_attachment = attachment;
+}
+
+static void DemuxMeta( input_thread_t *p_input, vlc_meta_t *p_meta, demux_t *p_demux )
+{
+    vlc_bool_t b_bool;
+    module_t *p_id3;
+
+
+#if 0
+    /* XXX I am not sure it is a great idea, besides, there is more than that
+     * if we want to do it right */
+    vlc_mutex_lock( &p_item->lock );
+    if( p_item->p_meta && (p_item->p_meta->i_status & ITEM_PREPARSED ) )
+    {
+        vlc_mutex_unlock( &p_item->lock );
+        return;
+    }
+    vlc_mutex_unlock( &p_item->lock );
+#endif
+
+    demux2_Control( p_demux, DEMUX_GET_META, p_meta );
+    if( demux2_Control( p_demux, DEMUX_HAS_UNSUPPORTED_META, &b_bool ) )
+        return;
+    if( !b_bool )
+        return;
+
+    p_demux->p_private = malloc( sizeof( demux_meta_t ) );
+    if(! p_demux->p_private )
+        return;
+
+    p_id3 = module_Need( p_demux, "meta reader", NULL, 0 );
+    if( p_id3 )
+    {
+        demux_meta_t *p_demux_meta = (demux_meta_t *)p_demux->p_private;
+
+        if( p_demux_meta->p_meta )
+        {
+            vlc_meta_Merge( p_meta, p_demux_meta->p_meta );
+            vlc_meta_Delete( p_demux_meta->p_meta );
+        }
+
+        if( p_demux_meta->i_attachments > 0 )
+        {
+            vlc_mutex_lock( &p_input->p->input.p_item->lock );
+            AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
+                              p_demux_meta->i_attachments, p_demux_meta->attachments );
+            vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+        }
+        module_Unneed( p_demux, p_id3 );
+    }
+    free( p_demux->p_private );
+}
+
 
 /*****************************************************************************
  * MRLSplit: parse the access, demux and url part of the