Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
linuxdvb & satip: fix pid subscription locking
  • Loading branch information
perexg committed May 1, 2015
1 parent a00a3da commit fd16a1e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
36 changes: 24 additions & 12 deletions src/input/mpegts/linuxdvb/linuxdvb_frontend.c
Expand Up @@ -366,19 +366,22 @@ static mpegts_pid_t *
linuxdvb_frontend_open_pid
( mpegts_input_t *mi, mpegts_mux_t *mm, int pid, int type, int weight, void *owner )
{
mpegts_pid_t *mp;
linuxdvb_frontend_t *lfe = (linuxdvb_frontend_t*)mi;
int change = 0;
mpegts_pid_t *mp;
int change;

if (!(mp = mpegts_input_open_pid(mi, mm, pid, type, weight, owner)))
return NULL;

change = 0;
pthread_mutex_lock(&lfe->lfe_dvr_lock);
if (pid < MPEGTS_FULLMUX_PID)
change = mpegts_pid_add(&lfe->lfe_pids, pid, weight) >= 0;
else if (pid == MPEGTS_FULLMUX_PID) {
change = lfe->lfe_pids.all == 0;
lfe->lfe_pids.all = 1;
}

if (!(mp = mpegts_input_open_pid(mi, mm, pid, type, weight, owner)))
return NULL;
pthread_mutex_unlock(&lfe->lfe_dvr_lock);

if (change && lfe->lfe_dvr_pipe.wr > 0)
tvh_write(lfe->lfe_dvr_pipe.wr, "c", 1);
Expand All @@ -391,17 +394,26 @@ linuxdvb_frontend_close_pid
( mpegts_input_t *mi, mpegts_mux_t *mm, int pid, int type, int weight, void *owner )
{
linuxdvb_frontend_t *lfe = (linuxdvb_frontend_t*)mi;
int change = 0, r;
mpegts_pid_t *mp;
mpegts_pid_sub_t *mps;
int change, r;

if (pid < MPEGTS_FULLMUX_PID)
change = mpegts_pid_del(&lfe->lfe_pids, pid, weight) >= 0;
else if (pid == MPEGTS_FULLMUX_PID) {
if ((r = mpegts_input_close_pid(mi, mm, pid, type, weight, owner)) <= 0)
return r;

change = 0;
pthread_mutex_lock(&lfe->lfe_dvr_lock);
if (pid == MPEGTS_FULLMUX_PID) {
change = lfe->lfe_pids.all != 0;
lfe->lfe_pids.all = 0;
} else if (pid < MPEGTS_FULLMUX_PID) {
mpegts_pid_done(&lfe->lfe_pids);
RB_FOREACH(mp, &mm->mm_pids, mp_link)
RB_FOREACH(mps, &mp->mp_subs, mps_link)
mpegts_pid_add(&lfe->lfe_pids, mp->mp_pid, mps->mps_weight);
change = 1;
}

if ((r = mpegts_input_close_pid(mi, mm, pid, type, weight, owner)) <= 0)
return r;
pthread_mutex_unlock(&lfe->lfe_dvr_lock);

if (change)
tvh_write(lfe->lfe_dvr_pipe.wr, "c", 1);
Expand Down
21 changes: 11 additions & 10 deletions src/input/mpegts/satip/satip_frontend.c
Expand Up @@ -561,7 +561,7 @@ satip_frontend_open_pid
if (mp->mp_pid > MPEGTS_FULLMUX_PID)
return mp;

pthread_mutex_unlock(&lfe->sf_dvr_lock);
pthread_mutex_lock(&lfe->sf_dvr_lock);
if ((tr = lfe->sf_req) != NULL) {
if (pid == MPEGTS_FULLMUX_PID) {
if (lfe->sf_device->sd_fullmux_ok) {
Expand All @@ -580,10 +580,10 @@ satip_frontend_open_pid
} else {
change |= satip_frontend_add_pid(lfe, mp->mp_pid, weight);
}
if (change)
tvh_write(lfe->sf_dvr_pipe.wr, "c", 1);
}
pthread_mutex_unlock(&lfe->sf_dvr_lock);
if (change)
tvh_write(lfe->sf_dvr_pipe.wr, "c", 1);

return mp;
}
Expand All @@ -594,15 +594,10 @@ satip_frontend_close_pid
{
satip_frontend_t *lfe = (satip_frontend_t*)mi;
satip_tune_req_t *tr;
mpegts_pid_t *mp;
mpegts_pid_sub_t *mps;
int change = 0, r;

if (pid < MPEGTS_FULLMUX_PID) {
pthread_mutex_lock(&lfe->sf_dvr_lock);
if ((tr = lfe->sf_req) != NULL)
change = mpegts_pid_del(&tr->sf_pids, pid, weight) >= 0;
pthread_mutex_unlock(&lfe->sf_dvr_lock);
}

if ((r = mpegts_input_close_pid(mi, mm, pid, type, weight, owner)) <= 0)
return r; /* return here even if change is nonzero - multiple PID subscribers */

Expand All @@ -620,6 +615,12 @@ satip_frontend_close_pid
change = 1;
}
}
} else {
mpegts_pid_done(&tr->sf_pids);
RB_FOREACH(mp, &mm->mm_pids, mp_link)
RB_FOREACH(mps, &mp->mp_subs, mps_link)
mpegts_pid_add(&tr->sf_pids, mp->mp_pid, mps->mps_weight);
change = 1;
}
if (change)
tvh_write(lfe->sf_dvr_pipe.wr, "c", 1);
Expand Down

0 comments on commit fd16a1e

Please sign in to comment.