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 6 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/C++/Core/Ap4CommonEncryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2794,12 +2794,12 @@ AP4_CencSampleInfoTable::Create(AP4_ProtectedSampleDescription* sample_descripti
child = child->GetNext()) {
if (child->GetData()->GetType() == AP4_ATOM_TYPE_SAIO) {
saio = AP4_DYNAMIC_CAST(AP4_SaioAtom, child->GetData());
if (saio->GetAuxInfoType() != 0 && saio->GetAuxInfoType() != AP4_PROTECTION_SCHEME_TYPE_CENC) {
if (saio != NULL && saio->GetAuxInfoType() != 0 && saio->GetAuxInfoType() != AP4_PROTECTION_SCHEME_TYPE_CENC) {
saio = NULL;
}
} else if (child->GetData()->GetType() == AP4_ATOM_TYPE_SAIZ) {
saiz = AP4_DYNAMIC_CAST(AP4_SaizAtom, child->GetData());
if (saiz->GetAuxInfoType() != 0 && saiz->GetAuxInfoType() != AP4_PROTECTION_SCHEME_TYPE_CENC) {
if (saiz != NULL && saiz->GetAuxInfoType() != 0 && saiz->GetAuxInfoType() != AP4_PROTECTION_SCHEME_TYPE_CENC) {
saiz = NULL;
}
}
Expand Down
29 changes: 28 additions & 1 deletion Source/C++/Core/Ap4Mpeg2Ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,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 @@ -760,6 +761,7 @@ AP4_Mpeg2TsWriter::~AP4_Mpeg2TsWriter()
delete m_PMT;
delete m_Audio;
delete m_Video;
delete m_Id3;
}

/*----------------------------------------------------------------------
Expand Down Expand Up @@ -823,6 +825,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 @@ -863,6 +869,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 @@ -929,6 +946,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
7 changes: 6 additions & 1 deletion Source/C++/Core/Ap4Mpeg2Ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,17 @@ class AP4_Mpeg2TsWriter
const AP4_UI08* descriptor = NULL,
AP4_Size descriptor_length = 0,
AP4_UI64 pcr_offset = AP4_MPEG2_TS_DEFAULT_PCR_OFFSET);


// 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_