From 835e024ad1f4e1818c85527e476c473416d2e18b Mon Sep 17 00:00:00 2001 From: Louis O'Bryan Date: Fri, 4 Aug 2017 11:10:50 -0700 Subject: [PATCH] Add CAMM atom and allow creating MP4 tracks with it. --- GNUmakefile.am | 1 + src/atom_camm.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/atoms.h | 9 +++++++++ src/mp4atom.cpp | 2 ++ src/mp4file.cpp | 10 +++++++++- 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/atom_camm.cpp diff --git a/GNUmakefile.am b/GNUmakefile.am index 947e6e3..d5071d0 100644 --- a/GNUmakefile.am +++ b/GNUmakefile.am @@ -16,6 +16,7 @@ libmp4v2_la_SOURCES = \ src/atom_amr.cpp \ src/atom_avc1.cpp \ src/atom_avcC.cpp \ + src/atom_camm.cpp \ src/atom_chpl.cpp \ src/atom_colr.cpp \ src/atom_d263.cpp \ diff --git a/src/atom_camm.cpp b/src/atom_camm.cpp new file mode 100644 index 0000000..a7ebbd7 --- /dev/null +++ b/src/atom_camm.cpp @@ -0,0 +1,42 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is MPEG4IP. + * + * The Initial Developer of the Original Code is Cisco Systems Inc. + * Portions created by Cisco Systems Inc. are + * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. + * + */ + +#include "src/impl.h" + +namespace mp4v2 { +namespace impl { + +/////////////////////////////////////////////////////////////////////////////// + +MP4CammAtom::MP4CammAtom(MP4File &file) + : MP4Atom(file, "camm") +{ + AddVersionAndFlags(); + + MP4Integer32Property* pCount = + new MP4Integer32Property(*this, "entryCount"); + pCount->SetValue(1); + pCount->SetReadOnly(); + AddProperty(pCount); +} + +/////////////////////////////////////////////////////////////////////////////// + +} +} // namespace mp4v2::impl diff --git a/src/atoms.h b/src/atoms.h index 382706f..672eee7 100644 --- a/src/atoms.h +++ b/src/atoms.h @@ -288,6 +288,15 @@ class MP4S263Atom : public MP4Atom { * Specialized Atoms ************************************************************************/ +class MP4CammAtom : public MP4Atom { +public: + MP4CammAtom(MP4File &file); +private: + MP4CammAtom(); + MP4CammAtom( const MP4CammAtom &src ); + MP4CammAtom &operator= ( const MP4CammAtom &src ); +}; + class MP4DrefAtom : public MP4Atom { public: MP4DrefAtom(MP4File &file); diff --git a/src/mp4atom.cpp b/src/mp4atom.cpp index 520cbc8..5ebbbe0 100644 --- a/src/mp4atom.cpp +++ b/src/mp4atom.cpp @@ -831,6 +831,8 @@ MP4Atom::factory( MP4File &file, MP4Atom* parent, const char* type ) break; case 'c': + if( ATOMID(type) == ATOMID("camm") ) + return new MP4CammAtom(file); if( ATOMID(type) == ATOMID("chap") ) return new MP4TrefTypeAtom( file, type ); if( ATOMID(type) == ATOMID("chpl") ) diff --git a/src/mp4file.cpp b/src/mp4file.cpp index 86f386b..1a27417 100644 --- a/src/mp4file.cpp +++ b/src/mp4file.cpp @@ -1132,7 +1132,11 @@ MP4TrackId MP4File::AddSystemsTrack(const char* type, uint32_t timeScale) (void)InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "nmhd", 0); - (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "mp4s"); + bool is_camm = strcmp(type, "camm") == 0; + const char *sample_entry = is_camm ? "camm" : "mp4s"; + + (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), + sample_entry); AddDescendantAtoms(MakeTrackName(trackId, NULL), "udta.name"); @@ -1144,6 +1148,10 @@ MP4TrackId MP4File::AddSystemsTrack(const char* type, uint32_t timeScale) (MP4Property**)&pStsdCountProperty); pStsdCountProperty->IncrementValue(); + if (is_camm) { + return trackId; + } + SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4s.esds.ESID", 0