Showing the changes to codec/decoder (82 of 308 files). Show all
Unified · Split
| @@ -0,0 +1,235 @@ | ||
| 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 | +;* sse2inc.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* macro and constant | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 8/5/2009 Created | |
| 39 | +;* | |
| 40 | +;* | |
| 41 | +;*************************************************************************/ | |
| 42 | +;*********************************************************************** | |
| 43 | +; Options, for DEBUG | |
| 44 | +;*********************************************************************** | |
| 45 | + | |
| 46 | +%if 1 | |
| 47 | + %define MOVDQ movdqa | |
| 48 | +%else | |
| 49 | + %define MOVDQ movdqu | |
| 50 | +%endif | |
| 51 | + | |
| 52 | +%if 1 | |
| 53 | + %define WELSEMMS emms | |
| 54 | +%else | |
| 55 | + %define WELSEMMS | |
| 56 | +%endif | |
| 57 | + | |
| 58 | +BITS 32 | |
| 59 | + | |
| 60 | +;*********************************************************************** | |
| 61 | +; Macros | |
| 62 | +;*********************************************************************** | |
| 63 | + | |
| 64 | +%macro WELS_EXTERN 1 | |
| 65 | + %ifdef PREFIX | |
| 66 | + global _%1 | |
| 67 | + %define %1 _%1 | |
| 68 | + %else | |
| 69 | + global %1 | |
| 70 | + %endif | |
| 71 | +%endmacro | |
| 72 | + | |
| 73 | +%macro WELS_AbsW 2 | |
| 74 | + pxor %2, %2 | |
| 75 | + psubw %2, %1 | |
| 76 | + pmaxsw %1, %2 | |
| 77 | +%endmacro | |
| 78 | + | |
| 79 | +%macro MMX_XSwap 4 | |
| 80 | + movq %4, %2 | |
| 81 | + punpckh%1 %4, %3 | |
| 82 | + punpckl%1 %2, %3 | |
| 83 | +%endmacro | |
| 84 | + | |
| 85 | +; pOut mm1, mm4, mm5, mm3 | |
| 86 | +%macro MMX_Trans4x4W 5 | |
| 87 | + MMX_XSwap wd, %1, %2, %5 | |
| 88 | + MMX_XSwap wd, %3, %4, %2 | |
| 89 | + MMX_XSwap dq, %1, %3, %4 | |
| 90 | + MMX_XSwap dq, %5, %2, %3 | |
| 91 | +%endmacro | |
| 92 | + | |
| 93 | +;for TRANSPOSE | |
| 94 | +%macro SSE2_XSawp 4 | |
| 95 | + movdqa %4, %2 | |
| 96 | + punpckl%1 %2, %3 | |
| 97 | + punpckh%1 %4, %3 | |
| 98 | +%endmacro | |
| 99 | + | |
| 100 | +; in: xmm1, xmm2, xmm3, xmm4 pOut: xmm1, xmm4, xmm5, mm3 | |
| 101 | +%macro SSE2_Trans4x4D 5 | |
| 102 | + SSE2_XSawp dq, %1, %2, %5 | |
| 103 | + SSE2_XSawp dq, %3, %4, %2 | |
| 104 | + SSE2_XSawp qdq, %1, %3, %4 | |
| 105 | + SSE2_XSawp qdq, %5, %2, %3 | |
| 106 | +%endmacro | |
| 107 | + | |
| 108 | +;in: xmm0, xmm1, xmm2, xmm3 pOut: xmm0, xmm1, xmm3, xmm4 | |
| 109 | +%macro SSE2_TransTwo4x4W 5 | |
| 110 | + SSE2_XSawp wd, %1, %2, %5 | |
| 111 | + SSE2_XSawp wd, %3, %4, %2 | |
| 112 | + SSE2_XSawp dq, %1, %3, %4 | |
| 113 | + SSE2_XSawp dq, %5, %2, %3 | |
| 114 | + SSE2_XSawp qdq, %1, %5, %2 | |
| 115 | + SSE2_XSawp qdq, %4, %3, %5 | |
| 116 | +%endmacro | |
| 117 | + | |
| 118 | +;in: m1, m2, m3, m4, m5, m6, m7, m8 | |
| 119 | +;pOut: m5, m3, m4, m8, m6, m2, m7, m1 | |
| 120 | +%macro SSE2_TransTwo8x8B 9 | |
| 121 | + movdqa %9, %8 | |
| 122 | + SSE2_XSawp bw, %1, %2, %8 | |
| 123 | + SSE2_XSawp bw, %3, %4, %2 | |
| 124 | + SSE2_XSawp bw, %5, %6, %4 | |
| 125 | + movdqa %6, %9 | |
| 126 | + movdqa %9, %4 | |
| 127 | + SSE2_XSawp bw, %7, %6, %4 | |
| 128 | + | |
| 129 | + SSE2_XSawp wd, %1, %3, %6 | |
| 130 | + SSE2_XSawp wd, %8, %2, %3 | |
| 131 | + SSE2_XSawp wd, %5, %7, %2 | |
| 132 | + movdqa %7, %9 | |
| 133 | + movdqa %9, %3 | |
| 134 | + SSE2_XSawp wd, %7, %4, %3 | |
| 135 | + | |
| 136 | + SSE2_XSawp dq, %1, %5, %4 | |
| 137 | + SSE2_XSawp dq, %6, %2, %5 | |
| 138 | + SSE2_XSawp dq, %8, %7, %2 | |
| 139 | + movdqa %7, %9 | |
| 140 | + movdqa %9, %5 | |
| 141 | + SSE2_XSawp dq, %7, %3, %5 | |
| 142 | + | |
| 143 | + SSE2_XSawp qdq, %1, %8, %3 | |
| 144 | + SSE2_XSawp qdq, %4, %2, %8 | |
| 145 | + SSE2_XSawp qdq, %6, %7, %2 | |
| 146 | + movdqa %7, %9 | |
| 147 | + movdqa %9, %1 | |
| 148 | + SSE2_XSawp qdq, %7, %5, %1 | |
| 149 | + movdqa %5, %9 | |
| 150 | +%endmacro | |
| 151 | + | |
| 152 | +;xmm0, xmm6, xmm7, [eax], [ecx] | |
| 153 | +;xmm7 = 0, eax = pix1, ecx = pix2, xmm0 save the result | |
| 154 | +%macro SSE2_LoadDiff8P 5 | |
| 155 | + movq %1, %4 | |
| 156 | + punpcklbw %1, %3 | |
| 157 | + movq %2, %5 | |
| 158 | + punpcklbw %2, %3 | |
| 159 | + psubw %1, %2 | |
| 160 | +%endmacro | |
| 161 | + | |
| 162 | +; m2 = m1 + m2, m1 = m1 - m2 | |
| 163 | +%macro SSE2_SumSub 3 | |
| 164 | + movdqa %3, %2 | |
| 165 | + paddw %2, %1 | |
| 166 | + psubw %1, %3 | |
| 167 | +%endmacro | |
| 168 | + | |
| 169 | + | |
| 170 | +%macro butterfly_1to16_sse 3 ; xmm? for dst, xmm? for tmp, one byte for pSrc [generic register name: a/b/c/d] | |
| 171 | + mov %3h, %3l | |
| 172 | + movd %1, e%3x ; i.e, 1% = eax (=b0) | |
| 173 | + pshuflw %2, %1, 00h ; ..., b0 b0 b0 b0 b0 b0 b0 b0 | |
| 174 | + pshufd %1, %2, 00h ; b0 b0 b0 b0, b0 b0 b0 b0, b0 b0 b0 b0, b0 b0 b0 b0 | |
| 175 | +%endmacro | |
| 176 | + | |
| 177 | +;copy a dw into a xmm for 8 times | |
| 178 | +%macro SSE2_Copy8Times 2 | |
| 179 | + movd %1, %2 | |
| 180 | + punpcklwd %1, %1 | |
| 181 | + pshufd %1, %1, 0 | |
| 182 | +%endmacro | |
| 183 | + | |
| 184 | +;copy a db into a xmm for 16 times | |
| 185 | +%macro SSE2_Copy16Times 2 | |
| 186 | + movd %1, %2 | |
| 187 | + pshuflw %1, %1, 0 | |
| 188 | + punpcklqdq %1, %1 | |
| 189 | + packuswb %1, %1 | |
| 190 | +%endmacro | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | +;*********************************************************************** | |
| 195 | +;preprocessor constants | |
| 196 | +;*********************************************************************** | |
| 197 | +;dw 32,32,32,32,32,32,32,32 for xmm | |
| 198 | +;dw 32,32,32,32 for mm | |
| 199 | +%macro WELS_DW32 1 | |
| 200 | + pcmpeqw %1,%1 | |
| 201 | + psrlw %1,15 | |
| 202 | + psllw %1,5 | |
| 203 | +%endmacro | |
| 204 | + | |
| 205 | +;dw 1, 1, 1, 1, 1, 1, 1, 1 for xmm | |
| 206 | +;dw 1, 1, 1, 1 for mm | |
| 207 | +%macro WELS_DW1 1 | |
| 208 | + pcmpeqw %1,%1 | |
| 209 | + psrlw %1,15 | |
| 210 | +%endmacro | |
| 211 | + | |
| 212 | +;all 0 for xmm and mm | |
| 213 | +%macro WELS_Zero 1 | |
| 214 | + pxor %1, %1 | |
| 215 | +%endmacro | |
| 216 | + | |
| 217 | +;dd 1, 1, 1, 1 for xmm | |
| 218 | +;dd 1, 1 for mm | |
| 219 | +%macro WELS_DD1 1 | |
| 220 | + pcmpeqw %1,%1 | |
| 221 | + psrld %1,31 | |
| 222 | +%endmacro | |
| 223 | + | |
| 224 | +;dB 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 | |
| 225 | +%macro WELS_DB1 1 | |
| 226 | + pcmpeqw %1,%1 | |
| 227 | + psrlw %1,15 | |
| 228 | + packuswb %1,%1 | |
| 229 | +%endmacro | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| @@ -0,0 +1,413 @@ | ||
| 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 | +;* block_add.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* add block | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 09/21/2009 Created | |
| 39 | +;* | |
| 40 | +;* | |
| 41 | +;*************************************************************************/ | |
| 42 | + | |
| 43 | +%include "asm_inc.asm" | |
| 44 | + | |
| 45 | +BITS 32 | |
| 46 | + | |
| 47 | +;******************************************************************************* | |
| 48 | +; Macros and other preprocessor constants | |
| 49 | +;******************************************************************************* | |
| 50 | + | |
| 51 | +%macro BLOCK_ADD_16_SSE2 4 | |
| 52 | + movdqa xmm0, [%2] | |
| 53 | + movdqa xmm1, [%3] | |
| 54 | + movdqa xmm2, [%3+10h] | |
| 55 | + movdqa xmm6, xmm0 | |
| 56 | + | |
| 57 | + punpcklbw xmm0, xmm7 | |
| 58 | + punpckhbw xmm6, xmm7 | |
| 59 | + | |
| 60 | + paddw xmm0, xmm1 | |
| 61 | + paddw xmm6, xmm2 | |
| 62 | + | |
| 63 | + packuswb xmm0, xmm6 | |
| 64 | + movdqa [%1], xmm0 | |
| 65 | + | |
| 66 | + lea %2, [%2+%4] | |
| 67 | + lea %3, [%3+%4*2] | |
| 68 | + lea %1, [%1+%4] | |
| 69 | +%endmacro | |
| 70 | + | |
| 71 | +%macro BLOCK_ADD_8_MMXEXT 4 | |
| 72 | + movq mm0, [%2] | |
| 73 | + movq mm1, [%3] | |
| 74 | + movq mm2, [%3+08h] | |
| 75 | + movq mm6, mm0 | |
| 76 | + | |
| 77 | + punpcklbw mm0, mm7 | |
| 78 | + punpckhbw mm6, mm7 | |
| 79 | + | |
| 80 | + paddw mm0, mm1 | |
| 81 | + paddw mm6, mm2 | |
| 82 | + | |
| 83 | + packuswb mm0, mm6 | |
| 84 | + movq [%1], mm0 | |
| 85 | + | |
| 86 | + lea %2, [%2+%4] | |
| 87 | + lea %3, [%3+%4*2] | |
| 88 | + lea %1, [%1+%4] | |
| 89 | +%endmacro | |
| 90 | + | |
| 91 | + | |
| 92 | +%macro BLOCK_ADD_16_STRIDE_SSE2 5 | |
| 93 | + movdqa xmm0, [%2] | |
| 94 | + movdqa xmm1, [%3] | |
| 95 | + movdqa xmm2, [%3+10h] | |
| 96 | + movdqa xmm6, xmm0 | |
| 97 | + | |
| 98 | + punpcklbw xmm0, xmm7 | |
| 99 | + punpckhbw xmm6, xmm7 | |
| 100 | + | |
| 101 | + paddw xmm0, xmm1 | |
| 102 | + paddw xmm6, xmm2 | |
| 103 | + | |
| 104 | + packuswb xmm0, xmm6 | |
| 105 | + movdqa [%1], xmm0 | |
| 106 | + | |
| 107 | + lea %2, [%2+%4] | |
| 108 | + lea %3, [%3+%5*2] | |
| 109 | + lea %1, [%1+%4] | |
| 110 | +%endmacro | |
| 111 | + | |
| 112 | + | |
| 113 | +%macro BLOCK_ADD_8_STRIDE_MMXEXT 5 | |
| 114 | + movq mm0, [%2] | |
| 115 | + movq mm1, [%3] | |
| 116 | + movq mm2, [%3+08h] | |
| 117 | + movq mm6, mm0 | |
| 118 | + | |
| 119 | + punpcklbw mm0, mm7 | |
| 120 | + punpckhbw mm6, mm7 | |
| 121 | + | |
| 122 | + paddw mm0, mm1 | |
| 123 | + paddw mm6, mm2 | |
| 124 | + | |
| 125 | + packuswb mm0, mm6 | |
| 126 | + movq [%1], mm0 | |
| 127 | + | |
| 128 | + lea %2, [%2+%4] | |
| 129 | + lea %3, [%3+%5*2] | |
| 130 | + lea %1, [%1+%4] | |
| 131 | +%endmacro | |
| 132 | + | |
| 133 | +%macro BLOCK_ADD_8_STRIDE_2_LINES_SSE2 5 | |
| 134 | + movdqa xmm1, [%3] | |
| 135 | + movq xmm0, [%2] | |
| 136 | + punpcklbw xmm0, xmm7 | |
| 137 | + paddw xmm0, xmm1 | |
| 138 | + packuswb xmm0, xmm7 | |
| 139 | + movq [%1], xmm0 | |
| 140 | + | |
| 141 | + movdqa xmm3, [%3+%5*2] | |
| 142 | + movq xmm2, [%2+%4] | |
| 143 | + punpcklbw xmm2, xmm7 | |
| 144 | + paddw xmm2, xmm3 | |
| 145 | + packuswb xmm2, xmm7 | |
| 146 | + movq [%1+%4], xmm2 | |
| 147 | + | |
| 148 | + lea %1, [%1+%4*2] | |
| 149 | + lea %2, [%2+%4*2] | |
| 150 | + lea %3, [%3+%5*4] | |
| 151 | +%endmacro | |
| 152 | + | |
| 153 | +%macro CHECK_DATA_16_ZERO_SSE4 3 | |
| 154 | + mov eax, 0h | |
| 155 | + movdqa xmm0, [%1] | |
| 156 | + movdqa xmm1, [%1+10h] | |
| 157 | + mov ebx, [ecx] | |
| 158 | + | |
| 159 | + por xmm0, xmm1 | |
| 160 | + ptest xmm7, xmm0 | |
| 161 | + cmovae eax, %3 | |
| 162 | + | |
| 163 | + add %1, 20h | |
| 164 | + add ecx, 04h | |
| 165 | + mov byte [%2+ebx], al | |
| 166 | +%endmacro | |
| 167 | + | |
| 168 | +%macro CHECK_RS_4x4_BLOCK_2_ZERO_SSE4 5 | |
| 169 | + movdqa xmm0, [%1] | |
| 170 | + movdqa xmm1, [%1+%3] | |
| 171 | + movdqa xmm2, [%1+%3*2] | |
| 172 | + movdqa xmm3, [%1+%4] | |
| 173 | + | |
| 174 | + mov eax, 0h | |
| 175 | + mov ebx, 0h | |
| 176 | + movdqa xmm4, xmm0 | |
| 177 | + movdqa xmm5, xmm2 | |
| 178 | + | |
| 179 | + punpcklqdq xmm0, xmm1 | |
| 180 | + punpckhqdq xmm4, xmm1 | |
| 181 | + punpcklqdq xmm2, xmm3 | |
| 182 | + punpckhqdq xmm5, xmm3 | |
| 183 | + | |
| 184 | + por xmm0, xmm2 | |
| 185 | + por xmm4, xmm5 | |
| 186 | + | |
| 187 | + ptest xmm7, xmm0 | |
| 188 | + cmovae eax, %5 | |
| 189 | + ptest xmm7, xmm4 | |
| 190 | + cmovae ebx, %5 | |
| 191 | + | |
| 192 | + mov byte [%2], al | |
| 193 | + mov byte [%2+1], bl | |
| 194 | +%endmacro | |
| 195 | + | |
| 196 | +%macro DATA_COPY_16x2_SSE2 3 | |
| 197 | + movdqa xmm0, [%1] | |
| 198 | + movdqa xmm1, [%1+10h] | |
| 199 | + movdqa xmm2, [%1+%3] | |
| 200 | + movdqa xmm3, [%1+%3+10h] | |
| 201 | + | |
| 202 | + movdqa [%2], xmm0 | |
| 203 | + movdqa [%2+10h], xmm1 | |
| 204 | + movdqa [%2+20h], xmm2 | |
| 205 | + movdqa [%2+30h], xmm3 | |
| 206 | + | |
| 207 | + lea %1, [%1+%3*2] | |
| 208 | + lea %2, [%2+40h] | |
| 209 | +%endmacro | |
| 210 | + | |
| 211 | + | |
| 212 | +%macro DATA_COPY_8x4_SSE2 4 | |
| 213 | + movdqa xmm0, [%1] | |
| 214 | + movdqa xmm1, [%1+%3] | |
| 215 | + movdqa xmm2, [%1+%3*2] | |
| 216 | + movdqa xmm3, [%1+%4] | |
| 217 | + | |
| 218 | + movdqa [%2], xmm0 | |
| 219 | + movdqa [%2+10h], xmm1 | |
| 220 | + movdqa [%2+20h], xmm2 | |
| 221 | + movdqa [%2+30h], xmm3 | |
| 222 | + | |
| 223 | + lea %1, [%1+%3*4] | |
| 224 | + lea %2, [%2+40h] | |
| 225 | +%endmacro | |
| 226 | + | |
| 227 | + | |
| 228 | +%macro CHECK_DATA_16_ZERO_SSE2 3 | |
| 229 | + mov eax, 0h | |
| 230 | + movdqa xmm0, [%1] | |
| 231 | + movdqa xmm1, [%1+10h] | |
| 232 | + mov ebx, [ecx] | |
| 233 | + | |
| 234 | + pcmpeqw xmm0, xmm7 | |
| 235 | + pcmpeqw xmm1, xmm7 | |
| 236 | + packsswb xmm0, xmm1 | |
| 237 | + pmovmskb edx, xmm0 | |
| 238 | + sub edx, 0ffffh | |
| 239 | + | |
| 240 | + cmovb eax, ebp | |
| 241 | + add ecx, 4 | |
| 242 | + add %1, 20h | |
| 243 | + mov byte [%2+ebx], al | |
| 244 | +%endmacro | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | +%macro CHECK_RS_4x4_BLOCK_2_ZERO_SSE2 5 | |
| 249 | + movdqa xmm0, [%1] | |
| 250 | + movdqa xmm1, [%1 + %3] | |
| 251 | + movdqa xmm2, [%1 + %3*2] | |
| 252 | + movdqa xmm3, [%1 + %4] | |
| 253 | + | |
| 254 | + movdqa xmm4, xmm0 | |
| 255 | + movdqa xmm5, xmm2 | |
| 256 | + | |
| 257 | + punpcklqdq xmm0, xmm1 | |
| 258 | + punpckhqdq xmm4, xmm1 | |
| 259 | + punpcklqdq xmm2, xmm3 | |
| 260 | + punpckhqdq xmm5, xmm3 | |
| 261 | + | |
| 262 | + pcmpeqw xmm0, xmm7 | |
| 263 | + pcmpeqw xmm2, xmm7 | |
| 264 | + pcmpeqw xmm4, xmm7 | |
| 265 | + pcmpeqw xmm5, xmm7 | |
| 266 | + | |
| 267 | + packsswb xmm0, xmm2 | |
| 268 | + packsswb xmm4, xmm5 | |
| 269 | + pmovmskb eax, xmm0 | |
| 270 | + pmovmskb ebx, xmm4 | |
| 271 | + | |
| 272 | + sub eax, 0ffffh | |
| 273 | + mov eax, 0 | |
| 274 | + cmovb eax, %5 | |
| 275 | + sub ebx, 0ffffh | |
| 276 | + mov ebx, 0 | |
| 277 | + cmovb ebx, %5 | |
| 278 | + mov byte [%2], al | |
| 279 | + mov byte [%2+1], bl | |
| 280 | +%endmacro | |
| 281 | + | |
| 282 | +;******************************************************************************* | |
| 283 | +; Data | |
| 284 | +;******************************************************************************* | |
| 285 | + | |
| 286 | +%ifdef FORMAT_COFF | |
| 287 | +SECTION .rodata data | |
| 288 | +%else | |
| 289 | +SECTION .rodata align=16 | |
| 290 | +%endif | |
| 291 | + | |
| 292 | +ALIGN 16 | |
| 293 | +SubMbScanIdx: | |
| 294 | + dd 0x0, 0x1, 0x4, 0x5, | |
| 295 | + dd 0x2, 0x3, 0x6, 0x7, | |
| 296 | + dd 0x8, 0x9, 0xc, 0xd, | |
| 297 | + dd 0xa, 0xb, 0xe, 0xf, | |
| 298 | + dd 0x10, 0x11, 0x14, 0x15, | |
| 299 | + dd 0x12, 0x13, 0x16, 0x17, | |
| 300 | + | |
| 301 | +;******************************************************************************* | |
| 302 | +; Code | |
| 303 | +;******************************************************************************* | |
| 304 | + | |
| 305 | +SECTION .text | |
| 306 | + | |
| 307 | + | |
| 308 | +WELS_EXTERN WelsResBlockZero16x16_sse2 | |
| 309 | + | |
| 310 | +ALIGN 16 | |
| 311 | +;******************************************************************************* | |
| 312 | +; void_t WelsResBlockZero16x16_sse2(int16_t* pBlock,int32_t iStride) | |
| 313 | +;******************************************************************************* | |
| 314 | +WelsResBlockZero16x16_sse2: | |
| 315 | + push esi | |
| 316 | + | |
| 317 | + mov esi, [esp+08h] | |
| 318 | + mov ecx, [esp+0ch] | |
| 319 | + lea ecx, [ecx*2] | |
| 320 | + lea eax, [ecx*3] | |
| 321 | + | |
| 322 | + pxor xmm7, xmm7 | |
| 323 | + | |
| 324 | + ; four lines | |
| 325 | + movdqa [esi], xmm7 | |
| 326 | + movdqa [esi+10h], xmm7 | |
| 327 | + | |
| 328 | + movdqa [esi+ecx], xmm7 | |
| 329 | + movdqa [esi+ecx+10h], xmm7 | |
| 330 | + | |
| 331 | + movdqa [esi+ecx*2], xmm7 | |
| 332 | + movdqa [esi+ecx*2+10h], xmm7 | |
| 333 | + | |
| 334 | + movdqa [esi+eax], xmm7 | |
| 335 | + movdqa [esi+eax+10h], xmm7 | |
| 336 | + | |
| 337 | + ; four lines | |
| 338 | + lea esi, [esi+ecx*4] | |
| 339 | + movdqa [esi], xmm7 | |
| 340 | + movdqa [esi+10h], xmm7 | |
| 341 | + | |
| 342 | + movdqa [esi+ecx], xmm7 | |
| 343 | + movdqa [esi+ecx+10h], xmm7 | |
| 344 | + | |
| 345 | + movdqa [esi+ecx*2], xmm7 | |
| 346 | + movdqa [esi+ecx*2+10h], xmm7 | |
| 347 | + | |
| 348 | + movdqa [esi+eax], xmm7 | |
| 349 | + movdqa [esi+eax+10h], xmm7 | |
| 350 | + | |
| 351 | + ; four lines | |
| 352 | + lea esi, [esi+ecx*4] | |
| 353 | + movdqa [esi], xmm7 | |
| 354 | + movdqa [esi+10h], xmm7 | |
| 355 | + | |
| 356 | + movdqa [esi+ecx], xmm7 | |
| 357 | + movdqa [esi+ecx+10h], xmm7 | |
| 358 | + | |
| 359 | + movdqa [esi+ecx*2], xmm7 | |
| 360 | + movdqa [esi+ecx*2+10h], xmm7 | |
| 361 | + | |
| 362 | + movdqa [esi+eax], xmm7 | |
| 363 | + movdqa [esi+eax+10h], xmm7 | |
| 364 | + | |
| 365 | + ; four lines | |
| 366 | + lea esi, [esi+ecx*4] | |
| 367 | + movdqa [esi], xmm7 | |
| 368 | + movdqa [esi+10h], xmm7 | |
| 369 | + | |
| 370 | + movdqa [esi+ecx], xmm7 | |
| 371 | + movdqa [esi+ecx+10h], xmm7 | |
| 372 | + | |
| 373 | + movdqa [esi+ecx*2], xmm7 | |
| 374 | + movdqa [esi+ecx*2+10h], xmm7 | |
| 375 | + | |
| 376 | + movdqa [esi+eax], xmm7 | |
| 377 | + movdqa [esi+eax+10h], xmm7 | |
| 378 | + | |
| 379 | + pop esi | |
| 380 | + ret | |
| 381 | + | |
| 382 | + | |
| 383 | +WELS_EXTERN WelsResBlockZero8x8_sse2 | |
| 384 | + | |
| 385 | +ALIGN 16 | |
| 386 | +;******************************************************************************* | |
| 387 | +; void_t WelsResBlockZero8x8_sse2(int16_t * pBlock, int32_t iStride) | |
| 388 | +;******************************************************************************* | |
| 389 | +WelsResBlockZero8x8_sse2: | |
| 390 | + push esi | |
| 391 | + | |
| 392 | + mov esi, [esp+08h] | |
| 393 | + mov ecx, [esp+0ch] | |
| 394 | + lea ecx, [ecx*2] | |
| 395 | + lea eax, [ecx*3] | |
| 396 | + | |
| 397 | + pxor xmm7, xmm7 | |
| 398 | + | |
| 399 | + movdqa [esi], xmm7 | |
| 400 | + movdqa [esi+ecx], xmm7 | |
| 401 | + movdqa [esi+ecx*2], xmm7 | |
| 402 | + movdqa [esi+eax], xmm7 | |
| 403 | + | |
| 404 | + lea esi, [esi+ecx*4] | |
| 405 | + movdqa [esi], xmm7 | |
| 406 | + movdqa [esi+ecx], xmm7 | |
| 407 | + movdqa [esi+ecx*2], xmm7 | |
| 408 | + movdqa [esi+eax], xmm7 | |
| 409 | + | |
| 410 | + | |
| 411 | + pop esi | |
| 412 | + ret | |
| 413 | + | |
| @@ -0,0 +1,169 @@ | ||
| 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 | +;* cpu_mmx.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* verify cpuid feature support and cpuid detection | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 04/29/2009 Created | |
| 39 | +;* | |
| 40 | +;*************************************************************************/ | |
| 41 | + | |
| 42 | +bits 32 | |
| 43 | + | |
| 44 | +;****************************************************************************************** | |
| 45 | +; Macros | |
| 46 | +;****************************************************************************************** | |
| 47 | + | |
| 48 | +%macro WELS_EXTERN 1 | |
| 49 | + %ifdef PREFIX | |
| 50 | + global _%1 | |
| 51 | + %define %1 _%1 | |
| 52 | + %else | |
| 53 | + global %1 | |
| 54 | + %endif | |
| 55 | +%endmacro | |
| 56 | + | |
| 57 | +;****************************************************************************************** | |
| 58 | +; Code | |
| 59 | +;****************************************************************************************** | |
| 60 | + | |
| 61 | +SECTION .text | |
| 62 | + | |
| 63 | +; refer to "The IA-32 Intel(R) Architecture Software Developers Manual, Volume 2A A-M" | |
| 64 | +; section CPUID - CPU Identification | |
| 65 | + | |
| 66 | +WELS_EXTERN WelsCPUIdVerify | |
| 67 | +ALIGN 16 | |
| 68 | +;****************************************************************************************** | |
| 69 | +; int32_t WelsCPUIdVerify() | |
| 70 | +;****************************************************************************************** | |
| 71 | +WelsCPUIdVerify: | |
| 72 | + pushfd ; decrease the SP by 4 and load EFLAGS register onto stack, pushfd 32 bit and pushf for 16 bit | |
| 73 | + pushfd ; need push 2 EFLAGS, one for processing and the another one for storing purpose | |
| 74 | + pop ecx ; get EFLAGS to bit manipulation | |
| 75 | + mov eax, ecx ; store into ecx followed | |
| 76 | + xor eax, 00200000h ; get ID flag (bit 21) of EFLAGS to directly indicate cpuid support or not | |
| 77 | + xor eax, ecx ; get the ID flag bitwise, eax - 0: not support; otherwise: support | |
| 78 | + popfd ; store back EFLAGS and keep unchanged for system | |
| 79 | + ret | |
| 80 | + | |
| 81 | +WELS_EXTERN WelsCPUId | |
| 82 | +ALIGN 16 | |
| 83 | +;**************************************************************************************************** | |
| 84 | +; void WelsCPUId( int32_t index, int32_t *uiFeatureA, int32_t *uiFeatureB, int32_t *uiFeatureC, int32_t *uiFeatureD ) | |
| 85 | +;**************************************************************************************************** | |
| 86 | +WelsCPUId: | |
| 87 | + push ebx | |
| 88 | + push edi | |
| 89 | + | |
| 90 | + mov eax, [esp+12] ; operating index | |
| 91 | + cpuid ; cpuid | |
| 92 | + | |
| 93 | + ; processing various information return | |
| 94 | + mov edi, [esp+16] | |
| 95 | + mov [edi], eax | |
| 96 | + mov edi, [esp+20] | |
| 97 | + mov [edi], ebx | |
| 98 | + mov edi, [esp+24] | |
| 99 | + mov [edi], ecx | |
| 100 | + mov edi, [esp+28] | |
| 101 | + mov [edi], edx | |
| 102 | + | |
| 103 | + pop edi | |
| 104 | + pop ebx | |
| 105 | + ret | |
| 106 | + | |
| 107 | +WELS_EXTERN WelsCPUSupportAVX | |
| 108 | +; need call after cpuid=1 and eax, ecx flag got then | |
| 109 | +ALIGN 16 | |
| 110 | +;**************************************************************************************************** | |
| 111 | +; int32_t WelsCPUSupportAVX( uint32_t eax, uint32_t ecx ) | |
| 112 | +;**************************************************************************************************** | |
| 113 | +WelsCPUSupportAVX: | |
| 114 | + mov eax, [esp+4] | |
| 115 | + mov ecx, [esp+8] | |
| 116 | + | |
| 117 | + ; refer to detection of AVX addressed in INTEL AVX manual document | |
| 118 | + and ecx, 018000000H | |
| 119 | + cmp ecx, 018000000H ; check both OSXSAVE and AVX feature flags | |
| 120 | + jne avx_not_supported | |
| 121 | + ; processor supports AVX instructions and XGETBV is enabled by OS | |
| 122 | + mov ecx, 0 ; specify 0 for XFEATURE_ENABLED_MASK register | |
| 123 | + XGETBV ; result in EDX:EAX | |
| 124 | + and eax, 06H | |
| 125 | + cmp eax, 06H ; check OS has enabled both XMM and YMM state support | |
| 126 | + jne avx_not_supported | |
| 127 | + mov eax, 1 | |
| 128 | + ret | |
| 129 | +avx_not_supported: | |
| 130 | + mov eax, 0 | |
| 131 | + ret | |
| 132 | + | |
| 133 | +WELS_EXTERN WelsCPUSupportFMA | |
| 134 | +; need call after cpuid=1 and eax, ecx flag got then | |
| 135 | +ALIGN 16 | |
| 136 | +;**************************************************************************************************** | |
| 137 | +; int32_t WelsCPUSupportFMA( uint32_t eax, uint32_t ecx ) | |
| 138 | +;**************************************************************************************************** | |
| 139 | +WelsCPUSupportFMA: | |
| 140 | + mov eax, [esp+4] | |
| 141 | + mov ecx, [esp+8] | |
| 142 | + | |
| 143 | + ; refer to detection of FMA addressed in INTEL AVX manual document | |
| 144 | + and ecx, 018001000H | |
| 145 | + cmp ecx, 018001000H ; check OSXSAVE, AVX, FMA feature flags | |
| 146 | + jne fma_not_supported | |
| 147 | + ; processor supports AVX,FMA instructions and XGETBV is enabled by OS | |
| 148 | + mov ecx, 0 ; specify 0 for XFEATURE_ENABLED_MASK register | |
| 149 | + XGETBV ; result in EDX:EAX | |
| 150 | + and eax, 06H | |
| 151 | + cmp eax, 06H ; check OS has enabled both XMM and YMM state support | |
| 152 | + jne fma_not_supported | |
| 153 | + mov eax, 1 | |
| 154 | + ret | |
| 155 | +fma_not_supported: | |
| 156 | + mov eax, 0 | |
| 157 | + ret | |
| 158 | + | |
| 159 | +WELS_EXTERN WelsEmms | |
| 160 | +ALIGN 16 | |
| 161 | +;****************************************************************************************** | |
| 162 | +; void WelsEmms() | |
| 163 | +;****************************************************************************************** | |
| 164 | +WelsEmms: | |
| 165 | + emms ; empty mmx technology states | |
| 166 | + ret | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| @@ -0,0 +1,129 @@ | ||
| 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 | +;* dct.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* WelsDctFourT4_sse2 | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 8/4/2009 Created | |
| 39 | +;* | |
| 40 | +;* | |
| 41 | +;*************************************************************************/ | |
| 42 | + | |
| 43 | +%include "asm_inc.asm" | |
| 44 | + | |
| 45 | +BITS 32 | |
| 46 | + | |
| 47 | +;******************************************************************************* | |
| 48 | +; Macros and other preprocessor constants | |
| 49 | +;******************************************************************************* | |
| 50 | +%macro MMX_SumSubDiv2 3 | |
| 51 | + movq %3, %2 | |
| 52 | + psraw %3, $1 | |
| 53 | + paddw %3, %1 | |
| 54 | + psraw %1, $1 | |
| 55 | + psubw %1, %2 | |
| 56 | +%endmacro | |
| 57 | + | |
| 58 | +%macro MMX_SumSub 3 | |
| 59 | + movq %3, %2 | |
| 60 | + psubw %2, %1 | |
| 61 | + paddw %1, %3 | |
| 62 | +%endmacro | |
| 63 | + | |
| 64 | +%macro MMX_IDCT 6 | |
| 65 | + MMX_SumSub %4, %5, %6 | |
| 66 | + MMX_SumSubDiv2 %3, %2, %1 | |
| 67 | + MMX_SumSub %1, %4, %6 | |
| 68 | + MMX_SumSub %3, %5, %6 | |
| 69 | +%endmacro | |
| 70 | + | |
| 71 | + | |
| 72 | +%macro MMX_StoreDiff4P 5 | |
| 73 | + movd %2, %5 | |
| 74 | + punpcklbw %2, %4 | |
| 75 | + paddw %1, %3 | |
| 76 | + psraw %1, $6 | |
| 77 | + paddsw %1, %2 | |
| 78 | + packuswb %1, %2 | |
| 79 | + movd %5, %1 | |
| 80 | +%endmacro | |
| 81 | + | |
| 82 | +;******************************************************************************* | |
| 83 | +; Code | |
| 84 | +;******************************************************************************* | |
| 85 | + | |
| 86 | +SECTION .text | |
| 87 | + | |
| 88 | +WELS_EXTERN IdctResAddPred_mmx | |
| 89 | + | |
| 90 | +ALIGN 16 | |
| 91 | +;******************************************************************************* | |
| 92 | +; void_t __cdecl IdctResAddPred_mmx( uint8_t *pPred, const int32_t kiStride, int16_t *pRs ) | |
| 93 | +;******************************************************************************* | |
| 94 | + | |
| 95 | +IdctResAddPred_mmx: | |
| 96 | + | |
| 97 | +%define pushsize 0 | |
| 98 | +%define pPred esp+pushsize+4 | |
| 99 | +%define kiStride esp+pushsize+8 | |
| 100 | +%define pRs esp+pushsize+12 | |
| 101 | + | |
| 102 | + mov eax, [pRs ] | |
| 103 | + mov edx, [pPred ] | |
| 104 | + mov ecx, [kiStride] | |
| 105 | + movq mm0, [eax+ 0] | |
| 106 | + movq mm1, [eax+ 8] | |
| 107 | + movq mm2, [eax+16] | |
| 108 | + movq mm3, [eax+24] | |
| 109 | + | |
| 110 | + MMX_Trans4x4W mm0, mm1, mm2, mm3, mm4 | |
| 111 | + MMX_IDCT mm1, mm2, mm3, mm4, mm0, mm6 | |
| 112 | + MMX_Trans4x4W mm1, mm3, mm0, mm4, mm2 | |
| 113 | + MMX_IDCT mm3, mm0, mm4, mm2, mm1, mm6 | |
| 114 | + | |
| 115 | + WELS_Zero mm7 | |
| 116 | + WELS_DW32 mm6 | |
| 117 | + | |
| 118 | + MMX_StoreDiff4P mm3, mm0, mm6, mm7, [edx] | |
| 119 | + MMX_StoreDiff4P mm4, mm0, mm6, mm7, [edx+ecx] | |
| 120 | + lea edx, [edx+2*ecx] | |
| 121 | + MMX_StoreDiff4P mm1, mm0, mm6, mm7, [edx] | |
| 122 | + MMX_StoreDiff4P mm2, mm0, mm6, mm7, [edx+ecx] | |
| 123 | + | |
| 124 | +%undef pushsize | |
| 125 | +%undef pPred | |
| 126 | +%undef kiStride | |
| 127 | +%undef pRs | |
| 128 | + emms | |
| 129 | + ret | |
| @@ -0,0 +1,2113 @@ | ||
| 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 | +;* deblock.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* edge loop | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 08/07/2009 Created | |
| 39 | +;* | |
| 40 | +;* | |
| 41 | +;*************************************************************************/ | |
| 42 | +%include "asm_inc.asm" | |
| 43 | +BITS 32 | |
| 44 | + | |
| 45 | +;******************************************************************************* | |
| 46 | +; Macros and other preprocessor constants | |
| 47 | +;******************************************************************************* | |
| 48 | + | |
| 49 | +%ifdef FORMAT_COFF | |
| 50 | +SECTION .rodata pData | |
| 51 | +%else | |
| 52 | +SECTION .rodata align=16 | |
| 53 | +%endif | |
| 54 | + | |
| 55 | +SECTION .text | |
| 56 | + | |
| 57 | +;******************************************************************************** | |
| 58 | +; void DeblockChromaEq4V_sse2(uint8_t * pPixCb, uint8_t * pPixCr, int32_t iStride, | |
| 59 | +; int32_t iAlpha, int32_t iBeta) | |
| 60 | +;******************************************************************************** | |
| 61 | +WELS_EXTERN DeblockChromaEq4V_sse2 | |
| 62 | + | |
| 63 | +ALIGN 16 | |
| 64 | +DeblockChromaEq4V_sse2: | |
| 65 | + push ebp | |
| 66 | + mov ebp,esp | |
| 67 | + and esp,0FFFFFFF0h | |
| 68 | + sub esp,68h | |
| 69 | + mov edx,[ebp+10h] ; iStride | |
| 70 | + mov eax,[ebp+8] ; pPixCb | |
| 71 | + mov ecx,[ebp+0Ch] ; pPixCr | |
| 72 | + movq xmm4,[ecx] | |
| 73 | + movq xmm5,[edx+ecx] | |
| 74 | + push esi | |
| 75 | + push edi | |
| 76 | + lea esi,[edx+edx] | |
| 77 | + mov edi,eax | |
| 78 | + sub edi,esi | |
| 79 | + movq xmm1,[edi] | |
| 80 | + mov edi,ecx | |
| 81 | + sub edi,esi | |
| 82 | + movq xmm2,[edi] | |
| 83 | + punpcklqdq xmm1,xmm2 | |
| 84 | + mov esi,eax | |
| 85 | + sub esi,edx | |
| 86 | + movq xmm2,[esi] | |
| 87 | + mov edi,ecx | |
| 88 | + sub edi,edx | |
| 89 | + movq xmm3,[edi] | |
| 90 | + punpcklqdq xmm2,xmm3 | |
| 91 | + movq xmm3,[eax] | |
| 92 | + punpcklqdq xmm3,xmm4 | |
| 93 | + movq xmm4,[edx+eax] | |
| 94 | + mov edx, [ebp + 14h] | |
| 95 | + punpcklqdq xmm4,xmm5 | |
| 96 | + movd xmm5,edx | |
| 97 | + mov edx, [ebp + 18h] | |
| 98 | + pxor xmm0,xmm0 | |
| 99 | + movdqa xmm6,xmm5 | |
| 100 | + punpcklwd xmm6,xmm5 | |
| 101 | + pshufd xmm5,xmm6,0 | |
| 102 | + movd xmm6,edx | |
| 103 | + movdqa xmm7,xmm6 | |
| 104 | + punpcklwd xmm7,xmm6 | |
| 105 | + pshufd xmm6,xmm7,0 | |
| 106 | + movdqa xmm7,xmm1 | |
| 107 | + punpckhbw xmm1,xmm0 | |
| 108 | + punpcklbw xmm7,xmm0 | |
| 109 | + movdqa [esp+40h],xmm1 | |
| 110 | + movdqa [esp+60h],xmm7 | |
| 111 | + movdqa xmm7,xmm2 | |
| 112 | + punpcklbw xmm7,xmm0 | |
| 113 | + movdqa [esp+10h],xmm7 | |
| 114 | + movdqa xmm7,xmm3 | |
| 115 | + punpcklbw xmm7,xmm0 | |
| 116 | + punpckhbw xmm3,xmm0 | |
| 117 | + movdqa [esp+50h],xmm7 | |
| 118 | + movdqa xmm7,xmm4 | |
| 119 | + punpckhbw xmm4,xmm0 | |
| 120 | + punpckhbw xmm2,xmm0 | |
| 121 | + punpcklbw xmm7,xmm0 | |
| 122 | + movdqa [esp+30h],xmm3 | |
| 123 | + movdqa xmm3,[esp+10h] | |
| 124 | + movdqa xmm1,xmm3 | |
| 125 | + psubw xmm1,[esp+50h] | |
| 126 | + pabsw xmm1,xmm1 | |
| 127 | + movdqa [esp+20h],xmm4 | |
| 128 | + movdqa xmm0,xmm5 | |
| 129 | + pcmpgtw xmm0,xmm1 | |
| 130 | + movdqa xmm1,[esp+60h] | |
| 131 | + psubw xmm1,xmm3 | |
| 132 | + pabsw xmm1,xmm1 | |
| 133 | + movdqa xmm4,xmm6 | |
| 134 | + pcmpgtw xmm4,xmm1 | |
| 135 | + pand xmm0,xmm4 | |
| 136 | + movdqa xmm1,xmm7 | |
| 137 | + psubw xmm1,[esp+50h] | |
| 138 | + pabsw xmm1,xmm1 | |
| 139 | + movdqa xmm4,xmm6 | |
| 140 | + pcmpgtw xmm4,xmm1 | |
| 141 | + movdqa xmm1,xmm2 | |
| 142 | + psubw xmm1,[esp+30h] | |
| 143 | + pabsw xmm1,xmm1 | |
| 144 | + pcmpgtw xmm5,xmm1 | |
| 145 | + movdqa xmm1,[esp+40h] | |
| 146 | + pand xmm0,xmm4 | |
| 147 | + psubw xmm1,xmm2 | |
| 148 | + pabsw xmm1,xmm1 | |
| 149 | + movdqa xmm4,xmm6 | |
| 150 | + pcmpgtw xmm4,xmm1 | |
| 151 | + movdqa xmm1,[esp+20h] | |
| 152 | + psubw xmm1,[esp+30h] | |
| 153 | + pand xmm5,xmm4 | |
| 154 | + pabsw xmm1,xmm1 | |
| 155 | + pcmpgtw xmm6,xmm1 | |
| 156 | + pand xmm5,xmm6 | |
| 157 | + mov edx,2 | |
| 158 | + movsx edx,dx | |
| 159 | + movd xmm1,edx | |
| 160 | + movdqa xmm4,xmm1 | |
| 161 | + punpcklwd xmm4,xmm1 | |
| 162 | + pshufd xmm1,xmm4,0 | |
| 163 | + movdqa xmm4,[esp+60h] | |
| 164 | + movdqa xmm6,xmm4 | |
| 165 | + paddw xmm6,xmm4 | |
| 166 | + paddw xmm6,xmm3 | |
| 167 | + paddw xmm6,xmm7 | |
| 168 | + movdqa [esp+10h],xmm1 | |
| 169 | + paddw xmm6,[esp+10h] | |
| 170 | + psraw xmm6,2 | |
| 171 | + movdqa xmm4,xmm0 | |
| 172 | + pandn xmm4,xmm3 | |
| 173 | + movdqa xmm3,[esp+40h] | |
| 174 | + movdqa xmm1,xmm0 | |
| 175 | + pand xmm1,xmm6 | |
| 176 | + por xmm1,xmm4 | |
| 177 | + movdqa xmm6,xmm3 | |
| 178 | + paddw xmm6,xmm3 | |
| 179 | + movdqa xmm3,[esp+10h] | |
| 180 | + paddw xmm6,xmm2 | |
| 181 | + paddw xmm6,[esp+20h] | |
| 182 | + paddw xmm6,xmm3 | |
| 183 | + psraw xmm6,2 | |
| 184 | + movdqa xmm4,xmm5 | |
| 185 | + pand xmm4,xmm6 | |
| 186 | + movdqa xmm6,xmm5 | |
| 187 | + pandn xmm6,xmm2 | |
| 188 | + por xmm4,xmm6 | |
| 189 | + packuswb xmm1,xmm4 | |
| 190 | + movdqa xmm4,[esp+50h] | |
| 191 | + movdqa xmm6,xmm7 | |
| 192 | + paddw xmm6,xmm7 | |
| 193 | + paddw xmm6,xmm4 | |
| 194 | + paddw xmm6,[esp+60h] | |
| 195 | + paddw xmm6,xmm3 | |
| 196 | + psraw xmm6,2 | |
| 197 | + movdqa xmm2,xmm0 | |
| 198 | + pand xmm2,xmm6 | |
| 199 | + pandn xmm0,xmm4 | |
| 200 | + por xmm2,xmm0 | |
| 201 | + movdqa xmm0,[esp+20h] | |
| 202 | + movdqa xmm6,xmm0 | |
| 203 | + paddw xmm6,xmm0 | |
| 204 | + movdqa xmm0,[esp+30h] | |
| 205 | + paddw xmm6,xmm0 | |
| 206 | + paddw xmm6,[esp+40h] | |
| 207 | + movdqa xmm4,xmm5 | |
| 208 | + paddw xmm6,xmm3 | |
| 209 | + movq [esi],xmm1 | |
| 210 | + psraw xmm6,2 | |
| 211 | + pand xmm4,xmm6 | |
| 212 | + pandn xmm5,xmm0 | |
| 213 | + por xmm4,xmm5 | |
| 214 | + packuswb xmm2,xmm4 | |
| 215 | + movq [eax],xmm2 | |
| 216 | + psrldq xmm1,8 | |
| 217 | + movq [edi],xmm1 | |
| 218 | + pop edi | |
| 219 | + psrldq xmm2,8 | |
| 220 | + movq [ecx],xmm2 | |
| 221 | + pop esi | |
| 222 | + mov esp,ebp | |
| 223 | + pop ebp | |
| 224 | + ret | |
| 225 | + | |
| 226 | +;****************************************************************************** | |
| 227 | +; void DeblockChromaLt4V_sse2(uint8_t * pPixCb, uint8_t * pPixCr, int32_t iStride, | |
| 228 | +; int32_t iAlpha, int32_t iBeta, int8_t * pTC); | |
| 229 | +;******************************************************************************* | |
| 230 | + | |
| 231 | +WELS_EXTERN DeblockChromaLt4V_sse2 | |
| 232 | + | |
| 233 | +DeblockChromaLt4V_sse2: | |
| 234 | + push ebp | |
| 235 | + mov ebp,esp | |
| 236 | + and esp,0FFFFFFF0h | |
| 237 | + sub esp,0E4h | |
| 238 | + push ebx | |
| 239 | + push esi | |
| 240 | + mov esi, [ebp+1Ch] ; pTC | |
| 241 | + movsx ebx, byte [esi+2] | |
| 242 | + push edi | |
| 243 | + movsx di,byte [esi+3] | |
| 244 | + mov word [esp+0Ch],bx | |
| 245 | + movsx bx,byte [esi+1] | |
| 246 | + movsx esi,byte [esi] | |
| 247 | + mov word [esp+0Eh],si | |
| 248 | + movzx esi,di | |
| 249 | + movd xmm1,esi | |
| 250 | + movzx esi,di | |
| 251 | + movd xmm2,esi | |
| 252 | + mov si,word [esp+0Ch] | |
| 253 | + mov edx, [ebp + 10h] | |
| 254 | + mov eax, [ebp + 08h] | |
| 255 | + movzx edi,si | |
| 256 | + movzx esi,si | |
| 257 | + mov ecx, [ebp + 0Ch] | |
| 258 | + movd xmm4,esi | |
| 259 | + movzx esi,bx | |
| 260 | + movd xmm5,esi | |
| 261 | + movd xmm3,edi | |
| 262 | + movzx esi,bx | |
| 263 | + movd xmm6,esi | |
| 264 | + mov si,word [esp+0Eh] | |
| 265 | + movzx edi,si | |
| 266 | + movzx esi,si | |
| 267 | + punpcklwd xmm6,xmm2 | |
| 268 | + pxor xmm0,xmm0 | |
| 269 | + movdqa [esp+40h],xmm0 | |
| 270 | + movd xmm7,edi | |
| 271 | + movd xmm0,esi | |
| 272 | + lea esi,[edx+edx] | |
| 273 | + mov edi,eax | |
| 274 | + sub edi,esi | |
| 275 | + punpcklwd xmm5,xmm1 | |
| 276 | + movdqa xmm1,[esp+40h] | |
| 277 | + punpcklwd xmm0,xmm4 | |
| 278 | + movq xmm4,[edx+ecx] | |
| 279 | + punpcklwd xmm7,xmm3 | |
| 280 | + movq xmm3,[eax] | |
| 281 | + punpcklwd xmm0,xmm6 | |
| 282 | + movq xmm6,[edi] | |
| 283 | + punpcklwd xmm7,xmm5 | |
| 284 | + punpcklwd xmm0,xmm7 | |
| 285 | + mov edi,ecx | |
| 286 | + sub edi,esi | |
| 287 | + movdqa xmm2,xmm1 | |
| 288 | + psubw xmm2,xmm0 | |
| 289 | + movdqa [esp+60h],xmm2 | |
| 290 | + movq xmm2, [edi] | |
| 291 | + punpcklqdq xmm6,xmm2 | |
| 292 | + mov esi,eax | |
| 293 | + sub esi,edx | |
| 294 | + movq xmm7,[esi] | |
| 295 | + mov edi,ecx | |
| 296 | + sub edi,edx | |
| 297 | + movq xmm2,[edi] | |
| 298 | + punpcklqdq xmm7,xmm2 | |
| 299 | + movq xmm2,[ecx] | |
| 300 | + punpcklqdq xmm3,xmm2 | |
| 301 | + movq xmm2,[edx+eax] | |
| 302 | + movsx edx,word [ebp + 14h] | |
| 303 | + punpcklqdq xmm2,xmm4 | |
| 304 | + movdqa [esp+0E0h],xmm2 | |
| 305 | + movd xmm2,edx | |
| 306 | + movsx edx,word [ebp + 18h] | |
| 307 | + movdqa xmm4,xmm2 | |
| 308 | + punpcklwd xmm4,xmm2 | |
| 309 | + movd xmm2,edx | |
| 310 | + movdqa xmm5,xmm2 | |
| 311 | + punpcklwd xmm5,xmm2 | |
| 312 | + pshufd xmm2,xmm5,0 | |
| 313 | + movdqa [esp+50h],xmm2 | |
| 314 | + movdqa xmm2,xmm6 | |
| 315 | + punpcklbw xmm2,xmm1 | |
| 316 | + movdqa [esp+0D0h],xmm3 | |
| 317 | + pshufd xmm4,xmm4,0 | |
| 318 | + movdqa [esp+30h],xmm2 | |
| 319 | + punpckhbw xmm6,xmm1 | |
| 320 | + movdqa [esp+80h],xmm6 | |
| 321 | + movdqa xmm6,[esp+0D0h] | |
| 322 | + punpckhbw xmm6,xmm1 | |
| 323 | + movdqa [esp+70h],xmm6 | |
| 324 | + movdqa xmm6, [esp+0E0h] | |
| 325 | + punpckhbw xmm6,xmm1 | |
| 326 | + movdqa [esp+90h],xmm6 | |
| 327 | + movdqa xmm5, [esp+0E0h] | |
| 328 | + movdqa xmm2,xmm7 | |
| 329 | + punpckhbw xmm7,xmm1 | |
| 330 | + punpcklbw xmm5,xmm1 | |
| 331 | + movdqa [esp+0A0h],xmm7 | |
| 332 | + punpcklbw xmm3,xmm1 | |
| 333 | + mov edx,4 | |
| 334 | + punpcklbw xmm2,xmm1 | |
| 335 | + movsx edx,dx | |
| 336 | + movd xmm6,edx | |
| 337 | + movdqa xmm7,xmm6 | |
| 338 | + punpcklwd xmm7,xmm6 | |
| 339 | + pshufd xmm6,xmm7,0 | |
| 340 | + movdqa xmm7,[esp+30h] | |
| 341 | + movdqa [esp+20h],xmm6 | |
| 342 | + psubw xmm7,xmm5 | |
| 343 | + movdqa xmm6,xmm0 | |
| 344 | + pcmpgtw xmm6,xmm1 | |
| 345 | + movdqa xmm1,[esp+60h] | |
| 346 | + movdqa [esp+40h],xmm6 | |
| 347 | + movdqa xmm6,xmm3 | |
| 348 | + psubw xmm6,xmm2 | |
| 349 | + psllw xmm6,2 | |
| 350 | + paddw xmm6,xmm7 | |
| 351 | + paddw xmm6, [esp+20h] | |
| 352 | + movdqa xmm7, [esp+50h] | |
| 353 | + psraw xmm6,3 | |
| 354 | + pmaxsw xmm1,xmm6 | |
| 355 | + movdqa [esp+10h],xmm0 | |
| 356 | + movdqa xmm6, [esp+10h] | |
| 357 | + pminsw xmm6,xmm1 | |
| 358 | + movdqa [esp+10h],xmm6 | |
| 359 | + movdqa xmm1,xmm2 | |
| 360 | + psubw xmm1,xmm3 | |
| 361 | + pabsw xmm1,xmm1 | |
| 362 | + movdqa xmm6,xmm4 | |
| 363 | + pcmpgtw xmm6,xmm1 | |
| 364 | + movdqa xmm1, [esp+30h] | |
| 365 | + psubw xmm1,xmm2 | |
| 366 | + pabsw xmm1,xmm1 | |
| 367 | + pcmpgtw xmm7,xmm1 | |
| 368 | + movdqa xmm1,[esp+50h] | |
| 369 | + pand xmm6,xmm7 | |
| 370 | + movdqa xmm7,[esp+50h] | |
| 371 | + psubw xmm5,xmm3 | |
| 372 | + pabsw xmm5,xmm5 | |
| 373 | + pcmpgtw xmm1,xmm5 | |
| 374 | + movdqa xmm5,[esp+80h] | |
| 375 | + psubw xmm5,[esp+90h] | |
| 376 | + pand xmm6,xmm1 | |
| 377 | + pand xmm6,[esp+40h] | |
| 378 | + movdqa xmm1,[esp+10h] | |
| 379 | + pand xmm1,xmm6 | |
| 380 | + movdqa xmm6,[esp+70h] | |
| 381 | + movdqa [esp+30h],xmm1 | |
| 382 | + movdqa xmm1,[esp+0A0h] | |
| 383 | + psubw xmm6,xmm1 | |
| 384 | + psllw xmm6,2 | |
| 385 | + paddw xmm6,xmm5 | |
| 386 | + paddw xmm6,[esp+20h] | |
| 387 | + movdqa xmm5,[esp+60h] | |
| 388 | + psraw xmm6,3 | |
| 389 | + pmaxsw xmm5,xmm6 | |
| 390 | + pminsw xmm0,xmm5 | |
| 391 | + movdqa xmm5,[esp+70h] | |
| 392 | + movdqa xmm6,xmm1 | |
| 393 | + psubw xmm6,xmm5 | |
| 394 | + pabsw xmm6,xmm6 | |
| 395 | + pcmpgtw xmm4,xmm6 | |
| 396 | + movdqa xmm6,[esp+80h] | |
| 397 | + psubw xmm6,xmm1 | |
| 398 | + pabsw xmm6,xmm6 | |
| 399 | + pcmpgtw xmm7,xmm6 | |
| 400 | + movdqa xmm6,[esp+90h] | |
| 401 | + pand xmm4,xmm7 | |
| 402 | + movdqa xmm7,[esp+50h] | |
| 403 | + psubw xmm6,xmm5 | |
| 404 | + pabsw xmm6,xmm6 | |
| 405 | + pcmpgtw xmm7,xmm6 | |
| 406 | + pand xmm4,xmm7 | |
| 407 | + pand xmm4,[esp+40h] | |
| 408 | + pand xmm0,xmm4 | |
| 409 | + movdqa xmm4,[esp+30h] | |
| 410 | + paddw xmm2,xmm4 | |
| 411 | + paddw xmm1,xmm0 | |
| 412 | + packuswb xmm2,xmm1 | |
| 413 | + movq [esi],xmm2 | |
| 414 | + psubw xmm3,xmm4 | |
| 415 | + psubw xmm5,xmm0 | |
| 416 | + packuswb xmm3,xmm5 | |
| 417 | + movq [eax],xmm3 | |
| 418 | + psrldq xmm2,8 | |
| 419 | + movq [edi],xmm2 | |
| 420 | + pop edi | |
| 421 | + pop esi | |
| 422 | + psrldq xmm3,8 | |
| 423 | + movq [ecx],xmm3 | |
| 424 | + pop ebx | |
| 425 | + mov esp,ebp | |
| 426 | + pop ebp | |
| 427 | + ret | |
| 428 | + | |
| 429 | +;*************************************************************************** | |
| 430 | +; void DeblockChromaEq4H_sse2(uint8_t * pPixCb, uint8_t * pPixCr, int32_t iStride, | |
| 431 | +; int32_t iAlpha, int32_t iBeta) | |
| 432 | +;*************************************************************************** | |
| 433 | + | |
| 434 | +WELS_EXTERN DeblockChromaEq4H_sse2 | |
| 435 | + | |
| 436 | +ALIGN 16 | |
| 437 | + | |
| 438 | +DeblockChromaEq4H_sse2: | |
| 439 | + push ebp | |
| 440 | + mov ebp,esp | |
| 441 | + and esp,0FFFFFFF0h | |
| 442 | + sub esp,0C8h | |
| 443 | + mov ecx,dword [ebp+8] | |
| 444 | + mov edx,dword [ebp+0Ch] | |
| 445 | + mov eax,dword [ebp+10h] | |
| 446 | + sub ecx,2 | |
| 447 | + sub edx,2 | |
| 448 | + push esi | |
| 449 | + lea esi,[eax+eax*2] | |
| 450 | + mov dword [esp+18h],ecx | |
| 451 | + mov dword [esp+4],edx | |
| 452 | + lea ecx,[ecx+eax*4] | |
| 453 | + lea edx,[edx+eax*4] | |
| 454 | + lea eax,[esp+7Ch] | |
| 455 | + push edi | |
| 456 | + mov dword [esp+14h],esi | |
| 457 | + mov dword [esp+18h],ecx | |
| 458 | + mov dword [esp+0Ch],edx | |
| 459 | + mov dword [esp+10h],eax | |
| 460 | + mov esi,dword [esp+1Ch] | |
| 461 | + mov ecx,dword [ebp+10h] | |
| 462 | + mov edx,dword [esp+14h] | |
| 463 | + movd xmm0,dword [esi] | |
| 464 | + movd xmm1,dword [esi+ecx] | |
| 465 | + movd xmm2,dword [esi+ecx*2] | |
| 466 | + movd xmm3,dword [esi+edx] | |
| 467 | + mov esi,dword [esp+8] | |
| 468 | + movd xmm4,dword [esi] | |
| 469 | + movd xmm5,dword [esi+ecx] | |
| 470 | + movd xmm6,dword [esi+ecx*2] | |
| 471 | + movd xmm7,dword [esi+edx] | |
| 472 | + punpckldq xmm0,xmm4 | |
| 473 | + punpckldq xmm1,xmm5 | |
| 474 | + punpckldq xmm2,xmm6 | |
| 475 | + punpckldq xmm3,xmm7 | |
| 476 | + mov esi,dword [esp+18h] | |
| 477 | + mov edi,dword [esp+0Ch] | |
| 478 | + movd xmm4,dword [esi] | |
| 479 | + movd xmm5,dword [edi] | |
| 480 | + punpckldq xmm4,xmm5 | |
| 481 | + punpcklqdq xmm0,xmm4 | |
| 482 | + movd xmm4,dword [esi+ecx] | |
| 483 | + movd xmm5,dword [edi+ecx] | |
| 484 | + punpckldq xmm4,xmm5 | |
| 485 | + punpcklqdq xmm1,xmm4 | |
| 486 | + movd xmm4,dword [esi+ecx*2] | |
| 487 | + movd xmm5,dword [edi+ecx*2] | |
| 488 | + punpckldq xmm4,xmm5 | |
| 489 | + punpcklqdq xmm2,xmm4 | |
| 490 | + movd xmm4,dword [esi+edx] | |
| 491 | + movd xmm5,dword [edi+edx] | |
| 492 | + punpckldq xmm4,xmm5 | |
| 493 | + punpcklqdq xmm3,xmm4 | |
| 494 | + movdqa xmm6,xmm0 | |
| 495 | + punpcklbw xmm0,xmm1 | |
| 496 | + punpckhbw xmm6,xmm1 | |
| 497 | + movdqa xmm7,xmm2 | |
| 498 | + punpcklbw xmm2,xmm3 | |
| 499 | + punpckhbw xmm7,xmm3 | |
| 500 | + movdqa xmm4,xmm0 | |
| 501 | + movdqa xmm5,xmm6 | |
| 502 | + punpcklwd xmm0,xmm2 | |
| 503 | + punpckhwd xmm4,xmm2 | |
| 504 | + punpcklwd xmm6,xmm7 | |
| 505 | + punpckhwd xmm5,xmm7 | |
| 506 | + movdqa xmm1,xmm0 | |
| 507 | + movdqa xmm2,xmm4 | |
| 508 | + punpckldq xmm0,xmm6 | |
| 509 | + punpckhdq xmm1,xmm6 | |
| 510 | + punpckldq xmm4,xmm5 | |
| 511 | + punpckhdq xmm2,xmm5 | |
| 512 | + movdqa xmm5,xmm0 | |
| 513 | + movdqa xmm6,xmm1 | |
| 514 | + punpcklqdq xmm0,xmm4 | |
| 515 | + punpckhqdq xmm5,xmm4 | |
| 516 | + punpcklqdq xmm1,xmm2 | |
| 517 | + punpckhqdq xmm6,xmm2 | |
| 518 | + mov edi,dword [esp+10h] | |
| 519 | + movdqa [edi],xmm0 | |
| 520 | + movdqa [edi+10h],xmm5 | |
| 521 | + movdqa [edi+20h],xmm1 | |
| 522 | + movdqa [edi+30h],xmm6 | |
| 523 | + movsx ecx,word [ebp+14h] | |
| 524 | + movsx edx,word [ebp+18h] | |
| 525 | + movdqa xmm6,[esp+80h] | |
| 526 | + movdqa xmm4,[esp+90h] | |
| 527 | + movdqa xmm5,[esp+0A0h] | |
| 528 | + movdqa xmm7,[esp+0B0h] | |
| 529 | + pxor xmm0,xmm0 | |
| 530 | + movd xmm1,ecx | |
| 531 | + movdqa xmm2,xmm1 | |
| 532 | + punpcklwd xmm2,xmm1 | |
| 533 | + pshufd xmm1,xmm2,0 | |
| 534 | + movd xmm2,edx | |
| 535 | + movdqa xmm3,xmm2 | |
| 536 | + punpcklwd xmm3,xmm2 | |
| 537 | + pshufd xmm2,xmm3,0 | |
| 538 | + movdqa xmm3,xmm6 | |
| 539 | + punpckhbw xmm6,xmm0 | |
| 540 | + movdqa [esp+60h],xmm6 | |
| 541 | + movdqa xmm6,[esp+90h] | |
| 542 | + punpckhbw xmm6,xmm0 | |
| 543 | + movdqa [esp+30h],xmm6 | |
| 544 | + movdqa xmm6,[esp+0A0h] | |
| 545 | + punpckhbw xmm6,xmm0 | |
| 546 | + movdqa [esp+40h],xmm6 | |
| 547 | + movdqa xmm6,[esp+0B0h] | |
| 548 | + punpckhbw xmm6,xmm0 | |
| 549 | + movdqa [esp+70h],xmm6 | |
| 550 | + punpcklbw xmm7,xmm0 | |
| 551 | + punpcklbw xmm4,xmm0 | |
| 552 | + punpcklbw xmm5,xmm0 | |
| 553 | + punpcklbw xmm3,xmm0 | |
| 554 | + movdqa [esp+50h],xmm7 | |
| 555 | + movdqa xmm6,xmm4 | |
| 556 | + psubw xmm6,xmm5 | |
| 557 | + pabsw xmm6,xmm6 | |
| 558 | + movdqa xmm0,xmm1 | |
| 559 | + pcmpgtw xmm0,xmm6 | |
| 560 | + movdqa xmm6,xmm3 | |
| 561 | + psubw xmm6,xmm4 | |
| 562 | + pabsw xmm6,xmm6 | |
| 563 | + movdqa xmm7,xmm2 | |
| 564 | + pcmpgtw xmm7,xmm6 | |
| 565 | + movdqa xmm6,[esp+50h] | |
| 566 | + psubw xmm6,xmm5 | |
| 567 | + pabsw xmm6,xmm6 | |
| 568 | + pand xmm0,xmm7 | |
| 569 | + movdqa xmm7,xmm2 | |
| 570 | + pcmpgtw xmm7,xmm6 | |
| 571 | + movdqa xmm6,[esp+30h] | |
| 572 | + psubw xmm6,[esp+40h] | |
| 573 | + pabsw xmm6,xmm6 | |
| 574 | + pcmpgtw xmm1,xmm6 | |
| 575 | + movdqa xmm6,[esp+60h] | |
| 576 | + psubw xmm6,[esp+30h] | |
| 577 | + pabsw xmm6,xmm6 | |
| 578 | + pand xmm0,xmm7 | |
| 579 | + movdqa xmm7,xmm2 | |
| 580 | + pcmpgtw xmm7,xmm6 | |
| 581 | + movdqa xmm6,[esp+70h] | |
| 582 | + psubw xmm6,[esp+40h] | |
| 583 | + pabsw xmm6,xmm6 | |
| 584 | + pand xmm1,xmm7 | |
| 585 | + pcmpgtw xmm2,xmm6 | |
| 586 | + pand xmm1,xmm2 | |
| 587 | + mov eax,2 | |
| 588 | + movsx ecx,ax | |
| 589 | + movd xmm2,ecx | |
| 590 | + movdqa xmm6,xmm2 | |
| 591 | + punpcklwd xmm6,xmm2 | |
| 592 | + pshufd xmm2,xmm6,0 | |
| 593 | + movdqa [esp+20h],xmm2 | |
| 594 | + movdqa xmm2,xmm3 | |
| 595 | + paddw xmm2,xmm3 | |
| 596 | + paddw xmm2,xmm4 | |
| 597 | + paddw xmm2,[esp+50h] | |
| 598 | + paddw xmm2,[esp+20h] | |
| 599 | + psraw xmm2,2 | |
| 600 | + movdqa xmm6,xmm0 | |
| 601 | + pand xmm6,xmm2 | |
| 602 | + movdqa xmm2,xmm0 | |
| 603 | + pandn xmm2,xmm4 | |
| 604 | + por xmm6,xmm2 | |
| 605 | + movdqa xmm2,[esp+60h] | |
| 606 | + movdqa xmm7,xmm2 | |
| 607 | + paddw xmm7,xmm2 | |
| 608 | + paddw xmm7,[esp+30h] | |
| 609 | + paddw xmm7,[esp+70h] | |
| 610 | + paddw xmm7,[esp+20h] | |
| 611 | + movdqa xmm4,xmm1 | |
| 612 | + movdqa xmm2,xmm1 | |
| 613 | + pandn xmm2,[esp+30h] | |
| 614 | + psraw xmm7,2 | |
| 615 | + pand xmm4,xmm7 | |
| 616 | + por xmm4,xmm2 | |
| 617 | + movdqa xmm2,[esp+50h] | |
| 618 | + packuswb xmm6,xmm4 | |
| 619 | + movdqa [esp+90h],xmm6 | |
| 620 | + movdqa xmm6,xmm2 | |
| 621 | + paddw xmm6,xmm2 | |
| 622 | + movdqa xmm2,[esp+20h] | |
| 623 | + paddw xmm6,xmm5 | |
| 624 | + paddw xmm6,xmm3 | |
| 625 | + movdqa xmm4,xmm0 | |
| 626 | + pandn xmm0,xmm5 | |
| 627 | + paddw xmm6,xmm2 | |
| 628 | + psraw xmm6,2 | |
| 629 | + pand xmm4,xmm6 | |
| 630 | + por xmm4,xmm0 | |
| 631 | + movdqa xmm0,[esp+70h] | |
| 632 | + movdqa xmm5,xmm0 | |
| 633 | + paddw xmm5,xmm0 | |
| 634 | + movdqa xmm0,[esp+40h] | |
| 635 | + paddw xmm5,xmm0 | |
| 636 | + paddw xmm5,[esp+60h] | |
| 637 | + movdqa xmm3,xmm1 | |
| 638 | + paddw xmm5,xmm2 | |
| 639 | + psraw xmm5,2 | |
| 640 | + pand xmm3,xmm5 | |
| 641 | + pandn xmm1,xmm0 | |
| 642 | + por xmm3,xmm1 | |
| 643 | + packuswb xmm4,xmm3 | |
| 644 | + movdqa [esp+0A0h],xmm4 | |
| 645 | + mov esi,dword [esp+10h] | |
| 646 | + movdqa xmm0,[esi] | |
| 647 | + movdqa xmm1,[esi+10h] | |
| 648 | + movdqa xmm2,[esi+20h] | |
| 649 | + movdqa xmm3,[esi+30h] | |
| 650 | + movdqa xmm6,xmm0 | |
| 651 | + punpcklbw xmm0,xmm1 | |
| 652 | + punpckhbw xmm6,xmm1 | |
| 653 | + movdqa xmm7,xmm2 | |
| 654 | + punpcklbw xmm2,xmm3 | |
| 655 | + punpckhbw xmm7,xmm3 | |
| 656 | + movdqa xmm4,xmm0 | |
| 657 | + movdqa xmm5,xmm6 | |
| 658 | + punpcklwd xmm0,xmm2 | |
| 659 | + punpckhwd xmm4,xmm2 | |
| 660 | + punpcklwd xmm6,xmm7 | |
| 661 | + punpckhwd xmm5,xmm7 | |
| 662 | + movdqa xmm1,xmm0 | |
| 663 | + movdqa xmm2,xmm4 | |
| 664 | + punpckldq xmm0,xmm6 | |
| 665 | + punpckhdq xmm1,xmm6 | |
| 666 | + punpckldq xmm4,xmm5 | |
| 667 | + punpckhdq xmm2,xmm5 | |
| 668 | + movdqa xmm5,xmm0 | |
| 669 | + movdqa xmm6,xmm1 | |
| 670 | + punpcklqdq xmm0,xmm4 | |
| 671 | + punpckhqdq xmm5,xmm4 | |
| 672 | + punpcklqdq xmm1,xmm2 | |
| 673 | + punpckhqdq xmm6,xmm2 | |
| 674 | + mov esi,dword [esp+1Ch] | |
| 675 | + mov ecx,dword [ebp+10h] | |
| 676 | + mov edx,dword [esp+14h] | |
| 677 | + mov edi,dword [esp+8] | |
| 678 | + movd dword [esi],xmm0 | |
| 679 | + movd dword [esi+ecx],xmm5 | |
| 680 | + movd dword [esi+ecx*2],xmm1 | |
| 681 | + movd dword [esi+edx],xmm6 | |
| 682 | + psrldq xmm0,4 | |
| 683 | + psrldq xmm5,4 | |
| 684 | + psrldq xmm1,4 | |
| 685 | + psrldq xmm6,4 | |
| 686 | + mov esi,dword [esp+18h] | |
| 687 | + movd dword [edi],xmm0 | |
| 688 | + movd dword [edi+ecx],xmm5 | |
| 689 | + movd dword [edi+ecx*2],xmm1 | |
| 690 | + movd dword [edi+edx],xmm6 | |
| 691 | + psrldq xmm0,4 | |
| 692 | + psrldq xmm5,4 | |
| 693 | + psrldq xmm1,4 | |
| 694 | + psrldq xmm6,4 | |
| 695 | + movd dword [esi],xmm0 | |
| 696 | + movd dword [esi+ecx],xmm5 | |
| 697 | + movd dword [esi+ecx*2],xmm1 | |
| 698 | + movd dword [esi+edx],xmm6 | |
| 699 | + psrldq xmm0,4 | |
| 700 | + psrldq xmm5,4 | |
| 701 | + psrldq xmm1,4 | |
| 702 | + psrldq xmm6,4 | |
| 703 | + mov edi,dword [esp+0Ch] | |
| 704 | + movd dword [edi],xmm0 | |
| 705 | + movd dword [edi+ecx],xmm5 | |
| 706 | + movd dword [edi+ecx*2],xmm1 | |
| 707 | + movd dword [edi+edx],xmm6 | |
| 708 | + pop edi | |
| 709 | + pop esi | |
| 710 | + mov esp,ebp | |
| 711 | + pop ebp | |
| 712 | + ret | |
| 713 | + | |
| 714 | +;******************************************************************************* | |
| 715 | +; void DeblockChromaLt4H_sse2(uint8_t * pPixCb, uint8_t * pPixCr, int32_t iStride, | |
| 716 | +; int32_t iAlpha, int32_t iBeta, int8_t * pTC); | |
| 717 | +;******************************************************************************* | |
| 718 | + | |
| 719 | +WELS_EXTERN DeblockChromaLt4H_sse2 | |
| 720 | + | |
| 721 | +ALIGN 16 | |
| 722 | + | |
| 723 | +DeblockChromaLt4H_sse2: | |
| 724 | + push ebp | |
| 725 | + mov ebp,esp | |
| 726 | + and esp,0FFFFFFF0h | |
| 727 | + sub esp,108h | |
| 728 | + mov ecx,dword [ebp+8] | |
| 729 | + mov edx,dword [ebp+0Ch] | |
| 730 | + mov eax,dword [ebp+10h] | |
| 731 | + sub ecx,2 | |
| 732 | + sub edx,2 | |
| 733 | + push esi | |
| 734 | + lea esi,[eax+eax*2] | |
| 735 | + mov dword [esp+10h],ecx | |
| 736 | + mov dword [esp+4],edx | |
| 737 | + lea ecx,[ecx+eax*4] | |
| 738 | + lea edx,[edx+eax*4] | |
| 739 | + lea eax,[esp+6Ch] | |
| 740 | + push edi | |
| 741 | + mov dword [esp+0Ch],esi | |
| 742 | + mov dword [esp+18h],ecx | |
| 743 | + mov dword [esp+10h],edx | |
| 744 | + mov dword [esp+1Ch],eax | |
| 745 | + mov esi,dword [esp+14h] | |
| 746 | + mov ecx,dword [ebp+10h] | |
| 747 | + mov edx,dword [esp+0Ch] | |
| 748 | + movd xmm0,dword [esi] | |
| 749 | + movd xmm1,dword [esi+ecx] | |
| 750 | + movd xmm2,dword [esi+ecx*2] | |
| 751 | + movd xmm3,dword [esi+edx] | |
| 752 | + mov esi,dword [esp+8] | |
| 753 | + movd xmm4,dword [esi] | |
| 754 | + movd xmm5,dword [esi+ecx] | |
| 755 | + movd xmm6,dword [esi+ecx*2] | |
| 756 | + movd xmm7,dword [esi+edx] | |
| 757 | + punpckldq xmm0,xmm4 | |
| 758 | + punpckldq xmm1,xmm5 | |
| 759 | + punpckldq xmm2,xmm6 | |
| 760 | + punpckldq xmm3,xmm7 | |
| 761 | + mov esi,dword [esp+18h] | |
| 762 | + mov edi,dword [esp+10h] | |
| 763 | + movd xmm4,dword [esi] | |
| 764 | + movd xmm5,dword [edi] | |
| 765 | + punpckldq xmm4,xmm5 | |
| 766 | + punpcklqdq xmm0,xmm4 | |
| 767 | + movd xmm4,dword [esi+ecx] | |
| 768 | + movd xmm5,dword [edi+ecx] | |
| 769 | + punpckldq xmm4,xmm5 | |
| 770 | + punpcklqdq xmm1,xmm4 | |
| 771 | + movd xmm4,dword [esi+ecx*2] | |
| 772 | + movd xmm5,dword [edi+ecx*2] | |
| 773 | + punpckldq xmm4,xmm5 | |
| 774 | + punpcklqdq xmm2,xmm4 | |
| 775 | + movd xmm4,dword [esi+edx] | |
| 776 | + movd xmm5,dword [edi+edx] | |
| 777 | + punpckldq xmm4,xmm5 | |
| 778 | + punpcklqdq xmm3,xmm4 | |
| 779 | + movdqa xmm6,xmm0 | |
| 780 | + punpcklbw xmm0,xmm1 | |
| 781 | + punpckhbw xmm6,xmm1 | |
| 782 | + movdqa xmm7,xmm2 | |
| 783 | + punpcklbw xmm2,xmm3 | |
| 784 | + punpckhbw xmm7,xmm3 | |
| 785 | + movdqa xmm4,xmm0 | |
| 786 | + movdqa xmm5,xmm6 | |
| 787 | + punpcklwd xmm0,xmm2 | |
| 788 | + punpckhwd xmm4,xmm2 | |
| 789 | + punpcklwd xmm6,xmm7 | |
| 790 | + punpckhwd xmm5,xmm7 | |
| 791 | + movdqa xmm1,xmm0 | |
| 792 | + movdqa xmm2,xmm4 | |
| 793 | + punpckldq xmm0,xmm6 | |
| 794 | + punpckhdq xmm1,xmm6 | |
| 795 | + punpckldq xmm4,xmm5 | |
| 796 | + punpckhdq xmm2,xmm5 | |
| 797 | + movdqa xmm5,xmm0 | |
| 798 | + movdqa xmm6,xmm1 | |
| 799 | + punpcklqdq xmm0,xmm4 | |
| 800 | + punpckhqdq xmm5,xmm4 | |
| 801 | + punpcklqdq xmm1,xmm2 | |
| 802 | + punpckhqdq xmm6,xmm2 | |
| 803 | + mov edi,dword [esp+1Ch] | |
| 804 | + movdqa [edi],xmm0 | |
| 805 | + movdqa [edi+10h],xmm5 | |
| 806 | + movdqa [edi+20h],xmm1 | |
| 807 | + movdqa [edi+30h],xmm6 | |
| 808 | + mov eax,dword [ebp+1Ch] | |
| 809 | + movsx cx,byte [eax+3] | |
| 810 | + movsx dx,byte [eax+2] | |
| 811 | + movsx si,byte [eax+1] | |
| 812 | + movsx ax,byte [eax] | |
| 813 | + movzx edi,cx | |
| 814 | + movzx ecx,cx | |
| 815 | + movd xmm2,ecx | |
| 816 | + movzx ecx,dx | |
| 817 | + movzx edx,dx | |
| 818 | + movd xmm3,ecx | |
| 819 | + movd xmm4,edx | |
| 820 | + movzx ecx,si | |
| 821 | + movzx edx,si | |
| 822 | + movd xmm5,ecx | |
| 823 | + pxor xmm0,xmm0 | |
| 824 | + movd xmm6,edx | |
| 825 | + movzx ecx,ax | |
| 826 | + movdqa [esp+60h],xmm0 | |
| 827 | + movzx edx,ax | |
| 828 | + movsx eax,word [ebp+14h] | |
| 829 | + punpcklwd xmm6,xmm2 | |
| 830 | + movd xmm1,edi | |
| 831 | + movd xmm7,ecx | |
| 832 | + movsx ecx,word [ebp+18h] | |
| 833 | + movd xmm0,edx | |
| 834 | + punpcklwd xmm7,xmm3 | |
| 835 | + punpcklwd xmm5,xmm1 | |
| 836 | + movdqa xmm1,[esp+60h] | |
| 837 | + punpcklwd xmm7,xmm5 | |
| 838 | + movdqa xmm5,[esp+0A0h] | |
| 839 | + punpcklwd xmm0,xmm4 | |
| 840 | + punpcklwd xmm0,xmm6 | |
| 841 | + movdqa xmm6, [esp+70h] | |
| 842 | + punpcklwd xmm0,xmm7 | |
| 843 | + movdqa xmm7,[esp+80h] | |
| 844 | + movdqa xmm2,xmm1 | |
| 845 | + psubw xmm2,xmm0 | |
| 846 | + movdqa [esp+0D0h],xmm2 | |
| 847 | + movd xmm2,eax | |
| 848 | + movdqa xmm3,xmm2 | |
| 849 | + punpcklwd xmm3,xmm2 | |
| 850 | + pshufd xmm4,xmm3,0 | |
| 851 | + movd xmm2,ecx | |
| 852 | + movdqa xmm3,xmm2 | |
| 853 | + punpcklwd xmm3,xmm2 | |
| 854 | + pshufd xmm2,xmm3,0 | |
| 855 | + movdqa xmm3, [esp+90h] | |
| 856 | + movdqa [esp+50h],xmm2 | |
| 857 | + movdqa xmm2,xmm6 | |
| 858 | + punpcklbw xmm2,xmm1 | |
| 859 | + punpckhbw xmm6,xmm1 | |
| 860 | + movdqa [esp+40h],xmm2 | |
| 861 | + movdqa [esp+0B0h],xmm6 | |
| 862 | + movdqa xmm6,[esp+90h] | |
| 863 | + movdqa xmm2,xmm7 | |
| 864 | + punpckhbw xmm7,xmm1 | |
| 865 | + punpckhbw xmm6,xmm1 | |
| 866 | + punpcklbw xmm2,xmm1 | |
| 867 | + punpcklbw xmm3,xmm1 | |
| 868 | + punpcklbw xmm5,xmm1 | |
| 869 | + movdqa [esp+0F0h],xmm7 | |
| 870 | + movdqa [esp+0C0h],xmm6 | |
| 871 | + movdqa xmm6, [esp+0A0h] | |
| 872 | + punpckhbw xmm6,xmm1 | |
| 873 | + movdqa [esp+0E0h],xmm6 | |
| 874 | + mov edx,4 | |
| 875 | + movsx eax,dx | |
| 876 | + movd xmm6,eax | |
| 877 | + movdqa xmm7,xmm6 | |
| 878 | + punpcklwd xmm7,xmm6 | |
| 879 | + pshufd xmm6,xmm7,0 | |
| 880 | + movdqa [esp+30h],xmm6 | |
| 881 | + movdqa xmm7, [esp+40h] | |
| 882 | + psubw xmm7,xmm5 | |
| 883 | + movdqa xmm6,xmm0 | |
| 884 | + pcmpgtw xmm6,xmm1 | |
| 885 | + movdqa [esp+60h],xmm6 | |
| 886 | + movdqa xmm1, [esp+0D0h] | |
| 887 | + movdqa xmm6,xmm3 | |
| 888 | + psubw xmm6,xmm2 | |
| 889 | + psllw xmm6,2 | |
| 890 | + paddw xmm6,xmm7 | |
| 891 | + paddw xmm6,[esp+30h] | |
| 892 | + psraw xmm6,3 | |
| 893 | + pmaxsw xmm1,xmm6 | |
| 894 | + movdqa xmm7,[esp+50h] | |
| 895 | + movdqa [esp+20h],xmm0 | |
| 896 | + movdqa xmm6, [esp+20h] | |
| 897 | + pminsw xmm6,xmm1 | |
| 898 | + movdqa [esp+20h],xmm6 | |
| 899 | + movdqa xmm6,xmm4 | |
| 900 | + movdqa xmm1,xmm2 | |
| 901 | + psubw xmm1,xmm3 | |
| 902 | + pabsw xmm1,xmm1 | |
| 903 | + pcmpgtw xmm6,xmm1 | |
| 904 | + movdqa xmm1, [esp+40h] | |
| 905 | + psubw xmm1,xmm2 | |
| 906 | + pabsw xmm1,xmm1 | |
| 907 | + pcmpgtw xmm7,xmm1 | |
| 908 | + movdqa xmm1, [esp+50h] | |
| 909 | + pand xmm6,xmm7 | |
| 910 | + movdqa xmm7, [esp+50h] | |
| 911 | + psubw xmm5,xmm3 | |
| 912 | + pabsw xmm5,xmm5 | |
| 913 | + pcmpgtw xmm1,xmm5 | |
| 914 | + movdqa xmm5, [esp+0B0h] | |
| 915 | + psubw xmm5,[esp+0E0h] | |
| 916 | + pand xmm6,xmm1 | |
| 917 | + pand xmm6, [esp+60h] | |
| 918 | + movdqa xmm1, [esp+20h] | |
| 919 | + pand xmm1,xmm6 | |
| 920 | + movdqa xmm6, [esp+0C0h] | |
| 921 | + movdqa [esp+40h],xmm1 | |
| 922 | + movdqa xmm1, [esp+0F0h] | |
| 923 | + psubw xmm6,xmm1 | |
| 924 | + psllw xmm6,2 | |
| 925 | + paddw xmm6,xmm5 | |
| 926 | + paddw xmm6, [esp+30h] | |
| 927 | + movdqa xmm5, [esp+0D0h] | |
| 928 | + psraw xmm6,3 | |
| 929 | + pmaxsw xmm5,xmm6 | |
| 930 | + pminsw xmm0,xmm5 | |
| 931 | + movdqa xmm5,[esp+0C0h] | |
| 932 | + movdqa xmm6,xmm1 | |
| 933 | + psubw xmm6,xmm5 | |
| 934 | + pabsw xmm6,xmm6 | |
| 935 | + pcmpgtw xmm4,xmm6 | |
| 936 | + movdqa xmm6,[esp+0B0h] | |
| 937 | + psubw xmm6,xmm1 | |
| 938 | + pabsw xmm6,xmm6 | |
| 939 | + pcmpgtw xmm7,xmm6 | |
| 940 | + movdqa xmm6, [esp+0E0h] | |
| 941 | + pand xmm4,xmm7 | |
| 942 | + movdqa xmm7, [esp+50h] | |
| 943 | + psubw xmm6,xmm5 | |
| 944 | + pabsw xmm6,xmm6 | |
| 945 | + pcmpgtw xmm7,xmm6 | |
| 946 | + pand xmm4,xmm7 | |
| 947 | + pand xmm4,[esp+60h] | |
| 948 | + pand xmm0,xmm4 | |
| 949 | + movdqa xmm4, [esp+40h] | |
| 950 | + paddw xmm2,xmm4 | |
| 951 | + paddw xmm1,xmm0 | |
| 952 | + psubw xmm3,xmm4 | |
| 953 | + psubw xmm5,xmm0 | |
| 954 | + packuswb xmm2,xmm1 | |
| 955 | + packuswb xmm3,xmm5 | |
| 956 | + movdqa [esp+80h],xmm2 | |
| 957 | + movdqa [esp+90h],xmm3 | |
| 958 | + mov esi,dword [esp+1Ch] | |
| 959 | + movdqa xmm0, [esi] | |
| 960 | + movdqa xmm1, [esi+10h] | |
| 961 | + movdqa xmm2, [esi+20h] | |
| 962 | + movdqa xmm3, [esi+30h] | |
| 963 | + movdqa xmm6,xmm0 | |
| 964 | + punpcklbw xmm0,xmm1 | |
| 965 | + punpckhbw xmm6,xmm1 | |
| 966 | + movdqa xmm7,xmm2 | |
| 967 | + punpcklbw xmm2,xmm3 | |
| 968 | + punpckhbw xmm7,xmm3 | |
| 969 | + movdqa xmm4,xmm0 | |
| 970 | + movdqa xmm5,xmm6 | |
| 971 | + punpcklwd xmm0,xmm2 | |
| 972 | + punpckhwd xmm4,xmm2 | |
| 973 | + punpcklwd xmm6,xmm7 | |
| 974 | + punpckhwd xmm5,xmm7 | |
| 975 | + movdqa xmm1,xmm0 | |
| 976 | + movdqa xmm2,xmm4 | |
| 977 | + punpckldq xmm0,xmm6 | |
| 978 | + punpckhdq xmm1,xmm6 | |
| 979 | + punpckldq xmm4,xmm5 | |
| 980 | + punpckhdq xmm2,xmm5 | |
| 981 | + movdqa xmm5,xmm0 | |
| 982 | + movdqa xmm6,xmm1 | |
| 983 | + punpcklqdq xmm0,xmm4 | |
| 984 | + punpckhqdq xmm5,xmm4 | |
| 985 | + punpcklqdq xmm1,xmm2 | |
| 986 | + punpckhqdq xmm6,xmm2 | |
| 987 | + mov esi,dword [esp+14h] | |
| 988 | + mov ecx,dword [ebp+10h] | |
| 989 | + mov edx,dword [esp+0Ch] | |
| 990 | + mov edi,dword [esp+8] | |
| 991 | + movd dword [esi],xmm0 | |
| 992 | + movd dword [esi+ecx],xmm5 | |
| 993 | + movd dword [esi+ecx*2],xmm1 | |
| 994 | + movd dword [esi+edx],xmm6 | |
| 995 | + psrldq xmm0,4 | |
| 996 | + psrldq xmm5,4 | |
| 997 | + psrldq xmm1,4 | |
| 998 | + psrldq xmm6,4 | |
| 999 | + mov esi,dword [esp+18h] | |
| 1000 | + movd dword [edi],xmm0 | |
| 1001 | + movd dword [edi+ecx],xmm5 | |
| 1002 | + movd dword [edi+ecx*2],xmm1 | |
| 1003 | + movd dword [edi+edx],xmm6 | |
| 1004 | + psrldq xmm0,4 | |
| 1005 | + psrldq xmm5,4 | |
| 1006 | + psrldq xmm1,4 | |
| 1007 | + psrldq xmm6,4 | |
| 1008 | + movd dword [esi],xmm0 | |
| 1009 | + movd dword [esi+ecx],xmm5 | |
| 1010 | + movd dword [esi+ecx*2],xmm1 | |
| 1011 | + movd dword [esi+edx],xmm6 | |
| 1012 | + psrldq xmm0,4 | |
| 1013 | + psrldq xmm5,4 | |
| 1014 | + psrldq xmm1,4 | |
| 1015 | + psrldq xmm6,4 | |
| 1016 | + mov edi,dword [esp+10h] | |
| 1017 | + movd dword [edi],xmm0 | |
| 1018 | + movd dword [edi+ecx],xmm5 | |
| 1019 | + movd dword [edi+ecx*2],xmm1 | |
| 1020 | + movd dword [edi+edx],xmm6 | |
| 1021 | + pop edi | |
| 1022 | + pop esi | |
| 1023 | + mov esp,ebp | |
| 1024 | + pop ebp | |
| 1025 | + ret | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | +;******************************************************************************* | |
| 1030 | +; void DeblockLumaLt4V_sse2(uint8_t * pPix, int32_t iStride, int32_t iAlpha, | |
| 1031 | +; int32_t iBeta, int8_t * pTC) | |
| 1032 | +;******************************************************************************* | |
| 1033 | + | |
| 1034 | + | |
| 1035 | +WELS_EXTERN DeblockLumaLt4V_sse2 | |
| 1036 | + | |
| 1037 | +ALIGN 16 | |
| 1038 | + | |
| 1039 | +DeblockLumaLt4V_sse2: | |
| 1040 | + push ebp | |
| 1041 | + mov ebp, esp | |
| 1042 | + and esp, -16 ; fffffff0H | |
| 1043 | + sub esp, 420 ; 000001a4H | |
| 1044 | + mov eax, dword [ebp+8] | |
| 1045 | + mov ecx, dword [ebp+12] | |
| 1046 | + | |
| 1047 | + pxor xmm0, xmm0 | |
| 1048 | + push ebx | |
| 1049 | + mov edx, dword [ebp+24] | |
| 1050 | + movdqa [esp+424-384], xmm0 | |
| 1051 | + push esi | |
| 1052 | + | |
| 1053 | + lea esi, [ecx+ecx*2] | |
| 1054 | + push edi | |
| 1055 | + mov edi, eax | |
| 1056 | + sub edi, esi | |
| 1057 | + movdqa xmm0, [edi] | |
| 1058 | + | |
| 1059 | + lea esi, [ecx+ecx] | |
| 1060 | + movdqa [esp+432-208], xmm0 | |
| 1061 | + mov edi, eax | |
| 1062 | + sub edi, esi | |
| 1063 | + movdqa xmm0, [edi] | |
| 1064 | + movdqa [esp+448-208], xmm0 | |
| 1065 | + | |
| 1066 | + mov ebx, eax | |
| 1067 | + sub ebx, ecx | |
| 1068 | + movdqa xmm0, [ebx] | |
| 1069 | + movdqa [esp+464-208], xmm0 | |
| 1070 | + | |
| 1071 | + movdqa xmm0, [eax] | |
| 1072 | + | |
| 1073 | + add ecx, eax | |
| 1074 | + movdqa [esp+480-208], xmm0 | |
| 1075 | + movdqa xmm0, [ecx] | |
| 1076 | + mov dword [esp+432-404], ecx | |
| 1077 | + | |
| 1078 | + movsx ecx, word [ebp+16] | |
| 1079 | + movdqa [esp+496-208], xmm0 | |
| 1080 | + movdqa xmm0, [esi+eax] | |
| 1081 | + | |
| 1082 | + movsx si, byte [edx] | |
| 1083 | + movdqa [esp+512-208], xmm0 | |
| 1084 | + movd xmm0, ecx | |
| 1085 | + movsx ecx, word [ebp+20] | |
| 1086 | + movdqa xmm1, xmm0 | |
| 1087 | + punpcklwd xmm1, xmm0 | |
| 1088 | + pshufd xmm0, xmm1, 0 | |
| 1089 | + movdqa [esp+432-112], xmm0 | |
| 1090 | + movd xmm0, ecx | |
| 1091 | + movsx cx, byte [edx+1] | |
| 1092 | + movdqa xmm1, xmm0 | |
| 1093 | + punpcklwd xmm1, xmm0 | |
| 1094 | + mov dword [esp+432-408], ebx | |
| 1095 | + movzx ebx, cx | |
| 1096 | + pshufd xmm0, xmm1, 0 | |
| 1097 | + movd xmm1, ebx | |
| 1098 | + movzx ebx, cx | |
| 1099 | + movd xmm2, ebx | |
| 1100 | + movzx ebx, cx | |
| 1101 | + movzx ecx, cx | |
| 1102 | + movd xmm4, ecx | |
| 1103 | + movzx ecx, si | |
| 1104 | + movd xmm5, ecx | |
| 1105 | + movzx ecx, si | |
| 1106 | + movd xmm6, ecx | |
| 1107 | + movzx ecx, si | |
| 1108 | + movd xmm7, ecx | |
| 1109 | + movzx ecx, si | |
| 1110 | + movdqa [esp+432-336], xmm0 | |
| 1111 | + movd xmm0, ecx | |
| 1112 | + | |
| 1113 | + movsx cx, byte [edx+3] | |
| 1114 | + movsx dx, byte [edx+2] | |
| 1115 | + movd xmm3, ebx | |
| 1116 | + punpcklwd xmm0, xmm4 | |
| 1117 | + movzx esi, cx | |
| 1118 | + punpcklwd xmm6, xmm2 | |
| 1119 | + punpcklwd xmm5, xmm1 | |
| 1120 | + punpcklwd xmm0, xmm6 | |
| 1121 | + punpcklwd xmm7, xmm3 | |
| 1122 | + punpcklwd xmm7, xmm5 | |
| 1123 | + punpcklwd xmm0, xmm7 | |
| 1124 | + movdqa [esp+432-400], xmm0 | |
| 1125 | + movd xmm0, esi | |
| 1126 | + movzx esi, cx | |
| 1127 | + movd xmm2, esi | |
| 1128 | + movzx esi, cx | |
| 1129 | + movzx ecx, cx | |
| 1130 | + movd xmm4, ecx | |
| 1131 | + movzx ecx, dx | |
| 1132 | + movd xmm3, esi | |
| 1133 | + movd xmm5, ecx | |
| 1134 | + punpcklwd xmm5, xmm0 | |
| 1135 | + | |
| 1136 | + movdqa xmm0, [esp+432-384] | |
| 1137 | + movzx ecx, dx | |
| 1138 | + movd xmm6, ecx | |
| 1139 | + movzx ecx, dx | |
| 1140 | + movzx edx, dx | |
| 1141 | + punpcklwd xmm6, xmm2 | |
| 1142 | + movd xmm7, ecx | |
| 1143 | + movd xmm1, edx | |
| 1144 | + | |
| 1145 | + movdqa xmm2, [esp+448-208] | |
| 1146 | + punpcklbw xmm2, xmm0 | |
| 1147 | + | |
| 1148 | + mov ecx, 4 | |
| 1149 | + movsx edx, cx | |
| 1150 | + punpcklwd xmm7, xmm3 | |
| 1151 | + punpcklwd xmm7, xmm5 | |
| 1152 | + movdqa xmm5, [esp+496-208] | |
| 1153 | + movdqa xmm3, [esp+464-208] | |
| 1154 | + punpcklbw xmm5, xmm0 | |
| 1155 | + movdqa [esp+432-240], xmm5 | |
| 1156 | + movdqa xmm5, [esp+512-208] | |
| 1157 | + punpcklbw xmm5, xmm0 | |
| 1158 | + movdqa [esp+432-352], xmm5 | |
| 1159 | + punpcklwd xmm1, xmm4 | |
| 1160 | + movdqa xmm4, [esp+432-208] | |
| 1161 | + punpcklwd xmm1, xmm6 | |
| 1162 | + movdqa xmm6, [esp+480-208] | |
| 1163 | + punpcklwd xmm1, xmm7 | |
| 1164 | + punpcklbw xmm6, xmm0 | |
| 1165 | + punpcklbw xmm3, xmm0 | |
| 1166 | + punpcklbw xmm4, xmm0 | |
| 1167 | + movdqa xmm7, xmm3 | |
| 1168 | + psubw xmm7, xmm4 | |
| 1169 | + pabsw xmm7, xmm7 | |
| 1170 | + movdqa [esp+432-272], xmm4 | |
| 1171 | + movdqa xmm4, [esp+432-336] | |
| 1172 | + movdqa xmm5, xmm4 | |
| 1173 | + pcmpgtw xmm5, xmm7 | |
| 1174 | + movdqa [esp+432-288], xmm5 | |
| 1175 | + movdqa xmm7, xmm6 | |
| 1176 | + psubw xmm7, [esp+432-352] | |
| 1177 | + pabsw xmm7, xmm7 | |
| 1178 | + movdqa xmm5, xmm4 | |
| 1179 | + pcmpgtw xmm5, xmm7 | |
| 1180 | + movdqa [esp+432-256], xmm5 | |
| 1181 | + movdqa xmm5, xmm3 | |
| 1182 | + pavgw xmm5, xmm6 | |
| 1183 | + movdqa [esp+432-304], xmm5 | |
| 1184 | + movdqa xmm5, [esp+432-400] | |
| 1185 | + psubw xmm5, [esp+432-288] | |
| 1186 | + psubw xmm5, [esp+432-256] | |
| 1187 | + movdqa [esp+432-224], xmm5 | |
| 1188 | + movdqa xmm5, xmm6 | |
| 1189 | + psubw xmm5, xmm3 | |
| 1190 | + movdqa [esp+432-32], xmm6 | |
| 1191 | + psubw xmm6, [esp+432-240] | |
| 1192 | + movdqa xmm7, xmm5 | |
| 1193 | + movdqa [esp+432-384], xmm5 | |
| 1194 | + movdqa xmm5, [esp+432-112] | |
| 1195 | + pabsw xmm7, xmm7 | |
| 1196 | + pcmpgtw xmm5, xmm7 | |
| 1197 | + pabsw xmm6, xmm6 | |
| 1198 | + movdqa xmm7, xmm4 | |
| 1199 | + pcmpgtw xmm7, xmm6 | |
| 1200 | + | |
| 1201 | + pand xmm5, xmm7 | |
| 1202 | + movdqa xmm6, xmm3 | |
| 1203 | + psubw xmm6, xmm2 | |
| 1204 | + pabsw xmm6, xmm6 | |
| 1205 | + movdqa xmm7, xmm4 | |
| 1206 | + pcmpgtw xmm7, xmm6 | |
| 1207 | + movdqa xmm6, [esp+432-400] | |
| 1208 | + pand xmm5, xmm7 | |
| 1209 | + movdqa xmm7, xmm6 | |
| 1210 | + pcmpeqw xmm6, xmm0 | |
| 1211 | + pcmpgtw xmm7, xmm0 | |
| 1212 | + por xmm7, xmm6 | |
| 1213 | + pand xmm5, xmm7 | |
| 1214 | + movdqa [esp+432-320], xmm5 | |
| 1215 | + movd xmm5, edx | |
| 1216 | + movdqa xmm6, xmm5 | |
| 1217 | + punpcklwd xmm6, xmm5 | |
| 1218 | + pshufd xmm5, xmm6, 0 | |
| 1219 | + movdqa [esp+432-336], xmm5 | |
| 1220 | + movdqa xmm5, [esp+432-224] | |
| 1221 | + movdqa [esp+432-368], xmm5 | |
| 1222 | + movdqa xmm6, xmm0 | |
| 1223 | + psubw xmm6, xmm5 | |
| 1224 | + movdqa xmm5, [esp+432-384] | |
| 1225 | + psllw xmm5, 2 | |
| 1226 | + movdqa xmm7, xmm2 | |
| 1227 | + psubw xmm7, [esp+432-240] | |
| 1228 | + paddw xmm7, xmm5 | |
| 1229 | + paddw xmm7, [esp+432-336] | |
| 1230 | + movdqa xmm5, [esp+432-368] | |
| 1231 | + psraw xmm7, 3 | |
| 1232 | + pmaxsw xmm6, xmm7 | |
| 1233 | + pminsw xmm5, xmm6 | |
| 1234 | + | |
| 1235 | + pand xmm5, [esp+432-320] | |
| 1236 | + movdqa xmm6, [esp+432-400] | |
| 1237 | + movdqa [esp+432-64], xmm5 | |
| 1238 | + movdqa [esp+432-384], xmm6 | |
| 1239 | + movdqa xmm5, xmm0 | |
| 1240 | + psubw xmm5, xmm6 | |
| 1241 | + movdqa [esp+432-368], xmm5 | |
| 1242 | + movdqa xmm6, xmm5 | |
| 1243 | + movdqa xmm5, [esp+432-272] | |
| 1244 | + paddw xmm5, [esp+432-304] | |
| 1245 | + movdqa xmm7, xmm2 | |
| 1246 | + paddw xmm7, xmm2 | |
| 1247 | + psubw xmm5, xmm7 | |
| 1248 | + psraw xmm5, 1 | |
| 1249 | + pmaxsw xmm6, xmm5 | |
| 1250 | + movdqa xmm5, [esp+432-384] | |
| 1251 | + pminsw xmm5, xmm6 | |
| 1252 | + | |
| 1253 | + pand xmm5, [esp+432-320] | |
| 1254 | + pand xmm5, [esp+432-288] | |
| 1255 | + movdqa xmm6, [esp+432-240] | |
| 1256 | + movdqa [esp+432-96], xmm5 | |
| 1257 | + movdqa xmm5, [esp+432-352] | |
| 1258 | + paddw xmm5, [esp+432-304] | |
| 1259 | + movdqa xmm7, xmm6 | |
| 1260 | + paddw xmm7, xmm6 | |
| 1261 | + movdqa xmm6, [esp+432-368] | |
| 1262 | + psubw xmm5, xmm7 | |
| 1263 | + | |
| 1264 | + movdqa xmm7, [esp+496-208] | |
| 1265 | + psraw xmm5, 1 | |
| 1266 | + pmaxsw xmm6, xmm5 | |
| 1267 | + movdqa xmm5, [esp+432-400] | |
| 1268 | + pminsw xmm5, xmm6 | |
| 1269 | + pand xmm5, [esp+432-320] | |
| 1270 | + pand xmm5, [esp+432-256] | |
| 1271 | + movdqa xmm6, [esp+448-208] | |
| 1272 | + punpckhbw xmm7, xmm0 | |
| 1273 | + movdqa [esp+432-352], xmm7 | |
| 1274 | + | |
| 1275 | + movdqa xmm7, [esp+512-208] | |
| 1276 | + punpckhbw xmm6, xmm0 | |
| 1277 | + movdqa [esp+432-48], xmm5 | |
| 1278 | + movdqa xmm5, [esp+432-208] | |
| 1279 | + movdqa [esp+432-368], xmm6 | |
| 1280 | + movdqa xmm6, [esp+464-208] | |
| 1281 | + punpckhbw xmm7, xmm0 | |
| 1282 | + punpckhbw xmm5, xmm0 | |
| 1283 | + movdqa [esp+432-384], xmm7 | |
| 1284 | + punpckhbw xmm6, xmm0 | |
| 1285 | + movdqa [esp+432-400], xmm6 | |
| 1286 | + | |
| 1287 | + movdqa xmm7, [esp+432-400] | |
| 1288 | + movdqa xmm6, [esp+480-208] | |
| 1289 | + psubw xmm7, xmm5 | |
| 1290 | + movdqa [esp+432-16], xmm5 | |
| 1291 | + pabsw xmm7, xmm7 | |
| 1292 | + punpckhbw xmm6, xmm0 | |
| 1293 | + movdqa xmm5, xmm4 | |
| 1294 | + pcmpgtw xmm5, xmm7 | |
| 1295 | + movdqa [esp+432-288], xmm5 | |
| 1296 | + | |
| 1297 | + movdqa xmm7, xmm6 | |
| 1298 | + psubw xmm7, [esp+432-384] | |
| 1299 | + pabsw xmm7, xmm7 | |
| 1300 | + movdqa xmm5, xmm4 | |
| 1301 | + pcmpgtw xmm5, xmm7 | |
| 1302 | + movdqa [esp+432-256], xmm5 | |
| 1303 | + | |
| 1304 | + movdqa xmm5, [esp+432-400] | |
| 1305 | + movdqa [esp+432-80], xmm6 | |
| 1306 | + pavgw xmm5, xmm6 | |
| 1307 | + movdqa [esp+432-304], xmm5 | |
| 1308 | + | |
| 1309 | + movdqa xmm5, xmm1 | |
| 1310 | + psubw xmm5, [esp+432-288] | |
| 1311 | + psubw xmm5, [esp+432-256] | |
| 1312 | + movdqa [esp+432-224], xmm5 | |
| 1313 | + movdqa xmm5, xmm6 | |
| 1314 | + psubw xmm5, [esp+432-400] | |
| 1315 | + psubw xmm6, [esp+432-352] | |
| 1316 | + movdqa [esp+432-272], xmm5 | |
| 1317 | + movdqa xmm7, xmm5 | |
| 1318 | + movdqa xmm5, [esp+432-112] | |
| 1319 | + pabsw xmm7, xmm7 | |
| 1320 | + pcmpgtw xmm5, xmm7 | |
| 1321 | + movdqa xmm7, xmm4 | |
| 1322 | + pabsw xmm6, xmm6 | |
| 1323 | + pcmpgtw xmm7, xmm6 | |
| 1324 | + movdqa xmm6, [esp+432-368] | |
| 1325 | + | |
| 1326 | + pand xmm5, xmm7 | |
| 1327 | + movdqa xmm7, [esp+432-400] | |
| 1328 | + psubw xmm7, xmm6 | |
| 1329 | + psubw xmm6, [esp+432-352] | |
| 1330 | + pabsw xmm7, xmm7 | |
| 1331 | + pcmpgtw xmm4, xmm7 | |
| 1332 | + pand xmm5, xmm4 | |
| 1333 | + | |
| 1334 | + paddw xmm2, [esp+432-96] | |
| 1335 | + movdqa xmm4, xmm1 | |
| 1336 | + pcmpgtw xmm4, xmm0 | |
| 1337 | + movdqa xmm7, xmm1 | |
| 1338 | + pcmpeqw xmm7, xmm0 | |
| 1339 | + por xmm4, xmm7 | |
| 1340 | + pand xmm5, xmm4 | |
| 1341 | + movdqa xmm4, [esp+432-224] | |
| 1342 | + movdqa [esp+432-320], xmm5 | |
| 1343 | + movdqa xmm5, [esp+432-272] | |
| 1344 | + movdqa xmm7, xmm0 | |
| 1345 | + psubw xmm7, xmm4 | |
| 1346 | + psubw xmm0, xmm1 | |
| 1347 | + psllw xmm5, 2 | |
| 1348 | + paddw xmm6, xmm5 | |
| 1349 | + paddw xmm6, [esp+432-336] | |
| 1350 | + movdqa xmm5, [esp+432-368] | |
| 1351 | + movdqa [esp+432-336], xmm0 | |
| 1352 | + psraw xmm6, 3 | |
| 1353 | + pmaxsw xmm7, xmm6 | |
| 1354 | + pminsw xmm4, xmm7 | |
| 1355 | + pand xmm4, [esp+432-320] | |
| 1356 | + movdqa xmm6, xmm0 | |
| 1357 | + movdqa xmm0, [esp+432-16] | |
| 1358 | + paddw xmm0, [esp+432-304] | |
| 1359 | + movdqa [esp+432-272], xmm4 | |
| 1360 | + movdqa xmm4, [esp+432-368] | |
| 1361 | + paddw xmm4, xmm4 | |
| 1362 | + psubw xmm0, xmm4 | |
| 1363 | + | |
| 1364 | + movdqa xmm4, [esp+432-64] | |
| 1365 | + psraw xmm0, 1 | |
| 1366 | + pmaxsw xmm6, xmm0 | |
| 1367 | + movdqa xmm0, [esp+432-400] | |
| 1368 | + movdqa xmm7, xmm1 | |
| 1369 | + pminsw xmm7, xmm6 | |
| 1370 | + movdqa xmm6, [esp+432-320] | |
| 1371 | + pand xmm7, xmm6 | |
| 1372 | + pand xmm7, [esp+432-288] | |
| 1373 | + paddw xmm5, xmm7 | |
| 1374 | + packuswb xmm2, xmm5 | |
| 1375 | + movdqa xmm5, [esp+432-272] | |
| 1376 | + paddw xmm0, xmm5 | |
| 1377 | + paddw xmm3, xmm4 | |
| 1378 | + packuswb xmm3, xmm0 | |
| 1379 | + | |
| 1380 | + movdqa xmm0, [esp+432-32] | |
| 1381 | + psubw xmm0, xmm4 | |
| 1382 | + movdqa xmm4, [esp+432-80] | |
| 1383 | + psubw xmm4, xmm5 | |
| 1384 | + | |
| 1385 | + movdqa xmm5, [esp+432-240] | |
| 1386 | + paddw xmm5, [esp+432-48] | |
| 1387 | + packuswb xmm0, xmm4 | |
| 1388 | + movdqa xmm4, [esp+432-384] | |
| 1389 | + paddw xmm4, [esp+432-304] | |
| 1390 | + movdqa [esp+480-208], xmm0 | |
| 1391 | + movdqa xmm0, [esp+432-352] | |
| 1392 | + movdqa xmm7, xmm0 | |
| 1393 | + paddw xmm0, xmm0 | |
| 1394 | + | |
| 1395 | + mov ecx, dword [esp+432-408] | |
| 1396 | + | |
| 1397 | + mov edx, dword [esp+432-404] | |
| 1398 | + psubw xmm4, xmm0 | |
| 1399 | + movdqa xmm0, [esp+432-336] | |
| 1400 | + movdqa [edi], xmm2 | |
| 1401 | + psraw xmm4, 1 | |
| 1402 | + pmaxsw xmm0, xmm4 | |
| 1403 | + pminsw xmm1, xmm0 | |
| 1404 | + movdqa xmm0, [esp+480-208] | |
| 1405 | + | |
| 1406 | + pop edi | |
| 1407 | + pand xmm1, xmm6 | |
| 1408 | + pand xmm1, [esp+428-256] | |
| 1409 | + movdqa [ecx], xmm3 | |
| 1410 | + paddw xmm7, xmm1 | |
| 1411 | + pop esi | |
| 1412 | + packuswb xmm5, xmm7 | |
| 1413 | + movdqa [eax], xmm0 | |
| 1414 | + movdqa [edx], xmm5 | |
| 1415 | + pop ebx | |
| 1416 | + mov esp, ebp | |
| 1417 | + pop ebp | |
| 1418 | + ret | |
| 1419 | + | |
| 1420 | + | |
| 1421 | +;******************************************************************************* | |
| 1422 | +; void DeblockLumaEq4V_sse2(uint8_t * pPix, int32_t iStride, int32_t iAlpha, | |
| 1423 | +; int32_t iBeta) | |
| 1424 | +;******************************************************************************* | |
| 1425 | + | |
| 1426 | +WELS_EXTERN DeblockLumaEq4V_sse2 | |
| 1427 | + | |
| 1428 | +ALIGN 16 | |
| 1429 | + | |
| 1430 | +DeblockLumaEq4V_sse2: | |
| 1431 | + | |
| 1432 | + push ebp | |
| 1433 | + mov ebp, esp | |
| 1434 | + and esp, -16 ; fffffff0H | |
| 1435 | + sub esp, 628 ; 00000274H | |
| 1436 | + mov eax, dword [ebp+8] | |
| 1437 | + mov ecx, dword [ebp+12] | |
| 1438 | + push ebx | |
| 1439 | + push esi | |
| 1440 | + | |
| 1441 | + lea edx, [ecx*4] | |
| 1442 | + pxor xmm0, xmm0 | |
| 1443 | + movdqa xmm2, xmm0 | |
| 1444 | + | |
| 1445 | + movdqa xmm0, [ecx+eax] | |
| 1446 | + mov esi, eax | |
| 1447 | + sub esi, edx | |
| 1448 | + movdqa xmm3, [esi] | |
| 1449 | + movdqa xmm5, [eax] | |
| 1450 | + push edi | |
| 1451 | + lea edi, [ecx+ecx] | |
| 1452 | + lea ebx, [ecx+ecx*2] | |
| 1453 | + mov dword [esp+640-600], edi | |
| 1454 | + mov esi, eax | |
| 1455 | + sub esi, edi | |
| 1456 | + movdqa xmm1, [esi] | |
| 1457 | + movdqa [esp+720-272], xmm0 | |
| 1458 | + mov edi, eax | |
| 1459 | + sub edi, ecx | |
| 1460 | + movdqa xmm4, [edi] | |
| 1461 | + add ecx, eax | |
| 1462 | + mov dword [esp+640-596], ecx | |
| 1463 | + | |
| 1464 | + mov ecx, dword [esp+640-600] | |
| 1465 | + movdqa xmm0, [ecx+eax] | |
| 1466 | + movdqa [esp+736-272], xmm0 | |
| 1467 | + | |
| 1468 | + movdqa xmm0, [eax+ebx] | |
| 1469 | + mov edx, eax | |
| 1470 | + sub edx, ebx | |
| 1471 | + | |
| 1472 | + movsx ebx, word [ebp+16] | |
| 1473 | + movdqa xmm6, [edx] | |
| 1474 | + add ecx, eax | |
| 1475 | + movdqa [esp+752-272], xmm0 | |
| 1476 | + movd xmm0, ebx | |
| 1477 | + | |
| 1478 | + movsx ebx, word [ebp+20] | |
| 1479 | + movdqa xmm7, xmm0 | |
| 1480 | + punpcklwd xmm7, xmm0 | |
| 1481 | + pshufd xmm0, xmm7, 0 | |
| 1482 | + movdqa [esp+640-320], xmm0 | |
| 1483 | + movd xmm0, ebx | |
| 1484 | + movdqa xmm7, xmm0 | |
| 1485 | + punpcklwd xmm7, xmm0 | |
| 1486 | + pshufd xmm0, xmm7, 0 | |
| 1487 | + | |
| 1488 | + movdqa xmm7, [esp+736-272] | |
| 1489 | + punpcklbw xmm7, xmm2 | |
| 1490 | + movdqa [esp+640-416], xmm7 | |
| 1491 | + movdqa [esp+640-512], xmm0 | |
| 1492 | + movdqa xmm0, xmm1 | |
| 1493 | + movdqa [esp+672-272], xmm1 | |
| 1494 | + movdqa xmm1, xmm4 | |
| 1495 | + movdqa [esp+704-272], xmm5 | |
| 1496 | + punpcklbw xmm5, xmm2 | |
| 1497 | + punpcklbw xmm1, xmm2 | |
| 1498 | + | |
| 1499 | + movdqa xmm7, xmm5 | |
| 1500 | + psubw xmm7, xmm1 | |
| 1501 | + pabsw xmm7, xmm7 | |
| 1502 | + movdqa [esp+640-560], xmm7 | |
| 1503 | + punpcklbw xmm0, xmm2 | |
| 1504 | + movdqa [esp+688-272], xmm4 | |
| 1505 | + movdqa xmm4, [esp+720-272] | |
| 1506 | + movdqa [esp+640-480], xmm0 | |
| 1507 | + | |
| 1508 | + movdqa xmm7, xmm1 | |
| 1509 | + psubw xmm7, xmm0 | |
| 1510 | + | |
| 1511 | + movdqa xmm0, [esp+640-512] | |
| 1512 | + pabsw xmm7, xmm7 | |
| 1513 | + punpcklbw xmm4, xmm2 | |
| 1514 | + pcmpgtw xmm0, xmm7 | |
| 1515 | + movdqa [esp+640-384], xmm4 | |
| 1516 | + movdqa xmm7, xmm5 | |
| 1517 | + psubw xmm7, xmm4 | |
| 1518 | + movdqa xmm4, [esp+640-512] | |
| 1519 | + movdqa [esp+656-272], xmm6 | |
| 1520 | + punpcklbw xmm6, xmm2 | |
| 1521 | + pabsw xmm7, xmm7 | |
| 1522 | + movdqa [esp+640-48], xmm2 | |
| 1523 | + movdqa [esp+640-368], xmm6 | |
| 1524 | + movdqa [esp+640-144], xmm1 | |
| 1525 | + movdqa [esp+640-400], xmm5 | |
| 1526 | + pcmpgtw xmm4, xmm7 | |
| 1527 | + pand xmm0, xmm4 | |
| 1528 | + movdqa xmm4, [esp+640-320] | |
| 1529 | + pcmpgtw xmm4, [esp+640-560] | |
| 1530 | + pand xmm0, xmm4 | |
| 1531 | + | |
| 1532 | + mov ebx, 2 | |
| 1533 | + movsx ebx, bx | |
| 1534 | + movd xmm4, ebx | |
| 1535 | + movdqa xmm7, xmm4 | |
| 1536 | + punpcklwd xmm7, xmm4 | |
| 1537 | + movdqa xmm4, [esp+640-320] | |
| 1538 | + psraw xmm4, 2 | |
| 1539 | + pshufd xmm7, xmm7, 0 | |
| 1540 | + paddw xmm4, xmm7 | |
| 1541 | + movdqa [esp+640-576], xmm4 | |
| 1542 | + pcmpgtw xmm4, [esp+640-560] | |
| 1543 | + movdqa [esp+640-560], xmm4 | |
| 1544 | + | |
| 1545 | + movdqa xmm4, [esp+640-512] | |
| 1546 | + movdqa [esp+640-624], xmm7 | |
| 1547 | + movdqa xmm7, xmm1 | |
| 1548 | + psubw xmm7, xmm6 | |
| 1549 | + pabsw xmm7, xmm7 | |
| 1550 | + pcmpgtw xmm4, xmm7 | |
| 1551 | + | |
| 1552 | + pand xmm4, [esp+640-560] | |
| 1553 | + movdqa [esp+640-544], xmm4 | |
| 1554 | + movdqa xmm4, [esp+640-512] | |
| 1555 | + movdqa xmm7, xmm5 | |
| 1556 | + psubw xmm7, [esp+640-416] | |
| 1557 | + pabsw xmm7, xmm7 | |
| 1558 | + pcmpgtw xmm4, xmm7 | |
| 1559 | + | |
| 1560 | + pand xmm4, [esp+640-560] | |
| 1561 | + movdqa [esp+640-560], xmm4 | |
| 1562 | + | |
| 1563 | + movdqa xmm4, [esp+640-544] | |
| 1564 | + pandn xmm4, xmm6 | |
| 1565 | + movdqa [esp+640-16], xmm4 | |
| 1566 | + mov ebx, 4 | |
| 1567 | + movsx ebx, bx | |
| 1568 | + movd xmm4, ebx | |
| 1569 | + movdqa xmm7, xmm4 | |
| 1570 | + punpcklwd xmm7, xmm4 | |
| 1571 | + movdqa xmm4, xmm3 | |
| 1572 | + punpcklbw xmm4, xmm2 | |
| 1573 | + psllw xmm4, 1 | |
| 1574 | + paddw xmm4, xmm6 | |
| 1575 | + paddw xmm4, xmm6 | |
| 1576 | + paddw xmm4, xmm6 | |
| 1577 | + paddw xmm4, [esp+640-480] | |
| 1578 | + | |
| 1579 | + movdqa xmm6, [esp+640-560] | |
| 1580 | + pshufd xmm7, xmm7, 0 | |
| 1581 | + paddw xmm4, xmm1 | |
| 1582 | + movdqa [esp+640-592], xmm7 | |
| 1583 | + paddw xmm4, xmm5 | |
| 1584 | + paddw xmm4, xmm7 | |
| 1585 | + movdqa xmm7, [esp+640-416] | |
| 1586 | + pandn xmm6, xmm7 | |
| 1587 | + movdqa [esp+640-80], xmm6 | |
| 1588 | + movdqa xmm6, [esp+752-272] | |
| 1589 | + punpcklbw xmm6, xmm2 | |
| 1590 | + psllw xmm6, 1 | |
| 1591 | + paddw xmm6, xmm7 | |
| 1592 | + paddw xmm6, xmm7 | |
| 1593 | + paddw xmm6, xmm7 | |
| 1594 | + paddw xmm6, [esp+640-384] | |
| 1595 | + | |
| 1596 | + movdqa xmm7, [esp+640-480] | |
| 1597 | + paddw xmm6, xmm5 | |
| 1598 | + paddw xmm6, xmm1 | |
| 1599 | + paddw xmm6, [esp+640-592] | |
| 1600 | + psraw xmm6, 3 | |
| 1601 | + pand xmm6, [esp+640-560] | |
| 1602 | + movdqa [esp+640-112], xmm6 | |
| 1603 | + movdqa xmm6, [esp+640-544] | |
| 1604 | + pandn xmm6, xmm7 | |
| 1605 | + movdqa [esp+640-336], xmm6 | |
| 1606 | + movdqa xmm6, [esp+640-544] | |
| 1607 | + movdqa [esp+640-528], xmm6 | |
| 1608 | + movdqa xmm6, [esp+640-368] | |
| 1609 | + paddw xmm6, xmm7 | |
| 1610 | + movdqa xmm7, xmm1 | |
| 1611 | + psraw xmm4, 3 | |
| 1612 | + pand xmm4, [esp+640-544] | |
| 1613 | + paddw xmm7, xmm5 | |
| 1614 | + paddw xmm6, xmm7 | |
| 1615 | + paddw xmm6, [esp+640-624] | |
| 1616 | + movdqa xmm7, [esp+640-528] | |
| 1617 | + | |
| 1618 | + paddw xmm5, xmm1 | |
| 1619 | + psraw xmm6, 2 | |
| 1620 | + pand xmm7, xmm6 | |
| 1621 | + | |
| 1622 | + movdqa xmm6, [esp+640-384] | |
| 1623 | + movdqa [esp+640-64], xmm7 | |
| 1624 | + movdqa xmm7, [esp+640-560] | |
| 1625 | + pandn xmm7, xmm6 | |
| 1626 | + movdqa [esp+640-304], xmm7 | |
| 1627 | + movdqa xmm7, [esp+640-560] | |
| 1628 | + movdqa [esp+640-528], xmm7 | |
| 1629 | + movdqa xmm7, [esp+640-416] | |
| 1630 | + paddw xmm7, xmm6 | |
| 1631 | + paddw xmm7, xmm5 | |
| 1632 | + paddw xmm7, [esp+640-624] | |
| 1633 | + movdqa xmm5, [esp+640-528] | |
| 1634 | + psraw xmm7, 2 | |
| 1635 | + pand xmm5, xmm7 | |
| 1636 | + movdqa [esp+640-32], xmm5 | |
| 1637 | + | |
| 1638 | + movdqa xmm5, [esp+640-544] | |
| 1639 | + movdqa [esp+640-528], xmm5 | |
| 1640 | + movdqa xmm5, [esp+640-480] | |
| 1641 | + movdqa xmm7, xmm5 | |
| 1642 | + paddw xmm7, xmm5 | |
| 1643 | + movdqa xmm5, xmm1 | |
| 1644 | + paddw xmm5, xmm6 | |
| 1645 | + paddw xmm6, [esp+640-592] | |
| 1646 | + paddw xmm7, xmm5 | |
| 1647 | + paddw xmm7, [esp+640-624] | |
| 1648 | + movdqa xmm5, [esp+640-528] | |
| 1649 | + psraw xmm7, 2 | |
| 1650 | + pandn xmm5, xmm7 | |
| 1651 | + movdqa xmm7, [esp+640-480] | |
| 1652 | + paddw xmm7, xmm1 | |
| 1653 | + paddw xmm7, [esp+640-400] | |
| 1654 | + movdqa xmm1, [esp+640-544] | |
| 1655 | + movdqa [esp+640-352], xmm5 | |
| 1656 | + movdqa xmm5, [esp+640-368] | |
| 1657 | + psllw xmm7, 1 | |
| 1658 | + paddw xmm7, xmm6 | |
| 1659 | + paddw xmm5, xmm7 | |
| 1660 | + | |
| 1661 | + movdqa xmm7, [esp+640-400] | |
| 1662 | + psraw xmm5, 3 | |
| 1663 | + pand xmm1, xmm5 | |
| 1664 | + movdqa xmm5, [esp+640-480] | |
| 1665 | + movdqa [esp+640-96], xmm1 | |
| 1666 | + movdqa xmm1, [esp+640-560] | |
| 1667 | + movdqa [esp+640-528], xmm1 | |
| 1668 | + movdqa xmm1, [esp+640-384] | |
| 1669 | + movdqa xmm6, xmm1 | |
| 1670 | + paddw xmm6, xmm1 | |
| 1671 | + paddw xmm1, [esp+640-400] | |
| 1672 | + paddw xmm1, [esp+640-144] | |
| 1673 | + paddw xmm7, xmm5 | |
| 1674 | + paddw xmm5, [esp+640-592] | |
| 1675 | + paddw xmm6, xmm7 | |
| 1676 | + paddw xmm6, [esp+640-624] | |
| 1677 | + movdqa xmm7, [esp+640-528] | |
| 1678 | + psraw xmm6, 2 | |
| 1679 | + psllw xmm1, 1 | |
| 1680 | + paddw xmm1, xmm5 | |
| 1681 | + | |
| 1682 | + movdqa xmm5, [esp+656-272] | |
| 1683 | + pandn xmm7, xmm6 | |
| 1684 | + movdqa xmm6, [esp+640-416] | |
| 1685 | + paddw xmm6, xmm1 | |
| 1686 | + movdqa xmm1, [esp+640-560] | |
| 1687 | + psraw xmm6, 3 | |
| 1688 | + pand xmm1, xmm6 | |
| 1689 | + | |
| 1690 | + movdqa xmm6, [esp+704-272] | |
| 1691 | + movdqa [esp+640-128], xmm1 | |
| 1692 | + movdqa xmm1, [esp+672-272] | |
| 1693 | + punpckhbw xmm1, xmm2 | |
| 1694 | + movdqa [esp+640-448], xmm1 | |
| 1695 | + movdqa xmm1, [esp+688-272] | |
| 1696 | + punpckhbw xmm1, xmm2 | |
| 1697 | + punpckhbw xmm6, xmm2 | |
| 1698 | + movdqa [esp+640-288], xmm7 | |
| 1699 | + punpckhbw xmm5, xmm2 | |
| 1700 | + movdqa [esp+640-496], xmm1 | |
| 1701 | + movdqa [esp+640-432], xmm6 | |
| 1702 | + | |
| 1703 | + movdqa xmm7, [esp+720-272] | |
| 1704 | + punpckhbw xmm7, xmm2 | |
| 1705 | + movdqa [esp+640-464], xmm7 | |
| 1706 | + | |
| 1707 | + movdqa xmm7, [esp+736-272] | |
| 1708 | + punpckhbw xmm7, xmm2 | |
| 1709 | + movdqa [esp+640-528], xmm7 | |
| 1710 | + | |
| 1711 | + movdqa xmm7, xmm6 | |
| 1712 | + | |
| 1713 | + psubw xmm6, [esp+640-464] | |
| 1714 | + psubw xmm7, xmm1 | |
| 1715 | + pabsw xmm7, xmm7 | |
| 1716 | + movdqa [esp+640-560], xmm7 | |
| 1717 | + por xmm4, [esp+640-16] | |
| 1718 | + pabsw xmm6, xmm6 | |
| 1719 | + movdqa xmm7, xmm1 | |
| 1720 | + psubw xmm7, [esp+640-448] | |
| 1721 | + | |
| 1722 | + movdqa xmm1, [esp+640-512] | |
| 1723 | + pabsw xmm7, xmm7 | |
| 1724 | + pcmpgtw xmm1, xmm7 | |
| 1725 | + movdqa xmm7, [esp+640-512] | |
| 1726 | + pcmpgtw xmm7, xmm6 | |
| 1727 | + movdqa xmm6, [esp+640-320] | |
| 1728 | + pand xmm1, xmm7 | |
| 1729 | + movdqa xmm7, [esp+640-560] | |
| 1730 | + pcmpgtw xmm6, xmm7 | |
| 1731 | + pand xmm1, xmm6 | |
| 1732 | + | |
| 1733 | + movdqa xmm6, [esp+640-576] | |
| 1734 | + pcmpgtw xmm6, xmm7 | |
| 1735 | + | |
| 1736 | + movdqa xmm7, [esp+640-496] | |
| 1737 | + punpckhbw xmm3, xmm2 | |
| 1738 | + movdqa [esp+640-560], xmm6 | |
| 1739 | + movdqa xmm6, [esp+640-512] | |
| 1740 | + psubw xmm7, xmm5 | |
| 1741 | + pabsw xmm7, xmm7 | |
| 1742 | + pcmpgtw xmm6, xmm7 | |
| 1743 | + | |
| 1744 | + pand xmm6, [esp+640-560] | |
| 1745 | + movdqa xmm7, [esp+640-432] | |
| 1746 | + psubw xmm7, [esp+640-528] | |
| 1747 | + | |
| 1748 | + psllw xmm3, 1 | |
| 1749 | + movdqa [esp+640-544], xmm6 | |
| 1750 | + movdqa xmm6, [esp+640-512] | |
| 1751 | + | |
| 1752 | + movdqa xmm2, [esp+640-544] | |
| 1753 | + paddw xmm3, xmm5 | |
| 1754 | + paddw xmm3, xmm5 | |
| 1755 | + paddw xmm3, xmm5 | |
| 1756 | + paddw xmm3, [esp+640-448] | |
| 1757 | + paddw xmm3, [esp+640-496] | |
| 1758 | + pabsw xmm7, xmm7 | |
| 1759 | + pcmpgtw xmm6, xmm7 | |
| 1760 | + pand xmm6, [esp+640-560] | |
| 1761 | + movdqa [esp+640-560], xmm6 | |
| 1762 | + | |
| 1763 | + movdqa xmm6, xmm0 | |
| 1764 | + pand xmm6, xmm4 | |
| 1765 | + movdqa xmm4, xmm0 | |
| 1766 | + pandn xmm4, [esp+640-368] | |
| 1767 | + por xmm6, xmm4 | |
| 1768 | + movdqa xmm4, [esp+640-432] | |
| 1769 | + paddw xmm3, xmm4 | |
| 1770 | + paddw xmm3, [esp+640-592] | |
| 1771 | + psraw xmm3, 3 | |
| 1772 | + pand xmm3, xmm2 | |
| 1773 | + pandn xmm2, xmm5 | |
| 1774 | + por xmm3, xmm2 | |
| 1775 | + movdqa xmm7, xmm1 | |
| 1776 | + pand xmm7, xmm3 | |
| 1777 | + movdqa xmm3, [esp+640-64] | |
| 1778 | + por xmm3, [esp+640-336] | |
| 1779 | + movdqa xmm2, xmm1 | |
| 1780 | + pandn xmm2, xmm5 | |
| 1781 | + por xmm7, xmm2 | |
| 1782 | + | |
| 1783 | + movdqa xmm2, xmm0 | |
| 1784 | + pand xmm2, xmm3 | |
| 1785 | + movdqa xmm3, xmm0 | |
| 1786 | + pandn xmm3, [esp+640-480] | |
| 1787 | + por xmm2, xmm3 | |
| 1788 | + packuswb xmm6, xmm7 | |
| 1789 | + movdqa [esp+640-336], xmm2 | |
| 1790 | + movdqa [esp+656-272], xmm6 | |
| 1791 | + movdqa xmm6, [esp+640-544] | |
| 1792 | + movdqa xmm2, xmm5 | |
| 1793 | + paddw xmm2, [esp+640-448] | |
| 1794 | + movdqa xmm3, xmm1 | |
| 1795 | + movdqa xmm7, [esp+640-496] | |
| 1796 | + paddw xmm7, xmm4 | |
| 1797 | + paddw xmm2, xmm7 | |
| 1798 | + paddw xmm2, [esp+640-624] | |
| 1799 | + movdqa xmm7, [esp+640-544] | |
| 1800 | + psraw xmm2, 2 | |
| 1801 | + pand xmm6, xmm2 | |
| 1802 | + movdqa xmm2, [esp+640-448] | |
| 1803 | + pandn xmm7, xmm2 | |
| 1804 | + por xmm6, xmm7 | |
| 1805 | + pand xmm3, xmm6 | |
| 1806 | + movdqa xmm6, xmm1 | |
| 1807 | + pandn xmm6, xmm2 | |
| 1808 | + paddw xmm2, [esp+640-496] | |
| 1809 | + paddw xmm2, xmm4 | |
| 1810 | + por xmm3, xmm6 | |
| 1811 | + movdqa xmm6, [esp+640-336] | |
| 1812 | + packuswb xmm6, xmm3 | |
| 1813 | + psllw xmm2, 1 | |
| 1814 | + movdqa [esp+672-272], xmm6 | |
| 1815 | + movdqa xmm6, [esp+640-96] | |
| 1816 | + por xmm6, [esp+640-352] | |
| 1817 | + | |
| 1818 | + movdqa xmm3, xmm0 | |
| 1819 | + pand xmm3, xmm6 | |
| 1820 | + movdqa xmm6, xmm0 | |
| 1821 | + pandn xmm6, [esp+640-144] | |
| 1822 | + por xmm3, xmm6 | |
| 1823 | + movdqa xmm6, [esp+640-544] | |
| 1824 | + movdqa [esp+640-352], xmm3 | |
| 1825 | + movdqa xmm3, [esp+640-464] | |
| 1826 | + paddw xmm3, [esp+640-592] | |
| 1827 | + paddw xmm2, xmm3 | |
| 1828 | + movdqa xmm3, [esp+640-448] | |
| 1829 | + paddw xmm5, xmm2 | |
| 1830 | + movdqa xmm2, [esp+640-496] | |
| 1831 | + psraw xmm5, 3 | |
| 1832 | + pand xmm6, xmm5 | |
| 1833 | + movdqa xmm5, [esp+640-464] | |
| 1834 | + paddw xmm2, xmm5 | |
| 1835 | + paddw xmm5, [esp+640-432] | |
| 1836 | + movdqa xmm4, xmm3 | |
| 1837 | + paddw xmm4, xmm3 | |
| 1838 | + paddw xmm4, xmm2 | |
| 1839 | + paddw xmm4, [esp+640-624] | |
| 1840 | + movdqa xmm2, [esp+640-544] | |
| 1841 | + paddw xmm3, [esp+640-592] | |
| 1842 | + psraw xmm4, 2 | |
| 1843 | + pandn xmm2, xmm4 | |
| 1844 | + por xmm6, xmm2 | |
| 1845 | + movdqa xmm7, xmm1 | |
| 1846 | + pand xmm7, xmm6 | |
| 1847 | + movdqa xmm6, [esp+640-496] | |
| 1848 | + movdqa xmm2, xmm1 | |
| 1849 | + pandn xmm2, xmm6 | |
| 1850 | + por xmm7, xmm2 | |
| 1851 | + movdqa xmm2, [esp+640-352] | |
| 1852 | + packuswb xmm2, xmm7 | |
| 1853 | + movdqa [esp+688-272], xmm2 | |
| 1854 | + movdqa xmm2, [esp+640-128] | |
| 1855 | + por xmm2, [esp+640-288] | |
| 1856 | + | |
| 1857 | + movdqa xmm4, xmm0 | |
| 1858 | + pand xmm4, xmm2 | |
| 1859 | + paddw xmm5, xmm6 | |
| 1860 | + movdqa xmm2, xmm0 | |
| 1861 | + pandn xmm2, [esp+640-400] | |
| 1862 | + por xmm4, xmm2 | |
| 1863 | + movdqa xmm2, [esp+640-528] | |
| 1864 | + psllw xmm5, 1 | |
| 1865 | + paddw xmm5, xmm3 | |
| 1866 | + movdqa xmm3, [esp+640-560] | |
| 1867 | + paddw xmm2, xmm5 | |
| 1868 | + psraw xmm2, 3 | |
| 1869 | + movdqa [esp+640-288], xmm4 | |
| 1870 | + movdqa xmm4, [esp+640-560] | |
| 1871 | + pand xmm4, xmm2 | |
| 1872 | + movdqa xmm2, [esp+640-464] | |
| 1873 | + movdqa xmm5, xmm2 | |
| 1874 | + paddw xmm5, xmm2 | |
| 1875 | + movdqa xmm2, [esp+640-432] | |
| 1876 | + paddw xmm2, [esp+640-448] | |
| 1877 | + movdqa xmm7, xmm1 | |
| 1878 | + paddw xmm5, xmm2 | |
| 1879 | + paddw xmm5, [esp+640-624] | |
| 1880 | + movdqa xmm6, [esp+640-560] | |
| 1881 | + psraw xmm5, 2 | |
| 1882 | + pandn xmm3, xmm5 | |
| 1883 | + por xmm4, xmm3 | |
| 1884 | + movdqa xmm3, [esp+640-32] | |
| 1885 | + por xmm3, [esp+640-304] | |
| 1886 | + pand xmm7, xmm4 | |
| 1887 | + movdqa xmm4, [esp+640-432] | |
| 1888 | + movdqa xmm5, [esp+640-464] | |
| 1889 | + movdqa xmm2, xmm1 | |
| 1890 | + pandn xmm2, xmm4 | |
| 1891 | + paddw xmm4, [esp+640-496] | |
| 1892 | + por xmm7, xmm2 | |
| 1893 | + movdqa xmm2, [esp+640-288] | |
| 1894 | + packuswb xmm2, xmm7 | |
| 1895 | + movdqa [esp+704-272], xmm2 | |
| 1896 | + | |
| 1897 | + movdqa xmm2, xmm0 | |
| 1898 | + pand xmm2, xmm3 | |
| 1899 | + movdqa xmm3, xmm0 | |
| 1900 | + pandn xmm3, [esp+640-384] | |
| 1901 | + por xmm2, xmm3 | |
| 1902 | + movdqa [esp+640-304], xmm2 | |
| 1903 | + movdqa xmm2, [esp+640-528] | |
| 1904 | + movdqa xmm3, xmm2 | |
| 1905 | + paddw xmm3, [esp+640-464] | |
| 1906 | + paddw xmm3, xmm4 | |
| 1907 | + paddw xmm3, [esp+640-624] | |
| 1908 | + psraw xmm3, 2 | |
| 1909 | + pand xmm6, xmm3 | |
| 1910 | + movdqa xmm3, [esp+640-560] | |
| 1911 | + movdqa xmm4, xmm3 | |
| 1912 | + pandn xmm4, xmm5 | |
| 1913 | + por xmm6, xmm4 | |
| 1914 | + movdqa xmm7, xmm1 | |
| 1915 | + pand xmm7, xmm6 | |
| 1916 | + movdqa xmm6, [esp+640-304] | |
| 1917 | + movdqa xmm4, xmm1 | |
| 1918 | + pandn xmm4, xmm5 | |
| 1919 | + por xmm7, xmm4 | |
| 1920 | + | |
| 1921 | + movdqa xmm4, xmm0 | |
| 1922 | + pandn xmm0, [esp+640-416] | |
| 1923 | + packuswb xmm6, xmm7 | |
| 1924 | + movdqa xmm7, [esp+640-112] | |
| 1925 | + por xmm7, [esp+640-80] | |
| 1926 | + pand xmm4, xmm7 | |
| 1927 | + por xmm4, xmm0 | |
| 1928 | + movdqa xmm0, [esp+752-272] | |
| 1929 | + punpckhbw xmm0, [esp+640-48] | |
| 1930 | + psllw xmm0, 1 | |
| 1931 | + paddw xmm0, xmm2 | |
| 1932 | + paddw xmm0, xmm2 | |
| 1933 | + paddw xmm0, xmm2 | |
| 1934 | + paddw xmm0, xmm5 | |
| 1935 | + paddw xmm0, [esp+640-432] | |
| 1936 | + paddw xmm0, [esp+640-496] | |
| 1937 | + paddw xmm0, [esp+640-592] | |
| 1938 | + psraw xmm0, 3 | |
| 1939 | + pand xmm0, xmm3 | |
| 1940 | + movdqa xmm7, xmm1 | |
| 1941 | + pandn xmm3, xmm2 | |
| 1942 | + por xmm0, xmm3 | |
| 1943 | + pand xmm7, xmm0 | |
| 1944 | + | |
| 1945 | + movdqa xmm0, [esp+656-272] | |
| 1946 | + movdqa [edx], xmm0 | |
| 1947 | + | |
| 1948 | + movdqa xmm0, [esp+672-272] | |
| 1949 | + | |
| 1950 | + mov edx, dword [esp+640-596] | |
| 1951 | + movdqa [esi], xmm0 | |
| 1952 | + movdqa xmm0, [esp+688-272] | |
| 1953 | + movdqa [edi], xmm0 | |
| 1954 | + movdqa xmm0, [esp+704-272] | |
| 1955 | + | |
| 1956 | + pop edi | |
| 1957 | + pandn xmm1, xmm2 | |
| 1958 | + movdqa [eax], xmm0 | |
| 1959 | + por xmm7, xmm1 | |
| 1960 | + pop esi | |
| 1961 | + packuswb xmm4, xmm7 | |
| 1962 | + movdqa [edx], xmm6 | |
| 1963 | + movdqa [ecx], xmm4 | |
| 1964 | + pop ebx | |
| 1965 | + mov esp, ebp | |
| 1966 | + pop ebp | |
| 1967 | + ret | |
| 1968 | + | |
| 1969 | + | |
| 1970 | +;******************************************************************************** | |
| 1971 | +; | |
| 1972 | +; void DeblockLumaTransposeH2V_sse2(uint8_t * pPixY, int32_t iStride, uint8_t * pDst); | |
| 1973 | +; | |
| 1974 | +;******************************************************************************** | |
| 1975 | + | |
| 1976 | +WELS_EXTERN DeblockLumaTransposeH2V_sse2 | |
| 1977 | + | |
| 1978 | +ALIGN 16 | |
| 1979 | + | |
| 1980 | +DeblockLumaTransposeH2V_sse2: | |
| 1981 | + push ebp | |
| 1982 | + push ebx | |
| 1983 | + mov ebp, esp | |
| 1984 | + and esp,0FFFFFFF0h | |
| 1985 | + sub esp, 10h | |
| 1986 | + | |
| 1987 | + mov eax, [ebp + 0Ch] | |
| 1988 | + mov ecx, [ebp + 10h] | |
| 1989 | + lea edx, [eax + ecx * 8] | |
| 1990 | + lea ebx, [ecx*3] | |
| 1991 | + | |
| 1992 | + movq xmm0, [eax] | |
| 1993 | + movq xmm7, [edx] | |
| 1994 | + punpcklqdq xmm0, xmm7 | |
| 1995 | + movq xmm1, [eax + ecx] | |
| 1996 | + movq xmm7, [edx + ecx] | |
| 1997 | + punpcklqdq xmm1, xmm7 | |
| 1998 | + movq xmm2, [eax + ecx*2] | |
| 1999 | + movq xmm7, [edx + ecx*2] | |
| 2000 | + punpcklqdq xmm2, xmm7 | |
| 2001 | + movq xmm3, [eax + ebx] | |
| 2002 | + movq xmm7, [edx + ebx] | |
| 2003 | + punpcklqdq xmm3, xmm7 | |
| 2004 | + | |
| 2005 | + lea eax, [eax + ecx * 4] | |
| 2006 | + lea edx, [edx + ecx * 4] | |
| 2007 | + movq xmm4, [eax] | |
| 2008 | + movq xmm7, [edx] | |
| 2009 | + punpcklqdq xmm4, xmm7 | |
| 2010 | + movq xmm5, [eax + ecx] | |
| 2011 | + movq xmm7, [edx + ecx] | |
| 2012 | + punpcklqdq xmm5, xmm7 | |
| 2013 | + movq xmm6, [eax + ecx*2] | |
| 2014 | + movq xmm7, [edx + ecx*2] | |
| 2015 | + punpcklqdq xmm6, xmm7 | |
| 2016 | + | |
| 2017 | + movdqa [esp], xmm0 | |
| 2018 | + movq xmm7, [eax + ebx] | |
| 2019 | + movq xmm0, [edx + ebx] | |
| 2020 | + punpcklqdq xmm7, xmm0 | |
| 2021 | + movdqa xmm0, [esp] | |
| 2022 | + | |
| 2023 | + SSE2_TransTwo8x8B xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, [esp] | |
| 2024 | + ;pOut: m5, m3, m4, m8, m6, m2, m7, m1 | |
| 2025 | + | |
| 2026 | + mov eax, [ebp + 14h] | |
| 2027 | + movdqa [eax], xmm4 | |
| 2028 | + movdqa [eax + 10h], xmm2 | |
| 2029 | + movdqa [eax + 20h], xmm3 | |
| 2030 | + movdqa [eax + 30h], xmm7 | |
| 2031 | + movdqa [eax + 40h], xmm5 | |
| 2032 | + movdqa [eax + 50h], xmm1 | |
| 2033 | + movdqa [eax + 60h], xmm6 | |
| 2034 | + movdqa [eax + 70h], xmm0 | |
| 2035 | + | |
| 2036 | + mov esp, ebp | |
| 2037 | + pop ebx | |
| 2038 | + pop ebp | |
| 2039 | + ret | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | +;******************************************************************************************* | |
| 2044 | +; | |
| 2045 | +; void DeblockLumaTransposeV2H_sse2(uint8_t * pPixY, int32_t iStride, uint8_t * pSrc); | |
| 2046 | +; | |
| 2047 | +;******************************************************************************************* | |
| 2048 | + | |
| 2049 | +WELS_EXTERN DeblockLumaTransposeV2H_sse2 | |
| 2050 | + | |
| 2051 | +ALIGN 16 | |
| 2052 | + | |
| 2053 | +DeblockLumaTransposeV2H_sse2: | |
| 2054 | + push ebp | |
| 2055 | + mov ebp, esp | |
| 2056 | + | |
| 2057 | + and esp, 0FFFFFFF0h | |
| 2058 | + sub esp, 10h | |
| 2059 | + | |
| 2060 | + mov eax, [ebp + 10h] | |
| 2061 | + mov ecx, [ebp + 0Ch] | |
| 2062 | + mov edx, [ebp + 08h] | |
| 2063 | + | |
| 2064 | + movdqa xmm0, [eax] | |
| 2065 | + movdqa xmm1, [eax + 10h] | |
| 2066 | + movdqa xmm2, [eax + 20h] | |
| 2067 | + movdqa xmm3, [eax + 30h] | |
| 2068 | + movdqa xmm4, [eax + 40h] | |
| 2069 | + movdqa xmm5, [eax + 50h] | |
| 2070 | + movdqa xmm6, [eax + 60h] | |
| 2071 | + movdqa xmm7, [eax + 70h] | |
| 2072 | + | |
| 2073 | + SSE2_TransTwo8x8B xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, [esp] | |
| 2074 | + ;pOut: m5, m3, m4, m8, m6, m2, m7, m1 | |
| 2075 | + | |
| 2076 | + lea eax, [ecx * 3] | |
| 2077 | + | |
| 2078 | + movq [edx], xmm4 | |
| 2079 | + movq [edx + ecx], xmm2 | |
| 2080 | + movq [edx + ecx*2], xmm3 | |
| 2081 | + movq [edx + eax], xmm7 | |
| 2082 | + | |
| 2083 | + lea edx, [edx + ecx*4] | |
| 2084 | + movq [edx], xmm5 | |
| 2085 | + movq [edx + ecx], xmm1 | |
| 2086 | + movq [edx + ecx*2], xmm6 | |
| 2087 | + movq [edx + eax], xmm0 | |
| 2088 | + | |
| 2089 | + psrldq xmm4, 8 | |
| 2090 | + psrldq xmm2, 8 | |
| 2091 | + psrldq xmm3, 8 | |
| 2092 | + psrldq xmm7, 8 | |
| 2093 | + psrldq xmm5, 8 | |
| 2094 | + psrldq xmm1, 8 | |
| 2095 | + psrldq xmm6, 8 | |
| 2096 | + psrldq xmm0, 8 | |
| 2097 | + | |
| 2098 | + lea edx, [edx + ecx*4] | |
| 2099 | + movq [edx], xmm4 | |
| 2100 | + movq [edx + ecx], xmm2 | |
| 2101 | + movq [edx + ecx*2], xmm3 | |
| 2102 | + movq [edx + eax], xmm7 | |
| 2103 | + | |
| 2104 | + lea edx, [edx + ecx*4] | |
| 2105 | + movq [edx], xmm5 | |
| 2106 | + movq [edx + ecx], xmm1 | |
| 2107 | + movq [edx + ecx*2], xmm6 | |
| 2108 | + movq [edx + eax], xmm0 | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + mov esp, ebp | |
| 2112 | + pop ebp | |
| 2113 | + ret | |
| @@ -0,0 +1,655 @@ | ||
| 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 | +;* expand_picture.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* mmxext/sse for expand_frame | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 09/25/2009 Created | |
| 39 | +;* | |
| 40 | +;* | |
| 41 | +;*************************************************************************/ | |
| 42 | + | |
| 43 | +%include "asm_inc.asm" | |
| 44 | + | |
| 45 | +BITS 32 | |
| 46 | + | |
| 47 | +;*********************************************************************** | |
| 48 | +; Macros and other preprocessor constants | |
| 49 | +;*********************************************************************** | |
| 50 | + | |
| 51 | +;*********************************************************************** | |
| 52 | +; Local Data (Read Only) | |
| 53 | +;*********************************************************************** | |
| 54 | + | |
| 55 | +;SECTION .rodata pData align=16 | |
| 56 | + | |
| 57 | +;*********************************************************************** | |
| 58 | +; Various memory constants (trigonometric values or rounding values) | |
| 59 | +;*********************************************************************** | |
| 60 | +;%define PADDING_SIZE_ASM 32 ; PADDING_LENGTH | |
| 61 | + | |
| 62 | +;*********************************************************************** | |
| 63 | +; Code | |
| 64 | +;*********************************************************************** | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | +SECTION .text | |
| 69 | + | |
| 70 | +;WELS_EXTERN expand_picture_luma_mmx | |
| 71 | +;WELS_EXTERN expand_picture_chroma_mmx | |
| 72 | +WELS_EXTERN ExpandPictureLuma_sse2 | |
| 73 | +WELS_EXTERN ExpandPictureChromaAlign_sse2 ; for chroma alignment | |
| 74 | +WELS_EXTERN ExpandPictureChromaUnalign_sse2 ; for chroma unalignment | |
| 75 | + | |
| 76 | +;;;;;;;expanding result;;;;;;; | |
| 77 | + | |
| 78 | +;aaaa|attttttttttttttttb|bbbb | |
| 79 | +;aaaa|attttttttttttttttb|bbbb | |
| 80 | +;aaaa|attttttttttttttttb|bbbb | |
| 81 | +;aaaa|attttttttttttttttb|bbbb | |
| 82 | +;---------------------------- | |
| 83 | +;aaaa|attttttttttttttttb|bbbb | |
| 84 | +;llll|l r|rrrr | |
| 85 | +;llll|l r|rrrr | |
| 86 | +;llll|l r|rrrr | |
| 87 | +;llll|l r|rrrr | |
| 88 | +;llll|l r|rrrr | |
| 89 | +;cccc|ceeeeeeeeeeeeeeeed|dddd | |
| 90 | +;---------------------------- | |
| 91 | +;cccc|ceeeeeeeeeeeeeeeed|dddd | |
| 92 | +;cccc|ceeeeeeeeeeeeeeeed|dddd | |
| 93 | +;cccc|ceeeeeeeeeeeeeeeed|dddd | |
| 94 | +;cccc|ceeeeeeeeeeeeeeeed|dddd | |
| 95 | + | |
| 96 | +%macro mov_line_8x4_mmx 3 ; dst, stride, mm? | |
| 97 | + movq [%1], %3 | |
| 98 | + movq [%1+%2], %3 | |
| 99 | + lea %1, [%1+2*%2] | |
| 100 | + movq [%1], %3 | |
| 101 | + movq [%1+%2], %3 | |
| 102 | + lea %1, [%1+2*%2] | |
| 103 | +%endmacro | |
| 104 | + | |
| 105 | +%macro mov_line_end8x4_mmx 3 ; dst, stride, mm? | |
| 106 | + movq [%1], %3 | |
| 107 | + movq [%1+%2], %3 | |
| 108 | + lea %1, [%1+2*%2] | |
| 109 | + movq [%1], %3 | |
| 110 | + movq [%1+%2], %3 | |
| 111 | + lea %1, [%1+%2] | |
| 112 | +%endmacro | |
| 113 | + | |
| 114 | +%macro mov_line_16x4_sse2 4 ; dst, stride, xmm?, u/a | |
| 115 | + movdq%4 [%1], %3 ; top(bottom)_0 | |
| 116 | + movdq%4 [%1+%2], %3 ; top(bottom)_1 | |
| 117 | + lea %1, [%1+2*%2] | |
| 118 | + movdq%4 [%1], %3 ; top(bottom)_2 | |
| 119 | + movdq%4 [%1+%2], %3 ; top(bottom)_3 | |
| 120 | + lea %1, [%1+2*%2] | |
| 121 | +%endmacro | |
| 122 | + | |
| 123 | +%macro mov_line_end16x4_sse2 4 ; dst, stride, xmm?, u/a | |
| 124 | + movdq%4 [%1], %3 ; top(bottom)_0 | |
| 125 | + movdq%4 [%1+%2], %3 ; top(bottom)_1 | |
| 126 | + lea %1, [%1+2*%2] | |
| 127 | + movdq%4 [%1], %3 ; top(bottom)_2 | |
| 128 | + movdq%4 [%1+%2], %3 ; top(bottom)_3 | |
| 129 | + lea %1, [%1+%2] | |
| 130 | +%endmacro | |
| 131 | + | |
| 132 | +%macro mov_line_32x4_sse2 3 ; dst, stride, xmm? | |
| 133 | + movdqa [%1], %3 ; top(bottom)_0 | |
| 134 | + movdqa [%1+16], %3 ; top(bottom)_0 | |
| 135 | + movdqa [%1+%2], %3 ; top(bottom)_1 | |
| 136 | + movdqa [%1+%2+16], %3 ; top(bottom)_1 | |
| 137 | + lea %1, [%1+2*%2] | |
| 138 | + movdqa [%1], %3 ; top(bottom)_2 | |
| 139 | + movdqa [%1+16], %3 ; top(bottom)_2 | |
| 140 | + movdqa [%1+%2], %3 ; top(bottom)_3 | |
| 141 | + movdqa [%1+%2+16], %3 ; top(bottom)_3 | |
| 142 | + lea %1, [%1+2*%2] | |
| 143 | +%endmacro | |
| 144 | + | |
| 145 | +%macro mov_line_end32x4_sse2 3 ; dst, stride, xmm? | |
| 146 | + movdqa [%1], %3 ; top(bottom)_0 | |
| 147 | + movdqa [%1+16], %3 ; top(bottom)_0 | |
| 148 | + movdqa [%1+%2], %3 ; top(bottom)_1 | |
| 149 | + movdqa [%1+%2+16], %3 ; top(bottom)_1 | |
| 150 | + lea %1, [%1+2*%2] | |
| 151 | + movdqa [%1], %3 ; top(bottom)_2 | |
| 152 | + movdqa [%1+16], %3 ; top(bottom)_2 | |
| 153 | + movdqa [%1+%2], %3 ; top(bottom)_3 | |
| 154 | + movdqa [%1+%2+16], %3 ; top(bottom)_3 | |
| 155 | + lea %1, [%1+%2] | |
| 156 | +%endmacro | |
| 157 | + | |
| 158 | +%macro exp_top_bottom_sse2 1 ; iPaddingSize [luma(32)/chroma(16)] | |
| 159 | + ; ebx [width/16(8)] | |
| 160 | + ; esi [pSrc+0], edi [pSrc-1], ecx [-stride], 32(16) ; top | |
| 161 | + ; eax [pSrc+(h-1)*stride], ebp [pSrc+(h+31)*stride], 32(16) ; bottom | |
| 162 | + | |
| 163 | +%if %1 == 32 ; for luma | |
| 164 | + sar ebx, 04h ; width / 16(8) pixels | |
| 165 | +.top_bottom_loops: | |
| 166 | + ; top | |
| 167 | + movdqa xmm0, [esi] ; first line of picture pData | |
| 168 | + mov_line_16x4_sse2 edi, ecx, xmm0, a ; dst, stride, xmm? | |
| 169 | + mov_line_16x4_sse2 edi, ecx, xmm0, a | |
| 170 | + mov_line_16x4_sse2 edi, ecx, xmm0, a | |
| 171 | + mov_line_16x4_sse2 edi, ecx, xmm0, a | |
| 172 | + mov_line_16x4_sse2 edi, ecx, xmm0, a ; dst, stride, xmm? | |
| 173 | + mov_line_16x4_sse2 edi, ecx, xmm0, a | |
| 174 | + mov_line_16x4_sse2 edi, ecx, xmm0, a | |
| 175 | + mov_line_end16x4_sse2 edi, ecx, xmm0, a | |
| 176 | + | |
| 177 | + ; bottom | |
| 178 | + movdqa xmm1, [eax] ; last line of picture pData | |
| 179 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a ; dst, stride, xmm? | |
| 180 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a | |
| 181 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a | |
| 182 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a | |
| 183 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a ; dst, stride, xmm? | |
| 184 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a | |
| 185 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a | |
| 186 | + mov_line_end16x4_sse2 ebp, ecx, xmm1, a | |
| 187 | + | |
| 188 | + lea esi, [esi+16] ; top pSrc | |
| 189 | + lea edi, [edi+16] ; top dst | |
| 190 | + lea eax, [eax+16] ; bottom pSrc | |
| 191 | + lea ebp, [ebp+16] ; bottom dst | |
| 192 | + neg ecx ; positive/negative stride need for next loop? | |
| 193 | + | |
| 194 | + dec ebx | |
| 195 | + jnz near .top_bottom_loops | |
| 196 | +%elif %1 == 16 ; for chroma ?? | |
| 197 | + mov edx, ebx | |
| 198 | + sar ebx, 04h ; (width / 16) pixels | |
| 199 | +.top_bottom_loops: | |
| 200 | + ; top | |
| 201 | + movdqa xmm0, [esi] ; first line of picture pData | |
| 202 | + mov_line_16x4_sse2 edi, ecx, xmm0, a ; dst, stride, xmm? | |
| 203 | + mov_line_16x4_sse2 edi, ecx, xmm0, a | |
| 204 | + mov_line_16x4_sse2 edi, ecx, xmm0, a | |
| 205 | + mov_line_end16x4_sse2 edi, ecx, xmm0, a | |
| 206 | + | |
| 207 | + ; bottom | |
| 208 | + movdqa xmm1, [eax] ; last line of picture pData | |
| 209 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a ; dst, stride, xmm? | |
| 210 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a | |
| 211 | + mov_line_16x4_sse2 ebp, ecx, xmm1, a | |
| 212 | + mov_line_end16x4_sse2 ebp, ecx, xmm1, a | |
| 213 | + | |
| 214 | + lea esi, [esi+16] ; top pSrc | |
| 215 | + lea edi, [edi+16] ; top dst | |
| 216 | + lea eax, [eax+16] ; bottom pSrc | |
| 217 | + lea ebp, [ebp+16] ; bottom dst | |
| 218 | + neg ecx ; positive/negative stride need for next loop? | |
| 219 | + | |
| 220 | + dec ebx | |
| 221 | + jnz near .top_bottom_loops | |
| 222 | + | |
| 223 | + ; for remaining 8 bytes | |
| 224 | + and edx, 0fh ; any 8 bytes left? | |
| 225 | + test edx, edx | |
| 226 | + jz near .to_be_continued ; no left to exit here | |
| 227 | + | |
| 228 | + ; top | |
| 229 | + movq mm0, [esi] ; remained 8 byte | |
| 230 | + mov_line_8x4_mmx edi, ecx, mm0 ; dst, stride, mm? | |
| 231 | + mov_line_8x4_mmx edi, ecx, mm0 ; dst, stride, mm? | |
| 232 | + mov_line_8x4_mmx edi, ecx, mm0 ; dst, stride, mm? | |
| 233 | + mov_line_end8x4_mmx edi, ecx, mm0 ; dst, stride, mm? | |
| 234 | + ; bottom | |
| 235 | + movq mm1, [eax] | |
| 236 | + mov_line_8x4_mmx ebp, ecx, mm1 ; dst, stride, mm? | |
| 237 | + mov_line_8x4_mmx ebp, ecx, mm1 ; dst, stride, mm? | |
| 238 | + mov_line_8x4_mmx ebp, ecx, mm1 ; dst, stride, mm? | |
| 239 | + mov_line_end8x4_mmx ebp, ecx, mm1 ; dst, stride, mm? | |
| 240 | + WELSEMMS | |
| 241 | + | |
| 242 | +.to_be_continued: | |
| 243 | +%endif | |
| 244 | +%endmacro | |
| 245 | + | |
| 246 | +%macro exp_left_right_sse2 2 ; iPaddingSize [luma(32)/chroma(16)], u/a | |
| 247 | + ; ecx [height] | |
| 248 | + ; esi [pSrc+0], edi [pSrc-32], edx [stride], 32(16) ; left | |
| 249 | + ; ebx [pSrc+(w-1)], ebp [pSrc+w], 32(16) ; right | |
| 250 | +; xor eax, eax ; for pixel pData (uint8_t) ; make sure eax=0 at least high 24 bits of eax = 0 | |
| 251 | + | |
| 252 | +%if %1 == 32 ; for luma | |
| 253 | +.left_right_loops: | |
| 254 | + ; left | |
| 255 | + mov al, byte [esi] ; pixel pData for left border | |
| 256 | + butterfly_1to16_sse xmm0, xmm1, a ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 257 | + movdqa [edi], xmm0 | |
| 258 | + movdqa [edi+16], xmm0 | |
| 259 | + | |
| 260 | + ; right | |
| 261 | + mov al, byte [ebx] | |
| 262 | + butterfly_1to16_sse xmm1, xmm2, a ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 263 | + movdqa [ebp], xmm1 | |
| 264 | + movdqa [ebp+16], xmm1 | |
| 265 | + | |
| 266 | + lea esi, [esi+edx] ; left pSrc | |
| 267 | + lea edi, [edi+edx] ; left dst | |
| 268 | + lea ebx, [ebx+edx] ; right pSrc | |
| 269 | + lea ebp, [ebp+edx] ; right dst | |
| 270 | + | |
| 271 | + dec ecx | |
| 272 | + jnz near .left_right_loops | |
| 273 | +%elif %1 == 16 ; for chroma ?? | |
| 274 | +.left_right_loops: | |
| 275 | + ; left | |
| 276 | + mov al, byte [esi] ; pixel pData for left border | |
| 277 | + butterfly_1to16_sse xmm0, xmm1, a ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 278 | + movdqa [edi], xmm0 | |
| 279 | + | |
| 280 | + ; right | |
| 281 | + mov al, byte [ebx] | |
| 282 | + butterfly_1to16_sse xmm1, xmm2, a ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 283 | + movdq%2 [ebp], xmm1 ; might not be aligned 16 bytes in case chroma planes | |
| 284 | + | |
| 285 | + lea esi, [esi+edx] ; left pSrc | |
| 286 | + lea edi, [edi+edx] ; left dst | |
| 287 | + lea ebx, [ebx+edx] ; right pSrc | |
| 288 | + lea ebp, [ebp+edx] ; right dst | |
| 289 | + | |
| 290 | + dec ecx | |
| 291 | + jnz near .left_right_loops | |
| 292 | +%endif | |
| 293 | +%endmacro | |
| 294 | + | |
| 295 | +%macro exp_cross_sse2 2 ; iPaddingSize [luma(32)/chroma(16)], u/a | |
| 296 | + ; top-left: (x)mm3, top-right: (x)mm4, bottom-left: (x)mm5, bottom-right: (x)mm6 | |
| 297 | + ; edi: TL, ebp: TR, eax: BL, ebx: BR, ecx, -stride | |
| 298 | +%if %1 == 32 ; luma | |
| 299 | + ; TL | |
| 300 | + mov_line_32x4_sse2 edi, ecx, xmm3 ; dst, stride, xmm? | |
| 301 | + mov_line_32x4_sse2 edi, ecx, xmm3 ; dst, stride, xmm? | |
| 302 | + mov_line_32x4_sse2 edi, ecx, xmm3 ; dst, stride, xmm? | |
| 303 | + mov_line_32x4_sse2 edi, ecx, xmm3 ; dst, stride, xmm? | |
| 304 | + mov_line_32x4_sse2 edi, ecx, xmm3 ; dst, stride, xmm? | |
| 305 | + mov_line_32x4_sse2 edi, ecx, xmm3 ; dst, stride, xmm? | |
| 306 | + mov_line_32x4_sse2 edi, ecx, xmm3 ; dst, stride, xmm? | |
| 307 | + mov_line_end32x4_sse2 edi, ecx, xmm3 ; dst, stride, xmm? | |
| 308 | + | |
| 309 | + ; TR | |
| 310 | + mov_line_32x4_sse2 ebp, ecx, xmm4 ; dst, stride, xmm? | |
| 311 | + mov_line_32x4_sse2 ebp, ecx, xmm4 ; dst, stride, xmm? | |
| 312 | + mov_line_32x4_sse2 ebp, ecx, xmm4 ; dst, stride, xmm? | |
| 313 | + mov_line_32x4_sse2 ebp, ecx, xmm4 ; dst, stride, xmm? | |
| 314 | + mov_line_32x4_sse2 ebp, ecx, xmm4 ; dst, stride, xmm? | |
| 315 | + mov_line_32x4_sse2 ebp, ecx, xmm4 ; dst, stride, xmm? | |
| 316 | + mov_line_32x4_sse2 ebp, ecx, xmm4 ; dst, stride, xmm? | |
| 317 | + mov_line_end32x4_sse2 ebp, ecx, xmm4 ; dst, stride, xmm? | |
| 318 | + | |
| 319 | + ; BL | |
| 320 | + mov_line_32x4_sse2 eax, ecx, xmm5 ; dst, stride, xmm? | |
| 321 | + mov_line_32x4_sse2 eax, ecx, xmm5 ; dst, stride, xmm? | |
| 322 | + mov_line_32x4_sse2 eax, ecx, xmm5 ; dst, stride, xmm? | |
| 323 | + mov_line_32x4_sse2 eax, ecx, xmm5 ; dst, stride, xmm? | |
| 324 | + mov_line_32x4_sse2 eax, ecx, xmm5 ; dst, stride, xmm? | |
| 325 | + mov_line_32x4_sse2 eax, ecx, xmm5 ; dst, stride, xmm? | |
| 326 | + mov_line_32x4_sse2 eax, ecx, xmm5 ; dst, stride, xmm? | |
| 327 | + mov_line_end32x4_sse2 eax, ecx, xmm5 ; dst, stride, xmm? | |
| 328 | + | |
| 329 | + ; BR | |
| 330 | + mov_line_32x4_sse2 ebx, ecx, xmm6 ; dst, stride, xmm? | |
| 331 | + mov_line_32x4_sse2 ebx, ecx, xmm6 ; dst, stride, xmm? | |
| 332 | + mov_line_32x4_sse2 ebx, ecx, xmm6 ; dst, stride, xmm? | |
| 333 | + mov_line_32x4_sse2 ebx, ecx, xmm6 ; dst, stride, xmm? | |
| 334 | + mov_line_32x4_sse2 ebx, ecx, xmm6 ; dst, stride, xmm? | |
| 335 | + mov_line_32x4_sse2 ebx, ecx, xmm6 ; dst, stride, xmm? | |
| 336 | + mov_line_32x4_sse2 ebx, ecx, xmm6 ; dst, stride, xmm? | |
| 337 | + mov_line_end32x4_sse2 ebx, ecx, xmm6 ; dst, stride, xmm? | |
| 338 | +%elif %1 == 16 ; chroma | |
| 339 | + ; TL | |
| 340 | + mov_line_16x4_sse2 edi, ecx, xmm3, a ; dst, stride, xmm? | |
| 341 | + mov_line_16x4_sse2 edi, ecx, xmm3, a ; dst, stride, xmm? | |
| 342 | + mov_line_16x4_sse2 edi, ecx, xmm3, a ; dst, stride, xmm? | |
| 343 | + mov_line_end16x4_sse2 edi, ecx, xmm3, a ; dst, stride, xmm? | |
| 344 | + | |
| 345 | + ; TR | |
| 346 | + mov_line_16x4_sse2 ebp, ecx, xmm4, %2 ; dst, stride, xmm? | |
| 347 | + mov_line_16x4_sse2 ebp, ecx, xmm4, %2 ; dst, stride, xmm? | |
| 348 | + mov_line_16x4_sse2 ebp, ecx, xmm4, %2 ; dst, stride, xmm? | |
| 349 | + mov_line_end16x4_sse2 ebp, ecx, xmm4, %2 ; dst, stride, xmm? | |
| 350 | + | |
| 351 | + ; BL | |
| 352 | + mov_line_16x4_sse2 eax, ecx, xmm5, a ; dst, stride, xmm? | |
| 353 | + mov_line_16x4_sse2 eax, ecx, xmm5, a ; dst, stride, xmm? | |
| 354 | + mov_line_16x4_sse2 eax, ecx, xmm5, a ; dst, stride, xmm? | |
| 355 | + mov_line_end16x4_sse2 eax, ecx, xmm5, a ; dst, stride, xmm? | |
| 356 | + | |
| 357 | + ; BR | |
| 358 | + mov_line_16x4_sse2 ebx, ecx, xmm6, %2 ; dst, stride, xmm? | |
| 359 | + mov_line_16x4_sse2 ebx, ecx, xmm6, %2 ; dst, stride, xmm? | |
| 360 | + mov_line_16x4_sse2 ebx, ecx, xmm6, %2 ; dst, stride, xmm? | |
| 361 | + mov_line_end16x4_sse2 ebx, ecx, xmm6, %2 ; dst, stride, xmm? | |
| 362 | +%endif | |
| 363 | +%endmacro | |
| 364 | + | |
| 365 | +ALIGN 16 | |
| 366 | +;***********************************************************************---------------- | |
| 367 | +; void ExpandPictureLuma_sse2( uint8_t *pDst, | |
| 368 | +; const int32_t kiStride, | |
| 369 | +; const int32_t kiWidth, | |
| 370 | +; const int32_t kiHeight ); | |
| 371 | +;***********************************************************************---------------- | |
| 372 | +ExpandPictureLuma_sse2: | |
| 373 | + push ebx | |
| 374 | + push edx | |
| 375 | + push esi | |
| 376 | + push edi | |
| 377 | + push ebp | |
| 378 | + | |
| 379 | + ; for both top and bottom border | |
| 380 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 381 | + mov esi, [esp+24] ; pDst | |
| 382 | + mov edx, [esp+28] ; kiStride | |
| 383 | + mov ebx, [esp+32] ; kiWidth | |
| 384 | + mov eax, [esp+36] ; kiHeight | |
| 385 | + ; also prepare for cross border pData top-left: xmm3 | |
| 386 | +; xor ecx, ecx | |
| 387 | + mov cl, byte [esi] | |
| 388 | + butterfly_1to16_sse xmm3, xmm4, c ; pDst, tmp, pSrc [generic register name: a/b/c/d] | |
| 389 | + ; load top border | |
| 390 | + mov ecx, edx ; kiStride | |
| 391 | + neg ecx ; -kiStride | |
| 392 | + lea edi, [esi+ecx] ; last line of top border | |
| 393 | + ; load bottom border | |
| 394 | + dec eax ; h-1 | |
| 395 | + imul eax, edx ; (h-1)*kiStride | |
| 396 | + lea eax, [esi+eax] ; last line of picture pData | |
| 397 | + sal edx, 05h ; 32*kiStride | |
| 398 | + lea ebp, [eax+edx] ; last line of bottom border, (h-1)*stride + 32 * stride | |
| 399 | + ; also prepare for cross border pData: bottom-left with xmm5, bottom-right xmm6 | |
| 400 | + dec ebx ; kiWidth-1 | |
| 401 | + lea ebx, [eax+ebx] ; dst[w-1][h-1] | |
| 402 | +; xor edx, edx | |
| 403 | + mov dl, byte [eax] ; bottom-left | |
| 404 | + butterfly_1to16_sse xmm5, xmm6, d ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 405 | + mov dl, byte [ebx] ; bottom-right | |
| 406 | + butterfly_1to16_sse xmm6, xmm4, d ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 407 | + ; for top & bottom expanding | |
| 408 | + mov ebx, [esp+32] ; kiWidth | |
| 409 | + exp_top_bottom_sse2 32 | |
| 410 | + | |
| 411 | + ; for both left and right border | |
| 412 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 413 | + mov esi, [esp+24] ; p_dst: left border pSrc | |
| 414 | + mov edx, [esp+28] ; kiStride | |
| 415 | + mov ebx, [esp+32] ; kiWidth | |
| 416 | + mov ecx, [esp+36] ; kiHeight | |
| 417 | + ; load left border | |
| 418 | + mov eax, -32 ; luma=-32, chroma=-16 | |
| 419 | + lea edi, [esi+eax] ; left border dst | |
| 420 | + dec ebx | |
| 421 | + lea ebx, [esi+ebx] ; right border pSrc, (p_dst + width - 1) | |
| 422 | + lea ebp, [ebx+1] ; right border dst | |
| 423 | + ; prepare for cross border pData: top-right with xmm4 | |
| 424 | +; xor eax, eax | |
| 425 | + mov al, byte [ebx] ; top-right | |
| 426 | + butterfly_1to16_sse xmm4, xmm0, a ; pDst, tmp, pSrc [generic register name: a/b/c/d] | |
| 427 | + ; for left & right border expanding | |
| 428 | + exp_left_right_sse2 32, a | |
| 429 | + | |
| 430 | + ; for cross border [top-left, top-right, bottom-left, bottom-right] | |
| 431 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 432 | + mov esi, [esp+24] ; pDst | |
| 433 | + mov ecx, [esp+28] ; kiStride | |
| 434 | + mov ebx, [esp+32] ; kiWidth | |
| 435 | + mov edx, [esp+36] ; kiHeight | |
| 436 | + ; have done xmm3,..,xmm6 cross pData initialization above, perform pading as below, To be continued.. | |
| 437 | + mov eax, -32 ; luma=-32, chroma=-16 | |
| 438 | + neg ecx ; -stride | |
| 439 | + lea edi, [esi+eax] | |
| 440 | + lea edi, [edi+ecx] ; last line of top-left border | |
| 441 | + lea ebp, [esi+ebx] | |
| 442 | + lea ebp, [ebp+ecx] ; last line of top-right border | |
| 443 | + add edx, 32 ; height+32(16), luma=32, chroma=16 | |
| 444 | + mov ecx, [esp+28] ; kiStride | |
| 445 | + imul edx, ecx ; (height+32(16)) * stride | |
| 446 | + lea eax, [edi+edx] ; last line of bottom-left border | |
| 447 | + lea ebx, [ebp+edx] ; last line of bottom-right border | |
| 448 | + neg ecx ; -kiStride | |
| 449 | + ; for left & right border expanding | |
| 450 | + exp_cross_sse2 32, a | |
| 451 | + | |
| 452 | +; sfence ; commit cache write back memory | |
| 453 | + | |
| 454 | + pop ebp | |
| 455 | + pop edi | |
| 456 | + pop esi | |
| 457 | + pop edx | |
| 458 | + pop ebx | |
| 459 | + | |
| 460 | + ret | |
| 461 | + | |
| 462 | +ALIGN 16 | |
| 463 | +;***********************************************************************---------------- | |
| 464 | +; void ExpandPictureChromaAlign_sse2( uint8_t *pDst, | |
| 465 | +; const int32_t kiStride, | |
| 466 | +; const int32_t kiWidth, | |
| 467 | +; const int32_t kiHeight ); | |
| 468 | +;***********************************************************************---------------- | |
| 469 | +ExpandPictureChromaAlign_sse2: | |
| 470 | + push ebx | |
| 471 | + push edx | |
| 472 | + push esi | |
| 473 | + push edi | |
| 474 | + push ebp | |
| 475 | + | |
| 476 | + ; for both top and bottom border | |
| 477 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 478 | + mov esi, [esp+24] ; pDst | |
| 479 | + mov edx, [esp+28] ; kiStride | |
| 480 | + mov ebx, [esp+32] ; kiWidth | |
| 481 | + mov eax, [esp+36] ; kiHeight | |
| 482 | + ; also prepare for cross border pData top-left: xmm3 | |
| 483 | +; xor ecx, ecx | |
| 484 | + mov cl, byte [esi] | |
| 485 | + butterfly_1to16_sse xmm3, xmm4, c ; pDst, tmp, pSrc [generic register name: a/b/c/d] | |
| 486 | + ; load top border | |
| 487 | + mov ecx, edx ; kiStride | |
| 488 | + neg ecx ; -kiStride | |
| 489 | + lea edi, [esi+ecx] ; last line of top border | |
| 490 | + ; load bottom border | |
| 491 | + dec eax ; h-1 | |
| 492 | + imul eax, edx ; (h-1)*kiStride | |
| 493 | + lea eax, [esi+eax] ; last line of picture pData | |
| 494 | + sal edx, 04h ; 16*kiStride | |
| 495 | + lea ebp, [eax+edx] ; last line of bottom border, (h-1)*kiStride + 16 * kiStride | |
| 496 | + ; also prepare for cross border pData: bottom-left with xmm5, bottom-right xmm6 | |
| 497 | + dec ebx ; kiWidth-1 | |
| 498 | + lea ebx, [eax+ebx] ; pDst[w-1][h-1] | |
| 499 | +; xor edx, edx | |
| 500 | + mov dl, byte [eax] ; bottom-left | |
| 501 | + butterfly_1to16_sse xmm5, xmm6, d ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 502 | + mov dl, byte [ebx] ; bottom-right | |
| 503 | + butterfly_1to16_sse xmm6, xmm4, d ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 504 | + ; for top & bottom expanding | |
| 505 | + mov ebx, [esp+32] ; kiWidth | |
| 506 | + exp_top_bottom_sse2 16 | |
| 507 | + | |
| 508 | + ; for both left and right border | |
| 509 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 510 | + mov esi, [esp+24] ; pDst: left border pSrc | |
| 511 | + mov edx, [esp+28] ; kiStride | |
| 512 | + mov ebx, [esp+32] ; kiWidth | |
| 513 | + mov ecx, [esp+36] ; kiHeight | |
| 514 | + ; load left border | |
| 515 | + mov eax, -16 ; luma=-32, chroma=-16 | |
| 516 | + lea edi, [esi+eax] ; left border dst | |
| 517 | + dec ebx | |
| 518 | + lea ebx, [esi+ebx] ; right border pSrc, (p_dst + width - 1) | |
| 519 | + lea ebp, [ebx+1] ; right border dst | |
| 520 | + ; prepare for cross border pData: top-right with xmm4 | |
| 521 | +; xor eax, eax | |
| 522 | + mov al, byte [ebx] ; top-right | |
| 523 | + butterfly_1to16_sse xmm4, xmm0, a ; pDst, tmp, pSrc [generic register name: a/b/c/d] | |
| 524 | + ; for left & right border expanding | |
| 525 | + exp_left_right_sse2 16, a | |
| 526 | + | |
| 527 | + ; for cross border [top-left, top-right, bottom-left, bottom-right] | |
| 528 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 529 | + mov esi, [esp+24] ; pDst | |
| 530 | + mov ecx, [esp+28] ; kiStride | |
| 531 | + mov ebx, [esp+32] ; kiWidth | |
| 532 | + mov edx, [esp+36] ; kiHeight | |
| 533 | + ; have done xmm3,..,xmm6 cross pData initialization above, perform pading as below, To be continued.. | |
| 534 | + mov eax, -16 ; chroma=-16 | |
| 535 | + neg ecx ; -stride | |
| 536 | + lea edi, [esi+eax] | |
| 537 | + lea edi, [edi+ecx] ; last line of top-left border | |
| 538 | + lea ebp, [esi+ebx] | |
| 539 | + lea ebp, [ebp+ecx] ; last line of top-right border | |
| 540 | + mov ecx, [esp+28] ; kiStride | |
| 541 | + add edx, 16 ; height+16, luma=32, chroma=16 | |
| 542 | + imul edx, ecx ; (kiHeight+16) * kiStride | |
| 543 | + lea eax, [edi+edx] ; last line of bottom-left border | |
| 544 | + lea ebx, [ebp+edx] ; last line of bottom-right border | |
| 545 | + neg ecx ; -kiStride | |
| 546 | + ; for left & right border expanding | |
| 547 | + exp_cross_sse2 16, a | |
| 548 | + | |
| 549 | +; sfence ; commit cache write back memory | |
| 550 | + | |
| 551 | + pop ebp | |
| 552 | + pop edi | |
| 553 | + pop esi | |
| 554 | + pop edx | |
| 555 | + pop ebx | |
| 556 | + | |
| 557 | + ret | |
| 558 | + | |
| 559 | +ALIGN 16 | |
| 560 | +;***********************************************************************---------------- | |
| 561 | +; void ExpandPictureChromaUnalign_sse2( uint8_t *pDst, | |
| 562 | +; const int32_t kiStride, | |
| 563 | +; const int32_t kiWidth, | |
| 564 | +; const int32_t kiHeight ); | |
| 565 | +;***********************************************************************---------------- | |
| 566 | +ExpandPictureChromaUnalign_sse2: | |
| 567 | + push ebx | |
| 568 | + push edx | |
| 569 | + push esi | |
| 570 | + push edi | |
| 571 | + push ebp | |
| 572 | + | |
| 573 | + ; for both top and bottom border | |
| 574 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 575 | + mov esi, [esp+24] ; pDst | |
| 576 | + mov edx, [esp+28] ; kiStride | |
| 577 | + mov ebx, [esp+32] ; kiWidth | |
| 578 | + mov eax, [esp+36] ; kiHeight | |
| 579 | + ; also prepare for cross border pData top-left: xmm3 | |
| 580 | +; xor ecx, ecx | |
| 581 | + mov cl, byte [esi] | |
| 582 | + butterfly_1to16_sse xmm3, xmm4, c ; pDst, tmp, pSrc [generic register name: a/b/c/d] | |
| 583 | + ; load top border | |
| 584 | + mov ecx, edx ; kiStride | |
| 585 | + neg ecx ; -kiStride | |
| 586 | + lea edi, [esi+ecx] ; last line of top border | |
| 587 | + ; load bottom border | |
| 588 | + dec eax ; h-1 | |
| 589 | + imul eax, edx ; (h-1)*kiStride | |
| 590 | + lea eax, [esi+eax] ; last line of picture pData | |
| 591 | + sal edx, 04h ; 16*kiStride | |
| 592 | + lea ebp, [eax+edx] ; last line of bottom border, (h-1)*kiStride + 16 * kiStride | |
| 593 | + ; also prepare for cross border pData: bottom-left with xmm5, bottom-right xmm6 | |
| 594 | + dec ebx ; kiWidth-1 | |
| 595 | + lea ebx, [eax+ebx] ; dst[w-1][h-1] | |
| 596 | +; xor edx, edx | |
| 597 | + mov dl, byte [eax] ; bottom-left | |
| 598 | + butterfly_1to16_sse xmm5, xmm6, d ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 599 | + mov dl, byte [ebx] ; bottom-right | |
| 600 | + butterfly_1to16_sse xmm6, xmm4, d ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 601 | + ; for top & bottom expanding | |
| 602 | + mov ebx, [esp+32] ; kiWidth | |
| 603 | + exp_top_bottom_sse2 16 | |
| 604 | + | |
| 605 | + ; for both left and right border | |
| 606 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 607 | + mov esi, [esp+24] ; p_dst: left border pSrc | |
| 608 | + mov edx, [esp+28] ; kiStride | |
| 609 | + mov ebx, [esp+32] ; kiWidth | |
| 610 | + mov ecx, [esp+36] ; kiHeight | |
| 611 | + ; load left border | |
| 612 | + mov eax, -16 ; luma=-32, chroma=-16 | |
| 613 | + lea edi, [esi+eax] ; left border dst | |
| 614 | + dec ebx | |
| 615 | + lea ebx, [esi+ebx] ; right border pSrc, (p_dst + width - 1) | |
| 616 | + lea ebp, [ebx+1] ; right border dst | |
| 617 | + ; prepare for cross border pData: top-right with xmm4 | |
| 618 | +; xor eax, eax | |
| 619 | + mov al, byte [ebx] ; top-right | |
| 620 | + butterfly_1to16_sse xmm4, xmm0, a ; dst, tmp, pSrc [generic register name: a/b/c/d] | |
| 621 | + ; for left & right border expanding | |
| 622 | + exp_left_right_sse2 16, u | |
| 623 | + | |
| 624 | + ; for cross border [top-left, top-right, bottom-left, bottom-right] | |
| 625 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 626 | + mov esi, [esp+24] ; p_dst | |
| 627 | + mov ecx, [esp+28] ; kiStride | |
| 628 | + mov ebx, [esp+32] ; kiWidth | |
| 629 | + mov edx, [esp+36] ; kiHeight | |
| 630 | + ; have done xmm3,..,xmm6 cross pData initialization above, perform pading as below, To be continued.. | |
| 631 | + neg ecx ; -kiStride | |
| 632 | + mov eax, -16 ; chroma=-16 | |
| 633 | + lea edi, [esi+eax] | |
| 634 | + lea edi, [edi+ecx] ; last line of top-left border | |
| 635 | + lea ebp, [esi+ebx] | |
| 636 | + lea ebp, [ebp+ecx] ; last line of top-right border | |
| 637 | + mov ecx, [esp+28] ; kiStride | |
| 638 | + add edx, 16 ; kiHeight+16, luma=32, chroma=16 | |
| 639 | + imul edx, ecx ; (kiHeight+16) * kiStride | |
| 640 | + lea eax, [edi+edx] ; last line of bottom-left border | |
| 641 | + lea ebx, [ebp+edx] ; last line of bottom-right border | |
| 642 | + neg ecx ; -kiStride | |
| 643 | + ; for left & right border expanding | |
| 644 | + exp_cross_sse2 16, u | |
| 645 | + | |
| 646 | +; sfence ; commit cache write back memory | |
| 647 | + | |
| 648 | + pop ebp | |
| 649 | + pop edi | |
| 650 | + pop esi | |
| 651 | + pop edx | |
| 652 | + pop ebx | |
| 653 | + | |
| 654 | + ret | |
| 655 | + | |
| @@ -0,0 +1,1498 @@ | ||
| 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 | +;* intra_pred.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* sse2 and mmx function for intra predict operations(decoder) | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 18/09/2009 Created | |
| 39 | +;* 19/11/2010 Added | |
| 40 | +;* WelsI16x16LumaPredDcTop_sse2, WelsI16x16LumaPredDcNA_sse2, | |
| 41 | +;* WelsIChromaPredDcLeft_mmx, WelsIChromaPredDcTop_sse2 | |
| 42 | +;* and WelsIChromaPredDcNA_mmx | |
| 43 | +;* | |
| 44 | +;* | |
| 45 | +;*************************************************************************/ | |
| 46 | + | |
| 47 | +%include "asm_inc.asm" | |
| 48 | +BITS 32 | |
| 49 | +;******************************************************************************* | |
| 50 | +; Local Data (Read Only) | |
| 51 | +;******************************************************************************* | |
| 52 | + | |
| 53 | +%ifdef FORMAT_COFF | |
| 54 | +SECTION .rodata data | |
| 55 | +%else | |
| 56 | +SECTION .rodata align=16 | |
| 57 | +%endif | |
| 58 | +%if 1 | |
| 59 | + %define WELSEMMS emms | |
| 60 | +%else | |
| 61 | + %define WELSEMMS | |
| 62 | +%endif | |
| 63 | + | |
| 64 | +align 16 | |
| 65 | +sse2_plane_inc_minus dw -7, -6, -5, -4, -3, -2, -1, 0 | |
| 66 | +align 16 | |
| 67 | +sse2_plane_inc dw 1, 2, 3, 4, 5, 6, 7, 8 | |
| 68 | +align 16 | |
| 69 | +sse2_plane_dec dw 8, 7, 6, 5, 4, 3, 2, 1 | |
| 70 | + | |
| 71 | +; for chroma plane mode | |
| 72 | +sse2_plane_inc_c dw 1, 2, 3, 4 | |
| 73 | +sse2_plane_dec_c dw 4, 3, 2, 1 | |
| 74 | +align 16 | |
| 75 | +sse2_plane_mul_b_c dw -3, -2, -1, 0, 1, 2, 3, 4 | |
| 76 | + | |
| 77 | +align 16 | |
| 78 | +mmx_01bytes: times 16 db 1 | |
| 79 | + | |
| 80 | +align 16 | |
| 81 | +mmx_0x02: dw 0x02, 0x00, 0x00, 0x00 | |
| 82 | + | |
| 83 | +align 16 | |
| 84 | +sse2_dc_0x80: times 16 db 0x80 | |
| 85 | +align 16 | |
| 86 | +sse2_wd_0x02: times 8 dw 0x02 | |
| 87 | + | |
| 88 | +;******************************************************************************* | |
| 89 | +; macros | |
| 90 | +;******************************************************************************* | |
| 91 | +;xmm0, xmm1, xmm2, eax, ecx | |
| 92 | +;lower 64 bits of xmm0 save the result | |
| 93 | +%macro SSE2_PRED_H_4X4_TWO_LINE 5 | |
| 94 | + movd %1, [%4-1] | |
| 95 | + movdqa %3, %1 | |
| 96 | + punpcklbw %1, %3 | |
| 97 | + movdqa %3, %1 | |
| 98 | + punpcklbw %1, %3 | |
| 99 | + | |
| 100 | + ;add %4, %5 | |
| 101 | + movd %2, [%4+%5-1] | |
| 102 | + movdqa %3, %2 | |
| 103 | + punpcklbw %2, %3 | |
| 104 | + movdqa %3, %2 | |
| 105 | + punpcklbw %2, %3 | |
| 106 | + punpckldq %1, %2 | |
| 107 | +%endmacro | |
| 108 | + | |
| 109 | + | |
| 110 | +%macro LOAD_COLUMN 6 | |
| 111 | + movd %1, [%5] | |
| 112 | + movd %2, [%5+%6] | |
| 113 | + punpcklbw %1, %2 | |
| 114 | + lea %5, [%5+2*%6] | |
| 115 | + movd %3, [%5] | |
| 116 | + movd %2, [%5+%6] | |
| 117 | + punpcklbw %3, %2 | |
| 118 | + punpcklwd %1, %3 | |
| 119 | + lea %5, [%5+2*%6] | |
| 120 | + movd %4, [%5] | |
| 121 | + movd %2, [%5+%6] | |
| 122 | + punpcklbw %4, %2 | |
| 123 | + lea %5, [%5+2*%6] | |
| 124 | + movd %3, [%5] | |
| 125 | + movd %2, [%5+%6] | |
| 126 | + lea %5, [%5+2*%6] | |
| 127 | + punpcklbw %3, %2 | |
| 128 | + punpcklwd %4, %3 | |
| 129 | + punpckhdq %1, %4 | |
| 130 | +%endmacro | |
| 131 | + | |
| 132 | +%macro SUMW_HORIZON 3 | |
| 133 | + movhlps %2, %1 ; x2 = xx xx xx xx d7 d6 d5 d4 | |
| 134 | + paddw %1, %2 ; x1 = xx xx xx xx d37 d26 d15 d04 | |
| 135 | + punpcklwd %1, %3 ; x1 = d37 d26 d15 d04 | |
| 136 | + movhlps %2, %1 ; x2 = xxxx xxxx d37 d26 | |
| 137 | + paddd %1, %2 ; x1 = xxxx xxxx d1357 d0246 | |
| 138 | + pshuflw %2, %1, 0x4e ; x2 = xxxx xxxx d0246 d1357 | |
| 139 | + paddd %1, %2 ; x1 = xxxx xxxx xxxx d01234567 | |
| 140 | +%endmacro | |
| 141 | + | |
| 142 | +%macro COPY_16_TIMES 2 | |
| 143 | + movdqa %2, [%1-16] | |
| 144 | + psrldq %2, 15 | |
| 145 | + pmuludq %2, [mmx_01bytes] | |
| 146 | + pshufd %2, %2, 0 | |
| 147 | +%endmacro | |
| 148 | + | |
| 149 | +%macro COPY_16_TIMESS 3 | |
| 150 | + movdqa %2, [%1+%3-16] | |
| 151 | + psrldq %2, 15 | |
| 152 | + pmuludq %2, [mmx_01bytes] | |
| 153 | + pshufd %2, %2, 0 | |
| 154 | +%endmacro | |
| 155 | + | |
| 156 | +%macro LOAD_COLUMN_C 6 | |
| 157 | + movd %1, [%5] | |
| 158 | + movd %2, [%5+%6] | |
| 159 | + punpcklbw %1,%2 | |
| 160 | + lea %5, [%5+2*%6] | |
| 161 | + movd %3, [%5] | |
| 162 | + movd %2, [%5+%6] | |
| 163 | + punpcklbw %3, %2 | |
| 164 | + punpckhwd %1, %3 | |
| 165 | + lea %5, [%5+2*%6] | |
| 166 | +%endmacro | |
| 167 | + | |
| 168 | +%macro LOAD_2_LEFT_AND_ADD 0 | |
| 169 | + lea eax, [eax+2*ecx] | |
| 170 | + movzx edx, byte [eax-0x01] | |
| 171 | + add ebx, edx | |
| 172 | + movzx edx, byte [eax+ecx-0x01] | |
| 173 | + add ebx, edx | |
| 174 | +%endmacro | |
| 175 | + | |
| 176 | +;******************************************************************************* | |
| 177 | +; Code | |
| 178 | +;******************************************************************************* | |
| 179 | + | |
| 180 | +SECTION .text | |
| 181 | +WELS_EXTERN WelsI4x4LumaPredH_sse2 | |
| 182 | +WELS_EXTERN WelsI4x4LumaPredDDR_mmx | |
| 183 | +WELS_EXTERN WelsI16x16LumaPredPlane_sse2 | |
| 184 | +WELS_EXTERN WelsI4x4LumaPredDc_sse2 | |
| 185 | + | |
| 186 | +ALIGN 16 | |
| 187 | +;******************************************************************************* | |
| 188 | +; void_t __cdecl WelsI4x4LumaPredH_sse2(uint8_t *pPred, const int32_t kiStride) | |
| 189 | +; | |
| 190 | +; pPred must align to 16 | |
| 191 | +;******************************************************************************* | |
| 192 | +WelsI4x4LumaPredH_sse2: | |
| 193 | + mov eax, [esp+4] ;pPred | |
| 194 | + mov ecx, [esp+8] ;kiStride | |
| 195 | + | |
| 196 | + movzx edx, byte [eax-1] | |
| 197 | + movd xmm0, edx | |
| 198 | + pmuludq xmm0, [mmx_01bytes] | |
| 199 | + | |
| 200 | + movzx edx, byte [eax+ecx-1] | |
| 201 | + movd xmm1, edx | |
| 202 | + pmuludq xmm1, [mmx_01bytes] | |
| 203 | + | |
| 204 | + lea eax, [eax+ecx] | |
| 205 | + movzx edx, byte [eax+ecx-1] | |
| 206 | + movd xmm2, edx | |
| 207 | + pmuludq xmm2, [mmx_01bytes] | |
| 208 | + | |
| 209 | + movzx edx, byte [eax+2*ecx-1] | |
| 210 | + movd xmm3, edx | |
| 211 | + pmuludq xmm3, [mmx_01bytes] | |
| 212 | + | |
| 213 | + sub eax, ecx | |
| 214 | + movd [eax], xmm0 | |
| 215 | + movd [eax+ecx], xmm1 | |
| 216 | + lea eax, [eax+2*ecx] | |
| 217 | + movd [eax], xmm2 | |
| 218 | + movd [eax+ecx], xmm3 | |
| 219 | + | |
| 220 | + ret | |
| 221 | + | |
| 222 | +;******************************************************************************* | |
| 223 | +; void_t WelsI16x16LumaPredPlane_sse2(uint8_t *pPred, const int32_t kiStride); | |
| 224 | +;******************************************************************************* | |
| 225 | +WelsI16x16LumaPredPlane_sse2: | |
| 226 | +%define pushsize 4 | |
| 227 | + push esi | |
| 228 | + mov esi, [esp + pushsize + 4] | |
| 229 | + mov ecx, [esp + pushsize + 8] | |
| 230 | + sub esi, 1 | |
| 231 | + sub esi, ecx | |
| 232 | + | |
| 233 | + ;for H | |
| 234 | + pxor xmm7, xmm7 | |
| 235 | + movq xmm0, [esi] | |
| 236 | + movdqa xmm5, [sse2_plane_dec] | |
| 237 | + punpcklbw xmm0, xmm7 | |
| 238 | + pmullw xmm0, xmm5 | |
| 239 | + movq xmm1, [esi + 9] | |
| 240 | + movdqa xmm6, [sse2_plane_inc] | |
| 241 | + punpcklbw xmm1, xmm7 | |
| 242 | + pmullw xmm1, xmm6 | |
| 243 | + psubw xmm1, xmm0 | |
| 244 | + | |
| 245 | + SUMW_HORIZON xmm1,xmm0,xmm2 | |
| 246 | + movd eax, xmm1 ; H += (i + 1) * (top[8 + i] - top[6 - i]); | |
| 247 | + movsx eax, ax | |
| 248 | + imul eax, 5 | |
| 249 | + add eax, 32 | |
| 250 | + sar eax, 6 ; b = (5 * H + 32) >> 6; | |
| 251 | + SSE2_Copy8Times xmm1, eax ; xmm1 = b,b,b,b,b,b,b,b | |
| 252 | + | |
| 253 | + movzx edx, BYTE [esi+16] | |
| 254 | + sub esi, 3 | |
| 255 | + LOAD_COLUMN xmm0, xmm2, xmm3, xmm4, esi, ecx | |
| 256 | + | |
| 257 | + add esi, 3 | |
| 258 | + movzx eax, BYTE [esi+8*ecx] | |
| 259 | + add edx, eax | |
| 260 | + shl edx, 4 ; a = (left[15*kiStride] + top[15]) << 4; | |
| 261 | + | |
| 262 | + sub esi, 3 | |
| 263 | + add esi, ecx | |
| 264 | + LOAD_COLUMN xmm7, xmm2, xmm3, xmm4, esi, ecx | |
| 265 | + pxor xmm4, xmm4 | |
| 266 | + punpckhbw xmm0, xmm4 | |
| 267 | + pmullw xmm0, xmm5 | |
| 268 | + punpckhbw xmm7, xmm4 | |
| 269 | + pmullw xmm7, xmm6 | |
| 270 | + psubw xmm7, xmm0 | |
| 271 | + | |
| 272 | + SUMW_HORIZON xmm7,xmm0,xmm2 | |
| 273 | + movd eax, xmm7 ; V | |
| 274 | + movsx eax, ax | |
| 275 | + | |
| 276 | + imul eax, 5 | |
| 277 | + add eax, 32 | |
| 278 | + sar eax, 6 ; c = (5 * V + 32) >> 6; | |
| 279 | + SSE2_Copy8Times xmm4, eax ; xmm4 = c,c,c,c,c,c,c,c | |
| 280 | + | |
| 281 | + mov esi, [esp + pushsize + 4] | |
| 282 | + add edx, 16 | |
| 283 | + imul eax, -7 | |
| 284 | + add edx, eax ; s = a + 16 + (-7)*c | |
| 285 | + SSE2_Copy8Times xmm0, edx ; xmm0 = s,s,s,s,s,s,s,s | |
| 286 | + | |
| 287 | + xor eax, eax | |
| 288 | + movdqa xmm5, [sse2_plane_inc_minus] | |
| 289 | + | |
| 290 | +get_i16x16_luma_pred_plane_sse2_1: | |
| 291 | + movdqa xmm2, xmm1 | |
| 292 | + pmullw xmm2, xmm5 | |
| 293 | + paddw xmm2, xmm0 | |
| 294 | + psraw xmm2, 5 | |
| 295 | + movdqa xmm3, xmm1 | |
| 296 | + pmullw xmm3, xmm6 | |
| 297 | + paddw xmm3, xmm0 | |
| 298 | + psraw xmm3, 5 | |
| 299 | + packuswb xmm2, xmm3 | |
| 300 | + movdqa [esi], xmm2 | |
| 301 | + paddw xmm0, xmm4 | |
| 302 | + add esi, ecx | |
| 303 | + inc eax | |
| 304 | + cmp eax, 16 | |
| 305 | + jnz get_i16x16_luma_pred_plane_sse2_1 | |
| 306 | + | |
| 307 | + pop esi | |
| 308 | + ret | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | +;******************************************************************************* | |
| 313 | +; void_t WelsI16x16LumaPredH_sse2(uint8_t *pPred, const int32_t kiStride); | |
| 314 | +;******************************************************************************* | |
| 315 | + | |
| 316 | +%macro SSE2_PRED_H_16X16_TWO_LINE_DEC 0 | |
| 317 | + lea eax, [eax+ecx*2] | |
| 318 | + | |
| 319 | + COPY_16_TIMES eax, xmm0 | |
| 320 | + movdqa [eax], xmm0 | |
| 321 | + COPY_16_TIMESS eax, xmm0, ecx | |
| 322 | + movdqa [eax+ecx], xmm0 | |
| 323 | +%endmacro | |
| 324 | + | |
| 325 | +WELS_EXTERN WelsI16x16LumaPredH_sse2 | |
| 326 | +WelsI16x16LumaPredH_sse2: | |
| 327 | + mov eax, [esp+4] ; pPred | |
| 328 | + mov ecx, [esp+8] ; kiStride | |
| 329 | + | |
| 330 | + COPY_16_TIMES eax, xmm0 | |
| 331 | + movdqa [eax], xmm0 | |
| 332 | + COPY_16_TIMESS eax, xmm0, ecx | |
| 333 | + movdqa [eax+ecx], xmm0 | |
| 334 | + | |
| 335 | + SSE2_PRED_H_16X16_TWO_LINE_DEC | |
| 336 | + SSE2_PRED_H_16X16_TWO_LINE_DEC | |
| 337 | + SSE2_PRED_H_16X16_TWO_LINE_DEC | |
| 338 | + SSE2_PRED_H_16X16_TWO_LINE_DEC | |
| 339 | + SSE2_PRED_H_16X16_TWO_LINE_DEC | |
| 340 | + SSE2_PRED_H_16X16_TWO_LINE_DEC | |
| 341 | + SSE2_PRED_H_16X16_TWO_LINE_DEC | |
| 342 | + | |
| 343 | + ret | |
| 344 | + | |
| 345 | +;******************************************************************************* | |
| 346 | +; void_t WelsI16x16LumaPredV_sse2(uint8_t *pPred, const int32_t kiStride); | |
| 347 | +;******************************************************************************* | |
| 348 | +WELS_EXTERN WelsI16x16LumaPredV_sse2 | |
| 349 | +WelsI16x16LumaPredV_sse2: | |
| 350 | + mov edx, [esp+4] ; pPred | |
| 351 | + mov ecx, [esp+8] ; kiStride | |
| 352 | + | |
| 353 | + sub edx, ecx | |
| 354 | + movdqa xmm0, [edx] | |
| 355 | + | |
| 356 | + movdqa [edx+ecx], xmm0 | |
| 357 | + lea edx, [edx+2*ecx] | |
| 358 | + movdqa [edx], xmm0 | |
| 359 | + movdqa [edx+ecx], xmm0 | |
| 360 | + lea edx, [edx+2*ecx] | |
| 361 | + movdqa [edx], xmm0 | |
| 362 | + movdqa [edx+ecx], xmm0 | |
| 363 | + lea edx, [edx+2*ecx] | |
| 364 | + movdqa [edx], xmm0 | |
| 365 | + movdqa [edx+ecx], xmm0 | |
| 366 | + lea edx, [edx+2*ecx] | |
| 367 | + movdqa [edx], xmm0 | |
| 368 | + movdqa [edx+ecx], xmm0 | |
| 369 | + lea edx, [edx+2*ecx] | |
| 370 | + movdqa [edx], xmm0 | |
| 371 | + movdqa [edx+ecx], xmm0 | |
| 372 | + lea edx, [edx+2*ecx] | |
| 373 | + movdqa [edx], xmm0 | |
| 374 | + movdqa [edx+ecx], xmm0 | |
| 375 | + lea edx, [edx+2*ecx] | |
| 376 | + movdqa [edx], xmm0 | |
| 377 | + movdqa [edx+ecx], xmm0 | |
| 378 | + lea edx, [edx+2*ecx] | |
| 379 | + movdqa [edx], xmm0 | |
| 380 | + | |
| 381 | + ret | |
| 382 | + | |
| 383 | +;******************************************************************************* | |
| 384 | +; void_t WelsIChromaPredPlane_sse2(uint8_t *pPred, const int32_t kiStride); | |
| 385 | +;******************************************************************************* | |
| 386 | +WELS_EXTERN WelsIChromaPredPlane_sse2 | |
| 387 | +WelsIChromaPredPlane_sse2: | |
| 388 | +%define pushsize 4 | |
| 389 | + push esi | |
| 390 | + mov esi, [esp + pushsize + 4] ;pPred | |
| 391 | + mov ecx, [esp + pushsize + 8] ;kiStride | |
| 392 | + sub esi, 1 | |
| 393 | + sub esi, ecx | |
| 394 | + | |
| 395 | + pxor mm7, mm7 | |
| 396 | + movq mm0, [esi] | |
| 397 | + movq mm5, [sse2_plane_dec_c] | |
| 398 | + punpcklbw mm0, mm7 | |
| 399 | + pmullw mm0, mm5 | |
| 400 | + movq mm1, [esi + 5] | |
| 401 | + movq mm6, [sse2_plane_inc_c] | |
| 402 | + punpcklbw mm1, mm7 | |
| 403 | + pmullw mm1, mm6 | |
| 404 | + psubw mm1, mm0 | |
| 405 | + | |
| 406 | + movq2dq xmm1, mm1 | |
| 407 | + pxor xmm2, xmm2 | |
| 408 | + SUMW_HORIZON xmm1,xmm0,xmm2 | |
| 409 | + movd eax, xmm1 | |
| 410 | + movsx eax, ax | |
| 411 | + imul eax, 17 | |
| 412 | + add eax, 16 | |
| 413 | + sar eax, 5 ; b = (17 * H + 16) >> 5; | |
| 414 | + SSE2_Copy8Times xmm1, eax ; mm1 = b,b,b,b,b,b,b,b | |
| 415 | + | |
| 416 | + movzx edx, BYTE [esi+8] | |
| 417 | + sub esi, 3 | |
| 418 | + LOAD_COLUMN_C mm0, mm2, mm3, mm4, esi, ecx | |
| 419 | + | |
| 420 | + add esi, 3 | |
| 421 | + movzx eax, BYTE [esi+4*ecx] | |
| 422 | + add edx, eax | |
| 423 | + shl edx, 4 ; a = (left[7*kiStride] + top[7]) << 4; | |
| 424 | + | |
| 425 | + sub esi, 3 | |
| 426 | + add esi, ecx | |
| 427 | + LOAD_COLUMN_C mm7, mm2, mm3, mm4, esi, ecx | |
| 428 | + pxor mm4, mm4 | |
| 429 | + punpckhbw mm0, mm4 | |
| 430 | + pmullw mm0, mm5 | |
| 431 | + punpckhbw mm7, mm4 | |
| 432 | + pmullw mm7, mm6 | |
| 433 | + psubw mm7, mm0 | |
| 434 | + | |
| 435 | + movq2dq xmm7, mm7 | |
| 436 | + pxor xmm2, xmm2 | |
| 437 | + SUMW_HORIZON xmm7,xmm0,xmm2 | |
| 438 | + movd eax, xmm7 ; V | |
| 439 | + movsx eax, ax | |
| 440 | + | |
| 441 | + imul eax, 17 | |
| 442 | + add eax, 16 | |
| 443 | + sar eax, 5 ; c = (17 * V + 16) >> 5; | |
| 444 | + SSE2_Copy8Times xmm4, eax ; mm4 = c,c,c,c,c,c,c,c | |
| 445 | + | |
| 446 | + mov esi, [esp + pushsize + 4] | |
| 447 | + add edx, 16 | |
| 448 | + imul eax, -3 | |
| 449 | + add edx, eax ; s = a + 16 + (-3)*c | |
| 450 | + SSE2_Copy8Times xmm0, edx ; xmm0 = s,s,s,s,s,s,s,s | |
| 451 | + | |
| 452 | + xor eax, eax | |
| 453 | + movdqa xmm5, [sse2_plane_mul_b_c] | |
| 454 | + | |
| 455 | +get_i_chroma_pred_plane_sse2_1: | |
| 456 | + movdqa xmm2, xmm1 | |
| 457 | + pmullw xmm2, xmm5 | |
| 458 | + paddw xmm2, xmm0 | |
| 459 | + psraw xmm2, 5 | |
| 460 | + packuswb xmm2, xmm2 | |
| 461 | + movq [esi], xmm2 | |
| 462 | + paddw xmm0, xmm4 | |
| 463 | + add esi, ecx | |
| 464 | + inc eax | |
| 465 | + cmp eax, 8 | |
| 466 | + jnz get_i_chroma_pred_plane_sse2_1 | |
| 467 | + | |
| 468 | + pop esi | |
| 469 | + WELSEMMS | |
| 470 | + ret | |
| 471 | + | |
| 472 | +ALIGN 16 | |
| 473 | +;******************************************************************************* | |
| 474 | +; 0 |1 |2 |3 |4 | | |
| 475 | +; 6 |7 |8 |9 |10| | |
| 476 | +; 11|12|13|14|15| | |
| 477 | +; 16|17|18|19|20| | |
| 478 | +; 21|22|23|24|25| | |
| 479 | +; 7 is the start pixel of current 4x4 block | |
| 480 | +; pPred[7] = ([6]+[0]*2+[1]+2)/4 | |
| 481 | +; | |
| 482 | +; void_t __cdecl WelsI4x4LumaPredDDR_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 483 | +; | |
| 484 | +;******************************************************************************* | |
| 485 | +WelsI4x4LumaPredDDR_mmx: | |
| 486 | + mov edx,[esp+4] ;pPred | |
| 487 | + mov eax,edx | |
| 488 | + mov ecx,[esp+8] ;kiStride | |
| 489 | + | |
| 490 | + movq mm1,[eax+ecx-8] ;get value of 11,decreasing 8 is trying to improve the performance of movq mm1[8] = 11 | |
| 491 | + movq mm2,[eax-8] ;get value of 6 mm2[8] = 6 | |
| 492 | + sub eax, ecx ;mov eax to above line of current block(postion of 1) | |
| 493 | + punpckhbw mm2,[eax-8] ;mm2[8](high 8th byte of mm2) = [0](value of 0), mm2[7]= [6] | |
| 494 | + movd mm3,[eax] ;get value 1, mm3[1] = [1],mm3[2]=[2],mm3[3]=[3] | |
| 495 | + punpckhwd mm1,mm2 ;mm1[8]=[0],mm1[7]=[6],mm1[6]=[11] | |
| 496 | + psllq mm3,18h ;mm3[5]=[1] | |
| 497 | + psrlq mm1,28h ;mm1[3]=[0],mm1[2]=[6],mm1[1]=[11] | |
| 498 | + por mm3,mm1 ;mm3[6]=[3],mm3[5]=[2],mm3[4]=[1],mm3[3]=[0],mm3[2]=[6],mm3[1]=[11] | |
| 499 | + movq mm1,mm3 ;mm1[6]=[3],mm1[5]=[2],mm1[4]=[1],mm1[3]=[0],mm1[2]=[6],mm1[1]=[11] | |
| 500 | + lea eax,[eax+ecx*2-8h] ;set eax point to 12 | |
| 501 | + movq mm4,[eax+ecx] ;get value of 16, mm4[8]=[16] | |
| 502 | + psllq mm3,8 ;mm3[7]=[3],mm3[6]=[2],mm3[5]=[1],mm3[4]=[0],mm3[3]=[6],mm3[2]=[11],mm3[1]=0 | |
| 503 | + psrlq mm4,38h ;mm4[1]=[16] | |
| 504 | + por mm3,mm4 ;mm3[7]=[3],mm3[6]=[2],mm3[5]=[1],mm3[4]=[0],mm3[3]=[6],mm3[2]=[11],mm3[1]=[16] | |
| 505 | + movq mm2,mm3 ;mm2[7]=[3],mm2[6]=[2],mm2[5]=[1],mm2[4]=[0],mm2[3]=[6],mm2[2]=[11],mm2[1]=[16] | |
| 506 | + movq mm4,[eax+ecx*2] ;mm4[8]=[21] | |
| 507 | + psllq mm3,8 ;mm3[8]=[3],mm3[7]=[2],mm3[6]=[1],mm3[5]=[0],mm3[4]=[6],mm3[3]=[11],mm3[2]=[16],mm3[1]=0 | |
| 508 | + psrlq mm4,38h ;mm4[1]=[21] | |
| 509 | + por mm3,mm4 ;mm3[8]=[3],mm3[7]=[2],mm3[6]=[1],mm3[5]=[0],mm3[4]=[6],mm3[3]=[11],mm3[2]=[16],mm3[1]=[21] | |
| 510 | + movq mm4,mm3 ;mm4[8]=[3],mm4[7]=[2],mm4[6]=[1],mm4[5]=[0],mm4[4]=[6],mm4[3]=[11],mm4[2]=[16],mm4[1]=[21] | |
| 511 | + pavgb mm3,mm1 ;mm3=([11]+[21]+1)/2 | |
| 512 | + pxor mm1,mm4 ;find odd value in the lowest bit of each byte | |
| 513 | + pand mm1,[mmx_01bytes] ;set the odd bit | |
| 514 | + psubusb mm3,mm1 ;decrease 1 from odd bytes | |
| 515 | + pavgb mm2,mm3 ;mm2=(([11]+[21]+1)/2+1+[16])/2 | |
| 516 | + | |
| 517 | + lea edx,[edx+ecx] | |
| 518 | + movd [edx+2*ecx],mm2 | |
| 519 | + sub edx,ecx | |
| 520 | + psrlq mm2,8 | |
| 521 | + movd [edx+2*ecx],mm2 | |
| 522 | + psrlq mm2,8 | |
| 523 | + movd [edx+ecx],mm2 | |
| 524 | + psrlq mm2,8 | |
| 525 | + movd [edx],mm2 | |
| 526 | + WELSEMMS | |
| 527 | + ret | |
| 528 | + | |
| 529 | +ALIGN 16 | |
| 530 | +;******************************************************************************* | |
| 531 | +; 0 |1 |2 |3 |4 | | |
| 532 | +; 5 |6 |7 |8 |9 | | |
| 533 | +; 10|11|12|13|14| | |
| 534 | +; 15|16|17|18|19| | |
| 535 | +; 20|21|22|23|24| | |
| 536 | +; 6 is the start pixel of current 4x4 block | |
| 537 | +; pPred[6] = ([1]+[2]+[3]+[4]+[5]+[10]+[15]+[20]+4)/8 | |
| 538 | +; | |
| 539 | +; void_t __cdecl WelsI4x4LumaPredDc_sse2(uint8_t *pPred, const int32_t kiStride) | |
| 540 | +; | |
| 541 | +;******************************************************************************* | |
| 542 | +WelsI4x4LumaPredDc_sse2: | |
| 543 | + mov eax,[esp+4] ;pPred | |
| 544 | + mov ecx,[esp+8] ;kiStride | |
| 545 | + push ebx | |
| 546 | + | |
| 547 | + movzx edx, byte [eax-1h] | |
| 548 | + | |
| 549 | + sub eax, ecx | |
| 550 | + movd xmm0, [eax] | |
| 551 | + pxor xmm1, xmm1 | |
| 552 | + psadbw xmm0, xmm1 | |
| 553 | + | |
| 554 | + movd ebx, xmm0 | |
| 555 | + add ebx, edx | |
| 556 | + | |
| 557 | + movzx edx, byte [eax+ecx*2-1h] | |
| 558 | + add ebx, edx | |
| 559 | + | |
| 560 | + lea eax, [eax+ecx*2-1] | |
| 561 | + movzx edx, byte [eax+ecx] | |
| 562 | + add ebx, edx | |
| 563 | + | |
| 564 | + movzx edx, byte [eax+ecx*2] | |
| 565 | + add ebx, edx | |
| 566 | + add ebx, 4 | |
| 567 | + sar ebx, 3 | |
| 568 | + imul ebx, 0x01010101 | |
| 569 | + | |
| 570 | + mov edx, [esp+8] ;pPred | |
| 571 | + mov [edx], ebx | |
| 572 | + mov [edx+ecx], ebx | |
| 573 | + mov [edx+2*ecx], ebx | |
| 574 | + lea edx, [edx+2*ecx] | |
| 575 | + mov [edx+ecx], ebx | |
| 576 | + | |
| 577 | + pop ebx | |
| 578 | + ret | |
| 579 | + | |
| 580 | +ALIGN 16 | |
| 581 | +;******************************************************************************* | |
| 582 | +; void_t __cdecl WelsIChromaPredH_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 583 | +; copy 8 pixel of 8 line from left | |
| 584 | +;******************************************************************************* | |
| 585 | +%macro MMX_PRED_H_8X8_ONE_LINE 4 | |
| 586 | + movq %1, [%3-8] | |
| 587 | + psrlq %1, 38h | |
| 588 | + | |
| 589 | + pmullw %1, [mmx_01bytes] | |
| 590 | + pshufw %1, %1, 0 | |
| 591 | + movq [%4], %1 | |
| 592 | +%endmacro | |
| 593 | + | |
| 594 | +%macro MMX_PRED_H_8X8_ONE_LINEE 4 | |
| 595 | + movq %1, [%3+ecx-8] | |
| 596 | + psrlq %1, 38h | |
| 597 | + | |
| 598 | + pmullw %1, [mmx_01bytes] | |
| 599 | + pshufw %1, %1, 0 | |
| 600 | + movq [%4], %1 | |
| 601 | +%endmacro | |
| 602 | + | |
| 603 | +WELS_EXTERN WelsIChromaPredH_mmx | |
| 604 | +WelsIChromaPredH_mmx: | |
| 605 | + mov edx, [esp+4] ;pPred | |
| 606 | + mov eax, edx | |
| 607 | + mov ecx, [esp+8] ;kiStride | |
| 608 | + | |
| 609 | + movq mm0, [eax-8] | |
| 610 | + psrlq mm0, 38h | |
| 611 | + | |
| 612 | + pmullw mm0, [mmx_01bytes] | |
| 613 | + pshufw mm0, mm0, 0 | |
| 614 | + movq [edx], mm0 | |
| 615 | + | |
| 616 | + MMX_PRED_H_8X8_ONE_LINEE mm0, mm1, eax, edx+ecx | |
| 617 | + | |
| 618 | + lea eax, [eax+ecx*2] | |
| 619 | + MMX_PRED_H_8X8_ONE_LINE mm0, mm1, eax, edx+2*ecx | |
| 620 | + | |
| 621 | + lea edx, [edx+2*ecx] | |
| 622 | + MMX_PRED_H_8X8_ONE_LINEE mm0, mm1, eax, edx+ecx | |
| 623 | + | |
| 624 | + lea eax, [eax+ecx*2] | |
| 625 | + MMX_PRED_H_8X8_ONE_LINE mm0, mm1, eax, edx+2*ecx | |
| 626 | + | |
| 627 | + lea edx, [edx+2*ecx] | |
| 628 | + MMX_PRED_H_8X8_ONE_LINEE mm0, mm1, eax, edx+ecx | |
| 629 | + | |
| 630 | + lea eax, [eax+ecx*2] | |
| 631 | + MMX_PRED_H_8X8_ONE_LINE mm0, mm1, eax, edx+2*ecx | |
| 632 | + | |
| 633 | + lea edx, [edx+2*ecx] | |
| 634 | + MMX_PRED_H_8X8_ONE_LINEE mm0, mm1, eax, edx+ecx | |
| 635 | + | |
| 636 | + WELSEMMS | |
| 637 | + ret | |
| 638 | + | |
| 639 | +ALIGN 16 | |
| 640 | +;******************************************************************************* | |
| 641 | +; void_t __cdecl get_i4x4_luma_pred_v_asm(uint8_t *pPred, const int32_t kiStride) | |
| 642 | +; copy pixels from top 4 pixels | |
| 643 | +;******************************************************************************* | |
| 644 | +WELS_EXTERN get_i4x4_luma_pred_v_asm | |
| 645 | +get_i4x4_luma_pred_v_asm: | |
| 646 | + mov eax, [esp+4] ;pPred | |
| 647 | + mov ecx, [esp+8] ;kiStride | |
| 648 | + | |
| 649 | + sub eax, ecx | |
| 650 | + mov edx, [eax] | |
| 651 | + mov [eax+ecx], edx | |
| 652 | + mov [eax+2*ecx], edx | |
| 653 | + lea eax, [eax+2*ecx] | |
| 654 | + mov [eax+ecx], edx | |
| 655 | + mov [eax+2*ecx], edx | |
| 656 | + | |
| 657 | + ret | |
| 658 | + | |
| 659 | +ALIGN 16 | |
| 660 | +;******************************************************************************* | |
| 661 | +; void_t __cdecl WelsIChromaPredV_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 662 | +; copy 8 pixels from top 8 pixels | |
| 663 | +;******************************************************************************* | |
| 664 | +WELS_EXTERN WelsIChromaPredV_mmx | |
| 665 | +WelsIChromaPredV_mmx: | |
| 666 | + mov eax, [esp+4] ;pPred | |
| 667 | + mov ecx, [esp+8] ;kiStride | |
| 668 | + | |
| 669 | + sub eax, ecx | |
| 670 | + movq mm0, [eax] | |
| 671 | + | |
| 672 | + movq [eax+ecx], mm0 | |
| 673 | + movq [eax+2*ecx], mm0 | |
| 674 | + lea eax, [eax+2*ecx] | |
| 675 | + movq [eax+ecx], mm0 | |
| 676 | + movq [eax+2*ecx], mm0 | |
| 677 | + lea eax, [eax+2*ecx] | |
| 678 | + movq [eax+ecx], mm0 | |
| 679 | + movq [eax+2*ecx], mm0 | |
| 680 | + lea eax, [eax+2*ecx] | |
| 681 | + movq [eax+ecx], mm0 | |
| 682 | + movq [eax+2*ecx], mm0 | |
| 683 | + | |
| 684 | + WELSEMMS | |
| 685 | + ret | |
| 686 | + | |
| 687 | + | |
| 688 | + ALIGN 16 | |
| 689 | +;******************************************************************************* | |
| 690 | +; lt|t0|t1|t2|t3| | |
| 691 | +; l0| | |
| 692 | +; l1| | |
| 693 | +; l2| | |
| 694 | +; l3| | |
| 695 | +; t3 will never been used | |
| 696 | +; destination: | |
| 697 | +; |a |b |c |d | | |
| 698 | +; |e |f |a |b | | |
| 699 | +; |g |h |e |f | | |
| 700 | +; |i |j |g |h | | |
| 701 | + | |
| 702 | +; a = (1 + lt + l0)>>1 | |
| 703 | +; e = (1 + l0 + l1)>>1 | |
| 704 | +; g = (1 + l1 + l2)>>1 | |
| 705 | +; i = (1 + l2 + l3)>>1 | |
| 706 | + | |
| 707 | +; d = (2 + t0 + (t1<<1) + t2)>>2 | |
| 708 | +; c = (2 + lt + (t0<<1) + t1)>>2 | |
| 709 | +; b = (2 + l0 + (lt<<1) + t0)>>2 | |
| 710 | + | |
| 711 | +; f = (2 + l1 + (l0<<1) + lt)>>2 | |
| 712 | +; h = (2 + l2 + (l1<<1) + l0)>>2 | |
| 713 | +; j = (2 + l3 + (l2<<1) + l1)>>2 | |
| 714 | +; [b a f e h g j i] + [d c b a] --> mov to memory | |
| 715 | +; | |
| 716 | +; void_t WelsI4x4LumaPredHD_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 717 | +;******************************************************************************* | |
| 718 | +WELS_EXTERN WelsI4x4LumaPredHD_mmx | |
| 719 | +WelsI4x4LumaPredHD_mmx: | |
| 720 | + mov edx, [esp+4] ; pPred | |
| 721 | + mov eax, edx | |
| 722 | + mov ecx, [esp+8] ; kiStride | |
| 723 | + sub eax, ecx | |
| 724 | + movd mm0, [eax-1] ; mm0 = [xx xx xx xx t2 t1 t0 lt] | |
| 725 | + psllq mm0, 20h ; mm0 = [t2 t1 t0 lt xx xx xx xx] | |
| 726 | + | |
| 727 | + movd mm1, [eax+2*ecx-4] | |
| 728 | + punpcklbw mm1, [eax+ecx-4] ; mm1[7] = l0, mm1[6] = l1 | |
| 729 | + lea eax, [eax+2*ecx] | |
| 730 | + movd mm2, [eax+2*ecx-4] | |
| 731 | + punpcklbw mm2, [eax+ecx-4] ; mm2[7] = l2, mm2[6] = l3 | |
| 732 | + punpckhwd mm2, mm1 ; mm2 = [l0 l1 l2 l3 xx xx xx xx] | |
| 733 | + psrlq mm2, 20h | |
| 734 | + pxor mm0, mm2 ; mm0 = [t2 t1 t0 lt l0 l1 l2 l3] | |
| 735 | + | |
| 736 | + movq mm1, mm0 | |
| 737 | + psrlq mm1, 10h ; mm1 = [xx xx t2 t1 t0 lt l0 l1] | |
| 738 | + movq mm2, mm0 | |
| 739 | + psrlq mm2, 8h ; mm2 = [xx t2 t1 t0 lt l0 l1 l2] | |
| 740 | + movq mm3, mm2 | |
| 741 | + movq mm4, mm1 | |
| 742 | + pavgb mm1, mm0 | |
| 743 | + | |
| 744 | + pxor mm4, mm0 ; find odd value in the lowest bit of each byte | |
| 745 | + pand mm4, [mmx_01bytes] ; set the odd bit | |
| 746 | + psubusb mm1, mm4 ; decrease 1 from odd bytes | |
| 747 | + | |
| 748 | + pavgb mm2, mm1 ; mm2 = [xx xx d c b f h j] | |
| 749 | + | |
| 750 | + movq mm4, mm0 | |
| 751 | + pavgb mm3, mm4 ; mm3 = [xx xx xx xx a e g i] | |
| 752 | + punpcklbw mm3, mm2 ; mm3 = [b a f e h g j i] | |
| 753 | + | |
| 754 | + psrlq mm2, 20h | |
| 755 | + psllq mm2, 30h ; mm2 = [d c 0 0 0 0 0 0] | |
| 756 | + movq mm4, mm3 | |
| 757 | + psrlq mm4, 10h ; mm4 = [0 0 b a f e h j] | |
| 758 | + pxor mm2, mm4 ; mm2 = [d c b a xx xx xx xx] | |
| 759 | + psrlq mm2, 20h ; mm2 = [xx xx xx xx d c b a] | |
| 760 | + | |
| 761 | + movd [edx], mm2 | |
| 762 | + lea edx, [edx+ecx] | |
| 763 | + movd [edx+2*ecx], mm3 | |
| 764 | + sub edx, ecx | |
| 765 | + psrlq mm3, 10h | |
| 766 | + movd [edx+2*ecx], mm3 | |
| 767 | + psrlq mm3, 10h | |
| 768 | + movd [edx+ecx], mm3 | |
| 769 | + WELSEMMS | |
| 770 | + ret | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | +ALIGN 16 | |
| 775 | +;******************************************************************************* | |
| 776 | +; lt|t0|t1|t2|t3| | |
| 777 | +; l0| | |
| 778 | +; l1| | |
| 779 | +; l2| | |
| 780 | +; l3| | |
| 781 | +; t3 will never been used | |
| 782 | +; destination: | |
| 783 | +; |a |b |c |d | | |
| 784 | +; |c |d |e |f | | |
| 785 | +; |e |f |g |g | | |
| 786 | +; |g |g |g |g | | |
| 787 | + | |
| 788 | +; a = (1 + l0 + l1)>>1 | |
| 789 | +; c = (1 + l1 + l2)>>1 | |
| 790 | +; e = (1 + l2 + l3)>>1 | |
| 791 | +; g = l3 | |
| 792 | + | |
| 793 | +; b = (2 + l0 + (l1<<1) + l2)>>2 | |
| 794 | +; d = (2 + l1 + (l2<<1) + l3)>>2 | |
| 795 | +; f = (2 + l2 + (l3<<1) + l3)>>2 | |
| 796 | + | |
| 797 | +; [g g f e d c b a] + [g g g g] --> mov to memory | |
| 798 | +; | |
| 799 | +; void_t WelsI4x4LumaPredHU_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 800 | +;******************************************************************************* | |
| 801 | +WELS_EXTERN WelsI4x4LumaPredHU_mmx | |
| 802 | +WelsI4x4LumaPredHU_mmx: | |
| 803 | + mov edx, [esp+4] ; pPred | |
| 804 | + mov eax, edx | |
| 805 | + mov ecx, [esp+8] ; kiStride | |
| 806 | + | |
| 807 | + movd mm0, [eax-4] ; mm0[3] = l0 | |
| 808 | + punpcklbw mm0, [eax+ecx-4] ; mm0[7] = l1, mm0[6] = l0 | |
| 809 | + lea eax, [eax+2*ecx] | |
| 810 | + movd mm2, [eax-4] ; mm2[3] = l2 | |
| 811 | + movd mm4, [eax+ecx-4] ; mm4[3] = l3 | |
| 812 | + punpcklbw mm2, mm4 | |
| 813 | + punpckhwd mm0, mm2 ; mm0 = [l3 l2 l1 l0 xx xx xx xx] | |
| 814 | + | |
| 815 | + psrlq mm4, 18h | |
| 816 | + psllq mm4, 38h ; mm4 = [l3 xx xx xx xx xx xx xx] | |
| 817 | + psrlq mm0, 8h | |
| 818 | + pxor mm0, mm4 ; mm0 = [l3 l3 l2 l1 l0 xx xx xx] | |
| 819 | + | |
| 820 | + movq mm1, mm0 | |
| 821 | + psllq mm1, 8h ; mm1 = [l3 l2 l1 l0 xx xx xx xx] | |
| 822 | + movq mm3, mm1 ; mm3 = [l3 l2 l1 l0 xx xx xx xx] | |
| 823 | + pavgb mm1, mm0 ; mm1 = [g e c a xx xx xx xx] | |
| 824 | + | |
| 825 | + movq mm2, mm0 | |
| 826 | + psllq mm2, 10h ; mm2 = [l2 l1 l0 xx xx xx xx xx] | |
| 827 | + movq mm5, mm2 | |
| 828 | + pavgb mm2, mm0 | |
| 829 | + | |
| 830 | + pxor mm5, mm0 ; find odd value in the lowest bit of each byte | |
| 831 | + pand mm5, [mmx_01bytes] ; set the odd bit | |
| 832 | + psubusb mm2, mm5 ; decrease 1 from odd bytes | |
| 833 | + | |
| 834 | + pavgb mm2, mm3 ; mm2 = [f d b xx xx xx xx xx] | |
| 835 | + | |
| 836 | + psrlq mm2, 8h | |
| 837 | + pxor mm2, mm4 ; mm2 = [g f d b xx xx xx xx] | |
| 838 | + | |
| 839 | + punpckhbw mm1, mm2 ; mm1 = [g g f e d c b a] | |
| 840 | + punpckhbw mm4, mm4 ; mm4 = [g g xx xx xx xx xx xx] | |
| 841 | + punpckhbw mm4, mm4 ; mm4 = [g g g g xx xx xx xx] | |
| 842 | + | |
| 843 | + psrlq mm4, 20h | |
| 844 | + lea edx, [edx+ecx] | |
| 845 | + movd [edx+2*ecx], mm4 | |
| 846 | + | |
| 847 | + sub edx, ecx | |
| 848 | + movd [edx], mm1 | |
| 849 | + psrlq mm1, 10h | |
| 850 | + movd [edx+ecx], mm1 | |
| 851 | + psrlq mm1, 10h | |
| 852 | + movd [edx+2*ecx], mm1 | |
| 853 | + WELSEMMS | |
| 854 | + ret | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | +ALIGN 16 | |
| 859 | +;******************************************************************************* | |
| 860 | +; lt|t0|t1|t2|t3| | |
| 861 | +; l0| | |
| 862 | +; l1| | |
| 863 | +; l2| | |
| 864 | +; l3| | |
| 865 | +; l3 will never been used | |
| 866 | +; destination: | |
| 867 | +; |a |b |c |d | | |
| 868 | +; |e |f |g |h | | |
| 869 | +; |i |a |b |c | | |
| 870 | +; |j |e |f |g | | |
| 871 | + | |
| 872 | +; a = (1 + lt + t0)>>1 | |
| 873 | +; b = (1 + t0 + t1)>>1 | |
| 874 | +; c = (1 + t1 + t2)>>1 | |
| 875 | +; d = (1 + t2 + t3)>>1 | |
| 876 | + | |
| 877 | +; e = (2 + l0 + (lt<<1) + t0)>>2 | |
| 878 | +; f = (2 + lt + (t0<<1) + t1)>>2 | |
| 879 | +; g = (2 + t0 + (t1<<1) + t2)>>2 | |
| 880 | + | |
| 881 | +; h = (2 + t1 + (t2<<1) + t3)>>2 | |
| 882 | +; i = (2 + lt + (l0<<1) + l1)>>2 | |
| 883 | +; j = (2 + l0 + (l1<<1) + l2)>>2 | |
| 884 | +; | |
| 885 | +; void_t WelsI4x4LumaPredVR_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 886 | +;******************************************************************************* | |
| 887 | +WELS_EXTERN WelsI4x4LumaPredVR_mmx | |
| 888 | +WelsI4x4LumaPredVR_mmx: | |
| 889 | + mov edx, [esp+4] ; pPred | |
| 890 | + mov eax, edx | |
| 891 | + mov ecx, [esp+8] ; kiStride | |
| 892 | + sub eax, ecx | |
| 893 | + movq mm0, [eax-1] ; mm0 = [xx xx xx t3 t2 t1 t0 lt] | |
| 894 | + psllq mm0, 18h ; mm0 = [t3 t2 t1 t0 lt xx xx xx] | |
| 895 | + | |
| 896 | + movd mm1, [eax+2*ecx-4] | |
| 897 | + punpcklbw mm1, [eax+ecx-4] ; mm1[7] = l0, mm1[6] = l1 | |
| 898 | + lea eax, [eax+2*ecx] | |
| 899 | + movq mm2, [eax+ecx-8] ; mm2[7] = l2 | |
| 900 | + punpckhwd mm2, mm1 ; mm2 = [l0 l1 l2 xx xx xx xx xx] | |
| 901 | + psrlq mm2, 28h | |
| 902 | + pxor mm0, mm2 ; mm0 = [t3 t2 t1 t0 lt l0 l1 l2] | |
| 903 | + | |
| 904 | + movq mm1, mm0 | |
| 905 | + psllq mm1, 8h ; mm1 = [t2 t1 t0 lt l0 l1 l2 xx] | |
| 906 | + pavgb mm1, mm0 ; mm1 = [d c b a xx xx xx xx] | |
| 907 | + | |
| 908 | + movq mm2, mm0 | |
| 909 | + psllq mm2, 10h ; mm2 = [t1 t0 lt l0 l1 l2 xx xx] | |
| 910 | + movq mm3, mm2 | |
| 911 | + pavgb mm2, mm0 | |
| 912 | + | |
| 913 | + pxor mm3, mm0 ; find odd value in the lowest bit of each byte | |
| 914 | + pand mm3, [mmx_01bytes] ; set the odd bit | |
| 915 | + psubusb mm2, mm3 ; decrease 1 from odd bytes | |
| 916 | + | |
| 917 | + movq mm3, mm0 | |
| 918 | + psllq mm3, 8h ; mm3 = [t2 t1 t0 lt l0 l1 l2 xx] | |
| 919 | + pavgb mm3, mm2 ; mm3 = [h g f e i j xx xx] | |
| 920 | + movq mm2, mm3 | |
| 921 | + | |
| 922 | + psrlq mm1, 20h ; mm1 = [xx xx xx xx d c b a] | |
| 923 | + movd [edx], mm1 | |
| 924 | + | |
| 925 | + psrlq mm2, 20h ; mm2 = [xx xx xx xx h g f e] | |
| 926 | + movd [edx+ecx], mm2 | |
| 927 | + | |
| 928 | + movq mm4, mm3 | |
| 929 | + psllq mm4, 20h | |
| 930 | + psrlq mm4, 38h ; mm4 = [xx xx xx xx xx xx xx i] | |
| 931 | + | |
| 932 | + movq mm5, mm3 | |
| 933 | + psllq mm5, 28h | |
| 934 | + psrlq mm5, 38h ; mm5 = [xx xx xx xx xx xx xx j] | |
| 935 | + | |
| 936 | + psllq mm1, 8h | |
| 937 | + pxor mm4, mm1 ; mm4 = [xx xx xx xx c b a i] | |
| 938 | + movd [edx+2*ecx], mm4 | |
| 939 | + | |
| 940 | + psllq mm2, 8h | |
| 941 | + pxor mm5, mm2 ; mm5 = [xx xx xx xx g f e j] | |
| 942 | + lea edx, [edx+2*ecx] | |
| 943 | + movd [edx+ecx], mm5 | |
| 944 | + WELSEMMS | |
| 945 | + ret | |
| 946 | + | |
| 947 | +ALIGN 16 | |
| 948 | +;******************************************************************************* | |
| 949 | +; lt|t0|t1|t2|t3|t4|t5|t6|t7 | |
| 950 | +; l0| | |
| 951 | +; l1| | |
| 952 | +; l2| | |
| 953 | +; l3| | |
| 954 | +; lt,t0,t1,t2,t3 will never been used | |
| 955 | +; destination: | |
| 956 | +; |a |b |c |d | | |
| 957 | +; |b |c |d |e | | |
| 958 | +; |c |d |e |f | | |
| 959 | +; |d |e |f |g | | |
| 960 | + | |
| 961 | +; a = (2 + t0 + t2 + (t1<<1))>>2 | |
| 962 | +; b = (2 + t1 + t3 + (t2<<1))>>2 | |
| 963 | +; c = (2 + t2 + t4 + (t3<<1))>>2 | |
| 964 | +; d = (2 + t3 + t5 + (t4<<1))>>2 | |
| 965 | + | |
| 966 | +; e = (2 + t4 + t6 + (t5<<1))>>2 | |
| 967 | +; f = (2 + t5 + t7 + (t6<<1))>>2 | |
| 968 | +; g = (2 + t6 + t7 + (t7<<1))>>2 | |
| 969 | + | |
| 970 | +; [g f e d c b a] --> mov to memory | |
| 971 | +; | |
| 972 | +; void_t WelsI4x4LumaPredDDL_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 973 | +;******************************************************************************* | |
| 974 | +WELS_EXTERN WelsI4x4LumaPredDDL_mmx | |
| 975 | +WelsI4x4LumaPredDDL_mmx: | |
| 976 | + mov edx, [esp+4] ; pPred | |
| 977 | + mov eax, edx | |
| 978 | + mov ecx, [esp+8] ; kiStride | |
| 979 | + sub eax, ecx | |
| 980 | + movq mm0, [eax] ; mm0 = [t7 t6 t5 t4 t3 t2 t1 t0] | |
| 981 | + movq mm1, mm0 | |
| 982 | + movq mm2, mm0 | |
| 983 | + | |
| 984 | + movq mm3, mm0 | |
| 985 | + psrlq mm3, 38h | |
| 986 | + psllq mm3, 38h ; mm3 = [t7 xx xx xx xx xx xx xx] | |
| 987 | + | |
| 988 | + psllq mm1, 8h ; mm1 = [t6 t5 t4 t3 t2 t1 t0 xx] | |
| 989 | + psrlq mm2, 8h | |
| 990 | + pxor mm2, mm3 ; mm2 = [t7 t7 t6 t5 t4 t3 t2 t1] | |
| 991 | + | |
| 992 | + movq mm3, mm1 | |
| 993 | + pavgb mm1, mm2 | |
| 994 | + pxor mm3, mm2 ; find odd value in the lowest bit of each byte | |
| 995 | + pand mm3, [mmx_01bytes] ; set the odd bit | |
| 996 | + psubusb mm1, mm3 ; decrease 1 from odd bytes | |
| 997 | + | |
| 998 | + pavgb mm0, mm1 ; mm0 = [g f e d c b a xx] | |
| 999 | + | |
| 1000 | + psrlq mm0, 8h | |
| 1001 | + movd [edx], mm0 | |
| 1002 | + psrlq mm0, 8h | |
| 1003 | + movd [edx+ecx], mm0 | |
| 1004 | + psrlq mm0, 8h | |
| 1005 | + movd [edx+2*ecx], mm0 | |
| 1006 | + psrlq mm0, 8h | |
| 1007 | + lea edx, [edx+2*ecx] | |
| 1008 | + movd [edx+ecx], mm0 | |
| 1009 | + WELSEMMS | |
| 1010 | + ret | |
| 1011 | + | |
| 1012 | + | |
| 1013 | +ALIGN 16 | |
| 1014 | +;******************************************************************************* | |
| 1015 | +; lt|t0|t1|t2|t3|t4|t5|t6|t7 | |
| 1016 | +; l0| | |
| 1017 | +; l1| | |
| 1018 | +; l2| | |
| 1019 | +; l3| | |
| 1020 | +; lt,t0,t1,t2,t3 will never been used | |
| 1021 | +; destination: | |
| 1022 | +; |a |b |c |d | | |
| 1023 | +; |e |f |g |h | | |
| 1024 | +; |b |c |d |i | | |
| 1025 | +; |f |g |h |j | | |
| 1026 | + | |
| 1027 | +; a = (1 + t0 + t1)>>1 | |
| 1028 | +; b = (1 + t1 + t2)>>1 | |
| 1029 | +; c = (1 + t2 + t3)>>1 | |
| 1030 | +; d = (1 + t3 + t4)>>1 | |
| 1031 | +; i = (1 + t4 + t5)>>1 | |
| 1032 | + | |
| 1033 | +; e = (2 + t0 + (t1<<1) + t2)>>2 | |
| 1034 | +; f = (2 + t1 + (t2<<1) + t3)>>2 | |
| 1035 | +; g = (2 + t2 + (t3<<1) + t4)>>2 | |
| 1036 | +; h = (2 + t3 + (t4<<1) + t5)>>2 | |
| 1037 | +; j = (2 + t4 + (t5<<1) + t6)>>2 | |
| 1038 | + | |
| 1039 | +; [i d c b a] + [j h g f e] --> mov to memory | |
| 1040 | +; | |
| 1041 | +; void_t WelsI4x4LumaPredVL_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 1042 | +;******************************************************************************* | |
| 1043 | +WELS_EXTERN WelsI4x4LumaPredVL_mmx | |
| 1044 | +WelsI4x4LumaPredVL_mmx: | |
| 1045 | + mov edx, [esp+4] ; pPred | |
| 1046 | + mov eax, edx | |
| 1047 | + mov ecx, [esp+8] ; kiStride | |
| 1048 | + | |
| 1049 | + sub eax, ecx | |
| 1050 | + movq mm0, [eax] ; mm0 = [t7 t6 t5 t4 t3 t2 t1 t0] | |
| 1051 | + movq mm1, mm0 | |
| 1052 | + movq mm2, mm0 | |
| 1053 | + | |
| 1054 | + psrlq mm1, 8h ; mm1 = [xx t7 t6 t5 t4 t3 t2 t1] | |
| 1055 | + psrlq mm2, 10h ; mm2 = [xx xx t7 t6 t5 t4 t3 t2] | |
| 1056 | + | |
| 1057 | + movq mm3, mm1 | |
| 1058 | + pavgb mm3, mm0 ; mm3 = [xx xx xx i d c b a] | |
| 1059 | + | |
| 1060 | + movq mm4, mm2 | |
| 1061 | + pavgb mm2, mm0 | |
| 1062 | + pxor mm4, mm0 ; find odd value in the lowest bit of each byte | |
| 1063 | + pand mm4, [mmx_01bytes] ; set the odd bit | |
| 1064 | + psubusb mm2, mm4 ; decrease 1 from odd bytes | |
| 1065 | + | |
| 1066 | + pavgb mm2, mm1 ; mm2 = [xx xx xx j h g f e] | |
| 1067 | + | |
| 1068 | + movd [edx], mm3 | |
| 1069 | + psrlq mm3, 8h | |
| 1070 | + movd [edx+2*ecx], mm3 | |
| 1071 | + | |
| 1072 | + movd [edx+ecx], mm2 | |
| 1073 | + psrlq mm2, 8h | |
| 1074 | + lea edx, [edx+2*ecx] | |
| 1075 | + movd [edx+ecx], mm2 | |
| 1076 | + WELSEMMS | |
| 1077 | + ret | |
| 1078 | + | |
| 1079 | +ALIGN 16 | |
| 1080 | +;******************************************************************************* | |
| 1081 | +; | |
| 1082 | +; void_t WelsIChromaPredDc_sse2(uint8_t *pPred, const int32_t kiStride) | |
| 1083 | +;******************************************************************************* | |
| 1084 | +WELS_EXTERN WelsIChromaPredDc_sse2 | |
| 1085 | +WelsIChromaPredDc_sse2: | |
| 1086 | + push ebx | |
| 1087 | + mov eax, [esp+8] ; pPred | |
| 1088 | + mov ecx, [esp+12] ; kiStride | |
| 1089 | + | |
| 1090 | + sub eax, ecx | |
| 1091 | + movq mm0, [eax] | |
| 1092 | + | |
| 1093 | + movzx ebx, byte [eax+ecx-0x01] ; l1 | |
| 1094 | + lea eax, [eax+2*ecx] | |
| 1095 | + movzx edx, byte [eax-0x01] ; l2 | |
| 1096 | + add ebx, edx | |
| 1097 | + movzx edx, byte [eax+ecx-0x01] ; l3 | |
| 1098 | + add ebx, edx | |
| 1099 | + lea eax, [eax+2*ecx] | |
| 1100 | + movzx edx, byte [eax-0x01] ; l4 | |
| 1101 | + add ebx, edx | |
| 1102 | + movd mm1, ebx ; mm1 = l1+l2+l3+l4 | |
| 1103 | + | |
| 1104 | + movzx ebx, byte [eax+ecx-0x01] ; l5 | |
| 1105 | + lea eax, [eax+2*ecx] | |
| 1106 | + movzx edx, byte [eax-0x01] ; l6 | |
| 1107 | + add ebx, edx | |
| 1108 | + movzx edx, byte [eax+ecx-0x01] ; l7 | |
| 1109 | + add ebx, edx | |
| 1110 | + lea eax, [eax+2*ecx] | |
| 1111 | + movzx edx, byte [eax-0x01] ; l8 | |
| 1112 | + add ebx, edx | |
| 1113 | + movd mm2, ebx ; mm2 = l5+l6+l7+l8 | |
| 1114 | + | |
| 1115 | + movq mm3, mm0 | |
| 1116 | + psrlq mm0, 0x20 | |
| 1117 | + psllq mm3, 0x20 | |
| 1118 | + psrlq mm3, 0x20 | |
| 1119 | + pxor mm4, mm4 | |
| 1120 | + psadbw mm0, mm4 | |
| 1121 | + psadbw mm3, mm4 ; sum1 = mm3+mm1, sum2 = mm0, sum3 = mm2 | |
| 1122 | + | |
| 1123 | + paddq mm3, mm1 | |
| 1124 | + movq mm1, mm2 | |
| 1125 | + paddq mm1, mm0; ; sum1 = mm3, sum2 = mm0, sum3 = mm2, sum4 = mm1 | |
| 1126 | + | |
| 1127 | + movq mm4, [mmx_0x02] | |
| 1128 | + | |
| 1129 | + paddq mm0, mm4 | |
| 1130 | + psrlq mm0, 0x02 | |
| 1131 | + | |
| 1132 | + paddq mm2, mm4 | |
| 1133 | + psrlq mm2, 0x02 | |
| 1134 | + | |
| 1135 | + paddq mm3, mm4 | |
| 1136 | + paddq mm3, mm4 | |
| 1137 | + psrlq mm3, 0x03 | |
| 1138 | + | |
| 1139 | + paddq mm1, mm4 | |
| 1140 | + paddq mm1, mm4 | |
| 1141 | + psrlq mm1, 0x03 | |
| 1142 | + | |
| 1143 | + pmuludq mm0, [mmx_01bytes] | |
| 1144 | + pmuludq mm3, [mmx_01bytes] | |
| 1145 | + psllq mm0, 0x20 | |
| 1146 | + pxor mm0, mm3 ; mm0 = m_up | |
| 1147 | + | |
| 1148 | + pmuludq mm2, [mmx_01bytes] | |
| 1149 | + pmuludq mm1, [mmx_01bytes] | |
| 1150 | + psllq mm1, 0x20 | |
| 1151 | + pxor mm1, mm2 ; mm2 = m_down | |
| 1152 | + | |
| 1153 | + mov edx, [esp+8] ; pPred | |
| 1154 | + | |
| 1155 | + movq [edx], mm0 | |
| 1156 | + movq [edx+ecx], mm0 | |
| 1157 | + movq [edx+2*ecx], mm0 | |
| 1158 | + lea edx, [edx+2*ecx] | |
| 1159 | + movq [edx+ecx], mm0 | |
| 1160 | + | |
| 1161 | + movq [edx+2*ecx], mm1 | |
| 1162 | + lea edx, [edx+2*ecx] | |
| 1163 | + movq [edx+ecx], mm1 | |
| 1164 | + movq [edx+2*ecx], mm1 | |
| 1165 | + lea edx, [edx+2*ecx] | |
| 1166 | + movq [edx+ecx], mm1 | |
| 1167 | + | |
| 1168 | + pop ebx | |
| 1169 | + WELSEMMS | |
| 1170 | + ret | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | +ALIGN 16 | |
| 1175 | +;******************************************************************************* | |
| 1176 | +; | |
| 1177 | +; void_t WelsI16x16LumaPredDc_sse2(uint8_t *pPred, const int32_t kiStride) | |
| 1178 | +;******************************************************************************* | |
| 1179 | +WELS_EXTERN WelsI16x16LumaPredDc_sse2 | |
| 1180 | +WelsI16x16LumaPredDc_sse2: | |
| 1181 | + push ebx | |
| 1182 | + mov eax, [esp+8] ; pPred | |
| 1183 | + mov ecx, [esp+12] ; kiStride | |
| 1184 | + | |
| 1185 | + sub eax, ecx | |
| 1186 | + movdqa xmm0, [eax] ; read one row | |
| 1187 | + pxor xmm1, xmm1 | |
| 1188 | + psadbw xmm0, xmm1 | |
| 1189 | + movdqa xmm1, xmm0 | |
| 1190 | + psrldq xmm1, 0x08 | |
| 1191 | + pslldq xmm0, 0x08 | |
| 1192 | + psrldq xmm0, 0x08 | |
| 1193 | + paddw xmm0, xmm1 | |
| 1194 | + | |
| 1195 | + movzx ebx, byte [eax+ecx-0x01] | |
| 1196 | + movzx edx, byte [eax+2*ecx-0x01] | |
| 1197 | + add ebx, edx | |
| 1198 | + lea eax, [eax+ecx] | |
| 1199 | + LOAD_2_LEFT_AND_ADD | |
| 1200 | + LOAD_2_LEFT_AND_ADD | |
| 1201 | + LOAD_2_LEFT_AND_ADD | |
| 1202 | + LOAD_2_LEFT_AND_ADD | |
| 1203 | + LOAD_2_LEFT_AND_ADD | |
| 1204 | + LOAD_2_LEFT_AND_ADD | |
| 1205 | + LOAD_2_LEFT_AND_ADD | |
| 1206 | + add ebx, 0x10 | |
| 1207 | + movd xmm1, ebx | |
| 1208 | + paddw xmm0, xmm1 | |
| 1209 | + psrld xmm0, 0x05 | |
| 1210 | + pmuludq xmm0, [mmx_01bytes] | |
| 1211 | + pshufd xmm0, xmm0, 0 | |
| 1212 | + | |
| 1213 | + mov edx, [esp+8] ; pPred | |
| 1214 | + | |
| 1215 | + movdqa [edx], xmm0 | |
| 1216 | + movdqa [edx+ecx], xmm0 | |
| 1217 | + movdqa [edx+2*ecx], xmm0 | |
| 1218 | + lea edx, [edx+2*ecx] | |
| 1219 | + | |
| 1220 | + movdqa [edx+ecx], xmm0 | |
| 1221 | + movdqa [edx+2*ecx], xmm0 | |
| 1222 | + lea edx, [edx+2*ecx] | |
| 1223 | + | |
| 1224 | + movdqa [edx+ecx], xmm0 | |
| 1225 | + movdqa [edx+2*ecx], xmm0 | |
| 1226 | + lea edx, [edx+2*ecx] | |
| 1227 | + | |
| 1228 | + movdqa [edx+ecx], xmm0 | |
| 1229 | + movdqa [edx+2*ecx], xmm0 | |
| 1230 | + lea edx, [edx+2*ecx] | |
| 1231 | + | |
| 1232 | + movdqa [edx+ecx], xmm0 | |
| 1233 | + movdqa [edx+2*ecx], xmm0 | |
| 1234 | + lea edx, [edx+2*ecx] | |
| 1235 | + | |
| 1236 | + movdqa [edx+ecx], xmm0 | |
| 1237 | + movdqa [edx+2*ecx], xmm0 | |
| 1238 | + lea edx, [edx+2*ecx] | |
| 1239 | + | |
| 1240 | + movdqa [edx+ecx], xmm0 | |
| 1241 | + movdqa [edx+2*ecx], xmm0 | |
| 1242 | + lea edx, [edx+2*ecx] | |
| 1243 | + | |
| 1244 | + movdqa [edx+ecx], xmm0 | |
| 1245 | + | |
| 1246 | + pop ebx | |
| 1247 | + | |
| 1248 | + ret | |
| 1249 | + | |
| 1250 | +;******************************************************************************* | |
| 1251 | +; for intra prediction as follows, 11/19/2010 | |
| 1252 | +;******************************************************************************* | |
| 1253 | + | |
| 1254 | +ALIGN 16 | |
| 1255 | +;******************************************************************************* | |
| 1256 | +; void_t WelsI16x16LumaPredDcTop_sse2(uint8_t *pPred, const int32_t kiStride) | |
| 1257 | +;******************************************************************************* | |
| 1258 | +WELS_EXTERN WelsI16x16LumaPredDcTop_sse2 | |
| 1259 | +WelsI16x16LumaPredDcTop_sse2: | |
| 1260 | + push ebx | |
| 1261 | + | |
| 1262 | + %define PUSH_SIZE 4 | |
| 1263 | + | |
| 1264 | + mov eax, [esp+PUSH_SIZE+4] ; pPred | |
| 1265 | + mov ebx, [esp+PUSH_SIZE+8] ; kiStride | |
| 1266 | + | |
| 1267 | + mov ecx, ebx | |
| 1268 | + neg ecx | |
| 1269 | + movdqa xmm0, [eax+ecx] ; pPred-kiStride, top line | |
| 1270 | + pxor xmm7, xmm7 | |
| 1271 | + movdqa xmm1, xmm0 | |
| 1272 | + punpcklbw xmm0, xmm7 | |
| 1273 | + punpckhbw xmm1, xmm7 | |
| 1274 | + | |
| 1275 | + paddw xmm0, xmm1 ; (ub.max(ff) << 4) will not excceed of uw, so can perform it in unit of unsigned word scope | |
| 1276 | + pshufd xmm1, xmm0, 04eh ; 01001110, w3w2w1w0,w7w6w5w4 | |
| 1277 | + paddw xmm0, xmm1 ; w3+7 w2+6 w1+5 w0+4 w3+7 w2+6 w1+5 w0+4 | |
| 1278 | + pshufd xmm1, xmm0, 0b1h ; 10110001, w1+5 w0+4 w3+7 w2+6 w1+5 w0+4 w3+7 w2+6 | |
| 1279 | + paddw xmm0, xmm1 ; w_o w_e w_o w_e w_o w_e w_o w_e (w_o=1+3+5+7, w_e=0+2+4+6) | |
| 1280 | + pshuflw xmm1, xmm0, 0b1h ; 10110001 | |
| 1281 | + paddw xmm0, xmm1 ; sum in word unit (x8) | |
| 1282 | + movd edx, xmm0 | |
| 1283 | + and edx, 0ffffh | |
| 1284 | + | |
| 1285 | + add edx, 08h | |
| 1286 | + sar edx, 04h | |
| 1287 | + mov dh, dl | |
| 1288 | + mov ecx, edx | |
| 1289 | + shl ecx, 010h | |
| 1290 | + or edx, ecx | |
| 1291 | + movd xmm1, edx | |
| 1292 | + pshufd xmm0, xmm1, 00h | |
| 1293 | + movdqa xmm1, xmm0 | |
| 1294 | + | |
| 1295 | + lea ecx, [2*ebx+ebx] ; 3*kiStride | |
| 1296 | + | |
| 1297 | + movdqa [eax], xmm0 | |
| 1298 | + movdqa [eax+ebx], xmm1 | |
| 1299 | + movdqa [eax+2*ebx], xmm0 | |
| 1300 | + movdqa [eax+ecx], xmm1 | |
| 1301 | + | |
| 1302 | + lea eax, [eax+4*ebx] | |
| 1303 | + movdqa [eax], xmm0 | |
| 1304 | + movdqa [eax+ebx], xmm1 | |
| 1305 | + movdqa [eax+2*ebx], xmm0 | |
| 1306 | + movdqa [eax+ecx], xmm1 | |
| 1307 | + | |
| 1308 | + lea eax, [eax+4*ebx] | |
| 1309 | + movdqa [eax], xmm0 | |
| 1310 | + movdqa [eax+ebx], xmm1 | |
| 1311 | + movdqa [eax+2*ebx], xmm0 | |
| 1312 | + movdqa [eax+ecx], xmm1 | |
| 1313 | + | |
| 1314 | + lea eax, [eax+4*ebx] | |
| 1315 | + movdqa [eax], xmm0 | |
| 1316 | + movdqa [eax+ebx], xmm1 | |
| 1317 | + movdqa [eax+2*ebx], xmm0 | |
| 1318 | + movdqa [eax+ecx], xmm1 | |
| 1319 | + | |
| 1320 | + %undef PUSH_SIZE | |
| 1321 | + pop ebx | |
| 1322 | + ret | |
| 1323 | + | |
| 1324 | +ALIGN 16 | |
| 1325 | +;******************************************************************************* | |
| 1326 | +; void_t WelsI16x16LumaPredDcNA_sse2(uint8_t *pPred, const int32_t kiStride) | |
| 1327 | +;******************************************************************************* | |
| 1328 | +WELS_EXTERN WelsI16x16LumaPredDcNA_sse2 | |
| 1329 | +WelsI16x16LumaPredDcNA_sse2: | |
| 1330 | + push ebx | |
| 1331 | + | |
| 1332 | + %define PUSH_SIZE 4 | |
| 1333 | + | |
| 1334 | + mov eax, [esp+PUSH_SIZE+4] ; pPred | |
| 1335 | + mov ebx, [esp+PUSH_SIZE+8] ; kiStride | |
| 1336 | + | |
| 1337 | + lea ecx, [2*ebx+ebx] ; 3*kiStride | |
| 1338 | + | |
| 1339 | + movdqa xmm0, [sse2_dc_0x80] | |
| 1340 | + movdqa xmm1, xmm0 | |
| 1341 | + movdqa [eax], xmm0 | |
| 1342 | + movdqa [eax+ebx], xmm1 | |
| 1343 | + movdqa [eax+2*ebx], xmm0 | |
| 1344 | + movdqa [eax+ecx], xmm1 | |
| 1345 | + lea eax, [eax+4*ebx] | |
| 1346 | + movdqa [eax], xmm0 | |
| 1347 | + movdqa [eax+ebx], xmm1 | |
| 1348 | + movdqa [eax+2*ebx], xmm0 | |
| 1349 | + movdqa [eax+ecx], xmm1 | |
| 1350 | + lea eax, [eax+4*ebx] | |
| 1351 | + movdqa [eax], xmm0 | |
| 1352 | + movdqa [eax+ebx], xmm1 | |
| 1353 | + movdqa [eax+2*ebx], xmm0 | |
| 1354 | + movdqa [eax+ecx], xmm1 | |
| 1355 | + lea eax, [eax+4*ebx] | |
| 1356 | + movdqa [eax], xmm0 | |
| 1357 | + movdqa [eax+ebx], xmm1 | |
| 1358 | + movdqa [eax+2*ebx], xmm0 | |
| 1359 | + movdqa [eax+ecx], xmm1 | |
| 1360 | + | |
| 1361 | + %undef PUSH_SIZE | |
| 1362 | + | |
| 1363 | + pop ebx | |
| 1364 | + ret | |
| 1365 | + | |
| 1366 | +ALIGN 16 | |
| 1367 | +;******************************************************************************* | |
| 1368 | +; void_t WelsIChromaPredDcLeft_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 1369 | +;******************************************************************************* | |
| 1370 | +WELS_EXTERN WelsIChromaPredDcLeft_mmx | |
| 1371 | +WelsIChromaPredDcLeft_mmx: | |
| 1372 | + push ebx | |
| 1373 | + push esi | |
| 1374 | + %define PUSH_SIZE 8 | |
| 1375 | + mov esi, [esp+PUSH_SIZE+4] ; pPred | |
| 1376 | + mov ecx, [esp+PUSH_SIZE+8] ; kiStride | |
| 1377 | + mov eax, esi | |
| 1378 | + ; for left | |
| 1379 | + dec eax | |
| 1380 | + xor ebx, ebx | |
| 1381 | + xor edx, edx | |
| 1382 | + mov bl, [eax] | |
| 1383 | + mov dl, [eax+ecx] | |
| 1384 | + add ebx, edx | |
| 1385 | + lea eax, [eax+2*ecx] | |
| 1386 | + mov dl, [eax] | |
| 1387 | + add ebx, edx | |
| 1388 | + mov dl, [eax+ecx] | |
| 1389 | + add ebx, edx | |
| 1390 | + add ebx, 02h | |
| 1391 | + sar ebx, 02h | |
| 1392 | + mov bh, bl | |
| 1393 | + movd mm1, ebx | |
| 1394 | + pshufw mm0, mm1, 00h ; up64 | |
| 1395 | + movq mm1, mm0 | |
| 1396 | + xor ebx, ebx | |
| 1397 | + lea eax, [eax+2*ecx] | |
| 1398 | + mov bl, [eax] | |
| 1399 | + mov dl, [eax+ecx] | |
| 1400 | + add ebx, edx | |
| 1401 | + lea eax, [eax+2*ecx] | |
| 1402 | + mov dl, [eax] | |
| 1403 | + add ebx, edx | |
| 1404 | + mov dl, [eax+ecx] | |
| 1405 | + add ebx, edx | |
| 1406 | + add ebx, 02h | |
| 1407 | + sar ebx, 02h | |
| 1408 | + mov bh, bl | |
| 1409 | + movd mm3, ebx | |
| 1410 | + pshufw mm2, mm3, 00h ; down64 | |
| 1411 | + movq mm3, mm2 | |
| 1412 | + lea ebx, [2*ecx+ecx] | |
| 1413 | + movq [esi], mm0 | |
| 1414 | + movq [esi+ecx], mm1 | |
| 1415 | + movq [esi+2*ecx], mm0 | |
| 1416 | + movq [esi+ebx], mm1 | |
| 1417 | + lea esi, [esi+4*ecx] | |
| 1418 | + movq [esi], mm2 | |
| 1419 | + movq [esi+ecx], mm3 | |
| 1420 | + movq [esi+2*ecx], mm2 | |
| 1421 | + movq [esi+ebx], mm3 | |
| 1422 | + pop esi | |
| 1423 | + pop ebx | |
| 1424 | + emms | |
| 1425 | + ret | |
| 1426 | + | |
| 1427 | +ALIGN 16 | |
| 1428 | +;******************************************************************************* | |
| 1429 | +; void_t WelsIChromaPredDcTop_sse2(uint8_t *pPred, const int32_t kiStride) | |
| 1430 | +;******************************************************************************* | |
| 1431 | +WELS_EXTERN WelsIChromaPredDcTop_sse2 | |
| 1432 | +WelsIChromaPredDcTop_sse2: | |
| 1433 | + push ebx | |
| 1434 | + %define PUSH_SIZE 4 | |
| 1435 | + mov eax, [esp+PUSH_SIZE+4] ; pPred | |
| 1436 | + mov ecx, [esp+PUSH_SIZE+8] ; kiStride | |
| 1437 | + mov ebx, ecx | |
| 1438 | + neg ebx | |
| 1439 | + movq xmm0, [eax+ebx] ; top: 8x1 pixels | |
| 1440 | + pxor xmm7, xmm7 | |
| 1441 | + punpcklbw xmm0, xmm7 ; ext 8x2 words | |
| 1442 | + pshufd xmm1, xmm0, 0B1h ; 10110001 B, w5 w4 w7 w6 w1 w0 w3 w2 | |
| 1443 | + paddw xmm0, xmm1 ; w5+7 w4+6 w5+7 w4+6 w1+3 w0+2 w1+3 w0+2 | |
| 1444 | + movdqa xmm1, xmm0 | |
| 1445 | + pshuflw xmm2, xmm0, 0B1h ; 10110001 B, .. w0+2 w1+3 w0+2 w1+3 | |
| 1446 | + pshufhw xmm3, xmm1, 0B1h ; 10110001 B, w4+6 w5+7 w4+6 w5+7 .. | |
| 1447 | + paddw xmm0, xmm2 ; .. w0+..+3 w0+..+3 w0+..+3 w0+..+3 | |
| 1448 | + paddw xmm1, xmm3 ; w4+..+7 w4+..+7 w4+..+7 w4+..+7 .. | |
| 1449 | + punpckhqdq xmm1, xmm7 | |
| 1450 | + punpcklqdq xmm0, xmm1 ; sum1 sum1 sum1 sum1 sum0 sum0 sum0 sum0 | |
| 1451 | + movdqa xmm6, [sse2_wd_0x02] | |
| 1452 | + paddw xmm0, xmm6 | |
| 1453 | + psraw xmm0, 02h | |
| 1454 | + packuswb xmm0, xmm7 | |
| 1455 | + lea ebx, [2*ecx+ecx] | |
| 1456 | + movq [eax], xmm0 | |
| 1457 | + movq [eax+ecx], xmm0 | |
| 1458 | + movq [eax+2*ecx], xmm0 | |
| 1459 | + movq [eax+ebx], xmm0 | |
| 1460 | + lea eax, [eax+4*ecx] | |
| 1461 | + movq [eax], xmm0 | |
| 1462 | + movq [eax+ecx], xmm0 | |
| 1463 | + movq [eax+2*ecx], xmm0 | |
| 1464 | + movq [eax+ebx], xmm0 | |
| 1465 | + %undef PUSH_SIZE | |
| 1466 | + pop ebx | |
| 1467 | + ret | |
| 1468 | + | |
| 1469 | + | |
| 1470 | +ALIGN 16 | |
| 1471 | +;******************************************************************************* | |
| 1472 | +; void_t WelsIChromaPredDcNA_mmx(uint8_t *pPred, const int32_t kiStride) | |
| 1473 | +;******************************************************************************* | |
| 1474 | +WELS_EXTERN WelsIChromaPredDcNA_mmx | |
| 1475 | +WelsIChromaPredDcNA_mmx: | |
| 1476 | + push ebx | |
| 1477 | + %define PUSH_SIZE 4 | |
| 1478 | + mov eax, [esp+PUSH_SIZE+4] ; pPred | |
| 1479 | + mov ebx, [esp+PUSH_SIZE+8] ; kiStride | |
| 1480 | + lea ecx, [2*ebx+ebx] | |
| 1481 | + movq mm0, [sse2_dc_0x80] | |
| 1482 | + movq mm1, mm0 | |
| 1483 | + movq [eax], mm0 | |
| 1484 | + movq [eax+ebx], mm1 | |
| 1485 | + movq [eax+2*ebx], mm0 | |
| 1486 | + movq [eax+ecx], mm1 | |
| 1487 | + lea eax, [eax+4*ebx] | |
| 1488 | + movq [eax], mm0 | |
| 1489 | + movq [eax+ebx], mm1 | |
| 1490 | + movq [eax+2*ebx], mm0 | |
| 1491 | + movq [eax+ecx], mm1 | |
| 1492 | + %undef PUSH_SIZE | |
| 1493 | + pop ebx | |
| 1494 | + emms | |
| 1495 | + ret | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| @@ -0,0 +1,330 @@ | ||
| 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 | +;* mb_copy.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* mb_copy and mb_copy1 | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 15/09/2009 Created | |
| 39 | +;* 12/28/2009 Modified with larger throughput | |
| 40 | +;* 12/29/2011 Tuned WelsCopy16x16NotAligned_sse2, added UpdateMbMv_sse2 WelsCopy16x8NotAligned_sse2, | |
| 41 | +;* WelsCopy16x8_mmx, WelsCopy8x16_mmx etc; | |
| 42 | +;* | |
| 43 | +;* | |
| 44 | +;*********************************************************************************************/ | |
| 45 | +%include "asm_inc.asm" | |
| 46 | +BITS 32 | |
| 47 | + | |
| 48 | +;******************************************************************************* | |
| 49 | +; Macros and other preprocessor constants | |
| 50 | +;******************************************************************************* | |
| 51 | + | |
| 52 | +;******************************************************************************* | |
| 53 | +; Local Data (Read Only) | |
| 54 | +;******************************************************************************* | |
| 55 | + | |
| 56 | +;SECTION .rodata data align=16 | |
| 57 | + | |
| 58 | +;******************************************************************************* | |
| 59 | +; Various memory constants (trigonometric values or rounding values) | |
| 60 | +;******************************************************************************* | |
| 61 | + | |
| 62 | +ALIGN 16 | |
| 63 | + | |
| 64 | +;******************************************************************************* | |
| 65 | +; Code | |
| 66 | +;******************************************************************************* | |
| 67 | + | |
| 68 | +SECTION .text | |
| 69 | + | |
| 70 | +WELS_EXTERN PixelAvgWidthEq4_mmx | |
| 71 | +WELS_EXTERN PixelAvgWidthEq8_mmx | |
| 72 | +WELS_EXTERN PixelAvgWidthEq16_sse2 | |
| 73 | + | |
| 74 | +WELS_EXTERN McCopyWidthEq4_mmx | |
| 75 | +WELS_EXTERN McCopyWidthEq8_mmx | |
| 76 | +WELS_EXTERN McCopyWidthEq16_sse2 | |
| 77 | + | |
| 78 | + | |
| 79 | +ALIGN 16 | |
| 80 | +;******************************************************************************* | |
| 81 | +; void_t PixelAvgWidthEq4_mmx( uint8_t *pDst, int iDstStride, | |
| 82 | +; uint8_t *pSrcA, int iSrcAStride, | |
| 83 | +; uint8_t *pSrcB, int iSrcBStride, | |
| 84 | +; int iHeight ); | |
| 85 | +;******************************************************************************* | |
| 86 | +PixelAvgWidthEq4_mmx: | |
| 87 | + | |
| 88 | + push esi | |
| 89 | + push edi | |
| 90 | + push ebp | |
| 91 | + push ebx | |
| 92 | + | |
| 93 | + mov edi, [esp+20] ; pDst | |
| 94 | + mov eax, [esp+24] ; iDstStride | |
| 95 | + mov esi, [esp+28] ; pSrcA | |
| 96 | + mov ecx, [esp+32] ; iSrcAStride | |
| 97 | + mov ebp, [esp+36] ; pSrcB | |
| 98 | + mov edx, [esp+40] ; iSrcBStride | |
| 99 | + mov ebx, [esp+44] ; iHeight | |
| 100 | +ALIGN 4 | |
| 101 | +.height_loop: | |
| 102 | + movd mm0, [ebp] | |
| 103 | + pavgb mm0, [esi] | |
| 104 | + movd [edi], mm0 | |
| 105 | + | |
| 106 | + dec ebx | |
| 107 | + lea edi, [edi+eax] | |
| 108 | + lea esi, [esi+ecx] | |
| 109 | + lea ebp, [ebp+edx] | |
| 110 | + jne .height_loop | |
| 111 | + | |
| 112 | + WELSEMMS | |
| 113 | + pop ebx | |
| 114 | + pop ebp | |
| 115 | + pop edi | |
| 116 | + pop esi | |
| 117 | + ret | |
| 118 | + | |
| 119 | +ALIGN 16 | |
| 120 | +;******************************************************************************* | |
| 121 | +; void_t PixelAvgWidthEq8_mmx( uint8_t *pDst, int iDstStride, | |
| 122 | +; uint8_t *pSrcA, int iSrcAStride, | |
| 123 | +; uint8_t *pSrcB, int iSrcBStride, | |
| 124 | +; int iHeight ); | |
| 125 | +;******************************************************************************* | |
| 126 | +PixelAvgWidthEq8_mmx: | |
| 127 | + | |
| 128 | + push esi | |
| 129 | + push edi | |
| 130 | + push ebp | |
| 131 | + push ebx | |
| 132 | + | |
| 133 | + mov edi, [esp+20] ; pDst | |
| 134 | + mov eax, [esp+24] ; iDstStride | |
| 135 | + mov esi, [esp+28] ; pSrcA | |
| 136 | + mov ecx, [esp+32] ; iSrcAStride | |
| 137 | + mov ebp, [esp+36] ; pSrcB | |
| 138 | + mov edx, [esp+40] ; iSrcBStride | |
| 139 | + mov ebx, [esp+44] ; iHeight | |
| 140 | +ALIGN 4 | |
| 141 | +.height_loop: | |
| 142 | + movq mm0, [esi] | |
| 143 | + pavgb mm0, [ebp] | |
| 144 | + movq [edi], mm0 | |
| 145 | + movq mm0, [esi+ecx] | |
| 146 | + pavgb mm0, [ebp+edx] | |
| 147 | + movq [edi+eax], mm0 | |
| 148 | + | |
| 149 | + lea esi, [esi+2*ecx] | |
| 150 | + lea ebp, [ebp+2*edx] | |
| 151 | + lea edi, [edi+2*eax] | |
| 152 | + | |
| 153 | + sub ebx, 2 | |
| 154 | + jnz .height_loop | |
| 155 | + | |
| 156 | + WELSEMMS | |
| 157 | + pop ebx | |
| 158 | + pop ebp | |
| 159 | + pop edi | |
| 160 | + pop esi | |
| 161 | + ret | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | +ALIGN 16 | |
| 166 | +;******************************************************************************* | |
| 167 | +; void_t PixelAvgWidthEq16_sse2( uint8_t *pDst, int iDstStride, | |
| 168 | +; uint8_t *pSrcA, int iSrcAStride, | |
| 169 | +; uint8_t *pSrcB, int iSrcBStride, | |
| 170 | +; int iHeight ); | |
| 171 | +;******************************************************************************* | |
| 172 | +PixelAvgWidthEq16_sse2: | |
| 173 | + push esi | |
| 174 | + push edi | |
| 175 | + push ebp | |
| 176 | + push ebx | |
| 177 | + | |
| 178 | + | |
| 179 | + mov edi, [esp+20] ; pDst | |
| 180 | + mov eax, [esp+24] ; iDstStride | |
| 181 | + mov esi, [esp+28] ; pSrcA | |
| 182 | + mov ecx, [esp+32] ; iSrcAStride | |
| 183 | + mov ebp, [esp+36] ; pSrcB | |
| 184 | + mov edx, [esp+40] ; iSrcBStride | |
| 185 | + mov ebx, [esp+44] ; iHeight | |
| 186 | +ALIGN 4 | |
| 187 | +.height_loop: | |
| 188 | + movdqu xmm0, [esi] | |
| 189 | + pavgb xmm0, [ebp] | |
| 190 | + movdqu [edi], xmm0 | |
| 191 | + | |
| 192 | + movdqu xmm0, [esi+ecx] | |
| 193 | + pavgb xmm0, [ebp+edx] | |
| 194 | + movdqu [edi+eax], xmm0 | |
| 195 | + | |
| 196 | + movdqu xmm0, [esi+2*ecx] | |
| 197 | + pavgb xmm0, [ebp+2*edx] | |
| 198 | + movdqu [edi+2*eax], xmm0 | |
| 199 | + | |
| 200 | + lea esi, [esi+2*ecx] | |
| 201 | + lea ebp, [ebp+2*edx] | |
| 202 | + lea edi, [edi+2*eax] | |
| 203 | + | |
| 204 | + movdqu xmm0, [esi+ecx] | |
| 205 | + pavgb xmm0, [ebp+edx] | |
| 206 | + movdqu [edi+eax], xmm0 | |
| 207 | + | |
| 208 | + lea esi, [esi+2*ecx] | |
| 209 | + lea ebp, [ebp+2*edx] | |
| 210 | + lea edi, [edi+2*eax] | |
| 211 | + | |
| 212 | + | |
| 213 | + sub ebx, 4 | |
| 214 | + jne .height_loop | |
| 215 | + | |
| 216 | + WELSEMMS | |
| 217 | + pop ebx | |
| 218 | + pop ebp | |
| 219 | + pop edi | |
| 220 | + pop esi | |
| 221 | + | |
| 222 | + ret | |
| 223 | + | |
| 224 | + | |
| 225 | +ALIGN 16 | |
| 226 | +;******************************************************************************* | |
| 227 | +; void_t McCopyWidthEq4_mmx( uint8_t *pSrc, int iSrcStride, | |
| 228 | +; uint8_t *pDst, int iDstStride, int iHeight ) | |
| 229 | +;******************************************************************************* | |
| 230 | +McCopyWidthEq4_mmx: | |
| 231 | + push esi | |
| 232 | + push edi | |
| 233 | + push ebx | |
| 234 | + | |
| 235 | + | |
| 236 | + mov esi, [esp+16] | |
| 237 | + mov eax, [esp+20] | |
| 238 | + mov edi, [esp+24] | |
| 239 | + mov ecx, [esp+28] | |
| 240 | + mov edx, [esp+32] | |
| 241 | +ALIGN 4 | |
| 242 | +.height_loop: | |
| 243 | + mov ebx, [esi] | |
| 244 | + mov [edi], ebx | |
| 245 | + | |
| 246 | + add esi, eax | |
| 247 | + add edi, ecx | |
| 248 | + dec edx | |
| 249 | + jnz .height_loop | |
| 250 | + WELSEMMS | |
| 251 | + pop ebx | |
| 252 | + pop edi | |
| 253 | + pop esi | |
| 254 | + ret | |
| 255 | + | |
| 256 | +ALIGN 16 | |
| 257 | +;******************************************************************************* | |
| 258 | +; void_t McCopyWidthEq8_mmx( uint8_t *pSrc, int iSrcStride, | |
| 259 | +; uint8_t *pDst, int iDstStride, int iHeight ) | |
| 260 | +;******************************************************************************* | |
| 261 | +McCopyWidthEq8_mmx: | |
| 262 | + push esi | |
| 263 | + push edi | |
| 264 | + mov esi, [esp+12] | |
| 265 | + mov eax, [esp+16] | |
| 266 | + mov edi, [esp+20] | |
| 267 | + mov ecx, [esp+24] | |
| 268 | + mov edx, [esp+28] | |
| 269 | + | |
| 270 | +ALIGN 4 | |
| 271 | +.height_loop: | |
| 272 | + movq mm0, [esi] | |
| 273 | + movq [edi], mm0 | |
| 274 | + add esi, eax | |
| 275 | + add edi, ecx | |
| 276 | + dec edx | |
| 277 | + jnz .height_loop | |
| 278 | + | |
| 279 | + WELSEMMS | |
| 280 | + pop edi | |
| 281 | + pop esi | |
| 282 | + ret | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | +ALIGN 16 | |
| 292 | +;******************************************************************************* | |
| 293 | +; void_t McCopyWidthEq16_sse2( uint8_t *pSrc, int iSrcStride, uint8_t *pDst, int iDstStride, int iHeight ) | |
| 294 | +;******************************************************************************* | |
| 295 | +;read unaligned memory | |
| 296 | +%macro SSE_READ_UNA 2 | |
| 297 | + movq %1, [%2] | |
| 298 | + movhps %1, [%2+8] | |
| 299 | +%endmacro | |
| 300 | + | |
| 301 | +;write unaligned memory | |
| 302 | +%macro SSE_WRITE_UNA 2 | |
| 303 | + movq [%1], %2 | |
| 304 | + movhps [%1+8], %2 | |
| 305 | +%endmacro | |
| 306 | +McCopyWidthEq16_sse2: | |
| 307 | + push esi | |
| 308 | + push edi | |
| 309 | + | |
| 310 | + mov esi, [esp+12] ; pSrc | |
| 311 | + mov eax, [esp+16] ; iSrcStride | |
| 312 | + mov edi, [esp+20] ; pDst | |
| 313 | + mov edx, [esp+24] ; iDstStride | |
| 314 | + mov ecx, [esp+28] ; iHeight | |
| 315 | + | |
| 316 | +ALIGN 4 | |
| 317 | +.height_loop: | |
| 318 | + SSE_READ_UNA xmm0, esi | |
| 319 | + SSE_READ_UNA xmm1, esi+eax | |
| 320 | + SSE_WRITE_UNA edi, xmm0 | |
| 321 | + SSE_WRITE_UNA edi+edx, xmm1 | |
| 322 | + | |
| 323 | + sub ecx, 2 | |
| 324 | + lea esi, [esi+eax*2] | |
| 325 | + lea edi, [edi+edx*2] | |
| 326 | + jnz .height_loop | |
| 327 | + | |
| 328 | + pop edi | |
| 329 | + pop esi | |
| 330 | + ret | |
| @@ -0,0 +1,317 @@ | ||
| 1 | +;*! | |
| 2 | +;* \copy | |
| 3 | +;* Copyright (c) 2004-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 | +;* mc_chroma.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* mmx motion compensation for chroma | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 10/13/2004 Created | |
| 39 | +;* | |
| 40 | +;* | |
| 41 | +;*************************************************************************/ | |
| 42 | +%include "asm_inc.asm" | |
| 43 | + | |
| 44 | +BITS 32 | |
| 45 | + | |
| 46 | +;*********************************************************************** | |
| 47 | +; Local Data (Read Only) | |
| 48 | +;*********************************************************************** | |
| 49 | + | |
| 50 | +SECTION .rodata align=16 | |
| 51 | + | |
| 52 | +;*********************************************************************** | |
| 53 | +; Various memory constants (trigonometric values or rounding values) | |
| 54 | +;*********************************************************************** | |
| 55 | + | |
| 56 | +ALIGN 16 | |
| 57 | +h264_d0x20_sse2: | |
| 58 | + dw 32,32,32,32,32,32,32,32 | |
| 59 | +ALIGN 16 | |
| 60 | +h264_d0x20_mmx: | |
| 61 | + dw 32,32,32,32 | |
| 62 | + | |
| 63 | + | |
| 64 | +;============================================================================= | |
| 65 | +; Code | |
| 66 | +;============================================================================= | |
| 67 | + | |
| 68 | +SECTION .text | |
| 69 | + | |
| 70 | +ALIGN 16 | |
| 71 | +;******************************************************************************* | |
| 72 | +; void McChromaWidthEq4_mmx( uint8_t *src, | |
| 73 | +; int32_t iSrcStride, | |
| 74 | +; uint8_t *pDst, | |
| 75 | +; int32_t iDstStride, | |
| 76 | +; uint8_t *pABCD, | |
| 77 | +; int32_t iHeigh ); | |
| 78 | +;******************************************************************************* | |
| 79 | +WELS_EXTERN McChromaWidthEq4_mmx | |
| 80 | +McChromaWidthEq4_mmx: | |
| 81 | + push esi | |
| 82 | + push edi | |
| 83 | + push ebx | |
| 84 | + | |
| 85 | + mov eax, [esp +12 + 20] | |
| 86 | + movd mm3, [eax] | |
| 87 | + WELS_Zero mm7 | |
| 88 | + punpcklbw mm3, mm3 | |
| 89 | + movq mm4, mm3 | |
| 90 | + punpcklwd mm3, mm3 | |
| 91 | + punpckhwd mm4, mm4 | |
| 92 | + | |
| 93 | + movq mm5, mm3 | |
| 94 | + punpcklbw mm3, mm7 | |
| 95 | + punpckhbw mm5, mm7 | |
| 96 | + | |
| 97 | + movq mm6, mm4 | |
| 98 | + punpcklbw mm4, mm7 | |
| 99 | + punpckhbw mm6, mm7 | |
| 100 | + | |
| 101 | + mov esi, [esp +12+ 4] | |
| 102 | + mov eax, [esp + 12 + 8] | |
| 103 | + mov edi, [esp + 12 + 12] | |
| 104 | + mov edx, [esp + 12 + 16] | |
| 105 | + mov ecx, [esp + 12 + 24] | |
| 106 | + | |
| 107 | + lea ebx, [esi + eax] | |
| 108 | + movd mm0, [esi] | |
| 109 | + movd mm1, [esi+1] | |
| 110 | + punpcklbw mm0, mm7 | |
| 111 | + punpcklbw mm1, mm7 | |
| 112 | +.xloop: | |
| 113 | + | |
| 114 | + pmullw mm0, mm3 | |
| 115 | + pmullw mm1, mm5 | |
| 116 | + paddw mm0, mm1 | |
| 117 | + | |
| 118 | + movd mm1, [ebx] | |
| 119 | + punpcklbw mm1, mm7 | |
| 120 | + movq mm2, mm1 | |
| 121 | + pmullw mm1, mm4 | |
| 122 | + paddw mm0, mm1 | |
| 123 | + | |
| 124 | + movd mm1, [ebx+1] | |
| 125 | + punpcklbw mm1, mm7 | |
| 126 | + movq mm7, mm1 | |
| 127 | + pmullw mm1,mm6 | |
| 128 | + paddw mm0, mm1 | |
| 129 | + movq mm1,mm7 | |
| 130 | + | |
| 131 | + paddw mm0, [h264_d0x20_mmx] | |
| 132 | + psrlw mm0, 6 | |
| 133 | + | |
| 134 | + WELS_Zero mm7 | |
| 135 | + packuswb mm0, mm7 | |
| 136 | + movd [edi], mm0 | |
| 137 | + | |
| 138 | + movq mm0, mm2 | |
| 139 | + | |
| 140 | + lea edi, [edi +edx ] | |
| 141 | + lea ebx, [ebx + eax] | |
| 142 | + | |
| 143 | + dec ecx | |
| 144 | + jnz near .xloop | |
| 145 | + WELSEMMS | |
| 146 | + pop ebx | |
| 147 | + pop edi | |
| 148 | + pop esi | |
| 149 | + ret | |
| 150 | + | |
| 151 | + | |
| 152 | +ALIGN 16 | |
| 153 | +;******************************************************************************* | |
| 154 | +; void McChromaWidthEq8_sse2( uint8_t *pSrc, | |
| 155 | +; int32_t iSrcStride, | |
| 156 | +; uint8_t *pDst, | |
| 157 | +; int32_t iDstStride, | |
| 158 | +; uint8_t *pABCD, | |
| 159 | +; int32_t iheigh ); | |
| 160 | +;******************************************************************************* | |
| 161 | +WELS_EXTERN McChromaWidthEq8_sse2 | |
| 162 | +McChromaWidthEq8_sse2: | |
| 163 | + push esi | |
| 164 | + push edi | |
| 165 | + push ebx | |
| 166 | + | |
| 167 | + mov eax, [esp +12 + 20] | |
| 168 | + movd xmm3, [eax] | |
| 169 | + WELS_Zero xmm7 | |
| 170 | + punpcklbw xmm3, xmm3 | |
| 171 | + punpcklwd xmm3, xmm3 | |
| 172 | + | |
| 173 | + movdqa xmm4, xmm3 | |
| 174 | + punpckldq xmm3, xmm3 | |
| 175 | + punpckhdq xmm4, xmm4 | |
| 176 | + movdqa xmm5, xmm3 | |
| 177 | + movdqa xmm6, xmm4 | |
| 178 | + | |
| 179 | + punpcklbw xmm3, xmm7 | |
| 180 | + punpckhbw xmm5, xmm7 | |
| 181 | + punpcklbw xmm4, xmm7 | |
| 182 | + punpckhbw xmm6, xmm7 | |
| 183 | + | |
| 184 | + mov esi, [esp +12+ 4] | |
| 185 | + mov eax, [esp + 12 + 8] | |
| 186 | + mov edi, [esp + 12 + 12] | |
| 187 | + mov edx, [esp + 12 + 16] | |
| 188 | + mov ecx, [esp + 12 + 24] | |
| 189 | + | |
| 190 | + lea ebx, [esi + eax] | |
| 191 | + movq xmm0, [esi] | |
| 192 | + movq xmm1, [esi+1] | |
| 193 | + punpcklbw xmm0, xmm7 | |
| 194 | + punpcklbw xmm1, xmm7 | |
| 195 | +.xloop: | |
| 196 | + | |
| 197 | + pmullw xmm0, xmm3 | |
| 198 | + pmullw xmm1, xmm5 | |
| 199 | + paddw xmm0, xmm1 | |
| 200 | + | |
| 201 | + movq xmm1, [ebx] | |
| 202 | + punpcklbw xmm1, xmm7 | |
| 203 | + movdqa xmm2, xmm1 | |
| 204 | + pmullw xmm1, xmm4 | |
| 205 | + paddw xmm0, xmm1 | |
| 206 | + | |
| 207 | + movq xmm1, [ebx+1] | |
| 208 | + punpcklbw xmm1, xmm7 | |
| 209 | + movdqa xmm7, xmm1 | |
| 210 | + pmullw xmm1, xmm6 | |
| 211 | + paddw xmm0, xmm1 | |
| 212 | + movdqa xmm1,xmm7 | |
| 213 | + | |
| 214 | + paddw xmm0, [h264_d0x20_sse2] | |
| 215 | + psrlw xmm0, 6 | |
| 216 | + | |
| 217 | + WELS_Zero xmm7 | |
| 218 | + packuswb xmm0, xmm7 | |
| 219 | + movq [edi], xmm0 | |
| 220 | + | |
| 221 | + movdqa xmm0, xmm2 | |
| 222 | + | |
| 223 | + lea edi, [edi +edx ] | |
| 224 | + lea ebx, [ebx + eax] | |
| 225 | + | |
| 226 | + dec ecx | |
| 227 | + jnz near .xloop | |
| 228 | + | |
| 229 | + pop ebx | |
| 230 | + pop edi | |
| 231 | + pop esi | |
| 232 | + ret | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | +ALIGN 16 | |
| 238 | +;*********************************************************************** | |
| 239 | +; void McChromaWidthEq8_ssse3( uint8_t *pSrc, | |
| 240 | +; int32_t iSrcStride, | |
| 241 | +; uint8_t *pDst, | |
| 242 | +; int32_t iDstStride, | |
| 243 | +; uint8_t *pABCD, | |
| 244 | +; int32_t iHeigh); | |
| 245 | +;*********************************************************************** | |
| 246 | +WELS_EXTERN McChromaWidthEq8_ssse3 | |
| 247 | +McChromaWidthEq8_ssse3: | |
| 248 | + push ebx | |
| 249 | + push esi | |
| 250 | + push edi | |
| 251 | + | |
| 252 | + mov eax, [esp + 12 + 20] | |
| 253 | + | |
| 254 | + pxor xmm7, xmm7 | |
| 255 | + movd xmm5, [eax] | |
| 256 | + punpcklwd xmm5, xmm5 | |
| 257 | + punpckldq xmm5, xmm5 | |
| 258 | + movdqa xmm6, xmm5 | |
| 259 | + punpcklqdq xmm5, xmm5 | |
| 260 | + punpckhqdq xmm6, xmm6 | |
| 261 | + | |
| 262 | + mov eax, [esp + 12 + 4] | |
| 263 | + mov edx, [esp + 12 + 8] | |
| 264 | + mov esi, [esp + 12 + 12] | |
| 265 | + mov edi, [esp + 12 + 16] | |
| 266 | + mov ecx, [esp + 12 + 24] | |
| 267 | + | |
| 268 | + sub esi, edi | |
| 269 | + sub esi, edi | |
| 270 | + movdqa xmm7, [h264_d0x20_sse2] | |
| 271 | + | |
| 272 | + movdqu xmm0, [eax] | |
| 273 | + movdqa xmm1, xmm0 | |
| 274 | + psrldq xmm1, 1 | |
| 275 | + punpcklbw xmm0, xmm1 | |
| 276 | + | |
| 277 | +.hloop_chroma: | |
| 278 | + lea esi, [esi+2*edi] | |
| 279 | + | |
| 280 | + movdqu xmm2, [eax+edx] | |
| 281 | + movdqa xmm3, xmm2 | |
| 282 | + psrldq xmm3, 1 | |
| 283 | + punpcklbw xmm2, xmm3 | |
| 284 | + movdqa xmm4, xmm2 | |
| 285 | + | |
| 286 | + pmaddubsw xmm0, xmm5 | |
| 287 | + pmaddubsw xmm2, xmm6 | |
| 288 | + paddw xmm0, xmm2 | |
| 289 | + paddw xmm0, xmm7 | |
| 290 | + psrlw xmm0, 6 | |
| 291 | + packuswb xmm0, xmm0 | |
| 292 | + movq [esi],xmm0 | |
| 293 | + | |
| 294 | + lea eax, [eax+2*edx] | |
| 295 | + movdqu xmm2, [eax] | |
| 296 | + movdqa xmm3, xmm2 | |
| 297 | + psrldq xmm3, 1 | |
| 298 | + punpcklbw xmm2, xmm3 | |
| 299 | + movdqa xmm0, xmm2 | |
| 300 | + | |
| 301 | + pmaddubsw xmm4, xmm5 | |
| 302 | + pmaddubsw xmm2, xmm6 | |
| 303 | + paddw xmm4, xmm2 | |
| 304 | + paddw xmm4, xmm7 | |
| 305 | + psrlw xmm4, 6 | |
| 306 | + packuswb xmm4, xmm4 | |
| 307 | + movq [esi+edi],xmm4 | |
| 308 | + | |
| 309 | + sub ecx, 2 | |
| 310 | + jnz .hloop_chroma | |
| 311 | + pop edi | |
| 312 | + pop esi | |
| 313 | + pop ebx | |
| 314 | + | |
| 315 | + ret | |
| 316 | + | |
| 317 | + | |
| @@ -0,0 +1,615 @@ | ||
| 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 | +;* mc_luma.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* sse2 motion compensation | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 17/08/2009 Created | |
| 39 | +;* | |
| 40 | +;* | |
| 41 | +;*************************************************************************/ | |
| 42 | +%include "asm_inc.asm" | |
| 43 | + | |
| 44 | +BITS 32 | |
| 45 | + | |
| 46 | +;******************************************************************************* | |
| 47 | +; Local Data (Read Only) | |
| 48 | +;******************************************************************************* | |
| 49 | + | |
| 50 | +SECTION .rodata align=16 | |
| 51 | + | |
| 52 | +;******************************************************************************* | |
| 53 | +; Various memory constants (trigonometric values or rounding values) | |
| 54 | +;******************************************************************************* | |
| 55 | + | |
| 56 | +ALIGN 16 | |
| 57 | +h264_w0x10: | |
| 58 | + dw 16, 16, 16, 16 | |
| 59 | + | |
| 60 | + | |
| 61 | +;******************************************************************************* | |
| 62 | +; Code | |
| 63 | +;******************************************************************************* | |
| 64 | + | |
| 65 | +SECTION .text | |
| 66 | + | |
| 67 | +WELS_EXTERN McHorVer20WidthEq4_mmx | |
| 68 | + | |
| 69 | + | |
| 70 | +ALIGN 16 | |
| 71 | +;******************************************************************************* | |
| 72 | +; void_t McHorVer20WidthEq4_mmx( uint8_t *pSrc, | |
| 73 | +; int iSrcStride, | |
| 74 | +; uint8_t *pDst, | |
| 75 | +; int iDstStride, | |
| 76 | +; int iHeight) | |
| 77 | +;******************************************************************************* | |
| 78 | +McHorVer20WidthEq4_mmx: | |
| 79 | + push esi | |
| 80 | + push edi | |
| 81 | + | |
| 82 | + mov esi, [esp+12] | |
| 83 | + mov eax, [esp+16] | |
| 84 | + mov edi, [esp+20] | |
| 85 | + mov ecx, [esp+24] | |
| 86 | + mov edx, [esp+28] | |
| 87 | + sub esi, 2 | |
| 88 | + WELS_Zero mm7 | |
| 89 | + movq mm6, [h264_w0x10] | |
| 90 | +.height_loop: | |
| 91 | + movd mm0, [esi] | |
| 92 | + punpcklbw mm0, mm7 | |
| 93 | + movd mm1, [esi+5] | |
| 94 | + punpcklbw mm1, mm7 | |
| 95 | + movd mm2, [esi+1] | |
| 96 | + punpcklbw mm2, mm7 | |
| 97 | + movd mm3, [esi+4] | |
| 98 | + punpcklbw mm3, mm7 | |
| 99 | + movd mm4, [esi+2] | |
| 100 | + punpcklbw mm4, mm7 | |
| 101 | + movd mm5, [esi+3] | |
| 102 | + punpcklbw mm5, mm7 | |
| 103 | + | |
| 104 | + paddw mm2, mm3 | |
| 105 | + paddw mm4, mm5 | |
| 106 | + psllw mm4, 2 | |
| 107 | + psubw mm4, mm2 | |
| 108 | + paddw mm0, mm1 | |
| 109 | + paddw mm0, mm4 | |
| 110 | + psllw mm4, 2 | |
| 111 | + paddw mm0, mm4 | |
| 112 | + paddw mm0, mm6 | |
| 113 | + psraw mm0, 5 | |
| 114 | + packuswb mm0, mm7 | |
| 115 | + movd [edi], mm0 | |
| 116 | + | |
| 117 | + add esi, eax | |
| 118 | + add edi, ecx | |
| 119 | + dec edx | |
| 120 | + jnz .height_loop | |
| 121 | + | |
| 122 | + WELSEMMS | |
| 123 | + pop edi | |
| 124 | + pop esi | |
| 125 | + ret | |
| 126 | + | |
| 127 | +;******************************************************************************* | |
| 128 | +; Macros and other preprocessor constants | |
| 129 | +;******************************************************************************* | |
| 130 | + | |
| 131 | + | |
| 132 | +%macro SSE_LOAD_8P 3 | |
| 133 | + movq %1, %3 | |
| 134 | + punpcklbw %1, %2 | |
| 135 | +%endmacro | |
| 136 | + | |
| 137 | +%macro FILTER_HV_W8 9 | |
| 138 | + paddw %1, %6 | |
| 139 | + movdqa %8, %3 | |
| 140 | + movdqa %7, %2 | |
| 141 | + paddw %1, [h264_w0x10_1] | |
| 142 | + paddw %8, %4 | |
| 143 | + paddw %7, %5 | |
| 144 | + psllw %8, 2 | |
| 145 | + psubw %8, %7 | |
| 146 | + paddw %1, %8 | |
| 147 | + psllw %8, 2 | |
| 148 | + paddw %1, %8 | |
| 149 | + psraw %1, 5 | |
| 150 | + WELS_Zero %8 | |
| 151 | + packuswb %1, %8 | |
| 152 | + movq %9, %1 | |
| 153 | +%endmacro | |
| 154 | + | |
| 155 | +;******************************************************************************* | |
| 156 | +; Local Data (Read Only) | |
| 157 | +;******************************************************************************* | |
| 158 | + | |
| 159 | +SECTION .rodata align=16 | |
| 160 | + | |
| 161 | +;******************************************************************************* | |
| 162 | +; Various memory constants (trigonometric values or rounding values) | |
| 163 | +;******************************************************************************* | |
| 164 | + | |
| 165 | +ALIGN 16 | |
| 166 | +h264_w0x10_1: | |
| 167 | + dw 16, 16, 16, 16, 16, 16, 16, 16 | |
| 168 | +ALIGN 16 | |
| 169 | +h264_mc_hc_32: | |
| 170 | +dw 32, 32, 32, 32, 32, 32, 32, 32 | |
| 171 | +;******************************************************************************* | |
| 172 | +; Code | |
| 173 | +;******************************************************************************* | |
| 174 | + | |
| 175 | +SECTION .text | |
| 176 | +WELS_EXTERN McHorVer22Width8HorFirst_sse2 | |
| 177 | +WELS_EXTERN McHorVer22VerLast_sse2 | |
| 178 | +WELS_EXTERN McHorVer02WidthEq8_sse2 | |
| 179 | +WELS_EXTERN McHorVer20WidthEq8_sse2 | |
| 180 | +WELS_EXTERN McHorVer20WidthEq16_sse2 | |
| 181 | + | |
| 182 | +ALIGN 16 | |
| 183 | +;*********************************************************************** | |
| 184 | +; void_t McHorVer22Width8HorFirst_sse2(int16_t *pSrc, | |
| 185 | +; int16_t iSrcStride, | |
| 186 | +; uint8_t *pDst, | |
| 187 | +; int32_t iDstStride | |
| 188 | +; int32_t iHeight | |
| 189 | +; ) | |
| 190 | +;*********************************************************************** | |
| 191 | +McHorVer22Width8HorFirst_sse2: | |
| 192 | + push esi | |
| 193 | + push edi | |
| 194 | + push ebx | |
| 195 | + mov esi, [esp+16] ;pSrc | |
| 196 | + mov eax, [esp+20] ;iSrcStride | |
| 197 | + mov edi, [esp+24] ;pDst | |
| 198 | + mov edx, [esp+28] ;iDstStride | |
| 199 | + mov ebx, [esp+32] ;iHeight | |
| 200 | + pxor xmm7, xmm7 | |
| 201 | + | |
| 202 | + sub esi, eax ;;;;;;;;need more 5 lines. | |
| 203 | + sub esi, eax | |
| 204 | + | |
| 205 | +.yloop_width_8: | |
| 206 | + movq xmm0, [esi] | |
| 207 | + punpcklbw xmm0, xmm7 | |
| 208 | + movq xmm1, [esi+5] | |
| 209 | + punpcklbw xmm1, xmm7 | |
| 210 | + movq xmm2, [esi+1] | |
| 211 | + punpcklbw xmm2, xmm7 | |
| 212 | + movq xmm3, [esi+4] | |
| 213 | + punpcklbw xmm3, xmm7 | |
| 214 | + movq xmm4, [esi+2] | |
| 215 | + punpcklbw xmm4, xmm7 | |
| 216 | + movq xmm5, [esi+3] | |
| 217 | + punpcklbw xmm5, xmm7 | |
| 218 | + | |
| 219 | + paddw xmm2, xmm3 | |
| 220 | + paddw xmm4, xmm5 | |
| 221 | + psllw xmm4, 2 | |
| 222 | + psubw xmm4, xmm2 | |
| 223 | + paddw xmm0, xmm1 | |
| 224 | + paddw xmm0, xmm4 | |
| 225 | + psllw xmm4, 2 | |
| 226 | + paddw xmm0, xmm4 | |
| 227 | + movdqa [edi], xmm0 | |
| 228 | + | |
| 229 | + add esi, eax | |
| 230 | + add edi, edx | |
| 231 | + dec ebx | |
| 232 | + jnz .yloop_width_8 | |
| 233 | + pop ebx | |
| 234 | + pop edi | |
| 235 | + pop esi | |
| 236 | + ret | |
| 237 | + | |
| 238 | +ALIGN 16 | |
| 239 | +;*********************************************************************** | |
| 240 | +;void_t McHorVer22VerLast_sse2( | |
| 241 | +; uint8_t *pSrc, | |
| 242 | +; int32_t pSrcStride, | |
| 243 | +; uint8_t * pDst, | |
| 244 | +; int32_t iDstStride, | |
| 245 | +; int32_t iWidth, | |
| 246 | +; int32_t iHeight); | |
| 247 | +;*********************************************************************** | |
| 248 | + | |
| 249 | +%macro FILTER_VER 9 | |
| 250 | + paddw %1, %6 | |
| 251 | + movdqa %7, %2 | |
| 252 | + movdqa %8, %3 | |
| 253 | + | |
| 254 | + | |
| 255 | + paddw %7, %5 | |
| 256 | + paddw %8, %4 | |
| 257 | + | |
| 258 | + psubw %1, %7 | |
| 259 | + psraw %1, 2 | |
| 260 | + paddw %1, %8 | |
| 261 | + psubw %1, %7 | |
| 262 | + psraw %1, 2 | |
| 263 | + paddw %8, %1 | |
| 264 | + paddw %8, [h264_mc_hc_32] | |
| 265 | + psraw %8, 6 | |
| 266 | + packuswb %8, %8 | |
| 267 | + movq %9, %8 | |
| 268 | +%endmacro | |
| 269 | + | |
| 270 | +McHorVer22VerLast_sse2: | |
| 271 | + push esi | |
| 272 | + push edi | |
| 273 | + push ebx | |
| 274 | + push ebp | |
| 275 | + | |
| 276 | + mov esi, [esp+20] | |
| 277 | + mov eax, [esp+24] | |
| 278 | + mov edi, [esp+28] | |
| 279 | + mov edx, [esp+32] | |
| 280 | + mov ebx, [esp+36] | |
| 281 | + mov ecx, [esp+40] | |
| 282 | + shr ebx, 3 | |
| 283 | + | |
| 284 | +.width_loop: | |
| 285 | + movdqa xmm0, [esi] | |
| 286 | + movdqa xmm1, [esi+eax] | |
| 287 | + lea esi, [esi+2*eax] | |
| 288 | + movdqa xmm2, [esi] | |
| 289 | + movdqa xmm3, [esi+eax] | |
| 290 | + lea esi, [esi+2*eax] | |
| 291 | + movdqa xmm4, [esi] | |
| 292 | + movdqa xmm5, [esi+eax] | |
| 293 | + | |
| 294 | + FILTER_VER xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, [edi] | |
| 295 | + dec ecx | |
| 296 | + lea esi, [esi+2*eax] | |
| 297 | + movdqa xmm6, [esi] | |
| 298 | + | |
| 299 | + movdqa xmm0, xmm1 | |
| 300 | + movdqa xmm1, xmm2 | |
| 301 | + movdqa xmm2, xmm3 | |
| 302 | + movdqa xmm3, xmm4 | |
| 303 | + movdqa xmm4, xmm5 | |
| 304 | + movdqa xmm5, xmm6 | |
| 305 | + | |
| 306 | + add edi, edx | |
| 307 | + sub esi, eax | |
| 308 | + | |
| 309 | +.start: | |
| 310 | + FILTER_VER xmm0,xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, [edi] | |
| 311 | + dec ecx | |
| 312 | + jz near .x_loop_dec | |
| 313 | + | |
| 314 | + lea esi, [esi+2*eax] | |
| 315 | + movdqa xmm6, [esi] | |
| 316 | + FILTER_VER xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm0,[edi+edx] | |
| 317 | + dec ecx | |
| 318 | + jz near .x_loop_dec | |
| 319 | + | |
| 320 | + lea edi, [edi+2*edx] | |
| 321 | + movdqa xmm7, [esi+eax] | |
| 322 | + FILTER_VER xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm0, xmm1, [edi] | |
| 323 | + dec ecx | |
| 324 | + jz near .x_loop_dec | |
| 325 | + | |
| 326 | + lea esi, [esi+2*eax] | |
| 327 | + movdqa xmm0, [esi] | |
| 328 | + FILTER_VER xmm3, xmm4, xmm5, xmm6, xmm7, xmm0, xmm1, xmm2,[edi+edx] | |
| 329 | + dec ecx | |
| 330 | + jz near .x_loop_dec | |
| 331 | + | |
| 332 | + lea edi, [edi+2*edx] | |
| 333 | + movdqa xmm1, [esi+eax] | |
| 334 | + FILTER_VER xmm4, xmm5, xmm6, xmm7, xmm0, xmm1, xmm2, xmm3,[edi] | |
| 335 | + dec ecx | |
| 336 | + jz near .x_loop_dec | |
| 337 | + | |
| 338 | + lea esi, [esi+2*eax] | |
| 339 | + movdqa xmm2, [esi] | |
| 340 | + FILTER_VER xmm5, xmm6, xmm7, xmm0, xmm1, xmm2, xmm3,xmm4,[edi+edx] | |
| 341 | + dec ecx | |
| 342 | + jz near .x_loop_dec | |
| 343 | + | |
| 344 | + lea edi, [edi+2*edx] | |
| 345 | + movdqa xmm3, [esi+eax] | |
| 346 | + FILTER_VER xmm6, xmm7, xmm0, xmm1, xmm2, xmm3,xmm4,xmm5,[edi] | |
| 347 | + dec ecx | |
| 348 | + jz near .x_loop_dec | |
| 349 | + | |
| 350 | + lea esi, [esi+2*eax] | |
| 351 | + movdqa xmm4, [esi] | |
| 352 | + FILTER_VER xmm7, xmm0, xmm1, xmm2, xmm3,xmm4,xmm5,xmm6, [edi+edx] | |
| 353 | + dec ecx | |
| 354 | + jz near .x_loop_dec | |
| 355 | + | |
| 356 | + lea edi, [edi+2*edx] | |
| 357 | + movdqa xmm5, [esi+eax] | |
| 358 | + jmp near .start | |
| 359 | + | |
| 360 | +.x_loop_dec: | |
| 361 | + dec ebx | |
| 362 | + jz near .exit | |
| 363 | + mov esi, [esp+20] | |
| 364 | + mov edi, [esp+28] | |
| 365 | + mov ecx, [esp+40] | |
| 366 | + add esi, 16 | |
| 367 | + add edi, 8 | |
| 368 | + jmp .width_loop | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | +.exit: | |
| 373 | + pop ebp | |
| 374 | + pop ebx | |
| 375 | + pop edi | |
| 376 | + pop esi | |
| 377 | + ret | |
| 378 | + | |
| 379 | + | |
| 380 | +ALIGN 16 | |
| 381 | +;******************************************************************************* | |
| 382 | +; void_t McHorVer20WidthEq8_sse2( uint8_t *pSrc, | |
| 383 | +; int iSrcStride, | |
| 384 | +; uint8_t *pDst, | |
| 385 | +; int iDstStride, | |
| 386 | +; int iHeight, | |
| 387 | +; ); | |
| 388 | +;******************************************************************************* | |
| 389 | +McHorVer20WidthEq8_sse2: | |
| 390 | + push esi | |
| 391 | + push edi | |
| 392 | + | |
| 393 | + mov esi, [esp + 12] ;pSrc | |
| 394 | + mov eax, [esp + 16] ;iSrcStride | |
| 395 | + mov edi, [esp + 20] ;pDst | |
| 396 | + mov ecx, [esp + 28] ;iHeight | |
| 397 | + mov edx, [esp + 24] ;iDstStride | |
| 398 | + | |
| 399 | + lea esi, [esi-2] ;pSrc -= 2; | |
| 400 | + | |
| 401 | + pxor xmm7, xmm7 | |
| 402 | + movdqa xmm6, [h264_w0x10_1] | |
| 403 | +.y_loop: | |
| 404 | + movq xmm0, [esi] | |
| 405 | + punpcklbw xmm0, xmm7 | |
| 406 | + movq xmm1, [esi+5] | |
| 407 | + punpcklbw xmm1, xmm7 | |
| 408 | + movq xmm2, [esi+1] | |
| 409 | + punpcklbw xmm2, xmm7 | |
| 410 | + movq xmm3, [esi+4] | |
| 411 | + punpcklbw xmm3, xmm7 | |
| 412 | + movq xmm4, [esi+2] | |
| 413 | + punpcklbw xmm4, xmm7 | |
| 414 | + movq xmm5, [esi+3] | |
| 415 | + punpcklbw xmm5, xmm7 | |
| 416 | + | |
| 417 | + paddw xmm2, xmm3 | |
| 418 | + paddw xmm4, xmm5 | |
| 419 | + psllw xmm4, 2 | |
| 420 | + psubw xmm4, xmm2 | |
| 421 | + paddw xmm0, xmm1 | |
| 422 | + paddw xmm0, xmm4 | |
| 423 | + psllw xmm4, 2 | |
| 424 | + paddw xmm0, xmm4 | |
| 425 | + paddw xmm0, xmm6 | |
| 426 | + psraw xmm0, 5 | |
| 427 | + | |
| 428 | + packuswb xmm0, xmm7 | |
| 429 | + movq [edi], xmm0 | |
| 430 | + | |
| 431 | + lea edi, [edi+edx] | |
| 432 | + lea esi, [esi+eax] | |
| 433 | + dec ecx | |
| 434 | + jnz near .y_loop | |
| 435 | + | |
| 436 | + pop edi | |
| 437 | + pop esi | |
| 438 | + ret | |
| 439 | + | |
| 440 | +ALIGN 16 | |
| 441 | +;******************************************************************************* | |
| 442 | +; void_t McHorVer20WidthEq16_sse2( uint8_t *pSrc, | |
| 443 | +; int iSrcStride, | |
| 444 | +; uint8_t *pDst, | |
| 445 | +; int iDstStride, | |
| 446 | +; int iHeight, | |
| 447 | +; ); | |
| 448 | +;******************************************************************************* | |
| 449 | +McHorVer20WidthEq16_sse2: | |
| 450 | + push esi | |
| 451 | + push edi | |
| 452 | + | |
| 453 | + | |
| 454 | + mov esi, [esp + 12] ;pSrc | |
| 455 | + mov eax, [esp + 16] ;iSrcStride | |
| 456 | + mov edi, [esp + 20] ;pDst | |
| 457 | + mov ecx, [esp + 28] ;iHeight | |
| 458 | + mov edx, [esp + 24] ;iDstStride | |
| 459 | + | |
| 460 | + lea esi, [esi-2] ;pSrc -= 2; | |
| 461 | + | |
| 462 | + pxor xmm7, xmm7 | |
| 463 | + movdqa xmm6, [h264_w0x10_1] | |
| 464 | +.y_loop: | |
| 465 | + | |
| 466 | + movq xmm0, [esi] | |
| 467 | + punpcklbw xmm0, xmm7 | |
| 468 | + movq xmm1, [esi+5] | |
| 469 | + punpcklbw xmm1, xmm7 | |
| 470 | + movq xmm2, [esi+1] | |
| 471 | + punpcklbw xmm2, xmm7 | |
| 472 | + movq xmm3, [esi+4] | |
| 473 | + punpcklbw xmm3, xmm7 | |
| 474 | + movq xmm4, [esi+2] | |
| 475 | + punpcklbw xmm4, xmm7 | |
| 476 | + movq xmm5, [esi+3] | |
| 477 | + punpcklbw xmm5, xmm7 | |
| 478 | + | |
| 479 | + paddw xmm2, xmm3 | |
| 480 | + paddw xmm4, xmm5 | |
| 481 | + psllw xmm4, 2 | |
| 482 | + psubw xmm4, xmm2 | |
| 483 | + paddw xmm0, xmm1 | |
| 484 | + paddw xmm0, xmm4 | |
| 485 | + psllw xmm4, 2 | |
| 486 | + paddw xmm0, xmm4 | |
| 487 | + paddw xmm0, xmm6 | |
| 488 | + psraw xmm0, 5 | |
| 489 | + packuswb xmm0, xmm7 | |
| 490 | + movq [edi], xmm0 | |
| 491 | + | |
| 492 | + movq xmm0, [esi+8] | |
| 493 | + punpcklbw xmm0, xmm7 | |
| 494 | + movq xmm1, [esi+5+8] | |
| 495 | + punpcklbw xmm1, xmm7 | |
| 496 | + movq xmm2, [esi+1+8] | |
| 497 | + punpcklbw xmm2, xmm7 | |
| 498 | + movq xmm3, [esi+4+8] | |
| 499 | + punpcklbw xmm3, xmm7 | |
| 500 | + movq xmm4, [esi+2+8] | |
| 501 | + punpcklbw xmm4, xmm7 | |
| 502 | + movq xmm5, [esi+3+8] | |
| 503 | + punpcklbw xmm5, xmm7 | |
| 504 | + | |
| 505 | + paddw xmm2, xmm3 | |
| 506 | + paddw xmm4, xmm5 | |
| 507 | + psllw xmm4, 2 | |
| 508 | + psubw xmm4, xmm2 | |
| 509 | + paddw xmm0, xmm1 | |
| 510 | + paddw xmm0, xmm4 | |
| 511 | + psllw xmm4, 2 | |
| 512 | + paddw xmm0, xmm4 | |
| 513 | + paddw xmm0, xmm6 | |
| 514 | + psraw xmm0, 5 | |
| 515 | + packuswb xmm0, xmm7 | |
| 516 | + movq [edi+8], xmm0 | |
| 517 | + | |
| 518 | + lea edi, [edi+edx] | |
| 519 | + lea esi, [esi+eax] | |
| 520 | + dec ecx | |
| 521 | + jnz near .y_loop | |
| 522 | + pop edi | |
| 523 | + pop esi | |
| 524 | + ret | |
| 525 | + | |
| 526 | + | |
| 527 | +;******************************************************************************* | |
| 528 | +; void_t McHorVer02WidthEq8_sse2( uint8_t *pSrc, | |
| 529 | +; int iSrcStride, | |
| 530 | +; uint8_t *pDst, | |
| 531 | +; int iDstStride, | |
| 532 | +; int iHeight ) | |
| 533 | +;******************************************************************************* | |
| 534 | +ALIGN 16 | |
| 535 | +McHorVer02WidthEq8_sse2: | |
| 536 | + push esi | |
| 537 | + push edi | |
| 538 | + | |
| 539 | + mov esi, [esp + 12] ;pSrc | |
| 540 | + mov edx, [esp + 16] ;iSrcStride | |
| 541 | + mov edi, [esp + 20] ;pDst | |
| 542 | + mov eax, [esp + 24] ;iDstStride | |
| 543 | + mov ecx, [esp + 28] ;iHeight | |
| 544 | + | |
| 545 | + sub esi, edx | |
| 546 | + sub esi, edx | |
| 547 | + | |
| 548 | + WELS_Zero xmm7 | |
| 549 | + | |
| 550 | + SSE_LOAD_8P xmm0, xmm7, [esi] | |
| 551 | + SSE_LOAD_8P xmm1, xmm7, [esi+edx] | |
| 552 | + lea esi, [esi+2*edx] | |
| 553 | + SSE_LOAD_8P xmm2, xmm7, [esi] | |
| 554 | + SSE_LOAD_8P xmm3, xmm7, [esi+edx] | |
| 555 | + lea esi, [esi+2*edx] | |
| 556 | + SSE_LOAD_8P xmm4, xmm7, [esi] | |
| 557 | + SSE_LOAD_8P xmm5, xmm7, [esi+edx] | |
| 558 | + | |
| 559 | +.start: | |
| 560 | + FILTER_HV_W8 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, [edi] | |
| 561 | + dec ecx | |
| 562 | + jz near .xx_exit | |
| 563 | + | |
| 564 | + lea esi, [esi+2*edx] | |
| 565 | + SSE_LOAD_8P xmm6, xmm7, [esi] | |
| 566 | + FILTER_HV_W8 xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm0, [edi+eax] | |
| 567 | + dec ecx | |
| 568 | + jz near .xx_exit | |
| 569 | + | |
| 570 | + lea edi, [edi+2*eax] | |
| 571 | + SSE_LOAD_8P xmm7, xmm0, [esi+edx] | |
| 572 | + FILTER_HV_W8 xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm0, xmm1, [edi] | |
| 573 | + dec ecx | |
| 574 | + jz near .xx_exit | |
| 575 | + | |
| 576 | + lea esi, [esi+2*edx] | |
| 577 | + SSE_LOAD_8P xmm0, xmm1, [esi] | |
| 578 | + FILTER_HV_W8 xmm3, xmm4, xmm5, xmm6, xmm7, xmm0, xmm1, xmm2, [edi+eax] | |
| 579 | + dec ecx | |
| 580 | + jz near .xx_exit | |
| 581 | + | |
| 582 | + lea edi, [edi+2*eax] | |
| 583 | + SSE_LOAD_8P xmm1, xmm2, [esi+edx] | |
| 584 | + FILTER_HV_W8 xmm4, xmm5, xmm6, xmm7, xmm0, xmm1, xmm2, xmm3, [edi] | |
| 585 | + dec ecx | |
| 586 | + jz near .xx_exit | |
| 587 | + | |
| 588 | + lea esi, [esi+2*edx] | |
| 589 | + SSE_LOAD_8P xmm2, xmm3, [esi] | |
| 590 | + FILTER_HV_W8 xmm5, xmm6, xmm7, xmm0, xmm1, xmm2, xmm3, xmm4, [edi+eax] | |
| 591 | + dec ecx | |
| 592 | + jz near .xx_exit | |
| 593 | + | |
| 594 | + lea edi, [edi+2*eax] | |
| 595 | + SSE_LOAD_8P xmm3, xmm4, [esi+edx] | |
| 596 | + FILTER_HV_W8 xmm6, xmm7, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, [edi] | |
| 597 | + dec ecx | |
| 598 | + jz near .xx_exit | |
| 599 | + | |
| 600 | + lea esi, [esi+2*edx] | |
| 601 | + SSE_LOAD_8P xmm4, xmm5, [esi] | |
| 602 | + FILTER_HV_W8 xmm7, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, [edi+eax] | |
| 603 | + dec ecx | |
| 604 | + jz near .xx_exit | |
| 605 | + | |
| 606 | + lea edi, [edi+2*eax] | |
| 607 | + SSE_LOAD_8P xmm5, xmm6, [esi+edx] | |
| 608 | + jmp near .start | |
| 609 | + | |
| 610 | +.xx_exit: | |
| 611 | + pop edi | |
| 612 | + pop esi | |
| 613 | + ret | |
| 614 | + | |
| 615 | + | |
| @@ -0,0 +1,135 @@ | ||
| 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 | +;* memzero.asm | |
| 33 | +;* | |
| 34 | +;* Abstract | |
| 35 | +;* | |
| 36 | +;* | |
| 37 | +;* History | |
| 38 | +;* 9/16/2009 Created | |
| 39 | +;* | |
| 40 | +;* | |
| 41 | +;*************************************************************************/ | |
| 42 | + | |
| 43 | +BITS 32 | |
| 44 | + | |
| 45 | +%include "asm_inc.asm" | |
| 46 | +;*********************************************************************** | |
| 47 | +; Code | |
| 48 | +;*********************************************************************** | |
| 49 | + | |
| 50 | +SECTION .text | |
| 51 | + | |
| 52 | +ALIGN 16 | |
| 53 | +;*********************************************************************** | |
| 54 | +;_inline void __cdecl WelsPrefetchZero_mmx(int8_t const*_A); | |
| 55 | +;*********************************************************************** | |
| 56 | +WELS_EXTERN WelsPrefetchZero_mmx | |
| 57 | +WelsPrefetchZero_mmx: | |
| 58 | + mov eax,[esp+4] | |
| 59 | + prefetchnta [eax] | |
| 60 | + ret | |
| 61 | + | |
| 62 | + | |
| 63 | +ALIGN 16 | |
| 64 | +;*********************************************************************** | |
| 65 | +; void WelsSetMemZeroAligned64_sse2(void *dst, int32_t size) | |
| 66 | +;*********************************************************************** | |
| 67 | +WELS_EXTERN WelsSetMemZeroAligned64_sse2 | |
| 68 | +WelsSetMemZeroAligned64_sse2: | |
| 69 | + mov eax, [esp + 4] ; dst | |
| 70 | + mov ecx, [esp + 8] | |
| 71 | + neg ecx | |
| 72 | + | |
| 73 | + pxor xmm0, xmm0 | |
| 74 | +.memzeroa64_sse2_loops: | |
| 75 | + movdqa [eax], xmm0 | |
| 76 | + movdqa [eax+16], xmm0 | |
| 77 | + movdqa [eax+32], xmm0 | |
| 78 | + movdqa [eax+48], xmm0 | |
| 79 | + add eax, 0x40 | |
| 80 | + | |
| 81 | + add ecx, 0x40 | |
| 82 | + jnz near .memzeroa64_sse2_loops | |
| 83 | + | |
| 84 | + ret | |
| 85 | + | |
| 86 | +ALIGN 16 | |
| 87 | +;*********************************************************************** | |
| 88 | +; void WelsSetMemZeroSize64_mmx(void *dst, int32_t size) | |
| 89 | +;*********************************************************************** | |
| 90 | +WELS_EXTERN WelsSetMemZeroSize64_mmx | |
| 91 | +WelsSetMemZeroSize64_mmx: | |
| 92 | + mov eax, [esp + 4] ; dst | |
| 93 | + mov ecx, [esp + 8] | |
| 94 | + neg ecx | |
| 95 | + | |
| 96 | + pxor mm0, mm0 | |
| 97 | +.memzero64_mmx_loops: | |
| 98 | + movq [eax], mm0 | |
| 99 | + movq [eax+8], mm0 | |
| 100 | + movq [eax+16], mm0 | |
| 101 | + movq [eax+24], mm0 | |
| 102 | + movq [eax+32], mm0 | |
| 103 | + movq [eax+40], mm0 | |
| 104 | + movq [eax+48], mm0 | |
| 105 | + movq [eax+56], mm0 | |
| 106 | + add eax, 0x40 | |
| 107 | + | |
| 108 | + add ecx, 0x40 | |
| 109 | + jnz near .memzero64_mmx_loops | |
| 110 | + | |
| 111 | + WELSEMMS | |
| 112 | + ret | |
| 113 | + | |
| 114 | +ALIGN 16 | |
| 115 | +;*********************************************************************** | |
| 116 | +; void WelsSetMemZeroSize8_mmx(void *dst, int32_t size) | |
| 117 | +;*********************************************************************** | |
| 118 | +WELS_EXTERN WelsSetMemZeroSize8_mmx | |
| 119 | +WelsSetMemZeroSize8_mmx: | |
| 120 | + mov eax, [esp + 4] ; dst | |
| 121 | + mov ecx, [esp + 8] ; size | |
| 122 | + neg ecx | |
| 123 | + pxor mm0, mm0 | |
| 124 | + | |
| 125 | +.memzero8_mmx_loops: | |
| 126 | + movq [eax], mm0 | |
| 127 | + add eax, 0x08 | |
| 128 | + | |
| 129 | + add ecx, 0x08 | |
| 130 | + jnz near .memzero8_mmx_loops | |
| 131 | + | |
| 132 | + WELSEMMS | |
| 133 | + ret | |
| 134 | + | |
| 135 | + | |
| @@ -0,0 +1,67 @@ | ||
| 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 common.h | |
| 33 | + * | |
| 34 | + * \brief common flag definitions | |
| 35 | + * | |
| 36 | + * \date 7/6/2009 Created | |
| 37 | + ************************************************************************************* | |
| 38 | + */ | |
| 39 | +#ifndef WELS_AS264_COMMON_H__ | |
| 40 | +#define WELS_AS264_COMMON_H__ | |
| 41 | +#define NO_WAITING_AU //slice level decoding | |
| 42 | +#define LONG_TERM_REF //for app | |
| 43 | + | |
| 44 | +#if defined(__cplusplus) | |
| 45 | +extern "C" { | |
| 46 | +#endif//__cplusplus | |
| 47 | + | |
| 48 | +#ifdef X86_ASM | |
| 49 | + | |
| 50 | +void MemZeroUnalign32Bytes(void *pSrc); | |
| 51 | +void MemZeroAlign32Bytes(void *pSrc); | |
| 52 | +void MemZeroUnalign16Bytes(void *pSrc); | |
| 53 | +void MemZeroAlign16Bytes(void *pSrc); | |
| 54 | +void MemZeroAlign128Bytes(void *pSrc); | |
| 55 | +void MemZeroUnalign128Bytes(void *pSrc); | |
| 56 | +void MemZeroAlign256Bytes(void *pSrc); | |
| 57 | +void MemZeroAlign240Bytes(void *pSrc); | |
| 58 | +void MmPrefetch0(char const *kpA); | |
| 59 | + | |
| 60 | +#endif// X86_ASM | |
| 61 | + | |
| 62 | +#if defined(__cplusplus) | |
| 63 | +} | |
| 64 | +#endif//__cplusplus | |
| 65 | + | |
| 66 | + | |
| 67 | +#endif // WELS_AS264_COMMON_H__ | |
| @@ -0,0 +1,158 @@ | ||
| 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 | + * \file au_parser.h | |
| 32 | + * | |
| 33 | + * \brief Interfaces introduced in Access Unit level based parser | |
| 34 | + * | |
| 35 | + * \date 03/10/2009 Created | |
| 36 | + * | |
| 37 | + ************************************************************************************* | |
| 38 | + */ | |
| 39 | +#ifndef WELS_ACCESS_UNIT_PARSER_H__ | |
| 40 | +#define WELS_ACCESS_UNIT_PARSER_H__ | |
| 41 | +#include "typedefs.h" | |
| 42 | +#include "wels_common_basis.h" | |
| 43 | +#include "nal_prefix.h" | |
| 44 | +#include "dec_frame.h" | |
| 45 | +#include "bit_stream.h" | |
| 46 | +#include "parameter_sets.h" | |
| 47 | +#include "decoder_context.h" | |
| 48 | + | |
| 49 | +namespace WelsDec { | |
| 50 | + | |
| 51 | +/*! | |
| 52 | + ************************************************************************************* | |
| 53 | + * \brief Start Code Prefix (0x 00 00 00 01) detection | |
| 54 | + * | |
| 55 | + * \param pBuf bitstream payload buffer | |
| 56 | + * \param pOffset offset between NAL rbsp and original bitsteam that | |
| 57 | + * start code prefix is seperated from. | |
| 58 | + * \param iBufSize count size of buffer | |
| 59 | + * | |
| 60 | + * \return RBSP buffer of start code prefix exclusive | |
| 61 | + * | |
| 62 | + * \note N/A | |
| 63 | + ************************************************************************************* | |
| 64 | + */ | |
| 65 | +uint8_t* DetectStartCodePrefix( const uint8_t *kpBuf, int32_t *pOffset, int32_t iBufSize ); | |
| 66 | + | |
| 67 | +/*! | |
| 68 | + ************************************************************************************* | |
| 69 | + * \brief to parse network abstraction layer unit, | |
| 70 | + * escape emulation_prevention_three_byte within it | |
| 71 | + former name is parse_nal | |
| 72 | + * | |
| 73 | + * \param pCtx decoder context | |
| 74 | + * \param pNalUnitHeader parsed result of NAL Unit Header to output | |
| 75 | + * \param pSrcRbsp bitstream buffer to input | |
| 76 | + * \param iSrcRbspLen length size of bitstream buffer payload | |
| 77 | + * \param pSrcNal | |
| 78 | + * \param iSrcNalLen | |
| 79 | + * \param pConsumedBytes consumed bytes during parsing | |
| 80 | + * | |
| 81 | + * \return decoded bytes payload, might be (pSrcRbsp+1) if no escapes | |
| 82 | + * | |
| 83 | + * \note N/A | |
| 84 | + ************************************************************************************* | |
| 85 | + */ | |
| 86 | +uint8_t* ParseNalHeader( PWelsDecoderContext pCtx, SNalUnitHeader *pNalUnitHeader, uint8_t *pSrcRbsp, int32_t iSrcRbspLen, uint8_t *pSrcNal, int32_t iSrcNalLen, int32_t* pConsumedBytes ); | |
| 87 | + | |
| 88 | +int32_t ParseNonVclNal( PWelsDecoderContext pCtx, uint8_t *pRbsp, const int32_t kiSrcLen ); | |
| 89 | + | |
| 90 | +void_t ParseRefBasePicMarking ( PBitStringAux pBs, PRefBasePicMarking pRefBasePicMarking ); | |
| 91 | + | |
| 92 | +void_t ParsePrefixNalUnit ( PWelsDecoderContext pCtx, PBitStringAux pBs ); | |
| 93 | + | |
| 94 | +bool_t CheckAccessUnitBoundary( const PNalUnit kpCurNal, const PNalUnit kpLastNal, const PSps kpSps ); | |
| 95 | +bool_t CheckAccessUnitBoundaryExt( PNalUnitHeaderExt pLastNalHdrExt, PNalUnitHeaderExt pCurNalHeaderExt, PSliceHeader pLastSliceHeader, PSliceHeader pCurSliceHeader ); | |
| 96 | +/*! | |
| 97 | + ************************************************************************************* | |
| 98 | + * \brief to parse Sequence Parameter Set (SPS) | |
| 99 | + * | |
| 100 | + * \param pCtx Decoder context | |
| 101 | + * \param pBsAux bitstream reader auxiliary | |
| 102 | + * \param pPicWidth picture width current Sps represented | |
| 103 | + * \param pPicHeight picture height current Sps represented | |
| 104 | + * | |
| 105 | + * \return 0 - successed | |
| 106 | + * 1 - failed | |
| 107 | + * | |
| 108 | + * \note Call it in case eNalUnitType is SPS. | |
| 109 | + ************************************************************************************* | |
| 110 | + */ | |
| 111 | +int32_t ParseSps( PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t *pPicWidth, int32_t *pPicHeight ); | |
| 112 | + | |
| 113 | +/*! | |
| 114 | + ************************************************************************************* | |
| 115 | + * \brief to parse Picture Parameter Set (PPS) | |
| 116 | + * | |
| 117 | + * \param pCtx Decoder context | |
| 118 | + * \param pPpsList pps list | |
| 119 | + * \param pBsAux bitstream reader auxiliary | |
| 120 | + * | |
| 121 | + * \return 0 - successed | |
| 122 | + * 1 - failed | |
| 123 | + * | |
| 124 | + * \note Call it in case eNalUnitType is PPS. | |
| 125 | + ************************************************************************************* | |
| 126 | + */ | |
| 127 | +int32_t ParsePps( PWelsDecoderContext pCtx, PPps pPpsList, PBitStringAux pBsAux ); | |
| 128 | + | |
| 129 | +/*! | |
| 130 | + ************************************************************************************* | |
| 131 | + * \brief to parse SEI message payload | |
| 132 | + * | |
| 133 | + * \param pSei sei message to be parsed output | |
| 134 | + * \param pBsAux bitstream reader auxiliary | |
| 135 | + * | |
| 136 | + * \return 0 - successed | |
| 137 | + * 1 - failed | |
| 138 | + * | |
| 139 | + * \note Call it in case eNalUnitType is NAL_UNIT_SEI. | |
| 140 | + ************************************************************************************* | |
| 141 | + */ | |
| 142 | +int32_t ParseSei( void_t *pSei, PBitStringAux pBsAux ); // reserved Sei_Msg type | |
| 143 | + | |
| 144 | +/*! | |
| 145 | + ************************************************************************************* | |
| 146 | + * \brief reset fmo list due to got Sps now | |
| 147 | + * | |
| 148 | + * \param pCtx decoder context | |
| 149 | + * | |
| 150 | + * \return count number of fmo context units are reset | |
| 151 | + ************************************************************************************* | |
| 152 | + */ | |
| 153 | +int32_t ResetFmoList( PWelsDecoderContext pCtx ); | |
| 154 | + | |
| 155 | +} // namespace WelsDec | |
| 156 | + | |
| 157 | +#endif//WELS_ACCESS_UNIT_PARSER_H__ | |
| 158 | + | |
| @@ -0,0 +1,77 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2004-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 | + | |
| 33 | + //bit_stream.h - bit-stream reading and / writing auxiliary data | |
| 34 | +#ifndef WELS_BIT_STREAM_H__ | |
| 35 | +#define WELS_BIT_STREAM_H__ | |
| 36 | + | |
| 37 | +#include "typedefs.h" | |
| 38 | + | |
| 39 | +namespace WelsDec { | |
| 40 | + | |
| 41 | +/* | |
| 42 | + * Bit-stream auxiliary reading / writing | |
| 43 | + */ | |
| 44 | +typedef struct TagBitStringAux { | |
| 45 | + uint8_t *pStartBuf; // buffer to start position | |
| 46 | + uint8_t *pEndBuf; // buffer + length | |
| 47 | + int32_t iBits; // count bits of overall bitstreaming input | |
| 48 | + | |
| 49 | + int32_t iIndex; //only for cavlc usage | |
| 50 | + uint8_t *pCurBuf; // current reading position | |
| 51 | + uint32_t uiCurBits; | |
| 52 | + int32_t iLeftBits; // count number of available bits left ([1, 8]), | |
| 53 | + // need pointer to next byte start position in case 0 bit left then 8 instead | |
| 54 | +}SBitStringAux, *PBitStringAux; | |
| 55 | + | |
| 56 | +//#pragma pack() | |
| 57 | + | |
| 58 | +/*! | |
| 59 | + * \brief input bits for decoder or initialize bitstream writing in encoder | |
| 60 | + * | |
| 61 | + * \param pBitString Bit string auxiliary pointer | |
| 62 | + * \param kpBuf bit-stream buffer | |
| 63 | + * \param kiSize size in bits for decoder; size in bytes for encoder | |
| 64 | + * | |
| 65 | + * \return size of buffer data in byte; failed in -1 return | |
| 66 | + */ | |
| 67 | +int32_t InitBits( PBitStringAux pBitString, const uint8_t *kpBuf, const int32_t kiSize ); | |
| 68 | + | |
| 69 | +void_t InitReadBits( PBitStringAux pBitString ); | |
| 70 | + | |
| 71 | +uint32_t EndianFix(uint32_t uiX); | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | +} // namespace WelsDec | |
| 76 | + | |
| 77 | +#endif//WELS_BIT_STREAM_H__ | |
| @@ -0,0 +1,80 @@ | ||
| 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 cpu.h | |
| 33 | + * | |
| 34 | + * \brief CPU feature compatibility detection | |
| 35 | + * | |
| 36 | + * \date 04/29/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#if !defined(WELS_CPU_DETECTION_H__) | |
| 41 | +#define WELS_CPU_DETECTION_H__ | |
| 42 | + | |
| 43 | +#include "typedefs.h" | |
| 44 | + | |
| 45 | +namespace WelsDec { | |
| 46 | + | |
| 47 | +#if defined(__cplusplus) | |
| 48 | +extern "C" { | |
| 49 | +#endif//__cplusplus | |
| 50 | + | |
| 51 | +#if defined(X86_ASM) | |
| 52 | +/* | |
| 53 | + * cpuid support verify routine | |
| 54 | + * return 0 if cpuid is not supported by cpu | |
| 55 | + */ | |
| 56 | +int32_t WelsCPUIdVerify(); | |
| 57 | + | |
| 58 | +void_t WelsCPUId( uint32_t uiIndex, uint32_t *pFeatureA, uint32_t *pFeatureB, uint32_t *pFeatureC, uint32_t *pFeatureD ); | |
| 59 | + | |
| 60 | +int32_t WelsCPUSupportAVX( uint32_t eax, uint32_t ecx ); | |
| 61 | +int32_t WelsCPUSupportFMA( uint32_t eax, uint32_t ecx ); | |
| 62 | + | |
| 63 | +void_t WelsEmms(); | |
| 64 | + | |
| 65 | +uint32_t WelsCPUFeatureDetect( int32_t *pNumberOfLogicProcessors ); | |
| 66 | + | |
| 67 | +/* | |
| 68 | + * clear FPU registers states for potential float based calculation if support | |
| 69 | + */ | |
| 70 | +void WelsCPURestore( const uint32_t kuiCPU ); | |
| 71 | + | |
| 72 | +#endif | |
| 73 | + | |
| 74 | +#if defined(__cplusplus) | |
| 75 | +} | |
| 76 | +#endif//__cplusplus | |
| 77 | + | |
| 78 | +} // namespace WelsDec | |
| 79 | + | |
| 80 | +#endif//WELS_CPU_DETECTION_H__ | |
| @@ -0,0 +1,80 @@ | ||
| 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 cpu_core.h | |
| 33 | + * | |
| 34 | + * \brief cpu core feature detection | |
| 35 | + * | |
| 36 | + * \date 4/24/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#if !defined(WELS_CPU_CORE_FEATURE_DETECTION_H__) | |
| 41 | +#define WELS_CPU_CORE_FEATURE_DETECTION_H__ | |
| 42 | + | |
| 43 | +/* | |
| 44 | + * WELS CPU feature flags | |
| 45 | + */ | |
| 46 | +#define WELS_CPU_MMX 0x00000001 /* mmx */ | |
| 47 | +#define WELS_CPU_MMXEXT 0x00000002 /* mmx-ext*/ | |
| 48 | +#define WELS_CPU_SSE 0x00000004 /* sse */ | |
| 49 | +#define WELS_CPU_SSE2 0x00000008 /* sse 2 */ | |
| 50 | +#define WELS_CPU_SSE3 0x00000010 /* sse 3 */ | |
| 51 | +#define WELS_CPU_SSE41 0x00000020 /* sse 4.1 */ | |
| 52 | +#define WELS_CPU_3DNOW 0x00000040 /* 3dnow! */ | |
| 53 | +#define WELS_CPU_3DNOWEXT 0x00000080 /* 3dnow! ext */ | |
| 54 | +#define WELS_CPU_ALTIVEC 0x00000100 /* altivec */ | |
| 55 | +#define WELS_CPU_SSSE3 0x00000200 /* ssse3 */ | |
| 56 | +#define WELS_CPU_SSE42 0x00000400 /* sse 4.2 */ | |
| 57 | + | |
| 58 | +/* CPU features application extensive */ | |
| 59 | +#define WELS_CPU_AVX 0x00000800 /* Advanced Vector eXtentions */ | |
| 60 | +#define WELS_CPU_FPU 0x00001000 /* x87-FPU on chip */ | |
| 61 | +#define WELS_CPU_HTT 0x00002000 /* Hyper-Threading Technology (HTT), Multi-threading enabled feature: | |
| 62 | + physical processor package is capable of supporting more than one logic processor | |
| 63 | + */ | |
| 64 | +#define WELS_CPU_CMOV 0x00004000 /* Conditional Move Instructions, | |
| 65 | + also if x87-FPU is present at indicated by the CPUID.FPU feature bit, then FCOMI and FCMOV are supported | |
| 66 | + */ | |
| 67 | +#define WELS_CPU_MOVBE 0x00008000 /* MOVBE instruction */ | |
| 68 | +#define WELS_CPU_AES 0x00010000 /* AES instruction extensions */ | |
| 69 | +#define WELS_CPU_FMA 0x00020000 /* AVX VEX FMA instruction sets */ | |
| 70 | + | |
| 71 | +#define WELS_CPU_CACHELINE_16 0x10000000 /* CacheLine Size 16 */ | |
| 72 | +#define WELS_CPU_CACHELINE_32 0x20000000 /* CacheLine Size 32 */ | |
| 73 | +#define WELS_CPU_CACHELINE_64 0x40000000 /* CacheLine Size 64 */ | |
| 74 | +#define WELS_CPU_CACHELINE_128 0x80000000 /* CacheLine Size 128 */ | |
| 75 | + | |
| 76 | +/* | |
| 77 | + * Interfaces for CPU core feature detection as below | |
| 78 | + */ | |
| 79 | + | |
| 80 | +#endif//WELS_CPU_CORE_FEATURE_DETECTION_H__ | |
| @@ -0,0 +1,104 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2010-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 crt_util_safe_x.h | |
| 33 | + * | |
| 34 | + * \brief Safe CRT like util for cross platfroms support | |
| 35 | + * | |
| 36 | + * \date 06/04/2010 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#ifndef WELS_CRT_UTIL_SAFE_CROSS_PLATFORMS_H__ | |
| 41 | +#define WELS_CRT_UTIL_SAFE_CROSS_PLATFORMS_H__ | |
| 42 | + | |
| 43 | +#include <string.h> | |
| 44 | +#include <stdlib.h> | |
| 45 | +#include <stdarg.h> | |
| 46 | +#include <stdio.h> | |
| 47 | +#include <math.h> | |
| 48 | +#include <time.h> | |
| 49 | + | |
| 50 | +#if defined(WIN32) | |
| 51 | +#include <windows.h> | |
| 52 | +#include <sys/types.h> | |
| 53 | +#include <sys/timeb.h> | |
| 54 | +#else | |
| 55 | +#include <sys/timeb.h> | |
| 56 | +#include <sys/time.h> | |
| 57 | +#include "typedefs.h" | |
| 58 | +#endif//WIN32 | |
| 59 | + | |
| 60 | +#include "typedefs.h" | |
| 61 | + | |
| 62 | +namespace WelsDec { | |
| 63 | + | |
| 64 | +#ifdef __cplusplus | |
| 65 | +extern "C" { | |
| 66 | +#endif | |
| 67 | + | |
| 68 | +#define WELS_FILE_SEEK_SET SEEK_SET | |
| 69 | +#define WELS_FILE_SEEK_CUR SEEK_CUR | |
| 70 | +#define WESL_FILE_SEEK_END SEEK_END | |
| 71 | + | |
| 72 | +typedef FILE WelsFileHandle; | |
| 73 | + | |
| 74 | +#ifdef WIN32 | |
| 75 | +typedef struct _timeb SWelsTime; | |
| 76 | +#else | |
| 77 | +typedef struct timeb SWelsTime; | |
| 78 | +#endif | |
| 79 | + | |
| 80 | +int32_t WelsSnprintf( str_t * buffer, int32_t sizeOfBuffer, const str_t * format, ... ); | |
| 81 | +str_t * WelsStrncpy(str_t * dest, int32_t sizeInBytes, const str_t * src, int32_t count); | |
| 82 | +str_t * WelsStrcat(str_t * dest, int32_t sizeInBytes, str_t * src); | |
| 83 | +int32_t WelsStrnlen(const str_t * str, int32_t maxlen); | |
| 84 | +int32_t WelsVsprintf(str_t * buffer, int32_t sizeOfBuffer, const str_t * format, va_list argptr); | |
| 85 | + | |
| 86 | +WelsFileHandle * WelsFopen(const str_t * filename, const str_t * mode); | |
| 87 | +int32_t WelsFclose(WelsFileHandle * fp); | |
| 88 | +int32_t WelsFread(void * buffer, int32_t size, int32_t count, WelsFileHandle * fp); | |
| 89 | +int32_t WelsFwrite(const void * buffer, int32_t size, int32_t count, WelsFileHandle * fp); | |
| 90 | +int32_t WelsFseek(WelsFileHandle * fp, int32_t offset, int32_t origin); | |
| 91 | +int32_t WelsFflush(WelsFileHandle * fp); | |
| 92 | + | |
| 93 | +int32_t WelsGetTimeOfDay(SWelsTime * tp); | |
| 94 | +int32_t WelsStrftime(str_t * buffer, int32_t size, const str_t * format, const SWelsTime * tp); | |
| 95 | +uint16_t WelsGetMillsecond(const SWelsTime * tp); | |
| 96 | + | |
| 97 | + | |
| 98 | +#ifdef __cplusplus | |
| 99 | +} | |
| 100 | +#endif | |
| 101 | + | |
| 102 | +} // namespace WelsDec | |
| 103 | + | |
| 104 | +#endif//WELS_CRT_UTIL_SAFE_CROSS_PLATFORMS_H__ | |
| @@ -0,0 +1,128 @@ | ||
| 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 deblocking.h | |
| 33 | + * | |
| 34 | + * \brief Interfaces introduced in frame deblocking filtering | |
| 35 | + * | |
| 36 | + * \date 05/14/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | + | |
| 41 | +#ifndef WELS_DEBLOCKING_H__ | |
| 42 | +#define WELS_DEBLOCKING_H__ | |
| 43 | + | |
| 44 | +#include "decoder_context.h" | |
| 45 | + | |
| 46 | +//#pragma pack(1) | |
| 47 | + | |
| 48 | +namespace WelsDec { | |
| 49 | + | |
| 50 | +/*! | |
| 51 | + * \brief deblocking module initialize | |
| 52 | + * | |
| 53 | + * \param pf | |
| 54 | + * cpu | |
| 55 | + * | |
| 56 | + * \return NONE | |
| 57 | + */ | |
| 58 | + | |
| 59 | +void_t DeblockingInit( PDeblockingFunc pDeblockingFunc, int32_t iCpu ); | |
| 60 | + | |
| 61 | + | |
| 62 | +/*! | |
| 63 | + * \brief deblocking filtering target slice | |
| 64 | + * | |
| 65 | + * \param dec Wels decoder context | |
| 66 | + * | |
| 67 | + * \return NONE | |
| 68 | + */ | |
| 69 | +void_t WelsDeblockingFilterSlice( PWelsDecoderContext pCtx, PDeblockingFilterMbFunc pDeblockMb ); | |
| 70 | + | |
| 71 | +/*! | |
| 72 | + * \brief pixel deblocking filtering | |
| 73 | + * | |
| 74 | + * \param filter deblocking filter | |
| 75 | + * \param pix pixel value | |
| 76 | + * \param stride frame stride | |
| 77 | + * \param bs boundary strength | |
| 78 | + * | |
| 79 | + * \return NONE | |
| 80 | + */ | |
| 81 | + | |
| 82 | +uint32_t DeblockingBsMarginalMBAvcbase( PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy); | |
| 83 | + | |
| 84 | +int32_t DeblockingAvailableNoInterlayer( PDqLayer pCurDqLayer, int32_t iFilterIdc ); | |
| 85 | + | |
| 86 | +void_t DeblockingIntraMb( PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag ); | |
| 87 | +void_t DeblockingInterMb( PDqLayer pCurDqLayer, PDeblockingFilter pFilter, uint8_t nBS[2][4][4], int32_t iBoundryFlag ); | |
| 88 | + | |
| 89 | +void_t WelsDeblockingMb( PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag ); | |
| 90 | + | |
| 91 | +void_t DeblockLumaLt4V_c( uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *pTc ); | |
| 92 | +void_t DeblockLumaEq4V_c( uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta ); | |
| 93 | + | |
| 94 | +void_t DeblockLumaLt4H_c( uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *pTc ); | |
| 95 | +void_t DeblockLumaEq4H_c( uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta ); | |
| 96 | + | |
| 97 | +void_t DeblockChromaLt4V_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *pTc ); | |
| 98 | +void_t DeblockChromaEq4V_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta ); | |
| 99 | + | |
| 100 | +void_t DeblockChromaLt4H_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *pTc ); | |
| 101 | +void_t DeblockChromaEq4H_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta ); | |
| 102 | + | |
| 103 | +#if defined(__cplusplus) | |
| 104 | +extern "C" { | |
| 105 | +#endif//__cplusplus | |
| 106 | + | |
| 107 | +#ifdef X86_ASM | |
| 108 | +void DeblockLumaLt4V_sse2( uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *pTc ); | |
| 109 | +void DeblockLumaEq4V_sse2( uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta ); | |
| 110 | +void DeblockLumaTransposeH2V_sse2(uint8_t * pPixY, int32_t iStride, uint8_t * pDst); | |
| 111 | +void DeblockLumaTransposeV2H_sse2(uint8_t * pPixY, int32_t iStride, uint8_t * pSrc); | |
| 112 | +void DeblockLumaLt4H_sse2(uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *pTc); | |
| 113 | +void DeblockLumaEq4H_sse2(uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta); | |
| 114 | +void DeblockChromaEq4V_sse2(uint8_t * pPixCb, uint8_t * pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta); | |
| 115 | +void DeblockChromaLt4V_sse2(uint8_t * pPixCb, uint8_t * pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t * pTC); | |
| 116 | +void DeblockChromaEq4H_sse2(uint8_t * pPixCb, uint8_t * pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta); | |
| 117 | +void DeblockChromaLt4H_sse2(uint8_t * pPixCb, uint8_t * pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t * pTC); | |
| 118 | +#endif | |
| 119 | +#if defined(__cplusplus) | |
| 120 | +} | |
| 121 | +#endif//__cplusplus | |
| 122 | + | |
| 123 | +} // namespace WelsDec | |
| 124 | + | |
| 125 | +//#pragma pack() | |
| 126 | + | |
| 127 | +#endif //WELS_DEBLOCKING_H__ | |
| 128 | + | |
| @@ -0,0 +1,143 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +//dec_frame.h | |
| 34 | +#ifndef WELS_DEC_FRAME_H__ | |
| 35 | +#define WELS_DEC_FRAME_H__ | |
| 36 | + | |
| 37 | +#include "typedefs.h" | |
| 38 | +#include "wels_const.h" | |
| 39 | +#include "wels_common_basis.h" | |
| 40 | +#include "parameter_sets.h" | |
| 41 | +#include "nal_prefix.h" | |
| 42 | +#include "slice.h" | |
| 43 | +#include "picture.h" | |
| 44 | +#include "bit_stream.h" | |
| 45 | +#include "fmo.h" | |
| 46 | + | |
| 47 | +namespace WelsDec { | |
| 48 | + | |
| 49 | +///////////////////////////////////DQ Layer level/////////////////////////////////// | |
| 50 | +typedef struct TagDqLayer SDqLayer; | |
| 51 | +typedef SDqLayer* PDqLayer; | |
| 52 | +typedef struct TagLayerInfo{ | |
| 53 | + SNalUnitHeaderExt sNalHeaderExt; | |
| 54 | + SSlice sSliceInLayer; // Here Slice identify to Frame on concept | |
| 55 | + PSubsetSps pSubsetSps; // current pSubsetSps used, memory alloc in external | |
| 56 | + PSps pSps; // current sps based avc used, memory alloc in external | |
| 57 | + PPps pPps; // current pps used | |
| 58 | +} SLayerInfo, *PLayerInfo; | |
| 59 | +/* Layer Representation */ | |
| 60 | + | |
| 61 | +struct TagDqLayer{ | |
| 62 | + SLayerInfo sLayerInfo; | |
| 63 | + | |
| 64 | + uint8_t *pCsData[3]; // pointer to reconstructed picture data | |
| 65 | + int32_t iCsStride[3]; // Cs stride | |
| 66 | + PBitStringAux pBitStringAux; // pointer to SBitStringAux | |
| 67 | + PFmo pFmo; // Current fmo context pointer used | |
| 68 | + int8_t *pMbType; | |
| 69 | + int32_t *pSliceIdc; // using int32_t for slice_idc | |
| 70 | + int16_t (*pMv[LIST_A])[MB_BLOCK4x4_NUM][MV_A]; | |
| 71 | + int8_t (*pRefIndex[LIST_A])[MB_BLOCK4x4_NUM]; | |
| 72 | + int8_t *pLumaQp; | |
| 73 | + int8_t *pChromaQp; | |
| 74 | + int8_t *pCbp; | |
| 75 | + int8_t (*pNzc)[24]; | |
| 76 | + int8_t (*pNzcRs)[24]; | |
| 77 | + int8_t *pResidualPredFlag; | |
| 78 | + int8_t *pInterPredictionDoneFlag; | |
| 79 | + int16_t (*pScaledTCoeff)[MB_COEFF_LIST_SIZE]; | |
| 80 | + int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16 | |
| 81 | + int8_t (*pIntra4x4FinalMode)[MB_BLOCK4x4_NUM]; | |
| 82 | + int8_t *pChromaPredMode; | |
| 83 | + //uint8_t (*motion_pred_flag[LIST_A])[MB_PARTITION_SIZE]; // 8x8 | |
| 84 | + int8_t (*pSubMbType)[MB_SUB_PARTITION_SIZE]; | |
| 85 | + int32_t iLumaStride; | |
| 86 | + int32_t iChromaStride; | |
| 87 | + uint8_t *pPred[3]; | |
| 88 | + int32_t iMbX; | |
| 89 | + int32_t iMbY; | |
| 90 | + int32_t iMbXyIndex; | |
| 91 | + int32_t iMbWidth; // MB width of this picture, equal to sSps.iMbWidth | |
| 92 | + int32_t iMbHeight; // MB height of this picture, equal to sSps.iMbHeight; | |
| 93 | + | |
| 94 | + /* Common syntax elements across all slices of a DQLayer */ | |
| 95 | + int32_t iSliceIdcBackup; | |
| 96 | + uint32_t uiSpsId; | |
| 97 | + uint32_t uiPpsId; | |
| 98 | + uint32_t uiDisableInterLayerDeblockingFilterIdc; | |
| 99 | + int32_t iInterLayerSliceAlphaC0Offset; | |
| 100 | + int32_t iInterLayerSliceBetaOffset; | |
| 101 | + //SPosOffset sScaledRefLayer; | |
| 102 | + int32_t iSliceGroupChangeCycle; | |
| 103 | + PRefPicListReorderSyn pRefPicListReordering; | |
| 104 | + PRefPicMarking pRefPicMarking; // Decoded reference picture marking syntaxs | |
| 105 | + PRefBasePicMarking pRefPicBaseMarking; | |
| 106 | + | |
| 107 | + PPicture pRef; // reference picture pointer | |
| 108 | + PPicture pDec; // reconstruction picture pointer for layer | |
| 109 | + | |
| 110 | + bool_t bStoreRefBasePicFlag; // iCurTid == 0 && iCurQid = 0 && bEncodeKeyPic = 1 | |
| 111 | + bool_t bTCoeffLevelPredFlag; | |
| 112 | + bool_t bConstrainedIntraResamplingFlag; | |
| 113 | + uint8_t uiRefLayerDqId; | |
| 114 | + uint8_t uiRefLayerChromaPhaseXPlus1Flag; | |
| 115 | + uint8_t uiRefLayerChromaPhaseYPlus1; | |
| 116 | + uint8_t uiLayerDqId; // dq_id of current layer | |
| 117 | + bool_t bUseRefBasePicFlag; // whether reference pic or reference base pic is referred? | |
| 118 | +}; | |
| 119 | + | |
| 120 | +typedef struct TagGpuAvcLayer{ | |
| 121 | + SLayerInfo sLayerInfo; | |
| 122 | + PBitStringAux pBitStringAux; // pointer to SBitStringAux | |
| 123 | + | |
| 124 | + int8_t *pMbType; | |
| 125 | + int32_t *pSliceIdc; // using int32_t for slice_idc | |
| 126 | + int8_t *pLumaQp; | |
| 127 | + int8_t *pCbp; | |
| 128 | + int8_t (*pNzc)[24]; | |
| 129 | + int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16 | |
| 130 | + | |
| 131 | + int32_t iMbX; | |
| 132 | + int32_t iMbY; | |
| 133 | + int32_t iMbXyIndex; | |
| 134 | + int32_t iMbWidth; // MB width of this picture, equal to sSps.iMbWidth | |
| 135 | + int32_t iMbHeight; // MB height of this picture, equal to sSps.iMbHeight; | |
| 136 | + | |
| 137 | +}SGpuAvcDqLayer, *PGpuAvcDqLayer; | |
| 138 | + | |
| 139 | +/////////////////////////////////////////////////////////////////////// | |
| 140 | + | |
| 141 | +} // namespace WelsDec | |
| 142 | + | |
| 143 | +#endif//WELS_DEC_FRAME_H__ | |
| @@ -0,0 +1,243 @@ | ||
| 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 golomb.h | |
| 33 | + * | |
| 34 | + * \brief Exponential Golomb entropy coding/decoding routine | |
| 35 | + * | |
| 36 | + * \date 03/13/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#ifndef WELS_EXPONENTIAL_GOLOMB_ENTROPY_CODING_H__ | |
| 41 | +#define WELS_EXPONENTIAL_GOLOMB_ENTROPY_CODING_H__ | |
| 42 | + | |
| 43 | +#include "typedefs.h" | |
| 44 | +#include "bit_stream.h" | |
| 45 | +#include "macros.h" | |
| 46 | +//#include <assert.h> | |
| 47 | +#include "ls_defines.h" | |
| 48 | + | |
| 49 | +namespace WelsDec { | |
| 50 | + | |
| 51 | +#define GET_WORD(iCurBits, pBufPtr, iLeftBits) { \ | |
| 52 | + iCurBits |= ((pBufPtr[0] << 8) | pBufPtr[1]) << (iLeftBits); \ | |
| 53 | + iLeftBits -= 16; \ | |
| 54 | + pBufPtr +=2; \ | |
| 55 | +} | |
| 56 | +#define NEED_BITS(iCurBits, pBufPtr, iLeftBits) { \ | |
| 57 | + if( iLeftBits > 0 ) { \ | |
| 58 | + GET_WORD(iCurBits, pBufPtr, iLeftBits); \ | |
| 59 | + } \ | |
| 60 | +} | |
| 61 | +#define UBITS(iCurBits, iNumBits) (iCurBits>>(32-(iNumBits))) | |
| 62 | +#define DUMP_BITS(iCurBits, pBufPtr, iLeftBits, iNumBits) { \ | |
| 63 | + iCurBits <<= (iNumBits); \ | |
| 64 | + iLeftBits += (iNumBits); \ | |
| 65 | + NEED_BITS(iCurBits, pBufPtr, iLeftBits); \ | |
| 66 | +} | |
| 67 | + | |
| 68 | +static inline int32_t ShowBits( PBitStringAux pBs, int32_t iNumBits ) | |
| 69 | +{ | |
| 70 | + return UBITS( pBs->uiCurBits, iNumBits ); | |
| 71 | +} | |
| 72 | +static inline void_t FlushBits( PBitStringAux pBs, int32_t iNumBits ) | |
| 73 | +{ | |
| 74 | + DUMP_BITS( pBs->uiCurBits, pBs->pCurBuf, pBs->iLeftBits, iNumBits ); | |
| 75 | +} | |
| 76 | +static inline int32_t BsGetBits( PBitStringAux pBs, int32_t iNumBits ) | |
| 77 | +{ | |
| 78 | + int32_t iRc = UBITS( pBs->uiCurBits, iNumBits ); | |
| 79 | + DUMP_BITS( pBs->uiCurBits, pBs->pCurBuf, pBs->iLeftBits, iNumBits ); | |
| 80 | + return iRc; | |
| 81 | +} | |
| 82 | + | |
| 83 | +/* | |
| 84 | + * Exponential Golomb codes decoding routines | |
| 85 | + */ | |
| 86 | + | |
| 87 | +// for data sharing cross modules and try to reduce size of binary generated, 12/10/2009 | |
| 88 | +extern const uint8_t g_kuiIntra4x4CbpTable[48]; | |
| 89 | +extern const uint8_t g_kuiInterCbpTable[48]; | |
| 90 | + | |
| 91 | +extern const uint8_t g_kuiLeadingZeroTable[256]; | |
| 92 | + | |
| 93 | +static const uint32_t g_kuiPrefix8BitsTable[16] = | |
| 94 | +{ | |
| 95 | + 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 | |
| 96 | +}; | |
| 97 | + | |
| 98 | + | |
| 99 | +static inline uint32_t GetPrefixBits(uint32_t uiValue) | |
| 100 | +{ | |
| 101 | + uint32_t iNumBit = 0; | |
| 102 | + | |
| 103 | + if (uiValue & 0xffff0000) | |
| 104 | + { | |
| 105 | + uiValue >>= 16; | |
| 106 | + iNumBit += 16; | |
| 107 | + } | |
| 108 | + if (uiValue & 0xff00) | |
| 109 | + { | |
| 110 | + uiValue >>= 8; | |
| 111 | + iNumBit += 8; | |
| 112 | + } | |
| 113 | + | |
| 114 | + if (uiValue & 0xf0) | |
| 115 | + { | |
| 116 | + uiValue >>= 4; | |
| 117 | + iNumBit += 4; | |
| 118 | + } | |
| 119 | + iNumBit += g_kuiPrefix8BitsTable[uiValue]; | |
| 120 | + | |
| 121 | + return (32-iNumBit); | |
| 122 | +} | |
| 123 | + | |
| 124 | +/* | |
| 125 | + * Read one bit from bit stream followed | |
| 126 | + */ | |
| 127 | +static inline uint32_t BsGetOneBit(PBitStringAux pBs) | |
| 128 | +{ | |
| 129 | + return ( BsGetBits(pBs, 1) ); | |
| 130 | +} | |
| 131 | + | |
| 132 | +static inline int32_t GetLeadingZeroBits( uint32_t iCurBits ) //<=16 bits | |
| 133 | +{ | |
| 134 | + int32_t iValue; | |
| 135 | + | |
| 136 | + iValue = UBITS( iCurBits, 8 );//ShowBits( bs, 8 ); | |
| 137 | + if( iValue ) | |
| 138 | + { | |
| 139 | + return g_kuiLeadingZeroTable[iValue]; | |
| 140 | + } | |
| 141 | + | |
| 142 | + iValue = UBITS( iCurBits, 16 );//ShowBits( bs, 16 ); | |
| 143 | + if( iValue ) | |
| 144 | + { | |
| 145 | + return (g_kuiLeadingZeroTable[iValue] + 8); | |
| 146 | + } | |
| 147 | + | |
| 148 | + //ASSERT(FALSE); // should not go here | |
| 149 | + return -1; | |
| 150 | +} | |
| 151 | + | |
| 152 | +static inline uint32_t BsGetUe( PBitStringAux pBs ) | |
| 153 | +{ | |
| 154 | + uint32_t iValue = 0; | |
| 155 | + int32_t iLeadingZeroBits = GetLeadingZeroBits( pBs->uiCurBits ); | |
| 156 | + | |
| 157 | + if ( iLeadingZeroBits == -1 ) //bistream error | |
| 158 | + { | |
| 159 | + return 0xffffffff;//-1 | |
| 160 | + } | |
| 161 | + | |
| 162 | + DUMP_BITS( pBs->uiCurBits, pBs->pCurBuf, pBs->iLeftBits, iLeadingZeroBits + 1 ); | |
| 163 | + | |
| 164 | + if( iLeadingZeroBits ) | |
| 165 | + { | |
| 166 | + iValue = UBITS( pBs->uiCurBits, iLeadingZeroBits ); | |
| 167 | + DUMP_BITS( pBs->uiCurBits, pBs->pCurBuf, pBs->iLeftBits, iLeadingZeroBits ); | |
| 168 | + } | |
| 169 | + | |
| 170 | + return ((1<<iLeadingZeroBits) - 1 + iValue); | |
| 171 | +} | |
| 172 | + | |
| 173 | + | |
| 174 | +/* | |
| 175 | + * Read signed exp golomb codes | |
| 176 | + */ | |
| 177 | +static inline int32_t BsGetSe(PBitStringAux pBs) | |
| 178 | +{ | |
| 179 | + uint32_t uiCodeNum; | |
| 180 | + | |
| 181 | + uiCodeNum = BsGetUe( pBs ); | |
| 182 | + | |
| 183 | + if(uiCodeNum&0x01) | |
| 184 | + { | |
| 185 | + return (int32_t)((uiCodeNum+1)>>1); | |
| 186 | + } | |
| 187 | + else | |
| 188 | + { | |
| 189 | + return NEG_NUM( (int32_t)(uiCodeNum>>1) ); | |
| 190 | + } | |
| 191 | +} | |
| 192 | + | |
| 193 | +/* | |
| 194 | + * Read truncated exp golomb codes | |
| 195 | + */ | |
| 196 | +static inline uint32_t BsGetTe(PBitStringAux pBs, uint8_t uiRange) | |
| 197 | +{ | |
| 198 | + if ( 1 == uiRange ) | |
| 199 | + { | |
| 200 | + return BsGetOneBit(pBs)^1; | |
| 201 | + } | |
| 202 | + else | |
| 203 | + { | |
| 204 | + return BsGetUe(pBs); | |
| 205 | + } | |
| 206 | +} | |
| 207 | + | |
| 208 | +/* | |
| 209 | + * Get unsigned truncated exp golomb code. | |
| 210 | + */ | |
| 211 | +static inline int32_t BsGetTe0(PBitStringAux pBs, int32_t iRange) | |
| 212 | +{ | |
| 213 | + if(iRange==1) | |
| 214 | + return 0; | |
| 215 | + else if(iRange==2) | |
| 216 | + return BsGetOneBit(pBs)^1; | |
| 217 | + else | |
| 218 | + return BsGetUe(pBs); | |
| 219 | +} | |
| 220 | + | |
| 221 | +/* | |
| 222 | + * Get number of trailing bits | |
| 223 | + */ | |
| 224 | +static inline int32_t BsGetTrailingBits( uint8_t *pBuf ) | |
| 225 | +{ | |
| 226 | + // TODO | |
| 227 | + uint32_t uiValue = *pBuf; | |
| 228 | + int32_t iRetNum = 1; | |
| 229 | + | |
| 230 | + do | |
| 231 | + { | |
| 232 | + if (uiValue&1) | |
| 233 | + return iRetNum; | |
| 234 | + uiValue >>= 1; | |
| 235 | + ++ iRetNum; | |
| 236 | + } while(iRetNum < 9); | |
| 237 | + | |
| 238 | + return 0; | |
| 239 | +} | |
| 240 | + | |
| 241 | +} // namespace WelsDec | |
| 242 | + | |
| 243 | +#endif//WELS_EXPONENTIAL_GOLOMB_ENTROPY_CODING_H__ | |
| @@ -0,0 +1,61 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +#ifndef WELS_DECODE_MB_AUX_H__ | |
| 34 | +#define WELS_DECODE_MB_AUX_H__ | |
| 35 | + | |
| 36 | +#include "typedefs.h" | |
| 37 | +#include "macros.h" | |
| 38 | + | |
| 39 | +namespace WelsDec { | |
| 40 | + | |
| 41 | +void_t InitDctClipTable(void_t); | |
| 42 | + | |
| 43 | +void_t IdctResAddPred_c(uint8_t *pPred, const int32_t kiStride, int16_t *pRs); | |
| 44 | + | |
| 45 | +#if defined(__cplusplus) | |
| 46 | +extern "C" { | |
| 47 | +#endif//__cplusplus | |
| 48 | + | |
| 49 | +#if defined(X86_ASM) | |
| 50 | + void_t IdctResAddPred_mmx(uint8_t *pPred, const int32_t kiStride, int16_t *pRs); | |
| 51 | +#endif//X86_ASM | |
| 52 | + | |
| 53 | +#if defined(__cplusplus) | |
| 54 | +} | |
| 55 | +#endif//__cplusplus | |
| 56 | + | |
| 57 | +void_t GetI4LumaIChromaAddrTable(int32_t *pBlockOffset, const int32_t kiYStride, const int32_t kiUVStride); | |
| 58 | + | |
| 59 | +} // namespace WelsDec | |
| 60 | + | |
| 61 | +#endif//WELS_DECODE_MB_AUX_H__ | |
| @@ -0,0 +1,90 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +#ifndef WELS_DECODE_SLICE_H__ | |
| 34 | +#define WELS_DECODE_SLICE_H__ | |
| 35 | + | |
| 36 | +#include "decoder_context.h" | |
| 37 | + | |
| 38 | +namespace WelsDec { | |
| 39 | + | |
| 40 | +void_t WelsBlockInit(int16_t* pBlock, int32_t iWidth, int32_t iHeight, int32_t iStride, uint8_t uiVal); | |
| 41 | + | |
| 42 | +int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx); | |
| 43 | +int32_t WelsDecodeMbCavlcISlice (PWelsDecoderContext pCtx, PNalUnit pNalCur); | |
| 44 | + | |
| 45 | +int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx); | |
| 46 | +int32_t WelsDecodeMbCavlcPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur); | |
| 47 | +typedef int32_t (*PWelsDecMbCavlcFunc) (PWelsDecoderContext pCtx, PNalUnit pNalCur); | |
| 48 | + | |
| 49 | +int32_t WelsTargetSliceConstruction(PWelsDecoderContext pCtx); //construction based on slice | |
| 50 | + | |
| 51 | +int32_t WelsDecodeSlice(PWelsDecoderContext pCtx, bool_t bFirstSliceInLayer, PNalUnit pNalCur); | |
| 52 | + | |
| 53 | + | |
| 54 | +int32_t WelsTargetMbConstruction(PWelsDecoderContext pCtx); | |
| 55 | + | |
| 56 | +int32_t WelsMbIntraPredictionConstruction(PWelsDecoderContext pCtx, PDqLayer pCurLayer, bool_t bOutput); | |
| 57 | +int32_t WelsMbInterSampleConstruction( PWelsDecoderContext pCtx, PDqLayer pCurLayer, | |
| 58 | + uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV, int32_t iStrideL, int32_t iStrideC ); | |
| 59 | +int32_t WelsMbInterConstruction(PWelsDecoderContext pCtx, PDqLayer pCurLayer); | |
| 60 | +void_t WelsLumaDcDequantIdct(int16_t *pBlock, int32_t iQp); | |
| 61 | +int32_t WelsMbInterPrediction (PWelsDecoderContext pCtx, PDqLayer pCurLayer); | |
| 62 | +void_t WelsMbCopy( uint8_t *pDst, int32_t iStrideDst, uint8_t *pSrc, int32_t iStrideSrc, | |
| 63 | + int32_t iHeight, int32_t iWidth ); | |
| 64 | + | |
| 65 | +void_t WelsChromaDcIdct( int16_t *pBlock ); | |
| 66 | + | |
| 67 | +#ifdef __cplusplus | |
| 68 | +extern "C" { | |
| 69 | +#endif//__cplusplus | |
| 70 | + | |
| 71 | +#ifdef X86_ASM | |
| 72 | +void_t WelsResBlockZero16x16_sse2 (int16_t* pBlock, int32_t iStride); | |
| 73 | +void_t WelsResBlockZero8x8_sse2 (int16_t* pBlock, int32_t iStride); | |
| 74 | +#endif | |
| 75 | + | |
| 76 | +#ifdef __cplusplus | |
| 77 | +} | |
| 78 | +#endif//__cplusplus | |
| 79 | + | |
| 80 | +void_t WelsBlockZero16x16_c(int16_t * pBlock, int32_t iStride); | |
| 81 | +void_t WelsBlockZero8x8_c (int16_t * pBlock, int32_t iStride); | |
| 82 | +void_t SetNonZeroCount_c (int16_t * pBlock, int8_t * pNonZeroCount); | |
| 83 | + | |
| 84 | +void_t WelsBlockFuncInit(SBlockFunc *pFunc, int32_t iCpu); | |
| 85 | + | |
| 86 | +} // namespace WelsDec | |
| 87 | + | |
| 88 | +#endif //WELS_DECODE_SLICE_H__ | |
| 89 | + | |
| 90 | + | |
| @@ -0,0 +1,151 @@ | ||
| 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 decoder.h | |
| 33 | + * | |
| 34 | + * \brief Interfaces introduced in decoder system architecture | |
| 35 | + * | |
| 36 | + * \date 03/10/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#ifndef WELS_DECODER_SYSTEM_ARCHITECTURE_H__ | |
| 41 | +#define WELS_DECODER_SYSTEM_ARCHITECTURE_H__ | |
| 42 | + | |
| 43 | +#include "typedefs.h" | |
| 44 | +#include "decoder_context.h" | |
| 45 | + | |
| 46 | +namespace WelsDec { | |
| 47 | + | |
| 48 | +#ifdef __cplusplus | |
| 49 | +extern "C" { | |
| 50 | +#endif//__cplusplus | |
| 51 | + | |
| 52 | +/*! | |
| 53 | + * \brief configure decoder parameters | |
| 54 | + */ | |
| 55 | +int32_t DecoderConfigParam ( PWelsDecoderContext pCtx, const void_t* kpParam ); | |
| 56 | + | |
| 57 | +/*! | |
| 58 | + ************************************************************************************* | |
| 59 | + * \brief Initialize Wels decoder parameters and memory | |
| 60 | + * | |
| 61 | + * \param pCtx input context to be initialized at first stage | |
| 62 | + * \param pTraceHandle handle for trace | |
| 63 | + * \param pLo log info pointer | |
| 64 | + * | |
| 65 | + * \return 0 - successed | |
| 66 | + * \return 1 - failed | |
| 67 | + * | |
| 68 | + * \note N/A | |
| 69 | + ************************************************************************************* | |
| 70 | + */ | |
| 71 | +int32_t WelsInitDecoder( PWelsDecoderContext pCtx, void_t * pTraceHandle, PWelsLogCallbackFunc pLog ); | |
| 72 | + | |
| 73 | +/*! | |
| 74 | + ************************************************************************************* | |
| 75 | + * \brief Uninitialize Wels decoder parameters and memory | |
| 76 | + * | |
| 77 | + * \param pCtx input context to be uninitialized at release stage | |
| 78 | + * | |
| 79 | + * \return NONE | |
| 80 | + * | |
| 81 | + * \note N/A | |
| 82 | + ************************************************************************************* | |
| 83 | + */ | |
| 84 | +void_t WelsEndDecoder( PWelsDecoderContext pCtx ); | |
| 85 | + | |
| 86 | +/*! | |
| 87 | + ************************************************************************************* | |
| 88 | + * \brief First entrance to decoding core interface. | |
| 89 | + * | |
| 90 | + * \param pCtx decoder context | |
| 91 | + * \param pBufBs bit streaming buffer | |
| 92 | + * \param kBsLen size in bytes length of bit streaming buffer input | |
| 93 | + * \param ppDst picture payload data to be output | |
| 94 | + * \param pDstBufInfo buf information of ouput data | |
| 95 | + * | |
| 96 | + * \return 0 - successed | |
| 97 | + * \return 1 - failed | |
| 98 | + * | |
| 99 | + * \note N/A | |
| 100 | + ************************************************************************************* | |
| 101 | + */ | |
| 102 | + | |
| 103 | +int32_t WelsDecodeBs( PWelsDecoderContext pCtx, const uint8_t *kpBsBuf, const int32_t kiBsLen, | |
| 104 | + uint8_t **ppDst, SBufferInfo* pDstBufInfo); | |
| 105 | + | |
| 106 | +/* | |
| 107 | + * request memory blocks for decoder avc part | |
| 108 | + */ | |
| 109 | +int32_t WelsRequestMem( PWelsDecoderContext pCtx, const int32_t kiMbWidth, const int32_t kiMbHeight ); | |
| 110 | + | |
| 111 | + | |
| 112 | +/* | |
| 113 | + * free memory blocks in avc | |
| 114 | + */ | |
| 115 | +void_t WelsFreeMem( PWelsDecoderContext pCtx ); | |
| 116 | + | |
| 117 | +/* | |
| 118 | + * set colorspace format in decoder | |
| 119 | + */ | |
| 120 | +int32_t DecoderSetCsp(PWelsDecoderContext pCtx, const int32_t kiColorFormat); | |
| 121 | + | |
| 122 | +/*! | |
| 123 | + * \brief make sure synchonozization picture resolution (get from slice header) among different parts (i.e, memory related and so on) | |
| 124 | + * over decoder internal | |
| 125 | + * ( MB coordinate and parts of data within decoder context structure ) | |
| 126 | + * \param pCtx Wels decoder context | |
| 127 | + * \param iMbWidth MB width | |
| 128 | + * \pram iMbHeight MB height | |
| 129 | + * \return 0 - successful; none 0 - something wrong | |
| 130 | + */ | |
| 131 | +int32_t SyncPictureResolutionExt( PWelsDecoderContext pCtx, const int32_t kiMbWidth, const int32_t kiMbHeight ); | |
| 132 | + | |
| 133 | +/*! | |
| 134 | + * \brief update maximal picture width and height if applicable when receiving a SPS NAL | |
| 135 | + */ | |
| 136 | +void_t UpdateMaxPictureResolution( PWelsDecoderContext pCtx, const int32_t kiCurWidth, const int32_t kiCurHeight ); | |
| 137 | + | |
| 138 | +void_t AssignFuncPointerForRec( PWelsDecoderContext pCtx ); | |
| 139 | + | |
| 140 | +void_t ResetParameterSetsState( PWelsDecoderContext pCtx ); | |
| 141 | + | |
| 142 | +void_t GetVclNalTemporalId( PWelsDecoderContext pCtx );//get the info that whether or not have VCL NAL in current AU, | |
| 143 | + //and if YES, get the temporal ID | |
| 144 | + | |
| 145 | +#ifdef __cplusplus | |
| 146 | +} | |
| 147 | +#endif//__cplusplus | |
| 148 | + | |
| 149 | +} // namespace WelsDec | |
| 150 | + | |
| 151 | +#endif//WELS_DECODER_SYSTEM_ARCHITECTURE_H__ | |
| @@ -0,0 +1,340 @@ | ||
| 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 decoder_context.h | |
| 33 | + * | |
| 34 | + * \brief mainly interface introduced in Wels decoder side | |
| 35 | + * | |
| 36 | + * \date 3/4/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#ifndef WELS_DECODER_FRAMEWORK_H__ | |
| 41 | +#define WELS_DECODER_FRAMEWORK_H__ | |
| 42 | +#include "typedefs.h" | |
| 43 | +#include "utils.h" | |
| 44 | +#include "wels_const.h" | |
| 45 | +#include "wels_common_basis.h" | |
| 46 | +#include "codec_app_def.h" | |
| 47 | +#include "parameter_sets.h" | |
| 48 | +#include "nalu.h" | |
| 49 | +#include "dec_frame.h" | |
| 50 | +#include "pic_queue.h" | |
| 51 | +#include "vlc_decoder.h" | |
| 52 | +#include "fmo.h" | |
| 53 | +#include "as264_common.h" // for LONG_TERM_REF macro,can be delete if not need this macro | |
| 54 | +#include "crt_util_safe_x.h" | |
| 55 | +#include "mb_cache.h" | |
| 56 | + | |
| 57 | +namespace WelsDec { | |
| 58 | + | |
| 59 | +#ifndef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 60 | +//#define MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 61 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 62 | + | |
| 63 | +typedef struct TagDataBuffer | |
| 64 | +{ | |
| 65 | + uint8_t* pHead; | |
| 66 | + uint8_t* pEnd; | |
| 67 | + | |
| 68 | + uint8_t* pStartPos; | |
| 69 | + uint8_t* pCurPos; | |
| 70 | +}SDataBuffer; | |
| 71 | + | |
| 72 | +//#ifdef __cplusplus | |
| 73 | +//extern "C" { | |
| 74 | +//#endif//__cplusplus | |
| 75 | + | |
| 76 | +//#pragma pack(1) | |
| 77 | + | |
| 78 | +/* | |
| 79 | + * Need move below structures to function pointer to seperate module/file later | |
| 80 | + */ | |
| 81 | + | |
| 82 | +//typedef int32_t (*rec_mb) (Mb *cur_mb, PWelsDecoderContext pCtx); | |
| 83 | + | |
| 84 | +/*typedef for get intra predictor func pointer*/ | |
| 85 | +typedef void_t (*PGetIntraPredFunc)(uint8_t *pPred, const int32_t kiLumaStride); | |
| 86 | +typedef void_t (*PIdctResAddPredFunc)(uint8_t *pPred, const int32_t kiStride, int16_t *pRs); | |
| 87 | +typedef void_t (*PExpandPictureFunc)( uint8_t *pDst, const int32_t kiStride, const int32_t kiPicWidth, const int32_t kiPicHeight ); | |
| 88 | + | |
| 89 | +/**/ | |
| 90 | +typedef struct TagRefPic { | |
| 91 | + PPicture pRefList[LIST_A][MAX_REF_PIC_COUNT]; // reference picture marking plus FIFO scheme | |
| 92 | + PPicture pShortRefList[LIST_A][MAX_SHORT_REF_COUNT]; | |
| 93 | + PPicture pLongRefList[LIST_A][MAX_LONG_REF_COUNT]; | |
| 94 | + uint8_t uiRefCount[LIST_A]; | |
| 95 | + uint8_t uiShortRefCount[LIST_A]; | |
| 96 | + uint8_t uiLongRefCount[LIST_A]; // dependend on ref pic module | |
| 97 | + int32_t iMaxLongTermFrameIdx; | |
| 98 | +} SRefPic, *PRefPic; | |
| 99 | + | |
| 100 | +typedef void_t (*PWelsMcFunc) (uint8_t* pSrc, int32_t iSrcStride, uint8_t* pDst, int32_t iDstStride, | |
| 101 | + int16_t iMvX, int16_t iMvY, int32_t iWidth, int32_t iHeight); | |
| 102 | +typedef struct TagMcFunc{ | |
| 103 | + PWelsMcFunc pMcLumaFunc; | |
| 104 | + PWelsMcFunc pMcChromaFunc; | |
| 105 | +}SMcFunc; | |
| 106 | + | |
| 107 | +//deblock module defination | |
| 108 | +struct TagDeblockingFunc; | |
| 109 | + | |
| 110 | +typedef struct tagDeblockingFilter { | |
| 111 | + uint8_t *pCsData[3]; // pointer to reconstructed picture data | |
| 112 | + int32_t iCsStride[2]; // Cs stride | |
| 113 | + ESliceType eSliceType; | |
| 114 | + int8_t iSliceAlphaC0Offset; | |
| 115 | + int8_t iSliceBetaOffset; | |
| 116 | + int8_t iChromaQP; | |
| 117 | + int8_t iLumaQP; | |
| 118 | + struct TagDeblockingFunc *pLoopf; | |
| 119 | +}SDeblockingFilter, *PDeblockingFilter; | |
| 120 | + | |
| 121 | +typedef void_t (*PDeblockingFilterMbFunc)( PDqLayer pCurDqLayer, PDeblockingFilter filter, int32_t boundry_flag ); | |
| 122 | +typedef void_t (*PLumaDeblockingLT4Func)( uint8_t *iSampleY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *iTc ); | |
| 123 | +typedef void_t (*PLumaDeblockingEQ4Func)( uint8_t *iSampleY, int32_t iStride, int32_t iAlpha, int32_t iBeta ); | |
| 124 | +typedef void_t (*PChromaDeblockingLT4Func)( uint8_t *iSampleCb, uint8_t *iSampleCr, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *iTc ); | |
| 125 | +typedef void_t (*PChromaDeblockingEQ4Func)( uint8_t *iSampleCb, uint8_t *iSampleCr, int32_t iStride, int32_t iAlpha, int32_t iBeta ); | |
| 126 | + | |
| 127 | +typedef struct TagDeblockingFunc { | |
| 128 | + PLumaDeblockingLT4Func pfLumaDeblockingLT4Ver; | |
| 129 | + PLumaDeblockingEQ4Func pfLumaDeblockingEQ4Ver; | |
| 130 | + PLumaDeblockingLT4Func pfLumaDeblockingLT4Hor; | |
| 131 | + PLumaDeblockingEQ4Func pfLumaDeblockingEQ4Hor; | |
| 132 | + | |
| 133 | + PChromaDeblockingLT4Func pfChromaDeblockingLT4Ver; | |
| 134 | + PChromaDeblockingEQ4Func pfChromaDeblockingEQ4Ver; | |
| 135 | + PChromaDeblockingLT4Func pfChromaDeblockingLT4Hor; | |
| 136 | + PChromaDeblockingEQ4Func pfChromaDeblockinEQ4Hor; | |
| 137 | +} SDeblockingFunc, *PDeblockingFunc; | |
| 138 | + | |
| 139 | +typedef void_t (*PWelsBlockAddStrideFunc)(uint8_t *pDest, uint8_t *pPred, int16_t *pRes, int32_t iPredStride, int32_t iResStride); | |
| 140 | +typedef void_t (*PWelsBlockZeroFunc) (int16_t* pBlock, int32_t iStride); | |
| 141 | +typedef void_t (*PWelsNonZeroCountFunc) (int16_t *pBlock, int8_t *pNonZeroCount); | |
| 142 | +typedef void_t (*PWelsSimpleIdct4x4AddFunc) (int16_t *pDest, int16_t *pSrc, int32_t iStride); | |
| 143 | + | |
| 144 | +typedef struct TagBlockFunc { | |
| 145 | + PWelsBlockZeroFunc pWelsBlockZero16x16Func; | |
| 146 | + PWelsBlockZeroFunc pWelsBlockZero8x8Func; | |
| 147 | + PWelsNonZeroCountFunc pWelsSetNonZeroCountFunc; | |
| 148 | +} SBlockFunc; | |
| 149 | + | |
| 150 | +typedef void_t ( *PWelsFillNeighborMbInfoIntra4x4Func )( PNeighAvail pNeighAvail, uint8_t* pNonZeroCount, int8_t* pIntraPredMode, PDqLayer pCurLayer ); | |
| 151 | +typedef int32_t (*PWelsParseIntra4x4ModeFunc) ( PNeighAvail pNeighAvail, int8_t* pIntraPredMode, PBitStringAux pBs, PDqLayer pCurDqLayer); | |
| 152 | +typedef int32_t (*PWelsParseIntra16x16ModeFunc) ( PNeighAvail pNeighAvail, PBitStringAux pBs, PDqLayer pCurDqLayer); | |
| 153 | + | |
| 154 | +typedef struct TagExpandPicFunc{ | |
| 155 | + PExpandPictureFunc pExpandLumaPicture; | |
| 156 | + PExpandPictureFunc pExpandChromaPicture[2]; | |
| 157 | +}SExpandPicFunc; | |
| 158 | + | |
| 159 | +/* | |
| 160 | + * SWelsDecoderContext: to maintail all modules data over decoder@framework | |
| 161 | + */ | |
| 162 | + | |
| 163 | +typedef struct TagWelsDecoderContext { | |
| 164 | + // Input | |
| 165 | + void_t *pArgDec; // structured arguments for decoder, reserved here for extension in the future | |
| 166 | + | |
| 167 | + SDataBuffer sRawData; | |
| 168 | + | |
| 169 | + // Configuration | |
| 170 | + SDecodingParam *pParam; | |
| 171 | + uint32_t uiCpuFlag; // CPU compatibility detected | |
| 172 | + int32_t iDecoderMode; // indicate decoder running mode | |
| 173 | + int32_t iSetMode; // indicate decoder mode set from upper layer, this is read-only for decoder internal | |
| 174 | + int32_t iDecoderOutputProperty; // indicate the output buffer property | |
| 175 | + int32_t iModeSwitchType; // 1: optimal decision; 2: forced switch to the other mode; 0: no switch | |
| 176 | + | |
| 177 | + int32_t iOutputColorFormat; // color space format to be outputed | |
| 178 | + VIDEO_BITSTREAM_TYPE eVideoType; //indicate the type of video to decide whether or not to do qp_delta error detection. | |
| 179 | + bool_t bErrorResilienceFlag; // error resilience flag | |
| 180 | + bool_t bHaveGotMemory; // global memory for decoder context related ever requested? | |
| 181 | + | |
| 182 | + int32_t iImgWidthInPixel; // width of image in pixel reconstruction picture to be output | |
| 183 | + int32_t iImgHeightInPixel;// height of image in pixel reconstruction picture to be output | |
| 184 | + int32_t iMaxWidthInSps; // maximal width of pixel in SPS sets | |
| 185 | + int32_t iMaxHeightInSps; // maximal height of pixel in SPS sets | |
| 186 | + | |
| 187 | + // Derived common elements | |
| 188 | + SNalUnitHeader sCurNalHead; | |
| 189 | + ESliceType eSliceType; // Slice type | |
| 190 | + int32_t iFrameNum; | |
| 191 | + int32_t iPrevFrameNum; // frame number of previous frame well decoded for non-truncated mode yet | |
| 192 | + bool_t bLastHasMmco5; // | |
| 193 | + int32_t iErrorCode; // error code return while decoding in case packets lost | |
| 194 | + SFmo sFmoList[MAX_PPS_COUNT]; // list for FMO storage | |
| 195 | + PFmo pFmo; // current fmo context after parsed slice_header | |
| 196 | + int32_t iActiveFmoNum; // active count number of fmo context in list | |
| 197 | + | |
| 198 | + /*needed info by decode slice level and mb level*/ | |
| 199 | + int32_t iDecBlockOffsetArray[24]; // address talbe for sub 4x4 block in intra4x4_mb, so no need to caculta the address every time. | |
| 200 | + | |
| 201 | + struct | |
| 202 | + { | |
| 203 | + int8_t *pMbType[LAYER_NUM_EXCHANGEABLE]; /* mb type */ | |
| 204 | + int16_t (*pMv[LAYER_NUM_EXCHANGEABLE][LIST_A])[MB_BLOCK4x4_NUM][MV_A]; //[LAYER_NUM_EXCHANGEABLE MB_BLOCK4x4_NUM*] | |
| 205 | + int8_t (*pRefIndex[LAYER_NUM_EXCHANGEABLE][LIST_A])[MB_BLOCK4x4_NUM]; | |
| 206 | + int8_t *pLumaQp[LAYER_NUM_EXCHANGEABLE]; /*mb luma_qp*/ | |
| 207 | + int8_t *pChromaQp[LAYER_NUM_EXCHANGEABLE]; /*mb chroma_qp*/ | |
| 208 | + int8_t (*pNzc[LAYER_NUM_EXCHANGEABLE])[24]; | |
| 209 | + int8_t (*pNzcRs[LAYER_NUM_EXCHANGEABLE])[24]; | |
| 210 | + int16_t (*pScaledTCoeff[LAYER_NUM_EXCHANGEABLE])[MB_COEFF_LIST_SIZE]; /*need be aligned*/ | |
| 211 | + int8_t (*pIntraPredMode[LAYER_NUM_EXCHANGEABLE])[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16 | |
| 212 | + int8_t (*pIntra4x4FinalMode[LAYER_NUM_EXCHANGEABLE])[MB_BLOCK4x4_NUM]; | |
| 213 | + int8_t *pChromaPredMode[LAYER_NUM_EXCHANGEABLE]; | |
| 214 | + int8_t *pCbp[LAYER_NUM_EXCHANGEABLE]; | |
| 215 | + uint8_t (*pMotionPredFlag[LAYER_NUM_EXCHANGEABLE][LIST_A])[MB_PARTITION_SIZE]; // 8x8 | |
| 216 | + int8_t (*pSubMbType[LAYER_NUM_EXCHANGEABLE])[MB_SUB_PARTITION_SIZE]; | |
| 217 | + int32_t *pSliceIdc[LAYER_NUM_EXCHANGEABLE]; // using int32_t for slice_idc | |
| 218 | + int8_t *pResidualPredFlag[LAYER_NUM_EXCHANGEABLE]; | |
| 219 | + int8_t *pInterPredictionDoneFlag[LAYER_NUM_EXCHANGEABLE]; | |
| 220 | + int16_t iMbWidth; | |
| 221 | + int16_t iMbHeight; | |
| 222 | + }sMb; | |
| 223 | + | |
| 224 | + | |
| 225 | + // reconstruction picture | |
| 226 | + PPicture pDec; //pointer to current picture being reconstructed | |
| 227 | + | |
| 228 | + // reference pictures | |
| 229 | + SRefPic sRefPic; | |
| 230 | + | |
| 231 | + SVlcTable sVlcTable; // vlc table | |
| 232 | + | |
| 233 | + SBitStringAux sBs; | |
| 234 | + | |
| 235 | + /* Global memory external */ | |
| 236 | + | |
| 237 | + SPosOffset sFrameCrop; | |
| 238 | + | |
| 239 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 240 | + int32_t iSpsTotalNum; //the number of SPS in current IDR interval | |
| 241 | + int32_t iSubspsTotalNum; //the number of subsps in current IDR interval | |
| 242 | + int32_t iPpsTotalNum; //the number of PPS in current IDR interval. | |
| 243 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 244 | + | |
| 245 | + SSps sSpsBuffer[MAX_SPS_COUNT]; | |
| 246 | + SPps sPpsBuffer[MAX_PPS_COUNT]; | |
| 247 | + PSliceHeader pSliceHeader; | |
| 248 | + | |
| 249 | + PPicBuff pPicBuff[LIST_A]; // Initially allocated memory for pictures which are used in decoding. | |
| 250 | + int32_t iPicQueueNumber; | |
| 251 | + | |
| 252 | + SSubsetSps sSubsetSpsBuffer[MAX_SPS_COUNT]; | |
| 253 | + SNalUnit sPrefixNal; | |
| 254 | + | |
| 255 | + PAccessUnit pAccessUnitList; // current access unit list to be performed | |
| 256 | + PSps pSps; // used by current AU | |
| 257 | + PPps pPps; // used by current AU | |
| 258 | + // Memory for pAccessUnitList is dynamically held till decoder destruction. | |
| 259 | + PDqLayer pCurDqLayer; // current DQ layer representation, also carry reference base layer if applicable | |
| 260 | + PDqLayer pDqLayersList[LAYER_NUM_EXCHANGEABLE]; // DQ layers list with memory allocated | |
| 261 | + uint8_t *pCsListXchg[LAYER_NUM_EXCHANGEABLE][3]; // Constructed picture buffer: 0- cur layer, 1- ref layer; | |
| 262 | + int16_t *pRsListXchg[LAYER_NUM_EXCHANGEABLE][3];// Residual picture buffer: 0- cur layer, 1- ref layer; | |
| 263 | + | |
| 264 | + int32_t iCsStride[3]; // strides for Cs | |
| 265 | + int32_t iRsStride[3]; // strides for Rs | |
| 266 | + | |
| 267 | + int32_t iPicWidthReq; // picture width have requested the memory | |
| 268 | + int32_t iPicHeightReq; // picture height have requested the memory | |
| 269 | + | |
| 270 | + uint8_t uiTargetDqId; // maximal DQ ID in current access unit, meaning target layer ID | |
| 271 | + bool_t bAvcBasedFlag; // For decoding bitstream: | |
| 272 | + bool_t bEndOfStreamFlag; // Flag on end of stream requested by external application layer | |
| 273 | + bool_t bInitialDqLayersMem; // dq layers related memory is available? | |
| 274 | + | |
| 275 | + bool_t bOnlyOneLayerInCurAuFlag; //only one layer in current AU: 1 | |
| 276 | + | |
| 277 | + // for EC parameter sets | |
| 278 | + bool_t bSpsExistAheadFlag; // whether does SPS NAL exist ahead of sequence? | |
| 279 | + bool_t bSubspsExistAheadFlag;// whether does Subset SPS NAL exist ahead of sequence? | |
| 280 | + bool_t bPpsExistAheadFlag; // whether does PPS NAL exist ahead of sequence? | |
| 281 | + | |
| 282 | + bool_t bSpsAvailFlags[MAX_SPS_COUNT]; | |
| 283 | + bool_t bSubspsAvailFlags[MAX_SPS_COUNT]; | |
| 284 | + bool_t bPpsAvailFlags[MAX_PPS_COUNT]; | |
| 285 | + bool_t bReferenceLostAtT0Flag; | |
| 286 | +#ifdef LONG_TERM_REF | |
| 287 | + bool_t bParamSetsLostFlag; //sps or pps do not exist or not correct | |
| 288 | + | |
| 289 | + bool_t bCurAuContainLtrMarkSeFlag; //current AU has the LTR marking syntax element, mark the previous frame or self | |
| 290 | + int32_t iFrameNumOfAuMarkedLtr; //if bCurAuContainLtrMarkSeFlag==true, SHOULD set this variable | |
| 291 | + | |
| 292 | + uint16_t uiCurIdrPicId; | |
| 293 | +#endif | |
| 294 | + | |
| 295 | + PGetIntraPredFunc pGetI16x16LumaPredFunc[7]; //h264_predict_copy_16x16; | |
| 296 | + PGetIntraPredFunc pGetI4x4LumaPredFunc[14]; // h264_predict_4x4_t | |
| 297 | + PGetIntraPredFunc pGetIChromaPredFunc[7]; // h264_predict_8x8_t | |
| 298 | + PIdctResAddPredFunc pIdctResAddPredFunc; | |
| 299 | + SMcFunc sMcFunc; | |
| 300 | + /* For Deblocking */ | |
| 301 | + SDeblockingFunc sDeblockingFunc; | |
| 302 | + SExpandPicFunc sExpandPicFunc; | |
| 303 | + | |
| 304 | + /* For Block */ | |
| 305 | + SBlockFunc sBlockFunc; | |
| 306 | + /* For EC */ | |
| 307 | + int32_t iCurSeqIntervalTargetDependId; | |
| 308 | + int32_t iCurSeqIntervalMaxPicWidth; | |
| 309 | + int32_t iCurSeqIntervalMaxPicHeight; | |
| 310 | + | |
| 311 | + PWelsFillNeighborMbInfoIntra4x4Func pFillInfoCacheIntra4x4Func; | |
| 312 | + PWelsParseIntra4x4ModeFunc pParseIntra4x4ModeFunc; | |
| 313 | + PWelsParseIntra16x16ModeFunc pParseIntra16x16ModeFunc; | |
| 314 | + | |
| 315 | + //feedback whether or not have VCL in current AU, and the temporal ID | |
| 316 | + int32_t iFeedbackVclNalInAu; | |
| 317 | + int32_t iFeedbackTidInAu; | |
| 318 | + | |
| 319 | + bool_t bAuReadyFlag; // TRUE: one au is ready for decoding; FALSE: default value | |
| 320 | + | |
| 321 | + //trace handle | |
| 322 | + void_t * pTraceHandle; | |
| 323 | + | |
| 324 | +#ifdef NO_WAITING_AU | |
| 325 | + //Save the last nal header info | |
| 326 | + SNalUnitHeaderExt sLastNalHdrExt; | |
| 327 | + SSliceHeader sLastSliceHeader; | |
| 328 | +#endif | |
| 329 | + | |
| 330 | +}SWelsDecoderContext, *PWelsDecoderContext; | |
| 331 | + | |
| 332 | +//#pragma pack() | |
| 333 | + | |
| 334 | +//#ifdef __cplusplus | |
| 335 | +//} | |
| 336 | +//#endif//__cplusplus | |
| 337 | + | |
| 338 | +} // namespace WelsDec | |
| 339 | + | |
| 340 | +#endif//WELS_DECODER_FRAMEWORK_H__ | |
| @@ -0,0 +1,138 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2008-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 | + * decoder_core.h | |
| 33 | + * | |
| 34 | + * Abstract | |
| 35 | + * Encapsulative core interfaces | |
| 36 | + * | |
| 37 | + * History | |
| 38 | + * 07/10/2008 Created | |
| 39 | + * | |
| 40 | + *****************************************************************************/ | |
| 41 | +#ifndef WELS_DECODER_CORE_H__ | |
| 42 | +#define WELS_DECODER_CORE_H__ | |
| 43 | + | |
| 44 | +#include "typedefs.h" | |
| 45 | +#include "wels_common_basis.h" | |
| 46 | +#include "decoder_context.h" | |
| 47 | + | |
| 48 | +#include "codec_def.h" | |
| 49 | + | |
| 50 | +namespace WelsDec { | |
| 51 | + | |
| 52 | +/* | |
| 53 | + * WelsInitMemory | |
| 54 | + * Memory request for introduced data | |
| 55 | + * Especially for: | |
| 56 | + * rbsp_au_buffer, cur_dq_layer_ptr and ref_dq_layer_ptr in MB info cache. | |
| 57 | + * return: | |
| 58 | + * 0 - success; otherwise returned error_no defined in error_no.h. | |
| 59 | +*/ | |
| 60 | +int32_t WelsInitMemory( PWelsDecoderContext pCtx ); | |
| 61 | + | |
| 62 | +/* | |
| 63 | + * WelsFreeMemory | |
| 64 | + * Free memory introduced in WelsInitMemory at destruction of decoder. | |
| 65 | + * | |
| 66 | + */ | |
| 67 | +void_t WelsFreeMemory( PWelsDecoderContext pCtx ); | |
| 68 | + | |
| 69 | +/*! | |
| 70 | + * \brief request memory when maximal picture width and height are available | |
| 71 | + */ | |
| 72 | +int32_t InitialDqLayersContext ( PWelsDecoderContext pCtx, const int32_t kiMaxWidth, const int32_t kiMaxHeight ); | |
| 73 | + | |
| 74 | +/*! | |
| 75 | + * \brief free dq layer context memory related | |
| 76 | + */ | |
| 77 | +void_t UninitialDqLayersContext ( PWelsDecoderContext pCtx ); | |
| 78 | + | |
| 79 | +/* | |
| 80 | + * DecodeNalHeaderExt | |
| 81 | + * Trigger condition: NAL_UNIT_TYPE = NAL_UNIT_PREFIX or NAL_UNIT_CODED_SLICE_EXT | |
| 82 | + * Parameter: | |
| 83 | + * pNal: target NALUnit ptr | |
| 84 | + * pSrc: NAL Unit bitstream | |
| 85 | + */ | |
| 86 | +void_t DecodeNalHeaderExt( PNalUnit pNal, uint8_t* pSrc ); | |
| 87 | + | |
| 88 | +/* | |
| 89 | + * ParseSliceHeaderSyntaxs | |
| 90 | + * Parse slice header of bitstream | |
| 91 | + */ | |
| 92 | +int32_t ParseSliceHeaderSyntaxs ( PWelsDecoderContext pCtx, PBitStringAux pBs, const bool_t kbExtensionFlag ); | |
| 93 | +/* | |
| 94 | + * Copy relative syntax elements of NALUnitHeaderExt, sRefPicBaseMarking and bStoreRefBasePicFlag in prefix nal unit. | |
| 95 | + * pSrc: mark as decoded prefix NAL | |
| 96 | + * pDst: succeeded VCL NAL based AVC (I/P Slice) | |
| 97 | + */ | |
| 98 | +bool_t PrefetchNalHeaderExtSyntax ( PWelsDecoderContext pCtx, PNalUnit const kpDst, PNalUnit const kpSrc); | |
| 99 | + | |
| 100 | + | |
| 101 | +/* | |
| 102 | + * ConstructAccessUnit | |
| 103 | + * construct an access unit for given input bitstream, maybe partial NAL Unit, one or more Units are involved to | |
| 104 | + * joint a collective access unit. | |
| 105 | + * parameter\ | |
| 106 | + * buf: bitstream data buffer | |
| 107 | + * bit_len: size in bit length of data | |
| 108 | + * buf_len: size in byte length of data | |
| 109 | + * coded_au: mark an Access Unit decoding finished | |
| 110 | + * return: | |
| 111 | + * 0 - success; otherwise returned error_no defined in error_no.h | |
| 112 | + */ | |
| 113 | +int32_t ConstructAccessUnit( PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferInfo *pDstInfo); | |
| 114 | + | |
| 115 | + | |
| 116 | +/* | |
| 117 | + * DecodeCurrentAccessUnit | |
| 118 | + * Decode current access unit when current AU is completed. | |
| 119 | + */ | |
| 120 | +int32_t DecodeCurrentAccessUnit( PWelsDecoderContext pCtx, uint8_t **ppDst, int32_t *iDstLen, int32_t *pWidth, int32_t *pHeight, SBufferInfo *pDstInfo ); | |
| 121 | + | |
| 122 | +/* | |
| 123 | + * Prepare current dq layer context initialization. | |
| 124 | + */ | |
| 125 | +void_t WelsDqLayerDecodeStart ( PWelsDecoderContext pCtx, PNalUnit pCurNal, PSps pSps, PPps pPps ); | |
| 126 | + | |
| 127 | + | |
| 128 | +int32_t WelsDecodeAccessUnitStart ( PWelsDecoderContext pCtx ); | |
| 129 | +void_t WelsDecodeAccessUnitEnd ( PWelsDecoderContext pCtx ); | |
| 130 | + | |
| 131 | +void_t ForceResetCurrentAccessUnit( PAccessUnit pAu ); | |
| 132 | +void_t ForceClearCurrentNal( PAccessUnit pAu ); | |
| 133 | + | |
| 134 | +} // namespace WelsDec | |
| 135 | + | |
| 136 | +#endif//WELS_DECODER_CORE_H__ | |
| 137 | + | |
| 138 | + | |
| @@ -0,0 +1,171 @@ | ||
| 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 error_code.h | |
| 33 | + * | |
| 34 | + * \brief Error codes used in Wels decoder side | |
| 35 | + * | |
| 36 | + * \date 3/4/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#ifndef WELS_ERROR_CODE_H__ | |
| 41 | +#define WELS_ERROR_CODE_H__ | |
| 42 | + | |
| 43 | +namespace WelsDec { | |
| 44 | + | |
| 45 | +typedef enum TagWelsErr | |
| 46 | +{ | |
| 47 | + ERR_NONE = 0, | |
| 48 | + ERR_INVALID_PARAMETERS = 1, | |
| 49 | + ERR_MALLOC_FAILED = 2, | |
| 50 | + ERR_API_FAILED = 3, | |
| 51 | + | |
| 52 | + ERR_BOUND = 31, | |
| 53 | +}EWelsErr; | |
| 54 | + | |
| 55 | +/* | |
| 56 | + * Specified error format: | |
| 57 | + * ERR_NO = (ERR_LEVEL_FROM (HIGH WORD) << 16) | (ERR_INFO_FROM (LOW WORD)) | |
| 58 | + * | |
| 59 | + */ | |
| 60 | +#define GENERATE_ERROR_NO(iErrLevel, iErrInfo) ((iErrLevel << 16) | (iErrInfo & 0xFFFF)) | |
| 61 | + | |
| 62 | + | |
| 63 | +/* ERR_LEVEL */ | |
| 64 | +//----------------------------------------------------------------------------------------------------------- | |
| 65 | +enum{ | |
| 66 | + ERR_LEVEL_ACCESS_UNIT = 1, | |
| 67 | + ERR_LEVEL_NAL_UNIT_HEADER, | |
| 68 | + ERR_LEVEL_PREFIX_NAL, | |
| 69 | + ERR_LEVEL_PARAM_SETS, | |
| 70 | + ERR_LEVEL_SLICE_HEADER, | |
| 71 | + ERR_LEVEL_SLICE_DATA, | |
| 72 | + ERR_LEVEL_MB_DATA, | |
| 73 | +}; | |
| 74 | + | |
| 75 | +//----------------------------------------------------------------------------------------------------------- | |
| 76 | + | |
| 77 | +/* More detailed error information, maximal value is 65535 */ | |
| 78 | +//----------------------------------------------------------------------------------------------------------- | |
| 79 | +#define ERR_INFO_COMMON_BASE 1 | |
| 80 | +#define ERR_INFO_SYNTAX_BASE 1001 | |
| 81 | +#define ERR_INFO_LOGIC_BASE 10001 | |
| 82 | +enum{ | |
| 83 | + /* Error from common system level: 1-1000 */ | |
| 84 | + ERR_INFO_OUT_OF_MEMORY = ERR_INFO_COMMON_BASE, | |
| 85 | + ERR_INFO_INVALID_ACCESS, | |
| 86 | + ERR_INFO_INVALID_PTR, | |
| 87 | + ERR_INFO_INVALID_PARAM, | |
| 88 | + ERR_INFO_FILE_NO_FOUND, | |
| 89 | + ERR_INFO_PATH_NO_FOUND, | |
| 90 | + ERR_INFO_ACCESS_DENIED, | |
| 91 | + ERR_INFO_NOT_READY, | |
| 92 | + ERR_INFO_WRITE_FAULT, | |
| 93 | + ERR_INFO_READ_FAULT, | |
| 94 | + /* Error from H.264 syntax elements parser: 1001-10000 */ | |
| 95 | + ERR_INFO_NO_PREFIX_CODE = ERR_INFO_SYNTAX_BASE, // No start prefix code indication | |
| 96 | + ERR_INFO_NO_PARAM_SETS, // No SPS and/ PPS before sequence header | |
| 97 | + ERR_INFO_PARAM_SETS_NOT_INTEGRATED, // Parameters sets (sps/pps) are not integrated at all before to decode VCL nal | |
| 98 | + ERR_INFO_SPS_ID_OVERFLOW, | |
| 99 | + ERR_INFO_PPS_ID_OVERFLOW, | |
| 100 | + ERR_INFO_INVALID_PROFILE_IDC, | |
| 101 | + ERR_INFO_UNMATCHED_LEVEL_IDC, | |
| 102 | + ERR_INFO_INVALID_POC_TYPE, | |
| 103 | + ERR_INFO_REF_COUNT_OVERFLOW, | |
| 104 | + ERR_INFO_CROPPING_NO_SUPPORTED, | |
| 105 | + ERR_INFO_INVALID_SLICEGROUP, | |
| 106 | + ERR_INFO_INVALID_SLICEGROUP_MAP_TYPE, | |
| 107 | + ERR_INFO_INVALID_FRAME_NUM, | |
| 108 | + ERR_INFO_FMO_INIT_FAIL, | |
| 109 | + ERR_INFO_SLICE_TYPE_OVERFLOW, | |
| 110 | + ERR_INFO_INVALID_QP, | |
| 111 | + ERR_INFO_INVALID_DBLOCKING_IDC, | |
| 112 | + ERR_INFO_INVALID_MB_TYPE, | |
| 113 | + ERR_INFO_INVALID_SUB_MB_TYPE, | |
| 114 | + ERR_INFO_UNAVAILABLE_TOP_BLOCK_FOR_INTRA, | |
| 115 | + ERR_INFO_UNAVAILABLE_LEFT_BLOCK_FOR_INTRA, | |
| 116 | + ERR_INFO_INVALID_REF_INDEX, | |
| 117 | + ERR_INFO_INVALID_CBP, | |
| 118 | + ERR_INFO_DQUANT_OUT_OF_RANGE, | |
| 119 | + ERR_INFO_CAVLC_INVALID_PREFIX, | |
| 120 | + ERR_INFO_CAVLC_INVALID_TOTAL_COEFF, | |
| 121 | + ERR_INFO_CAVLC_INVALID_ZERO_LEFT, | |
| 122 | + ERR_INFO_MV_OUT_OF_RANGE, | |
| 123 | + | |
| 124 | + ERR_INFO_INVALID_I4x4_PRED_MODE, | |
| 125 | + ERR_INFO_INVALID_I16x16_PRED_MODE, | |
| 126 | + ERR_INFO_INVALID_I_CHROMA_PRED_MODE, | |
| 127 | + | |
| 128 | + ERR_INFO_UNSUPPORTED_NON_BASELINE, | |
| 129 | + ERR_INFO_UNSUPPORTED_FMOTYPE, | |
| 130 | + ERR_INFO_UNSUPPORTED_MBAFF, | |
| 131 | + ERR_INFO_UNSUPPORTED_ILP, | |
| 132 | + ERR_INFO_UNSUPPORTED_CABAC_EL, | |
| 133 | + ERR_INFO_UNSUPPORTED_SPSI, | |
| 134 | + ERR_INFO_UNSUPPORTED_MGS, | |
| 135 | + ERR_INFO_UNSUPPORTED_BIPRED, | |
| 136 | + ERR_INFO_UNSUPPORTED_WP, | |
| 137 | + | |
| 138 | + ERR_INFO_FRAMES_LOST, | |
| 139 | + ERR_INFO_DEPENDENCY_SPATIAL_LAYER_LOST, | |
| 140 | + ERR_INFO_DEPENDENCY_QUALIT_LAYER_LOST, | |
| 141 | + ERR_INFO_REFERENCE_PIC_LOST, | |
| 142 | + ERR_INFO_INVALID_REORDERING, | |
| 143 | + ERR_INFO_INVALID_MARKING, | |
| 144 | + | |
| 145 | + ERR_INFO_FMO_NOT_SUPPORTED_IN_BASE_LAYER, | |
| 146 | + ERR_INFO_INVALID_ESS, | |
| 147 | + ERR_INFO_INVALID_SLICE_TYPE, | |
| 148 | + ERR_INFO_INVALID_REF_MARKING, | |
| 149 | + ERR_INFO_INVALID_REF_REORDERING, | |
| 150 | + | |
| 151 | + /* Error from corresponding logic, 10001-65535 */ | |
| 152 | + ERR_INFO_NO_IDR_PIC = ERR_INFO_LOGIC_BASE, // NO IDR picture available before sequence header | |
| 153 | + ERR_INFO_EC_NO_NEIGHBOUR_MBS, | |
| 154 | + ERR_INFO_EC_UNEXPECTED_MB_TYPE, | |
| 155 | + ERR_INFO_EC_NO_ENOUGH_NEIGHBOUR_MBS, | |
| 156 | + //for LTR | |
| 157 | + ERR_INFO_INVALID_MMCO_OPCODE_BASE, | |
| 158 | + ERR_INFO_INVALID_MMCO_SHORT2UNUSED, | |
| 159 | + EER_INFO_INVALID_MMCO_LONG2UNUSED, | |
| 160 | + ERR_INFO_INVALID_MMCO_SHOART2LONG, | |
| 161 | + ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW, | |
| 162 | + ERR_INFO_INVALID_MMCO_REF_NUM_NOT_ENOUGH, | |
| 163 | + ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX, | |
| 164 | +}; | |
| 165 | +//----------------------------------------------------------------------------------------------------------- | |
| 166 | + | |
| 167 | +} // namespace WelsDec | |
| 168 | + | |
| 169 | +#endif//WELS_ERROR_CODE_H__ | |
| 170 | + | |
| 171 | + | |
| @@ -0,0 +1,78 @@ | ||
| 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 expand_pic.h | |
| 33 | + * | |
| 34 | + * \brief Interface for expanding reconstructed picture to be used for reference | |
| 35 | + * | |
| 36 | + * \date 06/08/2009 Created | |
| 37 | + ************************************************************************************* | |
| 38 | + */ | |
| 39 | + | |
| 40 | +#ifndef WELS_EXPAND_PIC_H__ | |
| 41 | +#define WELS_EXPAND_PIC_H__ | |
| 42 | + | |
| 43 | +#include "decoder_context.h" | |
| 44 | +#include "picture.h" | |
| 45 | + | |
| 46 | +namespace WelsDec { | |
| 47 | + | |
| 48 | +void_t ExpandReferencingPicture(PPicture pPic, PExpandPictureFunc pExpandPictureLuma, PExpandPictureFunc pExpandPictureChroma[2]); | |
| 49 | + | |
| 50 | +#if defined(__cplusplus) | |
| 51 | +extern "C" { | |
| 52 | +#endif//__cplusplus | |
| 53 | + | |
| 54 | +#if defined(X86_ASM) | |
| 55 | +void_t ExpandPictureLuma_sse2( uint8_t *pDst, | |
| 56 | + const int32_t kiStride, | |
| 57 | + const int32_t kiPicWidth, | |
| 58 | + const int32_t kiPicHeight ); | |
| 59 | +void_t ExpandPictureChromaAlign_sse2( uint8_t *pDst, | |
| 60 | + const int32_t kiStride, | |
| 61 | + const int32_t kiPicWidth, | |
| 62 | + const int32_t kiPicHeight ); | |
| 63 | +void_t ExpandPictureChromaUnalign_sse2( uint8_t *pDst, | |
| 64 | + const int32_t kiStride, | |
| 65 | + const int32_t kiPicWidth, | |
| 66 | + const int32_t kiPicHeight ); | |
| 67 | +#endif//X86_ASM | |
| 68 | + | |
| 69 | +#if defined(__cplusplus) | |
| 70 | +} | |
| 71 | +#endif//__cplusplus | |
| 72 | + | |
| 73 | +// | |
| 74 | +void_t InitExpandPictureFunc( SExpandPicFunc *pExpandPicFunc, const uint32_t kuiCpuFlags ); | |
| 75 | + | |
| 76 | +} // namespace WelsDec | |
| 77 | + | |
| 78 | +#endif//WELS_EXPAND_PIC_H__ | |
| @@ -0,0 +1,113 @@ | ||
| 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 fmo.h | |
| 33 | + * | |
| 34 | + * \brief Flexible Macroblock Ordering implementation | |
| 35 | + * | |
| 36 | + * \date 2/4/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#ifndef WELS_FLEXIBLE_MACROBLOCK_ORDERING_H__ | |
| 41 | +#define WELS_FLEXIBLE_MACROBLOCK_ORDERING_H__ | |
| 42 | + | |
| 43 | +#include "typedefs.h" | |
| 44 | +#include "wels_const.h" | |
| 45 | +#include "parameter_sets.h" | |
| 46 | + | |
| 47 | +namespace WelsDec { | |
| 48 | + | |
| 49 | +#ifndef MB_XY_T | |
| 50 | +#define MB_XY_T int16_t | |
| 51 | +#endif//MB_XY_T | |
| 52 | + | |
| 53 | +/*! | |
| 54 | + * \brief Wels Flexible Macroblock Ordering (FMO) | |
| 55 | + */ | |
| 56 | +typedef struct TagFmo{ | |
| 57 | + uint8_t *pMbAllocMap; | |
| 58 | + int32_t iCountMbNum; | |
| 59 | + int32_t iSliceGroupCount; | |
| 60 | + int32_t iSliceGroupType; | |
| 61 | + bool_t bActiveFlag; | |
| 62 | + uint8_t uiReserved[3]; // reserved padding bytes | |
| 63 | +} SFmo, *PFmo; | |
| 64 | + | |
| 65 | + | |
| 66 | +/*! | |
| 67 | + * \brief Initialize Wels Flexible Macroblock Ordering (FMO) | |
| 68 | + * | |
| 69 | + * \param pFmo Wels fmo to be initialized | |
| 70 | + * \param pPps PPps | |
| 71 | + * \param kiMbWidth mb width | |
| 72 | + * \param kiMbHeight mb height | |
| 73 | + * | |
| 74 | + * \return 0 - successful; none 0 - failed; | |
| 75 | + */ | |
| 76 | +int32_t InitFmo( PFmo pFmo, PPps pPps, const int32_t kiMbWidth, const int32_t kiMbHeight ); | |
| 77 | + | |
| 78 | +/*! | |
| 79 | + * \brief Uninitialize Wels Flexible Macroblock Ordering (FMO) list | |
| 80 | + * | |
| 81 | + * \param pFmo Wels base fmo ptr to be uninitialized | |
| 82 | + * \param kiCnt count number of PPS per list | |
| 83 | + * \param kiAvail count available number of PPS in list | |
| 84 | + * | |
| 85 | + * \return NONE | |
| 86 | + */ | |
| 87 | +void_t UninitFmoList( PFmo pFmo, const int32_t kiCnt, const int32_t kiAvail ); | |
| 88 | + | |
| 89 | +/*! | |
| 90 | + * \brief update/insert FMO parameter unit | |
| 91 | + * | |
| 92 | + * \param pFmo FMO context | |
| 93 | + * \param pSps PSps | |
| 94 | + * \param pPps PPps | |
| 95 | + * \param pActiveFmoNum int32_t* [in/out] | |
| 96 | + * | |
| 97 | + * \return true - update/insert successfully; false - failed; | |
| 98 | + */ | |
| 99 | +bool_t FmoParamUpdate( PFmo pFmo, PSps pSps, PPps pPps, int32_t *pActiveFmoNum ); | |
| 100 | + | |
| 101 | +/*! | |
| 102 | + * \brief Get successive mb to be processed with given current mb_xy | |
| 103 | + * | |
| 104 | + * \param pFmo Wels fmo context | |
| 105 | + * \param iMbXy current mb_xy | |
| 106 | + * | |
| 107 | + * \return iNextMb - successful; -1 - failed; | |
| 108 | + */ | |
| 109 | +MB_XY_T FmoNextMb( PFmo pFmo, const MB_XY_T kiMbXy ); | |
| 110 | + | |
| 111 | +} // namespace WelsDec | |
| 112 | + | |
| 113 | +#endif//WELS_FLEXIBLE_MACROBLOCK_ORDERING_H__ | |
| @@ -0,0 +1,121 @@ | ||
| 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 get_intra_predictor.h | |
| 33 | + * | |
| 34 | + * \brief interfaces for get intra predictor about 16x16, 4x4, chroma. | |
| 35 | + * | |
| 36 | + * \date 4/2/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | + | |
| 41 | +#ifndef WELS_GET_INTRA_PREDICTOR_H__ | |
| 42 | +#define WELS_GET_INTRA_PREDICTOR_H__ | |
| 43 | + | |
| 44 | +#include "typedefs.h" | |
| 45 | + | |
| 46 | +//#pragma pack(1) | |
| 47 | + | |
| 48 | +namespace WelsDec { | |
| 49 | + | |
| 50 | +void_t WelsI4x4LumaPredV_c (uint8_t *pPred, const int32_t kiStride); | |
| 51 | +void_t WelsI4x4LumaPredH_c (uint8_t *pPred, const int32_t kiStride); | |
| 52 | +void_t WelsI4x4LumaPredDc_c (uint8_t *pPred, const int32_t kiStride); | |
| 53 | +void_t WelsI4x4LumaPredDcLeft_c(uint8_t *pPred, const int32_t kiStride); | |
| 54 | +void_t WelsI4x4LumaPredDcTop_c (uint8_t *pPred, const int32_t kiStride); | |
| 55 | +void_t WelsI4x4LumaPredDcNA_c (uint8_t *pPred, const int32_t kiStride); | |
| 56 | +void_t WelsI4x4LumaPredDDL_c (uint8_t *pPred, const int32_t kiStride); | |
| 57 | +void_t WelsI4x4LumaPredDDLTop_c(uint8_t *pPred, const int32_t kiStride); | |
| 58 | +void_t WelsI4x4LumaPredDDR_c (uint8_t *pPred, const int32_t kiStride); | |
| 59 | +void_t WelsI4x4LumaPredVL_c (uint8_t *pPred, const int32_t kiStride); | |
| 60 | +void_t WelsI4x4LumaPredVLTop_c (uint8_t *pPred, const int32_t kiStride); | |
| 61 | +void_t WelsI4x4LumaPredVR_c (uint8_t *pPred, const int32_t kiStride); | |
| 62 | +void_t WelsI4x4LumaPredHU_c (uint8_t *pPred, const int32_t kiStride); | |
| 63 | +void_t WelsI4x4LumaPredHD_c (uint8_t *pPred, const int32_t kiStride); | |
| 64 | + | |
| 65 | +void_t WelsIChromaPredV_c (uint8_t *pPred, const int32_t kiStride); | |
| 66 | +void_t WelsIChromaPredH_c (uint8_t *pPred, const int32_t kiStride); | |
| 67 | +void_t WelsIChromaPredPlane_c (uint8_t *pPred, const int32_t kiStride); | |
| 68 | +void_t WelsIChromaPredDc_c (uint8_t *pPred, const int32_t kiStride); | |
| 69 | +void_t WelsIChromaPredDcLeft_c (uint8_t *pPred, const int32_t kiStride); | |
| 70 | +void_t WelsIChromaPredDcTop_c (uint8_t *pPred, const int32_t kiStride); | |
| 71 | +void_t WelsIChromaPredDcNA_c (uint8_t *pPred, const int32_t kiStride); | |
| 72 | + | |
| 73 | +void_t WelsI16x16LumaPredV_c (uint8_t *pPred, const int32_t kiStride); | |
| 74 | +void_t WelsI16x16LumaPredH_c (uint8_t *pPred, const int32_t kiStride); | |
| 75 | +void_t WelsI16x16LumaPredPlane_c (uint8_t *pPred, const int32_t kiStride); | |
| 76 | +void_t WelsI16x16LumaPredDc_c (uint8_t *pPred, const int32_t kiStride); | |
| 77 | +void_t WelsI16x16LumaPredDcTop_c (uint8_t *pPred, const int32_t kiStride); | |
| 78 | +void_t WelsI16x16LumaPredDcLeft_c(uint8_t *pPred, const int32_t kiStride); | |
| 79 | +void_t WelsI16x16LumaPredDcNA_c (uint8_t *pPred, const int32_t kiStride); | |
| 80 | + | |
| 81 | +#if defined(__cplusplus) | |
| 82 | +extern "C" { | |
| 83 | +#endif//__cplusplus | |
| 84 | + | |
| 85 | +#if defined(X86_ASM) | |
| 86 | +void_t WelsI16x16LumaPredPlane_sse2(uint8_t *pPred, const int32_t kiStride); | |
| 87 | +void_t WelsI16x16LumaPredH_sse2 (uint8_t *pPred, const int32_t kiStride); | |
| 88 | +void_t WelsI16x16LumaPredV_sse2 (uint8_t *pPred, const int32_t kiStride); | |
| 89 | +void_t WelsI16x16LumaPredDc_sse2 (uint8_t *pPred, const int32_t kiStride); | |
| 90 | +void_t WelsI16x16LumaPredDcTop_sse2(uint8_t *pPred, const int32_t kiStride); | |
| 91 | +void_t WelsI16x16LumaPredDcNA_sse2 (uint8_t *pPred, const int32_t kiStride); | |
| 92 | + | |
| 93 | +void_t WelsIChromaPredDcTop_sse2 (uint8_t *pPred, const int32_t kiStride); | |
| 94 | +void_t WelsIChromaPredPlane_sse2 (uint8_t *pPred, const int32_t kiStride); | |
| 95 | +void_t WelsIChromaPredDc_sse2 (uint8_t *pPred, const int32_t kiStride); | |
| 96 | +void_t WelsIChromaPredH_mmx (uint8_t *pPred, const int32_t kiStride); | |
| 97 | +void_t WelsIChromaPredV_mmx (uint8_t *pPred, const int32_t kiStride); | |
| 98 | +void_t WelsIChromaPredDcLeft_mmx(uint8_t *pPred, const int32_t kiStride); | |
| 99 | +void_t WelsIChromaPredDcNA_mmx (uint8_t *pPred, const int32_t kiStride); | |
| 100 | + | |
| 101 | +void_t WelsI4x4LumaPredH_sse2 (uint8_t *pPred, const int32_t kiStride); | |
| 102 | +void_t WelsI4x4LumaPredDc_sse2(uint8_t *pPred, const int32_t kiStride); | |
| 103 | +void_t WelsI4x4LumaPredDDR_mmx(uint8_t *pPred, const int32_t kiStride); | |
| 104 | +void_t WelsI4x4LumaPredHD_mmx (uint8_t *pPred, const int32_t kiStride); | |
| 105 | +void_t WelsI4x4LumaPredHU_mmx (uint8_t *pPred, const int32_t kiStride); | |
| 106 | +void_t WelsI4x4LumaPredVR_mmx (uint8_t *pPred, const int32_t kiStride); | |
| 107 | +void_t WelsI4x4LumaPredDDL_mmx(uint8_t *pPred, const int32_t kiStride); | |
| 108 | +void_t WelsI4x4LumaPredVL_mmx (uint8_t *pPred, const int32_t kiStride); | |
| 109 | +#endif//X86_ASM | |
| 110 | + | |
| 111 | +#if defined(__cplusplus) | |
| 112 | +} | |
| 113 | +#endif//__cplusplus | |
| 114 | + | |
| 115 | +} // namespace WelsDec | |
| 116 | + | |
| 117 | +//#pragma pack() | |
| 118 | + | |
| 119 | +#endif //WELS_GET_INTRA_PREDICTOR_H__ | |
| 120 | + | |
| 121 | + | |
| @@ -0,0 +1,86 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +#ifndef ___LD_ST_MACROS___ | |
| 34 | +#define ___LD_ST_MACROS___ | |
| 35 | + | |
| 36 | +#include "typedefs.h" | |
| 37 | + | |
| 38 | +#ifdef __GNUC__ | |
| 39 | + | |
| 40 | + struct tagUnaligned_64 { uint64_t l; } __attribute__((packed)); | |
| 41 | + struct tagUnaligned_32 { uint32_t l; } __attribute__((packed)); | |
| 42 | + struct tagUnaligned_16 { uint16_t l; } __attribute__((packed)); | |
| 43 | + | |
| 44 | + #define LD16(a) (((struct tagUnaligned_16 *) (a))->l) | |
| 45 | + #define LD32(a) (((struct tagUnaligned_32 *) (a))->l) | |
| 46 | + #define LD64(a) (((struct tagUnaligned_64 *) (a))->l) | |
| 47 | + //#define _USE_STRUCT_INT_CVT | |
| 48 | +// #ifdef _USE_STRUCT_INT_CVT | |
| 49 | + #define ST16(a, b) (((struct tagUnaligned_16 *) (a))->l) = (b) | |
| 50 | + #define ST32(a, b) (((struct tagUnaligned_32 *) (a))->l) = (b) | |
| 51 | + #define ST64(a, b) (((struct tagUnaligned_64 *) (a))->l) = (b) | |
| 52 | +// #else | |
| 53 | +// inline void_t __ST16(void_t *dst, uint16_t v) { memcpy(dst, &v, 2); } | |
| 54 | +// inline void_t __ST32(void_t *dst, uint32_t v) { memcpy(dst, &v, 4); } | |
| 55 | + //inline void_t __ST64(void_t *dst, uint64_t v) { memcpy(dst, &v, 8); } | |
| 56 | +// #endif | |
| 57 | + | |
| 58 | +#else | |
| 59 | + | |
| 60 | +//#define INTD16(a) (*((int16_t*)(a))) | |
| 61 | +//#define INTD32(a) (*((int32_t*)(a))) | |
| 62 | +//#define INTD64(a) (*((int64_t*)(a))) | |
| 63 | + | |
| 64 | +#define LD16(a) (*((uint16_t*)(a))) | |
| 65 | +#define LD32(a) (*((uint32_t*)(a))) | |
| 66 | +#define LD64(a) (*((uint64_t*)(a))) | |
| 67 | + | |
| 68 | +#define ST16(a, b) *((uint16_t*)(a)) = (b) | |
| 69 | +#define ST32(a, b) *((uint32_t*)(a)) = (b) | |
| 70 | +#define ST64(a, b) *((uint64_t*)(a)) = (b) | |
| 71 | + | |
| 72 | +#endif /* !__GNUC__ */ | |
| 73 | + | |
| 74 | +#ifndef INTD16 | |
| 75 | +#define INTD16 LD16 | |
| 76 | +#endif//INTD16 | |
| 77 | + | |
| 78 | +#ifndef INTD32 | |
| 79 | +#define INTD32 LD32 | |
| 80 | +#endif//INTD32 | |
| 81 | + | |
| 82 | +#ifndef INTD64 | |
| 83 | +#define INTD64 LD64 | |
| 84 | +#endif//INTD64 | |
| 85 | + | |
| 86 | +#endif//___LD_ST_MACROS___ | |
| @@ -0,0 +1,306 @@ | ||
| 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 macros.h | |
| 33 | + * | |
| 34 | + * \brief MACRO based tool utilization | |
| 35 | + * | |
| 36 | + * \date 3/13/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#ifndef WELS_MACRO_UTILIZATIONS_H__ | |
| 41 | +#define WELS_MACRO_UTILIZATIONS_H__ | |
| 42 | + | |
| 43 | +#include <math.h> | |
| 44 | +#include <assert.h> | |
| 45 | +#include "typedefs.h" | |
| 46 | + | |
| 47 | + | |
| 48 | +namespace WelsDec { | |
| 49 | + | |
| 50 | +/* | |
| 51 | +* FORCE_STACK_ALIGN_1D: force 1 dimension local data aligned in stack | |
| 52 | +* _tp: type | |
| 53 | +* _nm: var name | |
| 54 | +* _sz: size | |
| 55 | +* _al: align bytes | |
| 56 | +* auxiliary var: _nm ## _tEmP | |
| 57 | +*/ | |
| 58 | +#define FORCE_STACK_ALIGN_1D(_tp, _nm, _sz, _al) \ | |
| 59 | + _tp _nm ## _tEmP[(_sz)+(_al)-1]; \ | |
| 60 | + _tp *_nm = _nm ## _tEmP + ((_al)-1) - (((int32_t)(_nm ## _tEmP + ((_al)-1)) & ((_al)-1))/sizeof(_tp)) | |
| 61 | + | |
| 62 | + | |
| 63 | +#define ENFORCE_STACK_ALIGN_2D(_tp, _nm, _cx, _cy, _al) \ | |
| 64 | + assert( ((_al) && !((_al) & ((_al) - 1))) && ((_al) >= sizeof(_tp)) ); /*_al should be power-of-2 and >= sizeof(_tp)*/\ | |
| 65 | + _tp _nm ## _tEmP[(_cx)*(_cy)+(_al)/sizeof(_tp)-1]; \ | |
| 66 | + _tp *_nm ## _tEmP_al = _nm ## _tEmP + ((_al)/sizeof(_tp)-1); \ | |
| 67 | + _nm ## _tEmP_al -= (((int32_t)_nm ## _tEmP_al & ((_al)-1))/sizeof(_tp)); \ | |
| 68 | + _tp (*_nm)[(_cy)] = (_tp (*)[(_cy)])_nm ## _tEmP_al; | |
| 69 | + | |
| 70 | + | |
| 71 | +///////////// from encoder | |
| 72 | +#if defined(_MSC_VER) | |
| 73 | + #define inline __inline | |
| 74 | + #define __FASTCALL __fastcall | |
| 75 | +// #define __align8(t,v) __declspec(align(8)) t v | |
| 76 | + #define __align16(t,v) __declspec(align(16)) t v | |
| 77 | +#elif defined(__GNUC__) | |
| 78 | +#if !defined(MAC_POWERPC) && !defined(UNIX) && !defined(ANDROID_NDK) && !defined(APPLE_IOS) | |
| 79 | + #define __FASTCALL __attribute__ ((fastcall))// linux, centos, mac_x86 can be used | |
| 80 | +#else | |
| 81 | + #define __FASTCALL // mean NULL for mac_ppc, solaris(sparc/x86) | |
| 82 | +#endif//MAC_POWERPC | |
| 83 | +// #define __align8(t,v) t v __attribute__ ((aligned (8))) | |
| 84 | + #define __align16(t,v) t v __attribute__ ((aligned (16))) | |
| 85 | + | |
| 86 | +#if defined(APPLE_IOS) | |
| 87 | + #define inline //For iOS platform | |
| 88 | +#endif | |
| 89 | + | |
| 90 | +#endif//_MSC_VER | |
| 91 | + | |
| 92 | + | |
| 93 | +#if !defined(SIZEOFRGB24) | |
| 94 | +#define SIZEOFRGB24(cx, cy) (3 * (cx) * (cy)) | |
| 95 | +#endif//SIZEOFRGB24 | |
| 96 | + | |
| 97 | +#if !defined(SIZEOFRGB32) | |
| 98 | +#define SIZEOFRGB32(cx, cy) (4 * (cx) * (cy)) | |
| 99 | +#endif//SIZEOFRGB32 | |
| 100 | +#if 1 | |
| 101 | +#ifndef WELS_ALIGN | |
| 102 | +#define WELS_ALIGN(x, n) (((x)+(n)-1)&~((n)-1)) | |
| 103 | +#endif//WELS_ALIGN | |
| 104 | + | |
| 105 | +#ifndef WELS_MAX | |
| 106 | +#define WELS_MAX(x, y) ((x) > (y) ? (x) : (y)) | |
| 107 | +#endif//WELS_MAX | |
| 108 | + | |
| 109 | +#ifndef WELS_MIN | |
| 110 | +#define WELS_MIN(x, y) ((x) < (y) ? (x) : (y)) | |
| 111 | +#endif//WELS_MIN | |
| 112 | +#else | |
| 113 | + | |
| 114 | +#ifndef WELS_ALIGN | |
| 115 | +#define WELS_ALIGN(x, n) (((x)+(n)-1)&~((n)-1)) | |
| 116 | +#endif//WELS_ALIGN | |
| 117 | + | |
| 118 | +#ifndef WELS_MAX | |
| 119 | +#define WELS_MAX(x, y) ((x) - (((x)-(y))&(((x)-(y))>>31))) | |
| 120 | +#endif//WELS_MAX | |
| 121 | + | |
| 122 | +#ifndef WELS_MIN | |
| 123 | +#define WELS_MIN(x, y) ((y) + (((x)-(y))&(((x)-(y))>>31))) | |
| 124 | +#endif//WELS_MIN | |
| 125 | + | |
| 126 | +#endif | |
| 127 | + | |
| 128 | +#ifndef WELS_CEIL | |
| 129 | +#define WELS_CEIL(x) ceil(x) // FIXME: low complexity instead of math library used | |
| 130 | +#endif//WELS_CEIL | |
| 131 | + | |
| 132 | +#ifndef WELS_FLOOR | |
| 133 | +#define WELS_FLOOR(x) floor(x) // FIXME: low complexity instead of math library used | |
| 134 | +#endif//WELS_FLOOR | |
| 135 | + | |
| 136 | +#ifndef WELS_ROUND | |
| 137 | +#define WELS_ROUND(x) ((int32_t)(0.5f+(x))) | |
| 138 | +#endif//WELS_ROUND | |
| 139 | + | |
| 140 | +#define WELS_NON_ZERO_COUNT_AVERAGE(nC,nA,nB) { \ | |
| 141 | + nC = nA + nB + 1; \ | |
| 142 | + nC >>= (uint8_t)( nA != -1 && nB != -1); \ | |
| 143 | + nC += (uint8_t)(nA == -1 && nB == -1); \ | |
| 144 | +} | |
| 145 | + | |
| 146 | +static __inline int32_t CeilLog2( int32_t i ) | |
| 147 | +{ | |
| 148 | + int32_t s = 0; i--; | |
| 149 | + while( i > 0 ) | |
| 150 | + { | |
| 151 | + s++; | |
| 152 | + i >>= 1; | |
| 153 | + } | |
| 154 | + return s; | |
| 155 | +} | |
| 156 | +/* | |
| 157 | +the second path will degrades the performance | |
| 158 | +*/ | |
| 159 | +#if 1 | |
| 160 | +static inline int32_t WelsMedian(int32_t iX, int32_t iY, int32_t iZ) | |
| 161 | +{ | |
| 162 | + int32_t iMin = iX, iMax = iX; | |
| 163 | + | |
| 164 | + if ( iY < iMin ) | |
| 165 | + iMin = iY; | |
| 166 | + else | |
| 167 | + iMax = iY; | |
| 168 | + | |
| 169 | + if ( iZ < iMin ) | |
| 170 | + iMin = iZ; | |
| 171 | + else if ( iZ > iMax ) | |
| 172 | + iMax = iZ; | |
| 173 | + | |
| 174 | + return (iX + iY + iZ) - (iMin + iMax); | |
| 175 | +} | |
| 176 | +#else | |
| 177 | +static inline int32_t WelsMedian(int32_t iX, int32_t iY, int32_t iZ) | |
| 178 | +{ | |
| 179 | + int32_t iTmp = (iX-iY)&((iX-iY)>>31); | |
| 180 | + iX -= iTmp; | |
| 181 | + iY += iTmp; | |
| 182 | + iY -= (iY-iZ)&((iY-iZ)>>31); | |
| 183 | + iY += (iX-iY)&((iX-iY)>>31); | |
| 184 | + return iY; | |
| 185 | +} | |
| 186 | + | |
| 187 | +#endif | |
| 188 | + | |
| 189 | +#ifndef NEG_NUM | |
| 190 | +//#define NEG_NUM( num ) (-num) | |
| 191 | +#define NEG_NUM(iX) (1+(~(iX))) | |
| 192 | +#endif// NEG_NUM | |
| 193 | + | |
| 194 | +#ifndef WELS_CLIP1 | |
| 195 | +//#define WELS_CLIP1(x) (x & ~255) ? (-x >> 31) : x | |
| 196 | +#define WELS_CLIP1(iX) (((iX) & ~255) ? (-(iX) >> 31) : (iX)) //iX not only a value but also can be an expression | |
| 197 | +#endif//WELS_CLIP1 | |
| 198 | + | |
| 199 | + | |
| 200 | +#ifndef WELS_SIGN | |
| 201 | +#define WELS_SIGN(iX) ((int32_t)(iX) >> 31) | |
| 202 | +#endif //WELS_SIGN | |
| 203 | +#ifndef WELS_ABS | |
| 204 | +#define WELS_ABS(iX) ((WELS_SIGN(iX) ^ (int32_t)(iX)) - WELS_SIGN(iX)) | |
| 205 | +#endif //WELS_ABS | |
| 206 | + | |
| 207 | +// WELS_CLIP3 | |
| 208 | +#ifndef WELS_CLIP3 | |
| 209 | +#define WELS_CLIP3(iX, iY, iZ) ((iX) < (iY) ? (iY) : ((iX) > (iZ) ? (iZ) : (iX))) | |
| 210 | +#endif //WELS_CLIP3 | |
| 211 | + | |
| 212 | +/* | |
| 213 | + * Description: to check variable validation and return the specified result | |
| 214 | + * iResult: value to be return | |
| 215 | + * bCaseIf: negative condition to be verified | |
| 216 | + */ | |
| 217 | +#ifndef WELS_VERIFY_RETURN_IF | |
| 218 | +#define WELS_VERIFY_RETURN_IF(iResult, bCaseIf) \ | |
| 219 | + if ( bCaseIf ){ \ | |
| 220 | + return iResult; \ | |
| 221 | + } | |
| 222 | +#endif//#if WELS_VERIFY_RETURN_IF | |
| 223 | + | |
| 224 | +/* | |
| 225 | + * Description: to check variable validation and return the specified result | |
| 226 | + * with correspoinding process advance. | |
| 227 | + * result: value to be return | |
| 228 | + * case_if: negative condition to be verified | |
| 229 | + * proc: process need perform | |
| 230 | + */ | |
| 231 | +#ifndef WELS_VERIFY_RETURN_PROC_IF | |
| 232 | +#define WELS_VERIFY_RETURN_PROC_IF(iResult, bCaseIf, fProc) \ | |
| 233 | + if ( bCaseIf ){ \ | |
| 234 | + fProc; \ | |
| 235 | + return iResult; \ | |
| 236 | + } | |
| 237 | +#endif//#if WELS_VERIFY_RETURN_PROC_IF | |
| 238 | + | |
| 239 | +/* | |
| 240 | + * Description: to check variable validation and return | |
| 241 | + * case_if: negtive condition to be verified | |
| 242 | + * return: NONE | |
| 243 | + */ | |
| 244 | +#ifndef WELS_VERIFY_IF | |
| 245 | +#define WELS_VERIFY_IF(bCaseIf) \ | |
| 246 | + if ( bCaseIf ){ \ | |
| 247 | + return; \ | |
| 248 | + } | |
| 249 | +#endif//#if WELS_VERIFY_IF | |
| 250 | + | |
| 251 | +/* | |
| 252 | + * Description: to check variable validation and return with correspoinding process advance. | |
| 253 | + * case_if: negtive condition to be verified | |
| 254 | + * proc: process need preform | |
| 255 | + * return: NONE | |
| 256 | + */ | |
| 257 | +#ifndef WELS_VERIFY_PROC_IF | |
| 258 | +#define WELS_VERIFY_PROC_IF(bCaseIf, fProc) \ | |
| 259 | + if ( bCaseIf ){ \ | |
| 260 | + fProc; \ | |
| 261 | + return; \ | |
| 262 | + } | |
| 263 | +#endif//#if WELS_VERIFY_IF | |
| 264 | + | |
| 265 | +/* | |
| 266 | + * Description: to safe free a ptr with free function pointer | |
| 267 | + * p: pointer to be destroyed | |
| 268 | + * free_fn: free function pointer used | |
| 269 | + */ | |
| 270 | +#ifndef WELS_SAFE_FREE_P | |
| 271 | +#define WELS_SAFE_FREE_P(pPtr, fFreeFunc) \ | |
| 272 | + do{ \ | |
| 273 | + if ( NULL != (pPtr) ){ \ | |
| 274 | + fFreeFunc( (pPtr) ); \ | |
| 275 | + (pPtr) = NULL; \ | |
| 276 | + } \ | |
| 277 | + }while( 0 ); | |
| 278 | +#endif//#if WELS_SAFE_FREE_P | |
| 279 | + | |
| 280 | +/* | |
| 281 | + * Description: to safe free an array ptr with free function pointer | |
| 282 | + * arr: pointer to an array, something like "**p"; | |
| 283 | + * num: number of elements in array | |
| 284 | + * free_fn: free function pointer | |
| 285 | + */ | |
| 286 | +#ifndef WELS_SAFE_FREE_ARR | |
| 287 | +#define WELS_SAFE_FREE_ARR(pArray, iNum, fFreeFunc) \ | |
| 288 | + do{ \ | |
| 289 | + if ( NULL != (pArray) ){ \ | |
| 290 | + int32_t iIdx = 0; \ | |
| 291 | + while( iIdx < iNum ){ \ | |
| 292 | + if ( NULL != (pArray)[iIdx] ){ \ | |
| 293 | + fFreeFunc( (pArray)[iIdx] ); \ | |
| 294 | + (pArray)[iIdx] = NULL; \ | |
| 295 | + } \ | |
| 296 | + ++ iIdx; \ | |
| 297 | + } \ | |
| 298 | + fFreeFunc((pArray)); \ | |
| 299 | + (pArray) = NULL; \ | |
| 300 | + } \ | |
| 301 | + }while( 0 ); | |
| 302 | +#endif//#if WELS_SAFE_FREE_ARR | |
| 303 | + | |
| 304 | +} // namespace WelsDec | |
| 305 | + | |
| 306 | +#endif//WELS_MACRO_UTILIZATIONS_H__ | |
| @@ -0,0 +1,81 @@ | ||
| 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 manage_dec_ref.h | |
| 33 | + * | |
| 34 | + * Abstract | |
| 35 | + * Interface for managing reference picture | |
| 36 | + * | |
| 37 | + * History | |
| 38 | + * 08/14/2009 Created | |
| 39 | + * | |
| 40 | + *****************************************************************************/ | |
| 41 | +#ifndef WELS_MANAGE_DEC_REF_H__ | |
| 42 | +#define WELS_MANAGE_DEC_REF_H__ | |
| 43 | + | |
| 44 | + | |
| 45 | +#include "typedefs.h" | |
| 46 | +#include "decoder_context.h" | |
| 47 | + | |
| 48 | +namespace WelsDec { | |
| 49 | + | |
| 50 | +typedef enum TagRemoveFlag{ | |
| 51 | + REMOVE_TARGET = 0, | |
| 52 | + REMOVE_BASE = 1, | |
| 53 | + REMOVE_BASE_FIRST = 2 | |
| 54 | +}ERemoveFlag; | |
| 55 | + | |
| 56 | +void_t WelsResetRefPic (PWelsDecoderContext pCtx); | |
| 57 | +int32_t WelsInitRefList (PWelsDecoderContext pCtx, int32_t iPoc); | |
| 58 | +int32_t WelsReorderRefList(PWelsDecoderContext pCtx); | |
| 59 | +int32_t WelsMarkAsRef (PWelsDecoderContext pCtx, const bool_t kbRefBaseMarkingFlag); | |
| 60 | + | |
| 61 | +static PPicture WelsDelShortFromList (PRefPic pRefPic, int32_t iFrameNum, ERemoveFlag eRemoveFlag); | |
| 62 | +static PPicture WelsDelLongFromList (PRefPic pRefPic, uint32_t uiLongTermFrameIdx, ERemoveFlag eRemoveFlag); | |
| 63 | +static PPicture WelsDelShortFromListSetUnref(PRefPic pRefPic, int32_t iFrameNum, ERemoveFlag eRemoveFlag); | |
| 64 | +static PPicture WelsDelLongFromListSetUnref (PRefPic pRefPic, uint32_t uiLongTermFrameIdx, ERemoveFlag eRemoveFlag); | |
| 65 | + | |
| 66 | +static int32_t MMCOBase (PWelsDecoderContext pCtx, PRefBasePicMarking pRefPicBaseMarking); | |
| 67 | +static int32_t MMCO (PWelsDecoderContext pCtx, PRefPicMarking pRefPicMarking); | |
| 68 | +static int32_t MMCOProcess (PWelsDecoderContext pCtx, uint32_t uiMmcoType, bool_t bRefBasePic, | |
| 69 | + int32_t iShortFrameNum, uint32_t uiLongTermPicNum, int32_t iLongTermFrameIdx, int32_t iMaxLongTermFrameIdx); | |
| 70 | +static int32_t SlidingWindow(PWelsDecoderContext pCtx); | |
| 71 | + | |
| 72 | +static int32_t AddShortTermToList(PRefPic pRefPic, PPicture pPic); | |
| 73 | +static int32_t AddLongTermToList (PRefPic pRefPic, PPicture pPic, int32_t iLongTermFrameIdx); | |
| 74 | +static int32_t AssignLongTermIdx (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx); | |
| 75 | +static int32_t MarkAsLongTerm (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx); | |
| 76 | + | |
| 77 | +} // namespace WelsDec | |
| 78 | + | |
| 79 | +#endif//WELS_MANAGE_DEC_REF_H__ | |
| 80 | + | |
| 81 | + | |
| @@ -0,0 +1,84 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +//mb_cache.h | |
| 34 | +#ifndef WELS_MACROBLOCK_CACHE_H__ | |
| 35 | +#define WELS_MACROBLOCK_CACHE_H__ | |
| 36 | + | |
| 37 | +#include "typedefs.h" | |
| 38 | + | |
| 39 | +namespace WelsDec { | |
| 40 | + | |
| 41 | +//#pragma pack(1) | |
| 42 | + | |
| 43 | +#define REF_NOT_AVAIL -2 | |
| 44 | +#define REF_NOT_IN_LIST -1 //intra | |
| 45 | + | |
| 46 | +/* | |
| 47 | + * MB Cache information, such one cache should be defined within a slice | |
| 48 | + */ | |
| 49 | +/* | |
| 50 | + * Cache for Luma Cache for Chroma(Cb, Cr) | |
| 51 | + * | |
| 52 | + * TL T T T T TL T T | |
| 53 | + * L - - - - L - - | |
| 54 | + * L - - - - L - - TR | |
| 55 | + * L - - - - | |
| 56 | + * L - - - - TR | |
| 57 | + * | |
| 58 | + */ | |
| 59 | + | |
| 60 | +////////////////////////mapping scan index//////////////////////// | |
| 61 | + | |
| 62 | +// for data sharing cross modules and try to reduce size of binary generated | |
| 63 | +extern const uint8_t g_kuiMbNonZeroCountIdx[24]; | |
| 64 | +extern const uint8_t g_kuiCache30ScanIdx[16]; | |
| 65 | +extern const uint8_t g_kuiCacheNzcScanIdx[24]; | |
| 66 | + | |
| 67 | +extern const uint8_t g_kuiScan4[16]; | |
| 68 | + | |
| 69 | +typedef struct TagNeighborAvail | |
| 70 | +{ | |
| 71 | + int32_t iTopAvail; | |
| 72 | + int32_t iLeftAvail; | |
| 73 | + int32_t iRightTopAvail; | |
| 74 | + int32_t iLeftTopAvail; //used for check intra_pred_mode avail or not //1: avail; 0: unavail | |
| 75 | + | |
| 76 | + int32_t iLeftType; | |
| 77 | + int32_t iTopType; | |
| 78 | + int32_t iLeftTopType; | |
| 79 | + int32_t iRightTopType; | |
| 80 | +}SNeighAvail, *PNeighAvail; | |
| 81 | + | |
| 82 | +} // namespace WelsDec | |
| 83 | + | |
| 84 | +#endif//WELS_MACROBLOCK_CACHE_H__ | |
| @@ -0,0 +1,79 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +#ifndef WELS_MC_H__ | |
| 34 | +#define WELS_MC_H__ | |
| 35 | + | |
| 36 | +#include "wels_const.h" | |
| 37 | +#include "macros.h" | |
| 38 | +#include "decoder_context.h" | |
| 39 | + | |
| 40 | +namespace WelsDec { | |
| 41 | + | |
| 42 | +void_t InitMcFunc(SMcFunc *pMcFunc, int32_t iCpu); | |
| 43 | + | |
| 44 | +#if defined(__cplusplus) | |
| 45 | +extern "C" { | |
| 46 | +#endif//__cplusplus | |
| 47 | + | |
| 48 | +//***************************************************************************// | |
| 49 | +// MMXEXT definition // | |
| 50 | +//***************************************************************************// | |
| 51 | +#if defined(X86_ASM) | |
| 52 | +typedef void_t (*PMcChromaWidthExtFunc)( uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, const uint8_t *kpABCD, int32_t iHeight ); | |
| 53 | +extern void_t McHorVer20WidthEq4_mmx (uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, int32_t iHeight); | |
| 54 | +extern void_t McChromaWidthEq4_mmx (uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, const uint8_t *kpABCD, int32_t iHeight ); | |
| 55 | +extern void_t McCopyWidthEq4_mmx (uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, int32_t iHeight); | |
| 56 | +extern void_t McCopyWidthEq8_mmx (uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, int32_t iHeight); | |
| 57 | +extern void_t PixelAvgWidthEq4_mmx (uint8_t *pDst, int32_t iDstStride, uint8_t *pSrcA, int32_t iSrcAStride, uint8_t *pSrcB, int32_t iSrcBStride, int32_t iHeight); | |
| 58 | +extern void_t PixelAvgWidthEq8_mmx (uint8_t *pDst, int32_t iDstStride, uint8_t *pSrcA, int32_t iSrcAStride, uint8_t *pSrcB, int32_t iSrcBStride, int32_t iHeight); | |
| 59 | +//***************************************************************************// | |
| 60 | +// SSE2 definition // | |
| 61 | +//***************************************************************************// | |
| 62 | +extern void_t McChromaWidthEq8_sse2 (uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, const uint8_t* kpABCD, int32_t iHeight ); | |
| 63 | +extern void_t McCopyWidthEq16_sse2 (uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, int32_t iHeight); | |
| 64 | +extern void_t McHorVer20WidthEq8_sse2 (uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, int32_t iHeight); | |
| 65 | +extern void_t McHorVer20WidthEq16_sse2(uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, int32_t iHeight); | |
| 66 | +extern void_t McHorVer02WidthEq8_sse2 (uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, int32_t iHeight); | |
| 67 | +extern void_t McHorVer22Width8HorFirst_sse2(uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst, int32_t iDstStride, int32_t iHeight); | |
| 68 | +extern void_t McHorVer22VerLast_sse2(uint8_t * pTap, int32_t iTapStride, uint8_t * pDst,int32_t iDstStride,int32_t iWidth,int32_t iHeight); | |
| 69 | +extern void_t PixelAvgWidthEq16_sse2 (uint8_t *pDst, int32_t iDstStride, uint8_t *pSrcA, int32_t iSrcAStride, uint8_t *pSrcB, int32_t iSrcBStride, int32_t iHeight); | |
| 70 | + | |
| 71 | +#endif //X86_ASM | |
| 72 | + | |
| 73 | +#if defined(__cplusplus) | |
| 74 | +} | |
| 75 | +#endif//__cplusplus | |
| 76 | + | |
| 77 | +} // namespace WelsDec | |
| 78 | + | |
| 79 | +#endif//WELS_MC_H__ | |
| @@ -0,0 +1,100 @@ | ||
| 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 measure_time.h | |
| 33 | + * | |
| 34 | + * \brief time cost measure utilization | |
| 35 | + * | |
| 36 | + * \date 04/28/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#ifndef WELS_TIME_COST_MEASURE_UTIL_H__ | |
| 41 | +#define WELS_TIME_COST_MEASURE_UTIL_H__ | |
| 42 | + | |
| 43 | +#include <stdlib.h> | |
| 44 | + | |
| 45 | +#if !(defined(_MSC_VER) || defined(__MINGW32__)) | |
| 46 | +#include <sys/time.h> | |
| 47 | +#else | |
| 48 | +#include "typedefs.h" | |
| 49 | +//#include <sys/types.h> | |
| 50 | +#include <sys/timeb.h> | |
| 51 | +#endif | |
| 52 | +#include <time.h> | |
| 53 | +#if defined(WIN32) | |
| 54 | +#include <windows.h> | |
| 55 | +#endif//#if WIN32 | |
| 56 | + | |
| 57 | +#ifdef __cplusplus | |
| 58 | +extern "C" { | |
| 59 | +#endif//__cplusplus | |
| 60 | + | |
| 61 | +/*! | |
| 62 | + * \brief time cost measure utilization | |
| 63 | + * \param void_t | |
| 64 | + * \return time elapsed since run (unit: microsecond) | |
| 65 | + */ | |
| 66 | + | |
| 67 | +int64_t WelsTime( void_t ) | |
| 68 | +{ | |
| 69 | +#if !(defined(_MSC_VER) || defined(__MINGW32__)) | |
| 70 | + struct timeval tv_date; | |
| 71 | + | |
| 72 | + gettimeofday( &tv_date, NULL ); | |
| 73 | + return( (int64_t) tv_date.tv_sec * 1000000 + (int64_t) tv_date.tv_usec ); | |
| 74 | +#else | |
| 75 | +#if defined (WIN32) | |
| 76 | + static int64_t iMtimeFreq = 0; | |
| 77 | + int64_t iMtimeCur = 0; | |
| 78 | + int64_t iResult = 0; | |
| 79 | + if ( !iMtimeFreq ){ | |
| 80 | + QueryPerformanceFrequency((LARGE_INTEGER *)&iMtimeFreq); | |
| 81 | + if ( !iMtimeFreq ) | |
| 82 | + iMtimeFreq = 1; | |
| 83 | + } | |
| 84 | + QueryPerformanceCounter((LARGE_INTEGER *)&iMtimeCur); | |
| 85 | + iResult = (int64_t)((double)iMtimeCur * 1e6 / (double)iMtimeFreq + 0.5); | |
| 86 | + return iResult; | |
| 87 | +#else | |
| 88 | + struct _timeb sTime; | |
| 89 | + | |
| 90 | + _ftime(&sTime); | |
| 91 | + return ((int64_t)sTime.time * (1000) + (int64_t)sTime.millitm) * (1000); | |
| 92 | +#endif//#if WIN32 | |
| 93 | +#endif//!(defined(_MSC_VER) || defined(__MINGW32__)) | |
| 94 | +} | |
| 95 | + | |
| 96 | +#ifdef __cplusplus | |
| 97 | +} | |
| 98 | +#endif | |
| 99 | + | |
| 100 | +#endif//WELS_TIME_COST_MEASURE_UTIL_H__ | |
| @@ -0,0 +1,92 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + * memory alignment utilization | |
| 32 | + */ | |
| 33 | + | |
| 34 | +#ifndef WELS_MEM_ALIGN_H__ | |
| 35 | +#define WELS_MEM_ALIGN_H__ | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | +#include <stdlib.h> | |
| 40 | +#include <string.h> | |
| 41 | +#include "utils.h" | |
| 42 | + | |
| 43 | +namespace WelsDec { | |
| 44 | + | |
| 45 | +//#define CACHE_LINE 64 | |
| 46 | + | |
| 47 | +#ifdef __cplusplus | |
| 48 | +extern "C" { | |
| 49 | +#endif//__cplusplus | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | +/*! | |
| 54 | +************************************************************************************* | |
| 55 | +* \brief malloc with zero filled utilization in Wels | |
| 56 | +* | |
| 57 | +* \param kuiSize size of memory block required | |
| 58 | +* | |
| 59 | +* \return allocated memory pointer exactly, failed in case of NULL return | |
| 60 | +* | |
| 61 | +* \note N/A | |
| 62 | +************************************************************************************* | |
| 63 | +*/ | |
| 64 | +void_t * WelsMalloc( const uint32_t kuiSize, const str_t *kpTag ); | |
| 65 | + | |
| 66 | +/*! | |
| 67 | +************************************************************************************* | |
| 68 | +* \brief free utilization in Wels | |
| 69 | +* | |
| 70 | +* \param pPtr data pointer to be free. | |
| 71 | +* i.e, uint8_t *pPtr = actual data to be free, argv = &pPtr. | |
| 72 | +* | |
| 73 | +* \return NONE | |
| 74 | +* | |
| 75 | +* \note N/A | |
| 76 | +************************************************************************************* | |
| 77 | +*/ | |
| 78 | +void_t WelsFree( void_t * pPtr, const str_t *kpTag ); | |
| 79 | + | |
| 80 | +#define WELS_SAFE_FREE(pPtr, pTag) if (pPtr) { WelsFree(pPtr, pTag); pPtr = NULL; } | |
| 81 | + | |
| 82 | +/* | |
| 83 | + * memory operation routines | |
| 84 | + */ | |
| 85 | + | |
| 86 | +#ifdef __cplusplus | |
| 87 | +} | |
| 88 | +#endif//__cplusplus | |
| 89 | + | |
| 90 | +} // namespace WelsDec | |
| 91 | + | |
| 92 | +#endif //WELS_MEM_ALIGN_H__ | |
| @@ -0,0 +1,65 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2008-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 | + * memmgr_nal_unit.h | |
| 33 | + * | |
| 34 | + * Abstract | |
| 35 | + * memory manager utils for NAL Unit list available | |
| 36 | + * | |
| 37 | + * History | |
| 38 | + * 07/10/2008 Created | |
| 39 | + * | |
| 40 | + *****************************************************************************/ | |
| 41 | +#ifndef WELS_MEMORY_MANAGER_NAL_UNIT_H__ | |
| 42 | +#define WELS_MEMORY_MANAGER_NAL_UNIT_H__ | |
| 43 | + | |
| 44 | +#include "typedefs.h" | |
| 45 | +#include "wels_common_basis.h" | |
| 46 | +#include "nalu.h" | |
| 47 | + | |
| 48 | +namespace WelsDec { | |
| 49 | + | |
| 50 | +int32_t MemInitNalList(PAccessUnit *ppAu, const uint32_t kuiSize); | |
| 51 | + | |
| 52 | +int32_t MemFreeNalList(PAccessUnit *ppAu); | |
| 53 | + | |
| 54 | +/* | |
| 55 | + * MemGetNextNal | |
| 56 | + * Get next NAL Unit for using. | |
| 57 | + * Need expand NAL Unit list if exceeding count number of available NAL Units withing an Access Unit | |
| 58 | + */ | |
| 59 | +PNalUnit MemGetNextNal(PAccessUnit *ppAu); | |
| 60 | + | |
| 61 | +} // namespace WelsDec | |
| 62 | + | |
| 63 | +#endif//WELS_MEMORY_MANAGER_NAL_UNIT_H__ | |
| 64 | + | |
| 65 | + | |
| @@ -0,0 +1,98 @@ | ||
| 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 | + | |
| 46 | +namespace WelsDec { | |
| 47 | + | |
| 48 | +/*! | |
| 49 | +* \brief update mv and ref_index cache for current MB, only for P_16x16 (SKIP inclusive) | |
| 50 | +* \param | |
| 51 | +* \param | |
| 52 | +*/ | |
| 53 | +void_t UpdateP16x16MotionInfo(PDqLayer pCurDqLayer, int8_t iRef, int16_t iMVs[2]); | |
| 54 | + | |
| 55 | + /*! | |
| 56 | + * \brief update mv and ref_index cache for current MB, only for P_16x8 | |
| 57 | + * \param | |
| 58 | + * \param | |
| 59 | + */ | |
| 60 | +void_t UpdateP16x8MotionInfo(PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30], | |
| 61 | + int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]); | |
| 62 | + | |
| 63 | + | |
| 64 | + /*! | |
| 65 | + * \brief update mv and ref_index cache for current MB, only for P_8x16 | |
| 66 | + * \param | |
| 67 | + * \param | |
| 68 | + */ | |
| 69 | +void_t UpdateP8x16MotionInfo(PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30], | |
| 70 | + int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]); | |
| 71 | + | |
| 72 | +/*! | |
| 73 | + * \brief get the motion predictor for 4*4 or 8*8 or 16*16 block | |
| 74 | + * \param | |
| 75 | + * \param output mvp_x and mvp_y | |
| 76 | + */ | |
| 77 | +void_t PredMv(int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30], | |
| 78 | + int32_t iPartIdx, int32_t iPartWidth, int8_t iRef, int16_t iMVP[2]); | |
| 79 | + | |
| 80 | +/*! | |
| 81 | + * \brief get the motion predictor for inter16x8 MB | |
| 82 | + * \param | |
| 83 | + * \param output mvp_x and mvp_y | |
| 84 | + */ | |
| 85 | +void_t PredInter16x8Mv(int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30], | |
| 86 | + int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]); | |
| 87 | + | |
| 88 | +/*! | |
| 89 | + * \brief get the motion predictor for inter8x16 MB | |
| 90 | + * \param | |
| 91 | + * \param output mvp_x and mvp_y | |
| 92 | + */ | |
| 93 | +void_t PredInter8x16Mv(int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30], | |
| 94 | + int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]); | |
| 95 | + | |
| 96 | +} // namespace WelsDec | |
| 97 | + | |
| 98 | +#endif//WELS_MV_PRED_H__ | |
| @@ -0,0 +1,89 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +//nal_prefix.h - definitions for NAL Unit Header(/Ext) and PrefixNALUnit | |
| 34 | +#ifndef WELS_NAL_UNIT_PREFIX_H__ | |
| 35 | +#define WELS_NAL_UNIT_PREFIX_H__ | |
| 36 | + | |
| 37 | +#include "typedefs.h" | |
| 38 | +#include "wels_common_basis.h" | |
| 39 | +#include "slice.h" | |
| 40 | + | |
| 41 | +namespace WelsDec { | |
| 42 | + | |
| 43 | +//#pragma pack(1) | |
| 44 | + | |
| 45 | +///////////////////////////////////NAL Unit prefix/headers/////////////////////////////////// | |
| 46 | + | |
| 47 | +/* NAL Unix Header in AVC, refer to Page 56 in JVT X201wcm */ | |
| 48 | +typedef struct TagNalUnitHeader{ | |
| 49 | + uint8_t uiForbiddenZeroBit; | |
| 50 | + uint8_t uiNalRefIdc; | |
| 51 | + ENalUnitType eNalUnitType; | |
| 52 | + uint8_t uiReservedOneByte; // only padding usage | |
| 53 | +}SNalUnitHeader, *PNalUnitHeader; | |
| 54 | + | |
| 55 | +/* NAL Unit Header in scalable extension syntax, refer to Page 390 in JVT X201wcm */ | |
| 56 | +typedef struct TagNalUnitHeaderExt{ | |
| 57 | + SNalUnitHeader sNalUnitHeader; | |
| 58 | + | |
| 59 | +// uint8_t reserved_one_bit; | |
| 60 | + bool_t bIdrFlag; | |
| 61 | + uint8_t uiPriorityId; | |
| 62 | + int8_t iNoInterLayerPredFlag; // change as int8_t to support 3 values probably in encoder | |
| 63 | + uint8_t uiDependencyId; | |
| 64 | + | |
| 65 | + uint8_t uiQualityId; | |
| 66 | + uint8_t uiTemporalId; | |
| 67 | + bool_t bUseRefBasePicFlag; | |
| 68 | + bool_t bDiscardableFlag; | |
| 69 | + | |
| 70 | + bool_t bOutputFlag; | |
| 71 | + uint8_t uiReservedThree2Bits; | |
| 72 | + // Derived variable(s) | |
| 73 | + uint8_t uiLayerDqId; | |
| 74 | + bool_t bNalExtFlag; | |
| 75 | +}SNalUnitHeaderExt, *PNalUnitHeaderExt; | |
| 76 | + | |
| 77 | +/* Prefix NAL Unix syntax, refer to Page 392 in JVT X201wcm */ | |
| 78 | +typedef struct TagPrefixNalUnit{ | |
| 79 | + SRefBasePicMarking sRefPicBaseMarking; | |
| 80 | + bool_t bStoreRefBasePicFlag; | |
| 81 | + bool_t bPrefixNalUnitAdditionalExtFlag; | |
| 82 | + bool_t bPrefixNalUnitExtFlag; | |
| 83 | +}SPrefixNalUnit, *PPrefixNalUnit; | |
| 84 | + | |
| 85 | +//#pragma pack() | |
| 86 | + | |
| 87 | +} // namespace WelsDec | |
| 88 | + | |
| 89 | +#endif//WELS_NAL_UNIT_PREFIX_H__ | |
| @@ -0,0 +1,79 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +//nalu.h: NAL Unit definition | |
| 34 | +#ifndef WELS_NAL_UNIT_H__ | |
| 35 | +#define WELS_NAL_UNIT_H__ | |
| 36 | + | |
| 37 | +#include "typedefs.h" | |
| 38 | +#include "wels_common_basis.h" | |
| 39 | +#include "nal_prefix.h" | |
| 40 | +#include "bit_stream.h" | |
| 41 | + | |
| 42 | +namespace WelsDec { | |
| 43 | + | |
| 44 | +///////////////////////////////////NAL UNIT level/////////////////////////////////// | |
| 45 | + | |
| 46 | +/* NAL Unit Structure */ | |
| 47 | +typedef struct TagNalUnit{ | |
| 48 | + SNalUnitHeaderExt sNalHeaderExt; | |
| 49 | + | |
| 50 | + union{ | |
| 51 | + struct SVclNal{ | |
| 52 | + SSliceHeaderExt sSliceHeaderExt; | |
| 53 | + SBitStringAux sSliceBitsRead; | |
| 54 | + uint8_t *pNalPos; // save the address of slice nal for GPU function | |
| 55 | + int32_t iNalLength; // save the nal length for GPU function | |
| 56 | + bool_t bSliceHeaderExtFlag; | |
| 57 | + } sVclNal; | |
| 58 | + SPrefixNalUnit sPrefixNal; | |
| 59 | + } sNalData; | |
| 60 | + | |
| 61 | +}SNalUnit, *PNalUnit; | |
| 62 | + | |
| 63 | +///////////////////////////////////ACCESS Unit level/////////////////////////////////// | |
| 64 | + | |
| 65 | +/* Access Unit structure */ | |
| 66 | +typedef struct TagAccessUnits{ | |
| 67 | + PNalUnit *pNalUnitsList; // list of NAL Units pointer in this AU | |
| 68 | + uint32_t uiAvailUnitsNum; // Number of NAL Units available in each AU list based current bitstream, | |
| 69 | + uint32_t uiActualUnitsNum; // actual number of NAL units belong to current au | |
| 70 | + // While available number exceeds count size below, need realloc extra NAL Units for list space. | |
| 71 | + uint32_t uiCountUnitsNum; // Count size number of malloced NAL Units in each AU list | |
| 72 | + uint32_t uiStartPos; | |
| 73 | + uint32_t uiEndPos; | |
| 74 | + bool_t bCompletedAuFlag; // Indicate whether it is a completed AU | |
| 75 | +}SAccessUnit, *PAccessUnit; | |
| 76 | + | |
| 77 | +} // namespace WelsDec | |
| 78 | + | |
| 79 | +#endif//WELS_NAL_UNIT_H__ | |
| @@ -0,0 +1,173 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +#ifndef WELS_PARAMETER_SETS_H__ | |
| 34 | +#define WELS_PARAMETER_SETS_H__ | |
| 35 | + | |
| 36 | +#include "typedefs.h" | |
| 37 | +#include "wels_const.h" | |
| 38 | +#include "wels_common_basis.h" | |
| 39 | + | |
| 40 | +namespace WelsDec { | |
| 41 | + | |
| 42 | +//#pragma pack(1) | |
| 43 | + | |
| 44 | +/* Sequence Parameter Set, refer to Page 57 in JVT X201wcm */ | |
| 45 | +typedef struct TagSps{ | |
| 46 | + int32_t iSpsId; | |
| 47 | + uint32_t iMbWidth; | |
| 48 | + uint32_t iMbHeight; | |
| 49 | + uint32_t uiTotalMbCount; //used in decode_slice_data() | |
| 50 | + | |
| 51 | + uint32_t uiLog2MaxFrameNum; | |
| 52 | + uint32_t uiPocType; | |
| 53 | + /* POC type 0 */ | |
| 54 | + int32_t iLog2MaxPocLsb; | |
| 55 | + /* POC type 1 */ | |
| 56 | + int32_t iOffsetForNonRefPic; | |
| 57 | + | |
| 58 | + int32_t iOffsetForTopToBottomField; | |
| 59 | + int32_t iNumRefFramesInPocCycle; | |
| 60 | + int8_t iOffsetForRefFrame[256]; | |
| 61 | + int32_t iNumRefFrames; | |
| 62 | + | |
| 63 | + SPosOffset sFrameCrop; | |
| 64 | + | |
| 65 | + ProfileIdc uiProfileIdc; | |
| 66 | + uint8_t uiLevelIdc; | |
| 67 | + uint8_t uiChromaFormatIdc; | |
| 68 | + uint8_t uiChromaArrayType; | |
| 69 | + | |
| 70 | + uint8_t uiBitDepthLuma; | |
| 71 | + uint8_t uiBitDepthChroma; | |
| 72 | + /* TO BE CONTINUE: POC type 1 */ | |
| 73 | + bool_t bDeltaPicOrderAlwaysZeroFlag; | |
| 74 | + bool_t bGapsInFrameNumValueAllowedFlag; | |
| 75 | + | |
| 76 | + bool_t bFrameMbsOnlyFlag; | |
| 77 | + bool_t bMbaffFlag; // MB Adapative Frame Field | |
| 78 | + bool_t bDirect8x8InferenceFlag; | |
| 79 | + bool_t bFrameCroppingFlag; | |
| 80 | + | |
| 81 | + bool_t bVuiParamPresentFlag; | |
| 82 | +// bool_t bTimingInfoPresentFlag; | |
| 83 | +// bool_t bFixedFrameRateFlag; | |
| 84 | + bool_t bConstraintSet0Flag; | |
| 85 | + bool_t bConstraintSet1Flag; | |
| 86 | + bool_t bConstraintSet2Flag; | |
| 87 | + bool_t bConstraintSet3Flag; | |
| 88 | + bool_t bSeparateColorPlaneFlag; | |
| 89 | + bool_t bQpPrimeYZeroTransfBypassFlag; | |
| 90 | + bool_t bSeqScalingMatrixPresentFlag; | |
| 91 | + bool_t bSeqScalingListPresentFlag[12]; | |
| 92 | +}SSps, *PSps; | |
| 93 | + | |
| 94 | + | |
| 95 | +/* Sequence Parameter Set extension syntax, refer to Page 58 in JVT X201wcm */ | |
| 96 | +//typedef struct TagSpsExt{ | |
| 97 | +// uint32_t iSpsId; | |
| 98 | +// uint32_t uiAuxFormatIdc; | |
| 99 | +// int32_t iAlphaOpaqueValue; | |
| 100 | +// int32_t iAlphaTransparentValue; | |
| 101 | + | |
| 102 | +// uint8_t uiBitDepthAux; | |
| 103 | +// bool_t bAlphaIncrFlag; | |
| 104 | +// bool_t bAdditionalExtFlag; | |
| 105 | +//}SSpsExt, *PSpsExt; | |
| 106 | + | |
| 107 | +/* Sequence Parameter Set extension syntax, refer to Page 391 in JVT X201wcm */ | |
| 108 | +typedef struct TagSpsSvcExt{ | |
| 109 | + SPosOffset sSeqScaledRefLayer; | |
| 110 | + | |
| 111 | + uint8_t uiExtendedSpatialScalability; // ESS | |
| 112 | + uint8_t uiChromaPhaseXPlus1Flag; | |
| 113 | + uint8_t uiChromaPhaseYPlus1; | |
| 114 | + uint8_t uiSeqRefLayerChromaPhaseXPlus1Flag; | |
| 115 | + uint8_t uiSeqRefLayerChromaPhaseYPlus1; | |
| 116 | + bool_t bInterLayerDeblockingFilterCtrlPresentFlag; | |
| 117 | + bool_t bSeqTCoeffLevelPredFlag; | |
| 118 | + bool_t bAdaptiveTCoeffLevelPredFlag; | |
| 119 | + bool_t bSliceHeaderRestrictionFlag; | |
| 120 | +}SSpsSvcExt, *PSpsSvcExt; | |
| 121 | + | |
| 122 | +/* Subset sequence parameter set syntax, refer to Page 391 in JVT X201wcm */ | |
| 123 | +typedef struct TagSubsetSps{ | |
| 124 | + SSps sSps; | |
| 125 | + SSpsSvcExt sSpsSvcExt; | |
| 126 | + bool_t bSvcVuiParamPresentFlag; | |
| 127 | + bool_t bAdditionalExtension2Flag; | |
| 128 | + bool_t bAdditionalExtension2DataFlag; | |
| 129 | +}SSubsetSps, *PSubsetSps; | |
| 130 | + | |
| 131 | +/* Picture parameter set syntax, refer to Page 59 in JVT X201wcm */ | |
| 132 | +typedef struct TagPps{ | |
| 133 | + int32_t iSpsId; | |
| 134 | + int32_t iPpsId; | |
| 135 | + | |
| 136 | + uint32_t uiNumSliceGroups; | |
| 137 | + uint32_t uiSliceGroupMapType; | |
| 138 | + /* slice_group_map_type = 0 */ | |
| 139 | + uint32_t uiRunLength[MAX_SLICEGROUP_IDS]; | |
| 140 | + /* slice_group_map_type = 2 */ | |
| 141 | + uint32_t uiTopLeft[MAX_SLICEGROUP_IDS]; | |
| 142 | + uint32_t uiBottomRight[MAX_SLICEGROUP_IDS]; | |
| 143 | + /* slice_group_map_type = 3, 4 or 5 */ | |
| 144 | + uint32_t uiSliceGroupChangeRate; | |
| 145 | + /* slice_group_map_type = 6 */ | |
| 146 | + uint32_t uiPicSizeInMapUnits; | |
| 147 | + uint32_t uiSliceGroupId[MAX_SLICEGROUP_IDS]; | |
| 148 | + | |
| 149 | + uint32_t uiNumRefIdxL0Active; | |
| 150 | + uint32_t uiNumRefIdxL1Active; | |
| 151 | + | |
| 152 | + int32_t iPicInitQp; | |
| 153 | + int32_t iPicInitQs; | |
| 154 | + int32_t iChromaQpIndexOffset; | |
| 155 | + | |
| 156 | + bool_t bEntropyCodingModeFlag; | |
| 157 | + bool_t bPicOrderPresentFlag; | |
| 158 | + /* slice_group_map_type = 3, 4 or 5 */ | |
| 159 | + bool_t bSliceGroupChangeDirectionFlag; | |
| 160 | + bool_t bDeblockingFilterControlPresentFlag; | |
| 161 | + | |
| 162 | + bool_t bConstainedIntraPredFlag; | |
| 163 | + bool_t bRedundantPicCntPresentFlag; | |
| 164 | + bool_t bWeightedPredFlag; | |
| 165 | + uint8_t uiWeightedBipredIdc; | |
| 166 | + | |
| 167 | +} SPps, *PPps; | |
| 168 | + | |
| 169 | +//#pragma pack() | |
| 170 | + | |
| 171 | +} // namespace WelsDec | |
| 172 | + | |
| 173 | +#endif //WELS_PARAMETER_SETS_H__ | |
| @@ -0,0 +1,213 @@ | ||
| 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 parse_mb_syn_cavlc.h | |
| 33 | + * | |
| 34 | + * \brief Parsing all syntax elements of mb and decoding residual with cavlc | |
| 35 | + * | |
| 36 | + * \date 03/17/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | + | |
| 41 | + | |
| 42 | +#ifndef WELS_PARSE_MB_SYN_CAVLC_H__ | |
| 43 | +#define WELS_PARSE_MB_SYN_CAVLC_H__ | |
| 44 | + | |
| 45 | +#include "wels_common_basis.h" | |
| 46 | +#include "decoder_context.h" | |
| 47 | +#include "dec_frame.h" | |
| 48 | +#include "slice.h" | |
| 49 | + | |
| 50 | +namespace WelsDec { | |
| 51 | + | |
| 52 | +#define I16_LUMA_DC 1 | |
| 53 | +#define I16_LUMA_AC 2 | |
| 54 | +#define LUMA_DC_AC 3 | |
| 55 | +#define CHROMA_DC 4 | |
| 56 | +#define CHROMA_AC 5 | |
| 57 | + | |
| 58 | +typedef struct TagReadBitsCache | |
| 59 | +{ | |
| 60 | + uint32_t uiCache32Bit; | |
| 61 | + uint8_t uiRemainBits; | |
| 62 | + uint8_t *pBuf; | |
| 63 | +}SReadBitsCache; | |
| 64 | + | |
| 65 | +#define SHIFT_BUFFER(pBitsCache) { pBitsCache->pBuf+=2; pBitsCache->uiRemainBits += 16; pBitsCache->uiCache32Bit |= (((pBitsCache->pBuf[2] << 8) | pBitsCache->pBuf[3]) << (32 - pBitsCache->uiRemainBits)); } | |
| 66 | +#define POP_BUFFER(pBitsCache, iCount) { pBitsCache->uiCache32Bit <<= iCount; pBitsCache->uiRemainBits -= iCount; } | |
| 67 | + | |
| 68 | +static const uint8_t g_kuiZigzagScan[16]={//4*4block residual zig-zag scan order | |
| 69 | + 0, 1, 4, 8, | |
| 70 | + 5, 2, 3, 6, | |
| 71 | + 9, 12, 13, 10, | |
| 72 | + 7, 11, 14, 15, | |
| 73 | +}; | |
| 74 | + | |
| 75 | + | |
| 76 | +typedef struct TagI16PredInfo{ | |
| 77 | + int8_t iPredMode; | |
| 78 | + int8_t iLeftAvail; | |
| 79 | + int8_t iTopAvail; | |
| 80 | + int8_t iLeftTopAvail; | |
| 81 | +} SI16PredInfo; | |
| 82 | +static const SI16PredInfo g_ksI16PredInfo[4] = { | |
| 83 | + {I16_PRED_V, 0, 1, 0}, | |
| 84 | + {I16_PRED_H, 1, 0, 0}, | |
| 85 | + { 0, 0, 0, 0}, | |
| 86 | + {I16_PRED_P, 1, 1, 1}, | |
| 87 | +}; | |
| 88 | + | |
| 89 | +static const SI16PredInfo g_ksChromaPredInfo[4] = { | |
| 90 | + { 0, 0, 0, 0}, | |
| 91 | + {C_PRED_H, 1, 0, 0}, | |
| 92 | + {C_PRED_V, 0, 1, 0}, | |
| 93 | + {C_PRED_P, 1, 1, 1}, | |
| 94 | +}; | |
| 95 | + | |
| 96 | + | |
| 97 | +typedef struct TagI4PredInfo { | |
| 98 | + int8_t iPredMode; | |
| 99 | + int8_t iLeftAvail; | |
| 100 | + int8_t iTopAvail; | |
| 101 | + int8_t iLeftTopAvail; | |
| 102 | +// int8_t right_top_avail; //when right_top unavailable but top avail, we can pad the right-top with the rightmost pixel of top | |
| 103 | +} SI4PredInfo; | |
| 104 | +static const SI4PredInfo g_ksI4PredInfo[9] = { | |
| 105 | + { I4_PRED_V, 0, 1, 0}, | |
| 106 | + { I4_PRED_H, 1, 0, 0}, | |
| 107 | + { 0, 0, 0, 0}, | |
| 108 | + {I4_PRED_DDL, 0, 1, 0}, | |
| 109 | + {I4_PRED_DDR, 1, 1, 1}, | |
| 110 | + { I4_PRED_VR, 1, 1, 1}, | |
| 111 | + { I4_PRED_HD, 1, 1, 1}, | |
| 112 | + { I4_PRED_VL, 0, 1, 0}, | |
| 113 | + { I4_PRED_HU, 1, 0, 0}, | |
| 114 | +}; | |
| 115 | + | |
| 116 | +static const uint8_t g_kuiI16CbpTable[6] = {0, 16, 32, 15, 31, 47}; //reference to JM | |
| 117 | + | |
| 118 | + | |
| 119 | +typedef struct TagPartMbInfo{ | |
| 120 | + MbType iType; | |
| 121 | + int8_t iPartCount; //P_16*16, P_16*8, P_8*16, P_8*8 based on 8*8 block; P_8*4, P_4*8, P_4*4 based on 4*4 block | |
| 122 | + int8_t iPartWidth; //based on 4*4 block | |
| 123 | +} SPartMbInfo; | |
| 124 | +static const SPartMbInfo g_ksInterMbTypeInfo[5]={ | |
| 125 | +{MB_TYPE_16x16, 1, 4}, | |
| 126 | +{MB_TYPE_16x8, 2, 4}, | |
| 127 | +{MB_TYPE_8x16, 2, 2}, | |
| 128 | +{MB_TYPE_8x8, 4, 4}, | |
| 129 | +{MB_TYPE_8x8_REF0, 4, 4}, //ref0--ref_idx not present in bit-stream and default as 0 | |
| 130 | +}; | |
| 131 | +static const SPartMbInfo g_ksInterSubMbTypeInfo[4]={ | |
| 132 | +{SUB_MB_TYPE_8x8, 1, 2}, | |
| 133 | +{SUB_MB_TYPE_8x4, 2, 2}, | |
| 134 | +{SUB_MB_TYPE_4x8, 2, 1}, | |
| 135 | +{SUB_MB_TYPE_4x4, 4, 1}, | |
| 136 | +}; | |
| 137 | + | |
| 138 | +void_t GetNeighborAvailMbType (PNeighAvail pNeighAvail, PDqLayer pCurLayer); | |
| 139 | +void_t WelsFillCacheNonZeroCount (PNeighAvail pNeighAvail, uint8_t* pNonZeroCount, PDqLayer pCurLayer); | |
| 140 | +void_t WelsFillCacheConstrain0Intra4x4(PNeighAvail pNeighAvail, uint8_t* pNonZeroCount, int8_t* pIntraPredMode, PDqLayer pCurLayer); | |
| 141 | +void_t WelsFillCacheConstrain1Intra4x4(PNeighAvail pNeighAvail, uint8_t* pNonZeroCount, int8_t* pIntraPredMode, PDqLayer pCurLayer); | |
| 142 | +void_t WelsFillCacheInter (PNeighAvail pNeighAvail, uint8_t* pNonZeroCount, | |
| 143 | + int16_t iMvArray[LIST_A][30][MV_A], int8_t iRefIdxArray[LIST_A][30], PDqLayer pCurLayer); | |
| 144 | + | |
| 145 | +void_t PredPSkipMvFromNeighbor (PDqLayer pCurLayer, int16_t iMvp[2]); | |
| 146 | + | |
| 147 | +/*! | |
| 148 | + * \brief check iPredMode for intra16x16 eligible or not | |
| 149 | + * \param input : current iPredMode | |
| 150 | + * \param output: 0 indicating decoding correctly; -1 means error occurence | |
| 151 | + */ | |
| 152 | + int32_t CheckIntra16x16PredMode(uint8_t uiSampleAvail, int8_t* pMode); | |
| 153 | + | |
| 154 | +/*! | |
| 155 | + * \brief check iPredMode for intra4x4 eligible or not | |
| 156 | + * \param input : current iPredMode | |
| 157 | + * \param output: 0 indicating decoding correctly; -1 means error occurence | |
| 158 | + */ | |
| 159 | + int32_t CheckIntra4x4PredMode(int32_t* pSampleAvail, int8_t* pMode, int32_t iIndex); | |
| 160 | + | |
| 161 | +/*! | |
| 162 | + * \brief check iPredMode for chroma eligible or not | |
| 163 | + * \param input : current iPredMode | |
| 164 | + * \param output: 0 indicating decoding correctly; -1 means error occurence | |
| 165 | + */ | |
| 166 | + int32_t CheckIntraChromaPredMode(uint8_t uiSampleAvail, int8_t* pMode); | |
| 167 | + | |
| 168 | +/*! | |
| 169 | + * \brief predict the mode of intra4x4 | |
| 170 | + * \param input : current intra4x4 block index | |
| 171 | + * \param output: mode index | |
| 172 | + */ | |
| 173 | +int32_t PredIntra4x4Mode(int8_t* pIntraPredMode, int32_t iIdx4); | |
| 174 | + | |
| 175 | + | |
| 176 | +void_t BsStartCavlc( PBitStringAux pBs ); | |
| 177 | +void_t BsEndCavlc( PBitStringAux pBs ); | |
| 178 | + | |
| 179 | +int32_t WelsResidualBlockCavlc( SVlcTable* pVlcTable, | |
| 180 | + uint8_t* pNonZeroCountCache, | |
| 181 | + PBitStringAux pBs, | |
| 182 | + /*int16_t* coeff_level,*/ | |
| 183 | + int32_t iIndex, | |
| 184 | + int32_t iMaxNumCoeff, | |
| 185 | + const uint8_t *kpZigzagTable, | |
| 186 | + int32_t iResidualProperty, | |
| 187 | + /*short *tCoeffLevel,*/ | |
| 188 | + int16_t *pTCoeff, | |
| 189 | + int32_t iMbMode, | |
| 190 | + uint8_t uiQp, | |
| 191 | + PWelsDecoderContext pCtx); | |
| 192 | + | |
| 193 | +/*! | |
| 194 | + * \brief parsing intra mode | |
| 195 | + * \param input : current mb, bit-stream | |
| 196 | + * \param output: 0 indicating decoding correctly; -1 means error | |
| 197 | + */ | |
| 198 | +int32_t ParseIntra4x4ModeConstrain0 (PNeighAvail pNeighAvail, int8_t* pIntraPredMode, PBitStringAux pBs, PDqLayer pCurDqLayer); | |
| 199 | +int32_t ParseIntra4x4ModeConstrain1 (PNeighAvail pNeighAvail, int8_t* pIntraPredMode, PBitStringAux pBs, PDqLayer pCurDqLayer); | |
| 200 | +int32_t ParseIntra16x16ModeConstrain0(PNeighAvail pNeighAvail, PBitStringAux pBs, PDqLayer pCurDqLayer); | |
| 201 | +int32_t ParseIntra16x16ModeConstrain1(PNeighAvail pNeighAvail, PBitStringAux pBs, PDqLayer pCurDqLayer); | |
| 202 | + | |
| 203 | +/*! | |
| 204 | + * \brief parsing inter info (including ref_index and mvd) | |
| 205 | + * \param input : decoding context, current mb, bit-stream | |
| 206 | + * \param output: 0 indicating decoding correctly; -1 means error | |
| 207 | + */ | |
| 208 | +int32_t ParseInterInfo(PWelsDecoderContext pCtx, int16_t iMvArray[LIST_A][30][MV_A], int8_t iRefIdxArray[LIST_A][30], PBitStringAux pBs); | |
| 209 | + | |
| 210 | +//#pragma pack() | |
| 211 | + | |
| 212 | +} // namespace WelsDec | |
| 213 | +#endif//WELS_PARSE_MB_SYN_CAVLC_H__ | |
| @@ -0,0 +1,63 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +//pic_queue.h | |
| 34 | +#ifndef WELS_PICTURE_QUEUE_H__ | |
| 35 | +#define WELS_PICTURE_QUEUE_H__ | |
| 36 | + | |
| 37 | + | |
| 38 | +#include "picture.h" | |
| 39 | + | |
| 40 | +//#pragma pack(1) | |
| 41 | + | |
| 42 | +namespace WelsDec { | |
| 43 | + | |
| 44 | +#define PICTURE_RESOLUTION_ALIGNMENT 32 | |
| 45 | + | |
| 46 | + | |
| 47 | +typedef struct TagPicBuff{ | |
| 48 | + PPicture* ppPic; | |
| 49 | + int32_t iCapacity; // capacity size of queue | |
| 50 | + int32_t iCurrentIdx; | |
| 51 | +}SPicBuff, *PPicBuff; | |
| 52 | + | |
| 53 | +/* | |
| 54 | + * Interfaces | |
| 55 | + */ | |
| 56 | + | |
| 57 | +PPicture PrefetchPic( PPicBuff pPicBuff ); // To get current node applicable | |
| 58 | + | |
| 59 | +} // namespace WelsDec | |
| 60 | + | |
| 61 | +//#pragma pack() | |
| 62 | + | |
| 63 | +#endif//WELS_PICTURE_QUEUE_H__ | |
| @@ -0,0 +1,87 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +//picture.h - reconstruction picture/ reference picture/ residual picture are declared here | |
| 34 | +#ifndef WELS_PICTURE_H__ | |
| 35 | +#define WELS_PICTURE_H__ | |
| 36 | + | |
| 37 | +#include "typedefs.h" | |
| 38 | + | |
| 39 | +//#pragma pack(1) | |
| 40 | + | |
| 41 | +namespace WelsDec { | |
| 42 | + | |
| 43 | +/* | |
| 44 | + * Reconstructed Picture definition | |
| 45 | + * It is used to express reference picture, also consequent reconstruction picture for output | |
| 46 | + */ | |
| 47 | +typedef struct TagPicture{ | |
| 48 | + /************************************payload data*********************************/ | |
| 49 | + uint8_t *pBuffer[4]; // pointer to the first allocated byte, basical offset of buffer, dimension: | |
| 50 | + uint8_t *pData[4]; // pointer to picture planes respectively | |
| 51 | + int32_t iLinesize[4];// linesize of picture planes respectively used currently | |
| 52 | + int32_t iPlanes; // How many planes are introduced due to color space format? | |
| 53 | + // picture information | |
| 54 | + | |
| 55 | + /*******************************from other standard syntax****************************/ | |
| 56 | + /*from sps*/ | |
| 57 | + int32_t iWidthInPixel; // picture width in pixel | |
| 58 | + int32_t iHeightInPixel;// picture height in pixel | |
| 59 | + /*from slice header*/ | |
| 60 | + int32_t iFramePoc; // frame POC | |
| 61 | + | |
| 62 | + /*******************************sef_definition for misc use****************************/ | |
| 63 | + bool_t bUsedAsRef; //for ref pic management | |
| 64 | + bool_t bIsLongRef; // long term reference frame flag //for ref pic management | |
| 65 | + uint8_t uiRefCount; | |
| 66 | + bool_t bAvailableFlag; // indicate whether it is available in this picture memory block. | |
| 67 | + | |
| 68 | + /*******************************for future use****************************/ | |
| 69 | + uint8_t uiTemporalId; | |
| 70 | + uint8_t uiSpatialId; | |
| 71 | + uint8_t uiQualityId; | |
| 72 | + bool_t bRefBaseFlag; | |
| 73 | + | |
| 74 | + int32_t iFrameNum; // frame number //for ref pic management | |
| 75 | + int32_t iLongTermFrameIdx; //id for long term ref pic | |
| 76 | + | |
| 77 | + int32_t iTotalNumMbRec; //show how many MB constructed | |
| 78 | + | |
| 79 | + int32_t iSpsId; //against mosaic caused by cross-IDR interval reference. | |
| 80 | + int32_t iPpsId; | |
| 81 | +}SPicture, *PPicture; // "Picture" declaration is comflict with Mac system | |
| 82 | + | |
| 83 | +} // namespace WelsDec | |
| 84 | + | |
| 85 | +//#pragma pack() | |
| 86 | + | |
| 87 | +#endif//WELS_PICTURE_H__ | |
| @@ -0,0 +1,76 @@ | ||
| 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 rec_mb.h | |
| 33 | + * | |
| 34 | + * \brief interfaces for all macroblock decoding process after mb syntax parsing and residual decoding with cavlc. | |
| 35 | + * | |
| 36 | + * \date 3/4/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | + | |
| 41 | +#ifndef WELS_REC_MB_H__ | |
| 42 | +#define WELS_REC_MB_H__ | |
| 43 | + | |
| 44 | +#include "typedefs.h" | |
| 45 | +#include "wels_common_basis.h" | |
| 46 | +#include "error_code.h" | |
| 47 | + | |
| 48 | +#include "decoder_context.h" | |
| 49 | + | |
| 50 | +//#pragma pack(1) | |
| 51 | + | |
| 52 | +namespace WelsDec { | |
| 53 | + | |
| 54 | +void_t WelsFillRecNeededMbInfo(PWelsDecoderContext pCtx, bool_t bOutput, PDqLayer pCurLayer); | |
| 55 | + | |
| 56 | +int32_t RecI4x4Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer); | |
| 57 | + | |
| 58 | +int32_t RecI4x4Luma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer); | |
| 59 | + | |
| 60 | +int32_t RecI4x4Chroma(int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer); | |
| 61 | + | |
| 62 | +int32_t RecI16x16Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer); | |
| 63 | + | |
| 64 | +int32_t RecChroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer); | |
| 65 | + | |
| 66 | +void_t GetInterPred (uint8_t *pPredY, uint8_t *pPredCb, uint8_t *pPredCr, PWelsDecoderContext pCtx); | |
| 67 | + | |
| 68 | +void_t FillBufForMc(uint8_t *pBuf, int32_t iBufStride, uint8_t *pSrc, int32_t iSrcStride, int32_t iSrcOffset, | |
| 69 | + int32_t iBlockWidth, int32_t iBlockHeight, int32_t iSrcX, int32_t iSrcY, int32_t iPicWidth, int32_t iPicHeight); | |
| 70 | + | |
| 71 | +} // namespace WelsDec | |
| 72 | + | |
| 73 | +//#pragma pack() | |
| 74 | + | |
| 75 | +#endif //WELS_REC_MB_H__ | |
| 76 | + | |
| @@ -0,0 +1,207 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +//wels_slice.h | |
| 34 | +#ifndef WELS_SLICE_H__ | |
| 35 | +#define WELS_SLICE_H__ | |
| 36 | + | |
| 37 | +#include "typedefs.h" | |
| 38 | +#include "wels_const.h" | |
| 39 | +#include "wels_common_basis.h" | |
| 40 | +#include "picture.h" | |
| 41 | +#include "parameter_sets.h" | |
| 42 | + | |
| 43 | +//#pragma pack(1) | |
| 44 | + | |
| 45 | +namespace WelsDec { | |
| 46 | + | |
| 47 | +/* | |
| 48 | + * Reference picture list reordering syntax, refer to page 64 in JVT X201wcm | |
| 49 | + */ | |
| 50 | +typedef struct TagRefPicListReorderSyntax { | |
| 51 | + struct { | |
| 52 | + uint32_t uiAbsDiffPicNumMinus1; | |
| 53 | + uint16_t uiLongTermPicNum; | |
| 54 | + uint16_t uiReorderingOfPicNumsIdc; | |
| 55 | + } sReorderingSyn[LIST_A][MAX_REF_PIC_COUNT]; | |
| 56 | + bool_t bRefPicListReorderingFlag[LIST_A]; | |
| 57 | +}SRefPicListReorderSyn, *PRefPicListReorderSyn; | |
| 58 | + | |
| 59 | +/* | |
| 60 | + * Prediction weight table syntax, refer to page 65 in JVT X201wcm | |
| 61 | + */ | |
| 62 | +typedef struct TagPredWeightTabSyntax{ | |
| 63 | + uint32_t uiLumaLog2WeightDenom; | |
| 64 | + uint32_t uiChromaLog2WeightDenom; | |
| 65 | + struct{ | |
| 66 | + int32_t iLumaWeight[MAX_REF_PIC_COUNT]; | |
| 67 | + int32_t iLumaOffset[MAX_REF_PIC_COUNT]; | |
| 68 | + int32_t iChromaWeight[MAX_REF_PIC_COUNT][2]; | |
| 69 | + int32_t iChromaOffset[MAX_REF_PIC_COUNT][2]; | |
| 70 | + bool_t bLumaWeightFlag; | |
| 71 | + bool_t bChromaWeightFlag; | |
| 72 | + }sPredList[LIST_A]; | |
| 73 | +}SPredWeightTabSyn; | |
| 74 | + | |
| 75 | +/* Decoded reference picture marking syntax, refer to Page 66 in JVT X201wcm */ | |
| 76 | +typedef struct TagRefPicMarking { | |
| 77 | + struct { | |
| 78 | + uint32_t uiMmcoType; | |
| 79 | + int32_t iShortFrameNum; | |
| 80 | + int32_t iDiffOfPicNum; | |
| 81 | + uint32_t uiLongTermPicNum; | |
| 82 | + int32_t iLongTermFrameIdx; | |
| 83 | + int32_t iMaxLongTermFrameIdx; | |
| 84 | + } sMmcoRef[MAX_MMCO_COUNT]; | |
| 85 | + | |
| 86 | + bool_t bNoOutputOfPriorPicsFlag; | |
| 87 | + bool_t bLongTermRefFlag; | |
| 88 | + bool_t bAdaptiveRefPicMarkingModeFlag; | |
| 89 | +} SRefPicMarking, *PRefPicMarking; | |
| 90 | + | |
| 91 | +/* Decode reference base picture marking syntax in Page 396 of JVT X201wcm */ | |
| 92 | +typedef struct TagRefBasePicMarkingSyn { | |
| 93 | + struct { | |
| 94 | + uint32_t uiMmcoType; | |
| 95 | + int32_t iShortFrameNum; | |
| 96 | + uint32_t uiDiffOfPicNums; | |
| 97 | + uint32_t uiLongTermPicNum; //should uint32_t, cover larger range of iFrameNum. | |
| 98 | + } mmco_base[MAX_MMCO_COUNT]; // MAX_REF_PIC for reference picture based on frame | |
| 99 | + | |
| 100 | + bool_t bAdaptiveRefBasePicMarkingModeFlag; | |
| 101 | +} SRefBasePicMarking, *PRefBasePicMarking; | |
| 102 | + | |
| 103 | +/* Header of slice syntax elements, refer to Page 63 in JVT X201wcm */ | |
| 104 | +typedef struct TagSliceHeaders{ | |
| 105 | + /*****************************slice header syntax and generated****************************/ | |
| 106 | + int32_t iFirstMbInSlice; | |
| 107 | + int32_t iFrameNum; | |
| 108 | + int32_t iPicOrderCntLsb; | |
| 109 | + int32_t iDeltaPicOrderCntBottom; | |
| 110 | + int32_t iDeltaPicOrderCnt[2]; | |
| 111 | + int32_t iRedundantPicCnt; | |
| 112 | + int32_t uiRefCount[LIST_A]; | |
| 113 | + int32_t iSliceQpDelta; //no use for iSliceQp is used directly | |
| 114 | + int32_t iSliceQp; | |
| 115 | + int32_t iSliceQsDelta; // For SP/SI slices | |
| 116 | + uint32_t uiDisableDeblockingFilterIdc; | |
| 117 | + int32_t iSliceAlphaC0Offset; | |
| 118 | + int32_t iSliceBetaOffset; | |
| 119 | + int32_t iSliceGroupChangeCycle; | |
| 120 | + | |
| 121 | + PSps pSps; | |
| 122 | + PPps pPps; | |
| 123 | + int32_t iSpsId; | |
| 124 | + int32_t iPpsId; | |
| 125 | + | |
| 126 | + /*********************got from other layer for efficency if possible*********************/ | |
| 127 | + SRefPicListReorderSyn pRefPicListReordering; // Reference picture list reordering syntaxs | |
| 128 | + SPredWeightTabSyn sPredWeightTable; | |
| 129 | + int32_t iCabacInitIdc; | |
| 130 | + int32_t iMbWidth; //from? | |
| 131 | + int32_t iMbHeight; //from? | |
| 132 | + SRefPicMarking sRefMarking; // Decoded reference picture marking syntaxs | |
| 133 | + | |
| 134 | + uint16_t uiIdrPicId; | |
| 135 | + ESliceType eSliceType; | |
| 136 | + bool_t bNumRefIdxActiveOverrideFlag; | |
| 137 | + bool_t bFieldPicFlag; //not supported in base profile | |
| 138 | + bool_t bBottomFiledFlag; //not supported in base profile | |
| 139 | + uint8_t uiPadding1Byte; | |
| 140 | + bool_t bSpForSwitchFlag; // For SP/SI slices | |
| 141 | + int16_t iPadding2Bytes; | |
| 142 | +}SSliceHeader, *PSliceHeader; | |
| 143 | + | |
| 144 | + | |
| 145 | +/* Slice header in scalable extension syntax, refer to Page 394 in JVT X201wcm */ | |
| 146 | +typedef struct TagSliceHeaderExt{ | |
| 147 | + SSliceHeader sSliceHeader; | |
| 148 | + PSubsetSps pSubsetSps; | |
| 149 | + | |
| 150 | + uint32_t uiNumMbsInSlice; | |
| 151 | + uint32_t uiDisableInterLayerDeblockingFilterIdc; | |
| 152 | + int32_t iInterLayerSliceAlphaC0Offset; | |
| 153 | + int32_t iInterLayerSliceBetaOffset; | |
| 154 | + | |
| 155 | + //SPosOffset sScaledRefLayer; | |
| 156 | + int32_t iScaledRefLayerPicWidthInSampleLuma; | |
| 157 | + int32_t iScaledRefLayerPicHeightInSampleLuma; | |
| 158 | + | |
| 159 | + SRefBasePicMarking sRefBasePicMarking; | |
| 160 | + bool_t bBasePredWeightTableFlag; | |
| 161 | + bool_t bStoreRefBasePicFlag; | |
| 162 | + bool_t bConstrainedIntraResamplingFlag; | |
| 163 | + bool_t bSliceSkipFlag; | |
| 164 | + | |
| 165 | + bool_t bAdaptiveBaseModeFlag; | |
| 166 | + bool_t bDefaultBaseModeFlag; | |
| 167 | + bool_t bAdaptiveMotionPredFlag; | |
| 168 | + bool_t bDefaultMotionPredFlag; | |
| 169 | + bool_t bAdaptiveResidualPredFlag; | |
| 170 | + bool_t bDefaultResidualPredFlag; | |
| 171 | + bool_t bTCoeffLevelPredFlag; | |
| 172 | + uint8_t uiRefLayerChromaPhaseXPlus1Flag; | |
| 173 | + | |
| 174 | + uint8_t uiRefLayerChromaPhaseYPlus1; | |
| 175 | + uint8_t uiRefLayerDqId; | |
| 176 | + uint8_t uiScanIdxStart; | |
| 177 | + uint8_t uiScanIdxEnd; | |
| 178 | +}SSliceHeaderExt, *PSliceHeaderExt; | |
| 179 | + | |
| 180 | + | |
| 181 | +typedef struct TagSlice{ | |
| 182 | + /*******************************slice_header****************************/ | |
| 183 | + SSliceHeaderExt sSliceHeaderExt; | |
| 184 | + | |
| 185 | + /*******************************use for future****************************/ | |
| 186 | + // for Macroblock coding within slice | |
| 187 | + int32_t iLastMbQp; // stored qp for last mb coded, maybe more efficient for mb skip detection etc. | |
| 188 | + | |
| 189 | + /*******************************slice_data****************************/ | |
| 190 | + /*slice_data_ext()*/ | |
| 191 | + int32_t iMbSkipRun; | |
| 192 | + int32_t iTotalMbInCurSlice; //record the total number of MB in current slice. | |
| 193 | + | |
| 194 | + /*slice_data_ext() generate*/ | |
| 195 | + | |
| 196 | + /*******************************misc use****************************/ | |
| 197 | + bool_t bSliceHeaderExtFlag; // Indicate which slice header is used, avc or ext? | |
| 198 | + /*************got from other layer for effiency if possible***************/ | |
| 199 | + /*from lower layer: slice header*/ | |
| 200 | + uint8_t eSliceType; | |
| 201 | + uint8_t uiPadding[2]; | |
| 202 | +}SSlice, *PSlice; | |
| 203 | + | |
| 204 | +} // namespace WelsDec | |
| 205 | + | |
| 206 | +//#pragma pack() | |
| 207 | +#endif//WELS_SLICE_H__ | |
| @@ -0,0 +1,91 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +// typedef.h | |
| 34 | +#ifndef WELS_TYPE_DEFINES_H__ | |
| 35 | +#define WELS_TYPE_DEFINES_H__ | |
| 36 | + | |
| 37 | +#include <limits.h> | |
| 38 | + | |
| 39 | +//////////////////////////////////////////////////////////////////////////// | |
| 40 | +// NOTICE : ALL internal implement MUST use the data type defined as below | |
| 41 | +// ONLY except with the interface file !!!!! | |
| 42 | +//////////////////////////////////////////////////////////////////////////// | |
| 43 | + | |
| 44 | +#ifndef _MSC_VER | |
| 45 | + | |
| 46 | +#include <stdint.h> | |
| 47 | + | |
| 48 | +#else | |
| 49 | + | |
| 50 | +// FIXME: all singed type should be declared explicit, for example, int8_t should be declared as signed char. | |
| 51 | +typedef signed char int8_t ; | |
| 52 | +typedef unsigned char uint8_t ; | |
| 53 | +typedef short int16_t ; | |
| 54 | +typedef unsigned short uint16_t; | |
| 55 | +typedef int int32_t ; | |
| 56 | +typedef unsigned int uint32_t; | |
| 57 | +typedef __int64 int64_t ; | |
| 58 | +typedef unsigned __int64 uint64_t; | |
| 59 | + | |
| 60 | +#endif // _MSC_VER defined | |
| 61 | + | |
| 62 | +// FIXME: all string type should be declared explicit as char. | |
| 63 | +typedef char str_t; | |
| 64 | +typedef float real32_t; | |
| 65 | + | |
| 66 | +#ifdef PESN | |
| 67 | +#undef PESN | |
| 68 | +#endif//PESN | |
| 69 | +#define PESN (0.000001f) // (1e-6) // desired float precision | |
| 70 | + | |
| 71 | +#ifndef NULL | |
| 72 | +#define NULL 0 | |
| 73 | +#endif | |
| 74 | + | |
| 75 | +typedef bool bool_t; | |
| 76 | +typedef int32_t BOOL_T; | |
| 77 | + | |
| 78 | +#ifndef FALSE | |
| 79 | +#define FALSE ((int32_t)0) | |
| 80 | +#endif//FALSE | |
| 81 | + | |
| 82 | +#ifndef TRUE | |
| 83 | +#define TRUE ((int32_t)1) | |
| 84 | +#endif//TRUE | |
| 85 | + | |
| 86 | +#ifndef void_t | |
| 87 | +#define void_t void | |
| 88 | +#endif | |
| 89 | + | |
| 90 | +#endif //WELS_TYPE_DEFINES_H__ | |
| 91 | + | |
| @@ -0,0 +1,99 @@ | ||
| 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 utils.h | |
| 33 | + * | |
| 34 | + * \brief Tool kits for decoder | |
| 35 | + * ( malloc, realloc, free, log output and PSNR calculation and so on ) | |
| 36 | + * | |
| 37 | + * \date 03/10/2009 Created | |
| 38 | + * | |
| 39 | + ************************************************************************************* | |
| 40 | + */ | |
| 41 | +#ifndef WELS_UTILS_H__ | |
| 42 | +#define WELS_UTILS_H__ | |
| 43 | + | |
| 44 | +#include <stdio.h> | |
| 45 | +#include <stdlib.h> | |
| 46 | +#include <stdarg.h> | |
| 47 | +#include "typedefs.h" | |
| 48 | + | |
| 49 | +namespace WelsDec { | |
| 50 | + | |
| 51 | +#ifdef __cplusplus | |
| 52 | +extern "C" { | |
| 53 | +#endif//__cplusplus | |
| 54 | + | |
| 55 | +// cache line size | |
| 56 | +extern uint32_t g_uiCacheLineSize; | |
| 57 | + | |
| 58 | +/* | |
| 59 | + * Function pointer declaration for various tool sets | |
| 60 | + */ | |
| 61 | +// wels log output | |
| 62 | +typedef void_t (*PWelsLogCallbackFunc)(void_t *pPtr, const int32_t kiLevel, const char *kpFmt, va_list pArgv); | |
| 63 | + | |
| 64 | +extern PWelsLogCallbackFunc g_pLog; | |
| 65 | + | |
| 66 | +#ifdef __GNUC__ | |
| 67 | +extern void_t WelsLog(void_t *pPtr, int32_t iLevel, const char *kpFmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); | |
| 68 | +#else | |
| 69 | +extern void_t WelsLog(void_t *pPtr, int32_t iLevel, const char *kpFmt, ...); | |
| 70 | +#endif | |
| 71 | + | |
| 72 | +#define DECODER_MODE_NAME(a) ((a == SW_MODE)?"SW_MODE":((a == GPU_MODE)?"GPU_MODE":((a == AUTO_MODE)?"AUTO_MODE":"SWITCH_MODE"))) | |
| 73 | +#define OUTPUT_PROPERTY_NAME(a) ((a == 0)?"system_memory":"video_memory") | |
| 74 | +#define BUFFER_STATUS_NAME(a) ((a == 0)?"unvalid":"valid") | |
| 75 | + | |
| 76 | + | |
| 77 | +/* | |
| 78 | + * Log output routines | |
| 79 | + */ | |
| 80 | + | |
| 81 | +typedef int32_t WelsLogLevel; | |
| 82 | +enum{ | |
| 83 | + WELS_LOG_QUIET = 0x00, // Quiet mode | |
| 84 | + WELS_LOG_ERROR = 1 << 0, // Error log level | |
| 85 | + WELS_LOG_WARNING = 1 << 1, // Warning log level | |
| 86 | + WELS_LOG_INFO = 1 << 2, // Information log level | |
| 87 | + WELS_LOG_DEBUG = 1 << 3, // Debug log level | |
| 88 | + WELS_LOG_RESV = 1 << 4, // Resversed log level | |
| 89 | + WELS_LOG_LEVEL_COUNT= 5, | |
| 90 | + WELS_LOG_DEFAULT = WELS_LOG_ERROR | WELS_LOG_WARNING | WELS_LOG_INFO | WELS_LOG_DEBUG // Default log level in Wels codec | |
| 91 | +}; | |
| 92 | + | |
| 93 | +#ifdef __cplusplus | |
| 94 | +} | |
| 95 | +#endif//__cplusplus | |
| 96 | + | |
| 97 | +} // namespace WelsDec | |
| 98 | + | |
| 99 | +#endif//WELS_UTILS_H__ | |
| @@ -0,0 +1,176 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +#ifndef WELS_VLC_DECODER_H__ | |
| 34 | +#define WELS_VLC_DECODER_H__ | |
| 35 | + | |
| 36 | +#include "bit_stream.h" | |
| 37 | +#include "dec_golomb.h" | |
| 38 | + | |
| 39 | +namespace WelsDec { | |
| 40 | + | |
| 41 | +typedef struct TagVlcTable | |
| 42 | +{ | |
| 43 | + const uint8_t (*kpCoeffTokenVlcTable[4][8])[2]; | |
| 44 | + const uint8_t (*kpChromaCoeffTokenVlcTable)[2]; | |
| 45 | + const uint8_t (*kpZeroTable[7])[2]; | |
| 46 | + const uint8_t (*kpTotalZerosTable[2][15])[2]; | |
| 47 | +}SVlcTable; | |
| 48 | + | |
| 49 | +// for data sharing cross modules and try to reduce size of binary generated | |
| 50 | +extern const uint8_t g_kuiVlcChromaTable[256][2]; | |
| 51 | +extern const uint8_t g_kuiVlcTable_0[256][2]; | |
| 52 | +extern const uint8_t g_kuiVlcTable_0_0[256][2]; | |
| 53 | +extern const uint8_t g_kuiVlcTable_0_1[4][2]; | |
| 54 | +extern const uint8_t g_kuiVlcTable_0_2[2][2]; | |
| 55 | +extern const uint8_t g_kuiVlcTable_0_3[2][2]; | |
| 56 | +extern const uint8_t g_kuiVlcTable_1[256][2]; | |
| 57 | +extern const uint8_t g_kuiVlcTable_1_0[64][2]; | |
| 58 | +extern const uint8_t g_kuiVlcTable_1_1[8][2]; | |
| 59 | +extern const uint8_t g_kuiVlcTable_1_2[2][2]; | |
| 60 | +extern const uint8_t g_kuiVlcTable_1_3[2][2]; | |
| 61 | +extern const uint8_t g_kuiVlcTable_2[256][2]; | |
| 62 | +extern const uint8_t g_kuiVlcTable_2_0[4][2]; | |
| 63 | +extern const uint8_t g_kuiVlcTable_2_1[4][2]; | |
| 64 | +extern const uint8_t g_kuiVlcTable_2_2[4][2]; | |
| 65 | +extern const uint8_t g_kuiVlcTable_2_3[4][2]; | |
| 66 | +extern const uint8_t g_kuiVlcTable_2_4[2][2]; | |
| 67 | +extern const uint8_t g_kuiVlcTable_2_5[2][2]; | |
| 68 | +extern const uint8_t g_kuiVlcTable_2_6[2][2]; | |
| 69 | +extern const uint8_t g_kuiVlcTable_2_7[2][2]; | |
| 70 | +extern const uint8_t g_kuiVlcTable_3[64][2]; | |
| 71 | +extern const uint8_t g_kuiVlcTableNeedMoreBitsThread[3]; | |
| 72 | +extern const uint8_t g_kuiVlcTableMoreBitsCount0[4]; | |
| 73 | +extern const uint8_t g_kuiVlcTableMoreBitsCount1[4]; | |
| 74 | +extern const uint8_t g_kuiVlcTableMoreBitsCount2[8]; | |
| 75 | +extern const uint8_t g_kuiNcMapTable[17]; | |
| 76 | +extern const uint8_t g_kuiVlcTrailingOneTotalCoeffTable[62][2]; | |
| 77 | +extern const uint8_t g_kuiTotalZerosTable0[512][2]; | |
| 78 | +extern const uint8_t g_kuiTotalZerosTable1[64][2]; | |
| 79 | +extern const uint8_t g_kuiTotalZerosTable2[64][2]; | |
| 80 | +extern const uint8_t g_kuiTotalZerosTable3[32][2]; | |
| 81 | +extern const uint8_t g_kuiTotalZerosTable4[32][2]; | |
| 82 | +extern const uint8_t g_kuiTotalZerosTable5[64][2]; | |
| 83 | +extern const uint8_t g_kuiTotalZerosTable6[64][2]; | |
| 84 | +extern const uint8_t g_kuiTotalZerosTable7[64][2]; | |
| 85 | +extern const uint8_t g_kuiTotalZerosTable8[64][2]; | |
| 86 | +extern const uint8_t g_kuiTotalZerosTable9[32][2]; | |
| 87 | +extern const uint8_t g_kuiTotalZerosTable10[16][2]; | |
| 88 | +extern const uint8_t g_kuiTotalZerosTable11[16][2]; | |
| 89 | +extern const uint8_t g_kuiTotalZerosTable12[8][2]; | |
| 90 | +extern const uint8_t g_kuiTotalZerosTable13[4][2]; | |
| 91 | +extern const uint8_t g_kuiTotalZerosTable14[2][2]; | |
| 92 | +extern const uint8_t g_kuiTotalZerosBitNumMap[15]; | |
| 93 | +extern const uint8_t g_kuiTotalZerosChromaTable0[8][2]; | |
| 94 | +extern const uint8_t g_kuiTotalZerosChromaTable1[4][2]; | |
| 95 | +extern const uint8_t g_kuiTotalZerosChromaTable2[2][2]; | |
| 96 | +extern const uint8_t g_kuiTotalZerosBitNumChromaMap[3]; | |
| 97 | +extern const uint8_t g_kuiZeroLeftTable0[2][2]; | |
| 98 | +extern const uint8_t g_kuiZeroLeftTable1[4][2]; | |
| 99 | +extern const uint8_t g_kuiZeroLeftTable2[4][2]; | |
| 100 | +extern const uint8_t g_kuiZeroLeftTable3[8][2]; | |
| 101 | +extern const uint8_t g_kuiZeroLeftTable4[8][2]; | |
| 102 | +extern const uint8_t g_kuiZeroLeftTable5[8][2]; | |
| 103 | +extern const uint8_t g_kuiZeroLeftTable6[8][2]; | |
| 104 | +extern const uint8_t g_kuiZeroLeftBitNumMap[16]; | |
| 105 | + | |
| 106 | +#ifdef WIN32 | |
| 107 | +//TODO need linux version | |
| 108 | +#define WELS_GET_PREFIX_BITS(inval,outval){\ | |
| 109 | + __asm xor eax, eax\ | |
| 110 | + __asm bsr eax, inval\ | |
| 111 | + __asm sub eax, 32\ | |
| 112 | + __asm neg eax\ | |
| 113 | + __asm mov outval, eax\ | |
| 114 | +} | |
| 115 | +#endif | |
| 116 | + | |
| 117 | +static inline void_t InitVlcTable(SVlcTable * pVlcTable) | |
| 118 | +{ | |
| 119 | + pVlcTable->kpChromaCoeffTokenVlcTable = g_kuiVlcChromaTable; | |
| 120 | + | |
| 121 | + pVlcTable->kpCoeffTokenVlcTable[0][0] = g_kuiVlcTable_0; | |
| 122 | + pVlcTable->kpCoeffTokenVlcTable[0][1] = g_kuiVlcTable_1; | |
| 123 | + pVlcTable->kpCoeffTokenVlcTable[0][2] = g_kuiVlcTable_2; | |
| 124 | + pVlcTable->kpCoeffTokenVlcTable[0][3] = g_kuiVlcTable_3; | |
| 125 | + | |
| 126 | + pVlcTable->kpCoeffTokenVlcTable[1][0] = g_kuiVlcTable_0_0; | |
| 127 | + pVlcTable->kpCoeffTokenVlcTable[1][1] = g_kuiVlcTable_0_1; | |
| 128 | + pVlcTable->kpCoeffTokenVlcTable[1][2] = g_kuiVlcTable_0_2; | |
| 129 | + pVlcTable->kpCoeffTokenVlcTable[1][3] = g_kuiVlcTable_0_3; | |
| 130 | + | |
| 131 | + pVlcTable->kpCoeffTokenVlcTable[2][0] = g_kuiVlcTable_1_0; | |
| 132 | + pVlcTable->kpCoeffTokenVlcTable[2][1] = g_kuiVlcTable_1_1; | |
| 133 | + pVlcTable->kpCoeffTokenVlcTable[2][2] = g_kuiVlcTable_1_2; | |
| 134 | + pVlcTable->kpCoeffTokenVlcTable[2][3] = g_kuiVlcTable_1_3; | |
| 135 | + | |
| 136 | + pVlcTable->kpCoeffTokenVlcTable[3][0] = g_kuiVlcTable_2_0; | |
| 137 | + pVlcTable->kpCoeffTokenVlcTable[3][1] = g_kuiVlcTable_2_1; | |
| 138 | + pVlcTable->kpCoeffTokenVlcTable[3][2] = g_kuiVlcTable_2_2; | |
| 139 | + pVlcTable->kpCoeffTokenVlcTable[3][3] = g_kuiVlcTable_2_3; | |
| 140 | + pVlcTable->kpCoeffTokenVlcTable[3][4] = g_kuiVlcTable_2_4; | |
| 141 | + pVlcTable->kpCoeffTokenVlcTable[3][5] = g_kuiVlcTable_2_5; | |
| 142 | + pVlcTable->kpCoeffTokenVlcTable[3][6] = g_kuiVlcTable_2_6; | |
| 143 | + pVlcTable->kpCoeffTokenVlcTable[3][7] = g_kuiVlcTable_2_7; | |
| 144 | + | |
| 145 | + pVlcTable->kpZeroTable[0] = g_kuiZeroLeftTable0; | |
| 146 | + pVlcTable->kpZeroTable[1] = g_kuiZeroLeftTable1; | |
| 147 | + pVlcTable->kpZeroTable[2] = g_kuiZeroLeftTable2; | |
| 148 | + pVlcTable->kpZeroTable[3] = g_kuiZeroLeftTable3; | |
| 149 | + pVlcTable->kpZeroTable[4] = g_kuiZeroLeftTable4; | |
| 150 | + pVlcTable->kpZeroTable[5] = g_kuiZeroLeftTable5; | |
| 151 | + pVlcTable->kpZeroTable[6] = g_kuiZeroLeftTable6; | |
| 152 | + | |
| 153 | + pVlcTable->kpTotalZerosTable[0][0] = g_kuiTotalZerosTable0; | |
| 154 | + pVlcTable->kpTotalZerosTable[0][1] = g_kuiTotalZerosTable1; | |
| 155 | + pVlcTable->kpTotalZerosTable[0][2] = g_kuiTotalZerosTable2; | |
| 156 | + pVlcTable->kpTotalZerosTable[0][3] = g_kuiTotalZerosTable3; | |
| 157 | + pVlcTable->kpTotalZerosTable[0][4] = g_kuiTotalZerosTable4; | |
| 158 | + pVlcTable->kpTotalZerosTable[0][5] = g_kuiTotalZerosTable5; | |
| 159 | + pVlcTable->kpTotalZerosTable[0][6] = g_kuiTotalZerosTable6; | |
| 160 | + pVlcTable->kpTotalZerosTable[0][7] = g_kuiTotalZerosTable7; | |
| 161 | + pVlcTable->kpTotalZerosTable[0][8] = g_kuiTotalZerosTable8; | |
| 162 | + pVlcTable->kpTotalZerosTable[0][9] = g_kuiTotalZerosTable9; | |
| 163 | + pVlcTable->kpTotalZerosTable[0][10] = g_kuiTotalZerosTable10; | |
| 164 | + pVlcTable->kpTotalZerosTable[0][11] = g_kuiTotalZerosTable11; | |
| 165 | + pVlcTable->kpTotalZerosTable[0][12] = g_kuiTotalZerosTable12; | |
| 166 | + pVlcTable->kpTotalZerosTable[0][13] = g_kuiTotalZerosTable13; | |
| 167 | + pVlcTable->kpTotalZerosTable[0][14] = g_kuiTotalZerosTable14; | |
| 168 | + pVlcTable->kpTotalZerosTable[1][0] = g_kuiTotalZerosChromaTable0; | |
| 169 | + pVlcTable->kpTotalZerosTable[1][1] = g_kuiTotalZerosChromaTable1; | |
| 170 | + pVlcTable->kpTotalZerosTable[1][2] = g_kuiTotalZerosChromaTable2; | |
| 171 | + | |
| 172 | +} | |
| 173 | + | |
| 174 | +} // namespace WelsDec | |
| 175 | + | |
| 176 | +#endif//WELS_VLC_DECODER_H__ | |
| @@ -0,0 +1,298 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +//wels_common_basis.h | |
| 34 | +#ifndef WELS_COMMON_BASIS_H__ | |
| 35 | +#define WELS_COMMON_BASIS_H__ | |
| 36 | + | |
| 37 | +#include "typedefs.h" | |
| 38 | +#include "macros.h" | |
| 39 | + | |
| 40 | +namespace WelsDec { | |
| 41 | + | |
| 42 | +// for data sharing cross modules and try to reduce size of binary generated | |
| 43 | + | |
| 44 | +extern const uint8_t g_kuiChromaQp[52]; | |
| 45 | + | |
| 46 | +/*common use table*/ | |
| 47 | +extern const uint8_t g_kuiScan8[24]; | |
| 48 | +extern const uint8_t g_kuiLumaDcZigzagScan[16]; | |
| 49 | +extern const uint8_t g_kuiChromaDcScan[4]; | |
| 50 | +extern __align16( const uint16_t, g_kuiDequantCoeff[52][8]); | |
| 51 | +/* Profile IDC */ | |
| 52 | +typedef uint8_t ProfileIdc; | |
| 53 | +enum{ | |
| 54 | + PRO_BASELINE = 66, | |
| 55 | + PRO_MAIN = 77, | |
| 56 | + PRO_EXTENDED = 88, | |
| 57 | + PRO_HIGH = 100, | |
| 58 | + PRO_HIGH10 = 110, | |
| 59 | + PRO_HIGH422 = 122, | |
| 60 | + PRO_HIGH444 = 144, | |
| 61 | + PRO_CAVLC444 = 244, | |
| 62 | + | |
| 63 | + PRO_SCALABLE_BASELINE = 83, | |
| 64 | + PRO_SCALABLE_HIGH = 86, | |
| 65 | +}; | |
| 66 | + | |
| 67 | +/* | |
| 68 | + * NAL Unit Type (5 Bits) | |
| 69 | + */ | |
| 70 | +typedef enum TagNalUnitType | |
| 71 | +{ | |
| 72 | + NAL_UNIT_UNSPEC_0 = 0, | |
| 73 | + NAL_UNIT_CODED_SLICE = 1, | |
| 74 | + NAL_UNIT_CODED_SLICE_DPA = 2, | |
| 75 | + NAL_UNIT_CODED_SLICE_DPB = 3, | |
| 76 | + NAL_UNIT_CODED_SLICE_DPC = 4, | |
| 77 | + NAL_UNIT_CODED_SLICE_IDR = 5, | |
| 78 | + NAL_UNIT_SEI = 6, | |
| 79 | + NAL_UNIT_SPS = 7, | |
| 80 | + NAL_UNIT_PPS = 8, | |
| 81 | + NAL_UNIT_AU_DELIMITER = 9, | |
| 82 | + NAL_UNIT_END_OF_SEQ = 10, | |
| 83 | + NAL_UNIT_END_OF_STR = 11, | |
| 84 | + NAL_UNIT_FILLER_DATA = 12, | |
| 85 | + NAL_UNIT_SPS_EXT = 13, | |
| 86 | + NAL_UNIT_PREFIX = 14, | |
| 87 | + NAL_UNIT_SUBSET_SPS = 15, | |
| 88 | + NAL_UNIT_RESV_16 = 16, | |
| 89 | + NAL_UNIT_RESV_17 = 17, | |
| 90 | + NAL_UNIT_RESV_18 = 18, | |
| 91 | + NAL_UNIT_AUX_CODED_SLICE = 19, | |
| 92 | + NAL_UNIT_CODED_SLICE_EXT = 20, | |
| 93 | + NAL_UNIT_RESV_21 = 21, | |
| 94 | + NAL_UNIT_RESV_22 = 22, | |
| 95 | + NAL_UNIT_RESV_23 = 23, | |
| 96 | + NAL_UNIT_UNSPEC_24 = 24, | |
| 97 | + NAL_UNIT_UNSPEC_25 = 25, | |
| 98 | + NAL_UNIT_UNSPEC_26 = 26, | |
| 99 | + NAL_UNIT_UNSPEC_27 = 27, | |
| 100 | + NAL_UNIT_UNSPEC_28 = 28, | |
| 101 | + NAL_UNIT_UNSPEC_29 = 29, | |
| 102 | + NAL_UNIT_UNSPEC_30 = 30, | |
| 103 | + NAL_UNIT_UNSPEC_31 = 31 | |
| 104 | +}ENalUnitType; | |
| 105 | + | |
| 106 | +static const uint8_t g_kuiEmulationPreventionThreeByte = 0x03; | |
| 107 | + | |
| 108 | +/* | |
| 109 | + * NAL Reference IDC (2 Bits) | |
| 110 | + */ | |
| 111 | +typedef uint8_t NalRefIdc; | |
| 112 | +enum{ | |
| 113 | + NRI_PRI_LOWEST = 0, | |
| 114 | + NRI_PRI_LOW = 1, | |
| 115 | + NRI_PRI_HIGH = 2, | |
| 116 | + NRI_PRI_HIGHEST = 3 | |
| 117 | +}; | |
| 118 | + | |
| 119 | +/* | |
| 120 | + * VCL TYPE | |
| 121 | + */ | |
| 122 | +typedef uint8_t VclType; | |
| 123 | +enum{ | |
| 124 | + NON_VCL = 0, | |
| 125 | + VCL = 1, | |
| 126 | + NOT_APP = 2 | |
| 127 | +}; | |
| 128 | + | |
| 129 | +/* | |
| 130 | + * vcl type map for given NAL unit type and corresponding H264 type | |
| 131 | + */ | |
| 132 | +extern const VclType g_kuiVclTypeMap[32][2]; | |
| 133 | + | |
| 134 | +#define IS_VCL_NAL(t, ext_idx) (g_kuiVclTypeMap[t][ext_idx] == VCL) | |
| 135 | +#define IS_PARAM_SETS_NALS(t) ( (t) == NAL_UNIT_SPS || (t) == NAL_UNIT_PPS || (t) == NAL_UNIT_SUBSET_SPS ) | |
| 136 | +#define IS_SPS_NAL(t) ( (t) == NAL_UNIT_SPS ) | |
| 137 | +#define IS_SUBSET_SPS_NAL(t) ( (t) == NAL_UNIT_SUBSET_SPS ) | |
| 138 | +#define IS_PPS_NAL(t) ( (t) == NAL_UNIT_PPS ) | |
| 139 | +#define IS_SEI_NAL(t) ( (t) == NAL_UNIT_SEI ) | |
| 140 | +#define IS_PREFIX_NAL(t) ( (t) == NAL_UNIT_PREFIX ) | |
| 141 | +#define IS_SUBSET_SPS_USED(t) ( (t) == NAL_UNIT_SUBSET_SPS || (t) == NAL_UNIT_CODED_SLICE_EXT ) | |
| 142 | +#define IS_VCL_NAL_AVC_BASE(t) ( (t) == NAL_UNIT_CODED_SLICE || (t) == NAL_UNIT_CODED_SLICE_IDR ) | |
| 143 | +#define IS_NEW_INTRODUCED_NAL(t) ( (t) == NAL_UNIT_PREFIX || (t) == NAL_UNIT_CODED_SLICE_EXT ) | |
| 144 | + | |
| 145 | +/* Base Slice Types | |
| 146 | + * Invalid in case of eSliceType exceeds 9, | |
| 147 | + * Need trim when eSliceType > 4 as fixed SliceType(eSliceType-4), | |
| 148 | + * meaning mapped version after eSliceType minus 4. | |
| 149 | + */ | |
| 150 | +typedef enum TagSliceType{ | |
| 151 | + P_SLICE = 0, | |
| 152 | + B_SLICE = 1, | |
| 153 | + I_SLICE = 2, | |
| 154 | + SP_SLICE= 3, | |
| 155 | + SI_SLICE= 4, | |
| 156 | + UNKNOWN_SLICE= 5 | |
| 157 | +}ESliceType; | |
| 158 | + | |
| 159 | +/* Slice Types in scalable extension */ | |
| 160 | +typedef uint8_t SliceTypeExt; | |
| 161 | +enum{ | |
| 162 | + EP_SLICE = 0, // EP_SLICE: 0, 5 | |
| 163 | + EB_SLICE = 1, // EB_SLICE: 1, 6 | |
| 164 | + EI_SLICE = 2 // EI_SLICE: 2, 7 | |
| 165 | +}; | |
| 166 | + | |
| 167 | +/* List Index */ | |
| 168 | +typedef uint8_t ListIndex; | |
| 169 | +enum{ | |
| 170 | + LIST_0 = 0, | |
| 171 | + LIST_1 = 1, | |
| 172 | + LIST_A = 2 | |
| 173 | +}; | |
| 174 | + | |
| 175 | +/* Picture Size */ | |
| 176 | +typedef struct TagPictureSize{ | |
| 177 | + int32_t iWidth; | |
| 178 | + int32_t iHeight; | |
| 179 | +}SPictureSize; | |
| 180 | + | |
| 181 | +/* Motion Vector components */ | |
| 182 | +typedef uint8_t MvComp; | |
| 183 | +enum{ | |
| 184 | + MV_X = 0, | |
| 185 | + MV_Y = 1, | |
| 186 | + MV_A = 2 | |
| 187 | +}; | |
| 188 | + | |
| 189 | +/* Chroma Components */ | |
| 190 | +typedef uint8_t ChromaComp; | |
| 191 | +enum{ | |
| 192 | + CHROMA_CB = 0, | |
| 193 | + CHROMA_CR = 1, | |
| 194 | + CHROMA_A = 2 | |
| 195 | +}; | |
| 196 | + | |
| 197 | +/* Position Offset structure */ | |
| 198 | +typedef struct TagPosOffset{ | |
| 199 | + int32_t iLeftOffset; | |
| 200 | + int32_t iTopOffset; | |
| 201 | + int32_t iRightOffset; | |
| 202 | + int32_t iBottomOffset; | |
| 203 | +}SPosOffset; | |
| 204 | + | |
| 205 | +enum EMbPosition // | |
| 206 | +{ | |
| 207 | + MB_LEFT = 0x01, // A | |
| 208 | + MB_TOP = 0x02, // B | |
| 209 | + MB_TOPRIGHT = 0x04, // C | |
| 210 | + MB_TOPLEFT = 0x08, // D, | |
| 211 | + MB_PRIVATE = 0x10, | |
| 212 | +}; | |
| 213 | +/* MB Type & Sub-MB Type */ | |
| 214 | +typedef int32_t MbType; | |
| 215 | +typedef int32_t SubMbType; | |
| 216 | + | |
| 217 | +#define MB_TYPE_INTRA4x4 0x01 | |
| 218 | +#define MB_TYPE_INTRA16x16 0x02 | |
| 219 | +#define MB_TYPE_INTRA8x8 0x03 | |
| 220 | +#define MB_TYPE_INTRA_PCM 0x04 | |
| 221 | + | |
| 222 | +#define MB_TYPE_INTRA_BL 0x05// I_BL new MB type | |
| 223 | + | |
| 224 | +#define MB_TYPE_16x16 0x06 | |
| 225 | +#define MB_TYPE_16x8 0x07 | |
| 226 | +#define MB_TYPE_8x16 0x08 | |
| 227 | +#define MB_TYPE_8x8 0x09 | |
| 228 | +#define MB_TYPE_8x8_REF0 0x0a | |
| 229 | + | |
| 230 | +#define SUB_MB_TYPE_8x8 0x0b | |
| 231 | +#define SUB_MB_TYPE_8x4 0x0c | |
| 232 | +#define SUB_MB_TYPE_4x8 0x0d | |
| 233 | +#define SUB_MB_TYPE_4x4 0x0e | |
| 234 | +#define MB_TYPE_SKIP 0x0f | |
| 235 | +#define MB_TYPE_DIRECT2 0x10 | |
| 236 | +#define not_available 0x20 | |
| 237 | + | |
| 238 | +#define IS_INTRA4x4(type) ( MB_TYPE_INTRA4x4 == (type) ) | |
| 239 | +#define IS_INTRA16x16(type) ( MB_TYPE_INTRA16x16 == (type) ) | |
| 240 | +#define IS_INTRA(type) ( (type) > 0 && (type) < 5 ) | |
| 241 | +#define IS_INTER(type) ( (type) > 5 && (type) < 16 ) | |
| 242 | + | |
| 243 | +#define IS_I_BL(type) ( (type) == MB_TYPE_INTRA_BL ) | |
| 244 | +#define IS_SUB8x8(type) (MB_TYPE_8x8 == (type) || MB_TYPE_8x8_REF0 == (type)) | |
| 245 | + | |
| 246 | +/* | |
| 247 | + * Memory Management Control Operation (MMCO) code | |
| 248 | + */ | |
| 249 | +enum{ | |
| 250 | + MMCO_END =0, | |
| 251 | + MMCO_SHORT2UNUSED =1, | |
| 252 | + MMCO_LONG2UNUSED =2, | |
| 253 | + MMCO_SHORT2LONG =3, | |
| 254 | + MMCO_SET_MAX_LONG =4, | |
| 255 | + MMCO_RESET =5, | |
| 256 | + MMCO_LONG =6 | |
| 257 | +}; | |
| 258 | + | |
| 259 | +/////////intra16x16 Luma | |
| 260 | +#define I16_PRED_V 0 | |
| 261 | +#define I16_PRED_H 1 | |
| 262 | +#define I16_PRED_DC 2 | |
| 263 | +#define I16_PRED_P 3 | |
| 264 | + | |
| 265 | +#define I16_PRED_DC_L 4 | |
| 266 | +#define I16_PRED_DC_T 5 | |
| 267 | +#define I16_PRED_DC_128 6 | |
| 268 | +//////////intra4x4 Luma | |
| 269 | +#define I4_PRED_V 0 | |
| 270 | +#define I4_PRED_H 1 | |
| 271 | +#define I4_PRED_DC 2 | |
| 272 | +#define I4_PRED_DDL 3 //diagonal_down_left | |
| 273 | +#define I4_PRED_DDR 4 //diagonal_down_right | |
| 274 | +#define I4_PRED_VR 5 //vertical_right | |
| 275 | +#define I4_PRED_HD 6 //horizon_down | |
| 276 | +#define I4_PRED_VL 7 //vertical_left | |
| 277 | +#define I4_PRED_HU 8 //horizon_up | |
| 278 | + | |
| 279 | +#define I4_PRED_DC_L 9 | |
| 280 | +#define I4_PRED_DC_T 10 | |
| 281 | +#define I4_PRED_DC_128 11 | |
| 282 | + | |
| 283 | +#define I4_PRED_DDL_TOP 12 //right-top replacing by padding rightmost pixel of top | |
| 284 | +#define I4_PRED_VL_TOP 13 //right-top replacing by padding rightmost pixel of top | |
| 285 | + | |
| 286 | +//////////intra Chroma | |
| 287 | +#define C_PRED_DC 0 | |
| 288 | +#define C_PRED_H 1 | |
| 289 | +#define C_PRED_V 2 | |
| 290 | +#define C_PRED_P 3 | |
| 291 | + | |
| 292 | +#define C_PRED_DC_L 4 | |
| 293 | +#define C_PRED_DC_T 5 | |
| 294 | +#define C_PRED_DC_128 6 | |
| 295 | + | |
| 296 | +} // namespace WelsDec | |
| 297 | + | |
| 298 | +#endif//WELS_COMMON_BASIS_H__ | |
| @@ -0,0 +1,104 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +//wels_const.h | |
| 34 | +#ifndef WELS_CONSTANCE_H__ | |
| 35 | +#define WELS_CONSTANCE_H__ | |
| 36 | + | |
| 37 | +// Miscellaneous sizing infos | |
| 38 | +#ifndef MAX_FNAME_LEN | |
| 39 | +#define MAX_FNAME_LEN 256 // maximal length of file name in char size | |
| 40 | +#endif//MAX_FNAME_LEN | |
| 41 | + | |
| 42 | +#ifndef WELS_LOG_BUF_SIZE | |
| 43 | +#define WELS_LOG_BUF_SIZE 4096 | |
| 44 | +#endif//WELS_LOG_BUF_SIZE | |
| 45 | + | |
| 46 | +#ifndef MAX_TRACE_LOG_SIZE | |
| 47 | +#define MAX_TRACE_LOG_SIZE (50 * (1<<20)) // max trace log size: 50 MB, overwrite occur if log file size exceeds this size | |
| 48 | +#endif//MAX_TRACE_LOG_SIZE | |
| 49 | + | |
| 50 | +/* MB width in pixels for specified colorspace I420 usually used in codec */ | |
| 51 | +#define MB_WIDTH_LUMA 16 | |
| 52 | +#define MB_WIDTH_CHROMA (MB_WIDTH_LUMA>>1) | |
| 53 | +/* MB height in pixels for specified colorspace I420 usually used in codec */ | |
| 54 | +#define MB_HEIGHT_LUMA 16 | |
| 55 | +#define MB_HEIGHT_CHROMA (MB_HEIGHT_LUMA>>1) | |
| 56 | + | |
| 57 | +/* Some list size */ | |
| 58 | +#define MB_COEFF_LIST_SIZE (256+((MB_WIDTH_CHROMA*MB_HEIGHT_CHROMA)<<1)) | |
| 59 | + | |
| 60 | +#define MB_PARTITION_SIZE 4 // Macroblock partition size in 8x8 sub-blocks | |
| 61 | +#define MB_SUB_PARTITION_SIZE 4 // Sub partition size in a 8x8 sub-block | |
| 62 | +#define MB_BLOCK4x4_NUM 16 | |
| 63 | +#define MB_BLOCK8x8_NUM 4 | |
| 64 | + | |
| 65 | +#define NAL_UNIT_HEADER_EXT_SIZE 3 // Size of NAL unit header for extension in byte | |
| 66 | + | |
| 67 | +#define MAX_SPS_COUNT 32 // Count number of SPS | |
| 68 | +#define MAX_PPS_COUNT 256 // Count number of PPS | |
| 69 | + | |
| 70 | +#define MAX_FRAME_RATE 30 // maximal frame rate to support | |
| 71 | +#define MIN_FRAME_RATE 1 // minimal frame rate need support | |
| 72 | + | |
| 73 | +#define MAX_REF_PIC_COUNT 16 // MAX Short + Long reference pictures | |
| 74 | +#define MIN_REF_PIC_COUNT 1 // minimal count number of reference pictures, 1 short + 2 key reference based? | |
| 75 | +#define MAX_SHORT_REF_COUNT 16 // maximal count number of short reference pictures | |
| 76 | +#define MAX_LONG_REF_COUNT 16 // maximal count number of long reference pictures | |
| 77 | + | |
| 78 | +#define MAX_MMCO_COUNT 66 | |
| 79 | + | |
| 80 | +#define MAX_SLICEGROUP_IDS 8 // Count number of Slice Groups | |
| 81 | + | |
| 82 | +#define ALIGN_RBSP_LEN_FIX 4 | |
| 83 | + | |
| 84 | +#define PADDING_LENGTH 32 // reference extension | |
| 85 | + | |
| 86 | +#define BASE_QUALITY_ID 0 | |
| 87 | +//#define BASE_DEPENDENCY_ID 0 | |
| 88 | +#define BASE_DQ_ID 0 | |
| 89 | +#define MAX_DQ_ID ((uint8_t)-1) | |
| 90 | +//#define MAX_LAYER_NUM (MAX_DEPENDENCY_LAYER * MAX_TEMPORAL_LEVEL * MAX_QUALITY_LEVEL) // Layer number of Three-tuple | |
| 91 | + | |
| 92 | +#define LAYER_NUM_EXCHANGEABLE 1 | |
| 93 | + | |
| 94 | +#define MAX_NAL_UNIT_NUM_IN_AU 32 // predefined maximal number of NAL Units in an access unit | |
| 95 | +#define MAX_ACCESS_UINT_CAPACITY 1048576 // Maximal AU capacity in bytes: (1<<20) = 1024 KB predefined | |
| 96 | + | |
| 97 | +enum { | |
| 98 | + BASE_MB = 0, | |
| 99 | + NON_AVC_REWRITE_ENHANCE_MB =1, | |
| 100 | + AVC_REWRITE_ENHANCE_MB = 2 | |
| 101 | + | |
| 102 | +}; | |
| 103 | + | |
| 104 | +#endif//WELS_CONSTANCE_H__ | |
| @@ -0,0 +1,1027 @@ | ||
| 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 au_parser.c | |
| 33 | + * | |
| 34 | + * \brief Interfaces introduced in Access Unit level based parser | |
| 35 | + * | |
| 36 | + * \date 03/10/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#include <string.h> | |
| 41 | +#include "codec_def.h" | |
| 42 | +#include "ls_defines.h" | |
| 43 | +#include "macros.h" | |
| 44 | +#include "au_parser.h" | |
| 45 | +#include "decoder.h" | |
| 46 | +#include "error_code.h" | |
| 47 | +#include "dec_frame.h" | |
| 48 | +#include "dec_golomb.h" | |
| 49 | +#include "bit_stream.h" | |
| 50 | +#include "utils.h" | |
| 51 | +#include "codec_app_def.h" | |
| 52 | +#include "memmgr_nal_unit.h" | |
| 53 | +#include "decoder_core.h" | |
| 54 | +#include "wels_common_basis.h" | |
| 55 | +#include "decoder_core.h" | |
| 56 | +#include "manage_dec_ref.h" | |
| 57 | +#include "mem_align.h" | |
| 58 | + | |
| 59 | +namespace WelsDec { | |
| 60 | +/*! | |
| 61 | + ************************************************************************************* | |
| 62 | + * \brief Start Code Prefix (0x 00 00 00 01) detection | |
| 63 | + * | |
| 64 | + * \param pBuf bitstream payload buffer | |
| 65 | + * \param pOffset offset between NAL rbsp and original bitsteam that | |
| 66 | + * start code prefix is seperated from. | |
| 67 | + * \param iBufSize count size of buffer | |
| 68 | + * | |
| 69 | + * \return RBSP buffer of start code prefix exclusive | |
| 70 | + * | |
| 71 | + * \note N/A | |
| 72 | + ************************************************************************************* | |
| 73 | + */ | |
| 74 | +uint8_t* DetectStartCodePrefix( const uint8_t *kpBuf, int32_t *pOffset, int32_t iBufSize ) | |
| 75 | +{ | |
| 76 | + uint8_t *pBits = (uint8_t *)kpBuf; | |
| 77 | + | |
| 78 | + do { | |
| 79 | + int32_t iIdx = 0; | |
| 80 | + while( (iIdx<iBufSize) && (!(*pBits)) ){ | |
| 81 | + ++ pBits; | |
| 82 | + ++ iIdx; | |
| 83 | + } | |
| 84 | + if( iIdx >= iBufSize ) break; | |
| 85 | + | |
| 86 | + ++ iIdx; | |
| 87 | + ++ pBits; | |
| 88 | + | |
| 89 | + if( (iIdx>=3) && ((*(pBits-1)) == 0x1) ){ | |
| 90 | + *pOffset = ((uint32_t)pBits) - ((uint32_t)kpBuf); | |
| 91 | + return pBits; | |
| 92 | + } | |
| 93 | + | |
| 94 | + iBufSize -= iIdx; | |
| 95 | + } while (1); | |
| 96 | + | |
| 97 | + return NULL; | |
| 98 | +} | |
| 99 | + | |
| 100 | +/*! | |
| 101 | + ************************************************************************************* | |
| 102 | + * \brief to parse nal unit | |
| 103 | + * | |
| 104 | + * \param pCtx decoder context | |
| 105 | + * \param pNalUnitHeader parsed result of NAL Unit Header to output | |
| 106 | + * \param pSrcRbsp bitstream buffer to input | |
| 107 | + * \param iSrcRbspLen length size of bitstream buffer payload | |
| 108 | + * \param pSrcNal | |
| 109 | + * \param iSrcNalLen | |
| 110 | + * \param pConsumedBytes consumed bytes during parsing | |
| 111 | + * | |
| 112 | + * \return decoded bytes payload, might be (pSrcRbsp+1) if no escapes | |
| 113 | + * | |
| 114 | + * \note N/A | |
| 115 | + ************************************************************************************* | |
| 116 | + */ | |
| 117 | +uint8_t* ParseNalHeader( PWelsDecoderContext pCtx, SNalUnitHeader *pNalUnitHeader, uint8_t *pSrcRbsp, int32_t iSrcRbspLen, uint8_t *pSrcNal, int32_t iSrcNalLen, int32_t* pConsumedBytes ) | |
| 118 | +{ | |
| 119 | + PNalUnit pCurNal = NULL; | |
| 120 | + uint8_t* pNal = pSrcRbsp; | |
| 121 | + int32_t iNalSize = iSrcRbspLen; | |
| 122 | + PBitStringAux pBs = NULL; | |
| 123 | + bool_t bExtensionFlag = false; | |
| 124 | + int32_t iErr = ERR_NONE; | |
| 125 | + int32_t iBitSize = 0; | |
| 126 | + | |
| 127 | + pNalUnitHeader->eNalUnitType = NAL_UNIT_UNSPEC_0;//SHOULD init it. because pCtx->sCurNalHead is common variable. | |
| 128 | + | |
| 129 | + //remove the consecutive ZERO at the end of current NAL in the reverse order.--2011.6.1 | |
| 130 | + { | |
| 131 | + int32_t iIndex = iSrcRbspLen - 1; | |
| 132 | + uint8_t uiBsZero = 0; | |
| 133 | + while ( iIndex >= 0 ) | |
| 134 | + { | |
| 135 | + uiBsZero = pSrcRbsp[iIndex]; | |
| 136 | + if ( 0 == uiBsZero ) | |
| 137 | + { | |
| 138 | + --iNalSize; | |
| 139 | + --iIndex; | |
| 140 | + } | |
| 141 | + else | |
| 142 | + { | |
| 143 | + break; | |
| 144 | + } | |
| 145 | + } | |
| 146 | + } | |
| 147 | + | |
| 148 | + pNalUnitHeader->uiForbiddenZeroBit = (uint8_t)(pNal[0] >> 7); // uiForbiddenZeroBit | |
| 149 | + if ( pNalUnitHeader->uiForbiddenZeroBit )//2010.4.14 | |
| 150 | + { | |
| 151 | + return NULL; //uiForbiddenZeroBit should always equal to 0 | |
| 152 | + } | |
| 153 | + | |
| 154 | + pNalUnitHeader->uiNalRefIdc = (uint8_t)(pNal[0] >> 5); // uiNalRefIdc | |
| 155 | + pNalUnitHeader->eNalUnitType = (ENalUnitType)(pNal[0] & 0x1f); // eNalUnitType | |
| 156 | + | |
| 157 | + ++pNal; | |
| 158 | + --iNalSize; | |
| 159 | + ++(*pConsumedBytes); | |
| 160 | + | |
| 161 | +#ifdef DEBUG_PARSE_INFO | |
| 162 | + WelsLog(pCtx, WELS_LOG_INFO, "nal type: %d \n", pNalUnitHeader->eNalUnitType); | |
| 163 | +#endif | |
| 164 | + | |
| 165 | + if ( !(IS_SEI_NAL(pNalUnitHeader->eNalUnitType) || IS_SPS_NAL(pNalUnitHeader->eNalUnitType) || pCtx->bSpsExistAheadFlag) ) | |
| 166 | + { | |
| 167 | + WelsLog( pCtx, WELS_LOG_WARNING, "parse_nal(), no exist Sequence Parameter Sets ahead of sequence when try to decode NAL(type:%d).\n", pNalUnitHeader->eNalUnitType); | |
| 168 | + pCtx->iErrorCode = dsNoParamSets; | |
| 169 | + return NULL; | |
| 170 | + } | |
| 171 | + if ( !(IS_SEI_NAL(pNalUnitHeader->eNalUnitType) || IS_PARAM_SETS_NALS(pNalUnitHeader->eNalUnitType) || pCtx->bPpsExistAheadFlag) ) | |
| 172 | + { | |
| 173 | + WelsLog( pCtx, WELS_LOG_WARNING, "parse_nal(), no exist Picture Parameter Sets ahead of sequence when try to decode NAL(type:%d).\n", pNalUnitHeader->eNalUnitType); | |
| 174 | + pCtx->iErrorCode = dsNoParamSets; | |
| 175 | + return NULL; | |
| 176 | + } | |
| 177 | + if ( (IS_VCL_NAL_AVC_BASE(pNalUnitHeader->eNalUnitType) && !(pCtx->bSpsExistAheadFlag || pCtx->bPpsExistAheadFlag)) || | |
| 178 | + (IS_NEW_INTRODUCED_NAL(pNalUnitHeader->eNalUnitType) && !(pCtx->bSpsExistAheadFlag || pCtx->bSubspsExistAheadFlag || pCtx->bPpsExistAheadFlag) ) ) | |
| 179 | + { | |
| 180 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseNalHeader(), no exist Parameter Sets ahead of sequence when try to decode slice(type:%d).\n", pNalUnitHeader->eNalUnitType); | |
| 181 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 182 | + return NULL; | |
| 183 | + } | |
| 184 | + | |
| 185 | + | |
| 186 | + switch(pNalUnitHeader->eNalUnitType){ | |
| 187 | + case NAL_UNIT_SEI: | |
| 188 | + | |
| 189 | + if ( pCtx->pAccessUnitList->uiAvailUnitsNum > 0 ) | |
| 190 | + { | |
| 191 | + pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1; | |
| 192 | + pCtx->bAuReadyFlag = true; | |
| 193 | + } | |
| 194 | + | |
| 195 | + break; | |
| 196 | + | |
| 197 | + case NAL_UNIT_SPS: | |
| 198 | + | |
| 199 | + if ( pCtx->pAccessUnitList->uiAvailUnitsNum > 0 ) | |
| 200 | + { | |
| 201 | + pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1; | |
| 202 | + pCtx->bAuReadyFlag = true; | |
| 203 | + } | |
| 204 | + | |
| 205 | + break; | |
| 206 | + | |
| 207 | + case NAL_UNIT_PREFIX: | |
| 208 | + pCurNal = &pCtx->sPrefixNal; | |
| 209 | + | |
| 210 | + if ( iNalSize < NAL_UNIT_HEADER_EXT_SIZE ) | |
| 211 | + { | |
| 212 | + return NULL; | |
| 213 | + } | |
| 214 | + | |
| 215 | + DecodeNalHeaderExt( pCurNal, pNal ); | |
| 216 | + | |
| 217 | + pNal += NAL_UNIT_HEADER_EXT_SIZE; | |
| 218 | + iNalSize -= NAL_UNIT_HEADER_EXT_SIZE; | |
| 219 | + *pConsumedBytes += NAL_UNIT_HEADER_EXT_SIZE; | |
| 220 | + | |
| 221 | + pCurNal->sNalHeaderExt.sNalUnitHeader.uiForbiddenZeroBit = pNalUnitHeader->uiForbiddenZeroBit; | |
| 222 | + pCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc = pNalUnitHeader->uiNalRefIdc; | |
| 223 | + pCurNal->sNalHeaderExt.sNalUnitHeader.eNalUnitType = pNalUnitHeader->eNalUnitType; | |
| 224 | + | |
| 225 | + pBs = &pCtx->sBs; | |
| 226 | + | |
| 227 | + iBitSize = (iNalSize<<3) - BsGetTrailingBits( pNal + iNalSize - 1 ); // convert into bit | |
| 228 | + | |
| 229 | + InitBits( pBs, pNal, iBitSize); | |
| 230 | + | |
| 231 | + ParsePrefixNalUnit( pCtx, pBs ); | |
| 232 | + | |
| 233 | + break; | |
| 234 | + case NAL_UNIT_CODED_SLICE_EXT: | |
| 235 | + bExtensionFlag = true; | |
| 236 | + case NAL_UNIT_CODED_SLICE: | |
| 237 | + case NAL_UNIT_CODED_SLICE_IDR: | |
| 238 | + { | |
| 239 | + PAccessUnit pCurAu = NULL; | |
| 240 | + uint32_t uiAvailNalNum; | |
| 241 | + pCurNal = MemGetNextNal( &pCtx->pAccessUnitList ); | |
| 242 | + if( NULL == pCurNal ) | |
| 243 | + { | |
| 244 | + WelsLog( pCtx, WELS_LOG_WARNING, "MemGetNextNal() fail due out of memory.\n"); | |
| 245 | + pCtx->iErrorCode |= dsOutOfMemory; | |
| 246 | + return NULL; | |
| 247 | + } | |
| 248 | + | |
| 249 | + pCurNal->sNalHeaderExt.sNalUnitHeader.uiForbiddenZeroBit = pNalUnitHeader->uiForbiddenZeroBit; | |
| 250 | + pCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc = pNalUnitHeader->uiNalRefIdc; | |
| 251 | + pCurNal->sNalHeaderExt.sNalUnitHeader.eNalUnitType = pNalUnitHeader->eNalUnitType; | |
| 252 | + pCurAu = pCtx->pAccessUnitList; | |
| 253 | + uiAvailNalNum = pCurAu->uiAvailUnitsNum; | |
| 254 | + | |
| 255 | + | |
| 256 | + if( pNalUnitHeader->eNalUnitType == NAL_UNIT_CODED_SLICE_EXT ) | |
| 257 | + { | |
| 258 | + if ( iNalSize < NAL_UNIT_HEADER_EXT_SIZE ) | |
| 259 | + { | |
| 260 | + return NULL; | |
| 261 | + } | |
| 262 | + | |
| 263 | + DecodeNalHeaderExt( pCurNal, pNal ); | |
| 264 | + if( pCurNal->sNalHeaderExt.uiQualityId != 0 || | |
| 265 | + pCurNal->sNalHeaderExt.bUseRefBasePicFlag ) | |
| 266 | + { | |
| 267 | + if( pCurNal->sNalHeaderExt.uiQualityId != 0 ) | |
| 268 | + WelsLog(pCtx, WELS_LOG_WARNING, "ParseNalHeader():uiQualityId (%d) != 0, MGS not supported!\n", pCurNal->sNalHeaderExt.uiQualityId); | |
| 269 | + if( pCurNal->sNalHeaderExt.bUseRefBasePicFlag != 0 ) | |
| 270 | + WelsLog(pCtx, WELS_LOG_WARNING, "ParseNalHeader():bUseRefBasePicFlag (%d) != 0, MGS not supported!\n", pCurNal->sNalHeaderExt.bUseRefBasePicFlag); | |
| 271 | + | |
| 272 | + pCtx->iErrorCode |= dsInvalidArgument; | |
| 273 | + ForceClearCurrentNal( pCurAu ); | |
| 274 | + | |
| 275 | + if ( uiAvailNalNum > 1 ) | |
| 276 | + { | |
| 277 | + pCurAu->uiEndPos = uiAvailNalNum - 2; | |
| 278 | + pCtx->bAuReadyFlag = true; | |
| 279 | + } | |
| 280 | + return NULL; | |
| 281 | + } | |
| 282 | + pNal += NAL_UNIT_HEADER_EXT_SIZE; | |
| 283 | + iNalSize -= NAL_UNIT_HEADER_EXT_SIZE; | |
| 284 | + *pConsumedBytes += NAL_UNIT_HEADER_EXT_SIZE; | |
| 285 | + | |
| 286 | + } | |
| 287 | + else | |
| 288 | + { | |
| 289 | + | |
| 290 | + | |
| 291 | + if ( NAL_UNIT_PREFIX == pCtx->sPrefixNal.sNalHeaderExt.sNalUnitHeader.eNalUnitType ) | |
| 292 | + { | |
| 293 | + PrefetchNalHeaderExtSyntax( pCtx, pCurNal, &pCtx->sPrefixNal ); | |
| 294 | + } | |
| 295 | + | |
| 296 | + pCurNal->sNalHeaderExt.bIdrFlag = ( NAL_UNIT_CODED_SLICE_IDR == pNalUnitHeader->eNalUnitType ) ? true : false; //SHOULD update this flag for AVC if no prefix NAL | |
| 297 | + pCurNal->sNalHeaderExt.iNoInterLayerPredFlag = 1; | |
| 298 | + } | |
| 299 | + | |
| 300 | + pBs = &pCurAu->pNalUnitsList[uiAvailNalNum-1]->sNalData.sVclNal.sSliceBitsRead; | |
| 301 | + iBitSize = (iNalSize<<3) - BsGetTrailingBits( pNal+ iNalSize - 1 ); // convert into bit | |
| 302 | + InitBits( pBs, pNal, iBitSize); | |
| 303 | + iErr = ParseSliceHeaderSyntaxs( pCtx, pBs, bExtensionFlag ); | |
| 304 | + if ( iErr != ERR_NONE ) | |
| 305 | + { | |
| 306 | + //if current NAL occur error when parsing, should clean it from pNalUnitsList | |
| 307 | + //otherwise, when Next good NAL decoding, this corrupt NAL is considered as normal NAL and lead to decoder crash | |
| 308 | + ForceClearCurrentNal( pCurAu ); | |
| 309 | + | |
| 310 | + if ( uiAvailNalNum > 1 ) | |
| 311 | + { | |
| 312 | + pCurAu->uiEndPos = uiAvailNalNum - 2; | |
| 313 | + pCtx->bAuReadyFlag = true; | |
| 314 | + | |
| 315 | + | |
| 316 | + } | |
| 317 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 318 | + if ( dsNoParamSets & pCtx->iErrorCode ) | |
| 319 | + { | |
| 320 | + if ( uiAvailNalNum <= 1 ) //no any data to decode and SPS/PPS ID mismatch, SHOULD request IDR | |
| 321 | + { | |
| 322 | +#ifdef LONG_TERM_REF | |
| 323 | + pCtx->bParamSetsLostFlag = true; | |
| 324 | +#else | |
| 325 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 326 | +#endif | |
| 327 | + ResetParameterSetsState( pCtx ); | |
| 328 | + } | |
| 329 | + return NULL; | |
| 330 | + } | |
| 331 | + else | |
| 332 | + { | |
| 333 | + return NULL; | |
| 334 | + } | |
| 335 | +#else | |
| 336 | + return NULL; | |
| 337 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 338 | + } | |
| 339 | + | |
| 340 | + if ( (uiAvailNalNum > 1) && | |
| 341 | + CheckAccessUnitBoundary( pCurAu->pNalUnitsList[uiAvailNalNum-1], pCurAu->pNalUnitsList[uiAvailNalNum-2], | |
| 342 | + pCurAu->pNalUnitsList[uiAvailNalNum-1]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pSps) ) | |
| 343 | + { | |
| 344 | + pCurAu->uiEndPos = uiAvailNalNum - 2; | |
| 345 | + pCtx->bAuReadyFlag = true; | |
| 346 | + | |
| 347 | + | |
| 348 | + } | |
| 349 | + } | |
| 350 | + break; | |
| 351 | + default: | |
| 352 | + break; | |
| 353 | + } | |
| 354 | + | |
| 355 | + return pNal; | |
| 356 | +} | |
| 357 | + | |
| 358 | + | |
| 359 | +bool_t CheckAccessUnitBoundaryExt( PNalUnitHeaderExt pLastNalHdrExt, PNalUnitHeaderExt pCurNalHeaderExt, PSliceHeader pLastSliceHeader, PSliceHeader pCurSliceHeader ) | |
| 360 | +{ | |
| 361 | + const PSps kpSps = pCurSliceHeader->pSps; | |
| 362 | + | |
| 363 | + //Sub-clause 7.1.4.1.1 temporal_id | |
| 364 | + if (pLastNalHdrExt->uiTemporalId != pCurNalHeaderExt->uiTemporalId) { | |
| 365 | + return TRUE; | |
| 366 | + } | |
| 367 | + | |
| 368 | + // Subclause 7.4.1.2.5 | |
| 369 | + if ( pLastSliceHeader->iRedundantPicCnt < pCurSliceHeader->iRedundantPicCnt ) | |
| 370 | + return FALSE; | |
| 371 | + else if ( pLastSliceHeader->iRedundantPicCnt > pCurSliceHeader->iRedundantPicCnt ) | |
| 372 | + return TRUE; | |
| 373 | + | |
| 374 | + // Subclause G7.4.1.2.4 | |
| 375 | + if ( pLastNalHdrExt->uiDependencyId < pCurNalHeaderExt->uiDependencyId ) | |
| 376 | + return FALSE; | |
| 377 | + else if ( pLastNalHdrExt->uiDependencyId > pCurNalHeaderExt->uiDependencyId ) | |
| 378 | + return TRUE; | |
| 379 | + if ( pLastNalHdrExt->uiQualityId < pCurNalHeaderExt->uiQualityId ) | |
| 380 | + return FALSE; | |
| 381 | + else if ( pLastNalHdrExt->uiQualityId > pCurNalHeaderExt->uiQualityId ) | |
| 382 | + return TRUE; | |
| 383 | + | |
| 384 | + // Subclause 7.4.1.2.4 | |
| 385 | + if ( pLastSliceHeader->iFrameNum != pCurSliceHeader->iFrameNum ) | |
| 386 | + return TRUE; | |
| 387 | + if ( pLastSliceHeader->iPpsId != pCurSliceHeader->iPpsId ) | |
| 388 | + return TRUE; | |
| 389 | + if ( pLastSliceHeader->bFieldPicFlag != pCurSliceHeader->bFieldPicFlag ) | |
| 390 | + return TRUE; | |
| 391 | + if ( pLastSliceHeader->bBottomFiledFlag != pCurSliceHeader->bBottomFiledFlag ) | |
| 392 | + return TRUE; | |
| 393 | + if ( (pLastNalHdrExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) != (pCurNalHeaderExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) ) | |
| 394 | + return TRUE; | |
| 395 | + if ( pLastNalHdrExt->bIdrFlag != pCurNalHeaderExt->bIdrFlag ) | |
| 396 | + return TRUE; | |
| 397 | + if ( pCurNalHeaderExt->bIdrFlag ){ | |
| 398 | + if ( pLastSliceHeader->uiIdrPicId != pCurSliceHeader->uiIdrPicId ) | |
| 399 | + return TRUE; | |
| 400 | + } | |
| 401 | + if ( kpSps->uiPocType == 0 ){ | |
| 402 | + if ( pLastSliceHeader->iPicOrderCntLsb != pCurSliceHeader->iPicOrderCntLsb ) | |
| 403 | + return TRUE; | |
| 404 | + if ( pLastSliceHeader->iDeltaPicOrderCntBottom != pCurSliceHeader->iDeltaPicOrderCntBottom ) | |
| 405 | + return TRUE; | |
| 406 | + } | |
| 407 | + else if ( kpSps->uiPocType == 1 ){ | |
| 408 | + if ( pLastSliceHeader->iDeltaPicOrderCnt[0] != pCurSliceHeader->iDeltaPicOrderCnt[0] ) | |
| 409 | + return TRUE; | |
| 410 | + if ( pLastSliceHeader->iDeltaPicOrderCnt[1] != pCurSliceHeader->iDeltaPicOrderCnt[1] ) | |
| 411 | + return TRUE; | |
| 412 | + } | |
| 413 | + | |
| 414 | + return FALSE; | |
| 415 | +} | |
| 416 | + | |
| 417 | + | |
| 418 | +bool_t CheckAccessUnitBoundary( const PNalUnit kpCurNal, const PNalUnit kpLastNal, const PSps kpSps ) | |
| 419 | +{ | |
| 420 | + const PNalUnitHeaderExt kpLastNalHeaderExt = &kpLastNal->sNalHeaderExt; | |
| 421 | + const PNalUnitHeaderExt kpCurNalHeaderExt = &kpCurNal->sNalHeaderExt; | |
| 422 | + const SSliceHeader *kpLastSliceHeader = &kpLastNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader; | |
| 423 | + const SSliceHeader *kpCurSliceHeader = &kpCurNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader; | |
| 424 | + | |
| 425 | + //Sub-clause 7.1.4.1.1 temporal_id | |
| 426 | + if (kpLastNalHeaderExt->uiTemporalId != kpCurNalHeaderExt->uiTemporalId) { | |
| 427 | + return TRUE; | |
| 428 | + } | |
| 429 | + | |
| 430 | + // Subclause 7.4.1.2.5 | |
| 431 | + if ( kpLastSliceHeader->iRedundantPicCnt < kpCurSliceHeader->iRedundantPicCnt ) | |
| 432 | + return FALSE; | |
| 433 | + else if ( kpLastSliceHeader->iRedundantPicCnt > kpCurSliceHeader->iRedundantPicCnt ) | |
| 434 | + return TRUE; | |
| 435 | + | |
| 436 | + // Subclause G7.4.1.2.4 | |
| 437 | + if ( kpLastNalHeaderExt->uiDependencyId < kpCurNalHeaderExt->uiDependencyId ) | |
| 438 | + return FALSE; | |
| 439 | + else if ( kpLastNalHeaderExt->uiDependencyId > kpCurNalHeaderExt->uiDependencyId ) | |
| 440 | + return TRUE; | |
| 441 | + if ( kpLastNalHeaderExt->uiQualityId < kpCurNalHeaderExt->uiQualityId ) | |
| 442 | + return FALSE; | |
| 443 | + else if ( kpLastNalHeaderExt->uiQualityId > kpCurNalHeaderExt->uiQualityId ) | |
| 444 | + return TRUE; | |
| 445 | + | |
| 446 | + // Subclause 7.4.1.2.4 | |
| 447 | + if ( kpLastSliceHeader->iFrameNum != kpCurSliceHeader->iFrameNum ) | |
| 448 | + return TRUE; | |
| 449 | + if ( kpLastSliceHeader->iPpsId != kpCurSliceHeader->iPpsId ) | |
| 450 | + return TRUE; | |
| 451 | + if ( kpLastSliceHeader->bFieldPicFlag != kpCurSliceHeader->bFieldPicFlag ) | |
| 452 | + return TRUE; | |
| 453 | + if ( kpLastSliceHeader->bBottomFiledFlag != kpCurSliceHeader->bBottomFiledFlag ) | |
| 454 | + return TRUE; | |
| 455 | + if ( (kpLastNalHeaderExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) != (kpCurNalHeaderExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) ) | |
| 456 | + return TRUE; | |
| 457 | + if ( kpLastNalHeaderExt->bIdrFlag != kpCurNalHeaderExt->bIdrFlag ) | |
| 458 | + return TRUE; | |
| 459 | + if ( kpCurNalHeaderExt->bIdrFlag ){ | |
| 460 | + if ( kpLastSliceHeader->uiIdrPicId != kpCurSliceHeader->uiIdrPicId ) | |
| 461 | + return TRUE; | |
| 462 | + } | |
| 463 | + if ( kpSps->uiPocType == 0 ){ | |
| 464 | + if ( kpLastSliceHeader->iPicOrderCntLsb != kpCurSliceHeader->iPicOrderCntLsb ) | |
| 465 | + return TRUE; | |
| 466 | + if ( kpLastSliceHeader->iDeltaPicOrderCntBottom != kpCurSliceHeader->iDeltaPicOrderCntBottom ) | |
| 467 | + return TRUE; | |
| 468 | + } | |
| 469 | + else if ( kpSps->uiPocType == 1 ){ | |
| 470 | + if ( kpLastSliceHeader->iDeltaPicOrderCnt[0] != kpCurSliceHeader->iDeltaPicOrderCnt[0] ) | |
| 471 | + return TRUE; | |
| 472 | + if ( kpLastSliceHeader->iDeltaPicOrderCnt[1] != kpCurSliceHeader->iDeltaPicOrderCnt[1] ) | |
| 473 | + return TRUE; | |
| 474 | + } | |
| 475 | + | |
| 476 | + return FALSE; | |
| 477 | +} | |
| 478 | + | |
| 479 | +/*! | |
| 480 | + ************************************************************************************* | |
| 481 | + * \brief to parse NON VCL NAL Units | |
| 482 | + * | |
| 483 | + * \param pCtx decoder context | |
| 484 | + * \param rbsp rbsp buffer of NAL Unit | |
| 485 | + * \param src_len length of rbsp buffer | |
| 486 | + * | |
| 487 | + * \return 0 - successed | |
| 488 | + * 1 - failed | |
| 489 | + * | |
| 490 | + ************************************************************************************* | |
| 491 | + */ | |
| 492 | +int32_t ParseNonVclNal( PWelsDecoderContext pCtx, uint8_t *pRbsp, const int32_t kiSrcLen ) | |
| 493 | +{ | |
| 494 | + PBitStringAux pBs = NULL; | |
| 495 | + ENalUnitType eNalType = NAL_UNIT_UNSPEC_0; // make initial value as unspecified | |
| 496 | + int32_t iPicWidth = 0; | |
| 497 | + int32_t iPicHeight = 0; | |
| 498 | + int32_t iBitSize = 0; | |
| 499 | + int32_t iErr = ERR_NONE; | |
| 500 | + | |
| 501 | + pBs = &pCtx->sBs; // SBitStringAux instance for non VCL NALs decoding | |
| 502 | + iBitSize = (kiSrcLen<<3) - BsGetTrailingBits( pRbsp + kiSrcLen - 1 ); // convert into bit | |
| 503 | + eNalType = pCtx->sCurNalHead.eNalUnitType; | |
| 504 | + | |
| 505 | + switch( eNalType ) { | |
| 506 | + case NAL_UNIT_SPS: | |
| 507 | + case NAL_UNIT_SUBSET_SPS: | |
| 508 | + if ( iBitSize > 0 ) | |
| 509 | + InitBits( pBs, pRbsp, iBitSize ); | |
| 510 | +#ifdef DEBUG_PARSE_INFO | |
| 511 | + WelsLog(pCtx, WELS_LOG_INFO, "parsing nal: %d \n", eNalType); | |
| 512 | +#endif | |
| 513 | + iErr = ParseSps( pCtx, pBs, &iPicWidth, &iPicHeight ); | |
| 514 | + if ( ERR_NONE != iErr ) // modified for pSps/pSubsetSps invalid, 12/1/2009 | |
| 515 | + { | |
| 516 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 517 | + return iErr; | |
| 518 | + } | |
| 519 | + | |
| 520 | + if ( ERR_NONE == iErr ) | |
| 521 | + UpdateMaxPictureResolution( pCtx, iPicWidth, iPicHeight ); | |
| 522 | + | |
| 523 | + break; | |
| 524 | + | |
| 525 | + case NAL_UNIT_PPS: | |
| 526 | + if ( iBitSize > 0 ) | |
| 527 | + InitBits( pBs, pRbsp, iBitSize ); | |
| 528 | +#ifdef DEBUG_PARSE_INFO | |
| 529 | + WelsLog(pCtx, WELS_LOG_INFO, "parsing nal: %d \n", eNalType); | |
| 530 | +#endif | |
| 531 | + iErr = ParsePps( pCtx, &pCtx->sPpsBuffer[0], pBs ); | |
| 532 | + if ( ERR_NONE != iErr ) // modified for pps invalid, 12/1/2009 | |
| 533 | + { | |
| 534 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 535 | + return iErr; | |
| 536 | + } | |
| 537 | + | |
| 538 | + pCtx->bPpsExistAheadFlag = true; | |
| 539 | + | |
| 540 | + break; | |
| 541 | + | |
| 542 | + case NAL_UNIT_SEI: | |
| 543 | + | |
| 544 | + break; | |
| 545 | + | |
| 546 | + case NAL_UNIT_PREFIX: | |
| 547 | + break; | |
| 548 | + case NAL_UNIT_CODED_SLICE_DPA: | |
| 549 | + case NAL_UNIT_CODED_SLICE_DPB: | |
| 550 | + case NAL_UNIT_CODED_SLICE_DPC: | |
| 551 | + | |
| 552 | + break; | |
| 553 | + | |
| 554 | + default: | |
| 555 | + break; | |
| 556 | + } | |
| 557 | + | |
| 558 | + return iErr; | |
| 559 | +} | |
| 560 | + | |
| 561 | +void_t ParseRefBasePicMarking ( PBitStringAux pBs, PRefBasePicMarking pRefBasePicMarking ) | |
| 562 | +{ | |
| 563 | + const bool_t kbAdaptiveMarkingModeFlag = !!BsGetOneBit( pBs ); | |
| 564 | + pRefBasePicMarking->bAdaptiveRefBasePicMarkingModeFlag = kbAdaptiveMarkingModeFlag; | |
| 565 | + if ( kbAdaptiveMarkingModeFlag ){ | |
| 566 | + int32_t iIdx = 0; | |
| 567 | + do { | |
| 568 | + const uint32_t kuiMmco = BsGetUe( pBs ); | |
| 569 | + | |
| 570 | + pRefBasePicMarking->mmco_base[iIdx].uiMmcoType = kuiMmco; | |
| 571 | + | |
| 572 | + if (kuiMmco == MMCO_END) | |
| 573 | + break; | |
| 574 | + | |
| 575 | + if (kuiMmco == MMCO_SHORT2UNUSED){ | |
| 576 | + pRefBasePicMarking->mmco_base[iIdx].uiDiffOfPicNums = 1 + BsGetUe( pBs ); | |
| 577 | + pRefBasePicMarking->mmco_base[iIdx].iShortFrameNum = 0; | |
| 578 | + } | |
| 579 | + else if (kuiMmco == MMCO_LONG2UNUSED){ | |
| 580 | + pRefBasePicMarking->mmco_base[iIdx].uiLongTermPicNum = BsGetUe( pBs ); | |
| 581 | + } | |
| 582 | + ++ iIdx; | |
| 583 | + } while(iIdx < MAX_MMCO_COUNT); | |
| 584 | + } | |
| 585 | +} | |
| 586 | + | |
| 587 | +void_t ParsePrefixNalUnit ( PWelsDecoderContext pCtx, PBitStringAux pBs ) | |
| 588 | +{ | |
| 589 | + PNalUnit pCurNal = &pCtx->sPrefixNal; | |
| 590 | + | |
| 591 | + if ( pCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc != 0 ){ | |
| 592 | + PNalUnitHeaderExt head_ext = &pCurNal->sNalHeaderExt; | |
| 593 | + PPrefixNalUnit sPrefixNal = &pCurNal->sNalData.sPrefixNal; | |
| 594 | + sPrefixNal->bStoreRefBasePicFlag = !!BsGetOneBit( pBs ); | |
| 595 | + if ( (head_ext->bUseRefBasePicFlag || sPrefixNal->bStoreRefBasePicFlag) && !head_ext->bIdrFlag ) | |
| 596 | + { | |
| 597 | + ParseRefBasePicMarking ( pBs, &sPrefixNal->sRefPicBaseMarking ); | |
| 598 | + } | |
| 599 | + sPrefixNal->bPrefixNalUnitAdditionalExtFlag = !!BsGetOneBit( pBs ); | |
| 600 | + if ( sPrefixNal->bPrefixNalUnitAdditionalExtFlag ){ | |
| 601 | + sPrefixNal->bPrefixNalUnitExtFlag = !!BsGetOneBit( pBs ); | |
| 602 | + } | |
| 603 | + } | |
| 604 | +} | |
| 605 | + | |
| 606 | + | |
| 607 | +int32_t DecodeSpsSvcExt( PWelsDecoderContext pCtx, PSubsetSps pSpsExt, PBitStringAux pBs ) | |
| 608 | +{ | |
| 609 | + PSpsSvcExt pExt = NULL; | |
| 610 | + uint8_t uiChromaArrayType = 1; | |
| 611 | + | |
| 612 | + pExt = &pSpsExt->sSpsSvcExt; | |
| 613 | + | |
| 614 | + pExt->bInterLayerDeblockingFilterCtrlPresentFlag = !!BsGetOneBit( pBs ); | |
| 615 | + pExt->uiExtendedSpatialScalability = BsGetBits( pBs, 2 ); | |
| 616 | + if ( pExt->uiExtendedSpatialScalability > 2 ) | |
| 617 | + { | |
| 618 | + WelsLog(pCtx, WELS_LOG_WARNING, "DecodeSpsSvcExt():extended_spatial_scalability (%d) != 0, ESS not supported!\n", pExt->uiExtendedSpatialScalability); | |
| 619 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_ESS); | |
| 620 | + } | |
| 621 | + | |
| 622 | + pExt->uiChromaPhaseXPlus1Flag = 0; // FIXME: Incoherent with JVT X201 standard (= 1), but conformance to JSVM (= 0) implementation. | |
| 623 | + pExt->uiChromaPhaseYPlus1 = 1; | |
| 624 | + uiChromaArrayType = pSpsExt->sSps.uiChromaArrayType; | |
| 625 | + | |
| 626 | + pExt->uiChromaPhaseXPlus1Flag = BsGetOneBit( pBs ); | |
| 627 | + pExt->uiChromaPhaseYPlus1 = BsGetBits( pBs, 2 ); | |
| 628 | + | |
| 629 | + pExt->uiSeqRefLayerChromaPhaseXPlus1Flag = pExt->uiChromaPhaseXPlus1Flag; | |
| 630 | + pExt->uiSeqRefLayerChromaPhaseYPlus1 = pExt->uiChromaPhaseYPlus1; | |
| 631 | + memset(&pExt->sSeqScaledRefLayer, 0, sizeof(SPosOffset)); | |
| 632 | + | |
| 633 | + if ( pExt->uiExtendedSpatialScalability == 1 ){ | |
| 634 | + SPosOffset* const kpPos = &pExt->sSeqScaledRefLayer; | |
| 635 | + pExt->uiSeqRefLayerChromaPhaseXPlus1Flag = BsGetOneBit( pBs ); | |
| 636 | + pExt->uiSeqRefLayerChromaPhaseYPlus1 = BsGetBits( pBs, 2 ); | |
| 637 | + | |
| 638 | + kpPos->iLeftOffset = BsGetSe( pBs ); | |
| 639 | + kpPos->iTopOffset = BsGetSe( pBs ); | |
| 640 | + kpPos->iRightOffset = BsGetSe( pBs ); | |
| 641 | + kpPos->iBottomOffset= BsGetSe( pBs ); | |
| 642 | + } | |
| 643 | + | |
| 644 | + pExt->bSeqTCoeffLevelPredFlag = !!BsGetOneBit( pBs ); | |
| 645 | + pExt->bAdaptiveTCoeffLevelPredFlag = false; | |
| 646 | + if ( pExt->bSeqTCoeffLevelPredFlag ) | |
| 647 | + pExt->bAdaptiveTCoeffLevelPredFlag = !!BsGetOneBit( pBs ); | |
| 648 | + pExt->bSliceHeaderRestrictionFlag = !!BsGetOneBit( pBs ); | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + return 0; | |
| 653 | +} | |
| 654 | + | |
| 655 | +/*! | |
| 656 | + ************************************************************************************* | |
| 657 | + * \brief to parse Sequence Parameter Set (SPS) | |
| 658 | + * | |
| 659 | + * \param pCtx Decoder context | |
| 660 | + * \param pBsAux bitstream reader auxiliary | |
| 661 | + * \param pPicWidth picture width current Sps represented | |
| 662 | + * \param pPicHeight picture height current Sps represented | |
| 663 | + * | |
| 664 | + * \return 0 - successed | |
| 665 | + * 1 - failed | |
| 666 | + * | |
| 667 | + * \note Call it in case eNalUnitType is SPS. | |
| 668 | + ************************************************************************************* | |
| 669 | + */ | |
| 670 | + | |
| 671 | + | |
| 672 | +int32_t ParseSps( PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t *pPicWidth, int32_t *pPicHeight ) | |
| 673 | +{ | |
| 674 | + PBitStringAux pBs = pBsAux; | |
| 675 | + PSps pSps = NULL; | |
| 676 | + PSubsetSps pSubsetSps = NULL; | |
| 677 | + SNalUnitHeader *pNalHead= &pCtx->sCurNalHead; | |
| 678 | + ProfileIdc uiProfileIdc; | |
| 679 | + uint8_t uiLevelIdc; | |
| 680 | + int32_t iSpsId; | |
| 681 | + bool_t bConstraintSetFlags[6] = { false }; | |
| 682 | + const bool_t kbUseSubsetFlag = IS_SUBSET_SPS_NAL(pNalHead->eNalUnitType); | |
| 683 | + | |
| 684 | + | |
| 685 | + if ( kbUseSubsetFlag ) // SubsetSps | |
| 686 | + { | |
| 687 | + pCtx->bSubspsExistAheadFlag = true; | |
| 688 | + } | |
| 689 | + else // Sps | |
| 690 | + { | |
| 691 | + pCtx->bSpsExistAheadFlag = true; | |
| 692 | + | |
| 693 | + // added for EC, 10/28/2009 | |
| 694 | + // for safe | |
| 695 | + memset( &pCtx->bSpsAvailFlags[0], 0, sizeof(pCtx->bSpsAvailFlags) ); | |
| 696 | + memset( &pCtx->bSubspsAvailFlags[0], 0, sizeof(pCtx->bSubspsAvailFlags) ); | |
| 697 | + memset( &pCtx->bPpsAvailFlags[0], 0, sizeof(pCtx->bPpsAvailFlags) ); | |
| 698 | + | |
| 699 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 700 | + pCtx->iSpsTotalNum = 0; | |
| 701 | + pCtx->iSubspsTotalNum = 0; | |
| 702 | + pCtx->iPpsTotalNum = 0; | |
| 703 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 704 | + } | |
| 705 | + | |
| 706 | + uiProfileIdc = BsGetBits( pBs, 8 ); | |
| 707 | + bConstraintSetFlags[0] = !!BsGetOneBit( pBs ); // constraint_set0_flag | |
| 708 | + bConstraintSetFlags[1] = !!BsGetOneBit( pBs ); // constraint_set1_flag | |
| 709 | + bConstraintSetFlags[2] = !!BsGetOneBit( pBs ); // constraint_set2_flag | |
| 710 | + bConstraintSetFlags[3] = !!BsGetOneBit( pBs ); // constraint_set3_flag | |
| 711 | + bConstraintSetFlags[4] = !!BsGetOneBit( pBs ); // constraint_set4_flag | |
| 712 | + bConstraintSetFlags[5] = !!BsGetOneBit( pBs ); // constraint_set5_flag | |
| 713 | + BsGetBits( pBs, 2 ); // reserved_zero_2bits, equal to 0 | |
| 714 | + uiLevelIdc = BsGetBits( pBs, 8 ); // level_idc | |
| 715 | + | |
| 716 | + iSpsId = BsGetUe( pBs ); // seq_parameter_set_id | |
| 717 | + | |
| 718 | + | |
| 719 | + if ( iSpsId >= MAX_SPS_COUNT || iSpsId < 0 ) // Modified to check invalid negative iSpsId, 12/1/2009 | |
| 720 | + { | |
| 721 | + WelsLog( pCtx, WELS_LOG_WARNING, " iSpsId is out of range! \n"); | |
| 722 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_SPS_ID_OVERFLOW); | |
| 723 | + } | |
| 724 | + | |
| 725 | + if ( kbUseSubsetFlag ) | |
| 726 | + { | |
| 727 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 728 | + pSubsetSps = &pCtx->sSubsetSpsBuffer[pCtx->iSubspsTotalNum]; | |
| 729 | + pCtx->bSubspsAvailFlags[pCtx->iSubspsTotalNum] = true; | |
| 730 | + | |
| 731 | + pSubsetSps->sSps.iSpsId = iSpsId; | |
| 732 | + pSps = &pSubsetSps->sSps; | |
| 733 | + ++pCtx->iSubspsTotalNum; | |
| 734 | +#else | |
| 735 | + pSubsetSps = &pCtx->sSubsetSpsBuffer[iSpsId]; | |
| 736 | + pSps = &pSubsetSps->sSps; | |
| 737 | + pCtx->bSubspsAvailFlags[iSpsId] = true; // added for EC, 10/28/2009 | |
| 738 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 739 | + } | |
| 740 | + else | |
| 741 | + { | |
| 742 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 743 | + pSps = &pCtx->sSpsBuffer[pCtx->iSpsTotalNum]; | |
| 744 | + pCtx->bSpsAvailFlags[pCtx->iSpsTotalNum] = true; | |
| 745 | + | |
| 746 | + pSps->iSpsId = iSpsId; | |
| 747 | + ++pCtx->iSpsTotalNum; | |
| 748 | +#else | |
| 749 | + pSps = &pCtx->sSpsBuffer[iSpsId]; | |
| 750 | + pCtx->bSpsAvailFlags[iSpsId] = true; // added for EC, 10/28/2009 | |
| 751 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 752 | + } | |
| 753 | + | |
| 754 | + // syntax elements in default | |
| 755 | + pSps->uiChromaFormatIdc = 1; | |
| 756 | + pSps->uiBitDepthLuma = | |
| 757 | + pSps->uiBitDepthChroma = 8; | |
| 758 | + | |
| 759 | + pSps->uiProfileIdc = uiProfileIdc; | |
| 760 | + pSps->uiLevelIdc = uiLevelIdc; | |
| 761 | + pSps->iSpsId = iSpsId; | |
| 762 | + | |
| 763 | + if ( PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc || | |
| 764 | + PRO_HIGH == uiProfileIdc || PRO_HIGH10 == uiProfileIdc || | |
| 765 | + PRO_HIGH422 == uiProfileIdc || PRO_HIGH444 == uiProfileIdc || | |
| 766 | + PRO_CAVLC444 == uiProfileIdc || 44 == uiProfileIdc ){ | |
| 767 | + | |
| 768 | + pSps->uiChromaFormatIdc = BsGetUe( pBs ); | |
| 769 | + if( pSps->uiChromaFormatIdc != 1 ) | |
| 770 | + { | |
| 771 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): chroma_format_idc (%d) = 1 supported.\n", pSps->uiChromaFormatIdc); | |
| 772 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | |
| 773 | + } | |
| 774 | + pSps->uiChromaArrayType = pSps->uiChromaFormatIdc; | |
| 775 | + pSps->uiBitDepthLuma = 8 + BsGetUe( pBs ); | |
| 776 | + if( pSps->uiBitDepthLuma != 8 ) | |
| 777 | + { | |
| 778 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): bit_depth_luma (%d) Only 8 bit supported.\n", pSps->uiBitDepthLuma); | |
| 779 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | |
| 780 | + } | |
| 781 | + | |
| 782 | + pSps->uiBitDepthChroma = 8 + BsGetUe( pBs ); | |
| 783 | + if( pSps->uiBitDepthChroma != 8 ) | |
| 784 | + { | |
| 785 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): bit_depth_chroma (%d). Only 8 bit supported.\n", pSps->uiBitDepthChroma); | |
| 786 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | |
| 787 | + } | |
| 788 | + pSps->bQpPrimeYZeroTransfBypassFlag = !!BsGetOneBit( pBs ); | |
| 789 | + pSps->bSeqScalingMatrixPresentFlag = !!BsGetOneBit( pBs ); | |
| 790 | + | |
| 791 | + if ( pSps->bSeqScalingMatrixPresentFlag ){ // For high profile, it is not used in current application. FIXME | |
| 792 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): seq_scaling_matrix_present_flag (%d). Feature not supported.\n", pSps->bSeqScalingMatrixPresentFlag); | |
| 793 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | |
| 794 | + } | |
| 795 | + } | |
| 796 | + | |
| 797 | + pSps->uiLog2MaxFrameNum = 4 + BsGetUe( pBs ); // log2_max_frame_num_minus4 | |
| 798 | + pSps->uiPocType = BsGetUe( pBs ); // pic_order_cnt_type | |
| 799 | + | |
| 800 | + if ( 0 == pSps->uiPocType ) | |
| 801 | + { | |
| 802 | + pSps->iLog2MaxPocLsb = 4 + BsGetUe( pBs ); // log2_max_pic_order_cnt_lsb_minus4 | |
| 803 | + | |
| 804 | + } | |
| 805 | + else if ( 1 == pSps->uiPocType ) | |
| 806 | + { | |
| 807 | + int32_t i; | |
| 808 | + pSps->bDeltaPicOrderAlwaysZeroFlag = !!BsGetOneBit( pBs ); // bDeltaPicOrderAlwaysZeroFlag | |
| 809 | + pSps->iOffsetForNonRefPic = BsGetSe( pBs ); // iOffsetForNonRefPic | |
| 810 | + pSps->iOffsetForTopToBottomField = BsGetSe( pBs ); // iOffsetForTopToBottomField | |
| 811 | + pSps->iNumRefFramesInPocCycle = BsGetUe( pBs ); // num_ref_frames_in_pic_order_cnt_cycle | |
| 812 | + for( i = 0; i < pSps->iNumRefFramesInPocCycle; i++ ) | |
| 813 | + pSps->iOffsetForRefFrame[ i ] = BsGetSe( pBs ); // iOffsetForRefFrame[ i ] | |
| 814 | + } | |
| 815 | + if ( pSps->uiPocType > 2 ) | |
| 816 | + { | |
| 817 | + WelsLog( pCtx, WELS_LOG_WARNING, " illegal pic_order_cnt_type: %d ! \n", pSps->uiPocType ); | |
| 818 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_POC_TYPE); | |
| 819 | + } | |
| 820 | + | |
| 821 | + pSps->iNumRefFrames = BsGetUe( pBs ); // max_num_ref_frames | |
| 822 | + pSps->bGapsInFrameNumValueAllowedFlag = !!BsGetOneBit( pBs ); // bGapsInFrameNumValueAllowedFlag | |
| 823 | + pSps->iMbWidth = 1 + BsGetUe( pBs ); // pic_width_in_mbs_minus1 | |
| 824 | + pSps->iMbHeight = 1 + BsGetUe( pBs ); // pic_height_in_map_units_minus1 | |
| 825 | + pSps->uiTotalMbCount = pSps->iMbWidth * pSps->iMbHeight; | |
| 826 | + pSps->bFrameMbsOnlyFlag = !!BsGetOneBit( pBs ); // frame_mbs_only_flag | |
| 827 | + | |
| 828 | + if ( !pSps->bFrameMbsOnlyFlag ) | |
| 829 | + { | |
| 830 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): frame_mbs_only_flag (%d) not supported.\n", pSps->bFrameMbsOnlyFlag); | |
| 831 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_MBAFF); | |
| 832 | + } | |
| 833 | + pSps->bDirect8x8InferenceFlag = !!BsGetOneBit( pBs ); // direct_8x8_inference_flag | |
| 834 | + pSps->bFrameCroppingFlag = !!BsGetOneBit( pBs ); // frame_cropping_flag | |
| 835 | + if ( pSps->bFrameCroppingFlag ) | |
| 836 | + { | |
| 837 | + pSps->sFrameCrop.iLeftOffset = BsGetUe( pBs ); // frame_crop_left_offset | |
| 838 | + pSps->sFrameCrop.iRightOffset = BsGetUe( pBs ); // frame_crop_right_offset | |
| 839 | + pSps->sFrameCrop.iTopOffset = BsGetUe( pBs ); // frame_crop_top_offset | |
| 840 | + pSps->sFrameCrop.iBottomOffset = BsGetUe( pBs ); // frame_crop_bottom_offset | |
| 841 | + } | |
| 842 | + else | |
| 843 | + { | |
| 844 | + pSps->sFrameCrop.iLeftOffset = 0; // frame_crop_left_offset | |
| 845 | + pSps->sFrameCrop.iRightOffset = 0; // frame_crop_right_offset | |
| 846 | + pSps->sFrameCrop.iTopOffset = 0; // frame_crop_top_offset | |
| 847 | + pSps->sFrameCrop.iBottomOffset = 0; // frame_crop_bottom_offset | |
| 848 | + } | |
| 849 | + pSps->bVuiParamPresentFlag = !!BsGetOneBit( pBs ); // vui_parameters_present_flag | |
| 850 | + | |
| 851 | + // Check if SPS SVC extension applicated | |
| 852 | + if ( kbUseSubsetFlag && ( PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc ) ) | |
| 853 | + { | |
| 854 | + if ( DecodeSpsSvcExt( pCtx, pSubsetSps, pBs ) != ERR_NONE ){ | |
| 855 | + return -1; | |
| 856 | + } | |
| 857 | + | |
| 858 | + pSubsetSps->bSvcVuiParamPresentFlag = !!BsGetOneBit( pBs ); | |
| 859 | + if ( pSubsetSps->bSvcVuiParamPresentFlag ){ | |
| 860 | + } | |
| 861 | + } | |
| 862 | + | |
| 863 | + | |
| 864 | + if ( PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc ) | |
| 865 | + pCtx->bAvcBasedFlag = false; | |
| 866 | + else | |
| 867 | + pCtx->bAvcBasedFlag = true; // added for avc base pBs | |
| 868 | + | |
| 869 | + *pPicWidth = pSps->iMbWidth << 4; | |
| 870 | + *pPicHeight = pSps->iMbHeight << 4; | |
| 871 | + | |
| 872 | + return 0; | |
| 873 | +} | |
| 874 | + | |
| 875 | +/*! | |
| 876 | + ************************************************************************************* | |
| 877 | + * \brief to parse Picture Parameter Set (PPS) | |
| 878 | + * | |
| 879 | + * \param pCtx Decoder context | |
| 880 | + * \param pPpsList pps list | |
| 881 | + * \param pBsAux bitstream reader auxiliary | |
| 882 | + * | |
| 883 | + * \return 0 - successed | |
| 884 | + * 1 - failed | |
| 885 | + * | |
| 886 | + * \note Call it in case eNalUnitType is PPS. | |
| 887 | + ************************************************************************************* | |
| 888 | + */ | |
| 889 | +int32_t ParsePps( PWelsDecoderContext pCtx, PPps pPpsList, PBitStringAux pBsAux ) | |
| 890 | +{ | |
| 891 | + | |
| 892 | + PPps pPps = NULL; | |
| 893 | + uint32_t uiPpsId = 0; | |
| 894 | + uint32_t iTmp; | |
| 895 | + | |
| 896 | + uiPpsId = BsGetUe(pBsAux); | |
| 897 | + if ( uiPpsId >= MAX_PPS_COUNT ) | |
| 898 | + { | |
| 899 | + return ERR_INFO_PPS_ID_OVERFLOW; | |
| 900 | + } | |
| 901 | + | |
| 902 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 903 | + pPps = &pPpsList[pCtx->iPpsTotalNum]; | |
| 904 | +#else | |
| 905 | + pPps = &pPpsList[uiPpsId]; | |
| 906 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 907 | + | |
| 908 | + | |
| 909 | + pPps->iPpsId = uiPpsId; | |
| 910 | + pPps->iSpsId = BsGetUe(pBsAux); | |
| 911 | + | |
| 912 | + if (pPps->iSpsId >= MAX_SPS_COUNT) | |
| 913 | + { | |
| 914 | + return ERR_INFO_SPS_ID_OVERFLOW; | |
| 915 | + } | |
| 916 | + | |
| 917 | + pPps->bEntropyCodingModeFlag = !!BsGetOneBit(pBsAux); | |
| 918 | + pPps->bPicOrderPresentFlag = !!BsGetOneBit(pBsAux); | |
| 919 | + | |
| 920 | + pPps->uiNumSliceGroups = 1 + BsGetUe(pBsAux); | |
| 921 | + | |
| 922 | + if (pPps->uiNumSliceGroups > MAX_SLICEGROUP_IDS) | |
| 923 | + { | |
| 924 | + return ERR_INFO_INVALID_SLICEGROUP; | |
| 925 | + } | |
| 926 | + | |
| 927 | + if (pPps->uiNumSliceGroups > 1) | |
| 928 | + { | |
| 929 | + pPps->uiSliceGroupMapType = BsGetUe(pBsAux); | |
| 930 | + if( pPps->uiSliceGroupMapType > 1) | |
| 931 | + { | |
| 932 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParsePps(): slice_group_map_type (%d): support only 0,1.\n", pPps->uiSliceGroupMapType); | |
| 933 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_FMOTYPE); | |
| 934 | + } | |
| 935 | + | |
| 936 | + switch(pPps->uiSliceGroupMapType) | |
| 937 | + { | |
| 938 | + case 0: | |
| 939 | + for (iTmp = 0; iTmp < pPps->uiNumSliceGroups; iTmp++) | |
| 940 | + { | |
| 941 | + pPps->uiRunLength[iTmp] = 1 + BsGetUe(pBsAux); | |
| 942 | + } | |
| 943 | + break; | |
| 944 | + default: | |
| 945 | + break; | |
| 946 | + } | |
| 947 | + } | |
| 948 | + | |
| 949 | + pPps->uiNumRefIdxL0Active = 1 + BsGetUe(pBsAux); | |
| 950 | + pPps->uiNumRefIdxL1Active = 1 + BsGetUe(pBsAux); | |
| 951 | + | |
| 952 | + if (pPps->uiNumRefIdxL0Active > MAX_REF_PIC_COUNT || | |
| 953 | + pPps->uiNumRefIdxL1Active > MAX_REF_PIC_COUNT) | |
| 954 | + { | |
| 955 | + return ERR_INFO_REF_COUNT_OVERFLOW; | |
| 956 | + } | |
| 957 | + | |
| 958 | + pPps->bWeightedPredFlag = !!BsGetOneBit(pBsAux); | |
| 959 | + pPps->uiWeightedBipredIdc = BsGetBits(pBsAux, 2); | |
| 960 | + if( pPps->bWeightedPredFlag || pPps->uiWeightedBipredIdc != 0 ) | |
| 961 | + { | |
| 962 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParsePps(): weighted_pred_flag (%d) weighted_bipred_idc (%d) neither supported.\n", pPps->bWeightedPredFlag, pPps->uiWeightedBipredIdc); | |
| 963 | + return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_WP); | |
| 964 | + } | |
| 965 | + | |
| 966 | + pPps->iPicInitQp = 26 + BsGetSe(pBsAux); | |
| 967 | + pPps->iPicInitQs = 26 + BsGetSe(pBsAux); | |
| 968 | + | |
| 969 | + pPps->iChromaQpIndexOffset = BsGetSe(pBsAux); | |
| 970 | + pPps->bDeblockingFilterControlPresentFlag = !!BsGetOneBit(pBsAux); | |
| 971 | + pPps->bConstainedIntraPredFlag = !!BsGetOneBit(pBsAux); | |
| 972 | + pPps->bRedundantPicCntPresentFlag = !!BsGetOneBit(pBsAux); | |
| 973 | + | |
| 974 | + | |
| 975 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 976 | + pCtx->bPpsAvailFlags[pCtx->iPpsTotalNum] = true; | |
| 977 | + ++pCtx->iPpsTotalNum; | |
| 978 | +#else | |
| 979 | + pCtx->bPpsAvailFlags[uiPpsId] = true; // added for EC, 10/28/2009 | |
| 980 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 981 | + | |
| 982 | + return ERR_NONE; | |
| 983 | +} | |
| 984 | + | |
| 985 | +/*! | |
| 986 | + ************************************************************************************* | |
| 987 | + * \brief to parse SEI message payload | |
| 988 | + * | |
| 989 | + * \param pSei sei message to be parsed output | |
| 990 | + * \param pBsAux bitstream reader auxiliary | |
| 991 | + * | |
| 992 | + * \return 0 - successed | |
| 993 | + * 1 - failed | |
| 994 | + * | |
| 995 | + * \note Call it in case eNalUnitType is NAL_UNIT_SEI. | |
| 996 | + ************************************************************************************* | |
| 997 | + */ | |
| 998 | +int32_t ParseSei( void_t *pSei, PBitStringAux pBsAux ) // reserved Sei_Msg type | |
| 999 | +{ | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + return ERR_NONE; | |
| 1003 | +} | |
| 1004 | + | |
| 1005 | +/*! | |
| 1006 | + ************************************************************************************* | |
| 1007 | + * \brief reset fmo list due to got Sps now | |
| 1008 | + * | |
| 1009 | + * \param pCtx decoder context | |
| 1010 | + * | |
| 1011 | + * \return count number of fmo context units are reset | |
| 1012 | + ************************************************************************************* | |
| 1013 | + */ | |
| 1014 | +int32_t ResetFmoList( PWelsDecoderContext pCtx ) | |
| 1015 | +{ | |
| 1016 | + int32_t iCountNum = 0; | |
| 1017 | + if ( NULL != pCtx ) | |
| 1018 | + { | |
| 1019 | + // Fixed memory leak due to PPS_ID might not be continuous sometimes, 1/5/2010 | |
| 1020 | + UninitFmoList( &pCtx->sFmoList[0], MAX_PPS_COUNT, pCtx->iActiveFmoNum ); | |
| 1021 | + iCountNum = pCtx->iActiveFmoNum; | |
| 1022 | + pCtx->iActiveFmoNum = 0; | |
| 1023 | + } | |
| 1024 | + return iCountNum; | |
| 1025 | +} | |
| 1026 | + | |
| 1027 | +} // namespace WelsDec | |
| @@ -0,0 +1,123 @@ | ||
| 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 bit_stream.cpp | |
| 33 | + * | |
| 34 | + * \brief Reading / writing bit-stream | |
| 35 | + * | |
| 36 | + * \date 03/10/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#include "bit_stream.h" | |
| 41 | +#include "macros.h" | |
| 42 | + | |
| 43 | +namespace WelsDec { | |
| 44 | + | |
| 45 | +#ifdef WORDS_BIGENDIAN | |
| 46 | +inline uint32_t EndianFix(uint32_t uiX) | |
| 47 | +{ | |
| 48 | + return uiX; | |
| 49 | +} | |
| 50 | +#else //WORDS_BIGENDIAN | |
| 51 | + | |
| 52 | +#ifdef _MSC_VER | |
| 53 | +inline uint32_t EndianFix(uint32_t uiX) | |
| 54 | +{ | |
| 55 | + __asm | |
| 56 | + { | |
| 57 | + mov eax, uiX | |
| 58 | + bswap eax | |
| 59 | + mov uiX, eax | |
| 60 | + } | |
| 61 | + return uiX; | |
| 62 | +} | |
| 63 | +#else //_MSC_VER | |
| 64 | + | |
| 65 | +inline uint32_t EndianFix(uint32_t uiX) | |
| 66 | +{ | |
| 67 | +#ifdef ARM_ARCHv7 | |
| 68 | + __asm__ __volatile__("rev %0, %0":"+r"(uiX)); //Just for the ARMv7 | |
| 69 | +#elif defined (X86_ARCH) | |
| 70 | + __asm__ __volatile__("bswap %0":"+r"(uiX)); | |
| 71 | +#else | |
| 72 | + uiX = ((uiX & 0xff000000)>> 24) | ((uiX & 0xff0000) >> 8) | | |
| 73 | + ((uiX & 0xff00) << 8) | ((uiX&0xff) << 24); | |
| 74 | +#endif | |
| 75 | + return uiX; | |
| 76 | +} | |
| 77 | +#endif //_MSC_VER | |
| 78 | + | |
| 79 | +#endif //WORDS_BIGENDIAN | |
| 80 | + | |
| 81 | +inline uint32_t GetValue4Bytes( uint8_t* pDstNal ) | |
| 82 | +{ | |
| 83 | + uint32_t uiValue = 0; | |
| 84 | + uiValue = (pDstNal[0]<<24) | (pDstNal[1]<<16) | (pDstNal[2]<<8) | (pDstNal[3]); | |
| 85 | + return uiValue; | |
| 86 | +} | |
| 87 | + | |
| 88 | +void_t InitReadBits( PBitStringAux pBitString ) | |
| 89 | +{ | |
| 90 | + pBitString->uiCurBits = GetValue4Bytes( pBitString->pCurBuf ); | |
| 91 | + pBitString->pCurBuf += 4; | |
| 92 | + pBitString->iLeftBits = -16; | |
| 93 | +} | |
| 94 | + | |
| 95 | +/*! | |
| 96 | + * \brief input bits for decoder or initialize bitstream writing in encoder | |
| 97 | + * | |
| 98 | + * \param pBitString Bit string auxiliary pointer | |
| 99 | + * \param kpBuf bit-stream buffer | |
| 100 | + * \param kiSize size in bits for decoder; size in bytes for encoder | |
| 101 | + * | |
| 102 | + * \return size of buffer data in byte; failed in -1 return | |
| 103 | + */ | |
| 104 | +int32_t InitBits( PBitStringAux pBitString, const uint8_t *kpBuf, const int32_t kiSize ) | |
| 105 | +{ | |
| 106 | + const int32_t kiSizeBuf = (kiSize + 7) >> 3; | |
| 107 | + uint8_t *pTmp = (uint8_t *)kpBuf; | |
| 108 | + | |
| 109 | + if ( NULL == pTmp ) | |
| 110 | + return -1; | |
| 111 | + | |
| 112 | + pBitString->pStartBuf = pTmp; // buffer to start position | |
| 113 | + pBitString->pEndBuf = pTmp + kiSizeBuf; // buffer + length | |
| 114 | + pBitString->iBits = kiSize; // count bits of overall bitstreaming inputindex; | |
| 115 | + | |
| 116 | + pBitString->pCurBuf = pBitString->pStartBuf; | |
| 117 | + InitReadBits( pBitString ); | |
| 118 | + | |
| 119 | + return kiSizeBuf; | |
| 120 | +} | |
| 121 | + | |
| 122 | +} // namespace WelsDec | |
| 123 | + | |
| @@ -0,0 +1,211 @@ | ||
| 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 cpu.cpp | |
| 33 | + * | |
| 34 | + * \brief CPU compatibility detection | |
| 35 | + * | |
| 36 | + * \date 04/29/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#include <string.h> | |
| 41 | + | |
| 42 | +#include "cpu.h" | |
| 43 | +#include "cpu_core.h" | |
| 44 | + | |
| 45 | +namespace WelsDec { | |
| 46 | + | |
| 47 | +#define CPU_Vender_AMD "AuthenticAMD" | |
| 48 | +#define CPU_Vender_INTEL "GenuineIntel" | |
| 49 | +#define CPU_Vender_CYRIX "CyrixInstead" | |
| 50 | + | |
| 51 | +#if defined(X86_ASM) | |
| 52 | + | |
| 53 | +uint32_t WelsCPUFeatureDetect( int32_t *pNumberOfLogicProcessors ) | |
| 54 | +{ | |
| 55 | + uint32_t uiCPU = 0; | |
| 56 | + uint32_t uiFeatureA = 0, uiFeatureB = 0, uiFeatureC = 0, uiFeatureD = 0; | |
| 57 | + int32_t CacheLineSize = 0; | |
| 58 | + int8_t chVenderName[16] = { 0 }; | |
| 59 | + | |
| 60 | + if( !WelsCPUIdVerify() ) | |
| 61 | + { | |
| 62 | + /* cpuid is not supported in cpu */ | |
| 63 | + return 0; | |
| 64 | + } | |
| 65 | + | |
| 66 | + WelsCPUId( 0, &uiFeatureA, (uint32_t*)&chVenderName[0],(uint32_t*)&chVenderName[8],(uint32_t*)&chVenderName[4] ); | |
| 67 | + if( uiFeatureA == 0 ) | |
| 68 | + { | |
| 69 | + /* maximum input value for basic cpuid information */ | |
| 70 | + return 0; | |
| 71 | + } | |
| 72 | + | |
| 73 | + WelsCPUId( 1, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD ); | |
| 74 | + if( (uiFeatureD & 0x00800000) == 0 ) | |
| 75 | + { | |
| 76 | + /* Basic MMX technology is not support in cpu, mean nothing for us so return here */ | |
| 77 | + return 0; | |
| 78 | + } | |
| 79 | + | |
| 80 | + uiCPU = WELS_CPU_MMX; | |
| 81 | + if( uiFeatureD & 0x02000000 ) | |
| 82 | + { | |
| 83 | + /* SSE technology is identical to AMD MMX extensions */ | |
| 84 | + uiCPU |= WELS_CPU_MMXEXT|WELS_CPU_SSE; | |
| 85 | + } | |
| 86 | + if( uiFeatureD & 0x04000000 ) | |
| 87 | + { | |
| 88 | + /* SSE2 support here */ | |
| 89 | + uiCPU |= WELS_CPU_SSE2; | |
| 90 | + } | |
| 91 | + if ( uiFeatureD & 0x00000001 ) | |
| 92 | + { | |
| 93 | + /* x87 FPU on-chip checking */ | |
| 94 | + uiCPU |= WELS_CPU_FPU; | |
| 95 | + } | |
| 96 | + if ( uiFeatureD & 0x00008000 ) | |
| 97 | + { | |
| 98 | + /* CMOV instruction checking */ | |
| 99 | + uiCPU |= WELS_CPU_CMOV; | |
| 100 | + } | |
| 101 | + if ( !strcmp((const str_t*)chVenderName,CPU_Vender_INTEL) ) // confirmed_safe_unsafe_usage | |
| 102 | + { | |
| 103 | + if ( uiFeatureD & 0x10000000 ) | |
| 104 | + { | |
| 105 | + /* Multi-Threading checking: contains of multiple logic processors */ | |
| 106 | + uiCPU |= WELS_CPU_HTT; | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + if( uiFeatureC & 0x00000001 ){ | |
| 111 | + /* SSE3 support here */ | |
| 112 | + uiCPU |= WELS_CPU_SSE3; | |
| 113 | + } | |
| 114 | + if( uiFeatureC & 0x00000200 ){ | |
| 115 | + /* SSSE3 support here */ | |
| 116 | + uiCPU |= WELS_CPU_SSSE3; | |
| 117 | + } | |
| 118 | + if( uiFeatureC & 0x00080000 ){ | |
| 119 | + /* SSE4.1 support here, 45nm Penryn processor */ | |
| 120 | + uiCPU |= WELS_CPU_SSE41; | |
| 121 | + } | |
| 122 | + if( uiFeatureC & 0x00100000 ){ | |
| 123 | + /* SSE4.2 support here, next generation Nehalem processor */ | |
| 124 | + uiCPU |= WELS_CPU_SSE42; | |
| 125 | + } | |
| 126 | + if ( WelsCPUSupportAVX( uiFeatureA, uiFeatureC ) ) | |
| 127 | + { | |
| 128 | + /* AVX supported */ | |
| 129 | + uiCPU |= WELS_CPU_AVX; | |
| 130 | + } | |
| 131 | + if ( WelsCPUSupportFMA( uiFeatureA, uiFeatureC ) ) | |
| 132 | + { | |
| 133 | + /* AVX FMA supported */ | |
| 134 | + uiCPU |= WELS_CPU_FMA; | |
| 135 | + } | |
| 136 | + if ( uiFeatureC & 0x02000000 ) | |
| 137 | + { | |
| 138 | + /* AES checking */ | |
| 139 | + uiCPU |= WELS_CPU_AES; | |
| 140 | + } | |
| 141 | + if ( uiFeatureC & 0x00400000 ) | |
| 142 | + { | |
| 143 | + /* MOVBE checking */ | |
| 144 | + uiCPU |= WELS_CPU_MOVBE; | |
| 145 | + } | |
| 146 | + | |
| 147 | + if ( pNumberOfLogicProcessors != NULL ) | |
| 148 | + { | |
| 149 | + // HTT enabled on chip | |
| 150 | + *pNumberOfLogicProcessors = (uiFeatureB & 0x00ff0000) >> 16; // feature bits: 23-16 on returned EBX | |
| 151 | + } | |
| 152 | + | |
| 153 | + WelsCPUId( 0x80000000, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD ); | |
| 154 | + | |
| 155 | + if( (!strcmp((const str_t*)chVenderName,CPU_Vender_AMD)) && (uiFeatureA>=0x80000001) ){ // confirmed_safe_unsafe_usage | |
| 156 | + WelsCPUId(0x80000001, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD ); | |
| 157 | + if( uiFeatureD&0x00400000 ){ | |
| 158 | + uiCPU |= WELS_CPU_MMXEXT; | |
| 159 | + } | |
| 160 | + if( uiFeatureD&0x80000000 ){ | |
| 161 | + uiCPU |= WELS_CPU_3DNOW; | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 165 | + if( !strcmp((const str_t*)chVenderName,CPU_Vender_INTEL) ){ // confirmed_safe_unsafe_usage | |
| 166 | + int32_t family, model; | |
| 167 | + | |
| 168 | + WelsCPUId(1, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD); | |
| 169 | + family = ((uiFeatureA>>8)&0xf) + ((uiFeatureA>>20)&0xff); | |
| 170 | + model = ((uiFeatureA>>4)&0xf) + ((uiFeatureA>>12)&0xf0); | |
| 171 | + | |
| 172 | + if( (family==6) && (model==9 || model==13 || model==14) ){ | |
| 173 | + uiCPU &= ~(WELS_CPU_SSE2|WELS_CPU_SSE3); | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + // get cache line size | |
| 178 | + if( (!strcmp((const str_t*)chVenderName,CPU_Vender_INTEL)) || !(strcmp((const str_t*)chVenderName,CPU_Vender_CYRIX)) ){ // confirmed_safe_unsafe_usage | |
| 179 | + WelsCPUId(1, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD); | |
| 180 | + | |
| 181 | + CacheLineSize = (uiFeatureB&0xff00)>>5; // ((clflush_line_size >> 8) << 3), CLFLUSH_line_size * 8 = CacheLineSize_in_byte | |
| 182 | + | |
| 183 | + if( CacheLineSize == 128 ){ | |
| 184 | + uiCPU |= WELS_CPU_CACHELINE_128; | |
| 185 | + } | |
| 186 | + else if( CacheLineSize == 64 ){ | |
| 187 | + uiCPU |= WELS_CPU_CACHELINE_64; | |
| 188 | + } | |
| 189 | + else if( CacheLineSize == 32 ){ | |
| 190 | + uiCPU |= WELS_CPU_CACHELINE_32; | |
| 191 | + } | |
| 192 | + else if( CacheLineSize == 16 ){ | |
| 193 | + uiCPU |= WELS_CPU_CACHELINE_16; | |
| 194 | + } | |
| 195 | + } | |
| 196 | + | |
| 197 | + return uiCPU; | |
| 198 | +} | |
| 199 | + | |
| 200 | + | |
| 201 | +void WelsCPURestore( const uint32_t kuiCPU ) | |
| 202 | +{ | |
| 203 | + if( kuiCPU & (WELS_CPU_MMX|WELS_CPU_MMXEXT|WELS_CPU_3DNOW|WELS_CPU_3DNOWEXT) ) | |
| 204 | + { | |
| 205 | + WelsEmms(); | |
| 206 | + } | |
| 207 | +} | |
| 208 | + | |
| 209 | +#endif | |
| 210 | + | |
| 211 | +} // namespace WelsDec | |
| @@ -0,0 +1,1013 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2010-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 deblocking.c | |
| 33 | + * | |
| 34 | + * \brief Interfaces introduced in frame deblocking filtering | |
| 35 | + * | |
| 36 | + * \date 08/02/2010 | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | + | |
| 41 | +#include "deblocking.h" | |
| 42 | +#include "cpu_core.h" | |
| 43 | +#include "fmo.h" | |
| 44 | + | |
| 45 | +namespace WelsDec { | |
| 46 | + | |
| 47 | +#define NO_SUPPORTED_FILTER_IDX (-1) | |
| 48 | +#define LEFT_FLAG_BIT 0 | |
| 49 | +#define TOP_FLAG_BIT 1 | |
| 50 | +#define LEFT_FLAG_MASK 0x01 | |
| 51 | +#define TOP_FLAG_MASK 0x02 | |
| 52 | + | |
| 53 | +#define SAME_MB_DIFF_REFIDX | |
| 54 | +#define g_kuiAlphaTable(x) g_kuiAlphaTable[(x)+12] | |
| 55 | +#define g_kiBetaTable(x) g_kiBetaTable[(x)+12] | |
| 56 | +#define g_kiTc0Table(x) g_kiTc0Table[(x)+12] | |
| 57 | + | |
| 58 | +#define MB_BS_MV(iRefIndex, iMotionVector, iMbXy, iMbBn, iIndex, iNeighIndex) \ | |
| 59 | +(\ | |
| 60 | + ( iRefIndex[iMbXy][iIndex] - iRefIndex[iMbBn][iNeighIndex] )||\ | |
| 61 | + ( WELS_ABS( iMotionVector[iMbXy][iIndex][0] - iMotionVector[iMbBn][iNeighIndex][0] ) >= 4 ) ||\ | |
| 62 | + ( WELS_ABS( iMotionVector[iMbXy][iIndex][1] - iMotionVector[iMbBn][iNeighIndex][1] ) >= 4 )\ | |
| 63 | +) | |
| 64 | + | |
| 65 | +#if defined(SAME_MB_DIFF_REFIDX) | |
| 66 | +#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \ | |
| 67 | +(\ | |
| 68 | + ( iRefIndex[iIndex] - iRefIndex[iNeighIndex] )||(\ | |
| 69 | + ( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |\ | |
| 70 | + ( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\ | |
| 71 | +) | |
| 72 | +#else | |
| 73 | +#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \ | |
| 74 | +(\ | |
| 75 | + !!(( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\ | |
| 76 | +) | |
| 77 | +#endif | |
| 78 | + | |
| 79 | +#define BS_EDGE(bsx1, iRefIndex, iMotionVector, iIndex, iNeighIndex) \ | |
| 80 | +( (bsx1|SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex))<<((uint8_t)(!!bsx1))) | |
| 81 | + | |
| 82 | +#define GET_ALPHA_BETA_FROM_QP(iQp, iAlphaOffset, iBetaOffset, iIndex, iAlpha, iBeta) \ | |
| 83 | +{\ | |
| 84 | + iIndex = (iQp + iAlphaOffset);\ | |
| 85 | + iAlpha = g_kuiAlphaTable(iIndex);\ | |
| 86 | + iBeta = g_kiBetaTable((iQp + iBetaOffset));\ | |
| 87 | +} | |
| 88 | + | |
| 89 | +static const uint8_t g_kuiAlphaTable[52+24] = { //this table refers to Table 8-16 in H.264/AVC standard | |
| 90 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 91 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 92 | + 0, 0, 0, 0, 0, 0, 4, 4, 5, 6, | |
| 93 | + 7, 8, 9, 10, 12, 13, 15, 17, 20, 22, | |
| 94 | + 25, 28, 32, 36, 40, 45, 50, 56, 63, 71, | |
| 95 | + 80, 90,101,113,127,144,162,182,203,226, | |
| 96 | + 255, 255 | |
| 97 | + ,255, 255,255, 255,255, 255,255, 255,255, 255,255, 255 | |
| 98 | +}; | |
| 99 | + | |
| 100 | +static const int8_t g_kiBetaTable[52+24] = { //this table refers to Table 8-16 in H.264/AVC standard | |
| 101 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 102 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 103 | + 0, 0, 0, 0, 0, 0, 2, 2, 2, 3, | |
| 104 | + 3, 3, 3, 4, 4, 4, 6, 6, 7, 7, | |
| 105 | + 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, | |
| 106 | + 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, | |
| 107 | + 18, 18 | |
| 108 | + ,18, 18,18, 18,18, 18,18, 18,18, 18,18, 18 | |
| 109 | +}; | |
| 110 | + | |
| 111 | +static const int8_t g_kiTc0Table[52+24][4] = { //this table refers Table 8-17 in H.264/AVC standard | |
| 112 | + { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, | |
| 113 | + { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, | |
| 114 | + { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, | |
| 115 | + { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, | |
| 116 | + { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 1 }, | |
| 117 | + { -1, 0, 0, 1 }, { -1, 0, 0, 1 }, { -1, 0, 0, 1 }, { -1, 0, 1, 1 }, { -1, 0, 1, 1 }, { -1, 1, 1, 1 }, | |
| 118 | + { -1, 1, 1, 1 }, { -1, 1, 1, 1 }, { -1, 1, 1, 1 }, { -1, 1, 1, 2 }, { -1, 1, 1, 2 }, { -1, 1, 1, 2 }, | |
| 119 | + { -1, 1, 1, 2 }, { -1, 1, 2, 3 }, { -1, 1, 2, 3 }, { -1, 2, 2, 3 }, { -1, 2, 2, 4 }, { -1, 2, 3, 4 }, | |
| 120 | + { -1, 2, 3, 4 }, { -1, 3, 3, 5 }, { -1, 3, 4, 6 }, { -1, 3, 4, 6 }, { -1, 4, 5, 7 }, { -1, 4, 5, 8 }, | |
| 121 | + { -1, 4, 6, 9 }, { -1, 5, 7,10 }, { -1, 6, 8,11 }, { -1, 6, 8,13 }, { -1, 7,10,14 }, { -1, 8,11,16 }, | |
| 122 | + { -1, 9,12,18 }, { -1, 10,13,20 }, {-1,11,15,23 }, { -1,13,17,25 } | |
| 123 | + ,{ -1,13,17,25 },{ -1,13,17,25 },{ -1,13,17,25 },{ -1,13,17,25 },{ -1,13,17,25 },{ -1,13,17,25 } | |
| 124 | + ,{ -1,13,17,25 },{ -1,13,17,25 },{ -1,13,17,25 },{ -1,13,17,25 },{ -1,13,17,25 },{ -1,13,17,25 } | |
| 125 | +}; | |
| 126 | + | |
| 127 | +static const uint8_t g_kuiTableBIdx[2][8] = | |
| 128 | +{ | |
| 129 | + {0, 4, 8, 12, | |
| 130 | + 3, 7, 11, 15}, | |
| 131 | + | |
| 132 | + {0, 1, 2, 3 , | |
| 133 | + 12, 13, 14, 15}, | |
| 134 | +}; | |
| 135 | + | |
| 136 | +#define TC0_TBL_LOOKUP(tc, iIndexA, pBS, bChroma) \ | |
| 137 | +{\ | |
| 138 | + tc[0] = g_kiTc0Table(iIndexA)[pBS[0]] + bChroma;\ | |
| 139 | + tc[1] = g_kiTc0Table(iIndexA)[pBS[1]] + bChroma;\ | |
| 140 | + tc[2] = g_kiTc0Table(iIndexA)[pBS[2]] + bChroma;\ | |
| 141 | + tc[3] = g_kiTc0Table(iIndexA)[pBS[3]] + bChroma;\ | |
| 142 | +} | |
| 143 | + | |
| 144 | +void_t inline DeblockingBSInsideMBAvsbase( int8_t* pNnzTab, uint8_t nBS[2][4][4], int32_t iLShiftFactor ) | |
| 145 | +{ | |
| 146 | + uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3; | |
| 147 | + FORCE_STACK_ALIGN_1D( uint8_t, uiBsx3, 4, 4 ); | |
| 148 | + | |
| 149 | + uiNnz32b0 = *(uint32_t *)(pNnzTab+0); | |
| 150 | + uiNnz32b1 = *(uint32_t *)(pNnzTab+4); | |
| 151 | + uiNnz32b2 = *(uint32_t *)(pNnzTab+8); | |
| 152 | + uiNnz32b3 = *(uint32_t *)(pNnzTab+12); | |
| 153 | + | |
| 154 | + *(uint32_t *)uiBsx3 = (uiNnz32b0|(uiNnz32b0>>8))<<iLShiftFactor; | |
| 155 | + nBS[0][1][0] = uiBsx3[0]; | |
| 156 | + nBS[0][2][0] = uiBsx3[1]; | |
| 157 | + nBS[0][3][0] = uiBsx3[2]; | |
| 158 | + | |
| 159 | + *(uint32_t *)uiBsx3 = (uiNnz32b1|(uiNnz32b1>>8))<<iLShiftFactor; | |
| 160 | + nBS[0][1][1] = uiBsx3[0]; | |
| 161 | + nBS[0][2][1] = uiBsx3[1]; | |
| 162 | + nBS[0][3][1] = uiBsx3[2]; | |
| 163 | + *(uint32_t *)nBS[1][1] = (uiNnz32b0|uiNnz32b1)<<iLShiftFactor; | |
| 164 | + | |
| 165 | + *(uint32_t *)uiBsx3 = (uiNnz32b2|(uiNnz32b2>>8))<<iLShiftFactor; | |
| 166 | + nBS[0][1][2] = uiBsx3[0]; | |
| 167 | + nBS[0][2][2] = uiBsx3[1]; | |
| 168 | + nBS[0][3][2] = uiBsx3[2]; | |
| 169 | + *(uint32_t *)nBS[1][2] = (uiNnz32b1|uiNnz32b2)<<iLShiftFactor; | |
| 170 | + | |
| 171 | + *(uint32_t *)uiBsx3 = (uiNnz32b3|(uiNnz32b3>>8))<<iLShiftFactor; | |
| 172 | + nBS[0][1][3] = uiBsx3[0]; | |
| 173 | + nBS[0][2][3] = uiBsx3[1]; | |
| 174 | + nBS[0][3][3] = uiBsx3[2]; | |
| 175 | + *(uint32_t *)nBS[1][3] = (uiNnz32b2|uiNnz32b3)<<iLShiftFactor; | |
| 176 | + | |
| 177 | +} | |
| 178 | + | |
| 179 | +void_t static inline DeblockingBSInsideMBNormal( PDqLayer pCurDqLayer, uint8_t nBS[2][4][4], int8_t* pNnzTab, int32_t iMbXy ) | |
| 180 | +{ | |
| 181 | + uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3; | |
| 182 | + int8_t* iRefIndex = pCurDqLayer->pRefIndex[LIST_0][iMbXy]; | |
| 183 | + FORCE_STACK_ALIGN_1D( uint8_t, uiBsx4, 4, 4 ); | |
| 184 | + | |
| 185 | + uiNnz32b0 = *(uint32_t *)(pNnzTab+0); | |
| 186 | + uiNnz32b1 = *(uint32_t *)(pNnzTab+4); | |
| 187 | + uiNnz32b2 = *(uint32_t *)(pNnzTab+8); | |
| 188 | + uiNnz32b3 = *(uint32_t *)(pNnzTab+12); | |
| 189 | + | |
| 190 | + *(uint32_t *)uiBsx4 = (uiNnz32b0|(uiNnz32b0>>8)); | |
| 191 | + nBS[0][1][0] = BS_EDGE(uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 1, 0); | |
| 192 | + nBS[0][2][0] = BS_EDGE(uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 2, 1); | |
| 193 | + nBS[0][3][0] = BS_EDGE(uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 3, 2); | |
| 194 | + | |
| 195 | + *(uint32_t *)uiBsx4 = (uiNnz32b1|(uiNnz32b1>>8)); | |
| 196 | + nBS[0][1][1] = BS_EDGE(uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 5, 4); | |
| 197 | + nBS[0][2][1] = BS_EDGE(uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 6, 5); | |
| 198 | + nBS[0][3][1] = BS_EDGE(uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 7, 6); | |
| 199 | + | |
| 200 | + *(uint32_t *)uiBsx4 = (uiNnz32b2|(uiNnz32b2>>8)); | |
| 201 | + nBS[0][1][2] = BS_EDGE(uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 9, 8); | |
| 202 | + nBS[0][2][2] = BS_EDGE(uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 10,9); | |
| 203 | + nBS[0][3][2] = BS_EDGE(uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 11,10); | |
| 204 | + | |
| 205 | + *(uint32_t *)uiBsx4 = (uiNnz32b3|(uiNnz32b3>>8)); | |
| 206 | + nBS[0][1][3] = BS_EDGE(uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 13,12); | |
| 207 | + nBS[0][2][3] = BS_EDGE(uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 14,13); | |
| 208 | + nBS[0][3][3] = BS_EDGE(uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 15,14); | |
| 209 | + | |
| 210 | + // horizontal | |
| 211 | + *(uint32_t *)uiBsx4 = (uiNnz32b0|uiNnz32b1); | |
| 212 | + nBS[1][1][0] = BS_EDGE(uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 4, 0); | |
| 213 | + nBS[1][1][1] = BS_EDGE(uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 5, 1); | |
| 214 | + nBS[1][1][2] = BS_EDGE(uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 6, 2); | |
| 215 | + nBS[1][1][3] = BS_EDGE(uiBsx4[3], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 7, 3); | |
| 216 | + | |
| 217 | + *(uint32_t *)uiBsx4 = (uiNnz32b1|uiNnz32b2); | |
| 218 | + nBS[1][2][0] = BS_EDGE(uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 8, 4); | |
| 219 | + nBS[1][2][1] = BS_EDGE(uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 9, 5); | |
| 220 | + nBS[1][2][2] = BS_EDGE(uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 10, 6); | |
| 221 | + nBS[1][2][3] = BS_EDGE(uiBsx4[3], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 11, 7); | |
| 222 | + | |
| 223 | + *(uint32_t *)uiBsx4 = (uiNnz32b2|uiNnz32b3); | |
| 224 | + nBS[1][3][0] = BS_EDGE(uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 12, 8); | |
| 225 | + nBS[1][3][1] = BS_EDGE(uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 13, 9); | |
| 226 | + nBS[1][3][2] = BS_EDGE(uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 14, 10); | |
| 227 | + nBS[1][3][3] = BS_EDGE(uiBsx4[3], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 15, 11); | |
| 228 | +} | |
| 229 | + | |
| 230 | +uint32_t DeblockingBsMarginalMBAvcbase( PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy) | |
| 231 | +{ | |
| 232 | + int32_t i; | |
| 233 | + uint32_t uiBSx4; | |
| 234 | + //uint8_t* bS = static_cast<uint8_t*>(&uiBSx4); | |
| 235 | + uint8_t* pBS = (uint8_t*)(&uiBSx4); | |
| 236 | + uint32_t uiBIdx = *(uint32_t *)(&g_kuiTableBIdx[iEdge][0]); | |
| 237 | + uint32_t uiBnIdx = *(uint32_t *)(&g_kuiTableBIdx[iEdge][4]); | |
| 238 | + | |
| 239 | + for( i = 0; i < 4; i++ ) | |
| 240 | + { | |
| 241 | + if( pCurDqLayer->pNzc[iMbXy][uiBIdx&0xff] | pCurDqLayer->pNzc[iNeighMb][uiBnIdx&0xff] ) | |
| 242 | + { | |
| 243 | + pBS[i] = 2; | |
| 244 | + } | |
| 245 | + else | |
| 246 | + { | |
| 247 | + pBS[i] = MB_BS_MV(pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, (uiBIdx&0xff), (uiBnIdx&0xff)); | |
| 248 | + } | |
| 249 | + uiBIdx = uiBIdx >> 8; | |
| 250 | + uiBnIdx = uiBnIdx >> 8; | |
| 251 | + } | |
| 252 | + return uiBSx4; | |
| 253 | +} | |
| 254 | +int32_t DeblockingAvailableNoInterlayer( PDqLayer pCurDqLayer, int32_t iFilterIdc ) | |
| 255 | +{ | |
| 256 | + int32_t iMbY = pCurDqLayer->iMbY; | |
| 257 | + int32_t iMbX = pCurDqLayer->iMbX; | |
| 258 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 259 | + BOOL_T bLeftFlag = FALSE; | |
| 260 | + BOOL_T bTopFlag = FALSE; | |
| 261 | + | |
| 262 | + if ( 2 == iFilterIdc ) | |
| 263 | + { | |
| 264 | + bLeftFlag = ( iMbX > 0 ) && ( pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy-1] ); | |
| 265 | + bTopFlag = ( iMbY > 0 ) && ( pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy-pCurDqLayer->iMbWidth] ); | |
| 266 | + } | |
| 267 | + else //if ( 0 == iFilterIdc ) | |
| 268 | + { | |
| 269 | + bLeftFlag = ( iMbX > 0 ); | |
| 270 | + bTopFlag = ( iMbY > 0 ); | |
| 271 | + } | |
| 272 | + return (bLeftFlag<<LEFT_FLAG_BIT)|(bTopFlag<<TOP_FLAG_BIT); | |
| 273 | +} | |
| 274 | + | |
| 275 | +void_t FilteringEdgeLumaH(SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS ) | |
| 276 | +{ | |
| 277 | + int32_t iIndexA; | |
| 278 | + int32_t iAlpha; | |
| 279 | + int32_t iBeta; | |
| 280 | + FORCE_STACK_ALIGN_1D( int8_t, tc, 4, 16 ); | |
| 281 | + | |
| 282 | + GET_ALPHA_BETA_FROM_QP(pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 283 | + | |
| 284 | + if( iAlpha | iBeta ) | |
| 285 | + { | |
| 286 | + TC0_TBL_LOOKUP(tc, iIndexA, pBS, 0); | |
| 287 | + pFilter->pLoopf->pfLumaDeblockingLT4Ver(pPix, iStride, iAlpha, iBeta, tc); | |
| 288 | + } | |
| 289 | + return; | |
| 290 | +} | |
| 291 | + | |
| 292 | + | |
| 293 | +void_t FilteringEdgeLumaV(SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS ) | |
| 294 | +{ | |
| 295 | + int32_t iIndexA; | |
| 296 | + int32_t iAlpha; | |
| 297 | + int32_t iBeta; | |
| 298 | + FORCE_STACK_ALIGN_1D( int8_t, tc, 4, 16 ); | |
| 299 | + | |
| 300 | + GET_ALPHA_BETA_FROM_QP(pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 301 | + | |
| 302 | + if( iAlpha | iBeta ) | |
| 303 | + { | |
| 304 | + TC0_TBL_LOOKUP(tc, iIndexA, pBS, 0); | |
| 305 | + pFilter->pLoopf->pfLumaDeblockingLT4Hor(pPix, iStride, iAlpha, iBeta, tc); | |
| 306 | + } | |
| 307 | + return; | |
| 308 | +} | |
| 309 | + | |
| 310 | + | |
| 311 | +void_t FilteringEdgeLumaIntraH( SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS ) | |
| 312 | +{ | |
| 313 | + int32_t iIndexA; | |
| 314 | + int32_t iAlpha; | |
| 315 | + int32_t iBeta; | |
| 316 | + | |
| 317 | + GET_ALPHA_BETA_FROM_QP(pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 318 | + | |
| 319 | + if( iAlpha | iBeta ) | |
| 320 | + { | |
| 321 | + pFilter->pLoopf->pfLumaDeblockingEQ4Ver(pPix, iStride, iAlpha, iBeta); | |
| 322 | + } | |
| 323 | + return; | |
| 324 | +} | |
| 325 | + | |
| 326 | +void_t FilteringEdgeLumaIntraV( SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS ) | |
| 327 | +{ | |
| 328 | + int32_t iIndexA; | |
| 329 | + int32_t iAlpha; | |
| 330 | + int32_t iBeta; | |
| 331 | + | |
| 332 | + GET_ALPHA_BETA_FROM_QP(pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 333 | + | |
| 334 | + if( iAlpha | iBeta ) | |
| 335 | + { | |
| 336 | + pFilter->pLoopf->pfLumaDeblockingEQ4Hor(pPix, iStride, iAlpha, iBeta); | |
| 337 | + } | |
| 338 | + return; | |
| 339 | +} | |
| 340 | +void_t FilteringEdgeChromaH( SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, uint8_t* pBS ) | |
| 341 | +{ | |
| 342 | + int32_t iIndexA; | |
| 343 | + int32_t iAlpha; | |
| 344 | + int32_t iBeta; | |
| 345 | + FORCE_STACK_ALIGN_1D( int8_t, tc, 4, 16 ); | |
| 346 | + | |
| 347 | + GET_ALPHA_BETA_FROM_QP(pFilter->iChromaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 348 | + | |
| 349 | + if( iAlpha | iBeta ) | |
| 350 | + { | |
| 351 | + TC0_TBL_LOOKUP(tc, iIndexA, pBS, 1); | |
| 352 | + pFilter->pLoopf->pfChromaDeblockingLT4Ver(pPixCb, pPixCr, iStride,iAlpha, iBeta, tc); | |
| 353 | + } | |
| 354 | + return; | |
| 355 | +} | |
| 356 | +void_t FilteringEdgeChromaV( SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, uint8_t* pBS ) | |
| 357 | +{ | |
| 358 | + int32_t iIndexA; | |
| 359 | + int32_t iAlpha; | |
| 360 | + int32_t iBeta; | |
| 361 | + FORCE_STACK_ALIGN_1D( int8_t, tc, 4, 16 ); | |
| 362 | + | |
| 363 | + GET_ALPHA_BETA_FROM_QP(pFilter->iChromaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 364 | + | |
| 365 | + if( iAlpha | iBeta ) | |
| 366 | + { | |
| 367 | + TC0_TBL_LOOKUP(tc, iIndexA, pBS, 1); | |
| 368 | + pFilter->pLoopf->pfChromaDeblockingLT4Hor(pPixCb, pPixCr, iStride, iAlpha, iBeta, tc); | |
| 369 | + } | |
| 370 | + return; | |
| 371 | +} | |
| 372 | + | |
| 373 | +void_t FilteringEdgeChromaIntraH( SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, uint8_t* pBS ) | |
| 374 | +{ | |
| 375 | + int32_t iIndexA; | |
| 376 | + int32_t iAlpha; | |
| 377 | + int32_t iBeta; | |
| 378 | + | |
| 379 | + GET_ALPHA_BETA_FROM_QP(pFilter->iChromaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 380 | + | |
| 381 | + if( iAlpha | iBeta ) | |
| 382 | + { | |
| 383 | + pFilter->pLoopf->pfChromaDeblockingEQ4Ver(pPixCb, pPixCr, iStride, iAlpha, iBeta); | |
| 384 | + } | |
| 385 | + return; | |
| 386 | +} | |
| 387 | + | |
| 388 | +void_t FilteringEdgeChromaIntraV( SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, uint8_t* pBS ) | |
| 389 | +{ | |
| 390 | + int32_t iIndexA; | |
| 391 | + int32_t iAlpha; | |
| 392 | + int32_t iBeta; | |
| 393 | + | |
| 394 | + GET_ALPHA_BETA_FROM_QP(pFilter->iChromaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 395 | + | |
| 396 | + if( iAlpha | iBeta ) | |
| 397 | + { | |
| 398 | + pFilter->pLoopf->pfChromaDeblockinEQ4Hor(pPixCb, pPixCr, iStride, iAlpha, iBeta); | |
| 399 | + } | |
| 400 | + return; | |
| 401 | +} | |
| 402 | + | |
| 403 | + | |
| 404 | +void_t DeblockingInterMb( PDqLayer pCurDqLayer, PDeblockingFilter pFilter, uint8_t nBS[2][4][4], int32_t iBoundryFlag ) | |
| 405 | +{ | |
| 406 | + int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 407 | + int32_t iMbX = pCurDqLayer->iMbX; | |
| 408 | + int32_t iMbY = pCurDqLayer->iMbY; | |
| 409 | + | |
| 410 | + int32_t iCurLumaQp = pCurDqLayer->pLumaQp[iMbXyIndex]; | |
| 411 | + int32_t iCurChromaQp = pCurDqLayer->pChromaQp[iMbXyIndex]; | |
| 412 | + int32_t iLineSize = pFilter->iCsStride[0]; | |
| 413 | + int32_t iLineSizeUV = pFilter->iCsStride[1]; | |
| 414 | + | |
| 415 | + uint8_t * pDestY, * pDestCb, * pDestCr; | |
| 416 | + pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4); | |
| 417 | + pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSizeUV + iMbX) << 3); | |
| 418 | + pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSizeUV + iMbX) << 3); | |
| 419 | + | |
| 420 | + if( iBoundryFlag & LEFT_FLAG_MASK) | |
| 421 | + { | |
| 422 | + int32_t iLeftXyIndex = iMbXyIndex - 1; | |
| 423 | + pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iLeftXyIndex] + 1) >> 1; | |
| 424 | + pFilter->iChromaQP = (iCurChromaQp + pCurDqLayer->pChromaQp[iLeftXyIndex]+ 1) >> 1; | |
| 425 | + | |
| 426 | + if( nBS[0][0][0] == 0x04 ) | |
| 427 | + { | |
| 428 | + FilteringEdgeLumaIntraV( pFilter, pDestY, iLineSize, NULL ); | |
| 429 | + FilteringEdgeChromaIntraV( pFilter, pDestCb, pDestCr, iLineSizeUV, NULL ); | |
| 430 | + } | |
| 431 | + else | |
| 432 | + { | |
| 433 | + if(*(uint32_t *)nBS[0][0] != 0) | |
| 434 | + { | |
| 435 | + FilteringEdgeLumaV( pFilter, pDestY, iLineSize, nBS[0][0] ); | |
| 436 | + FilteringEdgeChromaV( pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[0][0] ); | |
| 437 | + } | |
| 438 | + } | |
| 439 | + } | |
| 440 | + | |
| 441 | + pFilter->iLumaQP = iCurLumaQp; | |
| 442 | + pFilter->iChromaQP = iCurChromaQp; | |
| 443 | + | |
| 444 | + if(*(uint32_t *)nBS[0][1] != 0) | |
| 445 | + { | |
| 446 | + FilteringEdgeLumaV( pFilter, &pDestY[1<<2], iLineSize, nBS[0][1]); | |
| 447 | + } | |
| 448 | + | |
| 449 | + if(*(uint32_t *)nBS[0][2] != 0) | |
| 450 | + { | |
| 451 | + FilteringEdgeLumaV( pFilter, &pDestY[2<<2], iLineSize, nBS[0][2]); | |
| 452 | + FilteringEdgeChromaV( pFilter, &pDestCb[2<<1], &pDestCr[2<<1], iLineSizeUV, nBS[0][2] ); | |
| 453 | + } | |
| 454 | + | |
| 455 | + if(*(uint32_t *)nBS[0][3] != 0) | |
| 456 | + { | |
| 457 | + FilteringEdgeLumaV( pFilter, &pDestY[3<<2], iLineSize, nBS[0][3] ); | |
| 458 | + } | |
| 459 | + | |
| 460 | + if( iBoundryFlag & TOP_FLAG_MASK) | |
| 461 | + { | |
| 462 | + int32_t iTopXyIndex = iMbXyIndex - pCurDqLayer->iMbWidth; | |
| 463 | + pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iTopXyIndex] + 1) >> 1; | |
| 464 | + pFilter->iChromaQP = (iCurChromaQp + pCurDqLayer->pChromaQp[iTopXyIndex] + 1) >> 1; | |
| 465 | + | |
| 466 | + if( nBS[1][0][0] == 0x04) | |
| 467 | + { | |
| 468 | + FilteringEdgeLumaIntraH( pFilter, pDestY, iLineSize, NULL ); | |
| 469 | + FilteringEdgeChromaIntraH( pFilter, pDestCb, pDestCr, iLineSizeUV, NULL ); | |
| 470 | + } | |
| 471 | + else | |
| 472 | + { | |
| 473 | + if(*(uint32_t *)nBS[1][0] != 0) | |
| 474 | + { | |
| 475 | + FilteringEdgeLumaH( pFilter, pDestY, iLineSize, nBS[1][0] ); | |
| 476 | + FilteringEdgeChromaH( pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[1][0] ); | |
| 477 | + } | |
| 478 | + } | |
| 479 | + } | |
| 480 | + | |
| 481 | + pFilter->iLumaQP = iCurLumaQp; | |
| 482 | + pFilter->iChromaQP = iCurChromaQp; | |
| 483 | + | |
| 484 | + if(*(uint32_t *)nBS[1][1] != 0) | |
| 485 | + { | |
| 486 | + FilteringEdgeLumaH( pFilter, &pDestY[(1<<2)*iLineSize], iLineSize, nBS[1][1] ); | |
| 487 | + } | |
| 488 | + | |
| 489 | + if(*(uint32_t *)nBS[1][2] != 0) | |
| 490 | + { | |
| 491 | + FilteringEdgeLumaH( pFilter, &pDestY[(2<<2)*iLineSize], iLineSize, nBS[1][2] ); | |
| 492 | + FilteringEdgeChromaH( pFilter, &pDestCb[(2<<1)*iLineSizeUV], &pDestCr[(2<<1)*iLineSizeUV], iLineSizeUV, nBS[1][2] ); | |
| 493 | + } | |
| 494 | + | |
| 495 | + if(*(uint32_t *)nBS[1][3] != 0) | |
| 496 | + { | |
| 497 | + FilteringEdgeLumaH( pFilter, &pDestY[(3<<2)*iLineSize], iLineSize, nBS[1][3] ); | |
| 498 | + } | |
| 499 | +} | |
| 500 | + | |
| 501 | +void_t /*__FASTCALL*/ FilteringEdgeLumaHV( PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag ) | |
| 502 | +{ | |
| 503 | + int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 504 | + int32_t iMbX = pCurDqLayer->iMbX; | |
| 505 | + int32_t iMbY = pCurDqLayer->iMbY; | |
| 506 | + int32_t iMbWidth = pCurDqLayer->iMbWidth; | |
| 507 | + int32_t iLineSize = pFilter->iCsStride[0]; | |
| 508 | + | |
| 509 | + uint8_t *pDestY; | |
| 510 | + int32_t iCurQp; | |
| 511 | + int32_t iIndexA, iAlpha, iBeta; | |
| 512 | + | |
| 513 | + FORCE_STACK_ALIGN_1D(int8_t, iTc, 4, 16 ); | |
| 514 | + FORCE_STACK_ALIGN_1D(uint8_t, uiBSx4, 4, 4 ); | |
| 515 | + | |
| 516 | + pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4); | |
| 517 | + iCurQp = pCurDqLayer->pLumaQp[iMbXyIndex]; | |
| 518 | + | |
| 519 | + *(uint32_t*)uiBSx4 = 0x03030303; | |
| 520 | + | |
| 521 | + // luma v | |
| 522 | + if( iBoundryFlag & LEFT_FLAG_MASK) | |
| 523 | + { | |
| 524 | + pFilter->iLumaQP = ( iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex-1] + 1 ) >> 1; | |
| 525 | + FilteringEdgeLumaIntraV( pFilter, pDestY, iLineSize, NULL ); | |
| 526 | + } | |
| 527 | + | |
| 528 | + pFilter->iLumaQP = iCurQp; | |
| 529 | + GET_ALPHA_BETA_FROM_QP(pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 530 | + if( iAlpha | iBeta ) | |
| 531 | + { | |
| 532 | + TC0_TBL_LOOKUP(iTc, iIndexA, uiBSx4, 0); | |
| 533 | + pFilter->pLoopf->pfLumaDeblockingLT4Hor( &pDestY[1 << 2],iLineSize,iAlpha,iBeta,iTc ); | |
| 534 | + pFilter->pLoopf->pfLumaDeblockingLT4Hor( &pDestY[2 << 2],iLineSize,iAlpha,iBeta,iTc ); | |
| 535 | + pFilter->pLoopf->pfLumaDeblockingLT4Hor( &pDestY[3 << 2],iLineSize,iAlpha,iBeta,iTc ); | |
| 536 | + } | |
| 537 | + | |
| 538 | + // luma h | |
| 539 | + if( iBoundryFlag & TOP_FLAG_MASK) | |
| 540 | + { | |
| 541 | + pFilter->iLumaQP = ( iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex-iMbWidth] + 1 ) >> 1; | |
| 542 | + FilteringEdgeLumaIntraH( pFilter, pDestY, iLineSize, NULL ); | |
| 543 | + } | |
| 544 | + | |
| 545 | + pFilter->iLumaQP = iCurQp; | |
| 546 | + if( iAlpha | iBeta ) | |
| 547 | + { | |
| 548 | + pFilter->pLoopf->pfLumaDeblockingLT4Ver( &pDestY[(1<<2)*iLineSize],iLineSize,iAlpha,iBeta,iTc ); | |
| 549 | + pFilter->pLoopf->pfLumaDeblockingLT4Ver( &pDestY[(2<<2)*iLineSize],iLineSize,iAlpha,iBeta,iTc ); | |
| 550 | + pFilter->pLoopf->pfLumaDeblockingLT4Ver( &pDestY[(3<<2)*iLineSize],iLineSize,iAlpha,iBeta,iTc ); | |
| 551 | + } | |
| 552 | +} | |
| 553 | +void_t /*__FASTCALL*/ FilteringEdgeChromaHV( PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag ) | |
| 554 | +{ | |
| 555 | + int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 556 | + int32_t iMbX = pCurDqLayer->iMbX; | |
| 557 | + int32_t iMbY = pCurDqLayer->iMbY; | |
| 558 | + int32_t iMbWidth = pCurDqLayer->iMbWidth; | |
| 559 | + int32_t iLineSize = pFilter->iCsStride[1]; | |
| 560 | + | |
| 561 | + uint8_t *pDestCb, *pDestCr; | |
| 562 | + int32_t iCurQp; | |
| 563 | + int32_t iIndexA, iAlpha, iBeta; | |
| 564 | + | |
| 565 | + FORCE_STACK_ALIGN_1D( int8_t, iTc, 4, 16 ); | |
| 566 | + FORCE_STACK_ALIGN_1D( uint8_t, uiBSx4, 4, 4 ); | |
| 567 | + | |
| 568 | + pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSize + iMbX) << 3); | |
| 569 | + pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSize + iMbX) << 3); | |
| 570 | + iCurQp = pCurDqLayer->pChromaQp[iMbXyIndex]; | |
| 571 | + *(uint32_t*)uiBSx4 = 0x03030303; | |
| 572 | + | |
| 573 | + // chroma v | |
| 574 | + if( iBoundryFlag & LEFT_FLAG_MASK) | |
| 575 | + { | |
| 576 | + pFilter->iChromaQP = ( iCurQp + pCurDqLayer->pChromaQp[iMbXyIndex-1] + 1 ) >> 1; | |
| 577 | + FilteringEdgeChromaIntraV( pFilter, pDestCb, pDestCr, iLineSize, NULL); | |
| 578 | + } | |
| 579 | + | |
| 580 | + pFilter->iChromaQP = iCurQp; | |
| 581 | + GET_ALPHA_BETA_FROM_QP(pFilter->iChromaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, iBeta); | |
| 582 | + if( iAlpha | iBeta ) | |
| 583 | + { | |
| 584 | + TC0_TBL_LOOKUP(iTc, iIndexA, uiBSx4, 1); | |
| 585 | + pFilter->pLoopf->pfChromaDeblockingLT4Hor( &pDestCb[2 << 1],&pDestCr[2 << 1],iLineSize,iAlpha,iBeta,iTc ); | |
| 586 | + } | |
| 587 | + | |
| 588 | + // chroma h | |
| 589 | + if( iBoundryFlag & TOP_FLAG_MASK) | |
| 590 | + { | |
| 591 | + pFilter->iChromaQP = ( iCurQp + pCurDqLayer->pChromaQp[iMbXyIndex-iMbWidth] + 1 ) >> 1; | |
| 592 | + FilteringEdgeChromaIntraH( pFilter, pDestCb, pDestCr, iLineSize, NULL); | |
| 593 | + } | |
| 594 | + | |
| 595 | + pFilter->iChromaQP = iCurQp; | |
| 596 | + if( iAlpha | iBeta ) | |
| 597 | + { | |
| 598 | + pFilter->pLoopf->pfChromaDeblockingLT4Ver( &pDestCb[(2<<1)*iLineSize],&pDestCr[(2<<1)*iLineSize],iLineSize,iAlpha,iBeta,iTc ); | |
| 599 | + } | |
| 600 | +} | |
| 601 | + | |
| 602 | +// merge h&v lookup table operation to save performance | |
| 603 | +void_t DeblockingIntraMb( PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag ) | |
| 604 | +{ | |
| 605 | + FilteringEdgeLumaHV(pCurDqLayer, pFilter, iBoundryFlag); | |
| 606 | + FilteringEdgeChromaHV(pCurDqLayer, pFilter, iBoundryFlag); | |
| 607 | +} | |
| 608 | + | |
| 609 | +void_t WelsDeblockingMb( PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag ) | |
| 610 | +{ | |
| 611 | + uint8_t nBS[2][4][4] = { 0 }; | |
| 612 | + | |
| 613 | + int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 614 | + int32_t iCurMbType = pCurDqLayer->pMbType[iMbXyIndex]; | |
| 615 | + int32_t iMbNb; | |
| 616 | + | |
| 617 | + switch( iCurMbType ) | |
| 618 | + { | |
| 619 | + case MB_TYPE_INTRA4x4: | |
| 620 | + case MB_TYPE_INTRA16x16: | |
| 621 | + case MB_TYPE_INTRA_PCM: | |
| 622 | + DeblockingIntraMb( pCurDqLayer, pFilter, iBoundryFlag ); | |
| 623 | + break; | |
| 624 | + default: | |
| 625 | + | |
| 626 | + if(iBoundryFlag & LEFT_FLAG_MASK) | |
| 627 | + { | |
| 628 | + iMbNb = iMbXyIndex - 1; | |
| 629 | + *(uint32_t*)nBS[0][0] = IS_INTRA(pCurDqLayer->pMbType[iMbNb])?0x04040404:DeblockingBsMarginalMBAvcbase( pCurDqLayer, 0, iMbNb, iMbXyIndex); | |
| 630 | + } | |
| 631 | + else | |
| 632 | + { | |
| 633 | + *(uint32_t*)nBS[0][0] = 0; | |
| 634 | + } | |
| 635 | + if(iBoundryFlag & TOP_FLAG_MASK) | |
| 636 | + { | |
| 637 | + iMbNb = iMbXyIndex - pCurDqLayer->iMbWidth; | |
| 638 | + *(uint32_t*)nBS[1][0] = IS_INTRA(pCurDqLayer->pMbType[iMbNb])?0x04040404:DeblockingBsMarginalMBAvcbase( pCurDqLayer, 1, iMbNb, iMbXyIndex); | |
| 639 | + } | |
| 640 | + else | |
| 641 | + { | |
| 642 | + *(uint32_t*)nBS[1][0] = 0; | |
| 643 | + } | |
| 644 | + //SKIP MB_16x16 or others | |
| 645 | + if( iCurMbType != MB_TYPE_SKIP ) | |
| 646 | + { | |
| 647 | + if( iCurMbType == MB_TYPE_16x16 ) | |
| 648 | + { | |
| 649 | + DeblockingBSInsideMBAvsbase( pCurDqLayer->pNzc[iMbXyIndex], nBS, 1 ); | |
| 650 | + } | |
| 651 | + else | |
| 652 | + { | |
| 653 | + DeblockingBSInsideMBNormal(pCurDqLayer, nBS, pCurDqLayer->pNzc[iMbXyIndex], iMbXyIndex); | |
| 654 | + } | |
| 655 | + } | |
| 656 | + else | |
| 657 | + { | |
| 658 | + *(uint32_t*)nBS[0][1] = *(uint32_t*)nBS[0][2] = *(uint32_t*)nBS[0][3] = | |
| 659 | + *(uint32_t*)nBS[1][1] = *(uint32_t*)nBS[1][2] = *(uint32_t*)nBS[1][3] = 0; | |
| 660 | + } | |
| 661 | + DeblockingInterMb( pCurDqLayer, pFilter, nBS, iBoundryFlag ); | |
| 662 | + break; | |
| 663 | + } | |
| 664 | +} | |
| 665 | + | |
| 666 | +// C code only | |
| 667 | +void_t DeblockLumaLt4_c( uint8_t *pPix, int32_t iStrideX,int32_t iStrideY, int32_t iAlpha, int32_t iBeta, int8_t *pTc ) | |
| 668 | +{ | |
| 669 | + for( int32_t i = 0;i<16;i++) | |
| 670 | + { | |
| 671 | + int32_t iTc0 = pTc[i>>2]; | |
| 672 | + if(iTc0>=0) | |
| 673 | + { | |
| 674 | + int32_t p0 = pPix[-iStrideX]; | |
| 675 | + int32_t p1 = pPix[-2*iStrideX]; | |
| 676 | + int32_t p2 = pPix[-3*iStrideX]; | |
| 677 | + int32_t q0 = pPix[0]; | |
| 678 | + int32_t q1 = pPix[iStrideX]; | |
| 679 | + int32_t q2 = pPix[2*iStrideX]; | |
| 680 | + bool_t bDetaP0Q0= WELS_ABS( p0 - q0 )<iAlpha; | |
| 681 | + bool_t bDetaP1P0 = WELS_ABS( p1 - p0 ) < iBeta; | |
| 682 | + bool_t bDetaQ1Q0 = WELS_ABS( q1 - q0 ) < iBeta; | |
| 683 | + int32_t iTc = iTc0; | |
| 684 | + if ( bDetaP0Q0&& bDetaP1P0 && bDetaQ1Q0 ) | |
| 685 | + { | |
| 686 | + bool_t bDetaP2P0 = WELS_ABS( p2 - p0 ) < iBeta; | |
| 687 | + bool_t bDetaQ2Q0 = WELS_ABS( q2 - q0 ) < iBeta; | |
| 688 | + if ( bDetaP2P0) | |
| 689 | + { | |
| 690 | + pPix[-2*iStrideX] = p1 + WELS_CLIP3( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -iTc0, iTc0 ); | |
| 691 | + iTc++; | |
| 692 | + } | |
| 693 | + if (bDetaQ2Q0) | |
| 694 | + { | |
| 695 | + pPix[iStrideX] = q1 + WELS_CLIP3( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -iTc0, iTc0 ); | |
| 696 | + iTc++; | |
| 697 | + } | |
| 698 | + int32_t iDeta = WELS_CLIP3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -iTc, iTc ); | |
| 699 | + pPix[-iStrideX] = WELS_CLIP1( p0 + iDeta ); /* p0' */ | |
| 700 | + pPix[0] = WELS_CLIP1( q0 - iDeta ); /* q0' */ | |
| 701 | + } | |
| 702 | + } | |
| 703 | + pPix +=iStrideY; | |
| 704 | + } | |
| 705 | +} | |
| 706 | +void_t DeblockLumaEq4_c( uint8_t *pPix, int32_t iStrideX, int32_t iStrideY, int32_t iAlpha, int32_t iBeta ) | |
| 707 | +{ | |
| 708 | + int32_t p0,p1,p2,q0,q1,q2; | |
| 709 | + int32_t iDetaP0Q0; | |
| 710 | + bool_t bDetaP1P0,bDetaQ1Q0; | |
| 711 | + for (int32_t i = 0;i<16;i++) | |
| 712 | + { | |
| 713 | + p0 = pPix[-iStrideX]; | |
| 714 | + p1 = pPix[-2*iStrideX]; | |
| 715 | + p2 = pPix[-3*iStrideX]; | |
| 716 | + q0 = pPix[0]; | |
| 717 | + q1 = pPix[iStrideX]; | |
| 718 | + q2 = pPix[2*iStrideX]; | |
| 719 | + iDetaP0Q0 = WELS_ABS( p0 - q0 ); | |
| 720 | + bDetaP1P0 = WELS_ABS( p1 - p0 ) < iBeta; | |
| 721 | + bDetaQ1Q0 = WELS_ABS( q1 - q0 ) < iBeta; | |
| 722 | + if ((iDetaP0Q0<iAlpha) && bDetaP1P0 &&bDetaQ1Q0) | |
| 723 | + { | |
| 724 | + if (iDetaP0Q0< (( iAlpha >> 2 ) + 2 ) ) | |
| 725 | + { | |
| 726 | + bool_t bDetaP2P0 = WELS_ABS( p2 - p0 ) < iBeta; | |
| 727 | + bool_t bDetaQ2Q0 = WELS_ABS( q2 - q0 ) < iBeta; | |
| 728 | + if(bDetaP2P0) | |
| 729 | + { | |
| 730 | + const int32_t p3 = pPix[-4*iStrideX]; | |
| 731 | + pPix[-iStrideX] = ( p2 + (p1 << 1) + (p0 << 1) + (q0 << 1) + q1 + 4 ) >> 3; //p0 | |
| 732 | + pPix[-2*iStrideX] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; //p1 | |
| 733 | + pPix[-3*iStrideX] = ( (p3 << 1) + p2 + (p2 << 1) + p1 + p0 + q0 + 4 ) >> 3;//p2 | |
| 734 | + } | |
| 735 | + else | |
| 736 | + { | |
| 737 | + pPix[-1*iStrideX] = ( (p1 << 1) + p0 + q1 + 2 ) >> 2; //p0 | |
| 738 | + } | |
| 739 | + if (bDetaQ2Q0) | |
| 740 | + { | |
| 741 | + const int32_t q3 = pPix[3*iStrideX]; | |
| 742 | + pPix[0] = ( p1 + (p0 << 1) + (q0 << 1) + (q1 << 1) + q2 + 4 ) >> 3; //q0 | |
| 743 | + pPix[iStrideX] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; //q1 | |
| 744 | + pPix[2*iStrideX] = ( (q3 << 1) + q2 + (q2 << 1) + q1 + q0 + p0 + 4 ) >> 3;//q2 | |
| 745 | + } | |
| 746 | + else | |
| 747 | + { | |
| 748 | + pPix[0] = ( (q1 << 1) + q0 + p1 + 2 ) >> 2; //q0 | |
| 749 | + } | |
| 750 | + } | |
| 751 | + else | |
| 752 | + { | |
| 753 | + pPix[-iStrideX] = ( (p1 << 1) + p0 + q1 + 2 ) >> 2; //p0 | |
| 754 | + pPix[ 0] = ( (q1 << 1) + q0 + p1 + 2 ) >> 2; //q0 | |
| 755 | + } | |
| 756 | + } | |
| 757 | + pPix += iStrideY; | |
| 758 | + } | |
| 759 | +} | |
| 760 | +void_t DeblockLumaLt4V_c( uint8_t *pPix, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *tc ) | |
| 761 | +{ | |
| 762 | + DeblockLumaLt4_c( pPix, iStride, 1, iAlpha, iBeta, tc ); | |
| 763 | +} | |
| 764 | +void_t DeblockLumaLt4H_c( uint8_t *pPix, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *tc ) | |
| 765 | +{ | |
| 766 | + DeblockLumaLt4_c( pPix, 1, iStride, iAlpha, iBeta, tc ); | |
| 767 | +} | |
| 768 | +void_t DeblockLumaEq4V_c( uint8_t *pPix, int32_t iStride, int32_t iAlpha, int32_t iBeta ) | |
| 769 | +{ | |
| 770 | + DeblockLumaEq4_c( pPix, iStride, 1, iAlpha, iBeta); | |
| 771 | +} | |
| 772 | +void_t DeblockLumaEq4H_c( uint8_t *pPix, int32_t iStride, int32_t iAlpha, int32_t iBeta ) | |
| 773 | +{ | |
| 774 | + DeblockLumaEq4_c( pPix, 1, iStride, iAlpha, iBeta ); | |
| 775 | +} | |
| 776 | +void_t DeblockChromaLt4_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStrideX, int32_t iStrideY, int32_t iAlpha, int32_t iBeta, int8_t *pTc ) | |
| 777 | +{ | |
| 778 | + int32_t p0, p1, q0, q1,iDeta; | |
| 779 | + bool_t bDetaP0Q0,bDetaP1P0,bDetaQ1Q0; | |
| 780 | + | |
| 781 | + for(int32_t i = 0;i<8;i++) | |
| 782 | + { | |
| 783 | + int32_t iTc0 = pTc[i>>1]; | |
| 784 | + if(iTc0 >0) | |
| 785 | + { | |
| 786 | + p0 = pPixCb[-iStrideX]; | |
| 787 | + p1 = pPixCb[-2*iStrideX]; | |
| 788 | + q0 = pPixCb[0]; | |
| 789 | + q1 = pPixCb[iStrideX]; | |
| 790 | + | |
| 791 | + bDetaP0Q0 = WELS_ABS( p0 - q0 ) < iAlpha; | |
| 792 | + bDetaP1P0 = WELS_ABS( p1 - p0 ) < iBeta; | |
| 793 | + bDetaQ1Q0 = WELS_ABS( q1 - q0 ) < iBeta; | |
| 794 | + if( bDetaP0Q0&&bDetaP1P0 && bDetaQ1Q0) | |
| 795 | + { | |
| 796 | + iDeta = WELS_CLIP3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -iTc0, iTc0 ); | |
| 797 | + pPixCb[-iStrideX] = WELS_CLIP1( p0 + iDeta ); /* p0' */ | |
| 798 | + pPixCb[0] = WELS_CLIP1( q0 - iDeta ); /* q0' */ | |
| 799 | + } | |
| 800 | + | |
| 801 | + | |
| 802 | + p0 = pPixCr[-iStrideX]; | |
| 803 | + p1 = pPixCr[-2*iStrideX]; | |
| 804 | + q0 = pPixCr[0]; | |
| 805 | + q1 = pPixCr[iStrideX]; | |
| 806 | + | |
| 807 | + bDetaP0Q0 = WELS_ABS( p0 - q0 ) < iAlpha; | |
| 808 | + bDetaP1P0 = WELS_ABS( p1 - p0 ) < iBeta; | |
| 809 | + bDetaQ1Q0 = WELS_ABS( q1 - q0 ) < iBeta; | |
| 810 | + | |
| 811 | + if( bDetaP0Q0&&bDetaP1P0 && bDetaQ1Q0) | |
| 812 | + { | |
| 813 | + iDeta = WELS_CLIP3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -iTc0, iTc0 ); | |
| 814 | + pPixCr[-iStrideX] = WELS_CLIP1( p0 + iDeta ); /* p0' */ | |
| 815 | + pPixCr[0] = WELS_CLIP1( q0 - iDeta ); /* q0' */ | |
| 816 | + } | |
| 817 | + } | |
| 818 | + pPixCb += iStrideY; | |
| 819 | + pPixCr += iStrideY; | |
| 820 | + } | |
| 821 | +} | |
| 822 | +void_t DeblockChromaEq4_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStrideX, int32_t iStrideY, int32_t iAlpha, int32_t iBeta ) | |
| 823 | +{ | |
| 824 | + int32_t i = 0, d = 0; | |
| 825 | + int32_t p0, p1, q0, q1; | |
| 826 | + bool_t bDetaP0Q0,bDetaP1P0,bDetaQ1Q0; | |
| 827 | + for(int32_t i =0;i<8;i++) | |
| 828 | + { | |
| 829 | + //cb | |
| 830 | + p0 = pPixCb[-iStrideX]; | |
| 831 | + p1 = pPixCb[-2*iStrideX]; | |
| 832 | + q0 = pPixCb[0]; | |
| 833 | + q1 = pPixCb[iStrideX]; | |
| 834 | + bDetaP0Q0 = WELS_ABS( p0 - q0 ) < iAlpha; | |
| 835 | + bDetaP1P0 = WELS_ABS( p1 - p0 ) < iBeta; | |
| 836 | + bDetaQ1Q0 = WELS_ABS( q1 - q0 ) < iBeta; | |
| 837 | + if(bDetaP0Q0&&bDetaP1P0&&bDetaQ1Q0) | |
| 838 | + { | |
| 839 | + pPixCb[-iStrideX] = ( (p1 << 1) + p0 + q1 + 2 ) >> 2; /* p0' */ | |
| 840 | + pPixCb[0] = ( (q1 << 1) + q0 + p1 + 2 ) >> 2; /* q0' */ | |
| 841 | + } | |
| 842 | + | |
| 843 | + //cr | |
| 844 | + p0 = pPixCr[-iStrideX]; | |
| 845 | + p1 = pPixCr[-2*iStrideX]; | |
| 846 | + q0 = pPixCr[0]; | |
| 847 | + q1 = pPixCr[iStrideX]; | |
| 848 | + bDetaP0Q0 = WELS_ABS( p0 - q0 ) < iAlpha; | |
| 849 | + bDetaP1P0 = WELS_ABS( p1 - p0 ) < iBeta; | |
| 850 | + bDetaQ1Q0 = WELS_ABS( q1 - q0 ) < iBeta; | |
| 851 | + if(bDetaP0Q0&&bDetaP1P0&&bDetaQ1Q0) | |
| 852 | + { | |
| 853 | + pPixCr[-iStrideX] = ( (p1 << 1) + p0 + q1 + 2 ) >> 2; /* p0' */ | |
| 854 | + pPixCr[0] = ( (q1 << 1) + q0 + p1 + 2 ) >> 2; /* q0' */ | |
| 855 | + } | |
| 856 | + pPixCr += iStrideY; | |
| 857 | + pPixCb += iStrideY; | |
| 858 | + } | |
| 859 | +} | |
| 860 | +void_t DeblockChromaLt4V_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *tc ) | |
| 861 | +{ | |
| 862 | + DeblockChromaLt4_c( pPixCb, pPixCr, iStride, 1, iAlpha, iBeta, tc ); | |
| 863 | +} | |
| 864 | +void_t DeblockChromaLt4H_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *tc ) | |
| 865 | +{ | |
| 866 | + DeblockChromaLt4_c( pPixCb, pPixCr, 1, iStride, iAlpha, iBeta, tc ); | |
| 867 | +} | |
| 868 | +void_t DeblockChromaEq4V_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta ) | |
| 869 | +{ | |
| 870 | + DeblockChromaEq4_c( pPixCb, pPixCr, iStride, 1, iAlpha, iBeta ); | |
| 871 | +} | |
| 872 | +void_t DeblockChromaEq4H_c( uint8_t *pPixCb, uint8_t *pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta ) | |
| 873 | +{ | |
| 874 | + DeblockChromaEq4_c( pPixCb, pPixCr, 1, iStride, iAlpha, iBeta ); | |
| 875 | +} | |
| 876 | + | |
| 877 | +#ifdef X86_ASM | |
| 878 | +extern "C" { | |
| 879 | +void DeblockLumaLt4H_sse2(uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t *pTc) | |
| 880 | +{ | |
| 881 | + FORCE_STACK_ALIGN_1D(uint8_t, uiBuf, 16*8, 16); | |
| 882 | + | |
| 883 | + DeblockLumaTransposeH2V_sse2(pPixY - 4, iStride, &uiBuf[0]); | |
| 884 | + DeblockLumaLt4V_sse2(&uiBuf[4*16], 16, iAlpha, iBeta, pTc); | |
| 885 | + DeblockLumaTransposeV2H_sse2(pPixY - 4, iStride, &uiBuf[0]); | |
| 886 | +} | |
| 887 | + | |
| 888 | +void DeblockLumaEq4H_sse2(uint8_t *pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta) | |
| 889 | +{ | |
| 890 | + FORCE_STACK_ALIGN_1D(uint8_t, uiBuf, 16*8, 16); | |
| 891 | + | |
| 892 | + DeblockLumaTransposeH2V_sse2(pPixY - 4, iStride, &uiBuf[0]); | |
| 893 | + DeblockLumaEq4V_sse2(&uiBuf[4*16], 16, iAlpha, iBeta); | |
| 894 | + DeblockLumaTransposeV2H_sse2(pPixY - 4, iStride, &uiBuf[0]); | |
| 895 | +} | |
| 896 | + | |
| 897 | +} | |
| 898 | + | |
| 899 | +#endif | |
| 900 | +/*! | |
| 901 | + * \brief AVC slice deblocking filtering target layer | |
| 902 | + * | |
| 903 | + * \param dec Wels avc decoder context | |
| 904 | + * | |
| 905 | + * \return NONE | |
| 906 | + */ | |
| 907 | +void_t WelsDeblockingFilterSlice( PWelsDecoderContext pCtx, PDeblockingFilterMbFunc pDeblockMb ) | |
| 908 | +{ | |
| 909 | + PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 910 | + PSliceHeaderExt pSliceHeaderExt = &pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt; | |
| 911 | + int32_t iMbWidth = pCurDqLayer->iMbWidth; | |
| 912 | + int32_t iTotalMbCount = pSliceHeaderExt->sSliceHeader.pSps->uiTotalMbCount; | |
| 913 | + | |
| 914 | + SDeblockingFilter pFilter = {0}; | |
| 915 | + | |
| 916 | + PFmo pFmo = pCtx->pFmo; | |
| 917 | + int32_t iNextMbXyIndex = 0; | |
| 918 | + int32_t iTotalNumMb = pCurDqLayer->sLayerInfo.sSliceInLayer.iTotalMbInCurSlice; | |
| 919 | + int32_t iCountNumMb = 0; | |
| 920 | + int32_t iBoundryFlag; | |
| 921 | + int32_t iFilterIdc = pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.uiDisableDeblockingFilterIdc; | |
| 922 | + | |
| 923 | + /* Step1: parameters set */ | |
| 924 | + pFilter.pCsData[0] = pCtx->pDec->pData[0]; | |
| 925 | + pFilter.pCsData[1] = pCtx->pDec->pData[1]; | |
| 926 | + pFilter.pCsData[2] = pCtx->pDec->pData[2]; | |
| 927 | + | |
| 928 | + pFilter.iCsStride[0] = pCtx->pDec->iLinesize[0]; | |
| 929 | + pFilter.iCsStride[1] = pCtx->pDec->iLinesize[1]; | |
| 930 | + | |
| 931 | + pFilter.eSliceType = (ESliceType) pCurDqLayer->sLayerInfo.sSliceInLayer.eSliceType; | |
| 932 | + | |
| 933 | + pFilter.iSliceAlphaC0Offset = pSliceHeaderExt->sSliceHeader.iSliceAlphaC0Offset; | |
| 934 | + pFilter.iSliceBetaOffset = pSliceHeaderExt->sSliceHeader.iSliceBetaOffset; | |
| 935 | + | |
| 936 | + pFilter.pLoopf = &pCtx->sDeblockingFunc; | |
| 937 | + | |
| 938 | + /* Step2: macroblock deblocking */ | |
| 939 | + if( 0 == iFilterIdc || 2 == iFilterIdc ) | |
| 940 | + { | |
| 941 | + iNextMbXyIndex = pSliceHeaderExt->sSliceHeader.iFirstMbInSlice; | |
| 942 | + pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth; | |
| 943 | + pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth; | |
| 944 | + pCurDqLayer->iMbXyIndex = iNextMbXyIndex; | |
| 945 | + | |
| 946 | + do | |
| 947 | + { | |
| 948 | + iBoundryFlag = DeblockingAvailableNoInterlayer(pCurDqLayer, iFilterIdc); | |
| 949 | + | |
| 950 | + pDeblockMb( pCurDqLayer, &pFilter, iBoundryFlag ); | |
| 951 | + | |
| 952 | + ++iCountNumMb; | |
| 953 | + if ( iCountNumMb >= iTotalNumMb ) | |
| 954 | + { | |
| 955 | + break; | |
| 956 | + } | |
| 957 | + | |
| 958 | + if ( pSliceHeaderExt->sSliceHeader.pPps->uiNumSliceGroups > 1 ) | |
| 959 | + { | |
| 960 | + iNextMbXyIndex = FmoNextMb( pFmo, iNextMbXyIndex ); | |
| 961 | + } | |
| 962 | + else | |
| 963 | + { | |
| 964 | + ++iNextMbXyIndex; | |
| 965 | + } | |
| 966 | + if ( -1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbCount ) // slice group boundary or end of a frame | |
| 967 | + { | |
| 968 | + break; | |
| 969 | + } | |
| 970 | + | |
| 971 | + pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth; | |
| 972 | + pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth; | |
| 973 | + pCurDqLayer->iMbXyIndex = iNextMbXyIndex; | |
| 974 | + } while ( 1 ); | |
| 975 | + } | |
| 976 | +} | |
| 977 | +/*! | |
| 978 | + * \brief deblocking module initialize | |
| 979 | + * | |
| 980 | + * \param pf | |
| 981 | + * cpu | |
| 982 | + * | |
| 983 | + * \return NONE | |
| 984 | + */ | |
| 985 | + | |
| 986 | +void_t DeblockingInit( SDeblockingFunc *pFunc, int32_t iCpu ) | |
| 987 | +{ | |
| 988 | + pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_c; | |
| 989 | + pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_c; | |
| 990 | + pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_c; | |
| 991 | + pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_c; | |
| 992 | + | |
| 993 | + pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_c; | |
| 994 | + pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_c; | |
| 995 | + pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_c; | |
| 996 | + pFunc->pfChromaDeblockinEQ4Hor = DeblockChromaEq4H_c; | |
| 997 | + | |
| 998 | +#ifdef X86_ASM | |
| 999 | + if( iCpu & WELS_CPU_SSE2 ){ | |
| 1000 | + pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_sse2; | |
| 1001 | + pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_sse2; | |
| 1002 | + pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_sse2; | |
| 1003 | + pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_sse2; | |
| 1004 | + pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_sse2; | |
| 1005 | + pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_sse2; | |
| 1006 | + pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_sse2; | |
| 1007 | + pFunc->pfChromaDeblockinEQ4Hor = DeblockChromaEq4H_sse2; | |
| 1008 | + } | |
| 1009 | +#endif | |
| 1010 | + | |
| 1011 | +} | |
| 1012 | + | |
| 1013 | +} // namespace WelsDec | |
| @@ -0,0 +1,134 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +#include <string.h> | |
| 34 | + | |
| 35 | +#include "decode_mb_aux.h" | |
| 36 | +#include "wels_common_basis.h" | |
| 37 | + | |
| 38 | +namespace WelsDec { | |
| 39 | + | |
| 40 | +#define MAX_NEG_CROP 1024 | |
| 41 | +uint8_t g_ClipTable[256 + 2 * MAX_NEG_CROP]; //the front 1024 is 0, the back 1024 is 255, the middle 256 elements is 0-255 | |
| 42 | + | |
| 43 | + | |
| 44 | +/* init pClip table to pClip the final dct data */ | |
| 45 | +void_t InitDctClipTable(void_t) | |
| 46 | +{ | |
| 47 | + uint8_t *p = &g_ClipTable[0]; | |
| 48 | + const int32_t kiLength = MAX_NEG_CROP * sizeof(uint8_t); | |
| 49 | + int32_t i = 0; | |
| 50 | + | |
| 51 | + do | |
| 52 | + { | |
| 53 | + const int32_t kiIdx = MAX_NEG_CROP + i; | |
| 54 | + | |
| 55 | + p[kiIdx] = i; | |
| 56 | + p[1+kiIdx] = 1+i; | |
| 57 | + p[2+kiIdx] = 2+i; | |
| 58 | + p[3+kiIdx] = 3+i; | |
| 59 | + | |
| 60 | + i += 4; | |
| 61 | + } while(i < 256); | |
| 62 | + | |
| 63 | + memset( p, 0, kiLength); | |
| 64 | + memset( p + MAX_NEG_CROP + 256, 0xFF, kiLength); | |
| 65 | +} | |
| 66 | + | |
| 67 | +//NOTE::: p_RS should NOT be modified and it will lead to mismatch with JSVM. | |
| 68 | +// so should allocate kA array to store the temporary value (idct). | |
| 69 | +void_t IdctResAddPred_c(uint8_t *pPred, const int32_t kiStride, int16_t *pRs) | |
| 70 | +{ | |
| 71 | + int16_t iSrc[16]; | |
| 72 | + | |
| 73 | + uint8_t *pDst = pPred; | |
| 74 | + const int32_t kiStride2 = kiStride<<1; | |
| 75 | + const int32_t kiStride3 = kiStride + kiStride2; | |
| 76 | + uint8_t *pClip = &g_ClipTable[MAX_NEG_CROP]; | |
| 77 | + int32_t i; | |
| 78 | + | |
| 79 | + for(i=0; i<4; i++) | |
| 80 | + { | |
| 81 | + const int32_t kiY = i<<2; | |
| 82 | + const int32_t kiT0 = pRs[kiY] + pRs[kiY+2]; | |
| 83 | + const int32_t kiT1 = pRs[kiY] - pRs[kiY+2]; | |
| 84 | + const int32_t kiT2 = (pRs[kiY+1]>>1) - pRs[kiY+3]; | |
| 85 | + const int32_t kiT3 = pRs[kiY+1] + (pRs[kiY+3]>>1); | |
| 86 | + | |
| 87 | + iSrc[kiY] = kiT0 + kiT3; | |
| 88 | + iSrc[kiY+1] = kiT1 + kiT2; | |
| 89 | + iSrc[kiY+2] = kiT1 - kiT2; | |
| 90 | + iSrc[kiY+3] = kiT0 - kiT3; | |
| 91 | + } | |
| 92 | + | |
| 93 | + for(i=0; i<4; i++) | |
| 94 | + { | |
| 95 | + int32_t kT1 = iSrc[i] + iSrc[i+8]; | |
| 96 | + int32_t kT2 = iSrc[i+4] + (iSrc[i+12]>>1); | |
| 97 | + int32_t kT3 = (32 + kT1 + kT2) >> 6; | |
| 98 | + int32_t kT4 = (32 + kT1 - kT2) >> 6; | |
| 99 | + | |
| 100 | + pDst[i] = pClip[ kT3 + pPred[i] ]; | |
| 101 | + pDst[i+kiStride3] = pClip[ kT4 + pPred[i+kiStride3] ]; | |
| 102 | + | |
| 103 | + kT1 = iSrc[i] - iSrc[i+8]; | |
| 104 | + kT2 = (iSrc[i+4]>>1) - iSrc[i+12]; | |
| 105 | + pDst[i+kiStride] = pClip[ ((32 + kT1 + kT2) >> 6) + pDst[i+kiStride] ]; | |
| 106 | + pDst[i+kiStride2] = pClip[ ((32 + kT1 - kT2) >> 6) + pDst[i+kiStride2] ]; | |
| 107 | + } | |
| 108 | +} | |
| 109 | + | |
| 110 | +void_t GetI4LumaIChromaAddrTable(int32_t *pBlockOffset, const int32_t kiYStride, const int32_t kiUVStride) | |
| 111 | +{ | |
| 112 | + int32_t *pOffset = pBlockOffset; | |
| 113 | + int32_t i; | |
| 114 | + const uint8_t kuiScan0 = g_kuiScan8[0]; | |
| 115 | + | |
| 116 | + for(i=0; i<16; i++) | |
| 117 | + { | |
| 118 | + const uint32_t kuiA = g_kuiScan8[i] - kuiScan0; | |
| 119 | + const uint32_t kuiX = kuiA & 0x07; | |
| 120 | + const uint32_t kuiY = kuiA >> 3; | |
| 121 | + | |
| 122 | + pOffset[i]= (kuiX + kiYStride* kuiY) << 2; | |
| 123 | + } | |
| 124 | + | |
| 125 | + for(i=0; i<4; i++) | |
| 126 | + { | |
| 127 | + const uint32_t kuiA = g_kuiScan8[i] - kuiScan0; | |
| 128 | + | |
| 129 | + pOffset[16+i]= | |
| 130 | + pOffset[20+i]= ((kuiA & 0x07) + (kiUVStride/*>>1*/) * (kuiA >> 3)) << 2; | |
| 131 | + } | |
| 132 | +} | |
| 133 | + | |
| 134 | +} // namespace WelsDec | |
| @@ -0,0 +1,1361 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2008-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 | + * Abstract | |
| 33 | + * current slice decoding | |
| 34 | + * | |
| 35 | + * History | |
| 36 | + * 07/10/2008 Created | |
| 37 | + * 08/09/2013 Modified | |
| 38 | + * | |
| 39 | + *****************************************************************************/ | |
| 40 | +#include <memory.h> | |
| 41 | + | |
| 42 | +#include "typedefs.h" | |
| 43 | +#include "dec_golomb.h" | |
| 44 | + | |
| 45 | +#include "fmo.h" | |
| 46 | +#include "deblocking.h" | |
| 47 | +#include "utils.h" | |
| 48 | + | |
| 49 | +#include "decode_slice.h" | |
| 50 | + | |
| 51 | +#include "error_code.h" | |
| 52 | +#include "decode_mb_aux.h" | |
| 53 | +#include "parse_mb_syn_cavlc.h" | |
| 54 | +#include "rec_mb.h" | |
| 55 | +#include "mv_pred.h" | |
| 56 | + | |
| 57 | +#include "as264_common.h" | |
| 58 | +#include "cpu_core.h" | |
| 59 | +#include "expand_pic.h" | |
| 60 | + | |
| 61 | +namespace WelsDec { | |
| 62 | + | |
| 63 | +int32_t WelsTargetSliceConstruction( PWelsDecoderContext pCtx ) | |
| 64 | +{ | |
| 65 | + int32_t iPreQP = 0; | |
| 66 | + | |
| 67 | + PDqLayer pCurLayer = pCtx->pCurDqLayer; | |
| 68 | + PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | |
| 69 | + PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader; | |
| 70 | + | |
| 71 | + int32_t iTotalMbTargetLayer = pSliceHeader->pSps->uiTotalMbCount; | |
| 72 | + | |
| 73 | + int32_t iCurLayerWidth = pCurLayer->iMbWidth << 4; | |
| 74 | + int32_t iCurLayerHeight = pCurLayer->iMbHeight << 4; | |
| 75 | + | |
| 76 | + int32_t iNextMbXyIndex = 0; | |
| 77 | + PFmo pFmo = pCtx->pFmo; | |
| 78 | + | |
| 79 | + int32_t iTotalNumMb = pCurSlice->iTotalMbInCurSlice; | |
| 80 | + int32_t iCountNumMb = 0; | |
| 81 | + PDeblockingFilterMbFunc pDeblockMb; | |
| 82 | + | |
| 83 | + if ( !pCtx->bAvcBasedFlag && iCurLayerWidth != pCtx->iCurSeqIntervalMaxPicWidth ) | |
| 84 | + { | |
| 85 | + return -1; | |
| 86 | + } | |
| 87 | + | |
| 88 | + iNextMbXyIndex = pSliceHeader->iFirstMbInSlice; | |
| 89 | + pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; | |
| 90 | + pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; | |
| 91 | + pCurLayer->iMbXyIndex = iNextMbXyIndex; | |
| 92 | + | |
| 93 | + if ( 0 == iNextMbXyIndex ) | |
| 94 | + { | |
| 95 | + pCurLayer->pDec->iSpsId = pSliceHeader->iSpsId; | |
| 96 | + pCurLayer->pDec->iPpsId = pSliceHeader->iPpsId; | |
| 97 | + | |
| 98 | + pCurLayer->pDec->uiQualityId = pCurLayer->sLayerInfo.sNalHeaderExt.uiQualityId; | |
| 99 | + } | |
| 100 | + | |
| 101 | + do | |
| 102 | + { | |
| 103 | + iPreQP = pCurLayer->pLumaQp[pCurLayer->iMbXyIndex]; | |
| 104 | + | |
| 105 | + if ( WelsTargetMbConstruction( pCtx ) ) | |
| 106 | + { | |
| 107 | + WelsLog( pCtx, WELS_LOG_WARNING, "WelsTargetSliceConstruction():::MB(%d, %d) construction error. pCurSlice_type:%d\n", | |
| 108 | + pCurLayer->iMbX, pCurLayer->iMbY, pCurSlice->eSliceType ); | |
| 109 | + | |
| 110 | + return -1; | |
| 111 | + } | |
| 112 | + | |
| 113 | + ++iCountNumMb; | |
| 114 | + ++pCurLayer->pDec->iTotalNumMbRec; | |
| 115 | + if ( iCountNumMb >= iTotalNumMb ) | |
| 116 | + { | |
| 117 | + break; | |
| 118 | + } | |
| 119 | + if ( pCurLayer->pDec->iTotalNumMbRec > iTotalMbTargetLayer ) | |
| 120 | + { | |
| 121 | + WelsLog( pCtx, WELS_LOG_WARNING, "WelsTargetSliceConstruction():::fdec->iTotalNumMbRec:%d, iTotalMbTargetLayer:%d\n", | |
| 122 | + pCurLayer->pDec->iTotalNumMbRec, iTotalMbTargetLayer ); | |
| 123 | + | |
| 124 | + return -1; | |
| 125 | + } | |
| 126 | + | |
| 127 | + if ( pSliceHeader->pPps->uiNumSliceGroups > 1 ) | |
| 128 | + { | |
| 129 | + iNextMbXyIndex = FmoNextMb( pFmo, iNextMbXyIndex ); | |
| 130 | + } | |
| 131 | + else | |
| 132 | + { | |
| 133 | + ++iNextMbXyIndex; | |
| 134 | + } | |
| 135 | + if ( -1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbTargetLayer ) // slice group boundary or end of a frame | |
| 136 | + { | |
| 137 | + break; | |
| 138 | + } | |
| 139 | + pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; | |
| 140 | + pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; | |
| 141 | + pCurLayer->iMbXyIndex = iNextMbXyIndex; | |
| 142 | + } while (1); | |
| 143 | + | |
| 144 | + pCtx->pDec->iWidthInPixel = iCurLayerWidth; | |
| 145 | + pCtx->pDec->iHeightInPixel = iCurLayerHeight; | |
| 146 | + | |
| 147 | + if((pCurSlice->eSliceType != I_SLICE)&&(pCurSlice->eSliceType != P_SLICE)) | |
| 148 | + return 0; | |
| 149 | + | |
| 150 | + pDeblockMb = WelsDeblockingMb; | |
| 151 | + | |
| 152 | + if ( 1 == pSliceHeader->uiDisableDeblockingFilterIdc ) | |
| 153 | + { | |
| 154 | + return 0;//NO_SUPPORTED_FILTER_IDX | |
| 155 | + } | |
| 156 | + else | |
| 157 | + { | |
| 158 | + WelsDeblockingFilterSlice( pCtx, pDeblockMb ); | |
| 159 | + | |
| 160 | + } | |
| 161 | + // any other filter_idc not supported here, 7/22/2010 | |
| 162 | + | |
| 163 | + return 0; | |
| 164 | +} | |
| 165 | + | |
| 166 | +int32_t WelsMbInterSampleConstruction( PWelsDecoderContext pCtx, PDqLayer pCurLayer, | |
| 167 | + uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV, int32_t iStrideL, int32_t iStrideC ) | |
| 168 | +{ | |
| 169 | + int32_t iMbXy = pCurLayer->iMbXyIndex; | |
| 170 | + int32_t i, iIndex, iOffset; | |
| 171 | + | |
| 172 | + WelsChromaDcIdct( pCurLayer->pScaledTCoeff[iMbXy] + 256 ); // 256 = 16*16 | |
| 173 | + WelsChromaDcIdct( pCurLayer->pScaledTCoeff[iMbXy] + 320 ); // 320 = 16*16 + 16*4 | |
| 174 | + | |
| 175 | + for(i=0; i<16; i++) //luma | |
| 176 | + { | |
| 177 | + iIndex = g_kuiMbNonZeroCountIdx[i]; | |
| 178 | + if( pCurLayer->pNzc[iMbXy][iIndex] ) | |
| 179 | + { | |
| 180 | + iOffset = ((iIndex>>2)<<2) * iStrideL + ((iIndex%4)<<2); | |
| 181 | + pCtx->pIdctResAddPredFunc( pDstY+iOffset, iStrideL, pCurLayer->pScaledTCoeff[iMbXy]+(i<<4) ); | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + for ( i = 0; i < 4; i++ ) //chroma | |
| 186 | + { | |
| 187 | + iIndex = g_kuiMbNonZeroCountIdx[i+16]; //Cb | |
| 188 | + if ( pCurLayer->pNzc[iMbXy][iIndex] || *(pCurLayer->pScaledTCoeff[iMbXy]+((i+16)<<4)) ) | |
| 189 | + { | |
| 190 | + iOffset = (((iIndex-16)>>2)<<2) * iStrideC + (((iIndex-16)%4)<<2); | |
| 191 | + pCtx->pIdctResAddPredFunc( pDstU+iOffset, iStrideC, pCurLayer->pScaledTCoeff[iMbXy]+((i+16)<<4) ); | |
| 192 | + } | |
| 193 | + | |
| 194 | + iIndex = g_kuiMbNonZeroCountIdx[i+20]; //Cr | |
| 195 | + if ( pCurLayer->pNzc[iMbXy][iIndex] || *(pCurLayer->pScaledTCoeff[iMbXy]+((i+20)<<4)) ) | |
| 196 | + { | |
| 197 | + iOffset = (((iIndex-18)>>2)<<2) * iStrideC + (((iIndex-18)%4)<<2); | |
| 198 | + pCtx->pIdctResAddPredFunc( pDstV+iOffset, iStrideC , pCurLayer->pScaledTCoeff[iMbXy]+((i+20)<<4)); | |
| 199 | + } | |
| 200 | + } | |
| 201 | + | |
| 202 | + return 0; | |
| 203 | +} | |
| 204 | +int32_t WelsMbInterConstruction(PWelsDecoderContext pCtx, PDqLayer pCurLayer) | |
| 205 | +{ | |
| 206 | + int32_t iMbX = pCurLayer->iMbX; | |
| 207 | + int32_t iMbY = pCurLayer->iMbY; | |
| 208 | + uint8_t *pDstY, *pDstCb, *pDstCr; | |
| 209 | + | |
| 210 | + int32_t iLumaStride = pCtx->pDec->iLinesize[0]; | |
| 211 | + int32_t iChromaStride = pCtx->pDec->iLinesize[1]; | |
| 212 | + | |
| 213 | + pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX)<<4); | |
| 214 | + pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX)<<3); | |
| 215 | + pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX)<<3); | |
| 216 | + | |
| 217 | + GetInterPred(pDstY, pDstCb, pDstCr, pCtx); | |
| 218 | + WelsMbInterSampleConstruction( pCtx, pCurLayer, pDstY, pDstCb, pDstCr, iLumaStride, iChromaStride ); | |
| 219 | + | |
| 220 | + pCtx->sBlockFunc.pWelsSetNonZeroCountFunc(NULL, pCurLayer->pNzc[pCurLayer->iMbXyIndex]);// set all none-zero nzc to 1; dbk can be opti! | |
| 221 | + return 0; | |
| 222 | +} | |
| 223 | + | |
| 224 | +void_t WelsLumaDcDequantIdct(int16_t *pBlock, int32_t iQp){ | |
| 225 | + const int32_t kiQMul= g_kuiDequantCoeff[iQp][0]; | |
| 226 | +#define STRIDE 16 | |
| 227 | + int32_t i; | |
| 228 | + int32_t iTemp[16]; //FIXME check if this is a good idea | |
| 229 | + int16_t* pBlk = pBlock; | |
| 230 | + static const int32_t kiXOffset[4]={0, STRIDE, STRIDE<<2, 5*STRIDE}; | |
| 231 | + static const int32_t kiYOffset[4]={0, STRIDE<<1, STRIDE<<3, 10*STRIDE}; | |
| 232 | + | |
| 233 | + for(i=0; i<4; i++){ | |
| 234 | + const int32_t kiOffset= kiYOffset[i]; | |
| 235 | + const int32_t kiX1 = kiOffset + kiXOffset[2]; | |
| 236 | + const int32_t kiX2 = STRIDE + kiOffset; | |
| 237 | + const int32_t kiX3 = kiOffset + kiXOffset[3]; | |
| 238 | + const int32_t kiI4 = i << 2; // 4*i | |
| 239 | + const int32_t kiZ0= pBlk[kiOffset] + pBlk[kiX1]; | |
| 240 | + const int32_t kiZ1= pBlk[kiOffset] - pBlk[kiX1]; | |
| 241 | + const int32_t kiZ2= pBlk[kiX2] - pBlk[kiX3]; | |
| 242 | + const int32_t kiZ3= pBlk[kiX2] + pBlk[kiX3]; | |
| 243 | + | |
| 244 | + iTemp[kiI4] = kiZ0+kiZ3; | |
| 245 | + iTemp[1+kiI4]= kiZ1+kiZ2; | |
| 246 | + iTemp[2+kiI4]= kiZ1-kiZ2; | |
| 247 | + iTemp[3+kiI4]= kiZ0-kiZ3; | |
| 248 | + } | |
| 249 | + | |
| 250 | + for(i=0; i<4; i++){ | |
| 251 | + const int32_t kiOffset= kiXOffset[i]; | |
| 252 | + const int32_t kiI4 = 4 + i; | |
| 253 | + const int32_t kiZ0= iTemp[i] + iTemp[4+kiI4]; | |
| 254 | + const int32_t kiZ1= iTemp[i] - iTemp[4+kiI4]; | |
| 255 | + const int32_t kiZ2= iTemp[kiI4] - iTemp[8+kiI4]; | |
| 256 | + const int32_t kiZ3= iTemp[kiI4] + iTemp[8+kiI4]; | |
| 257 | + | |
| 258 | + pBlk[kiOffset]= ((kiZ0 + kiZ3)*kiQMul + 2)>>2; //FIXME think about merging this into decode_resdual | |
| 259 | + pBlk[kiYOffset[1] +kiOffset]= ((kiZ1 + kiZ2)*kiQMul + 2)>>2; | |
| 260 | + pBlk[kiYOffset[2] +kiOffset]= ((kiZ1 - kiZ2)*kiQMul + 2)>>2; | |
| 261 | + pBlk[kiYOffset[3] +kiOffset]= ((kiZ0 - kiZ3)*kiQMul + 2)>>2; | |
| 262 | + } | |
| 263 | + #undef STRIDE | |
| 264 | +} | |
| 265 | + | |
| 266 | +int32_t WelsMbIntraPredictionConstruction(PWelsDecoderContext pCtx, PDqLayer pCurLayer, bool_t bOutput) | |
| 267 | +{ | |
| 268 | +//seems IPCM should not enter this path | |
| 269 | + int32_t iMbXy = pCurLayer->iMbXyIndex; | |
| 270 | + | |
| 271 | + FORCE_STACK_ALIGN_1D( int16_t, pTempScaledTCoeff, MB_COEFF_LIST_SIZE, 16 ); | |
| 272 | + | |
| 273 | + memcpy(pTempScaledTCoeff, pCurLayer->pScaledTCoeff[iMbXy], 384*sizeof(pCurLayer->pScaledTCoeff[iMbXy][0])); | |
| 274 | + | |
| 275 | + WelsFillRecNeededMbInfo(pCtx, bOutput, pCurLayer); | |
| 276 | + | |
| 277 | + if(IS_INTRA16x16(pCurLayer->pMbType[iMbXy])) | |
| 278 | + { | |
| 279 | + int32_t i,j; | |
| 280 | + // really need? | |
| 281 | + for(i=0; i<16; i++) | |
| 282 | + { | |
| 283 | + j = g_kuiLumaDcZigzagScan[i]; | |
| 284 | + pTempScaledTCoeff[j] = pCurLayer->pScaledTCoeff[iMbXy][j]; | |
| 285 | + } | |
| 286 | + WelsLumaDcDequantIdct(pTempScaledTCoeff, pCurLayer->pLumaQp[iMbXy]); | |
| 287 | + RecI16x16Mb(iMbXy, pCtx,pTempScaledTCoeff,pCurLayer); | |
| 288 | + | |
| 289 | + return 0; | |
| 290 | + } | |
| 291 | + | |
| 292 | + if(IS_INTRA4x4(pCurLayer->pMbType[iMbXy])) | |
| 293 | + RecI4x4Mb(iMbXy, pCtx,pTempScaledTCoeff,pCurLayer); | |
| 294 | + | |
| 295 | + return 0; | |
| 296 | +} | |
| 297 | + | |
| 298 | +int32_t WelsMbInterPrediction(PWelsDecoderContext pCtx, PDqLayer pCurLayer) | |
| 299 | +{ | |
| 300 | + int32_t iMbX = pCurLayer->iMbX; | |
| 301 | + int32_t iMbY = pCurLayer->iMbY; | |
| 302 | + uint8_t *pDstY, *pDstCb, *pDstCr; | |
| 303 | + | |
| 304 | + int32_t iLumaStride = pCtx->pDec->iLinesize[0]; | |
| 305 | + int32_t iChromaStride = pCtx->pDec->iLinesize[1]; | |
| 306 | + | |
| 307 | + pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX)<<4); | |
| 308 | + pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX)<<3); | |
| 309 | + pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX)<<3); | |
| 310 | + | |
| 311 | + GetInterPred(pDstY, pDstCb, pDstCr, pCtx); | |
| 312 | + | |
| 313 | + return 0; | |
| 314 | +} | |
| 315 | + | |
| 316 | +void_t WelsMbCopy( uint8_t *pDst, int32_t iStrideDst, uint8_t *pSrc, int32_t iStrideSrc, | |
| 317 | + int32_t iHeight, int32_t iWidth ) | |
| 318 | +{ | |
| 319 | + int32_t i; | |
| 320 | + int32_t iOffsetDst = 0, iOffsetSrc = 0; | |
| 321 | + for ( i = 0; i < iHeight; i++ ) | |
| 322 | + { | |
| 323 | + memcpy( pDst+iOffsetDst, pSrc+iOffsetSrc, iWidth ); | |
| 324 | + iOffsetDst += iStrideDst; | |
| 325 | + iOffsetSrc += iStrideSrc; | |
| 326 | + } | |
| 327 | +} | |
| 328 | + | |
| 329 | + | |
| 330 | +int32_t WelsTargetMbConstruction(PWelsDecoderContext pCtx) | |
| 331 | +{ | |
| 332 | + PDqLayer pCurLayer = pCtx->pCurDqLayer; | |
| 333 | + if ( MB_TYPE_INTRA_PCM == pCurLayer->pMbType[pCurLayer->iMbXyIndex] ) | |
| 334 | + { | |
| 335 | + //copy cs into fdec | |
| 336 | + int32_t iCsStrideL = pCurLayer->iCsStride[0]; | |
| 337 | + int32_t iCsStrideC = pCurLayer->iCsStride[1]; | |
| 338 | + | |
| 339 | + int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; | |
| 340 | + int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1]; | |
| 341 | + | |
| 342 | + int32_t iCsOffsetL = ( pCurLayer->iMbX + pCurLayer->iMbY * iCsStrideL ) << 4; | |
| 343 | + int32_t iCsOffsetC = ( pCurLayer->iMbX + pCurLayer->iMbY * iCsStrideC ) << 3; | |
| 344 | + | |
| 345 | + int32_t iDecOffsetL = ( pCurLayer->iMbX + pCurLayer->iMbY * iDecStrideL ) << 4; | |
| 346 | + int32_t iDecOffsetC = ( pCurLayer->iMbX + pCurLayer->iMbY * iDecStrideC ) << 3; | |
| 347 | + | |
| 348 | + uint8_t* pSrcY = pCurLayer->pCsData[0] + iCsOffsetL; | |
| 349 | + uint8_t* pSrcU = pCurLayer->pCsData[1] + iCsOffsetC; | |
| 350 | + uint8_t* pSrcV = pCurLayer->pCsData[2] + iCsOffsetC; | |
| 351 | + | |
| 352 | + uint8_t* pDecY = pCurLayer->pDec->pData[0] + iDecOffsetL; | |
| 353 | + uint8_t* pDecU = pCurLayer->pDec->pData[1] + iDecOffsetC; | |
| 354 | + uint8_t* pDecV = pCurLayer->pDec->pData[2] + iDecOffsetC; | |
| 355 | + | |
| 356 | + WelsMbCopy( pDecY, iDecStrideL, pSrcY, iCsStrideL, 16, 16 ); | |
| 357 | + WelsMbCopy( pDecU, iDecStrideC, pSrcU, iCsStrideC, 8, 8 ); | |
| 358 | + WelsMbCopy( pDecV, iDecStrideC, pSrcV, iCsStrideC, 8, 8 ); | |
| 359 | + | |
| 360 | + return 0; | |
| 361 | + } | |
| 362 | + else if(IS_INTRA(pCurLayer->pMbType[pCurLayer->iMbXyIndex])) | |
| 363 | + { | |
| 364 | + WelsMbIntraPredictionConstruction(pCtx, pCurLayer, 1); | |
| 365 | + } | |
| 366 | + else if ( IS_INTER( pCurLayer->pMbType[pCurLayer->iMbXyIndex] ) ) //InterMB | |
| 367 | + { | |
| 368 | + if ( 0 == pCurLayer->pCbp[pCurLayer->iMbXyIndex] ) //uiCbp==0 include SKIP | |
| 369 | + { | |
| 370 | + WelsMbInterPrediction( pCtx, pCurLayer ); | |
| 371 | + } | |
| 372 | + else | |
| 373 | + { | |
| 374 | + WelsMbInterConstruction( pCtx, pCurLayer ); | |
| 375 | + } | |
| 376 | + } | |
| 377 | + else | |
| 378 | + { | |
| 379 | + WelsLog( pCtx, WELS_LOG_WARNING, "WelsTargetMbConstruction():::::Unknown MB type: %d\n", pCurLayer->pMbType[pCurLayer->iMbXyIndex] ); | |
| 380 | + return -1; | |
| 381 | + } | |
| 382 | + | |
| 383 | + return 0; | |
| 384 | +} | |
| 385 | + | |
| 386 | +void_t WelsChromaDcIdct( int16_t *pBlock ) | |
| 387 | +{ | |
| 388 | + int32_t iStride= 32; | |
| 389 | + int32_t iXStride= 16; | |
| 390 | + int32_t iStride1 = iXStride + iStride; | |
| 391 | + int16_t* pBlk = pBlock; | |
| 392 | + int32_t iA,iB,iC,iD,iE; | |
| 393 | + | |
| 394 | + iA= pBlk[0]; | |
| 395 | + iB= pBlk[iXStride]; | |
| 396 | + iC= pBlk[iStride]; | |
| 397 | + iD= pBlk[iStride1]; | |
| 398 | + | |
| 399 | + iE = iA-iB; | |
| 400 | + iA += iB; | |
| 401 | + iB = iC-iD; | |
| 402 | + iC += iD; | |
| 403 | + | |
| 404 | + pBlk[0]= (iA+iC) >> 1; | |
| 405 | + pBlk[iXStride]= (iE+iB) >> 1; | |
| 406 | + pBlk[iStride]= (iA-iC) >> 1; | |
| 407 | + pBlk[iStride1]= (iE-iB) >> 1; | |
| 408 | +} | |
| 409 | + | |
| 410 | +int32_t WelsDecodeSlice(PWelsDecoderContext pCtx, bool_t bFirstSliceInLayer, PNalUnit pNalCur) | |
| 411 | +{ | |
| 412 | + PDqLayer pCurLayer = pCtx->pCurDqLayer; | |
| 413 | + PFmo pFmo = pCtx->pFmo; | |
| 414 | + int32_t i, iRet; | |
| 415 | + int32_t iNextMbXyIndex, iSliceIdc; | |
| 416 | + | |
| 417 | + PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | |
| 418 | + PSliceHeaderExt pSliceHeaderExt = &pSlice->sSliceHeaderExt; | |
| 419 | + PSliceHeader pSliceHeader = &pSliceHeaderExt->sSliceHeader; | |
| 420 | + int32_t iMbX, iMbY; | |
| 421 | + const int32_t kiCountNumMb = pSliceHeader->pSps->uiTotalMbCount; //need to be correct when fmo or multi slice | |
| 422 | + PBitStringAux pBs = pCurLayer->pBitStringAux; | |
| 423 | + int32_t iUsedBits = 0; | |
| 424 | + | |
| 425 | + PWelsDecMbCavlcFunc pDecMbCavlcFunc; | |
| 426 | + | |
| 427 | + pSlice->iTotalMbInCurSlice = 0; //initialize at the starting of slice decoding. | |
| 428 | + | |
| 429 | + if ( P_SLICE == pSliceHeader->eSliceType ) | |
| 430 | + { | |
| 431 | + pDecMbCavlcFunc = WelsDecodeMbCavlcPSlice; | |
| 432 | + } | |
| 433 | + else //I_SLICE | |
| 434 | + { | |
| 435 | + pDecMbCavlcFunc = WelsDecodeMbCavlcISlice; | |
| 436 | + } | |
| 437 | + | |
| 438 | + if ( pSliceHeader->pPps->bConstainedIntraPredFlag ) | |
| 439 | + { | |
| 440 | + pCtx->pFillInfoCacheIntra4x4Func = WelsFillCacheConstrain1Intra4x4; | |
| 441 | + pCtx->pParseIntra4x4ModeFunc = ParseIntra4x4ModeConstrain1; | |
| 442 | + pCtx->pParseIntra16x16ModeFunc = ParseIntra16x16ModeConstrain1; | |
| 443 | + } | |
| 444 | + else | |
| 445 | + { | |
| 446 | + pCtx->pFillInfoCacheIntra4x4Func = WelsFillCacheConstrain0Intra4x4; | |
| 447 | + pCtx->pParseIntra4x4ModeFunc = ParseIntra4x4ModeConstrain0; | |
| 448 | + pCtx->pParseIntra16x16ModeFunc = ParseIntra16x16ModeConstrain0; | |
| 449 | + } | |
| 450 | + | |
| 451 | + pCtx->eSliceType = pSliceHeader->eSliceType; | |
| 452 | + | |
| 453 | + if (pCurLayer->sLayerInfo.pPps->bEntropyCodingModeFlag == 1) | |
| 454 | + { | |
| 455 | + //CABAC encoding is unsupported yet! | |
| 456 | + return -1; | |
| 457 | + } | |
| 458 | + | |
| 459 | + iNextMbXyIndex = pSliceHeader->iFirstMbInSlice; | |
| 460 | + | |
| 461 | + if ( iNextMbXyIndex >= kiCountNumMb ) | |
| 462 | + { | |
| 463 | + WelsLog(pCtx, WELS_LOG_ERROR, "WelsDecodeSlice()::iFirstMbInSlice(%d) > pSps->kiTotalMb(%d). ERROR!!! resolution change....\n", | |
| 464 | + iNextMbXyIndex, kiCountNumMb); | |
| 465 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 466 | + return dsNoParamSets; | |
| 467 | + } | |
| 468 | + | |
| 469 | + iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; | |
| 470 | + iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; // error is introduced by multiple slices case, 11/23/2009 | |
| 471 | + pSlice->iMbSkipRun = -1; | |
| 472 | + iSliceIdc = (pSliceHeader->iFirstMbInSlice<<7)+pCurLayer->uiLayerDqId; | |
| 473 | + | |
| 474 | + pCurLayer->iMbX = iMbX; | |
| 475 | + pCurLayer->iMbY = iMbY; | |
| 476 | + pCurLayer->iMbXyIndex = iNextMbXyIndex; | |
| 477 | + | |
| 478 | + if(pSliceHeaderExt->bSliceSkipFlag == 1) | |
| 479 | + { | |
| 480 | + for(i=0; i<(int32_t)pSliceHeaderExt->uiNumMbsInSlice; i++) | |
| 481 | + { | |
| 482 | + pCurLayer->pSliceIdc[iNextMbXyIndex] = iSliceIdc; | |
| 483 | + | |
| 484 | + | |
| 485 | + pCurLayer->pResidualPredFlag[iNextMbXyIndex] = 1; | |
| 486 | + | |
| 487 | + if ( pSliceHeaderExt->sSliceHeader.pPps->uiNumSliceGroups > 1 ) | |
| 488 | + { | |
| 489 | + iNextMbXyIndex = FmoNextMb( pFmo, iNextMbXyIndex ); | |
| 490 | + } | |
| 491 | + else | |
| 492 | + { | |
| 493 | + ++iNextMbXyIndex; | |
| 494 | + } | |
| 495 | + | |
| 496 | + iMbX = iNextMbXyIndex%pCurLayer->iMbWidth; | |
| 497 | + iMbY = iNextMbXyIndex%pCurLayer->iMbHeight; | |
| 498 | + | |
| 499 | + pCurLayer->iMbX = iMbX; | |
| 500 | + pCurLayer->iMbY = iMbY; | |
| 501 | + pCurLayer->iMbXyIndex = iNextMbXyIndex; | |
| 502 | + } | |
| 503 | + return 0; | |
| 504 | + } | |
| 505 | + | |
| 506 | + do{ | |
| 507 | + pCurLayer->pSliceIdc[iNextMbXyIndex] = iSliceIdc; | |
| 508 | + iRet = pDecMbCavlcFunc( pCtx, pNalCur ); | |
| 509 | + | |
| 510 | + if (iRet != ERR_NONE){ | |
| 511 | + return iRet; | |
| 512 | + } | |
| 513 | + | |
| 514 | + ++pSlice->iTotalMbInCurSlice; | |
| 515 | + | |
| 516 | + if ( pSliceHeader->pPps->uiNumSliceGroups > 1 ) | |
| 517 | + { | |
| 518 | + iNextMbXyIndex = FmoNextMb( pFmo, iNextMbXyIndex ); | |
| 519 | + } | |
| 520 | + else | |
| 521 | + { | |
| 522 | + ++iNextMbXyIndex; | |
| 523 | + } | |
| 524 | + if ( (-1 == iNextMbXyIndex) || (iNextMbXyIndex >= kiCountNumMb) ) // slice group boundary or end of a frame | |
| 525 | + { | |
| 526 | + break; | |
| 527 | + } | |
| 528 | + | |
| 529 | + // check whether there is left bits to read next time in case multiple slices | |
| 530 | + iUsedBits = ((pBs->pCurBuf-pBs->pStartBuf)<<3) - (16-pBs->iLeftBits); | |
| 531 | + if ( iUsedBits == pBs->iBits && 0 >= pCurLayer->sLayerInfo.sSliceInLayer.iMbSkipRun ) // slice boundary | |
| 532 | + { | |
| 533 | + break; | |
| 534 | + } | |
| 535 | + if ( iUsedBits > pBs->iBits )//When BS incomplete, as long as find it, SHOULD stop decoding to avoid mosaic or crash. | |
| 536 | + { | |
| 537 | + WelsLog( pCtx, WELS_LOG_WARNING, "WelsDecodeSlice()::::pBs incomplete, iUsedBits:%d > pBs->iBits:%d, MUST stop decoding.\n", | |
| 538 | + iUsedBits, pBs->iBits ); | |
| 539 | + return -1; | |
| 540 | + } | |
| 541 | + iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; | |
| 542 | + iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; | |
| 543 | + pCurLayer->iMbX = iMbX; | |
| 544 | + pCurLayer->iMbY = iMbY; | |
| 545 | + pCurLayer->iMbXyIndex = iNextMbXyIndex; | |
| 546 | + }while(1); | |
| 547 | + | |
| 548 | + return ERR_NONE; | |
| 549 | +} | |
| 550 | + | |
| 551 | +int32_t WelsActualDecodeMbCavlcISlice(PWelsDecoderContext pCtx) | |
| 552 | +{ | |
| 553 | + SVlcTable* pVlcTable = &pCtx->sVlcTable; | |
| 554 | + PDqLayer pCurLayer = pCtx->pCurDqLayer; | |
| 555 | + PBitStringAux pBs = pCurLayer->pBitStringAux; | |
| 556 | + PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | |
| 557 | + PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 558 | + | |
| 559 | + SNeighAvail sNeighAvail; | |
| 560 | + | |
| 561 | + int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; | |
| 562 | + int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; | |
| 563 | + | |
| 564 | + int32_t iMbX = pCurLayer->iMbX; | |
| 565 | + int32_t iMbY = pCurLayer->iMbY; | |
| 566 | + int32_t iMbXy = pCurLayer->iMbXyIndex; | |
| 567 | + int32_t iNMbMode, i; | |
| 568 | + uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0; | |
| 569 | + | |
| 570 | + FORCE_STACK_ALIGN_1D( uint8_t, pNonZeroCount, 48, 16 ); | |
| 571 | + | |
| 572 | + pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | |
| 573 | + pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag; | |
| 574 | + | |
| 575 | + uiMbType = BsGetUe(pBs); | |
| 576 | + if ( uiMbType > 25 ) | |
| 577 | + { | |
| 578 | + return ERR_INFO_INVALID_MB_TYPE; | |
| 579 | + } | |
| 580 | + | |
| 581 | + if ( 25 == uiMbType ) | |
| 582 | + { | |
| 583 | + int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; | |
| 584 | + int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1]; | |
| 585 | + | |
| 586 | + int32_t iOffsetL = ( iMbX + iMbY * iDecStrideL ) << 4; | |
| 587 | + int32_t iOffsetC = ( iMbX + iMbY * iDecStrideC ) << 3; | |
| 588 | + | |
| 589 | + uint8_t* pDecY = pCurLayer->pCsData[0] + iOffsetL; | |
| 590 | + uint8_t* pDecU = pCurLayer->pCsData[1] + iOffsetC; | |
| 591 | + uint8_t* pDecV = pCurLayer->pCsData[2] + iOffsetC; | |
| 592 | + | |
| 593 | + uint8_t *pTmpBsBuf; | |
| 594 | + | |
| 595 | + int32_t i; | |
| 596 | + int32_t iCopySizeY = ( sizeof( uint8_t ) << 4 ); | |
| 597 | + int32_t iCopySizeUV = ( sizeof( uint8_t ) << 3 ); | |
| 598 | + | |
| 599 | + int32_t iIndex = ((-pBs->iLeftBits)>>3) + 2; | |
| 600 | + | |
| 601 | + pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM; | |
| 602 | + | |
| 603 | + //step 1: locating bit-stream pointer [must align into integer byte] | |
| 604 | + pBs->pCurBuf -= iIndex; | |
| 605 | + | |
| 606 | + //step 2: copy pixel from bit-stream into fdec [reconstruction] | |
| 607 | + pTmpBsBuf = pBs->pCurBuf; | |
| 608 | + for ( i = 0; i < 16; i++ ) //luma | |
| 609 | + { | |
| 610 | + memcpy( pDecY , pTmpBsBuf, iCopySizeY ); | |
| 611 | + pDecY += iDecStrideL; | |
| 612 | + pTmpBsBuf += 16; | |
| 613 | + } | |
| 614 | + for ( i = 0; i < 8; i++ ) //cb | |
| 615 | + { | |
| 616 | + memcpy( pDecU, pTmpBsBuf, iCopySizeUV ); | |
| 617 | + pDecU += iDecStrideC; | |
| 618 | + pTmpBsBuf += 8; | |
| 619 | + } | |
| 620 | + for ( i = 0; i < 8; i++ ) //cr | |
| 621 | + { | |
| 622 | + memcpy( pDecV, pTmpBsBuf, iCopySizeUV ); | |
| 623 | + pDecV += iDecStrideC; | |
| 624 | + pTmpBsBuf += 8; | |
| 625 | + } | |
| 626 | + | |
| 627 | + pBs->pCurBuf += 384; | |
| 628 | + InitReadBits( pBs ); | |
| 629 | + | |
| 630 | + //step 3: update QP and pNonZeroCount | |
| 631 | + pCurLayer->pLumaQp[iMbXy] = 0; | |
| 632 | + pCurLayer->pChromaQp[iMbXy] = 0; | |
| 633 | + memset( pCurLayer->pNzc[iMbXy], 16, sizeof( pCurLayer->pNzc[iMbXy] ) ); //JVT-x201wcm1.doc, page229, 2009.10.23 | |
| 634 | + return 0; | |
| 635 | + } | |
| 636 | + else if (0 == uiMbType) //reference to JM | |
| 637 | + { | |
| 638 | + FORCE_STACK_ALIGN_1D( int8_t, pIntraPredMode, 48, 16 ); | |
| 639 | + pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; | |
| 640 | + pCtx->pFillInfoCacheIntra4x4Func( &sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer ); | |
| 641 | + if ( pCtx->pParseIntra4x4ModeFunc( &sNeighAvail, pIntraPredMode, pBs, pCurLayer ) ) | |
| 642 | + { | |
| 643 | + return -1; | |
| 644 | + } | |
| 645 | + | |
| 646 | + //uiCbp | |
| 647 | + uiCbp = BsGetUe(pBs); | |
| 648 | + //G.9.1 Alternative parsing process for coded pBlock pattern | |
| 649 | + if ( uiCbp > 47 ) | |
| 650 | + return ERR_INFO_INVALID_CBP; | |
| 651 | + | |
| 652 | + uiCbp = g_kuiIntra4x4CbpTable[uiCbp]; | |
| 653 | + | |
| 654 | + pCurLayer->pCbp[iMbXy] = uiCbp; | |
| 655 | + uiCbpC = uiCbp >> 4; | |
| 656 | + uiCbpL = uiCbp & 15; | |
| 657 | + } | |
| 658 | + else //I_PCM exclude, we can ignore it | |
| 659 | + { | |
| 660 | + pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; | |
| 661 | + pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType-1) & 3; | |
| 662 | + pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[(uiMbType-1)>>2]; | |
| 663 | + uiCbpC = pCurLayer->pCbp[iMbXy] >> 4; | |
| 664 | + uiCbpL = pCurLayer->pCbp[iMbXy] & 15; | |
| 665 | + WelsFillCacheNonZeroCount( &sNeighAvail, pNonZeroCount, pCurLayer ); | |
| 666 | + if ( pCtx->pParseIntra16x16ModeFunc( &sNeighAvail, pBs, pCurLayer ) ) | |
| 667 | + { | |
| 668 | + return -1; | |
| 669 | + } | |
| 670 | + } | |
| 671 | + | |
| 672 | + iNMbMode = BASE_MB; | |
| 673 | + | |
| 674 | + memset(pCurLayer->pScaledTCoeff[iMbXy], 0, 384*sizeof(pCurLayer->pScaledTCoeff[iMbXy][0])); | |
| 675 | + ST32(&pCurLayer->pNzc[iMbXy][0], 0); | |
| 676 | + ST32(&pCurLayer->pNzc[iMbXy][4], 0); | |
| 677 | + ST32(&pCurLayer->pNzc[iMbXy][8], 0); | |
| 678 | + ST32(&pCurLayer->pNzc[iMbXy][12], 0); | |
| 679 | + ST32(&pCurLayer->pNzc[iMbXy][16], 0); | |
| 680 | + ST32(&pCurLayer->pNzc[iMbXy][20], 0); | |
| 681 | + | |
| 682 | + if( pCurLayer->pCbp[iMbXy] == 0 && IS_INTRA4x4(pCurLayer->pMbType[iMbXy])) | |
| 683 | + { | |
| 684 | + pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; | |
| 685 | + pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pCurLayer->pLumaQp[iMbXy] + | |
| 686 | + pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)]; | |
| 687 | + | |
| 688 | + } | |
| 689 | + | |
| 690 | + if ( pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy] ) | |
| 691 | + { | |
| 692 | + int32_t iQpDelta, iId8x8, iId4x4; | |
| 693 | + | |
| 694 | + iQpDelta = BsGetSe(pBs); | |
| 695 | + | |
| 696 | + if (iQpDelta > 25 || iQpDelta < -26) //out of iQpDelta range | |
| 697 | + { | |
| 698 | + return ERR_INFO_INVALID_QP; | |
| 699 | + } | |
| 700 | + | |
| 701 | + pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp + iQpDelta; //update iLastMbQp | |
| 702 | + //refer to JVT-X201wcm1.doc equation(7-35) | |
| 703 | + if ( (unsigned)(pCurLayer->pLumaQp[iMbXy]) > 51 ) | |
| 704 | + { | |
| 705 | + if ( pCurLayer->pLumaQp[iMbXy] < 0 ) | |
| 706 | + { | |
| 707 | + pCurLayer->pLumaQp[iMbXy] += 52; | |
| 708 | + } | |
| 709 | + else | |
| 710 | + { | |
| 711 | + pCurLayer->pLumaQp[iMbXy] -= 52; | |
| 712 | + } | |
| 713 | + } | |
| 714 | + //QP should be in the range of [0, 51] | |
| 715 | + if ( pCurLayer->pLumaQp[iMbXy] < 0 || pCurLayer->pLumaQp[iMbXy] > 51 ) | |
| 716 | + { | |
| 717 | + return ERR_INFO_INVALID_QP; | |
| 718 | + } | |
| 719 | + pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; | |
| 720 | + pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pSlice->iLastMbQp + pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)]; | |
| 721 | + | |
| 722 | + | |
| 723 | + BsStartCavlc( pBs ); | |
| 724 | + | |
| 725 | + if ( MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy] ) | |
| 726 | + { | |
| 727 | + //step1: Luma DC | |
| 728 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, 0, 16, | |
| 729 | + g_kuiLumaDcZigzagScan, I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) ) | |
| 730 | + { | |
| 731 | + return -1;//abnormal | |
| 732 | + } | |
| 733 | + //step2: Luma AC | |
| 734 | + if (uiCbpL) | |
| 735 | + { | |
| 736 | + for (i = 0; i < 16; i++) | |
| 737 | + { | |
| 738 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, i, | |
| 739 | + iScanIdxEnd - WELS_MAX(iScanIdxStart, 1) + 1, g_kuiZigzagScan+ WELS_MAX(iScanIdxStart,1), | |
| 740 | + I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i<<4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) ) | |
| 741 | + { | |
| 742 | + return -1;//abnormal | |
| 743 | + } | |
| 744 | + } | |
| 745 | + ST32(&pCurLayer->pNzc[iMbXy][0], LD32(&pNonZeroCount[1+8*1])); | |
| 746 | + ST32(&pCurLayer->pNzc[iMbXy][4], LD32(&pNonZeroCount[1+8*2])); | |
| 747 | + ST32(&pCurLayer->pNzc[iMbXy][8], LD32(&pNonZeroCount[1+8*3])); | |
| 748 | + ST32(&pCurLayer->pNzc[iMbXy][12], LD32(&pNonZeroCount[1+8*4])); | |
| 749 | + } | |
| 750 | + else //pNonZeroCount = 0 | |
| 751 | + { | |
| 752 | + ST32(&pCurLayer->pNzc[iMbXy][0], 0); | |
| 753 | + ST32(&pCurLayer->pNzc[iMbXy][4], 0); | |
| 754 | + ST32(&pCurLayer->pNzc[iMbXy][8], 0); | |
| 755 | + ST32(&pCurLayer->pNzc[iMbXy][12], 0); | |
| 756 | + } | |
| 757 | + } | |
| 758 | + else //non-MB_TYPE_INTRA16x16 | |
| 759 | + { | |
| 760 | + for (iId8x8 = 0; iId8x8 < 4; iId8x8++) | |
| 761 | + { | |
| 762 | + if (uiCbpL & (1 << iId8x8)) | |
| 763 | + { | |
| 764 | + int32_t iIndex = (iId8x8 << 2); | |
| 765 | + for (iId4x4 = 0; iId4x4 < 4; iId4x4++) | |
| 766 | + { | |
| 767 | + //Luma (DC and AC decoding together) | |
| 768 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, iIndex, | |
| 769 | + iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan+iScanIdxStart, | |
| 770 | + LUMA_DC_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex<<4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) ) | |
| 771 | + { | |
| 772 | + return -1;//abnormal | |
| 773 | + } | |
| 774 | + iIndex++; | |
| 775 | + } | |
| 776 | + } | |
| 777 | + else | |
| 778 | + { | |
| 779 | + ST16(&pNonZeroCount[g_kuiCacheNzcScanIdx[(iId8x8<<2)]], 0); | |
| 780 | + ST16(&pNonZeroCount[g_kuiCacheNzcScanIdx[(iId8x8<<2)+2]], 0); | |
| 781 | + } | |
| 782 | + } | |
| 783 | + ST32(&pCurLayer->pNzc[iMbXy][0], LD32(&pNonZeroCount[1+8*1])); | |
| 784 | + ST32(&pCurLayer->pNzc[iMbXy][4], LD32(&pNonZeroCount[1+8*2])); | |
| 785 | + ST32(&pCurLayer->pNzc[iMbXy][8], LD32(&pNonZeroCount[1+8*3])); | |
| 786 | + ST32(&pCurLayer->pNzc[iMbXy][12], LD32(&pNonZeroCount[1+8*4])); | |
| 787 | + } | |
| 788 | + | |
| 789 | + //chroma | |
| 790 | + //step1: DC | |
| 791 | + if ( 1 == uiCbpC || 2 == uiCbpC ) | |
| 792 | + { | |
| 793 | + for (i = 0; i < 2; i++) //Cb Cr | |
| 794 | + { | |
| 795 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, | |
| 796 | + 16 + (i << 2), 4, g_kuiChromaDcScan, CHROMA_DC, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i<<6), | |
| 797 | + iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx) ) | |
| 798 | + { | |
| 799 | + return -1;//abnormal | |
| 800 | + } | |
| 801 | + } | |
| 802 | + } | |
| 803 | + | |
| 804 | + //step2: AC | |
| 805 | + if (2 == uiCbpC) | |
| 806 | + { | |
| 807 | + for (i = 0; i < 2; i++) //Cb Cr | |
| 808 | + { | |
| 809 | + int32_t iIndex = 16 + (i<<2); | |
| 810 | + for (iId4x4 = 0; iId4x4 < 4; iId4x4++) | |
| 811 | + { | |
| 812 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, iIndex, | |
| 813 | + iScanIdxEnd - WELS_MAX(iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX(iScanIdxStart,1), | |
| 814 | + CHROMA_AC, pCurLayer->pScaledTCoeff[iMbXy]+(iIndex<<4), iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx) ) | |
| 815 | + { | |
| 816 | + return -1;//abnormal | |
| 817 | + } | |
| 818 | + iIndex++; | |
| 819 | + } | |
| 820 | + } | |
| 821 | + ST16(&pCurLayer->pNzc[iMbXy][16], LD16(&pNonZeroCount[6+8*1])); | |
| 822 | + ST16(&pCurLayer->pNzc[iMbXy][20], LD16(&pNonZeroCount[6+8*2])); | |
| 823 | + ST16(&pCurLayer->pNzc[iMbXy][18], LD16(&pNonZeroCount[6+8*4])); | |
| 824 | + ST16(&pCurLayer->pNzc[iMbXy][22], LD16(&pNonZeroCount[6+8*5])); | |
| 825 | + } | |
| 826 | + else | |
| 827 | + { | |
| 828 | + ST16(&pCurLayer->pNzc[iMbXy][16], 0); | |
| 829 | + ST16(&pCurLayer->pNzc[iMbXy][20], 0); | |
| 830 | + ST16(&pCurLayer->pNzc[iMbXy][18], 0); | |
| 831 | + ST16(&pCurLayer->pNzc[iMbXy][22], 0); | |
| 832 | + } | |
| 833 | + BsEndCavlc( pBs ); | |
| 834 | + } | |
| 835 | + else | |
| 836 | + { | |
| 837 | + ST32(&pCurLayer->pNzc[iMbXy][0], 0); | |
| 838 | + ST32(&pCurLayer->pNzc[iMbXy][4], 0); | |
| 839 | + ST32(&pCurLayer->pNzc[iMbXy][8], 0); | |
| 840 | + ST32(&pCurLayer->pNzc[iMbXy][12], 0); | |
| 841 | + ST32(&pCurLayer->pNzc[iMbXy][16], 0); | |
| 842 | + ST32(&pCurLayer->pNzc[iMbXy][20], 0); | |
| 843 | + } | |
| 844 | + | |
| 845 | + return 0; | |
| 846 | +} | |
| 847 | + | |
| 848 | +int32_t WelsDecodeMbCavlcISlice(PWelsDecoderContext pCtx, PNalUnit pNalCur) | |
| 849 | +{ | |
| 850 | + PDqLayer pCurLayer = pCtx->pCurDqLayer; | |
| 851 | + PBitStringAux pBs = pCurLayer->pBitStringAux; | |
| 852 | + PSliceHeaderExt pSliceHeaderExt = &pCurLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt; | |
| 853 | + int32_t iBaseModeFlag; | |
| 854 | + int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15 | |
| 855 | + | |
| 856 | + if( pSliceHeaderExt->bAdaptiveBaseModeFlag == 1) | |
| 857 | + { | |
| 858 | + iBaseModeFlag = BsGetOneBit(pBs); | |
| 859 | + } | |
| 860 | + else | |
| 861 | + { | |
| 862 | + iBaseModeFlag = pSliceHeaderExt->bDefaultBaseModeFlag; | |
| 863 | + } | |
| 864 | + if( !iBaseModeFlag ) | |
| 865 | + { | |
| 866 | + iRet = WelsActualDecodeMbCavlcISlice( pCtx); | |
| 867 | + } | |
| 868 | + else | |
| 869 | + { | |
| 870 | + WelsLog( pCtx, WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.\n", iBaseModeFlag); | |
| 871 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP); | |
| 872 | + } | |
| 873 | + if ( iRet ) //occur error when parsing, MUST STOP decoding | |
| 874 | + { | |
| 875 | + return iRet; | |
| 876 | + } | |
| 877 | + | |
| 878 | + return 0; | |
| 879 | +} | |
| 880 | + | |
| 881 | +int32_t WelsActualDecodeMbCavlcPSlice(PWelsDecoderContext pCtx) | |
| 882 | +{ | |
| 883 | + SVlcTable* pVlcTable = &pCtx->sVlcTable; | |
| 884 | + PDqLayer pCurLayer = pCtx->pCurDqLayer; | |
| 885 | + PBitStringAux pBs = pCurLayer->pBitStringAux; | |
| 886 | + PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | |
| 887 | + PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 888 | + | |
| 889 | + SNeighAvail sNeighAvail; | |
| 890 | + | |
| 891 | + int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; | |
| 892 | + int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; | |
| 893 | + | |
| 894 | + int32_t iMbX = pCurLayer->iMbX; | |
| 895 | + int32_t iMbY = pCurLayer->iMbY; | |
| 896 | + int32_t iMbXy = pCurLayer->iMbXyIndex; | |
| 897 | + | |
| 898 | + int32_t iNMbMode, i; | |
| 899 | + uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0; | |
| 900 | + | |
| 901 | + FORCE_STACK_ALIGN_1D( uint8_t, pNonZeroCount, 48, 16 ); | |
| 902 | + pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;//2009.10.23 | |
| 903 | + | |
| 904 | + uiMbType = BsGetUe(pBs); | |
| 905 | + if (uiMbType < 5) //inter MB type | |
| 906 | + { | |
| 907 | + int16_t iMotionVector[LIST_A][30][MV_A]; | |
| 908 | + | |
| 909 | + int8_t iRefIndex[LIST_A][30]; | |
| 910 | + pCurLayer->pMbType[iMbXy] = g_ksInterMbTypeInfo[uiMbType].iType; | |
| 911 | + WelsFillCacheInter( &sNeighAvail, pNonZeroCount, iMotionVector, iRefIndex, pCurLayer ); | |
| 912 | + if ( ParseInterInfo(pCtx, iMotionVector, iRefIndex, pBs) ) | |
| 913 | + { | |
| 914 | + return -1;//abnormal | |
| 915 | + } | |
| 916 | + | |
| 917 | + if( pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag ==1 ) | |
| 918 | + { | |
| 919 | + pCurLayer->pResidualPredFlag[iMbXy] = BsGetOneBit(pBs); | |
| 920 | + } | |
| 921 | + else | |
| 922 | + { | |
| 923 | + pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag; | |
| 924 | + } | |
| 925 | + | |
| 926 | + if(pCurLayer->pResidualPredFlag[iMbXy] == 0) | |
| 927 | + { | |
| 928 | + iNMbMode = BASE_MB; | |
| 929 | + pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | |
| 930 | + } | |
| 931 | + else | |
| 932 | + { | |
| 933 | + WelsLog(pCtx, WELS_LOG_WARNING, "residual_pred_flag = 1 not supported.\n"); | |
| 934 | + return -1; | |
| 935 | + } | |
| 936 | + } | |
| 937 | + else //intra MB type | |
| 938 | + { | |
| 939 | + uiMbType -= 5; | |
| 940 | + if ( uiMbType > 25 ) | |
| 941 | + { | |
| 942 | + return ERR_INFO_INVALID_MB_TYPE; | |
| 943 | + } | |
| 944 | + | |
| 945 | + if ( 25 == uiMbType ) | |
| 946 | + { | |
| 947 | + int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; | |
| 948 | + int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1]; | |
| 949 | + | |
| 950 | + int32_t iOffsetL = ( iMbX + iMbY * iDecStrideL ) << 4; | |
| 951 | + int32_t iOffsetC = ( iMbX + iMbY * iDecStrideC ) << 3; | |
| 952 | + | |
| 953 | + uint8_t* pDecY = pCurLayer->pCsData[0] + iOffsetL; | |
| 954 | + uint8_t* pDecU = pCurLayer->pCsData[1] + iOffsetC; | |
| 955 | + uint8_t* pDecV = pCurLayer->pCsData[2] + iOffsetC; | |
| 956 | + | |
| 957 | + uint8_t *pTmpBsBuf; | |
| 958 | + | |
| 959 | + int32_t i; | |
| 960 | + int32_t iCopySizeY = ( sizeof( uint8_t ) << 4 ); | |
| 961 | + int32_t iCopySizeUV = ( sizeof( uint8_t ) << 3 ); | |
| 962 | + | |
| 963 | + int32_t iIndex = ((-pBs->iLeftBits)>>3) + 2; | |
| 964 | + | |
| 965 | + pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM; | |
| 966 | + | |
| 967 | + //step 1: locating bit-stream pointer [must align into integer byte] | |
| 968 | + pBs->pCurBuf -= iIndex; | |
| 969 | + | |
| 970 | + //step 2: copy pixel from bit-stream into fdec [reconstruction] | |
| 971 | + pTmpBsBuf = pBs->pCurBuf; | |
| 972 | + for ( i = 0; i < 16; i++ ) //luma | |
| 973 | + { | |
| 974 | + memcpy( pDecY , pTmpBsBuf, iCopySizeY ); | |
| 975 | + pDecY += iDecStrideL; | |
| 976 | + pTmpBsBuf += 16; | |
| 977 | + } | |
| 978 | + | |
| 979 | + for ( i = 0; i < 8; i++ ) //cb | |
| 980 | + { | |
| 981 | + memcpy( pDecU, pTmpBsBuf, iCopySizeUV ); | |
| 982 | + pDecU += iDecStrideC; | |
| 983 | + pTmpBsBuf += 8; | |
| 984 | + } | |
| 985 | + for ( i = 0; i < 8; i++ ) //cr | |
| 986 | + { | |
| 987 | + memcpy( pDecV, pTmpBsBuf, iCopySizeUV ); | |
| 988 | + pDecV += iDecStrideC; | |
| 989 | + pTmpBsBuf += 8; | |
| 990 | + } | |
| 991 | + | |
| 992 | + pBs->pCurBuf += 384; | |
| 993 | + InitReadBits( pBs ); | |
| 994 | + | |
| 995 | + //step 3: update QP and pNonZeroCount | |
| 996 | + pCurLayer->pLumaQp[iMbXy] = 0; | |
| 997 | + pCurLayer->pChromaQp[iMbXy] = 0; | |
| 998 | + ST32(&pCurLayer->pNzc[iMbXy][0], 0); | |
| 999 | + ST32(&pCurLayer->pNzc[iMbXy][4], 0); | |
| 1000 | + ST32(&pCurLayer->pNzc[iMbXy][8], 0); | |
| 1001 | + ST32(&pCurLayer->pNzc[iMbXy][12], 0); | |
| 1002 | + return 0; | |
| 1003 | + } | |
| 1004 | + else | |
| 1005 | + { | |
| 1006 | + if (0 == uiMbType) | |
| 1007 | + { | |
| 1008 | + FORCE_STACK_ALIGN_1D( int8_t, pIntraPredMode, 48, 16 ); | |
| 1009 | + pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; | |
| 1010 | + pCtx->pFillInfoCacheIntra4x4Func( &sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer ); | |
| 1011 | + if ( pCtx->pParseIntra4x4ModeFunc( &sNeighAvail, pIntraPredMode, pBs, pCurLayer ) ) | |
| 1012 | + { | |
| 1013 | + return -1; | |
| 1014 | + } | |
| 1015 | + iNMbMode = BASE_MB; | |
| 1016 | + } | |
| 1017 | + else //I_PCM exclude, we can ignore it | |
| 1018 | + { | |
| 1019 | + pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; | |
| 1020 | + pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType-1) & 3; | |
| 1021 | + pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[(uiMbType-1)>>2]; | |
| 1022 | + uiCbpC = pCurLayer->pCbp[iMbXy] >> 4; | |
| 1023 | + uiCbpL = pCurLayer->pCbp[iMbXy] & 15; | |
| 1024 | + WelsFillCacheNonZeroCount( &sNeighAvail, pNonZeroCount, pCurLayer ); | |
| 1025 | + if ( pCtx->pParseIntra16x16ModeFunc( &sNeighAvail, pBs, pCurLayer ) ) | |
| 1026 | + { | |
| 1027 | + return -1; | |
| 1028 | + } | |
| 1029 | + iNMbMode = BASE_MB; | |
| 1030 | + } | |
| 1031 | + } | |
| 1032 | + } | |
| 1033 | + | |
| 1034 | + if ( MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy] ) | |
| 1035 | + { | |
| 1036 | + uiCbp = BsGetUe(pBs); | |
| 1037 | + { | |
| 1038 | + if ( uiCbp > 47 ) | |
| 1039 | + return ERR_INFO_INVALID_CBP; | |
| 1040 | + | |
| 1041 | + if (MB_TYPE_INTRA4x4 == pCurLayer->pMbType[iMbXy]) | |
| 1042 | + { | |
| 1043 | + uiCbp = g_kuiIntra4x4CbpTable[uiCbp]; | |
| 1044 | + } | |
| 1045 | + else //inter | |
| 1046 | + uiCbp = g_kuiInterCbpTable[uiCbp]; | |
| 1047 | + } | |
| 1048 | + | |
| 1049 | + pCurLayer->pCbp[iMbXy] = uiCbp; | |
| 1050 | + uiCbpC = pCurLayer->pCbp[iMbXy] >> 4; | |
| 1051 | + uiCbpL = pCurLayer->pCbp[iMbXy] & 15; | |
| 1052 | + } | |
| 1053 | + | |
| 1054 | + if(iNMbMode == BASE_MB) | |
| 1055 | + { | |
| 1056 | + pCtx->sBlockFunc.pWelsBlockZero16x16Func(pCurLayer->pScaledTCoeff[iMbXy], 16); | |
| 1057 | + pCtx->sBlockFunc.pWelsBlockZero8x8Func(pCurLayer->pScaledTCoeff[iMbXy]+256, 8); | |
| 1058 | + pCtx->sBlockFunc.pWelsBlockZero8x8Func(pCurLayer->pScaledTCoeff[iMbXy]+256+64, 8); | |
| 1059 | + | |
| 1060 | + ST32(&pCurLayer->pNzc[iMbXy][0], 0); | |
| 1061 | + ST32(&pCurLayer->pNzc[iMbXy][4], 0); | |
| 1062 | + ST32(&pCurLayer->pNzc[iMbXy][8], 0); | |
| 1063 | + ST32(&pCurLayer->pNzc[iMbXy][12], 0); | |
| 1064 | + ST32(&pCurLayer->pNzc[iMbXy][20], 0); | |
| 1065 | + if( pCurLayer->pCbp[iMbXy] == 0 && !IS_INTRA16x16(pCurLayer->pMbType[iMbXy]) && !IS_I_BL(pCurLayer->pMbType[iMbXy])) | |
| 1066 | + { | |
| 1067 | + pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; | |
| 1068 | + pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pCurLayer->pLumaQp[iMbXy] + pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)]; | |
| 1069 | + } | |
| 1070 | + } | |
| 1071 | + | |
| 1072 | + if ( pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy] ) | |
| 1073 | + { | |
| 1074 | + int32_t iQpDelta, iId8x8, iId4x4; | |
| 1075 | + | |
| 1076 | + iQpDelta = BsGetSe(pBs); | |
| 1077 | + | |
| 1078 | + if (iQpDelta > 25 || iQpDelta < -26) //out of iQpDelta range | |
| 1079 | + { | |
| 1080 | + return ERR_INFO_INVALID_QP; | |
| 1081 | + } | |
| 1082 | + | |
| 1083 | + pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp + iQpDelta; //update iLastMbQp | |
| 1084 | + //refer to JVT-X201wcm1.doc equation(7-35) | |
| 1085 | + if ( (unsigned)(pCurLayer->pLumaQp[iMbXy]) > 51 ) | |
| 1086 | + { | |
| 1087 | + if ( pCurLayer->pLumaQp[iMbXy] < 0 ) | |
| 1088 | + { | |
| 1089 | + pCurLayer->pLumaQp[iMbXy] += 52; | |
| 1090 | + } | |
| 1091 | + else | |
| 1092 | + { | |
| 1093 | + pCurLayer->pLumaQp[iMbXy] -= 52; | |
| 1094 | + } | |
| 1095 | + } | |
| 1096 | + //QP should be in the range of [0, 51] | |
| 1097 | + if ( pCurLayer->pLumaQp[iMbXy] < 0 || pCurLayer->pLumaQp[iMbXy] > 51 ) | |
| 1098 | + { | |
| 1099 | + return ERR_INFO_INVALID_QP; | |
| 1100 | + } | |
| 1101 | + pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; | |
| 1102 | + pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pSlice->iLastMbQp + pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)]; | |
| 1103 | + | |
| 1104 | + BsStartCavlc( pBs ); | |
| 1105 | + | |
| 1106 | + if ( MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy] ) | |
| 1107 | + { | |
| 1108 | + //step1: Luma DC | |
| 1109 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan, | |
| 1110 | + I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) ) | |
| 1111 | + { | |
| 1112 | + return -1;//abnormal | |
| 1113 | + } | |
| 1114 | + //step2: Luma AC | |
| 1115 | + if (uiCbpL) | |
| 1116 | + { | |
| 1117 | + for (i = 0; i < 16; i++) | |
| 1118 | + { | |
| 1119 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount,pBs, i, | |
| 1120 | + iScanIdxEnd - WELS_MAX(iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX(iScanIdxStart,1), | |
| 1121 | + I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i<<4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) ) | |
| 1122 | + { | |
| 1123 | + return -1;//abnormal | |
| 1124 | + } | |
| 1125 | + } | |
| 1126 | + ST32(&pCurLayer->pNzc[iMbXy][0], LD32(&pNonZeroCount[1+8*1])); | |
| 1127 | + ST32(&pCurLayer->pNzc[iMbXy][4], LD32(&pNonZeroCount[1+8*2])); | |
| 1128 | + ST32(&pCurLayer->pNzc[iMbXy][8], LD32(&pNonZeroCount[1+8*3])); | |
| 1129 | + ST32(&pCurLayer->pNzc[iMbXy][12], LD32(&pNonZeroCount[1+8*4])); | |
| 1130 | + } | |
| 1131 | + else //pNonZeroCount = 0 | |
| 1132 | + { | |
| 1133 | + ST32(&pCurLayer->pNzc[iMbXy][0], 0); | |
| 1134 | + ST32(&pCurLayer->pNzc[iMbXy][4], 0); | |
| 1135 | + ST32(&pCurLayer->pNzc[iMbXy][8], 0); | |
| 1136 | + ST32(&pCurLayer->pNzc[iMbXy][12], 0); | |
| 1137 | + } | |
| 1138 | + } | |
| 1139 | + else //non-MB_TYPE_INTRA16x16 | |
| 1140 | + { | |
| 1141 | + for (iId8x8 = 0; iId8x8 < 4; iId8x8++) | |
| 1142 | + { | |
| 1143 | + if (uiCbpL & (1 << iId8x8)) | |
| 1144 | + { | |
| 1145 | + int32_t iIndex = (iId8x8 << 2); | |
| 1146 | + for (iId4x4 = 0; iId4x4 < 4; iId4x4++) | |
| 1147 | + { | |
| 1148 | + //Luma (DC and AC decoding together) | |
| 1149 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, iIndex, | |
| 1150 | + iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan+iScanIdxStart, LUMA_DC_AC, | |
| 1151 | + pCurLayer->pScaledTCoeff[iMbXy] + (iIndex<<4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) ) | |
| 1152 | + { | |
| 1153 | + return -1;//abnormal | |
| 1154 | + } | |
| 1155 | + iIndex++; | |
| 1156 | + } | |
| 1157 | + } | |
| 1158 | + else | |
| 1159 | + { | |
| 1160 | + ST16(&pNonZeroCount[g_kuiCacheNzcScanIdx[iId8x8<<2]],0); | |
| 1161 | + ST16(&pNonZeroCount[g_kuiCacheNzcScanIdx[(iId8x8<<2)+2]],0); | |
| 1162 | + } | |
| 1163 | + } | |
| 1164 | + ST32(&pCurLayer->pNzc[iMbXy][0], LD32(&pNonZeroCount[1+8*1])); | |
| 1165 | + ST32(&pCurLayer->pNzc[iMbXy][4], LD32(&pNonZeroCount[1+8*2])); | |
| 1166 | + ST32(&pCurLayer->pNzc[iMbXy][8], LD32(&pNonZeroCount[1+8*3])); | |
| 1167 | + ST32(&pCurLayer->pNzc[iMbXy][12], LD32(&pNonZeroCount[1+8*4])); | |
| 1168 | + } | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + //chroma | |
| 1172 | + //step1: DC | |
| 1173 | + if ( 1 == uiCbpC || 2 == uiCbpC ) | |
| 1174 | + { | |
| 1175 | + for (i = 0; i < 2; i++) //Cb Cr | |
| 1176 | + { | |
| 1177 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, | |
| 1178 | + 16 + (i << 2), 4, g_kuiChromaDcScan, CHROMA_DC, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i<<6), | |
| 1179 | + iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx) ) | |
| 1180 | + { | |
| 1181 | + return -1;//abnormal | |
| 1182 | + } | |
| 1183 | + } | |
| 1184 | + } | |
| 1185 | + else | |
| 1186 | + { | |
| 1187 | + } | |
| 1188 | + //step2: AC | |
| 1189 | + if (2 == uiCbpC) | |
| 1190 | + { | |
| 1191 | + for (i = 0; i < 2; i++) //Cb Cr | |
| 1192 | + { | |
| 1193 | + int32_t iIndex= 16 + (i<<2); | |
| 1194 | + for (iId4x4 = 0; iId4x4 < 4; iId4x4++) | |
| 1195 | + { | |
| 1196 | + if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, iIndex, | |
| 1197 | + iScanIdxEnd - WELS_MAX(iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX(iScanIdxStart,1), | |
| 1198 | + CHROMA_AC, pCurLayer->pScaledTCoeff[iMbXy]+(iIndex<<4), iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx) ) | |
| 1199 | + { | |
| 1200 | + return -1;//abnormal | |
| 1201 | + } | |
| 1202 | + iIndex++; | |
| 1203 | + } | |
| 1204 | + } | |
| 1205 | + ST16(&pCurLayer->pNzc[iMbXy][16], LD16(&pNonZeroCount[6+8*1])); | |
| 1206 | + ST16(&pCurLayer->pNzc[iMbXy][20], LD16(&pNonZeroCount[6+8*2])); | |
| 1207 | + ST16(&pCurLayer->pNzc[iMbXy][18], LD16(&pNonZeroCount[6+8*4])); | |
| 1208 | + ST16(&pCurLayer->pNzc[iMbXy][22], LD16(&pNonZeroCount[6+8*5])); | |
| 1209 | + } | |
| 1210 | + else | |
| 1211 | + { | |
| 1212 | + ST32(&pCurLayer->pNzc[iMbXy][16], 0); | |
| 1213 | + ST32(&pCurLayer->pNzc[iMbXy][20], 0); | |
| 1214 | + } | |
| 1215 | + BsEndCavlc( pBs ); | |
| 1216 | + } | |
| 1217 | + else | |
| 1218 | + { | |
| 1219 | + ST32(&pCurLayer->pNzc[iMbXy][0], 0); | |
| 1220 | + ST32(&pCurLayer->pNzc[iMbXy][4], 0); | |
| 1221 | + ST32(&pCurLayer->pNzc[iMbXy][8], 0); | |
| 1222 | + ST32(&pCurLayer->pNzc[iMbXy][12], 0); | |
| 1223 | + ST32(&pCurLayer->pNzc[iMbXy][16], 0); | |
| 1224 | + ST32(&pCurLayer->pNzc[iMbXy][20], 0); | |
| 1225 | + } | |
| 1226 | + | |
| 1227 | + return 0; | |
| 1228 | +} | |
| 1229 | + | |
| 1230 | +int32_t WelsDecodeMbCavlcPSlice(PWelsDecoderContext pCtx, PNalUnit pNalCur) | |
| 1231 | +{ | |
| 1232 | + PDqLayer pCurLayer = pCtx->pCurDqLayer; | |
| 1233 | + PBitStringAux pBs = pCurLayer->pBitStringAux; | |
| 1234 | + PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | |
| 1235 | + PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 1236 | + | |
| 1237 | + int32_t iMbXy = pCurLayer->iMbXyIndex; | |
| 1238 | + int32_t iBaseModeFlag, i; | |
| 1239 | + int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15 | |
| 1240 | + | |
| 1241 | + if (-1 == pSlice->iMbSkipRun) | |
| 1242 | + { | |
| 1243 | + pSlice->iMbSkipRun = BsGetUe(pBs); | |
| 1244 | + if ( -1 == pSlice->iMbSkipRun ) | |
| 1245 | + { | |
| 1246 | + return -1; | |
| 1247 | + } | |
| 1248 | + | |
| 1249 | + } | |
| 1250 | + if (pSlice->iMbSkipRun--) | |
| 1251 | + { | |
| 1252 | + int16_t iMv[2] = {0}; | |
| 1253 | + | |
| 1254 | + pCurLayer->pMbType[iMbXy] = MB_TYPE_SKIP; | |
| 1255 | + ST32(&pCurLayer->pNzc[iMbXy][0], 0); | |
| 1256 | + ST32(&pCurLayer->pNzc[iMbXy][4], 0); | |
| 1257 | + ST32(&pCurLayer->pNzc[iMbXy][8], 0); | |
| 1258 | + ST32(&pCurLayer->pNzc[iMbXy][12], 0); | |
| 1259 | + ST32(&pCurLayer->pNzc[iMbXy][16], 0); | |
| 1260 | + ST32(&pCurLayer->pNzc[iMbXy][20], 0); | |
| 1261 | + | |
| 1262 | + pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | |
| 1263 | + memset(pCurLayer->pRefIndex[0][iMbXy], 0, sizeof(int8_t) * 16); | |
| 1264 | + | |
| 1265 | + //predict iMv | |
| 1266 | + PredPSkipMvFromNeighbor( pCurLayer, iMv ); | |
| 1267 | + for (i = 0; i < 16; i++) | |
| 1268 | + { | |
| 1269 | + ST32( pCurLayer->pMv[0][iMbXy][i], *(uint32_t*)iMv ); | |
| 1270 | + } | |
| 1271 | + | |
| 1272 | + if(!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag) | |
| 1273 | + { | |
| 1274 | + memset(pCurLayer->pScaledTCoeff[iMbXy], 0, 384*sizeof(int16_t)); | |
| 1275 | + } | |
| 1276 | + | |
| 1277 | + //reset rS | |
| 1278 | + if(!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag || | |
| 1279 | + (pNalCur->sNalHeaderExt.uiQualityId==0 && pNalCur->sNalHeaderExt.uiDependencyId==0)) | |
| 1280 | + { | |
| 1281 | + pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; | |
| 1282 | + pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pCurLayer->pLumaQp[iMbXy] + pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)]; | |
| 1283 | + } | |
| 1284 | + | |
| 1285 | + pCurLayer->pCbp[iMbXy] = 0; | |
| 1286 | + | |
| 1287 | + return 0; | |
| 1288 | + } | |
| 1289 | + | |
| 1290 | + if( pSlice->sSliceHeaderExt.bAdaptiveBaseModeFlag == 1) | |
| 1291 | + { | |
| 1292 | + iBaseModeFlag = BsGetOneBit(pBs); | |
| 1293 | + } | |
| 1294 | + else | |
| 1295 | + { | |
| 1296 | + iBaseModeFlag = pSlice->sSliceHeaderExt.bDefaultBaseModeFlag; | |
| 1297 | + } | |
| 1298 | + if( !iBaseModeFlag ) | |
| 1299 | + { | |
| 1300 | + iRet = WelsActualDecodeMbCavlcPSlice( pCtx ); | |
| 1301 | + } | |
| 1302 | + else | |
| 1303 | + { | |
| 1304 | + WelsLog( pCtx, WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.\n", iBaseModeFlag); | |
| 1305 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP); | |
| 1306 | + } | |
| 1307 | + if ( iRet ) //occur error when parsing, MUST STOP decoding | |
| 1308 | + { | |
| 1309 | + return iRet; | |
| 1310 | + } | |
| 1311 | + | |
| 1312 | + return 0; | |
| 1313 | +} | |
| 1314 | + | |
| 1315 | +void_t WelsBlockInit(int16_t* pBlock, int32_t iWidth, int32_t iHeight, int32_t iStride, uint8_t uiVal) | |
| 1316 | +{ | |
| 1317 | + int32_t i; | |
| 1318 | + int16_t* pDst = pBlock; | |
| 1319 | + | |
| 1320 | + for(i=0; i<iHeight; i++) | |
| 1321 | + { | |
| 1322 | + memset(pDst, uiVal, iWidth*sizeof(int16_t)); | |
| 1323 | + pDst += iStride; | |
| 1324 | + } | |
| 1325 | +} | |
| 1326 | + | |
| 1327 | +void_t WelsBlockFuncInit(SBlockFunc * pFunc, int32_t iCpu) | |
| 1328 | +{ | |
| 1329 | + pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_c; | |
| 1330 | + pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_c; | |
| 1331 | + pFunc->pWelsSetNonZeroCountFunc = SetNonZeroCount_c; | |
| 1332 | + | |
| 1333 | +#ifdef X86_ASM | |
| 1334 | + if( iCpu & WELS_CPU_SSE2 ){ | |
| 1335 | + pFunc->pWelsBlockZero16x16Func = WelsResBlockZero16x16_sse2; | |
| 1336 | + pFunc->pWelsBlockZero8x8Func = WelsResBlockZero8x8_sse2; | |
| 1337 | + } | |
| 1338 | +#endif | |
| 1339 | +} | |
| 1340 | +void_t WelsBlockZero16x16_c(int16_t * pBlock, int32_t iStride) | |
| 1341 | +{ | |
| 1342 | + WelsBlockInit(pBlock,16,16,iStride,0); | |
| 1343 | +} | |
| 1344 | + | |
| 1345 | +void_t WelsBlockZero8x8_c(int16_t * pBlock, int32_t iStride) | |
| 1346 | +{ | |
| 1347 | + WelsBlockInit(pBlock,8,8,iStride,0); | |
| 1348 | +} | |
| 1349 | + | |
| 1350 | +void_t SetNonZeroCount_c(int16_t* pBlock, int8_t* pNonZeroCount) | |
| 1351 | +{ | |
| 1352 | + int32_t i; | |
| 1353 | + int32_t iIndex; | |
| 1354 | + | |
| 1355 | + for( i=0;i<24;i++ ){ | |
| 1356 | + iIndex = g_kuiMbNonZeroCountIdx[i]; | |
| 1357 | + pNonZeroCount[iIndex] = !!pNonZeroCount[iIndex]; | |
| 1358 | + } | |
| 1359 | +} | |
| 1360 | + | |
| 1361 | +} // namespace WelsDec | |
| @@ -0,0 +1,850 @@ | ||
| 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 decoder.c | |
| 33 | + * | |
| 34 | + * \brief Interfaces implementation introduced in decoder system architecture | |
| 35 | + * | |
| 36 | + * \date 03/10/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#include <string.h> | |
| 41 | +#include "macros.h" | |
| 42 | +#include "codec_def.h" | |
| 43 | +#include "decoder.h" | |
| 44 | +#include "error_code.h" | |
| 45 | +#include "cpu.h" | |
| 46 | +#include "cpu_core.h" | |
| 47 | +#include "au_parser.h" | |
| 48 | +#include "utils.h" | |
| 49 | +#include "nal_prefix.h" | |
| 50 | +#include "dec_frame.h" | |
| 51 | +#include "pic_queue.h" | |
| 52 | +#include "vlc_decoder.h" | |
| 53 | +#include "get_intra_predictor.h" | |
| 54 | +#include "rec_mb.h" | |
| 55 | +#include "mc.h" | |
| 56 | +#include "decode_mb_aux.h" | |
| 57 | +#include "manage_dec_ref.h" | |
| 58 | +#include "codec_app_def.h" | |
| 59 | +#include "decoder_core.h" | |
| 60 | +#include "deblocking.h" | |
| 61 | +#include "expand_pic.h" | |
| 62 | +#include "decode_slice.h" | |
| 63 | +#include "crt_util_safe_x.h" // Safe CRT routines like utils for cross platforms | |
| 64 | +#include "mem_align.h" | |
| 65 | + | |
| 66 | +namespace WelsDec { | |
| 67 | + | |
| 68 | +extern PPicture AllocPicture( PWelsDecoderContext pCtx,const int32_t kiPicWidth, const int32_t kiPicHeight ); | |
| 69 | + | |
| 70 | +extern void_t FreePicture( PPicture pPic ); | |
| 71 | + | |
| 72 | +#ifdef WORDS_BIGENDIAN | |
| 73 | +inline void_t GetValueOf4Bytes( uint8_t* pDstNal, int32_t iDdstIdx ) | |
| 74 | +{ | |
| 75 | + pDstNal[0] = (iDdstIdx & 0xff000000) >> 24; | |
| 76 | + pDstNal[1] = (iDdstIdx & 0xff0000) >> 16; | |
| 77 | + pDstNal[2] = (iDdstIdx & 0xff00) >> 8; | |
| 78 | + pDstNal[3] = (iDdstIdx & 0xff); | |
| 79 | +} | |
| 80 | +#else //WORDS_BIGENDIAN | |
| 81 | +inline void_t GetValueOf4Bytes( uint8_t* pDstNal, int32_t iDdstIdx ) | |
| 82 | +{ | |
| 83 | + pDstNal[0] = (iDdstIdx & 0xff); | |
| 84 | + pDstNal[1] = (iDdstIdx & 0xff00) >> 8; | |
| 85 | + pDstNal[2] = (iDdstIdx & 0xff0000) >> 16; | |
| 86 | + pDstNal[3] = (iDdstIdx & 0xff000000) >> 24; | |
| 87 | +} | |
| 88 | +#endif //WORDS_BIGENDIAN | |
| 89 | + | |
| 90 | +static int32_t CreatePicBuff(PWelsDecoderContext pCtx, PPicBuff *ppPicBuf, const int32_t kiSize, const int32_t kiPicWidth, const int32_t kiPicHeight) | |
| 91 | +{ | |
| 92 | + PPicBuff pPicBuf = NULL; | |
| 93 | + int32_t iPicIdx = 0; | |
| 94 | + if (kiSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) | |
| 95 | + { | |
| 96 | + return 1; | |
| 97 | + } | |
| 98 | + | |
| 99 | + pPicBuf = (PPicBuff)WelsMalloc( sizeof(SPicBuff), "PPicBuff" ); | |
| 100 | + | |
| 101 | + if ( NULL == pPicBuf ) | |
| 102 | + { | |
| 103 | + return 1; | |
| 104 | + } | |
| 105 | + | |
| 106 | + pPicBuf->ppPic = (PPicture *)WelsMalloc(kiSize * sizeof(PPicture), "PPicture*"); | |
| 107 | + | |
| 108 | + if ( NULL == pPicBuf->ppPic ) | |
| 109 | + { | |
| 110 | + return 1; | |
| 111 | + } | |
| 112 | + for (iPicIdx = 0; iPicIdx < kiSize; ++ iPicIdx) | |
| 113 | + { | |
| 114 | + PPicture pPic = AllocPicture( pCtx, kiPicWidth, kiPicHeight ); | |
| 115 | + if ( NULL == pPic ) | |
| 116 | + { | |
| 117 | + return 1; | |
| 118 | + } | |
| 119 | + pPicBuf->ppPic[iPicIdx] = pPic; | |
| 120 | + } | |
| 121 | + | |
| 122 | + // initialize context in queue | |
| 123 | + pPicBuf->iCapacity = kiSize; | |
| 124 | + pPicBuf->iCurrentIdx = 0; | |
| 125 | + *ppPicBuf = pPicBuf; | |
| 126 | + | |
| 127 | + return 0; | |
| 128 | +} | |
| 129 | + | |
| 130 | +static void_t DestroyPicBuff( PPicBuff *ppPicBuf ) | |
| 131 | +{ | |
| 132 | + PPicBuff pPicBuf = NULL; | |
| 133 | + | |
| 134 | + if ( NULL == ppPicBuf || NULL == *ppPicBuf ) | |
| 135 | + return; | |
| 136 | + | |
| 137 | + pPicBuf = *ppPicBuf; | |
| 138 | + while(pPicBuf->ppPic != NULL) | |
| 139 | + { | |
| 140 | + int32_t iPicIdx = 0; | |
| 141 | + while (iPicIdx < pPicBuf->iCapacity) | |
| 142 | + { | |
| 143 | + PPicture pPic = pPicBuf->ppPic[iPicIdx]; | |
| 144 | + if(pPic != NULL) | |
| 145 | + { | |
| 146 | + FreePicture( pPic ); | |
| 147 | + } | |
| 148 | + pPic = NULL; | |
| 149 | + ++ iPicIdx; | |
| 150 | + } | |
| 151 | + | |
| 152 | + WelsFree(pPicBuf->ppPic, "pPicBuf->queue"); | |
| 153 | + | |
| 154 | + pPicBuf->ppPic = NULL; | |
| 155 | + } | |
| 156 | + pPicBuf->iCapacity = 0; | |
| 157 | + pPicBuf->iCurrentIdx= 0; | |
| 158 | + | |
| 159 | + WelsFree( pPicBuf, "pPicBuf" ); | |
| 160 | + | |
| 161 | + pPicBuf = NULL; | |
| 162 | + *ppPicBuf = NULL; | |
| 163 | +} | |
| 164 | +/* | |
| 165 | + * fill data fields in default for decoder context | |
| 166 | + */ | |
| 167 | +void_t WelsDecoderDefaults( PWelsDecoderContext pCtx ) | |
| 168 | +{ | |
| 169 | + int32_t iCpuCores = 1; | |
| 170 | + memset( pCtx, 0, sizeof(SWelsDecoderContext) ); // fill zero first | |
| 171 | + | |
| 172 | + pCtx->pArgDec = NULL; | |
| 173 | + | |
| 174 | + pCtx->iOutputColorFormat = videoFormatI420; // yuv in default | |
| 175 | + pCtx->bHaveGotMemory = false; // not ever request memory blocks for decoder context related | |
| 176 | + pCtx->uiCpuFlag = 0; | |
| 177 | + | |
| 178 | + pCtx->bAuReadyFlag = 0; // au data is not ready | |
| 179 | + | |
| 180 | + | |
| 181 | + g_uiCacheLineSize = 16; | |
| 182 | +#if defined(X86_ASM) | |
| 183 | + pCtx->uiCpuFlag = WelsCPUFeatureDetect(&iCpuCores); | |
| 184 | +#ifdef HAVE_CACHE_LINE_ALIGN | |
| 185 | + if ( pCtx->uiCpuFlag & WELS_CPU_CACHELINE_64 ) | |
| 186 | + { | |
| 187 | + g_uiCacheLineSize = 64; | |
| 188 | + } | |
| 189 | + else if ( pCtx->uiCpuFlag & WELS_CPU_CACHELINE_32 ) | |
| 190 | + { | |
| 191 | + g_uiCacheLineSize = 32; | |
| 192 | + } | |
| 193 | +#endif//HAVE_CACHE_LINE_ALIGN | |
| 194 | +#endif//X86_ASM | |
| 195 | + | |
| 196 | + pCtx->iImgWidthInPixel = 0; | |
| 197 | + pCtx->iImgHeightInPixel = 0; // alloc picture data when picture size is available | |
| 198 | + | |
| 199 | + pCtx->iFrameNum = -1; | |
| 200 | + pCtx->iPrevFrameNum = -1; | |
| 201 | + pCtx->iErrorCode = ERR_NONE; | |
| 202 | + | |
| 203 | + pCtx->pDec = NULL; | |
| 204 | + | |
| 205 | + WelsResetRefPic(pCtx); | |
| 206 | + | |
| 207 | + pCtx->iActiveFmoNum = 0; | |
| 208 | + | |
| 209 | + pCtx->pPicBuff[LIST_0] = NULL; | |
| 210 | + pCtx->pPicBuff[LIST_1] = NULL; | |
| 211 | + | |
| 212 | + pCtx->bAvcBasedFlag = true; | |
| 213 | + | |
| 214 | +} | |
| 215 | + | |
| 216 | +/* | |
| 217 | + * destory_mb_blocks | |
| 218 | + */ | |
| 219 | + | |
| 220 | + | |
| 221 | +/* | |
| 222 | + * get size of reference picture list in target layer incoming, = (iNumRefFrames x 2) | |
| 223 | + */ | |
| 224 | +static inline int32_t GetTargetRefListSize( PWelsDecoderContext pCtx ) | |
| 225 | +{ | |
| 226 | + bool_t *pSubsetSpsAvail= &pCtx->bSubspsAvailFlags[0]; | |
| 227 | + bool_t *pSpsAvail = &pCtx->bSpsAvailFlags[0]; | |
| 228 | + int32_t iSubsetIdx = -1; | |
| 229 | + int32_t iSpsIdx = -1; | |
| 230 | + bool_t bExistSubsetSps = false; | |
| 231 | + int32_t bExistSps = false; | |
| 232 | + int32_t iPos = MAX_SPS_COUNT - 1; | |
| 233 | + int32_t iNumRefFrames = 0; | |
| 234 | + | |
| 235 | + while (iPos >= 0) | |
| 236 | + { | |
| 237 | + if ( pSubsetSpsAvail[iPos] ) | |
| 238 | + { | |
| 239 | + bExistSubsetSps = true; | |
| 240 | + iSubsetIdx = iPos; | |
| 241 | + break; | |
| 242 | + } | |
| 243 | + -- iPos; | |
| 244 | + } | |
| 245 | + | |
| 246 | + if ( !bExistSubsetSps ) | |
| 247 | + { | |
| 248 | + iPos = MAX_SPS_COUNT - 1; | |
| 249 | + while (iPos >= 0) | |
| 250 | + { | |
| 251 | + if ( pSpsAvail[iPos] ) | |
| 252 | + { | |
| 253 | + bExistSps = true; | |
| 254 | + iSpsIdx = iPos; | |
| 255 | + break; | |
| 256 | + } | |
| 257 | + -- iPos; | |
| 258 | + } | |
| 259 | + } | |
| 260 | + | |
| 261 | + if ( !(bExistSubsetSps || bExistSps) ) | |
| 262 | + { | |
| 263 | + iNumRefFrames = MAX_REF_PIC_COUNT; | |
| 264 | + } | |
| 265 | + else | |
| 266 | + { | |
| 267 | + PSps pSps = bExistSubsetSps ? (&pCtx->sSubsetSpsBuffer[iSubsetIdx].sSps) : (&pCtx->sSpsBuffer[iSpsIdx]); | |
| 268 | + | |
| 269 | + iNumRefFrames = (pSps->iNumRefFrames ) + 1; | |
| 270 | + } | |
| 271 | + | |
| 272 | + if ( 0 == iNumRefFrames ) | |
| 273 | + iNumRefFrames = (MIN_REF_PIC_COUNT); | |
| 274 | + | |
| 275 | +#ifdef LONG_TERM_REF | |
| 276 | + //pic_queue size minimum set 2 | |
| 277 | + if (iNumRefFrames <2) | |
| 278 | + { | |
| 279 | + iNumRefFrames = 2; | |
| 280 | + } | |
| 281 | +#endif | |
| 282 | + | |
| 283 | + return iNumRefFrames; | |
| 284 | +} | |
| 285 | + | |
| 286 | +/* | |
| 287 | + * request memory blocks for decoder avc part | |
| 288 | + */ | |
| 289 | +int32_t WelsRequestMem( PWelsDecoderContext pCtx, const int32_t kiMbWidth, const int32_t kiMbHeight ) | |
| 290 | +{ | |
| 291 | + const int32_t kiPicWidth = kiMbWidth << 4; | |
| 292 | + const int32_t kiPicHeight = kiMbHeight << 4; | |
| 293 | + int32_t iErr = ERR_NONE; | |
| 294 | + | |
| 295 | + int32_t iListIdx = 0; //, mb_blocks = 0; | |
| 296 | + int32_t iPicQueueSize = 0; // adaptive size of picture queue, = (pSps->iNumRefFrames x 2) | |
| 297 | + bool_t bNeedChangePicQueue = true; | |
| 298 | + | |
| 299 | + WELS_VERIFY_RETURN_IF( ERR_INFO_INVALID_PARAM, ( NULL == pCtx || kiPicWidth <= 0 || kiPicHeight <= 0 ) ) | |
| 300 | + | |
| 301 | + // Fixed the issue about different gop size over last, 5/17/2010 | |
| 302 | + // get picture queue size currently | |
| 303 | + iPicQueueSize = GetTargetRefListSize( pCtx ); // adaptive size of picture queue, = (pSps->iNumRefFrames x 2) | |
| 304 | + pCtx->iPicQueueNumber = iPicQueueSize; | |
| 305 | + if ( pCtx->pPicBuff[LIST_0] != NULL && pCtx->pPicBuff[LIST_0]->iCapacity == iPicQueueSize ) // comparing current picture queue size requested and previous allocation picture queue | |
| 306 | + bNeedChangePicQueue = false; | |
| 307 | + // HD based pic buffer need consider memory size consumed when switch from 720p to other lower size | |
| 308 | + WELS_VERIFY_RETURN_IF( ERR_NONE, pCtx->bHaveGotMemory && ( kiPicWidth == pCtx->iImgWidthInPixel && kiPicHeight == pCtx->iImgHeightInPixel ) && (!bNeedChangePicQueue) ) // have same scaled buffer | |
| 309 | + | |
| 310 | + // sync update pRefList | |
| 311 | + WelsResetRefPic( pCtx ); // added to sync update ref list due to pictures are free | |
| 312 | + | |
| 313 | + // for Recycled_Pic_Queue | |
| 314 | + for ( iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx ) | |
| 315 | + { | |
| 316 | + PPicBuff *ppPic = &pCtx->pPicBuff[iListIdx]; | |
| 317 | + if ( NULL != ppPic && NULL != *ppPic ) | |
| 318 | + { | |
| 319 | + DestroyPicBuff( ppPic ); | |
| 320 | + } | |
| 321 | + } | |
| 322 | + | |
| 323 | + // currently only active for LIST_0 due to have no B frames | |
| 324 | + iErr = CreatePicBuff( pCtx, &pCtx->pPicBuff[LIST_0], iPicQueueSize, kiPicWidth, kiPicHeight ); | |
| 325 | + if ( iErr != ERR_NONE ) | |
| 326 | + return iErr; | |
| 327 | + | |
| 328 | + | |
| 329 | + pCtx->iImgWidthInPixel = kiPicWidth; // target width of image to be reconstruted while decoding | |
| 330 | + pCtx->iImgHeightInPixel = kiPicHeight; // target height of image to be reconstruted while decoding | |
| 331 | + | |
| 332 | + pCtx->bHaveGotMemory = true; // global memory for decoder context related is requested | |
| 333 | + pCtx->pDec = NULL; // need prefetch a new pic due to spatial size changed | |
| 334 | + return ERR_NONE; | |
| 335 | +} | |
| 336 | + | |
| 337 | +/* | |
| 338 | + * free memory blocks in avc | |
| 339 | + */ | |
| 340 | +void_t WelsFreeMem( PWelsDecoderContext pCtx ) | |
| 341 | +{ | |
| 342 | + int32_t iListIdx = 0; | |
| 343 | + | |
| 344 | + /* TODO: free memory blocks introduced in avc */ | |
| 345 | + ResetFmoList( pCtx ); | |
| 346 | + | |
| 347 | + WelsResetRefPic( pCtx ); | |
| 348 | + | |
| 349 | + // for sPicBuff | |
| 350 | + for ( iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx ) | |
| 351 | + { | |
| 352 | + PPicBuff *pPicBuff = &pCtx->pPicBuff[iListIdx]; | |
| 353 | + if ( NULL != pPicBuff && NULL != *pPicBuff ) | |
| 354 | + { | |
| 355 | + DestroyPicBuff( pPicBuff ); | |
| 356 | + } | |
| 357 | + } | |
| 358 | + | |
| 359 | + // added for safe memory | |
| 360 | + pCtx->iImgWidthInPixel = 0; | |
| 361 | + pCtx->iImgHeightInPixel = 0; | |
| 362 | + pCtx->bHaveGotMemory = false; | |
| 363 | + | |
| 364 | +} | |
| 365 | + | |
| 366 | +/*! | |
| 367 | + * \brief Open decoder | |
| 368 | + */ | |
| 369 | +void_t WelsOpenDecoder( PWelsDecoderContext pCtx ) | |
| 370 | +{ | |
| 371 | + // function pointers | |
| 372 | + //initial MC function pointer-- | |
| 373 | + InitMcFunc(&(pCtx->sMcFunc), pCtx->uiCpuFlag); | |
| 374 | + | |
| 375 | + InitExpandPictureFunc(&(pCtx->sExpandPicFunc), pCtx->uiCpuFlag); | |
| 376 | + AssignFuncPointerForRec(pCtx); | |
| 377 | + | |
| 378 | + // vlc tables | |
| 379 | + InitVlcTable(&pCtx->sVlcTable); | |
| 380 | + | |
| 381 | + // startup memory | |
| 382 | + if ( ERR_NONE != WelsInitMemory( pCtx ) ) | |
| 383 | + return; | |
| 384 | + | |
| 385 | + pCtx->iMaxWidthInSps = 0; | |
| 386 | + pCtx->iMaxHeightInSps = 0; | |
| 387 | +#ifdef LONG_TERM_REF | |
| 388 | + pCtx->bParamSetsLostFlag = true; | |
| 389 | +#else | |
| 390 | + pCtx->bReferenceLostAtT0Flag = true; // should be true to waiting IDR at incoming AU bits following, 6/4/2010 | |
| 391 | +#endif //LONG_TERM_REF | |
| 392 | +} | |
| 393 | + | |
| 394 | +/*! | |
| 395 | + * \brief Close decoder | |
| 396 | + */ | |
| 397 | +void_t WelsCloseDecoder( PWelsDecoderContext pCtx ) | |
| 398 | +{ | |
| 399 | + WelsFreeMem( pCtx ); | |
| 400 | + | |
| 401 | + WelsFreeMemory( pCtx ); | |
| 402 | + | |
| 403 | + UninitialDqLayersContext( pCtx ); | |
| 404 | + | |
| 405 | +#ifdef LONG_TERM_REF | |
| 406 | + pCtx->bParamSetsLostFlag = false; | |
| 407 | +#else | |
| 408 | + pCtx->bReferenceLostAtT0Flag = false; | |
| 409 | +#endif | |
| 410 | +} | |
| 411 | + | |
| 412 | +/*! | |
| 413 | + * \brief configure decoder parameters | |
| 414 | + */ | |
| 415 | +int32_t DecoderConfigParam ( PWelsDecoderContext pCtx, const void_t* kpParam ) | |
| 416 | +{ | |
| 417 | + if ( NULL == pCtx || NULL == kpParam ) | |
| 418 | + return 1; | |
| 419 | + | |
| 420 | + pCtx->pParam = (SDecodingParam *)WelsMalloc( sizeof(SDecodingParam), "SDecodingParam" ); | |
| 421 | + | |
| 422 | + if ( NULL == pCtx->pParam ) | |
| 423 | + return 1; | |
| 424 | + | |
| 425 | + memcpy( pCtx->pParam, kpParam, sizeof(SDecodingParam) ); | |
| 426 | + pCtx->iOutputColorFormat = pCtx->pParam->iOutputColorFormat; | |
| 427 | + pCtx->bErrorResilienceFlag = pCtx->pParam->uiEcActiveFlag ? true : false; | |
| 428 | + | |
| 429 | + if ( VIDEO_BITSTREAM_SVC == pCtx->pParam->sVideoProperty.eVideoBsType || | |
| 430 | + VIDEO_BITSTREAM_AVC == pCtx->pParam->sVideoProperty.eVideoBsType ) | |
| 431 | + { | |
| 432 | + pCtx->eVideoType = pCtx->pParam->sVideoProperty.eVideoBsType; | |
| 433 | + } | |
| 434 | + else | |
| 435 | + { | |
| 436 | + pCtx->eVideoType = VIDEO_BITSTREAM_DEFAULT; | |
| 437 | + } | |
| 438 | + | |
| 439 | + WelsLog(pCtx, WELS_LOG_INFO, "eVideoType: %d\n", pCtx->eVideoType); | |
| 440 | + | |
| 441 | + return 0; | |
| 442 | +} | |
| 443 | + | |
| 444 | +/*! | |
| 445 | + ************************************************************************************* | |
| 446 | + * \brief Initialize Wels decoder parameters and memory | |
| 447 | + * | |
| 448 | + * \param pCtx input context to be initialized at first stage | |
| 449 | + * | |
| 450 | + * \return 0 - successed | |
| 451 | + * \return 1 - failed | |
| 452 | + * | |
| 453 | + * \note N/A | |
| 454 | + ************************************************************************************* | |
| 455 | + */ | |
| 456 | +int32_t WelsInitDecoder( PWelsDecoderContext pCtx, void_t * pTraceHandle, PWelsLogCallbackFunc pLog ) | |
| 457 | +{ | |
| 458 | + if ( pCtx == NULL ){ | |
| 459 | + return ERR_INFO_INVALID_PTR; | |
| 460 | + } | |
| 461 | + | |
| 462 | + // default | |
| 463 | + WelsDecoderDefaults( pCtx ); | |
| 464 | + | |
| 465 | + pCtx->pTraceHandle = pTraceHandle; | |
| 466 | + | |
| 467 | + g_pLog = pLog; | |
| 468 | + | |
| 469 | + // open decoder | |
| 470 | + WelsOpenDecoder( pCtx ); | |
| 471 | + | |
| 472 | + // decode mode setting | |
| 473 | + pCtx->iDecoderMode = SW_MODE; | |
| 474 | + pCtx->iSetMode = AUTO_MODE; | |
| 475 | + pCtx->iDecoderOutputProperty = BUFFER_HOST; | |
| 476 | + pCtx->iModeSwitchType = 0; // 0: do not do mode switch | |
| 477 | + | |
| 478 | + | |
| 479 | + return ERR_NONE; | |
| 480 | +} | |
| 481 | + | |
| 482 | +/*! | |
| 483 | + ************************************************************************************* | |
| 484 | + * \brief Uninitialize Wels decoder parameters and memory | |
| 485 | + * | |
| 486 | + * \param pCtx input context to be uninitialized at release stage | |
| 487 | + * | |
| 488 | + * \return NONE | |
| 489 | + * | |
| 490 | + * \note N/A | |
| 491 | + ************************************************************************************* | |
| 492 | + */ | |
| 493 | +void_t WelsEndDecoder( PWelsDecoderContext pCtx ) | |
| 494 | +{ | |
| 495 | + // close decoder | |
| 496 | + WelsCloseDecoder( pCtx ); | |
| 497 | +} | |
| 498 | + | |
| 499 | +void_t GetVclNalTemporalId( PWelsDecoderContext pCtx ) | |
| 500 | +{ | |
| 501 | + PAccessUnit pAccessUnit = pCtx->pAccessUnitList; | |
| 502 | + int32_t idx = pAccessUnit->uiStartPos; | |
| 503 | + | |
| 504 | + pCtx->iFeedbackVclNalInAu = FEEDBACK_VCL_NAL; | |
| 505 | + pCtx->iFeedbackTidInAu = pAccessUnit->pNalUnitsList[idx]->sNalHeaderExt.uiTemporalId; | |
| 506 | +} | |
| 507 | + | |
| 508 | +/*! | |
| 509 | + ************************************************************************************* | |
| 510 | + * \brief First entrance to decoding core interface. | |
| 511 | + * | |
| 512 | + * \param pCtx decoder context | |
| 513 | + * \param pBufBs bit streaming buffer | |
| 514 | + * \param kBsLen size in bytes length of bit streaming buffer input | |
| 515 | + * \param ppDst picture payload data to be output | |
| 516 | + * \param pDstBufInfo buf information of ouput data | |
| 517 | + * | |
| 518 | + * \return 0 - successed | |
| 519 | + * \return 1 - failed | |
| 520 | + * | |
| 521 | + * \note N/A | |
| 522 | + ************************************************************************************* | |
| 523 | + */ | |
| 524 | +int32_t WelsDecodeBs( PWelsDecoderContext pCtx, const uint8_t *kpBsBuf, const int32_t kiBsLen, | |
| 525 | + uint8_t **ppDst, SBufferInfo* pDstBufInfo) | |
| 526 | +{ | |
| 527 | + if ( !pCtx->bEndOfStreamFlag) | |
| 528 | + { | |
| 529 | + SDataBuffer* pRawData = &pCtx->sRawData; | |
| 530 | + | |
| 531 | + int32_t iSrcIdx = 0; //the index of source bit-stream till now after parsing one or more NALs | |
| 532 | + int32_t iSrcConsumed = 0; // consumed bit count of source bs | |
| 533 | + int32_t iDstIdx = 0; //the size of current NAL after 0x03 removal and 00 00 01 removal | |
| 534 | + int32_t iSrcLength = 0; //the total size of current AU or NAL | |
| 535 | + | |
| 536 | + int32_t iConsumedBytes = 0; | |
| 537 | + int32_t iOffset = 0; | |
| 538 | + | |
| 539 | + uint8_t* pSrcNal = NULL; | |
| 540 | + uint8_t* pDstNal = NULL; | |
| 541 | + uint8_t *pNalPayload = NULL; | |
| 542 | + | |
| 543 | + | |
| 544 | + if ( NULL == DetectStartCodePrefix( kpBsBuf, &iOffset, kiBsLen ) ) //CAN'T find the 00 00 01 start prefix from the source buffer | |
| 545 | + { | |
| 546 | + return dsBitstreamError; | |
| 547 | + } | |
| 548 | + | |
| 549 | + pSrcNal = const_cast<uint8_t*> (kpBsBuf) + iOffset; | |
| 550 | + iSrcLength = kiBsLen - iOffset; | |
| 551 | + | |
| 552 | + if ( (kiBsLen + 4) > ( pRawData->pEnd - pRawData->pCurPos ) ) | |
| 553 | + { | |
| 554 | + pRawData->pCurPos = pRawData->pHead; | |
| 555 | + } | |
| 556 | + | |
| 557 | + | |
| 558 | + //copy raw data from source buffer (application) to raw data buffer (codec inside) | |
| 559 | + //0x03 removal and extract all of NAL Unit from current raw data | |
| 560 | + pDstNal = pRawData->pCurPos + 4; //4-bytes used to write the length of current NAL rbsp | |
| 561 | + | |
| 562 | + while ( iSrcConsumed < iSrcLength ) | |
| 563 | + { | |
| 564 | + if ( ( 2 + iSrcConsumed < iSrcLength ) && | |
| 565 | + ( 0 == LD16(pSrcNal+iSrcIdx) ) && | |
| 566 | + ( (pSrcNal[2+iSrcIdx]==0x03) || (pSrcNal[2+iSrcIdx]==0x01) ) ) | |
| 567 | + { | |
| 568 | + if ( pSrcNal[2+iSrcIdx] == 0x03 ) | |
| 569 | + { | |
| 570 | + ST16(pDstNal+iDstIdx, 0); | |
| 571 | + iDstIdx += 2; | |
| 572 | + iSrcIdx += 3; | |
| 573 | + iSrcConsumed += 3; | |
| 574 | + } | |
| 575 | + else | |
| 576 | + { | |
| 577 | + GetValueOf4Bytes( pDstNal-4, iDstIdx ); //pDstNal-4 (non-aligned by 4) in Solaris10(SPARC). Given value by byte. | |
| 578 | + | |
| 579 | + iConsumedBytes = 0; | |
| 580 | + pNalPayload = ParseNalHeader( pCtx, &pCtx->sCurNalHead, pDstNal, iDstIdx, pSrcNal-3, iSrcIdx+3, &iConsumedBytes ); | |
| 581 | + | |
| 582 | + if (pCtx->bAuReadyFlag) | |
| 583 | + { | |
| 584 | + ConstructAccessUnit( pCtx, ppDst, pDstBufInfo ); | |
| 585 | + | |
| 586 | + if ( (dsOutOfMemory | dsNoParamSets) & pCtx->iErrorCode) | |
| 587 | + { | |
| 588 | +#ifdef LONG_TERM_REF | |
| 589 | + pCtx->bParamSetsLostFlag = true; | |
| 590 | +#else | |
| 591 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 592 | +#endif | |
| 593 | + ResetParameterSetsState( pCtx ); | |
| 594 | + | |
| 595 | + if( dsOutOfMemory & pCtx->iErrorCode){ | |
| 596 | + return pCtx->iErrorCode; | |
| 597 | + } | |
| 598 | + } | |
| 599 | + } | |
| 600 | + | |
| 601 | + if( (IS_PARAM_SETS_NALS(pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL(pCtx->sCurNalHead.eNalUnitType)) && | |
| 602 | + pNalPayload ) | |
| 603 | + { | |
| 604 | + if ( ParseNonVclNal( pCtx, pNalPayload, iDstIdx-iConsumedBytes ) ) | |
| 605 | + { | |
| 606 | + if ( dsNoParamSets & pCtx->iErrorCode ) | |
| 607 | + { | |
| 608 | +#ifdef LONG_TERM_REF | |
| 609 | + pCtx->bParamSetsLostFlag = true; | |
| 610 | +#else | |
| 611 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 612 | +#endif | |
| 613 | + ResetParameterSetsState( pCtx ); | |
| 614 | + } | |
| 615 | + return pCtx->iErrorCode; | |
| 616 | + } | |
| 617 | + } | |
| 618 | + | |
| 619 | + pDstNal += iDstIdx; //update current position | |
| 620 | + if ( (iSrcLength - iSrcConsumed + 4) > (pRawData->pEnd - pDstNal) ) | |
| 621 | + { | |
| 622 | + pRawData->pCurPos = pRawData->pHead; | |
| 623 | + } | |
| 624 | + else | |
| 625 | + { | |
| 626 | + pRawData->pCurPos = pDstNal; | |
| 627 | + } | |
| 628 | + pDstNal = pRawData->pCurPos + 4; //init, 4 bytes used to store the next NAL | |
| 629 | + | |
| 630 | + pSrcNal += iSrcIdx+3; | |
| 631 | + iSrcConsumed += 3; | |
| 632 | + iSrcIdx = 0; | |
| 633 | + iDstIdx = 0; //reset 0, used to statistic the length of next NAL | |
| 634 | + } | |
| 635 | + continue; | |
| 636 | + } | |
| 637 | + pDstNal[iDstIdx++] = pSrcNal[iSrcIdx++]; | |
| 638 | + iSrcConsumed++; | |
| 639 | + } | |
| 640 | + | |
| 641 | + //last NAL decoding | |
| 642 | + GetValueOf4Bytes( pDstNal-4, iDstIdx ); //pDstNal-4 (non-aligned by 4) in Solaris10(SPARC). Given value by byte. | |
| 643 | + | |
| 644 | + iConsumedBytes = 0; | |
| 645 | + pNalPayload = ParseNalHeader( pCtx, &pCtx->sCurNalHead, pDstNal, iDstIdx, pSrcNal-3, iSrcIdx+3, &iConsumedBytes ); | |
| 646 | + | |
| 647 | + if (pCtx->bAuReadyFlag) | |
| 648 | + { | |
| 649 | + ConstructAccessUnit( pCtx, ppDst, pDstBufInfo ); | |
| 650 | + | |
| 651 | + if ( (dsOutOfMemory | dsNoParamSets) & pCtx->iErrorCode) | |
| 652 | + { | |
| 653 | +#ifdef LONG_TERM_REF | |
| 654 | + pCtx->bParamSetsLostFlag = true; | |
| 655 | +#else | |
| 656 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 657 | +#endif | |
| 658 | + ResetParameterSetsState( pCtx ); | |
| 659 | + return pCtx->iErrorCode; | |
| 660 | + } | |
| 661 | + } | |
| 662 | + | |
| 663 | + if( (IS_PARAM_SETS_NALS(pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL(pCtx->sCurNalHead.eNalUnitType)) && pNalPayload ) | |
| 664 | + { | |
| 665 | + if ( ParseNonVclNal( pCtx, pNalPayload, iDstIdx-iConsumedBytes ) ) | |
| 666 | + { | |
| 667 | + if ( dsNoParamSets & pCtx->iErrorCode ) | |
| 668 | + { | |
| 669 | +#ifdef LONG_TERM_REF | |
| 670 | + pCtx->bParamSetsLostFlag = true; | |
| 671 | +#else | |
| 672 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 673 | +#endif | |
| 674 | + ResetParameterSetsState( pCtx ); | |
| 675 | + } | |
| 676 | + return pCtx->iErrorCode; | |
| 677 | + } | |
| 678 | + } | |
| 679 | + | |
| 680 | + pDstNal += iDstIdx; | |
| 681 | + pRawData->pCurPos = pDstNal; //init the pCurPos for next NAL(s) storage | |
| 682 | + } | |
| 683 | + else /* no supplementary picture payload input, but stored a picture */ | |
| 684 | + { | |
| 685 | + PAccessUnit pCurAu = pCtx->pAccessUnitList; // current access unit, it will never point to NULL after decode's successful initialization | |
| 686 | + | |
| 687 | + if ( pCurAu->uiAvailUnitsNum == 0 ) | |
| 688 | + { | |
| 689 | + return pCtx->iErrorCode; | |
| 690 | + } | |
| 691 | + else | |
| 692 | + { | |
| 693 | + pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1; | |
| 694 | + | |
| 695 | + ConstructAccessUnit( pCtx, ppDst, pDstBufInfo ); | |
| 696 | + | |
| 697 | + if ( (dsOutOfMemory | dsNoParamSets) & pCtx->iErrorCode) | |
| 698 | + { | |
| 699 | +#ifdef LONG_TERM_REF | |
| 700 | + pCtx->bParamSetsLostFlag = true; | |
| 701 | +#else | |
| 702 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 703 | +#endif | |
| 704 | + ResetParameterSetsState( pCtx ); | |
| 705 | + return pCtx->iErrorCode; | |
| 706 | + } | |
| 707 | + | |
| 708 | + } | |
| 709 | + } | |
| 710 | + | |
| 711 | + return pCtx->iErrorCode; | |
| 712 | +} | |
| 713 | + | |
| 714 | +/* | |
| 715 | + * set colorspace format in decoder | |
| 716 | + */ | |
| 717 | +int32_t DecoderSetCsp(PWelsDecoderContext pCtx, const int32_t kiColorFormat) | |
| 718 | +{ | |
| 719 | + WELS_VERIFY_RETURN_IF( 1, (NULL == pCtx) ); | |
| 720 | + | |
| 721 | + pCtx->iOutputColorFormat = kiColorFormat; | |
| 722 | + if ( pCtx->pParam != NULL ) | |
| 723 | + { | |
| 724 | + pCtx->pParam->iOutputColorFormat = kiColorFormat; | |
| 725 | + } | |
| 726 | + | |
| 727 | + return 0; | |
| 728 | +} | |
| 729 | + | |
| 730 | +/*! | |
| 731 | + * \brief make sure synchonozization picture resolution (get from slice header) among different parts (i.e, memory related and so on) | |
| 732 | + * over decoder internal | |
| 733 | + * ( MB coordinate and parts of data within decoder context structure ) | |
| 734 | + * \param pCtx Wels decoder context | |
| 735 | + * \param iMbWidth MB width | |
| 736 | + * \pram iMbHeight MB height | |
| 737 | + * \return 0 - successful; none 0 - something wrong | |
| 738 | + */ | |
| 739 | +int32_t SyncPictureResolutionExt( PWelsDecoderContext pCtx, const int32_t kiMbWidth, const int32_t kiMbHeight ) | |
| 740 | +{ | |
| 741 | + int32_t iErr = ERR_NONE; | |
| 742 | + const int32_t kiPicWidth = kiMbWidth << 4; | |
| 743 | + const int32_t kiPicHeight = kiMbHeight<< 4; | |
| 744 | + | |
| 745 | + iErr = WelsRequestMem( pCtx, kiMbWidth, kiMbHeight ); // common memory used | |
| 746 | + if ( ERR_NONE != iErr ) | |
| 747 | + { | |
| 748 | + WelsLog( pCtx, WELS_LOG_WARNING, "SyncPictureResolutionExt()::WelsRequestMem--buffer allocated failure.\n" ); | |
| 749 | + pCtx->iErrorCode = dsOutOfMemory; | |
| 750 | + return iErr; | |
| 751 | + } | |
| 752 | + | |
| 753 | + iErr = InitialDqLayersContext( pCtx, kiPicWidth, kiPicHeight ); | |
| 754 | + if ( ERR_NONE != iErr ) | |
| 755 | + { | |
| 756 | + WelsLog( pCtx, WELS_LOG_WARNING, "SyncPictureResolutionExt()::InitialDqLayersContext--buffer allocated failure.\n" ); | |
| 757 | + pCtx->iErrorCode = dsOutOfMemory; | |
| 758 | + } | |
| 759 | + | |
| 760 | + return iErr; | |
| 761 | +} | |
| 762 | + | |
| 763 | +/*! | |
| 764 | + * \brief update maximal picture width and height if applicable when receiving a SPS NAL | |
| 765 | + */ | |
| 766 | +void_t UpdateMaxPictureResolution( PWelsDecoderContext pCtx, const int32_t kiCurWidth, const int32_t kiCurHeight ) | |
| 767 | +{ | |
| 768 | + //any dimension larger than that of current dimension, should modify the max-dimension | |
| 769 | + if ( kiCurWidth > pCtx->iMaxWidthInSps || kiCurHeight > pCtx->iMaxHeightInSps) | |
| 770 | + { | |
| 771 | + pCtx->iMaxWidthInSps = kiCurWidth; | |
| 772 | + pCtx->iMaxHeightInSps = kiCurHeight; | |
| 773 | + } | |
| 774 | + | |
| 775 | + return; | |
| 776 | +} | |
| 777 | + | |
| 778 | +void_t AssignFuncPointerForRec(PWelsDecoderContext pCtx) | |
| 779 | +{ | |
| 780 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_V ] = WelsI16x16LumaPredV_c; | |
| 781 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_H ] = WelsI16x16LumaPredH_c; | |
| 782 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC ] = WelsI16x16LumaPredDc_c; | |
| 783 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_P ] = WelsI16x16LumaPredPlane_c; | |
| 784 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_L ] = WelsI16x16LumaPredDcLeft_c; | |
| 785 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_T ] = WelsI16x16LumaPredDcTop_c; | |
| 786 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_128] = WelsI16x16LumaPredDcNA_c; | |
| 787 | + | |
| 788 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_V ] = WelsI4x4LumaPredV_c; | |
| 789 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_H ] = WelsI4x4LumaPredH_c; | |
| 790 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC ] = WelsI4x4LumaPredDc_c; | |
| 791 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC_L ] = WelsI4x4LumaPredDcLeft_c; | |
| 792 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC_T ] = WelsI4x4LumaPredDcTop_c; | |
| 793 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC_128] = WelsI4x4LumaPredDcNA_c; | |
| 794 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDL ] = WelsI4x4LumaPredDDL_c; | |
| 795 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDL_TOP] = WelsI4x4LumaPredDDLTop_c; | |
| 796 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDR ] = WelsI4x4LumaPredDDR_c; | |
| 797 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VL ] = WelsI4x4LumaPredVL_c; | |
| 798 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VL_TOP] = WelsI4x4LumaPredVLTop_c; | |
| 799 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VR ] = WelsI4x4LumaPredVR_c; | |
| 800 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_HU ] = WelsI4x4LumaPredHU_c; | |
| 801 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_HD ] = WelsI4x4LumaPredHD_c; | |
| 802 | + | |
| 803 | + pCtx->pGetIChromaPredFunc[C_PRED_DC ] = WelsIChromaPredDc_c; | |
| 804 | + pCtx->pGetIChromaPredFunc[C_PRED_H ] = WelsIChromaPredH_c; | |
| 805 | + pCtx->pGetIChromaPredFunc[C_PRED_V ] = WelsIChromaPredV_c; | |
| 806 | + pCtx->pGetIChromaPredFunc[C_PRED_P ] = WelsIChromaPredPlane_c; | |
| 807 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_L ] = WelsIChromaPredDcLeft_c; | |
| 808 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_T ] = WelsIChromaPredDcTop_c; | |
| 809 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_128] = WelsIChromaPredDcNA_c; | |
| 810 | + | |
| 811 | + InitDctClipTable(); | |
| 812 | + pCtx->pIdctResAddPredFunc = IdctResAddPred_c; | |
| 813 | + | |
| 814 | +#if defined(X86_ASM) | |
| 815 | + if ( pCtx->uiCpuFlag & WELS_CPU_MMXEXT ) | |
| 816 | + { | |
| 817 | + pCtx->pIdctResAddPredFunc = IdctResAddPred_mmx; | |
| 818 | + | |
| 819 | + /////////mmx code opt--- | |
| 820 | + pCtx->pGetIChromaPredFunc[C_PRED_H] = WelsIChromaPredH_mmx; | |
| 821 | + pCtx->pGetIChromaPredFunc[C_PRED_V] = WelsIChromaPredV_mmx; | |
| 822 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_L ] = WelsIChromaPredDcLeft_mmx; | |
| 823 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_128] = WelsIChromaPredDcNA_mmx; | |
| 824 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDR] = WelsI4x4LumaPredDDR_mmx; | |
| 825 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_HD ] = WelsI4x4LumaPredHD_mmx; | |
| 826 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_HU ] = WelsI4x4LumaPredHU_mmx; | |
| 827 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VR ] = WelsI4x4LumaPredVR_mmx; | |
| 828 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDL] = WelsI4x4LumaPredDDL_mmx; | |
| 829 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VL ] = WelsI4x4LumaPredVL_mmx; | |
| 830 | + } | |
| 831 | + if ( pCtx->uiCpuFlag & WELS_CPU_SSE2 ) | |
| 832 | + { | |
| 833 | + /////////sse2 code opt--- | |
| 834 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC] = WelsI16x16LumaPredDc_sse2; | |
| 835 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_P] = WelsI16x16LumaPredPlane_sse2; | |
| 836 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_H] = WelsI16x16LumaPredH_sse2; | |
| 837 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_V] = WelsI16x16LumaPredV_sse2; | |
| 838 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_T ] = WelsI16x16LumaPredDcTop_sse2; | |
| 839 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_128] = WelsI16x16LumaPredDcNA_sse2; | |
| 840 | + pCtx->pGetIChromaPredFunc[C_PRED_P ] = WelsIChromaPredPlane_sse2; | |
| 841 | + pCtx->pGetIChromaPredFunc[C_PRED_DC] = WelsIChromaPredDc_sse2; | |
| 842 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_T] = WelsIChromaPredDcTop_sse2; | |
| 843 | + } | |
| 844 | +#endif | |
| 845 | + DeblockingInit(&pCtx->sDeblockingFunc, pCtx->uiCpuFlag); | |
| 846 | + | |
| 847 | + WelsBlockFuncInit(&pCtx->sBlockFunc, pCtx->uiCpuFlag); | |
| 848 | +} | |
| 849 | + | |
| 850 | +} // namespace WelsDec | |
| @@ -0,0 +1,2106 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + * decoder_core.c: Wels decoder framework core implementation | |
| 32 | + */ | |
| 33 | + | |
| 34 | +#include <string.h> | |
| 35 | +#include "codec_def.h" | |
| 36 | +#include "decoder_core.h" | |
| 37 | +#include "typedefs.h" | |
| 38 | +#include "wels_const.h" | |
| 39 | +#include "wels_common_basis.h" | |
| 40 | +#include "codec_app_def.h" | |
| 41 | +#include "decoder_context.h" | |
| 42 | +#include "dec_golomb.h" | |
| 43 | +#include "bit_stream.h" | |
| 44 | +#include "error_code.h" | |
| 45 | +#include "parameter_sets.h" | |
| 46 | +#include "fmo.h" | |
| 47 | +#include "utils.h" | |
| 48 | +#include "memmgr_nal_unit.h" | |
| 49 | +#include "dec_frame.h" | |
| 50 | +#include "au_parser.h" | |
| 51 | +#include "pic_queue.h" | |
| 52 | +#include "ls_defines.h" | |
| 53 | +#include "decode_slice.h" | |
| 54 | +#include "manage_dec_ref.h" | |
| 55 | +#include "expand_pic.h" | |
| 56 | +#include "decoder.h" | |
| 57 | +#include "decode_mb_aux.h" | |
| 58 | +#include "mem_align.h" | |
| 59 | + | |
| 60 | +namespace WelsDec { | |
| 61 | + | |
| 62 | +static inline int32_t DecodeFrameConstruction( PWelsDecoderContext pCtx, uint8_t **ppDst, int32_t *pDstLen, int32_t *pWidth, int32_t *pHeight, SBufferInfo *pDstInfo ) | |
| 63 | +{ | |
| 64 | + PDqLayer pCurDq = pCtx->pCurDqLayer; | |
| 65 | + PPicture pPic = pCtx->pDec; | |
| 66 | + | |
| 67 | + const int32_t kiWidth = pCurDq->iMbWidth << 4; | |
| 68 | + const int32_t kiHeight= pCurDq->iMbHeight << 4; | |
| 69 | + | |
| 70 | + const int32_t kiTotalNumMbInCurLayer = pCurDq->iMbWidth * pCurDq->iMbHeight; | |
| 71 | + | |
| 72 | + if ( pPic->iTotalNumMbRec != kiTotalNumMbInCurLayer ) | |
| 73 | + { | |
| 74 | + WelsLog( pCtx, WELS_LOG_WARNING, "DecodeFrameConstruction():::iTotalNumMbRec:%d, total_num_mb_sps:%d, cur_layer_mb_width:%d, cur_layer_mb_height:%d \n", | |
| 75 | + pPic->iTotalNumMbRec, kiTotalNumMbInCurLayer, pCurDq->iMbWidth, pCurDq->iMbHeight ); | |
| 76 | + return -1; | |
| 77 | + } | |
| 78 | +#ifdef NO_WAITING_AU | |
| 79 | + pPic->iTotalNumMbRec = 0; | |
| 80 | +#endif | |
| 81 | + | |
| 82 | + if ( I_SLICE == pCurDq->sLayerInfo.sSliceInLayer.eSliceType ) | |
| 83 | + { | |
| 84 | + memcpy( &(pCtx->sFrameCrop), &(pCurDq->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.pSps->sFrameCrop), sizeof(SPosOffset) );//confirmed_safe_unsafe_usage | |
| 85 | +#ifdef LONG_TERM_REF | |
| 86 | + pCtx->bParamSetsLostFlag = false; | |
| 87 | +#else | |
| 88 | + pCtx->bReferenceLostAtT0Flag = false; // need initialize it due I_SLICE, 6/4/2010 | |
| 89 | +#endif //LONG_TERM_REF | |
| 90 | + WelsLog( pCtx, WELS_LOG_INFO, "DecodeFrameConstruction()::::output good I frame, %d x %d, crop_left:%d, crop_right:%d, crop_top:%d, crop_bottom:%d.\n", | |
| 91 | + kiWidth, kiHeight, pCtx->sFrameCrop.iLeftOffset, pCtx->sFrameCrop.iRightOffset, pCtx->sFrameCrop.iTopOffset, pCtx->sFrameCrop.iBottomOffset ); | |
| 92 | + WelsLog( pCtx, WELS_LOG_INFO, "After decoding, set_mode:[%s], eWorkMode:[%s], eBufferProperty:[%s]\n", | |
| 93 | + DECODER_MODE_NAME(pCtx->iSetMode), DECODER_MODE_NAME(pCtx->iDecoderMode), OUTPUT_PROPERTY_NAME(pDstInfo->eBufferProperty)); | |
| 94 | + } | |
| 95 | + | |
| 96 | + //////output:::normal path | |
| 97 | + ppDst[0] = pPic->pData[0]; | |
| 98 | + ppDst[1] = pPic->pData[1]; | |
| 99 | + ppDst[2] = pPic->pData[2]; | |
| 100 | + *pDstLen = pPic->iLinesize[0]; | |
| 101 | + *(pDstLen+1) = pPic->iLinesize[1]; | |
| 102 | + *pWidth = kiWidth; | |
| 103 | + *pHeight = kiHeight; | |
| 104 | + | |
| 105 | + pDstInfo->UsrData.sSystemBuffer.iFormat = videoFormatI420; | |
| 106 | + | |
| 107 | + pDstInfo->UsrData.sSystemBuffer.iWidth = kiWidth - (pCtx->sFrameCrop.iLeftOffset + pCtx->sFrameCrop.iRightOffset)*2; | |
| 108 | + pDstInfo->UsrData.sSystemBuffer.iHeight = kiHeight - (pCtx->sFrameCrop.iTopOffset + pCtx->sFrameCrop.iBottomOffset)*2; | |
| 109 | + pDstInfo->UsrData.sSystemBuffer.iStride[0] = pPic->iLinesize[0]; | |
| 110 | + pDstInfo->UsrData.sSystemBuffer.iStride[1] = pPic->iLinesize[1]; | |
| 111 | + ppDst[0] = ppDst[0] + pCtx->sFrameCrop.iTopOffset*2*pPic->iLinesize[0] + pCtx->sFrameCrop.iLeftOffset*2; | |
| 112 | + ppDst[1] = ppDst[1] + pCtx->sFrameCrop.iTopOffset *pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset; | |
| 113 | + ppDst[2] = ppDst[2] + pCtx->sFrameCrop.iTopOffset *pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset; | |
| 114 | + pDstInfo->eBufferProperty = BUFFER_HOST; | |
| 115 | + pDstInfo->iBufferStatus = 1; | |
| 116 | + | |
| 117 | + return 0; | |
| 118 | +} | |
| 119 | + | |
| 120 | +inline BOOL_T CheckSliceNeedReconstruct(int16_t iCurDid, int16_t iCurQid, bool_t bStoreRefBasePicFlag, | |
| 121 | + uint8_t uiDidMax, uint8_t uiLayerDqId, uint8_t uiTargetDqId) | |
| 122 | +{ | |
| 123 | + return ( (iCurDid == uiDidMax) && (iCurQid == BASE_QUALITY_ID) && (bStoreRefBasePicFlag) ) // store base | |
| 124 | + || (uiLayerDqId == uiTargetDqId); // target layer | |
| 125 | +} | |
| 126 | + | |
| 127 | +inline uint8_t GetTargetDqId(uint8_t uiTargetDqId, SDecodingParam * psParam) | |
| 128 | +{ | |
| 129 | + uint8_t uiRequiredDqId = psParam ? psParam->uiTargetDqLayer : (uint8_t)255; | |
| 130 | + | |
| 131 | + return WELS_MIN(uiTargetDqId, uiRequiredDqId); | |
| 132 | +} | |
| 133 | + | |
| 134 | + | |
| 135 | +inline void_t HandleReferenceLostL0(PWelsDecoderContext pCtx, PNalUnit pCurNal) | |
| 136 | +{ | |
| 137 | + if( 0 == pCurNal->sNalHeaderExt.uiTemporalId ){ | |
| 138 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 139 | + } | |
| 140 | +#ifndef LONG_TERM_REF | |
| 141 | + if( pCtx->bReferenceLostAtT0Flag ){ | |
| 142 | + ResetParameterSetsState(pCtx); | |
| 143 | + } | |
| 144 | +#endif | |
| 145 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 146 | +} | |
| 147 | + | |
| 148 | +inline void_t HandleReferenceLost(PWelsDecoderContext pCtx, PNalUnit pCurNal) | |
| 149 | +{ | |
| 150 | + if( (0 == pCurNal->sNalHeaderExt.uiTemporalId) || (1 == pCurNal->sNalHeaderExt.uiTemporalId) ){ | |
| 151 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 152 | + } | |
| 153 | +#ifndef LONG_TERM_REF | |
| 154 | + if( pCtx->bReferenceLostAtT0Flag ){ | |
| 155 | + ResetParameterSetsState(pCtx); | |
| 156 | + } | |
| 157 | +#endif | |
| 158 | + pCtx->iErrorCode |= dsRefLost; | |
| 159 | +} | |
| 160 | + | |
| 161 | +inline int32_t WelsDecodeConstructSlice(PWelsDecoderContext pCtx, PNalUnit pCurNal) | |
| 162 | +{ | |
| 163 | + int32_t iRet = WelsTargetSliceConstruction(pCtx); | |
| 164 | + | |
| 165 | + if( iRet ){ | |
| 166 | + HandleReferenceLostL0(pCtx, pCurNal); | |
| 167 | + } | |
| 168 | + | |
| 169 | + return iRet; | |
| 170 | +} | |
| 171 | + | |
| 172 | +/* | |
| 173 | + * Predeclared function routines .. | |
| 174 | + */ | |
| 175 | +int32_t ParseRefPicListReordering ( PBitStringAux pBs, PSliceHeader pSh ) | |
| 176 | +{ | |
| 177 | + int32_t iList = 0; | |
| 178 | + const ESliceType keSt = pSh->eSliceType; | |
| 179 | + PRefPicListReorderSyn pRefPicListReordering = &pSh->pRefPicListReordering; | |
| 180 | + | |
| 181 | + if ( keSt == I_SLICE || keSt == SI_SLICE ) | |
| 182 | + return ERR_NONE; | |
| 183 | + | |
| 184 | + // Common syntaxs for P or B slices: list0, list1 followed if B slices used. | |
| 185 | + do { | |
| 186 | + pRefPicListReordering->bRefPicListReorderingFlag[iList] = !!BsGetOneBit( pBs); | |
| 187 | + | |
| 188 | + if ( pRefPicListReordering->bRefPicListReorderingFlag[iList] ){ | |
| 189 | + int32_t iIdx = 0; | |
| 190 | + do { | |
| 191 | + const uint8_t kuiIdc = BsGetUe( pBs ); | |
| 192 | + | |
| 193 | + //Fixed the referrence list reordering crash issue.(fault kIdc value > 3 case)--- | |
| 194 | + if ((iIdx >= MAX_REF_PIC_COUNT )||(kuiIdc > 3)) | |
| 195 | + { | |
| 196 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_REF_REORDERING); | |
| 197 | + } | |
| 198 | + pRefPicListReordering->sReorderingSyn[iList][iIdx].uiReorderingOfPicNumsIdc = kuiIdc; | |
| 199 | + if ( kuiIdc == 3 ) | |
| 200 | + break; | |
| 201 | + | |
| 202 | + if ( iIdx >= pSh->uiRefCount[iList] || iIdx >= MAX_REF_PIC_COUNT ) | |
| 203 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_REF_REORDERING); | |
| 204 | + | |
| 205 | + if (kuiIdc == 0 || kuiIdc == 1){ | |
| 206 | + pRefPicListReordering->sReorderingSyn[iList][iIdx].uiAbsDiffPicNumMinus1 = BsGetUe( pBs ); // uiAbsDiffPicNumMinus1 | |
| 207 | + } | |
| 208 | + else if (kuiIdc == 2){ | |
| 209 | + pRefPicListReordering->sReorderingSyn[iList][iIdx].uiLongTermPicNum= BsGetUe( pBs ); | |
| 210 | + } | |
| 211 | + | |
| 212 | + ++ iIdx; | |
| 213 | + } while(true); | |
| 214 | + } | |
| 215 | + if (keSt != B_SLICE) | |
| 216 | + break; | |
| 217 | + ++ iList; | |
| 218 | + } while(iList < LIST_A); | |
| 219 | + | |
| 220 | + return ERR_NONE; | |
| 221 | +} | |
| 222 | + | |
| 223 | +int32_t ParseDecRefPicMarking ( PWelsDecoderContext pCtx, PBitStringAux pBs, PSliceHeader pSh, PSps pSps, const bool_t kbIdrFlag) | |
| 224 | +{ | |
| 225 | + PRefPicMarking const kpRefMarking = &pSh->sRefMarking; | |
| 226 | + | |
| 227 | + if ( kbIdrFlag ){ | |
| 228 | + kpRefMarking->bNoOutputOfPriorPicsFlag = !!BsGetOneBit( pBs ); | |
| 229 | + kpRefMarking->bLongTermRefFlag = !!BsGetOneBit( pBs ); | |
| 230 | + } | |
| 231 | + else{ | |
| 232 | + kpRefMarking->bAdaptiveRefPicMarkingModeFlag = !!BsGetOneBit( pBs ); | |
| 233 | + if (kpRefMarking->bAdaptiveRefPicMarkingModeFlag){ | |
| 234 | + int32_t iIdx = 0; | |
| 235 | + do { | |
| 236 | + const int32_t kiMmco = BsGetUe( pBs ); | |
| 237 | + | |
| 238 | + kpRefMarking->sMmcoRef[iIdx].uiMmcoType = kiMmco; | |
| 239 | + if (kiMmco == MMCO_END) | |
| 240 | + break; | |
| 241 | + | |
| 242 | + if (kiMmco == MMCO_SHORT2UNUSED || kiMmco == MMCO_SHORT2LONG) | |
| 243 | + { | |
| 244 | + kpRefMarking->sMmcoRef[iIdx].iDiffOfPicNum = 1 + BsGetUe( pBs ); | |
| 245 | + kpRefMarking->sMmcoRef[iIdx].iShortFrameNum = (pSh->iFrameNum - kpRefMarking->sMmcoRef[iIdx].iDiffOfPicNum) & ((1<<pSps->uiLog2MaxFrameNum)-1); | |
| 246 | + } | |
| 247 | + else if (kiMmco == MMCO_LONG2UNUSED) | |
| 248 | + kpRefMarking->sMmcoRef[iIdx].uiLongTermPicNum = BsGetUe( pBs ); | |
| 249 | + | |
| 250 | + if (kiMmco == MMCO_SHORT2LONG || kiMmco == MMCO_LONG) | |
| 251 | + { | |
| 252 | + kpRefMarking->sMmcoRef[iIdx].iLongTermFrameIdx = BsGetUe( pBs ); | |
| 253 | + } | |
| 254 | + else if (kiMmco == MMCO_SET_MAX_LONG) | |
| 255 | + kpRefMarking->sMmcoRef[iIdx].iMaxLongTermFrameIdx = -1 + BsGetUe( pBs ); | |
| 256 | + ++ iIdx; | |
| 257 | + | |
| 258 | + } while(iIdx < MAX_MMCO_COUNT); | |
| 259 | + } | |
| 260 | + } | |
| 261 | + | |
| 262 | + return ERR_NONE; | |
| 263 | +} | |
| 264 | + | |
| 265 | +bool_t FillDefaultSliceHeaderExt ( PSliceHeaderExt pShExt, PNalUnitHeaderExt pNalExt ) | |
| 266 | +{ | |
| 267 | + if ( pShExt == NULL || pNalExt == NULL ) | |
| 268 | + return false; | |
| 269 | + | |
| 270 | + if ( pNalExt->iNoInterLayerPredFlag || pNalExt->uiQualityId > 0 ) | |
| 271 | + pShExt->bBasePredWeightTableFlag = false; | |
| 272 | + else | |
| 273 | + pShExt->bBasePredWeightTableFlag = true; | |
| 274 | + pShExt->uiRefLayerDqId = (uint8_t)-1; | |
| 275 | + pShExt->uiDisableInterLayerDeblockingFilterIdc = 0; | |
| 276 | + pShExt->iInterLayerSliceAlphaC0Offset = 0; | |
| 277 | + pShExt->iInterLayerSliceBetaOffset = 0; | |
| 278 | + pShExt->bConstrainedIntraResamplingFlag = false; | |
| 279 | + pShExt->uiRefLayerChromaPhaseXPlus1Flag = 0; | |
| 280 | + pShExt->uiRefLayerChromaPhaseYPlus1 = 1; | |
| 281 | + //memset(&pShExt->sScaledRefLayer, 0, sizeof(SPosOffset)); | |
| 282 | + | |
| 283 | + pShExt->iScaledRefLayerPicWidthInSampleLuma = pShExt->sSliceHeader.iMbWidth << 4; | |
| 284 | + pShExt->iScaledRefLayerPicHeightInSampleLuma = pShExt->sSliceHeader.iMbHeight << 4; | |
| 285 | + | |
| 286 | + pShExt->bSliceSkipFlag = false; | |
| 287 | + pShExt->bAdaptiveBaseModeFlag = false; | |
| 288 | + pShExt->bDefaultBaseModeFlag = false; | |
| 289 | + pShExt->bAdaptiveMotionPredFlag = false; | |
| 290 | + pShExt->bDefaultMotionPredFlag = false; | |
| 291 | + pShExt->bAdaptiveResidualPredFlag = false; | |
| 292 | + pShExt->bDefaultResidualPredFlag = false; | |
| 293 | + pShExt->bTCoeffLevelPredFlag = false; | |
| 294 | + pShExt->uiScanIdxStart = 0; | |
| 295 | + pShExt->uiScanIdxEnd = 15; | |
| 296 | + | |
| 297 | + return true; | |
| 298 | +} | |
| 299 | + | |
| 300 | +/* | |
| 301 | + * WelsInitMemory | |
| 302 | + * Memory request for new introduced data | |
| 303 | + * Especially for: | |
| 304 | + * rbsp_au_buffer, cur_dq_layer_ptr and ref_dq_layer_ptr in MB info cache. | |
| 305 | + * return: | |
| 306 | + * 0 - success; otherwise returned error_no defined in error_no.h. | |
| 307 | +*/ | |
| 308 | +int32_t WelsInitMemory( PWelsDecoderContext pCtx ) | |
| 309 | +{ | |
| 310 | + if (pCtx == NULL){ | |
| 311 | + return ERR_INFO_INVALID_PTR; | |
| 312 | + } | |
| 313 | + | |
| 314 | + if ( MemInitNalList( &pCtx->pAccessUnitList, MAX_NAL_UNIT_NUM_IN_AU ) != 0 ) | |
| 315 | + return ERR_INFO_OUT_OF_MEMORY; | |
| 316 | + | |
| 317 | + if ( ( pCtx->sRawData.pHead = static_cast<uint8_t*> (WelsMalloc( MAX_ACCESS_UINT_CAPACITY, "pCtx->sRawData->pHead" )) ) == NULL ) | |
| 318 | + { | |
| 319 | + return ERR_INFO_OUT_OF_MEMORY; | |
| 320 | + } | |
| 321 | + pCtx->sRawData.pStartPos = | |
| 322 | + pCtx->sRawData.pCurPos = pCtx->sRawData.pHead; | |
| 323 | + pCtx->sRawData.pEnd = pCtx->sRawData.pHead + MAX_ACCESS_UINT_CAPACITY; | |
| 324 | + | |
| 325 | + pCtx->uiTargetDqId = (uint8_t)-1; | |
| 326 | + pCtx->bEndOfStreamFlag = false; | |
| 327 | + pCtx->iImgWidthInPixel = 0; | |
| 328 | + pCtx->iImgHeightInPixel = 0; | |
| 329 | + | |
| 330 | + return ERR_NONE; | |
| 331 | +} | |
| 332 | + | |
| 333 | +/* | |
| 334 | + * WelsFreeMemory | |
| 335 | + * Free memory introduced in WelsInitMemory at destruction of decoder. | |
| 336 | + * | |
| 337 | + */ | |
| 338 | +void_t WelsFreeMemory( PWelsDecoderContext pCtx ) | |
| 339 | +{ | |
| 340 | + if ( pCtx == NULL ) | |
| 341 | + return; | |
| 342 | + | |
| 343 | + if ( NULL != pCtx->pParam ) | |
| 344 | + { | |
| 345 | + WelsFree( pCtx->pParam, "pCtx->pParam" ); | |
| 346 | + | |
| 347 | + pCtx->pParam = NULL; | |
| 348 | + } | |
| 349 | + | |
| 350 | + MemFreeNalList( &pCtx->pAccessUnitList ); | |
| 351 | + | |
| 352 | + if ( pCtx->sRawData.pHead ) | |
| 353 | + { | |
| 354 | + WelsFree(pCtx->sRawData.pHead, "pCtx->sRawData->pHead"); | |
| 355 | + } | |
| 356 | + pCtx->sRawData.pHead = NULL; | |
| 357 | + pCtx->sRawData.pEnd = NULL; | |
| 358 | + pCtx->sRawData.pStartPos = NULL; | |
| 359 | + pCtx->sRawData.pCurPos = NULL; | |
| 360 | +} | |
| 361 | + | |
| 362 | +/* | |
| 363 | + * DecodeNalHeaderExt | |
| 364 | + * Trigger condition: NAL_UNIT_TYPE = NAL_UNIT_PREFIX or NAL_UNIT_CODED_SLICE_EXT | |
| 365 | + * Parameter: | |
| 366 | + * pNal: target NALUnit ptr | |
| 367 | + * pSrc: NAL Unit bitstream | |
| 368 | + */ | |
| 369 | +void_t DecodeNalHeaderExt( PNalUnit pNal, uint8_t* pSrc ) | |
| 370 | +{ | |
| 371 | + PNalUnitHeaderExt pHeaderExt = &pNal->sNalHeaderExt; | |
| 372 | + | |
| 373 | + uint8_t uiCurByte = *pSrc; | |
| 374 | + pHeaderExt->bIdrFlag = !!(uiCurByte & 0x40); | |
| 375 | + pHeaderExt->uiPriorityId = uiCurByte & 0x3F; | |
| 376 | + | |
| 377 | + uiCurByte = *(++pSrc); | |
| 378 | + pHeaderExt->iNoInterLayerPredFlag = uiCurByte >> 7; | |
| 379 | + pHeaderExt->uiDependencyId = (uiCurByte & 0x70) >> 4; | |
| 380 | + pHeaderExt->uiQualityId = uiCurByte & 0x0F; | |
| 381 | + uiCurByte = *(++pSrc); | |
| 382 | + pHeaderExt->uiTemporalId = uiCurByte >> 5; | |
| 383 | + pHeaderExt->bUseRefBasePicFlag = !!(uiCurByte & 0x10); | |
| 384 | + pHeaderExt->bDiscardableFlag = !!(uiCurByte & 0x08); | |
| 385 | + pHeaderExt->bOutputFlag = !!(uiCurByte & 0x04); | |
| 386 | + pHeaderExt->uiReservedThree2Bits = uiCurByte & 0x03; | |
| 387 | + pHeaderExt->uiLayerDqId = (pHeaderExt->uiDependencyId << 4) | pHeaderExt->uiQualityId; | |
| 388 | +} | |
| 389 | + | |
| 390 | + | |
| 391 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 392 | +int32_t CheckPpsId( PWelsDecoderContext pCtx, PPps* ppPps, uint32_t uiPpsId ) | |
| 393 | +{ | |
| 394 | + PPps pPpsList = pCtx->sPpsBuffer; | |
| 395 | + int32_t iPpsNum = pCtx->iPpsTotalNum; | |
| 396 | + int32_t i = 0; | |
| 397 | + | |
| 398 | + if ( iPpsNum <= 0 ) | |
| 399 | + { | |
| 400 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 401 | + | |
| 402 | + WelsLog( pCtx, WELS_LOG_WARNING, "CheckPpsId():::::PPS list is empty...NO PPS!!!\n" ); | |
| 403 | + return dsNoParamSets; | |
| 404 | + } | |
| 405 | + | |
| 406 | + while ( i < iPpsNum ) | |
| 407 | + { | |
| 408 | + if ( uiPpsId == pPpsList[i].iPpsId ) | |
| 409 | + { | |
| 410 | + *ppPps = &pPpsList[i]; | |
| 411 | + break; | |
| 412 | + } | |
| 413 | + else | |
| 414 | + { | |
| 415 | + ++i; | |
| 416 | + } | |
| 417 | + } | |
| 418 | + | |
| 419 | + if ( i == iPpsNum ) | |
| 420 | + { | |
| 421 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 422 | + | |
| 423 | + WelsLog( pCtx, WELS_LOG_WARNING, "CheckPpsId()::::::CAN NOT find the matching from the PPS List. iPpsId:%d\n", uiPpsId ); | |
| 424 | + return dsNoParamSets; | |
| 425 | + } | |
| 426 | + | |
| 427 | + return 0; | |
| 428 | +} | |
| 429 | + | |
| 430 | +int32_t CheckSpsId( PWelsDecoderContext pCtx, PSubsetSps* ppSubsetSps, PSps* ppSps, int32_t iSpsId, bool_t bExtensionFlag ) | |
| 431 | +{ | |
| 432 | + PSps pSpsList = pCtx->sSpsBuffer; | |
| 433 | + PSubsetSps pSubspsList = pCtx->sSubsetSpsBuffer; | |
| 434 | + | |
| 435 | + int32_t iSpsNum = pCtx->iSpsTotalNum; | |
| 436 | + int32_t iSubspsNum = pCtx->iSubspsTotalNum; | |
| 437 | + int32_t i = 0; | |
| 438 | + | |
| 439 | + if ( bExtensionFlag ) | |
| 440 | + { | |
| 441 | + if ( iSubspsNum <= 0 ) | |
| 442 | + { | |
| 443 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 444 | + | |
| 445 | + WelsLog( pCtx, WELS_LOG_WARNING, "CheckSpsId()::::SUBSPS list is empty....NO SUBSPS\n" ); | |
| 446 | + return dsNoParamSets; | |
| 447 | + } | |
| 448 | + while ( i < iSubspsNum ) | |
| 449 | + { | |
| 450 | + if ( iSpsId == pSubspsList[i].sSps.iSpsId ) | |
| 451 | + { | |
| 452 | + *ppSubsetSps = &pSubspsList[i]; | |
| 453 | + *ppSps = &pSubspsList[i].sSps; | |
| 454 | + break; | |
| 455 | + } | |
| 456 | + else | |
| 457 | + { | |
| 458 | + ++i; | |
| 459 | + } | |
| 460 | + } | |
| 461 | + if ( i == iSubspsNum ) | |
| 462 | + { | |
| 463 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 464 | + | |
| 465 | + WelsLog( pCtx, WELS_LOG_WARNING, "CheckSpsId()::::::CAN NOT find the matching from the SUBSPS List. iSpsId:%d\n", iSpsId ); | |
| 466 | + return dsNoParamSets; | |
| 467 | + } | |
| 468 | + } | |
| 469 | + else | |
| 470 | + { | |
| 471 | + if ( iSpsNum <= 0 ) | |
| 472 | + { | |
| 473 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 474 | + | |
| 475 | + WelsLog( pCtx, WELS_LOG_WARNING, "CheckSpsId()::::SPS list is empty....NO SPS\n" ); | |
| 476 | + return dsNoParamSets; | |
| 477 | + } | |
| 478 | + while ( i < iSpsNum ) | |
| 479 | + { | |
| 480 | + if ( iSpsId == pSpsList[i].iSpsId ) | |
| 481 | + { | |
| 482 | + *ppSubsetSps = NULL; | |
| 483 | + *ppSps = &pSpsList[i]; | |
| 484 | + break; | |
| 485 | + } | |
| 486 | + else | |
| 487 | + { | |
| 488 | + ++i; | |
| 489 | + } | |
| 490 | + } | |
| 491 | + if ( i == iSpsNum ) | |
| 492 | + { | |
| 493 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 494 | + | |
| 495 | + WelsLog( pCtx, WELS_LOG_WARNING, "CheckSpsId()::::::CAN NOT find the matching from the SPS List. iSpsId:%d\n", iSpsId ); | |
| 496 | + return dsNoParamSets; | |
| 497 | + } | |
| 498 | + } | |
| 499 | + | |
| 500 | + return 0; | |
| 501 | +} | |
| 502 | + | |
| 503 | +#endif | |
| 504 | +/* | |
| 505 | + * decode_slice_header_avc | |
| 506 | + * Parse slice header of bitstream in avc for storing data structure | |
| 507 | + */ | |
| 508 | +int32_t ParseSliceHeaderSyntaxs ( PWelsDecoderContext pCtx, PBitStringAux pBs, const bool_t kbExtensionFlag ) | |
| 509 | +{ | |
| 510 | + PNalUnit const kpCurNal = pCtx->pAccessUnitList->pNalUnitsList[pCtx->pAccessUnitList->uiAvailUnitsNum-1]; | |
| 511 | + | |
| 512 | + PNalUnitHeaderExt pNalHeaderExt = NULL; | |
| 513 | + PSliceHeader pSliceHead = NULL; | |
| 514 | + PSliceHeaderExt pSliceHeadExt = NULL; | |
| 515 | + PSubsetSps pSubsetSps = NULL; | |
| 516 | + PSps pSps = NULL; | |
| 517 | + PPps pPps = NULL; | |
| 518 | + ENalUnitType eNalType = static_cast<ENalUnitType> (0); | |
| 519 | + int32_t iPpsId = 0; | |
| 520 | + int32_t iRet = ERR_NONE; | |
| 521 | + uint8_t uiSliceType = 0; | |
| 522 | + uint8_t uiQualityId = BASE_QUALITY_ID; | |
| 523 | + bool_t bIdrFlag = false; | |
| 524 | + bool_t bSgChangeCycleInvolved = false; // involved slice group change cycle ? | |
| 525 | + | |
| 526 | + if (kpCurNal == NULL) | |
| 527 | + { | |
| 528 | + return ERR_INFO_OUT_OF_MEMORY; | |
| 529 | + } | |
| 530 | + | |
| 531 | + pNalHeaderExt = &kpCurNal->sNalHeaderExt; | |
| 532 | + pSliceHead = &kpCurNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader; | |
| 533 | + eNalType = pNalHeaderExt->sNalUnitHeader.eNalUnitType; | |
| 534 | + | |
| 535 | + pSliceHeadExt = &kpCurNal->sNalData.sVclNal.sSliceHeaderExt; | |
| 536 | + | |
| 537 | + if ( pSliceHeadExt ){ | |
| 538 | + SRefBasePicMarking sBaseMarking; | |
| 539 | + const bool_t kbStoreRefBaseFlag = pSliceHeadExt->bStoreRefBasePicFlag; | |
| 540 | + memcpy(&sBaseMarking, &pSliceHeadExt->sRefBasePicMarking, sizeof(SRefBasePicMarking));//confirmed_safe_unsafe_usage | |
| 541 | + memset(pSliceHeadExt, 0, sizeof(SSliceHeaderExt)); | |
| 542 | + pSliceHeadExt->bStoreRefBasePicFlag = kbStoreRefBaseFlag; | |
| 543 | + memcpy(&pSliceHeadExt->sRefBasePicMarking, &sBaseMarking, sizeof(SRefBasePicMarking));//confirmed_safe_unsafe_usage | |
| 544 | + } | |
| 545 | + | |
| 546 | + kpCurNal->sNalData.sVclNal.bSliceHeaderExtFlag = kbExtensionFlag; | |
| 547 | + | |
| 548 | + pSliceHead->iFirstMbInSlice = BsGetUe( pBs ); | |
| 549 | + | |
| 550 | + uiSliceType= BsGetUe( pBs ); | |
| 551 | + if(uiSliceType > 9) | |
| 552 | + { | |
| 553 | + WelsLog( pCtx, WELS_LOG_WARNING, "slice type too large (%d) at first_mb(%d)\n", uiSliceType, pSliceHead->iFirstMbInSlice); | |
| 554 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_SLICE_TYPE); | |
| 555 | + } | |
| 556 | + if(uiSliceType > 4) | |
| 557 | + uiSliceType -= 5; | |
| 558 | + | |
| 559 | + if ( kbExtensionFlag ){ | |
| 560 | + if (uiSliceType > 2){ | |
| 561 | + WelsLog( pCtx, WELS_LOG_WARNING, "Invalid slice type(%d).\n", uiSliceType); | |
| 562 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_SLICE_TYPE); | |
| 563 | + } | |
| 564 | + } | |
| 565 | + | |
| 566 | + pSliceHead->eSliceType = static_cast <ESliceType> (uiSliceType); | |
| 567 | + | |
| 568 | + iPpsId= BsGetUe( pBs ); | |
| 569 | + | |
| 570 | + if(iPpsId >= MAX_PPS_COUNT){ | |
| 571 | + WelsLog( pCtx, WELS_LOG_WARNING, "iPpsId out of range\n"); | |
| 572 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_PPS_ID_OVERFLOW); | |
| 573 | + } | |
| 574 | + | |
| 575 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 576 | + if ( CheckPpsId( pCtx, &pPps, iPpsId ) ) | |
| 577 | + { | |
| 578 | + return dsNoParamSets; | |
| 579 | + } | |
| 580 | +#else | |
| 581 | + pPps = &pCtx->sPpsBuffer[iPpsId]; | |
| 582 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 583 | + | |
| 584 | + if (pPps->uiNumSliceGroups == 0){ | |
| 585 | + WelsLog( pCtx, WELS_LOG_WARNING, "non existing PPS referenced\n"); | |
| 586 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_NO_PARAM_SETS); | |
| 587 | + } | |
| 588 | + | |
| 589 | + if (pPps->iSpsId >= MAX_SPS_COUNT){ | |
| 590 | + WelsLog( pCtx, WELS_LOG_WARNING, "iSpsId out of range\n"); | |
| 591 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_SPS_ID_OVERFLOW); | |
| 592 | + } | |
| 593 | + | |
| 594 | + | |
| 595 | +#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 596 | + if ( CheckSpsId( pCtx, &pSubsetSps, &pSps, pPps->iSpsId, kExtensionFlag ) ) | |
| 597 | + { | |
| 598 | + return dsNoParamSets; | |
| 599 | + } | |
| 600 | +#else | |
| 601 | + if ( kbExtensionFlag ) | |
| 602 | + { | |
| 603 | + pSubsetSps = &pCtx->sSubsetSpsBuffer[pPps->iSpsId]; | |
| 604 | + pSps = &pSubsetSps->sSps; | |
| 605 | + } | |
| 606 | + else | |
| 607 | + { | |
| 608 | + pSps = &pCtx->sSpsBuffer[pPps->iSpsId]; | |
| 609 | + } | |
| 610 | + pCtx->pSps = pSps; | |
| 611 | +#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 612 | + pSliceHead->iPpsId = iPpsId; | |
| 613 | + pSliceHead->iSpsId = pPps->iSpsId; | |
| 614 | + pSliceHead->pPps = pPps; | |
| 615 | + pSliceHead->pSps = pSps; | |
| 616 | + | |
| 617 | + pSliceHeadExt->pSubsetSps = pSubsetSps; | |
| 618 | + | |
| 619 | + bIdrFlag = (!kbExtensionFlag && eNalType == NAL_UNIT_CODED_SLICE_IDR) || (kbExtensionFlag && pNalHeaderExt->bIdrFlag); | |
| 620 | + | |
| 621 | + if(pSps->uiLog2MaxFrameNum == 0){ | |
| 622 | + WelsLog( pCtx, WELS_LOG_WARNING, "non existing SPS referenced\n"); | |
| 623 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_NO_PARAM_SETS); | |
| 624 | + } | |
| 625 | + pSliceHead->iFrameNum = BsGetBits(pBs, pSps->uiLog2MaxFrameNum); | |
| 626 | + | |
| 627 | + pSliceHead->bFieldPicFlag = false; | |
| 628 | + pSliceHead->bBottomFiledFlag = false; | |
| 629 | + if( !pSps->bFrameMbsOnlyFlag ){ | |
| 630 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): frame_mbs_only_flag = %d not supported. \n", pSps->bFrameMbsOnlyFlag ); | |
| 631 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_MBAFF); | |
| 632 | + } | |
| 633 | + pSliceHead->iMbWidth = pSps->iMbWidth; | |
| 634 | + pSliceHead->iMbHeight = pSps->iMbHeight / (1 + pSliceHead->bFieldPicFlag); | |
| 635 | + | |
| 636 | + if ( bIdrFlag ){ | |
| 637 | + if ( pSliceHead->iFrameNum != 0 ){ | |
| 638 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(), invaild frame number: %d due to IDR frame introduced!\n", pSliceHead->iFrameNum); | |
| 639 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_FRAME_NUM); | |
| 640 | + } | |
| 641 | + pSliceHead->uiIdrPicId = BsGetUe(pBs); /* uiIdrPicId */ | |
| 642 | +#ifdef LONG_TERM_REF | |
| 643 | + pCtx->uiCurIdrPicId = pSliceHead->uiIdrPicId; | |
| 644 | +#endif | |
| 645 | + } | |
| 646 | + | |
| 647 | + pSliceHead->iDeltaPicOrderCntBottom = 0; | |
| 648 | + pSliceHead->iDeltaPicOrderCnt[0] = | |
| 649 | + pSliceHead->iDeltaPicOrderCnt[1] = 0; | |
| 650 | + if(pSps->uiPocType == 0){ | |
| 651 | + pSliceHead->iPicOrderCntLsb = BsGetBits(pBs, pSps->iLog2MaxPocLsb); | |
| 652 | + if( pPps->bPicOrderPresentFlag && !pSliceHead->bFieldPicFlag ){ | |
| 653 | + pSliceHead->iDeltaPicOrderCntBottom = BsGetSe(pBs); | |
| 654 | + } | |
| 655 | + } | |
| 656 | + else if(pSps->uiPocType == 1 && !pSps->bDeltaPicOrderAlwaysZeroFlag ){ | |
| 657 | + pSliceHead->iDeltaPicOrderCnt[0] = BsGetSe(pBs); | |
| 658 | + if( pPps->bPicOrderPresentFlag && !pSliceHead->bFieldPicFlag ) | |
| 659 | + pSliceHead->iDeltaPicOrderCnt[1]= BsGetSe(pBs); | |
| 660 | + } | |
| 661 | + | |
| 662 | + pSliceHead->iRedundantPicCnt = 0; | |
| 663 | + if( pPps->bRedundantPicCntPresentFlag ){ | |
| 664 | + pSliceHead->iRedundantPicCnt = BsGetUe(pBs); | |
| 665 | + } | |
| 666 | + | |
| 667 | + //set defaults, might be overriden a few line later | |
| 668 | + pSliceHead->uiRefCount[0] = pPps->uiNumRefIdxL0Active; | |
| 669 | + pSliceHead->uiRefCount[1] = pPps->uiNumRefIdxL1Active; | |
| 670 | + if ( kbExtensionFlag ){ | |
| 671 | + uiQualityId = pNalHeaderExt->uiQualityId; | |
| 672 | + if ( BASE_QUALITY_ID == uiQualityId && (EP_SLICE == uiSliceType || EB_SLICE == uiSliceType) ){ | |
| 673 | + const bool_t kbBipredFlag = (EB_SLICE == uiSliceType); | |
| 674 | + if ( kbBipredFlag ) | |
| 675 | + { | |
| 676 | + WelsLog ( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): kbBipredFlag = 1 not supported.\n"); | |
| 677 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_BIPRED); | |
| 678 | + } | |
| 679 | + pSliceHead->bNumRefIdxActiveOverrideFlag = !!BsGetOneBit(pBs); | |
| 680 | + if ( pSliceHead->bNumRefIdxActiveOverrideFlag ){ | |
| 681 | + pSliceHead->uiRefCount[0] = 1 + BsGetUe(pBs); | |
| 682 | + } | |
| 683 | + } | |
| 684 | + } | |
| 685 | + else if(uiSliceType == P_SLICE || uiSliceType == SP_SLICE || uiSliceType == B_SLICE){ | |
| 686 | + const bool_t kbBipredFlag = (B_SLICE == uiSliceType); | |
| 687 | + if( kbBipredFlag ){ | |
| 688 | + WelsLog ( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): kbBipredFlag = 1 not supported.\n"); | |
| 689 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_BIPRED); | |
| 690 | + } | |
| 691 | + pSliceHead->bNumRefIdxActiveOverrideFlag = !!BsGetOneBit(pBs); | |
| 692 | + if( pSliceHead->bNumRefIdxActiveOverrideFlag ){ | |
| 693 | + pSliceHead->uiRefCount[0] = 1 + BsGetUe(pBs); | |
| 694 | + } | |
| 695 | + } | |
| 696 | + | |
| 697 | + if( pSliceHead->uiRefCount[0] > MAX_REF_PIC_COUNT || pSliceHead->uiRefCount[1] > MAX_REF_PIC_COUNT){ | |
| 698 | + WelsLog( pCtx, WELS_LOG_WARNING, "reference overflow\n"); | |
| 699 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_REF_COUNT_OVERFLOW); | |
| 700 | + } | |
| 701 | + | |
| 702 | + if ( BASE_QUALITY_ID == uiQualityId ){ | |
| 703 | + iRet = ParseRefPicListReordering(pBs, pSliceHead); | |
| 704 | + if (iRet != ERR_NONE){ | |
| 705 | + WelsLog( pCtx, WELS_LOG_WARNING, "invalid ref pPic list reordering syntaxs!\n"); | |
| 706 | + return iRet; | |
| 707 | + } | |
| 708 | + | |
| 709 | + if ( kbExtensionFlag ){ | |
| 710 | + if ( pNalHeaderExt->iNoInterLayerPredFlag || pNalHeaderExt->uiQualityId > 0 ) | |
| 711 | + pSliceHeadExt->bBasePredWeightTableFlag = false; | |
| 712 | + else | |
| 713 | + pSliceHeadExt->bBasePredWeightTableFlag = true; | |
| 714 | + } | |
| 715 | + | |
| 716 | + if( kpCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc != 0 ){ | |
| 717 | + iRet = ParseDecRefPicMarking(pCtx, pBs, pSliceHead, pSps, bIdrFlag ); | |
| 718 | + if (iRet != ERR_NONE){ | |
| 719 | + return iRet; | |
| 720 | + } | |
| 721 | + | |
| 722 | + if ( kbExtensionFlag && !pSubsetSps->sSpsSvcExt.bSliceHeaderRestrictionFlag ){ | |
| 723 | + pSliceHeadExt->bStoreRefBasePicFlag = !!BsGetOneBit(pBs); | |
| 724 | + if ( (pNalHeaderExt->bUseRefBasePicFlag || pSliceHeadExt->bStoreRefBasePicFlag) && !bIdrFlag ){ | |
| 725 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): bUseRefBasePicFlag or bStoreRefBasePicFlag = 1 not supported.\n" ); | |
| 726 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP); | |
| 727 | + } | |
| 728 | + } | |
| 729 | + } | |
| 730 | + } | |
| 731 | + | |
| 732 | + if ( pPps->bEntropyCodingModeFlag ){ | |
| 733 | + WelsLog( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): CABAC in Enhancement layer not supported.\n" ); | |
| 734 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_CABAC_EL); | |
| 735 | + } | |
| 736 | + | |
| 737 | + pSliceHead->iSliceQpDelta = BsGetSe(pBs); | |
| 738 | + pSliceHead->iSliceQp = pPps->iPicInitQp + pSliceHead->iSliceQpDelta; | |
| 739 | + if( pSliceHead->iSliceQp < 0 || pSliceHead->iSliceQp > 51 ){ | |
| 740 | + WelsLog( pCtx, WELS_LOG_WARNING, "QP %d out of range\n", pSliceHead->iSliceQp); | |
| 741 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_QP); | |
| 742 | + } | |
| 743 | + | |
| 744 | + //FIXME qscale / qp ... stuff | |
| 745 | + if ( !kbExtensionFlag ){ | |
| 746 | + if( uiSliceType == SP_SLICE || uiSliceType == SI_SLICE ) | |
| 747 | + { | |
| 748 | + WelsLog( pCtx, WELS_LOG_WARNING, "SP/SI not supported\n"); | |
| 749 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_SPSI); | |
| 750 | + } | |
| 751 | + } | |
| 752 | + | |
| 753 | + pSliceHead->uiDisableDeblockingFilterIdc = 0; | |
| 754 | + pSliceHead->iSliceAlphaC0Offset = 0; | |
| 755 | + pSliceHead->iSliceBetaOffset = 0; | |
| 756 | + if ( pPps->bDeblockingFilterControlPresentFlag ){ | |
| 757 | + pSliceHead->uiDisableDeblockingFilterIdc = BsGetUe(pBs); | |
| 758 | + //refer to JVT-X201wcm1.doc G.7.4.3.4--2010.4.20 | |
| 759 | + if ( pSliceHead->uiDisableDeblockingFilterIdc > 6 ) | |
| 760 | + { | |
| 761 | + WelsLog( pCtx, WELS_LOG_WARNING, "disable_deblock_filter_idc (%d) out of range [0, 6]\n", pSliceHead->uiDisableDeblockingFilterIdc ); | |
| 762 | + return ERR_INFO_INVALID_DBLOCKING_IDC; | |
| 763 | + } | |
| 764 | + if (pSliceHead->uiDisableDeblockingFilterIdc != 1){ | |
| 765 | + pSliceHead->iSliceAlphaC0Offset = BsGetSe(pBs) << 1; // slice_alpha_c0_offset_div2 | |
| 766 | + pSliceHead->iSliceBetaOffset = BsGetSe(pBs) << 1; // iSliceBetaOffset | |
| 767 | + } | |
| 768 | + } | |
| 769 | + | |
| 770 | + bSgChangeCycleInvolved = (pPps->uiNumSliceGroups > 1 && pPps->uiSliceGroupMapType >= 3 && pPps->uiSliceGroupMapType <= 5); | |
| 771 | + if ( kbExtensionFlag && bSgChangeCycleInvolved ) | |
| 772 | + bSgChangeCycleInvolved= (bSgChangeCycleInvolved && (uiQualityId == BASE_QUALITY_ID)); | |
| 773 | + if ( bSgChangeCycleInvolved ){ | |
| 774 | + if ( pPps->uiSliceGroupChangeRate > 0 ){ | |
| 775 | + const int32_t kiNumBits = (int32_t)WELS_CEIL(log(static_cast<double>(1 + pPps->uiPicSizeInMapUnits / pPps->uiSliceGroupChangeRate))); | |
| 776 | + pSliceHead->iSliceGroupChangeCycle = BsGetBits(pBs, kiNumBits); // For FMO extra types | |
| 777 | + } | |
| 778 | + else | |
| 779 | + pSliceHead->iSliceGroupChangeCycle = 0; | |
| 780 | + } | |
| 781 | + | |
| 782 | + if ( !kbExtensionFlag ){ | |
| 783 | + FillDefaultSliceHeaderExt ( pSliceHeadExt, pNalHeaderExt ); | |
| 784 | + } | |
| 785 | + else{ | |
| 786 | + /* Extra syntax elements newly introduced */ | |
| 787 | + pSliceHeadExt->pSubsetSps = pSubsetSps; | |
| 788 | + | |
| 789 | + if ( !pNalHeaderExt->iNoInterLayerPredFlag && BASE_QUALITY_ID == uiQualityId ){ | |
| 790 | + //the following should be deleted for CODE_CLEAN | |
| 791 | + pSliceHeadExt->uiRefLayerDqId = BsGetUe(pBs); | |
| 792 | + if ( pSubsetSps->sSpsSvcExt.bInterLayerDeblockingFilterCtrlPresentFlag ) | |
| 793 | + { | |
| 794 | + pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc = BsGetUe(pBs); | |
| 795 | + //refer to JVT-X201wcm1.doc G.7.4.3.4--2010.4.20 | |
| 796 | + if ( pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc > 6 ) | |
| 797 | + { | |
| 798 | + WelsLog( pCtx, WELS_LOG_WARNING, "disable_inter_layer_deblock_filter_idc (%d) out of range [0, 6]\n", pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc ); | |
| 799 | + return ERR_INFO_INVALID_DBLOCKING_IDC; | |
| 800 | + } | |
| 801 | + if ( pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc != 1 ){ | |
| 802 | + pSliceHeadExt->iInterLayerSliceAlphaC0Offset = BsGetSe(pBs) << 1; | |
| 803 | + pSliceHeadExt->iInterLayerSliceBetaOffset = BsGetSe(pBs) << 1; | |
| 804 | + } | |
| 805 | + } | |
| 806 | + | |
| 807 | + pSliceHeadExt->uiRefLayerChromaPhaseXPlus1Flag = pSubsetSps->sSpsSvcExt.uiSeqRefLayerChromaPhaseXPlus1Flag; | |
| 808 | + pSliceHeadExt->uiRefLayerChromaPhaseYPlus1 = pSubsetSps->sSpsSvcExt.uiSeqRefLayerChromaPhaseYPlus1; | |
| 809 | + | |
| 810 | + pSliceHeadExt->bConstrainedIntraResamplingFlag = !!BsGetOneBit(pBs); | |
| 811 | + | |
| 812 | + { | |
| 813 | + SPosOffset pos; | |
| 814 | + pos.iLeftOffset = pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iLeftOffset; | |
| 815 | + pos.iTopOffset = pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iTopOffset * (2 - pSps->bFrameMbsOnlyFlag); | |
| 816 | + pos.iRightOffset= pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iRightOffset; | |
| 817 | + pos.iBottomOffset=pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iBottomOffset * (2 - pSps->bFrameMbsOnlyFlag); | |
| 818 | + //memcpy(&pSliceHeadExt->sScaledRefLayer, &pos, sizeof(SPosOffset));//confirmed_safe_unsafe_usage | |
| 819 | + pSliceHeadExt->iScaledRefLayerPicWidthInSampleLuma = (pSliceHead->iMbWidth << 4) - (pos.iLeftOffset+pos.iRightOffset); | |
| 820 | + pSliceHeadExt->iScaledRefLayerPicHeightInSampleLuma = (pSliceHead->iMbHeight << 4) - (pos.iTopOffset+pos.iBottomOffset) / (1 + pSliceHead->bFieldPicFlag); | |
| 821 | + } | |
| 822 | + } | |
| 823 | + else if (uiQualityId > BASE_QUALITY_ID){ | |
| 824 | + WelsLog( pCtx, WELS_LOG_WARNING, "MGS not supported.\n" ); | |
| 825 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_MGS); | |
| 826 | + pSliceHeadExt->uiRefLayerDqId = pNalHeaderExt->uiLayerDqId - 1; | |
| 827 | + } | |
| 828 | + else{ | |
| 829 | + pSliceHeadExt->uiRefLayerDqId = (uint8_t)-1; | |
| 830 | + } | |
| 831 | + | |
| 832 | + pSliceHeadExt->bSliceSkipFlag = false; | |
| 833 | + pSliceHeadExt->bAdaptiveBaseModeFlag = false; | |
| 834 | + pSliceHeadExt->bDefaultBaseModeFlag = false; | |
| 835 | + pSliceHeadExt->bAdaptiveMotionPredFlag = false; | |
| 836 | + pSliceHeadExt->bDefaultMotionPredFlag = false; | |
| 837 | + pSliceHeadExt->bAdaptiveResidualPredFlag = false; | |
| 838 | + pSliceHeadExt->bDefaultResidualPredFlag = false; | |
| 839 | + if ( pNalHeaderExt->iNoInterLayerPredFlag ) | |
| 840 | + pSliceHeadExt->bTCoeffLevelPredFlag = false; | |
| 841 | + else | |
| 842 | + pSliceHeadExt->bTCoeffLevelPredFlag = pSubsetSps->sSpsSvcExt.bSeqTCoeffLevelPredFlag; | |
| 843 | + | |
| 844 | + if ( !pNalHeaderExt->iNoInterLayerPredFlag ){ | |
| 845 | + pSliceHeadExt->bSliceSkipFlag = !!BsGetOneBit(pBs); | |
| 846 | + if ( pSliceHeadExt->bSliceSkipFlag ){ | |
| 847 | + pSliceHeadExt->uiNumMbsInSlice = 1 + BsGetUe(pBs); | |
| 848 | + } | |
| 849 | + else{ | |
| 850 | + pSliceHeadExt->bAdaptiveBaseModeFlag = !!BsGetOneBit(pBs); | |
| 851 | + if ( !pSliceHeadExt->bAdaptiveBaseModeFlag ){ | |
| 852 | + pSliceHeadExt->bDefaultBaseModeFlag = !!BsGetOneBit(pBs); | |
| 853 | + } | |
| 854 | + if ( !pSliceHeadExt->bDefaultBaseModeFlag ){ | |
| 855 | + pSliceHeadExt->bAdaptiveMotionPredFlag = !!BsGetOneBit(pBs); | |
| 856 | + if ( !pSliceHeadExt->bAdaptiveMotionPredFlag ) | |
| 857 | + pSliceHeadExt->bDefaultMotionPredFlag = !!BsGetOneBit(pBs); | |
| 858 | + } | |
| 859 | + | |
| 860 | + pSliceHeadExt->bAdaptiveResidualPredFlag = !!BsGetOneBit(pBs); | |
| 861 | + if ( !pSliceHeadExt->bAdaptiveResidualPredFlag ){ | |
| 862 | + pSliceHeadExt->bDefaultResidualPredFlag = !!BsGetOneBit(pBs); | |
| 863 | + } | |
| 864 | + } | |
| 865 | + if ( pSubsetSps->sSpsSvcExt.bAdaptiveTCoeffLevelPredFlag ) | |
| 866 | + pSliceHeadExt->bTCoeffLevelPredFlag = !!BsGetOneBit(pBs); | |
| 867 | + } | |
| 868 | + | |
| 869 | + if ( !pSubsetSps->sSpsSvcExt.bSliceHeaderRestrictionFlag ) | |
| 870 | + { | |
| 871 | + pSliceHeadExt->uiScanIdxStart = BsGetBits(pBs, 4); | |
| 872 | + pSliceHeadExt->uiScanIdxEnd = BsGetBits(pBs, 4); | |
| 873 | + if( pSliceHeadExt->uiScanIdxStart != 0 || pSliceHeadExt->uiScanIdxEnd != 15 ) | |
| 874 | + { | |
| 875 | + WelsLog( pCtx, WELS_LOG_WARNING, "uiScanIdxStart (%d) != 0 and uiScanIdxEnd (%d) !=15 not supported here\n", pSliceHeadExt->uiScanIdxStart, pSliceHeadExt->uiScanIdxEnd ); | |
| 876 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_MGS); | |
| 877 | + } | |
| 878 | + } | |
| 879 | + else{ | |
| 880 | + pSliceHeadExt->uiScanIdxStart = 0; | |
| 881 | + pSliceHeadExt->uiScanIdxEnd = 15; | |
| 882 | + } | |
| 883 | + } | |
| 884 | + | |
| 885 | + return ERR_NONE; | |
| 886 | +} | |
| 887 | + | |
| 888 | +/* | |
| 889 | + * Copy relative syntax elements of NALUnitHeaderExt, sRefPicBaseMarking and bStoreRefBasePicFlag in prefix nal unit. | |
| 890 | + * pSrc: mark as decoded prefix NAL | |
| 891 | + * ppDst: succeeded VCL NAL based AVC (I/P Slice) | |
| 892 | + */ | |
| 893 | +bool_t PrefetchNalHeaderExtSyntax ( PWelsDecoderContext pCtx, PNalUnit const kppDst, PNalUnit const kpSrc) | |
| 894 | +{ | |
| 895 | + PNalUnitHeaderExt pNalHdrExtD = NULL, pNalHdrExtS = NULL; | |
| 896 | + PSliceHeaderExt pShExtD = NULL; | |
| 897 | + PPrefixNalUnit pPrefixS = NULL; | |
| 898 | + PSps pSps = NULL; | |
| 899 | + int32_t iIdx = 0; | |
| 900 | + | |
| 901 | + if ( kppDst == NULL || kpSrc == NULL ) | |
| 902 | + return false; | |
| 903 | + | |
| 904 | + pNalHdrExtD = &kppDst->sNalHeaderExt; | |
| 905 | + pNalHdrExtS = &kpSrc->sNalHeaderExt; | |
| 906 | + pShExtD = &kppDst->sNalData.sVclNal.sSliceHeaderExt; | |
| 907 | + pPrefixS = &kpSrc->sNalData.sPrefixNal; | |
| 908 | + pSps = &pCtx->sSpsBuffer[pCtx->sPpsBuffer[pShExtD->sSliceHeader.iPpsId].iSpsId]; | |
| 909 | + | |
| 910 | + pNalHdrExtD->uiDependencyId = pNalHdrExtS->uiDependencyId; | |
| 911 | + pNalHdrExtD->uiQualityId = pNalHdrExtS->uiQualityId; | |
| 912 | + pNalHdrExtD->uiTemporalId = pNalHdrExtS->uiTemporalId; | |
| 913 | + pNalHdrExtD->uiPriorityId = pNalHdrExtS->uiPriorityId; | |
| 914 | + pNalHdrExtD->bIdrFlag = pNalHdrExtS->bIdrFlag; | |
| 915 | + pNalHdrExtD->iNoInterLayerPredFlag = pNalHdrExtS->iNoInterLayerPredFlag; | |
| 916 | + pNalHdrExtD->bDiscardableFlag = pNalHdrExtS->bDiscardableFlag; | |
| 917 | + pNalHdrExtD->bOutputFlag = pNalHdrExtS->bOutputFlag; | |
| 918 | + pNalHdrExtD->bUseRefBasePicFlag = pNalHdrExtS->bUseRefBasePicFlag; | |
| 919 | + pNalHdrExtD->uiLayerDqId = pNalHdrExtS->uiLayerDqId; | |
| 920 | + | |
| 921 | + pShExtD->bStoreRefBasePicFlag = pPrefixS->bStoreRefBasePicFlag; | |
| 922 | + memcpy(&pShExtD->sRefBasePicMarking, &pPrefixS->sRefPicBaseMarking, sizeof(SRefBasePicMarking));//confirmed_safe_unsafe_usage | |
| 923 | + if (pShExtD->sRefBasePicMarking.bAdaptiveRefBasePicMarkingModeFlag){ | |
| 924 | + PRefBasePicMarking pRefBasePicMarking = &pShExtD->sRefBasePicMarking; | |
| 925 | + iIdx = 0; | |
| 926 | + do { | |
| 927 | + if (pRefBasePicMarking->mmco_base[iIdx].uiMmcoType == MMCO_END) | |
| 928 | + break; | |
| 929 | + if (pRefBasePicMarking->mmco_base[iIdx].uiMmcoType == MMCO_SHORT2UNUSED) | |
| 930 | + pRefBasePicMarking->mmco_base[iIdx].iShortFrameNum = (pShExtD->sSliceHeader.iFrameNum-pRefBasePicMarking->mmco_base[iIdx].uiDiffOfPicNums) & ((1<<pSps->uiLog2MaxFrameNum)-1); | |
| 931 | + ++ iIdx; | |
| 932 | + } while(iIdx < MAX_MMCO_COUNT); | |
| 933 | + } | |
| 934 | + | |
| 935 | + return true; | |
| 936 | +} | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | +int32_t UpdateAccessUnit ( PWelsDecoderContext pCtx ) | |
| 941 | +{ | |
| 942 | + PAccessUnit pCurAu = pCtx->pAccessUnitList; | |
| 943 | + int32_t iIdx = pCurAu->uiEndPos; | |
| 944 | + | |
| 945 | + // Conversed iterator | |
| 946 | + pCtx->uiTargetDqId = pCurAu->pNalUnitsList[iIdx]->sNalHeaderExt.uiLayerDqId; | |
| 947 | + pCurAu->uiActualUnitsNum = iIdx + 1; | |
| 948 | + pCurAu->bCompletedAuFlag = true; | |
| 949 | + | |
| 950 | + // Added for mosaic avoidance, 11/19/2009 | |
| 951 | +#ifdef LONG_TERM_REF | |
| 952 | + if ( pCtx->bParamSetsLostFlag ) | |
| 953 | +#else | |
| 954 | + if ( pCtx->bReferenceLostAtT0Flag ) | |
| 955 | +#endif | |
| 956 | + { | |
| 957 | + uint32_t uiActualIdx = 0; | |
| 958 | + while ( uiActualIdx < pCurAu->uiActualUnitsNum ) { | |
| 959 | + PNalUnit nal = pCurAu->pNalUnitsList[uiActualIdx]; | |
| 960 | + | |
| 961 | + if ( nal->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR || nal->sNalHeaderExt.bIdrFlag ) | |
| 962 | + { | |
| 963 | + break; | |
| 964 | + } | |
| 965 | + ++ uiActualIdx; | |
| 966 | + } | |
| 967 | + if ( uiActualIdx == pCurAu->uiActualUnitsNum ) // no found IDR nal within incoming AU, need exit to avoid mosaic issue, 11/19/2009 | |
| 968 | + { | |
| 969 | + WelsLog( pCtx, WELS_LOG_WARNING, "UpdateAccessUnit():::::Key frame lost.....CAN NOT find IDR from current AU.\n" ); | |
| 970 | +#ifdef LONG_TERM_REF | |
| 971 | + pCtx->iErrorCode |= dsNoParamSets; | |
| 972 | + return dsNoParamSets; | |
| 973 | +#else | |
| 974 | + pCtx->iErrorCode |= dsRefLost; | |
| 975 | + return ERR_INFO_REFERENCE_PIC_LOST; | |
| 976 | +#endif | |
| 977 | + } | |
| 978 | + } | |
| 979 | + | |
| 980 | + return ERR_NONE; | |
| 981 | +} | |
| 982 | + | |
| 983 | +int32_t InitialDqLayersContext ( PWelsDecoderContext pCtx, const int32_t kiMaxWidth, const int32_t kiMaxHeight ) | |
| 984 | +{ | |
| 985 | + const int32_t kiPicStride = ((kiMaxWidth + 15) & 0xfffff0) + (PADDING_LENGTH<<1); | |
| 986 | + const int32_t kiPicLines = ((kiMaxHeight + 15) & 0xfffff0); | |
| 987 | + | |
| 988 | + int32_t i = 0; | |
| 989 | + | |
| 990 | + WELS_VERIFY_RETURN_IF( ERR_INFO_INVALID_PARAM, ( NULL == pCtx || kiMaxWidth <= 0 || kiMaxHeight <= 0 ) ) | |
| 991 | + pCtx->sMb.iMbWidth = (kiMaxWidth + 15) >> 4; | |
| 992 | + pCtx->sMb.iMbHeight = (kiMaxHeight + 15) >> 4; | |
| 993 | + | |
| 994 | + if ( pCtx->bInitialDqLayersMem && kiMaxWidth <= pCtx->iPicWidthReq && kiMaxHeight <= pCtx->iPicHeightReq ) // have same dimension memory, skipped | |
| 995 | + return ERR_NONE; | |
| 996 | + | |
| 997 | + | |
| 998 | + UninitialDqLayersContext( pCtx ); | |
| 999 | + | |
| 1000 | + do { | |
| 1001 | + PDqLayer pDq = (PDqLayer )WelsMalloc(sizeof(SDqLayer), "PDqLayer"); | |
| 1002 | + | |
| 1003 | + int32_t iPlaneIdx = 0; | |
| 1004 | + | |
| 1005 | + if ( pDq == NULL ) | |
| 1006 | + return ERR_INFO_OUT_OF_MEMORY; | |
| 1007 | + | |
| 1008 | + memset(pDq, 0, sizeof(SDqLayer)); | |
| 1009 | + if(pCtx->iDecoderMode == SW_MODE) | |
| 1010 | + { | |
| 1011 | + | |
| 1012 | + do { | |
| 1013 | + const int32_t kiHshift = iPlaneIdx ? 1 : 0; | |
| 1014 | + const int32_t kiVshift = kiHshift; | |
| 1015 | + const int32_t kiStride = WELS_ALIGN( (kiPicStride >> kiHshift), (16 << (1-kiHshift)) ); | |
| 1016 | + const int32_t kiLine = (kiPicLines + (PADDING_LENGTH<<1)) >> kiVshift; | |
| 1017 | + const int32_t kiSize = kiStride * kiLine; | |
| 1018 | + | |
| 1019 | + pCtx->pCsListXchg[i][iPlaneIdx] = (uint8_t *)WelsMalloc( kiSize * sizeof(uint8_t), "pCtx->pCsListXchg[][]" ); | |
| 1020 | + | |
| 1021 | + WELS_VERIFY_RETURN_IF( ERR_INFO_OUT_OF_MEMORY, (NULL == pCtx->pCsListXchg[i][iPlaneIdx]) ) | |
| 1022 | + pCtx->iCsStride[iPlaneIdx] = kiStride; | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + pCtx->pRsListXchg[i][iPlaneIdx] = (int16_t *)WelsMalloc( kiSize * sizeof(int16_t), "pCtx->pRsListXchg[][]" ); | |
| 1026 | + | |
| 1027 | + WELS_VERIFY_RETURN_IF( ERR_INFO_OUT_OF_MEMORY , (NULL == pCtx->pRsListXchg[i][iPlaneIdx]) ) | |
| 1028 | + pCtx->iRsStride[iPlaneIdx] = kiStride; | |
| 1029 | + | |
| 1030 | + ++ iPlaneIdx; | |
| 1031 | + } while(iPlaneIdx < 3); | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + pCtx->sMb.pMbType[i] = (int8_t *)WelsMalloc( pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight *sizeof(int8_t), "pCtx->sMb.pMbType[]" ); | |
| 1035 | + pCtx->sMb.pMv[i][0] = (int16_t (*)[16][2])WelsMalloc( pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int16_t) * MV_A * MB_BLOCK4x4_NUM, "pCtx->sMb.pMv[][]"); | |
| 1036 | + pCtx->sMb.pRefIndex[i][0] = (int8_t (*)[MB_BLOCK4x4_NUM])WelsMalloc( pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * MB_BLOCK4x4_NUM, "pCtx->sMb.pRefIndex[][]"); | |
| 1037 | + pCtx->sMb.pLumaQp[i] = (int8_t *)WelsMalloc( pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pLumaQp[]"); | |
| 1038 | + pCtx->sMb.pChromaQp[i] = (int8_t *)WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pChromaQp[]"); | |
| 1039 | + pCtx->sMb.pNzc[i] = (int8_t (*)[24])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * 24, "pCtx->sMb.pNzc[]"); | |
| 1040 | + pCtx->sMb.pNzcRs[i] = (int8_t (*)[24])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * 24, "pCtx->sMb.pNzcRs[]"); | |
| 1041 | + pCtx->sMb.pScaledTCoeff[i] = (int16_t (*)[MB_COEFF_LIST_SIZE])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int16_t) * MB_COEFF_LIST_SIZE, "pCtx->sMb.pScaledTCoeff[]"); | |
| 1042 | + pCtx->sMb.pIntraPredMode[i] = (int8_t (*)[8])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * 8, "pCtx->sMb.pIntraPredMode[]"); | |
| 1043 | + pCtx->sMb.pIntra4x4FinalMode[i] = (int8_t (*)[MB_BLOCK4x4_NUM])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * MB_BLOCK4x4_NUM, "pCtx->sMb.pIntra4x4FinalMode[]"); | |
| 1044 | + pCtx->sMb.pChromaPredMode[i] = (int8_t *)WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pChromaPredMode[]"); | |
| 1045 | + pCtx->sMb.pCbp[i] = (int8_t *)WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight *sizeof(int8_t), "pCtx->sMb.pCbp[]"); | |
| 1046 | + pCtx->sMb.pSubMbType[i] = (int8_t (*)[MB_PARTITION_SIZE])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * MB_PARTITION_SIZE, "pCtx->sMb.pSubMbType[]"); | |
| 1047 | + pCtx->sMb.pSliceIdc[i] = (int32_t *) WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int32_t), "pCtx->sMb.pSliceIdc[]"); // using int32_t for slice_idc, 4/21/2010 | |
| 1048 | + if ( pCtx->sMb.pSliceIdc[i] != NULL ) | |
| 1049 | + memset(pCtx->sMb.pSliceIdc[i], 0xff, (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int32_t)) ); | |
| 1050 | + pCtx->sMb.pResidualPredFlag[i] = (int8_t *) WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pResidualPredFlag[]"); | |
| 1051 | + //pCtx->sMb.pMotionPredFlag[i] = (uint8_t *) WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(uint8_t), "pCtx->sMb.pMotionPredFlag[]"); | |
| 1052 | + pCtx->sMb.pInterPredictionDoneFlag[i] = (int8_t *) WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pInterPredictionDoneFlag[]"); | |
| 1053 | + | |
| 1054 | + // check memory block valid due above allocated.. | |
| 1055 | + WELS_VERIFY_RETURN_IF ( ERR_INFO_OUT_OF_MEMORY, | |
| 1056 | + ( (NULL == pCtx->sMb.pMbType[i]) || | |
| 1057 | + (NULL == pCtx->sMb.pMv[i][0]) || | |
| 1058 | + (NULL == pCtx->sMb.pRefIndex[i][0]) || | |
| 1059 | + (NULL == pCtx->sMb.pLumaQp[i]) || | |
| 1060 | + (NULL == pCtx->sMb.pChromaQp[i]) || | |
| 1061 | + (NULL == pCtx->sMb.pNzc[i]) || | |
| 1062 | + (NULL == pCtx->sMb.pNzcRs[i]) || | |
| 1063 | + (NULL == pCtx->sMb.pScaledTCoeff[i]) || | |
| 1064 | + (NULL == pCtx->sMb.pIntraPredMode[i]) || | |
| 1065 | + (NULL == pCtx->sMb.pIntra4x4FinalMode[i]) || | |
| 1066 | + (NULL == pCtx->sMb.pChromaPredMode[i]) || | |
| 1067 | + (NULL == pCtx->sMb.pCbp[i]) || | |
| 1068 | + (NULL == pCtx->sMb.pSubMbType[i]) || | |
| 1069 | + (NULL == pCtx->sMb.pSliceIdc[i]) || | |
| 1070 | + (NULL == pCtx->sMb.pResidualPredFlag[i]) || | |
| 1071 | + (NULL == pCtx->sMb.pInterPredictionDoneFlag[i]) | |
| 1072 | + ) | |
| 1073 | + ) | |
| 1074 | + } // end of if(pCtx->iDecoderMode == SW_MODE) | |
| 1075 | + | |
| 1076 | + pCtx->pDqLayersList[i] = pDq; | |
| 1077 | + ++ i; | |
| 1078 | + } while( i < LAYER_NUM_EXCHANGEABLE ); | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + pCtx->bInitialDqLayersMem = true; | |
| 1082 | + pCtx->iPicWidthReq = kiMaxWidth; | |
| 1083 | + pCtx->iPicHeightReq = kiMaxHeight; | |
| 1084 | + | |
| 1085 | + return ERR_NONE; | |
| 1086 | +} | |
| 1087 | + | |
| 1088 | +void_t UninitialDqLayersContext ( PWelsDecoderContext pCtx ) | |
| 1089 | +{ | |
| 1090 | + int32_t i = 0; | |
| 1091 | + int32_t j = 0; | |
| 1092 | + | |
| 1093 | + do { | |
| 1094 | + PDqLayer pDq = pCtx->pDqLayersList[i]; | |
| 1095 | + if ( pDq == NULL ){ | |
| 1096 | + ++ i; | |
| 1097 | + continue; | |
| 1098 | + } | |
| 1099 | + | |
| 1100 | + if ( pCtx->pCsListXchg[i] ){ // cs picture | |
| 1101 | + j = 0; | |
| 1102 | + do { | |
| 1103 | + if ( NULL != pCtx->pCsListXchg[i][j] ) | |
| 1104 | + { | |
| 1105 | + WelsFree( pCtx->pCsListXchg[i][j], "pCtx->pCsListXchg[][]" ); | |
| 1106 | + | |
| 1107 | + pCtx->pCsListXchg[i][j] = NULL; | |
| 1108 | + } | |
| 1109 | + pCtx->iCsStride[j] = 0; | |
| 1110 | + ++ j; | |
| 1111 | + } while( j < 3 ); | |
| 1112 | + | |
| 1113 | + pDq->pCsData[i] = NULL; // for safe | |
| 1114 | + pDq->iCsStride[i] = 0; | |
| 1115 | + } | |
| 1116 | + if ( pCtx->pRsListXchg[i] ){ | |
| 1117 | + j = 0; | |
| 1118 | + do { | |
| 1119 | + if ( NULL != pCtx->pRsListXchg[i][j] ) | |
| 1120 | + { | |
| 1121 | + WelsFree( pCtx->pRsListXchg[i][j], "pCtx->pRsListXchg[][]" ); | |
| 1122 | + | |
| 1123 | + pCtx->pRsListXchg[i][j] = NULL; | |
| 1124 | + } | |
| 1125 | + pCtx->iRsStride[j] = 0; | |
| 1126 | + ++ j; | |
| 1127 | + } while(j < 3); | |
| 1128 | + } | |
| 1129 | + | |
| 1130 | + if (pCtx->sMb.pMbType[i]) | |
| 1131 | + { | |
| 1132 | + WelsFree( pCtx->sMb.pMbType[i], "pCtx->sMb.pMbType[]"); | |
| 1133 | + | |
| 1134 | + pCtx->sMb.pMbType[i] = NULL; | |
| 1135 | + } | |
| 1136 | + | |
| 1137 | + if (pCtx->sMb.pMv[i][0]) | |
| 1138 | + { | |
| 1139 | + WelsFree( pCtx->sMb.pMv[i][0], "pCtx->sMb.pMv[][]" ); | |
| 1140 | + | |
| 1141 | + pCtx->sMb.pMv[i][0] = NULL; | |
| 1142 | + } | |
| 1143 | + | |
| 1144 | + if (pCtx->sMb.pRefIndex[i][0]) | |
| 1145 | + { | |
| 1146 | + WelsFree( pCtx->sMb.pRefIndex[i][0], "pCtx->sMb.pRefIndex[][]" ); | |
| 1147 | + | |
| 1148 | + pCtx->sMb.pRefIndex[i][0] = NULL; | |
| 1149 | + } | |
| 1150 | + | |
| 1151 | + if (pCtx->sMb.pLumaQp[i]) | |
| 1152 | + { | |
| 1153 | + WelsFree(pCtx->sMb.pLumaQp[i], "pCtx->sMb.pLumaQp[]"); | |
| 1154 | + | |
| 1155 | + pCtx->sMb.pLumaQp[i] = NULL; | |
| 1156 | + } | |
| 1157 | + | |
| 1158 | + if (pCtx->sMb.pChromaQp[i]) | |
| 1159 | + { | |
| 1160 | + WelsFree(pCtx->sMb.pChromaQp[i], "pCtx->sMb.pChromaQp[]"); | |
| 1161 | + | |
| 1162 | + pCtx->sMb.pChromaQp[i] = NULL; | |
| 1163 | + } | |
| 1164 | + | |
| 1165 | + if (pCtx->sMb.pNzc[i]) | |
| 1166 | + { | |
| 1167 | + WelsFree(pCtx->sMb.pNzc[i], "pCtx->sMb.pNzc[]"); | |
| 1168 | + | |
| 1169 | + pCtx->sMb.pNzc[i] = NULL; | |
| 1170 | + } | |
| 1171 | + | |
| 1172 | + if (pCtx->sMb.pNzcRs[i]) | |
| 1173 | + { | |
| 1174 | + WelsFree(pCtx->sMb.pNzcRs[i], "pCtx->sMb.pNzcRs[]"); | |
| 1175 | + | |
| 1176 | + pCtx->sMb.pNzcRs[i] = NULL; | |
| 1177 | + } | |
| 1178 | + | |
| 1179 | + if (pCtx->sMb.pScaledTCoeff[i]) | |
| 1180 | + { | |
| 1181 | + WelsFree(pCtx->sMb.pScaledTCoeff[i], "pCtx->sMb.pScaledTCoeff[]"); | |
| 1182 | + | |
| 1183 | + pCtx->sMb.pScaledTCoeff[i] = NULL; | |
| 1184 | + } | |
| 1185 | + | |
| 1186 | + if (pCtx->sMb.pIntraPredMode[i]) | |
| 1187 | + { | |
| 1188 | + WelsFree(pCtx->sMb.pIntraPredMode[i], "pCtx->sMb.pIntraPredMode[]"); | |
| 1189 | + | |
| 1190 | + pCtx->sMb.pIntraPredMode[i] = NULL; | |
| 1191 | + } | |
| 1192 | + | |
| 1193 | + if (pCtx->sMb.pIntra4x4FinalMode[i]) | |
| 1194 | + { | |
| 1195 | + WelsFree(pCtx->sMb.pIntra4x4FinalMode[i], "pCtx->sMb.pIntra4x4FinalMode[]"); | |
| 1196 | + | |
| 1197 | + pCtx->sMb.pIntra4x4FinalMode[i] = NULL; | |
| 1198 | + } | |
| 1199 | + | |
| 1200 | + if (pCtx->sMb.pChromaPredMode[i]) | |
| 1201 | + { | |
| 1202 | + WelsFree(pCtx->sMb.pChromaPredMode[i], "pCtx->sMb.pChromaPredMode[]"); | |
| 1203 | + | |
| 1204 | + pCtx->sMb.pChromaPredMode[i] = NULL; | |
| 1205 | + } | |
| 1206 | + | |
| 1207 | + if (pCtx->sMb.pCbp[i]) | |
| 1208 | + { | |
| 1209 | + WelsFree( pCtx->sMb.pCbp[i], "pCtx->sMb.pCbp[]" ); | |
| 1210 | + | |
| 1211 | + pCtx->sMb.pCbp[i] = NULL; | |
| 1212 | + } | |
| 1213 | + | |
| 1214 | + // if (pCtx->sMb.pMotionPredFlag[i]) | |
| 1215 | + //{ | |
| 1216 | + // WelsFree( pCtx->sMb.pMotionPredFlag[i], "pCtx->sMb.pMotionPredFlag[]" ); | |
| 1217 | + | |
| 1218 | + // pCtx->sMb.pMotionPredFlag[i] = NULL; | |
| 1219 | + //} | |
| 1220 | + | |
| 1221 | + if (pCtx->sMb.pSubMbType[i]) | |
| 1222 | + { | |
| 1223 | + WelsFree(pCtx->sMb.pSubMbType[i], "pCtx->sMb.pSubMbType[]"); | |
| 1224 | + | |
| 1225 | + pCtx->sMb.pSubMbType[i] = NULL; | |
| 1226 | + } | |
| 1227 | + | |
| 1228 | + if (pCtx->sMb.pSliceIdc[i]) | |
| 1229 | + { | |
| 1230 | + WelsFree( pCtx->sMb.pSliceIdc[i], "pCtx->sMb.pSliceIdc[]" ); | |
| 1231 | + | |
| 1232 | + pCtx->sMb.pSliceIdc[i] = NULL; | |
| 1233 | + } | |
| 1234 | + | |
| 1235 | + if (pCtx->sMb.pResidualPredFlag[i]) | |
| 1236 | + { | |
| 1237 | + WelsFree( pCtx->sMb.pResidualPredFlag[i], "pCtx->sMb.pResidualPredFlag[]" ); | |
| 1238 | + | |
| 1239 | + pCtx->sMb.pResidualPredFlag[i] = NULL; | |
| 1240 | + } | |
| 1241 | + | |
| 1242 | + if (pCtx->sMb.pInterPredictionDoneFlag[i]) | |
| 1243 | + { | |
| 1244 | + WelsFree( pCtx->sMb.pInterPredictionDoneFlag[i], "pCtx->sMb.pInterPredictionDoneFlag[]" ); | |
| 1245 | + | |
| 1246 | + pCtx->sMb.pInterPredictionDoneFlag[i] = NULL; | |
| 1247 | + } | |
| 1248 | + WelsFree( pDq, "pDq" ); | |
| 1249 | + | |
| 1250 | + pDq = NULL; | |
| 1251 | + pCtx->pDqLayersList[i] = NULL; | |
| 1252 | + | |
| 1253 | + ++ i; | |
| 1254 | + } while( i < LAYER_NUM_EXCHANGEABLE ); | |
| 1255 | + | |
| 1256 | + pCtx->iPicWidthReq = 0; | |
| 1257 | + pCtx->iPicHeightReq = 0; | |
| 1258 | + pCtx->bInitialDqLayersMem = false; | |
| 1259 | +} | |
| 1260 | + | |
| 1261 | +void_t ResetCurrentAccessUnit ( PWelsDecoderContext pCtx ) | |
| 1262 | +{ | |
| 1263 | + PAccessUnit pCurAu = pCtx->pAccessUnitList; | |
| 1264 | + | |
| 1265 | + pCurAu->uiEndPos = 0; | |
| 1266 | + pCurAu->bCompletedAuFlag = false; | |
| 1267 | + if (pCurAu->uiActualUnitsNum > 0){ | |
| 1268 | + uint32_t iIdx = 0; | |
| 1269 | + const uint32_t kuiActualNum = pCurAu->uiActualUnitsNum; | |
| 1270 | + // a more simpler method to do nal units list management prefered here | |
| 1271 | + const uint32_t kuiAvailNum = pCurAu->uiAvailUnitsNum; | |
| 1272 | + const uint32_t kuiLeftNum = kuiAvailNum - kuiActualNum; | |
| 1273 | + | |
| 1274 | + // Swapping active nal unit nodes of succeeding AU with leading of list | |
| 1275 | + while (iIdx < kuiLeftNum) | |
| 1276 | + { | |
| 1277 | + PNalUnit t = pCurAu->pNalUnitsList[kuiActualNum+iIdx]; | |
| 1278 | + pCurAu->pNalUnitsList[kuiActualNum+iIdx] = pCurAu->pNalUnitsList[iIdx]; | |
| 1279 | + pCurAu->pNalUnitsList[iIdx] = t; | |
| 1280 | + ++ iIdx; | |
| 1281 | + } | |
| 1282 | + pCurAu->uiActualUnitsNum = pCurAu->uiAvailUnitsNum = kuiLeftNum; | |
| 1283 | + } | |
| 1284 | +} | |
| 1285 | + | |
| 1286 | +/*! | |
| 1287 | + * \brief Force reset current Acess Unit Nal list in case error parsing/decoding in current AU | |
| 1288 | + * \author | |
| 1289 | + * \history 11/16/2009 | |
| 1290 | + */ | |
| 1291 | +void_t ForceResetCurrentAccessUnit( PAccessUnit pAu ) | |
| 1292 | +{ | |
| 1293 | + uint32_t uiSucAuIdx = pAu->uiEndPos + 1; | |
| 1294 | + uint32_t uiCurAuIdx = 0; | |
| 1295 | + | |
| 1296 | + // swap the succeeding AU's nal units to the front | |
| 1297 | + while(uiSucAuIdx < pAu->uiAvailUnitsNum) | |
| 1298 | + { | |
| 1299 | + PNalUnit t = pAu->pNalUnitsList[uiSucAuIdx]; | |
| 1300 | + pAu->pNalUnitsList[uiSucAuIdx] = pAu->pNalUnitsList[uiCurAuIdx]; | |
| 1301 | + pAu->pNalUnitsList[uiCurAuIdx] = t; | |
| 1302 | + ++ uiSucAuIdx; | |
| 1303 | + ++ uiCurAuIdx; | |
| 1304 | + } | |
| 1305 | + | |
| 1306 | + // Update avail/actual units num accordingly for next AU parsing | |
| 1307 | + if ( pAu->uiAvailUnitsNum > pAu->uiEndPos ) | |
| 1308 | + pAu->uiAvailUnitsNum -= (pAu->uiEndPos+1); | |
| 1309 | + else | |
| 1310 | + pAu->uiAvailUnitsNum = 0; | |
| 1311 | + pAu->uiActualUnitsNum = 0; | |
| 1312 | + pAu->uiEndPos = 0; | |
| 1313 | + pAu->bCompletedAuFlag = false; | |
| 1314 | +} | |
| 1315 | + | |
| 1316 | +//clear current corrupted NAL from pNalUnitsList | |
| 1317 | +void_t ForceClearCurrentNal( PAccessUnit pAu ) | |
| 1318 | +{ | |
| 1319 | + if (pAu->uiAvailUnitsNum > 0) | |
| 1320 | + -- pAu->uiAvailUnitsNum; | |
| 1321 | +} | |
| 1322 | + | |
| 1323 | + | |
| 1324 | +void_t CheckAvailNalUnitsListContinuity( PWelsDecoderContext pCtx, int32_t iStartIdx, int32_t iEndIdx ) | |
| 1325 | +{ | |
| 1326 | + PAccessUnit pCurAu = pCtx->pAccessUnitList; | |
| 1327 | + | |
| 1328 | + uint8_t uiLastNuDependencyId, uiLastNuLayerDqId; | |
| 1329 | + uint8_t uiCurNuDependencyId, uiCurNuQualityId, uiCurNuLayerDqId, uiCurNuRefLayerDqId; | |
| 1330 | + | |
| 1331 | + int32_t iCurNalUnitIdx = 0; | |
| 1332 | + | |
| 1333 | + //check the continuity of pNalUnitsList forwards (from pIdxNoInterLayerPred to end_postion) | |
| 1334 | + uiLastNuDependencyId = pCurAu->pNalUnitsList[iStartIdx]->sNalHeaderExt.uiDependencyId;//starting nal unit | |
| 1335 | + uiLastNuLayerDqId = pCurAu->pNalUnitsList[iStartIdx]->sNalHeaderExt.uiLayerDqId;//starting nal unit | |
| 1336 | + iCurNalUnitIdx = iStartIdx + 1;//current nal unit | |
| 1337 | + while ( iCurNalUnitIdx <= iEndIdx ) | |
| 1338 | + { | |
| 1339 | + uiCurNuDependencyId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiDependencyId; | |
| 1340 | + uiCurNuQualityId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiQualityId; | |
| 1341 | + uiCurNuLayerDqId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiLayerDqId; | |
| 1342 | + uiCurNuRefLayerDqId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalData.sVclNal.sSliceHeaderExt.uiRefLayerDqId; | |
| 1343 | + | |
| 1344 | + if ( uiCurNuDependencyId == uiLastNuDependencyId ) | |
| 1345 | + { | |
| 1346 | + uiLastNuLayerDqId = uiCurNuLayerDqId; | |
| 1347 | + ++ iCurNalUnitIdx; | |
| 1348 | + } | |
| 1349 | + else //uiCurNuDependencyId != uiLastNuDependencyId, new dependency arrive | |
| 1350 | + { | |
| 1351 | + if ( uiCurNuQualityId == 0 ) | |
| 1352 | + { | |
| 1353 | + uiLastNuDependencyId = uiCurNuDependencyId; | |
| 1354 | + if ( uiCurNuRefLayerDqId == uiLastNuLayerDqId ) | |
| 1355 | + { | |
| 1356 | + uiLastNuLayerDqId = uiCurNuLayerDqId; | |
| 1357 | + ++ iCurNalUnitIdx; | |
| 1358 | + } | |
| 1359 | + else //cur_nu_layer_id != next_nu_ref_layer_dq_id, the chain is broken at this point | |
| 1360 | + { | |
| 1361 | + break; | |
| 1362 | + } | |
| 1363 | + } | |
| 1364 | + else //new dependency arrive, but no base quality layer, so we must stop in this point | |
| 1365 | + { | |
| 1366 | + break; | |
| 1367 | + } | |
| 1368 | + } | |
| 1369 | + } | |
| 1370 | + | |
| 1371 | + -- iCurNalUnitIdx; | |
| 1372 | + pCurAu->uiEndPos = iCurNalUnitIdx; | |
| 1373 | + pCtx->uiTargetDqId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiLayerDqId; | |
| 1374 | +} | |
| 1375 | + | |
| 1376 | +//main purpose: to support multi-slice and to include all slice which have the same uiDependencyId, uiQualityId and frame_num | |
| 1377 | +//for single slice, pIdxNoInterLayerPred SHOULD NOT be modified | |
| 1378 | +void_t RefineIdxNoInterLayerPred( PAccessUnit pCurAu, int32_t* pIdxNoInterLayerPred ) | |
| 1379 | +{ | |
| 1380 | + int32_t iLastNalDependId = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalHeaderExt.uiDependencyId; | |
| 1381 | + int32_t iLastNalQualityId = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalHeaderExt.uiQualityId; | |
| 1382 | + uint8_t uiLastNalTId = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalHeaderExt.uiTemporalId; | |
| 1383 | + int32_t iLastNalFrameNum = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFrameNum; | |
| 1384 | + int32_t iLastNalPoc = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb; | |
| 1385 | + int32_t iLastNalFirstMb = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFirstMbInSlice; | |
| 1386 | + int32_t iCurNalDependId, iCurNalQualityId, iCurNalTId, iCurNalFrameNum, iCurNalPoc, iCurNalFirstMb, iCurIdx, iFinalIdxNoInterLayerPred; | |
| 1387 | + | |
| 1388 | + bool_t bMultiSliceFind = false; | |
| 1389 | + | |
| 1390 | + iFinalIdxNoInterLayerPred = 0; | |
| 1391 | + iCurIdx = *pIdxNoInterLayerPred - 1; | |
| 1392 | + while ( iCurIdx >= 0 ) | |
| 1393 | + { | |
| 1394 | + if ( pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.iNoInterLayerPredFlag ) | |
| 1395 | + { | |
| 1396 | + iCurNalDependId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiDependencyId; | |
| 1397 | + iCurNalQualityId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiQualityId; | |
| 1398 | + iCurNalTId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiTemporalId; | |
| 1399 | + iCurNalFrameNum = pCurAu->pNalUnitsList[iCurIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFrameNum; | |
| 1400 | + iCurNalPoc = pCurAu->pNalUnitsList[iCurIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb; | |
| 1401 | + iCurNalFirstMb = pCurAu->pNalUnitsList[iCurIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFirstMbInSlice; | |
| 1402 | + | |
| 1403 | + if ( iCurNalDependId == iLastNalDependId && | |
| 1404 | + iCurNalQualityId == iLastNalQualityId && | |
| 1405 | + iCurNalTId == uiLastNalTId && | |
| 1406 | + iCurNalFrameNum == iLastNalFrameNum && | |
| 1407 | + iCurNalPoc == iLastNalPoc && | |
| 1408 | + iCurNalFirstMb != iLastNalFirstMb ) | |
| 1409 | + { | |
| 1410 | + bMultiSliceFind = true; | |
| 1411 | + iFinalIdxNoInterLayerPred = iCurIdx; | |
| 1412 | + --iCurIdx; | |
| 1413 | + continue; | |
| 1414 | + } | |
| 1415 | + else | |
| 1416 | + { | |
| 1417 | + break; | |
| 1418 | + } | |
| 1419 | + } | |
| 1420 | + --iCurIdx; | |
| 1421 | + } | |
| 1422 | + | |
| 1423 | + if ( bMultiSliceFind && *pIdxNoInterLayerPred != iFinalIdxNoInterLayerPred ) | |
| 1424 | + { | |
| 1425 | + *pIdxNoInterLayerPred = iFinalIdxNoInterLayerPred; | |
| 1426 | + } | |
| 1427 | +} | |
| 1428 | + | |
| 1429 | +bool_t CheckPocOfCurValidNalUnits( PAccessUnit pCurAu, int32_t pIdxNoInterLayerPred ) | |
| 1430 | +{ | |
| 1431 | + int32_t iEndIdx = pCurAu->uiEndPos; | |
| 1432 | + int32_t iCurAuPoc = pCurAu->pNalUnitsList[pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb; | |
| 1433 | + int32_t iTmpPoc, i; | |
| 1434 | + for ( i = pIdxNoInterLayerPred+1; i < iEndIdx; i++ ) | |
| 1435 | + { | |
| 1436 | + iTmpPoc = pCurAu->pNalUnitsList[i]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb; | |
| 1437 | + if ( iTmpPoc != iCurAuPoc ) | |
| 1438 | + { | |
| 1439 | + return false; | |
| 1440 | + } | |
| 1441 | + } | |
| 1442 | + | |
| 1443 | + return true; | |
| 1444 | +} | |
| 1445 | + | |
| 1446 | +bool_t CheckIntegrityNalUnitsList( PWelsDecoderContext pCtx ) | |
| 1447 | +{ | |
| 1448 | + PAccessUnit pCurAu = pCtx->pAccessUnitList; | |
| 1449 | + const int32_t kiEndPos = pCurAu->uiEndPos; | |
| 1450 | + int32_t iIdxNoInterLayerPred = 0; | |
| 1451 | + int32_t iCurNalUnitIdx = kiEndPos; | |
| 1452 | + | |
| 1453 | + ESliceType eSliceType = static_cast<ESliceType> (0);//EC 2009.11.12 | |
| 1454 | + | |
| 1455 | + if ( !pCurAu->bCompletedAuFlag ) | |
| 1456 | + return false; | |
| 1457 | + | |
| 1458 | + eSliceType = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.eSliceType; | |
| 1459 | + | |
| 1460 | + if ( I_SLICE == eSliceType ) | |
| 1461 | + { | |
| 1462 | + pCurAu->uiStartPos = 0; | |
| 1463 | + //step1: search the pNalUnit whose iNoInterLayerPredFlag equal to 1 backwards (from uiEndPos to 0) | |
| 1464 | + iIdxNoInterLayerPred = kiEndPos; | |
| 1465 | + while ( iIdxNoInterLayerPred >= 0 ) | |
| 1466 | + { | |
| 1467 | + if ( pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag ) | |
| 1468 | + { | |
| 1469 | + break; | |
| 1470 | + } | |
| 1471 | + --iIdxNoInterLayerPred; | |
| 1472 | + } | |
| 1473 | + if ( iIdxNoInterLayerPred < 0 ) | |
| 1474 | + { | |
| 1475 | + //can not find the Nal Unit whose no_inter_pred_falg equal to 1, MUST STOP decode | |
| 1476 | + return false; | |
| 1477 | + } | |
| 1478 | + | |
| 1479 | + //step2: support multi-slice, to include all base layer slice | |
| 1480 | + RefineIdxNoInterLayerPred( pCurAu, &iIdxNoInterLayerPred ); | |
| 1481 | + pCurAu->uiStartPos = iIdxNoInterLayerPred; | |
| 1482 | + CheckAvailNalUnitsListContinuity( pCtx, iIdxNoInterLayerPred, kiEndPos ); | |
| 1483 | + | |
| 1484 | + if ( !CheckPocOfCurValidNalUnits( pCurAu, iIdxNoInterLayerPred ) ) | |
| 1485 | + { | |
| 1486 | + return false; | |
| 1487 | + } | |
| 1488 | + | |
| 1489 | + pCtx->iCurSeqIntervalTargetDependId = pCurAu->pNalUnitsList[pCurAu->uiEndPos]->sNalHeaderExt.uiDependencyId; | |
| 1490 | + pCtx->iCurSeqIntervalMaxPicWidth = pCurAu->pNalUnitsList[pCurAu->uiEndPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iMbWidth << 4; | |
| 1491 | + pCtx->iCurSeqIntervalMaxPicHeight = pCurAu->pNalUnitsList[pCurAu->uiEndPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iMbHeight << 4; | |
| 1492 | + } | |
| 1493 | + else //P_SLICE | |
| 1494 | + { | |
| 1495 | + //step 1: search uiDependencyId equal to pCtx->cur_seq_interval_target_dependency_id | |
| 1496 | + bool_t bGetDependId = false; | |
| 1497 | + int32_t iIdxDependId = 0; | |
| 1498 | + | |
| 1499 | + iIdxDependId = kiEndPos; | |
| 1500 | + while ( iIdxDependId >= 0 ) | |
| 1501 | + { | |
| 1502 | + if ( pCtx->iCurSeqIntervalTargetDependId == pCurAu->pNalUnitsList[iIdxDependId]->sNalHeaderExt.uiDependencyId ) | |
| 1503 | + { | |
| 1504 | + bGetDependId = true; | |
| 1505 | + break; | |
| 1506 | + } | |
| 1507 | + else | |
| 1508 | + { | |
| 1509 | + --iIdxDependId; | |
| 1510 | + } | |
| 1511 | + } | |
| 1512 | + | |
| 1513 | + //step 2: switch according to whether or not find the index of pNalUnit whose uiDependencyId equal to iCurSeqIntervalTargetDependId | |
| 1514 | + if ( bGetDependId ) //get the index of pNalUnit whose uiDependencyId equal to iCurSeqIntervalTargetDependId | |
| 1515 | + { | |
| 1516 | + bool_t bGetNoInterPredFront = false; | |
| 1517 | + //step 2a: search iNoInterLayerPredFlag [0....iIdxDependId] | |
| 1518 | + iIdxNoInterLayerPred = iIdxDependId; | |
| 1519 | + while ( iIdxNoInterLayerPred >= 0 ) | |
| 1520 | + { | |
| 1521 | + if ( pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag ) | |
| 1522 | + { | |
| 1523 | + bGetNoInterPredFront = true; | |
| 1524 | + break; | |
| 1525 | + } | |
| 1526 | + --iIdxNoInterLayerPred; | |
| 1527 | + } | |
| 1528 | + //step 2b: switch, whether or not find the NAL unit whose no_inter_pred_flag equal to 1 among [0....iIdxDependId] | |
| 1529 | + if ( bGetNoInterPredFront ) //YES | |
| 1530 | + { | |
| 1531 | + RefineIdxNoInterLayerPred( pCurAu, &iIdxNoInterLayerPred ); | |
| 1532 | + pCurAu->uiStartPos = iIdxNoInterLayerPred; | |
| 1533 | + CheckAvailNalUnitsListContinuity( pCtx, iIdxNoInterLayerPred, iIdxDependId ); | |
| 1534 | + | |
| 1535 | + if ( !CheckPocOfCurValidNalUnits( pCurAu, iIdxNoInterLayerPred ) ) | |
| 1536 | + { | |
| 1537 | + return false; | |
| 1538 | + } | |
| 1539 | + } | |
| 1540 | + else //NO, should find the NAL unit whose no_inter_pred_flag equal to 1 among [iIdxDependId....uiEndPos] | |
| 1541 | + { | |
| 1542 | + iIdxNoInterLayerPred = iIdxDependId; | |
| 1543 | + while ( iIdxNoInterLayerPred <= kiEndPos ) | |
| 1544 | + { | |
| 1545 | + if ( pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag ) | |
| 1546 | + { | |
| 1547 | + break; | |
| 1548 | + } | |
| 1549 | + ++iIdxNoInterLayerPred; | |
| 1550 | + } | |
| 1551 | + | |
| 1552 | + if ( iIdxNoInterLayerPred > kiEndPos ) | |
| 1553 | + { | |
| 1554 | + return false; //cann't find the index of pNalUnit whose no_inter_pred_flag = 1 | |
| 1555 | + } | |
| 1556 | + | |
| 1557 | + RefineIdxNoInterLayerPred( pCurAu, &iIdxNoInterLayerPred ); | |
| 1558 | + pCurAu->uiStartPos = iIdxNoInterLayerPred; | |
| 1559 | + CheckAvailNalUnitsListContinuity( pCtx, iIdxNoInterLayerPred, kiEndPos ); | |
| 1560 | + | |
| 1561 | + if ( !CheckPocOfCurValidNalUnits( pCurAu, iIdxNoInterLayerPred ) ) | |
| 1562 | + { | |
| 1563 | + return false; | |
| 1564 | + } | |
| 1565 | + } | |
| 1566 | + } | |
| 1567 | + else //without the index of pNalUnit, should process this AU as common case | |
| 1568 | + { | |
| 1569 | + iIdxNoInterLayerPred = kiEndPos; | |
| 1570 | + while (iIdxNoInterLayerPred >= 0) | |
| 1571 | + { | |
| 1572 | + if ( pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag ) | |
| 1573 | + { | |
| 1574 | + break; | |
| 1575 | + } | |
| 1576 | + --iIdxNoInterLayerPred; | |
| 1577 | + } | |
| 1578 | + if (iIdxNoInterLayerPred < 0) | |
| 1579 | + { | |
| 1580 | + return false; //cann't find the index of pNalUnit whose iNoInterLayerPredFlag = 1 | |
| 1581 | + } | |
| 1582 | + | |
| 1583 | + RefineIdxNoInterLayerPred( pCurAu, &iIdxNoInterLayerPred ); | |
| 1584 | + pCurAu->uiStartPos = iIdxNoInterLayerPred; | |
| 1585 | + CheckAvailNalUnitsListContinuity( pCtx, iIdxNoInterLayerPred, kiEndPos ); | |
| 1586 | + | |
| 1587 | + if ( !CheckPocOfCurValidNalUnits( pCurAu, iIdxNoInterLayerPred ) ) | |
| 1588 | + { | |
| 1589 | + return false; | |
| 1590 | + } | |
| 1591 | + } | |
| 1592 | + } | |
| 1593 | + | |
| 1594 | + return true; | |
| 1595 | +} | |
| 1596 | + | |
| 1597 | +void_t CheckOnlyOneLayerInAu( PWelsDecoderContext pCtx ) | |
| 1598 | +{ | |
| 1599 | + PAccessUnit pCurAu = pCtx->pAccessUnitList; | |
| 1600 | + | |
| 1601 | + int32_t iEndIdx = pCurAu->uiEndPos; | |
| 1602 | + int32_t iCurIdx = pCurAu->uiStartPos; | |
| 1603 | + uint8_t uiDId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiDependencyId; | |
| 1604 | + uint8_t uiQId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiQualityId; | |
| 1605 | + uint8_t uiTId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiTemporalId; | |
| 1606 | + | |
| 1607 | + uint8_t uiCurDId, uiCurQId, uiCurTId; | |
| 1608 | + | |
| 1609 | + pCtx->bOnlyOneLayerInCurAuFlag = true; | |
| 1610 | + | |
| 1611 | + if ( iEndIdx == iCurIdx ) //only one NAL in pNalUnitsList | |
| 1612 | + { | |
| 1613 | + return; | |
| 1614 | + } | |
| 1615 | + | |
| 1616 | + ++iCurIdx; | |
| 1617 | + while ( iCurIdx <= iEndIdx ) | |
| 1618 | + { | |
| 1619 | + uiCurDId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiDependencyId; | |
| 1620 | + uiCurQId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiQualityId; | |
| 1621 | + uiCurTId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiTemporalId; | |
| 1622 | + | |
| 1623 | + if ( uiDId != uiCurDId || uiQId != uiCurQId || uiTId != uiCurTId ) | |
| 1624 | + { | |
| 1625 | + pCtx->bOnlyOneLayerInCurAuFlag = false; | |
| 1626 | + return; | |
| 1627 | + } | |
| 1628 | + | |
| 1629 | + ++iCurIdx; | |
| 1630 | + } | |
| 1631 | +} | |
| 1632 | + | |
| 1633 | +int32_t WelsDecodeAccessUnitStart ( PWelsDecoderContext pCtx ) | |
| 1634 | +{ | |
| 1635 | + // Roll back NAL units not being belong to current access unit list for proceeded access unit | |
| 1636 | + int32_t iRet = UpdateAccessUnit ( pCtx ); | |
| 1637 | + if ( iRet != ERR_NONE ) | |
| 1638 | + return iRet; | |
| 1639 | + | |
| 1640 | + pCtx->pAccessUnitList->uiStartPos = 0; | |
| 1641 | + if ( !pCtx->bAvcBasedFlag && !CheckIntegrityNalUnitsList( pCtx ) ) | |
| 1642 | + { | |
| 1643 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 1644 | + return dsBitstreamError; | |
| 1645 | + } | |
| 1646 | + | |
| 1647 | + //check current AU has only one layer or not | |
| 1648 | + //If YES, can use deblocking based on AVC | |
| 1649 | + if ( !pCtx->bAvcBasedFlag ) | |
| 1650 | + { | |
| 1651 | + CheckOnlyOneLayerInAu( pCtx ); | |
| 1652 | + } | |
| 1653 | + | |
| 1654 | + return ERR_NONE; | |
| 1655 | +} | |
| 1656 | + | |
| 1657 | +void_t WelsDecodeAccessUnitEnd ( PWelsDecoderContext pCtx ) | |
| 1658 | +{ | |
| 1659 | + // uninitialize context of current access unit and rbsp buffer clean | |
| 1660 | + ResetCurrentAccessUnit ( pCtx ); | |
| 1661 | +} | |
| 1662 | + | |
| 1663 | + | |
| 1664 | +int32_t CheckBSBound(int32_t iWidth, int32_t iHeight, int32_t sliceNum, int32_t ppsId) | |
| 1665 | +{ | |
| 1666 | + int32_t iRet = 0; | |
| 1667 | + | |
| 1668 | +#if defined(WIN32) | |
| 1669 | + iRet = ((iWidth == 80) && (iHeight = 45) && (sliceNum < 60)); | |
| 1670 | + | |
| 1671 | +#elif defined(MACOS) | |
| 1672 | + iRet = ((iWidth == 80) && (iHeight = 45) && (ppsId < 57)); | |
| 1673 | + | |
| 1674 | +#elif defined(ANDROID) | |
| 1675 | + iRet = ((iWidth == 40) && (iHeight = 22)); | |
| 1676 | + | |
| 1677 | +#endif | |
| 1678 | + | |
| 1679 | + return iRet; | |
| 1680 | + | |
| 1681 | +} | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | +/* | |
| 1686 | + * ConstructAccessUnit | |
| 1687 | + * construct an access unit for given input bitstream, maybe partial NAL Unit, one or more Units are involved to | |
| 1688 | + * joint a collective access unit. | |
| 1689 | + * parameter\ | |
| 1690 | + * buf: bitstream data buffer | |
| 1691 | + * bit_len: size in bit length of data | |
| 1692 | + * buf_len: size in byte length of data | |
| 1693 | + * coded_au: mark an Access Unit decoding finished | |
| 1694 | + * return: | |
| 1695 | + * 0 - success; otherwise returned error_no defined in error_no.h | |
| 1696 | + */ | |
| 1697 | +int32_t ConstructAccessUnit( PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferInfo *pDstInfo) | |
| 1698 | +{ | |
| 1699 | + int32_t iErr; | |
| 1700 | + int32_t iWidth; | |
| 1701 | + int32_t iHeight; | |
| 1702 | + int32_t iStride[2] = { 0 }; | |
| 1703 | + | |
| 1704 | + PAccessUnit pCurAu = pCtx->pAccessUnitList; | |
| 1705 | + | |
| 1706 | + pCtx->bAuReadyFlag = false; | |
| 1707 | + pCtx->bLastHasMmco5 = false; | |
| 1708 | + | |
| 1709 | + iErr = WelsDecodeAccessUnitStart( pCtx ); | |
| 1710 | + GetVclNalTemporalId( pCtx ); | |
| 1711 | + | |
| 1712 | + if ( ERR_NONE != iErr ) | |
| 1713 | + { | |
| 1714 | + ForceResetCurrentAccessUnit( pCtx->pAccessUnitList ); | |
| 1715 | + pDstInfo->iBufferStatus = 0; | |
| 1716 | + return iErr; | |
| 1717 | + } | |
| 1718 | + | |
| 1719 | + pCtx->pSps = pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pSps; | |
| 1720 | + pCtx->pPps = pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pPps; | |
| 1721 | + | |
| 1722 | + //try to allocate or relocate DPB memory only when IDR arrival. | |
| 1723 | + if ( NAL_UNIT_CODED_SLICE_IDR == pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalHeaderExt.sNalUnitHeader.eNalUnitType || | |
| 1724 | + pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalHeaderExt.bIdrFlag ) | |
| 1725 | + { | |
| 1726 | + WelsResetRefPic(pCtx); //clear ref pPic when IDR NAL | |
| 1727 | + iErr = SyncPictureResolutionExt( pCtx, (pCtx->iMaxWidthInSps+15)>>4, (pCtx->iMaxHeightInSps+15)>>4 ); | |
| 1728 | + | |
| 1729 | + if( ERR_NONE != iErr ){ | |
| 1730 | + WelsLog(pCtx, WELS_LOG_WARNING, "sync picture resolution ext failed, the error is %d", iErr); | |
| 1731 | + return iErr; | |
| 1732 | + } | |
| 1733 | + } | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + pDstInfo->eBufferProperty = (EBufferProperty)pCtx->iDecoderOutputProperty; | |
| 1737 | + | |
| 1738 | + iErr = DecodeCurrentAccessUnit( pCtx, ppDst, iStride, &iWidth, &iHeight, pDstInfo ); | |
| 1739 | + | |
| 1740 | + WelsDecodeAccessUnitEnd( pCtx ); | |
| 1741 | + | |
| 1742 | + if ( ERR_NONE != iErr ) | |
| 1743 | + { | |
| 1744 | + WelsLog( pCtx, WELS_LOG_INFO, "returned error from decoding:[0x%x]\n", iErr); | |
| 1745 | + | |
| 1746 | + pDstInfo->iBufferStatus = 0; | |
| 1747 | + return iErr; | |
| 1748 | + } | |
| 1749 | + | |
| 1750 | + return 0; | |
| 1751 | +} | |
| 1752 | + | |
| 1753 | +static inline void_t InitDqLayerInfo( PDqLayer pDqLayer, PLayerInfo pLayerInfo, PNalUnit pNalUnit, PPicture pPicDec ) | |
| 1754 | +{ | |
| 1755 | + PNalUnitHeaderExt pNalHdrExt = &pNalUnit->sNalHeaderExt; | |
| 1756 | + PSliceHeaderExt pShExt = &pNalUnit->sNalData.sVclNal.sSliceHeaderExt; | |
| 1757 | + PSliceHeader pSh = &pShExt->sSliceHeader; | |
| 1758 | + const uint8_t kuiQualityId = pNalHdrExt->uiQualityId; | |
| 1759 | + | |
| 1760 | + memcpy(&pDqLayer->sLayerInfo, pLayerInfo, sizeof(SLayerInfo));//confirmed_safe_unsafe_usage | |
| 1761 | + | |
| 1762 | + pDqLayer->pDec = pPicDec; | |
| 1763 | + pDqLayer->iMbWidth = pSh->iMbWidth; // MB width of this picture | |
| 1764 | + pDqLayer->iMbHeight = pSh->iMbHeight;// MB height of this picture | |
| 1765 | + | |
| 1766 | + pDqLayer->iSliceIdcBackup = (pSh->iFirstMbInSlice << 7) | (pNalHdrExt->uiDependencyId << 4) | (pNalHdrExt->uiQualityId); | |
| 1767 | + | |
| 1768 | + /* Common syntax elements across all slices of a DQLayer */ | |
| 1769 | + pDqLayer->uiPpsId = pLayerInfo->pPps->iPpsId; | |
| 1770 | + pDqLayer->uiDisableInterLayerDeblockingFilterIdc = pShExt->uiDisableInterLayerDeblockingFilterIdc; | |
| 1771 | + pDqLayer->iInterLayerSliceAlphaC0Offset = pShExt->iInterLayerSliceAlphaC0Offset; | |
| 1772 | + pDqLayer->iInterLayerSliceBetaOffset = pShExt->iInterLayerSliceBetaOffset; | |
| 1773 | + pDqLayer->iSliceGroupChangeCycle = pSh->iSliceGroupChangeCycle; | |
| 1774 | + pDqLayer->bStoreRefBasePicFlag = pShExt->bStoreRefBasePicFlag; | |
| 1775 | + pDqLayer->bTCoeffLevelPredFlag = pShExt->bTCoeffLevelPredFlag; | |
| 1776 | + pDqLayer->bConstrainedIntraResamplingFlag = pShExt->bConstrainedIntraResamplingFlag; | |
| 1777 | + pDqLayer->uiRefLayerDqId = pShExt->uiRefLayerDqId; | |
| 1778 | + pDqLayer->uiRefLayerChromaPhaseXPlus1Flag = pShExt->uiRefLayerChromaPhaseXPlus1Flag; | |
| 1779 | + pDqLayer->uiRefLayerChromaPhaseYPlus1 = pShExt->uiRefLayerChromaPhaseYPlus1; | |
| 1780 | + //memcpy(&pDqLayer->sScaledRefLayer, &pShExt->sScaledRefLayer, sizeof(SPosOffset));//confirmed_safe_unsafe_usage | |
| 1781 | + | |
| 1782 | + if ( kuiQualityId == BASE_QUALITY_ID ){ | |
| 1783 | + pDqLayer->pRefPicListReordering = &pSh->pRefPicListReordering; | |
| 1784 | + pDqLayer->pRefPicMarking = &pSh->sRefMarking; | |
| 1785 | + pDqLayer->pRefPicBaseMarking = &pShExt->sRefBasePicMarking; | |
| 1786 | + } | |
| 1787 | + | |
| 1788 | + pDqLayer->uiLayerDqId = pNalHdrExt->uiLayerDqId; // dq_id of current layer | |
| 1789 | + pDqLayer->bUseRefBasePicFlag = pNalHdrExt->bUseRefBasePicFlag; | |
| 1790 | +} | |
| 1791 | + | |
| 1792 | +void_t WelsDqLayerDecodeStart ( PWelsDecoderContext pCtx, PNalUnit pCurNal, PSps pSps, PPps pPps ) | |
| 1793 | +{ | |
| 1794 | + SNalUnitHeader *pNalHdr = &pCurNal->sNalHeaderExt.sNalUnitHeader; | |
| 1795 | + PSliceHeader pSh = &pCurNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader; | |
| 1796 | + | |
| 1797 | + pCtx->eSliceType = pSh->eSliceType; | |
| 1798 | + pCtx->pSliceHeader = pSh; | |
| 1799 | + | |
| 1800 | + pCtx->iFrameNum = pSh->iFrameNum; | |
| 1801 | + | |
| 1802 | + if ((pNalHdr->eNalUnitType == NAL_UNIT_CODED_SLICE_IDR || | |
| 1803 | + (pCurNal->sNalHeaderExt.uiQualityId == BASE_QUALITY_ID && pCurNal->sNalHeaderExt.bIdrFlag)) && | |
| 1804 | + pSh->iFrameNum == 0) //pSh->iFrameNum == 0 this condition can deleted?????? | |
| 1805 | + { | |
| 1806 | + WelsResetRefPic ( pCtx ); // Reset decoded picture buffer lists due to an IDR frame incomes | |
| 1807 | + } | |
| 1808 | +} | |
| 1809 | + | |
| 1810 | +int32_t InitRefPicList ( PWelsDecoderContext pCtx, const uint8_t kuiNRi, const bool_t kbFirstSlice, int32_t iPoc) | |
| 1811 | +{ | |
| 1812 | + int32_t iRet = ERR_NONE; | |
| 1813 | + if( kbFirstSlice) | |
| 1814 | + iRet = WelsInitRefList( pCtx, iPoc ); | |
| 1815 | + if ( (pCtx->eSliceType!=I_SLICE && pCtx->eSliceType!=SI_SLICE) && kbFirstSlice ){ | |
| 1816 | + iRet = WelsReorderRefList ( pCtx ); | |
| 1817 | + } | |
| 1818 | + | |
| 1819 | + return iRet; | |
| 1820 | +} | |
| 1821 | + | |
| 1822 | +void_t InitCurDqLayerData( PWelsDecoderContext pCtx, PDqLayer pCurDq ) | |
| 1823 | +{ | |
| 1824 | + if ( NULL != pCtx && NULL != pCurDq ) | |
| 1825 | + { | |
| 1826 | + pCurDq->pCsData[0] = pCtx->pCsListXchg[0][0]; | |
| 1827 | + pCurDq->pCsData[1] = pCtx->pCsListXchg[0][1]; | |
| 1828 | + pCurDq->pCsData[2] = pCtx->pCsListXchg[0][2]; | |
| 1829 | + pCurDq->iCsStride[0] = pCtx->iCsStride[0]; | |
| 1830 | + pCurDq->iCsStride[1] = pCtx->iCsStride[1]; | |
| 1831 | + pCurDq->iCsStride[2] = pCtx->iCsStride[2]; | |
| 1832 | + | |
| 1833 | + pCurDq->pMbType = pCtx->sMb.pMbType[0]; | |
| 1834 | + pCurDq->pSliceIdc = pCtx->sMb.pSliceIdc[0]; | |
| 1835 | + pCurDq->pMv[0] = pCtx->sMb.pMv[0][0]; | |
| 1836 | + pCurDq->pRefIndex[0] = pCtx->sMb.pRefIndex[0][0]; | |
| 1837 | + pCurDq->pLumaQp = pCtx->sMb.pLumaQp[0]; | |
| 1838 | + pCurDq->pChromaQp = pCtx->sMb.pChromaQp[0]; | |
| 1839 | + pCurDq->pNzc = pCtx->sMb.pNzc[0]; | |
| 1840 | + pCurDq->pNzcRs = pCtx->sMb.pNzcRs[0]; | |
| 1841 | + pCurDq->pScaledTCoeff = pCtx->sMb.pScaledTCoeff[0]; | |
| 1842 | + pCurDq->pIntraPredMode = pCtx->sMb.pIntraPredMode[0]; | |
| 1843 | + pCurDq->pIntra4x4FinalMode = pCtx->sMb.pIntra4x4FinalMode[0]; | |
| 1844 | + pCurDq->pChromaPredMode = pCtx->sMb.pChromaPredMode[0]; | |
| 1845 | + pCurDq->pCbp = pCtx->sMb.pCbp[0]; | |
| 1846 | + pCurDq->pSubMbType = pCtx->sMb.pSubMbType[0]; | |
| 1847 | + pCurDq->pInterPredictionDoneFlag = pCtx->sMb.pInterPredictionDoneFlag[0]; | |
| 1848 | + pCurDq->pResidualPredFlag = pCtx->sMb.pResidualPredFlag[0]; | |
| 1849 | + } | |
| 1850 | +} | |
| 1851 | + | |
| 1852 | +// added to reset state of parameter sets to waiting successive incoming IDR, 6/4/2010 | |
| 1853 | +// It will be called in case packets lost/ broken and decoded failed at temporal level 0 | |
| 1854 | +void_t ResetParameterSetsState( PWelsDecoderContext pCtx ) | |
| 1855 | +{ | |
| 1856 | + pCtx->bSpsExistAheadFlag = false; | |
| 1857 | + pCtx->bSubspsExistAheadFlag = false; | |
| 1858 | + pCtx->bPpsExistAheadFlag = false; | |
| 1859 | +} | |
| 1860 | + | |
| 1861 | +/* | |
| 1862 | + * DecodeCurrentAccessUnit | |
| 1863 | + * Decode current access unit when current AU is completed. | |
| 1864 | + */ | |
| 1865 | +int32_t DecodeCurrentAccessUnit( PWelsDecoderContext pCtx, uint8_t **ppDst, int32_t *pDstLen, int32_t *pWidth, int32_t *pHeight, SBufferInfo *pDstInfo ) | |
| 1866 | +{ | |
| 1867 | + int32_t iRefCount[LIST_A]; | |
| 1868 | + PNalUnit pNalCur = NULL; | |
| 1869 | + PAccessUnit pCurAu = pCtx->pAccessUnitList; | |
| 1870 | + | |
| 1871 | + int32_t iIdx = pCurAu->uiStartPos; | |
| 1872 | + int32_t iEndIdx = pCurAu->uiEndPos; | |
| 1873 | + | |
| 1874 | + int32_t iPpsId = 0; | |
| 1875 | + int32_t iRet = ERR_NONE; | |
| 1876 | + | |
| 1877 | + const uint8_t kuiTargetLayerDqId = GetTargetDqId(pCtx->uiTargetDqId, pCtx->pParam); | |
| 1878 | + const uint8_t kuiDependencyIdMax = (kuiTargetLayerDqId & 0x7F) >> 4; | |
| 1879 | + int16_t iLastIdD = -1, iLastIdQ = -1; | |
| 1880 | + int16_t iCurrIdD = 0, iCurrIdQ = 0; | |
| 1881 | + uint8_t uiNalRefIdc = 0; | |
| 1882 | + bool_t bFreshSliceAvailable = true; // Another fresh slice comingup for given dq layer, for multiple slices in case of header parts of slices sometimes loss over error-prone channels, 8/14/2008 | |
| 1883 | + PPicture pStoreBasePic = NULL; | |
| 1884 | + | |
| 1885 | + //update pCurDqLayer at the starting of AU decoding | |
| 1886 | + if ( pCtx->bInitialDqLayersMem ) | |
| 1887 | + { | |
| 1888 | + pCtx->pCurDqLayer = pCtx->pDqLayersList[0]; | |
| 1889 | + } | |
| 1890 | + | |
| 1891 | + InitCurDqLayerData( pCtx, pCtx->pCurDqLayer ); | |
| 1892 | + | |
| 1893 | + pNalCur = pCurAu->pNalUnitsList[iIdx]; | |
| 1894 | + while ( iIdx <= iEndIdx ) | |
| 1895 | + { | |
| 1896 | + PDqLayer dq_cur = pCtx->pCurDqLayer; | |
| 1897 | + SLayerInfo pLayerInfo; | |
| 1898 | + PSliceHeaderExt pShExt = NULL; | |
| 1899 | + PSliceHeader pSh = NULL; | |
| 1900 | + | |
| 1901 | + if( pCtx->pDec == NULL ){ | |
| 1902 | + pCtx->pDec = PrefetchPic(pCtx->pPicBuff[0]); | |
| 1903 | + | |
| 1904 | + if( NULL == pCtx->pDec ){ | |
| 1905 | + WelsLog( pCtx, WELS_LOG_ERROR, "DecodeCurrentAccessUnit()::::::PrefetchPic ERROR, pSps->iNumRefFrames:%d.\n", | |
| 1906 | + pCtx->pSps->iNumRefFrames ); | |
| 1907 | + pCtx->iErrorCode |= dsOutOfMemory; | |
| 1908 | + return ERR_INFO_REF_COUNT_OVERFLOW; | |
| 1909 | + } | |
| 1910 | + } | |
| 1911 | + | |
| 1912 | +#ifdef NO_WAITING_AU | |
| 1913 | + //For fixing the nal lossing issue | |
| 1914 | + if ((pCtx->pDec->iTotalNumMbRec != 0)&& | |
| 1915 | + (CheckAccessUnitBoundaryExt(&pCtx->sLastNalHdrExt, &pNalCur->sNalHeaderExt, &pCtx->sLastSliceHeader, &pNalCur->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader))) | |
| 1916 | + { | |
| 1917 | + pCtx->pDec->iTotalNumMbRec = 0; | |
| 1918 | + } | |
| 1919 | +#else | |
| 1920 | + //initialize at the starting of AU. | |
| 1921 | + pCtx->pDec->iTotalNumMbRec = 0; | |
| 1922 | +#endif | |
| 1923 | + if(pCtx->pDec->iTotalNumMbRec == 0) //Picture start to decode | |
| 1924 | + { | |
| 1925 | + for( int32_t i = 0; i < LAYER_NUM_EXCHANGEABLE; ++ i) | |
| 1926 | + memset(pCtx->sMb.pSliceIdc[i], 0xff, (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int32_t)) ); | |
| 1927 | + } | |
| 1928 | + GetI4LumaIChromaAddrTable(pCtx->iDecBlockOffsetArray, pCtx->pDec->iLinesize[0], pCtx->pDec->iLinesize[1]); | |
| 1929 | + | |
| 1930 | + if ( pNalCur->sNalHeaderExt.uiLayerDqId > kuiTargetLayerDqId ) { | |
| 1931 | + break; // Per formance it need not to decode the remaining bits any more due to given uiLayerDqId required, 9/2/2009 | |
| 1932 | + } | |
| 1933 | + | |
| 1934 | + memset(&pLayerInfo, 0, sizeof(SLayerInfo)); | |
| 1935 | + | |
| 1936 | + /* | |
| 1937 | + * Loop decoding for slices (even FMO and/ multiple slices) within a dq layer | |
| 1938 | + */ | |
| 1939 | + while ( iIdx <= iEndIdx ) | |
| 1940 | + { | |
| 1941 | + BOOL_T bReconstructSlice; | |
| 1942 | + iCurrIdQ = pNalCur->sNalHeaderExt.uiQualityId; | |
| 1943 | + iCurrIdD = pNalCur->sNalHeaderExt.uiDependencyId; | |
| 1944 | + pSh = &pNalCur->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader; | |
| 1945 | + pShExt = &pNalCur->sNalData.sVclNal.sSliceHeaderExt; | |
| 1946 | + | |
| 1947 | + bReconstructSlice = CheckSliceNeedReconstruct(iCurrIdD, iCurrIdQ, pShExt->bStoreRefBasePicFlag, | |
| 1948 | + kuiDependencyIdMax, pNalCur->sNalHeaderExt.uiLayerDqId, kuiTargetLayerDqId); | |
| 1949 | + | |
| 1950 | + memcpy(&pLayerInfo.sNalHeaderExt, &pNalCur->sNalHeaderExt, sizeof(SNalUnitHeaderExt));//confirmed_safe_unsafe_usage | |
| 1951 | + | |
| 1952 | + pCtx->pDec->iFrameNum = pSh->iFrameNum; | |
| 1953 | + | |
| 1954 | + memcpy(&pLayerInfo.sSliceInLayer.sSliceHeaderExt, pShExt, sizeof(SSliceHeaderExt));//confirmed_safe_unsafe_usage | |
| 1955 | + pLayerInfo.sSliceInLayer.bSliceHeaderExtFlag = pNalCur->sNalData.sVclNal.bSliceHeaderExtFlag; | |
| 1956 | + pLayerInfo.sSliceInLayer.eSliceType = pSh->eSliceType; | |
| 1957 | + pLayerInfo.sSliceInLayer.iLastMbQp = pSh->iSliceQp; | |
| 1958 | + dq_cur->pBitStringAux = &pNalCur->sNalData.sVclNal.sSliceBitsRead; | |
| 1959 | + | |
| 1960 | + uiNalRefIdc = pNalCur->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc; | |
| 1961 | + | |
| 1962 | + iPpsId = pSh->iPpsId; | |
| 1963 | + | |
| 1964 | + pLayerInfo.pPps = pSh->pPps; | |
| 1965 | + pLayerInfo.pSps = pSh->pSps; | |
| 1966 | + pLayerInfo.pSubsetSps = pShExt->pSubsetSps; | |
| 1967 | + | |
| 1968 | + pCtx->pFmo = &pCtx->sFmoList[iPpsId]; | |
| 1969 | + if ( !FmoParamUpdate( pCtx->pFmo, pLayerInfo.pSps, pLayerInfo.pPps, &pCtx->iActiveFmoNum ) ) { | |
| 1970 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 1971 | + WelsLog( pCtx, WELS_LOG_WARNING, "DecodeCurrentAccessUnit(), FmoParamUpdate failed, eSliceType: %d.\n", pSh->eSliceType); | |
| 1972 | + return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_FMO_INIT_FAIL); | |
| 1973 | + } | |
| 1974 | + | |
| 1975 | + bFreshSliceAvailable = (iCurrIdD != iLastIdD || iCurrIdQ != iLastIdQ); // do not need condition of (first_mb == 0) due multiple slices might be disorder | |
| 1976 | + | |
| 1977 | + WelsDqLayerDecodeStart ( pCtx, pNalCur, pLayerInfo.pSps, pLayerInfo.pPps ); | |
| 1978 | + | |
| 1979 | + if ( iCurrIdQ == BASE_QUALITY_ID ) | |
| 1980 | + { | |
| 1981 | + ST64(iRefCount, LD64(pLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.uiRefCount)); | |
| 1982 | + } | |
| 1983 | + | |
| 1984 | + if ( (iLastIdD < 0) || //case 1: first layer | |
| 1985 | + ( iLastIdD == iCurrIdD) ) //case 2: same uiDId | |
| 1986 | + { | |
| 1987 | + InitDqLayerInfo( dq_cur, &pLayerInfo, pNalCur, pCtx->pDec ); | |
| 1988 | + | |
| 1989 | + if ( !dq_cur->sLayerInfo.pSps->bGapsInFrameNumValueAllowedFlag ) | |
| 1990 | + { | |
| 1991 | + const bool_t kbIdrFlag = dq_cur->sLayerInfo.sNalHeaderExt.bIdrFlag || (dq_cur->sLayerInfo.sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR); | |
| 1992 | + // Subclause 8.2.5.2 Decoding process for gaps in frame_num | |
| 1993 | + if ( !kbIdrFlag && | |
| 1994 | + pSh->iFrameNum != pCtx->iPrevFrameNum && | |
| 1995 | + pSh->iFrameNum != ((pCtx->iPrevFrameNum+1) & ((1<<dq_cur->sLayerInfo.pSps->uiLog2MaxFrameNum)-1)) ) | |
| 1996 | + { | |
| 1997 | + WelsLog( pCtx, WELS_LOG_WARNING, "referencing pictures lost due frame gaps exist, prev_frame_num: %d, curr_frame_num: %d\n", pCtx->iPrevFrameNum, pSh->iFrameNum); | |
| 1998 | + | |
| 1999 | +#ifdef LONG_TERM_REF | |
| 2000 | + pCtx->bParamSetsLostFlag = true; | |
| 2001 | +#else | |
| 2002 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 2003 | +#endif | |
| 2004 | + ResetParameterSetsState( pCtx ); | |
| 2005 | + | |
| 2006 | + pCtx->iErrorCode |= dsRefLost; | |
| 2007 | + return ERR_INFO_REFERENCE_PIC_LOST; | |
| 2008 | + } | |
| 2009 | + } | |
| 2010 | + | |
| 2011 | + if ( iCurrIdD == kuiDependencyIdMax && iCurrIdQ == BASE_QUALITY_ID ) | |
| 2012 | + { | |
| 2013 | + iRet = InitRefPicList ( pCtx, uiNalRefIdc, bFreshSliceAvailable, pSh->iPicOrderCntLsb); | |
| 2014 | + if ( iRet ) | |
| 2015 | + { | |
| 2016 | + HandleReferenceLost(pCtx, pNalCur); | |
| 2017 | + WelsLog( pCtx, WELS_LOG_WARNING, "reference picture introduced by this frame is lost during transmission! uiTId: %d\n", pNalCur->sNalHeaderExt.uiTemporalId ); | |
| 2018 | + return iRet; | |
| 2019 | + } | |
| 2020 | + } | |
| 2021 | + | |
| 2022 | + iRet = WelsDecodeSlice ( pCtx, bFreshSliceAvailable, pNalCur ); | |
| 2023 | + | |
| 2024 | + //Output good store_base reconstruction when enhancement quality layer occurred error for MGS key picture case | |
| 2025 | + if ( iRet != ERR_NONE ) | |
| 2026 | + { | |
| 2027 | + WelsLog( pCtx, WELS_LOG_WARNING, "DecodeCurrentAccessUnit() failed (%d) in frame: %d uiDId: %d uiQId: %d\n", | |
| 2028 | + iRet, pSh->iFrameNum, iCurrIdD, iCurrIdQ); | |
| 2029 | + HandleReferenceLostL0(pCtx, pNalCur); | |
| 2030 | + return iRet; | |
| 2031 | + } | |
| 2032 | + if( bReconstructSlice ) { | |
| 2033 | + if( WelsDecodeConstructSlice(pCtx, pNalCur) ){ | |
| 2034 | + return -1; | |
| 2035 | + } | |
| 2036 | + } | |
| 2037 | + } | |
| 2038 | +#if defined (_DEBUG) && !defined (CODEC_FOR_TESTBED) | |
| 2039 | + fprintf( stderr, "cur_frame : %d iCurrIdD : %d\n ", | |
| 2040 | + dq_cur->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iFrameNum, iCurrIdD ); | |
| 2041 | +#endif//#if !CODEC_FOR_TESTBED | |
| 2042 | + iLastIdD = iCurrIdD; | |
| 2043 | + iLastIdQ = iCurrIdQ; | |
| 2044 | + | |
| 2045 | + //pNalUnitsList overflow. | |
| 2046 | + ++ iIdx; | |
| 2047 | + if (iIdx <= iEndIdx) | |
| 2048 | + { | |
| 2049 | + pNalCur = pCurAu->pNalUnitsList[iIdx]; | |
| 2050 | + } | |
| 2051 | + else | |
| 2052 | + { | |
| 2053 | + pNalCur = NULL; | |
| 2054 | + } | |
| 2055 | + | |
| 2056 | + if ( pNalCur == NULL || | |
| 2057 | + iLastIdD != pNalCur->sNalHeaderExt.uiDependencyId || | |
| 2058 | + iLastIdQ != pNalCur->sNalHeaderExt.uiQualityId ) | |
| 2059 | + break; | |
| 2060 | + } | |
| 2061 | + | |
| 2062 | + // A dq layer decoded here | |
| 2063 | +#if defined (_DEBUG) && !defined (CODEC_FOR_TESTBED) | |
| 2064 | +#undef fprintf | |
| 2065 | + fprintf(stderr, "POC: #%d, FRAME: #%d, D: %d, Q: %d, T: %d, P: %d, %d\n", | |
| 2066 | + pSh->iPicOrderCntLsb, pSh->iFrameNum, iCurrIdD, iCurrIdQ, dq_cur->sLayerInfo.sNalHeaderExt.uiTemporalId, dq_cur->sLayerInfo.sNalHeaderExt.uiPriorityId,dq_cur->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iSliceQp); | |
| 2067 | +#endif//#if !CODEC_FOR_TESTBED | |
| 2068 | + | |
| 2069 | + if( dq_cur->uiLayerDqId == kuiTargetLayerDqId ){ | |
| 2070 | + if( DecodeFrameConstruction( pCtx, ppDst, pDstLen, pWidth, pHeight, pDstInfo) ){ | |
| 2071 | +#ifdef NO_WAITING_AU | |
| 2072 | + memcpy(&pCtx->sLastNalHdrExt, &pCurAu->pNalUnitsList[iIdx-1]->sNalHeaderExt, sizeof(SNalUnitHeaderExt)); | |
| 2073 | + memcpy(&pCtx->sLastSliceHeader, &pCurAu->pNalUnitsList[iIdx-1]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader, sizeof(SSliceHeader)); | |
| 2074 | + return ERR_NONE; | |
| 2075 | +#else | |
| 2076 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 2077 | + return -1; | |
| 2078 | +#endif | |
| 2079 | + | |
| 2080 | + } | |
| 2081 | + if( (uiNalRefIdc > 0) && ( iCurrIdQ || (!dq_cur->bStoreRefBasePicFlag) ) ){ | |
| 2082 | + WelsMarkAsRef(pCtx, false); | |
| 2083 | + ExpandReferencingPicture(pCtx->pDec, pCtx->sExpandPicFunc.pExpandLumaPicture, pCtx->sExpandPicFunc.pExpandChromaPicture); | |
| 2084 | + pCtx->pDec = NULL; | |
| 2085 | + } | |
| 2086 | + } | |
| 2087 | + | |
| 2088 | + if( (iCurrIdD == kuiDependencyIdMax) && (iCurrIdQ == BASE_QUALITY_ID) && (dq_cur->bStoreRefBasePicFlag) ){ | |
| 2089 | + pStoreBasePic = pCtx->pDec; | |
| 2090 | + | |
| 2091 | + if( uiNalRefIdc > 0 ){ | |
| 2092 | + WelsMarkAsRef(pCtx, true); | |
| 2093 | + ExpandReferencingPicture(pCtx->pDec, pCtx->sExpandPicFunc.pExpandLumaPicture, pCtx->sExpandPicFunc.pExpandChromaPicture); | |
| 2094 | + pCtx->pDec = NULL; | |
| 2095 | + } | |
| 2096 | + } | |
| 2097 | + // need update frame_num due current frame is well decoded | |
| 2098 | + pCtx->iPrevFrameNum = pSh->iFrameNum; | |
| 2099 | + if( pCtx->bLastHasMmco5 ) | |
| 2100 | + pCtx->iPrevFrameNum = 0; | |
| 2101 | + } | |
| 2102 | + | |
| 2103 | + return ERR_NONE; | |
| 2104 | +} | |
| 2105 | + | |
| 2106 | +} // namespace WelsDec | |
| @@ -0,0 +1,661 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +// exp_data.c | |
| 34 | +// export date cross various modules (.c) | |
| 35 | +#include "typedefs.h" | |
| 36 | +#include "wels_common_basis.h" | |
| 37 | +#include "mb_cache.h" | |
| 38 | +#include "utils.h" | |
| 39 | +#include "vlc_decoder.h" | |
| 40 | + | |
| 41 | +namespace WelsDec { | |
| 42 | + | |
| 43 | +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 44 | + | |
| 45 | +//////non_zero_count[16+8] mapping scan index | |
| 46 | +const uint8_t g_kuiMbNonZeroCountIdx[24] = | |
| 47 | +{ // 0 1 | 4 5 luma 8*8 block non_zero_count[16+8] | |
| 48 | + 0, 1, 4, 5, // 2 3 | 6 7 0 | 1 0 1 2 3 | |
| 49 | + 2, 3, 6, 7, //--------------- --------- 4 5 6 7 | |
| 50 | + 8, 9, 12, 13, // 8 9 | 12 13 2 | 3 8 9 10 11 | |
| 51 | + 10, 11, 14, 15, // 10 11 | 14 15-----------------------------> 12 13 14 15 | |
| 52 | + 16, 17, 20, 21, //---------------- chroma 8*8 block 16 17 18 19 | |
| 53 | + 18, 19, 22, 23 // 16 17 | 20 21 0 1 20 21 22 23 | |
| 54 | +}; | |
| 55 | +//cache element equal to 26 | |
| 56 | + | |
| 57 | +const uint8_t g_kuiCacheNzcScanIdx[24] = | |
| 58 | +{ | |
| 59 | + /* Luma */ | |
| 60 | + 9, 10, 17, 18, // 1+1*8, 2+1*8, 1+2*8, 2+2*8, | |
| 61 | + 11, 12, 19, 20, // 3+1*8, 4+1*8, 3+2*8, 4+2*8, | |
| 62 | + 25, 26, 33, 34, // 1+3*8, 2+3*8, 1+4*8, 2+4*8, | |
| 63 | + 27, 28, 35, 36, // 3+3*8, 4+3*8, 3+4*8, 4+4*8, | |
| 64 | + /* Cb */ | |
| 65 | + 14, 15, // 6+1*8, 7+1*8, | |
| 66 | + 22, 23, // 6+2*8, 7+2*8, | |
| 67 | + | |
| 68 | + /* Cr */ | |
| 69 | + 38, 39, // 6+4*8, 7+4*8, | |
| 70 | + 46, 47, // 6+5*8, 7+5*8, | |
| 71 | +}; | |
| 72 | + | |
| 73 | +//cache element equal to 30 | |
| 74 | +const uint8_t g_kuiCache30ScanIdx[16] = //mv or ref_index cache scan index, 4*4 block as basic unit | |
| 75 | +{ | |
| 76 | + 7, 8, 13, 14, | |
| 77 | + 9, 10, 15, 16, | |
| 78 | + 19, 20, 25, 26, | |
| 79 | + 21, 22, 27, 28 | |
| 80 | +}; | |
| 81 | + | |
| 82 | +const uint8_t g_kuiScan4[16] = //for mb cache in sMb (only current element, without neighbor) | |
| 83 | +{ // 4*4block scan mb cache order | |
| 84 | + 0, 1, 4, 5, // 0 1 | 4 5 0 1 | 2 3 | |
| 85 | + 2, 3, 6, 7, // 2 3 | 6 7 4 5 | 6 7 | |
| 86 | + 8, 9, 12, 13, //----------------->----------- | |
| 87 | + 10, 11, 14, 15 // 8 9 |12 13 8 9 |10 11 | |
| 88 | +}; //10 11 |14 15 12 13 |14 15 | |
| 89 | + | |
| 90 | +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 91 | + | |
| 92 | +// extern at wels_common_basis.h | |
| 93 | + | |
| 94 | +const uint8_t g_kuiChromaQp[52]={ | |
| 95 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11, | |
| 96 | + 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, | |
| 97 | + 28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37, | |
| 98 | + 37,38,38,38,39,39,39,39 | |
| 99 | +}; | |
| 100 | + | |
| 101 | +/* | |
| 102 | + * vcl type map for given NAL unit type and corresponding H264 type | |
| 103 | + */ | |
| 104 | +const VclType g_kuiVclTypeMap[32][2] = | |
| 105 | +{ | |
| 106 | + { NON_VCL, NON_VCL }, // 0: NAL_UNIT_UNSPEC_0 | |
| 107 | + { VCL, VCL, }, // 1: NAL_UNIT_CODED_SLICE | |
| 108 | + { VCL, NOT_APP }, // 2: NAL_UNIT_CODED_SLICE_DPA | |
| 109 | + { VCL, NOT_APP }, // 3: NAL_UNIT_CODED_SLICE_DPB | |
| 110 | + { VCL, NOT_APP }, // 4: NAL_UNIT_CODED_SLICE_DPC | |
| 111 | + { VCL, VCL }, // 5: NAL_UNIT_CODED_SLICE_IDR | |
| 112 | + { NON_VCL, NON_VCL }, // 6: NAL_UNIT_SEI | |
| 113 | + { NON_VCL, NON_VCL }, // 7: NAL_UNIT_SPS | |
| 114 | + { NON_VCL, NON_VCL }, // 8: NAL_UNIT_PPS | |
| 115 | + { NON_VCL, NON_VCL }, // 9: NAL_UNIT_AU_DELIMITER | |
| 116 | + { NON_VCL, NON_VCL }, // 10: NAL_UNIT_END_OF_SEQ | |
| 117 | + { NON_VCL, NON_VCL }, // 11: NAL_UNIT_END_OF_STR | |
| 118 | + { NON_VCL, NON_VCL }, // 12: NAL_UNIT_FILLER_DATA | |
| 119 | + { NON_VCL, NON_VCL }, // 13: NAL_UNIT_SPS_EXT | |
| 120 | + { NON_VCL, NON_VCL }, // 14: NAL_UNIT_PREFIX, NEED associate succeeded NAL to make a VCL | |
| 121 | + { NON_VCL, NON_VCL }, // 15: NAL_UNIT_SUBSET_SPS | |
| 122 | + { NON_VCL, NON_VCL }, // 16: NAL_UNIT_RESV_16 | |
| 123 | + { NON_VCL, NON_VCL }, // 17: NAL_UNIT_RESV_17 | |
| 124 | + { NON_VCL, NON_VCL }, // 18: NAL_UNIT_RESV_18 | |
| 125 | + { NON_VCL, NON_VCL }, // 19: NAL_UNIT_AUX_CODED_SLICE | |
| 126 | + { NON_VCL, VCL }, // 20: NAL_UNIT_CODED_SLICE_EXT | |
| 127 | + { NON_VCL, NON_VCL }, // 21: NAL_UNIT_RESV_21 | |
| 128 | + { NON_VCL, NON_VCL }, // 22: NAL_UNIT_RESV_22 | |
| 129 | + { NON_VCL, NON_VCL }, // 23: NAL_UNIT_RESV_23 | |
| 130 | + { NON_VCL, NON_VCL }, // 24: NAL_UNIT_UNSPEC_24 | |
| 131 | + { NON_VCL, NON_VCL }, // 25: NAL_UNIT_UNSPEC_25 | |
| 132 | + { NON_VCL, NON_VCL }, // 26: NAL_UNIT_UNSPEC_26 | |
| 133 | + { NON_VCL, NON_VCL }, // 27: NAL_UNIT_UNSPEC_27 | |
| 134 | + { NON_VCL, NON_VCL }, // 28: NAL_UNIT_UNSPEC_28 | |
| 135 | + { NON_VCL, NON_VCL }, // 29: NAL_UNIT_UNSPEC_29 | |
| 136 | + { NON_VCL, NON_VCL }, // 30: NAL_UNIT_UNSPEC_30 | |
| 137 | + { NON_VCL, NON_VCL } // 31: NAL_UNIT_UNSPEC_31 | |
| 138 | +}; | |
| 139 | + | |
| 140 | +/*common use table*/ | |
| 141 | +const uint8_t g_kuiScan8[24]={ // [16 + 2*4] | |
| 142 | + 9, 10, 17, 18, // 1+1*8, 2+1*8, 1+2*8, 2+2*8, | |
| 143 | + 11, 12, 19, 20, // 3+1*8, 4+1*8, 3+2*8, 4+2*8, | |
| 144 | + 25, 26, 33, 34, // 1+3*8, 2+3*8, 1+4*8, 2+4*8, | |
| 145 | + 27, 28, 35, 36, // 3+3*8, 4+3*8, 3+4*8, 4+4*8, | |
| 146 | + 14, 15, // 6+1*8, 7+1*8, | |
| 147 | + 22, 23, // 6+2*8, 7+2*8, | |
| 148 | + 38, 39, // 6+4*8, 7+4*8, | |
| 149 | + 46, 47, // 6+5*8, 7+5*8, | |
| 150 | +}; | |
| 151 | + | |
| 152 | +const uint8_t g_kuiLumaDcZigzagScan[16]={ | |
| 153 | + 0, 16, 32, 128, // 0*16 + 0*64, 1*16 + 0*64, 2*16 + 0*64, 0*16 + 2*64, | |
| 154 | + 48, 64, 80, 96, // 3*16 + 0*64, 0*16 + 1*64, 1*16 + 1*64, 2*16 + 1*64, | |
| 155 | + 144, 160, 176, 192, // 1*16 + 2*64, 2*16 + 2*64, 3*16 + 2*64, 0*16 + 3*64, | |
| 156 | + 112, 208, 224, 240 // 3*16 + 1*64, 1*16 + 3*64, 2*16 + 3*64, 3*16 + 3*64, | |
| 157 | +}; | |
| 158 | + | |
| 159 | +const uint8_t g_kuiChromaDcScan[4]={ | |
| 160 | + 0, 16, 32, 48 | |
| 161 | +}; | |
| 162 | + | |
| 163 | +__align16( const uint16_t, g_kuiDequantCoeff[52][8]) = { | |
| 164 | + /* 0*/{ 10, 13, 10, 13, 13, 16, 13, 16 }, /* 1*/{ 11, 14, 11, 14, 14, 18, 14, 18 }, | |
| 165 | + /* 2*/{ 13, 16, 13, 16, 16, 20, 16, 20 }, /* 3*/{ 14, 18, 14, 18, 18, 23, 18, 23 }, | |
| 166 | + /* 4*/{ 16, 20, 16, 20, 20, 25, 20, 25 }, /* 5*/{ 18, 23, 18, 23, 23, 29, 23, 29 }, | |
| 167 | + /* 6*/{ 20, 26, 20, 26, 26, 32, 26, 32 }, /* 7*/{ 22, 28, 22, 28, 28, 36, 28, 36 }, | |
| 168 | + /* 8*/{ 26, 32, 26, 32, 32, 40, 32, 40 }, /* 9*/{ 28, 36, 28, 36, 36, 46, 36, 46 }, | |
| 169 | + /*10*/{ 32, 40, 32, 40, 40, 50, 40, 50 }, /*11*/{ 36, 46, 36, 46, 46, 58, 46, 58 }, | |
| 170 | + /*12*/{ 40, 52, 40, 52, 52, 64, 52, 64 }, /*13*/{ 44, 56, 44, 56, 56, 72, 56, 72 }, | |
| 171 | + /*14*/{ 52, 64, 52, 64, 64, 80, 64, 80 }, /*15*/{ 56, 72, 56, 72, 72, 92, 72, 92 }, | |
| 172 | + /*16*/{ 64, 80, 64, 80, 80, 100, 80, 100 }, /*17*/{ 72, 92, 72, 92, 92, 116, 92, 116 }, | |
| 173 | + /*18*/{ 80, 104, 80, 104, 104, 128, 104, 128 }, /*19*/{ 88, 112, 88, 112, 112, 144, 112, 144 }, | |
| 174 | + /*20*/{ 104, 128, 104, 128, 128, 160, 128, 160 }, /*21*/{ 112, 144, 112, 144, 144, 184, 144, 184 }, | |
| 175 | + /*22*/{ 128, 160, 128, 160, 160, 200, 160, 200 }, /*23*/{ 144, 184, 144, 184, 184, 232, 184, 232 }, | |
| 176 | + /*24*/{ 160, 208, 160, 208, 208, 256, 208, 256 }, /*25*/{ 176, 224, 176, 224, 224, 288, 224, 288 }, | |
| 177 | + /*26*/{ 208, 256, 208, 256, 256, 320, 256, 320 }, /*27*/{ 224, 288, 224, 288, 288, 368, 288, 368 }, | |
| 178 | + /*28*/{ 256, 320, 256, 320, 320, 400, 320, 400 }, /*29*/{ 288, 368, 288, 368, 368, 464, 368, 464 }, | |
| 179 | + /*30*/{ 320, 416, 320, 416, 416, 512, 416, 512 }, /*31*/{ 352, 448, 352, 448, 448, 576, 448, 576 }, | |
| 180 | + /*32*/{ 416, 512, 416, 512, 512, 640, 512, 640 }, /*33*/{ 448, 576, 448, 576, 576, 736, 576, 736 }, | |
| 181 | + /*34*/{ 512, 640, 512, 640, 640, 800, 640, 800 }, /*35*/{ 576, 736, 576, 736, 736, 928, 736, 928 }, | |
| 182 | + /*36*/{ 640, 832, 640, 832, 832, 1024, 832, 1024 }, /*37*/{ 704, 896, 704, 896, 896, 1152, 896, 1152 }, | |
| 183 | + /*38*/{ 832, 1024, 832, 1024, 1024, 1280, 1024, 1280 }, /*39*/{ 896, 1152, 896, 1152, 1152, 1472, 1152, 1472 }, | |
| 184 | + /*40*/{ 1024, 1280, 1024, 1280, 1280, 1600, 1280, 1600 }, /*41*/{ 1152, 1472, 1152, 1472, 1472, 1856, 1472, 1856 }, | |
| 185 | + /*42*/{ 1280, 1664, 1280, 1664, 1664, 2048, 1664, 2048 }, /*43*/{ 1408, 1792, 1408, 1792, 1792, 2304, 1792, 2304 }, | |
| 186 | + /*44*/{ 1664, 2048, 1664, 2048, 2048, 2560, 2048, 2560 }, /*45*/{ 1792, 2304, 1792, 2304, 2304, 2944, 2304, 2944 }, | |
| 187 | + /*46*/{ 2048, 2560, 2048, 2560, 2560, 3200, 2560, 3200 }, /*47*/{ 2304, 2944, 2304, 2944, 2944, 3712, 2944, 3712 }, | |
| 188 | + /*48*/{ 2560, 3328, 2560, 3328, 3328, 4096, 3328, 4096 }, /*49*/{ 2816, 3584, 2816, 3584, 3584, 4608, 3584, 4608 }, | |
| 189 | + /*50*/{ 3328, 4096, 3328, 4096, 4096, 5120, 4096, 5120 }, /*51*/{ 3584, 4608, 3584, 4608, 4608, 5888, 4608, 5888 }, | |
| 190 | +}; | |
| 191 | + | |
| 192 | +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 193 | + | |
| 194 | +const uint8_t g_kuiIntra4x4CbpTable[48] = | |
| 195 | +{ | |
| 196 | + 47, 31, 15, 0, 23, 27, 29, 30, 7, 11, 13, 14, 39, 43, 45, 46, //15 | |
| 197 | + 16, 3, 5, 10, 12, 19, 21, 26, 28, 35, 37, 42, 44, 1, 2, 4, //31 | |
| 198 | + 8, 17, 18, 20, 24, 6, 9, 22, 25, 32, 33, 34, 36, 40, 38, 41 //47 | |
| 199 | +}; | |
| 200 | + | |
| 201 | +const uint8_t g_kuiInterCbpTable[48] = | |
| 202 | +{ | |
| 203 | + 0, 16, 1, 2, 4, 8, 32, 3, 5, 10, 12, 15, 47, 7, 11, 13, //15 | |
| 204 | + 14, 6, 9, 31, 35, 37, 42, 44, 33, 34, 36, 40, 39, 43, 45, 46, //31 | |
| 205 | + 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41 //47 | |
| 206 | +}; | |
| 207 | + | |
| 208 | +const uint8_t g_kuiLeadingZeroTable[256] = | |
| 209 | +{ | |
| 210 | + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, | |
| 211 | + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
| 212 | + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
| 213 | + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
| 214 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
| 215 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
| 216 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
| 217 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
| 218 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 219 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 220 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 221 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 222 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 223 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 224 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 225 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
| 226 | +}; | |
| 227 | + | |
| 228 | +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 229 | + | |
| 230 | +// extern at vlc_decoder.h | |
| 231 | + | |
| 232 | +const uint8_t g_kuiVlcChromaTable[256][2] = | |
| 233 | +{ | |
| 234 | + {13, 7}, {13, 7}, {12, 8}, {11, 8}, {8, 7}, {8, 7}, {7, 7}, {7, 7}, {10, 6}, {10, 6}, {10, 6}, {10, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, //15 | |
| 235 | + { 3, 6}, { 3, 6}, { 3, 6}, { 3, 6}, {9, 6}, {9, 6}, {9, 6}, {9, 6}, { 4, 6}, { 4, 6}, { 4, 6}, { 4, 6}, {1, 6}, {1, 6}, {1, 6}, {1, 6}, //31 | |
| 236 | + { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, {5, 3}, {5, 3}, {5, 3}, {5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, {5, 3}, {5, 3}, {5, 3}, {5, 3}, //47 | |
| 237 | + { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, {5, 3}, {5, 3}, {5, 3}, {5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, {5, 3}, {5, 3}, {5, 3}, {5, 3}, //63 | |
| 238 | + { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, //79 | |
| 239 | + { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, //95 | |
| 240 | + { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, //111 | |
| 241 | + { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, //127 | |
| 242 | + { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, //143 | |
| 243 | + { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, //159 | |
| 244 | + { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, //175 | |
| 245 | + { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, //191 | |
| 246 | + { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, //207 | |
| 247 | + { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, //223 | |
| 248 | + { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, //239 | |
| 249 | + { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1} //255 | |
| 250 | +}; | |
| 251 | + | |
| 252 | +const uint8_t g_kuiVlcTable_0[256][2] = //[0] means the index of vlc table, [1] means the length of vlc code [256] value means the value of 8bits | |
| 253 | +{ | |
| 254 | + { 0, 0}, { 0, 0}, { 0, 0}, {0, 0}, {21, 8}, {12, 8}, {7, 8}, {3, 8}, {17, 7}, {17, 7}, {8, 7}, {8, 7}, {13, 6}, {13, 6}, {13, 6}, {13, 6}, //15 | |
| 255 | + { 4, 6}, { 4, 6}, { 4, 6}, {4, 6}, { 1, 6}, { 1, 6}, {1, 6}, {1, 6}, { 9, 5}, { 9, 5}, {9, 5}, {9, 5}, { 9, 5}, { 9, 5}, { 9, 5}, { 9, 5}, //31 | |
| 256 | + { 5, 3}, { 5, 3}, { 5, 3}, {5, 3}, { 5, 3}, { 5, 3}, {5, 3}, {5, 3}, { 5, 3}, { 5, 3}, {5, 3}, {5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, //47 | |
| 257 | + { 5, 3}, { 5, 3}, { 5, 3}, {5, 3}, { 5, 3}, { 5, 3}, {5, 3}, {5, 3}, { 5, 3}, { 5, 3}, {5, 3}, {5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, //63 | |
| 258 | + { 2, 2}, { 2, 2}, { 2, 2}, {2, 2}, { 2, 2}, { 2, 2}, {2, 2}, {2, 2}, { 2, 2}, { 2, 2}, {2, 2}, {2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, //79 | |
| 259 | + { 2, 2}, { 2, 2}, { 2, 2}, {2, 2}, { 2, 2}, { 2, 2}, {2, 2}, {2, 2}, { 2, 2}, { 2, 2}, {2, 2}, {2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, //95 | |
| 260 | + { 2, 2}, { 2, 2}, { 2, 2}, {2, 2}, { 2, 2}, { 2, 2}, {2, 2}, {2, 2}, { 2, 2}, { 2, 2}, {2, 2}, {2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, //111 | |
| 261 | + { 2, 2}, { 2, 2}, { 2, 2}, {2, 2}, { 2, 2}, { 2, 2}, {2, 2}, {2, 2}, { 2, 2}, { 2, 2}, {2, 2}, {2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, //127 | |
| 262 | + { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, //143 | |
| 263 | + { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, //159 | |
| 264 | + { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, //175 | |
| 265 | + { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, //191 | |
| 266 | + { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, //207 | |
| 267 | + { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, //223 | |
| 268 | + { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, //239 | |
| 269 | + { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1} //255 | |
| 270 | +}; | |
| 271 | + | |
| 272 | +const uint8_t g_kuiVlcTable_0_0[256][2] = // read 8 bits // for g_kuiVlcTable_0[0] //checked no error-- | |
| 273 | +{ | |
| 274 | + { 0, 0}, { 0, 0}, {47, 7}, {47, 7}, {58, 8}, {60, 8}, {59, 8}, {54, 8}, {61, 8}, {56, 8}, {55, 8}, {50, 8}, {57, 8}, {52, 8}, {51, 8}, {46, 8}, //15 | |
| 275 | + {53, 7}, {53, 7}, {48, 7}, {48, 7}, {43, 7}, {43, 7}, {42, 7}, {42, 7}, {49, 7}, {49, 7}, {44, 7}, {44, 7}, {39, 7}, {39, 7}, {38, 7}, {38, 7}, //31 | |
| 276 | + {45, 6}, {45, 6}, {45, 6}, {45, 6}, {40, 6}, {40, 6}, {40, 6}, {40, 6}, {35, 6}, {35, 6}, {35, 6}, {35, 6}, {34, 6}, {34, 6}, {34, 6}, {34, 6}, //47 | |
| 277 | + {41, 6}, {41, 6}, {41, 6}, {41, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {31, 6}, {31, 6}, {31, 6}, {31, 6}, {30, 6}, {30, 6}, {30, 6}, {30, 6}, //63 | |
| 278 | + {26, 5}, {26, 5}, {26, 5}, {26, 5}, {26, 5}, {26, 5}, {26, 5}, {26, 5}, {32, 5}, {32, 5}, {32, 5}, {32, 5}, {32, 5}, {32, 5}, {32, 5}, {32, 5}, //79 | |
| 279 | + {27, 5}, {27, 5}, {27, 5}, {27, 5}, {27, 5}, {27, 5}, {27, 5}, {27, 5}, {22, 5}, {22, 5}, {22, 5}, {22, 5}, {22, 5}, {22, 5}, {22, 5}, {22, 5}, //95 | |
| 280 | + {37, 5}, {37, 5}, {37, 5}, {37, 5}, {37, 5}, {37, 5}, {37, 5}, {37, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, //111 | |
| 281 | + {23, 5}, {23, 5}, {23, 5}, {23, 5}, {23, 5}, {23, 5}, {23, 5}, {23, 5}, {18, 5}, {18, 5}, {18, 5}, {18, 5}, {18, 5}, {18, 5}, {18, 5}, {18, 5}, //127 | |
| 282 | + {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, //143 | |
| 283 | + {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, {33, 3}, //159 | |
| 284 | + {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, //175 | |
| 285 | + {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, {24, 3}, //191 | |
| 286 | + {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, //207 | |
| 287 | + {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, //223 | |
| 288 | + {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, //239 | |
| 289 | + {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3}, {14, 3} //255 | |
| 290 | +}; | |
| 291 | + | |
| 292 | +const uint8_t g_kuiVlcTable_0_1[4][2] = // read 2 bits // for g_kuiVlcTable_0[1] //checked no error-- | |
| 293 | +{ | |
| 294 | + {29, 2}, {20, 2}, {15, 2}, {10, 2} | |
| 295 | +}; | |
| 296 | + | |
| 297 | +const uint8_t g_kuiVlcTable_0_2[2][2] = // read 1 bit // for g_kuiVlcTable_0[2] //checked no error-- | |
| 298 | +{ | |
| 299 | + {25, 1}, {16, 1} | |
| 300 | +}; | |
| 301 | + | |
| 302 | +const uint8_t g_kuiVlcTable_0_3[2][2] = // read 1 bit // for g_kuiVlcTable_0[3] //checked no error-- | |
| 303 | +{ | |
| 304 | + {11, 1}, {6, 1} | |
| 305 | +}; | |
| 306 | + | |
| 307 | +const uint8_t g_kuiVlcTable_1[256][2] = //checked no error-- | |
| 308 | +{ | |
| 309 | + { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {14, 8}, {20, 8}, {19, 8}, {10, 8}, {29, 7}, {29, 7}, {16, 7}, {16, 7}, {15, 7}, {15, 7}, { 6, 7}, { 6, 7}, //15 | |
| 310 | + {25, 6}, {25, 6}, {25, 6}, {25, 6}, {12, 6}, {12, 6}, {12, 6}, {12, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, { 3, 6}, { 3, 6}, { 3, 6}, { 3, 6}, //31 | |
| 311 | + {21, 6}, {21, 6}, {21, 6}, {21, 6}, { 8, 6}, { 8, 6}, { 8, 6}, { 8, 6}, { 7, 6}, { 7, 6}, { 7, 6}, { 7, 6}, { 1, 6}, { 1, 6}, { 1, 6}, { 1, 6}, //47 | |
| 312 | + {17, 5}, {17, 5}, {17, 5}, {17, 5}, {17, 5}, {17, 5}, {17, 5}, {17, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, //63 | |
| 313 | + {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, //79 | |
| 314 | + { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, //95 | |
| 315 | + { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, //111 | |
| 316 | + { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, //127 | |
| 317 | + { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, //143 | |
| 318 | + { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, //159 | |
| 319 | + { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, //175 | |
| 320 | + { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, //191 | |
| 321 | + { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, //207 | |
| 322 | + { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, //223 | |
| 323 | + { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, //239 | |
| 324 | + { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2} //255 | |
| 325 | + | |
| 326 | +}; | |
| 327 | + | |
| 328 | +const uint8_t g_kuiVlcTable_1_0[64][2] = // read 6 bits // for g_kuiVlcTable_1[0] //checked no error-- | |
| 329 | +{ | |
| 330 | + { 0, 0}, { 0, 0}, {57, 5}, {57, 5}, {61, 6}, {60, 6}, {59, 6}, {58, 6}, {55, 6}, {54, 6}, {56, 6}, {51, 6}, {52, 5}, {52, 5}, {50, 5}, {50, 5}, //15 | |
| 331 | + {53, 5}, {53, 5}, {48, 5}, {48, 5}, {47, 5}, {47, 5}, {46, 5}, {46, 5}, {49, 5}, {49, 5}, {44, 5}, {44, 5}, {43, 5}, {43, 5}, {42, 5}, {42, 5}, //31 | |
| 332 | + {38, 4}, {38, 4}, {38, 4}, {38, 4}, {40, 4}, {40, 4}, {40, 4}, {40, 4}, {39, 4}, {39, 4}, {39, 4}, {39, 4}, {34, 4}, {34, 4}, {34, 4}, {34, 4}, //47 | |
| 333 | + {45, 4}, {45, 4}, {45, 4}, {45, 4}, {36, 4}, {36, 4}, {36, 4}, {36, 4}, {35, 4}, {35, 4}, {35, 4}, {35, 4}, {30, 4}, {30, 4}, {30, 4}, {30, 4} //63 | |
| 334 | +}; | |
| 335 | + | |
| 336 | +const uint8_t g_kuiVlcTable_1_1[8][2] = // read 3 bits // for g_kuiVlcTable_1[1] //checked no error-- | |
| 337 | +{ | |
| 338 | + {41, 3}, {32, 3}, {31, 3}, {26, 3}, {37, 3}, {28, 3}, {27, 3}, {22, 3} | |
| 339 | +}; | |
| 340 | + | |
| 341 | +const uint8_t g_kuiVlcTable_1_2[2][2] = // read 1 bit // for g_kuiVlcTable_1[2] //checked no error-- | |
| 342 | +{ | |
| 343 | + {33, 1}, {24, 1} | |
| 344 | +}; | |
| 345 | + | |
| 346 | +const uint8_t g_kuiVlcTable_1_3[2][2] = // read 1 bit // for g_kuiVlcTable_1[3] //checked no error-- | |
| 347 | +{ | |
| 348 | + {23, 1}, {18, 1} | |
| 349 | +}; | |
| 350 | + | |
| 351 | +const uint8_t g_kuiVlcTable_2[256][2] = //checked no error-- | |
| 352 | +{ | |
| 353 | + { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {45, 8}, {40, 8}, {35, 8}, {30, 8}, {41, 8}, {36, 8}, {31, 8}, {26, 8}, //15 | |
| 354 | + {22, 7}, {22, 7}, {18, 7}, {18, 7}, {32, 7}, {32, 7}, {14, 7}, {14, 7}, {37, 7}, {37, 7}, {28, 7}, {28, 7}, {27, 7}, {27, 7}, {10, 7}, {10, 7}, //31 | |
| 355 | + { 6, 6}, { 6, 6}, { 6, 6}, { 6, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {23, 6}, {23, 6}, {23, 6}, {23, 6}, { 3, 6}, { 3, 6}, { 3, 6}, { 3, 6}, //47 | |
| 356 | + {33, 6}, {33, 6}, {33, 6}, {33, 6}, {20, 6}, {20, 6}, {20, 6}, {20, 6}, {19, 6}, {19, 6}, {19, 6}, {19, 6}, { 1, 6}, { 1, 6}, { 1, 6}, { 1, 6}, //63 | |
| 357 | + {15, 5}, {15, 5}, {15, 5}, {15, 5}, {15, 5}, {15, 5}, {15, 5}, {15, 5}, {16, 5}, {16, 5}, {16, 5}, {16, 5}, {16, 5}, {16, 5}, {16, 5}, {16, 5}, //79 | |
| 358 | + {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, //95 | |
| 359 | + { 7, 5}, { 7, 5}, { 7, 5}, { 7, 5}, { 7, 5}, { 7, 5}, { 7, 5}, { 7, 5}, {29, 5}, {29, 5}, {29, 5}, {29, 5}, {29, 5}, {29, 5}, {29, 5}, {29, 5}, //111 | |
| 360 | + { 8, 5}, { 8, 5}, { 8, 5}, { 8, 5}, { 8, 5}, { 8, 5}, { 8, 5}, { 8, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, { 4, 5}, //127 | |
| 361 | + {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, {25, 4}, //143 | |
| 362 | + {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, {21, 4}, //159 | |
| 363 | + {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, {17, 4}, //175 | |
| 364 | + {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, {13, 4}, //191 | |
| 365 | + { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, { 9, 4}, //207 | |
| 366 | + { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, { 5, 4}, //223 | |
| 367 | + { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, //239 | |
| 368 | + { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4} //255 | |
| 369 | +}; | |
| 370 | + | |
| 371 | +const uint8_t g_kuiVlcTable_2_0[4][2] = // read 2 bits // for g_kuiVlcTable_2[0] //checked | |
| 372 | +{ | |
| 373 | + {0, 0}, {58, 2}, {61, 2}, {60, 2} | |
| 374 | +}; | |
| 375 | + | |
| 376 | + | |
| 377 | +const uint8_t g_kuiVlcTable_2_1[4][2] = // read 2 bits // for g_kuiVlcTable_2[1] //checked | |
| 378 | +{ | |
| 379 | + {59, 2}, {54, 2}, {57, 2}, {56, 2} | |
| 380 | +}; | |
| 381 | + | |
| 382 | +const uint8_t g_kuiVlcTable_2_2[4][2] = // read 2 bits // for g_kuiVlcTable_2[2] //checked | |
| 383 | +{ | |
| 384 | + {55, 2}, {50, 2}, {53, 2}, {52, 2} | |
| 385 | +}; | |
| 386 | + | |
| 387 | +const uint8_t g_kuiVlcTable_2_3[4][2] = // read 2 bits // for g_kuiVlcTable_2[3] //checked | |
| 388 | +{ | |
| 389 | + {51, 2}, {46, 2}, {47, 1}, {47, 1} | |
| 390 | +}; | |
| 391 | + | |
| 392 | +const uint8_t g_kuiVlcTable_2_4[2][2] = // read 1 bit // for g_kuiVlcTable_2[4] //checked | |
| 393 | +{ | |
| 394 | + {42, 1}, {48, 1} | |
| 395 | +}; | |
| 396 | + | |
| 397 | +const uint8_t g_kuiVlcTable_2_5[2][2] = // read 1 bit // for g_kuiVlcTable_2[5] //checked | |
| 398 | +{ | |
| 399 | + {43, 1}, {38, 1} | |
| 400 | +}; | |
| 401 | + | |
| 402 | +const uint8_t g_kuiVlcTable_2_6[2][2] = // read 1 bit // for g_kuiVlcTable_2[6] //checked no error-- | |
| 403 | +{ | |
| 404 | + {49, 1}, {44, 1} | |
| 405 | +}; | |
| 406 | + | |
| 407 | +const uint8_t g_kuiVlcTable_2_7[2][2] = // read 1 bit // for g_kuiVlcTable_2[7] //checked no error-- | |
| 408 | +{ | |
| 409 | + {39, 1}, {34, 1} | |
| 410 | +}; | |
| 411 | + | |
| 412 | +const uint8_t g_kuiVlcTable_3[64][2] = // read 6 bits //corrected | |
| 413 | +{ | |
| 414 | + { 1, 6}, { 2, 6}, { 0, 0}, { 0, 6}, { 3, 6}, { 4, 6}, { 5, 6}, { 0, 0}, { 6, 6}, { 7, 6}, { 8, 6}, { 9, 6}, {10, 6}, {11, 6}, {12, 6}, {13, 6}, //15 | |
| 415 | + {14, 6}, {15, 6}, {16, 6}, {17, 6}, {18, 6}, {19, 6}, {20, 6}, {21, 6}, {22, 6}, {23, 6}, {24, 6}, {25, 6}, {26, 6}, {27, 6}, {28, 6}, {29, 6}, //31 | |
| 416 | + {30, 6}, {31, 6}, {32, 6}, {33, 6}, {34, 6}, {35, 6}, {36, 6}, {37, 6}, {38, 6}, {39, 6}, {40, 6}, {41, 6}, {42, 6}, {43, 6}, {44, 6}, {45, 6}, //47 | |
| 417 | + {46, 6}, {47, 6}, {48, 6}, {49, 6}, {50, 6}, {51, 6}, {52, 6}, {53, 6}, {54, 6}, {55, 6}, {56, 6}, {57, 6}, {58, 6}, {59, 6}, {60, 6}, {61, 6}, //63 | |
| 418 | +}; | |
| 419 | + | |
| 420 | + | |
| 421 | +const uint8_t g_kuiVlcTableNeedMoreBitsThread[3] = | |
| 422 | +{ | |
| 423 | + 4, 4, 8 | |
| 424 | +}; | |
| 425 | + | |
| 426 | +const uint8_t g_kuiVlcTableMoreBitsCount0[4] = | |
| 427 | +{ | |
| 428 | + 8, 2, 1, 1 | |
| 429 | +}; | |
| 430 | + | |
| 431 | +const uint8_t g_kuiVlcTableMoreBitsCount1[4] = | |
| 432 | +{ | |
| 433 | + 6, 3, 1, 1 | |
| 434 | +}; | |
| 435 | + | |
| 436 | +const uint8_t g_kuiVlcTableMoreBitsCount2[8] = | |
| 437 | +{ | |
| 438 | + 2, 2, 2, 2, 1, 1, 1, 1 | |
| 439 | +}; | |
| 440 | + | |
| 441 | +const uint8_t g_kuiNcMapTable[17] = | |
| 442 | +{ | |
| 443 | + 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3 | |
| 444 | +}; | |
| 445 | + | |
| 446 | + | |
| 447 | +const uint8_t g_kuiVlcTrailingOneTotalCoeffTable[62][2] = | |
| 448 | +{ | |
| 449 | + {0, 0}, | |
| 450 | + {0, 1}, {1, 1}, | |
| 451 | + {0, 2}, {1, 2}, {2, 2}, | |
| 452 | + {0, 3}, {1, 3}, {2, 3}, {3, 3}, | |
| 453 | + {0, 4}, {1, 4}, {2, 4}, {3, 4}, | |
| 454 | + {0, 5}, {1, 5}, {2, 5}, {3, 5}, | |
| 455 | + {0, 6}, {1, 6}, {2, 6}, {3, 6}, | |
| 456 | + {0, 7}, {1, 7}, {2, 7}, {3, 7}, | |
| 457 | + {0, 8}, {1, 8}, {2, 8}, {3, 8}, | |
| 458 | + {0, 9}, {1, 9}, {2, 9}, {3, 9}, | |
| 459 | + {0, 10}, {1, 10}, {2, 10}, {3, 10}, | |
| 460 | + {0, 11}, {1, 11}, {2, 11}, {3, 11}, | |
| 461 | + {0, 12}, {1, 12}, {2, 12}, {3, 12}, | |
| 462 | + {0, 13}, {1, 13}, {2, 13}, {3, 13}, | |
| 463 | + {0, 14}, {1, 14}, {2, 14}, {3, 14}, | |
| 464 | + {0, 15}, {1, 15}, {2, 15}, {3, 15}, | |
| 465 | + {0, 16}, {1, 16}, {2, 16}, {3, 16} | |
| 466 | +}; | |
| 467 | + | |
| 468 | +const uint8_t g_kuiTotalZerosTable0[512][2] = //read 9 bits, generated by tzVlcIndex=1 in Table 9-7 in H.264/AVC standard | |
| 469 | +{ | |
| 470 | + {0, 0}, {15, 9}, {14, 9}, {13, 9}, {12, 8}, {12, 8}, {11, 8}, {11, 8}, {10, 7}, {10, 7}, {10, 7}, {10, 7}, {9, 7}, {9, 7}, {9, 7}, {9, 7}, //15 | |
| 471 | + {8, 6}, { 8, 6}, { 8, 6}, { 8, 6}, { 8, 6}, { 8, 6}, { 8, 6}, { 8, 6}, { 7, 6}, { 7, 6}, { 7, 6}, { 7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, //31 | |
| 472 | + {6, 5}, { 6, 5}, { 6, 5}, { 6, 5}, { 6, 5}, { 6, 5}, { 6, 5}, { 6, 5}, { 6, 5}, { 6, 5}, { 6, 5}, { 6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, //47 | |
| 473 | + {5, 5}, { 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}, {5, 5}, {5, 5}, {5, 5}, {5, 5}, //63 | |
| 474 | + {4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, //79 | |
| 475 | + {4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, //95 | |
| 476 | + {3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, {3, 4}, {3, 4}, {3, 4}, {3, 4}, //111 | |
| 477 | + {3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, { 3, 4}, {3, 4}, {3, 4}, {3, 4}, {3, 4}, //127 | |
| 478 | + {2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, //143 | |
| 479 | + {2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, //159 | |
| 480 | + {2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, //175 | |
| 481 | + {2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, //191 | |
| 482 | + {1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, //207 | |
| 483 | + {1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, //223 | |
| 484 | + {1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, //239 | |
| 485 | + {1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, //255 | |
| 486 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //271 | |
| 487 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //287 | |
| 488 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //303 | |
| 489 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //319 | |
| 490 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //335 | |
| 491 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //351 | |
| 492 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //367 | |
| 493 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //383 | |
| 494 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //399 | |
| 495 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //415 | |
| 496 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //431 | |
| 497 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //447 | |
| 498 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //463 | |
| 499 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //479 | |
| 500 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, //495 | |
| 501 | + {0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1} //511 | |
| 502 | +}; | |
| 503 | + | |
| 504 | +const uint8_t g_kuiTotalZerosTable1[64][2] = //read 6 bits, generated by tzVlcIndex=2 in Table 9-7 in H.264/AVC standard | |
| 505 | +{ | |
| 506 | + {14, 6}, {13, 6}, {12, 6}, {11, 6}, {10, 5}, {10, 5}, {9, 5}, {9, 5}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {7, 4}, {7, 4}, {7, 4}, {7, 4}, //15 | |
| 507 | + { 6, 4}, { 6, 4}, { 6, 4}, { 6, 4}, { 5, 4}, { 5, 4}, {5, 4}, {5, 4}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, //31 | |
| 508 | + { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, {3, 3}, {3, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, //47 | |
| 509 | + { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, { 1, 3}, {1, 3}, {1, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3} //63 | |
| 510 | +}; | |
| 511 | + | |
| 512 | +const uint8_t g_kuiTotalZerosTable2[64][2] = //read 6 bits, generated by tzVlcIndex=3 in Table 9-7 in H.264/AVC standard | |
| 513 | +{ | |
| 514 | + {13, 6}, {11, 6}, {12, 5}, {12, 5}, {10, 5}, {10, 5}, {9, 5}, {9, 5}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4}, //15 | |
| 515 | + { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 0, 4}, { 0, 4}, {0, 4}, {0, 4}, {7, 3}, {7, 3}, {7, 3}, {7, 3}, {7, 3}, {7, 3}, {7, 3}, {7, 3}, //31 | |
| 516 | + { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, {6, 3}, {6, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, //47 | |
| 517 | + { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3} //63 | |
| 518 | +}; | |
| 519 | + | |
| 520 | +const uint8_t g_kuiTotalZerosTable3[32][2] = //read 5 bits, generated by tzVlcIndex=4 in Table 9-7 in H.264/AVC standard | |
| 521 | +{ | |
| 522 | + {12, 5}, {11, 5}, {10, 5}, {0, 5}, {9, 4}, {9, 4}, {7, 4}, {7, 4}, {3, 4}, {3, 4}, {2, 4}, {2, 4}, {8, 3}, {8, 3}, {8, 3}, {8, 3}, //15 | |
| 523 | + { 6, 3}, { 6, 3}, { 6, 3}, {6, 3}, {5, 3}, {5, 3}, {5, 3}, {5, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, //31 | |
| 524 | +}; | |
| 525 | + | |
| 526 | +const uint8_t g_kuiTotalZerosTable4[32][2] = //read 5 bits, generated by tzVlcIndex=5 in Table 9-7 in H.264/AVC standard | |
| 527 | +{ | |
| 528 | + {11, 5}, { 9, 5}, {10, 4}, {10, 4}, { 8, 4}, { 8, 4}, { 2, 4}, { 2, 4}, { 1, 4}, { 1, 4}, { 0, 4}, { 0, 4}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, //15 | |
| 529 | + { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3} //31 | |
| 530 | +}; | |
| 531 | + | |
| 532 | +const uint8_t g_kuiTotalZerosTable5[64][2] = //read 6 bits, generated by tzVlcIndex=6 in Table 9-7 in H.264/AVC standard | |
| 533 | +{ | |
| 534 | + {10, 6}, { 0, 6}, { 1, 5}, { 1, 5}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, //15 | |
| 535 | + { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, //31 | |
| 536 | + { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, //47 | |
| 537 | + { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3} //63 | |
| 538 | +}; | |
| 539 | + | |
| 540 | +const uint8_t g_kuiTotalZerosTable6[64][2] = //read 6 bits, generated by tzVlcIndex=7 in Table 9-7 in H.264/AVC standard | |
| 541 | +{ | |
| 542 | + { 9, 6}, { 0, 6}, { 1, 5}, { 1, 5}, { 7, 4}, { 7, 4}, { 7, 4}, { 7, 4}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, //15 | |
| 543 | + { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, { 4, 3}, //31 | |
| 544 | + { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, //47 | |
| 545 | + { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2} //63 | |
| 546 | +}; | |
| 547 | + | |
| 548 | +const uint8_t g_kuiTotalZerosTable7[64][2] = //read 6 bits, generated by tzVlcIndex=8 in Table 9-7 in H.264/AVC standard | |
| 549 | +{ | |
| 550 | + { 8, 6}, { 0, 6}, { 2, 5}, { 2, 5}, { 1, 4}, { 1, 4}, { 1, 4}, { 1, 4}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, { 7, 3}, //15 | |
| 551 | + { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 6, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, { 3, 3}, //31 | |
| 552 | + { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, //47 | |
| 553 | + { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2} //63 | |
| 554 | +}; | |
| 555 | + | |
| 556 | +const uint8_t g_kuiTotalZerosTable8[64][2] = //read 6 bits, generated by tzVlcIndex=9 in Table 9-7 in H.264/AVC standard | |
| 557 | +{ | |
| 558 | + { 1, 6}, { 0, 6}, { 7, 5}, { 7, 5}, { 2, 4}, { 2, 4}, { 2, 4}, { 2, 4}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, { 5, 3}, //15 | |
| 559 | + { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, //31 | |
| 560 | + { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, //47 | |
| 561 | + { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2} //63 | |
| 562 | +}; | |
| 563 | + | |
| 564 | +const uint8_t g_kuiTotalZerosTable9[32][2] = //read 5 bits, generated by tzVlcIndex=10 in Table 9-7 in H.264/AVC standard | |
| 565 | +{ | |
| 566 | + { 1, 5}, { 0, 5}, { 6, 4}, { 6, 4}, { 2, 3}, { 2, 3}, { 2, 3}, { 2, 3}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, { 5, 2}, //15 | |
| 567 | + { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 4, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2}, { 3, 2} //31 | |
| 568 | +}; | |
| 569 | + | |
| 570 | +const uint8_t g_kuiTotalZerosTable10[16][2] = //read 4 bits, generated by tzVlcIndex=11 in Table 9-7 in H.264/AVC standard | |
| 571 | +{ | |
| 572 | + { 0, 4}, { 1, 4}, { 2, 3}, { 2, 3}, { 3, 3}, { 3, 3}, { 5, 3}, { 5, 3}, { 4, 1}, { 4, 1}, { 4, 1}, { 4, 1}, { 4, 1}, { 4, 1}, { 4, 1}, { 4, 1} //15 | |
| 573 | +}; | |
| 574 | + | |
| 575 | +const uint8_t g_kuiTotalZerosTable11[16][2] = //read 4 bits, generated by tzVlcIndex=12 in Table 9-7 in H.264/AVC standard | |
| 576 | +{ | |
| 577 | + { 0, 4}, { 1, 4}, { 4, 3}, { 4, 3}, { 2, 2}, { 2, 2}, { 2, 2}, { 2, 2}, { 3, 1}, { 3, 1}, { 3, 1}, { 3, 1}, { 3, 1}, { 3, 1}, { 3, 1}, { 3, 1} //15 | |
| 578 | +}; | |
| 579 | + | |
| 580 | +const uint8_t g_kuiTotalZerosTable12[8][2] = //read 3 bits, generated by tzVlcIndex=13 in Table 9-7 in H.264/AVC standard | |
| 581 | +{ | |
| 582 | + { 0, 3}, { 1, 3}, { 3, 2}, { 3, 2}, { 2, 1}, { 2, 1}, { 2, 1}, { 2, 1} //8 | |
| 583 | +}; | |
| 584 | + | |
| 585 | +const uint8_t g_kuiTotalZerosTable13[4][2] = //read 2 bits, generated by tzVlcIndex=14 in Table 9-7 in H.264/AVC standard | |
| 586 | +{ | |
| 587 | + { 0, 2}, { 1, 2}, { 2, 1}, { 2, 1} | |
| 588 | +}; | |
| 589 | + | |
| 590 | +const uint8_t g_kuiTotalZerosTable14[2][2] = //read 1 bits generated by tzVlcIndex=15 in Table 9-7 in H.264/AVC standard | |
| 591 | +{ | |
| 592 | + { 0, 1}, { 1, 1} | |
| 593 | +}; | |
| 594 | + | |
| 595 | +const uint8_t g_kuiTotalZerosBitNumMap[15] = | |
| 596 | +{ | |
| 597 | + 9, 6, 6, 5, 5, 6, 6, 6, 6, 5, 4, 4, 3, 2, 1 | |
| 598 | +}; | |
| 599 | + | |
| 600 | + | |
| 601 | +const uint8_t g_kuiTotalZerosChromaTable0[8][2] = //read 3 bits, generated by tzVlcIndex=1 in Table 9-9(a) in H.264/AVC standard | |
| 602 | +{ | |
| 603 | + { 3, 3}, { 2, 3}, { 1, 2}, { 1, 2}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1} | |
| 604 | +}; | |
| 605 | + | |
| 606 | +const uint8_t g_kuiTotalZerosChromaTable1[4][2] = //read 2 bits, generated by tzVlcIndex=2 in Table 9-9(a) in H.264/AVC standard | |
| 607 | +{ | |
| 608 | + { 2, 2}, { 1, 2}, { 0, 1}, { 0, 1} | |
| 609 | +}; | |
| 610 | + | |
| 611 | +const uint8_t g_kuiTotalZerosChromaTable2[2][2] = //read 1 bits, generated by tzVlcIndex=3 in Table 9-9(a) in H.264/AVC standard | |
| 612 | +{ | |
| 613 | + { 1, 1}, { 0, 1} | |
| 614 | +}; | |
| 615 | + | |
| 616 | +const uint8_t g_kuiTotalZerosBitNumChromaMap[3] = | |
| 617 | +{ | |
| 618 | + 3, 2, 1 | |
| 619 | +}; | |
| 620 | + | |
| 621 | +const uint8_t g_kuiZeroLeftTable0[2][2] = //read 1 bits | |
| 622 | +{ | |
| 623 | + {1, 1}, {0, 1} | |
| 624 | +}; | |
| 625 | + | |
| 626 | +const uint8_t g_kuiZeroLeftTable1[4][2] = //read 2 bits | |
| 627 | +{ | |
| 628 | + {2, 2}, {1, 2}, {0, 1}, {0, 1} | |
| 629 | +}; | |
| 630 | + | |
| 631 | +const uint8_t g_kuiZeroLeftTable2[4][2] = //read 2 bits | |
| 632 | +{ | |
| 633 | + {3, 2}, {2, 2}, {1, 2}, {0, 2} | |
| 634 | +}; | |
| 635 | + | |
| 636 | +const uint8_t g_kuiZeroLeftTable3[8][2] = //read 3 bits | |
| 637 | +{ | |
| 638 | + {4, 3}, {3, 3}, {2, 2}, {2, 2}, {1, 2}, {1, 2}, {0, 2}, {0, 2} | |
| 639 | +}; | |
| 640 | + | |
| 641 | +const uint8_t g_kuiZeroLeftTable4[8][2] = //read 3 bits | |
| 642 | +{ | |
| 643 | + {5, 3}, {4, 3}, {3, 3}, {2, 3}, {1, 2}, {1, 2}, {0, 2}, {0, 2} | |
| 644 | +}; | |
| 645 | + | |
| 646 | +const uint8_t g_kuiZeroLeftTable5[8][2] = //read 3 bits | |
| 647 | +{ | |
| 648 | + {1, 3}, {2, 3}, {4, 3}, {3, 3}, {6, 3}, {5, 3}, {0, 2}, {0, 2} | |
| 649 | +}; | |
| 650 | + | |
| 651 | +const uint8_t g_kuiZeroLeftTable6[8][2] = //read 3 bits | |
| 652 | +{ | |
| 653 | + {7, 3}, {6, 3}, {5, 3}, {4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3} | |
| 654 | +}; | |
| 655 | + | |
| 656 | +const uint8_t g_kuiZeroLeftBitNumMap[16] = | |
| 657 | +{ | |
| 658 | + 0, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 | |
| 659 | +}; | |
| 660 | + | |
| 661 | +} // namespace WelsDec | |
| @@ -0,0 +1,165 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | + | |
| 33 | +#include <string.h> | |
| 34 | + | |
| 35 | +#include "typedefs.h" | |
| 36 | +#include "expand_pic.h" | |
| 37 | +#include "cpu_core.h" | |
| 38 | + | |
| 39 | +namespace WelsDec { | |
| 40 | + | |
| 41 | +// rewrite it (split into luma & chroma) that is helpful for mmx/sse2 optimization perform, 9/27/2009 | |
| 42 | +static inline void_t ExpandPictureLuma_c( uint8_t *pDst, const int32_t kiStride, const int32_t kiPicWidth, const int32_t kiPicHeight ) | |
| 43 | +{ | |
| 44 | + uint8_t *pTmp = pDst; | |
| 45 | + uint8_t *pDstLastLine = pTmp + (kiPicHeight-1) * kiStride; | |
| 46 | + const int32_t kiPaddingLen = PADDING_LENGTH; | |
| 47 | + const uint8_t kuiTopLeft = pTmp[0]; | |
| 48 | + const uint8_t kuiTopRight = pTmp[kiPicWidth-1]; | |
| 49 | + const uint8_t kuiBottomLeft = pDstLastLine[0]; | |
| 50 | + const uint8_t kuiBottomRight= pDstLastLine[kiPicWidth-1]; | |
| 51 | + int32_t i = 0; | |
| 52 | + | |
| 53 | + do { | |
| 54 | + const int32_t kiStrides = (1+i) * kiStride; | |
| 55 | + uint8_t* pTop = pTmp - kiStrides; | |
| 56 | + uint8_t* pBottom = pDstLastLine + kiStrides; | |
| 57 | + | |
| 58 | + // pad pTop and pBottom | |
| 59 | + memcpy(pTop, pTmp, kiPicWidth); | |
| 60 | + memcpy(pBottom, pDstLastLine, kiPicWidth); | |
| 61 | + | |
| 62 | + // pad corners | |
| 63 | + memset(pTop-kiPaddingLen, kuiTopLeft, kiPaddingLen); //pTop left | |
| 64 | + memset(pTop+kiPicWidth, kuiTopRight, kiPaddingLen); //pTop right | |
| 65 | + memset(pBottom-kiPaddingLen, kuiBottomLeft, kiPaddingLen); //pBottom left | |
| 66 | + memset(pBottom+kiPicWidth, kuiBottomRight, kiPaddingLen); //pBottom right | |
| 67 | + | |
| 68 | + ++ i; | |
| 69 | + } while( i < kiPaddingLen ); | |
| 70 | + | |
| 71 | + // pad left and right | |
| 72 | + i = 0; | |
| 73 | + do { | |
| 74 | + memset(pTmp-kiPaddingLen, pTmp[0], kiPaddingLen); | |
| 75 | + memset(pTmp+kiPicWidth, pTmp[kiPicWidth-1], kiPaddingLen); | |
| 76 | + | |
| 77 | + pTmp += kiStride; | |
| 78 | + ++ i; | |
| 79 | + } while( i < kiPicHeight ); | |
| 80 | +} | |
| 81 | + | |
| 82 | +static inline void_t ExpandPictureChroma_c( uint8_t *pDst, const int32_t kiStride, const int32_t kiPicWidth, const int32_t kiPicHeight ) | |
| 83 | +{ | |
| 84 | + uint8_t *pTmp = pDst; | |
| 85 | + uint8_t *pDstLastLine = pTmp + (kiPicHeight-1) * kiStride; | |
| 86 | + const int32_t kiPaddingLen = (PADDING_LENGTH>>1); | |
| 87 | + const uint8_t kuiTopLeft = pTmp[0]; | |
| 88 | + const uint8_t kuiTopRight = pTmp[kiPicWidth-1]; | |
| 89 | + const uint8_t kuiBottomLeft = pDstLastLine[0]; | |
| 90 | + const uint8_t kuiBottomRight= pDstLastLine[kiPicWidth-1]; | |
| 91 | + int32_t i = 0; | |
| 92 | + | |
| 93 | + do { | |
| 94 | + const int32_t kiStrides = (1+i) * kiStride; | |
| 95 | + uint8_t* pTop = pTmp - kiStrides; | |
| 96 | + uint8_t* pBottom = pDstLastLine + kiStrides; | |
| 97 | + | |
| 98 | + // pad pTop and pBottom | |
| 99 | + memcpy(pTop, pTmp, kiPicWidth); | |
| 100 | + memcpy(pBottom, pDstLastLine, kiPicWidth); | |
| 101 | + | |
| 102 | + // pad corners | |
| 103 | + memset(pTop-kiPaddingLen, kuiTopLeft, kiPaddingLen); //pTop left | |
| 104 | + memset(pTop+kiPicWidth, kuiTopRight, kiPaddingLen); //pTop right | |
| 105 | + memset(pBottom-kiPaddingLen, kuiBottomLeft, kiPaddingLen); //pBottom left | |
| 106 | + memset(pBottom+kiPicWidth, kuiBottomRight, kiPaddingLen); //pBottom right | |
| 107 | + | |
| 108 | + ++ i; | |
| 109 | + } while( i < kiPaddingLen ); | |
| 110 | + | |
| 111 | + // pad left and right | |
| 112 | + i = 0; | |
| 113 | + do { | |
| 114 | + memset(pTmp-kiPaddingLen, pTmp[0], kiPaddingLen); | |
| 115 | + memset(pTmp+kiPicWidth, pTmp[kiPicWidth-1], kiPaddingLen); | |
| 116 | + | |
| 117 | + pTmp += kiStride; | |
| 118 | + ++ i; | |
| 119 | + } while( i < kiPicHeight ); | |
| 120 | +} | |
| 121 | + | |
| 122 | +void_t InitExpandPictureFunc( SExpandPicFunc *pExpandPicFunc, const uint32_t kuiCpuFlags ) | |
| 123 | +{ | |
| 124 | + pExpandPicFunc->pExpandLumaPicture = ExpandPictureLuma_c; | |
| 125 | + pExpandPicFunc->pExpandChromaPicture[0] = ExpandPictureChroma_c; | |
| 126 | + pExpandPicFunc->pExpandChromaPicture[1] = ExpandPictureChroma_c; | |
| 127 | + | |
| 128 | +#if defined(X86_ASM) | |
| 129 | + if ( (kuiCpuFlags & WELS_CPU_SSE2) == WELS_CPU_SSE2 ) | |
| 130 | + { | |
| 131 | + pExpandPicFunc->pExpandLumaPicture = ExpandPictureLuma_sse2; | |
| 132 | + pExpandPicFunc->pExpandChromaPicture[0] = ExpandPictureChromaUnalign_sse2; | |
| 133 | + pExpandPicFunc->pExpandChromaPicture[1] = ExpandPictureChromaAlign_sse2; | |
| 134 | + } | |
| 135 | +#endif//X86_ASM | |
| 136 | +} | |
| 137 | + | |
| 138 | +void_t ExpandReferencingPicture(PPicture pPic, PExpandPictureFunc pExpLuma, PExpandPictureFunc pExpChroma[2]) | |
| 139 | +{ | |
| 140 | + /*local variable*/ | |
| 141 | + uint8_t *pPicY = pPic->pData[0]; | |
| 142 | + uint8_t *pPicCb = pPic->pData[1]; | |
| 143 | + uint8_t *pPicCr = pPic->pData[2]; | |
| 144 | + const int32_t kiWidthY = pPic->iWidthInPixel; | |
| 145 | + const int32_t kiHeightY = pPic->iHeightInPixel; | |
| 146 | + const int32_t kiWidthUV = kiWidthY >> 1; | |
| 147 | + const int32_t kiHeightUV= kiHeightY >> 1; | |
| 148 | + | |
| 149 | + pExpLuma(pPicY, pPic->iLinesize[0], kiWidthY, kiHeightY); | |
| 150 | + if ( kiWidthUV >= 16 ) | |
| 151 | + { | |
| 152 | + // fix coding picture size as 16x16 issues 7/27/2010 | |
| 153 | + const bool_t kbChrAligned= /*(kiWidthUV >= 16) && */((kiWidthUV & 0x0F) == 0); // chroma planes: (16+kiWidthUV) & 15 | |
| 154 | + pExpChroma[kbChrAligned](pPicCb, pPic->iLinesize[1], kiWidthUV, kiHeightUV); | |
| 155 | + pExpChroma[kbChrAligned](pPicCr, pPic->iLinesize[2], kiWidthUV, kiHeightUV); | |
| 156 | + } | |
| 157 | + else | |
| 158 | + { | |
| 159 | + // fix coding picture size as 16x16 issues 7/27/2010 | |
| 160 | + ExpandPictureChroma_c(pPicCb, pPic->iLinesize[1], kiWidthUV, kiHeightUV); | |
| 161 | + ExpandPictureChroma_c(pPicCr, pPic->iLinesize[2], kiWidthUV, kiHeightUV); | |
| 162 | + } | |
| 163 | +} | |
| 164 | + | |
| 165 | +} // namespace WelsDec | |
| @@ -0,0 +1,355 @@ | ||
| 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 fmo.c | |
| 33 | + * | |
| 34 | + * \brief Flexible Macroblock Ordering implementation | |
| 35 | + * | |
| 36 | + * \date 2/4/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#include <string.h> | |
| 41 | + | |
| 42 | +#include "fmo.h" | |
| 43 | +#include "macros.h" | |
| 44 | +#include "utils.h" | |
| 45 | +#include "mem_align.h" | |
| 46 | + | |
| 47 | +namespace WelsDec { | |
| 48 | + | |
| 49 | +/*! | |
| 50 | + * \brief Generate MB allocated map for interleaved slice group (TYPE 0) | |
| 51 | + * | |
| 52 | + * \param pFmo fmo context | |
| 53 | + * \param pPps pps context | |
| 54 | + * | |
| 55 | + * \return 0 - successful; none 0 - failed | |
| 56 | + */ | |
| 57 | +static inline int32_t FmoGenerateMbAllocMapType0( PFmo pFmo, PPps pPps ) | |
| 58 | +{ | |
| 59 | + uint32_t uiNumSliceGroups = 0; | |
| 60 | + int32_t iMbNum = 0; | |
| 61 | + int32_t i = 0; | |
| 62 | + | |
| 63 | + WELS_VERIFY_RETURN_IF( 1, ( NULL == pFmo || NULL == pPps ) ) | |
| 64 | + uiNumSliceGroups = pPps->uiNumSliceGroups; | |
| 65 | + iMbNum = pFmo->iCountMbNum; | |
| 66 | + WELS_VERIFY_RETURN_IF( 1, ( NULL == pFmo->pMbAllocMap || iMbNum <= 0 || uiNumSliceGroups >= MAX_SLICEGROUP_IDS ) ) | |
| 67 | + | |
| 68 | + do | |
| 69 | + { | |
| 70 | + uint8_t uiGroup = 0; | |
| 71 | + do { | |
| 72 | + const int32_t kiRunIdx = pPps->uiRunLength[uiGroup]; | |
| 73 | + int32_t j = 0; | |
| 74 | + do { | |
| 75 | + pFmo->pMbAllocMap[i+j] = uiGroup; | |
| 76 | + ++ j; | |
| 77 | + } while(j < kiRunIdx && i + j < iMbNum); | |
| 78 | + i += kiRunIdx; | |
| 79 | + ++ uiGroup; | |
| 80 | + } while(uiGroup < uiNumSliceGroups && i < iMbNum); | |
| 81 | + }while(i < iMbNum); | |
| 82 | + | |
| 83 | + return 0; // well here | |
| 84 | +} | |
| 85 | + | |
| 86 | +/*! | |
| 87 | + * \brief Generate MB allocated map for dispersed slice group (TYPE 1) | |
| 88 | + * | |
| 89 | + * \param pFmo fmo context | |
| 90 | + * \param pPps pps context | |
| 91 | + * \param iMbWidth MB width | |
| 92 | + * | |
| 93 | + * \return 0 - successful; none 0 - failed | |
| 94 | + */ | |
| 95 | +static inline int32_t FmoGenerateMbAllocMapType1( PFmo pFmo, PPps pPps, const int32_t kiMbWidth ) | |
| 96 | +{ | |
| 97 | + uint32_t uiNumSliceGroups = 0; | |
| 98 | + int32_t iMbNum = 0; | |
| 99 | + int16_t i = 0; | |
| 100 | + WELS_VERIFY_RETURN_IF( 1, ( NULL == pFmo || NULL == pPps ) ) | |
| 101 | + uiNumSliceGroups = pPps->uiNumSliceGroups; | |
| 102 | + iMbNum = pFmo->iCountMbNum; | |
| 103 | + WELS_VERIFY_RETURN_IF( 1, ( NULL == pFmo->pMbAllocMap || iMbNum <= 0 || kiMbWidth == 0 || uiNumSliceGroups >= MAX_SLICEGROUP_IDS ) ) | |
| 104 | + | |
| 105 | + do | |
| 106 | + { | |
| 107 | + pFmo->pMbAllocMap[i] = (uint8_t)(((i % kiMbWidth)+(((i / kiMbWidth)*uiNumSliceGroups)>>1)) % uiNumSliceGroups); | |
| 108 | + ++ i; | |
| 109 | + }while (i < iMbNum); | |
| 110 | + | |
| 111 | + return 0; // well here | |
| 112 | +} | |
| 113 | + | |
| 114 | +/*! | |
| 115 | + * \brief Generate MB allocated map for various type of slice group cases (TYPE 0, .., 6) | |
| 116 | + * | |
| 117 | + * \param pFmo fmo context | |
| 118 | + * \param pPps pps context | |
| 119 | + * \param kiMbWidth MB width | |
| 120 | + * \param kiMbHeight MB height | |
| 121 | + * | |
| 122 | + * \return 0 - successful; none 0 - failed | |
| 123 | + */ | |
| 124 | +static inline int32_t FmoGenerateSliceGroup( PFmo pFmo, const PPps kpPps, const int32_t kiMbWidth, const int32_t kiMbHeight ) | |
| 125 | +{ | |
| 126 | + int32_t iNumMb = 0; | |
| 127 | + int32_t iErr = 0; | |
| 128 | + bool_t bResolutionChanged = false; | |
| 129 | + | |
| 130 | + // the cases we would not like | |
| 131 | + WELS_VERIFY_RETURN_IF( 1, ( NULL == pFmo || NULL == kpPps ) ) | |
| 132 | + | |
| 133 | + iNumMb = pFmo->iCountMbNum; | |
| 134 | + | |
| 135 | + iNumMb = kiMbWidth * kiMbHeight; | |
| 136 | + | |
| 137 | + if ( 0 == iNumMb ) | |
| 138 | + return 1; | |
| 139 | + | |
| 140 | + | |
| 141 | + WelsFree(pFmo->pMbAllocMap, "_fmo->pMbAllocMap"); | |
| 142 | + pFmo->pMbAllocMap = (uint8_t *)WelsMalloc( iNumMb * sizeof(uint8_t), "_fmo->pMbAllocMap" ); | |
| 143 | + WELS_VERIFY_RETURN_IF( 1, (NULL == pFmo->pMbAllocMap) ) // out of memory | |
| 144 | + | |
| 145 | + pFmo->iCountMbNum = iNumMb; | |
| 146 | + | |
| 147 | + if ( kpPps->uiNumSliceGroups < 2 && iNumMb > 0) // only one slice group, exactly it is single slice based | |
| 148 | + { | |
| 149 | + memset ( pFmo->pMbAllocMap, 0, iNumMb * sizeof(int8_t)); // for safe | |
| 150 | + | |
| 151 | + pFmo->iSliceGroupCount = 1; | |
| 152 | + | |
| 153 | + return 0; | |
| 154 | + } | |
| 155 | + | |
| 156 | + if ( bResolutionChanged || ((int32_t)kpPps->uiSliceGroupMapType != pFmo->iSliceGroupType) | |
| 157 | + || ((int32_t)kpPps->uiNumSliceGroups != pFmo->iSliceGroupCount) ) | |
| 158 | + { | |
| 159 | + switch ( kpPps->uiSliceGroupMapType ) | |
| 160 | + { | |
| 161 | + case 0: | |
| 162 | + iErr = FmoGenerateMbAllocMapType0( pFmo, kpPps ); | |
| 163 | + break; | |
| 164 | + case 1: | |
| 165 | + iErr = FmoGenerateMbAllocMapType1( pFmo, kpPps, kiMbWidth ); | |
| 166 | + break; | |
| 167 | + case 2: | |
| 168 | + case 3: | |
| 169 | + case 4: | |
| 170 | + case 5: | |
| 171 | + case 6: | |
| 172 | + // Reserve for others slice group type | |
| 173 | + iErr = 1; | |
| 174 | + break; | |
| 175 | + default: | |
| 176 | + return 1; | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + if ( 0 == iErr ) // well now | |
| 181 | + { | |
| 182 | + pFmo->iSliceGroupCount = kpPps->uiNumSliceGroups; | |
| 183 | + pFmo->iSliceGroupType = kpPps->uiSliceGroupMapType; | |
| 184 | + } | |
| 185 | + | |
| 186 | + return iErr; | |
| 187 | +} | |
| 188 | + | |
| 189 | +/*! | |
| 190 | + * \brief Initialize Wels Flexible Macroblock Ordering (FMO) | |
| 191 | + * | |
| 192 | + * \param pFmo Wels fmo to be initialized | |
| 193 | + * \param pPps pps argument | |
| 194 | + * \param kiMbWidth mb width | |
| 195 | + * \param kiMbHeight mb height | |
| 196 | + * | |
| 197 | + * \return 0 - successful; none 0 - failed; | |
| 198 | + */ | |
| 199 | +int32_t InitFmo( PFmo pFmo, PPps pPps, const int32_t kiMbWidth, const int32_t kiMbHeight ) | |
| 200 | +{ | |
| 201 | + return FmoGenerateSliceGroup( pFmo, pPps, kiMbWidth, kiMbHeight ); | |
| 202 | +} | |
| 203 | + | |
| 204 | + | |
| 205 | +/*! | |
| 206 | + * \brief Uninitialize Wels Flexible Macroblock Ordering (FMO) list | |
| 207 | + * | |
| 208 | + * \param pFmo Wels base fmo ptr to be uninitialized | |
| 209 | + * \param kiCnt count number of PPS per list | |
| 210 | + * \param kiAvail count available number of PPS in list | |
| 211 | + * | |
| 212 | + * \return NONE | |
| 213 | + */ | |
| 214 | +void_t UninitFmoList( PFmo pFmo, const int32_t kiCnt, const int32_t kiAvail ) | |
| 215 | +{ | |
| 216 | + PFmo pIter = pFmo; | |
| 217 | + int32_t i = 0; | |
| 218 | + int32_t iFreeNodes = 0; | |
| 219 | + | |
| 220 | + if ( NULL == pIter || kiAvail <= 0 || kiCnt < kiAvail ) | |
| 221 | + return; | |
| 222 | + | |
| 223 | + while ( i < kiCnt ) { | |
| 224 | + if ( pIter != NULL && pIter->bActiveFlag ) | |
| 225 | + { | |
| 226 | + if ( NULL != pIter->pMbAllocMap ) | |
| 227 | + { | |
| 228 | + WelsFree( pIter->pMbAllocMap, "pIter->pMbAllocMap" ); | |
| 229 | + | |
| 230 | + pIter->pMbAllocMap = NULL; | |
| 231 | + } | |
| 232 | + pIter->iSliceGroupCount = 0; | |
| 233 | + pIter->iSliceGroupType = -1; | |
| 234 | + pIter->iCountMbNum = 0; | |
| 235 | + pIter->bActiveFlag = false; | |
| 236 | + ++ iFreeNodes; | |
| 237 | + if ( iFreeNodes >= kiAvail ) | |
| 238 | + break; | |
| 239 | + } | |
| 240 | + ++ pIter; | |
| 241 | + ++ i; | |
| 242 | + } | |
| 243 | +} | |
| 244 | + | |
| 245 | +/*! | |
| 246 | + * \brief detect parameter sets are changed or not | |
| 247 | + * | |
| 248 | + * \param pFmo fmo context | |
| 249 | + * \param kiCountNumMb (iMbWidth * iMbHeight) in Sps | |
| 250 | + * \param iSliceGroupType slice group type if fmo is exactly enabled | |
| 251 | + * \param iSliceGroupCount slice group count if fmo is exactly enabled | |
| 252 | + * | |
| 253 | + * \return true - changed or not initialized yet; false - not change at all | |
| 254 | + */ | |
| 255 | +bool_t FmoParamSetsChanged( PFmo pFmo, const int32_t kiCountNumMb, const int32_t kiSliceGroupType, const int32_t kiSliceGroupCount ) | |
| 256 | +{ | |
| 257 | + WELS_VERIFY_RETURN_IF( false, (NULL == pFmo) ) | |
| 258 | + | |
| 259 | + return ( (!pFmo->bActiveFlag) | |
| 260 | + || (kiCountNumMb != pFmo->iCountMbNum) | |
| 261 | + || (kiSliceGroupType != pFmo->iSliceGroupType) | |
| 262 | + || (kiSliceGroupCount != pFmo->iSliceGroupCount) ); | |
| 263 | +} | |
| 264 | + | |
| 265 | +/*! | |
| 266 | + * \brief update/insert FMO parameter unit | |
| 267 | + * | |
| 268 | + * \param _fmo FMO context | |
| 269 | + * \param _sps PSps | |
| 270 | + * \param _pps PPps | |
| 271 | + * \param pActiveFmoNum int32_t* [in/out] | |
| 272 | + * | |
| 273 | + * \return true - update/insert successfully; false - failed; | |
| 274 | + */ | |
| 275 | +bool_t FmoParamUpdate( PFmo pFmo, PSps pSps, PPps pPps, int32_t *pActiveFmoNum ) | |
| 276 | +{ | |
| 277 | + const uint32_t kuiMbWidth = pSps->iMbWidth; | |
| 278 | + const uint32_t kuiMbHeight= pSps->iMbHeight; | |
| 279 | + | |
| 280 | + if ( FmoParamSetsChanged( pFmo, | |
| 281 | + kuiMbWidth * kuiMbHeight, | |
| 282 | + pPps->uiSliceGroupMapType, | |
| 283 | + pPps->uiNumSliceGroups ) ) | |
| 284 | + { | |
| 285 | + | |
| 286 | + if ( InitFmo( pFmo, pPps, kuiMbWidth, kuiMbHeight ) ) | |
| 287 | + { | |
| 288 | + return false; | |
| 289 | + } | |
| 290 | + else | |
| 291 | + { | |
| 292 | + if ( !pFmo->bActiveFlag && *pActiveFmoNum < MAX_PPS_COUNT ) | |
| 293 | + { | |
| 294 | + ++ (*pActiveFmoNum); | |
| 295 | + pFmo->bActiveFlag = true; | |
| 296 | + } | |
| 297 | + } | |
| 298 | + } | |
| 299 | + | |
| 300 | + return true; | |
| 301 | +} | |
| 302 | + | |
| 303 | +/*! | |
| 304 | + * \brief Convert kMbXy to slice group idc correspondingly | |
| 305 | + * | |
| 306 | + * \param pFmo Wels fmo context | |
| 307 | + * \param kMbXy kMbXy to be converted | |
| 308 | + * | |
| 309 | + * \return slice group idc - successful; -1 - failed; | |
| 310 | + */ | |
| 311 | +int32_t FmoMbToSliceGroup( PFmo pFmo, const MB_XY_T kiMbXy ) | |
| 312 | +{ | |
| 313 | + const int32_t kiMbNum = pFmo->iCountMbNum; | |
| 314 | + const uint8_t* kpMbMap = pFmo->pMbAllocMap; | |
| 315 | + | |
| 316 | + if ( kiMbXy < 0 || kiMbXy >= kiMbNum || kpMbMap == NULL) | |
| 317 | + return -1; | |
| 318 | + | |
| 319 | + return kpMbMap[ kiMbXy ]; | |
| 320 | +} | |
| 321 | + | |
| 322 | +/*! | |
| 323 | + * \brief Get successive mb to be processed with given current kMbXy | |
| 324 | + * | |
| 325 | + * \param pFmo Wels fmo context | |
| 326 | + * \param kMbXy current kMbXy | |
| 327 | + * | |
| 328 | + * \return iNextMb - successful; -1 - failed; | |
| 329 | + */ | |
| 330 | +MB_XY_T FmoNextMb( PFmo pFmo, const MB_XY_T kiMbXy ) | |
| 331 | +{ | |
| 332 | + const int32_t kiTotalMb = pFmo->iCountMbNum; | |
| 333 | + const uint8_t* kpMbMap = pFmo->pMbAllocMap; | |
| 334 | + MB_XY_T iNextMb = kiMbXy; | |
| 335 | + const uint8_t kuiSliceGroupIdc = (uint8_t)FmoMbToSliceGroup( pFmo, kiMbXy ); | |
| 336 | + | |
| 337 | + if (kuiSliceGroupIdc == (uint8_t)(-1)) | |
| 338 | + return -1; | |
| 339 | + | |
| 340 | + do { | |
| 341 | + ++ iNextMb; | |
| 342 | + if (iNextMb >= kiTotalMb){ | |
| 343 | + iNextMb = -1; | |
| 344 | + break; | |
| 345 | + } | |
| 346 | + if (kpMbMap[iNextMb] == kuiSliceGroupIdc){ | |
| 347 | + break; | |
| 348 | + } | |
| 349 | + } while( 1 ); | |
| 350 | + | |
| 351 | + // -1: No further MB in this slice (could be end of picture) | |
| 352 | + return iNextMb; | |
| 353 | +} | |
| 354 | + | |
| 355 | +} // namespace WelsDec | |
| @@ -0,0 +1,700 @@ | ||
| 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 get_intra_predictor.c | |
| 33 | + * | |
| 34 | + * \brief implementation for get intra predictor about 16x16, 4x4, chroma. | |
| 35 | + * | |
| 36 | + * \date 4/2/2009 Created | |
| 37 | + * 9/14/2009 C level based optimization with high performance gained. | |
| 38 | + * [const, using ST32/ST64 to replace memset, memcpy and memmove etc.] | |
| 39 | + * | |
| 40 | + ************************************************************************************* | |
| 41 | + */ | |
| 42 | +#include <string.h> | |
| 43 | + | |
| 44 | +#include "macros.h" | |
| 45 | +#include "ls_defines.h" | |
| 46 | +#include "get_intra_predictor.h" | |
| 47 | + | |
| 48 | +namespace WelsDec { | |
| 49 | + | |
| 50 | +#define I4x4_COUNT 4 | |
| 51 | +#define I8x8_COUNT 8 | |
| 52 | +#define I16x16_COUNT 16 | |
| 53 | + | |
| 54 | +void_t WelsI4x4LumaPredV_c(uint8_t *pPred, const int32_t kiStride) | |
| 55 | +{ | |
| 56 | + const uint32_t kuiVal = LD32(pPred-kiStride); | |
| 57 | + | |
| 58 | + ST32( pPred , kuiVal ); | |
| 59 | + ST32( pPred+kiStride , kuiVal ); | |
| 60 | + ST32( pPred+(kiStride<<1) , kuiVal ); | |
| 61 | + ST32( pPred+(kiStride<<1)+kiStride , kuiVal ); | |
| 62 | +} | |
| 63 | + | |
| 64 | +void_t WelsI4x4LumaPredH_c(uint8_t *pPred, const int32_t kiStride) | |
| 65 | +{ | |
| 66 | + const int32_t kiStride2 = kiStride << 1; | |
| 67 | + const int32_t kiStride3 = kiStride2 + kiStride; | |
| 68 | + const uint32_t kuiL0 = 0x01010101U * pPred[-1 ]; | |
| 69 | + const uint32_t kuiL1 = 0x01010101U * pPred[-1+kiStride ]; | |
| 70 | + const uint32_t kuiL2 = 0x01010101U * pPred[-1+kiStride2]; | |
| 71 | + const uint32_t kuiL3 = 0x01010101U * pPred[-1+kiStride3]; | |
| 72 | + | |
| 73 | + ST32( pPred , kuiL0 ); | |
| 74 | + ST32( pPred+kiStride , kuiL1 ); | |
| 75 | + ST32( pPred+kiStride2, kuiL2 ); | |
| 76 | + ST32( pPred+kiStride3, kuiL3 ); | |
| 77 | +} | |
| 78 | + | |
| 79 | +void_t WelsI4x4LumaPredDc_c(uint8_t *pPred, const int32_t kiStride) | |
| 80 | +{ | |
| 81 | + const int32_t kiStride2 = kiStride << 1; | |
| 82 | + const int32_t kiStride3 = kiStride2 + kiStride; | |
| 83 | + const uint8_t kuiMean = ( pPred[-1] + pPred[-1+kiStride] + pPred[-1+kiStride2] + pPred[-1+kiStride3] + | |
| 84 | + pPred[-kiStride] + pPred[-kiStride+1] + pPred[-kiStride+2] + pPred[-kiStride+3] + 4 ) >> 3; | |
| 85 | + const uint32_t kuiMean32= 0x01010101U * kuiMean; | |
| 86 | + | |
| 87 | + ST32( pPred , kuiMean32 ); | |
| 88 | + ST32( pPred+kiStride , kuiMean32 ); | |
| 89 | + ST32( pPred+kiStride2, kuiMean32 ); | |
| 90 | + ST32( pPred+kiStride3, kuiMean32 ); | |
| 91 | +} | |
| 92 | + | |
| 93 | +void_t WelsI4x4LumaPredDcLeft_c(uint8_t *pPred, const int32_t kiStride) | |
| 94 | +{ | |
| 95 | + const int32_t kiStride2 = kiStride << 1; | |
| 96 | + const int32_t kiStride3 = kiStride2 + kiStride; | |
| 97 | + const uint8_t kuiMean = ( pPred[-1] + pPred[-1+kiStride] + pPred[-1+kiStride2] + pPred[-1+kiStride3] + 2 ) >> 2; | |
| 98 | + const uint32_t kuiMean32= 0x01010101U * kuiMean; | |
| 99 | + | |
| 100 | + ST32( pPred , kuiMean32 ); | |
| 101 | + ST32( pPred+kiStride , kuiMean32 ); | |
| 102 | + ST32( pPred+kiStride2, kuiMean32 ); | |
| 103 | + ST32( pPred+kiStride3, kuiMean32 ); | |
| 104 | +} | |
| 105 | + | |
| 106 | +void_t WelsI4x4LumaPredDcTop_c(uint8_t *pPred, const int32_t kiStride) | |
| 107 | +{ | |
| 108 | + const int32_t kiStride2 = kiStride << 1; | |
| 109 | + const int32_t kiStride3 = kiStride2 + kiStride; | |
| 110 | + const uint8_t kuiMean = (pPred[-kiStride] + pPred[-kiStride+1] + pPred[-kiStride+2] + pPred[-kiStride+3] + 2) >> 2; | |
| 111 | + const uint32_t kuiMean32= 0x01010101U * kuiMean; | |
| 112 | + | |
| 113 | + ST32( pPred , kuiMean32 ); | |
| 114 | + ST32( pPred+kiStride , kuiMean32 ); | |
| 115 | + ST32( pPred+kiStride2, kuiMean32 ); | |
| 116 | + ST32( pPred+kiStride3, kuiMean32 ); | |
| 117 | +} | |
| 118 | + | |
| 119 | +void_t WelsI4x4LumaPredDcNA_c(uint8_t *pPred, const int32_t kiStride) | |
| 120 | +{ | |
| 121 | + const uint32_t kuiDC32 = 0x80808080U; | |
| 122 | + | |
| 123 | + ST32( pPred , kuiDC32 ); | |
| 124 | + ST32( pPred+kiStride , kuiDC32 ); | |
| 125 | + ST32( pPred+(kiStride<<1) , kuiDC32 ); | |
| 126 | + ST32( pPred+(kiStride<<1)+kiStride, kuiDC32 ); | |
| 127 | +} | |
| 128 | + | |
| 129 | +/*down pLeft*/ | |
| 130 | +void_t WelsI4x4LumaPredDDL_c(uint8_t *pPred, const int32_t kiStride) | |
| 131 | +{ | |
| 132 | + const int32_t kiStride2 = kiStride<<1; | |
| 133 | + const int32_t kiStride3 = kiStride + kiStride2; | |
| 134 | + /*get pTop*/ | |
| 135 | + uint8_t *ptop = &pPred[-kiStride]; | |
| 136 | + const uint8_t kuiT0 = *ptop; | |
| 137 | + const uint8_t kuiT1 = *(ptop+1); | |
| 138 | + const uint8_t kuiT2 = *(ptop+2); | |
| 139 | + const uint8_t kuiT3 = *(ptop+3); | |
| 140 | + const uint8_t kuiT4 = *(ptop+4); | |
| 141 | + const uint8_t kuiT5 = *(ptop+5); | |
| 142 | + const uint8_t kuiT6 = *(ptop+6); | |
| 143 | + const uint8_t kuiT7 = *(ptop+7); | |
| 144 | + const uint8_t kuiDDL0 = (2 + kuiT0 + kuiT2 + (kuiT1<<1))>>2; // kDDL0 | |
| 145 | + const uint8_t kuiDDL1 = (2 + kuiT1 + kuiT3 + (kuiT2<<1))>>2; // kDDL1 | |
| 146 | + const uint8_t kuiDDL2 = (2 + kuiT2 + kuiT4 + (kuiT3<<1))>>2; // kDDL2 | |
| 147 | + const uint8_t kuiDDL3 = (2 + kuiT3 + kuiT5 + (kuiT4<<1))>>2; // kDDL3 | |
| 148 | + const uint8_t kuiDDL4 = (2 + kuiT4 + kuiT6 + (kuiT5<<1))>>2; // kDDL4 | |
| 149 | + const uint8_t kuiDDL5 = (2 + kuiT5 + kuiT7 + (kuiT6<<1))>>2; // kDDL5 | |
| 150 | + const uint8_t kuiDDL6 = (2 + kuiT6 + kuiT7 + (kuiT7<<1))>>2; // kDDL6 | |
| 151 | + const uint8_t kuiList[8]= { kuiDDL0, kuiDDL1, kuiDDL2, kuiDDL3, kuiDDL4, kuiDDL5, kuiDDL6, 0 }; | |
| 152 | + | |
| 153 | + ST32( pPred , LD32(kuiList ) ); | |
| 154 | + ST32( pPred+kiStride , LD32(kuiList+1) ); | |
| 155 | + ST32( pPred+kiStride2, LD32(kuiList+2) ); | |
| 156 | + ST32( pPred+kiStride3, LD32(kuiList+3) ); | |
| 157 | +} | |
| 158 | + | |
| 159 | +/*down pLeft*/ | |
| 160 | +void_t WelsI4x4LumaPredDDLTop_c(uint8_t *pPred, const int32_t kiStride) | |
| 161 | +{ | |
| 162 | + const int32_t kiStride2 = kiStride<<1; | |
| 163 | + const int32_t kiStride3 = kiStride + kiStride2; | |
| 164 | + /*get pTop*/ | |
| 165 | + uint8_t *ptop = &pPred[-kiStride]; | |
| 166 | + const uint8_t kuiT0 = *ptop; | |
| 167 | + const uint8_t kuiT1 = *(ptop+1); | |
| 168 | + const uint8_t kuiT2 = *(ptop+2); | |
| 169 | + const uint8_t kuiT3 = *(ptop+3); | |
| 170 | + const uint16_t kuiT01 = 1 + kuiT0 + kuiT1; | |
| 171 | + const uint16_t kuiT12 = 1 + kuiT1 + kuiT2; | |
| 172 | + const uint16_t kuiT23 = 1 + kuiT2 + kuiT3; | |
| 173 | + const uint16_t kuiT33 = 1 + (kuiT3 << 1); | |
| 174 | + const uint8_t kuiDLT0 = (kuiT01 + kuiT12) >> 2; // kDLT0 | |
| 175 | + const uint8_t kuiDLT1 = (kuiT12 + kuiT23) >> 2; // kDLT1 | |
| 176 | + const uint8_t kuiDLT2 = (kuiT23 + kuiT33) >> 2; // kDLT2 | |
| 177 | + const uint8_t kuiDLT3 = kuiT33 >> 1; // kDLT3 | |
| 178 | + const uint8_t kuiList[8]= { kuiDLT0, kuiDLT1, kuiDLT2, kuiDLT3, kuiDLT3, kuiDLT3, kuiDLT3 ,kuiDLT3 }; | |
| 179 | + | |
| 180 | + ST32( pPred, LD32(kuiList ) ); | |
| 181 | + ST32( pPred+kiStride, LD32(kuiList+1) ); | |
| 182 | + ST32( pPred+kiStride2, LD32(kuiList+2) ); | |
| 183 | + ST32( pPred+kiStride3, LD32(kuiList+3) ); | |
| 184 | +} | |
| 185 | + | |
| 186 | + | |
| 187 | +/*down right*/ | |
| 188 | +void_t WelsI4x4LumaPredDDR_c(uint8_t *pPred, const int32_t kiStride) | |
| 189 | +{ | |
| 190 | + const int32_t kiStride2 = kiStride<<1; | |
| 191 | + const int32_t kiStride3 = kiStride + kiStride2; | |
| 192 | + uint8_t *ptopleft = &pPred[-(kiStride+1)]; | |
| 193 | + uint8_t *pleft = &pPred[-1]; | |
| 194 | + const uint8_t kuiLT = *ptopleft; | |
| 195 | + /*get pLeft and pTop*/ | |
| 196 | + const uint8_t kuiL0 = *pleft; | |
| 197 | + const uint8_t kuiL1 = *(pleft+kiStride ); | |
| 198 | + const uint8_t kuiL2 = *(pleft+kiStride2); | |
| 199 | + const uint8_t kuiL3 = *(pleft+kiStride3); | |
| 200 | + const uint8_t kuiT0 = *(ptopleft+1); | |
| 201 | + const uint8_t kuiT1 = *(ptopleft+2); | |
| 202 | + const uint8_t kuiT2 = *(ptopleft+3); | |
| 203 | + const uint8_t kuiT3 = *(ptopleft+4); | |
| 204 | + const uint16_t kuiTL0 = 1 + kuiLT + kuiL0; | |
| 205 | + const uint16_t kuiLT0 = 1 + kuiLT + kuiT0; | |
| 206 | + const uint16_t kuiT01 = 1 + kuiT0 + kuiT1; | |
| 207 | + const uint16_t kuiT12 = 1 + kuiT1 + kuiT2; | |
| 208 | + const uint16_t kuiT23 = 1 + kuiT2 + kuiT3; | |
| 209 | + const uint16_t kuiL01 = 1 + kuiL0 + kuiL1; | |
| 210 | + const uint16_t kuiL12 = 1 + kuiL1 + kuiL2; | |
| 211 | + const uint16_t kuiL23 = 1 + kuiL2 + kuiL3; | |
| 212 | + const uint8_t kuiDDR0 = (kuiTL0 + kuiLT0) >> 2; // kuiDDR0 | |
| 213 | + const uint8_t kuiDDR1 = (kuiLT0 + kuiT01) >> 2; // kuiDDR1 | |
| 214 | + const uint8_t kuiDDR2 = (kuiT01 + kuiT12) >> 2; // kuiDDR2 | |
| 215 | + const uint8_t kuiDDR3 = (kuiT12 + kuiT23) >> 2; // kuiDDR3 | |
| 216 | + const uint8_t kuiDDR4 = (kuiTL0 + kuiL01) >> 2; // kuiDDR4 | |
| 217 | + const uint8_t kuiDDR5 = (kuiL01 + kuiL12) >> 2; // kuiDDR5 | |
| 218 | + const uint8_t kuiDDR6 = (kuiL12 + kuiL23) >> 2; // kuiDDR6 | |
| 219 | + const uint8_t kuiList[8]= { kuiDDR6, kuiDDR5, kuiDDR4, kuiDDR0, kuiDDR1, kuiDDR2, kuiDDR3, 0 }; | |
| 220 | + | |
| 221 | + ST32( pPred , LD32(kuiList+3) ); | |
| 222 | + ST32( pPred+kiStride , LD32(kuiList+2) ); | |
| 223 | + ST32( pPred+kiStride2, LD32(kuiList+1) ); | |
| 224 | + ST32( pPred+kiStride3, LD32(kuiList ) ); | |
| 225 | +} | |
| 226 | + | |
| 227 | + | |
| 228 | +/*vertical pLeft*/ | |
| 229 | +void_t WelsI4x4LumaPredVL_c(uint8_t *pPred, const int32_t kiStride) | |
| 230 | +{ | |
| 231 | + const int32_t kiStride2 = kiStride<<1; | |
| 232 | + const int32_t kiStride3 = kiStride + kiStride2; | |
| 233 | + uint8_t *ptopleft = &pPred[-(kiStride+1)]; | |
467 more lines aren’t shown here.
This diff is large: its 576 lines aren’t shown here.
This diff is large: its 758 lines aren’t shown here.
This diff is large: its 116 lines aren’t shown here.
This diff is large: its 154 lines aren’t shown here.
This diff is large: its 252 lines aren’t shown here.
This diff is large: its 1628 lines aren’t shown here.
This diff is large: its 167 lines aren’t shown here.
This diff is large: its 590 lines aren’t shown here.
This diff is large: its 308 lines aren’t shown here.
This diff is large: its 57 lines aren’t shown here.
This diff is large: its 173 lines aren’t shown here.
This diff is large: its 122 lines aren’t shown here.
This diff is large: its 16 lines aren’t shown here.
Binary file not shown.
This diff is large: its 116 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 420 lines aren’t shown here.
This diff is large: its 533 lines aren’t shown here.
This diff is large: its 4 lines aren’t shown here.