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

Various MP4Decrypt fixes #420

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion Source/C++/Core/Ap4CommonEncryption.cpp
Expand Up @@ -2315,7 +2315,7 @@ AP4_CencFragmentDecrypter::ProcessSample(AP4_DataBuffer& data_in,
/*----------------------------------------------------------------------
| AP4_CencDecryptingProcessor::AP4_CencDecryptingProcessor
+---------------------------------------------------------------------*/
AP4_CencDecryptingProcessor::AP4_CencDecryptingProcessor(const AP4_ProtectionKeyMap* key_map,
AP4_CencDecryptingProcessor::AP4_CencDecryptingProcessor(AP4_ProtectionKeyMap* key_map,
AP4_BlockCipherFactory* block_cipher_factory) :
m_KeyMap(key_map)
{
Expand Down Expand Up @@ -2359,6 +2359,20 @@ AP4_CencDecryptingProcessor::CreateTrackHandler(AP4_TrakAtom* trak)
sample_descs.Append(protected_desc);
sample_entries.Append(sample_entry);
}

AP4_ContainerAtom* schi = protected_desc->GetSchemeInfo()->GetSchiAtom();
if (schi != NULL) {
AP4_CencTrackEncryption* tenc;
if (protected_desc->GetSchemeType() == AP4_PROTECTION_SCHEME_TYPE_PIFF) {
tenc = AP4_DYNAMIC_CAST(AP4_CencTrackEncryption, schi->GetChild(AP4_ATOM_TYPE_UUID));
} else {
tenc = AP4_DYNAMIC_CAST(AP4_CencTrackEncryption, schi->GetChild(AP4_ATOM_TYPE_TENC));
}
if (tenc != NULL) {
const AP4_DataBuffer* key = m_KeyMap->GetKeyByKid(tenc->GetDefaultKid());
if (key != NULL) m_KeyMap->SetKey(trak->GetId(), key->GetData(), 16);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing to the key map from AP4_CencDecryptingProcessor breaks the constness of that map. It doesn't seem right. Can you explain why you need to write a key here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mp4decrypt couldn't properly handle selecting the track based on key ID, it only seemed to work by track ID.

}
}
}
}
if (sample_entries.ItemCount() == 0) return NULL;
Expand Down
4 changes: 2 additions & 2 deletions Source/C++/Core/Ap4CommonEncryption.h
Expand Up @@ -653,7 +653,7 @@ class AP4_CencDecryptingProcessor : public AP4_Processor
{
public:
// constructor
AP4_CencDecryptingProcessor(const AP4_ProtectionKeyMap* key_map,
AP4_CencDecryptingProcessor(AP4_ProtectionKeyMap* key_map,
AP4_BlockCipherFactory* block_cipher_factory = NULL);

// AP4_Processor methods
Expand All @@ -667,7 +667,7 @@ class AP4_CencDecryptingProcessor : public AP4_Processor
protected:
// members
AP4_BlockCipherFactory* m_BlockCipherFactory;
const AP4_ProtectionKeyMap* m_KeyMap;
AP4_ProtectionKeyMap* m_KeyMap;
};

/*----------------------------------------------------------------------
Expand Down