Skip to content

Commit

Permalink
Merge pull request #1710 from CastagnaIT/revert_senc
Browse files Browse the repository at this point in the history
[FragmentedSampleReader] Check default_isProtected before add senc
  • Loading branch information
CastagnaIT authored Nov 2, 2024
2 parents 935a80a + a9e7ca4 commit 397a0c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/common/AdaptiveUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ AP4_Movie* PLAYLIST::CreateMovieAtom(adaptive::AdaptiveStream& adStream,
defaultKid = DRM::ConvertKidStrToBytes(psshSet.defaultKID_);

AP4_ContainerAtom schi{AP4_ATOM_TYPE_SCHI};
schi.AddChild(new AP4_TencAtom(AP4_CENC_CIPHER_AES_128_CTR, 8, defaultKid.data()));
// Note TENC default_isProtected parameter is intentionally set to 0 (not encrypted)
// this is to prevent CFragmentedSampleReader::ProcessMoof from trying to create a SENC atom
// and so avoid decrypting with a CAdaptiveCencSampleDecrypter
schi.AddChild(new AP4_TencAtom(0, 8, defaultKid.data()));
sampleDesc = new AP4_ProtectedSampleDescription(0, sampleDesc, 0,
AP4_PROTECTION_SCHEME_TYPE_PIFF, 0, "", &schi);
}
Expand Down
18 changes: 16 additions & 2 deletions src/samplereader/FragmentedSampleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,24 @@ AP4_Result CFragmentedSampleReader::ProcessMoof(AP4_ContainerAtom* moof,
if (!m_protectedDesc || !traf)
return AP4_ERROR_INVALID_FORMAT;

bool isDefaultProtected{true};
AP4_ContainerAtom* schi = m_protectedDesc->GetSchemeInfo()->GetSchiAtom();
if (schi)
{
AP4_CencTrackEncryption* trackEnc =
AP4_DYNAMIC_CAST(AP4_CencTrackEncryption, schi->GetChild(AP4_ATOM_TYPE_TENC));
if (!trackEnc)
trackEnc = AP4_DYNAMIC_CAST(AP4_CencTrackEncryption,
schi->GetChild(AP4_UUID_PIFF_TRACK_ENCRYPTION_ATOM));
if (trackEnc)
isDefaultProtected = trackEnc->GetDefaultIsProtected() != 0;
}

// If the boxes saiz, saio, senc are missing, the stream does not conform to the specs and
// may not be decrypted, so try create an empty senc where all samples will use the same default IV
if (!traf->GetChild(AP4_ATOM_TYPE_SAIO) && !traf->GetChild(AP4_ATOM_TYPE_SAIZ) &&
!traf->GetChild(AP4_ATOM_TYPE_SENC))
if (isDefaultProtected && !traf->GetChild(AP4_ATOM_TYPE_SAIO) &&
!traf->GetChild(AP4_ATOM_TYPE_SAIZ) && !traf->GetChild(AP4_ATOM_TYPE_SENC) &&
!traf->GetChild(AP4_UUID_PIFF_SAMPLE_ENCRYPTION_ATOM))
{
traf->AddChild(new AP4_SencAtom());
}
Expand Down

0 comments on commit 397a0c1

Please sign in to comment.