]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
add functions for dropping packets when in iptv output
authorAndreas Öman <andreas@lonelycoder.com>
Wed, 28 Nov 2007 09:51:07 +0000 (09:51 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Wed, 28 Nov 2007 09:51:07 +0000 (09:51 +0000)
iptv_output.c
tsmux.c
tvhead.h

index f6162d68df425212d01b3e1c91887e78116fbff0..f912970966338037b53077c3e05e388a7128af1c 100644 (file)
 #define MULTICAST_PKT_SIZ (188 * 7)
 
 typedef struct output_multicast {
-  void *om_muxer;
+  th_muxer_t *om_muxer;
   int om_fd;
   struct sockaddr_in om_dst;
+
+  int om_intra_drop_rate;
+
+  int om_inter_drop_rate;
+  int om_inter_drop_cnt;
+
 } output_multicast_t;
 
 /**
@@ -53,6 +59,12 @@ iptv_output_ts(void *opaque, th_subscription_t *s,
 {
   output_multicast_t *om = opaque;
 
+  if(om->om_inter_drop_rate && 
+     ++om->om_inter_drop_cnt == om->om_inter_drop_rate) {
+    om->om_inter_drop_cnt = 0;
+    return;
+  }
+
   sendto(om->om_fd, pkt, blocks * 188, 0, 
         (struct sockaddr *)&om->om_dst, sizeof(struct sockaddr_in));
 }
@@ -71,6 +83,8 @@ iptv_subscription_callback(struct th_subscription *s,
   case TRANSPORT_AVAILABLE:
     assert(om->om_muxer == NULL);
     om->om_muxer = ts_muxer_init(s, iptv_output_ts, om, 0);
+    om->om_muxer->tm_drop_rate = om->om_intra_drop_rate;
+    printf("intrarate = %d\n", om->om_muxer->tm_drop_rate);
     ts_muxer_play(om->om_muxer, 0);
     break;
 
@@ -136,6 +150,13 @@ output_multicast_load(struct config_head *head)
   if((s = config_get_str_sub(head, "ttl", NULL)) != NULL)
     ttl = atoi(s);
 
+
+  if((s = config_get_str_sub(head, "intra-drop-rate", NULL)) != NULL)
+    om->om_intra_drop_rate = atoi(s);
+
+  if((s = config_get_str_sub(head, "inter-drop-rate", NULL)) != NULL)
+    om->om_inter_drop_rate = atoi(s);
+
   setsockopt(om->om_fd, SOL_IP, IP_MULTICAST_TTL, &ttl, sizeof(int));
 
   snprintf(title, sizeof(title), "%s:%d", inet_ntoa(om->om_dst.sin_addr),
diff --git a/tsmux.c b/tsmux.c
index a7518bf9152eca60889f75903aeee17aa157395e..485cf7c2900323c16eeda33893cbfd2cf5100408 100644 (file)
--- a/tsmux.c
+++ b/tsmux.c
@@ -371,8 +371,18 @@ ts_mux_packet(th_muxer_t *tm, int64_t pcr, uint8_t *outbuf, int maxblocks)
     /* Generate a transport stream packet */
 
     if(ts_make_pkt(tm, tms, outbuf, pcr1) == 0) {
-      outbuf += 188;
       rem = pkt_len(pkt) - tms->tms_offset;
+
+      /* Periodic drop (for testing purposes) */
+
+      if(i != 0 && i != maxblocks - 1 &&
+        tm->tm_drop_rate && ++tm->tm_drop_cnt == tm->tm_drop_rate) {
+       tm->tm_drop_cnt = 0;
+       i--;
+      } else {
+       outbuf += 188;
+      }
+
     } else {
       i--;
       rem = 0;
index d527b34027628f620553678a72b87550f34ab1aa..1d1499962eeaf7e33224f15e10de07de69ebad6f 100644 (file)
--- a/tvhead.h
+++ b/tvhead.h
@@ -561,6 +561,10 @@ typedef struct th_muxer {
   th_muxstream_t *tm_pmt;
 
   struct AVFormatContext *tm_avfctx;
+
+  int tm_drop_rate;
+  int tm_drop_cnt;
+
 } th_muxer_t;