Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
service/subscription: do not allow to subscribe services without PMT
  • Loading branch information
perexg committed Apr 25, 2016
1 parent c3eefc6 commit 7ebdc4a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/input/mpegts/mpegts_service.c
Expand Up @@ -280,7 +280,7 @@ mpegts_service_config_save ( service_t *t, char *filename, size_t fsize )
/*
* Service instance list
*/
static void
static int
mpegts_service_enlist
( service_t *t, tvh_input_t *ti, struct service_instance_list *sil,
int flags, int weight )
Expand All @@ -293,6 +293,10 @@ mpegts_service_enlist

assert(s->s_source_type == S_MPEG_TS);

/* invalid PMT */
if (s->s_pmt_pid <= 0 || s->s_pmt_pid >= 8191)
return SM_CODE_INVALID_SERVICE;

/* Create instances */
m->mm_create_instances(m);

Expand Down Expand Up @@ -322,6 +326,8 @@ mpegts_service_enlist

service_instance_add(sil, t, mi->mi_instance, mi->mi_name, p, w);
}

return 0;
}

/*
Expand Down
27 changes: 21 additions & 6 deletions src/service.c
Expand Up @@ -697,14 +697,15 @@ service_find_instance
idnode_list_mapping_t *ilm;
service_instance_t *si, *next;
profile_t *pro = prch ? prch->prch_pro : NULL;
int enlisted;
int enlisted, r, r1;

lock_assert(&global_lock);

/* Build list */
TAILQ_FOREACH(si, sil, si_link)
si->si_mark = 1;

r = 0;
if (ch) {
if (!ch->ch_enabled) {
*error = SM_CODE_SVC_NOT_ENABLED;
Expand All @@ -718,20 +719,34 @@ service_find_instance
pro->pro_svfilter == PROFILE_SVF_NONE ||
(pro->pro_svfilter == PROFILE_SVF_SD && service_is_sdtv(s)) ||
(pro->pro_svfilter == PROFILE_SVF_HD && service_is_hdtv(s))) {
s->s_enlist(s, ti, sil, flags, weight);
enlisted++;
r1 = s->s_enlist(s, ti, sil, flags, weight);
if (r1 == 0)
enlisted++;
else if (enlisted == 0)
r = r1;
}
}
}
if (enlisted == 0) {
LIST_FOREACH(ilm, &ch->ch_services, ilm_in2_link) {
s = (service_t *)ilm->ilm_in1;
if (s->s_is_enabled(s, flags))
s->s_enlist(s, ti, sil, flags, weight);
if (s->s_is_enabled(s, flags)) {
r1 = s->s_enlist(s, ti, sil, flags, weight);
if (r1 == 0)
enlisted++;
else if (enlisted == 0)
r = r1;
}
}
}
} else {
s->s_enlist(s, ti, sil, flags, weight);
r = s->s_enlist(s, ti, sil, flags, weight);
}

if (r) {
if (*error < r)
*error = r;
return NULL;
}

/* Clean */
Expand Down
4 changes: 2 additions & 2 deletions src/service.h
Expand Up @@ -310,8 +310,8 @@ typedef struct service {

int (*s_is_enabled)(struct service *t, int flags);

void (*s_enlist)(struct service *s, struct tvh_input *ti,
service_instance_list_t *sil, int flags, int weight);
int (*s_enlist)(struct service *s, struct tvh_input *ti,
service_instance_list_t *sil, int flags, int weight);

int (*s_start_feed)(struct service *s, int instance, int weight, int flags);

Expand Down
2 changes: 1 addition & 1 deletion src/service_mapper.c
Expand Up @@ -392,7 +392,7 @@ service_mapper_thread ( void *aux )
subscription_unsubscribe(sub, UNSUBSCRIBE_FINAL);

if(err) {
tvhinfo("service_mapper", "%s: failed [err %s]", s->s_nicename, err);
tvhinfo("service_mapper", "%s: failed [reason: %s]", s->s_nicename, err);
service_mapper_stat.fail++;
} else
service_mapper_process(&smi->conf, s, NULL);
Expand Down
2 changes: 2 additions & 0 deletions src/streaming.c
Expand Up @@ -445,6 +445,8 @@ streaming_code2txt(int code)
return N_("No service assigned to channel");
case SM_CODE_NO_ADAPTERS:
return N_("No assigned adapters");
case SM_CODE_INVALID_SERVICE:
return N_("Invalid service");

case SM_CODE_ABORTED:
return N_("Aborted by user");
Expand Down
1 change: 1 addition & 0 deletions src/tvheadend.h
Expand Up @@ -530,6 +530,7 @@ typedef enum {
#define SM_CODE_NO_SERVICE 207
#define SM_CODE_NO_VALID_ADAPTER 208
#define SM_CODE_NO_ADAPTERS 209
#define SM_CODE_INVALID_SERVICE 210

#define SM_CODE_ABORTED 300

Expand Down

1 comment on commit 7ebdc4a

@bluzee
Copy link
Contributor

@bluzee bluzee commented on 7ebdc4a Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have time to test this commit ATM, but I know there are channels transmitted on satellite that have no PMT. I've had to create services for them by manually editing config files.

Please sign in to comment.