Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mpegts: simplify pid subscriptions for input drivers
  • Loading branch information
perexg committed May 3, 2015
1 parent b609513 commit 9dcfd08
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 268 deletions.
9 changes: 3 additions & 6 deletions src/input/mpegts.h
Expand Up @@ -684,8 +684,7 @@ struct mpegts_input
void (*mi_stop_mux) (mpegts_input_t*,mpegts_mux_instance_t*);
void (*mi_open_service) (mpegts_input_t*,mpegts_service_t*,int flags, int first);
void (*mi_close_service) (mpegts_input_t*,mpegts_service_t*);
mpegts_pid_t *(*mi_open_pid)(mpegts_input_t*,mpegts_mux_t*,int,int,int,void*);
int (*mi_close_pid) (mpegts_input_t*,mpegts_mux_t*,int,int,int,void*);
void (*mi_update_pids) (mpegts_input_t*,mpegts_mux_t*);
void (*mi_create_mux_instance) (mpegts_input_t*,mpegts_mux_t*);
void (*mi_started_mux) (mpegts_input_t*,mpegts_mux_instance_t*);
void (*mi_stopping_mux) (mpegts_input_t*,mpegts_mux_instance_t*);
Expand Down Expand Up @@ -970,10 +969,8 @@ int dvb_tot_callback
int atsc_vct_callback
(struct mpegts_table *mt, const uint8_t *ptr, int len, int tableid);

void psi_tables_default ( struct mpegts_mux *mm );
void psi_tables_dvb ( struct mpegts_mux *mm );
void psi_tables_atsc_t ( struct mpegts_mux *mm );
void psi_tables_atsc_c ( struct mpegts_mux *mm );
void psi_tables_install
(mpegts_input_t *mi, mpegts_mux_t *mm, dvb_fe_delivery_system_t delsys);

