Repository navigation
Open
Labels
Type: Featurenon-breaking change which adds functionality
Description
Describe the feature
I found out that some manifest stream using key rotation with Zero KID placeholder (no pssh or kid information in mpd file and init segments) and inputstream.adaptive can not extract kid/pssh. With the same stream on desktop browser and using eme logger, I still able to get "quite long pssh" value and tried to decode it using Axinom Portal and saw that three is still kid value different than 0.
If it is possible to process this kind of MPD stream with inputstream.adaptive would be great! Thank you all!
2024-07-20 16:52:27.052 T:294952 info <general>: AddOnLog: inputstream.adaptive: Manifest successfully parsed (Periods: 1, Streams in first period: 4, Type: live)
2024-07-20 16:52:27.196 T:294952 error <general>: AddOnLog: inputstream.adaptive: License data: Cannot extract PSSH/KID data from the stream
2024-07-20 16:52:27.196 T:294952 warning <general>: AddOnLog: inputstream.adaptive: Initializing stream with unknown KID!
Here is information from mp4dump of init.m4s file to show that it has zero hex KID or PSSH:
[ftyp] size=8+16
major_brand = iso5
minor_version = 200
compatible_brand = iso6
compatible_brand = mp41
[moov] size=8+750
[mvhd] size=12+96
timescale = 1000
duration = 0
duration(ms) = 0
[trak] size=8+496
[tkhd] size=12+80, flags=3
enabled = 1
id = 1
duration = 0
width = 0.000000
height = 0.000000
[mdia] size=8+396
[mdhd] size=12+20
timescale = 48000
duration = 0
duration(ms) = 0
language = und
[hdlr] size=12+33
handler_type = soun
handler_name = SoundHandler
[minf] size=8+311
[smhd] size=12+4
balance = 0
[dinf] size=8+28
[dref] size=12+16
[url ] size=12+0, flags=1
location = [local to file]
[stbl] size=8+251
[stsd] size=12+171
entry_count = 1
[enca] size=8+159
data_reference_index = 1
channel_count = 2
sample_size = 16
sample_rate = 48000
[esds] size=12+39
[ESDescriptor] size=5+34
es_id = 1
stream_priority = 0
[DecoderConfig] size=5+20
stream_type = 5
object_type = 64
up_stream = 0
buffer_size = 0
max_bitrate = 127875
avg_bitrate = 0
DecoderSpecificInfo = 11 90
[Descriptor:06] size=5+1
[sinf] size=8+72
[frma] size=8+4
original_format = mp4a
[schm] size=12+8
scheme_type = cenc
scheme_version = 65536
[schi] size=8+32
[tenc] size=12+20
default_isProtected = 1
default_Per_Sample_IV_Size = 8
default_KID = [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
[stts] size=12+4
entry_count = 0
[stsc] size=12+4
entry_count = 0
[stsz] size=12+8
sample_size = 0
sample_count = 0
[stco] size=12+4
entry_count = 0
[mvex] size=8+32
[trex] size=12+20
track id = 1
default sample description index = 1
default sample duration = 0
default sample size = 0
default sample flags = 0
[udta] size=8+90
[meta] size=12+78
[hdlr] size=12+21
handler_type = mdir
handler_name =
[ilst] size=8+37
[.too] size=8+29
[data] size=8+21
type = 1
lang = 0
value = Lavf58.27.103
Motivation
inputstream.adaptive can play very well normal mpd stream on Kodi but fail to play mpd stream with Key Rotation with Zero KID Placeholder.
Are you willing to contribute in development?
No
Should a possible backport be considered?
No
Reacted by dimov-cz
Metadata
Metadata
Assignees
Labels
Type: Featurenon-breaking change which adds functionality
Type
Projects
- StatusShow more project fieldsTo do - Long term
Activity
CastagnaIT commentedon Aug 15, 2024
by assuming for widevine this sample stream should help us to make a future implementation
it will be a long-term thing (many months) at least from my part
dimov-cz commentedon Mar 20, 2025
Any plans on this?
Support in-band key rotation with zero KID placeholder (fixes xbmc#1602)
Support in-band key rotation with zero KID placeholder (fixes xbmc#1602)
Support in-band key rotation with zero KID placeholder (fixes xbmc#1602)
dimov-cz commentedon Sep 1, 2026
Following up on my "Any plans on this?" from last year - I gave it a go and it works.
Short version: the zero-KID / in-band rotation case can be handled with a fairly small change, and at least for the streams I tested it didn't need a full per-minute license renewal. The decrypter just has to be told which key each fragment uses.
I run Kodi 21 / Omega on CoreELEC (armhf, ODROID-N2+), so that's where I built and tested it. The SEIG/PSSH segment parsing from #1978 only lives on Piers, so my Omega branch backports that parsing and adds the wiring on top. On Piers the parsing is already there, so a PR would be mostly the wiring - which is why I'm asking first.
What it does (diff against Omega: Omega...feo-cz:inputstream.adaptive:keyrotation-pub):
CFragmentedSampleReaderflags a stream at init (m_useInbandKid) when the default KID is empty or all-zero, and for those streams reads the per-fragment KID from the SEIG box on every fragment and updates the reader key on change, soSetFragmentInfoalways hands the decrypter the current key. Streams with a valid default KID are left alone.CheckLicenseRenewal()(already called before everyDecrypt()) would cover a renewable-license case on top.AP4_SgpdAtommembers protected. Piers already has that, so it wouldn't need it.Test case is Czech Television (iVysilani) DRM VOD: no
default_KIDin the manifest, the init segmenttencKID is all zeros, and the real KID sits in each segment's SEIG box. Stock ISA fails with "Cannot extract PSSH/KID data from the stream" and nothing plays. With the change, two different programmes (different content keys) play and decrypt cleanly for several minutes, no decrypt errors.One honest caveat: these are VOD assets where the key stays constant, so I couldn't exercise real in-play key switching (that needs a live DRM stream, which is rare here). The code reads the SEIG KID every fragment and updates on change, so rotation should be handled, but I haven't verified the rotating case itself. Whether a renewal or a fresh session is needed when the CDM doesn't have the rotated key is the open question.
So - would a PR against Piers (the wiring on top of #1978) be welcome? And any preference on how you'd want the KID-change handling done before I open it?
CastagnaIT commentedon Sep 1, 2026
The concept of key rotation includes the DRM license management,
and your code doesn't do any of that, it just retrieves the KIDs... as is your code doesn’t make much sense
i will accept a PR only for a full feature implemented that include appropriate changes on widevine decrypter
dimov-cz commentedon Sep 3, 2026
Update on this - the rotating case now works too, so the open question from my last comment is answered.
Back then I could only test VOD assets with a constant key, so I couldn't exercise real in-play key switching. Since then I built a proper rotating stream (Shaka packager with
--crypto_period_duration, widevine_test key server) and also ran the public Shaka "firefox-key-rotation" demo asset against the cwip-shaka-proxy license server. Both rotate for real - a new content key every crypto period. (In-band rotation only covers key changes during playback, not the initial session bootstrap - the Shaka asset carries no PSSH in the manifest or the init segment, so I had to feed the first PSSH in by hand to get it started.)What VOD didn't need and rotation does: when a new period shows up with a KID the CDM has no key for, you have to fetch a fresh license from that segment's own PSSH (the pssh box in the moof).
CheckLicenseRenewal()alone doesn't cover it - that renews the existing session, it doesn't get you a key for a KID the session never had.The one thing that bit me: the license round-trip (fetching the new license over HTTP and feeding it back with
UpdateSession) is synchronous and takes ~1s, and if you run it on the demux thread the whole thing stalls and the picture stutters at every rotation. So the renewal runs on a worker thread. The reader queues the rotated KID (deduplicated) and adopts it right away; the old period keeps playing because its samples still carry the old key and old sessions are left open, only samples of the new KID have to wait (decode returns "not ready" until the key lands). Decoding deliberately doesn't take the CDM lock, so a renewal never stalls playback. On this box's L3 CDM that has been stable.This also needed two small changes in the vendored
cdm_adapter: a virtual getter that exposes the CDM mutex, plus a guard around the TimerExpired callback (it otherwise races the session ops on its own async thread). If you'd rather serialize that differently, I'm open to it.Result: across all rotations both streams play smoothly - no stutter and no dropped picture that I could see, several minutes each. That is from watching playback on the integrated video path (hardware decode); I haven't separately exercised rotating encrypted audio or the software CENC path.
I developed this on Omega because the target box is Kodi 21, so the branch is against Omega and backports the SEIG/PSSH parsing from #1978; on Piers that parsing is already in, so the real change is just the KID-per-fragment wiring plus the non-blocking renewal on top. Branch to build and try: Omega...feo-cz:inputstream.adaptive:keyrotation-v4 (being Omega-based it re-adds the #1978 parsing, so the real delta is smaller than the diff looks).
But my testing has been limited - two rotating streams, one box (L3 CDM), the hardware video path only, and no real live DRM (those are rare here). So this is more a "does it work for you too?" than a finished thing. If anyone can try the branch against a real live rotating stream, a different platform or CDM, encrypted audio, or the software CENC path, I'd be glad for the feedback - that would tell us whether it's worth turning into a proper PR and what still needs work.
[Widevine] In-band license renewal on key rotation
dimov-cz commentedon Nov 25, 2026
PRs are up against Piers: #2146 adds the in-band key rotation, #2147 has a few live playback fixes I found on the way (independent of DRM). Both are rebased on current Piers and run daily on live Czech TV channels (new key every ~10 min, new license every second key change) without a kNoKey or a stall. Testing on other platforms welcome, the list of what I couldn't test is in the PRs.
[Widevine] In-band license renewal on key rotation
[Widevine] In-band license renewal on key rotation
[Widevine] In-band license renewal on key rotation