[dvblast-devel] Saving EPG to a file

Nuno Mota mundumelga at gmail.com
Tue Oct 1 18:58:14 CEST 2013


Hi,

This is not the correct way to write this code but this is what works for
me. After saving to a file I parse it for XMLTV.dtd.

This is for those who really need this and might need some ideas.

Index: demux.c
===================================================================
RCS file: /var/dvblast-2.2/Attic/demux.c,v
retrieving revision 1.1.2.1.24.2
retrieving revision 1.1.2.1.24.2.46.3
diff -u -r1.1.2.1.24.2 -r1.1.2.1.24.2.46.3
--- demux.c    8 Mar 2013 12:40:18 -0000    1.1.2.1.24.2
+++ demux.c    27 Sep 2013 17:18:40 -0000    1.1.2.1.24.2.46.3
@@ -1036,6 +1036,18 @@
     bool b_epg = i_table_id >= EIT_TABLE_ID_SCHED_ACTUAL_FIRST &&
                  i_table_id <= EIT_TABLE_ID_SCHED_ACTUAL_LAST;
     int i;
+    uint8_t *p_event;
+    uint16_t current_event_id;
+
+    // Persistent values
+    static uint16_t this_event_id = 0;
+    static time_t wait_time = 0;
+    static time_t end_time = 0;
+
+    if ( wait_time == 0 )
+    {
+        wait_time = time(NULL);
+    }

     for ( i = 0; i < i_nb_outputs; i++ )
     {
@@ -1052,6 +1064,47 @@
                 psi_set_crc( p_eit );
             }

+            /*
+             * Checking if there are any events at all for this EIT.
+             * If not don't even print the empty EIT table
+             */
+            if ((p_event = eit_get_event(p_eit, 0)) == NULL)
+            {
+                return;
+            }
+            else if ( wait_time < time(NULL) )
+            {
+                current_event_id = eitn_get_event_id(p_event);
+
+                if ( this_event_id == 0 )
+                {
+                    // Make sure we start with an actual PF as it occurs
more often
+                    if (psi_get_tableid(p_eit) != EIT_TABLE_ID_PF_ACTUAL)
+                         return;
+
+                    this_event_id = current_event_id;
+                    end_time = time(NULL) + EPG_TIMEOUT;
+
+                    msg_Dbg( NULL, "Starting EIT parser with event id :
%d", this_event_id);
+                }
+                else if ( (this_event_id == current_event_id &&
psi_get_tableid(p_eit) == EIT_TABLE_ID_PF_ACTUAL)
+                          || end_time < time(NULL) )
+                {
+                    msg_Dbg( NULL, "Stopping EIT parser");
+
+                    // Resetting event id
+                    this_event_id = 0;
+                    // Scheduling next EPG grab
+                    wait_time = time(NULL) + EPG_INTERVAL;
+                    // Rename to final XML
+                    rename (epg_file_tmp, epg_file);
+
+                    return;
+                }
+
+                eit_print( p_eit, msg_Epg, NULL, demux_Iconv, NULL,
PRINT_XML );
+            }
+
             OutputPSISection( p_output, p_eit, EIT_PID,
&p_output->i_eit_cc,
                               i_dts, &p_output->p_eit_ts_buffer,
                               &p_output->i_eit_ts_buffer_offset );
Index: dvblast.c
===================================================================
RCS file: /var/dvblast-2.2/Attic/dvblast.c,v
retrieving revision 1.1.2.1.24.2
retrieving revision 1.1.2.1.24.2.46.1
diff -u -r1.1.2.1.24.2 -r1.1.2.1.24.2.46.1
--- dvblast.c    8 Mar 2013 12:40:18 -0000    1.1.2.1.24.2
+++ dvblast.c    26 Sep 2013 16:09:46 -0000    1.1.2.1.24.2.46.1
@@ -119,6 +119,10 @@
 int (*pf_SetFilter)( uint16_t i_pid ) = NULL;
 void (*pf_UnsetFilter)( int i_fd, uint16_t i_pid ) = NULL;

+/* EPG default  */
+char epg_file_tmp[EPG_NAME];
+char epg_file[EPG_NAME];
+
 /*****************************************************************************
  * Configuration files

*****************************************************************************/
@@ -879,6 +883,13 @@
         b_dvb_global = true;
     }

