Skip to content

Commit

Permalink
Added basic support for parsing sidx indexes
Browse files Browse the repository at this point in the history
Added support for interfacing with key servers using the SKM API (mp4-dash)
Fixed invalid 16-bit truncation when encrypting large frames with MPEG CENC
Fixed minor warnings
  • Loading branch information
bok committed Oct 3, 2014
1 parent 055768b commit 9f48dd7
Show file tree
Hide file tree
Showing 19 changed files with 550 additions and 32 deletions.
1 change: 1 addition & 0 deletions Build/Makefiles/Lib.mak
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ CORE_SOURCES = \
Ap4BlocAtom.cpp \
Ap4PsshAtom.cpp \
Ap4Dec3Atom.cpp \
Ap4SidxAtom.cpp \
Ap4HvccAtom.cpp \
Ap4NalParser.cpp \
Ap4AvcParser.cpp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
CA646B4F0CE97E49009699D7 /* Mp42Aac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CA646A8A0CE97B2D009699D7 /* Mp42Aac.cpp */; };
CA646B5F0CE97E75009699D7 /* Mp4RtpHintInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CA646A980CE97B2D009699D7 /* Mp4RtpHintInfo.cpp */; };
CA646B6F0CE97EC9009699D7 /* CryptoTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CA646A9D0CE97B51009699D7 /* CryptoTest.cpp */; };
CA7B648019D2355F00068D77 /* Ap4SidxAtom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CA7B647E19D2355F00068D77 /* Ap4SidxAtom.cpp */; };
CA7B648119D2355F00068D77 /* Ap4SidxAtom.h in Headers */ = {isa = PBXBuildFile; fileRef = CA7B647F19D2355F00068D77 /* Ap4SidxAtom.h */; };
CA7EECEC0F720663009F85F9 /* CompareFiles.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CA7EECE10F720627009F85F9 /* CompareFiles.cpp */; };
CA86EED119A95C68008A3B00 /* Ap4SegmentBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CA86EECF19A95C68008A3B00 /* Ap4SegmentBuilder.cpp */; };
CA86EED219A95C68008A3B00 /* Ap4SegmentBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = CA86EED019A95C68008A3B00 /* Ap4SegmentBuilder.h */; };
Expand Down Expand Up @@ -979,6 +981,8 @@
CA646B4A0CE97E27009699D7 /* mp42aac */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = mp42aac; sourceTree = BUILT_PRODUCTS_DIR; };
CA646B5A0CE97E52009699D7 /* mp4rtphintinfo */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = mp4rtphintinfo; sourceTree = BUILT_PRODUCTS_DIR; };
CA646B6A0CE97E82009699D7 /* cryptotest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = cryptotest; sourceTree = BUILT_PRODUCTS_DIR; };
CA7B647E19D2355F00068D77 /* Ap4SidxAtom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Ap4SidxAtom.cpp; sourceTree = "<group>"; };
CA7B647F19D2355F00068D77 /* Ap4SidxAtom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Ap4SidxAtom.h; sourceTree = "<group>"; };
CA7EECE10F720627009F85F9 /* CompareFiles.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompareFiles.cpp; sourceTree = "<group>"; };
CA7EECE50F720648009F85F9 /* CompareFilesTest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CompareFilesTest; sourceTree = BUILT_PRODUCTS_DIR; };
CA86EECF19A95C68008A3B00 /* Ap4SegmentBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Ap4SegmentBuilder.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1828,8 +1832,6 @@
children = (
CA5A8F8B13541628007C6EFC /* Ap4.cpp */,
CA9366100B437D030067D50B /* Ap4.h */,
CA9CB9BC0F86ABB400063C70 /* Ap48bdlAtom.cpp */,
CA9CB9BD0F86ABB400063C70 /* Ap48bdlAtom.h */,
CAF0104515343D5D00CCD976 /* Ap4AinfAtom.cpp */,
CAF0104615343D5D00CCD976 /* Ap4AinfAtom.h */,
CA9366110B437D030067D50B /* Ap4Array.h */,
Expand Down Expand Up @@ -1997,6 +1999,8 @@
CA86EED019A95C68008A3B00 /* Ap4SegmentBuilder.h */,
CA5734FB13B5DCFA00953446 /* Ap4SencAtom.cpp */,
CA5734FC13B5DCFA00953446 /* Ap4SencAtom.h */,
CA7B647E19D2355F00068D77 /* Ap4SidxAtom.cpp */,
CA7B647F19D2355F00068D77 /* Ap4SidxAtom.h */,
CA9366780B437D040067D50B /* Ap4SLConfigDescriptor.cpp */,
CA9366790B437D040067D50B /* Ap4SLConfigDescriptor.h */,
CA93667A0B437D040067D50B /* Ap4SmhdAtom.cpp */,
Expand Down Expand Up @@ -2051,6 +2055,8 @@
CA93669D0B437D040067D50B /* Ap4Version.h */,
CA93669E0B437D040067D50B /* Ap4VmhdAtom.cpp */,
CA93669F0B437D040067D50B /* Ap4VmhdAtom.h */,
CA9CB9BC0F86ABB400063C70 /* Ap48bdlAtom.cpp */,
CA9CB9BD0F86ABB400063C70 /* Ap48bdlAtom.h */,
);
name = Core;
path = "../../../Source/C++/Core";
Expand Down Expand Up @@ -2301,6 +2307,7 @@
CA9366F00B437D040067D50B /* Ap4OhdrAtom.h in Headers */,
CA9366F20B437D040067D50B /* Ap4OmaDcf.h in Headers */,
CA9366F40B437D040067D50B /* Ap4Processor.h in Headers */,
CA7B648119D2355F00068D77 /* Ap4SidxAtom.h in Headers */,
CA9366F60B437D040067D50B /* Ap4Protection.h in Headers */,
CA9366F70B437D040067D50B /* Ap4Results.h in Headers */,
CA9366F90B437D040067D50B /* Ap4RtpAtom.h in Headers */,
Expand Down Expand Up @@ -3375,6 +3382,7 @@
CA9366E10B437D040067D50B /* Ap4MoovAtom.cpp in Sources */,
CA86EED119A95C68008A3B00 /* Ap4SegmentBuilder.cpp in Sources */,
CA9366E30B437D040067D50B /* Ap4Movie.cpp in Sources */,
CA7B648019D2355F00068D77 /* Ap4SidxAtom.cpp in Sources */,
CA9366E50B437D040067D50B /* Ap4MvhdAtom.cpp in Sources */,
CA9366E70B437D040067D50B /* Ap4NmhdAtom.cpp in Sources */,
CA9366E90B437D040067D50B /* Ap4OdafAtom.cpp in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SaizAtom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SegmentBuilder.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SencAtom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SidxAtom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4Stz2Atom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4TencAtom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4TfdtAtom.cpp" />
Expand Down Expand Up @@ -216,6 +217,7 @@
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SaizAtom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SegmentBuilder.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SencAtom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SidxAtom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4Stz2Atom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4TencAtom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4TfdtAtom.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SegmentBuilder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SidxAtom.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4.h">
Expand Down Expand Up @@ -755,5 +758,8 @@
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SegmentBuilder.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SidxAtom.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SaizAtom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SegmentBuilder.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SencAtom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SidxAtom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4Stz2Atom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4TencAtom.cpp" />
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4TfdtAtom.cpp" />
Expand Down Expand Up @@ -221,6 +222,7 @@
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SaizAtom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SegmentBuilder.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SencAtom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SidxAtom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4Stz2Atom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4TencAtom.h" />
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4TfdtAtom.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SegmentBuilder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\Source\C++\Core\Ap4SidxAtom.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4.h">
Expand Down Expand Up @@ -758,5 +761,8 @@
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SegmentBuilder.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\Source\C++\Core\Ap4SidxAtom.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Source/C++/Core/Ap4.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
#include "Ap4TfraAtom.h"
#include "Ap4MfroAtom.h"
#include "Ap4Dec3Atom.h"
#include "Ap4SidxAtom.h"
#include "Ap4AdtsParser.h"
#include "Ap4AvcParser.h"
#include "Ap4SegmentBuilder.h"
Expand Down
1 change: 1 addition & 0 deletions Source/C++/Core/Ap4Atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ const AP4_Atom::Type AP4_ATOM_TYPE_MKID = AP4_ATOM_TYPE('m','k','i','d');
const AP4_Atom::Type AP4_ATOM_TYPE_PRFT = AP4_ATOM_TYPE('p','r','f','t');
const AP4_Atom::Type AP4_ATOM_TYPE_STPP = AP4_ATOM_TYPE('s','t','p','p');
const AP4_Atom::Type AP4_ATOM_TYPE_DEC3 = AP4_ATOM_TYPE('d','e','c','3');
const AP4_Atom::Type AP4_ATOM_TYPE_SIDX = AP4_ATOM_TYPE('s','i','d','x');

/*----------------------------------------------------------------------
| AP4_AtomListInspector
Expand Down
6 changes: 6 additions & 0 deletions Source/C++/Core/Ap4AtomFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
#include "Ap4AinfAtom.h"
#include "Ap4PsshAtom.h"
#include "Ap4Dec3Atom.h"
#include "Ap4SidxAtom.h"

/*----------------------------------------------------------------------
| AP4_AtomFactory::~AP4_AtomFactory
Expand Down Expand Up @@ -652,6 +653,11 @@ AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream& stream,
atom = AP4_PsshAtom::Create(size_32, stream);
break;

case AP4_ATOM_TYPE_SIDX:
if (atom_is_large) return AP4_ERROR_INVALID_FORMAT;
atom = AP4_SidxAtom::Create(size_32, stream);
break;

case AP4_ATOM_TYPE_MKID:
if (atom_is_large) return AP4_ERROR_INVALID_FORMAT;
if (GetContext() == AP4_ATOM_TYPE_MARL) {
Expand Down
4 changes: 2 additions & 2 deletions Source/C++/Core/Ap4CommonEncryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ AP4_CencCtrSubSampleEncrypter::GetSubSampleMap(AP4_DataBuffer& sample_data,

// store the info
bytes_of_cleartext_data.Append((AP4_UI16)cleartext_size);
bytes_of_encrypted_data.Append((AP4_UI16)(block_count*16));
bytes_of_encrypted_data.Append((AP4_UI32)(block_count*16));
}

return AP4_SUCCESS;
Expand Down Expand Up @@ -271,7 +271,7 @@ AP4_CencCbcSubSampleEncrypter::GetSubSampleMap(AP4_DataBuffer& sample_data,

// store the info
bytes_of_cleartext_data.Append((AP4_UI16)cleartext_size);
bytes_of_encrypted_data.Append((AP4_UI16)(block_count*16));
bytes_of_encrypted_data.Append((AP4_UI32)(block_count*16));
}

return AP4_SUCCESS;
Expand Down
156 changes: 156 additions & 0 deletions Source/C++/Core/Ap4SidxAtom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*****************************************************************
|
| AP4 - sidx Atoms
|
| Copyright 2002-2014 Axiomatic Systems, LLC
|
|
| This file is part of Bento4/AP4 (MP4 Atom Processing Library).
|
| Unless you have obtained Bento4 under a difference license,
| this version of Bento4 is Bento4|GPL.
| Bento4|GPL is free software; you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation; either version 2, or (at your option)
| any later version.
|
| Bento4|GPL is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with Bento4|GPL; see the file COPYING. If not, write to the
| Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
| 02111-1307, USA.
|
****************************************************************/

