Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to correctly do AP4_CencSampleInfoTable::Create on particular file #781

Closed
glennguy opened this issue Sep 29, 2022 · 3 comments
Closed

Comments

@glennguy
Copy link

glennguy commented Sep 29, 2022

Hi again
The attached zip contains the init and a segment from an audio track of a CBCS encrypted stream:
audio.zip
This decrypts successfully in browser/official app, but bento4/Kodi/inputstream.adaptive is not currently handling this properly.

When trying to create a sampleinfotable it's missing data because there's no SAIZ/SAIO boxes, and the SENC box is effectively empty:
image

This here actually creates the sampleinfotable:

// try to create a sample info table from senc
if (sample_info_table == NULL && sample_encryption_atom) {
AP4_Result result = sample_encryption_atom->CreateSampleInfoTable(0,
crypt_byte_block,
skip_byte_block,
per_sample_iv_size,
constant_iv_size,
constant_iv,
sample_info_table);
if (AP4_FAILED(result)) return result;
}

But m_sampleCount is 0 (and probably more data missing too), no IVs are stored and ultimately calling DecryptSampleData fails here:
if (iv == NULL) return AP4_ERROR_INVALID_FORMAT;

I'm hoping you can help with a solution or at least point me in the right direction. I've been at it for a couple of hours and tried a few things but now getting to the point of needing some help.

Thanks heaps.

edit: btw this is from the same stream/program with incorrect boxes in the video stream from issue #742

@glennguy
Copy link
Author

glennguy commented Sep 30, 2022

Hi I have some more info.

So I now see that the 'data' in this box is indicating that there's a 0 count for sample info.

From this document: https://www.uvcentral.com/files/CFFMediaFormat-2_1.pdf on page 39

sample_count is the number of encrypted samples in this track fragment. This value SHALL be
either zero (‘0’) or the total number of samples in the track fragment.

I have a workaround here but not really sure if it's proper. I just copy/pasted code from another function that gets the sample info count from the trun box. With this number populated the table is successfully created. I also had to alter SetSampleInfoSize to update m_SampleInfoCount - this made sense to me: https://github.com/glennguy/Bento4-axiomatic/commit/5b5200b01a243fe4be7fd72559ac356ef3cc0cad https://github.com/glennguy/Bento4-axiomatic/commit/96c9abfc603be06310cb9902d87f1d12959b46ab

Grateful for your feedback.

@barbibulle
Copy link
Contributor

This file is also not compliant (no saiz and saio, which are required by the spec).
I committed a change to the main branch that supports this case where saiz and saio are missing, and an senc box is present with sample_count == 0. In this case, all samples will use the same default IV.
Note that this is implemented with a special case for sample_count == 0 rather than building a table for all the samples, because just looking at the sample count in a trun box isn't enough to know how many samples there may be.
I couldn't verify that this works for your file, other than it not erroring out, because I don't have the decryption key, so I can't check that the decryption was actually correct.
Please let me know if this fix works for you.

@glennguy
Copy link
Author

glennguy commented Oct 2, 2022

Thanks for looking at this @barbibulle
Works like a charm, thanks heaps for very fast turnaround!

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

No branches or pull requests

2 participants