From: Jaroslav Kysela Date: Thu, 14 Dec 2017 13:58:57 +0000 (+0100) Subject: descrambler: capmt - try to handle PAT pid (zero) more correctly, issue #4794 X-Git-Tag: v4.2.5~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=005f12ab24a894242571ad933c39c162452f4992;p=thirdparty%2Ftvheadend.git descrambler: capmt - try to handle PAT pid (zero) more correctly, issue #4794 --- diff --git a/src/descrambler/capmt.c b/src/descrambler/capmt.c index 968329a19..b7a930d80 100644 --- a/src/descrambler/capmt.c +++ b/src/descrambler/capmt.c @@ -380,7 +380,7 @@ capmt_pid_remove(capmt_t *capmt, int adapter, int pid, uint32_t flags) lock_assert(&capmt->capmt_mutex); - if (pid <= 0) + if (pid < 0) return; for (i = 0; i < MAX_PIDS; i++) { o = &ca->ca_pids[i]; @@ -799,6 +799,20 @@ capmt_send_stop_descrambling(capmt_t *capmt, uint8_t demuxer) capmt_write_msg(capmt, 0, 0, buf, 8); } +/** + * + */ +static void +capmt_init_demuxes(capmt_t *capmt) +{ + int i, j; + + memset(&capmt->capmt_demuxes, 0, sizeof(capmt->capmt_demuxes)); + for (i = 0; i < MAX_INDEX; i++) + for (j = 0; j < MAX_FILTER; j++) + capmt->capmt_demuxes.filters[i].dmx[j].pid = PID_UNUSED; +} + /** * global_lock is held */ @@ -844,7 +858,7 @@ capmt_service_destroy(th_descrambler_t *td) } if (LIST_EMPTY(&capmt->capmt_services)) - memset(&capmt->capmt_demuxes, 0, sizeof(capmt->capmt_demuxes)); + capmt_init_demuxes(capmt); pthread_mutex_unlock(&capmt->capmt_mutex); @@ -939,7 +953,7 @@ capmt_set_filter(capmt_t *capmt, int adapter, sbuf_t *sb, int offset) cf->adapter = adapter; filter = &cf->dmx[filter_index]; - if (!filter->pid) { + if (filter->pid == PID_UNUSED) { add = 1; } else if (pid != filter->pid || flags != filter->flags) { capmt_pid_remove(capmt, adapter, filter->pid, filter->flags); @@ -991,10 +1005,11 @@ capmt_stop_filter(capmt_t *capmt, int adapter, sbuf_t *sb, int offset) goto end; flags = filter->flags; memset(filter, 0, sizeof(*filter)); + filter->pid = PID_UNUSED; capmt_pid_remove(capmt, adapter, pid, flags); /* short the max values */ filter_index = cf->max - 1; - while (filter_index != 255 && cf->dmx[filter_index].pid == 0) + while (filter_index != 255 && cf->dmx[filter_index].pid == PID_UNUSED) filter_index--; cf->max = filter_index == 255 ? 0 : filter_index + 1; demux_index = capmt->capmt_demuxes.max - 1; @@ -1711,7 +1726,7 @@ capmt_thread(void *aux) capmt->capmt_sock[i] = -1; capmt->capmt_sock_reconnect[i] = 0; } - memset(&capmt->capmt_demuxes, 0, sizeof(capmt->capmt_demuxes)); + capmt_init_demuxes(capmt); /* Accessible */ if (capmt->capmt_sockfile && capmt->capmt_oscam != CAPMT_OSCAM_TCP &&