• 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    nal_encap.h
33  *
34  * \brief   NAL pRawNal pData encapsulation
35  *
36  * \date    2/4/2009 Created
37  *
38  *************************************************************************************
39  */
40 #ifndef WELS_NAL_UNIT_ENCAPSULATION_H__
41 #define WELS_NAL_UNIT_ENCAPSULATION_H__
42 
43 #include "typedefs.h"
44 #include "wels_common_defs.h"
45 #include "wels_const.h"
46 
47 using namespace WelsCommon;
48 
49 //SBitStringAux
50 namespace WelsEnc {
51 
52 #define NAL_HEADER_SIZE (4)
53 /*
54  *  Raw payload pData for NAL unit, AVC/SVC compatible
55  */
56 typedef struct TagWelsNalRaw {
57 uint8_t*                pRawData;       // pRawNal payload for slice pData
58 int32_t                 iPayloadSize;   // size of pRawNal pData
59 
60 SNalUnitHeaderExt       sNalExt;        // NAL header information
61 
62 int32_t iStartPos; //NAL start position in buffer
63 } SWelsNalRaw;
64 
65 /*
66  *  Encoder majoy output pData
67  */
68 typedef struct TagWelsEncoderOutput {
69 uint8_t*        pBsBuffer;              // overall bitstream pBuffer allocation for a coded picture, recycling use intend.
70 uint32_t        uiSize;                 // size of allocation pBuffer above
71 
72 SBitStringAux   sBsWrite;
73 
74 // SWelsNalRaw             raw_nals[MAX_DEPENDENCY_LAYER*2+MAX_DEPENDENCY_LAYER*MAX_QUALITY_LEVEL]; // AVC: max up to SPS+PPS+max_slice_idc (2 + 8) for FMO;
75 SWelsNalRaw*    sNalList;               // nal list, adaptive for AVC/SVC in case single slice, multiple slices or fmo
76 int32_t*        pNalLen;
77 int32_t         iCountNals;             // count number of NAL in list
78 // SVC: num_sps (MAX_D) + num_pps (MAX_D) + num_vcl (MAX_D * MAX_Q)
79 int32_t         iNalIndex;              // coding NAL currently, 0 based
80 int32_t         iLayerBsIndex;          // layer index of  bit stream for SFrameBsIfo
81 // bool            bAnnexBFlag;            // annexeb flag, to figure it pOut the packetization mode whether need 4 bytes (0 0 0 1) of start code prefix
82 } SWelsEncoderOutput;
83 
84 //#define MT_DEBUG_BS_WR        0       // for MT debugging if needed
85 
86 typedef struct TagWelsSliceBs {
87 uint8_t*        pBs;                    // output bitstream, pBitStringAux not needed for slice 0 due to no dependency of pFrameBs available
88 uint32_t        uiBsPos;                // position of output bitstream
89 uint8_t*        pBsBuffer;              // overall bitstream pBuffer allocation for a coded slice, recycling use intend.
90 uint32_t        uiSize;                 // size of allocation pBuffer above
91 
92 SBitStringAux   sBsWrite;
93 
94 SWelsNalRaw     sNalList[2];            // nal list, PREFIX NAL(if applicable) + SLICE NAL
95 // int32_t         iCountNals;             // count number of NAL in list
96 int32_t         iNalLen[2];
97 int32_t         iNalIndex;              // coding NAL currently, 0 based
98 
99 // bool            bAnnexBFlag;            // annexeb flag, to figure it pOut the packetization mode whether need 4 bytes (0 0 0 1) of start code prefix
100 #if MT_DEBUG_BS_WR
101 bool            bSliceCodedFlag;
102 #endif//MT_DEBUG_BS_WR
103 } SWelsSliceBs;
104 
105 /*!
106  * \brief   load an initialize NAL pRawNal pData
107  */
108 void WelsLoadNal (SWelsEncoderOutput* pEncoderOuput, const int32_t/*EWelsNalUnitType*/ kiType,
109                   const int32_t/*EWelsNalRefIdc*/ kiNalRefIdc);
110 
111 /*!
112  * \brief   unload pRawNal NAL
113  */
114 void WelsUnloadNal (SWelsEncoderOutput* pEncoderOuput);
115 
116 /*!
117  * \brief   load an initialize NAL pRawNal pData
118  */
119 void WelsLoadNalForSlice (SWelsSliceBs* pSliceBs, const int32_t/*EWelsNalUnitType*/ kiType,
120                           const int32_t/*EWelsNalRefIdc*/ kiNalRefIdc);
121 
122 /*!
123  * \brief   unload pRawNal NAL
124  */
125 void WelsUnloadNalForSlice (SWelsSliceBs* pSliceBs);
126 
127 /*!
128  * \brief   encode NAL with emulation forbidden three bytes checking
129  * \param   pDst        pDst NAL pData
130  * \param   pDstLen     length of pDst NAL output
131  * \param   annexeb     annexeb flag
132  * \param   pRawNal     pRawNal NAL pData
133  * \return  ERR_CODE
134  */
135 int32_t WelsEncodeNal (SWelsNalRaw* pRawNal, void* pNalHeaderExt, const int32_t kiDstBufferLen, void* pDst,
136                        int32_t* pDstLen);
137 
138 /*!
139  * \brief   write prefix nal
140  */
141 int32_t WelsWriteSVCPrefixNal (SBitStringAux* pBitStringAux, const int32_t keNalRefIdc, const bool kbIdrFlag);
142 }
143 #endif//WELS_NAL_UNIT_ENCAPSULATION_H__
144