detect commercials on swedish TV4 and skip them while recording

This commit is contained in:
John Törnblom 2013-01-06 22:31:08 +01:00
parent 757a06b7d8
commit 39a74172ad
3 changed files with 47 additions and 4 deletions

View file

@ -400,6 +400,7 @@ dvr_thread(void *aux)
dvr_entry_t *de = aux;
streaming_queue_t *sq = &de->de_sq;
streaming_message_t *sm;
th_pkt_t *pkt;
int run = 1;
int started = 0;
@ -417,8 +418,25 @@ dvr_thread(void *aux)
pthread_mutex_unlock(&sq->sq_mutex);
switch(sm->sm_type) {
case SMT_MPEGTS:
case SMT_PACKET:
pkt = sm->sm_data;
if(pkt->pkt_commercial == COMMERCIAL_YES) {
dvr_rec_set_state(de, DVR_RS_COMMERCIAL, 0);
tsfix_set_comm_skip(de->de_tsfix, 1);
break;
}
dvr_rec_set_state(de, DVR_RS_RUNNING, 0);
tsfix_set_comm_skip(de->de_tsfix, 0);
if(started) {
muxer_write_pkt(de->de_mux, sm->sm_type, sm->sm_data);
sm->sm_data = NULL;
}
break;
case SMT_MPEGTS:
if(started) {
dvr_rec_set_state(de, DVR_RS_RUNNING, 0);
muxer_write_pkt(de->de_mux, sm->sm_type, sm->sm_data);

View file

@ -40,6 +40,7 @@ typedef struct tfstream {
int64_t tfs_dts_epoch;
int64_t tfs_last_dts_in;
int64_t tfs_drops;
} tfstream_t;
@ -56,6 +57,7 @@ typedef struct tsfix {
int tf_hasvideo;
int64_t tf_tsref;
time_t tf_start_time;
int tf_comm_skip;
struct th_pktref_queue tf_ptsq;
@ -160,6 +162,9 @@ normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt)
/* Subtract the transport wide start offset */
dts = pkt->pkt_dts - tf->tf_tsref;
/* Subtract dropped packets due to commercial breaks */
dts -= tfs->tfs_drops;
if(tfs->tfs_last_dts_norm == PTS_UNSET) {
if(dts < 0) {
/* Early packet with negative time stamp, drop those */
@ -322,11 +327,11 @@ tsfix_input_packet(tsfix_t *tf, streaming_message_t *sm)
tsfixprintf("reference clock set to %"PRId64"\n", tf->tf_tsref);
}
int pdur = pkt->pkt_duration >> pkt->pkt_field;
if(pkt->pkt_dts == PTS_UNSET) {
int pdur = pkt->pkt_duration >> pkt->pkt_field;
if(tfs->tfs_last_dts_in == PTS_UNSET) {
tfs->tfs_drops += pdur;
pkt_ref_dec(pkt);
return;
}
@ -337,6 +342,13 @@ tsfix_input_packet(tsfix_t *tf, streaming_message_t *sm)
streaming_component_type2txt(tfs->tfs_type),
tfs->tfs_last_dts_in, pdur, pkt->pkt_dts);
}
if(tf->tf_comm_skip && pkt->pkt_commercial == COMMERCIAL_YES) {
tfs->tfs_drops += pdur;
pkt_ref_dec(pkt);
return;
}
tfs->tfs_last_dts_in = pkt->pkt_dts;
compute_pts(tf, tfs, pkt);
@ -404,6 +416,17 @@ void tsfix_set_start_time(streaming_target_t *pad, time_t start)
}
/**
*
*/
void
tsfix_set_comm_skip(streaming_target_t *pad, int bool) {
tsfix_t *tf = (tsfix_t *)pad;
tf->tf_comm_skip = !!bool;
}
/**
*
*/

View file

@ -25,6 +25,8 @@ streaming_target_t *tsfix_create(streaming_target_t *output);
void tsfix_set_start_time(streaming_target_t *pad, time_t start);
void tsfix_set_comm_skip(streaming_target_t *pad, int bool);
void tsfix_destroy(streaming_target_t *gh);