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/Ap4CommonEncryption.cpp b/Source/C++/Core/Ap4CommonEncryption.cpp index 7ceb01d6d..f4d8ef5c3 100644 --- a/Source/C++/Core/Ap4CommonEncryption.cpp +++ b/Source/C++/Core/Ap4CommonEncryption.cpp @@ -2329,7 +2329,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) { @@ -2403,6 +2403,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 56a18a2f5..76f727cae 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 @@ -670,7 +670,7 @@ class AP4_CencDecryptingProcessor : public AP4_Processor // members AP4_BlockCipherFactory* m_BlockCipherFactory; - const AP4_ProtectionKeyMap* m_KeyMap; + AP4_ProtectionKeyMap* m_KeyMap; }; /*---------------------------------------------------------------------- diff --git a/Source/C++/Core/Ap4Processor.cpp b/Source/C++/Core/Ap4Processor.cpp index c4e1d78f7..16e22206a 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) { @@ -380,6 +381,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 @@ -702,7 +708,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) { @@ -718,7 +724,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 @@ -755,7 +761,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);