Add comments about aom_codec_enc_init_ver failure
Address the questions:
1. If aom_codec_enc_init_ver() fails, should I still call
aom_codec_destroy() on the encoder context?
2. Is it safe to call aom_codec_error_detail() when
aom_codec_enc_init_ver() failed?
Change-Id: I1b0e090d11dd9f853fe203f4cbb6080c3c7b0506
diff --git a/aom/aom_encoder.h b/aom/aom_encoder.h
index b4f7124..e3d8d29 100644
--- a/aom/aom_encoder.h
+++ b/aom/aom_encoder.h
@@ -903,7 +903,7 @@
/*!\brief Initialize an encoder instance
*
- * Initializes a encoder context using the given interface. Applications
+ * Initializes an encoder context using the given interface. Applications
* should call the aom_codec_enc_init convenience macro instead of this
* function directly, to ensure that the ABI version number parameter
* is properly initialized.
@@ -912,6 +912,9 @@
* is not thread safe and should be guarded with a lock if being used
* in a multithreaded context.
*
+ * If aom_codec_enc_init_ver() fails, it is not necessary to call
+ * aom_codec_destroy() on the encoder context.
+ *
* \param[in] ctx Pointer to this instance's context.
* \param[in] iface Pointer to the algorithm interface to use.
* \param[in] cfg Configuration to use, if known.
diff --git a/aom/src/aom_encoder.c b/aom/src/aom_encoder.c
index 888e632..77f5960 100644
--- a/aom/src/aom_encoder.c
+++ b/aom/src/aom_encoder.c
@@ -80,6 +80,10 @@
res = ctx->iface->init(ctx);
if (res) {
+ // IMPORTANT: ctx->priv->err_detail must be null or point to a string
+ // that remains valid after ctx->priv is destroyed, such as a C string
+ // literal. This makes it safe to call aom_codec_error_detail() after
+ // aom_codec_enc_init_ver() failed.
ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL;
aom_codec_destroy(ctx);
}
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index d291041..5d36480 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -564,6 +564,7 @@
ratio->den /= denom;
}
+// Called by encoder_encode() only. Must not be called by encoder_init().
static aom_codec_err_t update_error_state(
aom_codec_alg_priv_t *ctx, const struct aom_internal_error_info *error) {
const aom_codec_err_t res = error->error_code;