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

Add support for Video sample description extensions (COLR / GAMA / PASP / FIEL) #694

Open
wants to merge 3 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: 4 additions & 0 deletions Source/C++/Core/Ap4.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@
#include "Ap4Dec3Atom.h"
#include "Ap4Dac4Atom.h"
#include "Ap4SidxAtom.h"
#include "Ap4ColrAtom.h"
#include "Ap4GamaAtom.h"
#include "Ap4PaspAtom.h"
#include "Ap4FielAtom.h"
#include "Ap4AdtsParser.h"
#include "Ap4Ac4Parser.h"
#include "Ap4AvcParser.h"
Expand Down
13 changes: 13 additions & 0 deletions Source/C++/Core/Ap4Atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,15 @@ const AP4_Atom::Type AP4_ATOM_TYPE_HEV1 = AP4_ATOM_TYPE('h','e','v','1');
const AP4_Atom::Type AP4_ATOM_TYPE_HVC1 = AP4_ATOM_TYPE('h','v','c','1');
const AP4_Atom::Type AP4_ATOM_TYPE_DVHE = AP4_ATOM_TYPE('d','v','h','e');
const AP4_Atom::Type AP4_ATOM_TYPE_DVH1 = AP4_ATOM_TYPE('d','v','h','1');
const AP4_Atom::Type AP4_ATOM_TYPE_AP4H = AP4_ATOM_TYPE('a','p','4','h');
const AP4_Atom::Type AP4_ATOM_TYPE_AP4X = AP4_ATOM_TYPE('a','p','4','x');
const AP4_Atom::Type AP4_ATOM_TYPE_APCH = AP4_ATOM_TYPE('a','p','c','h');
const AP4_Atom::Type AP4_ATOM_TYPE_APCN = AP4_ATOM_TYPE('a','p','c','n');
const AP4_Atom::Type AP4_ATOM_TYPE_APCS = AP4_ATOM_TYPE('a','p','c','s');
const AP4_Atom::Type AP4_ATOM_TYPE_APCO = AP4_ATOM_TYPE('a','p','c','o');
const AP4_Atom::Type AP4_ATOM_TYPE_JPEG = AP4_ATOM_TYPE('j','p','e','g');
const AP4_Atom::Type AP4_ATOM_TYPE_AVDN = AP4_ATOM_TYPE('A','V','d','n');
const AP4_Atom::Type AP4_ATOM_TYPE_AVDH = AP4_ATOM_TYPE('A','V','d','h');
const AP4_Atom::Type AP4_ATOM_TYPE_VP08 = AP4_ATOM_TYPE('v','p','0','8');
const AP4_Atom::Type AP4_ATOM_TYPE_VP09 = AP4_ATOM_TYPE('v','p','0','9');
const AP4_Atom::Type AP4_ATOM_TYPE_VP10 = AP4_ATOM_TYPE('v','p','1','0');
Expand Down Expand Up @@ -588,6 +597,10 @@ const AP4_Atom::Type AP4_ATOM_TYPE_SIDX = AP4_ATOM_TYPE('s','i','d','x');
const AP4_Atom::Type AP4_ATOM_TYPE_SSIX = AP4_ATOM_TYPE('s','s','i','x');
const AP4_Atom::Type AP4_ATOM_TYPE_SBGP = AP4_ATOM_TYPE('s','b','g','p');
const AP4_Atom::Type AP4_ATOM_TYPE_SGPD = AP4_ATOM_TYPE('s','g','p','d');
const AP4_Atom::Type AP4_ATOM_TYPE_COLR = AP4_ATOM_TYPE('c','o','l','r');
const AP4_Atom::Type AP4_ATOM_TYPE_GAMA = AP4_ATOM_TYPE('g','a','m','a');
const AP4_Atom::Type AP4_ATOM_TYPE_PASP = AP4_ATOM_TYPE('p','a','s','p');
const AP4_Atom::Type AP4_ATOM_TYPE_FIEL = AP4_ATOM_TYPE('f','i','e','l');

