From 16663a5e696c5987581a454e5a64e42ea3663957 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 13 Feb 2019 13:34:03 -0500 Subject: [PATCH] lib: iterator.c: auto-seek: handle new message types When reading the time of a given message for auto-seeking purposes: * Skip packet beginning/end messages as packet object beginning/end time properties are about to be removed. * Use a stream activity beginning time if known, otherwise skip the message for infinite and unknown times. * Use a stream activity end time if known, otherwise skip the message for an unknown time (a positive infinite time is always greater than any requested time). * Use the beginning time of a discarded events/packets message because this beginning time must be greater than or equal to the previous message's time for the same stream. Signed-off-by: Philippe Proulx --- lib/graph/iterator.c | 74 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/lib/graph/iterator.c b/lib/graph/iterator.c index a0da4e66..bc8faf85 100644 --- a/lib/graph/iterator.c +++ b/lib/graph/iterator.c @@ -55,6 +55,8 @@ #include #include #include +#include +#include #include #include #include @@ -994,34 +996,88 @@ int get_message_ns_from_origin(const struct bt_message *msg, const struct bt_message_inactivity *inactivity_msg = (const void *) msg; - BT_ASSERT(inactivity_msg->default_cs); clk_snapshot = inactivity_msg->default_cs; + BT_ASSERT(clk_snapshot); break; } - case BT_MESSAGE_TYPE_STREAM_BEGINNING: - case BT_MESSAGE_TYPE_STREAM_END: + case BT_MESSAGE_TYPE_PACKET_BEGINNING: + case BT_MESSAGE_TYPE_PACKET_END: /* Ignore */ goto end; - case BT_MESSAGE_TYPE_PACKET_BEGINNING: + case BT_MESSAGE_TYPE_DISCARDED_EVENTS: + case BT_MESSAGE_TYPE_DISCARDED_PACKETS: { - const struct bt_message_packet *pkt_msg = + const struct bt_message_discarded_items *disc_items_msg = (const void *) msg; - clk_snapshot = pkt_msg->packet->default_beginning_cs; + clk_snapshot = disc_items_msg->default_begin_cs; + BT_ASSERT_PRE(clk_snapshot, + "Discarded events/packets message has no default clock snapshot: %!+n", + msg); break; } - case BT_MESSAGE_TYPE_PACKET_END: + case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING: { - const struct bt_message_packet *pkt_msg = + const struct bt_message_stream_activity *stream_act_msg = (const void *) msg; - clk_snapshot = pkt_msg->packet->default_end_cs; + switch (stream_act_msg->default_cs_state) { + case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN: + case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE: + /* + * -inf is always less than any requested time, + * and we can't assume any specific time for an + * unknown clock snapshot, so skip this. + */ + goto set_ignore; + case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN: + clk_snapshot = stream_act_msg->default_cs; + BT_ASSERT(clk_snapshot); + break; + default: + abort(); + } + break; } + case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END: + { + const struct bt_message_stream_activity *stream_act_msg = + (const void *) msg; + + switch (stream_act_msg->default_cs_state) { + case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN: + /* + * We can't assume any specific time for an + * unknown clock snapshot, so skip this. + */ + goto set_ignore; + case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE: + /* + * +inf is always greater than any requested + * time. + */ + *ns_from_origin = INT64_MAX; + goto end; + case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN: + clk_snapshot = stream_act_msg->default_cs; + BT_ASSERT(clk_snapshot); + break; + default: + abort(); + } + + break; + } + case BT_MESSAGE_TYPE_STREAM_BEGINNING: + case BT_MESSAGE_TYPE_STREAM_END: + /* Ignore */ + break; default: abort(); } +set_ignore: if (!clk_snapshot) { *ignore = true; goto end; -- 2.34.1