• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2009-2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  *
32  * \file    mv_pred.h
33  *
34  * \brief   Get MV predictor and update motion vector of mb cache
35  *
36  * \date    05/22/2009 Created
37  *
38  *************************************************************************************
39  */
40 
41 #ifndef WELS_MV_PRED_H__
42 #define WELS_MV_PRED_H__
43 
44 #include "dec_frame.h"
45 #include "decoder_context.h"
46 
47 #define RETURN_ERR_IF_NULL(pRefPic0) \
48 if ( pRefPic0 == NULL) \
49   return GENERATE_ERROR_NO(ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX)
50 
51 namespace WelsDec {
52 
53 /*!
54 * \brief     update mv and ref_index cache for current MB, only for P_16x16 (SKIP inclusive)
55 * \param
56 * \param
57 */
58 void UpdateP16x16MotionInfo (PDqLayer pCurDqLayer, int32_t listIdx, int8_t iRef, int16_t iMVs[2]);
59 
60 /*!
61 * \brief     update ref_index cache for current MB, only for P_16x16 (SKIP inclusive)
62 * \param
63 * \param
64 */
65 void UpdateP16x16RefIdx (PDqLayer pCurDqLayer, int32_t listIdx, int8_t iRef);
66 
67 /*!
68 * \brief     update mv only cache for current MB, only for P_16x16 (SKIP inclusive)
69 * \param
70 * \param
71 */
72 void UpdateP16x16MotionOnly (PDqLayer pCurDqLayer, int32_t listIdx, int16_t iMVs[2]);
73 
74 /*!
75 * \brief   update mv and ref_index cache for current MB, only for P_16x8
76 * \param
77 * \param
78 */
79 void UpdateP16x8MotionInfo (PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A],
80                             int8_t iRefIndex[LIST_A][30],
81                             int32_t listIdx, int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]);
82 
83 
84 /*!
85  * \brief    update mv and ref_index cache for current MB, only for P_8x16
86  * \param
87  * \param
88  */
89 void UpdateP8x16MotionInfo (PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A],
90                             int8_t iRefIndex[LIST_A][30],
91                             int32_t listIdx, int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]);
92 
93 /*!
94  * \brief   get the motion predictor for skip mode
95  * \param
96  * \param   output iMvp[]
97  */
98 void PredPSkipMvFromNeighbor (PDqLayer pCurDqLayer, int16_t iMvp[2]);
99 
100 /*!
101 * \brief   get the motion predictor and reference for B-slice direct mode version 2
102 * \param
103 * \param   output iMvp[] and ref
104 */
105 int32_t  PredMvBDirectSpatial (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A],
106                                SubMbType& subMbType);
107 
108 /*!
109 * \brief   get Colocated MB for both Spatial and Temporal Direct Mode
110 * \param
111 * \param   output MbType and SubMbType
112 */
113 int32_t GetColocatedMb (PWelsDecoderContext pCtx, MbType& mbType, SubMbType& subMbType);
114 
115 /*!
116 * \brief   get the motion predictor for B-slice temporal direct mode 16x16
117 */
118 int32_t PredBDirectTemporal (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A],
119                              SubMbType& subMbType);
120 
121 /*!
122 * \brief   get the motion params for B-slice spatial direct mode
123 * \param
124 * \param   output iMvp[]
125 */
126 
127 /*!
128  * \brief   get the motion predictor for 4*4 or 8*8 or 16*16 block
129  * \param
130  * \param   output iMvp[]
131  */
132 void PredMv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
133              int32_t listIdx, int32_t iPartIdx, int32_t iPartWidth, int8_t iRef, int16_t iMVP[2]);
134 
135 /*!
136  * \brief   get the motion predictor for inter16x8 MB
137  * \param
138  * \param   output mvp_x and mvp_y
139  */
140 void PredInter16x8Mv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
141                       int32_t listIdx, int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]);
142 
143 /*!
144  * \brief   get the motion predictor for inter8x16 MB
145  * \param
146  * \param   output mvp_x and mvp_y
147  */
148 void PredInter8x16Mv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
149                       int32_t listIdx, int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]);
150 
151 /*!
152 * \brief   Fill the spatial direct motion vectors for 8x8 direct MB
153 * \param
154 * \param   output motion vector cache and motion vector deviation cache
155 */
156 void FillSpatialDirect8x8Mv (PDqLayer pCurDqLayer, const int16_t& iIdx8, const int8_t& iPartCount, const int8_t& iPartW,
157                              const SubMbType& subMbType, const bool& bIsLongRef, int16_t pMvDirect[LIST_A][2], int8_t iRef[LIST_A],
158                              int16_t pMotionVector[LIST_A][30][MV_A], int16_t pMvdCache[LIST_A][30][MV_A]);
159 
160 /*!
161 * \brief   Fill the temporal direct motion vectors for 8x8 direct MB
162 * \param
163 * \param   output motion vector cache and motion vector deviation cache
164 */
165 void FillTemporalDirect8x8Mv (PDqLayer pCurDqLayer, const int16_t& iIdx8, const int8_t& iPartCount,
166                               const int8_t& iPartW,
167                               const SubMbType& subMbType, int8_t iRef[LIST_A], int16_t (*mvColoc)[2],
168                               int16_t pMotionVector[LIST_A][30][MV_A], int16_t pMvdCache[LIST_A][30][MV_A]);
169 
170 /*!
171 * \brief   returns ref_index in List_0 from the colocated ref_index in LIST_0.
172 * \param
173 *  returns ref_index in List_0 of ref picture LIST_0
174 */
175 int8_t MapColToList0 (PWelsDecoderContext& pCtx, const int8_t& colocRefIndexL0,
176                       const int32_t& ref0Count); //ISO/IEC 14496-10:2009(E) (8-193)
177 
178 /*!
179 * \brief     update ref_index cache for current MB, for 8x8
180 * \param
181 * \param
182 */
183 void Update8x8RefIdx (PDqLayer& pCurDqLayer, const int16_t& iPartIdx, const int32_t& listIdx, const int8_t& iRef);
184 
GetMbType(PDqLayer & pCurDqLayer)185 inline uint32_t* GetMbType (PDqLayer& pCurDqLayer) {
186   if (pCurDqLayer->pDec != NULL) {
187     return pCurDqLayer->pDec->pMbType;
188   } else {
189     return pCurDqLayer->pMbType;
190   }
191 }
192 
193 } // namespace WelsDec
194 
195 #endif//WELS_MV_PRED_H__
196