From 2a57bdaa7e6bd9caa6d3f30da089803ca7026d91 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Tue, 18 Dec 2012 22:23:42 +0100 Subject: openjpegenc/-dec: print openjpeg logs for debug tracing --- ext/openjpeg/gstopenjpegdec.c | 38 +++++++++++++++++++++++++++++++++++++- ext/openjpeg/gstopenjpegenc.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/ext/openjpeg/gstopenjpegdec.c b/ext/openjpeg/gstopenjpegdec.c index d027e960a..da2efdd18 100644 --- a/ext/openjpeg/gstopenjpegdec.c +++ b/ext/openjpeg/gstopenjpegdec.c @@ -863,6 +863,33 @@ gst_openjpeg_dec_negotiate (GstOpenJPEGDec * self, opj_image_t * image) return GST_FLOW_OK; } +static void +gst_openjpeg_dec_opj_error (const char *msg, void *userdata) +{ + GstOpenJPEGDec *self = GST_OPENJPEG_DEC (userdata); + gchar *trimmed = g_strchomp (g_strdup (msg)); + GST_TRACE_OBJECT (self, "openjpeg error: %s", trimmed); + g_free (trimmed); +} + +static void +gst_openjpeg_dec_opj_warning (const char *msg, void *userdata) +{ + GstOpenJPEGDec *self = GST_OPENJPEG_DEC (userdata); + gchar *trimmed = g_strchomp (g_strdup (msg)); + GST_TRACE_OBJECT (self, "openjpeg warning: %s", trimmed); + g_free (trimmed); +} + +static void +gst_openjpeg_dec_opj_info (const char *msg, void *userdata) +{ + GstOpenJPEGDec *self = GST_OPENJPEG_DEC (userdata); + gchar *trimmed = g_strchomp (g_strdup (msg)); + GST_TRACE_OBJECT (self, "openjpeg info: %s", trimmed); + g_free (trimmed); +} + static GstFlowReturn gst_openjpeg_dec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame) @@ -872,6 +899,7 @@ gst_openjpeg_dec_handle_frame (GstVideoDecoder * decoder, gint64 deadline; GstMapInfo map; opj_dinfo_t *dec; + opj_event_mgr_t callbacks; opj_cio_t *io; opj_image_t *image; GstVideoFrame vframe; @@ -891,7 +919,15 @@ gst_openjpeg_dec_handle_frame (GstVideoDecoder * decoder, if (!dec) goto initialization_error; - opj_set_event_mgr ((opj_common_ptr) dec, NULL, NULL); + if (G_UNLIKELY (gst_debug_category_get_threshold (GST_CAT_DEFAULT) >= + GST_LEVEL_TRACE)) { + callbacks.error_handler = gst_openjpeg_dec_opj_error; + callbacks.warning_handler = gst_openjpeg_dec_opj_warning; + callbacks.info_handler = gst_openjpeg_dec_opj_info; + opj_set_event_mgr ((opj_common_ptr) dec, &callbacks, self); + } else { + opj_set_event_mgr ((opj_common_ptr) dec, NULL, NULL); + } params = self->params; if (self->ncomps) diff --git a/ext/openjpeg/gstopenjpegenc.c b/ext/openjpeg/gstopenjpegenc.c index 06da0fb7e..24f08426f 100644 --- a/ext/openjpeg/gstopenjpegenc.c +++ b/ext/openjpeg/gstopenjpegenc.c @@ -714,6 +714,33 @@ gst_openjpeg_enc_fill_image (GstOpenJPEGEnc * self, GstVideoFrame * frame) return image; } +static void +gst_openjpeg_dec_opj_error (const char *msg, void *userdata) +{ + GstOpenJPEGEnc *self = GST_OPENJPEG_ENC (userdata); + gchar *trimmed = g_strchomp (g_strdup (msg)); + GST_TRACE_OBJECT (self, "openjpeg error: %s", trimmed); + g_free (trimmed); +} + +static void +gst_openjpeg_dec_opj_warning (const char *msg, void *userdata) +{ + GstOpenJPEGEnc *self = GST_OPENJPEG_ENC (userdata); + gchar *trimmed = g_strchomp (g_strdup (msg)); + GST_TRACE_OBJECT (self, "openjpeg warning: %s", trimmed); + g_free (trimmed); +} + +static void +gst_openjpeg_dec_opj_info (const char *msg, void *userdata) +{ + GstOpenJPEGEnc *self = GST_OPENJPEG_ENC (userdata); + gchar *trimmed = g_strchomp (g_strdup (msg)); + GST_TRACE_OBJECT (self, "openjpeg info: %s", trimmed); + g_free (trimmed); +} + static GstFlowReturn gst_openjpeg_enc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame) @@ -722,6 +749,7 @@ gst_openjpeg_enc_handle_frame (GstVideoEncoder * encoder, GstFlowReturn ret = GST_FLOW_OK; GstMapInfo map; opj_cinfo_t *enc; + opj_event_mgr_t callbacks; opj_cio_t *io; opj_image_t *image; GstVideoFrame vframe; @@ -733,7 +761,15 @@ gst_openjpeg_enc_handle_frame (GstVideoEncoder * encoder, if (!enc) goto initialization_error; - opj_set_event_mgr ((opj_common_ptr) enc, NULL, NULL); + if (G_UNLIKELY (gst_debug_category_get_threshold (GST_CAT_DEFAULT) >= + GST_LEVEL_TRACE)) { + callbacks.error_handler = gst_openjpeg_dec_opj_error; + callbacks.warning_handler = gst_openjpeg_dec_opj_warning; + callbacks.info_handler = gst_openjpeg_dec_opj_info; + opj_set_event_mgr ((opj_common_ptr) enc, &callbacks, self); + } else { + opj_set_event_mgr ((opj_common_ptr) enc, NULL, NULL); + } if (!gst_video_frame_map (&vframe, &self->input_state->info, frame->input_buffer, GST_MAP_READ)) -- cgit v1.2.1