2 Copyright (c) 2018, Bjoern Stresing, Patrick Bichiou, Wolfgang Ruppel,
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3. The name of the author may not be used to endorse or promote products
16 derived from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 This module implements ACES header parser.
36 #include "AS_02_ACES.h"
45 const byte_t Magic[] = {0x76, 0x2f, 0x31, 0x01};
46 const byte_t Version_short[] = {0x02, 0x00, 0x00, 0x00}; // Version Nr. 2 for attribute names and attribute type names shorter than 32 Bytes.
47 const byte_t Version_long[] = {0x02, 0x00, 0x04, 0x00}; // Version Nr. 1026 for attribute names and attribute type names exceeding 31 Bytes.
53 Attribute(const byte_t *const buf = NULL) : mAttrType(Invalid), mType(Unknown_t), mAttrName(), mpData(buf), mpValue(NULL), mDataSize(0), mValueSize(0)
58 // Move the internal data pointer to another position.
59 void Move(const byte_t *buf);
60 // The whole size of the Attribute (attribute name + attribute type name + attribute size + attribute value).
61 ui32_t GetTotalSize() const { return mDataSize; };
62 // The name of the Attribute.
63 std::string GetName() const { return mAttrName; };
64 // What kind of Attribute.
65 eAttributes GetAttribute() const { return mAttrType; };
66 // What Datatype the Attribute contains.
67 eTypes GetType() const { return mType; };
68 // You should check if the Attribute object is valid before using it.
69 bool IsValid() const { return mAttrType != Invalid; };
70 // Use this function to copy the raw data to a generic container for later use.
71 Result_t CopyToGenericContainer(other &value) const;
73 Result_t GetValueAsBasicType(ui8_t &value) const;
74 Result_t GetValueAsBasicType(i16_t &value) const;
75 Result_t GetValueAsBasicType(ui16_t &value) const; // use for real16_t
76 Result_t GetValueAsBasicType(i32_t &value) const;
77 Result_t GetValueAsBasicType(ui32_t &value) const;
78 Result_t GetValueAsBasicType(ui64_t &value) const;
79 Result_t GetValueAsBasicType(real32_t &value) const;
80 Result_t GetValueAsBasicType(real64_t &value) const;
81 Result_t GetValueAsBox2i(box2i &value) const;
82 Result_t GetValueAsChlist(chlist &value) const;
83 Result_t GetValueAsChromaticities(chromaticities &value) const;
84 Result_t GetValueAsKeycode(keycode &value) const;
85 Result_t GetValueAsRational(ASDCP::Rational &value) const;
86 Result_t GetValueAsString(std::string &value) const;
87 Result_t GetValueAsStringVector(stringVector &value) const;
88 Result_t GetValueAsV2f(v2f &value) const;
89 Result_t GetValueAsV3f(v3f &value) const;
90 Result_t GetValueAsTimecode(timecode &value) const;
93 KM_NO_COPY_CONSTRUCT(Attribute);
94 void MatchAttribute(const std::string &Type);
95 void MatchType(const std::string &Type);
97 eAttributes mAttrType;
99 std::string mAttrName;
100 const byte_t *mpData;
101 const byte_t *mpValue;
106 Result_t GetNextAttribute(const byte_t **buf, Attribute &attr);
107 Result_t CheckMagicNumber(const byte_t **buf);
108 Result_t CheckVersionField(const byte_t **buf);
110 class ACESDataAccessor
113 static void AsBasicType(const byte_t *buf, ui8_t &value);
114 static void AsBasicType(const byte_t *buf, i16_t &value);
115 static void AsBasicType(const byte_t *buf, ui16_t &value); // use for real16_t
116 static void AsBasicType(const byte_t *buf, i32_t &value);
117 static void AsBasicType(const byte_t *buf, ui32_t &value);
118 static void AsBasicType(const byte_t *buf, ui64_t &value);
119 static void AsBasicType(const byte_t *buf, real32_t &value);
120 static void AsBasicType(const byte_t *buf, real64_t &value);
121 static void AsBox2i(const byte_t *buf, box2i &value);
122 static void AsChlist(const byte_t *buf, ui32_t size, chlist &value);
123 static void AsChromaticities(const byte_t *buf, chromaticities &value);
124 static void AsKeycode(const byte_t *buf, keycode &value);
125 static void AsRational(const byte_t *buf, ASDCP::Rational &value);
126 static void AsString(const byte_t *buf, ui32_t size, std::string &value);
127 static void AsStringVector(const byte_t *buf, ui32_t size, stringVector &value);
128 static void AsV2f(const byte_t *buf, v2f &value);
129 static void AsV3f(const byte_t *buf, v3f &value);
130 static void AsTimecode(const byte_t *buf, timecode &value);