Skip to content

Conversation

@CastagnaIT
Copy link
Collaborator

Description

the issue #1973 revealed a clear implementation problem that we have been carrying with us since the early days of this add-on
ISA uses an incorrect method to select KID/PSSH to initialize DRM

current: look MPD protection data -> init DRM by using MPD data -> but MP4 reader use MP4 init segment protection info (reasons for mismatch and broken playback of your case)

needed: look MPD protection data -> look at MP4 init seg protection info -> try init DRM by using MP4 init seg protection info (init segment should have priority, since usually its more reliable, in theory) -> then if fails (e.g. missing KID) -> try init DRM by using MPD data

This is what i was able to understand also with the help of AI
since the drm info provided by segments should have always the priority over the MPD metadata, because segment data should be more updated than the MPD

an example is the CBCS sample stream from ISASamples addon where the MPD provide PSSH/defaultKID for SD content, instead the init segment provide the PSSH/defaultKID for HD content
so using the MPD protection data means broken playback

the issue #1973 instead is a bit different
MPD provide a correct PSSH/defKID, and init segment could be also correct but in this case the license for x reason dont provide the defaut KID specified by init segment, so fails, and should be used the MPD one (we need to fallback to MPD)

Full fixing this is not trivial and require much changes, also on android side that atm i don't have a complete picture due to missing pieces in our android wrapper code

Therefore even though it's a pain shit this workaround is the only thing that i can provide in a fast way

Motivation and context

a workaround for issue #1973
a complete fix require too much changes that touch different components
and too much time is required to do it

anyway it will be my next task to do since IMO is of fundamental importance

How has this been tested?

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • I have read the Contributing document
  • My code follows the Code Guidelines of this project
  • My change requires a change to the Wiki documentation
  • I have updated the documentation accordingly

@CastagnaIT CastagnaIT added Type: Feature non-breaking change which adds functionality v22 Piers labels Jan 13, 2026
@github-actions
Copy link
Contributor

Critical

Logic error: Inverted condition (src/samplereader/FragmentedSampleReader.cpp:112)
The condition !kodiProps.GetManifestConfig().ignoreMp4defaultKid || defaultKid.empty() is logically incorrect. When ignoreMp4defaultKid is true, the code should use manifest KID (skip MP4 parsing), but the condition still parses MP4 if defaultKid.empty(). This means if manifest KID is empty and user wants to ignore MP4, it will still use MP4 KID. The logic should be: use MP4 when flag is false OR when manifest KID is empty (fallback). Current logic: use MP4 when flag is false OR manifest KID is empty (same), but else branch only executes when flag is true AND manifest KID exists. If user sets flag to true but manifest has no KID, MP4 is used anyway, defeating the purpose.

//! @todo: This is a temporary workaround for a much broader issue,
//! where DRM initialization should occur first with MP4 init segment protection data
//! and then if it fails, try init DRM with manifest protection data
if (!kodiProps.GetManifestConfig().ignoreMp4defaultKid || defaultKid.empty())
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic error: This condition is incorrect. When ignoreMp4defaultKid=true, you want to skip MP4 parsing and use manifest KID. But if defaultKid.empty(), the condition evaluates true and MP4 is parsed anyway, defeating the flag's purpose.

The else branch (line 138) only executes when BOTH ignoreMp4defaultKid=true AND !defaultKid.empty(). If manifest provides no KID, the flag is ignored.

Likely intended: Parse MP4 when (flag is false) OR (manifest KID unavailable as fallback). Current achieves same for if-branch but else-branch is too restrictive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes the code flow is so messy, a future code rework is needed,
anyway the default kid if missing from MPD is extracted by DRM engine from same init segment, so change nothing, i removed the OR condition

…perty

This is a temporary workaround for a much broader issue
where DRM initialization should occur first by using MP4 init segment protection data
then if fails fallback by using manifest protection data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature non-breaking change which adds functionality v22 Piers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant