Skip to content

Commit

Permalink
[FragmentedSampleReader] Check default_isProtected before add senc
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Oct 30, 2024
1 parent b0130e9 commit d63dc6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/common/AdaptiveUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ 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()));
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 d63dc6f

Please sign in to comment.