/*----------------------------------------------------------------------
| includes
+---------------------------------------------------------------------*/
#include "Ap4SidxAtom.h"
#include "Ap4Utils.h"

/*----------------------------------------------------------------------
| dynamic cast support
+---------------------------------------------------------------------*/
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_SidxAtom)


/*----------------------------------------------------------------------
| AP4_SidxAtom::Create
+---------------------------------------------------------------------*/
AP4_SidxAtom*
AP4_SidxAtom::Create(AP4_Size size, AP4_ByteStream& stream)
{
AP4_UI08 version;
AP4_UI32 flags;
if (AP4_FAILED(AP4_Atom::ReadFullHeader(stream, version, flags))) return NULL;
if (version > 1) return NULL;
return new AP4_SidxAtom(size, version, flags, stream);
}

/*----------------------------------------------------------------------
| AP4_SidxAtom::AP4_SidxAtom
+---------------------------------------------------------------------*/
AP4_SidxAtom::AP4_SidxAtom(AP4_UI32 size,
AP4_UI08 version,
AP4_UI32 flags,
AP4_ByteStream& stream) :
AP4_Atom(AP4_ATOM_TYPE_SIDX, size, version, flags)
{
stream.ReadUI32(m_ReferenceId);
stream.ReadUI32(m_TimeScale);
if (version == 0) {
AP4_UI32 earliest_presentation_time = 0;
AP4_UI32 first_offset = 0;
stream.ReadUI32(earliest_presentation_time);
stream.ReadUI32(first_offset);
m_EarliestPresentationTime = earliest_presentation_time;
m_FirstOffset = first_offset;
} else {
stream.ReadUI64(m_EarliestPresentationTime);
stream.ReadUI64(m_FirstOffset);
}
AP4_UI16 reserved;
stream.ReadUI16(reserved);
AP4_UI16 reference_count = 0;
stream.ReadUI16(reference_count);
if (size < AP4_FULL_ATOM_HEADER_SIZE+4+4+(version==0?8:16)+2+2+reference_count*12) {
// not enough space to store all references, something's wrong
return;
}
m_References.SetItemCount(reference_count);
for (unsigned int i=0; i<reference_count; i++) {
AP4_UI32 value = 0;
stream.ReadUI32(value);
m_References[i].m_ReferenceType = (value&(1<<31))?1:0;
m_References[i].m_ReferencedSize = value & 0x7FFFFFFF;
stream.ReadUI32(m_References[i].m_SubsegmentDuration);
stream.ReadUI32(value);
m_References[i].m_StartsWithSap = ((value&(1<<31)) != 0);
m_References[i].m_SapType = (AP4_UI08)((value >>28)&0x07);
m_References[i].m_SapDeltaTime = value & 0x0FFFFFFF;
}
}

