[x265] [PATCH 3 of 3] cli: improve and document return codes

Steve Borho steve at borho.org
Thu Jan 29 16:33:30 CET 2015


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1422545587 21600
#      Thu Jan 29 09:33:07 2015 -0600
# Node ID 02d00fd3e9439d0e66a28c82bdfc6b5a73a2ed52
# Parent  31321122396b06e3c49bbc27a031fbbde7c78c25
cli: improve and document return codes

command parse errors were being reported but not many other errors were.

diff -r 31321122396b -r 02d00fd3e943 doc/reST/cli.rst
--- a/doc/reST/cli.rst	Thu Jan 29 09:31:58 2015 -0600
+++ b/doc/reST/cli.rst	Thu Jan 29 09:33:07 2015 -0600
@@ -45,6 +45,14 @@
 
 	**CLI ONLY**
 
+Command line executable return codes::
+
+	0. encode successful
+	1. unable to parse command line
+	2. unable to open encoder
+	3. unable to generate stream headers
+	4. encoder abort
+
 Logging/Statistic Options
 =========================
 
diff -r 31321122396b -r 02d00fd3e943 source/x265.cpp
--- a/source/x265.cpp	Thu Jan 29 09:31:58 2015 -0600
+++ b/source/x265.cpp	Thu Jan 29 09:33:07 2015 -0600
@@ -447,6 +447,14 @@
     return 1;
 }
 
+/* CLI return codes:
+ *
+ * 0 - encode successful
+ * 1 - unable to parse command line
+ * 2 - unable to open encoder
+ * 3 - unable to generate stream headers
+ * 4 - encoder abort */
+
 int main(int argc, char **argv)
 {
 #if HAVE_VLD
@@ -473,7 +481,7 @@
         cliopt.destroy();
         x265_param_free(param);
         x265_cleanup();
-        exit(1);
+        exit(2);
     }
 
     /* get the encoder parameters post-initialization */
@@ -493,12 +501,14 @@
     x265_stats stats;
     uint32_t nal;
     int16_t *errorBuf = NULL;
+    int ret = 0;
 
     if (!param->bRepeatHeaders)
     {
         if (x265_encoder_headers(encoder, &p_nal, &nal) < 0)
         {
             x265_log(param, X265_LOG_ERROR, "Failure generating stream headers\n");
+            ret = 3;
             goto fail;
         }
         else
@@ -550,6 +560,7 @@
         if (numEncoded < 0)
         {
             b_ctrl_c = 1;
+            ret = 4;
             break;
         }
         outFrameCount += numEncoded;
@@ -565,7 +576,12 @@
     /* Flush the encoder */
     while (!b_ctrl_c)
     {
-        uint32_t numEncoded = x265_encoder_encode(encoder, &p_nal, &nal, NULL, pic_recon);
+        int numEncoded = x265_encoder_encode(encoder, &p_nal, &nal, NULL, pic_recon);
+        if (numEncoded < 0)
+        {
+            ret = 4;
+            break;
+        }
         outFrameCount += numEncoded;
         if (numEncoded && pic_recon && cliopt.recon)
             cliopt.recon->writePicture(pic_out);
@@ -622,5 +638,6 @@
 #if HAVE_VLD
     assert(VLDReportLeaks() == 0);
 #endif
-    return 0;
+
+    return ret;
 }
diff -r 31321122396b -r 02d00fd3e943 source/x265cli.h
--- a/source/x265cli.h	Thu Jan 29 09:31:58 2015 -0600
+++ b/source/x265cli.h	Thu Jan 29 09:33:07 2015 -0600
@@ -377,6 +377,12 @@
     H1("\nReconstructed video options (debugging):\n");
     H1("-r/--recon <filename>            Reconstructed raw image YUV or Y4M output file name\n");
     H1("   --recon-depth <integer>       Bit-depth of reconstructed raw image file. Defaults to input bit depth, or 8 if Y4M\n");
+    H1("\nExecutable return codes:\n");
+    H1("    0 - encode successful\n");
+    H1("    1 - unable to parse command line\n");
+    H1("    2 - unable to open encoder\n");
+    H1("    3 - unable to generate stream headers\n");
+    H1("    4 - encoder abort\n");
 #undef OPT
 #undef H0
 #undef H1
@@ -384,7 +390,7 @@
     if (level < X265_LOG_DEBUG)
         printf("\nUse --log-level full --help for a full listing\n");
     printf("\n\nComplete documentation may be found at http://x265.readthedocs.org/en/default/cli.html\n");
-    exit(0);
+    exit(1);
 }
 
 #ifdef __cplusplus


More information about the x265-devel mailing list