changeset 11965:b4edf9b44d23 draft

api: change signature of x265_csvlog_encode() replace x265_encoder* with x265_param* and int padx, int pady as function arguments.
author Aarthi Thirumalai <aarthi@multicorewareinc.com>
date Thu, 04 Jan 2018 15:16:06 +0530
parents 5f6f6189a239
children 2f3c4158cf35
files source/CMakeLists.txt source/encoder/api.cpp source/x265.h
diffstat 3 files changed, 55 insertions(+-), 58 deletions(-) [+]
line wrap: on
line diff
--- a/source/CMakeLists.txt	Thu Jan 04 13:56:07 2018 +0530
+++ b/source/CMakeLists.txt	Thu Jan 04 15:16:06 2018 +0530
@@ -29,7 +29,7 @@ option(NATIVE_BUILD "Target the build CP
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 150)
+set(X265_BUILD 151)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
--- a/source/encoder/api.cpp	Thu Jan 04 13:56:07 2018 +0530
+++ b/source/encoder/api.cpp	Thu Jan 04 15:16:06 2018 +0530
@@ -312,7 +312,9 @@ void x265_encoder_log(x265_encoder* enc,
         Encoder *encoder = static_cast<Encoder*>(enc);
         x265_stats stats;
         encoder->fetchStats(&stats, sizeof(stats));
-        x265_csvlog_encode(enc, &stats, argc, argv);
+        int padx = encoder->m_sps.conformanceWindow.rightOffset;
+        int pady = encoder->m_sps.conformanceWindow.bottomOffset;
+        x265_csvlog_encode(encoder->m_param, &stats, padx, pady, argc, argv);
     }
 }
 
@@ -868,45 +870,38 @@ void x265_csvlog_frame(const x265_param*
     fflush(stderr);
 }
 
