]> git.sesse.net Git - vlc/blobdiff - modules/access/satellite/access.c
cdda/info.c: changes for libcddb 1.1.0 API
[vlc] / modules / access / satellite / access.c
index 55200f669c5d09b5371c7fe94f2374c1adc4c3b4..ef168fd4adea0302bc6bf9f68f1cb97f2fc1af94 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * access.c: Satellite card input
  *****************************************************************************
- * Copyright (C) 1998-2003 VideoLAN
+ * Copyright (C) 1998-2003 the VideoLAN team
  *
  * Authors: Johan Bilien <jobi@via.ecp.fr>
  *          Christophe Massiot <massiot@via.ecp.fr>
@@ -48,7 +48,9 @@
 
 #include "dvb.h"
 
-#define SATELLITE_READ_ONCE 80
+/* These are for the Dreambox port. I have no idea whether they're correct
+ * for other DVB adapters. --Meuuh */
+#define SATELLITE_READ_ONCE (64 * 1024)
 #define DMX_BUFFER_SIZE (1024 * 1024)
 
 /*****************************************************************************
@@ -60,16 +62,74 @@ static int     SatelliteSetArea    ( input_thread_t *, input_area_t * );
 static int     SatelliteSetProgram ( input_thread_t *, pgrm_descriptor_t * );
 static void    SatelliteSeek       ( input_thread_t *, off_t );
 
+typedef struct demux_handle_t
+{
+    int i_pid;
+    int i_handle;
+    int i_type;
+} demux_handle_t;
+
+#define PAT_TYPE 1
+#define PMT_TYPE 2
+#define ES_TYPE 3
+
+#define MAX_DEMUX 8 
+
+typedef struct thread_sat_data_t
+{
+    int i_handle;
+    demux_handle_t p_demux_handles[MAX_DEMUX];
+} thread_sat_data_t;
+
+static void AllocateDemux( input_thread_t * p_input, int i_pid,
+                           int i_type )
+{
+    thread_sat_data_t * p_satellite = (thread_sat_data_t *)p_input->p_access_data;
+    int                 i_demux;
+    int                 i;
+    i_demux = config_GetInt( p_input, "dvb-dmx" );
+
+    /* Find first free slot */
+    for ( i = 0; i < MAX_DEMUX; i++ )
+    {
+        if ( !p_satellite->p_demux_handles[i].i_type )
+        {
+            if (ioctl_SetDMXFilter( i_demux, i_pid, &p_satellite->p_demux_handles[i].i_handle, 3) < 0)
+            {
+                msg_Warn(p_input, "ioctl_SetDMXFilter failed (%d)", i_pid);
+                break;
+            }
+            p_satellite->p_demux_handles[i].i_type = i_type;
+            p_satellite->p_demux_handles[i].i_pid = i_pid;
+            break;
+        }
+    }
+}
+
+static void CloseProgram( input_thread_t * p_input )
+{
+    thread_sat_data_t * p_satellite = (thread_sat_data_t *)p_input->p_access_data;
+    int i;
+
+    for ( i = 1; i < MAX_DEMUX; i++ )
+    {
+        if ( p_satellite->p_demux_handles[i].i_type )
+        {
+            ioctl_UnsetDMXFilter( p_satellite->p_demux_handles[i].i_handle );
+            p_satellite->p_demux_handles[i].i_type = 0;
+        }
+    }
+}
+
 /*****************************************************************************
  * Open: open the dvr device
  *****************************************************************************/
 int E_(Open) ( vlc_object_t *p_this )
 {
     input_thread_t *    p_input = (input_thread_t *)p_this;
-    input_socket_t *    p_satellite;
+    thread_sat_data_t * p_satellite;
     char *              psz_parser;
     char *              psz_next;
-    int                 i_fd = 0;
     int                 i_freq = 0;
     int                 i_srate = 0;
     vlc_bool_t          b_pol = 0;
@@ -194,13 +254,14 @@ int E_(Open) ( vlc_object_t *p_this )
 
 
     /* Initialise structure */
-    p_satellite = malloc( sizeof( input_socket_t ) );
+    p_satellite = malloc( sizeof( thread_sat_data_t ) );
 
     if( p_satellite == NULL )
     {
         msg_Err( p_input, "out of memory" );
         return -1;
     }
+    memset( p_satellite, 0, sizeof( thread_sat_data_t ) );
 
     p_input->p_access_data = (void *)p_satellite;
 
@@ -237,7 +298,7 @@ int E_(Open) ( vlc_object_t *p_this )
 
         if ( ioctl_SECControl( i_tuner, i_freq, b_pol, i_lnb_slof, b_diseqc ) < 0 )
         {
-            msg_Err( p_input, "an error occured when controling SEC" );
+            msg_Err( p_input, "an error occurred when controling SEC" );
             close( p_satellite->i_handle );
             free( p_satellite );
             return -1;
@@ -283,14 +344,7 @@ int E_(Open) ( vlc_object_t *p_this )
     } /* i_freq */
 
     msg_Dbg( p_input, "setting filter on PAT" );
-
-    if ( ioctl_SetDMXFilter( i_demux, 0, &i_fd, 3 ) < 0 )
-    {
-        msg_Err( p_input, "an error occured when setting filter on PAT" );
-        close( p_satellite->i_handle );
-        free( p_satellite );
-        return -1;
-    }
+    AllocateDemux( p_input, 0, PAT_TYPE );
 
     if( input_InitStream( p_input, sizeof( stream_ts_data_t ) ) == -1 )
     {
@@ -308,7 +362,7 @@ int E_(Open) ( vlc_object_t *p_this )
 
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
-    p_input->i_mtu = SATELLITE_READ_ONCE * TS_PACKET_SIZE;
+    p_input->i_mtu = SATELLITE_READ_ONCE;
     p_input->stream.i_method = INPUT_METHOD_SATELLITE;
 
     return 0;
@@ -320,26 +374,12 @@ int E_(Open) ( vlc_object_t *p_this )
 void E_(Close) ( vlc_object_t *p_this )
 {
     input_thread_t *    p_input = (input_thread_t *)p_this;
-    input_socket_t *    p_satellite;
-    unsigned int        i_es_index;
+    thread_sat_data_t * p_satellite = (thread_sat_data_t *)p_input->p_access_data;
 
-    if ( p_input->stream.p_selected_program )
-    {
-        for ( i_es_index = 1 ;
-                i_es_index < p_input->stream.p_selected_program->
-                    i_es_number ;
-                i_es_index ++ )
-        {
-#define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
-            if ( p_es->p_decoder_fifo )
-            {
-                ioctl_UnsetDMXFilter( p_es->i_demux_fd );
-            }
-#undef p_es
-        }
-    }
+    msg_Dbg( p_input, "unsetting filters on all pids" );
+    CloseProgram( p_input );
+    close( p_satellite->p_demux_handles[0].i_handle );
 
-    p_satellite = (input_socket_t *)p_input;
     close( p_satellite->i_handle );
 }
 
@@ -349,10 +389,8 @@ void E_(Close) ( vlc_object_t *p_this )
 static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
                               size_t i_len )
 {
-    input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
+    thread_sat_data_t * p_satellite = (thread_sat_data_t *)p_input->p_access_data;
     ssize_t i_ret;
-    int i_program = config_GetInt( p_input, "program" );
-    int i_demux = config_GetInt( p_input, "dvb-dmx" );
 
     unsigned int i;
 
@@ -360,25 +398,25 @@ static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
     /* This is kludgy and consumes way too much CPU power - the access
      * module should have a callback from the demux when a new program
      * is encountered. --Meuuh */
-    for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
+    if ( !p_satellite->p_demux_handles[1].i_type )
     {
-        /* Only set a filter on the selected program : some boards
-         * (read: Dreambox) only have 8 filters, so you don't want to
-         * spend them on unwanted PMTs. --Meuuh */
-        if ( (!i_program || p_input->stream.pp_programs[i]->i_number == i_program) && p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd == 0 )
+        int i_program = config_GetInt( p_input, "program" );
+
+        for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
         {
-            msg_Dbg( p_input, "setting filter on PMT pid %d",
-                     p_input->stream.pp_programs[i]->pp_es[0]->i_id );
-            if (ioctl_SetDMXFilter( i_demux, p_input->stream.pp_programs[i]->pp_es[0]->i_id,
-                       &p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd,
-                       3 ) < 0)
+            /* Only set a filter on the selected program : some boards
+             * (read: Dreambox) only have 8 filters, so you don't want to
+             * spend them on unwanted PMTs. --Meuuh */
+            if ( (!i_program || p_input->stream.pp_programs[i]->i_number == i_program) )
             {
-                msg_Err(p_input, "ioctl_SetDMXFilter failed");
+                msg_Dbg( p_input, "setting filter on PMT pid %d",
+                         p_input->stream.pp_programs[i]->pp_es[0]->i_id );
+                AllocateDemux( p_input, p_input->stream.pp_programs[i]->pp_es[0]->i_id, PMT_TYPE );
             }
         }
     }
 
-    i_ret = read( p_access_data->i_handle, p_buffer, i_len );
+    i_ret = read( p_satellite->i_handle, p_buffer, i_len );
  
     if( i_ret < 0 )
     {
@@ -410,68 +448,54 @@ int SatelliteSetProgram( input_thread_t    * p_input,
 {
     unsigned int i_es_index;
     vlc_value_t val;
-    int i_demux = config_GetInt( p_input, "dvb-dmx" );
 
     if ( p_input->stream.p_selected_program )
     {
-        for ( i_es_index = 1 ; /* 0 should be the PMT */
+        for ( i_es_index = 0 ; /* 0 should be the PMT */
                 i_es_index < p_input->stream.p_selected_program->
                     i_es_number ;
                 i_es_index ++ )
         {
 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
-            if ( p_es->p_decoder_fifo )
+            if ( p_es->p_dec )
             {
                 input_UnselectES( p_input , p_es );
             }
-            if ( p_es->i_demux_fd )
-            {
-                ioctl_UnsetDMXFilter( p_es->i_demux_fd );
-                p_es->i_demux_fd = 0;
-            }
 #undef p_es
         }
     }
 
+    msg_Dbg( p_input, "unsetting filters on all pids" );
+    CloseProgram( p_input );
+    msg_Dbg( p_input, "setting filter on PMT pid %d",
+             p_new_prg->pp_es[0]->i_id );
+    AllocateDemux( p_input, p_new_prg->pp_es[0]->i_id, PMT_TYPE );
+
     for ( i_es_index = 1 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
     {
 #define p_es p_new_prg->pp_es[i_es_index]
         switch( p_es->i_cat )
         {
-            case MPEG1_VIDEO_ES:
-            case MPEG2_VIDEO_ES:
-            case MPEG2_MOTO_VIDEO_ES:
+            case VIDEO_ES:
                 msg_Dbg(p_input, "setting filter on video ES 0x%x",
                         p_es->i_id);
-                /* First set the filter. This may seem a little odd, but
+                /* Always set the filter. This may seem a little odd, but
                  * it allows you to stream the video with demuxstream
                  * without having a decoder or a stream output behind.
                  * The result is you'll sometimes filter a PID which you
                  * don't really want, but in the most common cases it
                  * should be OK. --Meuuh */
-                if (ioctl_SetDMXFilter( i_demux, p_es->i_id, &p_es->i_demux_fd, 1) < 0)
-                {
-                    msg_Dbg(p_input, "ioctl_SetDMXFilter failed");
-                }
-                else
-                {
-                    input_SelectES( p_input , p_es );
-                }
+                AllocateDemux( p_input, p_es->i_id, ES_TYPE );
+                input_SelectES( p_input , p_es );
                 break;
 
-            case MPEG1_AUDIO_ES:
-            case MPEG2_AUDIO_ES:
+            case AUDIO_ES:
                 msg_Dbg(p_input, "setting filter on audio ES 0x%x",
                         p_es->i_id);
-                if (ioctl_SetDMXFilter( i_demux, p_es->i_id, &p_es->i_demux_fd, 3) < 0)
-                {
-                    msg_Dbg(p_input, "ioctl_SetDMXFilter failed");
-                }
-                else
-                {
-                    input_SelectES( p_input , p_es );
-                }
+                AllocateDemux( p_input, p_es->i_id, ES_TYPE );
+                input_SelectES( p_input , p_es );
                 break;
+
             default:
                 /* Do not select private streams. This is to avoid the
                  * limit of 8 filters on the Dreambox and possibly on
@@ -483,14 +507,8 @@ int SatelliteSetProgram( input_thread_t    * p_input,
                 msg_Dbg(p_input, "setting filter on misc (0x%x) ES 0x%x",
                         p_es->i_cat,
                         p_es->i_id);
-                if (ioctl_SetDMXFilter( i_demux, p_es->i_id, &p_es->i_demux_fd, 3) < 0)
-                {
-                    msg_Dbg(p_input, "ioctl_SetDMXFilter failed");
-                }
-                else
-                {
-                    input_SelectES( p_input , p_es );
-                }
+                AllocateDemux( p_input, p_es->i_id, ES_TYPE );
+                input_SelectES( p_input , p_es );
 #endif
                 break;
 #undef p_es