Skip to content
Closed

WV Test #1935

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 36 additions & 21 deletions src/samplereader/FragmentedSampleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ bool CFragmentedSampleReader::Initialize(SESSION::CStream* stream)
AP4_SampleDescription* desc{m_track->GetSampleDescription(0)};
if (desc->GetType() == AP4_SampleDescription::TYPE_PROTECTED)
{
m_protectedDesc = static_cast<AP4_ProtectedSampleDescription*>(desc);
auto protectedDesc = static_cast<AP4_ProtectedSampleDescription*>(desc);

AP4_ContainerAtom* schi;
if (m_protectedDesc->GetSchemeInfo() &&
(schi = m_protectedDesc->GetSchemeInfo()->GetSchiAtom()))
if (protectedDesc->GetSchemeInfo() && (schi = protectedDesc->GetSchemeInfo()->GetSchiAtom()))
{
AP4_TencAtom* tenc(AP4_DYNAMIC_CAST(AP4_TencAtom, schi->GetChild(AP4_ATOM_TYPE_TENC, 0)));
if (tenc && tenc->GetDefaultKid())
Expand Down Expand Up @@ -133,15 +132,10 @@ AP4_Result CFragmentedSampleReader::ReadSample()
streamType = DRM::DRMMediaType::AUDIO;

AP4_Result result;
AP4_DataBuffer sampleData;
if (!m_codecHandler->ReadNextSample(m_sample, m_sampleData))
{
bool useDecryptingDecoder =
m_protectedDesc &&
(m_decrypterCaps.flags & DRM::DecrypterCapabilites::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 (AP4_FAILED(result = ReadNextSample(m_track->GetId(), m_sample, sampleData)))
{
if (result == AP4_ERROR_EOS)
{
Expand All @@ -166,20 +160,25 @@ AP4_Result CFragmentedSampleReader::ReadSample()
return result;
}

//Protection could have changed in ProcessMoof
bool useDecryptingDecoder =
m_singleSampleDecryptor &&
(m_decrypterCaps.flags & DRM::DecrypterCapabilites::SSD_SECURE_PATH) != 0;
//bool decrypterPresent{m_decrypter != nullptr};

//AP4_AvcSequenceParameterSet sps;
//AP4_AvcFrameParser::ParseFrameForSPS(m_sampleData.GetData(), m_sampleData.GetDataSize(), 4, sps);

//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());

*/
if (m_decrypter)
{
m_sampleData.Reserve(m_encrypted.GetDataSize());
if (AP4_FAILED(result =
m_decrypter->DecryptSampleData(m_poolId, m_encrypted, m_sampleData,
LOG::Log(LOGERROR, "READSAMPLE USE m_decrypter");
m_sampleData.Reserve(sampleData.GetDataSize());
if (AP4_FAILED(result = m_decrypter->DecryptSampleData(m_poolId, sampleData, m_sampleData,
NULL, streamType)))
{
LOG::Log(LOGERROR, "Decrypt Sample returns failure!");
Expand All @@ -200,10 +199,16 @@ AP4_Result CFragmentedSampleReader::ReadSample()
}
else if (useDecryptingDecoder)
{
m_sampleData.Reserve(m_encrypted.GetDataSize());
m_singleSampleDecryptor->DecryptSampleData(m_poolId, m_encrypted, m_sampleData, nullptr, 0,
LOG::Log(LOGERROR, "READSAMPLE USE useDecryptingDecoder");
m_sampleData.Reserve(sampleData.GetDataSize());
m_singleSampleDecryptor->DecryptSampleData(m_poolId, sampleData, m_sampleData, nullptr, 0,
nullptr, nullptr, streamType);
}
else
{
LOG::Log(LOGERROR, "READSAMPLE USE nothing");
m_sampleData.SetData(sampleData.GetData(), sampleData.GetDataSize());
}

if (m_codecHandler->Transform(m_sample.GetDts(), m_sample.GetDuration(), m_sampleData,
m_track->GetMediaTimeScale()))
Expand Down Expand Up @@ -405,9 +410,12 @@ AP4_Result CFragmentedSampleReader::ProcessMoof(AP4_ContainerAtom* moof,
AP4_CencSampleInfoTable* sample_table{nullptr};
AP4_UI32 algorithm_id = 0;

delete m_decrypter;
m_decrypter = 0;

if (m_decrypter)
{
delete m_decrypter;
m_decrypter = nullptr;
}

AP4_ContainerAtom* traf =
AP4_DYNAMIC_CAST(AP4_ContainerAtom, moof->GetChild(AP4_ATOM_TYPE_TRAF, 0));

Expand Down Expand Up @@ -472,6 +480,11 @@ AP4_Result CFragmentedSampleReader::ProcessMoof(AP4_ContainerAtom* moof,
else
{
// Reset for unencrypted content
if (m_decrypter)
{
delete m_decrypter;
m_decrypter = nullptr;
}
m_readerCryptoInfo = CryptoInfo();
}
}
Expand Down Expand Up @@ -513,9 +526,11 @@ void CFragmentedSampleReader::UpdateSampleDescription()
LOG::LogF(LOGERROR, "Cannot sample description from protected sample description");
return;
}
LOG::LogF(LOGWARNING, "m_protectedDesc PRESENT");
}
else {
m_protectedDesc = nullptr;
LOG::LogF(LOGWARNING, "m_protectedDesc NOT-PRESENT");
}

LOG::LogF(LOGDEBUG, "Codec fourcc: %s (%u)", CODEC::FourCCToString(desc->GetFormat()).c_str(),
Expand Down
1 change: 0 additions & 1 deletion src/samplereader/FragmentedSampleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class ATTR_DLL_LOCAL CFragmentedSampleReader : public ISampleReader, public AP4_
uint64_t m_timeBaseExt{0};
uint64_t m_timeBaseInt{0};
AP4_Sample m_sample;
AP4_DataBuffer m_encrypted;
AP4_DataBuffer m_sampleData;
CodecHandler* m_codecHandler{nullptr};
std::vector<uint8_t> m_defaultKey;
Expand Down