Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mpegts input: add reopen flag to mpegts_input_open_pid() to avoid fal…
…se dupe errors
  • Loading branch information
perexg committed Jan 22, 2016
1 parent 60e67b5 commit 724e818
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/input/mpegts.h
Expand Up @@ -935,7 +935,7 @@ void mpegts_input_save ( mpegts_input_t *mi, htsmsg_t *c );
void mpegts_input_flush_mux ( mpegts_input_t *mi, mpegts_mux_t *mm );

mpegts_pid_t * mpegts_input_open_pid
( mpegts_input_t *mi, mpegts_mux_t *mm, int pid, int type, int weight, void *owner );
( mpegts_input_t *mi, mpegts_mux_t *mm, int pid, int type, int weight, void *owner, int reopen );

int mpegts_input_close_pid
( mpegts_input_t *mi, mpegts_mux_t *mm, int pid, int type, int weight, void *owner );
Expand Down
43 changes: 24 additions & 19 deletions src/input/mpegts/mpegts_input.c
Expand Up @@ -456,7 +456,8 @@ mpegts_input_close_pids

mpegts_pid_t *
mpegts_input_open_pid
( mpegts_input_t *mi, mpegts_mux_t *mm, int pid, int type, int weight, void *owner )
( mpegts_input_t *mi, mpegts_mux_t *mm, int pid, int type, int weight,
void *owner, int reopen )
{
char buf[512];
mpegts_pid_t *mp;
Expand Down Expand Up @@ -488,10 +489,12 @@ mpegts_input_open_pid
buf, (type & MPS_TABLES) ? "tables" : "fullmux", type, owner);
mm->mm_update_pids_flag = 1;
} else {
mpegts_mux_nice_name(mm, buf, sizeof(buf));
tvherror("mpegts",
"%s - open PID %04x (%d) failed, dupe sub (owner %p)",
buf, mp->mp_pid, mp->mp_pid, owner);
if (!reopen) {
mpegts_mux_nice_name(mm, buf, sizeof(buf));
tvherror("mpegts",
"%s - open PID %04x (%d) failed, dupe sub (owner %p)",
buf, mp->mp_pid, mp->mp_pid, owner);
}
free(mps);
mp = NULL;
}
Expand All @@ -506,9 +509,11 @@ mpegts_input_open_pid
buf, mp->mp_pid, mp->mp_pid, type, owner);
mm->mm_update_pids_flag = 1;
} else {
mpegts_mux_nice_name(mm, buf, sizeof(buf));
tvherror("mpegts", "%s - open PID %04x (%d) failed, dupe sub (owner %p)",
buf, mp->mp_pid, mp->mp_pid, owner);
if (!reopen) {
mpegts_mux_nice_name(mm, buf, sizeof(buf));
tvherror("mpegts", "%s - open PID %04x (%d) failed, dupe sub (owner %p)",
buf, mp->mp_pid, mp->mp_pid, owner);
}
free(mps);
mp = NULL;
}
Expand Down Expand Up @@ -646,7 +651,7 @@ mpegts_input_cat_pass_callback
pthread_mutex_lock(&mi->mi_output_lock);
if ((mi = mm->mm_active->mmi_input) != NULL)
mpegts_input_open_pid(mi, mm, pid,
MPS_SERVICE, MPS_WEIGHT_CAT, s);
MPS_SERVICE, MPS_WEIGHT_CAT, s, 0);
pthread_mutex_unlock(&mi->mi_output_lock);
}
}
Expand All @@ -671,7 +676,7 @@ mpegts_input_open_service
elementary_stream_t *st;
mpegts_apids_t *pids;
mpegts_apid_t *p;
int i;
int i, reopen = !init;