mpegts_service_t *mpegts_service_create0
( mpegts_service_t *ms, const idclass_t *class, const char *uuid,
Expand Down
3 changes: 3 additions & 0 deletions src/input/mpegts/dvb.h
Expand Up @@ -340,6 +340,9 @@ typedef enum dvb_fe_delivery_system {
DVB_SYS_CMMB = 900,
DVB_SYS_DAB = 1000,
DVB_SYS_TURBO = 1100,
/* TVH internal */
DVB_SYS_ATSC_ALL = 9998,
DVB_SYS_UNKNOWN = 9999
} dvb_fe_delivery_system_t;

typedef enum dvb_fe_spectral_inversion {
Expand Down
59 changes: 55 additions & 4 deletions src/input/mpegts/dvb_psi.c
Expand Up @@ -2419,7 +2419,7 @@ dvb_tot_callback
* Install default table sets
*/

void
static void
psi_tables_default ( mpegts_mux_t *mm )
{
mpegts_table_add(mm, DVB_PAT_BASE, DVB_PAT_MASK, dvb_pat_callback,
Expand All @@ -2444,7 +2444,7 @@ psi_tables_dvb_fastscan( void *aux, bouquet_t *bq, const char *name, int pid )
}
#endif

void
static void
psi_tables_dvb ( mpegts_mux_t *mm )
{
mpegts_table_add(mm, DVB_NIT_BASE, DVB_NIT_MASK, dvb_nit_callback,
Expand Down Expand Up @@ -2473,18 +2473,69 @@ psi_tables_dvb ( mpegts_mux_t *mm )
#endif
}

void
static void
psi_tables_atsc_c ( mpegts_mux_t *mm )
{
mpegts_table_add(mm, DVB_VCT_C_BASE, DVB_VCT_MASK, atsc_vct_callback,
NULL, "vct", MT_QUICKREQ | MT_CRC | MT_RECORD,
DVB_VCT_PID, MPS_WEIGHT_VCT);
}

void
static void
psi_tables_atsc_t ( mpegts_mux_t *mm )
{
mpegts_table_add(mm, DVB_VCT_T_BASE, DVB_VCT_MASK, atsc_vct_callback,
NULL, "vct", MT_QUICKREQ | MT_CRC | MT_RECORD,
DVB_VCT_PID, MPS_WEIGHT_VCT);
}

void
psi_tables_install ( mpegts_input_t *mi, mpegts_mux_t *mm,
dvb_fe_delivery_system_t delsys)
{
if (mi == NULL || mm == NULL)
return;

psi_tables_default(mm);

switch (delsys) {
case DVB_SYS_DVBC_ANNEX_A:
case DVB_SYS_DVBC_ANNEX_C:
case DVB_SYS_DVBT:
case DVB_SYS_DVBT2:
case DVB_SYS_DVBS:
case DVB_SYS_DVBS2:
case DVB_SYS_ISDBS:
psi_tables_dvb(mm);
break;
case DVB_SYS_TURBO:
case DVB_SYS_ATSC:
case DVB_SYS_ATSCMH:
psi_tables_atsc_t(mm);
break;
case DVB_SYS_DVBC_ANNEX_B:
psi_tables_atsc_c(mm);
break;
case DVB_SYS_NONE:
case DVB_SYS_DVBH:
case DVB_SYS_ISDBT:
case DVB_SYS_ISDBC:
case DVB_SYS_DTMB:
case DVB_SYS_CMMB:
case DVB_SYS_DSS:
case DVB_SYS_DAB:
break;
case DVB_SYS_ATSC_ALL:
psi_tables_atsc_c(mm);
psi_tables_atsc_t(mm);
break;
case DVB_SYS_UNKNOWN:
psi_tables_dvb(mm);
psi_tables_atsc_c(mm);
psi_tables_atsc_t(mm);
break;
break;
}

mi->mi_update_pids(mi, mm);
}
9 changes: 3 additions & 6 deletions src/input/mpegts/iptv/iptv.c
Expand Up @@ -416,12 +416,9 @@ iptv_input_mux_started ( iptv_mux_t *im )

/* Install table handlers */
mpegts_mux_t *mm = (mpegts_mux_t*)im;
psi_tables_default(mm);
if (im->mm_iptv_atsc) {
psi_tables_atsc_t(mm);
psi_tables_atsc_c(mm);
} else
psi_tables_dvb(mm);
if (mm->mm_active)
psi_tables_install(mm->mm_active->mmi_input, mm,
im->mm_iptv_atsc ? DVB_SYS_ATSC_ALL : DVB_SYS_DVBT);
}

/* **************************************************************************
Expand Down
83 changes: 13 additions & 70 deletions src/input/mpegts/linuxdvb/linuxdvb_frontend.c
Expand Up @@ -362,63 +362,27 @@ linuxdvb_frontend_start_mux
return res;
}

static mpegts_pid_t *
linuxdvb_frontend_open_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;
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;
}
pthread_mutex_unlock(&lfe->lfe_dvr_lock);

if (change && lfe->lfe_dvr_pipe.wr > 0)
tvh_write(lfe->lfe_dvr_pipe.wr, "c", 1);

return mp;
}

static int
linuxdvb_frontend_close_pid
( mpegts_input_t *mi, mpegts_mux_t *mm, int pid, int type, int weight, void *owner )
static void
linuxdvb_frontend_update_pids
( mpegts_input_t *mi, mpegts_mux_t *mm )
{
linuxdvb_frontend_t *lfe = (linuxdvb_frontend_t*)mi;
mpegts_pid_t *mp;
mpegts_pid_sub_t *mps;
int change, r;

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)
mpegts_pid_done(&lfe->lfe_pids);
RB_FOREACH(mp, &mm->mm_pids, mp_link) {
if (mp->mp_pid == MPEGTS_FULLMUX_PID)
lfe->lfe_pids.all = 1;
else if (mp->mp_pid < MPEGTS_FULLMUX_PID) {
RB_FOREACH(mps, &mp->mp_subs, mps_link)
mpegts_pid_add(&lfe->lfe_pids, mp->mp_pid, mps->mps_weight);
change = 1;
}
}
pthread_mutex_unlock(&lfe->lfe_dvr_lock);

if (change)
tvh_write(lfe->lfe_dvr_pipe.wr, "c", 1);

return r;
tvh_write(lfe->lfe_dvr_pipe.wr, "c", 1);
}

static idnode_set_t *
Expand Down Expand Up @@ -448,27 +412,6 @@ linuxdvb_frontend_network_list ( mpegts_input_t *mi )
* Data processing
* *************************************************************************/

static void
linuxdvb_frontend_default_tables
( linuxdvb_frontend_t *lfe, dvb_mux_t *lm )
{
mpegts_mux_t *mm = (mpegts_mux_t*)lm;

psi_tables_default(mm);

/* ATSC */
if (lfe->lfe_type == DVB_TYPE_ATSC) {
if (lm->lm_tuning.dmc_fe_modulation == DVB_MOD_VSB_8)
psi_tables_atsc_t(mm);
else
psi_tables_atsc_c(mm);

/* DVB */
} else {
psi_tables_dvb(mm);
}
}

static inline int
ioctl_check( linuxdvb_frontend_t *lfe, int bit )
{
Expand Down Expand Up @@ -597,7 +540,8 @@ linuxdvb_frontend_monitor ( void *aux )
pthread_mutex_unlock(&lfe->lfe_dvr_lock);

/* Table handlers */
linuxdvb_frontend_default_tables(lfe, (dvb_mux_t*)mm);
psi_tables_install((mpegts_input_t *)lfe, mm,
((dvb_mux_t *)mm)->lm_tuning.dmc_fe_type);

/* Re-arm (quick) */
} else {
Expand Down Expand Up @@ -1620,8 +1564,7 @@ linuxdvb_frontend_create
lfe->mi_start_mux = linuxdvb_frontend_start_mux;
lfe->mi_stop_mux = linuxdvb_frontend_stop_mux;
lfe->mi_network_list = linuxdvb_frontend_network_list;
lfe->mi_open_pid = linuxdvb_frontend_open_pid;
lfe->mi_close_pid = linuxdvb_frontend_close_pid;
lfe->mi_update_pids = linuxdvb_frontend_update_pids;
lfe->mi_enabled_updated = linuxdvb_frontend_enabled_updated;

/* Adapter link */
Expand Down

0 comments on commit 9dcfd08

Please sign in to comment.