[libdvbpsi-devel] [Git][videolan/libdvbpsi][master] 3 commits: dvbinfo: correct expected continuity counter in error debug

Jean-Paul Saman (@jpsaman) gitlab at videolan.org
Thu Nov 21 14:51:23 UTC 2024



Jean-Paul Saman pushed to branch master at VideoLAN / libdvbpsi


Commits:
5a8890e9 by Jean-Paul Saman at 2024-11-21T13:30:39+01:00
dvbinfo: correct expected continuity counter in error debug

- - - - -
1e1c50df by Jean-Paul Saman at 2024-11-21T13:30:39+01:00
dvbinfo.c: use a summary file only when requested

- - - - -
d5d72168 by Jean-Paul Saman at 2024-11-21T14:47:58+01:00
dvbinfo: add some details on PAT/PMT in summary

- - - - -


2 changed files:

- examples/dvbinfo/dvbinfo.c
- examples/dvbinfo/libdvbpsi.c


Changes:

=====================================
examples/dvbinfo/dvbinfo.c
=====================================
@@ -353,6 +353,33 @@ static void *dvbinfo_capture(void *data)
     return NULL;
 }
 
+static void dvbinfo_write_summary_file(const char *psz_temp, dvbinfo_capture_t *capture,  ts_stream_t *stream)
+{
+    params_t *param = capture->params;
+
+    FILE *fd = fd = fopen(psz_temp, "w+");
+    if (!fd)
+    {
+        libdvbpsi_log(param, DVBINFO_LOG_ERROR,
+                        "failed opening summary file (disabling summary logging)\n");
+        param->b_summary = false;
+    }
+    else
+    {
+        libdvbpsi_summary(fd, stream, param->summary.mode);
+        fflush(fd);
+        fclose(fd);
+        unlink(param->summary.file); /* remove 'old' file */
+        int ret = rename(psz_temp, param->summary.file);
+        if (ret < 0)
+        {
+            libdvbpsi_log(param, DVBINFO_LOG_ERROR,
+                            "failed renming summary file (disabling summary logging)\n");
+            param->b_summary = false;
+        }
+    }
+}
+
 static int dvbinfo_process(dvbinfo_capture_t *capture)
 {
     int err = -1;
@@ -364,7 +391,7 @@ static int dvbinfo_process(dvbinfo_capture_t *capture)
     mtime_t deadline = 0;
     if (param->b_summary)
     {
-        if (asprintf(&psz_temp, "%s.part", param->summary.file) < 0)
+        if ((param->summary.file != NULL) && (asprintf(&psz_temp, "%s.part", param->summary.file) < 0))
         {
             libdvbpsi_log(param, DVBINFO_LOG_ERROR, "Could not create temporary summary file %s\n",
                           param->summary.file);
@@ -409,33 +436,17 @@ static int dvbinfo_process(dvbinfo_capture_t *capture)
             b_error = true;
 
         /* summary statistics */
-        if (param->b_summary)
+        if (param->b_summary && (mdate() >= deadline))
         {
-            if (mdate() >= deadline)
+            if (psz_temp)
             {
-                FILE *fd = fopen(psz_temp, "w+");
-                if (fd)
-                {
-                    libdvbpsi_summary(fd, stream, param->summary.mode);
-                    fflush(fd);
-                    fclose(fd);
-                    unlink(param->summary.file);
-                    int ret = rename(psz_temp, param->summary.file);
-                    if (ret < 0)
-                    {
-                        libdvbpsi_log(param, DVBINFO_LOG_ERROR,
-                                      "failed renming summary file (disabling summary logging)\n");
-                        param->b_summary = false;
-                    }
-                }
-                else
-                {
-                    libdvbpsi_log(param, DVBINFO_LOG_ERROR,
-                                  "failed opening summary file (disabling summary logging)\n");
-                    param->b_summary = false;
-                }
-                deadline = mdate() + param->summary.period;
+                dvbinfo_write_summary_file(psz_temp, capture, stream);
+            }
+            else
+            {
+                libdvbpsi_summary(stdout, stream, param->summary.mode);
             }
+            deadline = mdate() + param->summary.period;
         }
 
         /* reuse buffer */


=====================================
examples/dvbinfo/libdvbpsi.c
=====================================
@@ -491,29 +491,42 @@ static void summary(FILE *fd, ts_stream_t *stream)
     fprintf(fd, "\n=========================================================\n");
     fprintf(fd, "\nSummary: Bandwidth\n");
 
+    fprintf(fd, "\n---------------------------------------------------------\n");
+
+    if (stream->pat.handle && stream->pat.pid) {
+        fprintf(fd, "\nFound PAT: %4d (0x%4x), version %d,",
+                stream->pat.pid->i_pid, stream->pat.pid->i_pid, stream->pat.i_pat_version);
+
+        fprintf(fd, " seen %"PRId64" packets",
+                stream->pat.pid->i_packets);
+
+        i_packets += stream->pat.pid->i_packets;
+    }
+
     ts_pmt_t *pmt = stream->pmt;
     while (pmt) {
         /* Find PCR PID and get pcr timestamps */
-        fprintf(fd, "\n---------------------------------------------------------\n");
-        fprintf(fd, "\nFound PMT: %4d (0x%4x)\n", pmt->pid_pmt->i_pid, pmt->pid_pmt->i_pid);
+        fprintf(fd, "\nFound PMT: %4d (0x%4x),", pmt->pid_pmt->i_pid, pmt->pid_pmt->i_pid);
+        fprintf(fd, " seen %"PRId64" packets", pmt->pid_pmt->i_packets);
+        i_packets += pmt->pid_pmt->i_packets;
         if (!pmt->pid_pcr) {
-            fprintf(fd, "ERROR: PMT %4d (0x%4x) has no PCR defined\n",
+            fprintf(fd, "\nERROR: PMT %4d (0x%4x) has no PCR defined\n",
                         pmt->pid_pmt->i_pid, pmt->pid_pmt->i_pid);
             /* Next PMT */
             pmt = pmt->p_next;
             continue;
         }
-        fprintf(fd, "Found PCR: %4d (0x%4x)\n", pmt->pid_pcr->i_pid, pmt->pid_pcr->i_pid);
+        fprintf(fd, "\nFound PCR: %4d (0x%4x),", pmt->pid_pcr->i_pid, pmt->pid_pcr->i_pid);
 
-        int i_pmt_pid = pmt->pid_pcr->i_pid;
-        if (stream->pid[i_pmt_pid].b_pcr)
+        int i_pcr_pid = pmt->pid_pcr->i_pid;
+        if (stream->pid[i_pcr_pid].b_pcr)
         {
-            start = stream->pid[i_pmt_pid].i_first_pcr;
-            end = stream->pid[i_pmt_pid].i_last_pcr;
-            if (stream->pid[i_pmt_pid].b_discontinuity_indicator)
+            start = stream->pid[i_pcr_pid].i_first_pcr;
+            end = stream->pid[i_pcr_pid].i_last_pcr;
+            if (stream->pid[i_pcr_pid].b_discontinuity_indicator)
             {
                 fprintf(fd, "PCR discontinuity was signalled for PID: %4d (0x%4x)\n",
-                        i_pmt_pid, i_pmt_pid);
+                        i_pcr_pid, i_pcr_pid);
             }
         }
 
@@ -523,7 +536,7 @@ static void summary(FILE *fd, ts_stream_t *stream)
             if ((stream->pid[i_pid].pid_pmt == pmt->pid_pmt) &&
                  stream->pid[i_pid].b_seen )
             {
-                fprintf(fd, "Found PID: %4d (0x%4x), DRM: %s,", i_pid, i_pid,
+                fprintf(fd, "\nFound PID: %4d (0x%4x), DRM: %s,", i_pid, i_pid,
                         (stream->pid[i_pid].i_transport_scrambling_control != 0x00) ? "yes" : " no" );
 
                 double bitrate = 0;
@@ -535,7 +548,6 @@ static void summary(FILE *fd, ts_stream_t *stream)
                 fprintf(fd, " bitrate %0.4f kbit/s,", bitrate);
                 fprintf(fd, " seen %"PRId64" packets",
                         stream->pid[i_pid].i_packets);
-                fprintf(fd, "\n");
 
                 i_packets += stream->pid[i_pid].i_packets;
                 if (i_first_pcr == 0)
@@ -547,13 +559,15 @@ static void summary(FILE *fd, ts_stream_t *stream)
         }
         /* Print totals */
         double total_bitrate = (double)(((i_packets*188) + stream->i_lost_bytes) * 8)/((double)(i_last_pcr - i_first_pcr)/1000.0);
-        fprintf(fd, "\nTotal bitrate %0.4f kbits/s\n", total_bitrate);
+        fprintf(fd, "\n\nTotal bitrate %0.4f kbits/s\n", total_bitrate);
 
         fprintf(fd, "Number of packets: %"PRId64", stuffing %"PRId64" packets, lost %"PRId64" bytes\n",
                 i_packets, stream->i_null_packets, stream->i_lost_bytes);
         fprintf(fd, "PCR first: %"PRId64", last: %"PRId64", duration: %"PRId64"\n",
                 i_first_pcr, i_last_pcr, (mtime_t)(i_last_pcr - i_first_pcr));
 
+        fprintf(fd, "\n---------------------------------------------------------\n");
+
         /* Next PMT */
         pmt = pmt->p_next;
     }
@@ -3132,7 +3146,7 @@ bool libdvbpsi_process(ts_stream_t *stream, uint8_t *buf, ssize_t length, mtime_
         {
             stream->pf_log(stream->cb_data, 2,
                            "dvbinfo: Continuity counter discontinuity (pid %u 0x%x found %d expected %d)\n",
-                           i_pid, i_pid, stream->pid[i_pid].i_cc, i_old_cc+1);
+                           i_pid, i_pid, stream->pid[i_pid].i_cc, (i_old_cc+1)%16);
 
             /* Discontinuity has been handled */
             b_discontinuity_seen = false;



View it on GitLab: https://code.videolan.org/videolan/libdvbpsi/-/compare/89b53ce767f51f24bad7707ef3ddadb64a9dc383...d5d72168117cd7a22b82435983b347ab1e2ef598

-- 
View it on GitLab: https://code.videolan.org/videolan/libdvbpsi/-/compare/89b53ce767f51f24bad7707ef3ddadb64a9dc383...d5d72168117cd7a22b82435983b347ab1e2ef598
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the libdvbpsi-devel mailing list