]> git.sesse.net Git - vlc/blobdiff - plugins/mpeg/input_ts.c
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / plugins / mpeg / input_ts.c
index 26aa41c690635510d1960a998cacc2fb1a1ff2f9..d664906d08155c2f44910fb1a2ff2e98dc7b518b 100644 (file)
@@ -2,7 +2,7 @@
  * input_ts.c: TS demux and netlist management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_ts.c,v 1.1 2001/02/08 04:43:27 sam Exp $
+ * $Id: input_ts.c,v 1.5 2001/02/20 07:49:13 sam Exp $
  *
  * Authors: 
  *
@@ -21,6 +21,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME ts
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/uio.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 #include "config.h"
 #include "common.h"
@@ -44,6 +53,7 @@
 #include "input_ext-dec.h"
 
 #include "input.h"
+#include "input_ts.h"
 
 #include "mpeg_system.h"
 #include "input_netlist.h"
@@ -61,7 +71,7 @@ static void TSEnd       ( struct input_thread_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 = TSProbe;
@@ -69,6 +79,7 @@ void input_getfunctions( function_list_t * p_function_list )
     input.pf_open             = input_FileOpen;
     input.pf_close            = input_FileClose;
     input.pf_end              = TSEnd;
+    input.pf_set_area         = NULL;
     input.pf_read             = TSRead;
     input.pf_demux            = input_DemuxTS;
     input.pf_new_packet       = input_NetlistNewPacket;
@@ -85,13 +96,31 @@ void input_getfunctions( function_list_t * p_function_list )
  *****************************************************************************/
 static int TSProbe( 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 = 1;
+
     if( TestMethod( INPUT_METHOD_VAR, "ts" ) )
     {
         return( 999 );
     }
 
-    /* verify that the first byte is 0x47 */
-    return 1;
+    if( ( strlen(psz_name) > 5 ) && !strncasecmp( psz_name, "file:", 5 ) )
+    {
+        /* If the user specified "file:" then it's probably a file */
+        psz_name += 5;
+    }
+
+    i_handle = open( psz_name, 0 );
+    if( i_handle == -1 )
+    {
+        return( 0 );
+    }
+    close( i_handle );
+
+    return( i_score );
 }
 
 /*****************************************************************************
@@ -100,6 +129,58 @@ static int TSProbe( probedata_t * p_data )
 static void TSInit( input_thread_t * p_input )
 {
     /* Initialize netlist and TS structures */
+    thread_ts_data_t    * p_method;
+    pgrm_ts_data_t      * p_pgrm_demux;
+    es_descriptor_t     * kludge1;
+
+    /* Initialise structure */
+    p_method = malloc( sizeof( thread_ts_data_t ) );
+    if( p_method == NULL )
+    {
+        intf_ErrMsg( "Out of memory" );
+        p_input->b_error = 1;
+        return;
+    }
+    p_input->p_plugin_data = (void *)p_method;
+    p_input->p_method_data = NULL;
+    
+    /* XXX : For the time being, only file, after, i'll do the network */ 
+    
+    /* Initialize netlist */
+    if( input_NetlistInit( p_input, NB_DATA, NB_PES, TS_PACKET_SIZE, 
+                INPUT_READ_ONCE ) )
+    {
+        intf_ErrMsg( "Could not initialize netlist" );
+        return;
+    }
+   
+    /* Initialize the stream */
+    input_InitStream( p_input, sizeof( stream_ts_data_t ) );
+
+    /* FIXME : PSIDemux and PSIDecode */
+    /* Add audio and video programs */
+    /* p_input->stream.pp_programs[0] = */
+    input_AddProgram( p_input, 0, sizeof( pgrm_ts_data_t ) );
+    p_pgrm_demux = 
+        (pgrm_ts_data_t *)p_input->stream.pp_programs[0]->p_demux_data;
+    p_pgrm_demux->i_pcr_pid = 0x78;
+
+    kludge1 = input_AddES( p_input, p_input->stream.pp_programs[0], 
+                           0x78, sizeof( es_ts_data_t ) );
+
+    // kludge
+    kludge1->i_type = MPEG2_VIDEO_ES;
+
+    input_SelectES( p_input, kludge1 );
+
+    vlc_mutex_lock( &(p_input->stream.stream_lock) );
+    p_input->stream.pp_programs[0]->b_is_ok = 1;
+    vlc_mutex_unlock( &(p_input->stream.stream_lock) );
+
+//debug
+intf_ErrMsg("End of TSINIT");    
 }
 
 /*****************************************************************************
@@ -119,6 +200,34 @@ static void TSEnd( input_thread_t * p_input )
 static int TSRead( input_thread_t * p_input,
                    data_packet_t * pp_packets[INPUT_READ_ONCE] )
 {
-    return -1;
-}
+    unsigned int i_read, i_loop;
+    struct iovec * p_iovec;
+    
+    memset( pp_packets, 0, INPUT_READ_ONCE*sizeof(data_packet_t *) );
+    
+    p_iovec = input_NetlistGetiovec( p_input->p_method_data );
+    
+    if ( p_iovec == NULL )
+    {
+        return( -1 ); /* empty netlist */
+    } 
 
+    i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE );
+    
+    if( i_read == -1 )
+    {
+        intf_ErrMsg( "Could not readv" );
+        return( -1 );
+    }
+
+    input_NetlistMviovec( p_input->p_method_data, 
+            (int)(i_read/TS_PACKET_SIZE) , pp_packets );
+
+    /* check correct TS header */
+    for( i_loop=0; i_loop < (int)(i_read/TS_PACKET_SIZE); i_loop++ )
+    {
+        if( pp_packets[i_loop]->p_buffer[0] != 0x47 )
+            intf_ErrMsg( "Bad TS Packet (starcode != 0x47)." );
+    }
+    return 0;
+}