Skip to content

Conversation

@Jalle19
Copy link
Collaborator

@Jalle19 Jalle19 commented Sep 2, 2025

Fixes two scenarios:

  • a user wants to descramble a PID that is neither video nor audio. This wasn't possible because we skipped processing the PMT completely if it contained no video/audio stream PIDs
  • simply removing the video/audio check would potentially cause CA PMT to balloon due to all DVBSUB and TELETEXT PIDs etc. potentially being added to it. This has been improved now with the addition of marking each stream PID as scrambled or not based on whether it has a CA descriptor (0x09). Due to a bug this particular descriptor was never stored in the stream PID, so when the PMT was reconstructed on a DDCI device the information was no longer there are filtering out scrambled PIDs would cause all PIDs to be left out.

Before:

[02/09 21:04:30.427 AD3]: new PMT 0 AD 3, pid: 05D3 (1491), filter 6, len 106, pi_len 0, ver 1, pcr 1535, sid 4330 (17200)  
[02/09 21:04:30.427 AD3]: PMT pid 1491 - stream pid 05FF (1535), type 27, es_len 11, pos 9, caids 0
[02/09 21:04:30.427 AD3]: PMT 0 PI pos 1 caid 0B00 => pid 1016 (4118), index 0
[02/09 21:04:30.427 AD3]: PMT pid 1491 - stream pid 0D25 (3365), type 3, es_len 20, pos 25, caids 1
[02/09 21:04:30.427 AD3]: PMT pid 1491 - stream pid 0FA9 (4009), type 3, es_len 20, pos 50, caids 1
[02/09 21:04:30.427 AD3]: PMT pid 1491 - stream pid 181F (6175), type 6, es_len 22, pos 75, caids 1
...
[02/09 21:04:30.552 AD0]: new PMT 4 AD 0, pid: 05D3 (1491), filter 9, len 72, pi_len 6, ver 1, pcr 1535, sid 4330 (17200)  
[02/09 21:04:30.552 AD0]: PMT 4 PI pos 1 caid 0B00 => pid 1016 (4118), index 0
[02/09 21:04:30.553 AD0]: PMT pid 1491 - stream pid 05FF (1535), type 27, es_len 5, pos 15, caids 1
[02/09 21:04:30.553 AD0]: PMT pid 1491 - stream pid 0D25 (3365), type 3, es_len 14, pos 25, caids 1
[02/09 21:04:30.553 AD0]: PMT pid 1491 - stream pid 0FA9 (4009), type 3, es_len 14, pos 44, caids 1
[02/09 21:04:30.553 AD0]: PMT pid 1491 - stream pid 181F (6175), type 6, es_len 0, pos 63, caids 1

After:

[02/09 21:20:16.221 AD3]: new PMT 0 AD 3, pid: 05D3 (1491), filter 6, len 106, pi_len 0, ver 1, pcr 1535, sid 4330 (17200)  
[02/09 21:20:16.221 AD3]: PMT 0 PI pos 1 caid 0B00 => pid 1016 (4118), index 0
[02/09 21:20:16.221 AD3]: PMT pid 1491 - stream pid 05FF (1535), type 27, es_len 11, pos 9, caids 1
[02/09 21:20:16.221 AD3]: PMT pid 1491 - stream pid 0D25 (3365), type 3, es_len 20, pos 25, caids 1
[02/09 21:20:16.221 AD3]: PMT pid 1491 - stream pid 0FA9 (4009), type 3, es_len 20, pos 50, caids 1
[02/09 21:20:16.221 AD3]: PMT pid 1491 - stream pid 181F (6175), type 6, es_len 22, pos 75, caids 1
...
[02/09 21:20:16.308 AD0]: new PMT 4 AD 0, pid: 05D3 (1491), filter 9, len 112, pi_len 6, ver 1, pcr 1535, sid 4330 (17200)  
[02/09 21:20:16.308 AD0]: PMT 4 PI pos 1 caid 0B00 => pid 1016 (4118), index 0
[02/09 21:20:16.308 AD0]: PMT pid 1491 - stream pid 05FF (1535), type 27, es_len 11, pos 15, caids 1
[02/09 21:20:16.308 AD0]: PMT pid 1491 - stream pid 0D25 (3365), type 3, es_len 20, pos 31, caids 1
[02/09 21:20:16.308 AD0]: PMT pid 1491 - stream pid 0FA9 (4009), type 3, es_len 20, pos 56, caids 1
[02/09 21:20:16.308 AD0]: PMT pid 1491 - stream pid 181F (6175), type 6, es_len 22, pos 81, caids 1
...
[02/09 21:20:16.308 AD0]: CAPMT_add_PMT: omitting PMT 4 (ad 0) pid 6175 from CAPMT (not scrambled)

Fixes #1304 incidentally

@Jalle19 Jalle19 requested a review from catalinii September 2, 2025 18:02
@Jalle19
Copy link
Collaborator Author

Jalle19 commented Sep 5, 2025

Needs more work still. We add a CA descriptor to the DDCI PMT based on pmt->caids, gotta refactor that.

@Jalle19
Copy link
Collaborator Author

Jalle19 commented Sep 5, 2025

@catalinii what do you think about the approach in the latest commit? It needs some cleanup to reduce deduplication but it seems to work.

As far as I can tell, the only time the PMT itself contains a CA descriptor is when all elementary streams in it are scrambled. If a PMT contains e.g. subtitle elementary streams then the CA descriptor is placed on the individual elementary streams instead.

The end results of this change is that we only send actually encrypted PIDs to the CAM without having to use heuristics like "is video or audio", which is ultimately needed by #1303

@Jalle19
Copy link
Collaborator Author

Jalle19 commented Sep 5, 2025

Bit harder to test the CA PID mapping now but let's see

@catalinii
Copy link
Owner

LGTM.

Can u add some tests around process_pmt -> ddci_process_pmt to ensure everything happens as expected?

Basically to capture different scenarios (most of them were on Astra 19) and at least we can improve the unit testing to reduce the risk on future changes.

@Jalle19
Copy link
Collaborator Author

Jalle19 commented Sep 5, 2025

I'll clean this up and will try to add some more tests, then runtime test it for a while

@Jalle19
Copy link
Collaborator Author

Jalle19 commented Sep 6, 2025

Thinking about this some more. Would be nice to not have to complicate things so much, especially since tested code needs to be changed and new tests made.

@Jalle19 Jalle19 changed the title Improve how PIDs are selected for descrambling WIP: Improve how PIDs are selected for descrambling Sep 7, 2025
@Jalle19
Copy link
Collaborator Author

Jalle19 commented Sep 19, 2025

The way it stands right now, no PIDs will get sent to DVBAPI if the whole PMT is marked as scrambled... Need to rethink how to handle this. I think we should mark both PMTs and stream PIDs as scrambled.

@Jalle19
Copy link
Collaborator Author

Jalle19 commented Sep 19, 2025

Yeah, I'll refactor this so that both stream PIDs and PMTs have a list of descriptors and an is_scrambled boolean. This way it will also be easier to reconstruct the PMT in DDCI - no need to "convert" program-level descreiptors to elementary stream-level ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants