Add comments about vpx_codec_enc_init_ver failure
authorWan-Teh Chang <wtc@google.com>
Thu, 23 Mar 2023 21:50:10 +0000 (14:50 -0700)
committerJames Zern <jzern@google.com>
Fri, 5 May 2023 05:08:21 +0000 (22:08 -0700)
Address the questions:
1. If vpx_codec_enc_init_ver() fails, should I still call
   vpx_codec_destroy() on the encoder context?
2. Is it safe to call vpx_codec_error_detail() when
   vpx_codec_enc_init_ver() failed?

Change-Id: I1b0e090d11dd9f853fe203f4cbb6080c3c7b0506

vp9/vp9_cx_iface.c
vpx/src/vpx_encoder.c
vpx/vpx_encoder.h

index e264ae9..f067efd 100644 (file)
@@ -129,6 +129,8 @@ struct vpx_codec_alg_priv {
   BufferPool *buffer_pool;
 };
 
+// Called by encoder_set_config() and encoder_encode() only. Must not be called
+// by encoder_init().
 static vpx_codec_err_t update_error_state(
     vpx_codec_alg_priv_t *ctx, const struct vpx_internal_error_info *error) {
   const vpx_codec_err_t res = error->error_code;
index 846638f..0d6e480 100644 (file)
@@ -54,6 +54,10 @@ vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx,
     res = ctx->iface->init(ctx, NULL);
 
     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 vpx_codec_error_detail() after
+      // vpx_codec_enc_init_ver() failed.
       ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL;
       vpx_codec_destroy(ctx);
     }
index a7f1552..2de8089 100644 (file)
@@ -877,7 +877,7 @@ typedef struct vpx_svc_parameters {
 
 /*!\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 vpx_codec_enc_init convenience macro instead of this
  * function directly, to ensure that the ABI version number parameter
  * is properly initialized.
@@ -886,6 +886,9 @@ typedef struct vpx_svc_parameters {
  * is not thread safe and should be guarded with a lock if being used
  * in a multithreaded context.
  *
+ * If vpx_codec_enc_init_ver() fails, it is not necessary to call
+ * vpx_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. May be NULL.