catalinii / minisatip

minisatip is an SATIP server for linux using local DVB-S2, DVB-C, DVB-T or ATSC cards
https://minisatip.org
328 stars 81 forks source link

CA PIDs from adjacent services sometimes left in PMT PI #1083

Open Jalle19 opened 1 year ago

Jalle19 commented 1 year ago

I've been trying to track down a bug that occurs after a few days of runtime only. The issue manifests as decryption issues for a pair of channels, and I think the channels have to be on the same mux for this to occur.

The gist is that after some time, the DDCI adapter's virtual PMT will end up including CA PIDs from two different services, when it should only contain the one for the service actually being played, e.g.:

Mar 21 08:35:02 vladimir minisatip[104924]: [21/03 08:35:02.278 AD7]: returning new pmt 361 for adapter 7, pmt pid 1274, sid 29000 7148
Mar 21 08:35:02 vladimir minisatip[104924]: [21/03 08:35:02.278 AD7]: new PMT 361 AD 7, pid: 04FA (1274), len 48, pi_len 12, ver 6, pcr 1047, sid 7148 (29000)
Mar 21 08:35:02 vladimir minisatip[104924]: [21/03 08:35:02.278 AD7]: PMT 361 PI pos 1 caid 0B00 => pid 1012 (4114), index 0
Mar 21 08:35:02 vladimir minisatip[104924]: [21/03 08:35:02.278 AD7]: PMT 361 PI pos 2 caid 0B00 => pid 1018 (4120), index 1

In the above example, PID 4120 is the only CA PID actually available for the service. PID 4114 belongs to another service on the same mux.

When it works as expected, only PID 4120 should even be mentioned:

Mar 21 08:51:26 vladimir minisatip[220530]: [21/03 08:51:26.371 AD7]: returning new pmt 6 for adapter 7, pmt pid 1274, sid 29000 7148, caids 0
Mar 21 08:51:26 vladimir minisatip[220530]: [21/03 08:51:26.371 AD7]: new PMT 6 AD 7, pid: 04FA (1274), len 42, pi_len 6, ver 1, pcr 1047, sid 7148 (29000)
Mar 21 08:51:26 vladimir minisatip[220530]: [21/03 08:51:26.371 AD7]: PMT 6 PI pos 1 caid 0B00 => pid 1018 (4120), index 0

I've unfortunately haven't been able to reliably reproduce this since restarting minisatip fixes the issue at least temporarily. I've been trying to figure out in what situations the PMT could be left "stale" and include old CA PIDs, but so far no luck.

Leaving this here in case someone has experienced the same thing and has some pointers.

Jalle19 commented 1 year ago

@catalinii I'm testing https://github.com/Jalle19/minisatip/commit/0e4877fdcfda66ce68d90b96fdb3433a0327b5a9, mostly a shot in the dark.

Could you explain the idea behind "master PMT"? I haven't really figured it out. The header says "the pmt that contains the same pids as this PMT", but what does that mean? Is it a reference to the adapter PMT in the context of the DDCI PMT?

Jalle19 commented 1 year ago

I checked my logs for the month of March, and there's not a single case where pmt->id != pmt->master_pmt:

negge@vladimir:~$ journalctl -u minisatip --since 2023-03-01 | grep -i pmt | grep master | grep -v ' CW ' > master_pmt.txt
negge@vladimir:~$ head master_pmt.txt 
Mar 15 22:53:47 vladimir minisatip[104924]: [15/03 22:53:47.911 AD7]: deleting PMT 263, master PMT 263, name SVT2 HD
Mar 15 22:53:47 vladimir minisatip[104924]: [15/03 22:53:47.911 AD7]: deleting PMT 277, master PMT 277, name V sport
Mar 15 22:53:47 vladimir minisatip[104924]: [15/03 22:53:47.911 AD7]: deleting PMT 278, master PMT 278, name Viasat
Mar 15 23:02:06 vladimir minisatip[104924]: [15/03 23:02:06.281 AD6]: deleting PMT 254, master PMT 254, name V sport
Mar 15 23:02:06 vladimir minisatip[104924]: [15/03 23:02:06.281 AD6]: deleting PMT 266, master PMT 266, name V film
Mar 15 23:02:06 vladimir minisatip[104924]: [15/03 23:02:06.281 AD6]: deleting PMT 272, master PMT 272, name
Mar 15 23:02:06 vladimir minisatip[104924]: [15/03 23:02:06.281 AD6]: deleting PMT 273, master PMT 273, name V sport
Mar 15 23:02:06 vladimir minisatip[104924]: [15/03 23:02:06.281 AD6]: deleting PMT 274, master PMT 274, name V sport
Mar 15 23:02:06 vladimir minisatip[104924]: [15/03 23:02:06.281 AD6]: deleting PMT 275, master PMT 275, name V sport
Mar 15 23:02:06 vladimir minisatip[104924]: [15/03 23:02:06.281 AD6]: deleting PMT 276, master PMT 276, name V sport
negge@vladimir:~$ cat master_pmt.txt | awk '{if ($11!=$14) {print $11 $14}}'
negge@vladimir:~$
Jalle19 commented 1 year ago

Now that I think about it, if master PMT is never different from the PMT being processed, by "fix" does nothing. The code it removes does nothing either, but it doens't fix anything.

Jalle19 commented 1 year ago

minisatip_tv4tv6_bug.txt

Got it to happen again!