Showing the changes to codec/encoder/core/src/encoder.cpp (1 of 308 files). Show all
Unified · Split
| @@ -0,0 +1,554 @@ | |||
| 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 encoder.c | ||
| 33 | * | ||
| 34 | * \brief core encoder | ||
| 35 | * | ||
| 36 | * \date 5/14/2009 Created | ||
| 37 | * | ||
| 38 | ************************************************************************************* | ||
| 39 | */ | ||
| 40 | #include <stdio.h> | ||
| 41 | #include <stdlib.h> | ||
| 42 | #include <string.h> | ||
| 43 | #include <assert.h> | ||
| 44 | #include "encoder.h" | ||
| 45 | #include "extern.h" | ||
| 46 | #include "cpu.h" | ||
| 47 | #include "cpu_core.h" | ||
| 48 | #include "utils.h" | ||
| 49 | |||
| 50 | #include "encode_mb_aux.h" | ||
| 51 | #include "decode_mb_aux.h" | ||
| 52 | #include "get_intra_predictor.h" | ||
| 53 | #include "svc_encode_mb.h" | ||
| 54 | |||
| 55 | #include "deblocking.h" | ||
| 56 | #include "expand_pic.h" | ||
| 57 | |||
| 58 | #include "mc.h" | ||
| 59 | #include "sample.h" | ||
| 60 | |||
| 61 | #include "svc_encode_slice.h" | ||
| 62 | #include "svc_base_layer_md.h" | ||
| 63 | #include "svc_mode_decision.h" | ||
| 64 | #include "set_mb_syn_cavlc.h" | ||
| 65 | #include "crt_util_safe_x.h" // Safe CRT routines like utils for cross_platforms | ||
| 66 | #include "codec_def.h" | ||
| 67 | #ifdef MT_ENABLED | ||
| 68 | #include "slice_multi_threading.h" | ||
| 69 | #endif//MT_ENABLED | ||
| 70 | |||
| 71 | // global function pointers definition | ||
| 72 | namespace WelsSVCEnc { | ||
| 73 | /* Motion compensation */ | ||
| 74 | |||
| 75 | |||
| 76 | /*! | ||
| 77 | * \brief initialize source picture body | ||
| 78 | * \param pSrc SSourcePicture* | ||
| 79 | * \param csp internal csp format | ||
| 80 | * \param iWidth widht of picture in pixels | ||
| 81 | * \param iHeight iHeight of picture in pixels | ||
| 82 | * \return successful - 0; otherwise none 0 for failed | ||
| 83 | */ | ||
| 84 | int32_t InitPic( const void *kpSrc, const int32_t kiColorspace, const int32_t kiWidth, const int32_t kiHeight ) | ||
| 85 | { | ||
| 86 | SSourcePicture *pSrcPic = (SSourcePicture *)kpSrc; | ||
| 87 | |||
| 88 | if ( NULL == pSrcPic || kiWidth == 0 || kiHeight == 0 ) | ||
| 89 | return 1; | ||
| 90 | |||
| 91 | pSrcPic->iColorFormat = kiColorspace; | ||
| 92 | pSrcPic->iPicWidth = kiWidth; | ||
| 93 | pSrcPic->iPicHeight = kiHeight; | ||
| 94 | |||
| 95 | switch( kiColorspace & (~videoFormatVFlip) ) { | ||
| 96 | case videoFormatI420: | ||
| 97 | case videoFormatYV12: | ||
| 98 | pSrcPic->pData[0] = NULL; | ||
| 99 | pSrcPic->pData[1] = NULL; | ||
| 100 | pSrcPic->pData[2] = NULL; | ||
| 101 | pSrcPic->pData[3] = NULL; | ||
| 102 | pSrcPic->iStride[0] = kiWidth; | ||
| 103 | pSrcPic->iStride[2] = pSrcPic->iStride[1] = kiWidth >> 1; | ||
| 104 | pSrcPic->iStride[3] = 0; | ||
| 105 | break; | ||
| 106 | case videoFormatYUY2: | ||
| 107 | case videoFormatYVYU: | ||
| 108 | case videoFormatUYVY: | ||
| 109 | pSrcPic->pData[0] = NULL; | ||
| 110 | pSrcPic->pData[1] = NULL; | ||
| 111 | pSrcPic->pData[2] = NULL; | ||
| 112 | pSrcPic->pData[3] = NULL; | ||
| 113 | pSrcPic->iStride[0] = CALC_BI_STRIDE(kiWidth, 16); | ||
| 114 | pSrcPic->iStride[3] = pSrcPic->iStride[2] = pSrcPic->iStride[1] = 0; | ||
| 115 | break; | ||
| 116 | case videoFormatRGB: | ||
| 117 | case videoFormatBGR: | ||
| 118 | pSrcPic->pData[0] = NULL; | ||
| 119 | pSrcPic->pData[1] = NULL; | ||
| 120 | pSrcPic->pData[2] = NULL; | ||
| 121 | pSrcPic->pData[3] = NULL; | ||
| 122 | pSrcPic->iStride[0] = CALC_BI_STRIDE(kiWidth, 24); | ||
| 123 | pSrcPic->iStride[3] = pSrcPic->iStride[2] = pSrcPic->iStride[1] = 0; | ||
| 124 | if( kiColorspace & videoFormatVFlip ) | ||
| 125 | pSrcPic->iColorFormat = kiColorspace & (~videoFormatVFlip); | ||
| 126 | else | ||
| 127 | pSrcPic->iColorFormat = kiColorspace | videoFormatVFlip; | ||
| 128 | break; | ||
| 129 | case videoFormatBGRA: | ||
| 130 | case videoFormatRGBA: | ||
| 131 | case videoFormatARGB: | ||
| 132 | case videoFormatABGR: | ||
| 133 | pSrcPic->pData[0] = NULL; | ||
| 134 | pSrcPic->pData[1] = NULL; | ||
| 135 | pSrcPic->pData[2] = NULL; | ||
| 136 | pSrcPic->pData[3] = NULL; | ||
| 137 | pSrcPic->iStride[0] = kiWidth << 2; | ||
| 138 | pSrcPic->iStride[3] = pSrcPic->iStride[2] = pSrcPic->iStride[1] = 0; | ||
| 139 | if( kiColorspace & videoFormatVFlip ) | ||
| 140 | pSrcPic->iColorFormat = kiColorspace & (~videoFormatVFlip); | ||
| 141 | else | ||
| 142 | pSrcPic->iColorFormat = kiColorspace | videoFormatVFlip; | ||
| 143 | break; | ||
| 144 | default: | ||
| 145 | return 2; // any else? | ||
| 146 | } | ||
| 147 | |||
| 148 | return 0; | ||
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | void WelsInitBGDFunc( SWelsFuncPtrList *pFuncList, const bool_t kbEnableBackgroundDetection ) | ||
| 153 | { | ||
| 154 | if ( kbEnableBackgroundDetection ) | ||
| 155 | { | ||
| 156 | pFuncList->pfInterMdBackgroundDecision = (PInterMdBackgroundDecisionFunc)WelsMdInterJudgeBGDPskip; | ||
| 157 | pFuncList->pfInterMdBackgroundInfoUpdate = (PInterMdBackgroundInfoUpdateFunc)WelsMdInterUpdateBGDInfo; | ||
| 158 | } | ||
| 159 | else | ||
| 160 | { | ||
| 161 | pFuncList->pfInterMdBackgroundDecision = (PInterMdBackgroundDecisionFunc)WelsMdInterJudgeBGDPskipFalse; | ||
| 162 | pFuncList->pfInterMdBackgroundInfoUpdate = (PInterMdBackgroundInfoUpdateFunc)WelsMdInterUpdateBGDInfoNULL; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | /*! | ||
| 167 | * \brief initialize function pointers that potentially used in Wels encoding | ||
| 168 | * \param pEncCtx sWelsEncCtx* | ||
| 169 | * \return successful - 0; otherwise none 0 for failed | ||
| 170 | */ | ||
| 171 | int32_t InitFunctionPointers( SWelsFuncPtrList *pFuncList, SWelsSvcCodingParam *pParam, uint32_t uiCpuFlag ) | ||
| 172 | { | ||
| 173 | int32_t iReturn = 0; | ||
| 174 | |||
| 175 | /* Functionality utilization of CPU instructions dependency */ | ||
| 176 | pFuncList->pfSetMemZeroSize8 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage | ||
| 177 | pFuncList->pfSetMemZeroSize64Aligned16 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage | ||
| 178 | pFuncList->pfSetMemZeroSize64 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage | ||
| 179 | #if defined(X86_ASM) | ||
| 180 | if ( uiCpuFlag & WELS_CPU_MMXEXT ) | ||
| 181 | { | ||
| 182 | pFuncList->pfSetMemZeroSize8 = WelsSetMemZeroSize8_mmx; // confirmed_safe_unsafe_usage | ||
| 183 | pFuncList->pfSetMemZeroSize64Aligned16 = WelsSetMemZeroSize64_mmx; // confirmed_safe_unsafe_usage | ||
| 184 | pFuncList->pfSetMemZeroSize64 = WelsSetMemZeroSize64_mmx; // confirmed_safe_unsafe_usage | ||
| 185 | } | ||
| 186 | if ( uiCpuFlag & WELS_CPU_SSE2 ) | ||
| 187 | { | ||
| 188 | pFuncList->pfSetMemZeroSize64Aligned16 = WelsSetMemZeroAligned64_sse2; // confirmed_safe_unsafe_usage | ||
| 189 | } | ||
| 190 | #endif//X86_ASM | ||
| 191 | |||
| 192 | InitExpandPictureFunc( pFuncList, uiCpuFlag ); | ||
| 193 | |||
| 194 | /* Intra_Prediction_fn*/ | ||
| 195 | WelsInitFillingPredFuncs( uiCpuFlag ); | ||
| 196 | WelsInitIntraPredFuncs( pFuncList, uiCpuFlag ); | ||
| 197 | |||
| 198 | /* sad, satd, average */ | ||
| 199 | WelsInitSampleSadFunc(pFuncList, uiCpuFlag); | ||
| 200 | |||
| 201 | // | ||
| 202 | WelsInitBGDFunc(pFuncList, pParam->bEnableBackgroundDetection ); | ||
| 203 | // for pfGetVarianceFromIntraVaa function ptr adaptive by CPU features, 6/7/2010 | ||
| 204 | InitIntraAnalysisVaaInfo( pFuncList, uiCpuFlag ); | ||
| 205 | |||
| 206 | /* Motion compensation */ | ||
| 207 | /*init pixel average function*/ | ||
| 208 | /*get one column or row pixel when refinement*/ | ||
| 209 | WelsInitMcFuncs(pFuncList, uiCpuFlag); | ||
| 210 | InitCoeffFunc( uiCpuFlag ); | ||
| 211 | |||
| 212 | WelsInitEncodingFuncs( pFuncList, uiCpuFlag ); | ||
| 213 | WelsInitReconstructionFuncs( pFuncList, uiCpuFlag ); | ||
| 214 | |||
| 215 | DeblockingInit( &pFuncList->pfDeblocking, uiCpuFlag ); | ||
| 216 | WelsBlockFuncInit( &pFuncList->pfSetNZCZero, uiCpuFlag ); | ||
| 217 | |||
| 218 | InitFillNeighborCacheInterFunc ( pFuncList, pParam->bEnableBackgroundDetection ); | ||
| 219 | |||
| 220 | return iReturn; | ||
| 221 | } | ||
| 222 | |||
| 223 | /*! | ||
| 224 | * \brief initialize frame coding | ||
| 225 | */ | ||
| 226 | void InitFrameCoding( sWelsEncCtx *pEncCtx, const EFrameType keFrameType ) | ||
| 227 | { | ||
| 228 | // for bitstream writing | ||
| 229 | pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position | ||
| 230 | pEncCtx->pOut->iNalIndex = 0; // reset NAL index | ||
| 231 | |||
| 232 | InitBits( &pEncCtx->pOut->sBsWrite, pEncCtx->pOut->pBsBuffer, pEncCtx->pOut->uiSize ); | ||
| 233 | |||
| 234 | if ( keFrameType == WELS_FRAME_TYPE_P ) | ||
| 235 | { | ||
| 236 | if ( pEncCtx->pSvcParam->uiIntraPeriod ) | ||
| 237 | { | ||
| 238 | ++pEncCtx->iFrameIndex; | ||
| 239 | } | ||
| 240 | |||
| 241 | ++pEncCtx->uiFrameIdxRc; | ||
| 242 | |||
| 243 | if ( pEncCtx->iPOC < ( 1 << pEncCtx->pSps->iLog2MaxPocLsb ) - 2 ) // if iPOC type is no 0, this need be modification | ||
| 244 | pEncCtx->iPOC += 2; // for POC type 0 | ||
| 245 | else | ||
| 246 | pEncCtx->iPOC = 0; | ||
| 247 | |||
| 248 | if ( pEncCtx->eLastNalPriority != 0 ) | ||
| 249 | { | ||
| 250 | if ( pEncCtx->iFrameNum < (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1 ) | ||
| 251 | ++ pEncCtx->iFrameNum; | ||
| 252 | else | ||
| 253 | pEncCtx->iFrameNum = 0; // if iFrameNum overflow | ||
| 254 | } | ||
| 255 | pEncCtx->eNalType = NAL_UNIT_CODED_SLICE; | ||
| 256 | pEncCtx->eSliceType = P_SLICE; | ||
| 257 | pEncCtx->eNalPriority = NRI_PRI_HIGH; | ||
| 258 | } | ||
| 259 | else if ( keFrameType == WELS_FRAME_TYPE_IDR ) | ||
| 260 | { | ||
| 261 | pEncCtx->iFrameNum = 0; | ||
| 262 | pEncCtx->iPOC = 0; | ||
| 263 | pEncCtx->bEncCurFrmAsIdrFlag = false; | ||
| 264 | if ( pEncCtx->pSvcParam->uiIntraPeriod ) | ||
| 265 | { | ||
| 266 | pEncCtx->iFrameIndex = 0; | ||
| 267 | } | ||
| 268 | pEncCtx->uiFrameIdxRc = 0; | ||
| 269 | |||
| 270 | pEncCtx->eNalType = NAL_UNIT_CODED_SLICE_IDR; | ||
| 271 | pEncCtx->eSliceType = I_SLICE; | ||
| 272 | pEncCtx->eNalPriority = NRI_PRI_HIGHEST; | ||
| 273 | |||
| 274 | pEncCtx->iCodingIndex = 0; | ||
| 275 | |||
| 276 | // reset_ref_list | ||
| 277 | |||
| 278 | // rc_init_gop | ||
| 279 | } | ||
| 280 | else if ( keFrameType == WELS_FRAME_TYPE_I ) | ||
| 281 | { | ||
| 282 | if ( pEncCtx->iPOC < ( 1 << pEncCtx->pSps->iLog2MaxPocLsb ) - 2 ) // if iPOC type is no 0, this need be modification | ||
| 283 | pEncCtx->iPOC += 2; // for POC type 0 | ||
| 284 | else | ||
| 285 | pEncCtx->iPOC = 0; | ||
| 286 | |||
| 287 | if ( pEncCtx->eLastNalPriority != 0 ) | ||
| 288 | { | ||
| 289 | if ( pEncCtx->iFrameNum < (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1 ) | ||
| 290 | ++ pEncCtx->iFrameNum; | ||
| 291 | else | ||
| 292 | pEncCtx->iFrameNum = 0; // if iFrameNum overflow | ||
| 293 | } | ||
| 294 | |||
| 295 | pEncCtx->eNalType = NAL_UNIT_CODED_SLICE; | ||
| 296 | pEncCtx->eSliceType = I_SLICE; | ||
| 297 | pEncCtx->eNalPriority = NRI_PRI_HIGHEST; | ||
| 298 | |||
| 299 | // rc_init_gop | ||
| 300 | } | ||
| 301 | else // B pictures are not supported now, any else? | ||
| 302 | { | ||
| 303 | assert( 0 ); | ||
| 304 | } | ||
| 305 | |||
| 306 | #if defined(STAT_OUTPUT) | ||
| 307 | memset( &pEncCtx->sPerInfo, 0, sizeof(SStatSliceInfo) ); | ||
| 308 | #endif//FRAME_INFO_OUTPUT | ||
| 309 | |||
| 310 | #if defined(MT_ENABLED) && defined(PACKING_ONE_SLICE_PER_LAYER) | ||
| 311 | if ( pEncCtx->pSvcParam->iMultipleThreadIdc > 1 ) | ||
| 312 | reset_env_mt( pEncCtx ); | ||
| 313 | #endif | ||
| 314 | } | ||
| 315 | |||
| 316 | EFrameType DecideFrameType( sWelsEncCtx *pEncCtx, const int8_t kiSpatialNum ) | ||
| 317 | { | ||
| 318 | SWelsSvcCodingParam *pSvcParam = pEncCtx->pSvcParam; | ||
| 319 | EFrameType iFrameType = WELS_FRAME_TYPE_AUTO; | ||
| 320 | bool_t bSceneChangeFlag = false; | ||
| 321 | |||
| 322 | // perform scene change detection | ||
| 323 | if ( (!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag || | ||
| 324 | (kiSpatialNum < pSvcParam->iNumDependencyLayer) || (pEncCtx->uiFrameIdxRc < (VGOP_SIZE << 1)) ) // avoid too frequent I frame coding, rc control | ||
| 325 | { | ||
| 326 | bSceneChangeFlag = false; | ||
| 327 | } | ||
| 328 | else | ||
| 329 | { | ||
| 330 | bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag; | ||
| 331 | } | ||
| 332 | |||
| 333 | //scene_changed_flag: RC enable && iSpatialNum == pSvcParam->iNumDependencyLayer | ||
| 334 | //bIdrPeriodFlag: RC disable || iSpatialNum != pSvcParam->iNumDependencyLayer | ||
| 335 | //pEncCtx->bEncCurFrmAsIdrFlag: 1. first frame should be IDR; 2. idr pause; 3. idr request | ||
| 336 | iFrameType = ( pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag || pEncCtx->bEncCurFrmAsIdrFlag ) ? WELS_FRAME_TYPE_IDR : WELS_FRAME_TYPE_P; | ||
| 337 | |||
| 338 | if ( WELS_FRAME_TYPE_P == iFrameType && pEncCtx->iSkipFrameFlag > 0 ) // for frame skip, 1/5/2010 | ||
| 339 | { | ||
| 340 | -- pEncCtx->iSkipFrameFlag; | ||
| 341 | iFrameType = WELS_FRAME_TYPE_SKIP; | ||
| 342 | } | ||
| 343 | else if ( WELS_FRAME_TYPE_IDR == iFrameType ) | ||
| 344 | { | ||
| 345 | pEncCtx->iCodingIndex = 0; | ||
| 346 | } | ||
| 347 | |||
| 348 | return iFrameType; | ||
| 349 | } | ||
| 350 | |||
| 351 | /*! | ||
| 352 | * \brief Dump reconstruction for dependency layer | ||
| 353 | */ | ||
| 354 | |||
| 355 | extern "C" void DumpDependencyRec( SPicture *pCurPicture, const str_t *kpFileName, const int8_t kiDid ) | ||
| 356 | { | ||
| 357 | FILE *pDumpRecFile = NULL; | ||
| 358 | static bool_t bDependencyRecFlag[MAX_DEPENDENCY_LAYER] = {0}; | ||
| 359 | int32_t iWrittenSize = 0; | ||
| 360 | |||
| 361 | if ( NULL == pCurPicture || NULL == kpFileName || kiDid >= MAX_DEPENDENCY_LAYER ) | ||
| 362 | return; | ||
| 363 | |||
| 364 | if ( bDependencyRecFlag[kiDid] ) | ||
| 365 | { | ||
| 366 | if ( STRNLEN(kpFileName, MAX_FNAME_LEN) > 0 ) // confirmed_safe_unsafe_usage | ||
| 367 | #if defined(__GNUC__) || (defined(WIN32) && defined(_MSC_VER) && (_MSC_VER<1500)) | ||
| 368 | pDumpRecFile = FOPEN( kpFileName, "ab" ); | ||
| 369 | #elif defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008 | ||
| 370 | FOPEN(&pDumpRecFile, kpFileName, "ab"); | ||
| 371 | #endif//__GNUC__.. | ||
| 372 | else | ||
| 373 | { | ||
| 374 | str_t sDependencyRecFileName[16] = {0}; | ||
| 375 | #if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008 | ||
| 376 | SNPRINTF( sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid ); // confirmed_safe_unsafe_usage | ||
| 377 | FOPEN( &pDumpRecFile, sDependencyRecFileName, "ab" ); | ||
| 378 | #else | ||
| 379 | SNPRINTF( sDependencyRecFileName, 16, "rec%d.yuv", kiDid ); // confirmed_safe_unsafe_usage | ||
| 380 | pDumpRecFile = FOPEN( sDependencyRecFileName, "ab" ); | ||
| 381 | #endif//WIN32.. | ||
| 382 | } | ||
| 383 | if ( NULL != pDumpRecFile) | ||
| 384 | fseek( pDumpRecFile, 0, SEEK_END ); | ||
| 385 | } | ||
| 386 | else | ||
| 387 | { | ||
| 388 | if ( STRNLEN(kpFileName, MAX_FNAME_LEN) > 0 ) // confirmed_safe_unsafe_usage | ||
| 389 | { | ||
| 390 | #if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008 | ||
| 391 | FOPEN(&pDumpRecFile, kpFileName, "wb"); | ||
| 392 | #else | ||
| 393 | pDumpRecFile = FOPEN( kpFileName, "wb" ); | ||
| 394 | #endif//WIN32.. | ||
| 395 | } | ||
| 396 | else | ||
| 397 | { | ||
| 398 | str_t sDependencyRecFileName[16] = {0}; | ||
| 399 | #if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008 | ||
| 400 | SNPRINTF( sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid ); // confirmed_safe_unsafe_usage | ||
| 401 | FOPEN(&pDumpRecFile, sDependencyRecFileName, "wb"); | ||
| 402 | #else | ||
| 403 | SNPRINTF( sDependencyRecFileName, 16, "rec%d.yuv", kiDid ); // confirmed_safe_unsafe_usage | ||
| 404 | pDumpRecFile = FOPEN( sDependencyRecFileName, "wb"); | ||
| 405 | #endif//WIN32.. | ||
| 406 | } | ||
| 407 | bDependencyRecFlag[kiDid] = true; | ||
| 408 | } | ||
| 409 | |||
| 410 | if ( NULL != pDumpRecFile ) | ||
| 411 | { | ||
| 412 | int32_t i = 0; | ||
| 413 | int32_t j = 0; | ||
| 414 | const int32_t kiStrideY = pCurPicture->iLineSize[0]; | ||
| 415 | const int32_t kiLumaWidth = pCurPicture->iWidthInPixel; | ||
| 416 | const int32_t kiLumaHeight = pCurPicture->iHeightInPixel; | ||
| 417 | const int32_t kiChromaWidth = kiLumaWidth >> 1; | ||
| 418 | const int32_t kiChromaHeight = kiLumaHeight >> 1; | ||
| 419 | |||
| 420 | for( j = 0; j < kiLumaHeight; ++ j) | ||
| 421 | { | ||
| 422 | iWrittenSize = fwrite( &pCurPicture->pData[0][j*kiStrideY], 1, kiLumaWidth, pDumpRecFile ); | ||
| 423 | assert( iWrittenSize == kiLumaWidth ); | ||
| 424 | if ( iWrittenSize < kiLumaWidth ) | ||
| 425 | { | ||
| 426 | assert( 0 ); // make no sense for us if writing failed | ||
| 427 | fclose(pDumpRecFile); | ||
| 428 | return; | ||
| 429 | } | ||
| 430 | } | ||
| 431 | for( i = 1; i < I420_PLANES; ++ i) | ||
| 432 | { | ||
| 433 | const int32_t kiStrideUV = pCurPicture->iLineSize[i]; | ||
| 434 | for ( j = 0; j < kiChromaHeight; ++ j) | ||
| 435 | { | ||
| 436 | iWrittenSize = fwrite( &pCurPicture->pData[i][j*kiStrideUV], 1, kiChromaWidth, pDumpRecFile ); | ||
| 437 | assert(iWrittenSize == kiChromaWidth ); | ||
| 438 | if ( iWrittenSize < kiChromaWidth ) | ||
| 439 | { | ||
| 440 | assert( 0 ); // make no sense for us if writing failed | ||
| 441 | fclose(pDumpRecFile); | ||
| 442 | return; | ||
| 443 | } | ||
| 444 | } | ||
| 445 | } | ||
| 446 | fclose(pDumpRecFile); | ||
| 447 | pDumpRecFile = NULL; | ||
| 448 | } | ||
| 449 | } | ||
| 450 | |||
| 451 | /*! | ||
| 452 | * \brief Dump the reconstruction pictures | ||
| 453 | */ | ||
| 454 | |||
| 455 | void DumpRecFrame( SPicture *pCurPicture, const str_t *kpFileName ) | ||
| 456 | { | ||
| 457 | FILE *pDumpRecFile = NULL; | ||
| 458 | static bool_t bRecFlag = false; | ||
| 459 | int32_t iWrittenSize = 0; | ||
| 460 | |||
| 461 | if ( NULL == pCurPicture || NULL == kpFileName ) | ||
| 462 | return; | ||
| 463 | |||
| 464 | if ( bRecFlag ) | ||
| 465 | { | ||
| 466 | if ( STRNLEN(kpFileName, MAX_FNAME_LEN) > 0 ) // confirmed_safe_unsafe_usage | ||
| 467 | { | ||
| 468 | #if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008 | ||
| 469 | FOPEN(&pDumpRecFile, kpFileName, "ab"); | ||
| 470 | #else | ||
| 471 | pDumpRecFile = FOPEN( kpFileName, "ab" ); | ||
| 472 | #endif//WIN32 | ||
| 473 | } | ||
| 474 | else | ||
| 475 | { | ||
| 476 | #if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008 | ||
| 477 | FOPEN(&pDumpRecFile, "rec.yuv", "ab"); | ||
| 478 | #else | ||
| 479 | pDumpRecFile = FOPEN( "rec.yuv", "ab" ); | ||
| 480 | #endif//WIN32 | ||
| 481 | } | ||
| 482 | if ( NULL != pDumpRecFile) | ||
| 483 | fseek( pDumpRecFile, 0, SEEK_END ); | ||
| 484 | } | ||
| 485 | else | ||
| 486 | { | ||
| 487 | if ( STRNLEN(kpFileName, MAX_FNAME_LEN) > 0 ) // confirmed_safe_unsafe_usage | ||
| 488 | { | ||
| 489 | #if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008 | ||
| 490 | FOPEN(&pDumpRecFile, kpFileName, "wb"); | ||
| 491 | #else | ||
| 492 | pDumpRecFile = FOPEN( kpFileName, "wb" ); | ||
| 493 | #endif//WIN32 | ||
| 494 | } | ||
| 495 | else | ||
| 496 | { | ||
| 497 | #if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008 | ||
| 498 | FOPEN(&pDumpRecFile, "rec.yuv", "wb"); | ||
| 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 | /***********************************************************************************/ | ||
| 550 | void WelsSetMemZero_c(void *pDst, int32_t iSize) // confirmed_safe_unsafe_usage | ||
| 551 | { | ||
| 552 | memset(pDst, 0, iSize); | ||
| 553 | } | ||
| 554 | } | ||