]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Store quality and status in settings
authorAndreas Öman <andreas@lonelycoder.com>
Mon, 25 Aug 2008 18:55:46 +0000 (18:55 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Mon, 25 Aug 2008 18:55:46 +0000 (18:55 +0000)
dvb/dvb_adapter.c
dvb/dvb_multiplex.c
dvb/dvb_support.c
dvb/dvb_support.h
tvhead.h
webui/extjs.c

index 99eb80d9e1ba7e7427ff981d89465d4d9c433cb1..acfddaea93b77c826152fc584f5c69432bca2e7a 100644 (file)
@@ -285,8 +285,9 @@ dvb_fec_monitor(void *aux, int64_t now)
 {
   th_dvb_adapter_t *tda = aux;
   th_dvb_mux_instance_t *tdmi;
-  int i, v, vv;
+  int i, v, vv, n;
   const char *s;
+  int savemux = 0;
 
   dtimer_arm(&tda->tda_fec_monitor_timer, dvb_fec_monitor, tda, 1);
 
@@ -316,26 +317,32 @@ dvb_fec_monitor(void *aux, int64_t now)
     }
   }
   
-
-  if(dvb_mux_status(tdmi, 1) != NULL) {
+  n = dvb_mux_badness(tdmi);
+  if(n > 0) {
     if(tdmi->tdmi_quality > -50) {
-      tdmi->tdmi_quality--;
+      tdmi->tdmi_quality -= n;
       dvb_notify_mux_quality(tdmi);
+      savemux = 1;
     }
   } else {
 
     if(tdmi->tdmi_quality < 0) {
       tdmi->tdmi_quality++;
       dvb_notify_mux_quality(tdmi);
+      savemux = 1;
     }
   }
 
-  s = dvb_mux_status(tdmi, 0);
-
-  if(s != tdmi->tdmi_last_status) {
-    tdmi->tdmi_last_status = s;
+  s = dvb_mux_status(tdmi);
+  if(strcmp(s, tdmi->tdmi_last_status)) {
+    free(tdmi->tdmi_last_status);
+    tdmi->tdmi_last_status = strdup(s);
     dvb_notify_mux_status(tdmi);
+    savemux = 1;
   }
+
+  if(savemux)
+    dvb_mux_save(tdmi);
 }
 
 
index cb81d1f79308cae211259e1a4663b1348ec9f799..0a5fbcfc86737a4ae14d9a8df57ea7ef7e5d0c72 100644 (file)
@@ -119,6 +119,7 @@ dvb_mux_create(th_dvb_adapter_t *tda, struct dvb_frontend_parameters *fe_param,
   tdmi->tdmi_transport_stream_id = tsid;
   tdmi->tdmi_adapter = tda;
   tdmi->tdmi_network = network ? strdup(network) : NULL;
+  tdmi->tdmi_last_status = strdup("Initializing");
 
   if(entries_before == 0 && tda->tda_rootpath != NULL) {
     /* First mux on adapter with backing hardware, start scanner */
@@ -321,6 +322,9 @@ dvb_mux_save(th_dvb_mux_instance_t *tdmi)
 
   htsmsg_t *m = htsmsg_create();
 
+  htsmsg_add_u32(m, "quality", -tdmi->tdmi_quality);
+  htsmsg_add_str(m, "status", tdmi->tdmi_last_status);
+
   htsmsg_add_u32(m, "transportstreamid", tdmi->tdmi_transport_stream_id);
   if(tdmi->tdmi_network != NULL)
     htsmsg_add_str(m, "network", tdmi->tdmi_network);
@@ -389,12 +393,13 @@ dvb_mux_save(th_dvb_mux_instance_t *tdmi)
 static const char *
 tdmi_create_by_msg(th_dvb_adapter_t *tda, htsmsg_t *m)
 {
+  th_dvb_mux_instance_t *tdmi;
   struct dvb_frontend_parameters f;
   const char *s;
   int r;
   int polarisation = 0;
   unsigned int switchport = 0;
-  unsigned int tsid;
+  unsigned int tsid, u32;
 
   memset(&f, 0, sizeof(f));
   
@@ -481,8 +486,18 @@ tdmi_create_by_msg(th_dvb_adapter_t *tda, htsmsg_t *m)
   if(htsmsg_get_u32(m, "transportstreamid", &tsid))
     tsid = 0xffff;
 
-  dvb_mux_create(tda, &f, polarisation, switchport,
-                tsid, htsmsg_get_str(m, "network"), NULL);
+  tdmi = dvb_mux_create(tda, &f, polarisation, switchport,
+                       tsid, htsmsg_get_str(m, "network"), NULL);
+  if(tdmi != NULL) {
+    s = htsmsg_get_str(m, "status");
+    if(s != NULL) {
+      free((void *)tdmi->tdmi_last_status);
+      tdmi->tdmi_last_status = strdup(s);
+    }
+
+    if(!htsmsg_get_u32(m, "quality", &u32)) 
+      tdmi->tdmi_quality = -u32;
+  }
   return NULL;
 }
 
index feb4a6e8a464fdc567363f94233083c194d31fe7..a594591548ba58e6aa0c7b25c5a4339a45344dde 100644 (file)
@@ -268,28 +268,45 @@ dvb_adapter_find_by_identifier(const char *identifier)
 
 
 /**
- * 
+ *  Return a readable status text for the given mux
  */
 const char *
-dvb_mux_status(th_dvb_mux_instance_t *tdmi, int nullisok)
+dvb_mux_status(th_dvb_mux_instance_t *tdmi)
 {
-  int i, v, vv;
-  const char *txt = tdmi->tdmi_status ?: (nullisok ? NULL : "Ok");
-
-  v = vv = 0;
-  for(i = 0; i < TDMI_FEC_ERR_HISTOGRAM_SIZE; i++) {
-    if(tdmi->tdmi_fec_err_histogram[i] > DVB_FEC_ERROR_LIMIT)
-      v++;
-    vv += tdmi->tdmi_fec_err_histogram[i];
-  }
-  vv /= TDMI_FEC_ERR_HISTOGRAM_SIZE;
+  int i, v = 0;
+
+  for(i = 0; i < TDMI_FEC_ERR_HISTOGRAM_SIZE; i++)
+    v += tdmi->tdmi_fec_err_histogram[i] > DVB_FEC_ERROR_LIMIT;
   
   if(v == TDMI_FEC_ERR_HISTOGRAM_SIZE)
-    txt = "Constant FEC";
+    return "Constant FEC";
   else if(v > 0)
-    txt = "Bursty FEC";
+    return "Bursty FEC";
+
+  return tdmi->tdmi_status ?: "OK";
+}
 
-  return txt;
+
+/**
+ * Return a badness value (0-3)
+ */
+int
+dvb_mux_badness(th_dvb_mux_instance_t *tdmi)
+{
+  int i, v = 0;
+
+  if(tdmi->tdmi_status)
+    return 3;
+
+  for(i = 0; i < TDMI_FEC_ERR_HISTOGRAM_SIZE; i++)
+    v += tdmi->tdmi_fec_err_histogram[i] > DVB_FEC_ERROR_LIMIT;
+
+  if(v == TDMI_FEC_ERR_HISTOGRAM_SIZE)
+    return 2;
+  else if(v > 0)
+    return 1;
+
+  return 0;
 }
 
 
index 8927a79a837ba6782770f06accb4f01d18f7c393..a7d04bbd5589a91adaa5938939e7b1a50d2b4584 100644 (file)
@@ -59,7 +59,9 @@ int dvb_str_to_adaptertype(const char *str);
 const char *dvb_polarisation_to_str(int pol);
 th_dvb_adapter_t *dvb_adapter_find_by_identifier(const char *identifier);
 th_dvb_mux_instance_t *dvb_mux_find_by_identifier(const char *identifier);
-const char *dvb_mux_status(th_dvb_mux_instance_t *tdmi, int nullisok);
 void dvb_mux_nicename(char *buf, size_t size, th_dvb_mux_instance_t *tdmi);
 int dvb_quality_to_percent(int qual);
+int dvb_mux_badness(th_dvb_mux_instance_t *tdmi);
+const char *dvb_mux_status(th_dvb_mux_instance_t *tdmi);
+
 #endif /* DVB_SUPPORT_H */
index 0f881635d94b0a2cbd275841c3ed04909d405ffe..50c47ad73a721d2a5dc86d38a78f98638d66d7e5 100644 (file)
--- a/tvhead.h
+++ b/tvhead.h
@@ -178,7 +178,7 @@ typedef struct th_dvb_mux_instance {
 
   dtimer_t tdmi_initial_scan_timer;
   const char *tdmi_status;
-  const char *tdmi_last_status; /* For notification updates */
+  char *tdmi_last_status; /* For notification updates */
 
   int tdmi_quality;
 
index 61c6e87292ca9c4af0b3db6cce7af007b01590e9..de826bd50bd8818e8ee6d4c02124e8acbeba7a61 100644 (file)
@@ -263,7 +263,7 @@ extjs_dvbtree(http_connection_t *hc, http_reply_t *hr,
      
       extjs_dvbtree_node(out, 0,
                         tdmi->tdmi_identifier, buf, "DVB Mux",
-                        dvb_mux_status(tdmi, 0), 
+                        tdmi->tdmi_last_status,
                         100 + tdmi->tdmi_quality * 2, "mux");
     }
   } else if((tdmi = dvb_mux_find_by_identifier(s)) != NULL) {