我创建了一个程序,该程序使用Bento4解密曲目,但是我坚持将文件写入磁盘。写加密轨道时,程序崩溃,因为加密和解密样本的大小不同。
此问题出在以下注释之后,位于FragmentedSampleReader :: ReadSample()中的main.cpp中: //将初始化和数据写入解密的文件。
AP4_Result FragmentedSampleReader::ReadSample()
{
AP4_Position pos_init, pos_after_sample;
m_FragmentStream->Tell(pos_init);
AP4_Result result;
if (!m_codecHandler || !m_codecHandler->ReadNextSample(m_sample, m_sampleData))
{
bool useDecryptingDecoder = m_protectedDesc && (m_decrypterCaps.flags & SSD::SSD_DECRYPTER::SSD_CAPS::SSD_SECURE_PATH) != 0;
bool decrypterPresent(m_decrypter != nullptr);
if (AP4_FAILED(result = ReadNextSample(m_track->GetId(), m_sample, (m_decrypter || useDecryptingDecoder) ? m_encrypted : m_sampleData)))
{
if (result == AP4_ERROR_EOS)
{
if (dynamic_cast<AP4_DASHStream*>(m_FragmentStream)->waitingForSegment())
m_sampleData.SetDataSize(0);
else
m_eos = true;
}
return result;
}
//Protection could have changed in ProcessMoof
if (!decrypterPresent && m_decrypter != nullptr && !useDecryptingDecoder)
m_encrypted.SetData(m_sampleData.GetData(), m_sampleData.GetDataSize());
else if (decrypterPresent && m_decrypter == nullptr && !useDecryptingDecoder)
m_sampleData.SetData(m_encrypted.GetData(), m_encrypted.GetDataSize());
// Make sure that the decrypter is NOT allocating memory!
// If decrypter and addon are compiled with different DEBUG / RELEASE
// options freeing HEAP memory will fail.
if (m_decrypter)
{
m_sampleData.Reserve(m_encrypted.GetDataSize() + 4096);
result = m_decrypter->DecryptSampleData(m_poolId, m_encrypted, m_sampleData, NULL);
}
else if (useDecryptingDecoder)
{
m_sampleData.Reserve(m_encrypted.GetDataSize() + 1024);
result = m_singleSampleDecryptor->DecryptSampleData(m_poolId, m_encrypted, m_sampleData, nullptr, 0, nullptr, nullptr);
}
}
// Write initialisation & data into decrypted file
std::vector<char> buffer;
int pos_decrypted = file_decrypted_data.tellp();
if(pos_decrypted < pos_init)
{
buffer.reserve(pos_init - pos_decrypted);
file_fragment.seekg(pos_decrypted, std::ios::beg);
file_fragment.read(buffer.data(), pos_init - pos_decrypted);
file_decrypted_data.write(buffer.data(), pos_init - pos_decrypted);
}
m_FragmentStream->Tell(pos_after_sample);
int metadata_length = pos_after_sample - m_sampleData.GetDataSize() - pos_init;
buffer.reserve(metadata_length);
file_fragment.seekg(pos_init, std::ios::beg);
file_fragment.read(buffer.data(), metadata_length);
file_decrypted_data.write(buffer.data(), metadata_length);
file_decrypted_data.write((const char*)m_sampleData.GetData(), m_sampleData.GetDataSize());
return result;
};
我有一个官方的git repo:https://github.com/x-hgg-x/video_decrypter
它给了我下面的错误。
std::bad_alloc error