[dvblast-devel] [PATCH 15/20] dvblastctl: Add get_pids and get_pid <pid> commands.

Georgi Chorbadzhiyski gf at unixsol.org
Mon Sep 5 09:52:50 CEST 2011


---
 NEWS         |    1 +
 comm.c       |   28 ++++++++++++++++++++
 comm.h       |    9 ++++++
 dvblastctl.c |   82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 119 insertions(+), 1 deletions(-)

diff --git a/NEWS b/NEWS
index 2d65e84..3e59ad7 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,7 @@ Changes between 1.2 and 2.0:
   * Add detailed information for TS errors
   * Add support for getting PAT/CAT/NIT/SDT tables in dvblastctl
   * Add support for getting PMT table for chosen service in dvblastctl
+  * Add support for getting PID information (bps, error counters and more)
 
 Changes between 1.1 and 1.2:
 ----------------------------
diff --git a/comm.c b/comm.c
index 3119690..8f17747 100644
--- a/comm.c
+++ b/comm.c
@@ -80,6 +80,7 @@ void comm_Read( void )
     uint8_t *p_packed_section;
     unsigned int i_packed_section_size;
     uint8_t *p_input = p_buffer + COMM_HEADER_SIZE;
+    uint8_t *p_output = p_answer + COMM_HEADER_SIZE;
 
     i_size = recvfrom( i_comm_fd, p_buffer, COMM_BUFFER_SIZE, 0,
                        (struct sockaddr *)&sun_client, &sun_length );
@@ -219,6 +220,33 @@ void comm_Read( void )
         break;
     }
 
+    case CMD_GET_PIDS:
+    {
+        i_answer = RET_PIDS;
+        i_answer_size = sizeof(struct cmd_pid_info);
+        demux_get_PIDS_info( p_output );
+        break;
+    }
+
+    case CMD_GET_PID:
+    {
+        if ( i_size < COMM_HEADER_SIZE + 2 )
+        {
+            msg_Err( NULL, "command packet is too short (%zd)\n", i_size );
+            return;
+        }
+
+        uint16_t i_pid = (uint16_t)((p_input[0] << 8) | p_input[1]);
+        if ( i_pid >= MAX_PIDS ) {
+            i_answer = RET_NODATA;
+        } else {
+            i_answer = RET_PID;
+            i_answer_size = sizeof(ts_pid_info_t);
+            demux_get_PID_info( i_pid, p_output );
+        }
+        break;
+    }
+
     default:
         msg_Err( NULL, "wrong command %u", i_command );
         i_answer = RET_HUH;
diff --git a/comm.h b/comm.h
index 45372ef..e056d67 100644
--- a/comm.h
+++ b/comm.h
@@ -41,6 +41,8 @@
 #define CMD_GET_NIT 12
 #define CMD_GET_SDT 13
 #define CMD_GET_PMT 14 /* arg: service_id (uint16_t) */
+#define CMD_GET_PIDS 15
+#define CMD_GET_PID 16 /* arg: pid (uint16_t) */
 
 #define RET_OK 0
 #define RET_ERR 1
@@ -55,6 +57,8 @@
 #define RET_NIT 10
 #define RET_SDT 11
 #define RET_PMT 12
+#define RET_PIDS 13
+#define RET_PID 14
 #define RET_HUH 255
 
 struct ret_frontend_status
@@ -84,3 +88,8 @@ struct cmd_mmi_send
     uint8_t i_slot;
     en50221_mmi_object_t object;
 };
+
+struct cmd_pid_info
+{
+    ts_pid_info_t pids[MAX_PIDS];
+};
diff --git a/dvblastctl.c b/dvblastctl.c
index ef2e1aa..3af3c81 100644
--- a/dvblastctl.c
+++ b/dvblastctl.c
@@ -53,6 +53,7 @@ int i_verbose = 3;
 int i_syslog = 0;
 
 print_type_t i_print_type = PRINT_TEXT;
