Also similarly simplify the use of the return value from WelsStrftime and GetCodeName/GetLibName/GetVerNum.
Unified · Split
| @@ -110,20 +110,16 @@ CWelsDecoder::CWelsDecoder (void) · 109 unmodified lines | |||
| 110 | iCurUsed = WelsSnprintf (chFileName, iBufLeft, "bs_0x%p_", (void*)this); | 110 | iCurUsed = WelsSnprintf (chFileName, iBufLeft, "bs_0x%p_", (void*)this); |
| 111 | iCurUsedSize = WelsSnprintf (chFileNameSize, iBufLeftSize, "size_0x%p_", (void*)this); | 111 | iCurUsedSize = WelsSnprintf (chFileNameSize, iBufLeftSize, "size_0x%p_", (void*)this); |
| 112 | 112 | ||
| 113 | if (iCurUsed > 0) { | 113 | iBufUsed += iCurUsed; |
| 114 | iBufUsed += iCurUsed; | 114 | iBufLeft -= iCurUsed; |
| 115 | iBufLeft -= iCurUsed; | ||
| 116 | } | ||
| 117 | if (iBufLeft > 0) { | 115 | if (iBufLeft > 0) { |
| 118 | iCurUsed = WelsStrftime (&chFileName[iBufUsed], iBufLeft, "%y%m%d%H%M%S", &sCurTime); | 116 | iCurUsed = WelsStrftime (&chFileName[iBufUsed], iBufLeft, "%y%m%d%H%M%S", &sCurTime); |
| 119 | iBufUsed += iCurUsed; | 117 | iBufUsed += iCurUsed; |
| 120 | iBufLeft -= iCurUsed; | 118 | iBufLeft -= iCurUsed; |
| 121 | } | 119 | } |
| 122 | 120 | ||
| 123 | if (iCurUsedSize > 0) { | 121 | iBufUsedSize += iCurUsedSize; |
| 124 | iBufUsedSize += iCurUsedSize; | 122 | iBufLeftSize -= iCurUsedSize; |
| 125 | iBufLeftSize -= iCurUsedSize; | ||
| 126 | } | ||
| 127 | if (iBufLeftSize > 0) { | 123 | if (iBufLeftSize > 0) { |
| 128 | iCurUsedSize = WelsStrftime (&chFileNameSize[iBufUsedSize], iBufLeftSize, "%y%m%d%H%M%S", &sCurTime); | 124 | iCurUsedSize = WelsStrftime (&chFileNameSize[iBufUsedSize], iBufLeftSize, "%y%m%d%H%M%S", &sCurTime); |
| 129 | iBufUsedSize += iCurUsedSize; | 125 | iBufUsedSize += iCurUsedSize; |
| @@ -132,19 +128,15 @@ CWelsDecoder::CWelsDecoder (void) · 2 unmodified lines | |||
| 132 | 128 | ||
| 133 | if (iBufLeft > 0) { | 129 | if (iBufLeft > 0) { |
| 134 | iCurUsed = WelsSnprintf (&chFileName[iBufUsed], iBufLeft, ".%03.3u.264", WelsGetMillisecond (&sCurTime)); | 130 | iCurUsed = WelsSnprintf (&chFileName[iBufUsed], iBufLeft, ".%03.3u.264", WelsGetMillisecond (&sCurTime)); |
| 135 | if (iCurUsed > 0) { | 131 | iBufUsed += iCurUsed; |
| 136 | iBufUsed += iCurUsed; | 132 | iBufLeft -= iCurUsed; |
| 137 | iBufLeft -= iCurUsed; | ||
| 138 | } | ||
| 139 | } | 133 | } |
| 140 | 134 | ||
| 141 | if (iBufLeftSize > 0) { | 135 | if (iBufLeftSize > 0) { |
| 142 | iCurUsedSize = WelsSnprintf (&chFileNameSize[iBufUsedSize], iBufLeftSize, ".%03.3u.len", | 136 | iCurUsedSize = WelsSnprintf (&chFileNameSize[iBufUsedSize], iBufLeftSize, ".%03.3u.len", |
| 143 | WelsGetMillisecond (&sCurTime)); | 137 | WelsGetMillisecond (&sCurTime)); |
| 144 | if (iCurUsedSize > 0) { | 138 | iBufUsedSize += iCurUsedSize; |
| 145 | iBufUsedSize += iCurUsedSize; | 139 | iBufLeftSize -= iCurUsedSize; |
| 146 | iBufLeftSize -= iCurUsedSize; | ||
| 147 | } | ||
| 148 | } | 140 | } |
| 149 | 141 | ||
| 150 | 142 | ||
| @@ -144,26 +144,20 @@ void WelsLogDefault (void* pCtx, const int32_t kiLevel, const char* kpFmtStr, va · 143 unmodified lines | |||
| 144 | 144 | ||
| 145 | WelsGetTimeOfDay(&tTime); | 145 | WelsGetTimeOfDay(&tTime); |
| 146 | iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx); // confirmed_safe_unsafe_usage | 146 | iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx); // confirmed_safe_unsafe_usage |
| 147 | if (iCurUsed >= 0) { | 147 | iBufUsed += iCurUsed; |
| 148 | iBufUsed += iCurUsed; | 148 | iBufLeft -= iCurUsed; |
| 149 | iBufLeft -= iCurUsed; | ||
| 150 | } | ||
| 151 | 149 | ||
| 152 | if (iBufLeft > 0) { | 150 | if (iBufLeft > 0) { |
| 153 | iCurUsed = GetCodeName (&pBuf[iBufUsed], iBufLeft); | 151 | iCurUsed = GetCodeName (&pBuf[iBufUsed], iBufLeft); |
| 154 | if (iCurUsed > 0) { | 152 | iBufUsed += iCurUsed; |
| 155 | iBufUsed += iCurUsed; | 153 | iBufLeft -= iCurUsed; |
| 156 | iBufLeft -= iCurUsed; | ||
| 157 | } | ||
| 158 | pBuf[iBufUsed] = ' '; | 154 | pBuf[iBufUsed] = ' '; |
| 159 | ++ iBufUsed; | 155 | ++ iBufUsed; |
| 160 | -- iBufLeft; | 156 | -- iBufLeft; |
| 161 | 157 | ||
| 162 | iCurUsed = GetLibName (&pBuf[iBufUsed], iBufLeft); | 158 | iCurUsed = GetLibName (&pBuf[iBufUsed], iBufLeft); |
| 163 | if (iCurUsed > 0) { | 159 | iBufUsed += iCurUsed; |
| 164 | iBufUsed += iCurUsed; | 160 | iBufLeft -= iCurUsed; |
| 165 | iBufLeft -= iCurUsed; | ||
| 166 | } | ||
| 167 | pBuf[iBufUsed] = ' '; | 161 | pBuf[iBufUsed] = ' '; |
| 168 | ++ iBufUsed; | 162 | ++ iBufUsed; |
| 169 | -- iBufLeft; | 163 | -- iBufLeft; |
| @@ -172,10 +166,8 @@ void WelsLogDefault (void* pCtx, const int32_t kiLevel, const char* kpFmtStr, va · 2 unmodified lines | |||
| 172 | ++ iBufUsed; | 166 | ++ iBufUsed; |
| 173 | -- iBufLeft; | 167 | -- iBufLeft; |
| 174 | iCurUsed = GetVerNum (&pBuf[iBufUsed], iBufLeft); | 168 | iCurUsed = GetVerNum (&pBuf[iBufUsed], iBufLeft); |
| 175 | if (iCurUsed > 0) { | 169 | iBufUsed += iCurUsed; |
| 176 | iBufUsed += iCurUsed; | 170 | iBufLeft -= iCurUsed; |
| 177 | iBufLeft -= iCurUsed; | ||
| 178 | } | ||
| 179 | pBuf[iBufUsed] = ' '; | 171 | pBuf[iBufUsed] = ' '; |
| 180 | ++ iBufUsed; | 172 | ++ iBufUsed; |
| 181 | -- iBufLeft; | 173 | -- iBufLeft; |
| @@ -183,20 +175,16 @@ void WelsLogDefault (void* pCtx, const int32_t kiLevel, const char* kpFmtStr, va · 1 unmodified line | |||
| 183 | 175 | ||
| 184 | if (iBufLeft > 0) { | 176 | if (iBufLeft > 0) { |
| 185 | iCurUsed = WelsStrftime (&pBuf[iBufUsed], iBufLeft, "%y-%m-%d %H:%M:%S", &tTime); | 177 | iCurUsed = WelsStrftime (&pBuf[iBufUsed], iBufLeft, "%y-%m-%d %H:%M:%S", &tTime); |
| 186 | if (iCurUsed > 0) { | 178 | iBufUsed += iCurUsed; |
| 187 | iBufUsed += iCurUsed; | 179 | iBufLeft -= iCurUsed; |
| 188 | iBufLeft -= iCurUsed; | ||
| 189 | } | ||
| 190 | } else { | 180 | } else { |
| 191 | return; | 181 | return; |
| 192 | } | 182 | } |
| 193 | 183 | ||
| 194 | if (iBufLeft > 0) { | 184 | if (iBufLeft > 0) { |
| 195 | iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ", tTime.millitm); // confirmed_safe_unsafe_usage | 185 | iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ", tTime.millitm); // confirmed_safe_unsafe_usage |
| 196 | if (iCurUsed >= 0) { | 186 | iBufUsed += iCurUsed; |
| 197 | iBufUsed += iCurUsed; | 187 | iBufLeft -= iCurUsed; |
| 198 | iBufLeft -= iCurUsed; | ||
| 199 | } | ||
| 200 | } else { | 188 | } else { |
| 201 | return; | 189 | return; |
| 202 | } | 190 | } |
| @@ -209,18 +197,14 @@ void WelsLogDefault (void* pCtx, const int32_t kiLevel, const char* kpFmtStr, va · 6 unmodified lines | |||
| 209 | pStr = GetLogTag (kiLevel, &i_shift); | 197 | pStr = GetLogTag (kiLevel, &i_shift); |
| 210 | if (NULL != pStr) { | 198 | if (NULL != pStr) { |
| 211 | iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "%s ", pStr); | 199 | iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "%s ", pStr); |
| 212 | if (iCurUsed >= 0) { | 200 | iBufUsed += iCurUsed; |
| 213 | iBufUsed += iCurUsed; | 201 | iBufLeft -= iCurUsed; |
| 214 | iBufLeft -= iCurUsed; | ||
| 215 | } | ||
| 216 | } | 202 | } |
| 217 | } | 203 | } |
| 218 | if (iBufLeft > 0) { | 204 | if (iBufLeft > 0) { |
| 219 | iCurUsed = WelsVsnprintf (&pBuf[iBufUsed], iBufLeft, kpFmtStr, argv); // confirmed_safe_unsafe_usage | 205 | iCurUsed = WelsVsnprintf (&pBuf[iBufUsed], iBufLeft, kpFmtStr, argv); // confirmed_safe_unsafe_usage |
| 220 | if (iCurUsed > 0) { | 206 | iBufUsed += iCurUsed; |
| 221 | iBufUsed += iCurUsed; | 207 | iBufLeft -= iCurUsed; |
| 222 | iBufLeft -= iCurUsed; | ||
| 223 | } | ||
| 224 | } | 208 | } |
| 225 | #ifdef ENABLE_TRACE_FILE | 209 | #ifdef ENABLE_TRACE_FILE |
| 226 | if (NULL != pEncCtx && NULL != pEncCtx->pFileLog) { | 210 | if (NULL != pEncCtx && NULL != pEncCtx->pFileLog) { |
| @@ -90,20 +90,16 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder() · 89 unmodified lines | |||
| 90 | iCurUsedSize = WelsSnprintf (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this); | 90 | iCurUsedSize = WelsSnprintf (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this); |
| 91 | 91 | ||
| 92 | 92 | ||
| 93 | if (iCurUsed > 0) { | 93 | iBufferUsed += iCurUsed; |
| 94 | iBufferUsed += iCurUsed; | 94 | iBufferLeft -= iCurUsed; |
| 95 | iBufferLeft -= iCurUsed; | ||
| 96 | } | ||
| 97 | if (iBufferLeft > 0) { | 95 | if (iBufferLeft > 0) { |
| 98 | iCurUsed = WelsStrftime (&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S", &tTime); | 96 | iCurUsed = WelsStrftime (&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S", &tTime); |
| 99 | iBufferUsed += iCurUsed; | 97 | iBufferUsed += iCurUsed; |
| 100 | iBufferLeft -= iCurUsed; | 98 | iBufferLeft -= iCurUsed; |
| 101 | } | 99 | } |
| 102 | 100 | ||
| 103 | if (iCurUsedSize > 0) { | 101 | iBufferUsedSize += iCurUsedSize; |
| 104 | iBufferUsedSize += iCurUsedSize; | 102 | iBufferLeftSize -= iCurUsedSize; |
| 105 | iBufferLeftSize -= iCurUsedSize; | ||
| 106 | } | ||
| 107 | if (iBufferLeftSize > 0) { | 103 | if (iBufferLeftSize > 0) { |
| 108 | iCurUsedSize = WelsStrftime (&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S", &tTime); | 104 | iCurUsedSize = WelsStrftime (&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S", &tTime); |
| 109 | iBufferUsedSize += iCurUsedSize; | 105 | iBufferUsedSize += iCurUsedSize; |
| @@ -113,19 +109,15 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder() · 3 unmodified lines | |||
| 113 | if (iBufferLeft > 0) { | 109 | if (iBufferLeft > 0) { |
| 114 | iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", | 110 | iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", |
| 115 | WelsGetMillisecond(&tTime)); | 111 | WelsGetMillisecond(&tTime)); |
| 116 | if (iCurUsed > 0) { | 112 | iBufferUsed += iCurUsed; |
| 117 | iBufferUsed += iCurUsed; | 113 | iBufferLeft -= iCurUsed; |
| 118 | iBufferLeft -= iCurUsed; | ||
| 119 | } | ||
| 120 | } | 114 | } |
| 121 | 115 | ||
| 122 | if (iBufferLeftSize > 0) { | 116 | if (iBufferLeftSize > 0) { |
| 123 | iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", | 117 | iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", |
| 124 | WelsGetMillisecond(&tTime)); | 118 | WelsGetMillisecond(&tTime)); |
| 125 | if (iCurUsedSize > 0) { | 119 | iBufferUsedSize += iCurUsedSize; |
| 126 | iBufferUsedSize += iCurUsedSize; | 120 | iBufferLeftSize -= iCurUsedSize; |
| 127 | iBufferLeftSize -= iCurUsedSize; | ||
| 128 | } | ||
| 129 | } | 121 | } |
| 130 | 122 | ||
| 131 | m_pFileBs = WelsFopen (strStreamFileName, "wb"); | 123 | m_pFileBs = WelsFopen (strStreamFileName, "wb"); |