• 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  *  WelsDecoderExt.h
33  *
34  *  Abstract
35  *      Cisco OpenH264 decoder extension utilization interface
36  *
37  *  History
38  *      3/12/2009 Created
39  *
40  *
41  *************************************************************************/
42 #if !defined(WELS_PLUS_WELSDECODEREXT_H)
43 #define WELS_PLUS_WELSDECODEREXT_H
44 
45 #include "codec_api.h"
46 #include "codec_app_def.h"
47 #include "decoder_context.h"
48 #include "welsCodecTrace.h"
49 #include "cpu.h"
50 
51 class ISVCDecoder;
52 
53 namespace WelsDec {
54 
55 //#define OUTPUT_BIT_STREAM  ////for test to output bitstream
56 
57 class CWelsDecoder : public ISVCDecoder {
58  public:
59   CWelsDecoder (void);
60   virtual ~CWelsDecoder();
61 
62   virtual long EXTAPI Initialize (const SDecodingParam* pParam);
63   virtual long EXTAPI Uninitialize();
64 
65   /***************************************************************************
66   *   Description:
67   *       Decompress one frame, and output I420 or RGB24(in the future) decoded stream and its length.
68   *   Input parameters:
69   *       Parameter       TYPE                   Description
70   *       pSrc            unsigned char*         the h264 stream to decode
71   *       srcLength       int                    the length of h264 steam
72   *       pDst            unsigned char*         buffer pointer of decoded data
73   *       pDstInfo        SBufferInfo&           information provided to API including width, height, SW/HW option, etc
74   *
75   *   return: if decode frame success return 0, otherwise corresponding error returned.
76   ***************************************************************************/
77   virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* kpSrc,
78       const int kiSrcLen,
79       unsigned char** ppDst,
80       int* pStride,
81       int& iWidth,
82       int& iHeight);
83 
84   virtual DECODING_STATE EXTAPI DecodeFrameNoDelay (const unsigned char* kpSrc,
85       const int kiSrcLen,
86       unsigned char** ppDst,
87       SBufferInfo* pDstInfo);
88 
89   virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* kpSrc,
90       const int kiSrcLen,
91       unsigned char** ppDst,
92       SBufferInfo* pDstInfo);
93 
94   virtual DECODING_STATE EXTAPI FlushFrame (unsigned char** ppDst,
95       SBufferInfo* pDstInfo);
96 
97   virtual DECODING_STATE EXTAPI DecodeParser (const unsigned char* kpSrc,
98       const int kiSrcLen,
99       SParserBsInfo* pDstInfo);
100   virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* kpSrc,
101       const int kiSrcLen,
102       unsigned char* pDst,
103       int iDstStride,
104       int& iDstLen,
105       int& iWidth,
106       int& iHeight,
107       int& color_format);
108 
109   virtual long EXTAPI SetOption (DECODER_OPTION eOptID, void* pOption);
110   virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void* pOption);
111 
112  public:
113   DECODING_STATE DecodeFrame2WithCtx (PWelsDecoderContext pCtx, const unsigned char* kpSrc, const int kiSrcLen,
114                                       unsigned char** ppDst, SBufferInfo* pDstInfo);
115   DECODING_STATE ParseAccessUnit (SWelsDecoderThreadCTX& sThreadCtx);
116 
117  private:
118   welsCodecTrace*         m_pWelsTrace;
119   uint32_t                m_uiDecodeTimeStamp;
120   bool                    m_bIsBaseline;
121   int32_t                 m_iCpuCount;
122   int32_t                 m_iThreadCount;
123   int32_t                 m_iCtxCount;
124   PPicBuff                m_pPicBuff;
125   bool                    m_bParamSetsLostFlag;
126   bool                    m_bFreezeOutput;
127   int32_t                 m_DecCtxActiveCount;
128   PWelsDecoderThreadCTX   m_pDecThrCtx;
129   PWelsDecoderThreadCTX   m_pLastDecThrCtx;
130   int32_t                 m_iLastBufferedIdx;
131   WELS_MUTEX              m_csDecoder;
132   SWelsDecEvent           m_sBufferingEvent;
133   SWelsDecEvent           m_sReleaseBufferEvent;
134   SWelsDecSemphore        m_sIsBusy;
135   SPictInfo               m_sPictInfoList[16];
136   SPictReoderingStatus    m_sReoderingStatus;
137   PWelsDecoderThreadCTX   m_pDecThrCtxActive[WELS_DEC_MAX_NUM_CPU];
138   SVlcTable               m_sVlcTable;
139   SWelsLastDecPicInfo     m_sLastDecPicInfo;
140   SDecoderStatistics      m_sDecoderStatistics;// For real time debugging
141 
142  private:
143   int32_t InitDecoder (const SDecodingParam* pParam);
144   void UninitDecoder (void);
145   int32_t InitDecoderCtx (PWelsDecoderContext& pCtx, const SDecodingParam* pParam);
146   void UninitDecoderCtx (PWelsDecoderContext& pCtx);
147   int32_t ResetDecoder (PWelsDecoderContext& pCtx);
148   int32_t ThreadResetDecoder (PWelsDecoderContext& pCtx);
149 
150   void OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics);
151   DECODING_STATE ReorderPicturesInDisplay (PWelsDecoderContext pCtx, unsigned char** ppDst, SBufferInfo* pDstInfo);
152   int ThreadDecodeFrameInternal (const unsigned char* kpSrc, const int kiSrcLen, unsigned char** ppDst,
153                                  SBufferInfo* pDstInfo);
154   void BufferingReadyPicture (PWelsDecoderContext pCtx, unsigned char** ppDst, SBufferInfo* pDstInfo);
155   void ReleaseBufferedReadyPictureReorder (PWelsDecoderContext pCtx, unsigned char** ppDst, SBufferInfo* pDstInfo, bool isFlush = false);
156   void ReleaseBufferedReadyPictureNoReorder (PWelsDecoderContext pCtx, unsigned char** ppDst, SBufferInfo* pDstInfo);
157 
158   void OpenDecoderThreads();
159   void CloseDecoderThreads();
160 #ifdef OUTPUT_BIT_STREAM
161   WelsFileHandle* m_pFBS;
162   WelsFileHandle* m_pFBSSize;
163 #endif//OUTPUT_BIT_STREAM
164 
165 };
166 
167 } // namespace WelsDec
168 
169 #endif // !defined(WELS_PLUS_WELSDECODEREXT_H)
170