diff --git a/Source/C++/Core/Ap4CommonEncryption.cpp b/Source/C++/Core/Ap4CommonEncryption.cpp index fbc4d1ff..fb1af586 100644 --- a/Source/C++/Core/Ap4CommonEncryption.cpp +++ b/Source/C++/Core/Ap4CommonEncryption.cpp @@ -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; } } diff --git a/Source/C++/Core/Ap4Mpeg2Ts.cpp b/Source/C++/Core/Ap4Mpeg2Ts.cpp index 8bc9c985..61fba123 100644 --- a/Source/C++/Core/Ap4Mpeg2Ts.cpp +++ b/Source/C++/Core/Ap4Mpeg2Ts.cpp @@ -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); @@ -760,6 +761,7 @@ AP4_Mpeg2TsWriter::~AP4_Mpeg2TsWriter() delete m_PMT; delete m_Audio; delete m_Video; + delete m_Id3; } /*---------------------------------------------------------------------- @@ -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 @@ -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; im_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); @@ -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 +---------------------------------------------------------------------*/ diff --git a/Source/C++/Core/Ap4Mpeg2Ts.h b/Source/C++/Core/Ap4Mpeg2Ts.h index ac6f5a4c..ddc117c9 100644 --- a/Source/C++/Core/Ap4Mpeg2Ts.h +++ b/Source/C++/Core/Ap4Mpeg2Ts.h @@ -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_