UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
M4VlcDecoder.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "vdecmpeg4.h"
5#include "M4Memory.h"
6#include "M4Bitstream.h"
7
8namespace vdecmpeg4
9{
10#define MK_VLC(a,b) \
11 ( ((a)&0x1ffff) | ((b)<<17) )
12
13#define VLC_CODE(a) \
14 ((a)&0x1ffff)
15
16#define VLC_LEN(a) \
17 ((a)>>17)
18
19#define VLC_ERROR MK_VLC(0x1ffff, 0)
20#define VLC_ESCAPE 0x1BFF
21
22typedef uint32 M4_VLC;
23
24
32
33
34
36{
37public:
40 {}
41
45
47 void init();
48
51 {
52 uint32 bits = bs.show(12);
53 M4CHECK(bits >= 8);
54
55 M4_VLC vlc = getIntraVlcTab(bits);
57
58 bs.skip(VLC_LEN(vlc));
59
61 uint32 code = VLC_CODE(vlc);
62 if (code != VLC_ESCAPE)
63 {
64 run = (code >> 8) & 255;
65 level = code & 255;
66 last = (code >> 16) & 1;
67 int32 ret = bs.getBit() ? -level : level;
68 return ret;
69 }
70
71 uint32 escMode = bs.show(2);
72 if (escMode < 3)
73 {
74 bs.skip((escMode == 2) ? 2 : 1);
75
76 bits = bs.show(12);
77 M4CHECK(bits >= 8);
78
79 vlc = getIntraVlcTab(bits);
81
82 bs.skip(VLC_LEN(vlc));
83
84 code = VLC_CODE(vlc);
85 run = (code >> 8) & 255;
86 level = code & 255;
87 last = (code >> 16) & 1;
88
89 if (escMode < 2) // first escape mode, level is offset
90 {
91 level += mMaxLevel[last][run]; // need to add back the max level
92 }
93 else if (escMode == 2) // second escape mode, run is offset
94 {
95 run += mMaxRun[last][level] + 1;
96 }
97 else
98 {
99 M4CHECK(0); //todo.... (needs a final verification)
100 }
101
102 int32 ret = bs.getBit() ? -level : level;
103 return ret;
104 }
105
106 // third escape mode - fixed length codes
107 bs.skip(2);
108 last = (int32) bs.getBits(1);
109 run = (int32) bs.getBits(6);
110
111 bs.skip(1); // marker
112 level = (int32) bs.getBits(12);
113 bs.skip(1); // marker
114
115 return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level;
116 }
117
120 {
121 // use ISO Table B-16, max 12 bit of VLC code
122 uint32 bits = bs.show(12);
123 M4CHECK(bits >= 8);
124
125 M4_VLC vlc = getInterVlcTab(bits);
127
128 bs.skip(VLC_LEN(vlc));
129
130 int32 level;
131 uint32 code = VLC_CODE(vlc);
132 if (code != VLC_ESCAPE)
133 {
134 run = (code >> 4) & 255;
135 level = code & 15;
136 last = (code >> 12) & 1;
137 int32 ret = bs.getBit() ? -level : level;
138 return ret;
139 }
140
141 uint32 escMode = bs.show(2);
142 if (escMode < 3)
143 {
144 bs.skip((escMode == 2) ? 2 : 1);
145
146 bits = bs.show(12);
147 M4CHECK(bits >= 8);
148
149 vlc = getInterVlcTab(bits);
151
152 bs.skip(VLC_LEN(vlc));
153
154 code = VLC_CODE(vlc);
155 run = (code >> 4) & 255;
156 level = code & 15;
157 last = (code >> 12) & 1;
158
159 if (escMode < 2) // first escape mode, level is offset
160 {
161 level += mMaxLevel[last + 2][run]; // need to add back the max level
162 }
163 else if (escMode == 2) // second escape mode, run is offset
164 {
165 run += mMaxRun[last + 2][level] + 1;
166 }
167 else
168 {
169 M4CHECK(0); //todo.... (needs a final verification)
170 }
171
172 int32 ret = bs.getBit() ? -level : level;
173 return ret;
174 }
175
176 // third escape mode - fixed length codes
177 bs.skip(2);
178 last = (int32) bs.getBits(1);
179
180 run = (int32) bs.getBits(6);
181 bs.skip(1); // marker
182
183 level = (int32) bs.getBits(12);
184 bs.skip(1); // marker
185
186 return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level;
187 }
188
189private:
191 M4_VLC getIntraVlcTab(uint32 bits)
192 {
193 if (bits >=512)
194 {
195 return mIntraCodeTab.mVlcCodeTab[0][(bits >> 5) - 16];
196 }
197 else if (bits >= 128)
198 {
199 return mIntraCodeTab.mVlcCodeTab[1][(bits >> 2) - 32];
200 }
201 else
202 {
203 return mIntraCodeTab.mVlcCodeTab[2][bits - 8];
204 }
205 }
206
208 M4_VLC getInterVlcTab(uint32 bits)
209 {
210 if (bits >=512)
211 {
212 return mInterCodeTab.mVlcCodeTab[0][(bits >> 5) - 16];
213 }
214 else if (bits >= 128)
215 {
216 return mInterCodeTab.mVlcCodeTab[1][(bits >> 2) - 32];
217 }
218 else
219 {
220 return mInterCodeTab.mVlcCodeTab[2][bits - 8];
221 }
222 }
223
226
228 const M4VlcDecoder &operator=(const M4VlcDecoder &pObj);
229
230 M4BlockVlcCodeTab mIntraCodeTab;
231 M4BlockVlcCodeTab mInterCodeTab;
232
233 static uint8 mMaxLevel[4][64];
234 static uint8 mMaxRun[4][256];
235
236 static const M4_VLC mTabCbpCIntra[64];
237 static const M4_VLC mTabCbpCInter[257];
238 static const M4_VLC mTabCbpY[64];
239
240 static M4_VLC mTabTMNMV0[];
241 static M4_VLC mTabTMNMV1[];
242 static M4_VLC mTabTMNMV2[];
243
244 static M4_VLC mTabDCT3D0[];
245 static M4_VLC mTabDCT3D1[];
246 static M4_VLC mTabDCT3D2[];
247
248 static M4_VLC mTabDCT3D3[];
249 static M4_VLC mTabDCT3D4[];
250 static M4_VLC mTabDCT3D5[];
251
252 static const M4_VLC mDCLumTab[];
253
254 friend class M4BitstreamParser;
255};
256
257
258
259}
260
GLenum GLuint GLint level
Definition AndroidOpenGLFunctions.h:46
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define VLC_ESCAPE
Definition M4VlcDecoder.h:20
#define VLC_LEN(a)
Definition M4VlcDecoder.h:16
#define VLC_ERROR
Definition M4VlcDecoder.h:19
#define VLC_CODE(a)
Definition M4VlcDecoder.h:13
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition M4BitstreamParser.h:39
Definition M4Bitstream.h:22
Definition M4VlcDecoder.h:36
M4VlcDecoder()
Default constructor.
Definition M4VlcDecoder.h:39
int32 getCoeffInterNoAsm(int32 &run, int32 &last, M4Bitstream &bs)
Definition M4VlcDecoder.h:119
~M4VlcDecoder()
Destructor.
Definition M4VlcDecoder.h:43
void init()
Init vlc tables.
Definition M4VlcDecoder.cpp:15
int32 getCoeffIntraNoAsm(int32 &run, int32 &last, M4Bitstream &bs)
Definition M4VlcDecoder.h:50
Definition M4Bitstream.h:9
uint32 M4_VLC
Definition of VLC data types.
Definition M4VlcDecoder.h:22
helper struct for passing some C++ tables to the ASM routines. Must be initialized only once.
Definition M4VlcDecoder.h:27
M4_VLC * mVlcCodeTab[3]
Definition M4VlcDecoder.h:28
void * mMaxLevel
Definition M4VlcDecoder.h:29
void * mMaxRun
Definition M4VlcDecoder.h:30
#define M4CHECK
Definition vdecmpeg4_Types.h:8