10c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
20c1bc742181ded4930842b46e9507372f0b1b963James Dong * Copyright (C) 2009 The Android Open Source Project
30c1bc742181ded4930842b46e9507372f0b1b963James Dong *
40c1bc742181ded4930842b46e9507372f0b1b963James Dong * Licensed under the Apache License, Version 2.0 (the "License");
50c1bc742181ded4930842b46e9507372f0b1b963James Dong * you may not use this file except in compliance with the License.
60c1bc742181ded4930842b46e9507372f0b1b963James Dong * You may obtain a copy of the License at
70c1bc742181ded4930842b46e9507372f0b1b963James Dong *
80c1bc742181ded4930842b46e9507372f0b1b963James Dong *      http://www.apache.org/licenses/LICENSE-2.0
90c1bc742181ded4930842b46e9507372f0b1b963James Dong *
100c1bc742181ded4930842b46e9507372f0b1b963James Dong * Unless required by applicable law or agreed to in writing, software
110c1bc742181ded4930842b46e9507372f0b1b963James Dong * distributed under the License is distributed on an "AS IS" BASIS,
120c1bc742181ded4930842b46e9507372f0b1b963James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130c1bc742181ded4930842b46e9507372f0b1b963James Dong * See the License for the specific language governing permissions and
140c1bc742181ded4930842b46e9507372f0b1b963James Dong * limitations under the License.
150c1bc742181ded4930842b46e9507372f0b1b963James Dong */
160c1bc742181ded4930842b46e9507372f0b1b963James Dong
170c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
180c1bc742181ded4930842b46e9507372f0b1b963James Dong
190c1bc742181ded4930842b46e9507372f0b1b963James Dong    Table of contents
200c1bc742181ded4930842b46e9507372f0b1b963James Dong
210c1bc742181ded4930842b46e9507372f0b1b963James Dong     1. Include headers
220c1bc742181ded4930842b46e9507372f0b1b963James Dong     2. External compiler flags
230c1bc742181ded4930842b46e9507372f0b1b963James Dong     3. Module defines
240c1bc742181ded4930842b46e9507372f0b1b963James Dong     4. Local function prototypes
250c1bc742181ded4930842b46e9507372f0b1b963James Dong     5. Functions
260c1bc742181ded4930842b46e9507372f0b1b963James Dong          h264bsdInterPrediction
270c1bc742181ded4930842b46e9507372f0b1b963James Dong          MvPrediction16x16
280c1bc742181ded4930842b46e9507372f0b1b963James Dong          MvPrediction16x8
290c1bc742181ded4930842b46e9507372f0b1b963James Dong          MvPrediction8x16
300c1bc742181ded4930842b46e9507372f0b1b963James Dong          MvPrediction8x8
310c1bc742181ded4930842b46e9507372f0b1b963James Dong          MvPrediction
320c1bc742181ded4930842b46e9507372f0b1b963James Dong          MedianFilter
330c1bc742181ded4930842b46e9507372f0b1b963James Dong          GetInterNeighbour
340c1bc742181ded4930842b46e9507372f0b1b963James Dong          GetPredictionMv
350c1bc742181ded4930842b46e9507372f0b1b963James Dong
360c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
370c1bc742181ded4930842b46e9507372f0b1b963James Dong
380c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
390c1bc742181ded4930842b46e9507372f0b1b963James Dong    1. Include headers
400c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
410c1bc742181ded4930842b46e9507372f0b1b963James Dong
420c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_inter_prediction.h"
430c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_neighbour.h"
440c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_util.h"
450c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_reconstruct.h"
460c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_dpb.h"
470c1bc742181ded4930842b46e9507372f0b1b963James Dong
480c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
490c1bc742181ded4930842b46e9507372f0b1b963James Dong    2. External compiler flags
500c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
510c1bc742181ded4930842b46e9507372f0b1b963James Dong
520c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
530c1bc742181ded4930842b46e9507372f0b1b963James Dong    3. Module defines
540c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
550c1bc742181ded4930842b46e9507372f0b1b963James Dong
560c1bc742181ded4930842b46e9507372f0b1b963James Dongtypedef struct
570c1bc742181ded4930842b46e9507372f0b1b963James Dong{
580c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 available;
590c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 refIndex;
600c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv_t mv;
610c1bc742181ded4930842b46e9507372f0b1b963James Dong} interNeighbour_t;
620c1bc742181ded4930842b46e9507372f0b1b963James Dong
630c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
640c1bc742181ded4930842b46e9507372f0b1b963James Dong    4. Local function prototypes
650c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
660c1bc742181ded4930842b46e9507372f0b1b963James Dong
670c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 MvPrediction16x16(mbStorage_t *pMb, mbPred_t *mbPred,
680c1bc742181ded4930842b46e9507372f0b1b963James Dong    dpbStorage_t *dpb);
690c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 MvPrediction16x8(mbStorage_t *pMb, mbPred_t *mbPred,
700c1bc742181ded4930842b46e9507372f0b1b963James Dong    dpbStorage_t *dpb);
710c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 MvPrediction8x16(mbStorage_t *pMb, mbPred_t *mbPred,
720c1bc742181ded4930842b46e9507372f0b1b963James Dong    dpbStorage_t *dpb);
730c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 MvPrediction8x8(mbStorage_t *pMb, subMbPred_t *subMbPred,
740c1bc742181ded4930842b46e9507372f0b1b963James Dong    dpbStorage_t *dpb);
750c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 MvPrediction(mbStorage_t *pMb, subMbPred_t *subMbPred,
760c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 mbPartIdx, u32 subMbPartIdx);
770c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic i32 MedianFilter(i32 a, i32 b, i32 c);
780c1bc742181ded4930842b46e9507372f0b1b963James Dong
790c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void GetInterNeighbour(u32 sliceId, mbStorage_t *nMb,
800c1bc742181ded4930842b46e9507372f0b1b963James Dong    interNeighbour_t *n, u32 index);
810c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void GetPredictionMv(mv_t *mv, interNeighbour_t *a, u32 refIndex);
820c1bc742181ded4930842b46e9507372f0b1b963James Dong
830c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const neighbour_t N_A_SUB_PART[4][4][4] = {
840c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_A,5}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
850c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_A,5}, {MB_A,7}, {MB_NA,0}, {MB_NA,0} },
860c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_A,5}, {MB_CURR,0}, {MB_NA,0}, {MB_NA,0} },
870c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_A,5}, {MB_CURR,0}, {MB_A,7}, {MB_CURR,2} } },
880c1bc742181ded4930842b46e9507372f0b1b963James Dong
890c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_CURR,1}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
900c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,1}, {MB_CURR,3}, {MB_NA,0}, {MB_NA,0} },
910c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,1}, {MB_CURR,4}, {MB_NA,0}, {MB_NA,0} },
920c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,1}, {MB_CURR,4}, {MB_CURR,3}, {MB_CURR,6} } },
930c1bc742181ded4930842b46e9507372f0b1b963James Dong
940c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_A,13}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
950c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_A,13}, {MB_A,15}, {MB_NA,0}, {MB_NA,0} },
960c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_A,13}, {MB_CURR,8}, {MB_NA,0}, {MB_NA,0} },
970c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_A,13}, {MB_CURR,8}, {MB_A,15}, {MB_CURR,10} } },
980c1bc742181ded4930842b46e9507372f0b1b963James Dong
990c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_CURR,9}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,9}, {MB_CURR,11}, {MB_NA,0}, {MB_NA,0} },
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,9}, {MB_CURR,12}, {MB_NA,0}, {MB_NA,0} },
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,9}, {MB_CURR,12}, {MB_CURR,11}, {MB_CURR,14} } } };
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong
1040c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const neighbour_t N_B_SUB_PART[4][4][4] = {
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_B,10}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,10}, {MB_CURR,0}, {MB_NA,0}, {MB_NA,0} },
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,10}, {MB_B,11}, {MB_NA,0}, {MB_NA,0} },
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,10}, {MB_B,11}, {MB_CURR,0}, {MB_CURR,1} } },
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_B,14}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,14}, {MB_CURR,4}, {MB_NA,0}, {MB_NA,0} },
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,14}, {MB_B,15}, {MB_NA,0}, {MB_NA,0} },
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,14}, {MB_B,15}, {MB_CURR,4}, {MB_CURR,5} } },
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_CURR,2}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,2}, {MB_CURR,8}, {MB_NA,0}, {MB_NA,0} },
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,2}, {MB_CURR,3}, {MB_NA,0}, {MB_NA,0} },
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,2}, {MB_CURR,3}, {MB_CURR,8}, {MB_CURR,9} } },
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_CURR,6}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,6}, {MB_CURR,12}, {MB_NA,0}, {MB_NA,0} },
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,6}, {MB_CURR,7}, {MB_NA,0}, {MB_NA,0} },
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,6}, {MB_CURR,7}, {MB_CURR,12}, {MB_CURR,13} } } };
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong
1250c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const neighbour_t N_C_SUB_PART[4][4][4] = {
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_B,14}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,14}, {MB_NA,4}, {MB_NA,0}, {MB_NA,0} },
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,11}, {MB_B,14}, {MB_NA,0}, {MB_NA,0} },
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,11}, {MB_B,14}, {MB_CURR,1}, {MB_NA,4} } },
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_C,10}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_C,10}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,15}, {MB_C,10}, {MB_NA,0}, {MB_NA,0} },
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,15}, {MB_C,10}, {MB_CURR,5}, {MB_NA,0} } },
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_CURR,6}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,6}, {MB_NA,12}, {MB_NA,0}, {MB_NA,0} },
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,3}, {MB_CURR,6}, {MB_NA,0}, {MB_NA,0} },
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_NA,12} } },
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_NA,2}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_NA,2}, {MB_NA,8}, {MB_NA,0}, {MB_NA,0} },
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,7}, {MB_NA,2}, {MB_NA,0}, {MB_NA,0} },
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,7}, {MB_NA,2}, {MB_CURR,13}, {MB_NA,8} } } };
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong
1460c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const neighbour_t N_D_SUB_PART[4][4][4] = {
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_D,15}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_D,15}, {MB_A,5}, {MB_NA,0}, {MB_NA,0} },
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_D,15}, {MB_B,10}, {MB_NA,0}, {MB_NA,0} },
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_D,15}, {MB_B,10}, {MB_A,5}, {MB_CURR,0} } },
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_B,11}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,11}, {MB_CURR,1}, {MB_NA,0}, {MB_NA,0} },
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,11}, {MB_B,14}, {MB_NA,0}, {MB_NA,0} },
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_B,11}, {MB_B,14}, {MB_CURR,1}, {MB_CURR,4} } },
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_A,7}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_A,7}, {MB_A,13}, {MB_NA,0}, {MB_NA,0} },
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_A,7}, {MB_CURR,2}, {MB_NA,0}, {MB_NA,0} },
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_A,7}, {MB_CURR,2}, {MB_A,13}, {MB_CURR,8} } },
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong    { { {MB_CURR,3}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,3}, {MB_CURR,9}, {MB_NA,0}, {MB_NA,0} },
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,3}, {MB_CURR,6}, {MB_NA,0}, {MB_NA,0} },
1650c1bc742181ded4930842b46e9507372f0b1b963James Dong      { {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_CURR,12} } } };
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
1710c1bc742181ded4930842b46e9507372f0b1b963James Dong
1720c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterPrediction
1730c1bc742181ded4930842b46e9507372f0b1b963James Dong
1740c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
1750c1bc742181ded4930842b46e9507372f0b1b963James Dong          Processes one inter macroblock. Performs motion vector prediction
1760c1bc742181ded4930842b46e9507372f0b1b963James Dong          and reconstructs prediction macroblock. Writes the final macroblock
1770c1bc742181ded4930842b46e9507372f0b1b963James Dong          (prediction + residual) into the output image (currImage)
1780c1bc742181ded4930842b46e9507372f0b1b963James Dong
1790c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
1800c1bc742181ded4930842b46e9507372f0b1b963James Dong          pMb           pointer to macroblock specific information
1810c1bc742181ded4930842b46e9507372f0b1b963James Dong          pMbLayer      pointer to current macroblock data from stream
1820c1bc742181ded4930842b46e9507372f0b1b963James Dong          dpb           pointer to decoded picture buffer
1830c1bc742181ded4930842b46e9507372f0b1b963James Dong          mbNum         current macroblock number
1840c1bc742181ded4930842b46e9507372f0b1b963James Dong          currImage     pointer to output image
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          pointer where predicted macroblock will be stored
1860c1bc742181ded4930842b46e9507372f0b1b963James Dong
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
1880c1bc742181ded4930842b46e9507372f0b1b963James Dong          pMb           structure is updated with current macroblock
1890c1bc742181ded4930842b46e9507372f0b1b963James Dong          currImage     current macroblock is written into image
1900c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          prediction is stored here
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
1930c1bc742181ded4930842b46e9507372f0b1b963James Dong          HANTRO_OK     success
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong          HANTRO_NOK    error in motion vector prediction
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
1970c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdInterPrediction(mbStorage_t *pMb, macroblockLayer_t *pMbLayer,
1980c1bc742181ded4930842b46e9507372f0b1b963James Dong    dpbStorage_t *dpb, u32 mbNum, image_t *currImage, u8 *data)
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
2020c1bc742181ded4930842b46e9507372f0b1b963James Dong
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
2040c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 colAndRow;
2060c1bc742181ded4930842b46e9507372f0b1b963James Dong    subMbPartMode_e subPartMode;
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong    image_t refImage;
2080c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 fillBuff[32*21 + 15 + 32];
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *pFill;
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 tmp;
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMb);
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTER);
2150c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMbLayer);
2160c1bc742181ded4930842b46e9507372f0b1b963James Dong
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* 16-byte alignment */
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong    pFill = ALIGN(fillBuff, 16);
2190c1bc742181ded4930842b46e9507372f0b1b963James Dong
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* set row bits 15:0 */
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong    colAndRow = mbNum / currImage->width;
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*set col to bits 31:16 */
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong    colAndRow += (mbNum - colAndRow * currImage->width) << 16;
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong    colAndRow <<= 4;
2250c1bc742181ded4930842b46e9507372f0b1b963James Dong
2260c1bc742181ded4930842b46e9507372f0b1b963James Dong    refImage.width = currImage->width;
2270c1bc742181ded4930842b46e9507372f0b1b963James Dong    refImage.height = currImage->height;
2280c1bc742181ded4930842b46e9507372f0b1b963James Dong
2290c1bc742181ded4930842b46e9507372f0b1b963James Dong    switch (pMb->mbType)
2300c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2310c1bc742181ded4930842b46e9507372f0b1b963James Dong        case P_Skip:
2320c1bc742181ded4930842b46e9507372f0b1b963James Dong        case P_L0_16x16:
2330c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (MvPrediction16x16(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
2340c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
2350c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[0];
2360c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp = (0<<24) + (0<<16) + (16<<8) + 16;
2370c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv, &refImage,
2380c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    colAndRow, tmp, pFill);
2390c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
2400c1bc742181ded4930842b46e9507372f0b1b963James Dong
2410c1bc742181ded4930842b46e9507372f0b1b963James Dong        case P_L0_L0_16x8:
2420c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( MvPrediction16x8(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
2430c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
2440c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[0];
2450c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp = (0<<24) + (0<<16) + (16<<8) + 8;
2460c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv, &refImage,
2470c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    colAndRow, tmp, pFill);
2480c1bc742181ded4930842b46e9507372f0b1b963James Dong
2490c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[2];
2500c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp = (0<<24) + (8<<16) + (16<<8) + 8;
2510c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv+8, &refImage,
2520c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    colAndRow, tmp, pFill);
2530c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
2540c1bc742181ded4930842b46e9507372f0b1b963James Dong
2550c1bc742181ded4930842b46e9507372f0b1b963James Dong        case P_L0_L0_8x16:
2560c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( MvPrediction8x16(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
2570c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
2580c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[0];
2590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp = (0<<24) + (0<<16) + (8<<8) + 16;
2600c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv, &refImage,
2610c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    colAndRow, tmp, pFill);
2620c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[1];
2630c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp = (8<<24) + (0<<16) + (8<<8) + 16;
2640c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv+4, &refImage,
2650c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    colAndRow, tmp, pFill);
2660c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
2670c1bc742181ded4930842b46e9507372f0b1b963James Dong
2680c1bc742181ded4930842b46e9507372f0b1b963James Dong        default: /* P_8x8 and P_8x8ref0 */
2690c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( MvPrediction8x8(pMb, &pMbLayer->subMbPred, dpb) != HANTRO_OK)
2700c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
2710c1bc742181ded4930842b46e9507372f0b1b963James Dong            for (i = 0; i < 4; i++)
2720c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
2730c1bc742181ded4930842b46e9507372f0b1b963James Dong                refImage.data = pMb->refAddr[i];
2740c1bc742181ded4930842b46e9507372f0b1b963James Dong                subPartMode =
2750c1bc742181ded4930842b46e9507372f0b1b963James Dong                    h264bsdSubMbPartMode(pMbLayer->subMbPred.subMbType[i]);
2760c1bc742181ded4930842b46e9507372f0b1b963James Dong                x = i & 0x1 ? 8 : 0;
2770c1bc742181ded4930842b46e9507372f0b1b963James Dong                y = i < 2 ? 0 : 8;
2780c1bc742181ded4930842b46e9507372f0b1b963James Dong                switch (subPartMode)
2790c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
2800c1bc742181ded4930842b46e9507372f0b1b963James Dong                    case MB_SP_8x8:
2810c1bc742181ded4930842b46e9507372f0b1b963James Dong                        tmp = (x<<24) + (y<<16) + (8<<8) + 8;
2820c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
2830c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                    colAndRow, tmp, pFill);
2840c1bc742181ded4930842b46e9507372f0b1b963James Dong                        break;
2850c1bc742181ded4930842b46e9507372f0b1b963James Dong
2860c1bc742181ded4930842b46e9507372f0b1b963James Dong                    case MB_SP_8x4:
2870c1bc742181ded4930842b46e9507372f0b1b963James Dong                        tmp = (x<<24) + (y<<16) + (8<<8) + 4;
2880c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
2890c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                    colAndRow, tmp, pFill);
2900c1bc742181ded4930842b46e9507372f0b1b963James Dong                        tmp = (x<<24) + ((y+4)<<16) + (8<<8) + 4;
2910c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+2, &refImage,
2920c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                    colAndRow, tmp, pFill);
2930c1bc742181ded4930842b46e9507372f0b1b963James Dong                        break;
2940c1bc742181ded4930842b46e9507372f0b1b963James Dong
2950c1bc742181ded4930842b46e9507372f0b1b963James Dong                    case MB_SP_4x8:
2960c1bc742181ded4930842b46e9507372f0b1b963James Dong                        tmp = (x<<24) + (y<<16) + (4<<8) + 8;
2970c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
2980c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                    colAndRow, tmp, pFill);
2990c1bc742181ded4930842b46e9507372f0b1b963James Dong                        tmp = ((x+4)<<24) + (y<<16) + (4<<8) + 8;
3000c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+1, &refImage,
3010c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                    colAndRow, tmp, pFill);
3020c1bc742181ded4930842b46e9507372f0b1b963James Dong                        break;
3030c1bc742181ded4930842b46e9507372f0b1b963James Dong
3040c1bc742181ded4930842b46e9507372f0b1b963James Dong                    default:
3050c1bc742181ded4930842b46e9507372f0b1b963James Dong                        tmp = (x<<24) + (y<<16) + (4<<8) + 4;
3060c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
3070c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                    colAndRow, tmp, pFill);
3080c1bc742181ded4930842b46e9507372f0b1b963James Dong                        tmp = ((x+4)<<24) + (y<<16) + (4<<8) + 4;
3090c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+1, &refImage,
3100c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                    colAndRow, tmp, pFill);
3110c1bc742181ded4930842b46e9507372f0b1b963James Dong                        tmp = (x<<24) + ((y+4)<<16) + (4<<8) + 4;
3120c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+2, &refImage,
3130c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                    colAndRow, tmp, pFill);
3140c1bc742181ded4930842b46e9507372f0b1b963James Dong                        tmp = ((x+4)<<24) + ((y+4)<<16) + (4<<8) + 4;
3150c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+3, &refImage,
3160c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                    colAndRow, tmp, pFill);
3170c1bc742181ded4930842b46e9507372f0b1b963James Dong                        break;
3180c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
3190c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
3200c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
3210c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3220c1bc742181ded4930842b46e9507372f0b1b963James Dong
3230c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* if decoded flag > 1 -> mb has already been successfully decoded and
3240c1bc742181ded4930842b46e9507372f0b1b963James Dong     * written to output -> do not write again */
3250c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pMb->decoded > 1)
3260c1bc742181ded4930842b46e9507372f0b1b963James Dong        return HANTRO_OK;
3270c1bc742181ded4930842b46e9507372f0b1b963James Dong
3280c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
3290c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3300c1bc742181ded4930842b46e9507372f0b1b963James Dong
3310c1bc742181ded4930842b46e9507372f0b1b963James Dong#else /* H264DEC_OMXDL */
3320c1bc742181ded4930842b46e9507372f0b1b963James Dong
3330c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
3340c1bc742181ded4930842b46e9507372f0b1b963James Dong
3350c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterPrediction
3360c1bc742181ded4930842b46e9507372f0b1b963James Dong
3370c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
3380c1bc742181ded4930842b46e9507372f0b1b963James Dong          Processes one inter macroblock. Performs motion vector prediction
3390c1bc742181ded4930842b46e9507372f0b1b963James Dong          and reconstructs prediction macroblock. Writes the final macroblock
3400c1bc742181ded4930842b46e9507372f0b1b963James Dong          (prediction + residual) into the output image (currImage)
3410c1bc742181ded4930842b46e9507372f0b1b963James Dong
3420c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
3430c1bc742181ded4930842b46e9507372f0b1b963James Dong          pMb           pointer to macroblock specific information
3440c1bc742181ded4930842b46e9507372f0b1b963James Dong          pMbLayer      pointer to current macroblock data from stream
3450c1bc742181ded4930842b46e9507372f0b1b963James Dong          dpb           pointer to decoded picture buffer
3460c1bc742181ded4930842b46e9507372f0b1b963James Dong          mbNum         current macroblock number
3470c1bc742181ded4930842b46e9507372f0b1b963James Dong          currImage     pointer to output image
3480c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          pointer where predicted macroblock will be stored
3490c1bc742181ded4930842b46e9507372f0b1b963James Dong
3500c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
3510c1bc742181ded4930842b46e9507372f0b1b963James Dong          pMb           structure is updated with current macroblock
3520c1bc742181ded4930842b46e9507372f0b1b963James Dong          currImage     current macroblock is written into image
3530c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          prediction is stored here
3540c1bc742181ded4930842b46e9507372f0b1b963James Dong
3550c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
3560c1bc742181ded4930842b46e9507372f0b1b963James Dong          HANTRO_OK     success
3570c1bc742181ded4930842b46e9507372f0b1b963James Dong          HANTRO_NOK    error in motion vector prediction
3580c1bc742181ded4930842b46e9507372f0b1b963James Dong
3590c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
3600c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdInterPrediction(mbStorage_t *pMb, macroblockLayer_t *pMbLayer,
3610c1bc742181ded4930842b46e9507372f0b1b963James Dong    dpbStorage_t *dpb, u32 mbNum, image_t *currImage, u8 *data)
3620c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3630c1bc742181ded4930842b46e9507372f0b1b963James Dong
3640c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
3650c1bc742181ded4930842b46e9507372f0b1b963James Dong
3660c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
3670c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
3680c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 row, col;
3690c1bc742181ded4930842b46e9507372f0b1b963James Dong    subMbPartMode_e subPartMode;
3700c1bc742181ded4930842b46e9507372f0b1b963James Dong    image_t refImage;
3710c1bc742181ded4930842b46e9507372f0b1b963James Dong
3720c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
3730c1bc742181ded4930842b46e9507372f0b1b963James Dong
3740c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMb);
3750c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTER);
3760c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMbLayer);
3770c1bc742181ded4930842b46e9507372f0b1b963James Dong
3780c1bc742181ded4930842b46e9507372f0b1b963James Dong    row = mbNum / currImage->width;
3790c1bc742181ded4930842b46e9507372f0b1b963James Dong    col = mbNum - row * currImage->width;
3800c1bc742181ded4930842b46e9507372f0b1b963James Dong    row *= 16;
3810c1bc742181ded4930842b46e9507372f0b1b963James Dong    col *= 16;
3820c1bc742181ded4930842b46e9507372f0b1b963James Dong
3830c1bc742181ded4930842b46e9507372f0b1b963James Dong    refImage.width = currImage->width;
3840c1bc742181ded4930842b46e9507372f0b1b963James Dong    refImage.height = currImage->height;
3850c1bc742181ded4930842b46e9507372f0b1b963James Dong
3860c1bc742181ded4930842b46e9507372f0b1b963James Dong    switch (pMb->mbType)
3870c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3880c1bc742181ded4930842b46e9507372f0b1b963James Dong        case P_Skip:
3890c1bc742181ded4930842b46e9507372f0b1b963James Dong        case P_L0_16x16:
3900c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (MvPrediction16x16(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
3910c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
3920c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[0];
3930c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv, &refImage, col, row, 0, 0,
3940c1bc742181ded4930842b46e9507372f0b1b963James Dong                16, 16);
3950c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
3960c1bc742181ded4930842b46e9507372f0b1b963James Dong
3970c1bc742181ded4930842b46e9507372f0b1b963James Dong        case P_L0_L0_16x8:
3980c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( MvPrediction16x8(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
3990c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
4000c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[0];
4010c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv, &refImage, col, row, 0, 0,
4020c1bc742181ded4930842b46e9507372f0b1b963James Dong                16, 8);
4030c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[2];
4040c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv+8, &refImage, col, row, 0, 8,
4050c1bc742181ded4930842b46e9507372f0b1b963James Dong                16, 8);
4060c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
4070c1bc742181ded4930842b46e9507372f0b1b963James Dong
4080c1bc742181ded4930842b46e9507372f0b1b963James Dong        case P_L0_L0_8x16:
4090c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( MvPrediction8x16(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
4100c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
4110c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[0];
4120c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv, &refImage, col, row, 0, 0,
4130c1bc742181ded4930842b46e9507372f0b1b963James Dong                8, 16);
4140c1bc742181ded4930842b46e9507372f0b1b963James Dong            refImage.data = pMb->refAddr[1];
4150c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdPredictSamples(data, pMb->mv+4, &refImage, col, row, 8, 0,
4160c1bc742181ded4930842b46e9507372f0b1b963James Dong                8, 16);
4170c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
4180c1bc742181ded4930842b46e9507372f0b1b963James Dong
4190c1bc742181ded4930842b46e9507372f0b1b963James Dong        default: /* P_8x8 and P_8x8ref0 */
4200c1bc742181ded4930842b46e9507372f0b1b963James Dong            if ( MvPrediction8x8(pMb, &pMbLayer->subMbPred, dpb) != HANTRO_OK)
4210c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
4220c1bc742181ded4930842b46e9507372f0b1b963James Dong            for (i = 0; i < 4; i++)
4230c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
4240c1bc742181ded4930842b46e9507372f0b1b963James Dong                refImage.data = pMb->refAddr[i];
4250c1bc742181ded4930842b46e9507372f0b1b963James Dong                subPartMode =
4260c1bc742181ded4930842b46e9507372f0b1b963James Dong                    h264bsdSubMbPartMode(pMbLayer->subMbPred.subMbType[i]);
4270c1bc742181ded4930842b46e9507372f0b1b963James Dong                x = i & 0x1 ? 8 : 0;
4280c1bc742181ded4930842b46e9507372f0b1b963James Dong                y = i < 2 ? 0 : 8;
4290c1bc742181ded4930842b46e9507372f0b1b963James Dong                switch (subPartMode)
4300c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
4310c1bc742181ded4930842b46e9507372f0b1b963James Dong                    case MB_SP_8x8:
4320c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
4330c1bc742181ded4930842b46e9507372f0b1b963James Dong                            col, row, x, y, 8, 8);
4340c1bc742181ded4930842b46e9507372f0b1b963James Dong                        break;
4350c1bc742181ded4930842b46e9507372f0b1b963James Dong
4360c1bc742181ded4930842b46e9507372f0b1b963James Dong                    case MB_SP_8x4:
4370c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
4380c1bc742181ded4930842b46e9507372f0b1b963James Dong                            col, row, x, y, 8, 4);
4390c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+2, &refImage,
4400c1bc742181ded4930842b46e9507372f0b1b963James Dong                            col, row, x, y+4, 8, 4);
4410c1bc742181ded4930842b46e9507372f0b1b963James Dong                        break;
4420c1bc742181ded4930842b46e9507372f0b1b963James Dong
4430c1bc742181ded4930842b46e9507372f0b1b963James Dong                    case MB_SP_4x8:
4440c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
4450c1bc742181ded4930842b46e9507372f0b1b963James Dong                            col, row, x, y, 4, 8);
4460c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+1, &refImage,
4470c1bc742181ded4930842b46e9507372f0b1b963James Dong                            col, row, x+4, y, 4, 8);
4480c1bc742181ded4930842b46e9507372f0b1b963James Dong                        break;
4490c1bc742181ded4930842b46e9507372f0b1b963James Dong
4500c1bc742181ded4930842b46e9507372f0b1b963James Dong                    default:
4510c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
4520c1bc742181ded4930842b46e9507372f0b1b963James Dong                            col, row, x, y, 4, 4);
4530c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+1, &refImage,
4540c1bc742181ded4930842b46e9507372f0b1b963James Dong                            col, row, x+4, y, 4, 4);
4550c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+2, &refImage,
4560c1bc742181ded4930842b46e9507372f0b1b963James Dong                            col, row, x, y+4, 4, 4);
4570c1bc742181ded4930842b46e9507372f0b1b963James Dong                        h264bsdPredictSamples(data, pMb->mv+4*i+3, &refImage,
4580c1bc742181ded4930842b46e9507372f0b1b963James Dong                            col, row, x+4, y+4, 4, 4);
4590c1bc742181ded4930842b46e9507372f0b1b963James Dong                        break;
4600c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
4610c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
4620c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
4630c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4640c1bc742181ded4930842b46e9507372f0b1b963James Dong
4650c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* if decoded flag > 1 -> mb has already been successfully decoded and
4660c1bc742181ded4930842b46e9507372f0b1b963James Dong     * written to output -> do not write again */
4670c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pMb->decoded > 1)
4680c1bc742181ded4930842b46e9507372f0b1b963James Dong        return HANTRO_OK;
4690c1bc742181ded4930842b46e9507372f0b1b963James Dong
4700c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pMb->mbType != P_Skip)
4710c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4720c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdWriteOutputBlocks(currImage, mbNum, data,
4730c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMbLayer->residual.level);
4740c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4750c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
4760c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4770c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdWriteMacroblock(currImage, data);
4780c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4790c1bc742181ded4930842b46e9507372f0b1b963James Dong
4800c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
4810c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4820c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
4830c1bc742181ded4930842b46e9507372f0b1b963James Dong
4840c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
4850c1bc742181ded4930842b46e9507372f0b1b963James Dong
4860c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: MvPrediction16x16
4870c1bc742181ded4930842b46e9507372f0b1b963James Dong
4880c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
4890c1bc742181ded4930842b46e9507372f0b1b963James Dong            Motion vector prediction for 16x16 partition mode
4900c1bc742181ded4930842b46e9507372f0b1b963James Dong
4910c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
4920c1bc742181ded4930842b46e9507372f0b1b963James Dong
4930c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 MvPrediction16x16(mbStorage_t *pMb, mbPred_t *mbPred, dpbStorage_t *dpb)
4940c1bc742181ded4930842b46e9507372f0b1b963James Dong{
4950c1bc742181ded4930842b46e9507372f0b1b963James Dong
4960c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
4970c1bc742181ded4930842b46e9507372f0b1b963James Dong
4980c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv_t mv;
4990c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv_t mvPred;
5000c1bc742181ded4930842b46e9507372f0b1b963James Dong    interNeighbour_t a[3]; /* A, B, C */
5010c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 refIndex;
5020c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *tmp;
5030c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 *tmpMv1, *tmpMv2;
5040c1bc742181ded4930842b46e9507372f0b1b963James Dong
5050c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
5060c1bc742181ded4930842b46e9507372f0b1b963James Dong
5070c1bc742181ded4930842b46e9507372f0b1b963James Dong    refIndex = mbPred->refIdxL0[0];
5080c1bc742181ded4930842b46e9507372f0b1b963James Dong
5090c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetInterNeighbour(pMb->sliceId, pMb->mbA, a, 5);
5100c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetInterNeighbour(pMb->sliceId, pMb->mbB, a+1, 10);
5110c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*lint --e(740)  Unusual pointer cast (incompatible indirect types) */
5120c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmpMv1 = (u32*)(&a[0].mv); /* we test just that both MVs are zero */
5130c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*lint --e(740) */
5140c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmpMv2 = (u32*)(&a[1].mv); /* i.e. a[0].mv.hor == 0 && a[0].mv.ver == 0 */
5150c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pMb->mbType == P_Skip &&
5160c1bc742181ded4930842b46e9507372f0b1b963James Dong        (!a[0].available || !a[1].available ||
5170c1bc742181ded4930842b46e9507372f0b1b963James Dong         ( a[0].refIndex == 0 && ((u32)(*tmpMv1) == 0) ) ||
5180c1bc742181ded4930842b46e9507372f0b1b963James Dong         ( a[1].refIndex == 0 && ((u32)(*tmpMv2) == 0) )))
5190c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5200c1bc742181ded4930842b46e9507372f0b1b963James Dong            mv.hor = mv.ver = 0;
5210c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5220c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
5230c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5240c1bc742181ded4930842b46e9507372f0b1b963James Dong        mv = mbPred->mvdL0[0];
5250c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetInterNeighbour(pMb->sliceId, pMb->mbC, a+2, 10);
5260c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (!a[2].available)
5270c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
5280c1bc742181ded4930842b46e9507372f0b1b963James Dong            GetInterNeighbour(pMb->sliceId, pMb->mbD, a+2, 15);
5290c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
5300c1bc742181ded4930842b46e9507372f0b1b963James Dong
5310c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetPredictionMv(&mvPred, a, refIndex);
5320c1bc742181ded4930842b46e9507372f0b1b963James Dong
5330c1bc742181ded4930842b46e9507372f0b1b963James Dong        mv.hor += mvPred.hor;
5340c1bc742181ded4930842b46e9507372f0b1b963James Dong        mv.ver += mvPred.ver;
5350c1bc742181ded4930842b46e9507372f0b1b963James Dong
5360c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* horizontal motion vector range [-2048, 2047.75] */
5370c1bc742181ded4930842b46e9507372f0b1b963James Dong        if ((u32)(i32)(mv.hor+8192) >= (16384))
5380c1bc742181ded4930842b46e9507372f0b1b963James Dong            return(HANTRO_NOK);
5390c1bc742181ded4930842b46e9507372f0b1b963James Dong
5400c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* vertical motion vector range [-512, 511.75]
5410c1bc742181ded4930842b46e9507372f0b1b963James Dong         * (smaller for low levels) */
5420c1bc742181ded4930842b46e9507372f0b1b963James Dong        if ((u32)(i32)(mv.ver+2048) >= (4096))
5430c1bc742181ded4930842b46e9507372f0b1b963James Dong            return(HANTRO_NOK);
5440c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5450c1bc742181ded4930842b46e9507372f0b1b963James Dong
5460c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = h264bsdGetRefPicData(dpb, refIndex);
5470c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp == NULL)
5480c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
5490c1bc742181ded4930842b46e9507372f0b1b963James Dong
5500c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[0] = pMb->mv[1] = pMb->mv[2] = pMb->mv[3] =
5510c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[4] = pMb->mv[5] = pMb->mv[6] = pMb->mv[7] =
5520c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[8] = pMb->mv[9] = pMb->mv[10] = pMb->mv[11] =
5530c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[12] = pMb->mv[13] = pMb->mv[14] = pMb->mv[15] = mv;
5540c1bc742181ded4930842b46e9507372f0b1b963James Dong
5550c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[0] = refIndex;
5560c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[1] = refIndex;
5570c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[2] = refIndex;
5580c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[3] = refIndex;
5590c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[0] = tmp;
5600c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[1] = tmp;
5610c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[2] = tmp;
5620c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[3] = tmp;
5630c1bc742181ded4930842b46e9507372f0b1b963James Dong
5640c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
5650c1bc742181ded4930842b46e9507372f0b1b963James Dong
5660c1bc742181ded4930842b46e9507372f0b1b963James Dong}
5670c1bc742181ded4930842b46e9507372f0b1b963James Dong
5680c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
5690c1bc742181ded4930842b46e9507372f0b1b963James Dong
5700c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: MvPrediction16x8
5710c1bc742181ded4930842b46e9507372f0b1b963James Dong
5720c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
5730c1bc742181ded4930842b46e9507372f0b1b963James Dong            Motion vector prediction for 16x8 partition mode
5740c1bc742181ded4930842b46e9507372f0b1b963James Dong
5750c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
5760c1bc742181ded4930842b46e9507372f0b1b963James Dong
5770c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 MvPrediction16x8(mbStorage_t *pMb, mbPred_t *mbPred, dpbStorage_t *dpb)
5780c1bc742181ded4930842b46e9507372f0b1b963James Dong{
5790c1bc742181ded4930842b46e9507372f0b1b963James Dong
5800c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
5810c1bc742181ded4930842b46e9507372f0b1b963James Dong
5820c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv_t mv;
5830c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv_t mvPred;
5840c1bc742181ded4930842b46e9507372f0b1b963James Dong    interNeighbour_t a[3]; /* A, B, C */
5850c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 refIndex;
5860c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *tmp;
5870c1bc742181ded4930842b46e9507372f0b1b963James Dong
5880c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
5890c1bc742181ded4930842b46e9507372f0b1b963James Dong
5900c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv = mbPred->mvdL0[0];
5910c1bc742181ded4930842b46e9507372f0b1b963James Dong    refIndex = mbPred->refIdxL0[0];
5920c1bc742181ded4930842b46e9507372f0b1b963James Dong
5930c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetInterNeighbour(pMb->sliceId, pMb->mbB, a+1, 10);
5940c1bc742181ded4930842b46e9507372f0b1b963James Dong
5950c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (a[1].refIndex == refIndex)
5960c1bc742181ded4930842b46e9507372f0b1b963James Dong        mvPred = a[1].mv;
5970c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
5980c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5990c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetInterNeighbour(pMb->sliceId, pMb->mbA, a, 5);
6000c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetInterNeighbour(pMb->sliceId, pMb->mbC, a+2, 10);
6010c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (!a[2].available)
6020c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
6030c1bc742181ded4930842b46e9507372f0b1b963James Dong            GetInterNeighbour(pMb->sliceId, pMb->mbD, a+2, 15);
6040c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
6050c1bc742181ded4930842b46e9507372f0b1b963James Dong
6060c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetPredictionMv(&mvPred, a, refIndex);
6070c1bc742181ded4930842b46e9507372f0b1b963James Dong
6080c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
6090c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.hor += mvPred.hor;
6100c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.ver += mvPred.ver;
6110c1bc742181ded4930842b46e9507372f0b1b963James Dong
6120c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* horizontal motion vector range [-2048, 2047.75] */
6130c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((u32)(i32)(mv.hor+8192) >= (16384))
6140c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
6150c1bc742181ded4930842b46e9507372f0b1b963James Dong
6160c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
6170c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((u32)(i32)(mv.ver+2048) >= (4096))
6180c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
6190c1bc742181ded4930842b46e9507372f0b1b963James Dong
6200c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = h264bsdGetRefPicData(dpb, refIndex);
6210c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp == NULL)
6220c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
6230c1bc742181ded4930842b46e9507372f0b1b963James Dong
6240c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[0] = pMb->mv[1] = pMb->mv[2] = pMb->mv[3] =
6250c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[4] = pMb->mv[5] = pMb->mv[6] = pMb->mv[7] = mv;
6260c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[0] = refIndex;
6270c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[1] = refIndex;
6280c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[0] = tmp;
6290c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[1] = tmp;
6300c1bc742181ded4930842b46e9507372f0b1b963James Dong
6310c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv = mbPred->mvdL0[1];
6320c1bc742181ded4930842b46e9507372f0b1b963James Dong    refIndex = mbPred->refIdxL0[1];
6330c1bc742181ded4930842b46e9507372f0b1b963James Dong
6340c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetInterNeighbour(pMb->sliceId, pMb->mbA, a, 13);
6350c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (a[0].refIndex == refIndex)
6360c1bc742181ded4930842b46e9507372f0b1b963James Dong        mvPred = a[0].mv;
6370c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
6380c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6390c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[1].available = HANTRO_TRUE;
6400c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[1].refIndex = pMb->refPic[0];
6410c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[1].mv = pMb->mv[0];
6420c1bc742181ded4930842b46e9507372f0b1b963James Dong
6430c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* c is not available */
6440c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetInterNeighbour(pMb->sliceId, pMb->mbA, a+2, 7);
6450c1bc742181ded4930842b46e9507372f0b1b963James Dong
6460c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetPredictionMv(&mvPred, a, refIndex);
6470c1bc742181ded4930842b46e9507372f0b1b963James Dong
6480c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
6490c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.hor += mvPred.hor;
6500c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.ver += mvPred.ver;
6510c1bc742181ded4930842b46e9507372f0b1b963James Dong
6520c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* horizontal motion vector range [-2048, 2047.75] */
6530c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((u32)(i32)(mv.hor+8192) >= (16384))
6540c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
6550c1bc742181ded4930842b46e9507372f0b1b963James Dong
6560c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
6570c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((u32)(i32)(mv.ver+2048) >= (4096))
6580c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
6590c1bc742181ded4930842b46e9507372f0b1b963James Dong
6600c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = h264bsdGetRefPicData(dpb, refIndex);
6610c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp == NULL)
6620c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
6630c1bc742181ded4930842b46e9507372f0b1b963James Dong
6640c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[8] = pMb->mv[9] = pMb->mv[10] = pMb->mv[11] =
6650c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[12] = pMb->mv[13] = pMb->mv[14] = pMb->mv[15] = mv;
6660c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[2] = refIndex;
6670c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[3] = refIndex;
6680c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[2] = tmp;
6690c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[3] = tmp;
6700c1bc742181ded4930842b46e9507372f0b1b963James Dong
6710c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
6720c1bc742181ded4930842b46e9507372f0b1b963James Dong
6730c1bc742181ded4930842b46e9507372f0b1b963James Dong}
6740c1bc742181ded4930842b46e9507372f0b1b963James Dong
6750c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
6760c1bc742181ded4930842b46e9507372f0b1b963James Dong
6770c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: MvPrediction8x16
6780c1bc742181ded4930842b46e9507372f0b1b963James Dong
6790c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
6800c1bc742181ded4930842b46e9507372f0b1b963James Dong            Motion vector prediction for 8x16 partition mode
6810c1bc742181ded4930842b46e9507372f0b1b963James Dong
6820c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
6830c1bc742181ded4930842b46e9507372f0b1b963James Dong
6840c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 MvPrediction8x16(mbStorage_t *pMb, mbPred_t *mbPred, dpbStorage_t *dpb)
6850c1bc742181ded4930842b46e9507372f0b1b963James Dong{
6860c1bc742181ded4930842b46e9507372f0b1b963James Dong
6870c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
6880c1bc742181ded4930842b46e9507372f0b1b963James Dong
6890c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv_t mv;
6900c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv_t mvPred;
6910c1bc742181ded4930842b46e9507372f0b1b963James Dong    interNeighbour_t a[3]; /* A, B, C */
6920c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 refIndex;
6930c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *tmp;
6940c1bc742181ded4930842b46e9507372f0b1b963James Dong
6950c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
6960c1bc742181ded4930842b46e9507372f0b1b963James Dong
6970c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv = mbPred->mvdL0[0];
6980c1bc742181ded4930842b46e9507372f0b1b963James Dong    refIndex = mbPred->refIdxL0[0];
6990c1bc742181ded4930842b46e9507372f0b1b963James Dong
7000c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetInterNeighbour(pMb->sliceId, pMb->mbA, a, 5);
7010c1bc742181ded4930842b46e9507372f0b1b963James Dong
7020c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (a[0].refIndex == refIndex)
7030c1bc742181ded4930842b46e9507372f0b1b963James Dong        mvPred = a[0].mv;
7040c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
7050c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7060c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetInterNeighbour(pMb->sliceId, pMb->mbB, a+1, 10);
7070c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetInterNeighbour(pMb->sliceId, pMb->mbB, a+2, 14);
7080c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (!a[2].available)
7090c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7100c1bc742181ded4930842b46e9507372f0b1b963James Dong            GetInterNeighbour(pMb->sliceId, pMb->mbD, a+2, 15);
7110c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
7120c1bc742181ded4930842b46e9507372f0b1b963James Dong
7130c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetPredictionMv(&mvPred, a, refIndex);
7140c1bc742181ded4930842b46e9507372f0b1b963James Dong
7150c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7160c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.hor += mvPred.hor;
7170c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.ver += mvPred.ver;
7180c1bc742181ded4930842b46e9507372f0b1b963James Dong
7190c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* horizontal motion vector range [-2048, 2047.75] */
7200c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((u32)(i32)(mv.hor+8192) >= (16384))
7210c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
7220c1bc742181ded4930842b46e9507372f0b1b963James Dong
7230c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
7240c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((u32)(i32)(mv.ver+2048) >= (4096))
7250c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
7260c1bc742181ded4930842b46e9507372f0b1b963James Dong
7270c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = h264bsdGetRefPicData(dpb, refIndex);
7280c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp == NULL)
7290c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
7300c1bc742181ded4930842b46e9507372f0b1b963James Dong
7310c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[0] = pMb->mv[1] = pMb->mv[2] = pMb->mv[3] =
7320c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[8] = pMb->mv[9] = pMb->mv[10] = pMb->mv[11] = mv;
7330c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[0] = refIndex;
7340c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[2] = refIndex;
7350c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[0] = tmp;
7360c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[2] = tmp;
7370c1bc742181ded4930842b46e9507372f0b1b963James Dong
7380c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv = mbPred->mvdL0[1];
7390c1bc742181ded4930842b46e9507372f0b1b963James Dong    refIndex = mbPred->refIdxL0[1];
7400c1bc742181ded4930842b46e9507372f0b1b963James Dong
7410c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetInterNeighbour(pMb->sliceId, pMb->mbC, a+2, 10);
7420c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (!a[2].available)
7430c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7440c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetInterNeighbour(pMb->sliceId, pMb->mbB, a+2, 11);
7450c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7460c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (a[2].refIndex == refIndex)
7470c1bc742181ded4930842b46e9507372f0b1b963James Dong        mvPred = a[2].mv;
7480c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
7490c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7500c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[0].available = HANTRO_TRUE;
7510c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[0].refIndex = pMb->refPic[0];
7520c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[0].mv = pMb->mv[0];
7530c1bc742181ded4930842b46e9507372f0b1b963James Dong
7540c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetInterNeighbour(pMb->sliceId, pMb->mbB, a+1, 14);
7550c1bc742181ded4930842b46e9507372f0b1b963James Dong
7560c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetPredictionMv(&mvPred, a, refIndex);
7570c1bc742181ded4930842b46e9507372f0b1b963James Dong
7580c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7590c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.hor += mvPred.hor;
7600c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.ver += mvPred.ver;
7610c1bc742181ded4930842b46e9507372f0b1b963James Dong
7620c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* horizontal motion vector range [-2048, 2047.75] */
7630c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((u32)(i32)(mv.hor+8192) >= (16384))
7640c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
7650c1bc742181ded4930842b46e9507372f0b1b963James Dong
7660c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
7670c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((u32)(i32)(mv.ver+2048) >= (4096))
7680c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
7690c1bc742181ded4930842b46e9507372f0b1b963James Dong
7700c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = h264bsdGetRefPicData(dpb, refIndex);
7710c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp == NULL)
7720c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
7730c1bc742181ded4930842b46e9507372f0b1b963James Dong
7740c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[4] = pMb->mv[5] = pMb->mv[6] = pMb->mv[7] =
7750c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->mv[12] = pMb->mv[13] = pMb->mv[14] = pMb->mv[15] = mv;
7760c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[1] = refIndex;
7770c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refPic[3] = refIndex;
7780c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[1] = tmp;
7790c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->refAddr[3] = tmp;
7800c1bc742181ded4930842b46e9507372f0b1b963James Dong
7810c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
7820c1bc742181ded4930842b46e9507372f0b1b963James Dong
7830c1bc742181ded4930842b46e9507372f0b1b963James Dong}
7840c1bc742181ded4930842b46e9507372f0b1b963James Dong
7850c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
7860c1bc742181ded4930842b46e9507372f0b1b963James Dong
7870c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: MvPrediction8x8
7880c1bc742181ded4930842b46e9507372f0b1b963James Dong
7890c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
7900c1bc742181ded4930842b46e9507372f0b1b963James Dong            Motion vector prediction for 8x8 partition mode
7910c1bc742181ded4930842b46e9507372f0b1b963James Dong
7920c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
7930c1bc742181ded4930842b46e9507372f0b1b963James Dong
7940c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 MvPrediction8x8(mbStorage_t *pMb, subMbPred_t *subMbPred, dpbStorage_t *dpb)
7950c1bc742181ded4930842b46e9507372f0b1b963James Dong{
7960c1bc742181ded4930842b46e9507372f0b1b963James Dong
7970c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
7980c1bc742181ded4930842b46e9507372f0b1b963James Dong
7990c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i, j;
8000c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 numSubMbPart;
8010c1bc742181ded4930842b46e9507372f0b1b963James Dong
8020c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
8030c1bc742181ded4930842b46e9507372f0b1b963James Dong
8040c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0; i < 4; i++)
8050c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
8060c1bc742181ded4930842b46e9507372f0b1b963James Dong        numSubMbPart = h264bsdNumSubMbPart(subMbPred->subMbType[i]);
8070c1bc742181ded4930842b46e9507372f0b1b963James Dong        pMb->refPic[i] = subMbPred->refIdxL0[i];
8080c1bc742181ded4930842b46e9507372f0b1b963James Dong        pMb->refAddr[i] = h264bsdGetRefPicData(dpb, subMbPred->refIdxL0[i]);
8090c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (pMb->refAddr[i] == NULL)
8100c1bc742181ded4930842b46e9507372f0b1b963James Dong            return(HANTRO_NOK);
8110c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (j = 0; j < numSubMbPart; j++)
8120c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
8130c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (MvPrediction(pMb, subMbPred, i, j) != HANTRO_OK)
8140c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
8150c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
8160c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
8170c1bc742181ded4930842b46e9507372f0b1b963James Dong
8180c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
8190c1bc742181ded4930842b46e9507372f0b1b963James Dong
8200c1bc742181ded4930842b46e9507372f0b1b963James Dong}
8210c1bc742181ded4930842b46e9507372f0b1b963James Dong
8220c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
8230c1bc742181ded4930842b46e9507372f0b1b963James Dong
8240c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: MvPrediction
8250c1bc742181ded4930842b46e9507372f0b1b963James Dong
8260c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
8270c1bc742181ded4930842b46e9507372f0b1b963James Dong            Perform motion vector prediction for sub-partition
8280c1bc742181ded4930842b46e9507372f0b1b963James Dong
8290c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
8300c1bc742181ded4930842b46e9507372f0b1b963James Dong
8310c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 MvPrediction(mbStorage_t *pMb, subMbPred_t *subMbPred, u32 mbPartIdx,
8320c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 subMbPartIdx)
8330c1bc742181ded4930842b46e9507372f0b1b963James Dong{
8340c1bc742181ded4930842b46e9507372f0b1b963James Dong
8350c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
8360c1bc742181ded4930842b46e9507372f0b1b963James Dong
8370c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv_t mv, mvPred;
8380c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 refIndex;
8390c1bc742181ded4930842b46e9507372f0b1b963James Dong    subMbPartMode_e subMbPartMode;
8400c1bc742181ded4930842b46e9507372f0b1b963James Dong    const neighbour_t *n;
8410c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *nMb;
8420c1bc742181ded4930842b46e9507372f0b1b963James Dong    interNeighbour_t a[3]; /* A, B, C */
8430c1bc742181ded4930842b46e9507372f0b1b963James Dong
8440c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
8450c1bc742181ded4930842b46e9507372f0b1b963James Dong
8460c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv = subMbPred->mvdL0[mbPartIdx][subMbPartIdx];
8470c1bc742181ded4930842b46e9507372f0b1b963James Dong    subMbPartMode = h264bsdSubMbPartMode(subMbPred->subMbType[mbPartIdx]);
8480c1bc742181ded4930842b46e9507372f0b1b963James Dong    refIndex = subMbPred->refIdxL0[mbPartIdx];
8490c1bc742181ded4930842b46e9507372f0b1b963James Dong
8500c1bc742181ded4930842b46e9507372f0b1b963James Dong    n = N_A_SUB_PART[mbPartIdx][subMbPartMode]+subMbPartIdx;
8510c1bc742181ded4930842b46e9507372f0b1b963James Dong    nMb = h264bsdGetNeighbourMb(pMb, n->mb);
8520c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetInterNeighbour(pMb->sliceId, nMb, a, n->index);
8530c1bc742181ded4930842b46e9507372f0b1b963James Dong
8540c1bc742181ded4930842b46e9507372f0b1b963James Dong    n = N_B_SUB_PART[mbPartIdx][subMbPartMode]+subMbPartIdx;
8550c1bc742181ded4930842b46e9507372f0b1b963James Dong    nMb = h264bsdGetNeighbourMb(pMb, n->mb);
8560c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetInterNeighbour(pMb->sliceId, nMb, a+1, n->index);
8570c1bc742181ded4930842b46e9507372f0b1b963James Dong
8580c1bc742181ded4930842b46e9507372f0b1b963James Dong    n = N_C_SUB_PART[mbPartIdx][subMbPartMode]+subMbPartIdx;
8590c1bc742181ded4930842b46e9507372f0b1b963James Dong    nMb = h264bsdGetNeighbourMb(pMb, n->mb);
8600c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetInterNeighbour(pMb->sliceId, nMb, a+2, n->index);
8610c1bc742181ded4930842b46e9507372f0b1b963James Dong
8620c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (!a[2].available)
8630c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
8640c1bc742181ded4930842b46e9507372f0b1b963James Dong        n = N_D_SUB_PART[mbPartIdx][subMbPartMode]+subMbPartIdx;
8650c1bc742181ded4930842b46e9507372f0b1b963James Dong        nMb = h264bsdGetNeighbourMb(pMb, n->mb);
8660c1bc742181ded4930842b46e9507372f0b1b963James Dong        GetInterNeighbour(pMb->sliceId, nMb, a+2, n->index);
8670c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
8680c1bc742181ded4930842b46e9507372f0b1b963James Dong
8690c1bc742181ded4930842b46e9507372f0b1b963James Dong    GetPredictionMv(&mvPred, a, refIndex);
8700c1bc742181ded4930842b46e9507372f0b1b963James Dong
8710c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.hor += mvPred.hor;
8720c1bc742181ded4930842b46e9507372f0b1b963James Dong    mv.ver += mvPred.ver;
8730c1bc742181ded4930842b46e9507372f0b1b963James Dong
8740c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* horizontal motion vector range [-2048, 2047.75] */
8750c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (((u32)(i32)(mv.hor+8192) >= (16384)))
8760c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
8770c1bc742181ded4930842b46e9507372f0b1b963James Dong
8780c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
8790c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (((u32)(i32)(mv.ver+2048) >= (4096)))
8800c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_NOK);
8810c1bc742181ded4930842b46e9507372f0b1b963James Dong
8820c1bc742181ded4930842b46e9507372f0b1b963James Dong    switch (subMbPartMode)
8830c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
8840c1bc742181ded4930842b46e9507372f0b1b963James Dong        case MB_SP_8x8:
8850c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMb->mv[4*mbPartIdx] = mv;
8860c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMb->mv[4*mbPartIdx + 1] = mv;
8870c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMb->mv[4*mbPartIdx + 2] = mv;
8880c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMb->mv[4*mbPartIdx + 3] = mv;
8890c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
8900c1bc742181ded4930842b46e9507372f0b1b963James Dong
8910c1bc742181ded4930842b46e9507372f0b1b963James Dong        case MB_SP_8x4:
8920c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMb->mv[4*mbPartIdx + 2*subMbPartIdx] = mv;
8930c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMb->mv[4*mbPartIdx + 2*subMbPartIdx + 1] = mv;
8940c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
8950c1bc742181ded4930842b46e9507372f0b1b963James Dong
8960c1bc742181ded4930842b46e9507372f0b1b963James Dong        case MB_SP_4x8:
8970c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMb->mv[4*mbPartIdx + subMbPartIdx] = mv;
8980c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMb->mv[4*mbPartIdx + subMbPartIdx + 2] = mv;
8990c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
9000c1bc742181ded4930842b46e9507372f0b1b963James Dong
9010c1bc742181ded4930842b46e9507372f0b1b963James Dong        case MB_SP_4x4:
9020c1bc742181ded4930842b46e9507372f0b1b963James Dong            pMb->mv[4*mbPartIdx + subMbPartIdx] = mv;
9030c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
9040c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9050c1bc742181ded4930842b46e9507372f0b1b963James Dong
9060c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
9070c1bc742181ded4930842b46e9507372f0b1b963James Dong
9080c1bc742181ded4930842b46e9507372f0b1b963James Dong}
9090c1bc742181ded4930842b46e9507372f0b1b963James Dong
9100c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
9110c1bc742181ded4930842b46e9507372f0b1b963James Dong
9120c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: MedianFilter
9130c1bc742181ded4930842b46e9507372f0b1b963James Dong
9140c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
9150c1bc742181ded4930842b46e9507372f0b1b963James Dong            Median filtering for motion vector prediction
9160c1bc742181ded4930842b46e9507372f0b1b963James Dong
9170c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
9180c1bc742181ded4930842b46e9507372f0b1b963James Dong
9190c1bc742181ded4930842b46e9507372f0b1b963James Dongi32 MedianFilter(i32 a, i32 b, i32 c)
9200c1bc742181ded4930842b46e9507372f0b1b963James Dong{
9210c1bc742181ded4930842b46e9507372f0b1b963James Dong
9220c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
9230c1bc742181ded4930842b46e9507372f0b1b963James Dong
9240c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 max,min,med;
9250c1bc742181ded4930842b46e9507372f0b1b963James Dong
9260c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
9270c1bc742181ded4930842b46e9507372f0b1b963James Dong
9280c1bc742181ded4930842b46e9507372f0b1b963James Dong    max = min = med = a;
9290c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (b > max)
9300c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9310c1bc742181ded4930842b46e9507372f0b1b963James Dong        max = b;
9320c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9330c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (b < min)
9340c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9350c1bc742181ded4930842b46e9507372f0b1b963James Dong        min = b;
9360c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9370c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (c > max)
9380c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9390c1bc742181ded4930842b46e9507372f0b1b963James Dong        med = max;
9400c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9410c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (c < min)
9420c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9430c1bc742181ded4930842b46e9507372f0b1b963James Dong        med = min;
9440c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9450c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
9460c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9470c1bc742181ded4930842b46e9507372f0b1b963James Dong        med = c;
9480c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9490c1bc742181ded4930842b46e9507372f0b1b963James Dong
9500c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(med);
9510c1bc742181ded4930842b46e9507372f0b1b963James Dong}
9520c1bc742181ded4930842b46e9507372f0b1b963James Dong
9530c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
9540c1bc742181ded4930842b46e9507372f0b1b963James Dong
9550c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: GetInterNeighbour
9560c1bc742181ded4930842b46e9507372f0b1b963James Dong
9570c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
9580c1bc742181ded4930842b46e9507372f0b1b963James Dong            Get availability, reference index and motion vector of a neighbour
9590c1bc742181ded4930842b46e9507372f0b1b963James Dong
9600c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
9610c1bc742181ded4930842b46e9507372f0b1b963James Dong
9620c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid GetInterNeighbour(u32 sliceId, mbStorage_t *nMb,
9630c1bc742181ded4930842b46e9507372f0b1b963James Dong    interNeighbour_t *n, u32 index)
9640c1bc742181ded4930842b46e9507372f0b1b963James Dong{
9650c1bc742181ded4930842b46e9507372f0b1b963James Dong
9660c1bc742181ded4930842b46e9507372f0b1b963James Dong    n->available = HANTRO_FALSE;
9670c1bc742181ded4930842b46e9507372f0b1b963James Dong    n->refIndex = 0xFFFFFFFF;
9680c1bc742181ded4930842b46e9507372f0b1b963James Dong    n->mv.hor = n->mv.ver = 0;
9690c1bc742181ded4930842b46e9507372f0b1b963James Dong
9700c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (nMb && (sliceId == nMb->sliceId))
9710c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9720c1bc742181ded4930842b46e9507372f0b1b963James Dong        u32 tmp;
9730c1bc742181ded4930842b46e9507372f0b1b963James Dong        mv_t tmpMv;
9740c1bc742181ded4930842b46e9507372f0b1b963James Dong
9750c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = nMb->mbType;
9760c1bc742181ded4930842b46e9507372f0b1b963James Dong        n->available = HANTRO_TRUE;
9770c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* MbPartPredMode "inlined" */
9780c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp <= P_8x8ref0)
9790c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
9800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmpMv = nMb->mv[index];
9810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp = nMb->refPic[index>>2];
9820c1bc742181ded4930842b46e9507372f0b1b963James Dong            n->refIndex = tmp;
9830c1bc742181ded4930842b46e9507372f0b1b963James Dong            n->mv = tmpMv;
9840c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
9850c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9860c1bc742181ded4930842b46e9507372f0b1b963James Dong
9870c1bc742181ded4930842b46e9507372f0b1b963James Dong}
9880c1bc742181ded4930842b46e9507372f0b1b963James Dong
9890c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
9900c1bc742181ded4930842b46e9507372f0b1b963James Dong
9910c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: GetPredictionMv
9920c1bc742181ded4930842b46e9507372f0b1b963James Dong
9930c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
9940c1bc742181ded4930842b46e9507372f0b1b963James Dong            Compute motion vector predictor based on neighbours A, B and C
9950c1bc742181ded4930842b46e9507372f0b1b963James Dong
9960c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
9970c1bc742181ded4930842b46e9507372f0b1b963James Dong
9980c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid GetPredictionMv(mv_t *mv, interNeighbour_t *a, u32 refIndex)
9990c1bc742181ded4930842b46e9507372f0b1b963James Dong{
10000c1bc742181ded4930842b46e9507372f0b1b963James Dong
10010c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ( a[1].available || a[2].available || !a[0].available)
10020c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10030c1bc742181ded4930842b46e9507372f0b1b963James Dong        u32 isA, isB, isC;
10040c1bc742181ded4930842b46e9507372f0b1b963James Dong        isA = (a[0].refIndex == refIndex) ? HANTRO_TRUE : HANTRO_FALSE;
10050c1bc742181ded4930842b46e9507372f0b1b963James Dong        isB = (a[1].refIndex == refIndex) ? HANTRO_TRUE : HANTRO_FALSE;
10060c1bc742181ded4930842b46e9507372f0b1b963James Dong        isC = (a[2].refIndex == refIndex) ? HANTRO_TRUE : HANTRO_FALSE;
10070c1bc742181ded4930842b46e9507372f0b1b963James Dong
10080c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (((u32)isA+(u32)isB+(u32)isC) != 1)
10090c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
10100c1bc742181ded4930842b46e9507372f0b1b963James Dong            mv->hor = (i16)MedianFilter(a[0].mv.hor, a[1].mv.hor, a[2].mv.hor);
10110c1bc742181ded4930842b46e9507372f0b1b963James Dong            mv->ver = (i16)MedianFilter(a[0].mv.ver, a[1].mv.ver, a[2].mv.ver);
10120c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
10130c1bc742181ded4930842b46e9507372f0b1b963James Dong        else if (isA)
10140c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mv = a[0].mv;
10150c1bc742181ded4930842b46e9507372f0b1b963James Dong        else if (isB)
10160c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mv = a[1].mv;
10170c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
10180c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mv = a[2].mv;
10190c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10200c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
10210c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10220c1bc742181ded4930842b46e9507372f0b1b963James Dong        *mv = a[0].mv;
10230c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10240c1bc742181ded4930842b46e9507372f0b1b963James Dong
10250c1bc742181ded4930842b46e9507372f0b1b963James Dong}
10260c1bc742181ded4930842b46e9507372f0b1b963James Dong
10270c1bc742181ded4930842b46e9507372f0b1b963James Dong
1028