History

Reduce code duplication

Martin Storsjö committed 12 years ago

Commit 586d0ba1 parent 00f28cc1 file · +15 −31Browse files

Showing the changes to codec/encoder/core/src/encoder.cpp (1 of 1 file). Show all

Unified · Split

codec/encoder/core/src/encoder.cpp+15−31
@@ -353,29 +353,20 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 352 unmodified lines
353353 extern "C" void DumpDependencyRec (SPicture* pCurPicture, const char* kpFileName, const int8_t kiDid, bool bAppend) {
354354 WelsFileHandle* pDumpRecFile = NULL;
355355 int32_t iWrittenSize = 0;
356+ const char* openMode = bAppend ? "ab" : "wb";
356357
357358 if (NULL == pCurPicture || NULL == kpFileName || kiDid >= MAX_DEPENDENCY_LAYER)
358359 return;
359360
360− if (bAppend) {
361− if (strlen (kpFileName) > 0) // confirmed_safe_unsafe_usage
362− pDumpRecFile = WelsFopen (kpFileName, "ab");
363− else {
364− char sDependencyRecFileName[16] = {0};
365− WelsSnprintf (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
366− pDumpRecFile = WelsFopen (sDependencyRecFileName, "ab");
367− }
368− if (NULL != pDumpRecFile)
369− WelsFseek (pDumpRecFile, 0, SEEK_END);
370− } else {
371− if (strlen (kpFileName) > 0) { // confirmed_safe_unsafe_usage
372− pDumpRecFile = WelsFopen (kpFileName, "wb");
373− } else {
374− char sDependencyRecFileName[16] = {0};
375− WelsSnprintf (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
376− pDumpRecFile = WelsFopen (sDependencyRecFileName, "wb");
377− }
361+ if (strlen (kpFileName) > 0) // confirmed_safe_unsafe_usage
362+ pDumpRecFile = WelsFopen (kpFileName, openMode);
363+ else {
364+ char sDependencyRecFileName[16] = {0};
365+ WelsSnprintf (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
366+ pDumpRecFile = WelsFopen (sDependencyRecFileName, openMode);
378367 }
368+ if (NULL != pDumpRecFile && bAppend)
369+ WelsFseek (pDumpRecFile, 0, SEEK_END);
379370
380371 if (NULL != pDumpRecFile) {
381372 int32_t i = 0;
@@ -419,25 +410,18 @@ extern "C" void DumpDependencyRec (SPicture* pCurPicture, const char* kpFileName · 37 unmodified lines
419410 void DumpRecFrame (SPicture* pCurPicture, const char* kpFileName, bool bAppend) {
420411 WelsFileHandle* pDumpRecFile = NULL;
421412 int32_t iWrittenSize = 0;
413+ const char* openMode = bAppend ? "ab" : "wb";
422414
423415 if (NULL == pCurPicture || NULL == kpFileName)
424416 return;
425417
426− if (bAppend) {
427− if (strlen (kpFileName) > 0) { // confirmed_safe_unsafe_usage
428− pDumpRecFile = WelsFopen (kpFileName, "ab");
429− } else {
430− pDumpRecFile = WelsFopen ("rec.yuv", "ab");
431− }
432− if (NULL != pDumpRecFile)
433− WelsFseek (pDumpRecFile, 0, SEEK_END);
418+ if (strlen (kpFileName) > 0) { // confirmed_safe_unsafe_usage
419+ pDumpRecFile = WelsFopen (kpFileName, openMode);
434420 } else {
435− if (strlen (kpFileName) > 0) { // confirmed_safe_unsafe_usage
436− pDumpRecFile = WelsFopen (kpFileName, "wb");
437− } else {
438− pDumpRecFile = WelsFopen ("rec.yuv", "wb");
439− }
421+ pDumpRecFile = WelsFopen ("rec.yuv", openMode);
440422 }
423+ if (NULL != pDumpRecFile && bAppend)
424+ WelsFseek (pDumpRecFile, 0, SEEK_END);
441425
442426 if (NULL != pDumpRecFile) {
443427 int32_t i = 0;

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