summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2017-10-09 17:27:22 +0200
committerNicolas Dufresne <nicolas.dufresne@collabora.com>2017-10-11 13:49:30 -0400
commit3a0e4bc35d751b3e2487443418bc1713be6b8517 (patch)
treee2519bd80b5dbd2856c7ee363c0991ea4947f327
parent855659686252474b52253e57e1db869900caea32 (diff)
downloadgst-omx-3a0e4bc35d751b3e2487443418bc1713be6b8517.tar.gz
add gst_omx_buffer_flags_to_string()
Make debug logs more readable so users don't have to manually figure out the meaning of flags. https://bugzilla.gnome.org/show_bug.cgi?id=788767
-rw-r--r--omx/gstomx.c97
-rw-r--r--omx/gstomx.h1
-rw-r--r--omx/gstomxvideodec.c3
-rw-r--r--omx/gstomxvideoenc.c3
4 files changed, 98 insertions, 6 deletions
diff --git a/omx/gstomx.c b/omx/gstomx.c
index 400e3d6..5093103 100644
--- a/omx/gstomx.c
+++ b/omx/gstomx.c
@@ -55,6 +55,10 @@ GST_DEBUG_CATEGORY (gstomx_debug);
G_LOCK_DEFINE_STATIC (core_handles);
static GHashTable *core_handles;
+/* Cache used by gst_omx_buffer_flags_to_string() */
+G_LOCK_DEFINE_STATIC (buffer_flags_str);
+static GHashTable *buffer_flags_str;
+
GstOMXCore *
gst_omx_core_acquire (const gchar * filename)
{
@@ -197,6 +201,10 @@ gst_omx_core_release (GstOMXCore * core)
if (core->user_count == 0) {
GST_DEBUG ("Deinit core %p", core);
core->deinit ();
+
+ G_LOCK (buffer_flags_str);
+ g_clear_pointer (&buffer_flags_str, g_hash_table_unref);
+ G_UNLOCK (buffer_flags_str);
}
g_mutex_unlock (&core->lock);
@@ -343,8 +351,9 @@ gst_omx_component_handle_messages (GstOMXComponent * comp)
if (!port)
break;
- GST_DEBUG_OBJECT (comp->parent, "%s port %u got buffer flags 0x%08x",
- comp->name, port->index, (guint) flags);
+ GST_DEBUG_OBJECT (comp->parent,
+ "%s port %u got buffer flags 0x%08x (%s)", comp->name, port->index,
+ (guint) flags, gst_omx_buffer_flags_to_string (flags));
if ((flags & OMX_BUFFERFLAG_EOS)
&& port->port_def.eDir == OMX_DirOutput)
port->eos = TRUE;
@@ -577,9 +586,10 @@ EventHandler (OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent,
msg->type = GST_OMX_MESSAGE_BUFFER_FLAG;
msg->content.buffer_flag.port = nData1;
msg->content.buffer_flag.flags = nData2;
- GST_DEBUG_OBJECT (comp->parent, "%s port %u got buffer flags 0x%08x",
+ GST_DEBUG_OBJECT (comp->parent, "%s port %u got buffer flags 0x%08x (%s)",
comp->name, (guint) msg->content.buffer_flag.port,
- (guint) msg->content.buffer_flag.flags);
+ (guint) msg->content.buffer_flag.flags,
+ gst_omx_buffer_flags_to_string (msg->content.buffer_flag.flags));
gst_omx_component_send_message (comp, msg);
break;
@@ -2484,6 +2494,85 @@ gst_omx_command_to_string (OMX_COMMANDTYPE cmd)
return "Unknown command";
}
+struct BufferFlagString
+{
+ guint32 flag;
+ const gchar *str;
+};
+
+struct BufferFlagString buffer_flags_map[] = {
+ {OMX_BUFFERFLAG_EOS, "eos"},
+ {OMX_BUFFERFLAG_STARTTIME, "start-time"},
+ {OMX_BUFFERFLAG_DECODEONLY, "decode-only"},
+ {OMX_BUFFERFLAG_DATACORRUPT, "data-corrupt"},
+ {OMX_BUFFERFLAG_ENDOFFRAME, "end-of-frame"},
+ {OMX_BUFFERFLAG_SYNCFRAME, "sync-frame"},
+ {OMX_BUFFERFLAG_EXTRADATA, "extra-data"},
+ {OMX_BUFFERFLAG_CODECCONFIG, "codec-config"},
+ /* Introduced in OMX 1.2.0 */
+#ifdef OMX_BUFFERFLAG_TIMESTAMPINVALID
+ {OMX_BUFFERFLAG_TIMESTAMPINVALID, "timestamp-invalid"},
+#endif
+#ifdef OMX_BUFFERFLAG_READONLY
+ {OMX_BUFFERFLAG_READONLY, "read-only"},
+#endif
+#ifdef OMX_BUFFERFLAG_ENDOFSUBFRAME
+ {OMX_BUFFERFLAG_ENDOFSUBFRAME, "end-of-subframe"},
+#endif
+#ifdef OMX_BUFFERFLAG_SKIPFRAME
+ {OMX_BUFFERFLAG_SKIPFRAME, "skip-frame"},
+#endif
+ {0, NULL},
+};
+
+
+const gchar *
+gst_omx_buffer_flags_to_string (guint32 flags)
+{
+ GString *s = NULL;
+ guint i;
+ const gchar *str;
+
+ if (flags == 0)
+ return "";
+
+ /* Keep a cache of the string representation of the flags so we don't allocate
+ * and free strings for each buffer. In practice we should only have a handfull
+ * of flags so the cache won't consume much memory. */
+ if (!buffer_flags_str) {
+ G_LOCK (buffer_flags_str);
+ buffer_flags_str = g_hash_table_new_full (NULL, NULL, NULL, g_free);
+ G_UNLOCK (buffer_flags_str);
+ }
+
+ str = g_hash_table_lookup (buffer_flags_str, GUINT_TO_POINTER (flags));
+ if (str)
+ return str;
+
+ for (i = 0; buffer_flags_map[i].str != NULL; i++) {
+ if ((flags & buffer_flags_map[i].flag) == 0)
+ continue;
+
+ if (!s)
+ s = g_string_new (buffer_flags_map[i].str);
+ else
+ g_string_append_printf (s, ", %s", buffer_flags_map[i].str);
+ }
+
+ if (!s)
+ return "<unknown>";
+
+ str = g_string_free (s, FALSE);
+
+ G_LOCK (buffer_flags_str);
+ /* Transfer ownership of str to hash table */
+ g_hash_table_insert (buffer_flags_str, GUINT_TO_POINTER (flags),
+ (gchar *) str);
+ G_UNLOCK (buffer_flags_str);
+
+ return str;
+}
+
#if defined(USE_OMX_TARGET_RPI)
#define DEFAULT_HACKS (GST_OMX_HACK_NO_COMPONENT_ROLE | GST_OMX_HACK_HEIGHT_MULTIPLE_16)
#else
diff --git a/omx/gstomx.h b/omx/gstomx.h
index 77a2066..b6cb57b 100644
--- a/omx/gstomx.h
+++ b/omx/gstomx.h
@@ -345,6 +345,7 @@ GKeyFile * gst_omx_get_configuration (void);
const gchar * gst_omx_error_to_string (OMX_ERRORTYPE err);
const gchar * gst_omx_state_to_string (OMX_STATETYPE state);
const gchar * gst_omx_command_to_string (OMX_COMMANDTYPE cmd);
+const gchar * gst_omx_buffer_flags_to_string (guint32 flags);
guint64 gst_omx_parse_hacks (gchar ** hacks);
diff --git a/omx/gstomxvideodec.c b/omx/gstomxvideodec.c
index c98905d..b4c47a6 100644
--- a/omx/gstomxvideodec.c
+++ b/omx/gstomxvideodec.c
@@ -1531,8 +1531,9 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
goto flushing;
}
- GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x %" G_GUINT64_FORMAT,
+ GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x (%s) %" G_GUINT64_FORMAT,
(guint) buf->omx_buf->nFlags,
+ gst_omx_buffer_flags_to_string (buf->omx_buf->nFlags),
(guint64) GST_OMX_GET_TICKS (buf->omx_buf->nTimeStamp));
GST_VIDEO_DECODER_STREAM_LOCK (self);
diff --git a/omx/gstomxvideoenc.c b/omx/gstomxvideoenc.c
index 609faf2..dfd6704 100644
--- a/omx/gstomxvideoenc.c
+++ b/omx/gstomxvideoenc.c
@@ -752,8 +752,9 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
goto flushing;
}
- GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x %" G_GUINT64_FORMAT,
+ GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x (%s) %" G_GUINT64_FORMAT,
(guint) buf->omx_buf->nFlags,
+ gst_omx_buffer_flags_to_string (buf->omx_buf->nFlags),
(guint64) GST_OMX_GET_TICKS (buf->omx_buf->nTimeStamp));
GST_VIDEO_ENCODER_STREAM_LOCK (self);