History

Pretty printed the C++ code with astyle

Ethan Hugg committed 12 years ago

Commit ff6b6691 parent 063709c225 files · +48457 −51954Browse files

Showing the changes to codec/encoder/core/src/encoder.cpp (1 of 225 files). Show all

Unified · Split

codec/encoder/core/src/encoder.cpp+498−554
@@ -1,554 +1,498 @@
1/*!1/*!
2 * \copy2 * \copy
3 * Copyright (c) 2009-2013, Cisco Systems3 * Copyright (c) 2009-2013, Cisco Systems
4 * All rights reserved.4 * All rights reserved.
5 *5 *
6 * Redistribution and use in source and binary forms, with or without6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions7 * modification, are permitted provided that the following conditions
8 * are met:8 * are met:
9 *9 *
10 * * Redistributions of source code must retain the above copyright10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.11 * notice, this list of conditions and the following disclaimer.
12 *12 *
13 * * Redistributions in binary form must reproduce the above copyright13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the15 * the documentation and/or other materials provided with the
16 * distribution.16 * distribution.
17 *17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.29 * POSSIBILITY OF SUCH DAMAGE.
30 *30 *
31 *31 *
32 * \file encoder.c32 * \file encoder.c
33 *33 *
34 * \brief core encoder34 * \brief core encoder
35 *35 *
36 * \date 5/14/2009 Created36 * \date 5/14/2009 Created
37 *37 *
38 *************************************************************************************38 *************************************************************************************
39 */39 */
40#include <stdio.h>40#include <stdio.h>
41#include <stdlib.h>41#include <stdlib.h>
42#include <string.h>42#include <string.h>
43#include <assert.h>43#include <assert.h>
44#include "encoder.h"44#include "encoder.h"
45#include "extern.h"45#include "extern.h"
46#include "cpu.h"46#include "cpu.h"
47#include "cpu_core.h"47#include "cpu_core.h"
48#include "utils.h"48#include "utils.h"
49 49
50#include "encode_mb_aux.h"50#include "encode_mb_aux.h"
51#include "decode_mb_aux.h"51#include "decode_mb_aux.h"
52#include "get_intra_predictor.h"52#include "get_intra_predictor.h"
53#include "svc_encode_mb.h"53#include "svc_encode_mb.h"
54 54
55#include "deblocking.h"55#include "deblocking.h"
56#include "expand_pic.h"56#include "expand_pic.h"
57 57
58#include "mc.h"58#include "mc.h"
59#include "sample.h"59#include "sample.h"
60 60
61#include "svc_encode_slice.h"61#include "svc_encode_slice.h"
62#include "svc_base_layer_md.h"62#include "svc_base_layer_md.h"
63#include "svc_mode_decision.h"63#include "svc_mode_decision.h"
64#include "set_mb_syn_cavlc.h"64#include "set_mb_syn_cavlc.h"
65#include "crt_util_safe_x.h" // Safe CRT routines like utils for cross_platforms65#include "crt_util_safe_x.h" // Safe CRT routines like utils for cross_platforms
66#include "codec_def.h"66#include "codec_def.h"
67#ifdef MT_ENABLED67#ifdef MT_ENABLED
68#include "slice_multi_threading.h"68#include "slice_multi_threading.h"
69#endif//MT_ENABLED69#endif//MT_ENABLED
70 70
71// global function pointers definition71// global function pointers definition
72namespace WelsSVCEnc {72namespace WelsSVCEnc {
73/* Motion compensation */73/* Motion compensation */
74 74
75 75
76/*!76/*!
77 * \brief initialize source picture body77 * \brief initialize source picture body
78 * \param pSrc SSourcePicture*78 * \param pSrc SSourcePicture*
79 * \param csp internal csp format79 * \param csp internal csp format
80 * \param iWidth widht of picture in pixels80 * \param iWidth widht of picture in pixels
81 * \param iHeight iHeight of picture in pixels81 * \param iHeight iHeight of picture in pixels
82 * \return successful - 0; otherwise none 0 for failed82 * \return successful - 0; otherwise none 0 for failed
83 */83 */
84int32_t InitPic( const void *kpSrc, const int32_t kiColorspace, const int32_t kiWidth, const int32_t kiHeight )84int32_t InitPic (const void* kpSrc, const int32_t kiColorspace, const int32_t kiWidth, const int32_t kiHeight) {
85{85 SSourcePicture* pSrcPic = (SSourcePicture*)kpSrc;
86 SSourcePicture *pSrcPic = (SSourcePicture *)kpSrc;86
87 87 if (NULL == pSrcPic || kiWidth == 0 || kiHeight == 0)
88 if ( NULL == pSrcPic || kiWidth == 0 || kiHeight == 0 )88 return 1;
89 return 1;89
90 90 pSrcPic->iColorFormat = kiColorspace;
91 pSrcPic->iColorFormat = kiColorspace;91 pSrcPic->iPicWidth = kiWidth;
92 pSrcPic->iPicWidth = kiWidth;92 pSrcPic->iPicHeight = kiHeight;
93 pSrcPic->iPicHeight = kiHeight;93
94 94 switch (kiColorspace & (~videoFormatVFlip)) {
95 switch( kiColorspace & (~videoFormatVFlip) ) {95 case videoFormatI420:
96 case videoFormatI420:96 case videoFormatYV12:
97 case videoFormatYV12:97 pSrcPic->pData[0] = NULL;
98 pSrcPic->pData[0] = NULL;98 pSrcPic->pData[1] = NULL;
99 pSrcPic->pData[1] = NULL;99 pSrcPic->pData[2] = NULL;
100 pSrcPic->pData[2] = NULL;100 pSrcPic->pData[3] = NULL;
101 pSrcPic->pData[3] = NULL;101 pSrcPic->iStride[0] = kiWidth;
102 pSrcPic->iStride[0] = kiWidth;102 pSrcPic->iStride[2] = pSrcPic->iStride[1] = kiWidth >> 1;
103 pSrcPic->iStride[2] = pSrcPic->iStride[1] = kiWidth >> 1;103 pSrcPic->iStride[3] = 0;
104 pSrcPic->iStride[3] = 0;104 break;
105 break; 105 case videoFormatYUY2:
106 case videoFormatYUY2:106 case videoFormatYVYU:
107 case videoFormatYVYU:107 case videoFormatUYVY:
108 case videoFormatUYVY:108 pSrcPic->pData[0] = NULL;
109 pSrcPic->pData[0] = NULL;109 pSrcPic->pData[1] = NULL;
110 pSrcPic->pData[1] = NULL;110 pSrcPic->pData[2] = NULL;
111 pSrcPic->pData[2] = NULL;111 pSrcPic->pData[3] = NULL;
112 pSrcPic->pData[3] = NULL; 112 pSrcPic->iStride[0] = CALC_BI_STRIDE (kiWidth, 16);
113 pSrcPic->iStride[0] = CALC_BI_STRIDE(kiWidth, 16);113 pSrcPic->iStride[3] = pSrcPic->iStride[2] = pSrcPic->iStride[1] = 0;
114 pSrcPic->iStride[3] = pSrcPic->iStride[2] = pSrcPic->iStride[1] = 0; 114 break;
115 break;115 case videoFormatRGB:
116 case videoFormatRGB:116 case videoFormatBGR:
117 case videoFormatBGR:117 pSrcPic->pData[0] = NULL;
118 pSrcPic->pData[0] = NULL;118 pSrcPic->pData[1] = NULL;
119 pSrcPic->pData[1] = NULL;119 pSrcPic->pData[2] = NULL;
120 pSrcPic->pData[2] = NULL;120 pSrcPic->pData[3] = NULL;
121 pSrcPic->pData[3] = NULL; 121 pSrcPic->iStride[0] = CALC_BI_STRIDE (kiWidth, 24);
122 pSrcPic->iStride[0] = CALC_BI_STRIDE(kiWidth, 24);122 pSrcPic->iStride[3] = pSrcPic->iStride[2] = pSrcPic->iStride[1] = 0;
123 pSrcPic->iStride[3] = pSrcPic->iStride[2] = pSrcPic->iStride[1] = 0;123 if (kiColorspace & videoFormatVFlip)
124 if( kiColorspace & videoFormatVFlip )124 pSrcPic->iColorFormat = kiColorspace & (~videoFormatVFlip);
125 pSrcPic->iColorFormat = kiColorspace & (~videoFormatVFlip);125 else
126 else 126 pSrcPic->iColorFormat = kiColorspace | videoFormatVFlip;
127 pSrcPic->iColorFormat = kiColorspace | videoFormatVFlip;127 break;
128 break;128 case videoFormatBGRA:
129 case videoFormatBGRA:129 case videoFormatRGBA:
130 case videoFormatRGBA:130 case videoFormatARGB:
131 case videoFormatARGB:131 case videoFormatABGR:
132 case videoFormatABGR:132 pSrcPic->pData[0] = NULL;
133 pSrcPic->pData[0] = NULL;133 pSrcPic->pData[1] = NULL;
134 pSrcPic->pData[1] = NULL;134 pSrcPic->pData[2] = NULL;
135 pSrcPic->pData[2] = NULL;135 pSrcPic->pData[3] = NULL;
136 pSrcPic->pData[3] = NULL; 136 pSrcPic->iStride[0] = kiWidth << 2;
137 pSrcPic->iStride[0] = kiWidth << 2;137 pSrcPic->iStride[3] = pSrcPic->iStride[2] = pSrcPic->iStride[1] = 0;
138 pSrcPic->iStride[3] = pSrcPic->iStride[2] = pSrcPic->iStride[1] = 0; 138 if (kiColorspace & videoFormatVFlip)
139 if( kiColorspace & videoFormatVFlip )139 pSrcPic->iColorFormat = kiColorspace & (~videoFormatVFlip);
140 pSrcPic->iColorFormat = kiColorspace & (~videoFormatVFlip);140 else
141 else 141 pSrcPic->iColorFormat = kiColorspace | videoFormatVFlip;
142 pSrcPic->iColorFormat = kiColorspace | videoFormatVFlip;142 break;
143 break;143 default:
144 default:144 return 2; // any else?
145 return 2; // any else?145 }
146 }146
147 147 return 0;
148 return 0;148}
149}149
150 150
151 151void WelsInitBGDFunc (SWelsFuncPtrList* pFuncList, const bool_t kbEnableBackgroundDetection) {
152void WelsInitBGDFunc( SWelsFuncPtrList *pFuncList, const bool_t kbEnableBackgroundDetection )152 if (kbEnableBackgroundDetection) {
153{153 pFuncList->pfInterMdBackgroundDecision = (PInterMdBackgroundDecisionFunc)WelsMdInterJudgeBGDPskip;
154 if ( kbEnableBackgroundDetection )154 pFuncList->pfInterMdBackgroundInfoUpdate = (PInterMdBackgroundInfoUpdateFunc)WelsMdInterUpdateBGDInfo;
155 {155 } else {
156 pFuncList->pfInterMdBackgroundDecision = (PInterMdBackgroundDecisionFunc)WelsMdInterJudgeBGDPskip;156 pFuncList->pfInterMdBackgroundDecision = (PInterMdBackgroundDecisionFunc)WelsMdInterJudgeBGDPskipFalse;
157 pFuncList->pfInterMdBackgroundInfoUpdate = (PInterMdBackgroundInfoUpdateFunc)WelsMdInterUpdateBGDInfo;157 pFuncList->pfInterMdBackgroundInfoUpdate = (PInterMdBackgroundInfoUpdateFunc)WelsMdInterUpdateBGDInfoNULL;
158 }158 }
159 else159}
160 {160
161 pFuncList->pfInterMdBackgroundDecision = (PInterMdBackgroundDecisionFunc)WelsMdInterJudgeBGDPskipFalse;161/*!
162 pFuncList->pfInterMdBackgroundInfoUpdate = (PInterMdBackgroundInfoUpdateFunc)WelsMdInterUpdateBGDInfoNULL;162 * \brief initialize function pointers that potentially used in Wels encoding
163 }163 * \param pEncCtx sWelsEncCtx*
164}164 * \return successful - 0; otherwise none 0 for failed
165 165 */
166/*!166int32_t InitFunctionPointers (SWelsFuncPtrList* pFuncList, SWelsSvcCodingParam* pParam, uint32_t uiCpuFlag) {
167 * \brief initialize function pointers that potentially used in Wels encoding167 int32_t iReturn = 0;
168 * \param pEncCtx sWelsEncCtx*168
169 * \return successful - 0; otherwise none 0 for failed169 /* Functionality utilization of CPU instructions dependency */
170 */170 pFuncList->pfSetMemZeroSize8 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage
171int32_t InitFunctionPointers( SWelsFuncPtrList *pFuncList, SWelsSvcCodingParam *pParam, uint32_t uiCpuFlag )171 pFuncList->pfSetMemZeroSize64Aligned16 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage
172{ 172 pFuncList->pfSetMemZeroSize64 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage
173 int32_t iReturn = 0;173#if defined(X86_ASM)
174 174 if (uiCpuFlag & WELS_CPU_MMXEXT) {
175 /* Functionality utilization of CPU instructions dependency */175 pFuncList->pfSetMemZeroSize8 = WelsSetMemZeroSize8_mmx; // confirmed_safe_unsafe_usage
176 pFuncList->pfSetMemZeroSize8 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage176 pFuncList->pfSetMemZeroSize64Aligned16 = WelsSetMemZeroSize64_mmx; // confirmed_safe_unsafe_usage
177 pFuncList->pfSetMemZeroSize64Aligned16 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage177 pFuncList->pfSetMemZeroSize64 = WelsSetMemZeroSize64_mmx; // confirmed_safe_unsafe_usage
178 pFuncList->pfSetMemZeroSize64 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage178 }
179#if defined(X86_ASM)179 if (uiCpuFlag & WELS_CPU_SSE2) {
180 if ( uiCpuFlag & WELS_CPU_MMXEXT )180 pFuncList->pfSetMemZeroSize64Aligned16 = WelsSetMemZeroAligned64_sse2; // confirmed_safe_unsafe_usage
181 { 181 }
182 pFuncList->pfSetMemZeroSize8 = WelsSetMemZeroSize8_mmx; // confirmed_safe_unsafe_usage182#endif//X86_ASM
183 pFuncList->pfSetMemZeroSize64Aligned16 = WelsSetMemZeroSize64_mmx; // confirmed_safe_unsafe_usage183
184 pFuncList->pfSetMemZeroSize64 = WelsSetMemZeroSize64_mmx; // confirmed_safe_unsafe_usage184 InitExpandPictureFunc (pFuncList, uiCpuFlag);
185 }185
186 if ( uiCpuFlag & WELS_CPU_SSE2 )186 /* Intra_Prediction_fn*/
187 {187 WelsInitFillingPredFuncs (uiCpuFlag);
188 pFuncList->pfSetMemZeroSize64Aligned16 = WelsSetMemZeroAligned64_sse2; // confirmed_safe_unsafe_usage188 WelsInitIntraPredFuncs (pFuncList, uiCpuFlag);
189 }189
190#endif//X86_ASM190 /* sad, satd, average */
191 191 WelsInitSampleSadFunc (pFuncList, uiCpuFlag);
192 InitExpandPictureFunc( pFuncList, uiCpuFlag );192
193 193 //
194 /* Intra_Prediction_fn*/ 194 WelsInitBGDFunc (pFuncList, pParam->bEnableBackgroundDetection);
195 WelsInitFillingPredFuncs( uiCpuFlag );195 // for pfGetVarianceFromIntraVaa function ptr adaptive by CPU features, 6/7/2010
196 WelsInitIntraPredFuncs( pFuncList, uiCpuFlag );196 InitIntraAnalysisVaaInfo (pFuncList, uiCpuFlag);
197 197
198 /* sad, satd, average */198 /* Motion compensation */
199 WelsInitSampleSadFunc(pFuncList, uiCpuFlag);199 /*init pixel average function*/
200 200 /*get one column or row pixel when refinement*/
201 //201 WelsInitMcFuncs (pFuncList, uiCpuFlag);
202 WelsInitBGDFunc(pFuncList, pParam->bEnableBackgroundDetection );202 InitCoeffFunc (uiCpuFlag);
203 // for pfGetVarianceFromIntraVaa function ptr adaptive by CPU features, 6/7/2010203
204 InitIntraAnalysisVaaInfo( pFuncList, uiCpuFlag );204 WelsInitEncodingFuncs (pFuncList, uiCpuFlag);
205 205 WelsInitReconstructionFuncs (pFuncList, uiCpuFlag);
206 /* Motion compensation */206
207 /*init pixel average function*/207 DeblockingInit (&pFuncList->pfDeblocking, uiCpuFlag);
208 /*get one column or row pixel when refinement*/208 WelsBlockFuncInit (&pFuncList->pfSetNZCZero, uiCpuFlag);
209 WelsInitMcFuncs(pFuncList, uiCpuFlag);209
210 InitCoeffFunc( uiCpuFlag );210 InitFillNeighborCacheInterFunc (pFuncList, pParam->bEnableBackgroundDetection);
211 211
212 WelsInitEncodingFuncs( pFuncList, uiCpuFlag );212 return iReturn;
213 WelsInitReconstructionFuncs( pFuncList, uiCpuFlag );213}
214 214
215 DeblockingInit( &pFuncList->pfDeblocking, uiCpuFlag );215/*!
216 WelsBlockFuncInit( &pFuncList->pfSetNZCZero, uiCpuFlag );216 * \brief initialize frame coding
217 217 */
218 InitFillNeighborCacheInterFunc ( pFuncList, pParam->bEnableBackgroundDetection );218void InitFrameCoding (sWelsEncCtx* pEncCtx, const EFrameType keFrameType) {
219 219 // for bitstream writing
220 return iReturn;220 pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position
221}221 pEncCtx->pOut->iNalIndex = 0; // reset NAL index
222 222
223/*!223 InitBits (&pEncCtx->pOut->sBsWrite, pEncCtx->pOut->pBsBuffer, pEncCtx->pOut->uiSize);
224 * \brief initialize frame coding 224
225 */225 if (keFrameType == WELS_FRAME_TYPE_P) {
226void InitFrameCoding( sWelsEncCtx *pEncCtx, const EFrameType keFrameType )226 if (pEncCtx->pSvcParam->uiIntraPeriod) {
227{227 ++pEncCtx->iFrameIndex;
228 // for bitstream writing228 }
229 pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position229
230 pEncCtx->pOut->iNalIndex = 0; // reset NAL index230 ++pEncCtx->uiFrameIdxRc;
231 231
232 InitBits( &pEncCtx->pOut->sBsWrite, pEncCtx->pOut->pBsBuffer, pEncCtx->pOut->uiSize );232 if (pEncCtx->iPOC < (1 << pEncCtx->pSps->iLog2MaxPocLsb) - 2) // if iPOC type is no 0, this need be modification
233 233 pEncCtx->iPOC += 2; // for POC type 0
234 if ( keFrameType == WELS_FRAME_TYPE_P )234 else
235 {235 pEncCtx->iPOC = 0;
236 if ( pEncCtx->pSvcParam->uiIntraPeriod )236
237 {237 if (pEncCtx->eLastNalPriority != 0) {
238 ++pEncCtx->iFrameIndex;238 if (pEncCtx->iFrameNum < (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1)
239 }239 ++ pEncCtx->iFrameNum;
240 240 else
241 ++pEncCtx->uiFrameIdxRc;241 pEncCtx->iFrameNum = 0; // if iFrameNum overflow
242 242 }
243 if ( pEncCtx->iPOC < ( 1 << pEncCtx->pSps->iLog2MaxPocLsb ) - 2 ) // if iPOC type is no 0, this need be modification243 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE;
244 pEncCtx->iPOC += 2; // for POC type 0244 pEncCtx->eSliceType = P_SLICE;
245 else245 pEncCtx->eNalPriority = NRI_PRI_HIGH;
246 pEncCtx->iPOC = 0;246 } else if (keFrameType == WELS_FRAME_TYPE_IDR) {
247 247 pEncCtx->iFrameNum = 0;
248 if ( pEncCtx->eLastNalPriority != 0 )248 pEncCtx->iPOC = 0;
249 {249 pEncCtx->bEncCurFrmAsIdrFlag = false;
250 if ( pEncCtx->iFrameNum < (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1 )250 if (pEncCtx->pSvcParam->uiIntraPeriod) {
251 ++ pEncCtx->iFrameNum;251 pEncCtx->iFrameIndex = 0;
252 else252 }
253 pEncCtx->iFrameNum = 0; // if iFrameNum overflow253 pEncCtx->uiFrameIdxRc = 0;
254 }254
255 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE;255 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE_IDR;
256 pEncCtx->eSliceType = P_SLICE;256 pEncCtx->eSliceType = I_SLICE;
257 pEncCtx->eNalPriority = NRI_PRI_HIGH;257 pEncCtx->eNalPriority = NRI_PRI_HIGHEST;
258 }258
259 else if ( keFrameType == WELS_FRAME_TYPE_IDR )259 pEncCtx->iCodingIndex = 0;
260 {260
261 pEncCtx->iFrameNum = 0;261 // reset_ref_list
262 pEncCtx->iPOC = 0;262
263 pEncCtx->bEncCurFrmAsIdrFlag = false;263 // rc_init_gop
264 if ( pEncCtx->pSvcParam->uiIntraPeriod )264 } else if (keFrameType == WELS_FRAME_TYPE_I) {
265 {265 if (pEncCtx->iPOC < (1 << pEncCtx->pSps->iLog2MaxPocLsb) - 2) // if iPOC type is no 0, this need be modification
266 pEncCtx->iFrameIndex = 0;266 pEncCtx->iPOC += 2; // for POC type 0
267 } 267 else
268 pEncCtx->uiFrameIdxRc = 0;268 pEncCtx->iPOC = 0;
269 269
270 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE_IDR;270 if (pEncCtx->eLastNalPriority != 0) {
271 pEncCtx->eSliceType = I_SLICE;271 if (pEncCtx->iFrameNum < (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1)
272 pEncCtx->eNalPriority = NRI_PRI_HIGHEST;272 ++ pEncCtx->iFrameNum;
273 273 else
274 pEncCtx->iCodingIndex = 0;274 pEncCtx->iFrameNum = 0; // if iFrameNum overflow
275 275 }
276 // reset_ref_list276
277 277 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE;
278 // rc_init_gop 278 pEncCtx->eSliceType = I_SLICE;
279 }279 pEncCtx->eNalPriority = NRI_PRI_HIGHEST;
280 else if ( keFrameType == WELS_FRAME_TYPE_I )280
281 {281 // rc_init_gop
282 if ( pEncCtx->iPOC < ( 1 << pEncCtx->pSps->iLog2MaxPocLsb ) - 2 ) // if iPOC type is no 0, this need be modification282 } else { // B pictures are not supported now, any else?
283 pEncCtx->iPOC += 2; // for POC type 0283 assert (0);
284 else284 }
285 pEncCtx->iPOC = 0;285
286 286#if defined(STAT_OUTPUT)
287 if ( pEncCtx->eLastNalPriority != 0 )287 memset (&pEncCtx->sPerInfo, 0, sizeof (SStatSliceInfo));
288 {288#endif//FRAME_INFO_OUTPUT
289 if ( pEncCtx->iFrameNum < (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1 )289
290 ++ pEncCtx->iFrameNum;290#if defined(MT_ENABLED) && defined(PACKING_ONE_SLICE_PER_LAYER)
291 else291 if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1)
292 pEncCtx->iFrameNum = 0; // if iFrameNum overflow292 reset_env_mt (pEncCtx);
293 }293#endif
294 294}
295 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE;295
296 pEncCtx->eSliceType = I_SLICE;296EFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum) {
297 pEncCtx->eNalPriority = NRI_PRI_HIGHEST;297 SWelsSvcCodingParam* pSvcParam = pEncCtx->pSvcParam;
298 298 EFrameType iFrameType = WELS_FRAME_TYPE_AUTO;
299 // rc_init_gop299 bool_t bSceneChangeFlag = false;
300 }300
301 else // B pictures are not supported now, any else?301 // perform scene change detection
302 {302 if ((!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag ||
303 assert( 0 );303 (kiSpatialNum < pSvcParam->iNumDependencyLayer)
304 }304 || (pEncCtx->uiFrameIdxRc < (VGOP_SIZE << 1))) { // avoid too frequent I frame coding, rc control
305 305 bSceneChangeFlag = false;
306#if defined(STAT_OUTPUT)306 } else {
307 memset( &pEncCtx->sPerInfo, 0, sizeof(SStatSliceInfo) );307 bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag;
308#endif//FRAME_INFO_OUTPUT308 }
309 309
310#if defined(MT_ENABLED) && defined(PACKING_ONE_SLICE_PER_LAYER)310 //scene_changed_flag: RC enable && iSpatialNum == pSvcParam->iNumDependencyLayer
311 if ( pEncCtx->pSvcParam->iMultipleThreadIdc > 1 )311 //bIdrPeriodFlag: RC disable || iSpatialNum != pSvcParam->iNumDependencyLayer
312 reset_env_mt( pEncCtx );312 //pEncCtx->bEncCurFrmAsIdrFlag: 1. first frame should be IDR; 2. idr pause; 3. idr request
313#endif313 iFrameType = (pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag
314}314 || pEncCtx->bEncCurFrmAsIdrFlag) ? WELS_FRAME_TYPE_IDR : WELS_FRAME_TYPE_P;
315 315
316EFrameType DecideFrameType( sWelsEncCtx *pEncCtx, const int8_t kiSpatialNum )316 if (WELS_FRAME_TYPE_P == iFrameType && pEncCtx->iSkipFrameFlag > 0) { // for frame skip, 1/5/2010
317{ 317 -- pEncCtx->iSkipFrameFlag;
318 SWelsSvcCodingParam *pSvcParam = pEncCtx->pSvcParam;318 iFrameType = WELS_FRAME_TYPE_SKIP;
319 EFrameType iFrameType = WELS_FRAME_TYPE_AUTO;319 } else if (WELS_FRAME_TYPE_IDR == iFrameType) {
320 bool_t bSceneChangeFlag = false;320 pEncCtx->iCodingIndex = 0;
321 321 }
322 // perform scene change detection 322
323 if ( (!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag || 323 return iFrameType;
324 (kiSpatialNum < pSvcParam->iNumDependencyLayer) || (pEncCtx->uiFrameIdxRc < (VGOP_SIZE << 1)) ) // avoid too frequent I frame coding, rc control 324}
325 {325
326 bSceneChangeFlag = false;326/*!
327 }327 * \brief Dump reconstruction for dependency layer
328 else328 */
329 {329
330 bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag;330extern "C" void DumpDependencyRec (SPicture* pCurPicture, const str_t* kpFileName, const int8_t kiDid) {
331 }331 FILE* pDumpRecFile = NULL;
332 332 static bool_t bDependencyRecFlag[MAX_DEPENDENCY_LAYER] = {0};
333 //scene_changed_flag: RC enable && iSpatialNum == pSvcParam->iNumDependencyLayer 333 int32_t iWrittenSize = 0;
334 //bIdrPeriodFlag: RC disable || iSpatialNum != pSvcParam->iNumDependencyLayer334
335 //pEncCtx->bEncCurFrmAsIdrFlag: 1. first frame should be IDR; 2. idr pause; 3. idr request335 if (NULL == pCurPicture || NULL == kpFileName || kiDid >= MAX_DEPENDENCY_LAYER)
336 iFrameType = ( pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag || pEncCtx->bEncCurFrmAsIdrFlag ) ? WELS_FRAME_TYPE_IDR : WELS_FRAME_TYPE_P;336 return;
337 337
338 if ( WELS_FRAME_TYPE_P == iFrameType && pEncCtx->iSkipFrameFlag > 0 ) // for frame skip, 1/5/2010338 if (bDependencyRecFlag[kiDid]) {
339 {339 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) // confirmed_safe_unsafe_usage
340 -- pEncCtx->iSkipFrameFlag;340#if defined(__GNUC__) || (defined(WIN32) && defined(_MSC_VER) && (_MSC_VER<1500))
341 iFrameType = WELS_FRAME_TYPE_SKIP;341 pDumpRecFile = FOPEN (kpFileName, "ab");
342 }342#elif defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
343 else if ( WELS_FRAME_TYPE_IDR == iFrameType )343 FOPEN (&pDumpRecFile, kpFileName, "ab");
344 {344#endif//__GNUC__..
345 pEncCtx->iCodingIndex = 0;345 else {
346 }346 str_t sDependencyRecFileName[16] = {0};
347 347#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
348 return iFrameType;348 SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
349}349 FOPEN (&pDumpRecFile, sDependencyRecFileName, "ab");
350 350#else
351/*!351 SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
352 * \brief Dump reconstruction for dependency layer352 pDumpRecFile = FOPEN (sDependencyRecFileName, "ab");
353 */353#endif//WIN32..
354 354 }
355extern "C" void DumpDependencyRec( SPicture *pCurPicture, const str_t *kpFileName, const int8_t kiDid )355 if (NULL != pDumpRecFile)
356{356 fseek (pDumpRecFile, 0, SEEK_END);
357 FILE *pDumpRecFile = NULL; 357 } else {
358 static bool_t bDependencyRecFlag[MAX_DEPENDENCY_LAYER] = {0};358 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage
359 int32_t iWrittenSize = 0;359#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
360 360 FOPEN (&pDumpRecFile, kpFileName, "wb");
361 if ( NULL == pCurPicture || NULL == kpFileName || kiDid >= MAX_DEPENDENCY_LAYER )361#else
362 return;362 pDumpRecFile = FOPEN (kpFileName, "wb");
363 363#endif//WIN32..
364 if ( bDependencyRecFlag[kiDid] )364 } else {
365 {365 str_t sDependencyRecFileName[16] = {0};
366 if ( STRNLEN(kpFileName, MAX_FNAME_LEN) > 0 ) // confirmed_safe_unsafe_usage366#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
367#if defined(__GNUC__) || (defined(WIN32) && defined(_MSC_VER) && (_MSC_VER<1500))367 SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
368 pDumpRecFile = FOPEN( kpFileName, "ab" );368 FOPEN (&pDumpRecFile, sDependencyRecFileName, "wb");
369#elif defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008369#else
370 FOPEN(&pDumpRecFile, kpFileName, "ab");370 SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
371#endif//__GNUC__..371 pDumpRecFile = FOPEN (sDependencyRecFileName, "wb");
372 else372#endif//WIN32..
373 {373 }
374 str_t sDependencyRecFileName[16] = {0}; 374 bDependencyRecFlag[kiDid] = true;
375#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008375 }
376 SNPRINTF( sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid ); // confirmed_safe_unsafe_usage376
377 FOPEN( &pDumpRecFile, sDependencyRecFileName, "ab" );377 if (NULL != pDumpRecFile) {
378#else378 int32_t i = 0;
379 SNPRINTF( sDependencyRecFileName, 16, "rec%d.yuv", kiDid ); // confirmed_safe_unsafe_usage379 int32_t j = 0;
380 pDumpRecFile = FOPEN( sDependencyRecFileName, "ab" );380 const int32_t kiStrideY = pCurPicture->iLineSize[0];
381#endif//WIN32..381 const int32_t kiLumaWidth = pCurPicture->iWidthInPixel;
382 }382 const int32_t kiLumaHeight = pCurPicture->iHeightInPixel;
383 if ( NULL != pDumpRecFile)383 const int32_t kiChromaWidth = kiLumaWidth >> 1;
384 fseek( pDumpRecFile, 0, SEEK_END );384 const int32_t kiChromaHeight = kiLumaHeight >> 1;
385 }385
386 else386 for (j = 0; j < kiLumaHeight; ++ j) {
387 {387 iWrittenSize = fwrite (&pCurPicture->pData[0][j * kiStrideY], 1, kiLumaWidth, pDumpRecFile);
388 if ( STRNLEN(kpFileName, MAX_FNAME_LEN) > 0 ) // confirmed_safe_unsafe_usage388 assert (iWrittenSize == kiLumaWidth);
389 {389 if (iWrittenSize < kiLumaWidth) {
390#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008390 assert (0); // make no sense for us if writing failed
391 FOPEN(&pDumpRecFile, kpFileName, "wb");391 fclose (pDumpRecFile);
392#else392 return;
393 pDumpRecFile = FOPEN( kpFileName, "wb" );393 }
394#endif//WIN32..394 }
395 }395 for (i = 1; i < I420_PLANES; ++ i) {
396 else396 const int32_t kiStrideUV = pCurPicture->iLineSize[i];
397 {397 for (j = 0; j < kiChromaHeight; ++ j) {
398 str_t sDependencyRecFileName[16] = {0};398 iWrittenSize = fwrite (&pCurPicture->pData[i][j * kiStrideUV], 1, kiChromaWidth, pDumpRecFile);
399#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008399 assert (iWrittenSize == kiChromaWidth);
400 SNPRINTF( sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid ); // confirmed_safe_unsafe_usage400 if (iWrittenSize < kiChromaWidth) {
401 FOPEN(&pDumpRecFile, sDependencyRecFileName, "wb");401 assert (0); // make no sense for us if writing failed
402#else402 fclose (pDumpRecFile);
403 SNPRINTF( sDependencyRecFileName, 16, "rec%d.yuv", kiDid ); // confirmed_safe_unsafe_usage403 return;
404 pDumpRecFile = FOPEN( sDependencyRecFileName, "wb");404 }
405#endif//WIN32..405 }
406 }406 }
407 bDependencyRecFlag[kiDid] = true;407 fclose (pDumpRecFile);
408 }408 pDumpRecFile = NULL;
409 409 }
410 if ( NULL != pDumpRecFile )410}
411 {411
412 int32_t i = 0;412/*!
413 int32_t j = 0;413 * \brief Dump the reconstruction pictures
414 const int32_t kiStrideY = pCurPicture->iLineSize[0]; 414 */
415 const int32_t kiLumaWidth = pCurPicture->iWidthInPixel;415
416 const int32_t kiLumaHeight = pCurPicture->iHeightInPixel;416void DumpRecFrame (SPicture* pCurPicture, const str_t* kpFileName) {
417 const int32_t kiChromaWidth = kiLumaWidth >> 1;417 FILE* pDumpRecFile = NULL;
418 const int32_t kiChromaHeight = kiLumaHeight >> 1; 418 static bool_t bRecFlag = false;
419 419 int32_t iWrittenSize = 0;
420 for( j = 0; j < kiLumaHeight; ++ j)420
421 {421 if (NULL == pCurPicture || NULL == kpFileName)
422 iWrittenSize = fwrite( &pCurPicture->pData[0][j*kiStrideY], 1, kiLumaWidth, pDumpRecFile );422 return;
423 assert( iWrittenSize == kiLumaWidth );423
424 if ( iWrittenSize < kiLumaWidth )424 if (bRecFlag) {
425 {425 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage
426 assert( 0 ); // make no sense for us if writing failed426#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
427 fclose(pDumpRecFile);427 FOPEN (&pDumpRecFile, kpFileName, "ab");
428 return;428#else
429 }429 pDumpRecFile = FOPEN (kpFileName, "ab");
430 }430#endif//WIN32
431 for( i = 1; i < I420_PLANES; ++ i)431 } else {
432 {432#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
433 const int32_t kiStrideUV = pCurPicture->iLineSize[i]; 433 FOPEN (&pDumpRecFile, "rec.yuv", "ab");
434 for ( j = 0; j < kiChromaHeight; ++ j)434#else
435 {435 pDumpRecFile = FOPEN ("rec.yuv", "ab");
436 iWrittenSize = fwrite( &pCurPicture->pData[i][j*kiStrideUV], 1, kiChromaWidth, pDumpRecFile );436#endif//WIN32
437 assert(iWrittenSize == kiChromaWidth );437 }
438 if ( iWrittenSize < kiChromaWidth )438 if (NULL != pDumpRecFile)
439 {439 fseek (pDumpRecFile, 0, SEEK_END);
440 assert( 0 ); // make no sense for us if writing failed440 } else {
441 fclose(pDumpRecFile);441 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage
442 return;442#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
443 }443 FOPEN (&pDumpRecFile, kpFileName, "wb");
444 }444#else
445 }445 pDumpRecFile = FOPEN (kpFileName, "wb");
446 fclose(pDumpRecFile);446#endif//WIN32
447 pDumpRecFile = NULL;447 } else {
448 }448#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
449}449 FOPEN (&pDumpRecFile, "rec.yuv", "wb");
450 450#else
451/*!451 pDumpRecFile = FOPEN ("rec.yuv", "wb");
452 * \brief Dump the reconstruction pictures452#endif//WIN32..
453 */453 }
454 454 bRecFlag = true;
455void DumpRecFrame( SPicture *pCurPicture, const str_t *kpFileName )455 }
456{456
457 FILE *pDumpRecFile = NULL; 457 if (NULL != pDumpRecFile) {
458 static bool_t bRecFlag = false;458 int32_t i = 0;
459 int32_t iWrittenSize = 0;459 int32_t j = 0;
460 460 const int32_t kiStrideY = pCurPicture->iLineSize[0];
461 if ( NULL == pCurPicture || NULL == kpFileName )461 const int32_t kiLumaWidth = pCurPicture->iWidthInPixel;
462 return;462 const int32_t kiLumaHeight = pCurPicture->iHeightInPixel;
463 463 const int32_t kiChromaWidth = kiLumaWidth >> 1;
464 if ( bRecFlag )464 const int32_t kiChromaHeight = kiLumaHeight >> 1;
465 {465
466 if ( STRNLEN(kpFileName, MAX_FNAME_LEN) > 0 ) // confirmed_safe_unsafe_usage466 for (j = 0; j < kiLumaHeight; ++ j) {
467 {467 iWrittenSize = fwrite (&pCurPicture->pData[0][j * kiStrideY], 1, kiLumaWidth, pDumpRecFile);
468#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008468 assert (iWrittenSize == kiLumaWidth);
469 FOPEN(&pDumpRecFile, kpFileName, "ab");469 if (iWrittenSize < kiLumaWidth) {
470#else470 assert (0); // make no sense for us if writing failed
471 pDumpRecFile = FOPEN( kpFileName, "ab" );471 fclose (pDumpRecFile);
472#endif//WIN32472 return;
473 }473 }
474 else474 }
475 {475 for (i = 1; i < I420_PLANES; ++ i) {
476#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008476 const int32_t kiStrideUV = pCurPicture->iLineSize[i];
477 FOPEN(&pDumpRecFile, "rec.yuv", "ab");477 for (j = 0; j < kiChromaHeight; ++ j) {
478#else478 iWrittenSize = fwrite (&pCurPicture->pData[i][j * kiStrideUV], 1, kiChromaWidth, pDumpRecFile);
479 pDumpRecFile = FOPEN( "rec.yuv", "ab" );479 assert (iWrittenSize == kiChromaWidth);
480#endif//WIN32480 if (iWrittenSize < kiChromaWidth) {
481 }481 assert (0); // make no sense for us if writing failed
482 if ( NULL != pDumpRecFile)482 fclose (pDumpRecFile);
483 fseek( pDumpRecFile, 0, SEEK_END );483 return;
484 }484 }
485 else485 }
486 {486 }
487 if ( STRNLEN(kpFileName, MAX_FNAME_LEN) > 0 ) // confirmed_safe_unsafe_usage487 fclose (pDumpRecFile);
488 {488 pDumpRecFile = NULL;
489#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008489 }
490 FOPEN(&pDumpRecFile, kpFileName, "wb");490}
491#else491
492 pDumpRecFile = FOPEN( kpFileName, "wb" );492
493#endif//WIN32493
494 }494/***********************************************************************************/
495 else495void WelsSetMemZero_c (void* pDst, int32_t iSize) { // confirmed_safe_unsafe_usage
496 {496 memset (pDst, 0, iSize);
497#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008497}
498 FOPEN(&pDumpRecFile, "rec.yuv", "wb");498}
499#else
500 pDumpRecFile = FOPEN( "rec.yuv", "wb");
501#endif//WIN32..
502 }
503 bRecFlag = true;
504 }
505
506 if ( NULL != pDumpRecFile )
507 {
508 int32_t i = 0;
509 int32_t j = 0;
510 const int32_t kiStrideY = pCurPicture->iLineSize[0];
511 const int32_t kiLumaWidth = pCurPicture->iWidthInPixel;
512 const int32_t kiLumaHeight = pCurPicture->iHeightInPixel;
513 const int32_t kiChromaWidth = kiLumaWidth >> 1;
514 const int32_t kiChromaHeight = kiLumaHeight >> 1;
515
516 for( j = 0; j < kiLumaHeight; ++ j)
517 {
518 iWrittenSize = fwrite( &pCurPicture->pData[0][j*kiStrideY], 1, kiLumaWidth, pDumpRecFile );
519 assert( iWrittenSize == kiLumaWidth );
520 if ( iWrittenSize < kiLumaWidth )
521 {
522 assert( 0 ); // make no sense for us if writing failed
523 fclose(pDumpRecFile);
524 return;
525 }
526 }
527 for( i = 1; i < I420_PLANES; ++ i)
528 {
529 const int32_t kiStrideUV = pCurPicture->iLineSize[i];
530 for ( j = 0; j < kiChromaHeight; ++ j)
531 {
532 iWrittenSize = fwrite( &pCurPicture->pData[i][j*kiStrideUV], 1, kiChromaWidth, pDumpRecFile );
533 assert(iWrittenSize == kiChromaWidth );
534 if ( iWrittenSize < kiChromaWidth )
535 {
536 assert( 0 ); // make no sense for us if writing failed
537 fclose(pDumpRecFile);
538 return;
539 }
540 }
541 }
542 fclose(pDumpRecFile);
543 pDumpRecFile = NULL;
544 }
545}
546
547
548
549/***********************************************************************************/
550void WelsSetMemZero_c(void *pDst, int32_t iSize) // confirmed_safe_unsafe_usage
551{
552 memset(pDst, 0, iSize);
553}
554}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t