/*----------------------------------------------------------------------
| AP4_AtomListInspector
Expand Down
37 changes: 37 additions & 0 deletions Source/C++/Core/Ap4AtomFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
#include "Ap4SidxAtom.h"
#include "Ap4SbgpAtom.h"
#include "Ap4SgpdAtom.h"
#include "Ap4ColrAtom.h"
#include "Ap4GamaAtom.h"
#include "Ap4PaspAtom.h"
#include "Ap4FielAtom.h"

/*----------------------------------------------------------------------
| AP4_AtomFactory::~AP4_AtomFactory
Expand Down Expand Up @@ -352,6 +356,19 @@ AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream& stream,
atom = new AP4_AudioSampleEntry(type, size_32, stream, *this);
break;

// ProRes
case AP4_ATOM_TYPE_AP4H:
case AP4_ATOM_TYPE_AP4X:
case AP4_ATOM_TYPE_APCH:
case AP4_ATOM_TYPE_APCN:
case AP4_ATOM_TYPE_APCS:
case AP4_ATOM_TYPE_APCO:
// mjpeg
case AP4_ATOM_TYPE_JPEG:
// Avid DNxHD / DNxHR
case AP4_ATOM_TYPE_AVDN:
case AP4_ATOM_TYPE_AVDH:
// VP8/9/10
case AP4_ATOM_TYPE_VP08:
case AP4_ATOM_TYPE_VP09:
case AP4_ATOM_TYPE_VP10:
Expand Down Expand Up @@ -777,6 +794,26 @@ AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream& stream,
}
break;

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

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

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

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

// track ref types
case AP4_ATOM_TYPE_HINT:
case AP4_ATOM_TYPE_CDSC:
Expand Down
119 changes: 119 additions & 0 deletions Source/C++/Core/Ap4ColrAtom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*****************************************************************
|
| AP4 - colr Atoms
|
| Copyright 2002-2022 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 "Ap4ColrAtom.h"
#include "Ap4Utils.h"

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

/*----------------------------------------------------------------------
| AP4_ColrAtom::Create
+---------------------------------------------------------------------*/
AP4_ColrAtom*
AP4_ColrAtom::Create(AP4_Size size, AP4_ByteStream& stream)
{
return new AP4_ColrAtom(size, stream);
}

/*----------------------------------------------------------------------
| AP4_ColrAtom::AP4_ColrAtom
+---------------------------------------------------------------------*/
AP4_ColrAtom::AP4_ColrAtom(AP4_UI32 type,
AP4_UI16 primaries,
AP4_UI16 transfer_function,
AP4_UI16 matrix_index) :
AP4_Atom(AP4_ATOM_TYPE_COLR, AP4_ATOM_HEADER_SIZE + 10),
m_Type(type),
m_Primaries(primaries),
m_TransferFunction(transfer_function),
m_MatrixIndex(matrix_index)
{
}

/*----------------------------------------------------------------------
| AP4_ColrAtom::AP4_ColrAtom
+---------------------------------------------------------------------*/
AP4_ColrAtom::AP4_ColrAtom() :
AP4_Atom(AP4_ATOM_TYPE_COLR, AP4_ATOM_HEADER_SIZE + 10),
m_Type(AP4_COLR_TYPE_NCLC),
m_Primaries(AP4_COLR_PRIMARIES_BT709),
m_TransferFunction(AP4_COLR_TRANSFER_FUNCTION_BT709),
m_MatrixIndex(AP4_COLR_COLORSPACE_BT709)
{
}

/*----------------------------------------------------------------------
| AP4_ColrAtom::AP4_ColrAtom
+---------------------------------------------------------------------*/
AP4_ColrAtom::AP4_ColrAtom(AP4_UI32 size,
AP4_ByteStream& stream) :
AP4_Atom(AP4_ATOM_TYPE_COLR, size)
{
stream.ReadUI32(m_Type);
stream.ReadUI16(m_Primaries);
stream.ReadUI16(m_TransferFunction);
stream.ReadUI16(m_MatrixIndex);
}

/*----------------------------------------------------------------------
| AP4_ColrAtom::InspectFields
+---------------------------------------------------------------------*/
AP4_Result
AP4_ColrAtom::InspectFields(AP4_AtomInspector& inspector)
{
char type[5];
AP4_FormatFourChars(type, m_Type);
inspector.AddField("type", type);
inspector.AddField("primaries", m_Primaries);
inspector.AddField("transfer_function", m_TransferFunction);
inspector.AddField("matrix_index", m_MatrixIndex);
return AP4_SUCCESS;
}

/*----------------------------------------------------------------------
| AP4_ColrAtom::WriteFields
+---------------------------------------------------------------------*/
AP4_Result
AP4_ColrAtom::WriteFields(AP4_ByteStream& stream)
{
AP4_Result result;
result = stream.WriteUI32(m_Type);
if (AP4_FAILED(result)) return result;
result = stream.WriteUI16(m_Primaries);
if (AP4_FAILED(result)) return result;
result = stream.WriteUI16(m_TransferFunction);
if (AP4_FAILED(result)) return result;
result = stream.WriteUI16(m_MatrixIndex);
return result;
}
136 changes: 136 additions & 0 deletions Source/C++/Core/Ap4ColrAtom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*****************************************************************
|
| AP4 - colr Atoms
|
| Copyright 2002-2022 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.
|
****************************************************************/

#ifndef _AP4_COLR_ATOM_H_
#define _AP4_COLR_ATOM_H_

/*----------------------------------------------------------------------
| includes
+---------------------------------------------------------------------*/
#include "Ap4Atom.h"

