GPMF_common.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
2 // SPDX-FileCopyrightText: Copyright 2017 GoPro Inc (http://gopro.com/).
3 
25 #ifndef _GPMF_COMMON_H
26 #define _GPMF_COMMON_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef enum GPMF_ERROR
33 {
34  GPMF_OK = 0,
35  GPMF_ERROR_MEMORY, // NULL Pointer or insufficient memory
36  GPMF_ERROR_BAD_STRUCTURE, // Non-complaint GPMF structure detected
37  GPMF_ERROR_BUFFER_END, // reached the end of the provided buffer
38  GPMF_ERROR_FIND, // Find failed to return the requested data, but structure is valid.
39  GPMF_ERROR_LAST, // reached the end of a search at the current nest level
40  GPMF_ERROR_TYPE_NOT_SUPPORTED, // a needed TYPE tuple is missing or has unsupported elements.
41  GPMF_ERROR_SCALE_NOT_SUPPORTED, // scaling for an non-scaling type, e.g. scaling a FourCC field to a float.
42  GPMF_ERROR_SCALE_COUNT, // A SCAL tuple has a mismatching element count.
43  GPMF_ERROR_UNKNOWN_TYPE, // Potentially valid data with a new or unknown type.
44  GPMF_ERROR_RESERVED // internal usage
45 } GPMF_ERROR;
46 
47 #define GPMF_ERR uint32_t
48 
49 typedef enum
50 {
51  GPMF_TYPE_STRING_ASCII = 'c', //single byte 'c' style character string
52  GPMF_TYPE_SIGNED_BYTE = 'b',//single byte signed number
53  GPMF_TYPE_UNSIGNED_BYTE = 'B', //single byte unsigned number
54  GPMF_TYPE_SIGNED_SHORT = 's',//16-bit integer
55  GPMF_TYPE_UNSIGNED_SHORT = 'S',//16-bit integer
56  GPMF_TYPE_FLOAT = 'f', //32-bit single precision float (IEEE 754)
57  GPMF_TYPE_FOURCC = 'F', //32-bit four character tag
58  GPMF_TYPE_SIGNED_LONG = 'l',//32-bit integer
59  GPMF_TYPE_UNSIGNED_LONG = 'L', //32-bit integer
60  GPMF_TYPE_Q15_16_FIXED_POINT = 'q', // Q number Q15.16 - 16-bit signed integer (A) with 16-bit fixed point (B) for A.B value (range -32768.0 to 32767.99998).
61  GPMF_TYPE_Q31_32_FIXED_POINT = 'Q', // Q number Q31.32 - 32-bit signed integer (A) with 32-bit fixed point (B) for A.B value.
62  GPMF_TYPE_SIGNED_64BIT_INT = 'j', //64 bit signed long
63  GPMF_TYPE_UNSIGNED_64BIT_INT = 'J', //64 bit unsigned long
64  GPMF_TYPE_DOUBLE = 'd', //64 bit double precision float (IEEE 754)
65  GPMF_TYPE_STRING_UTF8 = 'u', //UTF-8 formatted text string. As the character storage size varies, the size is in bytes, not UTF characters.
66  GPMF_TYPE_UTC_DATE_TIME = 'U', //128-bit ASCII Date + UTC Time format yymmddhhmmss.sss - 16 bytes ASCII (years 20xx covered)
67  GPMF_TYPE_GUID = 'G', //128-bit ID (like UUID)
68 
69  GPMF_TYPE_COMPLEX = '?', //for sample with complex data structures, base size in bytes. Data is either opaque, or the stream has a TYPE structure field for the sample.
70  GPMF_TYPE_COMPRESSED = '#', //Huffman compression STRM payloads. 4-CC <type><size><rpt> <data ...> is compressed as 4-CC '#'<new size/rpt> <type><size><rpt> <compressed data ...>
71 
72  GPMF_TYPE_NEST = 0, // used to nest more GPMF formatted metadata
73 
74  /* ------------- Internal usage only ------------- */
75  GPMF_TYPE_EMPTY = 0xfe, // used to distinguish between grouped metadata (like FACE) with no data (no faces detected) and an empty payload (FACE device reported no samples.)
76  GPMF_TYPE_ERROR = 0xff // used to report an error
78 
79 
80 
81 #define MAKEID(a,b,c,d) (((d&0xff)<<24)|((c&0xff)<<16)|((b&0xff)<<8)|(a&0xff))
82 #define STR2FOURCC(s) ((s[0]<<0)|(s[1]<<8)|(s[2]<<16)|(s[3]<<24))
83 
84 #define BYTESWAP64(a) (((a&0xff)<<56)|((a&0xff00)<<40)|((a&0xff0000)<<24)|((a&0xff000000)<<8) | ((a>>56)&0xff)|((a>>40)&0xff00)|((a>>24)&0xff0000)|((a>>8)&0xff000000) )
85 #define BYTESWAP32(a) (((a&0xff)<<24)|((a&0xff00)<<8)|((a>>8)&0xff00)|((a>>24)&0xff))
86 #define BYTESWAP16(a) ((((a)>>8)&0xff)|(((a)<<8)&0xff00))
87 #define BYTESWAP2x16(a) (((a>>8)&0xff)|((a<<8)&0xff00)|((a>>8)&0xff0000)|((a<<8)&0xff000000))
88 #define NOSWAP8(a) (a)
89 
90 #define GPMF_SAMPLES(a) (((a>>24) & 0xff)|(((a>>16)&0xff)<<8))
91 #define GPMF_SAMPLE_SIZE(a) (((a)>>8)&0xff)
92 #define GPMF_SAMPLE_TYPE(a) (a&0xff)
93 #define GPMF_MAKE_TYPE_SIZE_COUNT(t,s,c) ((t)&0xff)|(((s)&0xff)<<8)|(((c)&0xff)<<24)|(((c)&0xff00)<<8)
94 #define GPMF_DATA_SIZE(a) ((GPMF_SAMPLE_SIZE(a)*GPMF_SAMPLES(a)+3)&~0x3)
95 #define GPMF_DATA_PACKEDSIZE(a) ((GPMF_SAMPLE_SIZE(a)*GPMF_SAMPLES(a)))
96 #define GPMF_VALID_FOURCC(a) (((((a>>24)&0xff)>='a'&&((a>>24)&0xff)<='z') || (((a>>24)&0xff)>='A'&&((a>>24)&0xff)<='Z') || (((a>>24)&0xff)>='0'&&((a>>24)&0xff)<='9') || (((a>>24)&0xff)==' ') ) && \
97  ( (((a>>16)&0xff)>='a'&&((a>>16)&0xff)<='z') || (((a>>16)&0xff)>='A'&&((a>>16)&0xff)<='Z') || (((a>>16)&0xff)>='0'&&((a>>16)&0xff)<='9') || (((a>>16)&0xff)==' ') ) && \
98  ( (((a>>8)&0xff)>='a'&&((a>>8)&0xff)<='z') || (((a>>8)&0xff)>='A'&&((a>>8)&0xff)<='Z') || (((a>>8)&0xff)>='0'&&((a>>8)&0xff)<='9') || (((a>>8)&0xff)==' ') ) && \
99  ( (((a>>0)&0xff)>='a'&&((a>>0)&0xff)<='z') || (((a>>0)&0xff)>='A'&&((a>>0)&0xff)<='Z') || (((a>>0)&0xff)>='0'&&((a>>0)&0xff)<='9') || (((a>>0)&0xff)==' ') ))
100 
101 #define PRINTF_4CC(k) ((k) >> 0) & 0xff, ((k) >> 8) & 0xff, ((k) >> 16) & 0xff, ((k) >> 24) & 0xff
102 
103 
104 typedef enum GPMFKey // TAG in all caps are GoPro preserved (are defined by GoPro, but can be used by others.)
105 {
106  // Internal Metadata structure and formatting tags
107  GPMF_KEY_DEVICE = MAKEID('D','E','V','C'),//DEVC - nested device data to speed the parsing of multiple devices in post
108  GPMF_KEY_DEVICE_ID = MAKEID('D','V','I','D'),//DVID - unique id per stream for a metadata source (in camera or external input) (single 4 byte int)
109  GPMF_KEY_DEVICE_NAME = MAKEID('D','V','N','M'),//DVNM - human readable device type/name (char string)
110  GPMF_KEY_STREAM = MAKEID('S','T','R','M'),//STRM - nested channel/stream of telemetry data
111  GPMF_KEY_STREAM_NAME = MAKEID('S','T','N','M'),//STNM - human readable telemetry/metadata stream type/name (char string)
112  GPMF_KEY_SI_UNITS = MAKEID('S','I','U','N'),//SIUN - Display string for metadata units where inputs are in SI units "uT","rad/s","km/s","m/s","mm/s" etc.
113  GPMF_KEY_UNITS = MAKEID('U','N','I','T'),//UNIT - Freeform display string for metadata units (char string like "RPM", "MPH", "km/h", etc)
114  GPMF_KEY_MATRIX = MAKEID('M','T','R','X'),//MTRX - 2D matrix for any sensor calibration.
115  GPMF_KEY_ORIENTATION_IN = MAKEID('O','R','I','N'),//ORIN - input 'n' channel data orientation, lowercase is negative, e.g. "Zxy" or "ABGR".
116  GPMF_KEY_ORIENTATION_OUT = MAKEID('O','R','I','O'),//ORIO - output 'n' channel data orientation, e.g. "XYZ" or "RGBA".
117  GPMF_KEY_SCALE = MAKEID('S','C','A','L'),//SCAL - divisor for input data to scale to the correct units.
118  GPMF_KEY_TYPE = MAKEID('T','Y','P','E'),//TYPE - Type define for complex data structures
119  GPMF_KEY_TOTAL_SAMPLES = MAKEID('T','S','M','P'),//TSMP - Total Sample Count including the current payload
120  GPMF_KEY_TICK = MAKEID('T','I','C','K'),//TICK - Beginning of data timing (arrival) in milliseconds.
121  GPMF_KEY_TOCK = MAKEID('T','O','C','K'),//TOCK - End of data timing (arrival) in milliseconds.
122  GPMF_KEY_TIME_OFFSET = MAKEID('T','I','M','O'),//TIMO - Time offset of the metadata stream that follows (single 4 byte float)
123  GPMF_KEY_TIMING_OFFSET = MAKEID('T','I','M','O'),//TIMO - duplicated, as older code might use the other version of TIMO
124  GPMF_KEY_TIME_STAMP = MAKEID('S','T','M','P'),//STMP - Time stamp for the first sample.
125  GPMF_KEY_TIME_STAMPS = MAKEID('S','T','P','S'),//STPS - Stream of all the timestamps delivered (Generally don't use this. This would be if your sensor has no periodic times, yet precision is required, or for debugging.)
126  GPMF_KEY_PREFORMATTED = MAKEID('P','F','R','M'),//PFRM - GPMF data
127  GPMF_KEY_TEMPERATURE_C = MAKEID('T','M','P','C'),//TMPC - Temperature in Celsius
128  GPMF_KEY_EMPTY_PAYLOADS = MAKEID('E','M','P','T'),//EMPT - Payloads that are empty since the device start (e.g. BLE disconnect.)
129  GPMF_KEY_QUANTIZE = MAKEID('Q','U','A','N'),//QUAN - quantize used to enable stream compression - 1 - enable, 2+ enable and quantize by this value
130  GPMF_KEY_VERSION = MAKEID('V','E','R','S'),//VERS - version of the metadata stream (debugging)
131  GPMF_KEY_FREESPACE = MAKEID('F','R','E','E'),//FREE - n bytes reserved for more metadata added to an existing stream
132  GPMF_KEY_REMARK = MAKEID('R','M','R','K'),//RMRK - adding comments to the bitstream (debugging)
133 
134  GPMF_KEY_END = 0//(null)
135 } GPMFKey;
136 
137 
138 
139 #ifdef __cplusplus
140 }
141 #endif
142 
143 #endif
GPMF_TYPE_UTC_DATE_TIME
@ GPMF_TYPE_UTC_DATE_TIME
Definition: GPMF_common.h:66
GPMF_KEY_DEVICE_NAME
@ GPMF_KEY_DEVICE_NAME
Definition: GPMF_common.h:109
GPMF_ERROR_SCALE_NOT_SUPPORTED
@ GPMF_ERROR_SCALE_NOT_SUPPORTED
Definition: GPMF_common.h:41
GPMF_TYPE_STRING_UTF8
@ GPMF_TYPE_STRING_UTF8
Definition: GPMF_common.h:65
GPMF_TYPE_EMPTY
@ GPMF_TYPE_EMPTY
Definition: GPMF_common.h:75
GPMF_ERROR_RESERVED
@ GPMF_ERROR_RESERVED
Definition: GPMF_common.h:44
GPMF_KEY_MATRIX
@ GPMF_KEY_MATRIX
Definition: GPMF_common.h:114
GPMF_KEY_ORIENTATION_OUT
@ GPMF_KEY_ORIENTATION_OUT
Definition: GPMF_common.h:116
GPMF_KEY_STREAM_NAME
@ GPMF_KEY_STREAM_NAME
Definition: GPMF_common.h:111
GPMF_ERROR_MEMORY
@ GPMF_ERROR_MEMORY
Definition: GPMF_common.h:35
GPMF_ERROR
GPMF_ERROR
Definition: GPMF_common.h:32
GPMF_KEY_TIME_STAMPS
@ GPMF_KEY_TIME_STAMPS
Definition: GPMF_common.h:125
GPMF_KEY_TICK
@ GPMF_KEY_TICK
Definition: GPMF_common.h:120
GPMF_KEY_END
@ GPMF_KEY_END
Definition: GPMF_common.h:134
GPMF_KEY_DEVICE_ID
@ GPMF_KEY_DEVICE_ID
Definition: GPMF_common.h:108
GPMF_KEY_QUANTIZE
@ GPMF_KEY_QUANTIZE
Definition: GPMF_common.h:129
GPMF_TYPE_UNSIGNED_BYTE
@ GPMF_TYPE_UNSIGNED_BYTE
Definition: GPMF_common.h:53
GPMF_KEY_FREESPACE
@ GPMF_KEY_FREESPACE
Definition: GPMF_common.h:131
GPMF_KEY_PREFORMATTED
@ GPMF_KEY_PREFORMATTED
Definition: GPMF_common.h:126
GPMF_KEY_TIMING_OFFSET
@ GPMF_KEY_TIMING_OFFSET
Definition: GPMF_common.h:123
GPMF_KEY_TIME_STAMP
@ GPMF_KEY_TIME_STAMP
Definition: GPMF_common.h:124
GPMF_TYPE_UNSIGNED_SHORT
@ GPMF_TYPE_UNSIGNED_SHORT
Definition: GPMF_common.h:55
GPMF_TYPE_FLOAT
@ GPMF_TYPE_FLOAT
Definition: GPMF_common.h:56
GPMF_ERROR_SCALE_COUNT
@ GPMF_ERROR_SCALE_COUNT
Definition: GPMF_common.h:42
GPMF_KEY_EMPTY_PAYLOADS
@ GPMF_KEY_EMPTY_PAYLOADS
Definition: GPMF_common.h:128
GPMF_ERROR_UNKNOWN_TYPE
@ GPMF_ERROR_UNKNOWN_TYPE
Definition: GPMF_common.h:43
GPMF_KEY_STREAM
@ GPMF_KEY_STREAM
Definition: GPMF_common.h:110
GPMF_KEY_REMARK
@ GPMF_KEY_REMARK
Definition: GPMF_common.h:132
GPMF_KEY_ORIENTATION_IN
@ GPMF_KEY_ORIENTATION_IN
Definition: GPMF_common.h:115
GPMF_KEY_DEVICE
@ GPMF_KEY_DEVICE
Definition: GPMF_common.h:107
GPMF_KEY_TOTAL_SAMPLES
@ GPMF_KEY_TOTAL_SAMPLES
Definition: GPMF_common.h:119
MAKEID
#define MAKEID(a, b, c, d)
Definition: GPMF_common.h:81
GPMF_TYPE_COMPRESSED
@ GPMF_TYPE_COMPRESSED
Definition: GPMF_common.h:70
GPMF_ERROR_TYPE_NOT_SUPPORTED
@ GPMF_ERROR_TYPE_NOT_SUPPORTED
Definition: GPMF_common.h:40
GPMF_TYPE_SIGNED_LONG
@ GPMF_TYPE_SIGNED_LONG
Definition: GPMF_common.h:58
GPMF_TYPE_SIGNED_BYTE
@ GPMF_TYPE_SIGNED_BYTE
Definition: GPMF_common.h:52
GPMF_TYPE_NEST
@ GPMF_TYPE_NEST
Definition: GPMF_common.h:72
GPMFKey
GPMFKey
Definition: GPMF_common.h:104
GPMF_KEY_SI_UNITS
@ GPMF_KEY_SI_UNITS
Definition: GPMF_common.h:112
GPMF_OK
@ GPMF_OK
Definition: GPMF_common.h:34
GPMF_TYPE_ERROR
@ GPMF_TYPE_ERROR
Definition: GPMF_common.h:76
GPMF_KEY_TYPE
@ GPMF_KEY_TYPE
Definition: GPMF_common.h:118
GPMF_TYPE_COMPLEX
@ GPMF_TYPE_COMPLEX
Definition: GPMF_common.h:69
GPMF_KEY_TEMPERATURE_C
@ GPMF_KEY_TEMPERATURE_C
Definition: GPMF_common.h:127
GPMF_TYPE_UNSIGNED_64BIT_INT
@ GPMF_TYPE_UNSIGNED_64BIT_INT
Definition: GPMF_common.h:63
GPMF_KEY_VERSION
@ GPMF_KEY_VERSION
Definition: GPMF_common.h:130
GPMF_SampleType
GPMF_SampleType
Definition: GPMF_common.h:49
GPMF_TYPE_SIGNED_SHORT
@ GPMF_TYPE_SIGNED_SHORT
Definition: GPMF_common.h:54
GPMF_ERROR_BUFFER_END
@ GPMF_ERROR_BUFFER_END
Definition: GPMF_common.h:37
GPMF_ERROR_BAD_STRUCTURE
@ GPMF_ERROR_BAD_STRUCTURE
Definition: GPMF_common.h:36
GPMF_TYPE_UNSIGNED_LONG
@ GPMF_TYPE_UNSIGNED_LONG
Definition: GPMF_common.h:59
GPMF_TYPE_DOUBLE
@ GPMF_TYPE_DOUBLE
Definition: GPMF_common.h:64
GPMF_TYPE_Q15_16_FIXED_POINT
@ GPMF_TYPE_Q15_16_FIXED_POINT
Definition: GPMF_common.h:60
GPMF_TYPE_FOURCC
@ GPMF_TYPE_FOURCC
Definition: GPMF_common.h:57
GPMF_TYPE_SIGNED_64BIT_INT
@ GPMF_TYPE_SIGNED_64BIT_INT
Definition: GPMF_common.h:62
GPMF_KEY_SCALE
@ GPMF_KEY_SCALE
Definition: GPMF_common.h:117
GPMF_KEY_TIME_OFFSET
@ GPMF_KEY_TIME_OFFSET
Definition: GPMF_common.h:122
GPMF_KEY_TOCK
@ GPMF_KEY_TOCK
Definition: GPMF_common.h:121
GPMF_TYPE_STRING_ASCII
@ GPMF_TYPE_STRING_ASCII
Definition: GPMF_common.h:51
GPMF_TYPE_Q31_32_FIXED_POINT
@ GPMF_TYPE_Q31_32_FIXED_POINT
Definition: GPMF_common.h:61
GPMF_TYPE_GUID
@ GPMF_TYPE_GUID
Definition: GPMF_common.h:67
GPMF_ERROR_FIND
@ GPMF_ERROR_FIND
Definition: GPMF_common.h:38
GPMF_KEY_UNITS
@ GPMF_KEY_UNITS
Definition: GPMF_common.h:113
GPMF_ERROR_LAST
@ GPMF_ERROR_LAST
Definition: GPMF_common.h:39


gpmf_metadata_extractor
Author(s): Martin Pecka , Liam Samuel Pach
autogenerated on Wed May 28 2025 02:07:33