summaryrefslogtreecommitdiff
path: root/gpr/source/lib/vc5_common/syntax.h
blob: 699c72e243ce085fe0412e2b1807a64a0744bd67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*! @file syntax.h
 *
 *  @brief Declaration of bitstream elements and functions that define the syntax
 *  of an encoded sample.
 *
 *  @version 1.0.0
 *
 *  (C) Copyright 2018 GoPro Inc (http://gopro.com/).
 *
 *  Licensed under either:
 *  - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
 *  - MIT license, http://opensource.org/licenses/MIT
 *  at your option.
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#ifndef SYNTAX_H
#define SYNTAX_H

#define CODEC_TAG_SIZE		16			//!< Size of a codec tag (in bits)
#define CODEC_TAG_MASK		0xFFFF		//!< Mask for usable part of tag or value

typedef uint32_t SEGMENT;		//!< The bitstream is a sequence of segments

typedef int16_t TAGWORD;		//!< Bitstream tag or value

//! Number of bits in a tag or value
static const BITCOUNT tagword_count = 16;

//! Number of bits in a segment (tag value pair)
static const BITCOUNT segment_count = 32;

typedef union tagvalue			//!< Bitstream tag and value pair
{
	struct {					// Fields are in the order for byte swapping
		TAGWORD value;
		TAGWORD tag;
	} tuple;					//!< Tag value pair as separate members

	uint32_t  longword;			//!< Tag value pair as a int32_t word

} TAGVALUE;

/*!
	@brief Values corresponding to the special codewords

	Special codewords are inserted into an entropy coded band to
	mark certain locations in the bitstream.  For example, the end
	of an encoded band is marked by the band end codeword.  Special
	codewords are recorded in the codebook as entries that have a
	run length of zero.  The value indicates the syntax element that
	is represented by the codeword.
*/
typedef enum _special_marker
{
	SPECIAL_MARKER_BAND_END = 1,

} SPECIAL_MARKER;


// The encoded quality is inserted into the bitstream using two tag value pairs
#define ENCODED_QUALITY_LOW_SHIFT	0			//!< Shift for the low part of the quality
#define ENCODED_QUALITY_LOW_MASK	0xFFFF		//!< Mask for the low part of the quality
#define ENCODED_QUALITY_HIGH_SHIFT	16			//!< Shift for the high part of the quality
#define ENCODED_QUALITY_HIGH_MASK	0xFFFF		//!< Mask for the high part of the quality

#ifdef __cplusplus
extern "C" {
#endif

TAGWORD RequiredTag(TAGWORD tag);

//TAGVALUE GetSegment(BITSTREAM *stream);

//TAGWORD GetValue(BITSTREAM *stream, int tag);

// Output a tagged value with double word alignment
CODEC_ERROR PutTagPair(BITSTREAM *stream, int tag, int value);

// Output an optional tagged value
CODEC_ERROR PutTagPairOptional(BITSTREAM *stream, int tag, int value);

// Output a tag that marks a place in the bitstream for debugging
CODEC_ERROR PutTagMarker(BITSTREAM *stream, uint32_t  marker, int size);

TAGWORD OptionalTag(TAGWORD tag);

//bool IsTagOptional(TAGWORD tag);

//bool IsTagRequired(TAGWORD tag);

//bool IsValidSegment(BITSTREAM *stream, TAGVALUE segment, TAGWORD tag);

//CODEC_ERROR AlignBitsTag(BITSTREAM *stream);

bool IsLowPassHeaderMarker(int marker);
bool IsLowPassBandMarker(int marker);
bool IsHighPassBandMarker(int marker);

bool IsAlignedTag(BITSTREAM *stream);

bool IsAlignedSegment(BITSTREAM *stream);

// Write an index block for the sample bands
CODEC_ERROR PutGroupIndex(BITSTREAM *stream,
						  void *index_table[],
						  int index_table_length,
						  size_t *channel_size_table_offset);

TAGWORD PackTransformPrescale(TRANSFORM *transform);

//TODO: Move other declarations for routines that write syntax elements here
struct _encoder ;

CODEC_ERROR PutFrameStructureFlags(struct _encoder *encoder, BITSTREAM *stream);

// Output a tag and marker before the lowpass coefficients for debugging
CODEC_ERROR PutVideoLowpassMarker(BITSTREAM *stream);

#ifdef __cplusplus
}
#endif

#endif // SYNTAX_H