]> git.sesse.net Git - vlc/blobdiff - plugins/mpeg/input_ps.c
* Bug fixes and enhancements in the Gtk+/Gnome interfaces.
[vlc] / plugins / mpeg / input_ps.c
index fb5a841a9e9ff42f9a44fbe7a6753189bce6a934..b9190e360daba5e7656f804063057e76bd618467 100644 (file)
@@ -2,7 +2,7 @@
  * input_ps.c: PS demux and packet management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_ps.c,v 1.3 2001/02/08 13:52:35 massiot Exp $
+ * $Id: input_ps.c,v 1.11 2001/03/15 01:42:20 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -21,6 +21,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME ps
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include <string.h>
 #include <errno.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+
 #include "config.h"
 #include "common.h"
 #include "threads.h"
@@ -71,7 +79,7 @@ static void DeletePES   ( void *, struct pes_packet_s * );
  * Functions exported as capabilities. They are declared as static so that
  * we don't pollute the namespace too much.
  *****************************************************************************/
-void input_getfunctions( function_list_t * p_function_list )
+void _M( input_getfunctions )( function_list_t * p_function_list )
 {
 #define input p_function_list->functions.input
     p_function_list->pf_probe = PSProbe;
@@ -79,6 +87,7 @@ void input_getfunctions( function_list_t * p_function_list )
     input.pf_open             = input_FileOpen;
     input.pf_close            = input_FileClose;
     input.pf_end              = PSEnd;
+    input.pf_set_area         = NULL;
     input.pf_read             = PSRead;
     input.pf_demux            = input_DemuxPS;
     input.pf_new_packet       = NewPacket;
@@ -99,12 +108,32 @@ void input_getfunctions( function_list_t * p_function_list )
  *****************************************************************************/
 static int PSProbe( probedata_t *p_data )
 {
+    input_thread_t * p_input = (input_thread_t *)p_data;
+
+    char * psz_name = p_input->p_source;
+    int i_handle;
+    int i_score = 10;
+
     if( TestMethod( INPUT_METHOD_VAR, "ps" ) )
     {
         return( 999 );
     }
 
-    return 10;
+    if( ( strlen(psz_name) > 5 ) && !strncasecmp( psz_name, "file:", 5 ) )
+    {
+        /* If the user specified "file:" then it's probably a file */
+        i_score = 100;
+        psz_name += 5;
+    }
+
+    i_handle = open( psz_name, 0 );
+    if( i_handle == -1 )
+    {
+        return( 0 );
+    }
+    close( i_handle );
+
+    return( i_score );
 }
 
 /*****************************************************************************
@@ -132,7 +161,7 @@ static void PSInit( input_thread_t * p_input )
         p_input->b_error = 1;
         return;
     }
-    fseek( p_method->stream, 0, SEEK_SET );
+    rewind( p_method->stream );
 
     /* FIXME : detect if InitStream failed */
     input_InitStream( p_input, sizeof( stream_ps_data_t ) );
@@ -176,14 +205,15 @@ static void PSInit( input_thread_t * p_input )
             }
 
             /* File too big. */
-            if( p_input->stream.i_tell > INPUT_PREPARSE_LENGTH )
+            if( p_input->stream.p_selected_area->i_tell >
+                                                    INPUT_PREPARSE_LENGTH )
             {
                 break;
             }
         }
-        fseek( p_method->stream, 0, SEEK_SET );
+        rewind( p_method->stream );
         vlc_mutex_lock( &p_input->stream.stream_lock );
