openh264dec: Hook up openh264 messages to GStreamer logging
authorJan Schmidt <jan@centricular.com>
Wed, 30 Jan 2019 03:46:37 +0000 (14:46 +1100)
committerJan Schmidt <jan@centricular.com>
Wed, 30 Jan 2019 03:53:02 +0000 (14:53 +1100)
Use the OpenH264 callback to pass Openh264 internal warning/error
messages through the GStreamer logging framework

ext/openh264/gstopenh264dec.cpp

index d4b2da88e784a71b31ad93a228eb8ecee7d46b6c..afc4d2f520fa04e15bf340912ec1390d30cc028c 100644 (file)
@@ -113,12 +113,34 @@ gst_openh264dec_init (GstOpenh264Dec * openh264dec)
   gst_video_decoder_set_needs_format (GST_VIDEO_DECODER (openh264dec), TRUE);
 }
 
+static void
+openh264_trace_cb (void *ctx, int level, const char *string)
+{
+  GObject *o = G_OBJECT (ctx);
+  GstDebugLevel lvl = GST_LEVEL_WARNING;
+
+  if (level >= WELS_LOG_DETAIL)
+    lvl = GST_LEVEL_LOG;
+  else if (level >= WELS_LOG_DEBUG)
+    lvl = GST_LEVEL_DEBUG;
+  else if (level >= WELS_LOG_INFO)
+    lvl = GST_LEVEL_INFO;
+  else if (level >= WELS_LOG_WARNING)
+    lvl = GST_LEVEL_WARNING;
+  else if (level >= WELS_LOG_ERROR)
+    lvl = GST_LEVEL_ERROR;
+
+  gst_debug_log (GST_CAT_DEFAULT, lvl, "", "", 0, o, "%s", string);
+}
+
 static gboolean
 gst_openh264dec_start (GstVideoDecoder * decoder)
 {
   GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder);
   gint ret;
   SDecodingParam dec_param = { 0 };
+  int log_level;
+  WelsTraceCallback log_cb;
 
   if (openh264dec->decoder != NULL) {
     openh264dec->decoder->Uninitialize ();
@@ -127,6 +149,14 @@ gst_openh264dec_start (GstVideoDecoder * decoder)
   }
   WelsCreateDecoder (&(openh264dec->decoder));
 
+  log_level = WELS_LOG_WARNING;
+  log_cb = openh264_trace_cb;
+  openh264dec->decoder->SetOption (DECODER_OPTION_TRACE_LEVEL, &log_level);
+  openh264dec->decoder->SetOption (DECODER_OPTION_TRACE_CALLBACK,
+      (void *) &log_cb);
+  openh264dec->decoder->SetOption (DECODER_OPTION_TRACE_CALLBACK_CONTEXT,
+      (void *) &decoder);
+
   dec_param.uiTargetDqLayer = 255;
   dec_param.eEcActiveIdc = ERROR_CON_FRAME_COPY;
 #if OPENH264_MAJOR == 1 && OPENH264_MINOR < 6