/*----------------------------------------------------------------------
| constants
+---------------------------------------------------------------------*/
const AP4_UI16 AP4_COLR_PRIMARIES_RESERVED0 = 0;
const AP4_UI16 AP4_COLR_PRIMARIES_BT709 = 1;
const AP4_UI16 AP4_COLR_PRIMARIES_UNSPECIFIED = 2;
const AP4_UI16 AP4_COLR_PRIMARIES_RESERVED = 3;
const AP4_UI16 AP4_COLR_PRIMARIES_BT470M = 4;
const AP4_UI16 AP4_COLR_PRIMARIES_BT470BG = 5;
const AP4_UI16 AP4_COLR_PRIMARIES_SMPTE170M = 6;
const AP4_UI16 AP4_COLR_PRIMARIES_SMPTE240M = 7;
const AP4_UI16 AP4_COLR_PRIMARIES_FILM = 8;
const AP4_UI16 AP4_COLR_PRIMARIES_BT2020 = 9;
const AP4_UI16 AP4_COLR_PRIMARIES_SMPTE428 = 10;
const AP4_UI16 AP4_COLR_PRIMARIES_XYZ = 10;
const AP4_UI16 AP4_COLR_PRIMARIES_SMPTE431 = 11;
const AP4_UI16 AP4_COLR_PRIMARIES_P3DCI = 11;
const AP4_UI16 AP4_COLR_PRIMARIES_SMPTE432 = 12;
const AP4_UI16 AP4_COLR_PRIMARIES_P3D65 = 12;

const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_RESERVED0 = 0;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_BT709 = 1;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_UNSPECIFIED = 2;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_RESERVED = 3;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_GAMMA22 = 4;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_GAMMA28 = 5;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_SMPTE170M = 6;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_SMPTE240M = 7;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_LINEAR = 8;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_LOG = 9;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_LOG_SQRT = 10;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_IEC61966_2_4 = 11;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_BT1361_ECG = 12;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_IEC61966_2_1 = 13;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_BT2020_10 = 14;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_BT2020_12 = 15;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_SMPTE2084 = 16;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_ST2084 = 16;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_SMPTE428 = 17;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_ARIB_STD_B67 = 18;
const AP4_UI16 AP4_COLR_TRANSFER_FUNCTION_HLG = 18;

const AP4_UI16 AP4_COLR_COLORSPACE_GBR = 0;
const AP4_UI16 AP4_COLR_COLORSPACE_BT709 = 1;
const AP4_UI16 AP4_COLR_COLORSPACE_UNSPECIFIED = 2;
const AP4_UI16 AP4_COLR_COLORSPACE_RESERVED = 3;
const AP4_UI16 AP4_COLR_COLORSPACE_FCC = 4;
const AP4_UI16 AP4_COLR_COLORSPACE_BT470BG = 5;
const AP4_UI16 AP4_COLR_COLORSPACE_SMPTE170M = 6;
const AP4_UI16 AP4_COLR_COLORSPACE_SMPTE240M = 7;
const AP4_UI16 AP4_COLR_COLORSPACE_YCOCG = 8;
const AP4_UI16 AP4_COLR_COLORSPACE_BT2020_NCL = 9;
const AP4_UI16 AP4_COLR_COLORSPACE_BT2020_CL = 10;
const AP4_UI16 AP4_COLR_COLORSPACE_SMPTE2085 = 11;
const AP4_UI16 AP4_COLR_COLORSPACE_CHROMA_DERIVED_NCL = 12;
const AP4_UI16 AP4_COLR_COLORSPACE_CHROMA_DERIVED_CL = 13;
const AP4_UI16 AP4_COLR_COLORSPACE_ICTCP = 14;

const AP4_UI32 AP4_COLR_TYPE_NCLC = AP4_ATOM_TYPE('n','c','l','c');

/*----------------------------------------------------------------------
| AP4_ColrAtom
+---------------------------------------------------------------------*/
class AP4_ColrAtom : public AP4_Atom
{
public:
AP4_IMPLEMENT_DYNAMIC_CAST_D(AP4_ColrAtom, AP4_Atom)

// class methods
static AP4_ColrAtom* Create(AP4_Size size, AP4_ByteStream& stream);

// constructors
AP4_ColrAtom(AP4_UI32 type,
AP4_UI16 primaries,
AP4_UI16 transfer_function,
AP4_UI16 matrix_index);
AP4_ColrAtom();

// methods
virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
virtual AP4_Result WriteFields(AP4_ByteStream& stream);

// accessors
AP4_UI32 GetType() const { return m_Type; }
AP4_UI16 GetPrimaries() const { return m_Primaries; }
AP4_UI16 GetTransferFunction() const { return m_TransferFunction; }
AP4_UI16 GetMatrixIndex() const { return m_MatrixIndex; }

private:
// methods
AP4_ColrAtom(AP4_UI32 size, AP4_ByteStream& stream);

// members
AP4_UI32 m_Type;
AP4_UI16 m_Primaries;
AP4_UI16 m_TransferFunction;
AP4_UI16 m_MatrixIndex;
};

#endif // _AP4_COLR_ATOM_H_
Loading