From 0c10f1266b07610811c19fe0c72f52d7c13bec9c Mon Sep 17 00:00:00 2001 From: truedread Date: Tue, 13 Aug 2019 00:00:10 -0700 Subject: [PATCH 1/2] Fix show-progress argument for mp4decrypt --- Source/C++/Apps/Mp4Decrypt/Mp4Decrypt.cpp | 3 ++- Source/C++/Core/Ap4Processor.cpp | 12 +++++++++--- Source/C++/Core/Ap4Processor.h | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/C++/Apps/Mp4Decrypt/Mp4Decrypt.cpp b/Source/C++/Apps/Mp4Decrypt/Mp4Decrypt.cpp index 471291878..6f0780555 100644 --- a/Source/C++/Apps/Mp4Decrypt/Mp4Decrypt.cpp +++ b/Source/C++/Apps/Mp4Decrypt/Mp4Decrypt.cpp @@ -79,7 +79,8 @@ class ProgressListener : public AP4_Processor::ProgressListener AP4_Result ProgressListener::OnProgress(unsigned int step, unsigned int total) { - printf("\r%d/%d", step, total); + fprintf(stdout, "\r%d/%d", step, total); + fflush(stdout); return AP4_SUCCESS; } diff --git a/Source/C++/Core/Ap4Processor.cpp b/Source/C++/Core/Ap4Processor.cpp index 17c6dab37..990a396ec 100644 --- a/Source/C++/Core/Ap4Processor.cpp +++ b/Source/C++/Core/Ap4Processor.cpp @@ -143,6 +143,7 @@ AP4_Processor::ProcessFragments(AP4_MoovAtom* moov, AP4_ContainerAtom* mfra, AP4_SidxAtom* sidx, AP4_Position sidx_position, + ProgressListener* listener, AP4_ByteStream& input, AP4_ByteStream& output) { @@ -370,6 +371,11 @@ AP4_Processor::ProcessFragments(AP4_MoovAtom* moov, for (unsigned int i=0; iOnProgress(fragment_index+1, atoms.ItemCount()); + } } // update the mfra if we have one @@ -692,7 +698,7 @@ AP4_Processor::Process(AP4_ByteStream& input, AP4_ASSERT(after-before == mdat_payload_size); #endif } - + // find the position of the sidx atom AP4_Position sidx_position = 0; if (sidx) { @@ -708,7 +714,7 @@ AP4_Processor::Process(AP4_ByteStream& input, } // process the fragments, if any - result = ProcessFragments(moov, frags, mfra, sidx, sidx_position, fragments?*fragments:input, output); + result = ProcessFragments(moov, frags, mfra, sidx, sidx_position, listener, fragments?*fragments:input, output); if (AP4_FAILED(result)) return result; // update and re-write the sidx if we have one @@ -745,7 +751,7 @@ AP4_Processor::Process(AP4_ByteStream& input, // so we need to delete it here delete moov; } - + return AP4_SUCCESS; } diff --git a/Source/C++/Core/Ap4Processor.h b/Source/C++/Core/Ap4Processor.h index b8c9e9925..794747bc5 100644 --- a/Source/C++/Core/Ap4Processor.h +++ b/Source/C++/Core/Ap4Processor.h @@ -263,6 +263,7 @@ class AP4_Processor { AP4_ContainerAtom* mfra, AP4_SidxAtom* sidx, AP4_Position sidx_position, + ProgressListener* listener, AP4_ByteStream& input, AP4_ByteStream& output); From 907235eb24ef728e34f8bfaca2eaf16dc928223a Mon Sep 17 00:00:00 2001 From: truedread Date: Tue, 13 Aug 2019 00:18:24 -0700 Subject: [PATCH 2/2] Fix for PIFF encryption type and selection of track by KID --- Source/C++/Core/Ap4CommonEncryption.cpp | 16 +++++++++++++++- Source/C++/Core/Ap4CommonEncryption.h | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Source/C++/Core/Ap4CommonEncryption.cpp b/Source/C++/Core/Ap4CommonEncryption.cpp index 73d84493c..dae31252b 100644 --- a/Source/C++/Core/Ap4CommonEncryption.cpp +++ b/Source/C++/Core/Ap4CommonEncryption.cpp @@ -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) { @@ -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); + } + } } } if (sample_entries.ItemCount() == 0) return NULL; diff --git a/Source/C++/Core/Ap4CommonEncryption.h b/Source/C++/Core/Ap4CommonEncryption.h index a40068655..bc8116610 100644 --- a/Source/C++/Core/Ap4CommonEncryption.h +++ b/Source/C++/Core/Ap4CommonEncryption.h @@ -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 @@ -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; }; /*----------------------------------------------------------------------