[vlc-devel] [PATCH 1/2] vpx: refactor error handling

Tristan Matthews tmatth at videolan.org
Mon Feb 8 17:26:00 CET 2016


---
 modules/codec/vpx.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/modules/codec/vpx.c b/modules/codec/vpx.c
index 90180b8..2ec2bfe 100644
--- a/modules/codec/vpx.c
+++ b/modules/codec/vpx.c
@@ -53,6 +53,15 @@ vlc_module_begin ()
     set_subcategory(SUBCAT_INPUT_VCODEC)
 vlc_module_end ()
 
+static void vpx_err_msg(vlc_object_t *this, struct vpx_codec_ctx *ctx, const char *msg)
+{
+    const char *error  = vpx_codec_error(ctx);
+    const char *detail = vpx_codec_error_detail(ctx);
+    if (!detail)
+        detail = "no specific information";
+    msg_Err(this, msg, error, detail);
+}
+
 /*****************************************************************************
  * decoder_sys_t: libvpx decoder descriptor
  *****************************************************************************/
@@ -67,6 +76,7 @@ struct decoder_sys_t
 static picture_t *Decode(decoder_t *dec, block_t **pp_block)
 {
     struct vpx_codec_ctx *ctx = &dec->p_sys->ctx;
+    vlc_object_t *p_this = (vlc_object_t *)dec;
 
     block_t *block = *pp_block;
     if (!block)
@@ -95,11 +105,7 @@ static picture_t *Decode(decoder_t *dec, block_t **pp_block)
 
     if (err != VPX_CODEC_OK) {
         free(pkt_pts);
-        const char *error  = vpx_codec_error(ctx);
-        const char *detail = vpx_codec_error_detail(ctx);
-        if (!detail)
-            detail = "no specific information";
-        msg_Err(dec, "Failed to decode frame: %s (%s)", error, detail);
+        vpx_err_msg(p_this, ctx, "Failed to decode frame: %s (%s)");
         return NULL;
     }
 
@@ -191,8 +197,7 @@ static int Open(vlc_object_t *p_this)
         vp_version, vpx_codec_version_str(), vpx_codec_build_config());
 
     if (vpx_codec_dec_init(&sys->ctx, iface, &deccfg, 0) != VPX_CODEC_OK) {
-        const char *error = vpx_codec_error(&sys->ctx);
-        msg_Err(p_this, "Failed to initialize decoder: %s\n", error);
+        vpx_err_msg(p_this, &sys->ctx, "Failed to initialize decoder: %s (%s)");
         free(sys);
         return VLC_EGENERIC;;
     }
-- 
1.9.1



More information about the vlc-devel mailing list