shithub: libopusenc

Download patch

ref: 51f6ebd39969366013a870a66cd26b62514ff113
parent: 4f76493c968b44b62575a9b0202c6864b9dac26d
author: Jean-Marc Valin <[email protected]>
date: Thu May 18 19:43:10 EDT 2017

Implement ope_strerror()

--- a/include/opusenc.h
+++ b/include/opusenc.h
@@ -333,6 +333,13 @@
  */
 OPE_EXPORT int ope_encoder_ctl(OggOpusEnc *enc, int request, ...);
 
+/** Converts an opusenc error code into a human readable string.
+  *
+  * @param error Error number
+  * @returns Error string
+  */
+OPE_EXPORT const char *ope_strerror(int error);
+
 /** Returns a string representing the version of libopusenc being used at run time.
     \return A string describing the version of this library */
 OPE_EXPORT const char *ope_get_version_string(void);
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -805,6 +805,19 @@
   return ret;
 }
 
+const char *ope_strerror(int error) {
+  static const char * const ope_error_strings[5] = {
+    "cannot open file",
+    "call cannot be made at this point",
+    "unrecoverable error",
+    "invalid picture file",
+    "invalid icon file (pictures of type 1 MUST be 32x32 PNGs)"
+  };
+  if (error > -30) return opus_strerror(error+10);
+  else if (error >= OPE_INVALID_ICON) return ope_error_strings[-error-30];
+  else return "unknown error";
+}
+
 const char *ope_get_version_string(void)
 {
   return "libopusenc " PACKAGE_VERSION;