[dvblast-devel] [PATCH] added new PID filter method

Wolfgang Haupt w.haupt at at-visions.com
Tue May 7 14:28:30 CEST 2013


Hello Guys,

i needed a way to filter PIDs by ESTYPE.
Refering to:https://github.com/gfto/dvblast/pull/3
Please let me know what you think about it.

Kind Regards,
Wolfgang Haupt

---
  NEWS      |  1 +
  README    | 18 ++++++++++++++++
  demux.c   | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
  dvblast.c | 43 ++++++++++++++++++++++++++++++++++++--
  dvblast.h |  7 +++++++
  5 files changed, 134 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index eb5ea32..53418c4 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Changes between 2.2 and 2.3:
      globally and per output.
    * Added support for multi-delivery system frontends.
    * Added support for multistream that appeared in Linux 3.6
+  * Added new PID filter method using ES-Types
  
  Changes between 2.1 and 2.2:
  ----------------------------
diff --git a/README b/README
index bc0a9d3..39171fd 100644
--- a/README
+++ b/README
@@ -200,6 +200,24 @@ included PAT and PMT may contain ghost programs or ESes.
  
  All four PIDs are required!
  
+5. ES-Types
+
+224.1.1.50:30050/udp 1 4711 E:0x1b:0:0,E:0x04:0x0a:ger,E:0x06:0x56:deu
+
+DVBlast will stream PID's corresponding to es_type 0x1b (h.264 video), 0x04 (mpeg-2 audio)
+and teletext (0x06 = private data, 0x56 = teletext description table, deu = language).
+
+Splitting up the fields (example audio):
+  E: //indicates that you want to filter by es_type
+  0x04: es_type
+  0x0a: description type
+  ger:  language
+
+Further examples:
+224.1.1.50:30050/udp 1 4711 E:0x1b:0:0,E:0x04:0x0a:eng (streams HD video and mpeg-2 audio english)
+224.1.1.50:30050/udp 1 4711 E:0x02:0:0,E:0x04:0x0a:ger (streams mpeg-2 video and mpeg-2 audio german)
+
+
  Note that the CAM will not be programmed in that case (unless it has
  been programmed by another line of the config file). The file is read
  from the command-line :
diff --git a/demux.c b/demux.c
index 78c0fed..7843140 100644
--- a/demux.c
+++ b/demux.c
@@ -51,6 +51,9 @@
  extern bool b_enable_emm;
  extern bool b_enable_ecm;
  
+extern output_estype_options_t *p_estypes;
+extern int i_nb_estypes;
+
  /*****************************************************************************
   * Local declarations
   *****************************************************************************/
@@ -126,6 +129,7 @@ static void GetPIDS( uint16_t **ppi_wanted_pids, int *pi_nb_wanted_pids,
                       const uint16_t *pi_pids, int i_nb_pids );
  static bool SIDIsSelected( uint16_t i_sid );
  static bool PIDWouldBeSelected( uint8_t *p_es );
+static bool AdditionalPIDFiltering( uint8_t *p_es );
  static bool PMTNeedsDescrambling( uint8_t *p_pmt );
  static void FlushEIT( output_t *p_output, mtime_t i_dts );
  static void SendTDT( block_t *p_ts );
