inputstream.adaptive
inputstream.adaptive copied to clipboard
[MPD K20/21] Audio stopped working with CBCS encryption
Bug report
Describe the bug
Recently my live television provider switched from CENC to CBCS encryption, unfortunately after this the audio playback stopped working.
Expected Behavior
Working video and audio when opening the live stream.
Actual Behavior
Stream opens without audio/sound and the video sometimes seems to be buffering every x seconds probably due to the audio not getting decrypted and decoded properly.
Kodi does show the audio tracks when you open the audio settings in the player, but there is no sound on both the audio tracks.
Possible Fix
See if there is a way to fix or add support for CBCS audio if this is the issue and not a codec problem.
To Reproduce
The live streams seem to be limited/locked to my ip or hostname by my isp, so you sadly won't be able to open them if your isp does not match.
Debuglog, DASH and MPD
You can find debug logs, dash files and mpd files here: https://github.com/trdum/cbcsinput
Your Environment
Tested operating systems:
- Windows 11
- Android 13
- Linux Ubuntu 20.04
- macOS Big Sur
Tested Kodi versions:
- Kodi 18 and 19: No CBCS support so no video and audio.
- Kodi 20.5 / InputAdaptive 20.3.18: Video Ok, Audio None
- Kodi 21b3 / InputAdaptive 21.4.3: Video Ok, Audio None
with CBCS is shown these ffmpeg errors, imo this could be or bad decrypted data or not supported stream
2024-02-09 14:25:16.396 T:5728 debug <general>: ffmpeg[0x19f9ec37ce0]: [ac3] Multiple frames in a packet.
2024-02-09 14:25:16.396 T:5728 debug <general>: ffmpeg[0x19f9ec37ce0]: [ac3] Additional substreams is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
2024-02-09 14:25:16.396 T:5728 debug <general>: ffmpeg[0x19f9ec37ce0]: [ac3] If you want to help, upload a sample of this file to https://streams.videolan.org/upload/ and contact the ffmpeg-devel mailing list. ([email protected])
2024-02-09 14:25:16.407 T:5728 error <general>: ffmpeg[0x19f9ec37ce0]: [ac3] invalid bitstream id
2024-02-09 14:25:16.407 T:5728 debug <general>: CVideoPlayerAudio: stream props changed, checking for passthrough
2024-02-09 14:25:16.407 T:5728 info <general>: CDVDAudioCodecFFmpeg::Open() Successful opened audio decoder ac3
2024-02-09 14:25:16.407 T:5728 info <general>: Creating audio stream (codec id: 86019, channels: 3, sample rate: 48000, no pass-through)
I can't help on that, maybe someone else will be able to provide help
Thanks for taking the time to look into the issue.
I'm secretly hoping the ffmpeg/ac3 errors are caused because the audio isn't decrypted by inputstream adaptive making Kodi fail to playback the audio and output those errors in the logs because the audio stream it is trying to open is still encrypted and can't understand it this way.
When opening the CBCS streams in the web browser the audio works as it should, I did found a way to still access the CENC streams and the audio works in Kodi but most likely they will close those streams soon.
I tried to do some comparison between the CENC and CBCS audio streams using a few different tools but I can't detect much difference between the two, my knowledge analyzing and comparing streams is limited but here are some details:
So far I can see the streams provide two audio tracks one AC3 and one AAC.
CBCS and CENC both have the same audio tracks:
AC3 5chan (1633889587/86019) (ATSC A52 Dolby AC-3 Audio)
AAC 2chan (1836069985/86018) (AAC-LC ISO/IEC 13818-7 Audio with ADTS)
The audio tracks seem to be using identical codecs... as far as I can see, it also won't make much sense to me if they would use completely different audio codecs when the only logical difference should be the DRM to reduce unnecessary server load on their end.
Edit: added a few more dash examples to the logs that hopefully might help.
All I can suggest is either a) decryption isn't happening for audio or b) decryption isn't happening correctly
The log is consistent with the audio decoder being fed junk... I'm inclined to think that it's just not being decrypted at all.
I don't think it's likely the files themselves are the wrong codec compared to what the manifest reports.
Are you able to provide more info on if/how we could reproduce this ourselves (is it a free service and is it geolocked)? Alternatively if you can build inputstream.adaptive we could ask for a couple of log statements to insert into the decrypter to confirm whether audio decryption is happening or not.
Thanks for the reply.
The live streams are provided by my ISP and seem to be locked to my ip or hostname, the requested mpd links expire after a few minutes so I unfortunately can't share the streams.
I can build inputstream adaptive manually and tried to change a few things but I don't have enough knowledge on how the CBCS decryption fully works, attaching visual studio debugger to Kodi doesn't work with DRM streams because Kodi crashes. (According to the wiki this is because of the encryption)
Just tried a few other free CBCS streams I found online, for example this one also only has working video and no audio on the CBCS stream:
Edit: converted to m3u playlists https://github.com/Trdum/cbcsplaylist
Stream URLs: https://media.axprod.net/TestVectors/v9-MultiFormat/Clear/Manifest_1080p.mpd (VideoOk+AudioOk) https://media.axprod.net/TestVectors/v9-MultiFormat/Encrypted_Cenc/Manifest_1080p.mpd (VideoOk+AudioOk) https://media.axprod.net/TestVectors/v9-MultiFormat/Encrypted_Cbcs/Manifest_1080p.mpd (VideoOk+AudioFail)
License URL: https://drm-widevine-licensing.axtest.net/AcquireLicense
Request header: "X-AxDRM-Message": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiNjllNTQwODgtZTllMC00NTMwLThjMWEtMWViNmRjZDBkMTRlIiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsInZlcnNpb24iOjIsImxpY2Vuc2UiOnsiYWxsb3dfcGVyc2lzdGVuY2UiOnRydWV9LCJjb250ZW50X2tleXNfc291cmNlIjp7ImlubGluZSI6W3siaWQiOiJmOGM4MGMyNS02OTBmLTQ3MzYtODEzMi00MzBlNWM2OTk0Y2UiLCJlbmNyeXB0ZWRfa2V5IjoiaVhxNDlaODlzOGRDajBqbTJBN1h6UT09IiwidXNhZ2VfcG9saWN5IjoiUG9saWN5IEEifV19LCJjb250ZW50X2tleV91c2FnZV9wb2xpY2llcyI6W3sibmFtZSI6IlBvbGljeSBBIiwicGxheXJlYWR5Ijp7Im1pbl9kZXZpY2Vfc2VjdXJpdHlfbGV2ZWwiOjE1MCwicGxheV9lbmFibGVycyI6WyI3ODY2MjdEOC1DMkE2LTQ0QkUtOEY4OC0wOEFFMjU1QjAxQTciXX19XX19.k9OlwW0rUwuf5d5Eb0iO98AFR3qp7qKdFzSbg2PQj78"
Post data: R{SSM}
Hope the audio not working on the stream above is caused by the same issue as my stream.
If this is not the case I can add extra debug logs to inputstream adaptive to help find the issue there.
Few more CBCS example streams I tested: https://storage.googleapis.com/shaka-demo-assets/sintel-cbcs/dash.mpd (VideoOk+AudioOk) https://github.com/Axinom/public-test-vectors/blob/master/axinom.exolist.json (VideoOk+AudioOk) https://github.com/Axinom/public-test-vectors/blob/master/TestVectors-v9.md https://refapp.hbbtv.org/production/catalogue/config.json
Ok, you need to put something like this: LOG::Log(LOGDEBUG, "Decrypting sample - Stream Id: %u, mode: %u, crypt blocks: %u, skip blocks: %u", m_streamId, m_readerCryptoInfo.m_mode, m_readerCryptoInfo.m_cryptBlocks, m_readerCryptoInfo.m_skipBlocks); into FragmentedSampleReader.cpp:
Inbetween these 2 lines: https://github.com/xbmc/inputstream.adaptive/blob/31dc91e870313c9145d881d17abcb372997a274f/src/samplereader/FragmentedSampleReader.cpp#L177-L178 and these 2 lines: https://github.com/xbmc/inputstream.adaptive/blob/31dc91e870313c9145d881d17abcb372997a274f/src/samplereader/FragmentedSampleReader.cpp#L199-L200
Mode should be 2 for CBCS and 1 for CENC (0 for unencrypted which shouldn't happen) Crypt/Skip should be 1/9 for CBCS and 0/0 for CENC.
And of course for your CBCS stream you should be seeing log statements for both audio and video stream IDs e.g 1001, 1004... something like that.
I haven't actually compiled and tested myself but it should be right
ISP Stream CBCS:
inputstream.adaptive: Decrypting sample 177178 - Stream Id: 1001, mode: 2, crypt blocks: 1, skip blocks: 9
Opening stream: 1001 source: 256 Creating video codec with codec id: 27 Opening stream: 1003 source: 256 Finding audio codec for: 86019
ISP Stream CENC:
inputstream.adaptive: Decrypting sample 177178 - Stream Id: 1001, mode: 1, crypt blocks: 0, skip blocks: 0 inputstream.adaptive: Decrypting sample 177178 - Stream Id: 1003, mode: 1, crypt blocks: 0, skip blocks: 0
Opening stream: 1001 source: 256 Creating video codec with codec id: 27 Opening stream: 1003 source: 256 Finding audio codec for: 86019
Test Axinom Stream CBCS:
AddOnLog: inputstream.adaptive: Decrypting sample 177178 - Stream Id: 1001, mode: 2, crypt blocks: 1, skip blocks: 9
Opening stream: 1001 source: 256 Creating video codec with codec id: 27 Opening stream: 1002 source: 256 Finding audio codec for: 86018
Test Axinom Stream CENC:
inputstream.adaptive: Decrypting sample 177178 - Stream Id: 1001, mode: 1, crypt blocks: 0, skip blocks: 0 inputstream.adaptive: Decrypting sample 177178 - Stream Id: 1002, mode: 1, crypt blocks: 0, skip blocks: 0
Opening stream: 1001 source: 256 Creating video codec with codec id: 27 Opening stream: 1002 source: 256 Finding audio codec for: 86018
Both my ISP and Axinom test CBCS stream seems to be skipping the audio track decryption.
On the CBCS streams I only see stream 1001 and it's not showing any logs for line 199/200, when I place the debug log on line 175 the audio track shows up as "Stream Id: 1002, mode: 0, crypt blocks: 0, skip blocks: 0"
Perhaps you can try to open the Axinom stream on your Kodi to see if you have the same result, guess this will also make it alot easier for you to find the issue using that stream, guessing the issue is the same as my ISP stream.
I made m3u files of the Axinom streams so you can easily open them as files in Kodi to test here: https://github.com/Trdum/cbcsplaylist
Thanks for helping.
Ok thanks for all that info, very helpful!
My usual Windows debugging trick of setting a sleep statement then attaching debugger and breaking afterwards isn't working atm, just crashes :/ I've traced the issue to here https://github.com/xbmc/inputstream.adaptive/blob/31dc91e870313c9145d881d17abcb372997a274f/src/samplereader/FragmentedSampleReader.cpp#L378-L379
Even though the TRAF atom is there under the MOOF, it fails to get it
And from there the m_decrypter member is left empty and the next readsample will not try to decrypt.
So maybe a bug in bento4? @CastagnaIT have you had any luck recently with attaching debugger in Windows when widevine is involved?
Otherwise maybe we have to look at setting up some test code to load a file in and try that way...
unfurnately no way debugwith drm... add some log the AP4_CencSampleInfoTable::Create return error -10 (AP4_ERROR_INVALID_FORMAT) https://github.com/xbmc/inputstream.adaptive/blob/31dc91e870313c9145d881d17abcb372997a274f/src/samplereader/FragmentedSampleReader.cpp#L385-L387
imo this happens on second part of Create method
https://github.com/xbmc/Bento4/blob/1f295b8a7c2c20c6398032dcfbf398ddb68a3300/Source/C%2B%2B/Core/Ap4CommonEncryption.cpp#L2788-L2789 or line https://github.com/xbmc/Bento4/blob/1f295b8a7c2c20c6398032dcfbf398ddb68a3300/Source/C%2B%2B/Core/Ap4CommonEncryption.cpp#L2822-L2824
on video packet the saio/saiz/senc there are
but on audio packet these atoms seem to be all missing i suspect that exit with last check for sample_info_table that return AP4_ERROR_INVALID_FORMAT
its similar situation about your old issue: https://github.com/axiomatic-systems/Bento4/issues/781 but your old workaround is no more available on links maybe you remember something
Yeah I can see that a workaround could be to create a senc atom.
I'm not having much luck. I can create a senc atom but can't get the sample count populated. Otherwise I can create the data for the atom but can't get it to dynamic cast. Or, we ask bento4 to help with this case upstream. What do you think?
senc atom just needs to be 16 bytes and added as child to traf and set traf as parent
- UI32 for box size (00 00 00 16)
- UI32 for box type (AP4_ATOM_TYPE_SENC)
- UI32 for flags etc (00 00 00 00)
- UI32 for data - sample count eg. (00 00 00 BB) -
trun->GetEntries().ItemCount()
i tested sample stream with shaka player that a/v works hoping to find some hint on sourcecode but without luck, yeah it is worth trying to ask for some advice on how best to proceed to bento4 dev
I've opened an issue at bento4 https://github.com/axiomatic-systems/Bento4/issues/944
@Trdum have you some time to test your stream with broken audio? here some test builds, its for Kodi 22: https://jenkins.kodi.tv/blue/organizations/jenkins/xbmc%2Finputstream.adaptive/detail/PR-1688/1/artifacts
i will backport to v21, but i would like have a your feedback in advance
Hey Stefano,
I can confirm audio is now working on the CBCS live tv streams.
Tested using KodiSetup-20241006-4b7921ce-master-x64 on Windows 11.
Thanks for picking up this issue and fixing it.