GPMF_parser.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_PARSER_H
26 #define _GPMF_PARSER_H
27 
28 #include <stdint.h>
29 #include <stddef.h>
30 #include "GPMF_common.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define GPMF_NEST_LIMIT 16
37 
38 typedef struct GPMF_stream
39 {
40  uint32_t *buffer;
42  uint32_t pos;
46  uint32_t nest_level;
47  uint32_t device_count;
48  uint32_t device_id;
49  char device_name[32];
50  size_t cbhandle; // compression handler
51 } GPMF_stream;
52 
53 
54 
55 typedef enum GPMF_LEVELS
56 {
57  GPMF_CURRENT_LEVEL = 0, // search or validate within the current GPMF next level
58  GPMF_RECURSE_LEVELS = 1, // search or validate recursing all levels
59  GPMF_TOLERANT = 2 // Ignore minor errors like unknown datatypes if the structure is otherwise valid.
60 } GPMF_LEVELS;
61 
62 
63 
64 // Prepare GPMF data
65 GPMF_ERR GPMF_Init(GPMF_stream *gs, uint32_t *buffer, uint32_t datasize); //Initialize a GPMF_stream for parsing a particular buffer.
66 GPMF_ERR GPMF_ResetState(GPMF_stream *gs); //Read from beginning of the buffer again
67 GPMF_ERR GPMF_CopyState(GPMF_stream *src, GPMF_stream *dst); //Copy state,
68 GPMF_ERR GPMF_Validate(GPMF_stream *gs, GPMF_LEVELS recurse); //Is the nest structure valid GPMF?
69 
70 // Navigate through GPMF data
71 GPMF_ERR GPMF_Next(GPMF_stream *gs, GPMF_LEVELS recurse); //Step to the next GPMF KLV entrance, optionally recurse up or down nesting levels.
72 GPMF_ERR GPMF_FindPrev(GPMF_stream *gs, uint32_t fourCC, GPMF_LEVELS recurse); //find a previous FourCC -- at the current level only if recurse is false
73 GPMF_ERR GPMF_FindNext(GPMF_stream *gs, uint32_t fourCC, GPMF_LEVELS recurse); //find a particular FourCC upcoming -- at the current level only if recurse is false
74 GPMF_ERR GPMF_SeekToSamples(GPMF_stream *gs); //find the last FourCC in the current level, this is raw data for any STRM
75 
76 // Get information about the current GPMF KLV
77 uint32_t GPMF_Key(GPMF_stream *gs); //return the current Key (FourCC)
78 GPMF_SampleType GPMF_Type(GPMF_stream *gs); //return the current Type (GPMF_Type)
79 uint32_t GPMF_StructSize(GPMF_stream *gs); //return the current sample structure size
80 uint32_t GPMF_Repeat(GPMF_stream *gs); //return the current repeat or the number of samples of this structure
81 uint32_t GPMF_PayloadSampleCount(GPMF_stream *gs); //return the current number of samples of this structure, supporting multisample entries.
82 uint32_t GPMF_ElementsInStruct(GPMF_stream *gs); //return the current number elements within the structure (e.g. 3-axis gyro)
83 uint32_t GPMF_RawDataSize(GPMF_stream *gs); //return the data size for the current GPMF KLV
84 void * GPMF_RawData(GPMF_stream *gs); //return a pointer the KLV data (which is Bigendian if the type is known.)
85 
86 
87 GPMF_ERR GPMF_Modify(GPMF_stream* gs, //find and inplace overwrite a GPMF KLV with new KLV, if the lengths match.
88  uint32_t origfourCC, uint32_t newfourCC, GPMF_SampleType newType, uint32_t newStructSize, uint32_t newRepeat, void* newData);
89 
90 // Get information about where the GPMF KLV is nested
91 uint32_t GPMF_NestLevel(GPMF_stream *gs); //return the current nest level
92 uint32_t GPMF_DeviceID(GPMF_stream *gs); //return the current device ID (DVID), to seperate match sensor data from difference devices.
93 GPMF_ERR GPMF_DeviceName(GPMF_stream *gs, char *devicename_buf, uint32_t devicename_buf_size); //return the current device name (DVNM), to seperate match sensor data from difference devices.
94 
95 // Utilities for data types
96 uint32_t GPMF_SizeofType(GPMF_SampleType type); // GPMF equivalent to sizeof(type)
97 uint32_t GPMF_ExpandComplexTYPE(char *src, uint32_t srcsize, char *dst, uint32_t *dstsize); // GPMF using TYPE for cmple structure. { float val[16],uin32_t flags; } has type "f[8]L", this tools expands to the simpler format "ffffffffL"
98 uint32_t GPMF_SizeOfComplexTYPE(char *typearray, uint32_t typestringlength); // GPMF equivalent to sizeof(typedef) for complex types.
99 GPMF_ERR GPMF_Reserved(uint32_t key); // Test for a reverse GPMF Key, returns GPMF_OK is not reversed.
100 
101 //Tools for extracting sensor data
102 uint32_t GPMF_FormattedDataSize(GPMF_stream *gs); //return the decompressed data size for the current GPMF KLV
103 uint32_t GPMF_ScaledDataSize(GPMF_stream *gs, GPMF_SampleType type); //return the decompressed data size for the current GPMF KLV
104 GPMF_ERR GPMF_FormattedData(GPMF_stream *gs, void *buffer, uint32_t buffersize, uint32_t sample_offset, uint32_t read_samples); // extract 'n' samples into local endian memory format.
105 GPMF_ERR GPMF_ScaledData(GPMF_stream *gs, void *buffer, uint32_t buffersize, uint32_t sample_offset, uint32_t read_samples, GPMF_SampleType type); // extract 'n' samples into local endian memory format // return a point the KLV data.
106 
107 //Tools for Compressed datatypes
108 
109 typedef struct GPMF_codebook
110 {
111  int16_t value; //value to store
112  uint8_t offset; //0 to 128+ bytes to skip before store (leading zeros)
113  uint8_t bits_used; //1 to 16,32 (if escape code > 16 then read from bit-steam),
114  int8_t bytes_stored; //bytes stored in value: 0, 1 or 2
115  int8_t command; //0 - OKAY, -1 valid code, 1 - end
116 } GPMF_codebook;
117 
118 
119 GPMF_ERR GPMF_AllocCodebook(size_t *cbhandle);
120 GPMF_ERR GPMF_FreeCodebook(size_t cbhandle);
121 GPMF_ERR GPMF_DecompressedSize(GPMF_stream *gs, uint32_t *neededsize);
122 GPMF_ERR GPMF_Decompress(GPMF_stream *gs, uint32_t *localbuf, uint32_t localbuf_size);
124 
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #endif
GPMF_TOLERANT
@ GPMF_TOLERANT
Definition: GPMF_parser.h:59
GPMF_codebook::offset
uint8_t offset
Definition: GPMF_parser.h:112
GPMF_stream
struct GPMF_stream GPMF_stream
GPMF_stream::pos
uint32_t pos
Definition: GPMF_parser.h:42
GPMF_stream::cbhandle
size_t cbhandle
Definition: GPMF_parser.h:50
GPMF_Key
uint32_t GPMF_Key(GPMF_stream *gs)
GPMF_PayloadSampleCount
uint32_t GPMF_PayloadSampleCount(GPMF_stream *gs)
GPMF_stream::nest_level
uint32_t nest_level
Definition: GPMF_parser.h:46
GPMF_ExpandComplexTYPE
uint32_t GPMF_ExpandComplexTYPE(char *src, uint32_t srcsize, char *dst, uint32_t *dstsize)
GPMF_codebook::bytes_stored
int8_t bytes_stored
Definition: GPMF_parser.h:114
GPMF_stream::device_count
uint32_t device_count
Definition: GPMF_parser.h:47
GPMF_ElementsInStruct
uint32_t GPMF_ElementsInStruct(GPMF_stream *gs)
GPMF_Type
GPMF_SampleType GPMF_Type(GPMF_stream *gs)
GPMF_stream::device_id
uint32_t device_id
Definition: GPMF_parser.h:48
GPMF_Reserved
GPMF_ERR GPMF_Reserved(uint32_t key)
GPMF_RawDataSize
uint32_t GPMF_RawDataSize(GPMF_stream *gs)
GPMF_FindPrev
GPMF_ERR GPMF_FindPrev(GPMF_stream *gs, uint32_t fourCC, GPMF_LEVELS recurse)
GPMF_DeviceID
uint32_t GPMF_DeviceID(GPMF_stream *gs)
GPMF_stream::last_seek
uint32_t last_seek[GPMF_NEST_LIMIT]
Definition: GPMF_parser.h:45
GPMF_StructSize
uint32_t GPMF_StructSize(GPMF_stream *gs)
GPMF_stream::buffer_size_longs
uint32_t buffer_size_longs
Definition: GPMF_parser.h:41
GPMF_Decompress
GPMF_ERR GPMF_Decompress(GPMF_stream *gs, uint32_t *localbuf, uint32_t localbuf_size)
GPMF_stream::device_name
char device_name[32]
Definition: GPMF_parser.h:49
GPMF_Free
GPMF_ERR GPMF_Free(GPMF_stream *gs)
GPMF_CopyState
GPMF_ERR GPMF_CopyState(GPMF_stream *src, GPMF_stream *dst)
GPMF_SeekToSamples
GPMF_ERR GPMF_SeekToSamples(GPMF_stream *gs)
GPMF_Next
GPMF_ERR GPMF_Next(GPMF_stream *gs, GPMF_LEVELS recurse)
GPMF_FreeCodebook
GPMF_ERR GPMF_FreeCodebook(size_t cbhandle)
GPMF_stream
Definition: GPMF_parser.h:38
GPMF_common.h
GPMF Parser library include.
GPMF_DecompressedSize
GPMF_ERR GPMF_DecompressedSize(GPMF_stream *gs, uint32_t *neededsize)
GPMF_FindNext
GPMF_ERR GPMF_FindNext(GPMF_stream *gs, uint32_t fourCC, GPMF_LEVELS recurse)
GPMF_ScaledDataSize
uint32_t GPMF_ScaledDataSize(GPMF_stream *gs, GPMF_SampleType type)
GPMF_codebook
struct GPMF_codebook GPMF_codebook
GPMF_RawData
void * GPMF_RawData(GPMF_stream *gs)
GPMF_LEVELS
GPMF_LEVELS
Definition: GPMF_parser.h:55
GPMF_FormattedData
GPMF_ERR GPMF_FormattedData(GPMF_stream *gs, void *buffer, uint32_t buffersize, uint32_t sample_offset, uint32_t read_samples)
GPMF_SampleType
GPMF_SampleType
Definition: GPMF_common.h:49
GPMF_codebook::command
int8_t command
Definition: GPMF_parser.h:115
GPMF_ScaledData
GPMF_ERR GPMF_ScaledData(GPMF_stream *gs, void *buffer, uint32_t buffersize, uint32_t sample_offset, uint32_t read_samples, GPMF_SampleType type)
GPMF_DeviceName
GPMF_ERR GPMF_DeviceName(GPMF_stream *gs, char *devicename_buf, uint32_t devicename_buf_size)
GPMF_AllocCodebook
GPMF_ERR GPMF_AllocCodebook(size_t *cbhandle)
GPMF_ResetState
GPMF_ERR GPMF_ResetState(GPMF_stream *gs)
GPMF_NestLevel
uint32_t GPMF_NestLevel(GPMF_stream *gs)
GPMF_codebook::bits_used
uint8_t bits_used
Definition: GPMF_parser.h:113
GPMF_SizeOfComplexTYPE
uint32_t GPMF_SizeOfComplexTYPE(char *typearray, uint32_t typestringlength)
GPMF_ERR
#define GPMF_ERR
Definition: GPMF_common.h:47
GPMF_SizeofType
uint32_t GPMF_SizeofType(GPMF_SampleType type)
GPMF_RECURSE_LEVELS
@ GPMF_RECURSE_LEVELS
Definition: GPMF_parser.h:58
GPMF_codebook
Definition: GPMF_parser.h:109
GPMF_stream::nest_size
uint32_t nest_size[GPMF_NEST_LIMIT]
Definition: GPMF_parser.h:44
GPMF_stream::last_level_pos
uint32_t last_level_pos[GPMF_NEST_LIMIT]
Definition: GPMF_parser.h:43
GPMF_Modify
GPMF_ERR GPMF_Modify(GPMF_stream *gs, uint32_t origfourCC, uint32_t newfourCC, GPMF_SampleType newType, uint32_t newStructSize, uint32_t newRepeat, void *newData)
GPMF_FormattedDataSize
uint32_t GPMF_FormattedDataSize(GPMF_stream *gs)
GPMF_Repeat
uint32_t GPMF_Repeat(GPMF_stream *gs)
GPMF_stream::buffer
uint32_t * buffer
Definition: GPMF_parser.h:40
GPMF_CURRENT_LEVEL
@ GPMF_CURRENT_LEVEL
Definition: GPMF_parser.h:57
GPMF_NEST_LIMIT
#define GPMF_NEST_LIMIT
Definition: GPMF_parser.h:36
GPMF_Validate
GPMF_ERR GPMF_Validate(GPMF_stream *gs, GPMF_LEVELS recurse)
GPMF_Init
GPMF_ERR GPMF_Init(GPMF_stream *gs, uint32_t *buffer, uint32_t datasize)
GPMF_codebook::value
int16_t value
Definition: GPMF_parser.h:111


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