Skip to content

Commit 23cbc52

Browse files
committed
test
1 parent b8718f9 commit 23cbc52

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

src/samplereader/FragmentedSampleReader.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,10 @@ AP4_Result CFragmentedSampleReader::ReadSample()
133133
streamType = DRM::DRMMediaType::AUDIO;
134134

135135
AP4_Result result;
136+
AP4_DataBuffer sampleData;
136137
if (!m_codecHandler->ReadNextSample(m_sample, m_sampleData))
137138
{
138-
bool useDecryptingDecoder =
139-
m_protectedDesc &&
140-
(m_decrypterCaps.flags & DRM::DecrypterCapabilites::SSD_SECURE_PATH) != 0;
141-
bool decrypterPresent{m_decrypter != nullptr};
142-
if (AP4_FAILED(result = ReadNextSample(m_track->GetId(), m_sample,
143-
(m_decrypter || useDecryptingDecoder) ? m_encrypted
144-
: m_sampleData)))
139+
if (AP4_FAILED(result = ReadNextSample(m_track->GetId(), m_sample, sampleData)))
145140
{
146141
if (result == AP4_ERROR_EOS)
147142
{
@@ -166,20 +161,24 @@ AP4_Result CFragmentedSampleReader::ReadSample()
166161
return result;
167162
}
168163

164+
//Protection could have changed in ProcessMoof
165+
bool useDecryptingDecoder =
166+
m_protectedDesc &&
167+
(m_decrypterCaps.flags & DRM::DecrypterCapabilites::SSD_SECURE_PATH) != 0;
168+
//bool decrypterPresent{m_decrypter != nullptr};
169+
169170
//AP4_AvcSequenceParameterSet sps;
170171
//AP4_AvcFrameParser::ParseFrameForSPS(m_sampleData.GetData(), m_sampleData.GetDataSize(), 4, sps);
171-
172-
//Protection could have changed in ProcessMoof
172+
/*
173173
if (!decrypterPresent && m_decrypter != nullptr && !useDecryptingDecoder)
174174
m_encrypted.SetData(m_sampleData.GetData(), m_sampleData.GetDataSize());
175175
else if (decrypterPresent && m_decrypter == nullptr && !useDecryptingDecoder)
176176
m_sampleData.SetData(m_encrypted.GetData(), m_encrypted.GetDataSize());
177-
177+
*/
178178
if (m_decrypter)
179179
{
180-
m_sampleData.Reserve(m_encrypted.GetDataSize());
181-
if (AP4_FAILED(result =
182-
m_decrypter->DecryptSampleData(m_poolId, m_encrypted, m_sampleData,
180+
m_sampleData.Reserve(sampleData.GetDataSize());
181+
if (AP4_FAILED(result = m_decrypter->DecryptSampleData(m_poolId, sampleData, m_sampleData,
183182
NULL, streamType)))
184183
{
185184
LOG::Log(LOGERROR, "Decrypt Sample returns failure!");
@@ -200,10 +199,12 @@ AP4_Result CFragmentedSampleReader::ReadSample()
200199
}
201200
else if (useDecryptingDecoder)
202201
{
203-
m_sampleData.Reserve(m_encrypted.GetDataSize());
204-
m_singleSampleDecryptor->DecryptSampleData(m_poolId, m_encrypted, m_sampleData, nullptr, 0,
202+
m_sampleData.Reserve(sampleData.GetDataSize());
203+
m_singleSampleDecryptor->DecryptSampleData(m_poolId, sampleData, m_sampleData, nullptr, 0,
205204
nullptr, nullptr, streamType);
206205
}
206+
else
207+
m_sampleData.SetData(sampleData.GetData(), sampleData.GetDataSize());
207208

208209
if (m_codecHandler->Transform(m_sample.GetDts(), m_sample.GetDuration(), m_sampleData,
209210
m_track->GetMediaTimeScale()))
@@ -405,9 +406,12 @@ AP4_Result CFragmentedSampleReader::ProcessMoof(AP4_ContainerAtom* moof,
405406
AP4_CencSampleInfoTable* sample_table{nullptr};
406407
AP4_UI32 algorithm_id = 0;
407408

408-
delete m_decrypter;
409-
m_decrypter = 0;
410-
409+
if (m_decrypter)
410+
{
411+
delete m_decrypter;
412+
m_decrypter = nullptr;
413+
}
414+
411415
AP4_ContainerAtom* traf =
412416
AP4_DYNAMIC_CAST(AP4_ContainerAtom, moof->GetChild(AP4_ATOM_TYPE_TRAF, 0));
413417

@@ -472,11 +476,16 @@ AP4_Result CFragmentedSampleReader::ProcessMoof(AP4_ContainerAtom* moof,
472476
else
473477
{
474478
// Reset for unencrypted content
479+
if (m_decrypter)
480+
{
481+
delete m_decrypter;
482+
m_decrypter = nullptr;
483+
}
475484
m_readerCryptoInfo = CryptoInfo();
476485
}
477486
}
478487
SUCCESS:
479-
if (m_singleSampleDecryptor && m_codecHandler)
488+
if (m_singleSampleDecryptor && m_decrypter && m_codecHandler)
480489
{
481490
if (AP4_FAILED(m_singleSampleDecryptor->SetFragmentInfo(
482491
m_poolId, m_defaultKey, m_codecHandler->m_naluLengthSize, m_codecHandler->m_extraData,

src/samplereader/FragmentedSampleReader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class ATTR_DLL_LOCAL CFragmentedSampleReader : public ISampleReader, public AP4_
7070
uint64_t m_timeBaseExt{0};
7171
uint64_t m_timeBaseInt{0};
7272
AP4_Sample m_sample;
73-
AP4_DataBuffer m_encrypted;
7473
AP4_DataBuffer m_sampleData;
7574
CodecHandler* m_codecHandler{nullptr};
7675
std::vector<uint8_t> m_defaultKey;

0 commit comments

Comments
 (0)