Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 1 file). Show all
Unified · Split
| @@ -2433,6 +2433,51 @@ int32_t GetMultipleThreadIdc (SLogContext* pLogCtx, SWelsSvcCodingParam* pCoding · 2432 unmodified lines | ||
| 2433 | 2433 | return 0; |
| 2434 | 2434 | } |
| 2435 | 2435 | |
| 2436 | +/*! | |
| 2437 | + * \brief uninitialize Wels encoder core library | |
| 2438 | + * \pParam pEncCtx sWelsEncCtx* | |
| 2439 | + * \return none | |
| 2440 | + */ | |
| 2441 | +void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { | |
| 2442 | + if (NULL == ppCtx || NULL == *ppCtx) | |
| 2443 | + return; | |
| 2444 | + | |
| 2445 | + WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO, | |
| 2446 | + "WelsUninitEncoderExt(), pCtx= %p, iMultipleThreadIdc= %d.", | |
| 2447 | + (void*) (*ppCtx), (*ppCtx)->pSvcParam->iMultipleThreadIdc); | |
| 2448 | + | |
| 2449 | +#if defined(STAT_OUTPUT) | |
| 2450 | + StatOverallEncodingExt (*ppCtx); | |
| 2451 | +#endif | |
| 2452 | + | |
| 2453 | + if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) { | |
| 2454 | + const int32_t iThreadCount = (*ppCtx)->pSvcParam->iMultipleThreadIdc; | |
| 2455 | + int32_t iThreadIdx = 0; | |
| 2456 | + | |
| 2457 | + while (iThreadIdx < iThreadCount) { | |
| 2458 | + int res = 0; | |
| 2459 | + if ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]) { | |
| 2460 | + WelsEventSignal (& (*ppCtx)->pSliceThreading->pExitEncodeEvent[iThreadIdx]); | |
| 2461 | + WelsEventSignal (& (*ppCtx)->pSliceThreading->pThreadMasterEvent[iThreadIdx]); | |
| 2462 | + res = WelsThreadJoin ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]); // waiting thread exit | |
| 2463 | + WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO, "WelsUninitEncoderExt(), pthread_join(pThreadHandles%d) return %d..", | |
| 2464 | + iThreadIdx, | |
| 2465 | + res); | |
| 2466 | + (*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx] = 0; | |
| 2467 | + } | |
| 2468 | + ++ iThreadIdx; | |
| 2469 | + } | |
| 2470 | + } | |
| 2471 | + | |
| 2472 | + if ((*ppCtx)->pVpp) { | |
| 2473 | + (*ppCtx)->pVpp->FreeSpatialPictures (*ppCtx); | |
| 2474 | + delete (*ppCtx)->pVpp; | |
| 2475 | + (*ppCtx)->pVpp = NULL; | |
| 2476 | + } | |
| 2477 | + FreeMemorySvc (ppCtx); | |
| 2478 | + *ppCtx = NULL; | |
| 2479 | +} | |
| 2480 | + | |
| 2436 | 2481 | /*! |
| 2437 | 2482 | * \brief initialize Wels avc encoder core library |
| 2438 | 2483 | * \pParam ppCtx sWelsEncCtx** |
| @@ -2502,7 +2547,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 63 unmodified lines | ||
| 2502 | 2547 | iRet = RequestMemorySvc (&pCtx, pExistingParasetList); |
| 2503 | 2548 | if (iRet != 0) { |
| 2504 | 2549 | WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), RequestMemorySvc failed return %d.", iRet); |
| 2505 | − FreeMemorySvc (&pCtx); | |
| 2550 | + WelsUninitEncoderExt (&pCtx); | |
| 2506 | 2551 | return iRet; |
| 2507 | 2552 | } |
| 2508 | 2553 | |
| @@ -2514,12 +2559,12 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 5 unmodified lines | ||
| 2514 | 2559 | if (pCtx->pVpp == NULL) { |
| 2515 | 2560 | iRet = 1; |
| 2516 | 2561 | WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pOut of memory in case new CWelsPreProcess()."); |
| 2517 | − FreeMemorySvc (&pCtx); | |
| 2562 | + WelsUninitEncoderExt (&pCtx); | |
| 2518 | 2563 | return iRet; |
| 2519 | 2564 | } |
| 2520 | 2565 | if ((iRet = pCtx->pVpp->AllocSpatialPictures (pCtx, pCtx->pSvcParam)) != 0) { |
| 2521 | 2566 | WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pVPP alloc spatial pictures failed"); |
| 2522 | − FreeMemorySvc (&pCtx); | |
| 2567 | + WelsUninitEncoderExt (&pCtx); | |
| 2523 | 2568 | return iRet; |
| 2524 | 2569 | } |
| 2525 | 2570 | |
| @@ -2618,50 +2663,6 @@ void StatOverallEncodingExt (sWelsEncCtx* pCtx) { · 92 unmodified lines | ||
| 2618 | 2663 | } |
| 2619 | 2664 | } |
| 2620 | 2665 | #endif |
| 2621 | −/*! | |
| 2622 | − * \brief uninitialize Wels encoder core library | |
| 2623 | − * \pParam pEncCtx sWelsEncCtx* | |
| 2624 | − * \return none | |
| 2625 | − */ | |
| 2626 | −void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { | |
| 2627 | − if (NULL == ppCtx || NULL == *ppCtx) | |
| 2628 | − return; | |
| 2629 | − | |
| 2630 | − WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO, | |
| 2631 | − "WelsUninitEncoderExt(), pCtx= %p, iMultipleThreadIdc= %d.", | |
| 2632 | − (void*) (*ppCtx), (*ppCtx)->pSvcParam->iMultipleThreadIdc); | |
| 2633 | − | |
| 2634 | −#if defined(STAT_OUTPUT) | |
| 2635 | − StatOverallEncodingExt (*ppCtx); | |
| 2636 | −#endif | |
| 2637 | − | |
| 2638 | − if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) { | |
| 2639 | − const int32_t iThreadCount = (*ppCtx)->pSvcParam->iMultipleThreadIdc; | |
| 2640 | − int32_t iThreadIdx = 0; | |
| 2641 | − | |
| 2642 | − while (iThreadIdx < iThreadCount) { | |
| 2643 | − int res = 0; | |
| 2644 | − if ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]) { | |
| 2645 | − WelsEventSignal (& (*ppCtx)->pSliceThreading->pExitEncodeEvent[iThreadIdx]); | |
| 2646 | − WelsEventSignal (& (*ppCtx)->pSliceThreading->pThreadMasterEvent[iThreadIdx]); | |
| 2647 | − res = WelsThreadJoin ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]); // waiting thread exit | |
| 2648 | − WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO, "WelsUninitEncoderExt(), pthread_join(pThreadHandles%d) return %d..", | |
| 2649 | − iThreadIdx, | |
| 2650 | − res); | |
| 2651 | − (*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx] = 0; | |
| 2652 | − } | |
| 2653 | − ++ iThreadIdx; | |
| 2654 | − } | |
| 2655 | − } | |
| 2656 | − | |
| 2657 | − if ((*ppCtx)->pVpp) { | |
| 2658 | − (*ppCtx)->pVpp->FreeSpatialPictures (*ppCtx); | |
| 2659 | − delete (*ppCtx)->pVpp; | |
| 2660 | − (*ppCtx)->pVpp = NULL; | |
| 2661 | − } | |
| 2662 | − FreeMemorySvc (ppCtx); | |
| 2663 | − *ppCtx = NULL; | |
| 2664 | −} | |
| 2665 | 2666 | |
| 2666 | 2667 | /*! |
| 2667 | 2668 | * \brief get temporal level due to configuration and coding context |