-        p_input->stream.i_tell = 0;
+        p_input->stream.p_selected_area->i_tell = 0;
         if( p_demux_data->b_has_PSM )
         {
             /* (The PSM decoder will care about spawning the decoders) */
@@ -211,12 +241,12 @@ static void PSInit( input_thread_t * p_input )
 
                     case MPEG1_AUDIO_ES:
                     case MPEG2_AUDIO_ES:
-                        if( main_GetIntVariable( INPUT_DVD_CHANNEL_VAR, 0 )
+                        if( main_GetIntVariable( INPUT_CHANNEL_VAR, 0 )
                                 == (p_es->i_id & 0x1F) )
-                        switch( main_GetIntVariable( INPUT_DVD_AUDIO_VAR, 0 ) )
+                        switch( main_GetIntVariable( INPUT_AUDIO_VAR, 0 ) )
                         {
                         case 0:
-                            main_PutIntVariable( INPUT_DVD_CHANNEL_VAR,
+                            main_PutIntVariable( INPUT_AUDIO_VAR,
                                                  REQUESTED_MPEG );
                         case REQUESTED_MPEG:
                             input_SelectES( p_input, p_es );
@@ -224,12 +254,12 @@ static void PSInit( input_thread_t * p_input )
                         break;
 
                     case AC3_AUDIO_ES:
-                        if( main_GetIntVariable( INPUT_DVD_CHANNEL_VAR, 0 )
+                        if( main_GetIntVariable( INPUT_CHANNEL_VAR, 0 )
                                 == ((p_es->i_id & 0xF00) >> 8) )
-                        switch( main_GetIntVariable( INPUT_DVD_AUDIO_VAR, 0 ) )
+                        switch( main_GetIntVariable( INPUT_AUDIO_VAR, 0 ) )
                         {
                         case 0:
-                            main_PutIntVariable( INPUT_DVD_CHANNEL_VAR,
+                            main_PutIntVariable( INPUT_AUDIO_VAR,
                                                  REQUESTED_AC3 );
                         case REQUESTED_AC3:
                             input_SelectES( p_input, p_es );
@@ -237,7 +267,7 @@ static void PSInit( input_thread_t * p_input )
                         break;
 
                     case DVD_SPU_ES:
-                        if( main_GetIntVariable( INPUT_DVD_SUBTITLE_VAR, -1 )
+                        if( main_GetIntVariable( INPUT_SUBTITLE_VAR, -1 )
                                 == ((p_es->i_id & 0x1F00) >> 8) )
                         {
                             input_SelectES( p_input, p_es );
@@ -271,7 +301,6 @@ static void PSInit( input_thread_t * p_input )
  *****************************************************************************/
 static void PSEnd( input_thread_t * p_input )
 {
-    free( p_input->stream.p_demux_data );
     free( p_input->p_plugin_data );
 }
 
@@ -299,7 +328,7 @@ static __inline__ int SafeRead( input_thread_t * p_input, byte_t * p_buffer,
         }
     }
     vlc_mutex_lock( &p_input->stream.stream_lock );
-    p_input->stream.i_tell += i_len;
+    p_input->stream.p_selected_area->i_tell += i_len;
     vlc_mutex_unlock( &p_input->stream.stream_lock );
     return( 0 );
 }
@@ -342,7 +371,7 @@ static int PSRead( input_thread_t * p_input,
                 /* It is common for MPEG-1 streams to pad with zeros
                  * (although it is forbidden by the recommendation), so
                  * don't bother everybody in this case. */
-                intf_WarnMsg( 1, "Garbage at input (%x)", i_startcode );
+                intf_WarnMsg( 1, "Garbage at input (%.8x)", i_startcode );
             }
 
             while( (i_startcode & 0xFFFFFF00) != 0x100L )
@@ -439,9 +468,9 @@ static void PSSeek( input_thread_t * p_input, off_t i_position )
     p_method = (thread_ps_data_t *)p_input->p_plugin_data;
 
     /* A little bourrin but should work for a while --Meuuh */
-    fseek( p_method->stream, i_position, SEEK_SET );
+    fseeko( p_method->stream, i_position, SEEK_SET );
 
-    p_input->stream.i_tell = i_position;
+    p_input->stream.p_selected_area->i_tell = i_position;
 }
 
 /*
@@ -499,7 +528,7 @@ static pes_packet_t * NewPES( void * p_garbage )
         return NULL;
     }
 
-    p_pes->b_messed_up = p_pes->b_data_alignment = p_pes->b_discontinuity =
+    p_pes->b_data_alignment = p_pes->b_discontinuity =
         p_pes->i_pts = p_pes->i_dts = 0;
     p_pes->i_pes_size = 0;
     p_pes->p_first = NULL;