Add support for deliberate corruption of generated MPEG TS streams

This commit is contained in:
Andreas Öman 2008-02-05 11:27:57 +00:00
parent c891a87e87
commit 9df2cfbe53
6 changed files with 35 additions and 14 deletions

View file

@ -410,7 +410,7 @@ client_subscription_callback(struct th_subscription *s,
case TRANSPORT_AVAILABLE:
assert(c->c_muxer == NULL);
c->c_muxer = ts_muxer_init(s, client_output_ts, c,
TS_HTSCLIENT | TS_SEEK);
TS_HTSCLIENT | TS_SEEK, 0);
ts_muxer_play(c->c_muxer, 0);
break;

View file

@ -44,7 +44,7 @@ typedef struct output_multicast {
int om_fd;
struct sockaddr_in om_dst;
int om_intra_drop_rate;
int om_corruption;
int om_inter_drop_rate;
int om_inter_drop_cnt;
@ -101,8 +101,8 @@ iptv_subscription_callback(struct th_subscription *s,
switch(event) {
case TRANSPORT_AVAILABLE:
assert(om->om_muxer == NULL);
om->om_muxer = ts_muxer_init(s, iptv_output_ts, om, TS_SEEK);
// om->om_muxer->tm_drop_rate = om->om_intra_drop_rate;
om->om_muxer = ts_muxer_init(s, iptv_output_ts, om, TS_SEEK,
om->om_corruption);
ts_muxer_play(om->om_muxer, 0);
break;
@ -166,8 +166,8 @@ output_multicast_load(struct config_head *head)
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, "corruption-interval", NULL)) != NULL)
om->om_corruption = atoi(s);
if((s = config_get_str_sub(head, "inter-drop-rate", NULL)) != NULL)
om->om_inter_drop_rate = atoi(s);

2
rtsp.c
View file

@ -124,7 +124,7 @@ rtsp_subscription_callback(struct th_subscription *s,
case TRANSPORT_AVAILABLE:
assert(rs->rs_muxer == NULL);
rs->rs_muxer = ts_muxer_init(s, rtp_output_ts, &rs->rs_rtp_streamer,
TS_SEEK);
TS_SEEK, 0);
break;
case TRANSPORT_UNAVAILABLE:

26
tsmux.c
View file

@ -366,7 +366,7 @@ lookahead_dequeue(ts_muxer_t *ts, th_muxstream_t *tms)
if(tms->tms_mux_offset == AV_NOPTS_VALUE) {
if(tms->tms_stream->st_vbv_delay == -1)
tms->tms_mux_offset = tdur + pkt->pkt_duration;
tms->tms_mux_offset = tdur - pkt->pkt_duration;
else
tms->tms_mux_offset = tms->tms_stream->st_vbv_delay;
}
@ -532,15 +532,31 @@ lookahead_dequeue(ts_muxer_t *ts, th_muxstream_t *tms)
*tsb++ = u16 >> 8;
*tsb++ = u16;
}
memcpy(tsb, pkt->pkt_payload + off, tsrem);
if(tms->tms_corruption_interval != 0) {
/* Only corruption payload, never the header */
if(tms->tms_corruption_last + tms->tms_corruption_interval < pcr &&
off != 0 && pkt->pkt_frametype == PKT_I_FRAME) {
tms->tms_corruption_counter = 50;
tms->tms_corruption_last = pcr;
}
if(tms->tms_corruption_counter) {
tms->tms_cc++;
tms->tms_corruption_counter--;
}
}
tm->tm_contentsize = tsrem;
tmf_enq(&tms->tms_delivery_fifo, tm);
toff += tsrem;
off += tsrem;
}
}
tms->tms_lookahead_depth -= pkt->pkt_payloadlen;
tms->tms_lookahead_packets--;
@ -587,7 +603,7 @@ ts_mux_packet_input(void *opaque, th_muxstream_t *tms, th_pkt_t *pkt)
*/
ts_muxer_t *
ts_muxer_init(th_subscription_t *s, ts_mux_output_t *output,
void *opaque, int flags)
void *opaque, int flags, int corruption)
{
ts_muxer_t *ts = calloc(1, sizeof(ts_muxer_t));
int dopcr;
@ -610,6 +626,7 @@ ts_muxer_init(th_subscription_t *s, ts_mux_output_t *output,
ts->ts_pcr_start = AV_NOPTS_VALUE;
ts->ts_pcr_ref = AV_NOPTS_VALUE;
ts->ts_pcr_last = INT64_MIN;
/* Do TS MUX specific init per stream */
@ -619,6 +636,7 @@ ts_muxer_init(th_subscription_t *s, ts_mux_output_t *output,
dopcr = 0;
switch(st->st_type) {
case HTSTV_MPEG2VIDEO:
tms->tms_corruption_interval = (int64_t)corruption * 1000000LL;
tms->tms_sc = 0x1e0;
dopcr = 1;
break;

View file

@ -45,14 +45,13 @@ typedef struct ts_muxer {
int64_t ts_pcr_start;
int64_t ts_pcr_ref; /* System clock when PCR was/is/will be 0 */
int64_t ts_pcr_last;
} ts_muxer_t;
ts_muxer_t *ts_muxer_init(th_subscription_t *s, ts_mux_output_t *output,
void *opaque, int flags);
void *opaque, int flags, int corruption);
void ts_muxer_deinit(ts_muxer_t *ts, th_subscription_t *s);

View file

@ -601,7 +601,11 @@ typedef struct th_muxstream {
int tms_sc; /* start code */
int tms_cc;
int64_t tms_corruption_interval;
int64_t tms_corruption_last;
int tms_corruption_counter;
/* Memebers used when running with ffmpeg */
struct AVStream *tms_avstream;