• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    svc_encode_slice.h
33  *
34  * \brief   svc encoding slice
35  *
36  * \date    2009.07.27 Created
37  *
38  *************************************************************************************
39  */
40 #ifndef SVC_ENCODE_SLICE_H__
41 #define SVC_ENCODE_SLICE_H__
42 
43 #include "encoder_context.h"
44 #include "as264_common.h"
45 #include "svc_enc_macroblock.h"
46 #include "mb_cache.h"
47 
48 namespace WelsEnc {
49 #if defined(MB_TYPES_CHECK)
50 void WelsCountMbType (int32_t (*iMbCount)[18], const EWelsSliceType eSt, const SMB* pMb);
51 #endif
52 
53 void UpdateMbNeighbor(SDqLayer* pCurDq, SMB* pMb, const int32_t kiMbWidth, uint16_t uiSliceIdc);
54 
55 void UpdateNonZeroCountCache (SMB* pMb, SMbCache* pMbCache);
56 
57 //for P SSlice (intra part + inter part, MB level)
58 void OutputPMbWithoutConstructCsRsNoCopy (sWelsEncCtx* pEncCtx, SDqLayer* pDq, SSlice* pSlice, SMB* pMb);
59 
60 void WelsSliceHeaderScalExtInit (SDqLayer* pCurLayer, SSlice* pSlice);
61 void WelsSliceHeaderExtInit (sWelsEncCtx* pEncCtx, SDqLayer* pCurLayer, SSlice* pSlice);
62 
63 void WelsSliceHeaderWrite (SBitStringAux* pBs, SDqLayer* pCurLayer, SSlice* pSlice, uint32_t uiPpsIdBasis);
64 void WelsSliceHeaderExtWrite (SBitStringAux* pBs, SDqLayer* pCurLayer, SSlice* pSlice, uint32_t uiPpsIdBasis);
65 
66 //===================MB-leve encode====================//
67 void WelsInterMbEncode (sWelsEncCtx* pEncCtx, SSlice* pSlice, SMB* pCurMb); //only for inter part
68 //for I SSlice (only intra part, MB level)
69 void WelsIMbChromaEncode (sWelsEncCtx* pEncCtx, SMB* pCurMb, SMbCache* pMbCache);
70 //for P SSlice (intra part + inter part, MB level)
71 void WelsPMbChromaEncode (sWelsEncCtx* pEncCtx, SSlice* pSlice, SMB* pCurMb);
72 
73 
74 //===================MB-level encode====================//
75 //encapsulation func: store base rec, highest Dependency Layer(only one quality) rec, single layer rec
76 int32_t WelsPSliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice,  const bool kbIsHighestDlayerFlag);
77 int32_t WelsPSliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice,  const bool kbIsHighestDlayerFlag);
78 
79 //encapsulation func: store base rec, highest Dependency Layer(only one quality) rec, single layer rec
80 int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice);         // for intra non-dynamic slice
81 int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice);  // for intra dynamic slice
82 
83 //slice buffer init, allocate/re-allocate and free process
84 int32_t AllocMbCacheAligned (SMbCache* pMbCache, CMemoryAlign* pMa);
85 void FreeMbCache (SMbCache* pMbCache, CMemoryAlign* pMa);
86 
87 int32_t InitSliceBoundaryInfo (SDqLayer* pCurLayer,
88                                SSliceArgument* pSliceArgument,
89                                const int32_t kiSliceNumInFrame);
90 
91 int32_t SetSliceBoundaryInfo(SDqLayer* pCurLayer, SSlice* pSlice, const int32_t kiSliceIdx);
92 
93 int32_t AllocateSliceMBBuffer (SSlice* pSlice, CMemoryAlign* pMa);
94 
95 int32_t InitSliceBsBuffer (SSlice* pSlice,
96                            SBitStringAux* pBsWrite,
97                            bool bIndependenceBsBuffer,
98                            const int32_t iMaxSliceBufferSize,
99                            CMemoryAlign* pMa);
100 
101 void FreeSliceBuffer (SSlice*& pSliceList,
102                       const int32_t kiMaxSliceNum,
103                       CMemoryAlign* pMa,
104                       const char* kpTag);
105 
106 void InitSliceHeadWithBase (SSlice* pSlice, SSlice* pBaseSlice);
107 
108 void InitSliceRefInfoWithBase (SSlice* pSlice, SSlice* pBaseSlice, const uint8_t kuiRefCount);
109 
110 int32_t InitSliceList (SSlice*& pSliceList,
111                        SBitStringAux* pBsWrite,
112                        const int32_t kiMaxSliceNum,
113                        const int32_t kiMaxSliceBufferSize,
114                        const bool bIndependenceBsBuffer,
115                        CMemoryAlign* pMa);
116 
117 int32_t InitAllSlicesInThread (sWelsEncCtx* pCtx);
118 
119 int32_t InitOneSliceInThread (sWelsEncCtx* pCtx,
120                               SSlice*& pSlice,
121                               const int32_t kiSlcBuffIdx,
122                               const int32_t kiDlayerIdx,
123                               const int32_t kiSliceIdx);
124 
125 int32_t InitSliceInLayer (sWelsEncCtx* pCtx,
126                           SDqLayer* pDqLayer,
127                           const int32_t kiDlayerIndex,
128                           CMemoryAlign* pMa);
129 
130 int32_t ReallocateSliceList (sWelsEncCtx* pCtx,
131                              SSliceArgument* pSliceArgument,
132                              SSlice*& pSliceList,
133                              const int32_t kiMaxSliceNumOld,
134                              const int32_t kiMaxSliceNumNew);
135 
136 int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx,
137                                  SDqLayer* pDqLayer,
138                                  const int32_t kiDlayerIdx,
139                                  const int32_t KiSlcBuffIdx);
140 
141 int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx);
142 
143 int32_t GetCurLayerNalCount(const SDqLayer* pCurDq, const int32_t kiCodedSliceNum);
144 int32_t GetTotalCodedNalCount(SFrameBSInfo* pFbi);
145 
146 int32_t FrameBsRealloc (sWelsEncCtx* pCtx,
147                         SFrameBSInfo* pFrameBsInfo,
148                         SLayerBSInfo* pLayerBsInfo,
149                         const int32_t kiMaxSliceNumOld);
150 
151 int32_t ReOrderSliceInLayer(sWelsEncCtx* pCtx,
152                             const SliceModeEnum kuiSliceMode,
153                             const int32_t kiThreadNum);
154 
155 int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx,
156                               SFrameBSInfo* pFrameBsInfo,
157                               SLayerBSInfo* pLayerBsInfo,
158                               const SliceModeEnum kuiSliceMode);
159 
160 //slice encoding process
161 int32_t WelsCodePSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice);
162 int32_t WelsCodePOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice);
163 
164 int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, SSlice* pCurSlice,
165                           const int32_t keNalType);
166 
167 void WelsInitSliceEncodingFuncs (uint32_t uiCpuFlag);
168 
169 void UpdateMbNeighbourInfoForNextSlice (SDqLayer* pCurDq,
170                                         SMB* pMbList,
171                                         const int32_t kiNextSliceFirstMbIdx,
172                                         const int32_t kiLastMbIdxInPartition);
173 void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
174                        int32_t iNextSliceFirstMbIdx, const int32_t kiLastMbIdxInPartition);
175 int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pMd,
176                            const int32_t kiSliceFirstMbXY); // for inter non-dynamic slice
177 int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pMd,
178     const int32_t kiSliceFirstMbXY); // for inter dynamic slice
179 
180 
181 bool DynSlcJudgeSliceBoundaryStepBack (void* pEncCtx, void* pSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
182                                        SDynamicSlicingStack* pDss);
183 }
184 #endif //SVC_ENCODE_SLICE_H__
185