-void x265_csvlog_encode(x265_encoder *enc, const x265_stats* stats, int argc, char** argv)
+void x265_csvlog_encode(const x265_param *p, const x265_stats *stats, int padx, int pady, int argc, char** argv)
 {
-    if (enc)
+    if (p && p->csvfpt)
     {
-        Encoder *encoder = static_cast<Encoder*>(enc);
-        int padx = encoder->m_sps.conformanceWindow.rightOffset;
-        int pady = encoder->m_sps.conformanceWindow.bottomOffset;
         const x265_api * api = x265_api_get(0);
 
-        if (!encoder->m_param->csvfpt)
-            return;
-
-        if (encoder->m_param->csvLogLevel)
+        if (p->csvLogLevel)
         {
             // adding summary to a per-frame csv log file, so it needs a summary header
-            fprintf(encoder->m_param->csvfpt, "\nSummary\n");
-            fputs(summaryCSVHeader, encoder->m_param->csvfpt);
+            fprintf(p->csvfpt, "\nSummary\n");
+            fputs(summaryCSVHeader, p->csvfpt);
         }
 
         // CLI arguments or other
         if (argc)
         {
-            fputc('"', encoder->m_param->csvfpt);
+            fputc('"', p->csvfpt);
             for (int i = 1; i < argc; i++)
             {
-                fputc(' ', encoder->m_param->csvfpt);
-                fputs(argv[i], encoder->m_param->csvfpt);
+                fputc(' ', p->csvfpt);
+                fputs(argv[i], p->csvfpt);
             }
-            fputc('"', encoder->m_param->csvfpt);
+            fputc('"', p->csvfpt);
         }
         else
         {
-            const x265_param* paramTemp = encoder->m_param;
-            char *opts = x265_param2string((x265_param*)paramTemp, padx, pady);
+            char *opts = x265_param2string((x265_param*)p, padx, pady);
             if (opts)
             {
-                fputc('"', encoder->m_param->csvfpt);
-                fputs(opts, encoder->m_param->csvfpt);
-                fputc('"', encoder->m_param->csvfpt);
+                fputc('"', p->csvfpt);
+                fputs(opts, p->csvfpt);
+                fputc('"', p->csvfpt);
             }
         }
 
@@ -917,70 +912,71 @@ void x265_csvlog_encode(x265_encoder *en
         timeinfo = localtime(&now);
         char buffer[200];
         strftime(buffer, 128, "%c", timeinfo);
-        fprintf(encoder->m_param->csvfpt, ", %s, ", buffer);
+        fprintf(p->csvfpt, ", %s, ", buffer);
 
         // elapsed time, fps, bitrate
-        fprintf(encoder->m_param->csvfpt, "%.2f, %.2f, %.2f,",
+        fprintf(p->csvfpt, "%.2f, %.2f, %.2f,",
             stats->elapsedEncodeTime, stats->encodedPictureCount / stats->elapsedEncodeTime, stats->bitrate);
 
-        if (encoder->m_param->bEnablePsnr)
-            fprintf(encoder->m_param->csvfpt, " %.3lf, %.3lf, %.3lf, %.3lf,",
+        if (p->bEnablePsnr)
+            fprintf(p->csvfpt, " %.3lf, %.3lf, %.3lf, %.3lf,",
             stats->globalPsnrY / stats->encodedPictureCount, stats->globalPsnrU / stats->encodedPictureCount,
             stats->globalPsnrV / stats->encodedPictureCount, stats->globalPsnr);
         else
-            fprintf(encoder->m_param->csvfpt, " -, -, -, -,");
-        if (encoder->m_param->bEnableSsim)
-            fprintf(encoder->m_param->csvfpt, " %.6f, %6.3f,", stats->globalSsim, x265_ssim2dB(stats->globalSsim));
+            fprintf(p->csvfpt, " -, -, -, -,");
+        if (p->bEnableSsim)
+            fprintf(p->csvfpt, " %.6f, %6.3f,", stats->globalSsim, x265_ssim2dB(stats->globalSsim));
         else
-            fprintf(encoder->m_param->csvfpt, " -, -,");
+            fprintf(p->csvfpt, " -, -,");
 
         if (stats->statsI.numPics)
         {
-            fprintf(encoder->m_param->csvfpt, " %-6u, %2.2lf, %-8.2lf,", stats->statsI.numPics, stats->statsI.avgQp, stats->statsI.bitrate);
-            if (encoder->m_param->bEnablePsnr)
-                fprintf(encoder->m_param->csvfpt, " %.3lf, %.3lf, %.3lf,", stats->statsI.psnrY, stats->statsI.psnrU, stats->statsI.psnrV);
+            fprintf(p->csvfpt, " %-6u, %2.2lf, %-8.2lf,", stats->statsI.numPics, stats->statsI.avgQp, stats->statsI.bitrate);
+            if (p->bEnablePsnr)
+                fprintf(p->csvfpt, " %.3lf, %.3lf, %.3lf,", stats->statsI.psnrY, stats->statsI.psnrU, stats->statsI.psnrV);
             else
-                fprintf(encoder->m_param->csvfpt, " -, -, -,");
-            if (encoder->m_param->bEnableSsim)
-                fprintf(encoder->m_param->csvfpt, " %.3lf,", stats->statsI.ssim);
+                fprintf(p->csvfpt, " -, -, -,");
+            if (p->bEnableSsim)
+                fprintf(p->csvfpt, " %.3lf,", stats->statsI.ssim);
             else
-                fprintf(encoder->m_param->csvfpt, " -,");
+                fprintf(p->csvfpt, " -,");
         }
         else
-            fprintf(encoder->m_param->csvfpt, " -, -, -, -, -, -, -,");
+            fprintf(p->csvfpt, " -, -, -, -, -, -, -,");
 
         if (stats->statsP.numPics)
         {
-            fprintf(encoder->m_param->csvfpt, " %-6u, %2.2lf, %-8.2lf,", stats->statsP.numPics, stats->statsP.avgQp, stats->statsP.bitrate);
-            if (encoder->m_param->bEnablePsnr)
-                fprintf(encoder->m_param->csvfpt, " %.3lf, %.3lf, %.3lf,", stats->statsP.psnrY, stats->statsP.psnrU, stats->statsP.psnrV);
+            fprintf(p->csvfpt, " %-6u, %2.2lf, %-8.2lf,", stats->statsP.numPics, stats->statsP.avgQp, stats->statsP.bitrate);
+            if (p->bEnablePsnr)
+                fprintf(p->csvfpt, " %.3lf, %.3lf, %.3lf,", stats->statsP.psnrY, stats->statsP.psnrU, stats->statsP.psnrV);
             else
-                fprintf(encoder->m_param->csvfpt, " -, -, -,");
-            if (encoder->m_param->bEnableSsim)
-                fprintf(encoder->m_param->csvfpt, " %.3lf,", stats->statsP.ssim);
+                fprintf(p->csvfpt, " -, -, -,");
+            if (p->bEnableSsim)
+                fprintf(p->csvfpt, " %.3lf,", stats->statsP.ssim);
             else
-                fprintf(encoder->m_param->csvfpt, " -,");
+                fprintf(p->csvfpt, " -,");
         }
         else
-            fprintf(encoder->m_param->csvfpt, " -, -, -, -, -, -, -,");
+            fprintf(p->csvfpt, " -, -, -, -, -, -, -,");
 
         if (stats->statsB.numPics)
         {
-            fprintf(encoder->m_param->csvfpt, " %-6u, %2.2lf, %-8.2lf,", stats->statsB.numPics, stats->statsB.avgQp, stats->statsB.bitrate);
-            if (encoder->m_param->bEnablePsnr)
-                fprintf(encoder->m_param->csvfpt, " %.3lf, %.3lf, %.3lf,", stats->statsB.psnrY, stats->statsB.psnrU, stats->statsB.psnrV);
+            fprintf(p->csvfpt, " %-6u, %2.2lf, %-8.2lf,", stats->statsB.numPics, stats->statsB.avgQp, stats->statsB.bitrate);
+            if (p->bEnablePsnr)
+                fprintf(p->csvfpt, " %.3lf, %.3lf, %.3lf,", stats->statsB.psnrY, stats->statsB.psnrU, stats->statsB.psnrV);
             else
-                fprintf(encoder->m_param->csvfpt, " -, -, -,");
-            if (encoder->m_param->bEnableSsim)
-                fprintf(encoder->m_param->csvfpt, " %.3lf,", stats->statsB.ssim);
+                fprintf(p->csvfpt, " -, -, -,");
+            if (p->bEnableSsim)
+                fprintf(p->csvfpt, " %.3lf,", stats->statsB.ssim);
             else
-                fprintf(encoder->m_param->csvfpt, " -,");
+                fprintf(p->csvfpt, " -,");
         }
         else
-            fprintf(encoder->m_param->csvfpt, " -, -, -, -, -, -, -,");
+            fprintf(p->csvfpt, " -, -, -, -, -, -, -,");
 
-        fprintf(encoder->m_param->csvfpt, " %-6u, %-6u, %s\n", stats->maxCLL, stats->maxFALL, api->version_str);
+        fprintf(p->csvfpt, " %-6u, %-6u, %s\n", stats->maxCLL, stats->maxFALL, api->version_str);
     }
+
 }
 
 /* The dithering algorithm is based on Sierra-2-4A error diffusion.
--- a/source/x265.h	Thu Jan 04 13:56:07 2018 +0530
+++ b/source/x265.h	Thu Jan 04 15:16:06 2018 +0530
@@ -1779,9 +1779,10 @@ FILE* x265_csvlog_open(const x265_param 
 void x265_csvlog_frame(const x265_param *, const x265_picture *);
 
 /* Log final encode statistics to the CSV file handle. 'argc' and 'argv' are
- * intended to be command line arguments passed to the encoder. Encode
+ * intended to be command line arguments passed to the encoder. padx and pady are
+ * padding offsets for conformance and can be given from sps settings. Encode
  * statistics should be queried from the encoder just prior to closing it. */
-void x265_csvlog_encode(x265_encoder *encoder, const x265_stats *, int argc, char** argv);
+void x265_csvlog_encode(const x265_param*, const x265_stats *, int padx, int pady, int argc, char** argv);
 
 /* In-place downshift from a bit-depth greater than 8 to a bit-depth of 8, using
  * the residual bits to dither each row. */
@@ -1836,7 +1837,7 @@ typedef struct x265_api
     int           (*get_ref_frame_list)(x265_encoder*, x265_picyuv**, x265_picyuv**, int, int, int*, int*);
     FILE*         (*csvlog_open)(const x265_param*);
     void          (*csvlog_frame)(const x265_param*, const x265_picture*);
-    void          (*csvlog_encode)(x265_encoder*, const x265_stats*, int, char**);
+    void          (*csvlog_encode)(const x265_param*, const x265_stats *, int, int, int, char**);
     void          (*dither_image)(x265_picture*, int, int, int16_t*, int);
     int           (*set_analysis_data)(x265_encoder *encoder, x265_analysis_data *analysis_data, int poc, uint32_t cuBytes);
     /* add new pointers to the end, or increment X265_MAJOR_VERSION */