/*----------------------------------------------------------------------
| AP4_SidxAtom::WriteFields
+---------------------------------------------------------------------*/
AP4_Result
AP4_SidxAtom::WriteFields(AP4_ByteStream& stream)
{
stream.WriteUI32(m_ReferenceId);
stream.WriteUI32(m_TimeScale);
if (m_Version == 0) {
stream.WriteUI32((AP4_UI32)m_EarliestPresentationTime);
stream.WriteUI32((AP4_UI32)m_FirstOffset);
} else {
stream.WriteUI64(m_EarliestPresentationTime);
stream.WriteUI64(m_FirstOffset);
}
stream.WriteUI16(0);
stream.WriteUI16((AP4_UI16)m_References.ItemCount());
for (unsigned int i=0; i<m_References.ItemCount(); i++) {
stream.WriteUI32((m_References[i].m_ReferenceType<<31) |
m_References[i].m_ReferencedSize);
stream.WriteUI32(m_References[i].m_SubsegmentDuration);
stream.WriteUI32(((m_References[i].m_StartsWithSap?1:0)<<31) |
(m_References[i].m_SapType << 28) |
m_References[i].m_SapDeltaTime);
}

return AP4_SUCCESS;
}

/*----------------------------------------------------------------------
| AP4_SidxAtom::InspectFields
+---------------------------------------------------------------------*/
AP4_Result
AP4_SidxAtom::InspectFields(AP4_AtomInspector& inspector)
{
inspector.AddField("reference_ID", m_ReferenceId);
inspector.AddField("timescale", m_TimeScale);
inspector.AddField("earliest_presentation_time", m_EarliestPresentationTime);
inspector.AddField("first_offset", m_FirstOffset);

if (inspector.GetVerbosity() >= 1) {
AP4_UI32 reference_count = m_References.ItemCount();
for (unsigned int i=0; i<reference_count; i++) {
char header[32];
AP4_FormatString(header, sizeof(header), "%04d", i);
char value[256];
AP4_FormatString(value, sizeof(value), "reference_type=%d, referenced_size=%u, subsegment_duration=%u, starts_with_SAP=%d, SAP_type=%d, SAP_delta_time=%d",
m_References[i].m_ReferenceType,
m_References[i].m_ReferencedSize,
m_References[i].m_SubsegmentDuration,
m_References[i].m_StartsWithSap,
m_References[i].m_SapType,
m_References[i].m_SapDeltaTime);
inspector.AddField(header, value);
}
}

return AP4_SUCCESS;
}
Loading

0 comments on commit 9f48dd7

Please sign in to comment.