/* Add to list */
pthread_mutex_lock(&mi->mi_output_lock);
Expand All @@ -683,34 +688,34 @@ mpegts_input_open_service
pthread_mutex_lock(&s->s_stream_mutex);
if (s->s_type == STYPE_STD) {

mpegts_input_open_pid(mi, mm, s->s_pmt_pid, MPS_SERVICE, MPS_WEIGHT_PMT, s);
mpegts_input_open_pid(mi, mm, s->s_pcr_pid, MPS_SERVICE, MPS_WEIGHT_PCR, s);
mpegts_input_open_pid(mi, mm, s->s_pmt_pid, MPS_SERVICE, MPS_WEIGHT_PMT, s, reopen);
mpegts_input_open_pid(mi, mm, s->s_pcr_pid, MPS_SERVICE, MPS_WEIGHT_PCR, s, reopen);
if (s->s_scrambled_pass)
mpegts_input_open_pid(mi, mm, DVB_CAT_PID, MPS_SERVICE, MPS_WEIGHT_CAT, s);
mpegts_input_open_pid(mi, mm, DVB_CAT_PID, MPS_SERVICE, MPS_WEIGHT_CAT, s, reopen);
/* Open only filtered components here */
TAILQ_FOREACH(st, &s->s_filt_components, es_filt_link)
if ((s->s_scrambled_pass || st->es_type != SCT_CA) &&
st->es_pid != s->s_pmt_pid && st->es_pid != s->s_pcr_pid) {
st->es_pid_opened = 1;
mpegts_input_open_pid(mi, mm, st->es_pid, MPS_SERVICE, mpegts_mps_weight(st), s);
mpegts_input_open_pid(mi, mm, st->es_pid, MPS_SERVICE, mpegts_mps_weight(st), s, reopen);
}

mpegts_service_update_slave_pids(s, 0);

} else {
if ((pids = s->s_pids) != NULL) {
if (pids->all) {
mpegts_input_open_pid(mi, mm, MPEGTS_FULLMUX_PID, MPS_RAW | MPS_ALL, MPS_WEIGHT_RAW, s);
mpegts_input_open_pid(mi, mm, MPEGTS_FULLMUX_PID, MPS_RAW | MPS_ALL, MPS_WEIGHT_RAW, s, reopen);
} else {
for (i = 0; i < pids->count; i++) {
p = &pids->pids[i];
mpegts_input_open_pid(mi, mm, p->pid, MPS_RAW, p->weight, s);
mpegts_input_open_pid(mi, mm, p->pid, MPS_RAW, p->weight, s, reopen);
}
}
} else if (flags & SUBSCRIPTION_TABLES) {
mpegts_input_open_pid(mi, mm, MPEGTS_TABLES_PID, MPS_RAW | MPS_TABLES, MPS_WEIGHT_PAT, s);
mpegts_input_open_pid(mi, mm, MPEGTS_TABLES_PID, MPS_RAW | MPS_TABLES, MPS_WEIGHT_PAT, s, reopen);
} else if (flags & SUBSCRIPTION_MINIMAL) {
mpegts_input_open_pid(mi, mm, DVB_PAT_PID, MPS_RAW, MPS_WEIGHT_PAT, s);
mpegts_input_open_pid(mi, mm, DVB_PAT_PID, MPS_RAW, MPS_WEIGHT_PAT, s, reopen);
}
}

Expand Down Expand Up @@ -1163,7 +1168,7 @@ mpegts_input_table_waiting ( mpegts_input_t *mi, mpegts_mux_t *mm )
if (!mt->mt_subscribed) {
mt->mt_subscribed = 1;
pthread_mutex_unlock(&mm->mm_tables_lock);
mpegts_input_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt->mt_weight, mt);
mpegts_input_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt->mt_weight, mt, 0);
} else {
pthread_mutex_unlock(&mm->mm_tables_lock);
}
Expand Down
2 changes: 1 addition & 1 deletion src/input/mpegts/mpegts_mux.c
Expand Up @@ -888,7 +888,7 @@ mpegts_mux_open_table ( mpegts_mux_t *mm, mpegts_table_t *mt, int subscribe )
mt->mt_subscribed = 1;
pthread_mutex_unlock(&mm->mm_tables_lock);
pthread_mutex_lock(&mi->mi_output_lock);
mpegts_input_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt->mt_weight, mt);
mpegts_input_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt->mt_weight, mt, 0);
pthread_mutex_unlock(&mi->mi_output_lock);
pthread_mutex_lock(&mm->mm_tables_lock);
mpegts_table_release(mt);
Expand Down
6 changes: 3 additions & 3 deletions src/input/mpegts/mpegts_service.c
Expand Up @@ -892,12 +892,12 @@ mpegts_service_raw_update_pids(mpegts_service_t *t, mpegts_apids_t *pids)
mpegts_input_close_pids(mi, mm, t, 1);
for (i = 0; i < x->count; i++) {
pi = &x->pids[i];
mpegts_input_open_pid(mi, mm, pi->pid, MPS_RAW, pi->weight, t);
mpegts_input_open_pid(mi, mm, pi->pid, MPS_RAW, pi->weight, t, 0);
}
} else {
if (pids->all) {
mpegts_input_close_pids(mi, mm, t, 1);
mpegts_input_open_pid(mi, mm, MPEGTS_FULLMUX_PID, MPS_RAW, MPS_WEIGHT_RAW, t);
mpegts_input_open_pid(mi, mm, MPEGTS_FULLMUX_PID, MPS_RAW, MPS_WEIGHT_RAW, t, 0);
} else {
mpegts_pid_compare(p, x, &add, &del);
for (i = 0; i < del.count; i++) {
Expand All @@ -906,7 +906,7 @@ mpegts_service_raw_update_pids(mpegts_service_t *t, mpegts_apids_t *pids)
}
for (i = 0; i < add.count; i++) {
pi = &add.pids[i];
mpegts_input_open_pid(mi, mm, pi->pid, MPS_RAW, pi->weight, t);
mpegts_input_open_pid(mi, mm, pi->pid, MPS_RAW, pi->weight, t, 0);
}
mpegts_pid_done(&add);
mpegts_pid_done(&del);
Expand Down

0 comments on commit 724e818

Please sign in to comment.