+mtime_t now;
 
 /*****************************************************************************
  * The following two functinos are from biTStream's examples and are under the
@@ -83,11 +84,60 @@ char *psi_iconv(void *_unused, const char *psz_encoding,
     return iconv_append_null(p_string, i_length);
 }
 
+void print_pids_header( void )
+{
+    if ( i_print_type == PRINT_XML )
+        printf("<PIDS>\n");
+}
+
+void print_pids_footer( void )
+{
+    if ( i_print_type == PRINT_XML )
+        printf("</PIDS>\n");
+}
+
+void print_pid(uint16_t i_pid, ts_pid_info_t *p_info)
+{
+    if ( p_info->i_packets == 0 )
+        return;
+    if ( i_print_type == PRINT_TEXT )
+        printf("pid %d packn %lu ccerr %lu tserr %lu scramble %d Bps %lu seen %"PRId64"\n",
+            i_pid,
+            p_info->i_packets,
+            p_info->i_cc_errors,
+            p_info->i_transport_errors,
+            p_info->i_scrambling,
+            p_info->i_bytes_per_sec,
+            now - p_info->i_last_packet_ts
+        );
+    else
+        printf("<PID pid=\"%d\" packn=\"%lu\" ccerr=\"%lu\" tserr=\"%lu\" scramble=\"%d\" Bps=\"%lu\" seen=\"%"PRId64"\" />\n",
+            i_pid,
+            p_info->i_packets,
+            p_info->i_cc_errors,
+            p_info->i_transport_errors,
+            p_info->i_scrambling,
+            p_info->i_bytes_per_sec,
+            now - p_info->i_last_packet_ts
+        );
+}
+
+void print_pids( uint8_t *p_data )
+{
+    int i_pid;
+    print_pids_header();
+    for ( i_pid = 0; i_pid < MAX_PIDS; i_pid++ ) {
+        ts_pid_info_t *p_info = (ts_pid_info_t *)(p_data + i_pid * sizeof(ts_pid_info_t));
+        print_pid( i_pid, p_info );
+    }
+    print_pids_footer();
+}
+
 void usage()
 {
     msg_Raw( NULL, "DVBlastctl %d.%d.%d (%s)", VERSION_MAJOR, VERSION_MINOR,
              VERSION_REVISION, VERSION_EXTRA );
-    msg_Raw( NULL, "Usage: dvblastctl -r <remote socket> reload|shutdown|fe_status|mmi_status|mmi_open|mmi_close|mmi_get|mmi_send_text|mmi_send_choice|get_pat|get_cat|get_nit|get_sdt|get_pmt [<ServiceID>] [<CAM slot>] [-x <text|xml>] [<text/choice>]" );
+    msg_Raw( NULL, "Usage: dvblastctl -r <remote socket> reload|shutdown|fe_status|mmi_status|mmi_open|mmi_close|mmi_get|mmi_send_text|mmi_send_choice|get_pat|get_cat|get_nit|get_sdt|get_pmt|get_pids|get_pid [<PID>] [<ServiceID>] [<CAM slot>] [-x <text|xml>] [<text/choice>]" );
     exit(1);
 }
 
@@ -102,6 +152,7 @@ int main( int i_argc, char **ppsz_argv )
     struct sockaddr_un sun_client, sun_server;
     uint8_t p_buffer[COMM_BUFFER_SIZE];
     uint8_t *p_data = p_buffer + COMM_HEADER_SIZE;
+    uint16_t i_pid = 0;
 
     for ( ; ; )
     {
@@ -152,6 +203,8 @@ int main( int i_argc, char **ppsz_argv )
           && strcmp(ppsz_argv[optind], "get_nit")
           && strcmp(ppsz_argv[optind], "get_sdt")
           && strcmp(ppsz_argv[optind], "get_pmt")
+          && strcmp(ppsz_argv[optind], "get_pid")
+          && strcmp(ppsz_argv[optind], "get_pids")
           && strcmp(ppsz_argv[optind], "mmi_status")
           && strcmp(ppsz_argv[optind], "mmi_slot_status")
           && strcmp(ppsz_argv[optind], "mmi_open")
@@ -163,6 +216,7 @@ int main( int i_argc, char **ppsz_argv )
 
     if ( (!strcmp(ppsz_argv[optind], "mmi_slot_status")
            || !strcmp(ppsz_argv[optind], "get_pmt")
+           || !strcmp(ppsz_argv[optind], "get_pid")
            || !strcmp(ppsz_argv[optind], "mmi_open")
            || !strcmp(ppsz_argv[optind], "mmi_close")
            || !strcmp(ppsz_argv[optind], "mmi_get")
@@ -242,6 +296,14 @@ int main( int i_argc, char **ppsz_argv )
         i_size = COMM_HEADER_SIZE + 2;
         p_data[0] = (uint8_t)((i_sid >> 8) & 0xff);
         p_data[1] = (uint8_t)(i_sid & 0xff);
+    } else if ( !strcmp(ppsz_argv[optind], "get_pids") )
+        p_buffer[1] = CMD_GET_PIDS;
+    else if ( !strcmp(ppsz_argv[optind], "get_pid") ) {
+        i_pid = (uint16_t)atoi(ppsz_argv[optind + 1]);
+        p_buffer[1] = CMD_GET_PID;
+        i_size = COMM_HEADER_SIZE + 2;
+        p_data[0] = (uint8_t)((i_pid >> 8) & 0xff);
+        p_data[1] = (uint8_t)(i_pid & 0xff);
     } else if ( !strcmp(ppsz_argv[optind], "mmi_status") )
         p_buffer[1] = CMD_MMI_STATUS;
     else
@@ -340,6 +402,8 @@ int main( int i_argc, char **ppsz_argv )
         exit(255);
     }
 
+    now = mdate();
+
     switch ( p_buffer[1] )
     {
     case RET_OK:
@@ -395,6 +459,22 @@ int main( int i_argc, char **ppsz_argv )
         break;
     }
 
+    case RET_PID:
+    {
+        print_pids_header();
+        print_pid( i_pid, (ts_pid_info_t *)p_data );
+        print_pids_footer();
+        exit(0);
+        break;
+    }
+
+    case RET_PIDS:
+    {
+        print_pids( p_data );
+        exit(0);
+        break;
+    }
+
     case RET_FRONTEND_STATUS:
     {
         struct ret_frontend_status *p_ret =
-- 
1.7.5.1



More information about the dvblast-devel mailing list