History

Pretty printed the C++ code with astyle

Ethan Hugg committed 12 years ago

Commit ff6b6691 parent 063709c225 files · +48457 −51954Browse files

Showing the changes to codec/encoder/plus/src/welsEncoderExt.cpp (1 of 225 files). Show all

Unified · Split

codec/encoder/plus/src/welsEncoderExt.cpp+1226−1255
@@ -1,1255 +1,1226 @@
1/*!1/*!
2 * \copy2 * \copy
3 * Copyright (c) 2013, Cisco Systems3 * Copyright (c) 2013, Cisco Systems
4 * All rights reserved.4 * All rights reserved.
5 *5 *
6 * Redistribution and use in source and binary forms, with or without6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions7 * modification, are permitted provided that the following conditions
8 * are met:8 * are met:
9 *9 *
10 * * Redistributions of source code must retain the above copyright10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.11 * notice, this list of conditions and the following disclaimer.
12 *12 *
13 * * Redistributions in binary form must reproduce the above copyright13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the15 * the documentation and/or other materials provided with the
16 * distribution.16 * distribution.
17 *17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.29 * POSSIBILITY OF SUCH DAMAGE.
30 *30 *
31 */31 */
32 32
33#include <assert.h>33#include <assert.h>
34#include "welsEncoderExt.h"34#include "welsEncoderExt.h"
35#include "welsCodecTrace.h"35#include "welsCodecTrace.h"
36#include "typedefs.h"36#include "typedefs.h"
37#include "wels_const.h"37#include "wels_const.h"
38#include "utils.h"38#include "utils.h"
39#include "macros.h"39#include "macros.h"
40 40
41#include "crt_util_safe_x.h" // Safe CRT routines like util for cross platforms41#include "crt_util_safe_x.h" // Safe CRT routines like util for cross platforms
42#include "ref_list_mgr_svc.h"42#include "ref_list_mgr_svc.h"
43 43
44#include <time.h>44#include <time.h>
45#if defined(WIN32) /*&& defined(_DEBUG)*/45#if defined(WIN32) /*&& defined(_DEBUG)*/
46 46
47#include <windows.h>47#include <windows.h>
48#include <stdio.h>48#include <stdio.h>
49#include <stdarg.h>49#include <stdarg.h>
50#include <sys/types.h>50#include <sys/types.h>
51#include <sys/timeb.h>51#include <sys/timeb.h>
52#else52#else
53#include <sys/time.h>53#include <sys/time.h>
54#endif54#endif
55 55
56namespace WelsSVCEnc {56namespace WelsSVCEnc {
57 57
58/*58/*
59 * CWelsH264SVCEncoder class implementation59 * CWelsH264SVCEncoder class implementation
60 */60 */
61CWelsH264SVCEncoder::CWelsH264SVCEncoder()61CWelsH264SVCEncoder::CWelsH264SVCEncoder()
62: m_pEncContext ( NULL ),62 : m_pEncContext (NULL),
63#if defined(WIN32)||defined(_MACH_PLATFORM)||defined(__GNUC__) 63#if defined(WIN32)||defined(_MACH_PLATFORM)||defined(__GNUC__)
64 m_pWelsTrace ( NULL ),64 m_pWelsTrace (NULL),
65#endif65#endif
66 m_pSrcPicList ( NULL ),66 m_pSrcPicList (NULL),
67 m_iSrcListSize ( 0 ),67 m_iSrcListSize (0),
68 m_iMaxPicWidth ( 0 ),68 m_iMaxPicWidth (0),
69 m_iMaxPicHeight ( 0 ),69 m_iMaxPicHeight (0),
70 m_iCspInternal ( 0 ),70 m_iCspInternal (0),
71 m_bInitialFlag ( FALSE )71 m_bInitialFlag (FALSE) {
72{72#ifdef REC_FRAME_COUNT
73#ifdef REC_FRAME_COUNT73 int32_t m_uiCountFrameNum = 0;
74 int32_t m_uiCountFrameNum = 0;74#endif//REC_FRAME_COUNT
75#endif//REC_FRAME_COUNT75
76 76#ifdef OUTPUT_BIT_STREAM
77#ifdef OUTPUT_BIT_STREAM77 str_t strStreamFileName[1024] = { 0 }; //for .264
78 str_t strStreamFileName[1024] = { 0 }; //for .26478 int32_t iBufferUsed = 0;
79 int32_t iBufferUsed = 0;79 int32_t iBufferLeft = 1023;
80 int32_t iBufferLeft = 1023;80
81 81 str_t strLenFileName[1024] = { 0 }; //for .len
82 str_t strLenFileName[1024] = { 0 }; //for .len82 int32_t iBufferUsedSize = 0;
83 int32_t iBufferUsedSize = 0;83 int32_t iBufferLeftSize = 1023;
84 int32_t iBufferLeftSize = 1023;84#endif//OUTPUT_BIT_STREAM
85#endif//OUTPUT_BIT_STREAM85
86 86#ifdef OUTPUT_BIT_STREAM
87#ifdef OUTPUT_BIT_STREAM87 time_t tTime;
88 time_t tTime;88
89 89#if defined( WIN32 )
90#if defined( WIN32 )90#if defined(_MSC_VER)
91#if defined(_MSC_VER)91#if _MSC_VER>=1500
92#if _MSC_VER>=150092 struct tm tTimeNow;
93 struct tm tTimeNow;93#else
94#else94 struct tm* tTimeNow;
95 struct tm *tTimeNow;95#endif//_MSC_VER>=1500
96#endif//_MSC_VER>=150096#endif//_MSC_VER
97#endif//_MSC_VER97 struct _timeb tTimeb;
98 struct _timeb tTimeb;98
99 99 time (&tTime);
100 time(&tTime);100#if defined(_MSC_VER)
101#if defined(_MSC_VER)101#if _MSC_VER>=1500
102#if _MSC_VER>=1500102 LOCALTIME (&tTimeNow, &tTime);
103 LOCALTIME(&tTimeNow, &tTime);103#else
104#else104 tTimeNow = LOCALTIME (&tTime);
105 tTimeNow = LOCALTIME(&tTime);105 if (NULL == tTimeNow)
106 if ( NULL == tTimeNow )106 return;
107 return;107#endif//_MSC_VER>=1500
108#endif//_MSC_VER>=1500108#endif//_MSC_VER
109#endif//_MSC_VER109 FTIME (&tTimeb);
110 FTIME(&tTimeb);110#elif defined( __GNUC__ )
111#elif defined( __GNUC__ )111 struct tm* tTimeNow;
112 struct tm* tTimeNow;112 struct timeval tTimev;
113 struct timeval tTimev;113 time (&tTime);
114 time(&tTime);114 tTimeNow = (struct tm*)localtime (&tTime);
115 tTimeNow = (struct tm *)localtime(&tTime);115 gettimeofday (&tTimev, NULL);
116 gettimeofday(&tTimev,NULL);116#endif//WIN32
117#endif//WIN32 117
118 118#ifdef WIN32
119#ifdef WIN32119#if defined(_MSC_VER)
120#if defined(_MSC_VER)120#if _MSC_VER>=1500
121#if _MSC_VER>=1500121 iBufferUsed += SNPRINTF (strStreamFileName, iBufferLeft, iBufferLeft, "enc_bs_0x%p_", (void*)this);
122 iBufferUsed += SNPRINTF(strStreamFileName, iBufferLeft, iBufferLeft, "enc_bs_0x%p_", (void*)this);122 iBufferUsedSize += SNPRINTF (strLenFileName, iBufferLeftSize, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
123 iBufferUsedSize += SNPRINTF(strLenFileName, iBufferLeftSize, iBufferLeftSize, "enc_size_0x%p_", (void*)this);123#else
124#else124 iBufferUsed += SNPRINTF (strStreamFileName, iBufferLeft, "enc_bs_0x%p_", (void*)this);
125 iBufferUsed += SNPRINTF(strStreamFileName, iBufferLeft, "enc_bs_0x%p_", (void*)this);125 iBufferUsedSize += SNPRINTF (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
126 iBufferUsedSize += SNPRINTF(strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this);126#endif//_MSC_VER>=1500
127#endif//_MSC_VER>=1500127#endif//_MSC_VER
128#endif//_MSC_VER128#else
129#else129 iBufferUsed += SNPRINTF (strStreamFileName, iBufferLeft, "/tmp/enc_bs_0x%p_", (void*)this);
130 iBufferUsed += SNPRINTF(strStreamFileName, iBufferLeft, "/tmp/enc_bs_0x%p_", (void*)this);130 iBufferUsedSize += SNPRINTF (strLenFileName, iBufferLeftSize, "/tmp/enc_size_0x%p", (void*)this);
131 iBufferUsedSize += SNPRINTF(strLenFileName, iBufferLeftSize, "/tmp/enc_size_0x%p", (void*)this);131#endif//WIN32
132#endif//WIN32132
133 133
134 134 iBufferLeft -= iBufferUsed;
135 iBufferLeft -= iBufferUsed;135 if (iBufferLeft > iBufferUsed) {
136 if ( iBufferLeft > iBufferUsed )136#if defined(_GNUC__)
137 { 137 iBufferUsed += strftime (&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S", tTimeNow);
138#if defined(_GNUC__)138#else
139 iBufferUsed += strftime(&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S", tTimeNow);139#if defined(_MSC_VER)
140#else 140 iBufferUsed += strftime (&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S",
141#if defined(_MSC_VER)141#if _MSC_VER>=1500
142 iBufferUsed += strftime(&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S", 142 & tTimeNow
143#if _MSC_VER>=1500143#else
144 &tTimeNow144 tTimeNow
145#else145#endif//_MSC_VER>=1500
146 tTimeNow146 );
147#endif//_MSC_VER>=1500147#endif//_MSC_VER
148 );148#endif//__GNUC__
149#endif//_MSC_VER 149 iBufferLeft -= iBufferUsed;
150#endif//__GNUC__150 }
151 iBufferLeft -= iBufferUsed;151
152 }152 iBufferLeftSize -= iBufferUsedSize;
153 153 if (iBufferLeftSize > iBufferUsedSize) {
154 iBufferLeftSize -= iBufferUsedSize;154#if defined(_GNUC__)
155 if ( iBufferLeftSize> iBufferUsedSize )155 iBufferUsedSize += strftime (&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S", tTimeNow);
156 { 156#else
157#if defined(_GNUC__)157#if defined(_MSC_VER)
158 iBufferUsedSize += strftime(&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S", tTimeNow);158 iBufferUsedSize += strftime (&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S",
159#else159#if _MSC_VER>=1500
160#if defined(_MSC_VER)160 & tTimeNow
161 iBufferUsedSize += strftime(&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S", 161#else
162#if _MSC_VER>=1500162 tTimeNow
163 &tTimeNow163#endif//_MSC_VER>=1500
164#else164 );
165 tTimeNow165#endif//_MSC_VER
166#endif//_MSC_VER>=1500166#endif//__GNUC__
167 );167 iBufferLeftSize -= iBufferUsedSize;
168#endif//_MSC_VER168 }
169#endif//__GNUC__169
170 iBufferLeftSize -= iBufferUsedSize;170 if (iBufferLeft > iBufferUsed) {
171 }171#ifdef WIN32
172 172#if defined(_MSC_VER)
173 if ( iBufferLeft > iBufferUsed )173#if _MSC_VER>=1500
174 {174 iBufferUsed += SNPRINTF (&strStreamFileName[iBufferUsed], iBufferLeft, iBufferLeft, ".%03.3u.264", tTimeb.millitm);
175#ifdef WIN32175#else
176#if defined(_MSC_VER)176 iBufferUsed += SNPRINTF (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimeb.millitm);
177#if _MSC_VER>=1500177#endif//_MSC_VER>=1500
178 iBufferUsed += SNPRINTF(&strStreamFileName[iBufferUsed], iBufferLeft, iBufferLeft, ".%03.3u.264", tTimeb.millitm);178#endif//_MSC_VER
179#else179#else
180 iBufferUsed += SNPRINTF(&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimeb.millitm);180 iBufferUsed += SNPRINTF (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimev.tv_usec / 1000);
181#endif//_MSC_VER>=1500181#endif//WIN32
182#endif//_MSC_VER182 iBufferLeft -= iBufferUsed;
183#else183 }
184 iBufferUsed += SNPRINTF(&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimev.tv_usec/1000);184
185#endif//WIN32185 if (iBufferLeftSize > iBufferUsedSize) {
186 iBufferLeft -= iBufferUsed;186#ifdef WIN32
187 }187#if defined(_MSC_VER)
188 188#if _MSC_VER>=1500
189 if ( iBufferLeftSize > iBufferUsedSize )189 iBufferUsedSize += SNPRINTF (&strLenFileName[iBufferUsedSize], iBufferLeftSize, iBufferLeftSize, ".%03.3u.len",
190 {190 tTimeb.millitm);
191#ifdef WIN32191#else
192#if defined(_MSC_VER)192 iBufferUsedSize += SNPRINTF (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimeb.millitm);
193#if _MSC_VER>=1500193#endif//_MSC_VER>=1500
194 iBufferUsedSize += SNPRINTF(&strLenFileName[iBufferUsedSize], iBufferLeftSize, iBufferLeftSize, ".%03.3u.len", tTimeb.millitm);194#endif//_MSC_VER
195#else195#else
196 iBufferUsedSize += SNPRINTF(&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimeb.millitm);196 iBufferUsedSize += SNPRINTF (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimev.tv_usec / 1000);
197#endif//_MSC_VER>=1500197#endif//WIN32
198#endif//_MSC_VER198 iBufferLeftSize -= iBufferUsedSize;
199#else199 }
200 iBufferUsedSize += SNPRINTF(&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimev.tv_usec/1000);200
201#endif//WIN32201#if defined(__GNUC__)
202 iBufferLeftSize -= iBufferUsedSize;202 m_pFileBs = FOPEN (strStreamFileName, "wb");
203 }203 m_pFileBsSize = FOPEN (strLenFileName, "wb");
204 204#else
205#if defined(__GNUC__)205#if defined(_MSC_VER)
206 m_pFileBs = FOPEN(strStreamFileName, "wb");206#if _MSC_VER>=1500
207 m_pFileBsSize = FOPEN(strLenFileName, "wb");207 FOPEN (&m_pFileBs, strStreamFileName, "wb");
208#else208 FOPEN (&m_pFileBsSize, strLenFileName, "wb");
209#if defined(_MSC_VER)209#else
210#if _MSC_VER>=1500210 m_pFileBs = FOPEN (strStreamFileName, "wb");
211 FOPEN(&m_pFileBs, strStreamFileName, "wb");211 m_pFileBsSize = FOPEN (strLenFileName, "wb");
212 FOPEN(&m_pFileBsSize, strLenFileName, "wb");212#endif//_MSC_VER>=1500
213#else213#endif//_MSC_VER
214 m_pFileBs = FOPEN(strStreamFileName, "wb");214#endif//__GNUC__
215 m_pFileBsSize = FOPEN(strLenFileName, "wb");215
216#endif//_MSC_VER>=1500216 m_bSwitch = FALSE;
217#endif//_MSC_VER217 m_iSwitchTimes = 0;
218#endif//__GNUC__218#endif//OUTPUT_BIT_STREAM
219 219
220 m_bSwitch = FALSE;220 InitEncoder();
221 m_iSwitchTimes = 0;221}
222#endif//OUTPUT_BIT_STREAM222
223 223CWelsH264SVCEncoder::~CWelsH264SVCEncoder() {
224 InitEncoder();224 WelsLog (NULL, WELS_LOG_INFO, "CWelsH264SVCEncoder::~CWelsH264SVCEncoder()\n");
225}225#if defined(WIN32)||defined(_MACH_PLATFORM)||defined(__GNUC__)
226 226
227CWelsH264SVCEncoder::~CWelsH264SVCEncoder()227 if (m_pWelsTrace != NULL) {
228{ 228 delete m_pWelsTrace;
229 WelsLog(NULL, WELS_LOG_INFO, "CWelsH264SVCEncoder::~CWelsH264SVCEncoder()\n");229 m_pWelsTrace = NULL;
230#if defined(WIN32)||defined(_MACH_PLATFORM)||defined(__GNUC__) 230 }
231 231#endif
232 if ( m_pWelsTrace != NULL )232#ifdef REC_FRAME_COUNT
233 {233 WelsLog (m_pEncContext, WELS_LOG_INFO,
234 delete m_pWelsTrace;234 "CWelsH264SVCEncoder::~CWelsH264SVCEncoder(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum,
235 m_pWelsTrace = NULL;235 m_iCspInternal);
236 }236#endif
237#endif237
238#ifdef REC_FRAME_COUNT238#ifdef REC_FRAME_COUNT
239 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::~CWelsH264SVCEncoder(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );239 m_uiCountFrameNum = 0;
240#endif240#endif//REC_FRAME_COUNT
241 241
242#ifdef REC_FRAME_COUNT242#ifdef OUTPUT_BIT_STREAM
243 m_uiCountFrameNum = 0;243 if (m_pFileBs) {
244#endif//REC_FRAME_COUNT244 fclose (m_pFileBs);
245 245 m_pFileBs = NULL;
246#ifdef OUTPUT_BIT_STREAM246 }
247 if ( m_pFileBs )247 if (m_pFileBsSize) {
248 {248 fclose (m_pFileBsSize);
249 fclose( m_pFileBs );249 m_pFileBsSize = NULL;
250 m_pFileBs = NULL;250 }
251 }251 m_bSwitch = FALSE;
252 if ( m_pFileBsSize )252 m_iSwitchTimes = 0;
253 {253#endif//OUTPUT_BIT_STREAM
254 fclose( m_pFileBsSize );254
255 m_pFileBsSize = NULL;255 Uninitialize();
256 }256}
257 m_bSwitch = FALSE;257
258 m_iSwitchTimes = 0;258void CWelsH264SVCEncoder::InitEncoder (void) {
259#endif//OUTPUT_BIT_STREAM259#if defined(WIN32)||defined(_MACH_PLATFORM)||defined(__GNUC__)
260 260
261 Uninitialize();261#ifdef REC_FRAME_COUNT
262}262 WelsLog (m_pEncContext, WELS_LOG_INFO,
263 263 "CWelsH264SVCEncoder::InitEncoder, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal);
264void CWelsH264SVCEncoder::InitEncoder( void )264#endif
265{265
266#if defined(WIN32)||defined(_MACH_PLATFORM)||defined(__GNUC__) 266 m_pWelsTrace = new welsCodecTrace();
267 267 if (m_pWelsTrace != NULL) {
268#ifdef REC_FRAME_COUNT268 const int32_t iWelsTraceExistingFlag = m_pWelsTrace->WelsTraceModuleIsExist();
269 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::InitEncoder, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );269 if (iWelsTraceExistingFlag) {
270#endif270 m_pWelsTrace->SetTraceLevel (WELS_LOG_DEFAULT);
271 271 WelsSetLogCallback (welsCodecTrace::CODEC_TRACE);
272 m_pWelsTrace = new welsCodecTrace();272 }
273 if ( m_pWelsTrace != NULL )273 }
274 {274
275 const int32_t iWelsTraceExistingFlag = m_pWelsTrace->WelsTraceModuleIsExist();275 // initialization
276 if ( iWelsTraceExistingFlag )276 WelsSetLogLevel (WELS_LOG_DEFAULT); // no output, WELS_LOG_QUIET
277 {277#endif
278 m_pWelsTrace->SetTraceLevel( WELS_LOG_DEFAULT );278}
279 WelsSetLogCallback( welsCodecTrace::CODEC_TRACE );279
280 }280/* Interfaces override from ISVCEncoder */
281 }281
282 282/*
283 // initialization 283 * SVC Encoder Initialization
284 WelsSetLogLevel( WELS_LOG_DEFAULT ); // no output, WELS_LOG_QUIET284 */
285#endif 285int CWelsH264SVCEncoder::Initialize (SVCEncodingParam* argv, const INIT_TYPE iInitType) {
286}286 if (INIT_TYPE_PARAMETER_BASED != iInitType || NULL == argv) {
287 287 WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInitType= %d, argv= 0x%p\n",
288/* Interfaces override from ISVCEncoder */288 iInitType, (void*)argv);
289 289 return cmInitParaError;
290/*290 }
291 * SVC Encoder Initialization291
292 */292 if (m_bInitialFlag) {
293int CWelsH264SVCEncoder::Initialize(SVCEncodingParam* argv, const INIT_TYPE iInitType)293 WelsLog (m_pEncContext, WELS_LOG_WARNING, "CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d\n",
294{294 m_bInitialFlag);
295 if ( INIT_TYPE_PARAMETER_BASED != iInitType || NULL == argv )295 Uninitialize();
296 {296 }
297 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInitType= %d, argv= 0x%p\n", iInitType, (void *)argv);297
298 return cmInitParaError;298 SVCEncodingParam sEncodingParam;
299 }299 SWelsSvcCodingParam sConfig (true);
300 300
301 if ( m_bInitialFlag )301 memcpy (&sEncodingParam, argv, sizeof (SVCEncodingParam)); // confirmed_safe_unsafe_usage
302 {302
303 WelsLog(m_pEncContext, WELS_LOG_WARNING, "CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d\n", m_bInitialFlag);303#ifdef REC_FRAME_COUNT
304 Uninitialize();304 WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Initialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
305 } 305 m_uiCountFrameNum, m_iCspInternal);
306 306 WelsLog (m_pEncContext, WELS_LOG_INFO,
307 SVCEncodingParam sEncodingParam;307 "coding_param->iPicWidth= %d;coding_param->iPicHeight= %d;coding_param->iTargetBitrate= %d;coding_param->iRCMode= %d;coding_param->iTemporalLayerNum= %d;coding_param->iSpatialLayerNum= %d;coding_param->fFrameRate= %.6ff;coding_param->iInputCsp= %d;coding_param->iKeyPicCodingMode= %d;coding_param->uiIntraPeriod= %d;coding_param->bEnableSpsPpsIdAddition = %d;coding_param->bPrefixNalAddingCtrl = %d;coding_param->bEnableDenoise= %d;coding_param->bEnableBackgroundDetection= %d;coding_param->bEnableAdaptiveQuant= %d;coding_param->bEnableCropPic= %d;coding_param->bEnableLongTermReference= %d;coding_param->iLtrMarkPeriod= %d;\n",
308 SWelsSvcCodingParam sConfig( true );308 sEncodingParam.iPicWidth,
309 309 sEncodingParam.iPicHeight,
310 memcpy(&sEncodingParam, argv, sizeof(SVCEncodingParam)); // confirmed_safe_unsafe_usage310 sEncodingParam.iTargetBitrate,
311 311 sEncodingParam.iRCMode,
312#ifdef REC_FRAME_COUNT312 sEncodingParam.iTemporalLayerNum,
313 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Initialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );313 sEncodingParam.iSpatialLayerNum,
314 WelsLog( m_pEncContext, WELS_LOG_INFO, "coding_param->iPicWidth= %d;coding_param->iPicHeight= %d;coding_param->iTargetBitrate= %d;coding_param->iRCMode= %d;coding_param->iTemporalLayerNum= %d;coding_param->iSpatialLayerNum= %d;coding_param->fFrameRate= %.6ff;coding_param->iInputCsp= %d;coding_param->iKeyPicCodingMode= %d;coding_param->uiIntraPeriod= %d;coding_param->bEnableSpsPpsIdAddition = %d;coding_param->bPrefixNalAddingCtrl = %d;coding_param->bEnableDenoise= %d;coding_param->bEnableBackgroundDetection= %d;coding_param->bEnableAdaptiveQuant= %d;coding_param->bEnableCropPic= %d;coding_param->bEnableLongTermReference= %d;coding_param->iLtrMarkPeriod= %d;\n",314 sEncodingParam.fFrameRate,
315 sEncodingParam.iPicWidth,315 sEncodingParam.iInputCsp,
316 sEncodingParam.iPicHeight,316 sEncodingParam.iKeyPicCodingMode,
317 sEncodingParam.iTargetBitrate,317 sEncodingParam.iIntraPeriod,
318 sEncodingParam.iRCMode,318 sEncodingParam.bEnableSpsPpsIdAddition,
319 sEncodingParam.iTemporalLayerNum,319 sEncodingParam.bPrefixNalAddingCtrl,
320 sEncodingParam.iSpatialLayerNum,320 sEncodingParam.bEnableDenoise,
321 sEncodingParam.fFrameRate,321 sEncodingParam.bEnableBackgroundDetection,
322 sEncodingParam.iInputCsp,322 sEncodingParam.bEnableAdaptiveQuant,
323 sEncodingParam.iKeyPicCodingMode,323 sEncodingParam.bEnableCropPic,
324 sEncodingParam.iIntraPeriod,324 sEncodingParam.bEnableLongTermReference,
325 sEncodingParam.bEnableSpsPpsIdAddition,325 sEncodingParam.iLtrMarkPeriod);
326 sEncodingParam.bPrefixNalAddingCtrl,326 int32_t i = 0;
327 sEncodingParam.bEnableDenoise,327 while (i < sEncodingParam.iSpatialLayerNum) {
328 sEncodingParam.bEnableBackgroundDetection,328 SSpatialLayerConfig* spatial_cfg = &sEncodingParam.sSpatialLayers[i];
329 sEncodingParam.bEnableAdaptiveQuant,329 WelsLog (m_pEncContext, WELS_LOG_INFO,
330 sEncodingParam.bEnableCropPic,330 "coding_param->sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iQualityLayerNum= %d; .iSpatialBitrate= %d; .iCgsSnrRefined= %d; .iInterSpatialLayerPredFlag= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.uiSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\n",
331 sEncodingParam.bEnableLongTermReference,331 i, spatial_cfg->iVideoWidth,
332 sEncodingParam.iLtrMarkPeriod);332 spatial_cfg->iVideoHeight,
333 int32_t i = 0;333 spatial_cfg->fFrameRate,
334 while (i < sEncodingParam.iSpatialLayerNum) {334 spatial_cfg->iQualityLayerNum,
335 SSpatialLayerConfig *spatial_cfg = &sEncodingParam.sSpatialLayers[i];335 spatial_cfg->iSpatialBitrate,
336 WelsLog( m_pEncContext, WELS_LOG_INFO, "coding_param->sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iQualityLayerNum= %d; .iSpatialBitrate= %d; .iCgsSnrRefined= %d; .iInterSpatialLayerPredFlag= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.uiSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\n",336 spatial_cfg->iCgsSnrRefined,
337 i, spatial_cfg->iVideoWidth,337 spatial_cfg->iInterSpatialLayerPredFlag,
338 spatial_cfg->iVideoHeight,338 spatial_cfg->sSliceCfg.uiSliceMode,
339 spatial_cfg->fFrameRate,339 spatial_cfg->sSliceCfg.sSliceArgument.uiSliceNum,
340 spatial_cfg->iQualityLayerNum,340 spatial_cfg->sSliceCfg.sSliceArgument.uiSliceSizeConstraint
341 spatial_cfg->iSpatialBitrate,341 );
342 spatial_cfg->iCgsSnrRefined,342 ++ i;
343 spatial_cfg->iInterSpatialLayerPredFlag,343 }
344 spatial_cfg->sSliceCfg.uiSliceMode, 344#endif//REC_FRAME_COUNT
345 spatial_cfg->sSliceCfg.sSliceArgument.uiSliceNum,345
346 spatial_cfg->sSliceCfg.sSliceArgument.uiSliceSizeConstraint346 // Convert SVCEncodingParam into WelsSVCParamConfig here..
347 );347 if (sConfig.ParamTranscode (sEncodingParam, true)) {
348 ++ i;348 WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");
349 }349 Uninitialize();
350#endif//REC_FRAME_COUNT350 return cmInitParaError;
351 351 }
352 // Convert SVCEncodingParam into WelsSVCParamConfig here.. 352
353 if ( sConfig.ParamTranscode( sEncodingParam, true ) ){353 m_iSrcListSize = 1;
354 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");354
355 Uninitialize();355 return Initialize ((void*)&sConfig, INIT_TYPE_CONFIG_BASED);
356 return cmInitParaError;356}
357 }357
358 358int CWelsH264SVCEncoder::Initialize (void* argv, const INIT_TYPE iInitType) {
359 m_iSrcListSize = 1;359 if (INIT_TYPE_CONFIG_BASED != iInitType || NULL == argv) {
360 360 WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInitType= %d, argv= 0x%p.\n",
361 return Initialize((void *)&sConfig, INIT_TYPE_CONFIG_BASED);361 iInitType, (void*)argv);
362}362 return cmInitParaError;
363 363 }
364int CWelsH264SVCEncoder::Initialize(void * argv, const INIT_TYPE iInitType)364
365{365 if (m_bInitialFlag) {
366 if ( INIT_TYPE_CONFIG_BASED != iInitType || NULL == argv )366 WelsLog (m_pEncContext, WELS_LOG_WARNING, "CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d.\n",
367 {367 m_bInitialFlag);
368 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInitType= %d, argv= 0x%p.\n", iInitType, (void *)argv);368 Uninitialize();
369 return cmInitParaError;369 }
370 }370
371 371 SWelsSvcCodingParam* pCfg = static_cast<SWelsSvcCodingParam*> (argv);
372 if ( m_bInitialFlag )372
373 {373 const int32_t iColorspace = pCfg->iInputCsp;
374 WelsLog(m_pEncContext, WELS_LOG_WARNING, "CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d.\n", m_bInitialFlag);374 if (0 == iColorspace) {
375 Uninitialize();375 WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInputCsp= %d.\n", iColorspace);
376 }376 Uninitialize();
377 377 return cmInitParaError;
378 SWelsSvcCodingParam *pCfg = static_cast<SWelsSvcCodingParam*>(argv); 378 }
379 379
380 const int32_t iColorspace = pCfg->iInputCsp;380 // Check valid parameters
381 if ( 0 == iColorspace )381 const int32_t iNumOfLayers = pCfg->iNumDependencyLayer;
382 { 382 if (iNumOfLayers < 1 || iNumOfLayers > MAX_DEPENDENCY_LAYER) {
383 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInputCsp= %d.\n", iColorspace);383 WelsLog (m_pEncContext, WELS_LOG_ERROR,
384 Uninitialize();384 "CWelsH264SVCEncoder::Initialize(), invalid iNumDependencyLayer= %d, valid at range of [1, %d].\n", iNumOfLayers,
385 return cmInitParaError;385 MAX_DEPENDENCY_LAYER);
386 } 386 Uninitialize();
387 387 return cmInitParaError;
388 // Check valid parameters388 }
389 const int32_t iNumOfLayers = pCfg->iNumDependencyLayer;389 if (pCfg->iNumTemporalLayer < 1)
390 if ( iNumOfLayers < 1 || iNumOfLayers > MAX_DEPENDENCY_LAYER ){390 pCfg->iNumTemporalLayer = 1;
391 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iNumDependencyLayer= %d, valid at range of [1, %d].\n", iNumOfLayers, MAX_DEPENDENCY_LAYER);391 if (pCfg->iNumTemporalLayer > MAX_TEMPORAL_LEVEL) {
392 Uninitialize();392 WelsLog (m_pEncContext, WELS_LOG_ERROR,
393 return cmInitParaError;393 "CWelsH264SVCEncoder::Initialize(), invalid iNumTemporalLayer= %d, valid at range of [1, %d].\n",
394 }394 pCfg->iNumTemporalLayer, MAX_TEMPORAL_LEVEL);
395 if ( pCfg->iNumTemporalLayer < 1 )395 Uninitialize();
396 pCfg->iNumTemporalLayer = 1;396 return cmInitParaError;
397 if ( pCfg->iNumTemporalLayer > MAX_TEMPORAL_LEVEL ){397 }
398 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iNumTemporalLayer= %d, valid at range of [1, %d].\n", pCfg->iNumTemporalLayer, MAX_TEMPORAL_LEVEL);398
399 Uninitialize();399 // assert( cfg.uiGopSize >= 1 && ( cfg.uiIntraPeriod && (cfg.uiIntraPeriod % cfg.uiGopSize) == 0) );
400 return cmInitParaError;400
401 }401 if (pCfg->uiGopSize < 1 || pCfg->uiGopSize > MAX_GOP_SIZE) {
402 402 WelsLog (m_pEncContext, WELS_LOG_ERROR,
403 // assert( cfg.uiGopSize >= 1 && ( cfg.uiIntraPeriod && (cfg.uiIntraPeriod % cfg.uiGopSize) == 0) );403 "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d].\n", pCfg->uiGopSize,
404 404 MAX_GOP_SIZE);
405 if ( pCfg->uiGopSize < 1 || pCfg->uiGopSize > MAX_GOP_SIZE ){405 Uninitialize();
406 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d].\n", pCfg->uiGopSize, MAX_GOP_SIZE);406 return cmInitParaError;
407 Uninitialize();407 }
408 return cmInitParaError;408
409 }409 if (!WELS_POWER2_IF (pCfg->uiGopSize)) {
410 410 WelsLog (m_pEncContext, WELS_LOG_ERROR,
411 if ( !WELS_POWER2_IF(pCfg->uiGopSize) ){411 "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d] and yield to power of 2.\n",
412 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d] and yield to power of 2.\n", pCfg->uiGopSize, MAX_GOP_SIZE);412 pCfg->uiGopSize, MAX_GOP_SIZE);
413 Uninitialize();413 Uninitialize();
414 return cmInitParaError;414 return cmInitParaError;
415 }415 }
416 416
417 if ( pCfg->uiIntraPeriod && pCfg->uiIntraPeriod < pCfg->uiGopSize ) 417 if (pCfg->uiIntraPeriod && pCfg->uiIntraPeriod < pCfg->uiGopSize) {
418 { 418 WelsLog (m_pEncContext, WELS_LOG_ERROR,
419 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d.\n", pCfg->uiIntraPeriod, pCfg->uiGopSize);419 "CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d.\n",
420 Uninitialize();420 pCfg->uiIntraPeriod, pCfg->uiGopSize);
421 return cmInitParaError;421 Uninitialize();
422 }422 return cmInitParaError;
423 423 }
424 if ( ( pCfg->uiIntraPeriod && (pCfg->uiIntraPeriod & (pCfg->uiGopSize-1)) != 0) )424
425 {425 if ((pCfg->uiIntraPeriod && (pCfg->uiIntraPeriod & (pCfg->uiGopSize - 1)) != 0)) {
426 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d also multiple of it.\n", pCfg->uiIntraPeriod, pCfg->uiGopSize);426 WelsLog (m_pEncContext, WELS_LOG_ERROR,
427 Uninitialize();427 "CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d also multiple of it.\n",
428 return cmInitParaError;428 pCfg->uiIntraPeriod, pCfg->uiGopSize);
429 }429 Uninitialize();
430 430 return cmInitParaError;
431 // Fine tune num_ref_num431 }
432 if (pCfg->bEnableLongTermReference){432
433 pCfg->iLTRRefNum = LONG_TERM_REF_NUM;433 // Fine tune num_ref_num
434 }else{434 if (pCfg->bEnableLongTermReference) {
435 pCfg->iLTRRefNum = 0;435 pCfg->iLTRRefNum = LONG_TERM_REF_NUM;
436 }436 } else {
437 pCfg->iNumRefFrame = ((pCfg->uiGopSize>>1)>1)?((pCfg->uiGopSize>>1)+pCfg->iLTRRefNum):(MIN_REF_PIC_COUNT+pCfg->iLTRRefNum);437 pCfg->iLTRRefNum = 0;
438 438 }
439 pCfg->iNumRefFrame = WELS_CLIP3(pCfg->iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);439 pCfg->iNumRefFrame = ((pCfg->uiGopSize >> 1) > 1) ? ((pCfg->uiGopSize >> 1) + pCfg->iLTRRefNum) :
440 440 (MIN_REF_PIC_COUNT + pCfg->iLTRRefNum);
441 if (pCfg->uiLtrMarkPeriod == 0)441
442 {442 pCfg->iNumRefFrame = WELS_CLIP3 (pCfg->iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);
443 pCfg->uiLtrMarkPeriod = 30;443
444 }444 if (pCfg->uiLtrMarkPeriod == 0) {
445 445 pCfg->uiLtrMarkPeriod = 30;
446 const int32_t kiDecStages = WELS_LOG2( pCfg->uiGopSize );446 }
447 pCfg->iInputCsp = iColorspace; 447
448 pCfg->iNumTemporalLayer = (int8_t)(1 + kiDecStages);448 const int32_t kiDecStages = WELS_LOG2 (pCfg->uiGopSize);
449 pCfg->iLoopFilterAlphaC0Offset = WELS_CLIP3( pCfg->iLoopFilterAlphaC0Offset, -6, 6 );449 pCfg->iInputCsp = iColorspace;
450 pCfg->iLoopFilterBetaOffset = WELS_CLIP3( pCfg->iLoopFilterBetaOffset, -6, 6 );450 pCfg->iNumTemporalLayer = (int8_t) (1 + kiDecStages);
451 451 pCfg->iLoopFilterAlphaC0Offset = WELS_CLIP3 (pCfg->iLoopFilterAlphaC0Offset, -6, 6);
452// m_pSrcPicList = (SSourcePicture **)WelsMalloc( pCfg->iNumDependencyLayer * sizeof(SSourcePicture *), "m_pSrcPicList" );452 pCfg->iLoopFilterBetaOffset = WELS_CLIP3 (pCfg->iLoopFilterBetaOffset, -6, 6);
453 // prefer use new/delete pair due encoder intialization stage not start yet for CacheLineSize not detection here (16 or 64 not matched)453
454 m_pSrcPicList = new SSourcePicture* [iNumOfLayers];454// m_pSrcPicList = (SSourcePicture **)WelsMalloc( pCfg->iNumDependencyLayer * sizeof(SSourcePicture *), "m_pSrcPicList" );
455 455 // prefer use new/delete pair due encoder intialization stage not start yet for CacheLineSize not detection here (16 or 64 not matched)
456 if ( NULL == m_pSrcPicList ){456 m_pSrcPicList = new SSourcePicture* [iNumOfLayers];
457 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), pOut of memory due m_pSrcPicList memory request.\n");457
458 Uninitialize();458 if (NULL == m_pSrcPicList) {
459 return cmMallocMemeError;459 WelsLog (m_pEncContext, WELS_LOG_ERROR,
460 }460 "CWelsH264SVCEncoder::Initialize(), pOut of memory due m_pSrcPicList memory request.\n");
461 461 Uninitialize();
462 // decide property list size between INIT_TYPE_PARAMETER_BASED/INIT_TYPE_CONFIG_BASED 462 return cmMallocMemeError;
463 m_iMaxPicWidth = pCfg->iActualPicWidth;463 }
464 m_iMaxPicHeight = pCfg->iActualPicHeight; 464
465 m_iSrcListSize = iNumOfLayers; 465 // decide property list size between INIT_TYPE_PARAMETER_BASED/INIT_TYPE_CONFIG_BASED
466 466 m_iMaxPicWidth = pCfg->iActualPicWidth;
467 for (int32_t i = 0; i < m_iSrcListSize; ++ i)467 m_iMaxPicHeight = pCfg->iActualPicHeight;
468 {468 m_iSrcListSize = iNumOfLayers;
469// m_pSrcPicList[i] = (SSourcePicture *)WelsMalloc( sizeof(SSourcePicture), "m_pSrcPicList[]" );469
470 // prefer use new/delete pair due encoder intialization stage not start yet for CacheLineSize not detection here (16 or 64 not matched)470 for (int32_t i = 0; i < m_iSrcListSize; ++ i) {
471 m_pSrcPicList[i] = new SSourcePicture;471// m_pSrcPicList[i] = (SSourcePicture *)WelsMalloc( sizeof(SSourcePicture), "m_pSrcPicList[]" );
472 472 // prefer use new/delete pair due encoder intialization stage not start yet for CacheLineSize not detection here (16 or 64 not matched)
473 if ( NULL == m_pSrcPicList[i] )473 m_pSrcPicList[i] = new SSourcePicture;
474 { 474
475 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), pOut of memory due m_pSrcPicList[%d] memory request.\n", i);475 if (NULL == m_pSrcPicList[i]) {
476 Uninitialize();476 WelsLog (m_pEncContext, WELS_LOG_ERROR,
477 m_iSrcListSize = 0;477 "CWelsH264SVCEncoder::Initialize(), pOut of memory due m_pSrcPicList[%d] memory request.\n", i);
478 return cmMallocMemeError;478 Uninitialize();
479 }479 m_iSrcListSize = 0;
480 InitPic( m_pSrcPicList[i], iColorspace, m_iMaxPicWidth, m_iMaxPicHeight );480 return cmMallocMemeError;
481 } 481 }
482 482 InitPic (m_pSrcPicList[i], iColorspace, m_iMaxPicWidth, m_iMaxPicHeight);
483#if defined(OUTPUT_BIT_STREAM) || defined(ENABLE_TRACE_FILE)483 }
484 str_t fpath[MAX_FNAME_LEN] = {0};484
485#if defined(__GNUC__)485#if defined(OUTPUT_BIT_STREAM) || defined(ENABLE_TRACE_FILE)
486 SNPRINTF(fpath, MAX_FNAME_LEN, "/tmp/"); // confirmed_safe_unsafe_usage486 str_t fpath[MAX_FNAME_LEN] = {0};
487 487#if defined(__GNUC__)
488#else//__GNUC__488 SNPRINTF (fpath, MAX_FNAME_LEN, "/tmp/"); // confirmed_safe_unsafe_usage
489 489
490#if defined (_MSC_VER)490#else//__GNUC__
491#if _MSC_VER>=1500491
492 SNPRINTF(fpath, MAX_FNAME_LEN, MAX_FNAME_LEN, ".\\" ); // confirmed_safe_unsafe_usage492#if defined (_MSC_VER)
493#else493#if _MSC_VER>=1500
494 SNPRINTF(fpath, MAX_FNAME_LEN, ".\\" ); // confirmed_safe_unsafe_usage494 SNPRINTF (fpath, MAX_FNAME_LEN, MAX_FNAME_LEN, ".\\"); // confirmed_safe_unsafe_usage
495#endif//_MSC_VER>=1500495#else
496#endif//_MSC_VER496 SNPRINTF (fpath, MAX_FNAME_LEN, ".\\"); // confirmed_safe_unsafe_usage
497#endif //__GNUC__497#endif//_MSC_VER>=1500
498 498#endif//_MSC_VER
499 strcpy(pCfg->sTracePath, fpath); // confirmed_safe_unsafe_usage499#endif //__GNUC__
500 500
501#endif //#if defined(OUTPUT_BIT_STREAM) || defined(ENABLE_TRACE_FILE)501 strcpy (pCfg->sTracePath, fpath); // confirmed_safe_unsafe_usage
502 502
503 if ( WelsInitEncoderExt( &m_pEncContext, pCfg ) )503#endif //#if defined(OUTPUT_BIT_STREAM) || defined(ENABLE_TRACE_FILE)
504 { 504
505 WelsLog(m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.\n");505 if (WelsInitEncoderExt (&m_pEncContext, pCfg)) {
506 Uninitialize();506 WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.\n");
507 return cmInitParaError;507 Uninitialize();
508 } 508 return cmInitParaError;
509 509 }
510 m_iCspInternal = iColorspace;510
511 m_bInitialFlag = TRUE;511 m_iCspInternal = iColorspace;
512 512 m_bInitialFlag = TRUE;
513 return cmResultSuccess;513
514}514 return cmResultSuccess;
515 515}
516/*516
517 * SVC Encoder Uninitialization517/*
518 */518 * SVC Encoder Uninitialization
519int32_t CWelsH264SVCEncoder::Uninitialize()519 */
520{520int32_t CWelsH264SVCEncoder::Uninitialize() {
521 if ( !m_bInitialFlag )521 if (!m_bInitialFlag) {
522 {522 return 0;
523 return 0;523 }
524 }524
525 525 WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n");
526 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n" );526
527 527#ifdef REC_FRAME_COUNT
528#ifdef REC_FRAME_COUNT528 WelsLog (m_pEncContext, WELS_LOG_INFO,
529 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );529 "CWelsH264SVCEncoder::Uninitialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal);
530#endif//REC_FRAME_COUNT530#endif//REC_FRAME_COUNT
531 531
532 if ( NULL != m_pEncContext )532 if (NULL != m_pEncContext) {
533 {533 if (NULL != m_pSrcPicList) {
534 if ( NULL != m_pSrcPicList )534 for (int32_t i = 0; i < m_iSrcListSize; i++) {
535 {535 SSourcePicture* pic = m_pSrcPicList[i];
536 for (int32_t i = 0; i < m_iSrcListSize; i++)536 if (NULL != pic) {
537 {537// WelsFree( pic, "m_pSrcPicList[]" );
538 SSourcePicture *pic = m_pSrcPicList[i];538 // prefer use new/delete pair due encoder intialization stage not start yet for CacheLineSize not detection here (16 or 64 not matched)
539 if ( NULL != pic )539 delete pic;
540 {540
541// WelsFree( pic, "m_pSrcPicList[]" );541 pic = NULL;
542 // prefer use new/delete pair due encoder intialization stage not start yet for CacheLineSize not detection here (16 or 64 not matched)542 }
543 delete pic;543 }
544 544// WelsFree( m_pSrcPicList, "m_pSrcPicList" );
545 pic = NULL;545 // prefer use new/delete pair due encoder intialization stage not start yet for CacheLineSize not detection here (16 or 64 not matched)
546 }546 delete [] m_pSrcPicList;
547 }547
548// WelsFree( m_pSrcPicList, "m_pSrcPicList" );548 m_pSrcPicList = NULL;
549 // prefer use new/delete pair due encoder intialization stage not start yet for CacheLineSize not detection here (16 or 64 not matched)549 m_iSrcListSize = 0;
550 delete [] m_pSrcPicList;550 }
551 551
552 m_pSrcPicList = NULL;552 WelsUninitEncoderExt (&m_pEncContext);
553 m_iSrcListSize= 0;553 m_pEncContext = NULL;
554 }554 }
555 555
556 WelsUninitEncoderExt( &m_pEncContext );556 m_bInitialFlag = FALSE;
557 m_pEncContext = NULL;557
558 } 558 return 0;
559 559}
560 m_bInitialFlag = FALSE;560
561 561
562 return 0;562int32_t CWelsH264SVCEncoder::RawData2SrcPic (const uint8_t* pSrc) {
563}563 assert (m_iSrcListSize > 0);
564 564
565 565 int32_t y_length = m_iMaxPicWidth * m_iMaxPicHeight;
566int32_t CWelsH264SVCEncoder::RawData2SrcPic(const uint8_t * pSrc)566 m_pSrcPicList[0]->pData[0] = const_cast<uint8_t*> (pSrc);
567{ 567
568 assert( m_iSrcListSize > 0 );568 switch (m_iCspInternal & (~videoFormatVFlip)) {
569 569 case videoFormatYVYU:
570 int32_t y_length = m_iMaxPicWidth * m_iMaxPicHeight;570 case videoFormatUYVY:
571 m_pSrcPicList[0]->pData[0] = const_cast<uint8_t*>(pSrc);571 case videoFormatYUY2:
572 572 case videoFormatRGB:
573 switch(m_iCspInternal & (~videoFormatVFlip))573 case videoFormatBGR:
574 {574 case videoFormatBGRA:
575 case videoFormatYVYU:575 case videoFormatRGBA:
576 case videoFormatUYVY:576 case videoFormatARGB:
577 case videoFormatYUY2: 577 case videoFormatABGR:
578 case videoFormatRGB:578 m_pSrcPicList[0]->pData[1] = m_pSrcPicList[0]->pData[2] = NULL;
579 case videoFormatBGR: 579 break;
580 case videoFormatBGRA:580 case videoFormatI420:
581 case videoFormatRGBA:581 case videoFormatYV12:
582 case videoFormatARGB:582 m_pSrcPicList[0]->pData[1] = m_pSrcPicList[0]->pData[0] + y_length;
583 case videoFormatABGR:583 m_pSrcPicList[0]->pData[2] = m_pSrcPicList[0]->pData[1] + (y_length >> 2);
584 m_pSrcPicList[0]->pData[1] = m_pSrcPicList[0]->pData[2] = NULL; 584 break;
585 break;585 default:
586 case videoFormatI420:586 return 1;
587 case videoFormatYV12:587 }
588 m_pSrcPicList[0]->pData[1] = m_pSrcPicList[0]->pData[0] + y_length;588
589 m_pSrcPicList[0]->pData[2] = m_pSrcPicList[0]->pData[1] + ( y_length >> 2 );589 return 0;
590 break; 590}
591 default:591
592 return 1; 592
593 }593/*
594 594 * SVC core encoding
595 return 0;595 */
596}596int CWelsH264SVCEncoder::EncodeFrame (const unsigned char* pSrc, SFrameBSInfo* pBsInfo) {
597 597 if (! (pSrc && m_pEncContext && m_bInitialFlag)) {
598 598 return videoFrameTypeInvalid;
599/*599 }
600 * SVC core encoding600
601 */601 int32_t uiFrameType = videoFrameTypeInvalid;
602int CWelsH264SVCEncoder::EncodeFrame(const unsigned char* pSrc, SFrameBSInfo* pBsInfo)602
603{603 if (RawData2SrcPic ((uint8_t*)pSrc) == 0) {
604 if ( !(pSrc && m_pEncContext && m_bInitialFlag) )604 uiFrameType = EncodeFrame (const_cast<const SSourcePicture**> (m_pSrcPicList), 1, pBsInfo);
605 {605 }
606 return videoFrameTypeInvalid;606
607 }607#ifdef REC_FRAME_COUNT
608 608 ++ m_uiCountFrameNum;
609 int32_t uiFrameType = videoFrameTypeInvalid; 609 WelsLog (m_pEncContext, WELS_LOG_INFO,
610 610 "CWelsH264SVCEncoder::EncodeFrame(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal);
611 if( RawData2SrcPic((uint8_t *)pSrc) == 0 ){611#endif//REC_FRAME_COUNT
612 uiFrameType = EncodeFrame(const_cast<const SSourcePicture**>(m_pSrcPicList), 1, pBsInfo);612
613 }613#ifdef DUMP_SRC_PICTURE
614 614 DumpSrcPicture (pSrc);
615#ifdef REC_FRAME_COUNT615#endif // DUMP_SRC_PICTURE
616 ++ m_uiCountFrameNum;616
617 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::EncodeFrame(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );617 return uiFrameType;
618#endif//REC_FRAME_COUNT 618}
619 619
620#ifdef DUMP_SRC_PICTURE620
621 DumpSrcPicture(pSrc);621int CWelsH264SVCEncoder::EncodeFrame (const SSourcePicture** pSrcPicList, int nSrcPicNum, SFrameBSInfo* pBsInfo) {
622#endif // DUMP_SRC_PICTURE 622 if (! (pSrcPicList && m_pEncContext && m_bInitialFlag)) {
623 623 return videoFrameTypeInvalid;
624 return uiFrameType;624 }
625}625
626 626 int32_t iFrameTypeReturned = 0;
627 627 int32_t iFrameType = videoFrameTypeInvalid;
628int CWelsH264SVCEncoder::EncodeFrame(const SSourcePicture ** pSrcPicList, int nSrcPicNum, SFrameBSInfo * pBsInfo)628
629{629 if (nSrcPicNum > 0) {
630 if ( !(pSrcPicList && m_pEncContext && m_bInitialFlag) )630 iFrameTypeReturned = WelsEncoderEncodeExt (m_pEncContext, pBsInfo, pSrcPicList, nSrcPicNum);
631 { 631 } else {
632 return videoFrameTypeInvalid;632 assert (0);
633 }633 return videoFrameTypeInvalid;
634 634 }
635 int32_t iFrameTypeReturned = 0;635
636 int32_t iFrameType = videoFrameTypeInvalid;636 switch (iFrameTypeReturned) {
637 637 case WELS_FRAME_TYPE_P:
638 if (nSrcPicNum > 0)638 iFrameType = videoFrameTypeP;
639 {639 break;
640 iFrameTypeReturned = WelsEncoderEncodeExt( m_pEncContext, pBsInfo, pSrcPicList, nSrcPicNum); 640 case WELS_FRAME_TYPE_IDR:
641 }641 iFrameType = videoFrameTypeIDR;
642 else642 break;
643 {643 case WELS_FRAME_TYPE_SKIP:
644 assert ( 0 );644 iFrameType = videoFrameTypeSkip;
645 return videoFrameTypeInvalid;645 break;
646 }646 case WELS_FRAME_TYPE_I:
647 647 iFrameType = videoFrameTypeI;
648 switch( iFrameTypeReturned )648 break;
649 {649 case WELS_FRAME_TYPE_AUTO:
650 case WELS_FRAME_TYPE_P:650 case WELS_FRAME_TYPE_B: // not support B pictures
651 iFrameType = videoFrameTypeP;651 iFrameType = videoFrameTypeInvalid;
652 break;652 break;
653 case WELS_FRAME_TYPE_IDR:653 default:
654 iFrameType = videoFrameTypeIDR;654 break;
655 break;655 }
656 case WELS_FRAME_TYPE_SKIP:656
657 iFrameType = videoFrameTypeSkip;657
658 break;658
659 case WELS_FRAME_TYPE_I:659 ///////////////////for test
660 iFrameType = videoFrameTypeI;660#ifdef OUTPUT_BIT_STREAM
661 break;661 if (iFrameType != videoFrameTypeInvalid && iFrameType != videoFrameTypeSkip) {
662 case WELS_FRAME_TYPE_AUTO:662 SLayerBSInfo* pLayer = NULL;
663 case WELS_FRAME_TYPE_B: // not support B pictures663 int32_t i = 0, j = 0, iCurLayerBits = 0, total_bits = 0;
664 iFrameType = videoFrameTypeInvalid;664
665 break;665 if (m_bSwitch) {
666 default:666 if (m_pFileBs) {
667 break;667 fclose (m_pFileBs);
668 } 668 m_pFileBs = NULL;
669 669 }
670 670 if (m_pFileBsSize) {
671 671 fclose (m_pFileBsSize);
672 ///////////////////for test672 m_pFileBsSize = NULL;
673#ifdef OUTPUT_BIT_STREAM673 }
674 if ( iFrameType != videoFrameTypeInvalid && iFrameType != videoFrameTypeSkip )674 str_t strStreamFileName[128] = {0};
675 { 675#if defined(__GNUC__)
676 SLayerBSInfo* pLayer = NULL;676
677 int32_t i = 0, j = 0, iCurLayerBits = 0, total_bits = 0; 677 int32_t iLen = SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d.264", m_pEncContext->sTracePath, m_iSwitchTimes,
678 678 m_pEncContext->pSvcParam->iActualPicWidth);
679 if ( m_bSwitch )679 m_pFileBs = FOPEN (strStreamFileName, "wb");
680 {680 SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d_size.iLen", m_pEncContext->sTracePath, m_iSwitchTimes,
681 if ( m_pFileBs )681 m_pEncContext->pSvcParam->iActualPicWidth);
682 {682 m_pFileBsSize = FOPEN (strStreamFileName, "wb");
683 fclose( m_pFileBs );683
684 m_pFileBs = NULL;684#else//__GNUC__
685 }685
686 if ( m_pFileBsSize )686#if defined (_MSC_VER)
687 {687#if _MSC_VER>=1500
688 fclose( m_pFileBsSize );688 int32_t iLen = SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d.264", m_iSwitchTimes,
689 m_pFileBsSize = NULL;689 m_pEncContext->pSvcParam->iActualPicWidth);
690 }690 FOPEN (&m_pFileBs, strStreamFileName, "wb");
691 str_t strStreamFileName[128] = {0};691 SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes,
692#if defined(__GNUC__)692 m_pEncContext->pSvcParam->iActualPicWidth);
693 693 FOPEN (&m_pFileBsSize, strStreamFileName, "wb");
694 int32_t iLen = SNPRINTF(strStreamFileName, 128, "%sadj%d_w%d.264", m_pEncContext->sTracePath, m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);694#else
695 m_pFileBs = FOPEN( strStreamFileName, "wb" );695 int32_t iLen = SNPRINTF (strStreamFileName, 128, "adj%d_w%d.264", m_iSwitchTimes,
696 SNPRINTF(strStreamFileName, 128, "%sadj%d_w%d_size.iLen", m_pEncContext->sTracePath, m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);696 m_pEncContext->pSvcParam->iActualPicWidth);
697 m_pFileBsSize = FOPEN( strStreamFileName, "wb");697 m_pFileBs = FOPEN (strStreamFileName, "wb");
698 698 SNPRINTF (strStreamFileName, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);
699#else//__GNUC__699 m_pFileBsSize = FOPEN (strStreamFileName, "wb");
700 700#endif//_MSC_VER>=1500
701#if defined (_MSC_VER)701#endif//_MSC_VER
702#if _MSC_VER>=1500702
703 int32_t iLen = SNPRINTF(strStreamFileName, 128, 128, "adj%d_w%d.264", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);703
704 FOPEN( &m_pFileBs, strStreamFileName, "wb" );704#endif//__GNUC__
705 SNPRINTF(strStreamFileName, 128, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);705
706 FOPEN( &m_pFileBsSize, strStreamFileName, "wb");706 m_bSwitch = FALSE;
707#else707 }
708 int32_t iLen = SNPRINTF(strStreamFileName, 128, "adj%d_w%d.264", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);708
709 m_pFileBs = FOPEN( strStreamFileName, "wb" );709 for (i = 0; i < pBsInfo->iLayerNum; i++) {
710 SNPRINTF(strStreamFileName, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);710 pLayer = &pBsInfo->sLayerInfo[i];
711 m_pFileBsSize = FOPEN( strStreamFileName, "wb");711
712#endif//_MSC_VER>=1500712 iCurLayerBits = 0;
713#endif//_MSC_VER713 for (j = 0; j < pLayer->iNalCount; j++) {
714 714 iCurLayerBits += pLayer->iNalLengthInByte[j];
715 715 }
716#endif//__GNUC__716 total_bits += iCurLayerBits;
717 717 if (m_pFileBs != NULL)
718 m_bSwitch = FALSE;718 fwrite (pLayer->pBsBuf, 1, iCurLayerBits, m_pFileBs);
719 }719 }
720 720
721 for ( i = 0; i < pBsInfo->iLayerNum; i++ )721 if (m_pFileBsSize != NULL)
722 {722 fwrite (&total_bits, sizeof (int32_t), 1, m_pFileBsSize);
723 pLayer = &pBsInfo->sLayerInfo[i];723 }
724 724#endif //OUTPUT_BIT_STREAM
725 iCurLayerBits = 0;725#ifdef DUMP_SRC_PICTURE
726 for ( j = 0; j < pLayer->iNalCount; j++ )726 DumpSrcPicture (pSrcPicList[0]->pData[0]);
727 {727#endif // DUMP_SRC_PICTURE
728 iCurLayerBits += pLayer->iNalLengthInByte[j];728
729 }729 return iFrameType;
730 total_bits += iCurLayerBits;730
731 if ( m_pFileBs != NULL )731}
732 fwrite( pLayer->pBsBuf, 1, iCurLayerBits, m_pFileBs );732
733 }733/*
734 734 * return: 0 - success; otherwise - failed;
735 if ( m_pFileBsSize != NULL )735 */
736 fwrite( &total_bits, sizeof(int32_t), 1, m_pFileBsSize );736int CWelsH264SVCEncoder::PauseFrame (const unsigned char* kpSrc, SFrameBSInfo* pBsInfo) {
737 }737 int32_t iReturn = 1;
738#endif //OUTPUT_BIT_STREAM738
739#ifdef DUMP_SRC_PICTURE739 ForceIntraFrame (true);
740 DumpSrcPicture(pSrcPicList[0]->pData[0]);740
741#endif // DUMP_SRC_PICTURE 741 if (EncodeFrame (kpSrc, pBsInfo) != videoFrameTypeInvalid) {
742 742 iReturn = 0;
743 return iFrameType;743 }
744 744
745}745 // to avoid pause frame bitstream and
746 746 // normal bitstream use different video channel.
747/*747 ForceIntraFrame (true);
748 * return: 0 - success; otherwise - failed;748
749 */749 return (int)iReturn;
750int CWelsH264SVCEncoder::PauseFrame(const unsigned char* kpSrc, SFrameBSInfo* pBsInfo)750}
751{751
752 int32_t iReturn = 1;752
753 753/*
754 ForceIntraFrame(true);754 * Force key frame
755 755 */
756 if( EncodeFrame(kpSrc, pBsInfo) != videoFrameTypeInvalid ){756int CWelsH264SVCEncoder::ForceIntraFrame (bool bIDR) {
757 iReturn = 0;757 if (! (m_pEncContext && m_bInitialFlag)) {
758 }758 return 1;
759 759 }
760 // to avoid pause frame bitstream and 760
761 // normal bitstream use different video channel. 761#ifdef REC_FRAME_COUNT
762 ForceIntraFrame(true); 762 WelsLog (m_pEncContext, WELS_LOG_INFO,
763 763 "CWelsH264SVCEncoder::ForceIntraFrame(), bIDR= %d, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", bIDR,
764 return (int)iReturn;764 m_uiCountFrameNum, m_iCspInternal);
765}765#endif//REC_FRAME_COUNT
766 766
767 767 ForceCodingIDR (m_pEncContext);
768/*768
769 * Force key frame769 return 0;
770 */770}
771int CWelsH264SVCEncoder::ForceIntraFrame(bool bIDR)771
772{772/************************************************************************
773 if ( !(m_pEncContext && m_bInitialFlag) )773* InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,..
774 {774************************************************************************/
775 return 1;775int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) {
776 }776 if (NULL == pOption) {
777 777 return cmInitParaError;
778#ifdef REC_FRAME_COUNT778 }
779 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::ForceIntraFrame(), bIDR= %d, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", bIDR, m_uiCountFrameNum, m_iCspInternal );779
780#endif//REC_FRAME_COUNT780 if (NULL == m_pEncContext || FALSE == m_bInitialFlag) {
781 781 return cmInitExpected;
782 ForceCodingIDR( m_pEncContext ); 782 }
783 783
784 return 0;784 switch (eOptionId) {
785}785 case ENCODER_OPTION_INTER_SPATIAL_PRED: { // Inter spatial layer prediction flag
786 786 WelsLog (m_pEncContext, WELS_LOG_INFO, "ENCODER_OPTION_INTER_SPATIAL_PRED, this feature not supported at present.\n");
787/************************************************************************787 }
788* InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,..788 break;
789************************************************************************/789 case ENCODER_OPTION_DATAFORMAT: { // Input color space
790int CWelsH264SVCEncoder::SetOption(ENCODER_OPTION eOptionId, void* pOption)790 int32_t iValue = * ((int32_t*)pOption);
791{791 int32_t iColorspace = iValue;
792 if ( NULL == pOption ){ 792 if (iColorspace == 0) {
793 return cmInitParaError;793 return cmInitParaError;
794 }794 }
795 795
796 if ( NULL == m_pEncContext || FALSE == m_bInitialFlag ){ 796#ifdef REC_FRAME_COUNT
797 return cmInitExpected;797 WelsLog (m_pEncContext, WELS_LOG_INFO,
798 }798 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_DATAFORMAT, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n",
799 799 m_uiCountFrameNum, m_iCspInternal, iValue);
800 switch( eOptionId ) {800#endif//REC_FRAME_COUNT
801 case ENCODER_OPTION_INTER_SPATIAL_PRED: // Inter spatial layer prediction flag801
802 {802
803 WelsLog( m_pEncContext, WELS_LOG_INFO, "ENCODER_OPTION_INTER_SPATIAL_PRED, this feature not supported at present.\n" );803 int32_t iPicIdx = m_iSrcListSize - 1;
804 }804 while (iPicIdx >= 0) {
805 break;805 if (m_pSrcPicList[iPicIdx] == NULL) {
806 case ENCODER_OPTION_DATAFORMAT: // Input color space806 -- iPicIdx;
807 {807 if (iPicIdx < 0) return cmInitParaError;
808 int32_t iValue = *((int32_t*)pOption);808 continue;
809 int32_t iColorspace = iValue;809 }
810 if ( iColorspace == 0 ){ 810
811 return cmInitParaError;811 if (m_pSrcPicList[iPicIdx]->iColorFormat == iColorspace) {
812 }812 -- iPicIdx;
813 813 continue;
814#ifdef REC_FRAME_COUNT814 }
815 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_DATAFORMAT, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n", m_uiCountFrameNum, m_iCspInternal, iValue );815
816#endif//REC_FRAME_COUNT816 InitPic (m_pSrcPicList[iPicIdx], iColorspace, m_iMaxPicWidth, m_iMaxPicHeight);
817 817 }
818 818 m_iCspInternal = iColorspace;
819 int32_t iPicIdx = m_iSrcListSize -1;819#ifdef REC_FRAME_COUNT
820 while ( iPicIdx >= 0 )820 WelsLog (m_pEncContext, WELS_LOG_INFO,
821 {821 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_DATAFORMAT, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
822 if ( m_pSrcPicList[iPicIdx] == NULL )822 m_uiCountFrameNum, m_iCspInternal);
823 {823#endif//REC_FRAME_COUNT
824 -- iPicIdx;824 }
825 if (iPicIdx < 0) return cmInitParaError;825 break;
826 continue;826 case ENCODER_OPTION_IDR_INTERVAL: { // IDR Interval
827 }827 int32_t iValue = * ((int32_t*)pOption);
828 828#ifdef REC_FRAME_COUNT
829 if ( m_pSrcPicList[iPicIdx]->iColorFormat == iColorspace )829 WelsLog (m_pEncContext, WELS_LOG_INFO,
830 { 830 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_IDR_INTERVAL, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n",
831 -- iPicIdx;831 m_uiCountFrameNum, m_iCspInternal, iValue);
832 continue;832#endif//REC_FRAME_COUNT
833 }833
834 834 if (iValue < -1 || iValue == 0)
835 InitPic( m_pSrcPicList[iPicIdx], iColorspace, m_iMaxPicWidth, m_iMaxPicHeight );835 iValue = 1;
836 } 836 if (iValue == (int32_t)m_pEncContext->pSvcParam->uiIntraPeriod) {
837 m_iCspInternal = iColorspace;837 return cmResultSuccess;
838#ifdef REC_FRAME_COUNT838 }
839 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_DATAFORMAT, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );839
840#endif//REC_FRAME_COUNT840
841 } 841 m_pEncContext->pSvcParam->uiIntraPeriod = (uint32_t)iValue;
842 break;842 }
843 case ENCODER_OPTION_IDR_INTERVAL: // IDR Interval843 break;
844 {844 case ENCODER_OPTION_SVC_ENCODE_PARAM: { // SVC Encoding Parameter
845 int32_t iValue = *((int32_t*)pOption);845 SVCEncodingParam sEncodingParam;
846#ifdef REC_FRAME_COUNT846 SWelsSvcCodingParam sConfig (true);
847 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_IDR_INTERVAL, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n", m_uiCountFrameNum, m_iCspInternal, iValue );847 int32_t iInputColorspace = 0;
848#endif//REC_FRAME_COUNT848 int32_t iTargetWidth = 0;
849 849 int32_t iTargetHeight = 0;
850 if ( iValue < -1 || iValue == 0 )850
851 iValue = 1;851 memcpy (&sEncodingParam, pOption, sizeof (SVCEncodingParam)); // confirmed_safe_unsafe_usage
852 if ( iValue == (int32_t)m_pEncContext->pSvcParam->uiIntraPeriod ){ 852 WelsLog (m_pEncContext, WELS_LOG_INFO, "ENCODER_OPTION_SVC_ENCODE_PARAM, sEncodingParam.iInputCsp= 0x%x\n",
853 return cmResultSuccess;853 sEncodingParam.iInputCsp);
854 }854 WelsLog (m_pEncContext, WELS_LOG_INFO,
855 855 "coding_param->iPicWidth= %d;coding_param->iPicHeight= %d;coding_param->iTargetBitrate= %d;coding_param->iRCMode= %d;coding_param->iPaddingFlag= %d;coding_param->iTemporalLayerNum= %d;coding_param->iSpatialLayerNum= %d;coding_param->fFrameRate= %.6ff;coding_param->iInputCsp= %d;coding_param->iKeyPicCodingMode= %d;coding_param->uiIntraPeriod= %d;coding_param->bEnableSpsPpsIdAddition = %d;coding_param->bPrefixNalAddingCtrl = %d;coding_param->bEnableDenoise= %d;coding_param->bEnableBackgroundDetection= %d;coding_param->bEnableAdaptiveQuant= %d;coding_param->bEnableCropPic= %d;coding_param->bEnableLongTermReference= %d;coding_param->iLtrMarkPeriod= %d;\n",
856 856 sEncodingParam.iPicWidth,
857 m_pEncContext->pSvcParam->uiIntraPeriod = (uint32_t)iValue; 857 sEncodingParam.iPicHeight,
858 }858 sEncodingParam.iTargetBitrate,
859 break;859 sEncodingParam.iRCMode,
860 case ENCODER_OPTION_SVC_ENCODE_PARAM: // SVC Encoding Parameter860 sEncodingParam.iPaddingFlag,
861 {861 sEncodingParam.iTemporalLayerNum,
862 SVCEncodingParam sEncodingParam;862 sEncodingParam.iSpatialLayerNum,
863 SWelsSvcCodingParam sConfig( true );863 sEncodingParam.fFrameRate,
864 int32_t iInputColorspace = 0;864 sEncodingParam.iInputCsp,
865 int32_t iTargetWidth = 0;865 sEncodingParam.iKeyPicCodingMode,
866 int32_t iTargetHeight= 0;866 sEncodingParam.iIntraPeriod,
867 867 sEncodingParam.bEnableSpsPpsIdAddition,
868 memcpy(&sEncodingParam, pOption, sizeof(SVCEncodingParam)); // confirmed_safe_unsafe_usage868 sEncodingParam.bPrefixNalAddingCtrl,
869 WelsLog( m_pEncContext, WELS_LOG_INFO, "ENCODER_OPTION_SVC_ENCODE_PARAM, sEncodingParam.iInputCsp= 0x%x\n", sEncodingParam.iInputCsp );869 sEncodingParam.bEnableDenoise,
870 WelsLog( m_pEncContext, WELS_LOG_INFO, "coding_param->iPicWidth= %d;coding_param->iPicHeight= %d;coding_param->iTargetBitrate= %d;coding_param->iRCMode= %d;coding_param->iPaddingFlag= %d;coding_param->iTemporalLayerNum= %d;coding_param->iSpatialLayerNum= %d;coding_param->fFrameRate= %.6ff;coding_param->iInputCsp= %d;coding_param->iKeyPicCodingMode= %d;coding_param->uiIntraPeriod= %d;coding_param->bEnableSpsPpsIdAddition = %d;coding_param->bPrefixNalAddingCtrl = %d;coding_param->bEnableDenoise= %d;coding_param->bEnableBackgroundDetection= %d;coding_param->bEnableAdaptiveQuant= %d;coding_param->bEnableCropPic= %d;coding_param->bEnableLongTermReference= %d;coding_param->iLtrMarkPeriod= %d;\n",870 sEncodingParam.bEnableBackgroundDetection,
871 sEncodingParam.iPicWidth,871 sEncodingParam.bEnableAdaptiveQuant,
872 sEncodingParam.iPicHeight,872 sEncodingParam.bEnableCropPic,
873 sEncodingParam.iTargetBitrate,873 sEncodingParam.bEnableLongTermReference,
874 sEncodingParam.iRCMode,874 sEncodingParam.iLtrMarkPeriod);
875 sEncodingParam.iPaddingFlag,875 int32_t i = 0;
876 sEncodingParam.iTemporalLayerNum,876 while (i < sEncodingParam.iSpatialLayerNum) {
877 sEncodingParam.iSpatialLayerNum,877 SSpatialLayerConfig* pSpatialCfg = &sEncodingParam.sSpatialLayers[i];
878 sEncodingParam.fFrameRate,878 WelsLog (m_pEncContext, WELS_LOG_INFO,
879 sEncodingParam.iInputCsp,879 "coding_param->sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iQualityLayerNum= %d; .iSpatialBitrate= %d; .iCgsSnrRefined= %d; .iInterSpatialLayerPredFlag= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.iSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\n",
880 sEncodingParam.iKeyPicCodingMode,880 i, pSpatialCfg->iVideoWidth,
881 sEncodingParam.iIntraPeriod,881 pSpatialCfg->iVideoHeight,
882 sEncodingParam.bEnableSpsPpsIdAddition,882 pSpatialCfg->fFrameRate,
883 sEncodingParam.bPrefixNalAddingCtrl,883 pSpatialCfg->iQualityLayerNum,
884 sEncodingParam.bEnableDenoise,884 pSpatialCfg->iSpatialBitrate,
885 sEncodingParam.bEnableBackgroundDetection,885 pSpatialCfg->iCgsSnrRefined,
886 sEncodingParam.bEnableAdaptiveQuant,886 pSpatialCfg->iInterSpatialLayerPredFlag,
887 sEncodingParam.bEnableCropPic,887 pSpatialCfg->sSliceCfg.uiSliceMode,
888 sEncodingParam.bEnableLongTermReference,888 pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceNum,
889 sEncodingParam.iLtrMarkPeriod);889 pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceSizeConstraint
890 int32_t i = 0;890 );
891 while (i < sEncodingParam.iSpatialLayerNum)891 ++ i;
892 {892 }
893 SSpatialLayerConfig *pSpatialCfg = &sEncodingParam.sSpatialLayers[i]; 893#ifdef OUTPUT_BIT_STREAM
894 WelsLog( m_pEncContext, WELS_LOG_INFO, "coding_param->sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iQualityLayerNum= %d; .iSpatialBitrate= %d; .iCgsSnrRefined= %d; .iInterSpatialLayerPredFlag= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.iSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\n",894 if (sEncodingParam.sSpatialLayers[sEncodingParam.iSpatialLayerNum - 1].iVideoWidth !=
895 i, pSpatialCfg->iVideoWidth,895 m_pEncContext->pSvcParam->sDependencyLayers[m_pEncContext->pSvcParam->iNumDependencyLayer - 1].iFrameWidth) {
896 pSpatialCfg->iVideoHeight,896 ++ m_iSwitchTimes;
897 pSpatialCfg->fFrameRate,897 m_bSwitch = TRUE;
898 pSpatialCfg->iQualityLayerNum,898 }
899 pSpatialCfg->iSpatialBitrate,899#endif//OUTPUT_BIT_STREAM
900 pSpatialCfg->iCgsSnrRefined,900 if (sEncodingParam.iSpatialLayerNum < 1
901 pSpatialCfg->iInterSpatialLayerPredFlag,901 || sEncodingParam.iSpatialLayerNum > MAX_SPATIAL_LAYER_NUM) { // verify number of spatial layer
902 pSpatialCfg->sSliceCfg.uiSliceMode, 902 return cmInitParaError;
903 pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceNum,903 }
904 pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceSizeConstraint904
905 );905 iInputColorspace = sEncodingParam.iInputCsp;
906 ++ i;906 if (sConfig.ParamTranscode (sEncodingParam, true)) {
907 }907 return cmInitParaError;
908#ifdef OUTPUT_BIT_STREAM908 }
909 if ( sEncodingParam.sSpatialLayers[sEncodingParam.iSpatialLayerNum-1].iVideoWidth != m_pEncContext->pSvcParam->sDependencyLayers[m_pEncContext->pSvcParam->iNumDependencyLayer-1].iFrameWidth )909 if (sConfig.iNumDependencyLayer < 1) {
910 {910 return cmInitParaError;
911 ++ m_iSwitchTimes;911 }
912 m_bSwitch = TRUE;912 iTargetWidth = sConfig.iActualPicWidth;
913 }913 iTargetHeight = sConfig.iActualPicHeight;
914#endif//OUTPUT_BIT_STREAM914 if (m_pSrcPicList[0] == NULL) {
915 if ( sEncodingParam.iSpatialLayerNum < 1 || sEncodingParam.iSpatialLayerNum > MAX_SPATIAL_LAYER_NUM ) // verify number of spatial layer915 return cmInitParaError;
916 { 916 }
917 return cmInitParaError;917 if (m_iCspInternal != iInputColorspace || m_iMaxPicWidth != iTargetWidth
918 }918 || m_iMaxPicHeight != iTargetHeight) { // for color space due to changed
919 919 InitPic (m_pSrcPicList[0], iInputColorspace, iTargetWidth, iTargetHeight);
920 iInputColorspace = sEncodingParam.iInputCsp; 920 m_iMaxPicWidth = iTargetWidth;
921 if ( sConfig.ParamTranscode( sEncodingParam, true ) )921 m_iMaxPicHeight = iTargetHeight;
922 { 922 m_iCspInternal = iInputColorspace;
923 return cmInitParaError;923 }
924 }924#ifdef REC_FRAME_COUNT
925 if ( sConfig.iNumDependencyLayer < 1 )925 WelsLog (m_pEncContext, WELS_LOG_INFO,
926 { 926 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_SVC_ENCODE_PARAM, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
927 return cmInitParaError;927 m_uiCountFrameNum, m_iCspInternal);
928 }928#endif//REC_FRAME_COUNT
929 iTargetWidth = sConfig.iActualPicWidth;929
930 iTargetHeight = sConfig.iActualPicHeight; 930 /* New configuration available here */
931 if ( m_pSrcPicList[0] == NULL )931 sConfig.iInputCsp = m_iCspInternal; // I420 in default designed for presentation in encoder used internal
932 { 932 sConfig.DetermineTemporalSettings();
933 return cmInitParaError;933
934 }934 /* Check every field whether there is new request for memory block changed or else, Oct. 24, 2008 */
935 if ( m_iCspInternal != iInputColorspace || m_iMaxPicWidth != iTargetWidth || m_iMaxPicHeight != iTargetHeight ){ // for color space due to changed935 WelsEncoderParamAdjust (&m_pEncContext, &sConfig);
936 InitPic( m_pSrcPicList[0], iInputColorspace, iTargetWidth, iTargetHeight );936 }
937 m_iMaxPicWidth = iTargetWidth;937 break;
938 m_iMaxPicHeight = iTargetHeight;938 case ENCODER_OPTION_FRAME_RATE: { // Maximal input frame rate
939 m_iCspInternal = iInputColorspace;939 float iValue = * ((float*)pOption);
940 } 940#ifdef REC_FRAME_COUNT
941#ifdef REC_FRAME_COUNT941 WelsLog (m_pEncContext, WELS_LOG_INFO,
942 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_SVC_ENCODE_PARAM, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );942 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_FRAME_RATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n",
943#endif//REC_FRAME_COUNT943 m_uiCountFrameNum, m_iCspInternal, iValue);
944 944#endif//REC_FRAME_COUNT
945 /* New configuration available here */945 m_pEncContext->pSvcParam->fMaxFrameRate = iValue;
946 sConfig.iInputCsp = m_iCspInternal; // I420 in default designed for presentation in encoder used internal946
947 sConfig.DetermineTemporalSettings();947 }
948 948 break;
949 /* Check every field whether there is new request for memory block changed or else, Oct. 24, 2008 */949 case ENCODER_OPTION_iBitRate: { // Target bit-rate
950 WelsEncoderParamAdjust( &m_pEncContext, &sConfig ); 950 int32_t iValue = * ((int32_t*)pOption);
951 }951#ifdef REC_FRAME_COUNT
952 break;952 WelsLog (m_pEncContext, WELS_LOG_INFO,
953 case ENCODER_OPTION_FRAME_RATE: // Maximal input frame rate953 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_iBitRate, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n",
954 {954 m_uiCountFrameNum, m_iCspInternal, iValue);
955 float iValue = *((float*)pOption);955#endif//REC_FRAME_COUNT
956#ifdef REC_FRAME_COUNT956 m_pEncContext->pSvcParam->iTargetBitrate = iValue;
957 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_FRAME_RATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n", m_uiCountFrameNum, m_iCspInternal, iValue );957
958#endif//REC_FRAME_COUNT958 }
959 m_pEncContext->pSvcParam->fMaxFrameRate = iValue; 959 break;
960 960 case ENCODER_OPTION_RC_MODE: { // 0:quality mode;1:bit-rate mode
961 }961 int32_t iValue = * ((int32_t*)pOption);
962 break;962 m_pEncContext->pSvcParam->iRCMode = iValue;
963 case ENCODER_OPTION_iBitRate: // Target bit-rate963 }
964 {964 break;
965 int32_t iValue = *((int32_t*)pOption);965 case ENCODER_PADDING_PADDING: { // 0:disable padding;1:padding
966#ifdef REC_FRAME_COUNT966 int32_t iValue = * ((int32_t*)pOption);
967 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_iBitRate, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n", m_uiCountFrameNum, m_iCspInternal, iValue );967 m_pEncContext->pSvcParam->iPaddingFlag = iValue;
968#endif//REC_FRAME_COUNT968 }
969 m_pEncContext->pSvcParam->iTargetBitrate = iValue; 969 break;
970 970 case ENCODER_LTR_RECOVERY_REQUEST: {
971 }971 SLTRRecoverRequest* pLTR_Recover_Request = (SLTRRecoverRequest*) (pOption);
972 break;972 FilterLTRRecoveryRequest (m_pEncContext, pLTR_Recover_Request);
973 case ENCODER_OPTION_RC_MODE: // 0:quality mode;1:bit-rate mode973 }
974 {974 break;
975 int32_t iValue = *((int32_t*)pOption); 975 case ENCODER_LTR_MARKING_FEEDBACK: {
976 m_pEncContext->pSvcParam->iRCMode = iValue; 976 SLTRMarkingFeedback* fb = (SLTRMarkingFeedback*) (pOption);
977 }977 FilterLTRMarkingFeedback (m_pEncContext, fb);
978 break;978 }
979 case ENCODER_PADDING_PADDING: // 0:disable padding;1:padding979 break;
980 {980 case ENCOCER_LTR_MARKING_PERIOD: {
981 int32_t iValue = *((int32_t*)pOption); 981 uint32_t iValue = * ((uint32_t*) (pOption));
982 m_pEncContext->pSvcParam->iPaddingFlag = iValue; 982 m_pEncContext->pSvcParam->uiLtrMarkPeriod = iValue;
983 }983 }
984 break;984 break;
985 case ENCODER_LTR_RECOVERY_REQUEST:985 case ENCODER_OPTION_LTR: {
986 {986 uint32_t iValue = * ((uint32_t*) (pOption));
987 SLTRRecoverRequest* pLTR_Recover_Request = (SLTRRecoverRequest*)(pOption);987 m_pEncContext->pSvcParam->bEnableLongTermReference = iValue ? true : false;
988 FilterLTRRecoveryRequest(m_pEncContext,pLTR_Recover_Request);988 WelsLog (m_pEncContext, WELS_LOG_WARNING, " CWelsH264SVCEncoder::SetOption enable LTR = %d",
989 }989 m_pEncContext->pSvcParam->bEnableLongTermReference);
990 break;990 }
991 case ENCODER_LTR_MARKING_FEEDBACK:991 break;
992 {992 case ENCODER_OPTION_ENABLE_SSEI: {
993 SLTRMarkingFeedback* fb = (SLTRMarkingFeedback*)(pOption);993 bool_t iValue = * ((bool_t*)pOption);
994 FilterLTRMarkingFeedback(m_pEncContext,fb);994 m_pEncContext->pSvcParam->bEnableSSEI = iValue;
995 }995 WelsLog (m_pEncContext, WELS_LOG_INFO, " CWelsH264SVCEncoder::SetOption enable SSEI = %d \n",
996 break;996 m_pEncContext->pSvcParam->bEnableSSEI);
997 case ENCOCER_LTR_MARKING_PERIOD:997 }
998 {998 break;
999 uint32_t iValue = *((uint32_t*)(pOption));999 case ENCODER_OPTION_ENABLE_PREFIX_NAL_ADDING: {
1000 m_pEncContext->pSvcParam->uiLtrMarkPeriod = iValue;1000 bool_t iValue = * ((bool_t*)pOption);
1001 }1001 m_pEncContext->pSvcParam->bPrefixNalAddingCtrl = iValue;
1002 break;1002 WelsLog (m_pEncContext, WELS_LOG_INFO, " CWelsH264SVCEncoder::SetOption bPrefixNalAddingCtrl = %d \n",
1003 case ENCODER_OPTION_LTR:1003 m_pEncContext->pSvcParam->bPrefixNalAddingCtrl);
1004 { 1004 }
1005 uint32_t iValue = *((uint32_t*)(pOption));1005 break;
1006 m_pEncContext->pSvcParam->bEnableLongTermReference = iValue?true:false;1006 case ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION: {
1007 WelsLog(m_pEncContext,WELS_LOG_WARNING," CWelsH264SVCEncoder::SetOption enable LTR = %d",m_pEncContext->pSvcParam->bEnableLongTermReference);1007 bool_t iValue = * ((bool_t*)pOption);
1008 }1008
1009 break;1009 m_pEncContext->pSvcParam->bEnableSpsPpsIdAddition = iValue;
1010 case ENCODER_OPTION_ENABLE_SSEI:1010 WelsLog (m_pEncContext, WELS_LOG_INFO, " CWelsH264SVCEncoder::SetOption enable SPS/PPS ID = %d \n",
1011 {1011 m_pEncContext->pSvcParam->bEnableSpsPpsIdAddition);
1012 bool_t iValue = *((bool_t*)pOption);1012 }
1013 m_pEncContext->pSvcParam->bEnableSSEI = iValue;1013 break;
1014 WelsLog( m_pEncContext, WELS_LOG_INFO, " CWelsH264SVCEncoder::SetOption enable SSEI = %d \n", m_pEncContext->pSvcParam->bEnableSSEI );1014 case ENCODER_OPTION_CURRENT_PATH: {
1015 }1015 if (m_pEncContext->pSvcParam != NULL) {
1016 break;1016 str_t* path = static_cast<str_t*> (pOption);
1017 case ENCODER_OPTION_ENABLE_PREFIX_NAL_ADDING:1017 m_pEncContext->pSvcParam->pCurPath = path;
1018 {1018 }
1019 bool_t iValue = *((bool_t*)pOption);1019 }
1020 m_pEncContext->pSvcParam->bPrefixNalAddingCtrl = iValue;1020 break;
1021 WelsLog( m_pEncContext, WELS_LOG_INFO, " CWelsH264SVCEncoder::SetOption bPrefixNalAddingCtrl = %d \n", m_pEncContext->pSvcParam->bPrefixNalAddingCtrl ); 1021 default:
1022 }1022 return cmInitParaError;
1023 break;1023 }
1024 case ENCODER_OPTION_ENABLE_SPS_PPS_ID_ADDITION:1024
1025 {1025 return 0;
1026 bool_t iValue = *((bool_t*)pOption);1026}
1027 1027
1028 m_pEncContext->pSvcParam->bEnableSpsPpsIdAddition = iValue;1028int CWelsH264SVCEncoder::GetOption (ENCODER_OPTION eOptionId, void* pOption) {
1029 WelsLog( m_pEncContext, WELS_LOG_INFO, " CWelsH264SVCEncoder::SetOption enable SPS/PPS ID = %d \n", m_pEncContext->pSvcParam->bEnableSpsPpsIdAddition ); 1029 if (NULL == pOption) {
1030 }1030 return cmInitParaError;
1031 break;1031 }
1032 case ENCODER_OPTION_CURRENT_PATH:1032 if (NULL == m_pEncContext || FALSE == m_bInitialFlag) {
1033 {1033 return cmInitExpected;
1034 if (m_pEncContext->pSvcParam != NULL)1034 }
1035 {1035
1036 str_t * path = static_cast<str_t *>(pOption);1036 switch (eOptionId) {
1037 m_pEncContext->pSvcParam->pCurPath = path; 1037 case ENCODER_OPTION_INTER_SPATIAL_PRED: { // Inter spatial layer prediction flag
1038 } 1038 WelsLog (m_pEncContext, WELS_LOG_INFO, "ENCODER_OPTION_INTER_SPATIAL_PRED, this feature not supported at present.\n");
1039 }1039 }
1040 break;1040 break;
1041 default: 1041 case ENCODER_OPTION_DATAFORMAT: { // Input color space
1042 return cmInitParaError;1042#ifdef REC_FRAME_COUNT
1043 }1043 WelsLog (m_pEncContext, WELS_LOG_INFO,
1044 1044 "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_DATAFORMAT, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
1045 return 0;1045 m_uiCountFrameNum, m_iCspInternal);
1046}1046#endif//REC_FRAME_COUNT
1047 1047
1048int CWelsH264SVCEncoder::GetOption(ENCODER_OPTION eOptionId, void* pOption)1048 * ((int32_t*)pOption) = m_iCspInternal;
1049{1049 }
1050 if ( NULL == pOption ){ 1050 break;
1051 return cmInitParaError;1051 case ENCODER_OPTION_IDR_INTERVAL: { // IDR Interval
1052 } 1052#ifdef REC_FRAME_COUNT
1053 if ( NULL == m_pEncContext || FALSE == m_bInitialFlag ){ 1053 WelsLog (m_pEncContext, WELS_LOG_INFO,
1054 return cmInitExpected;1054 "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_IDR_INTERVAL, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
1055 }1055 m_uiCountFrameNum, m_iCspInternal);
1056 1056#endif//REC_FRAME_COUNT
1057 switch( eOptionId ) {1057 * ((int32_t*)pOption) = m_pEncContext->pSvcParam->uiIntraPeriod;
1058 case ENCODER_OPTION_INTER_SPATIAL_PRED: // Inter spatial layer prediction flag1058 }
1059 {1059 break;
1060 WelsLog( m_pEncContext, WELS_LOG_INFO, "ENCODER_OPTION_INTER_SPATIAL_PRED, this feature not supported at present.\n" );1060 case ENCODER_OPTION_SVC_ENCODE_PARAM: { // SVC Encoding Parameter
1061 }1061#ifdef REC_FRAME_COUNT
1062 break;1062 WelsLog (m_pEncContext, WELS_LOG_INFO,
1063 case ENCODER_OPTION_DATAFORMAT: // Input color space1063 "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_SVC_ENCODE_PARAM, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
1064 {1064 m_uiCountFrameNum, m_iCspInternal);
1065#ifdef REC_FRAME_COUNT1065#endif//REC_FRAME_COUNT
1066 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_DATAFORMAT, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );1066 memcpy (pOption, m_pEncContext->pSvcParam, sizeof (SWelsSvcCodingParam)); // confirmed_safe_unsafe_usage
1067#endif//REC_FRAME_COUNT1067 }
1068 1068 break;
1069 *((int32_t*)pOption) = m_iCspInternal;1069 case ENCODER_OPTION_FRAME_RATE: { // Maximal input frame rate
1070 }1070#ifdef REC_FRAME_COUNT
1071 break;1071 WelsLog (m_pEncContext, WELS_LOG_INFO,
1072 case ENCODER_OPTION_IDR_INTERVAL: // IDR Interval1072 "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_FRAME_RATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
1073 {1073 m_uiCountFrameNum, m_iCspInternal);
1074#ifdef REC_FRAME_COUNT1074#endif//REC_FRAME_COUNT
1075 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_IDR_INTERVAL, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );1075 * ((float*)pOption) = m_pEncContext->pSvcParam->fMaxFrameRate;
1076#endif//REC_FRAME_COUNT1076 }
1077 *((int32_t*)pOption) = m_pEncContext->pSvcParam->uiIntraPeriod;1077 break;
1078 }1078 case ENCODER_OPTION_iBitRate: { // Target bit-rate
1079 break;1079#ifdef REC_FRAME_COUNT
1080 case ENCODER_OPTION_SVC_ENCODE_PARAM: // SVC Encoding Parameter1080 WelsLog (m_pEncContext, WELS_LOG_INFO,
1081 {1081 "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_iBitRate, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
1082#ifdef REC_FRAME_COUNT1082 m_uiCountFrameNum, m_iCspInternal);
1083 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_SVC_ENCODE_PARAM, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );1083#endif//REC_FRAME_COUNT
1084#endif//REC_FRAME_COUNT1084 * ((int32_t*)pOption) = m_pEncContext->pSvcParam->iTargetBitrate;
1085 memcpy( pOption, m_pEncContext->pSvcParam, sizeof(SWelsSvcCodingParam) ); // confirmed_safe_unsafe_usage1085 }
1086 }1086 break;
1087 break;1087 default:
1088 case ENCODER_OPTION_FRAME_RATE: // Maximal input frame rate1088 return cmInitParaError;
1089 {1089 }
1090#ifdef REC_FRAME_COUNT1090
1091 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_FRAME_RATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );1091 return 0;
1092#endif//REC_FRAME_COUNT1092}
1093 *((float*)pOption) = m_pEncContext->pSvcParam->fMaxFrameRate;1093
1094 }1094void CWelsH264SVCEncoder::DumpSrcPicture (const uint8_t* pSrc) {
1095 break;1095#ifdef DUMP_SRC_PICTURE
1096 case ENCODER_OPTION_iBitRate: // Target bit-rate1096 FILE* pFile = NULL;
1097 {1097 str_t strFileName[256] = {0};
1098#ifdef REC_FRAME_COUNT1098 const int32_t iDataLength = m_iMaxPicWidth * m_iMaxPicHeight;
1099 WelsLog( m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_iBitRate, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal );1099
1100#endif//REC_FRAME_COUNT1100#if defined(__GNUC__)
1101 *((int32_t*)pOption) = m_pEncContext->pSvcParam->iTargetBitrate;1101 STRNCPY (strFileName, 256, "/tmp/pic_in_", STRNLEN ("/tmp/pic_in_", 255)); // confirmed_safe_unsafe_usage
1102 }1102#else
1103 break;1103 STRNCPY (strFileName, 256, "d:\\incoming\\mosaic_st\\pic_in_", STRNLEN ("d:\\incoming\\mosaic_st\\pic_in_",
1104 default: 1104 255)); // confirmed_safe_unsafe_usage
1105 return cmInitParaError;1105#endif//__GNUC__
1106 }1106
1107 1107 if (m_iMaxPicWidth == 640) {
1108 return 0;1108 STRCAT (strFileName, 256, "360p."); // confirmed_safe_unsafe_usage
1109}1109 } else if (m_iMaxPicWidth == 320) {
1110 1110 STRCAT (strFileName, 256, "180p."); // confirmed_safe_unsafe_usage
1111void CWelsH264SVCEncoder::DumpSrcPicture(const uint8_t *pSrc)1111 } else if (m_iMaxPicWidth == 160) {
1112{1112 STRCAT (strFileName, 256, "90p."); // confirmed_safe_unsafe_usage
1113#ifdef DUMP_SRC_PICTURE1113 }
1114 FILE *pFile = NULL;1114
1115 str_t strFileName[256] = {0};1115 switch (m_iCspInternal) {
1116 const int32_t iDataLength = m_iMaxPicWidth * m_iMaxPicHeight;1116 case videoFormatI420:
1117 1117 case videoFormatYV12:
1118#if defined(__GNUC__)1118 STRCAT (strFileName, 256, "yuv"); // confirmed_safe_unsafe_usage
1119 STRNCPY(strFileName, 256, "/tmp/pic_in_", STRNLEN("/tmp/pic_in_", 255)); // confirmed_safe_unsafe_usage1119#if defined(__GNUC__)
1120#else1120 pFile = FOPEN (strFileName, "ab+");
1121 STRNCPY(strFileName, 256, "d:\\incoming\\mosaic_st\\pic_in_", STRNLEN("d:\\incoming\\mosaic_st\\pic_in_", 255)); // confirmed_safe_unsafe_usage1121#else
1122#endif//__GNUC__1122#if defined(_MSC_VER)
1123 1123#if _MSC_VER>=1500
1124 if ( m_iMaxPicWidth == 640 )1124 FOPEN (&pFile, strFileName, "ab+");
1125 {1125#else
1126 STRCAT(strFileName, 256, "360p."); // confirmed_safe_unsafe_usage1126 pFile = FOPEN (strFileName, "ab+");
1127 }1127#endif//_MSC_VER>=1500
1128 else if ( m_iMaxPicWidth == 320 )1128#endif//_MSC_VER
1129 {1129#endif//__GNUC__
1130 STRCAT(strFileName, 256, "180p."); // confirmed_safe_unsafe_usage1130 // WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_I420, m_iCspInternal= 0x%x\n", m_iCspInternal);
1131 }1131 if (NULL != pFile) {
1132 else if ( m_iMaxPicWidth == 160 )1132 fwrite (pSrc, sizeof (uint8_t), (iDataLength * 3) >> 1, pFile);
1133 {1133 fflush (pFile);
1134 STRCAT(strFileName, 256, "90p."); // confirmed_safe_unsafe_usage1134 fclose (pFile);
1135 } 1135 }
1136 1136 break;
1137 switch( m_iCspInternal) {1137 case videoFormatRGB:
1138 case videoFormatI420:1138 STRCAT (strFileName, 256, "rgb"); // confirmed_safe_unsafe_usage
1139 case videoFormatYV12:1139#if defined(__GNUC__)
1140 STRCAT(strFileName, 256, "yuv"); // confirmed_safe_unsafe_usage1140 pFile = FOPEN (strFileName, "ab+");
1141#if defined(__GNUC__)1141#else
1142 pFile = FOPEN(strFileName, "ab+");1142#if defined(_MSC_VER)
1143#else1143#if _MSC_VER>=1500
1144#if defined(_MSC_VER)1144 FOPEN (&pFile, strFileName, "ab+");
1145#if _MSC_VER>=15001145#else
1146 FOPEN(&pFile, strFileName, "ab+");1146 pFile = FOPEN (strFileName, "ab+");
1147#else1147#endif//_MSC_VER>=1500
1148 pFile = FOPEN(strFileName, "ab+");1148#endif//_MSC_VER
1149#endif//_MSC_VER>=15001149#endif//__GNUC__
1150#endif//_MSC_VER 1150 if (NULL != pFile) {
1151#endif//__GNUC__1151 fwrite (pSrc, sizeof (uint8_t), iDataLength * 3, pFile);
1152 // WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_I420, m_iCspInternal= 0x%x\n", m_iCspInternal);1152 fflush (pFile);
1153 if (NULL != pFile)1153 fclose (pFile);
1154 { 1154 }
1155 fwrite( pSrc, sizeof(uint8_t), (iDataLength * 3)>>1, pFile );1155 case videoFormatBGR:
1156 fflush( pFile );1156 STRCAT (strFileName, 256, "bgr"); // confirmed_safe_unsafe_usage
1157 fclose(pFile);1157#if defined(__GNUC__)
1158 }1158 pFile = FOPEN (strFileName, "ab+");
1159 break;1159#else
1160 case videoFormatRGB:1160#if defined(_MSC_VER)
1161 STRCAT(strFileName, 256, "rgb"); // confirmed_safe_unsafe_usage1161#if _MSC_VER>=1500
1162#if defined(__GNUC__)1162 FOPEN (&pFile, strFileName, "ab+");
1163 pFile = FOPEN(strFileName, "ab+");1163#else
1164#else1164 pFile = FOPEN (strFileName, "ab+");
1165#if defined(_MSC_VER)1165#endif//_MSC_VER>=1500
1166#if _MSC_VER>=15001166#endif//_MSC_VER
1167 FOPEN(&pFile, strFileName, "ab+");1167#endif//__GNUC__
1168#else1168 // WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_BGR, m_iCspInternal= 0x%x\n", m_iCspInternal);
1169 pFile = FOPEN(strFileName, "ab+");1169 if (NULL != pFile) {
1170#endif//_MSC_VER>=15001170 fwrite (pSrc, sizeof (uint8_t), iDataLength * 3, pFile);
1171#endif//_MSC_VER 1171 fflush (pFile);
1172#endif//__GNUC__1172 fclose (pFile);
1173 if ( NULL != pFile )1173 }
1174 { 1174 break;
1175 fwrite( pSrc, sizeof(uint8_t), iDataLength * 3, pFile );1175 case videoFormatYUY2:
1176 fflush( pFile );1176 STRCAT (strFileName, 256, "yuy2"); // confirmed_safe_unsafe_usage
1177 fclose( pFile );1177#if defined(__GNUC__)
1178 }1178 pFile = FOPEN (strFileName, "ab+");
1179 case videoFormatBGR:1179#else
1180 STRCAT(strFileName, 256, "bgr"); // confirmed_safe_unsafe_usage1180#if defined(_MSC_VER)
1181#if defined(__GNUC__)1181#if _MSC_VER>=1500
1182 pFile = FOPEN(strFileName, "ab+");1182 FOPEN (&pFile, strFileName, "ab+");
1183#else1183#else
1184#if defined(_MSC_VER)1184 pFile = FOPEN (strFileName, "ab+");
1185#if _MSC_VER>=15001185#endif//_MSC_VER>=1500
1186 FOPEN(&pFile, strFileName, "ab+");1186#endif//_MSC_VER
1187#else1187#endif//__GNUC__
1188 pFile = FOPEN(strFileName, "ab+");1188 if (NULL != pFile) {
1189#endif//_MSC_VER>=15001189 fwrite (pSrc, sizeof (uint8_t), (CALC_BI_STRIDE (m_iMaxPicWidth, 16)) * m_iMaxPicHeight, pFile);
1190#endif//_MSC_VER 1190 fflush (pFile);
1191#endif//__GNUC__1191 fclose (pFile);
1192 // WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_BGR, m_iCspInternal= 0x%x\n", m_iCspInternal);1192 }
1193 if ( NULL != pFile )1193 break;
1194 {1194 default:
1195 fwrite( pSrc, sizeof(uint8_t), iDataLength * 3, pFile );1195 WelsLog (m_pEncContext, WELS_LOG_INFO, "Exclusive case, m_iCspInternal= 0x%x\n", m_iCspInternal);
1196 fflush( pFile );1196 break;
1197 fclose( pFile );1197 }
1198 } 1198#endif//DUMP_SRC_PICTURE
1199 break;1199 return;
1200 case videoFormatYUY2:1200}
1201 STRCAT(strFileName, 256, "yuy2"); // confirmed_safe_unsafe_usage1201}
1202#if defined(__GNUC__)1202
1203 pFile = FOPEN(strFileName, "ab+");1203using namespace WelsSVCEnc;
1204#else1204
1205#if defined(_MSC_VER)1205int32_t CreateSVCEncoder (ISVCEncoder** ppEncoder) {
1206#if _MSC_VER>=15001206 assert (ppEncoder);
1207 FOPEN(&pFile, strFileName, "ab+");1207
1208#else1208 if (NULL == ppEncoder)
1209 pFile = FOPEN(strFileName, "ab+");1209 return 1;
1210#endif//_MSC_VER>=15001210
1211#endif//_MSC_VER 1211 if ((*ppEncoder = new CWelsH264SVCEncoder()) != NULL) {
1212#endif//__GNUC__1212 return 0;
1213 if ( NULL != pFile )1213 }
1214 {1214
1215 fwrite( pSrc, sizeof(uint8_t), (CALC_BI_STRIDE(m_iMaxPicWidth, 16)) * m_iMaxPicHeight, pFile );1215 return 1;
1216 fflush( pFile );1216}
1217 fclose( pFile );1217
1218 } 1218void DestroySVCEncoder (ISVCEncoder* pEncoder) {
1219 break;1219 CWelsH264SVCEncoder* pSVCEncoder = (CWelsH264SVCEncoder*)pEncoder;
1220 default:1220
1221 WelsLog( m_pEncContext, WELS_LOG_INFO, "Exclusive case, m_iCspInternal= 0x%x\n", m_iCspInternal);1221 if (pSVCEncoder) {
1222 break;1222 delete pSVCEncoder;
1223 }1223 pSVCEncoder = NULL;
1224#endif//DUMP_SRC_PICTURE1224 }
1225 return;1225}
1226}1226//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1227}
1228
1229using namespace WelsSVCEnc;
1230
1231int32_t CreateSVCEncoder(ISVCEncoder** ppEncoder)
1232{
1233 assert( ppEncoder );
1234
1235 if ( NULL == ppEncoder )
1236 return 1;
1237
1238 if( ( *ppEncoder = new CWelsH264SVCEncoder() ) != NULL )
1239 {
1240 return 0;
1241 }
1242
1243 return 1;
1244}
1245
1246void DestroySVCEncoder(ISVCEncoder* pEncoder)
1247{
1248 CWelsH264SVCEncoder *pSVCEncoder = (CWelsH264SVCEncoder*)pEncoder;
1249
1250 if( pSVCEncoder ){
1251 delete pSVCEncoder;
1252 pSVCEncoder = NULL;
1253 }
1254}
1255//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t