5 from glib_gobject_helper import g_type_to_name, g_type_name_from_instance
7 if sys.version_info[0] >= 3:
11 def is_gst_type(val, klass):
12 def _is_gst_type(type):
13 if str(type) == klass:
16 while type.code == gdb.TYPE_CODE_TYPEDEF:
19 if type.code != gdb.TYPE_CODE_STRUCT:
22 fields = type.fields()
26 first_field = fields[0]
27 return _is_gst_type(first_field.type)
30 if type.code != gdb.TYPE_CODE_PTR:
33 return _is_gst_type(type)
36 class GstMiniObjectPrettyPrinter:
37 "Prints a GstMiniObject instance pointer"
39 def __init__(self, val):
44 inst = self.val.cast(gdb.lookup_type("GstMiniObject").pointer())
46 name = g_type_to_name(gtype)
47 return "0x%x [%s]" % (long(self.val), name)
49 return "0x%x" % long(self.val)
52 class GstObjectPrettyPrinter:
53 "Prints a GstObject instance"
55 def __init__(self, val):
60 name = g_type_name_from_instance(self.val)
62 name = str(self.val.type.target())
63 if long(self.val) != 0:
64 inst = self.val.cast(gdb.lookup_type("GstObject").pointer())
65 inst_name = inst["name"].string()
67 name += "|" + inst_name
68 return ("0x%x [%s]") % (long(self.val), name)
70 return "0x%x" % long(self.val)
73 class GstClockTimePrinter:
74 "Prints a GstClockTime / GstClockTimeDiff"
76 def __init__(self, val):
80 GST_SECOND = 1000000000
81 GST_CLOCK_TIME_NONE = 2**64-1
82 GST_CLOCK_STIME_NONE = -2**63
86 if str(self.val.type) == "GstClockTimeDiff":
87 if n == GST_CLOCK_STIME_NONE:
89 prefix = "+" if n >= 0 else "-"
92 if n == GST_CLOCK_TIME_NONE:
96 return str(n) + " [99:99:99.999999999]"
98 return str(n) + " [%s%u:%02u:%02u.%09u]" % (
100 n / (GST_SECOND * 60 * 60),
101 (n / (GST_SECOND * 60)) % 60,
102 (n / GST_SECOND) % 60,
106 def gst_pretty_printer_lookup(val):
107 if is_gst_type(val, "GstMiniObject"):
108 return GstMiniObjectPrettyPrinter(val)
109 if is_gst_type(val, "GstObject"):
110 return GstObjectPrettyPrinter(val)
111 if str(val.type) == "GstClockTime" or str(val.type) == "GstClockTimeDiff":
112 return GstClockTimePrinter(val)
120 # Make sure this is always used befor the glib lookup function.
121 # Otherwise the gobject pretty printer is used for GstObjects
122 obj.pretty_printers.insert(0, gst_pretty_printer_lookup)