UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
M4MotionVectorMgr.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 "M4Decoder.h"
6#include "M4Memory.h"
7#include "M4Global.h"
8#include "M4MemOps.h"
9
10namespace vdecmpeg4
11{
12
14{
15public:
18
21
22 // -----------------------------------------------------------------------------------------
23
25 void init();
26
28 void readMvForward(M4_MB* mb);
29
32
35 {
36 int32 scale_fac = 1 << (code - 1);
37 int32 high = (32 * scale_fac) - 1;
38 int32 low = (-32 * scale_fac);
39 int32 range = (64 * scale_fac);
40
41 res.x = predictor.x + inputMv.x;
42 res.y = predictor.y + inputMv.y;
43
44 if (res.x < low)
45 {
46 res.x += range;
47 }
48 else if (res.x > high)
49 {
50 res.x -= range;
51 }
52
53 if (res.y < low)
54 {
55 res.y += range;
56 }
57 else if (res.y > high)
58 {
59 res.y -= range;
60 }
61 }
62
65 {
66 // Add input motion vector to predictor
67 res.x = inputMv.x + predictor.x;
68 res.y = inputMv.y + predictor.y;
69
70 // clipping
71 if (res.x < mMvClipLow)
72 {
73 res.x += mMvClipRange;
74 }
75 else if (res.x > mMvClipHigh)
76 {
77 res.x -= mMvClipRange;
78 }
79
80 if (res.y < mMvClipLow)
81 {
82 res.y += mMvClipRange;
83 }
84 else if (res.y > mMvClipHigh)
85 {
86 res.y -= mMvClipRange;
87 }
88 }
89
92 {
93 // Get the differential motion vector (MVDx, MVDy) from the bitstream
94 res.x = mDecoder->mBitstreamParser.getMv(code);
95 res.y = mDecoder->mBitstreamParser.getMv(code);
96 }
97
99 static const M4_VECTOR MV_ZERO;
100
101 void* operator new(size_t sz, M4MemHandler& memSys);
102 void operator delete(void* ptr);
103
104private:
105
108
111 {
112 }
113
115 void _predictMv(M4_VECTOR& res, int32 mbx, int32 mby, uint32 block);
116
119
122
124 const M4MotionVectorMgr &operator=(const M4MotionVectorMgr &pObj);
125
126 int32 mMvClipHigh;
127 int32 mMvClipLow;
128 int32 mMvClipRange;
129
131 M4Decoder* mDecoder;
132
134};
135
136
139{
140 FMemory::Memzero(mb->mFMv, sizeof(M4_VECTOR)*4);
141 mb->mMvResidual = 0;
142}
143
144}
145
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 M4_MEMORY_HANDLER
Definition M4Memory.h:14
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
int32 getMv(const uint16 code)
Definition M4BitstreamParser.h:261
Definition M4Decoder.h:30
Definition M4Memory.h:34
Definition M4MotionVectorMgr.h:14
void addMvForward(M4_VECTOR &res, const M4_VECTOR &inputMv, const M4_VECTOR &predictor)
Add predicted motion vector to FORWARD prediction.
Definition M4MotionVectorMgr.h:64
static void destroy(M4MotionVectorMgr *&pMgr, M4MemHandler &memSys)
Destruction.
Definition M4MotionVectorMgr.cpp:65
void init()
Init members for current frame.
Definition M4MotionVectorMgr.cpp:92
static const M4_VECTOR MV_ZERO
Zero motion vector.
Definition M4MotionVectorMgr.h:99
void readMvForward(M4_MB *mb)
Read the motion vector residual from the bitstream.
Definition M4MotionVectorMgr.cpp:108
void addMv(M4_VECTOR &res, uint16 code, const M4_VECTOR &inputMv, const M4_VECTOR &predictor)
Add predictor and input motion vector based on forward/backward code.
Definition M4MotionVectorMgr.h:34
void readMv(M4_VECTOR &res, uint16 code)
Read motion vector residual from file.
Definition M4MotionVectorMgr.h:91
void predictAddForward(M4_MB *mb, int32 mbx, int32 mby)
Add the residual to the prediction.
Definition M4MotionVectorMgr.cpp:141
static M4MotionVectorMgr * create(M4Decoder *pDecoder, M4MemHandler &memSys)
Creation.
Definition M4MotionVectorMgr.cpp:52
Definition M4Bitstream.h:9
void M4MotionVectorClear(M4_MB *mb)
GENERIC: Set all motion vectors to 0.
Definition M4MotionVectorMgr.h:138
static UE_FORCEINLINE_HINT void * Memzero(void *Dest, SIZE_T Count)
Definition UnrealMemory.h:131
Definition M4Global.h:89
Motion vector.
Definition M4Global.h:71