gdb: refactor time formating

Make it reuseable independent of the GstClockTimePrinter.
This commit is contained in:
Michael Olbrich 2019-05-11 20:39:00 +02:00 committed by Tim-Philipp Müller
parent 744687e537
commit 0d7db77bae

View file

@ -91,20 +91,15 @@ class GstObjectPrettyPrinter:
return "0x%x" % long(self.val)
class GstClockTimePrinter:
"Prints a GstClockTime / GstClockTimeDiff"
def __init__(self, val):
self.val = val
def to_string(self):
GST_SECOND = 1000000000
GST_CLOCK_TIME_NONE = 2**64-1
GST_CLOCK_STIME_NONE = -2**63
n = int(self.val)
def format_time(n, signed):
prefix = ""
invalid = False
if str(self.val.type) == "GstClockTimeDiff":
if signed:
if n == GST_CLOCK_STIME_NONE:
invalid = True
prefix = "+" if n >= 0 else "-"
@ -114,9 +109,9 @@ class GstClockTimePrinter:
invalid = True
if invalid:
return str(n) + " [99:99:99.999999999]"
return "99:99:99.999999999"
return str(n) + " [%s%u:%02u:%02u.%09u]" % (
return "%s%u:%02u:%02u.%09u" % (
prefix,
n / (GST_SECOND * 60 * 60),
(n / (GST_SECOND * 60)) % 60,
@ -124,6 +119,20 @@ class GstClockTimePrinter:
n % GST_SECOND)
def format_time_value(val):
return format_time(int(val), str(val.type) == "GstClockTimeDiff")
class GstClockTimePrinter:
"Prints a GstClockTime / GstClockTimeDiff"
def __init__(self, val):
self.val = val
def to_string(self):
return "%d [%s]" % (int(self.val), format_time_value(self.val))
def gst_pretty_printer_lookup(val):
if is_gst_type(val, "GstMiniObject"):
return GstMiniObjectPrettyPrinter(val)