Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two small memory leaks #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/C++/Core/Ap4CommonEncryption.cpp
Expand Up @@ -1873,6 +1873,8 @@ class AP4_CencFragmentDecrypter : public AP4_Processor::FragmentHandler {
m_SaizAtom(saiz_atom),
m_SampleEncryptionAtom(sample_encryption_atom) {}

~AP4_CencFragmentDecrypter() { delete m_SampleDecrypter; }

// methods
virtual AP4_Result ProcessFragment();
virtual AP4_Result FinishFragment();
Expand Down
29 changes: 28 additions & 1 deletion Source/C++/Core/Ap4Mpeg2Ts.cpp
Expand Up @@ -721,7 +721,8 @@ AP4_Mpeg2TsVideoSampleStream::WriteSample(AP4_Sample& sample,
+---------------------------------------------------------------------*/
AP4_Mpeg2TsWriter::AP4_Mpeg2TsWriter(AP4_UI16 pmt_pid) :
m_Audio(NULL),
m_Video(NULL)
m_Video(NULL),
m_Id3(NULL)
{
m_PAT = new Stream(0);
m_PMT = new Stream(pmt_pid);
Expand All @@ -736,6 +737,7 @@ AP4_Mpeg2TsWriter::~AP4_Mpeg2TsWriter()
delete m_PMT;
delete m_Audio;
delete m_Video;
delete m_Id3;
}

/*----------------------------------------------------------------------
Expand Down Expand Up @@ -799,6 +801,10 @@ AP4_Mpeg2TsWriter::WritePMT(AP4_ByteStream& output)
section_length += 5+m_Video->m_Descriptor.GetDataSize();;
pcr_pid = m_Video->GetPID();
}
if (m_Id3) {
section_length += 5+m_Id3->m_Descriptor.GetDataSize();
// Don't consider the ID3 stream for the PCR (Program Clock Reference)
}

writer.Write(0, 8); // pointer
writer.Write(2, 8); // table_id
Expand Down Expand Up @@ -839,6 +845,17 @@ AP4_Mpeg2TsWriter::WritePMT(AP4_ByteStream& output)
}
}

if (m_Id3) {
writer.Write(m_Id3->m_StreamType, 8); // stream_type
writer.Write(0x7, 3); // reserved
writer.Write(m_Id3->GetPID(), 13); // elementary_PID
writer.Write(0xF, 4); // reserved
writer.Write(m_Id3->m_Descriptor.GetDataSize(), 12); // ES_info_length
for (unsigned int i=0; i<m_Id3->m_Descriptor.GetDataSize(); i++) {
writer.Write(m_Id3->m_Descriptor.GetData()[i], 8);
}
}

writer.Write(ComputeCRC(writer.GetData()+1, section_length-1), 32); // CRC

output.Write(writer.GetData(), section_length+4);
Expand Down Expand Up @@ -901,6 +918,16 @@ AP4_Mpeg2TsWriter::SetVideoStream(AP4_UI32 timescale,
return AP4_SUCCESS;
}

/*----------------------------------------------------------------------
| AP4_Mpeg2TsWriter::AssignId3Stream
+---------------------------------------------------------------------*/
AP4_Result
AP4_Mpeg2TsWriter::AssignId3Stream(SampleStream* stream)
{
m_Id3 = stream;
return AP4_SUCCESS;
}

/*----------------------------------------------------------------------
| AP4_Mpeg2TsWriter::SampleStream::WriteSample
+---------------------------------------------------------------------*/
Expand Down
4 changes: 4 additions & 0 deletions Source/C++/Core/Ap4Mpeg2Ts.h
Expand Up @@ -156,12 +156,16 @@ class AP4_Mpeg2TsWriter
AP4_UI16 pid = AP4_MPEG2_TS_DEFAULT_PID_VIDEO,
const AP4_UI08* descriptor = NULL,
AP4_Size descriptor_length = 0);
// Using 'Assign' instead of 'Set' since a stream object is not
// actually created like in SetAudioStream() or SetVideoStream()
AP4_Result AssignId3Stream(SampleStream* stream);

private:
Stream* m_PAT;
Stream* m_PMT;
SampleStream* m_Audio;
SampleStream* m_Video;
SampleStream* m_Id3;
};

#endif // _AP4_MPEG2_TS_H_