All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: vidtv: add a poor guy's simulation to preBER stats
@ 2020-09-15  8:09 Mauro Carvalho Chehab
  0 siblings, 0 replies; only message in thread
From: Mauro Carvalho Chehab @ 2020-09-15  8:09 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

A typical digital TV stream has errors that are corrected
by Viterbi. While the error rate after Viterbi is usually
zero, with good signals, there are some chances of getting
random errors before that, which are auto-corrected by
the error code algorithm.

Add a poor guy's implementation that would show some
noise at the pre-BER part of the demod.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/test-drivers/vidtv/vidtv_mux.c | 23 ++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_mux.c b/drivers/media/test-drivers/vidtv/vidtv_mux.c
index 5d1a275d504b..26a742c95c76 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_mux.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_mux.c
@@ -21,6 +21,7 @@
 #include <linux/delay.h>
 #include <linux/vmalloc.h>
 #include <linux/math64.h>
+
 #include "vidtv_mux.h"
 #include "vidtv_ts.h"
 #include "vidtv_pes.h"
@@ -376,6 +377,7 @@ static void vidtv_mux_clear(struct vidtv_mux *m)
 	m->mux_buf_offset = 0;
 }
 
+#define ERR_RATE 10000000
 static void vidtv_mux_tick(struct work_struct *work)
 {
 	struct vidtv_mux *m = container_of(work,
@@ -384,6 +386,7 @@ static void vidtv_mux_tick(struct work_struct *work)
 	struct dtv_frontend_properties *c = &m->fe->dtv_property_cache;
 	u32 nbytes;
 	u32 npkts;
+	u32 tot_bits = 0;
 
 	while (m->streaming) {
 		nbytes = 0;
@@ -419,10 +422,26 @@ static void vidtv_mux_tick(struct work_struct *work)
 		 * but post BER count can be lower than pre BER, if the error
 		 * correction logic discards packages.
 		 */
-		c->pre_bit_count.stat[0].uvalue = nbytes;
-		c->post_bit_count.stat[0].uvalue = nbytes;
+		c->pre_bit_count.stat[0].uvalue = nbytes * 8;
+		c->post_bit_count.stat[0].uvalue = nbytes * 8;
 		c->block_count.stat[0].uvalue += npkts;
 
+		/*
+		 * Even without any visible errors for the user, the pre-BER
+		 * stats usually have an error range up to 1E-6. So,
+		 * add some random error increment count to it.
+		 *
+		 * Please notice that this is a poor guy's implementation,
+		 * as it will produce one corrected bit error every time
+		 * ceil(total bytes / ERR_RATE) is incremented, without
+		 * any sort of (pseudo-)randomness.
+		 */
+		tot_bits += nbytes * 8;
+		if (tot_bits > ERR_RATE) {
+			c->pre_bit_error.stat[0].uvalue++;
+			tot_bits -= ERR_RATE;
+		}
+
 		usleep_range(VIDTV_SLEEP_USECS, VIDTV_MAX_SLEEP_USECS);
 	}
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-15  8:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-15  8:09 [PATCH] media: vidtv: add a poor guy's simulation to preBER stats Mauro Carvalho Chehab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.