@@ -909,9 +913,12 @@ static void GetPIDS( uint16_t **ppi_wanted_pids, int *pi_nb_wanted_pids,
          j++;
          if ( PIDWouldBeSelected( p_es ) )
          {
-            *ppi_wanted_pids = realloc( *ppi_wanted_pids,
+            if ( AdditionalPIDFiltering( p_es ) )
+            {
+                *ppi_wanted_pids = realloc( *ppi_wanted_pids,
                                    (*pi_nb_wanted_pids + 1) * sizeof(uint16_t) );
-            (*ppi_wanted_pids)[(*pi_nb_wanted_pids)++] = pmtn_get_pid( p_es );
+                (*ppi_wanted_pids)[(*pi_nb_wanted_pids)++] = pmtn_get_pid( p_es );
+            }
          }
      }
  
@@ -1306,7 +1313,7 @@ static void NewPMT( output_t *p_output )
          uint16_t i_pid = pmtn_get_pid( p_current_es );
  
          j++;
-        if ( (p_output->config.i_nb_pids || !PIDWouldBeSelected( p_current_es ))
+        if ( (p_output->config.i_nb_pids || !PIDWouldBeSelected( p_current_es ) || !AdditionalPIDFiltering( p_current_es ))
                && !IsIn( p_output->config.pi_pids, p_output->config.i_nb_pids,
                          i_pid ) )
              continue;
@@ -1645,6 +1652,60 @@ static bool PIDWouldBeSelected( uint8_t *p_es )
  }
  
  /*****************************************************************************
+ * AdditionalPIDFiltering
+ *****************************************************************************/
+static bool AdditionalPIDFiltering( uint8_t *p_es )
+{
+    uint8_t i_type = pmtn_get_streamtype( p_es );
+    int i=0;
+
+    if ( p_estypes == NULL)
+        return true;
+
+    for (i=0;i<i_nb_estypes;i++)
+    {
+        if ( i_type == p_estypes[i].i_es_type)
+        {
+            if ( p_estypes[i].i_tag == 0)
+                return true;
+
+            uint16_t j = 0;
+            const uint8_t *p_desc;
+            while ( (p_desc = descs_get_desc( pmtn_get_descs( p_es ), j )) != NULL )
+            {
+                uint8_t i_tag = desc_get_tag( p_desc );
+                j++;
+                uint8_t *p_desc_n = NULL;
+                uint16_t k = 0;
+                char lang[4] = {0};
+
+                if( i_tag == p_estypes[i].i_tag)
+                {
+                    #define IF_DESC(id)                                                                                  \
+                       if( i_tag == 0x##id)                                                                              \
+                       {                                                                                                 \
+                           while ( (p_desc_n = desc##id##_get_language((uint8_t*)p_desc, k)) != NULL )                   \
+                           {                                                                                             \
+                               snprintf(lang, sizeof(lang), "%3.3s", (const char *)desc##id##n_get_code(p_desc_n));      \
+                               if( p_estypes[i].psz_option && memcmp(p_estypes[i].psz_option, lang, sizeof(lang)) == 0)  \
+                                   return true;                                                                          \
+                               k++;                                                                                      \
+                           }                                                                                             \
+                       }
+
+                    IF_DESC(46);
+                    IF_DESC(56);
+                    IF_DESC(59);
+                    IF_DESC(0a);
+                }
+            }
+        }
+    }
+    return false;
+}
+
+
+/*****************************************************************************
   * PIDCarriesPES
   *****************************************************************************/
  static bool PIDCarriesPES( const uint8_t *p_es )
@@ -2298,7 +2359,9 @@ static void HandlePMT( uint16_t i_pid, uint8_t *p_pmt, mtime_t i_dts )
          j++;
  
          if ( PIDWouldBeSelected( p_es ) )
-            SelectPID( i_sid, i_pid );
+            if ( AdditionalPIDFiltering( p_es ) )
+                SelectPID( i_sid, i_pid );
+
          p_pids[i_pid].b_pes = PIDCarriesPES( p_es );
  
          if ( b_enable_ecm )
diff --git a/dvblast.c b/dvblast.c
index 03186f8..11468b0 100644
--- a/dvblast.c
+++ b/dvblast.c
@@ -127,6 +127,9 @@ void (*pf_Reset)( void ) = NULL;
  int (*pf_SetFilter)( uint16_t i_pid ) = NULL;
  void (*pf_UnsetFilter)( int i_fd, uint16_t i_pid ) = NULL;
  
+output_estype_options_t *p_estypes = NULL;
+int i_nb_estypes = 0;
+
  /*****************************************************************************
   * Configuration files
   *****************************************************************************/
@@ -359,11 +362,18 @@ static void config_ReadFile( char *psz_file )
          return;
      }
  
+    if (p_estypes != NULL)
+    {
+        free(p_estypes);
+        p_estypes = NULL;
+    }
+
      while ( fgets( psz_line, sizeof(psz_line), p_file ) != NULL )
      {
          output_config_t config;
          output_t *p_output;
          char *psz_token, *psz_parser;
+        char *psz_sub_token, *psz_sub_parser, *psz_estype;
  
          psz_parser = strchr( psz_line, '#' );
          if ( psz_parser != NULL )
@@ -410,9 +420,35 @@ static void config_ReadFile( char *psz_file )
                  psz_token = strtok_r( psz_token, ",", &psz_parser );
                  if ( psz_token == NULL )
                      break;
-                config.pi_pids = realloc( config.pi_pids,
+
+                if ( psz_token[0] == 'E')
+                {
+                    psz_estype = (char*) malloc(sizeof(char) * strlen(psz_token) + 1);
+                    memset(psz_estype, 0, strlen(psz_token) + 1);
+                    memcpy(psz_estype, psz_token+2, strlen(psz_token) + 1);
+                    p_estypes = realloc( p_estypes,
+                                 (i_nb_estypes + 1) * sizeof(output_estype_options_t));
+
+                    psz_sub_token = strtok_r( psz_estype, ":", &psz_sub_parser);
+                    if ( psz_sub_token != NULL)
+                        p_estypes[i_nb_estypes].i_es_type=strtol( psz_sub_token, NULL , 0);
+
+                    psz_sub_token = strtok_r( NULL, ":", &psz_sub_parser);
+                    if ( psz_sub_token != NULL )
+                        p_estypes[i_nb_estypes].i_tag = strtol(psz_sub_token, NULL, 0);
+
+                    psz_sub_token = strtok_r( NULL, ":", &psz_sub_parser);
+                    if ( psz_sub_token != NULL )
+                        p_estypes[i_nb_estypes].psz_option = strdup(psz_sub_token);
+
+                    i_nb_estypes++;
+                }
+                else
+                {
+                    config.pi_pids = realloc( config.pi_pids,
                                   (config.i_nb_pids + 1) * sizeof(uint16_t) );
-                config.pi_pids[config.i_nb_pids++] = strtol(psz_token, NULL, 0);
+                    config.pi_pids[config.i_nb_pids++] = strtol(psz_token, NULL, 0);
+                }
                  psz_token = NULL;
              }
          }
@@ -1140,6 +1176,9 @@ int main( int i_argc, char **pp_argv )
      demux_Close();
      free( p_network_name );
  
+    if ( p_estypes )
+      free(p_estypes);
+
      if ( b_enable_syslog )
          msg_Disconnect();
  
diff --git a/dvblast.h b/dvblast.h
index afae63c..776fe12 100644
--- a/dvblast.h
+++ b/dvblast.h
@@ -123,6 +123,13 @@ typedef struct output_config_t
      uint16_t pi_confpids[N_MAP_PIDS];
  } output_config_t;
  
+typedef struct output_estype_options_t
+{
+    int i_es_type;
+    int i_tag;
+    char *psz_option;
+} output_estype_options_t;
+
  typedef struct output_t
  {
      output_config_t config;
-- 
1.7.11.7





More information about the dvblast-devel mailing list