+    if ( b_epg_global )
+    {
+        // Create EPG file string
+        sprintf (epg_file_tmp, "/tmp/epg_adapter%d.tmp", i_adapter);
+        sprintf (epg_file, "/tmp/epg_adapter%d.xml", i_adapter);
+    }
+
     memset( &output_dup, 0, sizeof(output_dup) );
     if ( psz_dup_config != NULL )
     {
Index: dvblast.h
===================================================================
RCS file: /var/dvblast-2.2/Attic/dvblast.h,v
retrieving revision 1.1.2.1.24.3
retrieving revision 1.1.2.1.24.3.44.4
diff -u -r1.1.2.1.24.3 -r1.1.2.1.24.3.44.4
--- dvblast.h    2 Apr 2013 14:52:29 -0000    1.1.2.1.24.3
+++ dvblast.h    1 Oct 2013 14:22:09 -0000    1.1.2.1.24.3.44.4
@@ -43,6 +43,10 @@
 #define DEFAULT_FRONTEND_TIMEOUT 30000000 /* 30 s */
 #define EXIT_STATUS_FRONTEND_TIMEOUT 100

+#define EPG_NAME 50
+#define EPG_TIMEOUT 60
+#define EPG_INTERVAL 600
+
 /*****************************************************************************
  * Output configuration flags (for output_t -> i_config) - bit values
  * Bit  0 : Set for watch mode
@@ -193,6 +197,9 @@
 extern int (*pf_SetFilter)( uint16_t i_pid );
 extern void (*pf_UnsetFilter)( int i_fd, uint16_t i_pid );

+extern char epg_file_tmp[];
+extern char epg_file[];
+
 /*****************************************************************************
  * Prototypes

*****************************************************************************/
@@ -212,6 +219,7 @@
 __attribute__ ((format(printf, 2, 3))) void msg_Dbg( void *_unused, const
char *psz_format, ... );
 __attribute__ ((format(printf, 2, 3))) void msg_Raw( void *_unused, const
char *psz_format, ... );
 __attribute__ ((format(printf, 2, 3))) void msg_Crit( void *_unused, const
char *psz_format, ... );
+__attribute__ ((format(printf, 2, 3))) void msg_Epg( void *_unused, const
char *psz_format, ... );

 /* */
 bool streq(char *a, char *b);
Index: dvblastctl.c
===================================================================
RCS file: /var/dvblast-2.2/Attic/dvblastctl.c,v
retrieving revision 1.1.2.1.24.2
retrieving revision 1.1.2.1.24.2.46.1
diff -u -r1.1.2.1.24.2 -r1.1.2.1.24.2.46.1
--- dvblastctl.c    8 Mar 2013 12:40:18 -0000    1.1.2.1.24.2
+++ dvblastctl.c    26 Sep 2013 16:09:46 -0000    1.1.2.1.24.2.46.1
@@ -56,6 +56,9 @@
 int i_fd = -1;
 char psz_client_socket[PATH_MAX] = {0};

+/* Never used here. For compilation reasons only  */
+char epg_file_tmp[EPG_NAME];
+
 static void clean_client_socket() {
     if ( i_fd > -1 )
     {
Index: util.c
===================================================================
RCS file: /var/dvblast-2.2/Attic/util.c,v
retrieving revision 1.1.2.1.24.2
retrieving revision 1.1.2.1.24.1.44.2
diff -u -r1.1.2.1.24.2 -r1.1.2.1.24.1.44.2
--- util.c    26 Sep 2013 16:16:13 -0000    1.1.2.1.24.2
+++ util.c    26 Sep 2013 16:18:06 -0000    1.1.2.1.24.1.44.2
@@ -65,6 +65,8 @@
 {
     i_syslog = 0;
     closelog();
+
+    unlink (epg_file_tmp);
 }

 /*****************************************************************************
@@ -176,6 +178,23 @@
 }

 /*****************************************************************************
+ * msg_Epg
+
*****************************************************************************/
+void msg_Epg( void *_unused, const char *psz_format, ... )
+{
+    FILE * pFile;
+    va_list args;
+
+    pFile = fopen (epg_file_tmp,"a");
+
+    va_start( args, psz_format );
+    vfprintf( pFile, psz_format, args );
+
+    fclose (pFile);
+
+}
+
+/*****************************************************************************
  * streq

*****************************************************************************/
 inline bool streq(char *a, char *b) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/dvblast-devel/attachments/20131001/9c3d68d4/attachment.html>


More information about the dvblast-devel mailing list