add functions for dropping packets when in iptv output

This commit is contained in:
Andreas Öman 2007-11-28 09:51:07 +00:00
parent 44e7245df2
commit 75e157f24f
3 changed files with 37 additions and 2 deletions

View file

@ -39,9 +39,15 @@
#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),

12
tsmux.c
View file

@ -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;

View file

@ -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;