diff options
author | Wan-Teh Chang <wtc@google.com> | 2023-03-23 14:50:10 -0700 |
---|---|---|
committer | James Zern <jzern@google.com> | 2023-05-04 22:08:21 -0700 |
commit | 601a98b1542fa1fb439c715a9e2e8559338d33f8 (patch) | |
tree | 70c97495250029f204b4f6aae510375ad82c164e | |
parent | 3580bc559a223818a29c263e8b59d72ce56dddd5 (diff) | |
download | libvpx-601a98b1542fa1fb439c715a9e2e8559338d33f8.tar.gz |
Add comments about vpx_codec_enc_init_ver failure
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
-rw-r--r-- | vp9/vp9_cx_iface.c | 2 | ||||
-rw-r--r-- | vpx/src/vpx_encoder.c | 4 | ||||
-rw-r--r-- | vpx/vpx_encoder.h | 5 |
3 files changed, 10 insertions, 1 deletions
diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index e264ae9bd..f067efdf7 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -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; diff --git a/vpx/src/vpx_encoder.c b/vpx/src/vpx_encoder.c index 846638fe5..0d6e48015 100644 --- a/vpx/src/vpx_encoder.c +++ b/vpx/src/vpx_encoder.c @@ -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); } diff --git a/vpx/vpx_encoder.h b/vpx/vpx_encoder.h index a7f1552de..2de808973 100644 --- a/vpx/vpx_encoder.h +++ b/vpx/vpx_encoder.h @@ -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. |